Per the FileManager documentation, VirtualFileEntries is a subset of SeenFileEntries. This means we only have to iterate over the latter to create complete UID mapping. This allows us to map UID to FileEntryRef instead of FileEntry.
|3,850 ms||libcxx CI Modules > llvm-libc++-shared-cfg-in.libcxx/algorithms/specialized_algorithms/special_mem_concepts::nothrow_sentinel_for.compile.pass.cpp|
Script: -- : 'COMPILED WITH'; /home/libcxx-builder/.buildkite-agent/builds/9f2cc96f206f-1/llvm-project/libcxx-ci/install/bin/clang++ /home/libcxx-builder/.buildkite-agent/builds/9f2cc96f206f-1/llvm-project/libcxx-ci/libcxx/test/libcxx/algorithms/specialized.algorithms/special.mem.concepts/nothrow_sentinel_for.compile.pass.cpp --target=x86_64-unknown-linux-gnu -nostdinc++ -I /home/libcxx-builder/.buildkite-agent/builds/9f2cc96f206f-1/llvm-project/libcxx-ci/build/generic-modules/include/c++/v1 -I /home/libcxx-builder/.buildkite-agent/builds/9f2cc96f206f-1/llvm-project/libcxx-ci/build/generic-modules/include/c++/v1 -I /home/libcxx-builder/.buildkite-agent/builds/9f2cc96f206f-1/llvm-project/libcxx-ci/libcxx/test/support -std=c++2b -fmodules -fcxx-modules -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-noexcept-type -Wno-atomic-alignment -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_DISABLE_AVAILABILITY -Werror=thread-safety -Wuser-defined-warnings -fsyntax-only
|1,530 ms||x64 debian > LLVM.CodeGen/AArch64::implicit-null-check.ll|
Script: -- : 'RUN: at line 2'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/llc < /var/lib/buildkite-agent/builds/llvm-project/llvm/test/CodeGen/AArch64/implicit-null-check.ll -verify-machineinstrs -O3 -mtriple=aarch64-unknown-unknown -enable-implicit-null-checks | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck /var/lib/buildkite-agent/builds/llvm-project/llvm/test/CodeGen/AArch64/implicit-null-check.ll
Iterating over SeenFileEntries and skipping VirtualFileEntries looks good to me.
I'm not sure about changing this to FileEntryRef though. The way this API works you only get one per unique file, which is well suited to FileEntry * which has the same uniquing behaviour. In this case you're going to get a FileEntryRef, but *which* ref you get is non-deterministic if there were multiple refs for the same file (depends on hash table iteration order). Also, it will never give you a vfs mapped path since it's skipping those (V.dyn_cast<FileEntry *>()).
I think if we want to change this to FileEntryRef it needs to be deterministic which ref you get.
I think this might be the root of the problem we are seeing: depending on build configuration sometimes our build inputs are hard links that in the case of identical inputs point to the same inode. In that case we are seeing non-deterministic header paths serialized in pcm files. IIUC the header files are serialized based in their unique ID, so it wouldn't be possible to handle this case, is this right?
If compiling a single pcm accesses multiple hard links with the same UID, then it would not be possible to use the set of UIDs to get the "right path". At best we could make it get a deterministic path -- e.g. if we tracked the order of access.
If compiling a single pcm accesses only one hard link but it's an implicit module build and the overall compiler invocation accesses another one with the same UID, you are currently in the same situation as above, though in theory you could avoid it by not sharing the FileManager across implicit module builds. In clang-scan-deps we don't share the FileManager and we get away with it because we have a separate filesystem caching layer. In a normal implicit modules build I don't know how much this would cost.
If you're on a platform that supports fcntl with F_GETPATH such as Darwin, another possible source of non-determinism is that the underlying OS may return a non-deterministic RealPath from openFileForRead when there are multiple hard links.
Sounds like the easies way out is serializing all FileEntryRef objects we know in deterministic order.
With you so far. Is there a reason we need to use the UIDs in this case? Would it be possible to refactor GetUniqueIDMapping to instead populate an array with all the FileEntryRefs that had been seen and serialize that instead?