Skip to content

Commit 3496a74

Browse files
committed
[ModuleInterface] Print the public keyword on imports in Swift 6 mode
If the access-level on imports proposal is accepted as written, all imports printed in swiftinterfaces will be `public`. Whether or not we require the explicit `public` keyword in Swift 6 mode, printing it will have no downside. It also goes along with the mentality that swiftinterfaces should be more explicit than implicit. rdar://115455383
1 parent 33db186 commit 3496a74

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/Frontend/ModuleInterfaceSupport.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ static void printImports(raw_ostream &out,
348348
out << "@_spi(" << spiName << ") ";
349349
}
350350

351+
if (M->getASTContext().LangOpts.isSwiftVersionAtLeast(6)) {
352+
out << "public ";
353+
}
354+
351355
out << "import ";
352356
if (Opts.AliasModuleNames &&
353357
AliasModuleNamesTargets.contains(importedModule->getName().str()))

test/ModuleInterface/imports.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface) -I %S/Inputs/imports-clang-modules/ -I %t
66
// RUN: %FileCheck -implicit-check-not BAD %s < %t.swiftinterface
77

8+
/// Swift 6 variant.
9+
// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s %S/Inputs/imports-other.swift -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -I %S/Inputs/imports-clang-modules/ -I %t -verify -swift-version 6
10+
// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface) -I %S/Inputs/imports-clang-modules/ -I %t
11+
// RUN: %FileCheck -implicit-check-not BAD -check-prefix CHECK-6 %s < %t.swiftinterface
812

913
@_exported import empty // expected-warning {{module 'empty' was not compiled with library evolution support; using it means binary compatibility for 'imports' can't be guaranteed}}
1014
@_exported import emptyButWithLibraryEvolution
@@ -29,3 +33,17 @@ import NotSoSecret2 // expected-warning {{'NotSoSecret2' inconsistently imported
2933
// CHECK-NEXT: {{^}}@_exported import empty{{$}}
3034
// CHECK-NEXT: {{^}}@_exported import emptyButWithLibraryEvolution{{$}}
3135
// CHECK-NOT: import
36+
37+
// CHECK-6-NOT: import
38+
// CHECK-6: {{^}}public import A{{$}}
39+
// CHECK-6-NEXT: {{^}}public import B{{$}}
40+
// CHECK-6-NEXT: {{^}}public import B.B2{{$}}
41+
// CHECK-6-NEXT: {{^}}public import B.B3{{$}}
42+
// CHECK-6-NEXT: {{^}}public import C/*.c*/{{$}}
43+
// CHECK-6-NEXT: {{^}}public import D{{$}}
44+
// CHECK-6-NEXT: {{^}}public import NotSoSecret{{$}}
45+
// CHECK-6-NEXT: {{^}}public import NotSoSecret2{{$}}
46+
// CHECK-6-NEXT: {{^}}public import Swift{{$}}
47+
// CHECK-6-NEXT: {{^}}@_exported public import empty{{$}}
48+
// CHECK-6-NEXT: {{^}}@_exported public import emptyButWithLibraryEvolution{{$}}
49+
// CHECK-6-NOT: import

0 commit comments

Comments
 (0)