Skip to content

Commit a568102

Browse files
committed
[IDE] Print imports of submodules from other TLMs
We previously excluded all submodule imports when printing the module interface, to avoid inheriting incidental imports of other submodules as an artifact of clang submodules collectively being imported into the top level module. This also excluded explicit imports of submodules however. This change includes imports of submodules from another top level module in the module interface. "Real" imports of other submodules under the same top level module are unfortunately still excluded.
1 parent 9fad85c commit a568102

File tree

6 files changed

+20
-2
lines changed

6 files changed

+20
-2
lines changed

lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ static bool shouldPrintImport(ImportDecl *ImportD, ModuleDecl *OrigMod,
348348
return true;
349349
if (ImportedClangMod == OrigClangMod)
350350
return false;
351+
// We don't want to print modules that just happen to be part of our TLM,
352+
// but submodules from other TLMs should still be included
353+
if (!ImportedClangMod->isSubModuleOf(OrigClangMod->getTopLevelModule()))
354+
return true;
351355
return ImportedClangMod->isSubModuleOf(OrigClangMod);
352356
}
353357

test/Interop/C/swiftify-import/clang-includes-aliasing-imports.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ typedef int aliasing4_t;
8686
#include "Aliasing3.h"
8787
#include "Aliasing4.h"
8888

89-
// CHECK-A2-NOT: import
89+
// CHECK-A2: import A3.Aliasing
90+
// CHECK-A2: import A4.Aliasing
9091

9192
#define __sized_by(s) __attribute__((__sized_by__(s)))
9293

test/Interop/C/swiftify-import/clang-includes-indirect-explicit-modules.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ typedef int d1_t;
8686
#include "C1.h"
8787
#include "D1.h"
8888

89-
// CHECK-B2-NOT: import
89+
// CHECK-B2: import A1.B1
90+
// CHECK-B2: import A1.B1.C1
91+
// CHECK-B2: import A1.B1.C1.D1
9092

9193
b1_t b2b(void * _Nonnull __sized_by(size), int size);
9294
c1_t b2c(void * _Nonnull __sized_by(size), int size);

test/Interop/C/swiftify-import/clang-includes-noexport.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import ClangIncludesNoExportModule
1010

1111
// CHECK: import ModuleA
1212
// CHECK-NEXT: import ModuleB
13+
// CHECK-NEXT: import ModuleDeep.ModuleDeepNested.ModuleDeepNestedNested
14+
// CHECK-NEXT: import ModuleOuter.ModuleC
15+
// CHECK-NEXT: import ModuleOuter.ModuleD
1316
// CHECK-NOT: import
1417
// CHECK-EMPTY:
1518

test/Interop/C/swiftify-import/clang-includes-redundant-imports.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ typedef int g1_t;
179179
#include "D1.h"
180180

181181
// CHECK-B2: import A1
182+
// CHECK-B2: import A1.B1
183+
// CHECK-B2: import A1.B1.C1
184+
// CHECK-B2: import A1.B1.C1.D1
182185
// CHECK-B2: import A2.B2.C2
183186

184187

@@ -192,6 +195,8 @@ c2_t b2_2(void * _Nonnull __sized_by(size), int size);
192195
#include "B1.h"
193196
#include "C1.h"
194197

198+
// CHECK-C2: import A1.B1
199+
// CHECK-C2: import A1.B1.C1
195200
// CHECK-C2: @_exported import A2.B2.C2.D2
196201

197202
typedef int c2_t;

test/Interop/C/swiftify-import/clang-includes.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import ClangIncludesModule
1010

1111
// CHECK: @_exported import ModuleA
1212
// CHECK-NEXT: @_exported import ModuleB
13+
// CHECK-NEXT: @_exported import ModuleDeep.ModuleDeepNested.ModuleDeepNestedNested
14+
// CHECK-NEXT: @_exported import ModuleOuter.ModuleC
15+
// CHECK-NEXT: @_exported import ModuleOuter.ModuleD
1316
// CHECK-NOT: import
1417
// CHECK-EMPTY:
1518

0 commit comments

Comments
 (0)