From 792be3fe856dc6b18a9d9626338c63e1d2bec16a Mon Sep 17 00:00:00 2001 From: Ellie Shin Date: Wed, 14 Dec 2022 15:48:31 -0800 Subject: [PATCH 1/4] Modify AccessScope to allow checks for package access level Resolves rdar://103534243 --- include/swift/AST/AccessScope.h | 75 +++++++++++++++++++++++++-------- lib/AST/Decl.cpp | 10 +++-- lib/AST/DeclContext.cpp | 8 ++-- lib/Sema/TypeCheckAccess.cpp | 3 +- 4 files changed, 72 insertions(+), 24 deletions(-) diff --git a/include/swift/AST/AccessScope.h b/include/swift/AST/AccessScope.h index 684a6a7f7ee57..88ea5ed5bd64c 100644 --- a/include/swift/AST/AccessScope.h +++ b/include/swift/AST/AccessScope.h @@ -20,20 +20,40 @@ namespace swift { +/// Used to provide the kind of scope limitation in AccessScope::Value +enum class AccessLimitKind : uint8_t { None = 0, Private, Package }; + /// The wrapper around the outermost DeclContext from which /// a particular declaration can be accessed. class AccessScope { - /// The declaration context (if not public) along with a bit saying - /// whether this scope is private, SPI or not. - /// If the declaration context is set, the bit means that the scope is - /// private or not. If the declaration context is null, the bit means that - /// this scope is SPI or not. - llvm::PointerIntPair Value; + /// The declaration context along with an enum indicating the level of + /// scope limitation. + /// If the declaration context is set, and the limit kind is Private, the + /// access level is considered 'private'. Whether it's 'internal' or + /// 'fileprivate' is determined by what the declaration context casts to. If + /// the declaration context is null, and the limit kind is None, the access + /// level is considered 'public'. If the limit kind is Private, the access + /// level is considered SPI. If it's Package, the access level is considered + /// 'package'. Below is a table showing the combinations. + /// + /// AccessLimitKind DC == nullptr DC != nullptr + /// --------------------------------------------------------------------------- + /// None public fileprivate or internal (check DC to tell which) + /// Private `@_spi` public private + /// Package package (unused) + + llvm::PointerIntPair Value; public: - AccessScope(const DeclContext *DC, bool isPrivate = false); + AccessScope(const DeclContext *DC, + AccessLimitKind limitKind = AccessLimitKind::None); - static AccessScope getPublic() { return AccessScope(nullptr, false); } + static AccessScope getPublic() { + return AccessScope(nullptr, AccessLimitKind::None); + } + static AccessScope getPackage() { + return AccessScope(nullptr, AccessLimitKind::Package); + } /// Check if private access is allowed. This is a lexical scope check in Swift /// 3 mode. In Swift 4 mode, declarations and extensions of the same type will @@ -46,25 +66,46 @@ class AccessScope { bool operator==(AccessScope RHS) const { return Value == RHS.Value; } bool operator!=(AccessScope RHS) const { return !(*this == RHS); } bool hasEqualDeclContextWith(AccessScope RHS) const { + if (isPublic()) + return RHS.isPublic(); + if (isPackage()) + return RHS.isPackage(); return getDeclContext() == RHS.getDeclContext(); } - bool isPublic() const { return !Value.getPointer(); } - bool isPrivate() const { return Value.getPointer() && Value.getInt(); } + bool isPublic() const { + return !Value.getPointer() && Value.getInt() == AccessLimitKind::None; + } + bool isPrivate() const { + return Value.getPointer() && Value.getInt() == AccessLimitKind::Private; + } bool isFileScope() const; bool isInternal() const; + bool isPackage() const { + return !Value.getPointer() && Value.getInt() == AccessLimitKind::Package; + } - /// Returns true if this is a child scope of the specified other access scope. - /// + /// Returns true if this scope is more restrictive than the argument scope. + /// It's often used to compute the min access scope. The order of restrictiveness + /// is: private (most restrictive), fileprivate, internal, package, public (least restrictive). /// \see DeclContext::isChildContextOf bool isChildOf(AccessScope AS) const { - if (!isPublic() && !AS.isPublic()) - return allowsPrivateAccess(getDeclContext(), AS.getDeclContext()); - if (isPublic() && AS.isPublic()) - return false; - return AS.isPublic(); + if (isInternalOrLess()) { + if (AS.isInternalOrLess()) + return allowsPrivateAccess(getDeclContext(), AS.getDeclContext()); + else + return AS.isPackage() || AS.isPublic(); + } + if (isPackage()) + return AS.isPublic(); + + // If this is public, it can't be less than access level of AS + // so return false + return false; } + bool isInternalOrLess() const { return getDeclContext() != nullptr; } + /// Returns the associated access level for diagnostic purposes. AccessLevel accessLevelForDiagnostics() const; diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 8166f31a0cd02..c79ee8b317555 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -3678,11 +3678,13 @@ getAccessScopeForFormalAccess(const ValueDecl *VD, while (!resultDC->isModuleScopeContext()) { if (isa(resultDC)) { return AccessScope(resultDC->getModuleScopeContext(), - access == AccessLevel::Private); + access == AccessLevel::Private + ? AccessLimitKind::Private + : AccessLimitKind::None); } if (resultDC->isLocalContext() || access == AccessLevel::Private) - return AccessScope(resultDC, /*private*/true); + return AccessScope(resultDC, AccessLimitKind::Private); if (auto enclosingNominal = dyn_cast(resultDC)) { auto enclosingAccess = @@ -3713,7 +3715,9 @@ getAccessScopeForFormalAccess(const ValueDecl *VD, case AccessLevel::Private: case AccessLevel::FilePrivate: assert(resultDC->isModuleScopeContext()); - return AccessScope(resultDC, access == AccessLevel::Private); + return AccessScope(resultDC, access == AccessLevel::Private + ? AccessLimitKind::Private + : AccessLimitKind::None); case AccessLevel::Internal: return AccessScope(resultDC->getParentModule()); case AccessLevel::Public: diff --git a/lib/AST/DeclContext.cpp b/lib/AST/DeclContext.cpp index 9886b060838f4..21cff61384596 100644 --- a/lib/AST/DeclContext.cpp +++ b/lib/AST/DeclContext.cpp @@ -1136,11 +1136,13 @@ getPrivateDeclContext(const DeclContext *DC, const SourceFile *useSF) { return lastExtension ? lastExtension : DC; } -AccessScope::AccessScope(const DeclContext *DC, bool isPrivate) - : Value(DC, isPrivate) { - if (isPrivate) { +AccessScope::AccessScope(const DeclContext *DC, AccessLimitKind limitKind) + : Value(DC, limitKind) { + auto isPrivate = false; + if (limitKind == AccessLimitKind::Private) { DC = getPrivateDeclContext(DC, DC->getParentSourceFile()); Value.setPointer(DC); + isPrivate = true; } if (!DC || isa(DC)) assert(!isPrivate && "public or internal scope can't be private"); diff --git a/lib/Sema/TypeCheckAccess.cpp b/lib/Sema/TypeCheckAccess.cpp index 3c2683e2cf48b..354b07d692142 100644 --- a/lib/Sema/TypeCheckAccess.cpp +++ b/lib/Sema/TypeCheckAccess.cpp @@ -2095,7 +2095,8 @@ static void checkExtensionGenericParamAccess(const ExtensionDecl *ED) { case AccessLevel::FilePrivate: { const DeclContext *DC = ED->getModuleScopeContext(); bool isPrivate = (userSpecifiedAccess == AccessLevel::Private); - desiredAccessScope = AccessScope(DC, isPrivate); + desiredAccessScope = AccessScope(DC, isPrivate ? AccessLimitKind::Private + : AccessLimitKind::None); break; } case AccessLevel::Internal: From 1c66d02f926384f995ec2e275bb8bf1536471d1f Mon Sep 17 00:00:00 2001 From: Ellie Shin Date: Thu, 12 Jan 2023 15:01:54 -0800 Subject: [PATCH 2/4] Add `package` access level to enum AccessLevel Resolves rdar://104198440 --- include/swift/AST/AccessScope.h | 2 +- include/swift/AST/AttrKind.h | 6 ++++++ include/swift/AST/Decl.h | 5 +++-- lib/APIDigester/ModuleAnalyzerNodes.cpp | 1 + lib/AST/ASTPrinter.cpp | 3 +++ lib/AST/ASTVerifier.cpp | 2 +- lib/AST/AccessRequests.cpp | 2 ++ lib/AST/Attr.cpp | 1 + lib/AST/Decl.cpp | 3 +++ lib/AST/Module.cpp | 1 + lib/IDE/CodeCompletionResultBuilder.h | 5 +++++ lib/IRGen/GenDecl.cpp | 1 + lib/SIL/IR/SIL.cpp | 1 + lib/SIL/IR/SILDeclRef.cpp | 2 ++ lib/SIL/IR/SILModule.cpp | 1 + lib/SILOptimizer/Analysis/BasicCalleeAnalysis.cpp | 1 + lib/SILOptimizer/IPO/DeadFunctionElimination.cpp | 1 + lib/SILOptimizer/IPO/GlobalOpt.cpp | 1 + lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp | 1 + lib/SILOptimizer/Utils/Devirtualize.cpp | 2 ++ lib/SILOptimizer/Utils/InstOptUtils.cpp | 1 + lib/Sema/MiscDiagnostics.cpp | 1 + lib/Sema/TypeCheckAccess.cpp | 1 + lib/Sema/TypeCheckDeclPrimary.cpp | 1 + lib/Sema/TypeCheckProtocol.cpp | 1 + lib/Serialization/Deserialization.cpp | 1 + lib/Serialization/ModuleFormat.h | 3 ++- lib/Serialization/Serialization.cpp | 1 + tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp | 3 +++ tools/SourceKit/lib/SwiftLang/SwiftLangSupport.cpp | 6 ++++++ utils/gyb_syntax_support/AttributeKinds.py | 1 + 31 files changed, 57 insertions(+), 5 deletions(-) diff --git a/include/swift/AST/AccessScope.h b/include/swift/AST/AccessScope.h index 88ea5ed5bd64c..10d62f51fda03 100644 --- a/include/swift/AST/AccessScope.h +++ b/include/swift/AST/AccessScope.h @@ -70,6 +70,7 @@ class AccessScope { return RHS.isPublic(); if (isPackage()) return RHS.isPackage(); + return getDeclContext() == RHS.getDeclContext(); } @@ -98,7 +99,6 @@ class AccessScope { } if (isPackage()) return AS.isPublic(); - // If this is public, it can't be less than access level of AS // so return false return false; diff --git a/include/swift/AST/AttrKind.h b/include/swift/AST/AttrKind.h index e0a708d64d75b..90329600f9a81 100644 --- a/include/swift/AST/AttrKind.h +++ b/include/swift/AST/AttrKind.h @@ -60,6 +60,12 @@ enum class AccessLevel : uint8_t { FilePrivate, /// Internal access is limited to the current module. Internal, + /// Package access is not limited, but some capabilities may be + /// restricted outside of the current package containing modules. + /// It's similar to Public in that it's accessible from other modules + /// and subclassable only within the defining module as long as + /// the modules are in the same package. + Package, /// Public access is not limited, but some capabilities may be /// restricted outside of the current module. Public, diff --git a/include/swift/AST/Decl.h b/include/swift/AST/Decl.h index 578dfbf369d1c..f7a6ce2f82ce3 100644 --- a/include/swift/AST/Decl.h +++ b/include/swift/AST/Decl.h @@ -687,13 +687,14 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated { NumPathElements : 8 ); - SWIFT_INLINE_BITFIELD(ExtensionDecl, Decl, 3+1, + SWIFT_INLINE_BITFIELD(ExtensionDecl, Decl, 4+1, /// An encoding of the default and maximum access level for this extension. + /// The value 4 corresponds to AccessLevel::Public /// /// This is encoded as (1 << (maxAccess-1)) | (1 << (defaultAccess-1)), /// which works because the maximum is always greater than or equal to the /// default, and 'private' is never used. 0 represents an uncomputed value. - DefaultAndMaxAccessLevel : 3, + DefaultAndMaxAccessLevel : 4, /// Whether there is are lazily-loaded conformances for this extension. HasLazyConformances : 1 diff --git a/lib/APIDigester/ModuleAnalyzerNodes.cpp b/lib/APIDigester/ModuleAnalyzerNodes.cpp index 7efd6c327fe6b..e26036b3edc50 100644 --- a/lib/APIDigester/ModuleAnalyzerNodes.cpp +++ b/lib/APIDigester/ModuleAnalyzerNodes.cpp @@ -1733,6 +1733,7 @@ SDKContext::shouldIgnore(Decl *D, const Decl* Parent) const { case AccessLevel::Private: case AccessLevel::FilePrivate: return true; + case AccessLevel::Package: case AccessLevel::Public: case AccessLevel::Open: break; diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp index 26ce3ca99ab92..c6c0be851bf30 100644 --- a/lib/AST/ASTPrinter.cpp +++ b/lib/AST/ASTPrinter.cpp @@ -728,6 +728,9 @@ class PrintAST : public ASTVisitor { case AccessLevel::Public: Printer << tok::kw_public; break; + case AccessLevel::Package: + Printer.printKeyword("package", Options); + break; case AccessLevel::Open: Printer.printKeyword("open", Options); break; diff --git a/lib/AST/ASTVerifier.cpp b/lib/AST/ASTVerifier.cpp index 8069da8e260ba..008ae7450a2fa 100644 --- a/lib/AST/ASTVerifier.cpp +++ b/lib/AST/ASTVerifier.cpp @@ -944,7 +944,7 @@ class Verifier : public ASTWalker { PrettyStackTraceDecl debugStack("verifying access", D); if (!D->getASTContext().isAccessControlDisabled() && D->getFormalAccessScope().isPublic() && - D->getFormalAccess() < AccessLevel::Public) { + D->getFormalAccess() <= AccessLevel::Package) { Out << "non-public decl has no formal access scope\n"; D->dump(Out); abort(); diff --git a/lib/AST/AccessRequests.cpp b/lib/AST/AccessRequests.cpp index f776c0c9c1f6c..ad656a2692540 100644 --- a/lib/AST/AccessRequests.cpp +++ b/lib/AST/AccessRequests.cpp @@ -251,6 +251,8 @@ DefaultAndMaxAccessLevelRequest::evaluate(Evaluator &evaluator, maxAccess = AccessLevel::Public; } else if (maxScope->isPublic()) { maxAccess = AccessLevel::Public; + } else if (maxScope->isPackage()) { + maxAccess = AccessLevel::Package; } else if (isa(maxScope->getDeclContext())) { maxAccess = AccessLevel::Internal; } else { diff --git a/lib/AST/Attr.cpp b/lib/AST/Attr.cpp index 29379a20b0929..933eb2019ecc4 100644 --- a/lib/AST/Attr.cpp +++ b/lib/AST/Attr.cpp @@ -74,6 +74,7 @@ StringRef swift::getAccessLevelSpelling(AccessLevel value) { case AccessLevel::Private: return "private"; case AccessLevel::FilePrivate: return "fileprivate"; case AccessLevel::Internal: return "internal"; + case AccessLevel::Package: return "package"; case AccessLevel::Public: return "public"; case AccessLevel::Open: return "open"; } diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index c79ee8b317555..c30d3ee29c865 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -3598,6 +3598,7 @@ AccessLevel ValueDecl::getEffectiveAccess() const { switch (effectiveAccess) { case AccessLevel::Open: break; + case AccessLevel::Package: case AccessLevel::Public: case AccessLevel::Internal: if (getModuleContext()->isTestingEnabled() || @@ -3720,6 +3721,7 @@ getAccessScopeForFormalAccess(const ValueDecl *VD, : AccessLimitKind::None); case AccessLevel::Internal: return AccessScope(resultDC->getParentModule()); + case AccessLevel::Package: case AccessLevel::Public: case AccessLevel::Open: return AccessScope::getPublic(); @@ -3869,6 +3871,7 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD, auto *useSF = dyn_cast(useFile); return useSF && useSF->hasTestableOrPrivateImport(access, sourceModule); } + case AccessLevel::Package: case AccessLevel::Public: case AccessLevel::Open: return true; diff --git a/lib/AST/Module.cpp b/lib/AST/Module.cpp index 6de5868784fcf..ba781ebf9fe09 100644 --- a/lib/AST/Module.cpp +++ b/lib/AST/Module.cpp @@ -2752,6 +2752,7 @@ bool SourceFile::hasTestableOrPrivateImport( auto *module = ofDecl->getModuleContext(); switch (accessLevel) { case AccessLevel::Internal: + case AccessLevel::Package: case AccessLevel::Public: // internal/public access only needs an import marked as @_private. The // filename does not need to match (and we don't serialize it for such diff --git a/lib/IDE/CodeCompletionResultBuilder.h b/lib/IDE/CodeCompletionResultBuilder.h index 54ef59b58a70f..41e7347f925e7 100644 --- a/lib/IDE/CodeCompletionResultBuilder.h +++ b/lib/IDE/CodeCompletionResultBuilder.h @@ -179,6 +179,11 @@ class CodeCompletionResultBuilder { case AccessLevel::Internal: // 'internal' is the default, don't add it. break; + case AccessLevel::Package: + addChunkWithTextNoCopy( + CodeCompletionString::Chunk::ChunkKind::AccessControlKeyword, + "package "); + break; case AccessLevel::Public: addChunkWithTextNoCopy( CodeCompletionString::Chunk::ChunkKind::AccessControlKeyword, diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp index 324d90ca37c75..bf34af52ef8b7 100644 --- a/lib/IRGen/GenDecl.cpp +++ b/lib/IRGen/GenDecl.cpp @@ -1529,6 +1529,7 @@ bool IRGenerator::hasLazyMetadata(TypeDecl *type) { switch (type->getEffectiveAccess()) { case AccessLevel::Open: case AccessLevel::Public: + case AccessLevel::Package: // We can't remove metadata for externally visible types. return false; case AccessLevel::Internal: diff --git a/lib/SIL/IR/SIL.cpp b/lib/SIL/IR/SIL.cpp index 3ca3ac06c400a..430e0454ca34c 100644 --- a/lib/SIL/IR/SIL.cpp +++ b/lib/SIL/IR/SIL.cpp @@ -40,6 +40,7 @@ FormalLinkage swift::getDeclLinkage(const ValueDecl *D) { return FormalLinkage::PublicNonUnique; switch (D->getEffectiveAccess()) { + case AccessLevel::Package: case AccessLevel::Public: case AccessLevel::Open: return FormalLinkage::PublicUnique; diff --git a/lib/SIL/IR/SILDeclRef.cpp b/lib/SIL/IR/SILDeclRef.cpp index 1787ba4d51e13..1279567c7cffb 100644 --- a/lib/SIL/IR/SILDeclRef.cpp +++ b/lib/SIL/IR/SILDeclRef.cpp @@ -600,6 +600,7 @@ SILLinkage SILDeclRef::getDefinitionLinkage() const { return SILLinkage::Shared; return SILLinkage::Hidden; + case AccessLevel::Package: case AccessLevel::Public: case AccessLevel::Open: switch (limit) { @@ -1490,6 +1491,7 @@ SubclassScope SILDeclRef::getSubclassScope() const { // SILModule, so we don't need to do anything. return SubclassScope::NotApplicable; case AccessLevel::Internal: + case AccessLevel::Package: case AccessLevel::Public: // If the class is internal or public, it can only be subclassed from // the same AST Module, but possibly a different SILModule. diff --git a/lib/SIL/IR/SILModule.cpp b/lib/SIL/IR/SILModule.cpp index f3ea5e7db2ed2..1c262504fa0f3 100644 --- a/lib/SIL/IR/SILModule.cpp +++ b/lib/SIL/IR/SILModule.cpp @@ -926,6 +926,7 @@ SILLinkage swift::getDeclSILLinkage(const ValueDecl *decl) { case AccessLevel::Internal: linkage = SILLinkage::Hidden; break; + case AccessLevel::Package: case AccessLevel::Public: case AccessLevel::Open: linkage = SILLinkage::Public; diff --git a/lib/SILOptimizer/Analysis/BasicCalleeAnalysis.cpp b/lib/SILOptimizer/Analysis/BasicCalleeAnalysis.cpp index 73e1776635412..0152748a27166 100644 --- a/lib/SILOptimizer/Analysis/BasicCalleeAnalysis.cpp +++ b/lib/SILOptimizer/Analysis/BasicCalleeAnalysis.cpp @@ -177,6 +177,7 @@ void CalleeCache::computeWitnessMethodCalleesForWitnessTable( switch (Conf->getProtocol()->getEffectiveAccess()) { case AccessLevel::Open: llvm_unreachable("protocols cannot have open access level"); + case AccessLevel::Package: case AccessLevel::Public: canCallUnknown = true; break; diff --git a/lib/SILOptimizer/IPO/DeadFunctionElimination.cpp b/lib/SILOptimizer/IPO/DeadFunctionElimination.cpp index 7a2a6c3162246..efa671ed52a44 100644 --- a/lib/SILOptimizer/IPO/DeadFunctionElimination.cpp +++ b/lib/SILOptimizer/IPO/DeadFunctionElimination.cpp @@ -394,6 +394,7 @@ class DeadFunctionAndGlobalElimination { case AccessLevel::Internal: linkage = SILLinkage::Hidden; break; + case AccessLevel::Package: case AccessLevel::Public: case AccessLevel::Open: linkage = SILLinkage::Public; diff --git a/lib/SILOptimizer/IPO/GlobalOpt.cpp b/lib/SILOptimizer/IPO/GlobalOpt.cpp index d9d16fdfe0766..f93142d501888 100644 --- a/lib/SILOptimizer/IPO/GlobalOpt.cpp +++ b/lib/SILOptimizer/IPO/GlobalOpt.cpp @@ -490,6 +490,7 @@ static bool canBeChangedExternally(SILGlobalVariable *SILG) { return false; case AccessLevel::Internal: return !SILG->getModule().isWholeModule(); + case AccessLevel::Package: case AccessLevel::Public: case AccessLevel::Open: return true; diff --git a/lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp b/lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp index 5e4a17ca1a406..dedafe1154f36 100644 --- a/lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp +++ b/lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp @@ -305,6 +305,7 @@ static bool isDefaultCaseKnown(ClassHierarchyAnalysis *CHA, case AccessLevel::Open: return false; case AccessLevel::Public: + case AccessLevel::Package: case AccessLevel::Internal: if (!AI.getModule().isWholeModule()) return false; diff --git a/lib/SILOptimizer/Utils/Devirtualize.cpp b/lib/SILOptimizer/Utils/Devirtualize.cpp index 35371d1b755d6..250dc0275c503 100644 --- a/lib/SILOptimizer/Utils/Devirtualize.cpp +++ b/lib/SILOptimizer/Utils/Devirtualize.cpp @@ -156,6 +156,7 @@ static bool isKnownFinalClass(ClassDecl *cd, SILModule &module, case AccessLevel::Open: return false; case AccessLevel::Public: + case AccessLevel::Package: case AccessLevel::Internal: if (!module.isWholeModule()) return false; @@ -177,6 +178,7 @@ static bool isKnownFinalClass(ClassDecl *cd, SILModule &module, case AccessLevel::Open: return false; case AccessLevel::Public: + case AccessLevel::Package: case AccessLevel::Internal: if (!module.isWholeModule()) return false; diff --git a/lib/SILOptimizer/Utils/InstOptUtils.cpp b/lib/SILOptimizer/Utils/InstOptUtils.cpp index e94779694fce6..ed1125a655e2a 100644 --- a/lib/SILOptimizer/Utils/InstOptUtils.cpp +++ b/lib/SILOptimizer/Utils/InstOptUtils.cpp @@ -1344,6 +1344,7 @@ bool swift::calleesAreStaticallyKnowable(SILModule &module, ValueDecl *vd) { case AccessLevel::Open: return false; case AccessLevel::Public: + case AccessLevel::Package: if (isa(vd)) { // Constructors are special: a derived class in another module can // "override" a constructor if its class is "open", although the diff --git a/lib/Sema/MiscDiagnostics.cpp b/lib/Sema/MiscDiagnostics.cpp index ab8908dd00d6f..2aacd74e37353 100644 --- a/lib/Sema/MiscDiagnostics.cpp +++ b/lib/Sema/MiscDiagnostics.cpp @@ -5554,6 +5554,7 @@ void swift::fixItAccess(InFlightDiagnostic &diag, ValueDecl *VD, case AccessLevel::Private: fixItString = "private "; break; case AccessLevel::FilePrivate: fixItString = "fileprivate "; break; case AccessLevel::Internal: fixItString = "internal "; break; + case AccessLevel::Package: fixItString = "package "; break; case AccessLevel::Public: fixItString = "public "; break; case AccessLevel::Open: fixItString = "open "; break; } diff --git a/lib/Sema/TypeCheckAccess.cpp b/lib/Sema/TypeCheckAccess.cpp index 354b07d692142..0f23c0f8cc2da 100644 --- a/lib/Sema/TypeCheckAccess.cpp +++ b/lib/Sema/TypeCheckAccess.cpp @@ -2102,6 +2102,7 @@ static void checkExtensionGenericParamAccess(const ExtensionDecl *ED) { case AccessLevel::Internal: desiredAccessScope = AccessScope(ED->getModuleContext()); break; + case AccessLevel::Package: case AccessLevel::Public: case AccessLevel::Open: break; diff --git a/lib/Sema/TypeCheckDeclPrimary.cpp b/lib/Sema/TypeCheckDeclPrimary.cpp index 4ae10edbd2f39..2cb18835126ad 100644 --- a/lib/Sema/TypeCheckDeclPrimary.cpp +++ b/lib/Sema/TypeCheckDeclPrimary.cpp @@ -3420,6 +3420,7 @@ class DeclChecker : public DeclVisitor { case AccessLevel::Open: requiredAccess = AccessLevel::Public; break; + case AccessLevel::Package: case AccessLevel::Public: case AccessLevel::Internal: requiredAccess = AccessLevel::Internal; diff --git a/lib/Sema/TypeCheckProtocol.cpp b/lib/Sema/TypeCheckProtocol.cpp index b3da90bf8668d..9a677be0cf983 100644 --- a/lib/Sema/TypeCheckProtocol.cpp +++ b/lib/Sema/TypeCheckProtocol.cpp @@ -6180,6 +6180,7 @@ static void diagnoseUnstableName(ProtocolConformance *conformance, case AccessLevel::Internal: case AccessLevel::Open: case AccessLevel::Public: + case AccessLevel::Package: break; } } diff --git a/lib/Serialization/Deserialization.cpp b/lib/Serialization/Deserialization.cpp index 626073cd2b254..834ae92dea8c6 100644 --- a/lib/Serialization/Deserialization.cpp +++ b/lib/Serialization/Deserialization.cpp @@ -2481,6 +2481,7 @@ static Optional getActualAccessLevel(uint8_t raw) { CASE(Private) CASE(FilePrivate) CASE(Internal) + CASE(Package) CASE(Public) CASE(Open) #undef CASE diff --git a/lib/Serialization/ModuleFormat.h b/lib/Serialization/ModuleFormat.h index 5565f5d4fbef9..6f1d27c968a59 100644 --- a/lib/Serialization/ModuleFormat.h +++ b/lib/Serialization/ModuleFormat.h @@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0; /// describe what change you made. The content of this comment isn't important; /// it just ensures a conflict if two people change the module format. /// Don't worry about adhering to the 80-column limit for this line. -const uint16_t SWIFTMODULE_VERSION_MINOR = 728; // package name field +const uint16_t SWIFTMODULE_VERSION_MINOR = 735; // add package access modifier /// A standard hash seed used for all string hashes in a serialized module. /// @@ -521,6 +521,7 @@ enum class AccessLevel : uint8_t { Private = 0, FilePrivate, Internal, + Package, Public, Open, }; diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp index d1c4e39a2aa00..761985fe2ef81 100644 --- a/lib/Serialization/Serialization.cpp +++ b/lib/Serialization/Serialization.cpp @@ -2188,6 +2188,7 @@ static uint8_t getRawStableAccessLevel(swift::AccessLevel access) { CASE(Private) CASE(FilePrivate) CASE(Internal) + CASE(Package) CASE(Public) CASE(Open) #undef CASE diff --git a/tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp b/tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp index d50388d4b33e7..980252602d389 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp @@ -1134,6 +1134,7 @@ namespace { static UIdent getAccessLevelUID(AccessLevel Access) { static UIdent AccessOpen("source.lang.swift.accessibility.open"); static UIdent AccessPublic("source.lang.swift.accessibility.public"); + static UIdent AccessPackage("source.lang.swift.accessibility.package"); static UIdent AccessInternal("source.lang.swift.accessibility.internal"); static UIdent AccessFilePrivate("source.lang.swift.accessibility.fileprivate"); static UIdent AccessPrivate("source.lang.swift.accessibility.private"); @@ -1145,6 +1146,8 @@ static UIdent getAccessLevelUID(AccessLevel Access) { return AccessFilePrivate; case AccessLevel::Internal: return AccessInternal; + case AccessLevel::Package: + return AccessPackage; case AccessLevel::Public: return AccessPublic; case AccessLevel::Open: diff --git a/tools/SourceKit/lib/SwiftLang/SwiftLangSupport.cpp b/tools/SourceKit/lib/SwiftLang/SwiftLangSupport.cpp index 193c123074b8d..5c5b2c40dcc0b 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftLangSupport.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftLangSupport.cpp @@ -74,11 +74,13 @@ static UIdent Attr_ObjcNamed("source.decl.attribute.objc.name"); static UIdent Attr_Private("source.decl.attribute.private"); static UIdent Attr_FilePrivate("source.decl.attribute.fileprivate"); static UIdent Attr_Internal("source.decl.attribute.internal"); +static UIdent Attr_Package("source.decl.attribute.package"); static UIdent Attr_Public("source.decl.attribute.public"); static UIdent Attr_Open("source.decl.attribute.open"); static UIdent Attr_Setter_Private("source.decl.attribute.setter_access.private"); static UIdent Attr_Setter_FilePrivate("source.decl.attribute.setter_access.fileprivate"); static UIdent Attr_Setter_Internal("source.decl.attribute.setter_access.internal"); +static UIdent Attr_Setter_Package("source.decl.attribute.setter_access.package"); static UIdent Attr_Setter_Public("source.decl.attribute.setter_access.public"); static UIdent Attr_Setter_Open("source.decl.attribute.setter_access.open"); static UIdent EffectiveAccess_Public("source.decl.effective_access.public"); @@ -793,6 +795,8 @@ Optional SwiftLangSupport::getUIDForDeclAttribute(const swift::DeclAttri return Attr_FilePrivate; case AccessLevel::Internal: return Attr_Internal; + case AccessLevel::Package: + return Attr_Package; case AccessLevel::Public: return Attr_Public; case AccessLevel::Open: @@ -807,6 +811,8 @@ Optional SwiftLangSupport::getUIDForDeclAttribute(const swift::DeclAttri return Attr_Setter_FilePrivate; case AccessLevel::Internal: return Attr_Setter_Internal; + case AccessLevel::Package: + return Attr_Setter_Package; case AccessLevel::Public: return Attr_Setter_Public; case AccessLevel::Open: diff --git a/utils/gyb_syntax_support/AttributeKinds.py b/utils/gyb_syntax_support/AttributeKinds.py index 9eaf0918cc068..9e29dbcecd16a 100644 --- a/utils/gyb_syntax_support/AttributeKinds.py +++ b/utils/gyb_syntax_support/AttributeKinds.py @@ -833,6 +833,7 @@ def __init__(self, name, swift_name=None): DeclAttributeAlias('fileprivate', 'AccessControl', swift_name='fileprivateKeyword'), DeclAttributeAlias('internal', 'AccessControl', swift_name='internalKeyword'), DeclAttributeAlias('public', 'AccessControl', swift_name='publicKeyword'), + ContextualDeclAttributeAlias('package', 'AccessControl'), ContextualDeclAttributeAlias('open', 'AccessControl'), DeclAttribute('__setter_access', 'SetterAccess', OnVar, OnSubscript, From c2acf617845397e66b49f132f7a2b73c19422f80 Mon Sep 17 00:00:00 2001 From: Ellie Shin Date: Thu, 19 Jan 2023 16:09:40 -0800 Subject: [PATCH 3/4] Add package to diags --- include/swift/AST/DiagnosticsSema.def | 242 +++++++++++++------------- 1 file changed, 121 insertions(+), 121 deletions(-) diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index 7c786d817eb74..c4c0e99ed30b8 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -150,17 +150,17 @@ FIXIT(insert_type_qualification,"%0.",(Type)) ERROR(candidate_inaccessible,none, "%0 is inaccessible due to " - "'%select{private|fileprivate|internal|@_spi|@_spi}1' protection level", + "'%select{private|fileprivate|internal|package|@_spi|@_spi}1' protection level", (DeclBaseName, AccessLevel)) NOTE(note_candidate_inaccessible,none, "%0 is inaccessible due to " - "'%select{private|fileprivate|internal|@_spi|@_spi}1' protection level", + "'%select{private|fileprivate|internal|package|@_spi|@_spi}1' protection level", (DeclName, AccessLevel)) ERROR(init_candidate_inaccessible,none, "%0 initializer is inaccessible due to " - "'%select{private|fileprivate|internal|@_spi|@_spi}1' protection level", + "'%select{private|fileprivate|internal|package|@_spi|@_spi}1' protection level", (Type, AccessLevel)) ERROR(cannot_pass_rvalue_mutating_subelement,none, @@ -1562,42 +1562,42 @@ NOTE(access_control_in_protocol_detail,none, "protocol requirements implicitly have the same access as the " "protocol itself", ()) ERROR(access_control_setter,none, - "'%select{private|fileprivate|internal|public|open}0(set)' modifier can only " + "'%select{private|fileprivate|internal|package|public|open}0(set)' modifier can only " "be applied to variables and subscripts", (AccessLevel)) ERROR(access_control_setter_read_only,none, - "'%select{private|fileprivate|internal|public|%error}0(set)' modifier cannot be " + "'%select{private|fileprivate|internal|package|public|%error}0(set)' modifier cannot be " "applied to %select{constants|read-only variables|read-only properties" "|read-only subscripts}1", (AccessLevel, unsigned)) ERROR(access_control_setter_more,none, - "%select{private|fileprivate|internal|public|%error}0 " + "%select{private|fileprivate|internal|package|public|%error}0 " "%select{variable|property|subscript}1 cannot have " - "%select{%error|a fileprivate|an internal|a public|an open}2 setter", + "%select{%error|a fileprivate|an internal|a package|a public|an open}2 setter", (AccessLevel, unsigned, AccessLevel)) WARNING(access_control_setter_redundant,none, - "'%select{private|fileprivate|internal|public|open}0(set)' modifier is " - "redundant for %select{a private|a fileprivate|an internal|a public|an open}2 " + "'%select{private|fileprivate|internal|package|public|open}0(set)' modifier is " + "redundant for %select{a private|a fileprivate|an internal|a package|a public|an open}2 " "%1", (AccessLevel, DescriptiveDeclKind, AccessLevel)) WARNING(access_control_ext_member_more,none, - "'%select{%error|fileprivate|internal|public|open}0' modifier conflicts " + "'%select{%error|fileprivate|internal|package|public|open}0' modifier conflicts " "with extension's default access of " - "'%select{private|fileprivate|internal|public|%error}1'", + "'%select{private|fileprivate|internal|package|public|%error}1'", (AccessLevel, AccessLevel)) WARNING(access_control_ext_member_redundant,none, - "'%select{%error|fileprivate|internal|public|%error}0' modifier is redundant " + "'%select{%error|fileprivate|internal|package|public|%error}0' modifier is redundant " "for %1 declared in %select{a private (equivalent to fileprivate)|a fileprivate" - "|an internal|a public|%error}2 extension", + "|an internal|a package|a public|%error}2 extension", (AccessLevel, DescriptiveDeclKind, AccessLevel)) ERROR(access_control_ext_requirement_member_more,none, - "cannot declare %select{%error|a fileprivate|an internal|a public|an open}0 %1 " - "in an extension with %select{private|fileprivate|internal|public|%error}2 " + "cannot declare %select{%error|a fileprivate|an internal|a package|a public|an open}0 %1 " + "in an extension with %select{private|fileprivate|internal|package|public|%error}2 " "requirements", (AccessLevel, DescriptiveDeclKind, AccessLevel)) ERROR(access_control_extension_more,none, - "extension of %select{private|fileprivate|internal|%error|%error}0 %1 cannot " - "be declared %select{%error|fileprivate|internal|public|%error}2", + "extension of %select{private|fileprivate|internal|package|%error|%error}0 %1 cannot " + "be declared %select{%error|fileprivate|internal|package|public|%error}2", (AccessLevel, DescriptiveDeclKind, AccessLevel)) ERROR(access_control_extension_open,none, "extensions cannot be declared 'open'; declare individual members as 'open' instead", @@ -1750,34 +1750,34 @@ NOTE(static_requires_initializer_add_init,none, ERROR(pattern_type_access,none, "%select{%select{variable|constant}0|property}1 " "%select{must be declared %select{" - "%select{private|fileprivate|internal|%error|%error}3|private or fileprivate}4" + "%select{private|fileprivate|internal|package|%error|%error}3|private or fileprivate}4" "|cannot be declared " - "%select{in this context|fileprivate|internal|public|open}3}2 " + "%select{in this context|fileprivate|internal|package|public|open}3}2 " "because its type uses " - "%select{a private|a fileprivate|an internal|%error|%error}5 type", + "%select{a private|a fileprivate|an internal|a package|%error|%error}5 type", (bool, bool, bool, AccessLevel, bool, AccessLevel)) WARNING(pattern_type_access_warn,none, "%select{%select{variable|constant}0|property}1 " - "%select{should be declared %select{private|fileprivate|internal|%error|%error}5" - "|should not be declared %select{in this context|fileprivate|internal|public|open}3}2 " + "%select{should be declared %select{private|fileprivate|internal|package|%error|%error}5" + "|should not be declared %select{in this context|fileprivate|internal|package|public|open}3}2 " "because its type uses " - "%select{a private|a fileprivate|an internal|%error|%error}5 type", + "%select{a private|a fileprivate|an internal|a package|%error|%error}5 type", (bool, bool, bool, AccessLevel, bool, AccessLevel)) ERROR(pattern_type_access_inferred,none, "%select{%select{variable|constant}0|property}1 " "%select{must be declared %select{" - "%select{private|fileprivate|internal|%error|%error}3|private or fileprivate}4" + "%select{private|fileprivate|internal|package|%error|%error}3|private or fileprivate}4" "|cannot be declared " - "%select{in this context|fileprivate|internal|public|open}3}2 " + "%select{in this context|fileprivate|internal|package|public|open}3}2 " "because its type %6 uses " - "%select{a private|a fileprivate|an internal|%error|%error}5 type", + "%select{a private|a fileprivate|an internal|a package|%error|%error}5 type", (bool, bool, bool, AccessLevel, bool, AccessLevel, Type)) WARNING(pattern_type_access_inferred_warn,none, "%select{%select{variable|constant}0|property}1 " - "%select{should be declared %select{private|fileprivate|internal|%error|%error}5" - "|should not be declared %select{in this context|fileprivate|internal|public|open}3}2 " + "%select{should be declared %select{private|fileprivate|internal|package|%error|%error}5" + "|should not be declared %select{in this context|fileprivate|internal|package|public|open}3}2 " "because its type %6 uses " - "%select{a private|a fileprivate|an internal|%error|%error}5 type", + "%select{a private|a fileprivate|an internal|a package|%error|%error}5 type", (bool, bool, bool, AccessLevel, bool, AccessLevel, Type)) ERROR(pattern_type_not_usable_from_inline,none, @@ -1873,19 +1873,19 @@ ERROR(unable_to_convert_generic_swift_types,none, // Type aliases ERROR(type_alias_underlying_type_access,none, "type alias %select{must be declared %select{" - "%select{private|fileprivate|internal|%error|%error}1|private or fileprivate}3" + "%select{private|fileprivate|internal|package|%error|%error}1|private or fileprivate}3" "|cannot be declared " - "%select{in this context|fileprivate|internal|public|open}1}0 " + "%select{in this context|fileprivate|internal|package|public|open}1}0 " "because its underlying type uses " - "%select{a private|a fileprivate|an internal|%error|%error}2 type", + "%select{a private|a fileprivate|an internal|a package|%error|%error}2 type", (bool, AccessLevel, AccessLevel, bool)) WARNING(type_alias_underlying_type_access_warn,none, "type alias %select{should be declared " - "%select{private|fileprivate|internal|%error|%error}1" + "%select{private|fileprivate|internal|package|%error|%error}1" "|should not be declared " - "%select{in this context|fileprivate|internal|public|open}1}0 " + "%select{in this context|fileprivate|internal|package|public|open}1}0 " "because its underlying type uses " - "%select{a private|a fileprivate|an internal|%error|%error}2 type", + "%select{a private|a fileprivate|an internal|a package|%error|%error}2 type", (bool, AccessLevel, AccessLevel, bool)) ERROR(type_alias_underlying_type_not_usable_from_inline,none, "type referenced from the underlying type of a " @@ -1901,18 +1901,18 @@ WARNING(type_alias_underlying_type_not_usable_from_inline_warn,none, // Subscripts ERROR(subscript_type_access,none, "subscript %select{must be declared " - "%select{private|fileprivate|internal|%error|%error}1" + "%select{private|fileprivate|internal|package|%error|%error}1" "|cannot be declared " - "%select{in this context|fileprivate|internal|public|open}1}0 " + "%select{in this context|fileprivate|internal|package|public|open}1}0 " "because its %select{index|element type}3 uses " - "%select{a private|a fileprivate|an internal|%error|%error}2 type", + "%select{a private|a fileprivate|an internal|a package|%error|%error}2 type", (bool, AccessLevel, AccessLevel, bool)) WARNING(subscript_type_access_warn,none, "subscript %select{should be declared " - "%select{private|fileprivate|internal|%error|%error}1" - "|should not be declared %select{in this context|fileprivate|internal|public|open}1}0 " + "%select{private|fileprivate|internal|package|%error|%error}1" + "|should not be declared %select{in this context|fileprivate|internal|package|public|open}1}0 " "because its %select{index|element type}3 uses " - "%select{a private|a fileprivate|an internal|%error|%error}2 type", + "%select{a private|a fileprivate|an internal|a package|%error|%error}2 type", (bool, AccessLevel, AccessLevel, bool)) ERROR(subscript_type_usable_from_inline,none, "%select{index type|element type}0 of a '@usableFromInline' subscript " @@ -1927,26 +1927,26 @@ WARNING(subscript_type_usable_from_inline_warn,none, ERROR(function_type_access,none, "%select{function|method|initializer}4 " "%select{must be declared %select{" - "%select{private|fileprivate|internal|%error|%error}1|private or fileprivate}2" + "%select{private|fileprivate|internal|package|%error|%error}1|private or fileprivate}2" "|cannot be declared " - "%select{in this context|fileprivate|internal|public|open}1}0 " + "%select{in this context|fileprivate|internal|package|public|open}1}0 " "because its %select{parameter|result}5 uses " - "%select{a private|a fileprivate|an internal|an '@_spi'|an '@_spi'}3" + "%select{a private|a fileprivate|an internal|a package|an '@_spi'|an '@_spi'}3" "%select{| API wrapper}6 type", (bool, AccessLevel, bool, AccessLevel, unsigned, bool, bool)) ERROR(function_type_spi,none, "%select{function|method|initializer}0 " "cannot be declared '@_spi' " "because its %select{parameter|result}1 uses " - "%select{a private|a fileprivate|an internal|a public|an open}2 type" + "%select{a private|a fileprivate|an internal|a package|a public|an open}2 type" "%select{| that is not '@_spi'}3", (unsigned, bool, AccessLevel, bool)) WARNING(function_type_access_warn,none, "%select{function|method|initializer}4 " - "%select{should be declared %select{private|fileprivate|internal|%error|%error}1" - "|should not be declared %select{in this context|fileprivate|internal|public|open}1}0 " + "%select{should be declared %select{private|fileprivate|internal|package|%error|%error}1" + "|should not be declared %select{in this context|fileprivate|internal|package|public|open}1}0 " "because its %select{parameter|result}5 uses " - "%select{a private|a fileprivate|an internal|%error|%error}3 " + "%select{a private|a fileprivate|an internal|a package|%error|%error}3 " "%select{|API wrapper}6 type", (bool, AccessLevel, bool, AccessLevel, unsigned, bool, bool)) ERROR(function_type_usable_from_inline,none, @@ -1961,7 +1961,7 @@ WARNING(function_type_usable_from_inline_warn,none, (unsigned, bool, bool)) ERROR(spi_attribute_on_non_public,none, - "%select{private|fileprivate|internal|%error|%error}0 %1 " + "%select{private|fileprivate|internal|package|%error|%error}0 %1 " "cannot be declared '@_spi' because only public and open " "declarations can be '@_spi'", (AccessLevel, DescriptiveDeclKind)) @@ -2270,8 +2270,8 @@ ERROR(witness_requires_class_implementation,none, ERROR(witness_not_accessible_proto,none, "%select{initializer %1|method %1|%select{|setter for }2property %1" "|subscript%select{| setter}2}0 must be declared " - "%select{%error|fileprivate|internal|public|%error}3 because it matches a " - "requirement in %select{private|fileprivate|internal|public|%error}4 protocol " + "%select{%error|fileprivate|internal|package|public|%error}3 because it matches a " + "requirement in %select{private|fileprivate|internal|package|public|%error}4 protocol " "%5", (RequirementKind, DeclName, bool, AccessLevel, AccessLevel, Identifier)) ERROR(witness_not_as_sendable,none, @@ -2287,9 +2287,9 @@ ERROR(witness_not_accessible_type,none, "type because it matches a requirement in protocol %5", (RequirementKind, DeclName, bool, AccessLevel, AccessLevel, Identifier)) ERROR(type_witness_not_accessible_proto,none, - "%0 %1 must be declared %select{%error|fileprivate|internal|public|%error}2 " + "%0 %1 must be declared %select{%error|fileprivate|internal|package|public|%error}2 " "because it matches a requirement in " - "%select{%error|fileprivate|internal|public|%error}2 protocol %3", + "%select{%error|fileprivate|internal|package|public|%error}2 protocol %3", (DescriptiveDeclKind, Identifier, AccessLevel, Identifier)) ERROR(type_witness_not_accessible_type,none, "%0 %1 must be as accessible as its enclosing type because it " @@ -2308,11 +2308,11 @@ ERROR(type_witness_objc_generic_parameter,none, "used for associated type %3 of protocol %4", (Type, Type, bool, Identifier, Identifier)) NOTE(witness_fix_access,none, - "mark the %0 as '%select{%error|fileprivate|internal|public|%error}1' to " + "mark the %0 as '%select{%error|fileprivate|internal|package|public|%error}1' to " "satisfy the requirement", (DescriptiveDeclKind, AccessLevel)) NOTE(witness_move_to_another_extension,none, "move the %0 to another extension where it can be declared " - "'%select{%error|%error|internal|public|%error}1' to " + "'%select{%error|%error|internal|package|public|%error}1' to " "satisfy the requirement", (DescriptiveDeclKind, AccessLevel)) WARNING(assoc_type_default_conformance_failed,none, "default type %0 for associated type %1 does not satisfy constraint " @@ -2322,19 +2322,19 @@ NOTE(assoc_type_default_here,none, ERROR(protocol_access,none, "%select{protocol must be declared %select{" - "%select{private|fileprivate|internal|%error|%error}1" + "%select{private|fileprivate|internal|package|%error|%error}1" "|private or fileprivate}4 because %select{it refines|its 'where' clause uses}2" - "|%select{in this context|fileprivate|internal|public|%error}1 " + "|%select{in this context|fileprivate|internal|package|public|%error}1 " "%select{protocol cannot refine|protocol's 'where' clause cannot use}2}0 " - "%select{a private|a fileprivate|an internal|%error|%error}3 %5", + "%select{a private|a fileprivate|an internal|a package|%error|%error}3 %5", (bool, AccessLevel, bool, AccessLevel, bool, DescriptiveDeclKind)) WARNING(protocol_access_warn,none, "%select{protocol should be declared " - "%select{private|fileprivate|internal|%error|%error}1 because " + "%select{private|fileprivate|internal|package|%error|%error}1 because " "%select{it refines|its 'where' clause uses}2" - "|%select{in this context|fileprivate|internal|public|%error}1 " + "|%select{in this context|fileprivate|internal|package|public|%error}1 " "%select{protocol should not refine|protocol's 'where' clause should not use}2}0 " - "%select{a private|a fileprivate|an internal|%error|%error}3 %5", + "%select{a private|a fileprivate|an internal|a package|%error|%error}3 %5", (bool, AccessLevel, bool, AccessLevel, bool, DescriptiveDeclKind)) ERROR(protocol_usable_from_inline,none, "protocol %select{refined|used}0 by '@usableFromInline' protocol " @@ -2373,15 +2373,15 @@ NOTE(default_associated_type_req_fail,none, (Type, Identifier, Type, Type, bool)) ERROR(associated_type_access,none, "associated type in " - "%select{a private|a fileprivate|an internal|a public|%error}0 protocol " + "%select{a private|a fileprivate|an internal|a package|a public|%error}0 protocol " "uses " - "%select{a private|a fileprivate|an internal|%error|%error}1 type in its " + "%select{a private|a fileprivate|an internal|a package|%error|%error}1 type in its " "%select{default definition|requirement}2 ", (AccessLevel, AccessLevel, unsigned)) WARNING(associated_type_access_warn,none, "associated type in " - "%select{a private|a fileprivate|an internal|a public|%error}0 protocol uses " - "%select{a private|a fileprivate|an internal|%error|%error}1 type in its " + "%select{a private|a fileprivate|an internal|a package|a public|%error}0 protocol uses " + "%select{a private|a fileprivate|an internal|a package|%error|%error}1 type in its " "%select{default definition|requirement}2 ", (AccessLevel, AccessLevel, unsigned)) ERROR(associated_type_not_usable_from_inline,none, @@ -2559,8 +2559,8 @@ WARNING(append_interpolation_void_or_discardable,none, "'appendInterpolation' method does not return 'Void' or have a " "discardable result", ()) WARNING(append_interpolation_access_control,none, - "'appendInterpolation' method is %select{private|fileprivate|internal|" - "public|open}0, but %1 is %select{private|fileprivate|internal|public|" + "'appendInterpolation' method is %select{private|fileprivate|internal|package|" + "public|open}0, but %1 is %select{private|fileprivate|internal|package|public|" "open}2", (AccessLevel, DeclName, AccessLevel)) @@ -2671,18 +2671,18 @@ ERROR(associated_type_objc,none, ERROR(generic_param_access,none, "%0 %select{must be declared %select{" - "%select{private|fileprivate|internal|%error|%error}3|private or fileprivate}4" + "%select{private|fileprivate|internal|package|%error|%error}3|private or fileprivate}4" "|cannot be declared " - "%select{in this context|fileprivate|internal|public|open}2}1 " + "%select{in this context|fileprivate|internal|package|public|open}2}1 " "because its generic %select{parameter|requirement}5 uses " - "%select{a private|a fileprivate|an internal|an '@_spi'|an '@_spi'}3 type", + "%select{a private|a fileprivate|an internal|a package|an '@_spi'|an '@_spi'}3 type", (DescriptiveDeclKind, bool, AccessLevel, AccessLevel, bool, bool)) WARNING(generic_param_access_warn,none, "%0 %select{should be declared " - "%select{private|fileprivate|internal|%error|%error}3" - "|should not be declared %select{in this context|fileprivate|internal|public|open}2}1 " + "%select{private|fileprivate|internal|package|%error|%error}3" + "|should not be declared %select{in this context|fileprivate|internal|package|public|open}2}1 " "because its generic %select{parameter|requirement}5 uses " - "%select{a private|a fileprivate|an internal|an '@_spi'|an '@_spi'}3 type", + "%select{a private|a fileprivate|an internal|a package|an '@_spi'|an '@_spi'}3 type", (DescriptiveDeclKind, bool, AccessLevel, AccessLevel, bool, bool)) ERROR(generic_param_usable_from_inline,none, "type referenced from a " @@ -2923,12 +2923,12 @@ ERROR(inheritance_from_objc_runtime_visible_class,none, // Enums ERROR(enum_case_access,none, - "enum case in %select{a private|a fileprivate|an internal|a public|%error}0 enum " - "uses %select{a private|a fileprivate|an internal|%error|%error}1 type", + "enum case in %select{a private|a fileprivate|an internal|a package|a public|%error}0 enum " + "uses %select{a private|a fileprivate|an internal|a package|%error|%error}1 type", (AccessLevel, AccessLevel)) WARNING(enum_case_access_warn,none, - "enum case in %select{a private|a fileprivate|an internal|a public|%error}0 enum " - "uses %select{a private|a fileprivate|an internal|%error|%error}1 type", + "enum case in %select{a private|a fileprivate|an internal|a package|a public|%error}0 enum " + "uses %select{a private|a fileprivate|an internal|a package|%error|%error}1 type", (AccessLevel, AccessLevel)) ERROR(enum_case_usable_from_inline,none, "type of enum case in '@usableFromInline' enum " @@ -2957,18 +2957,18 @@ NOTE(enum_declares_rawrep_with_raw_type,none, "%0 declares raw type %1, which implies RawRepresentable", (Type, Type)) ERROR(enum_raw_type_access,none, "enum %select{must be declared %select{" - "%select{private|fileprivate|internal|%error|%error}1|private or fileprivate}3" + "%select{private|fileprivate|internal|package|%error|%error}1|private or fileprivate}3" "|cannot be declared " - "%select{in this context|fileprivate|internal|public|open}1}0 " + "%select{in this context|fileprivate|internal|package|public|open}1}0 " "because its raw type uses " - "%select{a private|a fileprivate|an internal|%error|%error}2 type", + "%select{a private|a fileprivate|an internal|a package|%error|%error}2 type", (bool, AccessLevel, AccessLevel, bool)) WARNING(enum_raw_type_access_warn,none, "enum %select{should be declared " - "%select{private|fileprivate|internal|%error|%error}1" - "|should not be declared %select{in this context|fileprivate|internal|public|open}1}0 " + "%select{private|fileprivate|internal|package|%error|%error}1" + "|should not be declared %select{in this context|fileprivate|internal|package|public|open}1}0 " "because its raw type uses " - "%select{a private|a fileprivate|an internal|%error|%error}2 type", + "%select{a private|a fileprivate|an internal|a package|%error|%error}2 type", (bool, AccessLevel, AccessLevel, bool)) ERROR(enum_raw_type_not_usable_from_inline,none, @@ -3186,7 +3186,7 @@ NOTE(decodable_super_init_not_designated_here,none, "cannot automatically synthesize %0 because implementation would need to call %1, which is not designated", (DeclName, DeclName)) NOTE(decodable_inaccessible_super_init_here,none, "cannot automatically synthesize %0 because implementation would need to call %1, which is inaccessible due to " - "'%select{private|fileprivate|internal|%error|%error}2' protection level", + "'%select{private|fileprivate|internal|package|%error|%error}2' protection level", (DeclName, DeclName, AccessLevel)) NOTE(decodable_super_init_is_failable_here,none, "cannot automatically synthesize %0 because implementation would need to call %1, which is failable", (DeclName, DeclName)) @@ -3270,11 +3270,11 @@ ERROR(attr_not_on_stored_properties,none, WARNING(attr_has_no_effect_on_decl_with_access_level,none, "'%0' does not have any effect on " - "%select{private|fileprivate|internal|%error|%error}1 declarations", + "%select{private|fileprivate|internal|package|%error|%error}1 declarations", (DeclAttribute, AccessLevel)) ERROR(attr_not_on_decl_with_invalid_access_level,none, "'%0' may not be used on " - "%select{private|fileprivate|internal|%error|%error}1 declarations", + "%select{private|fileprivate|internal|package|%error|%error}1 declarations", (DeclAttribute, AccessLevel)) ERROR(attr_has_no_effect_decl_not_available_before,none, @@ -3555,14 +3555,14 @@ NOTE(derivative_attr_duplicate_note,none, ERROR(derivative_attr_access_level_mismatch,none, "derivative function must have same access level as original function; " "derivative function %2 is " - "%select{private|fileprivate|internal|public|open}3, " + "%select{private|fileprivate|internal|package|public|open}3, " "but original function %0 is " - "%select{private|fileprivate|internal|public|open}1", + "%select{private|fileprivate|internal|package|public|open}1", (/*original*/ DeclName, /*original*/ AccessLevel, /*derivative*/ DeclName, /*derivative*/ AccessLevel)) NOTE(derivative_attr_fix_access,none, "mark the derivative function as " - "'%select{private|fileprivate|internal|@usableFromInline|@usableFromInline}0' " + "'%select{private|fileprivate|internal|package|@usableFromInline|@usableFromInline}0' " "to match the original function", (AccessLevel)) ERROR(derivative_attr_static_method_mismatch_original,none, "unexpected derivative function declaration; " @@ -5037,8 +5037,8 @@ ERROR(global_actor_non_final_class,none, ERROR(global_actor_top_level_var,none, "top-level code variables cannot have a global actor", ()) ERROR(global_actor_access,none, - "%select{private|fileprivate|internal|public|open}0 %1 %2 " - "cannot have %select{private|fileprivate|internal|%error|%error}3 " + "%select{private|fileprivate|internal|package|public|open}0 %1 %2 " + "cannot have %select{private|fileprivate|internal|package|%error|%error}3 " "global actor %4", (AccessLevel, DescriptiveDeclKind, DeclName, AccessLevel, DeclName)) ERROR(global_actor_not_usable_from_inline,none, @@ -5114,20 +5114,20 @@ ERROR(array_literal_intrinsics_not_found,none, "Array", ()) ERROR(class_super_access,none, "class %select{must be declared %select{" - "%select{private|fileprivate|internal|%error|%error}1|private or fileprivate}3" - "|cannot be declared %select{in this context|fileprivate|internal|public|open}1}0 " + "%select{private|fileprivate|internal|package|%error|%error}1|private or fileprivate}3" + "|cannot be declared %select{in this context|fileprivate|internal|package|public|open}1}0 " "because its superclass " - "%select{is %select{private|fileprivate|internal|'@_spi'|'@_spi'}2" - "|uses %select{a private|a fileprivate|an internal|an '@_spi'|an '@_spi'}2 " + "%select{is %select{private|fileprivate|internal|package|'@_spi'|'@_spi'}2" + "|uses %select{a private|a fileprivate|an internal|a package|an '@_spi'|an '@_spi'}2 " "type as a generic parameter}4", (bool, AccessLevel, AccessLevel, bool, bool)) WARNING(class_super_access_warn,none, "class %select{should be declared " - "%select{private|fileprivate|internal|%error|%error}1" - "|should not be declared %select{in this context|fileprivate|internal|public|open}1}0 " + "%select{private|fileprivate|internal|package|%error|%error}1" + "|should not be declared %select{in this context|fileprivate|internal|package|public|open}1}0 " "because its superclass " - "%select{is %select{private|fileprivate|internal|'@_spi'|'@_spi'}2" - "|uses %select{a private|a fileprivate|an internal|an '@_spi'|an '@_spi'}2 " + "%select{is %select{private|fileprivate|internal|package|'@_spi'|'@_spi'}2" + "|uses %select{a private|a fileprivate|an internal|a package|an '@_spi'|an '@_spi'}2 " "type as a generic parameter}4", (bool, AccessLevel, AccessLevel, bool, bool)) ERROR(class_super_not_usable_from_inline,none, @@ -5711,9 +5711,9 @@ ERROR(non_nominal_type_eraser,none, ERROR(type_eraser_does_not_conform,none, "type eraser %0 must conform to protocol %1", (Type, Type)) ERROR(type_eraser_not_accessible,none, - "%select{private|fileprivate|internal|public|open}0 type eraser %1 " + "%select{private|fileprivate|internal|package|public|open}0 type eraser %1 " "cannot have more restrictive access than protocol %2 " - "(which is %select{private|fileprivate|internal|public|open}3)", + "(which is %select{private|fileprivate|internal|package|public|open}3)", (AccessLevel, Identifier, Type, AccessLevel)) ERROR(type_eraser_missing_init,none, "type eraser %0 must have an initializer of the form " @@ -5730,9 +5730,9 @@ NOTE(type_eraser_init_unsatisfied_requirements,none, "'init(erasing:)' cannot have unsatisfied requirements " "when %0 = 'some %1'", (Type, StringRef)) NOTE(type_eraser_init_not_accessible,none, - "%select{private|fileprivate|internal|public|open}0 'init(erasing:)' " + "%select{private|fileprivate|internal|package|public|open}0 'init(erasing:)' " "cannot have more restrictive access than protocol %1 " - "(which is %select{private|fileprivate|internal|public|open}2)", + "(which is %select{private|fileprivate|internal|package|public|open}2)", (AccessLevel, Type, AccessLevel)) NOTE(type_eraser_init_spi,none, "'init(erasing:)' is SPI, but protocol %0 is not" @@ -5965,7 +5965,7 @@ WARNING(discardable_result_on_void_never_function, none, ERROR(fixed_layout_attr_on_internal_type, none, "'@_fixed_layout' attribute can only be applied to '@usableFromInline' " "or public declarations, but %0 is " - "%select{private|fileprivate|internal|%error|%error}1", + "%select{private|fileprivate|internal|package|%error|%error}1", (DeclName, AccessLevel)) WARNING(fixed_layout_struct, @@ -5974,7 +5974,7 @@ WARNING(fixed_layout_struct, ERROR(frozen_attr_on_internal_type, none, "'@frozen' attribute can only be applied to '@usableFromInline' " "or public declarations, but %0 is " - "%select{private|fileprivate|internal|%error|%error}1", + "%select{private|fileprivate|internal|package|%error|%error}1", (DeclName, AccessLevel)) ERROR(usable_from_inline_attr_with_explicit_access, @@ -6004,12 +6004,12 @@ ERROR(local_type_in_inlinable_function, (Identifier, unsigned)) ERROR(resilience_decl_unavailable, - none, DECL_OR_ACCESSOR "4 %1 is %select{private|fileprivate|internal|%error|%error}2 and " + none, DECL_OR_ACCESSOR "4 %1 is %select{private|fileprivate|internal|package|%error|%error}2 and " "cannot be referenced from " FRAGILE_FUNC_KIND "3", (DescriptiveDeclKind, DeclName, AccessLevel, unsigned, bool)) WARNING(resilience_decl_unavailable_warn, - none, DECL_OR_ACCESSOR "4 %1 is %select{private|fileprivate|internal|%error|%error}2 and " + none, DECL_OR_ACCESSOR "4 %1 is %select{private|fileprivate|internal|package|%error|%error}2 and " "should not be referenced from " FRAGILE_FUNC_KIND "3", (DescriptiveDeclKind, DeclName, AccessLevel, unsigned, bool)) @@ -6071,7 +6071,7 @@ ERROR(inlinable_dynamic_not_supported, ERROR(inlinable_decl_not_public, none, "'@inlinable' attribute can only be applied to public declarations, " - "but %0 is %select{private|fileprivate|internal|%error|%error}1", + "but %0 is %select{private|fileprivate|internal|package|%error|%error}1", (DeclBaseName, AccessLevel)) ERROR(inlinable_resilient_deinit, @@ -6240,9 +6240,9 @@ ERROR(property_wrapper_wrong_initial_value_init, none, ERROR(property_wrapper_failable_init, none, "property wrapper initializer %0 cannot be failable", (DeclName)) ERROR(property_wrapper_type_requirement_not_accessible,none, - "%select{private|fileprivate|internal|public|open}0 %1 %2 cannot have " + "%select{private|fileprivate|internal|package|public|open}0 %1 %2 cannot have " "more restrictive access than its enclosing property wrapper type %3 " - "(which is %select{private|fileprivate|internal|public|open}4)", + "(which is %select{private|fileprivate|internal|package|public|open}4)", (AccessLevel, DescriptiveDeclKind, DeclName, Type, AccessLevel)) ERROR(property_wrapper_ambiguous_enclosing_self_subscript, none, "property wrapper type %0 has multiple enclosing-self subscripts %1", @@ -6328,11 +6328,11 @@ ERROR(composed_property_wrapper_mismatch, none, ERROR(property_wrapper_type_access,none, "%select{%select{variable|constant}0|property}1 " "%select{must be declared %select{" - "%select{private|fileprivate|internal|%error|%error}3|private or fileprivate}4" + "%select{private|fileprivate|internal|package|%error|%error}3|private or fileprivate}4" "|cannot be declared " - "%select{in this context|fileprivate|internal|public|open}3}2 " + "%select{in this context|fileprivate|internal|package|public|open}3}2 " "because its property wrapper type uses " - "%select{a private|a fileprivate|an internal|%error|%error}5 type", + "%select{a private|a fileprivate|an internal|a package|%error|%error}5 type", (bool, bool, bool, AccessLevel, bool, AccessLevel)) ERROR(property_wrapper_type_not_usable_from_inline,none, "property wrapper type referenced from a '@usableFromInline' " @@ -6704,9 +6704,9 @@ ERROR(type_wrapper_subscript_invalid_keypath_parameter,none, (Identifier, Type)) ERROR(type_wrapper_type_requirement_not_accessible,none, - "%select{private|fileprivate|internal|public|open}0 %1 %2 cannot have " + "%select{private|fileprivate|internal|package|public|open}0 %1 %2 cannot have " "more restrictive access than its enclosing type wrapper type %3 " - "(which is %select{private|fileprivate|internal|public|open}4)", + "(which is %select{private|fileprivate|internal|package|public|open}4)", (AccessLevel, DescriptiveDeclKind, DeclName, Type, AccessLevel)) ERROR(type_wrapper_ignored_on_local_properties,none, @@ -6763,18 +6763,18 @@ ERROR(macro_error, none, "%1 (in macro %0)", (DeclName, StringRef)) ERROR(macro_type_access,none, "macro %select{must be declared " - "%select{private|fileprivate|internal|%error|%error}1" + "%select{private|fileprivate|internal|package|%error|%error}1" "|cannot be declared " - "%select{in this context|fileprivate|internal|public|open}1}0 " + "%select{in this context|fileprivate|internal|package|public|open}1}0 " "because its %select{parameter|result type}3 uses " - "%select{a private|a fileprivate|an internal|%error|%error}2 type", + "%select{a private|a fileprivate|an internal|a package|%error|%error}2 type", (bool, AccessLevel, AccessLevel, bool)) WARNING(macro_type_access_warn,none, "macro %select{should be declared " - "%select{private|fileprivate|internal|%error|%error}1" - "|should not be declared %select{in this context|fileprivate|internal|public|open}1}0 " + "%select{private|fileprivate|internal|package|%error|%error}1" + "|should not be declared %select{in this context|fileprivate|internal|package|public|open}1}0 " "because its %select{parameter|result type}3 uses " - "%select{a private|a fileprivate|an internal|%error|%error}2 type", + "%select{a private|a fileprivate|an internal|a package|%error|%error}2 type", (bool, AccessLevel, AccessLevel, bool)) ERROR(macro_in_nested,none, "macro %0 can only be declared at file scope", (DeclName)) From bf8f9a896ac494b2c60daf1070bfb06b7a25b4b0 Mon Sep 17 00:00:00 2001 From: Ellie Shin Date: Fri, 20 Jan 2023 00:44:56 -0800 Subject: [PATCH 4/4] Add missing package acl in diags --- include/swift/AST/DiagnosticsSema.def | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index 0099622efa36e..96005e1b2441e 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -6040,7 +6040,7 @@ ERROR(frozen_attr_on_internal_type, ERROR(usable_from_inline_attr_with_explicit_access, none, "'@usableFromInline' attribute can only be applied to internal " - "declarations, but %0 is %select{private|fileprivate|%error|public|open}1", + "declarations, but %0 is %select{private|fileprivate|%error|package|public|open}1", (DeclName, AccessLevel)) WARNING(inlinable_implies_usable_from_inline,none, @@ -6918,9 +6918,9 @@ ERROR(runtime_attribute_type_failable_init,none, "runtime attribute type initializer %0 cannot be failable", (DeclName)) ERROR(runtime_attribute_type_requirement_not_accessible,none, - "%select{private|fileprivate|internal|public|open}0 %1 %2 cannot have " + "%select{private|fileprivate|internal|package|public|open}0 %1 %2 cannot have " "more restrictive access than its enclosing runtime attribute type %3 " - "(which is %select{private|fileprivate|internal|public|open}4)", + "(which is %select{private|fileprivate|internal|package|public|open}4)", (AccessLevel, DescriptiveDeclKind, DeclName, Type, AccessLevel))