-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[ASTWriter] Do not allocate source location space for module maps used only for textual headers #116374
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
[ASTWriter] Do not allocate source location space for module maps used only for textual headers #116374
Changes from 2 commits
ff328f2
e0a1835
5611185
9cad088
441efe6
8899db3
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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -184,14 +184,30 @@ GetAffectingModuleMaps(const Preprocessor &PP, Module *RootModule) { | |||||||||||||
| const SourceManager &SM = PP.getSourceManager(); | ||||||||||||||
| const ModuleMap &MM = HS.getModuleMap(); | ||||||||||||||
|
|
||||||||||||||
| llvm::DenseSet<FileID> ModuleMaps; | ||||||||||||||
|
|
||||||||||||||
| llvm::DenseSet<const Module *> ProcessedModules; | ||||||||||||||
| auto CollectModuleMapsForHierarchy = [&](const Module *M) { | ||||||||||||||
| // Module maps used only by textual headers are special. Their FileID is | ||||||||||||||
| // non-affecting, but their FileEntry is (i.e. must be written as InputFile). | ||||||||||||||
| enum AffectedReason : bool { | ||||||||||||||
| ARTextualHeader = 0, | ||||||||||||||
| ARImportOrTextualHeader = 1, | ||||||||||||||
| }; | ||||||||||||||
| auto AssignMostImportant = [](AffectedReason &L, AffectedReason R) { | ||||||||||||||
| L = std::max(L, R); | ||||||||||||||
| }; | ||||||||||||||
|
||||||||||||||
| auto AssignMostImportant = [](AffectedReason &L, AffectedReason R) { | |
| L = std::max(L, R); | |
| }; | |
| auto AssignMostImportant = [](AffectedReason &LHS, AffectedReason RHS) { | |
| LHS = std::max(LHS, RHS); | |
| }; |
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.
I've updated to use LHS and RHS. However, I actually wanted to argue that L and R are better choices for small functions. I have found that because of the HS suffix, it is actually easier to confuse the two and misread the code.
It usually does not matter, but if there's an error, it becomes harder to spot, e.g.
LHS.a < RHS.a && LHS.b < RHS.b && LHS.c < LHS.c && LHS.d < RHS.dvs
L.a < R.a && L.b < R.b && L.c < L.c && L.d < R.dAt least for me, the second variant stands out much more clearly.
That's the reason why I started using this pattern instead of the more common LHS and RHS.
ilya-biryukov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
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.
Avoid else after return.
| } else { | |
| It->second = Reason; | |
| } | |
| } | |
| It->second = Reason; |
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.
I cannot in that case, because It is only valid for the scope of the if.
Increasing the visibility scope of It seems like a worse trade-off. But let me know if you have other suggestions how to rewrite the code better, I might be missing some ideas.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| // Same as prune-non-affecting-module-map-repeated.cpp, but check that textual-only | ||
| // inclusions do not cause duplication of the module map files they are defined in. | ||
|
|
||
| // RUN: rm -rf %t && mkdir %t | ||
| // RUN: split-file %s %t | ||
|
|
||
| // RUN: %clang_cc1 -xc++ -fmodules -fno-implicit-modules \ | ||
| // RUN: -fmodule-map-file=%t/base.map -fmodule-map-file=%t/mixed.map\ | ||
| // RUN: -fmodule-map-file=%t/mod1.map \ | ||
| // RUN: -fmodule-name=mod1 -emit-module %t/mod1.map -o %t/mod1.pcm | ||
| // RUN: %clang_cc1 -xc++ -fmodules -fno-implicit-modules \ | ||
| // RUN: -fmodule-map-file=%t/mixed.map\ | ||
| // RUN: -fmodule-name=mixed -emit-module %t/mixed.map -o %t/mixed.pcm | ||
| // RUN: %clang_cc1 -xc++ -fmodules -fno-implicit-modules \ | ||
| // RUN: -fmodule-map-file=%t/base.map -fmodule-map-file=%t/mod1.map -fmodule-map-file=%t/mod2.map \ | ||
| // RUN: -fmodule-file=%t/mod1.pcm -fmodule-file=%t/mixed.pcm \ | ||
| // RUN: -fmodule-name=mod2 -emit-module %t/mod2.map -o %t/mod2.pcm | ||
| // RUN: %clang_cc1 -xc++ -fmodules -fno-implicit-modules \ | ||
| // RUN: -fmodule-map-file=%t/base.map -fmodule-map-file=%t/mod2.map -fmodule-map-file=%t/mod3.map \ | ||
| // RUN: -fmodule-file=%t/mod2.pcm -fmodule-file=%t/mixed.pcm \ | ||
| // RUN: -fmodule-name=mod3 -emit-module %t/mod3.map -o %t/mod3.pcm | ||
| // RUN: %clang_cc1 -xc++ -fmodules -fno-implicit-modules \ | ||
| // RUN: -fmodule-map-file=%t/base.map -fmodule-map-file=%t/mod3.map -fmodule-map-file=%t/mod4.map \ | ||
| // RUN: -fmodule-file=%t/mod3.pcm \ | ||
| // RUN: -fmodule-name=mod4 -emit-module %t/mod4.map -o %t/mod4.pcm | ||
| // RUN: %clang_cc1 -xc++ -fmodules -fno-implicit-modules -fmodule-map-file=%t/base.map -fmodule-map-file=%t/mod4.map -fmodule-file=%t/mod4.pcm -fsyntax-only -verify %t/check_slocs.cc | ||
|
|
||
| //--- base.map | ||
| module base { textual header "vector.h" } | ||
| //--- mixed.map | ||
| module mixed { textual header "mixed_text.h" header "mixed_mod.h"} | ||
| //--- mod1.map | ||
| module mod1 { header "mod1.h" } | ||
| //--- mod2.map | ||
| module mod2 { header "mod2.h" } | ||
| //--- mod3.map | ||
| module mod3 { header "mod3.h" } | ||
| //--- mod4.map | ||
| module mod4 { header "mod4.h" } | ||
| //--- check_slocs.cc | ||
| #include "mod4.h" | ||
| #include "vector.h" | ||
| #pragma clang __debug sloc_usage // expected-remark {{source manager location address space usage}} | ||
| // expected-note@* {{% of available space}} | ||
|
|
||
| // base.map must only be present once, despite being used in each module. | ||
| // Because its location in every module compile should be non-affecting. | ||
|
|
||
| // [email protected]:1 {{file entered 1 time}} | ||
|
|
||
| // different modules use either only textual header from mixed.map or both textual and modular | ||
| // headers. Either combination must lead to only 1 use at the end, because the module is ultimately | ||
| // in the import chain and any textual uses should not change that. | ||
|
|
||
| // [email protected]:1 {{file entered 1 time}} | ||
|
|
||
| // expected-note@* + {{file entered}} | ||
|
|
||
|
|
||
| //--- vector.h | ||
| #ifndef VECTOR_H | ||
| #define VECTOR_H | ||
| #endif | ||
|
|
||
| //--- mixed_text.h | ||
| #ifndef MIXED_TEXT_H | ||
| #define MIXED_TEXT_H | ||
| #endif | ||
| //--- mixed_mod.h | ||
| #ifndef MIXED_MOD_H | ||
| #define MIXED_MOD_H | ||
| #endif | ||
|
|
||
| //--- mod1.h | ||
| #ifndef MOD1 | ||
| #define MOD1 | ||
| #include "vector.h" | ||
| #include "mixed_text.h" | ||
| int mod1(); | ||
| #endif | ||
| //--- mod2.h | ||
| #ifndef MOD2 | ||
| #define MOD2 | ||
| #include "vector.h" | ||
| #include "mod1.h" | ||
| #include "mixed_mod.h" | ||
| int mod2(); | ||
| #endif | ||
| //--- mod3.h | ||
| #ifndef MOD3 | ||
| #define MOD3 | ||
| #include "vector.h" | ||
| #include "mod2.h" | ||
| #include "mixed_text.h" | ||
| #include "mixed_mod.h" | ||
| int mod3(); | ||
| #endif | ||
| //--- mod4.h | ||
| #ifndef MOD4 | ||
| #define MOD4 | ||
| #include "vector.h" | ||
| #include "mod3.h" | ||
| int mod4(); | ||
| #endif |
Uh oh!
There was an error while loading. Please reload this page.