Skip to content

Commit e7f9433

Browse files
committed
s/treatAsPublic/hasEffectivelyPublicAccess.
Update tests.
1 parent 3ab011e commit e7f9433

File tree

6 files changed

+24
-15
lines changed

6 files changed

+24
-15
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2973,13 +2973,13 @@ class ValueDecl : public Decl {
29732973
/// \c \@usableFromInline, \c \@inlinalbe, and \c \@_alwaysEmitIntoClient
29742974
bool isUsableFromInline() const;
29752975

2976-
/// Treat as public and allow skipping type check if the following conditions
2976+
/// Treat as public and allow skipping access checks if the following conditions
29772977
/// are met:
2978-
/// - This decl has a package access level.
2979-
/// - Has a @usableFromInline (or other inlinable) attribute
2978+
/// - This decl has a package access level,
2979+
/// - Has a @usableFromInline (or other inlinable) attribute,
29802980
/// - And is defined in a module built from a public or private
29812981
/// interface that does not contain package-name.
2982-
bool treatAsPublic() const;
2982+
bool hasEffectivelyPublicAccess() const;
29832983

29842984
/// Returns \c true if this declaration is *not* intended to be used directly
29852985
/// by application developers despite the visibility.

lib/AST/ASTVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ class Verifier : public ASTWalker {
10161016
if (!D->getASTContext().isAccessControlDisabled()) {
10171017
if (D->getFormalAccessScope().isPublic() &&
10181018
D->getFormalAccess() < AccessLevel::Public &&
1019-
!D->treatAsPublic()) {
1019+
!D->hasEffectivelyPublicAccess()) {
10201020
Out << "non-public decl has no formal access scope\n";
10211021
D->dump(Out);
10221022
abort();

lib/AST/Decl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4212,7 +4212,7 @@ bool ValueDecl::isUsableFromInline() const {
42124212
return false;
42134213
}
42144214

4215-
bool ValueDecl::treatAsPublic() const {
4215+
bool ValueDecl::hasEffectivelyPublicAccess() const {
42164216
// If a package decl has a @usableFromInline (or other inlinable)
42174217
// attribute, and is defined in a module built from interface, it
42184218
// can be referenced by another module that imports it even though
@@ -4319,7 +4319,7 @@ static AccessLevel getAdjustedFormalAccess(const ValueDecl *VD,
43194319
if (useDC && VD->getASTContext().isAccessControlDisabled())
43204320
return getMaximallyOpenAccessFor(VD);
43214321

4322-
if (VD->treatAsPublic())
4322+
if (VD->hasEffectivelyPublicAccess())
43234323
return AccessLevel::Public;
43244324

43254325
if (treatUsableFromInlineAsPublic &&
@@ -4504,7 +4504,7 @@ getAccessScopeForFormalAccess(const ValueDecl *VD,
45044504
case AccessLevel::Package: {
45054505
auto pkg = resultDC->getPackageContext(/*lookupIfNotCurrent*/ true);
45064506
if (!pkg) {
4507-
if (VD->treatAsPublic())
4507+
if (VD->hasEffectivelyPublicAccess())
45084508
return AccessScope::getPublic();
45094509
// Instead of reporting and failing early, return the scope of resultDC to
45104510
// allow continuation (should still non-zero exit later if in script mode)
@@ -4641,7 +4641,7 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
46414641
if (VD->getASTContext().isAccessControlDisabled())
46424642
return true;
46434643

4644-
if (VD->treatAsPublic())
4644+
if (VD->hasEffectivelyPublicAccess())
46454645
return true;
46464646

46474647
auto access = getAccessLevel();

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4277,7 +4277,7 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
42774277
requiredAccessScope.requiredAccessForDiagnostics();
42784278
auto proto = conformance->getProtocol();
42794279
auto protoAccessScope = proto->getFormalAccessScope(DC);
4280-
if (proto->treatAsPublic())
4280+
if (proto->hasEffectivelyPublicAccess())
42814281
return;
42824282

42834283
bool protoForcesAccess =

test/ModuleInterface/package_interface_disable_package_name.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@
2828
/// Verify building modules from non-package interfaces succeeds without the package-name flag.
2929
// RUN: %target-swift-frontend -compile-module-from-interface %t/Bar.swiftinterface -o %t/Bar.swiftmodule -module-name Bar
3030
// RUN: %target-swift-frontend -typecheck %t/Use.swift -I %t -verify
31+
// RUN: %target-swift-frontend -typecheck %t/Use.swift -I %t -package-name barpkg -verify
3132

3233
// RUN: rm -rf %t/Bar.swiftmodule
3334
// RUN: %target-swift-frontend -compile-module-from-interface %t/Bar.private.swiftinterface -o %t/Bar.swiftmodule -module-name Bar
3435
// RUN: %target-swift-frontend -typecheck %t/Use.swift -I %t -verify
36+
// RUN: %target-swift-frontend -typecheck %t/Use.swift -I %t -package-name barpkg -verify
3537

3638
// RUN: rm -rf %t/Bar.swiftmodule
3739
// RUN: %target-swift-frontend -compile-module-from-interface %t/Bar.package.swiftinterface -o %t/Bar.swiftmodule -module-name Bar
38-
// RUN: %target-swift-frontend -typecheck %t/Use.swift -I %t -verify
40+
// RUN: %target-swift-frontend -typecheck %t/Use.swift -I %t -package-name barpkg -experimental-package-interface-load -verify
3941

4042
// RUN: rm -rf %t/Bar.swiftmodule
4143
// RUN: rm -rf %t/Bar.swiftinterface
@@ -58,15 +60,15 @@
5860

5961
/// Building modules from non-package interfaces with package-name (default mode) should succeed.
6062
// RUN: %target-swift-frontend -compile-module-from-interface %t/Bar.swiftinterface -o %t/Bar.swiftmodule -module-name Bar
61-
// RUN: %target-swift-frontend -typecheck %t/Use.swift -I %t -verify
63+
// RUN: %target-swift-frontend -typecheck %t/ExpectFail.swift -I %t -package-name barpkg -verify
6264

6365
// RUN: rm -rf %t/Bar.swiftmodule
6466
// RUN: %target-swift-frontend -compile-module-from-interface %t/Bar.private.swiftinterface -o %t/Bar.swiftmodule -module-name Bar
65-
// RUN: %target-swift-frontend -typecheck %t/Use.swift -I %t -verify
67+
// RUN: %target-swift-frontend -typecheck %t/ExpectFail.swift -I %t -package-name barpkg -verify
6668

6769
// RUN: rm -rf %t/Bar.swiftmodule
6870
// RUN: %target-swift-frontend -compile-module-from-interface %t/Bar.package.swiftinterface -o %t/Bar.swiftmodule -module-name Bar
69-
// RUN: %target-swift-frontend -typecheck %t/Use.swift -I %t -verify
71+
// RUN: %target-swift-frontend -typecheck %t/Use.swift -I %t -package-name barpkg -experimental-package-interface-load -verify
7072

7173
//--- Bar.swift
7274
public struct PubStruct {}
@@ -94,3 +96,10 @@ import Bar
9496
func use(_ arg: PubStruct) -> PubStruct {
9597
return UfiPkgStruct(arg, arg).ufiPkgVar
9698
}
99+
100+
//--- ExpectFail.swift
101+
import Bar // expected-error {{module 'Bar' is in package 'barpkg' but was built from a non-package interface; modules of the same package can only be loaded if built from source or package interface}}
102+
103+
func use(_ arg: PubStruct) -> PubStruct {
104+
return UfiPkgStruct(arg, arg).ufiPkgVar
105+
}

test/Sema/accessibility_package_inline_interface.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
// CHECK-UTILS: }
7171

7272

73-
// BEGIN Utils.swift
73+
//--- Utils.swift
7474
package protocol PackageProto {
7575
var pkgVar: Double { get set }
7676
func pkgFunc()

0 commit comments

Comments
 (0)