This is an archive of the discontinued LLVM Phabricator instance.

[llvm] Enable specifying the order of Registry entries
DraftPublic

Authored by njames93 on Nov 13 2020, 12:03 PM.
This is a draft revision that has not yet been submitted for review.

Details

Reviewers
None
Summary

Adds support for specifying the order that items appear in llvm::Registry instances.
Currently they appear in the Registry linked list in an undefined order due to the 'static initialization order fiasco'.
For most registries this doesn't pose a problem as there is no observable difference in behaviour, however for a select few there is.
Take the CompilationDatabasePlugins as example. Usages of this is to load a database from a directory with each plugin, breaking out of the loop once a plugin is successful.
In the case where 2 plugins both can load from the same directory, the database you will get will depend on which plugin entry was initialized first. A bug for this has been reported here - https://github.com/clangd/clangd/issues/578.

This patch adds an optional paramater to the Registry::Add function to specify the order of the plugins in the list, lower orders appear near the start. Any plugins that dont specify an order will be placed at the end using the same SIOF behaviour that currently exists.

Diff Detail

Event Timeline

njames93 created this revision.Nov 13 2020, 12:03 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptNov 13 2020, 12:03 PM
njames93 updated this revision to Diff 305312.Nov 14 2020, 6:22 AM
  • Fix some lint warnings, can't fix the include order as the fix disagrees with clang-format.
  • Add missing new line at end of test file.
nridge added a subscriber: nridge.Nov 14 2020, 11:34 AM
njames93 updated this revision to Diff 305454.Nov 16 2020, 3:22 AM

Use __LINE__ instead of __COUNTER__ macro as its standardized.