Skip to content

Commit 0a1d52e

Browse files
author
Brian King
committed
Update the language and method names to avoid the term 'shared private'
1 parent b3d44e0 commit 0a1d52e

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

include/swift/AST/AccessScope.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ class AccessScope {
3030

3131
static AccessScope getPublic() { return AccessScope(nullptr); }
3232

33-
/// Perform the shared private access check. Private scope is shared between
34-
/// the declaration and all of the extensions of that type inside the file.
35-
/// This will return false in Swift 3 mode because private is not shared
36-
/// between types.
37-
static bool checkSharedPrivateAccess(const DeclContext *useDC, const DeclContext *sourceDC);
33+
/// Check if private access is allowed. This is a lexical scope check in Swift
34+
/// 3 mode. In Swift 4 mode, declarations and extensions of the same type will
35+
/// also allow access.
36+
static bool allowsPrivateAccess(const DeclContext *useDC, const DeclContext *sourceDC);
3837

3938
/// Returns nullptr if access scope is public.
4039
const DeclContext *getDeclContext() const { return Value.getPointer(); }
@@ -54,8 +53,7 @@ class AccessScope {
5453
/// \see DeclContext::isChildContextOf
5554
bool isChildOf(AccessScope AS) const {
5655
if (!isPublic() && !AS.isPublic())
57-
return (getDeclContext()->isChildContextOf(AS.getDeclContext()) ||
58-
checkSharedPrivateAccess(getDeclContext(), AS.getDeclContext()));
56+
return allowsPrivateAccess(getDeclContext(), AS.getDeclContext());
5957
if (isPublic() && AS.isPublic())
6058
return false;
6159
return AS.isPublic();

lib/AST/DeclContext.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -970,13 +970,13 @@ Accessibility AccessScope::accessibilityForDiagnostics() const {
970970
return Accessibility::Private;
971971
}
972972

973-
/// Return the DeclContext to compare when checking shared private access in
974-
/// Swift 4 mode. The shared scope is the type declaration if the context
973+
/// Return the DeclContext to compare when checking private access in
974+
/// Swift 4 mode. The context returned is the type declaration if the context
975975
/// and the type declaration are in the same file, otherwise it is the types
976976
/// last extension in the source file. If the context does not refer to a
977977
/// declaration or extension, the supplied context is returned.
978978
static const DeclContext *
979-
getSharedPrivateDeclContext(const DeclContext *DC, const SourceFile *useSF) {
979+
getPrivateDeclContext(const DeclContext *DC, const SourceFile *useSF) {
980980
auto NTD = DC->getAsNominalTypeOrNominalTypeExtensionContext();
981981
if (!NTD)
982982
return DC;
@@ -996,8 +996,12 @@ getSharedPrivateDeclContext(const DeclContext *DC, const SourceFile *useSF) {
996996
return lastExtension ? lastExtension : DC;
997997
}
998998

999-
bool AccessScope::checkSharedPrivateAccess(const DeclContext *useDC, const DeclContext *sourceDC) {
1000-
// Shared private scope is not performed in Swift 3 mode.
999+
bool AccessScope::allowsPrivateAccess(const DeclContext *useDC, const DeclContext *sourceDC) {
1000+
// Check the lexical scope.
1001+
if (useDC->isChildContextOf(sourceDC))
1002+
return true;
1003+
1004+
// Only check lexical scope in Swift 3 mode
10011005
if (useDC->getASTContext().isSwiftVersion3())
10021006
return false;
10031007

@@ -1008,10 +1012,10 @@ bool AccessScope::checkSharedPrivateAccess(const DeclContext *useDC, const DeclC
10081012
if (useSF != sourceDC->getParentSourceFile() || !sourceNTD)
10091013
return false;
10101014

1011-
// Compare the shared private scopes and iterate over the parent types.
1012-
sourceDC = getSharedPrivateDeclContext(sourceDC, useSF);
1015+
// Compare the private scopes and iterate over the parent types.
1016+
sourceDC = getPrivateDeclContext(sourceDC, useSF);
10131017
while (!useDC->isModuleContext()) {
1014-
useDC = getSharedPrivateDeclContext(useDC, useSF);
1018+
useDC = getPrivateDeclContext(useDC, useSF);
10151019
if (useDC == sourceDC)
10161020
return true;
10171021

lib/AST/NameLookup.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,8 +1263,7 @@ static bool checkAccessibility(const DeclContext *useDC,
12631263
switch (access) {
12641264
case Accessibility::Private:
12651265
return (useDC == sourceDC ||
1266-
useDC->isChildContextOf(sourceDC) ||
1267-
AccessScope::checkSharedPrivateAccess(useDC, sourceDC));
1266+
AccessScope::allowsPrivateAccess(useDC, sourceDC));
12681267
case Accessibility::FilePrivate:
12691268
return useDC->getModuleScopeContext() == sourceDC->getModuleScopeContext();
12701269
case Accessibility::Internal: {

0 commit comments

Comments
 (0)