Page MenuHomePhabricator

[clang][modules] Use extensible RTTI for ModuleFileExtension
ClosedPublic

Authored by jansvoboda11 on Mar 1 2021, 10:04 AM.

Details

Summary

Clang exposes an interface for extending the PCM/PCH file format: ModuleFileExtension.

Clang itself has only a single implementation of the interface: TestModuleFileExtension that can be instantiated via the -ftest-module-file_extension= command line argument (and is stored in FrontendOptions::ModuleFileExtensions).

Clients of the Clang library can extend the PCM/PCH file format by pushing an instance of their extension class to the FrontendOptions::ModuleFileExtensions vector.

When generating the -ftest-module-file_extension= command line argument from FrontendOptions, a downcast is used to distinguish between the Clang's testing extension and other (client) extensions.

This functionality is enabled by LLVM-style RTTI. However, this style of RTTI is hard to extend, as it requires patching Clang (adding new case to the ModuleFileExtensionKind enum).

This patch switches to the LLVM RTTI for open class hierarchies, which allows libClang users (e.g. Swift) to create implementations of ModuleFileExtension without patching Clang. (Documentation of the feature: https://llvm.org/docs/HowToSetUpLLVMStyleRTTI.html#rtti-for-open-class-hierarchies)

Diff Detail

Event Timeline

jansvoboda11 requested review of this revision.Mar 1 2021, 10:04 AM
jansvoboda11 created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2021, 10:04 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
jansvoboda11 edited the summary of this revision. (Show Details)Mar 1 2021, 10:05 AM
jansvoboda11 edited the summary of this revision. (Show Details)
jansvoboda11 edited the summary of this revision. (Show Details)Mar 1 2021, 10:11 AM

Looks fine to me, but it would be good for a Swift person to look at this patch.

artemcm accepted this revision.Mar 4 2021, 10:04 AM
artemcm added a subscriber: artemcm.

This looks good to me, thanks!

This revision is now accepted and ready to land.Mar 4 2021, 10:04 AM