Skip to content

Commit b6bfb8d

Browse files
authored
Merge pull request #19750 from slavapestov/remove-swift-3
Remove some more Swift 3 compatibility hacks
2 parents 2b95449 + 0b0d7dc commit b6bfb8d

23 files changed

+50
-242
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
}

include/swift/AST/DiagnosticsParse.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,9 +1480,6 @@ ERROR(where_without_generic_params,none,
14801480
"'where' clause cannot be attached to "
14811481
"%select{a non-generic|a protocol|an associated type}0 "
14821482
"declaration", (unsigned))
1483-
WARNING(swift3_where_inside_brackets,none,
1484-
"'where' clause next to generic parameters is deprecated "
1485-
"and will be removed in the future version of Swift", ())
14861483
ERROR(where_inside_brackets,none,
14871484
"'where' clause next to generic parameters is obsolete, "
14881485
"must be written following the declaration's type", ())

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,10 +1370,6 @@ ERROR(nscoding_unstable_mangled_name,none,
13701370
"%select{private|fileprivate|nested|local}0 class %1 has an "
13711371
"unstable name when archiving via 'NSCoding'",
13721372
(unsigned, Type))
1373-
WARNING(nscoding_unstable_mangled_name_warn,none,
1374-
"%select{private|fileprivate|nested|local}0 class %1 has an "
1375-
"unstable name when archiving via 'NSCoding'",
1376-
(unsigned, Type))
13771373
NOTE(unstable_mangled_name_add_objc_new,none,
13781374
"for new classes, use '@objc' to specify a unique, prefixed Objective-C "
13791375
"runtime name", ())
@@ -1626,10 +1622,6 @@ ERROR(requirement_restricts_self,none,
16261622
"%0 requirement %1 cannot add constraint '%2%select{:|:| ==|:}3 %4' on "
16271623
"'Self'",
16281624
(DescriptiveDeclKind, DeclName, StringRef, unsigned, StringRef))
1629-
WARNING(requirement_restricts_self_swift3,none,
1630-
"adding constraint '%2%select{:|:| ==|:}3 %4' on 'Self' via %0 "
1631-
"requirement %1 is deprecated in Swift 3",
1632-
(DescriptiveDeclKind, DeclName, StringRef, unsigned, StringRef))
16331625
ERROR(witness_argument_name_mismatch,none,
16341626
"%select{method|initializer}0 %1 has different argument labels from those "
16351627
"required by protocol %2 (%3)", (bool, DeclName, Type, DeclName))
@@ -2150,9 +2142,6 @@ ERROR(override_dynamic_self_mismatch,none,
21502142
ERROR(override_class_declaration_in_extension,none,
21512143
"cannot override a non-dynamic class declaration from an extension",
21522144
())
2153-
WARNING(override_class_declaration_in_extension_warning,none,
2154-
"cannot override a non-dynamic class declaration from an extension",
2155-
())
21562145
ERROR(override_throws,none,
21572146
"cannot override non-throwing %select{method|initializer}0 with "
21582147
"throwing %select{method|initializer}0", (bool))
@@ -2250,8 +2239,6 @@ ERROR(inheritance_from_cf_class,none,
22502239
ERROR(inheritance_from_objc_runtime_visible_class,none,
22512240
"cannot inherit from class %0 because it is only visible via the "
22522241
"Objective-C runtime", (Identifier))
2253-
WARNING(class_inherits_anyobject,none,
2254-
"conformance of class %0 to 'AnyObject' is redundant", (Type))
22552242

22562243
// Enums
22572244
ERROR(enum_case_access,none,
@@ -2343,9 +2330,6 @@ NOTE(construct_raw_representable_from_unwrapped_value,none,
23432330
"construct %0 from unwrapped %1 value", (Type, Type))
23442331

23452332
// Derived conformances
2346-
ERROR(swift3_cannot_synthesize_in_extension,none,
2347-
"implementation of %0 cannot be automatically synthesized in an extension "
2348-
"in Swift 3", (Type))
23492333
ERROR(cannot_synthesize_init_in_extension_of_nonfinal,none,
23502334
"implementation of %0 for non-final class cannot be automatically "
23512335
"synthesized in extension because initializer requirement %1 can only be "
@@ -2490,9 +2474,6 @@ ERROR(override_static,none,
24902474
ERROR(member_cannot_be_final,none,
24912475
"only classes and class members may be marked with 'final'",
24922476
())
2493-
WARNING(protocol_extension_cannot_be_final,none,
2494-
"functions in a protocol extension do not need to be marked with 'final'",
2495-
())
24962477

24972478
ERROR(final_not_allowed_here,none,
24982479
"'final' may only be applied to classes, properties, methods, and "
@@ -3303,10 +3284,6 @@ ERROR(isa_collection_downcast_pattern_value_unimplemented,none,
33033284
"collection downcast in cast pattern is not implemented; use an explicit "
33043285
"downcast to %0 instead", (Type))
33053286

3306-
WARNING(swift3_ignore_specialized_enum_element_call,none,
3307-
"cannot specialize enum case; ignoring generic argument, "
3308-
"which will be rejected in future version of Swift", ())
3309-
33103287
//------------------------------------------------------------------------------
33113288
// MARK: Error-handling diagnostics
33123289
//------------------------------------------------------------------------------
@@ -3809,11 +3786,6 @@ ERROR(objc_class_method_not_permitted,none,
38093786
OBJC_DIAG_SELECT " defines Objective-C class method %2, which is "
38103787
"not permitted by Swift", (unsigned, DeclName, ObjCSelector))
38113788

3812-
WARNING(objc_class_method_not_permitted_swift3_compat_warning,none,
3813-
OBJC_DIAG_SELECT " defines Objective-C class method %2, which is "
3814-
"not guaranteed to be invoked by Swift and will be disallowed in future "
3815-
"versions", (unsigned, DeclName, ObjCSelector))
3816-
38173789
ERROR(objc_witness_selector_mismatch,none,
38183790
"Objective-C method %2 provided by " OBJC_DIAG_SELECT
38193791
" does not match the requirement's selector (%3)",

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/Parse/ParseGeneric.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,8 @@ Parser::diagnoseWhereClauseInGenericParamList(const GenericParamList *
225225
if (Tok.is(tok::kw_where))
226226
WhereClauseText << ',';
227227

228-
// For Swift 3, keep this warning.
229-
const auto Message = Context.isSwiftVersion3()
230-
? diag::swift3_where_inside_brackets
231-
: diag::where_inside_brackets;
232-
233-
auto Diag = diagnose(WhereRangeInsideBrackets.Start, Message);
228+
auto Diag = diagnose(WhereRangeInsideBrackets.Start,
229+
diag::where_inside_brackets);
234230

235231
Diag.fixItRemoveChars(RemoveWhereRange.getStart(),
236232
RemoveWhereRange.getEnd());

lib/Sema/DerivedConformances.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -360,19 +360,6 @@ bool DerivedConformance::checkAndDiagnoseDisallowedContext(
360360
allowCrossfileExtensions = ED && ED->hasOnlyCasesWithoutAssociatedValues();
361361
}
362362

363-
if (TC.Context.isSwiftVersion3()) {
364-
// In Swift 3, a 'private' property can't be accessed in any extensions, so
365-
// we can't synthesize anything that uses them. Thus, we stick to the old
366-
// rule for synthesis, which is never in an extension except for the
367-
// Equatable/Hashable cases mentioned above.
368-
if (!allowCrossfileExtensions && Nominal != ConformanceDecl) {
369-
TC.diagnose(ConformanceDecl->getLoc(),
370-
diag::swift3_cannot_synthesize_in_extension,
371-
getProtocolType());
372-
return true;
373-
}
374-
}
375-
376363
if (!allowCrossfileExtensions &&
377364
Nominal->getModuleScopeContext() !=
378365
getConformanceContext()->getModuleScopeContext()) {

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,

lib/Sema/TypeCheckAttr.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,8 @@ class AttributeEarlyChecker : public AttributeVisitor<AttributeEarlyChecker> {
213213
// 'final' only makes sense in the context of a class declaration.
214214
// Reject it on global functions, protocols, structs, enums, etc.
215215
if (!D->getDeclContext()->getSelfClassDecl()) {
216-
if (TC.Context.isSwiftVersion3() &&
217-
D->getDeclContext()->getExtendedProtocolDecl())
218-
TC.diagnose(attr->getLocation(),
219-
diag::protocol_extension_cannot_be_final)
220-
.fixItRemove(attr->getRange());
221-
else
222-
TC.diagnose(attr->getLocation(), diag::member_cannot_be_final)
223-
.fixItRemove(attr->getRange());
216+
TC.diagnose(attr->getLocation(), diag::member_cannot_be_final)
217+
.fixItRemove(attr->getRange());
224218

225219
// Remove the attribute so child declarations are not flagged as final
226220
// and duplicate the error message.

lib/Sema/TypeCheckDecl.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -383,18 +383,6 @@ static void checkInheritanceClause(
383383
if (!inheritedTy)
384384
continue;
385385
}
386-
387-
// Swift 3 compatibility -- a class inheriting from AnyObject is a no-op.
388-
if (ctx.LangOpts.isSwiftVersion3() && isa<ClassDecl>(decl) &&
389-
inheritedTy->isAnyObject()) {
390-
auto classDecl = cast<ClassDecl>(decl);
391-
auto removeRange = getRemovalRange(i);
392-
diags.diagnose(inherited.getSourceRange().Start,
393-
diag::class_inherits_anyobject,
394-
classDecl->getDeclaredInterfaceType())
395-
.fixItRemoveChars(removeRange.Start, removeRange.End);
396-
continue;
397-
}
398386
}
399387

400388
// If this is an enum inheritance clause, check for a raw type.

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,13 +1584,8 @@ void markAsObjC(ValueDecl *D, ObjCReason reason,
15841584
// Swift 3 and earlier allowed you to override `initialize`, but
15851585
// Swift's semantics do not guarantee that it will be called at
15861586
// the point you expect. It is disallowed in Swift 4 and later.
1587-
if (sel.getSelectorPieces().front() == ctx.Id_initialize) {
1588-
if (ctx.LangOpts.isSwiftVersion3())
1589-
return
1590-
diag::objc_class_method_not_permitted_swift3_compat_warning;
1591-
else
1592-
return diag::objc_class_method_not_permitted;
1593-
}
1587+
if (sel.getSelectorPieces().front() == ctx.Id_initialize)
1588+
return diag::objc_class_method_not_permitted;
15941589
return None;
15951590
case 1:
15961591
if (sel.getSelectorPieces().front() == ctx.Id_allocWithZone)

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,9 +1560,7 @@ static bool checkSingleOverride(ValueDecl *override, ValueDecl *base) {
15601560
!base->isDynamic() &&
15611561
override->getDeclContext()->isExtensionContext()) {
15621562
// For compatibility, only generate a warning in Swift 3
1563-
diags.diagnose(override, (ctx.isSwiftVersion3()
1564-
? diag::override_class_declaration_in_extension_warning
1565-
: diag::override_class_declaration_in_extension));
1563+
diags.diagnose(override, diag::override_class_declaration_in_extension);
15661564
diags.diagnose(base, diag::overridden_here);
15671565
}
15681566
}

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,7 @@ void TypeChecker::checkProtocolSelfRequirements(ValueDecl *decl) {
263263
continue;
264264

265265
diagnose(decl,
266-
Context.isSwiftVersion3()
267-
? diag::requirement_restricts_self_swift3
268-
: diag::requirement_restricts_self,
266+
diag::requirement_restricts_self,
269267
decl->getDescriptiveKind(), decl->getFullName(),
270268
req.getFirstType().getString(),
271269
static_cast<unsigned>(req.getKind()),

0 commit comments

Comments
 (0)