mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Sema: Remove most of the remaining Swift 3 support
This commit is contained in:
@@ -1370,10 +1370,6 @@ ERROR(nscoding_unstable_mangled_name,none,
|
||||
"%select{private|fileprivate|nested|local}0 class %1 has an "
|
||||
"unstable name when archiving via 'NSCoding'",
|
||||
(unsigned, Type))
|
||||
WARNING(nscoding_unstable_mangled_name_warn,none,
|
||||
"%select{private|fileprivate|nested|local}0 class %1 has an "
|
||||
"unstable name when archiving via 'NSCoding'",
|
||||
(unsigned, Type))
|
||||
NOTE(unstable_mangled_name_add_objc_new,none,
|
||||
"for new classes, use '@objc' to specify a unique, prefixed Objective-C "
|
||||
"runtime name", ())
|
||||
@@ -1626,10 +1622,6 @@ ERROR(requirement_restricts_self,none,
|
||||
"%0 requirement %1 cannot add constraint '%2%select{:|:| ==|:}3 %4' on "
|
||||
"'Self'",
|
||||
(DescriptiveDeclKind, DeclName, StringRef, unsigned, StringRef))
|
||||
WARNING(requirement_restricts_self_swift3,none,
|
||||
"adding constraint '%2%select{:|:| ==|:}3 %4' on 'Self' via %0 "
|
||||
"requirement %1 is deprecated in Swift 3",
|
||||
(DescriptiveDeclKind, DeclName, StringRef, unsigned, StringRef))
|
||||
ERROR(witness_argument_name_mismatch,none,
|
||||
"%select{method|initializer}0 %1 has different argument labels from those "
|
||||
"required by protocol %2 (%3)", (bool, DeclName, Type, DeclName))
|
||||
@@ -2150,9 +2142,6 @@ ERROR(override_dynamic_self_mismatch,none,
|
||||
ERROR(override_class_declaration_in_extension,none,
|
||||
"cannot override a non-dynamic class declaration from an extension",
|
||||
())
|
||||
WARNING(override_class_declaration_in_extension_warning,none,
|
||||
"cannot override a non-dynamic class declaration from an extension",
|
||||
())
|
||||
ERROR(override_throws,none,
|
||||
"cannot override non-throwing %select{method|initializer}0 with "
|
||||
"throwing %select{method|initializer}0", (bool))
|
||||
@@ -2250,8 +2239,6 @@ ERROR(inheritance_from_cf_class,none,
|
||||
ERROR(inheritance_from_objc_runtime_visible_class,none,
|
||||
"cannot inherit from class %0 because it is only visible via the "
|
||||
"Objective-C runtime", (Identifier))
|
||||
WARNING(class_inherits_anyobject,none,
|
||||
"conformance of class %0 to 'AnyObject' is redundant", (Type))
|
||||
|
||||
// Enums
|
||||
ERROR(enum_case_access,none,
|
||||
@@ -2343,9 +2330,6 @@ NOTE(construct_raw_representable_from_unwrapped_value,none,
|
||||
"construct %0 from unwrapped %1 value", (Type, Type))
|
||||
|
||||
// Derived conformances
|
||||
ERROR(swift3_cannot_synthesize_in_extension,none,
|
||||
"implementation of %0 cannot be automatically synthesized in an extension "
|
||||
"in Swift 3", (Type))
|
||||
ERROR(cannot_synthesize_init_in_extension_of_nonfinal,none,
|
||||
"implementation of %0 for non-final class cannot be automatically "
|
||||
"synthesized in extension because initializer requirement %1 can only be "
|
||||
@@ -2490,9 +2474,6 @@ ERROR(override_static,none,
|
||||
ERROR(member_cannot_be_final,none,
|
||||
"only classes and class members may be marked with 'final'",
|
||||
())
|
||||
WARNING(protocol_extension_cannot_be_final,none,
|
||||
"functions in a protocol extension do not need to be marked with 'final'",
|
||||
())
|
||||
|
||||
ERROR(final_not_allowed_here,none,
|
||||
"'final' may only be applied to classes, properties, methods, and "
|
||||
@@ -3303,10 +3284,6 @@ ERROR(isa_collection_downcast_pattern_value_unimplemented,none,
|
||||
"collection downcast in cast pattern is not implemented; use an explicit "
|
||||
"downcast to %0 instead", (Type))
|
||||
|
||||
WARNING(swift3_ignore_specialized_enum_element_call,none,
|
||||
"cannot specialize enum case; ignoring generic argument, "
|
||||
"which will be rejected in future version of Swift", ())
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// MARK: Error-handling diagnostics
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -3809,11 +3786,6 @@ ERROR(objc_class_method_not_permitted,none,
|
||||
OBJC_DIAG_SELECT " defines Objective-C class method %2, which is "
|
||||
"not permitted by Swift", (unsigned, DeclName, ObjCSelector))
|
||||
|
||||
WARNING(objc_class_method_not_permitted_swift3_compat_warning,none,
|
||||
OBJC_DIAG_SELECT " defines Objective-C class method %2, which is "
|
||||
"not guaranteed to be invoked by Swift and will be disallowed in future "
|
||||
"versions", (unsigned, DeclName, ObjCSelector))
|
||||
|
||||
ERROR(objc_witness_selector_mismatch,none,
|
||||
"Objective-C method %2 provided by " OBJC_DIAG_SELECT
|
||||
" does not match the requirement's selector (%3)",
|
||||
|
||||
@@ -360,19 +360,6 @@ bool DerivedConformance::checkAndDiagnoseDisallowedContext(
|
||||
allowCrossfileExtensions = ED && ED->hasOnlyCasesWithoutAssociatedValues();
|
||||
}
|
||||
|
||||
if (TC.Context.isSwiftVersion3()) {
|
||||
// In Swift 3, a 'private' property can't be accessed in any extensions, so
|
||||
// we can't synthesize anything that uses them. Thus, we stick to the old
|
||||
// rule for synthesis, which is never in an extension except for the
|
||||
// Equatable/Hashable cases mentioned above.
|
||||
if (!allowCrossfileExtensions && Nominal != ConformanceDecl) {
|
||||
TC.diagnose(ConformanceDecl->getLoc(),
|
||||
diag::swift3_cannot_synthesize_in_extension,
|
||||
getProtocolType());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!allowCrossfileExtensions &&
|
||||
Nominal->getModuleScopeContext() !=
|
||||
getConformanceContext()->getModuleScopeContext()) {
|
||||
|
||||
@@ -213,14 +213,8 @@ public:
|
||||
// 'final' only makes sense in the context of a class declaration.
|
||||
// Reject it on global functions, protocols, structs, enums, etc.
|
||||
if (!D->getDeclContext()->getSelfClassDecl()) {
|
||||
if (TC.Context.isSwiftVersion3() &&
|
||||
D->getDeclContext()->getExtendedProtocolDecl())
|
||||
TC.diagnose(attr->getLocation(),
|
||||
diag::protocol_extension_cannot_be_final)
|
||||
.fixItRemove(attr->getRange());
|
||||
else
|
||||
TC.diagnose(attr->getLocation(), diag::member_cannot_be_final)
|
||||
.fixItRemove(attr->getRange());
|
||||
TC.diagnose(attr->getLocation(), diag::member_cannot_be_final)
|
||||
.fixItRemove(attr->getRange());
|
||||
|
||||
// Remove the attribute so child declarations are not flagged as final
|
||||
// and duplicate the error message.
|
||||
|
||||
@@ -383,18 +383,6 @@ static void checkInheritanceClause(
|
||||
if (!inheritedTy)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Swift 3 compatibility -- a class inheriting from AnyObject is a no-op.
|
||||
if (ctx.LangOpts.isSwiftVersion3() && isa<ClassDecl>(decl) &&
|
||||
inheritedTy->isAnyObject()) {
|
||||
auto classDecl = cast<ClassDecl>(decl);
|
||||
auto removeRange = getRemovalRange(i);
|
||||
diags.diagnose(inherited.getSourceRange().Start,
|
||||
diag::class_inherits_anyobject,
|
||||
classDecl->getDeclaredInterfaceType())
|
||||
.fixItRemoveChars(removeRange.Start, removeRange.End);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// If this is an enum inheritance clause, check for a raw type.
|
||||
|
||||
@@ -1584,13 +1584,8 @@ void markAsObjC(ValueDecl *D, ObjCReason reason,
|
||||
// Swift 3 and earlier allowed you to override `initialize`, but
|
||||
// Swift's semantics do not guarantee that it will be called at
|
||||
// the point you expect. It is disallowed in Swift 4 and later.
|
||||
if (sel.getSelectorPieces().front() == ctx.Id_initialize) {
|
||||
if (ctx.LangOpts.isSwiftVersion3())
|
||||
return
|
||||
diag::objc_class_method_not_permitted_swift3_compat_warning;
|
||||
else
|
||||
return diag::objc_class_method_not_permitted;
|
||||
}
|
||||
if (sel.getSelectorPieces().front() == ctx.Id_initialize)
|
||||
return diag::objc_class_method_not_permitted;
|
||||
return None;
|
||||
case 1:
|
||||
if (sel.getSelectorPieces().front() == ctx.Id_allocWithZone)
|
||||
|
||||
@@ -1560,9 +1560,7 @@ static bool checkSingleOverride(ValueDecl *override, ValueDecl *base) {
|
||||
!base->isDynamic() &&
|
||||
override->getDeclContext()->isExtensionContext()) {
|
||||
// For compatibility, only generate a warning in Swift 3
|
||||
diags.diagnose(override, (ctx.isSwiftVersion3()
|
||||
? diag::override_class_declaration_in_extension_warning
|
||||
: diag::override_class_declaration_in_extension));
|
||||
diags.diagnose(override, diag::override_class_declaration_in_extension);
|
||||
diags.diagnose(base, diag::overridden_here);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,9 +263,7 @@ void TypeChecker::checkProtocolSelfRequirements(ValueDecl *decl) {
|
||||
continue;
|
||||
|
||||
diagnose(decl,
|
||||
Context.isSwiftVersion3()
|
||||
? diag::requirement_restricts_self_swift3
|
||||
: diag::requirement_restricts_self,
|
||||
diag::requirement_restricts_self,
|
||||
decl->getDescriptiveKind(), decl->getFullName(),
|
||||
req.getFirstType().getString(),
|
||||
static_cast<unsigned>(req.getKind()),
|
||||
|
||||
@@ -539,16 +539,11 @@ public:
|
||||
// then required to have keywords for every argument that name properties
|
||||
// of the type.
|
||||
Pattern *visitCallExpr(CallExpr *ce) {
|
||||
if (!TC.Context.isSwiftVersion3()) {
|
||||
// swift(>=4) mode.
|
||||
// Specialized call are not allowed anyway.
|
||||
// Let it be diagnosed as an expression.
|
||||
// For Swift3 mode, we emit warnings just before constructing the
|
||||
// enum-element-pattern below.
|
||||
if (isa<UnresolvedSpecializeExpr>(ce->getFn()))
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Specialized call are not allowed anyway.
|
||||
// Let it be diagnosed as an expression.
|
||||
if (isa<UnresolvedSpecializeExpr>(ce->getFn()))
|
||||
return nullptr;
|
||||
|
||||
SmallVector<ComponentIdentTypeRepr *, 2> components;
|
||||
if (!ExprToIdentTypeRepr(components, TC.Context).visit(ce->getFn()))
|
||||
return nullptr;
|
||||
@@ -597,19 +592,8 @@ public:
|
||||
loc.setType(enumTy);
|
||||
}
|
||||
|
||||
if (auto generic = dyn_cast<GenericIdentTypeRepr>(tailComponent)) {
|
||||
assert(TC.Context.isSwiftVersion3() && "should be handled above");
|
||||
|
||||
// Swift3 used to ignore the last generic argument clause:
|
||||
// EnumTy.CaseVal<SomeType>()
|
||||
// used to be wrongfully converted to
|
||||
// (pattern_enum_element type='EnumTy' EnumTy.CaseVal
|
||||
// (pattern_tuple type='()' names=))
|
||||
// To keep source compatibility, just emit a warning with fix-it.
|
||||
TC.diagnose(generic->getAngleBrackets().Start,
|
||||
diag::swift3_ignore_specialized_enum_element_call)
|
||||
.fixItRemove(generic->getAngleBrackets());
|
||||
}
|
||||
assert(!isa<GenericIdentTypeRepr>(tailComponent) &&
|
||||
"should be handled above");
|
||||
|
||||
auto *subPattern = getSubExprPattern(ce->getArg());
|
||||
return new (TC.Context) EnumElementPattern(loc,
|
||||
@@ -1451,7 +1435,7 @@ recur:
|
||||
validateDeclForNameLookup(elt);
|
||||
if (EEP->hasSubPattern()) {
|
||||
Pattern *sub = EEP->getSubPattern();
|
||||
if (!Context.isSwiftVersion3() && !elt->hasAssociatedValues()) {
|
||||
if (!elt->hasAssociatedValues()) {
|
||||
diagnose(EEP->getLoc(),
|
||||
diag::enum_element_pattern_assoc_values_mismatch,
|
||||
EEP->getName());
|
||||
|
||||
@@ -4713,10 +4713,8 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
|
||||
if (kind && getLangOpts().EnableNSKeyedArchiverDiagnostics &&
|
||||
isa<NormalProtocolConformance>(conformance) &&
|
||||
!hasExplicitObjCName(classDecl)) {
|
||||
bool emitWarning = Context.LangOpts.isSwiftVersion3();
|
||||
diagnose(cast<NormalProtocolConformance>(conformance)->getLoc(),
|
||||
emitWarning ? diag::nscoding_unstable_mangled_name_warn
|
||||
: diag::nscoding_unstable_mangled_name,
|
||||
diag::nscoding_unstable_mangled_name,
|
||||
static_cast<unsigned>(kind.getValue()),
|
||||
classDecl->getDeclaredInterfaceType());
|
||||
auto insertionLoc =
|
||||
|
||||
@@ -1477,13 +1477,6 @@ static bool diagnoseAvailability(IdentTypeRepr *IdType,
|
||||
auto componentRange = IdType->getComponentRange();
|
||||
for (auto comp : componentRange) {
|
||||
if (auto *typeDecl = comp->getBoundDecl()) {
|
||||
// In Swift 3, components other than the last one were not properly
|
||||
// checked for availability.
|
||||
// FIXME: We should try to downgrade these errors to warnings, not just
|
||||
// skip diagnosing them.
|
||||
if (ctx.LangOpts.isSwiftVersion3() && comp != componentRange.back())
|
||||
continue;
|
||||
|
||||
// FIXME: Need to eliminate the type checker argument.
|
||||
TypeChecker &tc = static_cast<TypeChecker &>(*ctx.getLazyResolver());
|
||||
if (diagnoseDeclAvailability(typeDecl, tc, DC, comp->getIdLoc(),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-build-swift %s -module-name=test -o %t/a.out -swift-version 3
|
||||
// RUN: %target-build-swift %s -module-name=test -o %t/a.out
|
||||
// RUN: %target-codesign %t/a.out
|
||||
// RUN: %target-run %t/a.out %S/Inputs/test.arc | %FileCheck %s
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
import Foundation
|
||||
|
||||
struct ABC {
|
||||
@objc(_TtCV4test3ABC11NestedClass)
|
||||
class NestedClass : NSObject, NSCoding {
|
||||
var i : Int
|
||||
|
||||
@@ -31,6 +32,7 @@ struct ABC {
|
||||
}
|
||||
}
|
||||
|
||||
@objc(_TtC4testP33_25D299289FEB01A726765440D53BD3D112PrivateClass)
|
||||
private class PrivateClass : NSObject, NSCoding {
|
||||
var pi : Int
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// RUN: %target-run-simple-swift-swift3
|
||||
// RUN: %target-run-simple-swift
|
||||
// REQUIRES: executable_test
|
||||
// REQUIRES: objc_interop
|
||||
|
||||
@@ -60,7 +60,7 @@ DemangleToMetadataTests.test("Imported swift_wrapper types") {
|
||||
}
|
||||
|
||||
DemangleToMetadataTests.test("Imported enum types") {
|
||||
expectEqual(NSURLSessionTask.State.self,
|
||||
expectEqual(URLSessionTask.State.self,
|
||||
_typeByMangledName("So21NSURLSessionTaskStateV")!)
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,9 @@ typedef NSString *NSErrorDomain;
|
||||
@end
|
||||
|
||||
@interface NSDictionary<KeyType, ValueType> : NSObject
|
||||
|
||||
+ (void) classMethod;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSSet<ObjectType> : NSObject
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
// RUN: %target-swift-emit-silgen -sdk %S/Inputs -I %S/Inputs -enable-source-import %s -enable-objc-interop -swift-version 3 | %FileCheck %s
|
||||
// RUN: %target-swift-emit-silgen -sdk %S/Inputs -I %S/Inputs -enable-source-import %s -enable-objc-interop | %FileCheck %s
|
||||
// RUN: %target-swift-emit-sil -O -sdk %S/Inputs -I %S/Inputs -enable-source-import %s -enable-objc-interop
|
||||
|
||||
import Foundation
|
||||
class MyFunkyDictionary: NSDictionary {
|
||||
// CHECK-LABEL: sil hidden @$s23super_objc_class_method17MyFunkyDictionaryC10initializeyyFZ
|
||||
// CHECK: objc_super_method %0 : $@thick MyFunkyDictionary.Type, #NSObject.initialize!1.foreign : (NSObject.Type) -> () -> ()
|
||||
override class func initialize() {
|
||||
super.initialize()
|
||||
// CHECK-LABEL: sil hidden @$s23super_objc_class_method17MyFunkyDictionaryC0C6MethodyyFZ : $@convention(method) (@thick MyFunkyDictionary.Type) -> ()
|
||||
// CHECK: objc_super_method %0 : $@thick MyFunkyDictionary.Type, #NSDictionary.classMethod!1.foreign : (NSDictionary.Type) -> () -> ()
|
||||
override class func classMethod() {
|
||||
super.classMethod()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
// RUN: %target-swift-frontend -emit-sil %s -swift-version 3 | %FileCheck %s
|
||||
// RUN: %target-swift-frontend -emit-sil -I %S/Inputs -enable-source-import %s -swift-version 3 | %FileCheck %s
|
||||
|
||||
// REQUIRES: objc_interop
|
||||
|
||||
import Foundation
|
||||
class MyFunkyDictionary: NSDictionary {
|
||||
// CHECK-LABEL: sil hidden @$s23super_objc_class_method17MyFunkyDictionaryC10initializeyyFZ
|
||||
// CHECK: objc_super_method %0 : $@thick MyFunkyDictionary.Type, #NSObject.initialize!1.foreign : (NSObject.Type) -> () -> ()
|
||||
override class func initialize() {
|
||||
super.initialize()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3093,8 +3093,7 @@ int main(int argc, char *argv[]) {
|
||||
InitInvok.getLangOptions().InferImportAsMember |=
|
||||
options::InferImportAsMember;
|
||||
InitInvok.getLangOptions().EnableSwift3ObjCInference =
|
||||
options::EnableSwift3ObjCInference ||
|
||||
InitInvok.getLangOptions().isSwiftVersion3();
|
||||
options::EnableSwift3ObjCInference;
|
||||
InitInvok.getClangImporterOptions().ImportForwardDeclarations |=
|
||||
options::ObjCForwardDeclarations;
|
||||
InitInvok.getClangImporterOptions().InferImportAsMember |=
|
||||
|
||||
Reference in New Issue
Block a user