Skip to content

SourceKit: avoid self-imports in generated Swift interfaces #35427

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

Merged
merged 1 commit into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/IDE/ModuleInterfacePrinting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,9 @@ void swift::ide::printModuleInterface(
auto ShouldPrintImport = [&](ImportDecl *ImportD) -> bool {
if (!TargetClangMod)
return true;
if (ImportD->getModule() == TargetMod)
return false;

auto ImportedMod = ImportD->getClangModule();
if (!ImportedMod)
return true;
Expand Down
2 changes: 1 addition & 1 deletion test/IDE/print_ast_overlay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public class FooOverlayClassDerived : FooOverlayClassBase {

// PASS_NO_INTERNAL-NOT: overlay_func_internal

// PASS_ANNOTATED: <decl:Import>@_exported import <ref:module>Foo</ref></decl>
// PASS_ANNOTATED-NOT: import Foo
// PASS_ANNOTATED: <decl:Import>@_exported import <ref:module>Foo</ref>.<ref:module>FooSub</ref></decl>
// PASS_ANNOTATED: <decl:Import>@_exported import <ref:module>FooHelper</ref></decl>
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import OverlaidClangFramework
import SwiftOnoneSupport

func fromOverlaidClangFramework()
Expand All @@ -21,61 +20,51 @@ func fromOverlaidClangFrameworkCrossImport()
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 7,
key.length: 22
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 30,
key.length: 6
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 37,
key.length: 17
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 56,
key.offset: 26,
key.length: 4
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 61,
key.offset: 31,
key.length: 26
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 90,
key.offset: 60,
key.length: 4
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 95,
key.offset: 65,
key.length: 33
},
{
key.kind: source.lang.swift.syntaxtype.comment,
key.offset: 133,
key.offset: 103,
key.length: 39
},
{
key.kind: source.lang.swift.syntaxtype.comment.mark,
key.offset: 136,
key.offset: 106,
key.length: 35
},
{
key.kind: source.lang.swift.syntaxtype.comment,
key.offset: 174,
key.offset: 144,
key.length: 76
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 250,
key.offset: 220,
key.length: 4
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 255,
key.offset: 225,
key.length: 37
}
]
Expand All @@ -84,23 +73,23 @@ func fromOverlaidClangFrameworkCrossImport()
key.kind: source.lang.swift.decl.function.free,
key.name: "fromOverlaidClangFramework()",
key.usr: "c:@F@fromOverlaidClangFramework",
key.offset: 56,
key.offset: 26,
key.length: 33,
key.fully_annotated_decl: "<decl.function.free><syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>fromOverlaidClangFramework</decl.name>()</decl.function.free>"
},
{
key.kind: source.lang.swift.decl.function.free,
key.name: "fromOverlaidClangFrameworkOverlay()",
key.usr: "s:22OverlaidClangFramework04fromabC7OverlayyyF",
key.offset: 90,
key.offset: 60,
key.length: 40,
key.fully_annotated_decl: "<decl.function.free><syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>fromOverlaidClangFrameworkOverlay</decl.name>()</decl.function.free>"
},
{
key.kind: source.lang.swift.decl.function.free,
key.name: "fromOverlaidClangFrameworkCrossImport()",
key.usr: "s:41_OverlaidClangFramework_BystandingLibrary04fromabC11CrossImportyyF",
key.offset: 250,
key.offset: 220,
key.length: 44,
key.fully_annotated_decl: "<decl.function.free><syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>fromOverlaidClangFrameworkCrossImport</decl.name>()</decl.function.free>",
key.required_bystanders: [
Expand Down
14 changes: 5 additions & 9 deletions test/SourceKit/InterfaceGen/gen_clang_module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var x: FooClassBase

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

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

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

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

// CHECK-USR: (232:15-232:33)
// CHECK-USR: (231:15-231:33)

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

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

// CHECK-IMPORT: source.lang.swift.ref.module ()
// CHECK-IMPORT-NEXT: Foo{{$}}
// CHECK-IMPORT-NEXT: Foo{{$}}
// CHECK-IMPORT: source.lang.swift.ref.module ()
// CHECK-IMPORT-NEXT: Foo{{$}}
// CHECK-IMPORT-NEXT: Foo{{$}}
Expand Down
Loading