Skip to content

Commit 0b0d7dc

Browse files
committed
Sema: Remove most of the remaining Swift 3 support
1 parent d488509 commit 0b0d7dc

16 files changed

+30
-132
lines changed

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/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/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()),

lib/Sema/TypeCheckPattern.cpp

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -539,16 +539,11 @@ class ResolvePattern : public ASTVisitor<ResolvePattern,
539539
// then required to have keywords for every argument that name properties
540540
// of the type.
541541
Pattern *visitCallExpr(CallExpr *ce) {
542-
if (!TC.Context.isSwiftVersion3()) {
543-
// swift(>=4) mode.
544-
// Specialized call are not allowed anyway.
545-
// Let it be diagnosed as an expression.
546-
// For Swift3 mode, we emit warnings just before constructing the
547-
// enum-element-pattern below.
548-
if (isa<UnresolvedSpecializeExpr>(ce->getFn()))
549-
return nullptr;
550-
}
551-
542+
// Specialized call are not allowed anyway.
543+
// Let it be diagnosed as an expression.
544+
if (isa<UnresolvedSpecializeExpr>(ce->getFn()))
545+
return nullptr;
546+
552547
SmallVector<ComponentIdentTypeRepr *, 2> components;
553548
if (!ExprToIdentTypeRepr(components, TC.Context).visit(ce->getFn()))
554549
return nullptr;
@@ -597,19 +592,8 @@ class ResolvePattern : public ASTVisitor<ResolvePattern,
597592
loc.setType(enumTy);
598593
}
599594

600-
if (auto generic = dyn_cast<GenericIdentTypeRepr>(tailComponent)) {
601-
assert(TC.Context.isSwiftVersion3() && "should be handled above");
602-
603-
// Swift3 used to ignore the last generic argument clause:
604-
// EnumTy.CaseVal<SomeType>()
605-
// used to be wrongfully converted to
606-
// (pattern_enum_element type='EnumTy' EnumTy.CaseVal
607-
// (pattern_tuple type='()' names=))
608-
// To keep source compatibility, just emit a warning with fix-it.
609-
TC.diagnose(generic->getAngleBrackets().Start,
610-
diag::swift3_ignore_specialized_enum_element_call)
611-
.fixItRemove(generic->getAngleBrackets());
612-
}
595+
assert(!isa<GenericIdentTypeRepr>(tailComponent) &&
596+
"should be handled above");
613597

614598
auto *subPattern = getSubExprPattern(ce->getArg());
615599
return new (TC.Context) EnumElementPattern(loc,
@@ -1451,7 +1435,7 @@ bool TypeChecker::coercePatternToType(Pattern *&P, TypeResolution resolution,
14511435
validateDeclForNameLookup(elt);
14521436
if (EEP->hasSubPattern()) {
14531437
Pattern *sub = EEP->getSubPattern();
1454-
if (!Context.isSwiftVersion3() && !elt->hasAssociatedValues()) {
1438+
if (!elt->hasAssociatedValues()) {
14551439
diagnose(EEP->getLoc(),
14561440
diag::enum_element_pattern_assoc_values_mismatch,
14571441
EEP->getName());

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4713,10 +4713,8 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
47134713
if (kind && getLangOpts().EnableNSKeyedArchiverDiagnostics &&
47144714
isa<NormalProtocolConformance>(conformance) &&
47154715
!hasExplicitObjCName(classDecl)) {
4716-
bool emitWarning = Context.LangOpts.isSwiftVersion3();
47174716
diagnose(cast<NormalProtocolConformance>(conformance)->getLoc(),
4718-
emitWarning ? diag::nscoding_unstable_mangled_name_warn
4719-
: diag::nscoding_unstable_mangled_name,
4717+
diag::nscoding_unstable_mangled_name,
47204718
static_cast<unsigned>(kind.getValue()),
47214719
classDecl->getDeclaredInterfaceType());
47224720
auto insertionLoc =

lib/Sema/TypeCheckType.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,13 +1477,6 @@ static bool diagnoseAvailability(IdentTypeRepr *IdType,
14771477
auto componentRange = IdType->getComponentRange();
14781478
for (auto comp : componentRange) {
14791479
if (auto *typeDecl = comp->getBoundDecl()) {
1480-
// In Swift 3, components other than the last one were not properly
1481-
// checked for availability.
1482-
// FIXME: We should try to downgrade these errors to warnings, not just
1483-
// skip diagnosing them.
1484-
if (ctx.LangOpts.isSwiftVersion3() && comp != componentRange.back())
1485-
continue;
1486-
14871480
// FIXME: Need to eliminate the type checker argument.
14881481
TypeChecker &tc = static_cast<TypeChecker &>(*ctx.getLazyResolver());
14891482
if (diagnoseDeclAvailability(typeDecl, tc, DC, comp->getIdLoc(),

test/Interpreter/SDK/archive_compatibility.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-build-swift %s -module-name=test -o %t/a.out -swift-version 3
2+
// RUN: %target-build-swift %s -module-name=test -o %t/a.out
33
// RUN: %target-codesign %t/a.out
44
// RUN: %target-run %t/a.out %S/Inputs/test.arc | %FileCheck %s
55

@@ -14,6 +14,7 @@
1414
import Foundation
1515

1616
struct ABC {
17+
@objc(_TtCV4test3ABC11NestedClass)
1718
class NestedClass : NSObject, NSCoding {
1819
var i : Int
1920

@@ -31,6 +32,7 @@ struct ABC {
3132
}
3233
}
3334

35+
@objc(_TtC4testP33_25D299289FEB01A726765440D53BD3D112PrivateClass)
3436
private class PrivateClass : NSObject, NSCoding {
3537
var pi : Int
3638

test/Runtime/demangleToMetadataObjC.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-run-simple-swift-swift3
1+
// RUN: %target-run-simple-swift
22
// REQUIRES: executable_test
33
// REQUIRES: objc_interop
44

@@ -60,7 +60,7 @@ DemangleToMetadataTests.test("Imported swift_wrapper types") {
6060
}
6161

6262
DemangleToMetadataTests.test("Imported enum types") {
63-
expectEqual(NSURLSessionTask.State.self,
63+
expectEqual(URLSessionTask.State.self,
6464
_typeByMangledName("So21NSURLSessionTaskStateV")!)
6565
}
6666

test/SILGen/Inputs/usr/include/BridgeTestFoundation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ typedef NSString *NSErrorDomain;
2424
@end
2525

2626
@interface NSDictionary<KeyType, ValueType> : NSObject
27+
28+
+ (void) classMethod;
29+
2730
@end
2831

2932
@interface NSSet<ObjectType> : NSObject
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
// RUN: %target-swift-emit-silgen -sdk %S/Inputs -I %S/Inputs -enable-source-import %s -enable-objc-interop -swift-version 3 | %FileCheck %s
1+
// RUN: %target-swift-emit-silgen -sdk %S/Inputs -I %S/Inputs -enable-source-import %s -enable-objc-interop | %FileCheck %s
2+
// RUN: %target-swift-emit-sil -O -sdk %S/Inputs -I %S/Inputs -enable-source-import %s -enable-objc-interop
23

34
import Foundation
45
class MyFunkyDictionary: NSDictionary {
5-
// CHECK-LABEL: sil hidden @$s23super_objc_class_method17MyFunkyDictionaryC10initializeyyFZ
6-
// CHECK: objc_super_method %0 : $@thick MyFunkyDictionary.Type, #NSObject.initialize!1.foreign : (NSObject.Type) -> () -> ()
7-
override class func initialize() {
8-
super.initialize()
6+
// CHECK-LABEL: sil hidden @$s23super_objc_class_method17MyFunkyDictionaryC0C6MethodyyFZ : $@convention(method) (@thick MyFunkyDictionary.Type) -> ()
7+
// CHECK: objc_super_method %0 : $@thick MyFunkyDictionary.Type, #NSDictionary.classMethod!1.foreign : (NSDictionary.Type) -> () -> ()
8+
override class func classMethod() {
9+
super.classMethod()
910
}
1011
}
1112

test/SILOptimizer/super_objc_class_method.swift

Lines changed: 0 additions & 14 deletions
This file was deleted.

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3093,8 +3093,7 @@ int main(int argc, char *argv[]) {
30933093
InitInvok.getLangOptions().InferImportAsMember |=
30943094
options::InferImportAsMember;
30953095
InitInvok.getLangOptions().EnableSwift3ObjCInference =
3096-
options::EnableSwift3ObjCInference ||
3097-
InitInvok.getLangOptions().isSwiftVersion3();
3096+
options::EnableSwift3ObjCInference;
30983097
InitInvok.getClangImporterOptions().ImportForwardDeclarations |=
30993098
options::ObjCForwardDeclarations;
31003099
InitInvok.getClangImporterOptions().InferImportAsMember |=

0 commit comments

Comments
 (0)