Skip to content

Commit 34322fc

Browse files
authored
Merge pull request #68587 from xymus/print-public-5.10
[5.10] ModuleInterface: prepare to accept access-level on imports in swiftinterfaces
2 parents ecfac0b + b24e5f1 commit 34322fc

File tree

5 files changed

+67
-8
lines changed

5 files changed

+67
-8
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()))

lib/Sema/TypeCheckAttr.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,8 @@ void AttributeChecker::visitLazyAttr(LazyAttr *attr) {
968968

969969
bool AttributeChecker::visitAbstractAccessControlAttr(
970970
AbstractAccessControlAttr *attr) {
971-
// Access control attr may only be used on value decls and extensions.
971+
// Access control attr may only be used on value decls, extensions and
972+
// imports.
972973
if (!isa<ValueDecl>(D) && !isa<ExtensionDecl>(D) && !isa<ImportDecl>(D)) {
973974
diagnoseAndRemoveAttr(attr, diag::invalid_decl_modifier, attr);
974975
return true;
@@ -996,7 +997,9 @@ bool AttributeChecker::visitAbstractAccessControlAttr(
996997
}
997998

998999
if (auto importDecl = dyn_cast<ImportDecl>(D)) {
999-
if (!D->getASTContext().LangOpts.hasFeature(Feature::AccessLevelOnImport)) {
1000+
SourceFile *File = D->getDeclContext()->getParentSourceFile();
1001+
if (!D->getASTContext().LangOpts.hasFeature(Feature::AccessLevelOnImport) &&
1002+
File && File->Kind != SourceFileKind::Interface) {
10001003
diagnoseAndRemoveAttr(attr, diag::access_level_on_import_not_enabled);
10011004
return true;
10021005
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/// Swift 6 variant to imports.swift. Both can be reintegrated once
2+
/// -swift-version 6 is accepted by release compilers.
3+
// REQUIRES: asserts
4+
5+
// RUN: %empty-directory(%t)
6+
// RUN: %target-swift-frontend -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -emit-module -o %t/empty.swiftmodule %S/../Inputs/empty.swift
7+
// RUN: %target-swift-frontend -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -emit-module -o %t/emptyButWithLibraryEvolution.swiftmodule %S/../Inputs/empty.swift -enable-library-evolution
8+
9+
/// Swift 6 variant.
10+
// 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
11+
// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface) -I %S/Inputs/imports-clang-modules/ -I %t
12+
// RUN: %FileCheck -implicit-check-not BAD -check-prefix CHECK-6 %s < %t.swiftinterface
13+
14+
@_exported import empty // expected-warning {{module 'empty' was not compiled with library evolution support; using it means binary compatibility for 'main' can't be guaranteed}}
15+
@_exported import emptyButWithLibraryEvolution
16+
import B.B2
17+
import func C.c // expected-warning {{scoped imports are not yet supported in module interfaces}}
18+
import D
19+
@_implementationOnly import Secret_BAD
20+
21+
@_implementationOnly import NotSoSecret // expected-note {{imported as implementation-only here}}
22+
import NotSoSecret2 // expected-warning {{'NotSoSecret2' inconsistently imported as implementation-only}}
23+
24+
// CHECK-6-NOT: import
25+
// CHECK-6: {{^}}public import A{{$}}
26+
// CHECK-6-NEXT: {{^}}public import B{{$}}
27+
// CHECK-6-NEXT: {{^}}public import B.B2{{$}}
28+
// CHECK-6-NEXT: {{^}}public import B.B3{{$}}
29+
// CHECK-6-NEXT: {{^}}public import C/*.c*/{{$}}
30+
// CHECK-6-NEXT: {{^}}public import D{{$}}
31+
// CHECK-6-NEXT: {{^}}public import NotSoSecret{{$}}
32+
// CHECK-6-NEXT: {{^}}public import NotSoSecret2{{$}}
33+
// CHECK-6-NEXT: {{^}}public import Swift{{$}}
34+
// CHECK-6-NEXT: {{^}}@_exported public import empty{{$}}
35+
// CHECK-6-NEXT: {{^}}@_exported public import emptyButWithLibraryEvolution{{$}}
36+
// CHECK-6-NOT: import

test/ModuleInterface/imports.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
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-
98
@_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}}
109
@_exported import emptyButWithLibraryEvolution
1110
import B.B2

test/Sema/access-level-import-flag-check.swift

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
// RUN: split-file %s %t
33

44
/// Build the libraries.
5-
// RUN: %target-swift-frontend -emit-module %t/PublicLib.swift -o %t
6-
// RUN: %target-swift-frontend -emit-module %t/PackageLib.swift -o %t
7-
// RUN: %target-swift-frontend -emit-module %t/InternalLib.swift -o %t
8-
// RUN: %target-swift-frontend -emit-module %t/FileprivateLib.swift -o %t
9-
// RUN: %target-swift-frontend -emit-module %t/PrivateLib.swift -o %t
5+
// RUN: %target-swift-frontend -emit-module %t/PublicLib.swift -o %t \
6+
// RUN: -enable-library-evolution
7+
// RUN: %target-swift-frontend -emit-module %t/PackageLib.swift -o %t \
8+
// RUN: -enable-library-evolution
9+
// RUN: %target-swift-frontend -emit-module %t/InternalLib.swift -o %t \
10+
// RUN: -enable-library-evolution
11+
// RUN: %target-swift-frontend -emit-module %t/FileprivateLib.swift -o %t \
12+
// RUN: -enable-library-evolution
13+
// RUN: %target-swift-frontend -emit-module %t/PrivateLib.swift -o %t \
14+
// RUN: -enable-library-evolution
1015

1116
/// Check flag requirement, without and with the flag.
1217
// RUN: %target-swift-frontend -typecheck %t/ClientWithoutTheFlag.swift -I %t -verify \
@@ -16,6 +21,9 @@
1621
// RUN: -package-name package
1722
// REQUIRES: asserts
1823

24+
/// swiftinterfaces don't need the flag.
25+
// RUN: %target-swift-typecheck-module-from-interface(%t/Client.swiftinterface) -I %t
26+
1927
//--- PublicLib.swift
2028
//--- PackageLib.swift
2129
//--- InternalLib.swift
@@ -28,3 +36,12 @@ package import PackageLib // expected-error@:1 {{Access level on imports require
2836
internal import InternalLib // expected-error@:1 {{Access level on imports require '-enable-experimental-feature AccessLevelOnImport'}}
2937
fileprivate import FileprivateLib // expected-error@:1 {{Access level on imports require '-enable-experimental-feature AccessLevelOnImport'}}
3038
private import PrivateLib // expected-error@:1 {{Access level on imports require '-enable-experimental-feature AccessLevelOnImport'}}
39+
40+
//--- Client.swiftinterface
41+
// swift-interface-format-version: 1.0
42+
// swift-module-flags: -enable-library-evolution -package-name MyPackage
43+
public import PublicLib
44+
package import PackageLib
45+
internal import InternalLib
46+
fileprivate import FileprivateLib
47+
private import PrivateLib

0 commit comments

Comments
 (0)