Skip to content

[5.1] [ModuleInterfaces] Warn when emitting an interface in unsupported scenarios #24442

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
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
7 changes: 7 additions & 0 deletions include/swift/AST/DiagnosticsFrontend.def
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ ERROR(invalid_vfs_overlay_file,none,
WARNING(module_interface_scoped_import_unsupported,none,
"scoped imports are not yet supported in module interfaces",
())
WARNING(warn_unsupported_module_interface_swift_version,none,
"module interfaces are only supported with Swift language version 5 "
"or later (currently using -swift-version %0)",
(StringRef))
WARNING(warn_unsupported_module_interface_library_evolution,none,
"module interfaces are only supported with -enable-library-evolution",
())
ERROR(error_extracting_version_from_module_interface,none,
"error extracting version from module interface", ())
ERROR(unsupported_version_of_module_interface,none,
Expand Down
23 changes: 19 additions & 4 deletions lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,26 @@ static bool printAsObjCIfNeeded(StringRef outputPath, ModuleDecl *M,
/// \returns true if there were any errors
///
/// \see swift::emitParseableInterface
static bool printParseableInterfaceIfNeeded(StringRef outputPath,
ParseableInterfaceOptions const &Opts,
ModuleDecl *M) {
static bool
printParseableInterfaceIfNeeded(StringRef outputPath,
ParseableInterfaceOptions const &Opts,
LangOptions const &LangOpts,
ModuleDecl *M) {
if (outputPath.empty())
return false;
return withOutputFile(M->getDiags(), outputPath,

DiagnosticEngine &diags = M->getDiags();
if (!LangOpts.isSwiftVersionAtLeast(5)) {
assert(LangOpts.isSwiftVersionAtLeast(4));
diags.diagnose(SourceLoc(),
diag::warn_unsupported_module_interface_swift_version,
LangOpts.isSwiftVersionAtLeast(4, 2) ? "4.2" : "4");
}
if (M->getResilienceStrategy() != ResilienceStrategy::Resilient) {
diags.diagnose(SourceLoc(),
diag::warn_unsupported_module_interface_library_evolution);
}
return withOutputFile(diags, outputPath,
[M, Opts](raw_ostream &out) -> bool {
return swift::emitParseableInterface(out, Opts, M);
});
Expand Down Expand Up @@ -922,6 +936,7 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
hadAnyError |= printParseableInterfaceIfNeeded(
Invocation.getParseableInterfaceOutputPathForWholeModule(),
Invocation.getParseableInterfaceOptions(),
Invocation.getLangOptions(),
Instance.getMainModule());
}

Expand Down
2 changes: 1 addition & 1 deletion test/ParseableInterface/imports.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -o %t/empty.swiftmodule %S/../Inputs/empty.swift
// RUN: %target-swift-frontend -typecheck -emit-parseable-module-interface-path - %s %S/Inputs/imports-other.swift -I %S/Inputs/imports-clang-modules/ -I %t -verify | %FileCheck -implicit-check-not BAD %s
// RUN: %target-swift-frontend -typecheck -emit-parseable-module-interface-path - %s %S/Inputs/imports-other.swift -I %S/Inputs/imports-clang-modules/ -I %t -verify -swift-version 5 -enable-library-evolution | %FileCheck -implicit-check-not BAD %s


@_exported import empty
Expand Down
33 changes: 33 additions & 0 deletions test/ParseableInterface/unsupported-configurations.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -typecheck -emit-parseable-module-interface-path %t/empty.swiftinterface %s -swift-version 4 2>&1 | %FileCheck -DVERSION=4 %s
// RUN: ls %t/empty.swiftinterface

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -typecheck -emit-parseable-module-interface-path %t/empty.swiftinterface %s -swift-version 4.2 2>&1 | %FileCheck -DVERSION=4.2 %s
// RUN: ls %t/empty.swiftinterface

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -typecheck -emit-parseable-module-interface-path %t/empty.swiftinterface %s -swift-version 4.2 -enable-library-evolution 2>&1 | %FileCheck -check-prefix=CHECK-VERSION-ONLY -DVERSION=4.2 %s
// RUN: ls %t/empty.swiftinterface

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -typecheck -emit-parseable-module-interface-path %t/empty.swiftinterface %s -swift-version 5 2>&1 | %FileCheck -check-prefix=CHECK-EVOLUTION-ONLY %s
// RUN: ls %t/empty.swiftinterface

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -typecheck -emit-parseable-module-interface-path %t/empty.swiftinterface %s -swift-version 5 -enable-library-evolution 2>&1 | %FileCheck -check-prefix=NEGATIVE -allow-empty %s
// RUN: ls %t/empty.swiftinterface

// CHECK-DAG: warning: module interfaces are only supported with Swift language version 5 or later (currently using -swift-version [[VERSION]])
// CHECK-DAG: warning: module interfaces are only supported with -enable-library-evolution

// CHECK-VERSION-ONLY-NOT: warning:
// CHECK-VERSION-ONLY: warning: module interfaces are only supported with Swift language version 5 or later (currently using -swift-version [[VERSION]])
// CHECK-VERSION-ONLY-NOT: warning:

// CHECK-EVOLUTION-ONLY-NOT: warning:
// CHECK-EVOLUTION-ONLY: warning: module interfaces are only supported with -enable-library-evolution
// CHECK-EVOLUTION-ONLY-NOT: warning:

// NEGATIVE-NOT: warning:
// NEGATIVE-NOT: error: