Skip to content

Enable lazy ClangImporter diagnostics by default #40903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ namespace swift {
/// Enable experimental flow-sensitive concurrent captures.
bool EnableExperimentalFlowSensitiveConcurrentCaptures = false;

/// Enable experimental ClangImporter diagnostics.
bool EnableExperimentalClangImporterDiagnostics = false;
/// Disable experimental ClangImporter diagnostics.
bool DisableExperimentalClangImporterDiagnostics = false;

/// Enable experimental eager Clang module diagnostics.
bool EnableExperimentalEagerClangModuleDiagnostics = false;
Expand Down
6 changes: 3 additions & 3 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ def enable_experimental_flow_sensitive_concurrent_captures :
Flag<["-"], "enable-experimental-flow-sensitive-concurrent-captures">,
HelpText<"Enable flow-sensitive concurrent captures">;

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

def enable_experimental_eager_clang_module_diagnostics :
Flag<["-"], "enable-experimental-eager-clang-module-diagnostics">,
Expand Down
3 changes: 1 addition & 2 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2397,8 +2397,7 @@ void ClangImporter::Implementation::addImportDiagnostic(
ImportDiagnosticTarget target, Diagnostic &&diag,
const clang::SourceLocation &loc) {
ImportDiagnostic importDiag = ImportDiagnostic(target, diag, loc);
if (!(SwiftContext.LangOpts.EnableExperimentalClangImporterDiagnostics ||
SwiftContext.LangOpts.EnableExperimentalEagerClangModuleDiagnostics) ||
if (SwiftContext.LangOpts.DisableExperimentalClangImporterDiagnostics ||
CollectedDiagnostics.count(importDiag))
return;

Expand Down
5 changes: 3 additions & 2 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,11 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.EnableExperimentalFlowSensitiveConcurrentCaptures |=
Args.hasArg(OPT_enable_experimental_flow_sensitive_concurrent_captures);

Opts.EnableExperimentalClangImporterDiagnostics |=
Args.hasArg(OPT_enable_experimental_clang_importer_diagnostics);
Opts.DisableExperimentalClangImporterDiagnostics |=
Args.hasArg(OPT_disable_experimental_clang_importer_diagnostics);

Opts.EnableExperimentalEagerClangModuleDiagnostics |=
!Args.hasArg(OPT_disable_experimental_clang_importer_diagnostics) &&
Args.hasArg(OPT_enable_experimental_eager_clang_module_diagnostics);

Opts.DisableImplicitConcurrencyModuleImport |=
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3627,7 +3627,7 @@ bool MissingMemberFailure::diagnoseAsError() {
.highlight(getSourceRange())
.highlight(nameLoc.getSourceRange());
const auto &ctx = getSolution().getDC()->getASTContext();
if (ctx.LangOpts.EnableExperimentalClangImporterDiagnostics) {
if (!ctx.LangOpts.DisableExperimentalClangImporterDiagnostics) {
ctx.getClangModuleLoader()->diagnoseMemberValue(getName().getFullName(),
baseType);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/PreCheckExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
.diagnose(Loc, diag::cannot_find_in_scope, Name,
Name.isOperator())
.highlight(UDRE->getSourceRange());
if (Context.LangOpts.EnableExperimentalClangImporterDiagnostics) {
if (!Context.LangOpts.DisableExperimentalClangImporterDiagnostics) {
Context.getClangModuleLoader()->diagnoseTopLevelValue(
Name.getFullName());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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
// 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

let s: PartialImport
s.c = 5
Expand Down
2 changes: 1 addition & 1 deletion test/ClangImporter/experimental_diagnostics_cfuncs.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-experimental-clang-importer-diagnostics -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace

import cfuncs

Expand Down
3 changes: 1 addition & 2 deletions test/ClangImporter/experimental_diagnostics_cmacros.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-experimental-clang-importer-diagnostics -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace

import macros

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


_ = FUNC_LIKE_MACRO()
// CHECK: experimental_diagnostics_cmacros.swift:{{[0-9]+}}:{{[0-9]+}}: error: cannot find 'FUNC_LIKE_MACRO' in scope
// CHECK-NEXT: _ = FUNC_LIKE_MACRO()
Expand Down
2 changes: 1 addition & 1 deletion test/ClangImporter/experimental_diagnostics_cstructs.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-experimental-clang-importer-diagnostics -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace

import ctypes

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace

// REQUIRES: objc_interop

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace

// REQUIRES: objc_interop

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: not %target-swift-frontend -I %S/Inputs/custom-modules -enable-experimental-clang-importer-diagnostics -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
// RUN: not %target-swift-frontend -I %S/Inputs/custom-modules -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace

// This test tests that requests for diagnosis, performed by name,
// resolve to the correct Clang declarations, even when the same name is used
Expand Down
72 changes: 72 additions & 0 deletions test/ClangImporter/experimental_diagnostics_no_noise.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace

// REQUIRES: objc_interop

// Referencing a single declaration should only surface diagnostics about that declaration, no more

import IncompleteTypes
import cfuncs
import ctypes

// CHECK-NOT: note
// CHECK-NOT: warning
// CHECK-NOT: error
let bar = Bar()
_ = bar.methodReturningForwardDeclaredInterface()
// CHECK: experimental_diagnostics_no_noise.swift:{{[0-9]+}}:{{[0-9]+}}: error: value of type 'Bar' has no member 'methodReturningForwardDeclaredInterface'
// CHECK-NEXT: _ = bar.methodReturningForwardDeclaredInterface()
// CHECK-NEXT: ~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK-NEXT: IncompleteTypes.h:{{[0-9]+}}:{{[0-9]+}}: note: method 'methodReturningForwardDeclaredInterface' not imported
// CHECK-NEXT: - (ForwardDeclaredInterface *) methodReturningForwardDeclaredInterface;
// CHECK-NEXT: ^
// CHECK-NEXT: IncompleteTypes.h:{{[0-9]+}}:{{[0-9]+}}: note: return type not imported
// CHECK-NEXT: - (ForwardDeclaredInterface *) methodReturningForwardDeclaredInterface;
// CHECK-NEXT: ^
// CHECK-NEXT: IncompleteTypes.h:{{[0-9]+}}:{{[0-9]+}}: note: interface 'ForwardDeclaredInterface' is incomplete
// CHECK-NEXT: - (ForwardDeclaredInterface *) methodReturningForwardDeclaredInterface;
// CHECK-NEXT: ^
// CHECK-NEXT: IncompleteTypes.h:{{[0-9]+}}:{{[0-9]+}}: note: interface 'ForwardDeclaredInterface' forward declared here
// CHECK-NEXT: @class ForwardDeclaredInterface;
// CHECK-NEXT: ^

// CHECK-NOT: note
// CHECK-NOT: warning
// CHECK-NOT: error
unsupported_parameter_type(1,2)
// CHECK: experimental_diagnostics_no_noise.swift:{{[0-9]+}}:{{[0-9]+}}: error: cannot find 'unsupported_parameter_type' in scope
// CHECK-NEXT: unsupported_parameter_type(1,2)
// CHECK-NEXT: ^~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:{{[0-9]+}}: note: function 'unsupported_parameter_type' not imported
// CHECK-NEXT: int unsupported_parameter_type(int param1, _Complex int param2);
// CHECK-NEXT: {{^}}^
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:{{[0-9]+}}: note: parameter 'param2' not imported
// CHECK-NEXT: int unsupported_parameter_type(int param1, _Complex int param2);
// CHECK-NEXT: {{^}} ^
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:{{[0-9]+}}: note: built-in type 'Complex' not supported
// CHECK-NEXT: int unsupported_parameter_type(int param1, _Complex int param2);
// CHECK-NEXT: {{^}} ^

// CHECK-NOT: note
// CHECK-NOT: warning
// CHECK-NOT: error
let s: PartialImport
s.c = 5
// CHECK: experimental_diagnostics_no_noise.swift:{{[0-9]+}}:{{[0-9]+}}: error: value of type 'PartialImport' has no member 'c'
// CHECK-NEXT: s.c = 5
// CHECK-NEXT: ~ ^
// CHECK-NEXT: ctypes.h:{{[0-9]+}}:{{[0-9]+}}: note: field 'c' not imported
// CHECK-NEXT: int _Complex c;
// CHECK-NEXT: ^
// CHECK-NEXT: ctypes.h:{{[0-9]+}}:{{[0-9]+}}: note: built-in type 'Complex' not supported
// CHECK-NEXT: int _Complex c;
// CHECK-NEXT: ^
// CHECK-NEXT: ctypes.PartialImport:{{[0-9]+}}:{{[0-9]+}}: note: did you mean 'a'?
// CHECK-NEXT: public var a: Int32
// CHECK-NEXT: ^
// CHECK-NEXT: ctypes.PartialImport:{{[0-9]+}}:{{[0-9]+}}: note: did you mean 'b'?
// CHECK-NEXT: public var b: Int32
// CHECK-NEXT: ^

// CHECK-NOT: note
// CHECK-NOT: warning
// CHECK-NOT: error
36 changes: 36 additions & 0 deletions test/ClangImporter/experimental_diagnostics_opt_out.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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

// REQUIRES: objc_interop

import cfuncs
import ctypes
import IncompleteTypes

// CHECK-NOT: warning
// CHECK-NOT: error
// CHECK-NOT: note
let bar = Bar()
_ = bar.methodReturningForwardDeclaredInterface()
// CHECK: experimental_diagnostics_opt_out.swift:{{[0-9]+}}:{{[0-9]+}}: error: value of type 'Bar' has no member 'methodReturningForwardDeclaredInterface'
// CHECK-NOT: warning
// CHECK-NOT: error
// CHECK-NOT: note

// CHECK-NOT: warning
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Remove unnecessary CHECK-NOTs

// CHECK-NOT: error
let s: PartialImport
s.c = 5
// CHECK: experimental_diagnostics_opt_out.swift:{{[0-9]+}}:{{[0-9]+}}: error: value of type 'PartialImport' has no member 'c'
// CHECK: ctypes.PartialImport:{{[0-9]+}}:{{[0-9]+}}: note: did you mean 'a'?
// CHECK: ctypes.PartialImport:{{[0-9]+}}:{{[0-9]+}}: note: did you mean 'b'?
// CHECK-NOT: warning
// CHECK-NOT: error
// CHECK-NOT: note

// CHECK-NOT: warning
// CHECK-NOT: error
unsupported_parameter_type(1,2)
// CHECK: experimental_diagnostics_opt_out.swift:{{[0-9]+}}:{{[0-9]+}}: error: cannot find 'unsupported_parameter_type' in scope
// CHECK-NOT: warning
// CHECK-NOT: error
// CHECK-NOT: note
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-experimental-clang-importer-diagnostics -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace

import macros

Expand Down