Skip to content

Commit 4a46d47

Browse files
authored
Disable diagnostics about problem NSCoding-conforming classes for now. (#9808)
Adoption so far shows that the criteria we set up here are too broad. This is particularly problematic for subclasses of NS/UIView and the like that might never be encoded at all. rdar://problem/32306355
1 parent d1bd12f commit 4a46d47

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ namespace swift {
227227
/// of Swift do not.
228228
Swift3ObjCInferenceWarnings WarnSwift3ObjCInference =
229229
Swift3ObjCInferenceWarnings::None;
230+
231+
/// Diagnose uses of NSCoding with classes that have unstable mangled names.
232+
bool EnableNSKeyedArchiverDiagnostics = false;
230233

231234
/// Enable keypath components that aren't fully implemented.
232235
bool EnableExperimentalKeyPathComponents = false;

include/swift/Option/FrontendOptions.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,13 @@ def disable_swift3_objc_inference :
304304
Flags<[FrontendOption, HelpHidden]>,
305305
HelpText<"Disable Swift 3's @objc inference rules for NSObject-derived classes and 'dynamic' members (emulates Swift 4 behavior)">;
306306

307+
def enable_nskeyedarchiver_diagnostics :
308+
Flag<["-"], "enable-nskeyedarchiver-diagnostics">,
309+
HelpText<"Diagnose classes with unstable mangled names adopting NSCoding">;
310+
def disable_nskeyedarchiver_diagnostics :
311+
Flag<["-"], "disable-nskeyedarchiver-diagnostics">,
312+
HelpText<"Allow classes with unstable mangled names to adopt NSCoding">;
313+
307314
def warn_long_function_bodies : Separate<["-"], "warn-long-function-bodies">,
308315
MetaVarName<"<n>">,
309316
HelpText<"Warns when type-checking a function takes longer than <n> ms">;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,11 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
10381038
}
10391039
}
10401040

1041+
Opts.EnableNSKeyedArchiverDiagnostics =
1042+
Args.hasFlag(OPT_enable_nskeyedarchiver_diagnostics,
1043+
OPT_disable_nskeyedarchiver_diagnostics,
1044+
Opts.EnableNSKeyedArchiverDiagnostics);
1045+
10411046
llvm::Triple Target = Opts.Target;
10421047
StringRef TargetArg;
10431048
if (const Arg *A = Args.getLastArg(OPT_target)) {

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6058,7 +6058,8 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
60586058
}
60596059
}
60606060

6061-
if (kind && !hasExplicitObjCName(classDecl) &&
6061+
if (kind && getLangOpts().EnableNSKeyedArchiverDiagnostics &&
6062+
!hasExplicitObjCName(classDecl) &&
60626063
!classDecl->getAttrs().hasAttribute<NSKeyedArchiverClassNameAttr>() &&
60636064
!classDecl->getAttrs()
60646065
.hasAttribute<NSKeyedArchiverEncodeNonGenericSubclassesOnlyAttr>()) {

test/decl/protocol/conforms/nscoding.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s -verify
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s -enable-nskeyedarchiver-diagnostics -verify
2+
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s 2>&1 | %FileCheck -check-prefix CHECK-NO-DIAGS %s
23

34
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s -dump-ast 2> %t.ast
45
// RUN: %FileCheck %s < %t.ast
56

67
// REQUIRES: objc_interop
78

9+
// CHECK-NO-DIAGS-NOT: NSCoding
10+
// CHECK-NO-DIAGS-NOT: unstable
11+
812
import Foundation
913

1014
// Top-level classes

0 commit comments

Comments
 (0)