This is an archive of the discontinued LLVM Phabricator instance.

[clang-tblgen] Fix non-determinism in generating AttrSubMatchRulesParserStringSwitches.inc
ClosedPublic

Authored by ikudrin on Nov 3 2021, 10:53 PM.

Details

Summary

llvm::MapVector, compared to std::map, guarantees the same iteration order in different runs.

Diff Detail

Event Timeline

ikudrin created this revision.Nov 3 2021, 10:53 PM
ikudrin requested review of this revision.Nov 3 2021, 10:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 3 2021, 10:53 PM

I'd like to understand the motivation behind the change a bit more. What problems stem from generating the parsing helpers in a different order? Why do we not need the same changes when generating documentation (see EmitClangAttrDocs())?

We've noticed binary differences in clang in several builds on our local build bots, and the patch fixed that.

As for generating the documentation, the issue can be seen, for example, in Clang-12 and Clang-13 documentation, where the section "Nullable Attributes" is placed differently. Maybe it'll be better to sort the categories alphabetically. Anyway, that is a similar but still a different issue.

We've noticed binary differences in clang in several builds on our local build bots, and the patch fixed that.

As for generating the documentation, the issue can be seen, for example, in Clang-12 and Clang-13 documentation, where the section "Nullable Attributes" is placed differently. Maybe it'll be better to sort the categories alphabetically. Anyway, that is a similar but still a different issue.

FWIW, I consider the documentation issue to be more of a problem than the one being fixed here. The fix for this means code we generate will be generated in the same order every time, which has nice properties in terms of doing incremental builds, but is largely unimportant as far as users are concerned. The documentation is user facing, so there's more of a chance to notice positional changes there.

I'm happy enough with the changes, but please fix the other nondeterminism at the same time so that we don't have to play whack-a-mole in this file.

The compiler has to be deterministic and one way to check that is to recompile a relatively large project several times. For clang, that large project is usually clang itself, so it has to be compiled in a stable way.

Anyway, I've prepared a fix for generating the documentation, D113477. Please, take a look.

aaron.ballman accepted this revision.Nov 9 2021, 4:53 AM

LGTM, thanks for the fix!

This revision is now accepted and ready to land.Nov 9 2021, 4:53 AM
This revision was automatically updated to reflect the committed changes.