Sort dependencies of types correctly so the C++ compiler does not get confused.