Skip to content

Commit a7c535b

Browse files
committed
[modules] Change module manager visitation order to be a bit more stable when
more modules are added: visit modules depth-first rather than breadth-first. The visitation is still (approximately) oldest-to-newest, and still guarantees that a module is visited before anything it imports, so modules that are imported by others sometimes need to jump to a later position in the visitation order when more modules are loaded, but independent module trees don't interfere with each other any more. llvm-svn: 242863
1 parent f8e102d commit a7c535b

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

clang/lib/Serialization/ModuleManager.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -316,28 +316,24 @@ ModuleManager::visit(bool (*Visitor)(ModuleFile &M, void *UserData),
316316
SmallVector<ModuleFile *, 4> Queue;
317317
Queue.reserve(N);
318318
llvm::SmallVector<unsigned, 4> UnusedIncomingEdges;
319-
UnusedIncomingEdges.reserve(size());
320-
for (ModuleIterator M = begin(), MEnd = end(); M != MEnd; ++M) {
321-
if (unsigned Size = (*M)->ImportedBy.size())
322-
UnusedIncomingEdges.push_back(Size);
323-
else {
324-
UnusedIncomingEdges.push_back(0);
319+
UnusedIncomingEdges.resize(size());
320+
for (auto M = rbegin(), MEnd = rend(); M != MEnd; ++M) {
321+
unsigned Size = (*M)->ImportedBy.size();
322+
UnusedIncomingEdges[(*M)->Index] = Size;
323+
if (!Size)
325324
Queue.push_back(*M);
326-
}
327325
}
328326

329327
// Traverse the graph, making sure to visit a module before visiting any
330328
// of its dependencies.
331-
unsigned QueueStart = 0;
332-
while (QueueStart < Queue.size()) {
333-
ModuleFile *CurrentModule = Queue[QueueStart++];
329+
while (!Queue.empty()) {
330+
ModuleFile *CurrentModule = Queue.pop_back_val();
334331
VisitOrder.push_back(CurrentModule);
335332

336333
// For any module that this module depends on, push it on the
337334
// stack (if it hasn't already been marked as visited).
338-
for (llvm::SetVector<ModuleFile *>::iterator
339-
M = CurrentModule->Imports.begin(),
340-
MEnd = CurrentModule->Imports.end();
335+
for (auto M = CurrentModule->Imports.rbegin(),
336+
MEnd = CurrentModule->Imports.rend();
341337
M != MEnd; ++M) {
342338
// Remove our current module as an impediment to visiting the
343339
// module we depend on. If we were the last unvisited module

clang/test/Modules/macros.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: rm -rf %t
22
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s
3+
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s -DALT
34
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s -detailed-preprocessing-record
45
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -DLOCAL_VISIBILITY -fmodules-local-submodule-visibility -x objective-c++ -verify -fmodules-cache-path=%t -I %S/Inputs %s
56
// RUN: not %clang_cc1 -E -fmodules -fimplicit-module-maps -x objective-c -fmodules-cache-path=%t -I %S/Inputs %s | FileCheck -check-prefix CHECK-PREPROCESSED %s
@@ -157,6 +158,10 @@ int TOP_DEF_RIGHT_UNDEF; // ok, no longer defined
157158
# endif
158159
#endif
159160

161+
#ifdef ALT
162+
int tmp = TOP_OTHER_REDEF1;
163+
#endif
164+
160165
@import macros_other;
161166

162167
#ifndef TOP_OTHER_UNDEF1
@@ -166,13 +171,13 @@ int TOP_DEF_RIGHT_UNDEF; // ok, no longer defined
166171
#ifndef TOP_OTHER_UNDEF2
167172
# error TOP_OTHER_UNDEF2 should still be defined
168173
#endif
169-
174+
#pragma clang __debug macro TOP_OTHER_REDEF1
170175
#ifndef TOP_OTHER_REDEF1
171176
# error TOP_OTHER_REDEF1 should still be defined
172177
#endif
173178
int n1 = TOP_OTHER_REDEF1; // expected-warning{{ambiguous expansion of macro 'TOP_OTHER_REDEF1'}}
174-
// expected-note@macros_top.h:19 {{expanding this definition}}
175-
// expected-note@macros_other.h:4 {{other definition}}
179+
// expected-note@macros_other.h:4 {{expanding this definition}}
180+
// expected-note@macros_top.h:19 {{other definition}}
176181

177182
#ifndef TOP_OTHER_REDEF2
178183
# error TOP_OTHER_REDEF2 should still be defined

0 commit comments

Comments
 (0)