Skip to content

Commit fda0b80

Browse files
authored
Merge pull request #40903 from NuriAmari/default-diagnostics
Enable lazy ClangImporter diagnostics by default
2 parents 05a17cc + 7ec861f commit fda0b80

16 files changed

+127
-20
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ namespace swift {
328328
/// Enable experimental flow-sensitive concurrent captures.
329329
bool EnableExperimentalFlowSensitiveConcurrentCaptures = false;
330330

331-
/// Enable experimental ClangImporter diagnostics.
332-
bool EnableExperimentalClangImporterDiagnostics = false;
331+
/// Disable experimental ClangImporter diagnostics.
332+
bool DisableExperimentalClangImporterDiagnostics = false;
333333

334334
/// Enable experimental eager Clang module diagnostics.
335335
bool EnableExperimentalEagerClangModuleDiagnostics = false;

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ def enable_experimental_flow_sensitive_concurrent_captures :
287287
Flag<["-"], "enable-experimental-flow-sensitive-concurrent-captures">,
288288
HelpText<"Enable flow-sensitive concurrent captures">;
289289

290-
def enable_experimental_clang_importer_diagnostics :
291-
Flag<["-"], "enable-experimental-clang-importer-diagnostics">,
292-
HelpText<"Enable experimental diagnostics when importing C, C++, and Objective-C libraries">;
290+
def disable_experimental_clang_importer_diagnostics :
291+
Flag<["-"], "disable-experimental-clang-importer-diagnostics">,
292+
HelpText<"Disable experimental diagnostics when importing C, C++, and Objective-C libraries">;
293293

294294
def enable_experimental_eager_clang_module_diagnostics :
295295
Flag<["-"], "enable-experimental-eager-clang-module-diagnostics">,

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,8 +2397,7 @@ void ClangImporter::Implementation::addImportDiagnostic(
23972397
ImportDiagnosticTarget target, Diagnostic &&diag,
23982398
const clang::SourceLocation &loc) {
23992399
ImportDiagnostic importDiag = ImportDiagnostic(target, diag, loc);
2400-
if (!(SwiftContext.LangOpts.EnableExperimentalClangImporterDiagnostics ||
2401-
SwiftContext.LangOpts.EnableExperimentalEagerClangModuleDiagnostics) ||
2400+
if (SwiftContext.LangOpts.DisableExperimentalClangImporterDiagnostics ||
24022401
CollectedDiagnostics.count(importDiag))
24032402
return;
24042403

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,11 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
470470
Opts.EnableExperimentalFlowSensitiveConcurrentCaptures |=
471471
Args.hasArg(OPT_enable_experimental_flow_sensitive_concurrent_captures);
472472

473-
Opts.EnableExperimentalClangImporterDiagnostics |=
474-
Args.hasArg(OPT_enable_experimental_clang_importer_diagnostics);
473+
Opts.DisableExperimentalClangImporterDiagnostics |=
474+
Args.hasArg(OPT_disable_experimental_clang_importer_diagnostics);
475475

476476
Opts.EnableExperimentalEagerClangModuleDiagnostics |=
477+
!Args.hasArg(OPT_disable_experimental_clang_importer_diagnostics) &&
477478
Args.hasArg(OPT_enable_experimental_eager_clang_module_diagnostics);
478479

479480
Opts.DisableImplicitConcurrencyModuleImport |=

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3650,7 +3650,7 @@ bool MissingMemberFailure::diagnoseAsError() {
36503650
.highlight(getSourceRange())
36513651
.highlight(nameLoc.getSourceRange());
36523652
const auto &ctx = getSolution().getDC()->getASTContext();
3653-
if (ctx.LangOpts.EnableExperimentalClangImporterDiagnostics) {
3653+
if (!ctx.LangOpts.DisableExperimentalClangImporterDiagnostics) {
36543654
ctx.getClangModuleLoader()->diagnoseMemberValue(getName().getFullName(),
36553655
baseType);
36563656
}

lib/Sema/PreCheckExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
590590
.diagnose(Loc, diag::cannot_find_in_scope, Name,
591591
Name.isOperator())
592592
.highlight(UDRE->getSourceRange());
593-
if (Context.LangOpts.EnableExperimentalClangImporterDiagnostics) {
593+
if (!Context.LangOpts.DisableExperimentalClangImporterDiagnostics) {
594594
Context.getClangModuleLoader()->diagnoseTopLevelValue(
595595
Name.getFullName());
596596
}

test/ClangImporter/experimental_clang_importer_diagnostics_bridging_header.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not %target-swift-frontend -enable-experimental-clang-importer-diagnostics -enable-objc-interop -import-objc-header %S/Inputs/experimental_clang_importer_diagnostics_bridging_header.h -typecheck %s 2>&1 | %FileCheck %s
1+
// RUN: not %target-swift-frontend -enable-objc-interop -import-objc-header %S/Inputs/experimental_clang_importer_diagnostics_bridging_header.h -typecheck %s 2>&1 | %FileCheck %s
22

33
let s: PartialImport
44
s.c = 5

test/ClangImporter/experimental_diagnostics_cfuncs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-experimental-clang-importer-diagnostics -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
1+
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
22

33
import cfuncs
44

test/ClangImporter/experimental_diagnostics_cmacros.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-experimental-clang-importer-diagnostics -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
1+
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
22

33
import macros
44

@@ -13,7 +13,6 @@ _ = INVALID_INTEGER_LITERAL_2
1313
// CHECK-NEXT: #define INVALID_INTEGER_LITERAL_2 10abc
1414
// CHECK-NEXT: {{^}} ^
1515

16-
1716
_ = FUNC_LIKE_MACRO()
1817
// CHECK: experimental_diagnostics_cmacros.swift:{{[0-9]+}}:{{[0-9]+}}: error: cannot find 'FUNC_LIKE_MACRO' in scope
1918
// CHECK-NEXT: _ = FUNC_LIKE_MACRO()

test/ClangImporter/experimental_diagnostics_cstructs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-experimental-clang-importer-diagnostics -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
1+
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
22

33
import ctypes
44

test/ClangImporter/experimental_diagnostics_incomplete_types.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-experimental-clang-importer-diagnostics -enable-objc-interop -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
1+
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
22

33
// REQUIRES: objc_interop
44

test/ClangImporter/experimental_diagnostics_incomplete_types_negative.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-experimental-clang-importer-diagnostics -enable-objc-interop -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
1+
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
22

33
// REQUIRES: objc_interop
44

test/ClangImporter/experimental_diagnostics_lookup_accuracy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not %target-swift-frontend -I %S/Inputs/custom-modules -enable-experimental-clang-importer-diagnostics -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
1+
// RUN: not %target-swift-frontend -I %S/Inputs/custom-modules -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
22

33
// This test tests that requests for diagnosis, performed by name,
44
// resolve to the correct Clang declarations, even when the same name is used
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
2+
3+
// REQUIRES: objc_interop
4+
5+
// Referencing a single declaration should only surface diagnostics about that declaration, no more
6+
7+
import IncompleteTypes
8+
import cfuncs
9+
import ctypes
10+
11+
// CHECK-NOT: note
12+
// CHECK-NOT: warning
13+
// CHECK-NOT: error
14+
let bar = Bar()
15+
_ = bar.methodReturningForwardDeclaredInterface()
16+
// CHECK: experimental_diagnostics_no_noise.swift:{{[0-9]+}}:{{[0-9]+}}: error: value of type 'Bar' has no member 'methodReturningForwardDeclaredInterface'
17+
// CHECK-NEXT: _ = bar.methodReturningForwardDeclaredInterface()
18+
// CHECK-NEXT: ~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19+
// CHECK-NEXT: IncompleteTypes.h:{{[0-9]+}}:{{[0-9]+}}: note: method 'methodReturningForwardDeclaredInterface' not imported
20+
// CHECK-NEXT: - (ForwardDeclaredInterface *) methodReturningForwardDeclaredInterface;
21+
// CHECK-NEXT: ^
22+
// CHECK-NEXT: IncompleteTypes.h:{{[0-9]+}}:{{[0-9]+}}: note: return type not imported
23+
// CHECK-NEXT: - (ForwardDeclaredInterface *) methodReturningForwardDeclaredInterface;
24+
// CHECK-NEXT: ^
25+
// CHECK-NEXT: IncompleteTypes.h:{{[0-9]+}}:{{[0-9]+}}: note: interface 'ForwardDeclaredInterface' is incomplete
26+
// CHECK-NEXT: - (ForwardDeclaredInterface *) methodReturningForwardDeclaredInterface;
27+
// CHECK-NEXT: ^
28+
// CHECK-NEXT: IncompleteTypes.h:{{[0-9]+}}:{{[0-9]+}}: note: interface 'ForwardDeclaredInterface' forward declared here
29+
// CHECK-NEXT: @class ForwardDeclaredInterface;
30+
// CHECK-NEXT: ^
31+
32+
// CHECK-NOT: note
33+
// CHECK-NOT: warning
34+
// CHECK-NOT: error
35+
unsupported_parameter_type(1,2)
36+
// CHECK: experimental_diagnostics_no_noise.swift:{{[0-9]+}}:{{[0-9]+}}: error: cannot find 'unsupported_parameter_type' in scope
37+
// CHECK-NEXT: unsupported_parameter_type(1,2)
38+
// CHECK-NEXT: ^~~~~~~~~~~~~~~~~~~~~~~~~~
39+
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:{{[0-9]+}}: note: function 'unsupported_parameter_type' not imported
40+
// CHECK-NEXT: int unsupported_parameter_type(int param1, _Complex int param2);
41+
// CHECK-NEXT: {{^}}^
42+
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:{{[0-9]+}}: note: parameter 'param2' not imported
43+
// CHECK-NEXT: int unsupported_parameter_type(int param1, _Complex int param2);
44+
// CHECK-NEXT: {{^}} ^
45+
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:{{[0-9]+}}: note: built-in type 'Complex' not supported
46+
// CHECK-NEXT: int unsupported_parameter_type(int param1, _Complex int param2);
47+
// CHECK-NEXT: {{^}} ^
48+
49+
// CHECK-NOT: note
50+
// CHECK-NOT: warning
51+
// CHECK-NOT: error
52+
let s: PartialImport
53+
s.c = 5
54+
// CHECK: experimental_diagnostics_no_noise.swift:{{[0-9]+}}:{{[0-9]+}}: error: value of type 'PartialImport' has no member 'c'
55+
// CHECK-NEXT: s.c = 5
56+
// CHECK-NEXT: ~ ^
57+
// CHECK-NEXT: ctypes.h:{{[0-9]+}}:{{[0-9]+}}: note: field 'c' not imported
58+
// CHECK-NEXT: int _Complex c;
59+
// CHECK-NEXT: ^
60+
// CHECK-NEXT: ctypes.h:{{[0-9]+}}:{{[0-9]+}}: note: built-in type 'Complex' not supported
61+
// CHECK-NEXT: int _Complex c;
62+
// CHECK-NEXT: ^
63+
// CHECK-NEXT: ctypes.PartialImport:{{[0-9]+}}:{{[0-9]+}}: note: did you mean 'a'?
64+
// CHECK-NEXT: public var a: Int32
65+
// CHECK-NEXT: ^
66+
// CHECK-NEXT: ctypes.PartialImport:{{[0-9]+}}:{{[0-9]+}}: note: did you mean 'b'?
67+
// CHECK-NEXT: public var b: Int32
68+
// CHECK-NEXT: ^
69+
70+
// CHECK-NOT: note
71+
// CHECK-NOT: warning
72+
// CHECK-NOT: error
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -disable-experimental-clang-importer-diagnostics -enable-objc-interop -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
2+
3+
// REQUIRES: objc_interop
4+
5+
import cfuncs
6+
import ctypes
7+
import IncompleteTypes
8+
9+
// CHECK-NOT: warning
10+
// CHECK-NOT: error
11+
// CHECK-NOT: note
12+
let bar = Bar()
13+
_ = bar.methodReturningForwardDeclaredInterface()
14+
// CHECK: experimental_diagnostics_opt_out.swift:{{[0-9]+}}:{{[0-9]+}}: error: value of type 'Bar' has no member 'methodReturningForwardDeclaredInterface'
15+
// CHECK-NOT: warning
16+
// CHECK-NOT: error
17+
// CHECK-NOT: note
18+
19+
// CHECK-NOT: warning
20+
// CHECK-NOT: error
21+
let s: PartialImport
22+
s.c = 5
23+
// CHECK: experimental_diagnostics_opt_out.swift:{{[0-9]+}}:{{[0-9]+}}: error: value of type 'PartialImport' has no member 'c'
24+
// CHECK: ctypes.PartialImport:{{[0-9]+}}:{{[0-9]+}}: note: did you mean 'a'?
25+
// CHECK: ctypes.PartialImport:{{[0-9]+}}:{{[0-9]+}}: note: did you mean 'b'?
26+
// CHECK-NOT: warning
27+
// CHECK-NOT: error
28+
// CHECK-NOT: note
29+
30+
// CHECK-NOT: warning
31+
// CHECK-NOT: error
32+
unsupported_parameter_type(1,2)
33+
// CHECK: experimental_diagnostics_opt_out.swift:{{[0-9]+}}:{{[0-9]+}}: error: cannot find 'unsupported_parameter_type' in scope
34+
// CHECK-NOT: warning
35+
// CHECK-NOT: error
36+
// CHECK-NOT: note

test/ClangImporter/experimental_diagnostics_unreferenced_cmacros.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-experimental-clang-importer-diagnostics -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
1+
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
22

33
import macros
44

0 commit comments

Comments
 (0)