Translation units with multiple direct modular dependencies trigger a non-deterministic ordering in clang-scan-deps. This boils down to usage of std::unordered_map, which gets replaced by std::map in this patch.
Depends on D103526.
Differential D103807
[clang][deps] Ensure deterministic order of TU '-fmodule-file=' arguments jansvoboda11 on Jun 7 2021, 6:09 AM. Authored by
Details Translation units with multiple direct modular dependencies trigger a non-deterministic ordering in clang-scan-deps. This boils down to usage of std::unordered_map, which gets replaced by std::map in this patch. Depends on D103526.
Diff Detail
Event TimelineComment Actions llvm discourages the use of std::map: Comment Actions I'm not sure the performance problems with std::map will matter in practice here, but have you considered sorting before emission rather than relying on the data structure's iteration order? (It'd make it easy to switch to StringMap in the future.) Comment Actions I'm aware of the drawbacks of std::map, but I think having the container sorted at all times promotes correctness/determinism which we really care about in this context. Forgetting to call sort at all the right places is very easy as this patch demonstrates. But if you are strongly opposed to using std::map here, I'm okay with using std::unordered_map or llvm::StringMap and sorting where necessary. Comment Actions Another option to be aware of is MapVector (https://llvm.org/docs/ProgrammersManual.html#llvm-adt-mapvector-h). Does not sort, but guarantees iteration order. But LGTM anyway. I don't think the exact data structure is important here. Please just add a comment documenting that consumers need a deterministic iteration order so anyone updating or optimizing this later knows what the constraints are. |