-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][modules] Avoid calling expensive SourceManager::translateFile()
#86216
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,7 @@ | |
// CHECK-NEXT: "context-hash": "{{.*}}", | ||
// CHECK-NEXT: "file-deps": [ | ||
// CHECK-NEXT: "[[PREFIX]]/first/module.modulemap", | ||
// CHECK-NEXT: "[[PREFIX]]/second/module.modulemap", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a side-effect of the change in |
||
// CHECK-NEXT: "[[PREFIX]]/second/second.h", | ||
// CHECK-NEXT: "[[PREFIX]]/second/second.modulemap" | ||
// CHECK-NEXT: ], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the connection between this change and the rest of the commit?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider that
SourceManager::translateFile()
always prefers localSLocEntries
. Now let's say that a module is defined in a module map that gets included via theextern
directive from a top-level module map Clang find via header search. Before loading PCM for this module, the following code will resolve to the localSLocEntry
(there are no loaded entries yet).After compiling and loading the PCM for such module,
Module::DefinitionLoc
gets updated and now points into the loadedSLocEntry
. Therefore,ModuleMap::getContainingModuleMapFile(Module)
returns the loadedSLocEntry
. Then,SourceManager::translateFile()
maps that to the localSLocEntry
, so we end up with a result identical to the previous one.This patch gets rid of the unnecessary conversions and does this instead.
This means that after loading the PCM for the module, this points into the table of loaded
SLocEntries
. The importer knows that the containing module map is not a top level module map. When it attempts to walk up the include chain to get the the top-level module map for this module (usingSourceManager::getIncludeLoc()
) it gets an invalidSourceLocation
. This is because the PCM was not compiled from the top-level module map, itsSourceManager
never knew about the file, and therefore can't walk up from the loadedSLocEntry
.This means that the true top-level module map never makes it into the set of affecting module maps we compute in
ASTWriter
. It's in turn left out from theINPUT_FILE
block that only has the containing module map that's marked as not-top-level file. This ultimately breaks the dependency scanner. When generating-fmodule-map-file=
arguments for the explicit compilation, it only uses files that made it into theINPUT_FILE
block (are affecting) and are top-level (to avoid exploding the command line with transitive module maps). This then breaks the explicit compile, which doesn't have any (neither the top-level nor the containing module map) for the module in question.So this piece of code is here to ensure implicit builds are always invoked with the top-level module map, not the containing one. This fixes the walk over the include chain of loaded
SLocEntries
and fixesclang/test/ClangScanDeps/modules-extern-unrelated.m
.