This is an archive of the discontinued LLVM Phabricator instance.

Moved the IndexDataConsumer::finish call into the IndexASTConsumer from IndexAction
ClosedPublic

Authored by gribozavr on Aug 28 2019, 6:31 AM.

Details

Summary

Doing so removes the last reason to expose a FrontendAction from
libIndex.

Event Timeline

gribozavr created this revision.Aug 28 2019, 6:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 28 2019, 6:31 AM
ilya-biryukov added inline comments.Aug 28 2019, 6:44 AM
clang/lib/Index/IndexingAction.cpp
77

The fact that we call addPPCallbacks after creating ASTContext is a bit concerning.

This wouldn't probably cause any problems in practice, but generally changing preprocessor by the time ASTContext is already created seems dangerous (what if something there ever starts depending on the state of the preprocessor?)

I think this concern is easily elevated if we change Preprocessor and call addPPCallbacks on CreateASTConsumer(CompilerInvocation& CI). That would mean we have a separate function that sets up the preprocessor and creates IndexASTConsumer and it should be exposed to the clients.

Have you considered this approach? Would it work?

gribozavr marked 2 inline comments as done.Aug 28 2019, 7:10 AM
gribozavr added inline comments.
clang/lib/Index/IndexingAction.cpp
77

It does feel a bit weird, but we shouldn't have started parsing before calling Initialize on the ASTConsumer. Therefore I agree with you that it won't cause problems in practice.

Calling addPPCallbacks in FrontendAction is against the goal of this patch set. The goal is to encapsulate as much as possible in the IndexASTConsumer, because they compose well, unlike FrontendActions. Therefore, requiring customization in FrontendAction is not possible.

jkorous added inline comments.Aug 28 2019, 10:34 AM
clang/lib/Index/IndexingAction.cpp
77

We could also move the preprocessor setup to constructor and check/add asserts that ASTContext has been provided to IndexingContext and IndexDataConsumer implementations.

ilya-biryukov accepted this revision.Aug 28 2019, 10:35 AM
ilya-biryukov marked an inline comment as done.

LGTM

clang/lib/Index/IndexingAction.cpp
77

LG, let's keep it like this and hope this won't break in the future too.
And if it will, we would probably be able to fix this by setting up PPCallbacks at the time when we create the ASTConsumer, i.e.

std::unique_ptr<ASTConsumer> createIndexASTConsumer(CompilerInvocation &CI) {
  CI.getPreprocessor().addPPCallback();
  return llvm::make_unique<IndexASTConsumer>(...);
}

That would reduce the gap between FrontendAction::BeginSourceFile and addPPCallbacks to just a few instructions, and the chances of breaking stuff would be even less.

This revision is now accepted and ready to land.Aug 28 2019, 10:35 AM
gribozavr closed this revision.Aug 29 2019, 4:39 AM
gribozavr marked an inline comment as done.

Committed as r370336.