Skip to content

Commit daa134f

Browse files
authored
Merge pull request swiftlang#35427 from egorzhdan/sk-self-imports
SourceKit: avoid self-imports in generated Swift interfaces
2 parents 0bd17e4 + bce1f93 commit daa134f

7 files changed

+1337
-1381
lines changed

lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,9 @@ void swift::ide::printModuleInterface(
609609
auto ShouldPrintImport = [&](ImportDecl *ImportD) -> bool {
610610
if (!TargetClangMod)
611611
return true;
612+
if (ImportD->getModule() == TargetMod)
613+
return false;
614+
612615
auto ImportedMod = ImportD->getClangModule();
613616
if (!ImportedMod)
614617
return true;

test/IDE/print_ast_overlay.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ public class FooOverlayClassDerived : FooOverlayClassBase {
4141

4242
// PASS_NO_INTERNAL-NOT: overlay_func_internal
4343

44-
// PASS_ANNOTATED: <decl:Import>@_exported import <ref:module>Foo</ref></decl>
44+
// PASS_ANNOTATED-NOT: import Foo
4545
// PASS_ANNOTATED: <decl:Import>@_exported import <ref:module>Foo</ref>.<ref:module>FooSub</ref></decl>
4646
// PASS_ANNOTATED: <decl:Import>@_exported import <ref:module>FooHelper</ref></decl>

test/SourceKit/DocSupport/doc_cross_import_common.swift.OverlaidClangFramework.response

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import OverlaidClangFramework
21
import SwiftOnoneSupport
32

43
func fromOverlaidClangFramework()
@@ -21,61 +20,51 @@ func fromOverlaidClangFrameworkCrossImport()
2120
{
2221
key.kind: source.lang.swift.syntaxtype.identifier,
2322
key.offset: 7,
24-
key.length: 22
25-
},
26-
{
27-
key.kind: source.lang.swift.syntaxtype.keyword,
28-
key.offset: 30,
29-
key.length: 6
30-
},
31-
{
32-
key.kind: source.lang.swift.syntaxtype.identifier,
33-
key.offset: 37,
3423
key.length: 17
3524
},
3625
{
3726
key.kind: source.lang.swift.syntaxtype.keyword,
38-
key.offset: 56,
27+
key.offset: 26,
3928
key.length: 4
4029
},
4130
{
4231
key.kind: source.lang.swift.syntaxtype.identifier,
43-
key.offset: 61,
32+
key.offset: 31,
4433
key.length: 26
4534
},
4635
{
4736
key.kind: source.lang.swift.syntaxtype.keyword,
48-
key.offset: 90,
37+
key.offset: 60,
4938
key.length: 4
5039
},
5140
{
5241
key.kind: source.lang.swift.syntaxtype.identifier,
53-
key.offset: 95,
42+
key.offset: 65,
5443
key.length: 33
5544
},
5645
{
5746
key.kind: source.lang.swift.syntaxtype.comment,
58-
key.offset: 133,
47+
key.offset: 103,
5948
key.length: 39
6049
},
6150
{
6251
key.kind: source.lang.swift.syntaxtype.comment.mark,
63-
key.offset: 136,
52+
key.offset: 106,
6453
key.length: 35
6554
},
6655
{
6756
key.kind: source.lang.swift.syntaxtype.comment,
68-
key.offset: 174,
57+
key.offset: 144,
6958
key.length: 76
7059
},
7160
{
7261
key.kind: source.lang.swift.syntaxtype.keyword,
73-
key.offset: 250,
62+
key.offset: 220,
7463
key.length: 4
7564
},
7665
{
7766
key.kind: source.lang.swift.syntaxtype.identifier,
78-
key.offset: 255,
67+
key.offset: 225,
7968
key.length: 37
8069
}
8170
]
@@ -84,23 +73,23 @@ func fromOverlaidClangFrameworkCrossImport()
8473
key.kind: source.lang.swift.decl.function.free,
8574
key.name: "fromOverlaidClangFramework()",
8675
key.usr: "c:@F@fromOverlaidClangFramework",
87-
key.offset: 56,
76+
key.offset: 26,
8877
key.length: 33,
8978
key.fully_annotated_decl: "<decl.function.free><syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>fromOverlaidClangFramework</decl.name>()</decl.function.free>"
9079
},
9180
{
9281
key.kind: source.lang.swift.decl.function.free,
9382
key.name: "fromOverlaidClangFrameworkOverlay()",
9483
key.usr: "s:22OverlaidClangFramework04fromabC7OverlayyyF",
95-
key.offset: 90,
84+
key.offset: 60,
9685
key.length: 40,
9786
key.fully_annotated_decl: "<decl.function.free><syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>fromOverlaidClangFrameworkOverlay</decl.name>()</decl.function.free>"
9887
},
9988
{
10089
key.kind: source.lang.swift.decl.function.free,
10190
key.name: "fromOverlaidClangFrameworkCrossImport()",
10291
key.usr: "s:41_OverlaidClangFramework_BystandingLibrary04fromabC11CrossImportyyF",
103-
key.offset: 250,
92+
key.offset: 220,
10493
key.length: 44,
10594
key.fully_annotated_decl: "<decl.function.free><syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>fromOverlaidClangFrameworkCrossImport</decl.name>()</decl.function.free>",
10695
key.required_bystanders: [

test/SourceKit/InterfaceGen/gen_clang_module.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var x: FooClassBase
3131

3232
// RUN: %sourcekitd-test -req=interface-gen-open -module Foo -- -I %t.overlays -F %S/../Inputs/libIDE-mock-sdk \
3333
// RUN: -target %target-triple %clang-importer-sdk-nosource -I %t \
34-
// RUN: == -req=cursor -pos=205:67 | %FileCheck -check-prefix=CHECK1 %s
34+
// RUN: == -req=cursor -pos=204:67 | %FileCheck -check-prefix=CHECK1 %s
3535
// The cursor points to 'FooClassBase' inside the list of base classes, see 'gen_clang_module.swift.response'
3636

3737
// RUN: %sourcekitd-test -req=interface-gen-open -module Foo -- -I %t.overlays -F %S/../Inputs/libIDE-mock-sdk \
@@ -47,7 +47,7 @@ var x: FooClassBase
4747

4848
// RUN: %sourcekitd-test -req=interface-gen-open -module Foo -- -I %t.overlays -F %S/../Inputs/libIDE-mock-sdk \
4949
// RUN: -target %target-triple %clang-importer-sdk-nosource -I %t \
50-
// RUN: == -req=cursor -pos=232:20 | %FileCheck -check-prefix=CHECK2 %s
50+
// RUN: == -req=cursor -pos=231:20 | %FileCheck -check-prefix=CHECK2 %s
5151
// The cursor points inside the interface, see 'gen_clang_module.swift.response'
5252

5353
// CHECK2: source.lang.swift.decl.function.method.instance ({{.*}}Foo.framework/Headers/Foo.h:170:10-170:27)
@@ -61,7 +61,7 @@ var x: FooClassBase
6161
// RUN: == -req=find-usr -usr "c:objc(cs)FooClassDerived(im)fooInstanceFunc0" | %FileCheck -check-prefix=CHECK-USR %s
6262
// The returned line:col points inside the interface, see 'gen_clang_module.swift.response'
6363

64-
// CHECK-USR: (232:15-232:33)
64+
// CHECK-USR: (231:15-231:33)
6565

6666
// RUN: %sourcekitd-test -req=interface-gen-open -module Foo -- -I %t.overlays -F %S/../Inputs/libIDE-mock-sdk \
6767
// RUN: -target %target-triple %clang-importer-sdk-nosource -I %t \
@@ -73,14 +73,10 @@ var x: FooClassBase
7373

7474
// RUN: %sourcekitd-test -req=interface-gen-open -module Foo -- -I %t.overlays -F %S/../Inputs/libIDE-mock-sdk \
7575
// RUN: -target %target-triple %clang-importer-sdk-nosource -I %t \
76-
// RUN: == -req=cursor -pos=1:8 \
77-
// RUN: == -req=cursor -pos=2:8 == -req=cursor -pos=2:12 \
78-
// RUN: == -req=cursor -pos=3:8 | %FileCheck -check-prefix=CHECK-IMPORT %s
76+
// RUN: == -req=cursor -pos=1:8 == -req=cursor -pos=1:12 \
77+
// RUN: == -req=cursor -pos=2:8 | %FileCheck -check-prefix=CHECK-IMPORT %s
7978
// The cursors point to module names inside the imports, see 'gen_clang_module.swift.response'
8079

81-
// CHECK-IMPORT: source.lang.swift.ref.module ()
82-
// CHECK-IMPORT-NEXT: Foo{{$}}
83-
// CHECK-IMPORT-NEXT: Foo{{$}}
8480
// CHECK-IMPORT: source.lang.swift.ref.module ()
8581
// CHECK-IMPORT-NEXT: Foo{{$}}
8682
// CHECK-IMPORT-NEXT: Foo{{$}}

0 commit comments

Comments
 (0)