Skip to content

[IncludeTree] Fix PPCallback for include tree that can cause missing .d file #8624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2024

Conversation

cachemeifyoucan
Copy link

For IncludeDirective callback from include-tree, do not callback with null FileEntry as that dependency collector using that to indicate a missing header include, and will not emit dependency file in this case.

Unlike a regular callback from Lexer, include tree doesn't resolve headers so it cannot callback with a FileEntry to the header file being included when the include is actually a module. The behavior for the callback has to be changed slightly that it uses the ASTFile FileEntry.

rdar://126885995

@cachemeifyoucan
Copy link
Author

@swift-ci please test llvm

// the same behavior as non-include-tree build where the FileEntry is for
// the header file.
Module *M = Imported;
InclusionCallback(M->getASTFile(), Imported);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will behave correctly for the dependency file generator, but I'm concerned that other PPCallbacks do actually look at the file entry.

Some options

  1. Accept the weirdness for now and make this a FIXME comment
  2. Change the dependency file generator so it ignores a missing file when building with include tree. I see there is an option AddMissingHeaderDeps, but not sure if this is exactly what we want or not.
  3. Open the file and pass the correct FileEntryRef -- this file presumably exists in the include tree filesystem. The downside is we would need to record the path in the includetree and open it, which is unfortunate.

I'm leaning toward (1) or (2).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what that parameter means is kind of debatable. Doc says:

  /// \param File The actual file that may be included by this inclusion
  /// directive.

So technically ASTFile is the file getting "included" here but I don't know if it is a valid assumption till now that the file means "headerfile" and you can rely on this information. From all the code in tree, dependency is the only consumer that actually uses File, and dependency graph is the only one that cares about what File points to.

In this case, the dependency graph (.dot) file will have nodes for .pcm file and that include directive is an edge from source file to pcm file.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see several consumers that look at the File, at least in this branch:

  • clang-tidy HeaderIncludeCycleCheck
  • clangd IncludeStructure::RecordHeaders
  • clangd IncludeGraphCollector
  • include-cleaner PPRecorder and RecordPragma
  • modularize CoverageCheckerCallbacks
  • clang ModuleDependencyPPCallbacks
  • clang IndexingAction
  • libclang CXIndexDataConsumer

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed a bunch in clang-tools-extra. I guess that makes (2) a less good option.

….d file

For IncludeDirective callback from include-tree, do not callback with
null FileEntry as that dependency collector using that to indicate a
missing header include, and will not emit dependency file in this case.

Unlike a regular callback from Lexer, include tree doesn't resolve
headers so it cannot callback with a FileEntry to the header file being
included when the include is actually a module. The behavior for the
callback has to be changed slightly that it uses the ASTFile FileEntry.

rdar://126885995
@cachemeifyoucan
Copy link
Author

Sounds like (1) might actually be the best solution right now. Add FIXME and update test to also generate a .dot file which points to pcm to clarify the intent.

@cachemeifyoucan
Copy link
Author

@swift-ci please test llvm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants