Skip to content

Commit e5c6bb6

Browse files
committed
Remove support for Swift 3 @objc inference.
Obsolete the `-enable-swift3-objc-inference` option and related options by removing support for inferring `@objc` attributes using Swift 3 rules. Automated migration from Swift 3 has not been supported by the compiler for many years.
1 parent 3e16fa4 commit e5c6bb6

23 files changed

+17
-634
lines changed

include/swift/AST/Attr.h

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,13 @@ class DeclAttribute : public AttributeBase {
118118
AddedByAccessNote : 1
119119
);
120120

121-
SWIFT_INLINE_BITFIELD(ObjCAttr, DeclAttribute, 1+1+1,
121+
SWIFT_INLINE_BITFIELD(ObjCAttr, DeclAttribute, 1+1,
122122
/// Whether this attribute has location information that trails the main
123123
/// record, which contains the locations of the parentheses and any names.
124124
HasTrailingLocationInfo : 1,
125125

126126
/// Whether the name is implicit, produced as the result of caching.
127-
ImplicitName : 1,
128-
129-
/// Whether the @objc was inferred using Swift 3's deprecated inference
130-
/// rules.
131-
Swift3Inferred : 1
127+
ImplicitName : 1
132128
);
133129

134130
SWIFT_INLINE_BITFIELD(DynamicReplacementAttr, DeclAttribute, 1,
@@ -823,7 +819,6 @@ class ObjCAttr final : public DeclAttribute,
823819
NameData(nullptr) {
824820
Bits.ObjCAttr.HasTrailingLocationInfo = false;
825821
Bits.ObjCAttr.ImplicitName = implicitName;
826-
Bits.ObjCAttr.Swift3Inferred = false;
827822

828823
if (name) {
829824
NameData = name->getOpaqueValue();
@@ -933,18 +928,6 @@ class ObjCAttr final : public DeclAttribute,
933928
Bits.ObjCAttr.ImplicitName = implicit;
934929
}
935930

936-
/// Determine whether this attribute was inferred based on Swift 3's
937-
/// deprecated @objc inference rules.
938-
bool isSwift3Inferred() const {
939-
return Bits.ObjCAttr.Swift3Inferred;
940-
}
941-
942-
/// Set whether this attribute was inferred based on Swift 3's deprecated
943-
/// @objc inference rules.
944-
void setSwift3Inferred(bool inferred = true) {
945-
Bits.ObjCAttr.Swift3Inferred = inferred;
946-
}
947-
948931
/// Retrieve the source locations for the names in a non-implicit
949932
/// nullary or selector attribute.
950933
ArrayRef<SourceLoc> getNameLocs() const;

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -644,10 +644,6 @@ ERROR(expression_unused_keypath_result,NoUsage,
644644
ERROR(expr_keypath_non_objc_property,none,
645645
"argument of '#keyPath' refers to non-'@objc' property %0",
646646
(Identifier))
647-
WARNING(expr_keypath_swift3_objc_inference,Deprecation,
648-
"argument of '#keyPath' refers to property %0 in %1 that depends on "
649-
"'@objc' inference deprecated in Swift 4",
650-
(Identifier, Identifier))
651647
ERROR(expr_keypath_type_of_property,none,
652648
"cannot refer to type member %0 within instance of type %1",
653649
(DeclNameRef, Type))
@@ -755,10 +751,6 @@ ERROR(expr_selector_not_objc,none,
755751
NOTE(make_decl_objc,none,
756752
"add '@objc' to expose this %0 to Objective-C",
757753
(DescriptiveDeclKind))
758-
WARNING(expr_selector_swift3_objc_inference,Deprecation,
759-
"argument of '#selector' refers to %kind0 in %1 that depends on "
760-
"'@objc' inference deprecated in Swift 4",
761-
(const ValueDecl *, const ValueDecl *))
762754

763755
// Selectors-as-string-literals.
764756
WARNING(selector_literal_invalid,none,
@@ -2132,11 +2124,6 @@ ERROR(missing_unimplemented_init_runtime,none,
21322124
ERROR(missing_undefined_runtime,none,
21332125
"standard library error: missing _undefined", ())
21342126

2135-
WARNING(expr_dynamic_lookup_swift3_objc_inference,Deprecation,
2136-
"reference to %kind0 of %1 depends on '@objc' inference "
2137-
"deprecated in Swift 4",
2138-
(const ValueDecl *, Identifier))
2139-
21402127
ERROR(inherited_default_value_not_in_designated_constructor,none,
21412128
"default value inheritance via 'super' is only valid on the parameters of "
21422129
"designated initializers", ())
@@ -3450,11 +3437,6 @@ WARNING(implicitly_final_cannot_be_open_swift4,none,
34503437
"static declarations}0 are implicitly 'final'; use 'public' instead of "
34513438
"'open'", (unsigned))
34523439

3453-
WARNING(override_swift3_objc_inference,Deprecation,
3454-
"override of %kind0 from extension of %1 depends on deprecated "
3455-
"inference of '@objc'",
3456-
(const ValueDecl *, Identifier))
3457-
34583440
// Inheritance
34593441
ERROR(duplicate_inheritance,none,
34603442
"duplicate inheritance from %0", (Type))
@@ -6126,18 +6108,6 @@ ERROR(objc_operator, none,
61266108
"operator methods cannot be declared @objc", ())
61276109
ERROR(objc_operator_proto, none,
61286110
"@objc protocols must not have operator requirements", ())
6129-
WARNING(objc_inference_swift3_dynamic,Deprecation,
6130-
"inference of '@objc' for 'dynamic' members is deprecated", ())
6131-
WARNING(objc_inference_swift3_objc_derived,Deprecation,
6132-
"inference of '@objc' for members of Objective-C-derived classes is "
6133-
"deprecated", ())
6134-
6135-
NOTE(objc_inference_swift3_addobjc,none,
6136-
"add '@objc' to continue exposing an Objective-C entry point (Swift 3 "
6137-
"behavior)", ())
6138-
NOTE(objc_inference_swift3_addnonobjc,none,
6139-
"add '@nonobjc' to suppress the Objective-C entry point (Swift 4 "
6140-
"behavior)", ())
61416111

61426112
ERROR(objc_for_generic_class,none,
61436113
"generic subclasses of '@objc' classes cannot have an explicit '@objc' "
@@ -6153,10 +6123,6 @@ ERROR(objc_setter_for_nonobjc_property,none,
61536123
"'@objc' setter for non-'@objc' property", ())
61546124
ERROR(objc_setter_for_nonobjc_subscript,none,
61556125
"'@objc' setter for non-'@objc' subscript", ())
6156-
WARNING(accessor_swift3_objc_inference,Deprecation,
6157-
"%kind0 with '@objc' %select{getter|setter}1 depends on "
6158-
"deprecated inference of '@objc'",
6159-
(const AbstractStorageDecl *, bool))
61606126

61616127
ERROR(objc_enum_generic,none,
61626128
"'@objc' enum cannot be generic", ())
@@ -6187,10 +6153,6 @@ ERROR(objc_extension_not_class,none,
61876153
// If you change this, also change enum ObjCReason
61886154
#define OBJC_ATTR_SELECT "select{marked @_cdecl|marked dynamic|marked @objc|marked @objcMembers|marked @IBOutlet|marked @IBAction|marked @IBSegueAction|marked @NSManaged|a member of an @objc protocol|implicitly @objc|an @objc override|an implementation of an @objc requirement|marked @IBInspectable|marked @GKInspectable|in an @objc extension of a class (without @nonobjc)|in an @_objcImplementation extension of a class (without final or @nonobjc)|marked @objc by an access note}"
61896155

6190-
WARNING(attribute_meaningless_when_nonobjc,none,
6191-
"'@%0' attribute is meaningless on a property that cannot be "
6192-
"represented in Objective-C", (StringRef))
6193-
61946156
ERROR(objc_invalid_on_var,none,
61956157
"property cannot be %" OBJC_ATTR_SELECT "0 "
61966158
"because its type cannot be represented in Objective-C", (unsigned))
@@ -6249,10 +6211,6 @@ NOTE(objc_overriding_objc_decl,none,
62496211
NOTE(objc_witness_objc_requirement,none,
62506212
"satisfying requirement for %kind0 in protocol %1",
62516213
(const ValueDecl *, const ProtocolDecl *))
6252-
WARNING(witness_swift3_objc_inference,Deprecation,
6253-
"use of %kind0 to satisfy a requirement of protocol %1 depends on "
6254-
"'@objc' inference deprecated in Swift 4",
6255-
(const ValueDecl *, Type))
62566214

62576215
ERROR(no_opaque_return_type_of,none,
62586216
"unable to resolve type for _opaqueReturnTypeOf attribute", ())

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,6 @@ namespace swift {
5151
#include "swift/AST/PlatformConditionKinds.def"
5252
};
5353

54-
/// Describes which Swift 3 Objective-C inference warnings should be
55-
/// emitted.
56-
enum class Swift3ObjCInferenceWarnings {
57-
/// No warnings; this is the default.
58-
None,
59-
/// "Minimal" warnings driven by uses of declarations that make use of
60-
/// the Objective-C entry point directly.
61-
Minimal,
62-
/// "Complete" warnings that add "@objc" for every entry point that
63-
/// Swift 3 would have inferred as "@objc" but Swift 4 will not.
64-
Complete,
65-
};
66-
6754
/// Describes how strict concurrency checking should be.
6855
enum class StrictConcurrency {
6956
/// Enforce Sendable constraints where it has been explicitly adopted and
@@ -439,21 +426,12 @@ namespace swift {
439426
/// will be used in editor. This usually leads to more aggressive fixit.
440427
bool DiagnosticsEditorMode = false;
441428

442-
/// Whether to enable Swift 3 @objc inference, e.g., for members of
443-
/// Objective-C-derived classes and 'dynamic' members.
444-
bool EnableSwift3ObjCInference = false;
445-
446429
/// Access or distribution level of the whole module being parsed.
447430
LibraryLevel LibraryLevel = LibraryLevel::Other;
448431

449432
/// The name of the package this module belongs to.
450433
std::string PackageName;
451434

452-
/// Warn about cases where Swift 3 would infer @objc but later versions
453-
/// of Swift do not.
454-
Swift3ObjCInferenceWarnings WarnSwift3ObjCInference =
455-
Swift3ObjCInferenceWarnings::None;
456-
457435
/// Diagnose implicit 'override'.
458436
bool WarnImplicitOverrides = false;
459437

include/swift/Migrator/FixitFilter.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,6 @@ struct FixitFilter {
8080
if (Info.ID == diag::could_not_find_enum_case.ID)
8181
return false;
8282

83-
// Sema suggests adding both `@objc` and `@nonobjc` as alternative fix-its
84-
// for inferring Swift-3 style @objc visibility, but we don't want the
85-
// migrator to suggest `@nonobjc`.
86-
if (Info.ID == diag::objc_inference_swift3_addnonobjc.ID) {
87-
return false;
88-
}
89-
9083
// With SE-110, the migrator may get a recommendation to add a Void
9184
// placeholder in the call to f in:
9285
// func foo(f: (Void) -> ()) {
@@ -132,10 +125,6 @@ struct FixitFilter {
132125
Info.ID == diag::deprecated_any_composition.ID ||
133126
Info.ID == diag::deprecated_operator_body.ID ||
134127
Info.ID == diag::unbound_generic_parameter_explicit_fix.ID ||
135-
Info.ID == diag::objc_inference_swift3_addobjc.ID ||
136-
Info.ID == diag::objc_inference_swift3_dynamic.ID ||
137-
Info.ID == diag::override_swift3_objc_inference.ID ||
138-
Info.ID == diag::objc_inference_swift3_objc_derived.ID ||
139128
Info.ID == diag::missing_several_cases.ID ||
140129
Info.ID == diag::missing_particular_case.ID ||
141130
Info.ID == diag::missing_unknown_case.ID ||

include/swift/Option/FrontendOptions.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,12 +677,12 @@ def report_errors_to_debugger : Flag<["-"], "report-errors-to-debugger">,
677677

678678
def enable_swift3_objc_inference : Flag<["-"], "enable-swift3-objc-inference">,
679679
Flags<[FrontendOption, HelpHidden]>,
680-
HelpText<"Deprecated">;
680+
HelpText<"Deprecated, has no effect">;
681681

682682
def disable_swift3_objc_inference :
683683
Flag<["-"], "disable-swift3-objc-inference">,
684684
Flags<[FrontendOption, HelpHidden]>,
685-
HelpText<"Deprecated">;
685+
HelpText<"Deprecated, has no effect">;
686686

687687
def enable_implicit_dynamic : Flag<["-"], "enable-implicit-dynamic">,
688688
Flags<[FrontendOption, NoInteractiveOption, HelpHidden]>,

include/swift/Option/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,12 +788,12 @@ def continue_building_after_errors : Flag<["-"], "continue-building-after-errors
788788
def warn_swift3_objc_inference_complete :
789789
Flag<["-"], "warn-swift3-objc-inference-complete">,
790790
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
791-
HelpText<"Deprecated">;
791+
HelpText<"Deprecated, has no effect">;
792792

793793
def warn_swift3_objc_inference_minimal :
794794
Flag<["-"], "warn-swift3-objc-inference-minimal">,
795795
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
796-
HelpText<"Deprecated">;
796+
HelpText<"Deprecated, has no effect">;
797797

798798
def enable_actor_data_race_checks :
799799
Flag<["-"], "enable-actor-data-race-checks">,

lib/AST/Attr.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,6 @@ ObjCAttr::ObjCAttr(SourceLoc atLoc, SourceRange baseRange,
17751775
}
17761776

17771777
Bits.ObjCAttr.ImplicitName = false;
1778-
Bits.ObjCAttr.Swift3Inferred = false;
17791778
}
17801779

17811780
ObjCAttr *ObjCAttr::create(ASTContext &Ctx, llvm::Optional<ObjCSelector> name,
@@ -1853,7 +1852,6 @@ SourceLoc ObjCAttr::getRParenLoc() const {
18531852

18541853
ObjCAttr *ObjCAttr::clone(ASTContext &context) const {
18551854
auto attr = new (context) ObjCAttr(getName(), isNameImplicit());
1856-
attr->setSwift3Inferred(isSwift3Inferred());
18571855
attr->setAddedByAccessNote(getAddedByAccessNote());
18581856
return attr;
18591857
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -917,10 +917,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
917917
Opts.EnableAppExtensionRestrictions |= Args.hasArg(OPT_enable_app_extension);
918918
Opts.EnableAppExtensionRestrictions |= Opts.EnableAppExtensionLibraryRestrictions;
919919

920-
Opts.EnableSwift3ObjCInference =
921-
Args.hasFlag(OPT_enable_swift3_objc_inference,
922-
OPT_disable_swift3_objc_inference, false);
923-
924920
if (Args.hasArg(OPT_enable_swift3_objc_inference))
925921
Diags.diagnose(SourceLoc(), diag::warn_flag_deprecated,
926922
"-enable-swift3-objc-inference");
@@ -981,17 +977,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
981977

982978
Opts.EnableSPIOnlyImports = Args.hasArg(OPT_experimental_spi_only_imports);
983979

984-
if (Opts.EnableSwift3ObjCInference) {
985-
if (const Arg *A = Args.getLastArg(
986-
OPT_warn_swift3_objc_inference_minimal,
987-
OPT_warn_swift3_objc_inference_complete)) {
988-
if (A->getOption().getID() == OPT_warn_swift3_objc_inference_minimal)
989-
Opts.WarnSwift3ObjCInference = Swift3ObjCInferenceWarnings::Minimal;
990-
else
991-
Opts.WarnSwift3ObjCInference = Swift3ObjCInferenceWarnings::Complete;
992-
}
993-
}
994-
995980
if (Args.hasArg(OPT_warn_swift3_objc_inference_minimal))
996981
Diags.diagnose(SourceLoc(), diag::warn_flag_deprecated,
997982
"-warn-swift3-objc-inference-minimal");

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,12 +1328,6 @@ class DeclAndTypePrinter::Implementation
13281328
printAvailability(AFD);
13291329
}
13301330

1331-
if (auto accessor = dyn_cast<AccessorDecl>(AFD)) {
1332-
printSwift3ObjCDeprecatedInference(accessor->getStorage());
1333-
} else {
1334-
printSwift3ObjCDeprecatedInference(AFD);
1335-
}
1336-
13371331
os << ";\n";
13381332

13391333
if (makeNewUnavailable) {
@@ -1775,36 +1769,6 @@ class DeclAndTypePrinter::Implementation
17751769
}
17761770
}
17771771

1778-
void printSwift3ObjCDeprecatedInference(ValueDecl *VD) {
1779-
const LangOptions &langOpts = getASTContext().LangOpts;
1780-
if (!langOpts.EnableSwift3ObjCInference ||
1781-
langOpts.WarnSwift3ObjCInference == Swift3ObjCInferenceWarnings::None) {
1782-
return;
1783-
}
1784-
auto attr = VD->getAttrs().getAttribute<ObjCAttr>();
1785-
if (!attr || !attr->isSwift3Inferred())
1786-
return;
1787-
1788-
os << " SWIFT_DEPRECATED_OBJC(\"Swift ";
1789-
if (isa<VarDecl>(VD))
1790-
os << "property";
1791-
else if (isa<SubscriptDecl>(VD))
1792-
os << "subscript";
1793-
else if (isa<ConstructorDecl>(VD))
1794-
os << "initializer";
1795-
else
1796-
os << "method";
1797-
os << " '";
1798-
auto nominal = VD->getDeclContext()->getSelfNominalTypeDecl();
1799-
printEncodedString(os, nominal->getName().str(), /*includeQuotes=*/false);
1800-
os << ".";
1801-
SmallString<32> scratch;
1802-
printEncodedString(os, VD->getName().getString(scratch),
1803-
/*includeQuotes=*/false);
1804-
os << "' uses '@objc' inference deprecated in Swift 4; add '@objc' to "
1805-
<< "provide an Objective-C entrypoint\")";
1806-
}
1807-
18081772
void visitFuncDecl(FuncDecl *FD) {
18091773
if (outputLang == OutputLanguageMode::Cxx) {
18101774
if (FD->getDeclContext()->isTypeContext())
@@ -2041,8 +2005,6 @@ class DeclAndTypePrinter::Implementation
20412005
print(objTy, kind, objCName.str().str());
20422006
}
20432007

2044-
printSwift3ObjCDeprecatedInference(VD);
2045-
20462008
printAvailability(VD);
20472009

20482010
auto *getter = VD->getOpaqueAccessor(AccessorKind::Get);

lib/SILGen/SILGenBridging.cpp

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,44 +1624,6 @@ void SILGenFunction::emitNativeToForeignThunk(SILDeclRef thunk) {
16241624
}
16251625
}
16261626

1627-
// If the '@objc' was inferred due to deprecated rules,
1628-
// emit a Builtin.swift3ImplicitObjCEntrypoint().
1629-
//
1630-
// However, don't do so for 'dynamic' members, which must use Objective-C
1631-
// dispatch and therefore create many false positives.
1632-
if (thunk.hasDecl()) {
1633-
auto decl = thunk.getDecl();
1634-
1635-
// For an accessor, look at the storage declaration's attributes.
1636-
if (auto accessor = dyn_cast<AccessorDecl>(decl)) {
1637-
decl = accessor->getStorage();
1638-
}
1639-
1640-
if (auto attr = decl->getAttrs().getAttribute<ObjCAttr>()) {
1641-
// If @objc was inferred based on the Swift 3 @objc inference rules, emit
1642-
// a call to Builtin.swift3ImplicitObjCEntrypoint() to enable runtime
1643-
// logging of the uses of such entrypoints.
1644-
if (attr->isSwift3Inferred() && !decl->shouldUseObjCDispatch()) {
1645-
// Get the starting source location of the declaration so we can say
1646-
// exactly where to stick '@objc'.
1647-
SourceLoc objcInsertionLoc =
1648-
decl->getAttributeInsertionLoc(/*modifier*/ false);
1649-
1650-
auto objcInsertionLocArgs
1651-
= emitSourceLocationArgs(objcInsertionLoc, loc);
1652-
1653-
B.createBuiltin(loc,
1654-
getASTContext().getIdentifier("swift3ImplicitObjCEntrypoint"),
1655-
getModule().Types.getEmptyTupleType(), { }, {
1656-
objcInsertionLocArgs.filenameStartPointer.forward(*this),
1657-
objcInsertionLocArgs.filenameLength.forward(*this),
1658-
objcInsertionLocArgs.line.forward(*this),
1659-
objcInsertionLocArgs.column.forward(*this)
1660-
});
1661-
}
1662-
}
1663-
}
1664-
16651627
// Now, enter a cleanup used for bridging the arguments. Note that if we
16661628
// have an indirect result, it must be outside of this scope, otherwise
16671629
// we will deallocate it too early.

0 commit comments

Comments
 (0)