Skip to content

Commit d2cf701

Browse files
committed
AST: Remove Swift 3 access control checking
1 parent e178bf2 commit d2cf701

File tree

4 files changed

+14
-97
lines changed

4 files changed

+14
-97
lines changed

include/swift/AST/AccessScopeChecker.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,15 @@ class TypeReprAccessScopeChecker : private ASTWalker, AccessScopeChecker {
5555
};
5656

5757
class TypeAccessScopeChecker : private TypeWalker, AccessScopeChecker {
58-
bool CanonicalizeParentTypes;
59-
6058
TypeAccessScopeChecker(const DeclContext *useDC,
61-
bool treatUsableFromInlineAsPublic,
62-
bool canonicalizeParentTypes);
59+
bool treatUsableFromInlineAsPublic);
6360

6461
Action walkToTypePre(Type T);
6562

6663
public:
6764
static Optional<AccessScope>
6865
getAccessScope(Type T, const DeclContext *useDC,
69-
bool treatUsableFromInlineAsPublic = false,
70-
bool canonicalizeParentTypes = false);
66+
bool treatUsableFromInlineAsPublic = false);
7167
};
7268

7369
}

lib/AST/AccessScopeChecker.cpp

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,14 @@ TypeReprAccessScopeChecker::getAccessScope(TypeRepr *TR, const DeclContext *useD
6363
}
6464

6565
TypeAccessScopeChecker::TypeAccessScopeChecker(const DeclContext *useDC,
66-
bool treatUsableFromInlineAsPublic,
67-
bool canonicalizeParentTypes)
68-
: AccessScopeChecker(useDC, treatUsableFromInlineAsPublic),
69-
CanonicalizeParentTypes(canonicalizeParentTypes) {}
66+
bool treatUsableFromInlineAsPublic)
67+
: AccessScopeChecker(useDC, treatUsableFromInlineAsPublic) {}
7068

7169
TypeWalker::Action
7270
TypeAccessScopeChecker::walkToTypePre(Type T) {
7371
ValueDecl *VD;
74-
if (auto *BNAD = dyn_cast<NameAliasType>(T.getPointer())) {
75-
if (CanonicalizeParentTypes &&
76-
BNAD->getDecl()->getUnderlyingTypeLoc().getType()->hasTypeParameter())
77-
VD = nullptr;
78-
else
79-
VD = BNAD->getDecl();
80-
}
72+
if (auto *BNAD = dyn_cast<NameAliasType>(T.getPointer()))
73+
VD = BNAD->getDecl();
8174
else if (auto *NTD = T->getAnyNominal())
8275
VD = NTD;
8376
else
@@ -86,39 +79,13 @@ TypeAccessScopeChecker::walkToTypePre(Type T) {
8679
if (!visitDecl(VD))
8780
return Action::Stop;
8881

89-
if (!CanonicalizeParentTypes) {
90-
return Action::Continue;
91-
}
92-
93-
Type nominalParentTy;
94-
if (auto nominalTy = dyn_cast<NominalType>(T.getPointer())) {
95-
nominalParentTy = nominalTy->getParent();
96-
} else if (auto genericTy = dyn_cast<BoundGenericType>(T.getPointer())) {
97-
nominalParentTy = genericTy->getParent();
98-
for (auto genericArg : genericTy->getGenericArgs())
99-
genericArg.walk(*this);
100-
} else if (auto NameAliasTy =
101-
dyn_cast<NameAliasType>(T.getPointer())) {
102-
// The parent type would have been lost previously, so look right through
103-
// this type.
104-
if (NameAliasTy->getDecl()->getUnderlyingTypeLoc().getType()
105-
->hasTypeParameter())
106-
Type(NameAliasTy->getSinglyDesugaredType()).walk(*this);
107-
} else {
108-
return Action::Continue;
109-
}
110-
111-
if (nominalParentTy)
112-
nominalParentTy->getCanonicalType().walk(*this);
113-
return Action::SkipChildren;
82+
return Action::Continue;
11483
}
11584

11685
Optional<AccessScope>
11786
TypeAccessScopeChecker::getAccessScope(Type T, const DeclContext *useDC,
118-
bool treatUsableFromInlineAsPublic,
119-
bool canonicalizeParentTypes) {
120-
TypeAccessScopeChecker checker(useDC, treatUsableFromInlineAsPublic,
121-
canonicalizeParentTypes);
87+
bool treatUsableFromInlineAsPublic) {
88+
TypeAccessScopeChecker checker(useDC, treatUsableFromInlineAsPublic);
12289
T.walk(checker);
12390
return checker.Scope;
12491
}

lib/AST/DeclContext.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -780,9 +780,6 @@ IterableDeclContext::castDeclToIterableDeclContext(const Decl *D) {
780780
/// declaration or extension, the supplied context is returned.
781781
static const DeclContext *
782782
getPrivateDeclContext(const DeclContext *DC, const SourceFile *useSF) {
783-
if (DC->getASTContext().isSwiftVersion3())
784-
return DC;
785-
786783
auto NTD = DC->getSelfNominalTypeDecl();
787784
if (!NTD)
788785
return DC;
@@ -834,10 +831,6 @@ bool AccessScope::allowsPrivateAccess(const DeclContext *useDC, const DeclContex
834831
if (useDC->isChildContextOf(sourceDC))
835832
return true;
836833

837-
// Only check lexical scope in Swift 3 mode
838-
if (useDC->getASTContext().isSwiftVersion3())
839-
return false;
840-
841834
// Do not allow access if the sourceDC is in a different file
842835
auto useSF = useDC->getParentSourceFile();
843836
if (useSF != sourceDC->getParentSourceFile())

lib/Sema/TypeCheckAccess.cpp

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -182,53 +182,14 @@ void AccessControlCheckerBase::checkTypeAccessImpl(
182182
if (!typeAccessScope.hasValue())
183183
return;
184184

185-
auto shouldComplainAboutAccessScope =
186-
[contextAccessScope](AccessScope scope) -> bool {
187-
if (scope.isPublic())
188-
return false;
189-
if (scope.hasEqualDeclContextWith(contextAccessScope))
190-
return false;
191-
if (contextAccessScope.isChildOf(scope))
192-
return false;
193-
return true;
194-
};
195-
196-
if (!shouldComplainAboutAccessScope(typeAccessScope.getValue()))
185+
if (typeAccessScope->isPublic())
186+
return;
187+
if (typeAccessScope->hasEqualDeclContextWith(contextAccessScope))
188+
return;
189+
if (contextAccessScope.isChildOf(*typeAccessScope))
197190
return;
198191

199192
auto downgradeToWarning = DowngradeToWarning::No;
200-
if (!checkUsableFromInline) {
201-
// Swift 3.0 wasn't nearly as strict as checking types because it didn't
202-
// look at the TypeRepr at all except to highlight a particular part of the
203-
// type in diagnostics, and looked through typealiases in other cases.
204-
// Approximate this behavior by running our non-TypeRepr-based check again
205-
// and downgrading to a warning when the checks disagree.
206-
if (TC.getLangOpts().isSwiftVersion3()) {
207-
auto typeOnlyAccessScope =
208-
TypeAccessScopeChecker::getAccessScope(
209-
type, useDC,
210-
/*treatUsableFromInlineAsPublic*/false,
211-
/*canonicalizeParents*/true);
212-
if (typeOnlyAccessScope.hasValue()) {
213-
// If Swift 4 would have complained about a private type, but Swift 4
214-
// would only diagnose an internal type, complain about the Swift 3
215-
// offense first to avoid confusing users.
216-
if (shouldComplainAboutAccessScope(typeOnlyAccessScope.getValue()))
217-
typeAccessScope = typeOnlyAccessScope;
218-
else
219-
downgradeToWarning = DowngradeToWarning::Yes;
220-
}
221-
}
222-
223-
// Swift 3.0.0 mistakenly didn't diagnose any issues when the context
224-
// access scope represented a private or fileprivate level.
225-
if (!contextAccessScope.isPublic() &&
226-
!isa<ModuleDecl>(contextAccessScope.getDeclContext()) &&
227-
TC.getLangOpts().isSwiftVersion3()) {
228-
downgradeToWarning = DowngradeToWarning::Yes;
229-
}
230-
}
231-
232193
const TypeRepr *complainRepr =
233194
TypeAccessScopeDiagnoser::findTypeWithScope(
234195
typeRepr,

0 commit comments

Comments
 (0)