This is an archive of the discontinued LLVM Phabricator instance.

[clang] Change ordering of PreableCallbacks to make sure PP can be referenced in them
ClosedPublic

Authored by kbobyrev on Nov 24 2021, 4:17 AM.

Details

Summary

Currently, BeforeExecute is called before BeginSourceFile which does not allow
using PP in the callbacks. Change the ordering to ensure it is possible.
This is a prerequisite for D114370.

Originated from a discussion with @kadircet.

Diff Detail

Event Timeline

kbobyrev requested review of this revision.Nov 24 2021, 4:17 AM
kbobyrev created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptNov 24 2021, 4:17 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

As discussed offline this definitely LGTM, let me summarize the reasoning here.

The original review was in https://reviews.llvm.org/D41365. It's unclear why they went with before BeginSourceFile. In theory having the callback issued before BeginSourceFile allows setting various options that'll effect parsing, but today there's only one user (at least in the upstream) of this callback, clangd, which uses the callack to stash some state from CompilerIntance rather than mutating it.
If we ever have users that'll need to mutate the CompilerIntance before BeginSourceFile, I think we should have a particular callback for that use case then.

Will still wait for feedback from @sammccall as he might have some historical context.

sammccall accepted this revision.Nov 25 2021, 7:55 AM

Yeah this change definitely looks safe:

  • we've moving it across BeginSourceFile only, which doesn't seem to do anything for the usual parse that we'd use when building preambles.
  • BeforeExecute isn't widely used

Also it seems saner: Before/AfterExecute are now consistently nested inside Begin/EndSourceFile.

I don't have particular insight into the original motivation, but I guess it was just driven by what was needed: why go for the "more powerful" thing if we only needed to inspect the CompilerInstance?

This revision is now accepted and ready to land.Nov 25 2021, 7:55 AM