Skip to content

Commit 65e94cd

Browse files
authored
Merge pull request swiftlang#69517 from apple/es-pkg-in-public
Add package name to public swiftinterface
2 parents a7f716f + 662e2cf commit 65e94cd

File tree

10 files changed

+22
-65
lines changed

10 files changed

+22
-65
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,25 +2742,6 @@ class ValueDecl : public Decl {
27422742
/// \c \@usableFromInline, \c \@inlinalbe, and \c \@_alwaysEmitIntoClient
27432743
bool isUsableFromInline() const;
27442744

2745-
/// Returns \c true if this value decl needs a special case handling for an
2746-
/// interface file.
2747-
///
2748-
/// One such case is a reference of an inlinable decl with a `package` access level
2749-
/// in an interface file as follows: Package decls are only printed in interface files if
2750-
/// they are inlinable (as defined in \c isUsableFromInline). They could be
2751-
/// referenced by a module outside of its defining module that belong to the same
2752-
/// package determined by the `package-name` flag. However, the flag is only in
2753-
/// .swiftmodule and .private.swiftinterface, thus type checking references of inlinable
2754-
/// package symbols in public interfaces fails due to the missing flag.
2755-
/// Instead of adding the package-name flag to the public interfaces, which
2756-
/// could raise a security concern, we grant access to such cases.
2757-
///
2758-
/// \sa useDC The use site where this value decl is referenced.
2759-
/// \sa useAcl The access level of its use site.
2760-
/// \sa declScope The access scope of this decl site.
2761-
bool skipAccessCheckIfInterface(const DeclContext *useDC, AccessLevel useAcl,
2762-
AccessScope declScope) const;
2763-
27642745
/// Returns \c true if this declaration is *not* intended to be used directly
27652746
/// by application developers despite the visibility.
27662747
bool shouldHideFromEditor() const;

include/swift/AST/Module.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ class PackageUnit: public DeclContext {
210210
/// Equality check via package name instead of pointer comparison.
211211
/// Returns false if the name is empty.
212212
bool isSamePackageAs(PackageUnit *other) {
213+
if (!other)
214+
return false;
213215
return !(getName().empty()) && getName() == other->getName();
214216
}
215217
};

include/swift/Option/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ def module_abi_name : Separate<["-"], "module-abi-name">,
548548
Flags<[FrontendOption, ModuleInterfaceOption]>,
549549
HelpText<"ABI name to use for the contents of this module">;
550550
def package_name : Separate<["-"], "package-name">,
551-
Flags<[FrontendOption, ModuleInterfaceOptionIgnorablePrivate]>,
551+
Flags<[FrontendOption, ModuleInterfaceOption]>,
552552
HelpText<"Name of the package the module belongs to">;
553553
def export_as : Separate<["-"], "export-as">,
554554
Flags<[FrontendOption, ModuleInterfaceOption]>,

lib/AST/Decl.cpp

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3952,17 +3952,6 @@ bool ValueDecl::isUsableFromInline() const {
39523952
return false;
39533953
}
39543954

3955-
bool ValueDecl::skipAccessCheckIfInterface(const DeclContext *useDC,
3956-
AccessLevel useAcl,
3957-
AccessScope declScope) const {
3958-
if (!useDC || useAcl != AccessLevel::Package || !declScope.isPackage() ||
3959-
!isUsableFromInline() ||
3960-
getDeclContext()->getParentModule() == useDC->getParentModule())
3961-
return false;
3962-
auto useSF = useDC->getParentSourceFile();
3963-
return useSF && useSF->Kind == SourceFileKind::Interface;
3964-
}
3965-
39663955
bool ValueDecl::shouldHideFromEditor() const {
39673956
// Hide private stdlib declarations.
39683957
if (isPrivateStdlibDecl(/*treatNonBuiltinProtocolsAsPublic*/ false) ||
@@ -4293,19 +4282,16 @@ static bool checkAccessUsingAccessScopes(const DeclContext *useDC,
42934282
AccessScope accessScope = getAccessScopeForFormalAccess(
42944283
VD, access, useDC,
42954284
/*treatUsableFromInlineAsPublic*/ includeInlineable);
4296-
if (accessScope.getDeclContext() == useDC) return true;
4297-
if (!AccessScope(useDC).isChildOf(accessScope)) {
4298-
// Grant access if this VD is an inlinable package decl referenced by
4299-
// another module in an interface file.
4300-
if (VD->skipAccessCheckIfInterface(useDC, access, accessScope))
4301-
return true;
4285+
if (accessScope.getDeclContext() == useDC)
4286+
return true;
4287+
if (!AccessScope(useDC).isChildOf(accessScope))
43024288
return false;
4303-
}
43044289
// useDC is null only when caller wants to skip non-public type checks.
4305-
if (!useDC) return true;
4306-
4290+
if (!useDC)
4291+
return true;
43074292
// Check SPI access
4308-
if (!VD->isSPI()) return true;
4293+
if (!VD->isSPI())
4294+
return true;
43094295
auto useSF = dyn_cast<SourceFile>(useDC->getModuleScopeContext());
43104296
return !useSF || useSF->isImportedAsSPI(VD) ||
43114297
VD->getDeclContext()->getParentModule() == useDC->getParentModule();
@@ -4426,14 +4412,6 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
44264412
return useSF && useSF->hasTestableOrPrivateImport(access, sourceModule);
44274413
}
44284414
case AccessLevel::Package: {
4429-
auto srcFile = sourceDC->getParentSourceFile();
4430-
4431-
// srcFile could be null if VD decl is from an imported .swiftmodule
4432-
if (srcFile && srcFile->Kind == SourceFileKind::Interface) {
4433-
// If source file is interface, package decls must be usableFromInline or
4434-
// inlinable, and are accessed only within the defining module so return true
4435-
return true;
4436-
}
44374415
auto srcPkg = sourceDC->getPackageContext(/*lookupIfNotCurrent*/ true);
44384416
auto usePkg = useDC->getPackageContext(/*lookupIfNotCurrent*/ true);
44394417
return srcPkg && usePkg && usePkg->isSamePackageAs(srcPkg);

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4435,10 +4435,6 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
44354435
requiredAccessScope.requiredAccessForDiagnostics();
44364436
auto proto = conformance->getProtocol();
44374437
auto protoAccessScope = proto->getFormalAccessScope(DC);
4438-
// Skip diagnostics of a witness of a package protocol that is inlinalbe
4439-
// referenced in an interface file.
4440-
if (proto->skipAccessCheckIfInterface(DC, requiredAccess, protoAccessScope))
4441-
return;
44424438
bool protoForcesAccess =
44434439
requiredAccessScope.hasEqualDeclContextWith(protoAccessScope);
44444440
auto diagKind = protoForcesAccess

test/ModuleInterface/lazy-typecheck.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@
77
// (1) Generate a baseline .swiftinterface and build a client against it.
88
// RUN: %target-swift-frontend -swift-version 5 %S/../Inputs/lazy_typecheck.swift -module-name lazy_typecheck -typecheck -emit-module-interface-path %t/baseline/lazy_typecheck.swiftinterface -enable-library-evolution -parse-as-library -package-name Package -DFLAG
99
// RUN: rm -rf %t/baseline/*.swiftmodule
10-
// RUN: %target-swift-frontend -package-name Package -typecheck -verify %S/../Inputs/lazy_typecheck_client.swift -I %t/baseline/
10+
// RUN: %target-swift-frontend -package-name ClientPackage -typecheck -verify %S/../Inputs/lazy_typecheck_client.swift -I %t/baseline/
1111

1212
// (2) Generate a .swiftinterface with -experimental-lazy-typecheck and build the client against it.
1313
// The .swiftinterface should be identical to the baseline and avoid triggering typechecking
1414
// for any "NoTypecheck" decls.
1515
// RUN: %target-swift-frontend -swift-version 5 %S/../Inputs/lazy_typecheck.swift -module-name lazy_typecheck -typecheck -emit-module-interface-path %t/lazy/lazy_typecheck.swiftinterface -enable-library-evolution -parse-as-library -package-name Package -DFLAG -debug-forbid-typecheck-prefix NoTypecheck -experimental-lazy-typecheck
1616
// RUN: rm -rf %t/lazy/*.swiftmodule
17-
// RUN: %target-swift-frontend -package-name Package -typecheck -verify %S/../Inputs/lazy_typecheck_client.swift -I %t/lazy
17+
// RUN: %target-swift-frontend -package-name ClientPackage -typecheck -verify %S/../Inputs/lazy_typecheck_client.swift -I %t/lazy
1818
// FIXME: The emitted interfaces should be identical
1919
// diff -u %t/baseline/lazy_typecheck.swiftinterface %t/lazy/lazy_typecheck.swiftinterface
2020

2121
// (3) Same as (2), but with -experimental-skip-all-function-bodies added.
2222
// RUN: %target-swift-frontend -swift-version 5 %S/../Inputs/lazy_typecheck.swift -module-name lazy_typecheck -typecheck -emit-module-interface-path %t/lazy-skip-all/lazy_typecheck.swiftinterface -enable-library-evolution -parse-as-library -package-name Package -DFLAG -debug-forbid-typecheck-prefix NoTypecheck -experimental-lazy-typecheck -experimental-skip-non-exportable-decls -experimental-skip-all-function-bodies
2323
// RUN: rm -rf %t/lazy-skip-all/*.swiftmodule
24-
// RUN: %target-swift-frontend -package-name Package -typecheck -verify %S/../Inputs/lazy_typecheck_client.swift -I %t/lazy-skip-all
24+
// RUN: %target-swift-frontend -package-name ClientPackage -typecheck -verify %S/../Inputs/lazy_typecheck_client.swift -I %t/lazy-skip-all
2525
// FIXME: The emitted interfaces should be identical
2626
// diff -u %t/baseline/lazy_typecheck.swiftinterface %t/lazy-skip-all/lazy_typecheck.swiftinterface
2727

2828
// (4) Same as (2), but with -experimental-skip-non-inlinable-function-bodies added.
2929
// RUN: %target-swift-frontend -swift-version 5 %S/../Inputs/lazy_typecheck.swift -module-name lazy_typecheck -typecheck -emit-module-interface-path %t/lazy-skip-non-inlinable/lazy_typecheck.swiftinterface -enable-library-evolution -parse-as-library -package-name Package -DFLAG -debug-forbid-typecheck-prefix NoTypecheck -experimental-lazy-typecheck -experimental-skip-non-inlinable-function-bodies
3030
// RUN: rm -rf %t/lazy-skip-non-inlinable/*.swiftmodule
31-
// RUN: %target-swift-frontend -package-name Package -typecheck -verify %S/../Inputs/lazy_typecheck_client.swift -I %t/lazy-skip-non-inlinable
31+
// RUN: %target-swift-frontend -package-name ClientPackage -typecheck -verify %S/../Inputs/lazy_typecheck_client.swift -I %t/lazy-skip-non-inlinable
3232
// FIXME: The emitted interfaces should be identical
3333
// diff -u %t/baseline/lazy_typecheck.swiftinterface %t/lazy-skip-non-inlinable/lazy_typecheck.swiftinterface
3434

test/Sema/accessibility_package_inline_interface.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// RUN: %target-swift-typecheck-module-from-interface(%t/Utils.swiftinterface) -I%t
1010

1111
// RUN: %FileCheck %s -check-prefix CHECK-UTILS < %t/Utils.swiftinterface
12-
// CHECK-UTILS-NOT: -package-name myLib
1312
// CHECK-UTILS: -module-name Utils
13+
// CHECK-UTILS: -package-name myLib
1414
// CHECK-UTILS: @usableFromInline
1515
// CHECK-UTILS: package class PackageKlassProto {
1616
// CHECK-UTILS: @usableFromInline

test/Sema/accessibility_package_interface.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
// RUN: %target-swift-typecheck-module-from-interface(%t/Utils.swiftinterface) -I %t
1313
// RUN: %FileCheck %s --check-prefix=CHECK-PUBLIC-UTILS < %t/Utils.swiftinterface
1414

15-
// CHECK-PUBLIC-UTILS-NOT: -package-name swift-utils.log
1615
// CHECK-PUBLIC-UTILS-NOT: package func packageFunc()
1716
// CHECK-PUBLIC-UTILS-NOT: package protocol PackageProto
1817
// CHECK-PUBLIC-UTILS-NOT: var pkgVar
1918
// CHECK-PUBLIC-UTILS-NOT: package class PackageKlass
2019
// CHECK-PUBLIC-UTILS-NOT: package var pkgVar
2120
// CHECK-PUBLIC-UTILS: -module-name Utils
21+
// CHECK-PUBLIC-UTILS: -package-name swift-utils.log
2222
// CHECK-PUBLIC-UTILS: public func publicFunc()
2323
// CHECK-PUBLIC-UTILS: @usableFromInline
2424
// CHECK-PUBLIC-UTILS: package func ufiPackageFunc()
@@ -39,7 +39,7 @@
3939
// CHECK-PRIVATE-UTILS-NOT: package class PackageKlass
4040
// CHECK-PRIVATE-UTILS-NOT: package var pkgVar
4141
// CHECK-PRIVATE-UTILS: -module-name Utils
42-
// CHECK-PRIVATE-UTILS: swift-module-flags-ignorable-private: -package-name swift-utils.log
42+
// CHECK-PRIVATE-UTILS: -package-name swift-utils.log
4343
// CHECK-PRIVATE-UTILS: public func publicFunc()
4444
// CHECK-PRIVATE-UTILS: @usableFromInline
4545
// CHECK-PRIVATE-UTILS: package func ufiPackageFunc()
@@ -64,7 +64,7 @@
6464

6565
// RUN: %target-swift-typecheck-module-from-interface(%t/Client.swiftinterface) -I %t -verify
6666
// RUN: %FileCheck %s --check-prefix=CHECK-PUBLIC-CLIENT < %t/Client.swiftinterface
67-
// CHECK-PUBLIC-CLIENT-NOT: -package-name swift-utils.log
67+
// CHECK-PUBLIC-CLIENT: -package-name swift-utils.log
6868
// CHECK-PUBLIC-CLIENT: @inlinable public func clientFunc()
6969
// CHECK-PUBLIC-CLIENT: publicFunc()
7070
// CHECK-PUBLIC-CLIENT: ufiPackageFunc()

test/Serialization/load_package_module.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
// RUN: %target-swift-typecheck-module-from-interface(%t/LibInterface.swiftinterface) -I %t
2020
// RUN: %FileCheck %s --check-prefix=CHECK-PUBLIC < %t/LibInterface.swiftinterface
2121
// CHECK-PUBLIC: -module-name LibInterface
22-
// CHECK-PUBLIC-NOT: -package-name
22+
// CHECK-PUBLIC: -package-name
2323

2424
// RUN: %target-swift-typecheck-module-from-interface(%t/LibInterface.private.swiftinterface) -module-name LibInterface -I %t
2525
// RUN: %FileCheck %s --check-prefix=CHECK-PRIVATE < %t/LibInterface.private.swiftinterface
26-
// CHECK-PRIVATE: swift-module-flags-ignorable-private: -package-name libPkg
26+
// CHECK-PRIVATE: -package-name libPkg
2727

2828
// RUN: not %target-swift-frontend -typecheck %t/ClientLoadInterface.swift -package-name otherPkg -I %t 2> %t/resultX.output
2929
// RUN: %FileCheck %s -check-prefix CHECK-X < %t/resultX.output

test/Serialization/module_package_name.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
// RUN: %target-swift-typecheck-module-from-interface(%t/Logging.swiftinterface) -I %t
1212
// RUN: %FileCheck %s --check-prefix=CHECK-PUBLIC < %t/Logging.swiftinterface
1313
// CHECK-PUBLIC: -module-name Logging
14-
// CHECK-PUBLIC-NOT: -package-name
14+
// CHECK-PUBLIC: -package-name
1515

1616
// RUN: %target-swift-typecheck-module-from-interface(%t/Logging.private.swiftinterface) -module-name Logging -I %t
1717
// RUN: %FileCheck %s --check-prefix=CHECK-PRIVATE < %t/Logging.private.swiftinterface
1818
// CHECK-PRIVATE: -module-name Logging
19-
// CHECK-PRIVATE: swift-module-flags-ignorable-private: -package-name MyLoggingPkg
19+
// CHECK-PRIVATE: -package-name MyLoggingPkg
2020

2121
//--- File.swift
2222
public func log(level: Int) {}

0 commit comments

Comments
 (0)