In ASTWriter, input files are sorted based on whether they are system or user. The current implementation used single std::queue with push_back and push_front. This resulted in the user files being reversed.
This patch fixes that by keeping the system/user distinction, but otherwise serializing files in the order they were loaded by the SourceManager. This is then used in the dependency scanner to report module map dependencies in the correct order.
Depends on D134224.
This is loop invariant and can be pulled out.