Skip to content

Commit 1e5637f

Browse files
authored
Merge pull request #24420 from jrose-apple/underpromise
[ModuleInterfaces] Warn when emitting an interface in unsupported scenarios
2 parents 8d2b1bb + 3eff026 commit 1e5637f

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,13 @@ ERROR(invalid_vfs_overlay_file,none,
261261
WARNING(module_interface_scoped_import_unsupported,none,
262262
"scoped imports are not yet supported in module interfaces",
263263
())
264+
WARNING(warn_unsupported_module_interface_swift_version,none,
265+
"module interfaces are only supported with Swift language version 5 "
266+
"or later (currently using -swift-version %0)",
267+
(StringRef))
268+
WARNING(warn_unsupported_module_interface_library_evolution,none,
269+
"module interfaces are only supported with -enable-library-evolution",
270+
())
264271
ERROR(error_extracting_version_from_module_interface,none,
265272
"error extracting version from module interface", ())
266273
ERROR(unsupported_version_of_module_interface,none,

lib/FrontendTool/FrontendTool.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,26 @@ static bool printAsObjCIfNeeded(StringRef outputPath, ModuleDecl *M,
358358
/// \returns true if there were any errors
359359
///
360360
/// \see swift::emitParseableInterface
361-
static bool printParseableInterfaceIfNeeded(StringRef outputPath,
362-
ParseableInterfaceOptions const &Opts,
363-
ModuleDecl *M) {
361+
static bool
362+
printParseableInterfaceIfNeeded(StringRef outputPath,
363+
ParseableInterfaceOptions const &Opts,
364+
LangOptions const &LangOpts,
365+
ModuleDecl *M) {
364366
if (outputPath.empty())
365367
return false;
366-
return withOutputFile(M->getDiags(), outputPath,
368+
369+
DiagnosticEngine &diags = M->getDiags();
370+
if (!LangOpts.isSwiftVersionAtLeast(5)) {
371+
assert(LangOpts.isSwiftVersionAtLeast(4));
372+
diags.diagnose(SourceLoc(),
373+
diag::warn_unsupported_module_interface_swift_version,
374+
LangOpts.isSwiftVersionAtLeast(4, 2) ? "4.2" : "4");
375+
}
376+
if (M->getResilienceStrategy() != ResilienceStrategy::Resilient) {
377+
diags.diagnose(SourceLoc(),
378+
diag::warn_unsupported_module_interface_library_evolution);
379+
}
380+
return withOutputFile(diags, outputPath,
367381
[M, Opts](raw_ostream &out) -> bool {
368382
return swift::emitParseableInterface(out, Opts, M);
369383
});
@@ -921,6 +935,7 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
921935
hadAnyError |= printParseableInterfaceIfNeeded(
922936
Invocation.getParseableInterfaceOutputPathForWholeModule(),
923937
Invocation.getParseableInterfaceOptions(),
938+
Invocation.getLangOptions(),
924939
Instance.getMainModule());
925940
}
926941

test/ParseableInterface/imports.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -emit-module -o %t/empty.swiftmodule %S/../Inputs/empty.swift
3-
// 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
3+
// 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
44

55

66
@_exported import empty
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -typecheck -emit-parseable-module-interface-path %t/empty.swiftinterface %s -swift-version 4 2>&1 | %FileCheck -DVERSION=4 %s
3+
// RUN: ls %t/empty.swiftinterface
4+
5+
// RUN: %empty-directory(%t)
6+
// 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
7+
// RUN: ls %t/empty.swiftinterface
8+
9+
// RUN: %empty-directory(%t)
10+
// 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
11+
// RUN: ls %t/empty.swiftinterface
12+
13+
// RUN: %empty-directory(%t)
14+
// 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
15+
// RUN: ls %t/empty.swiftinterface
16+
17+
// RUN: %empty-directory(%t)
18+
// 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
19+
// RUN: ls %t/empty.swiftinterface
20+
21+
// CHECK-DAG: warning: module interfaces are only supported with Swift language version 5 or later (currently using -swift-version [[VERSION]])
22+
// CHECK-DAG: warning: module interfaces are only supported with -enable-library-evolution
23+
24+
// CHECK-VERSION-ONLY-NOT: warning:
25+
// CHECK-VERSION-ONLY: warning: module interfaces are only supported with Swift language version 5 or later (currently using -swift-version [[VERSION]])
26+
// CHECK-VERSION-ONLY-NOT: warning:
27+
28+
// CHECK-EVOLUTION-ONLY-NOT: warning:
29+
// CHECK-EVOLUTION-ONLY: warning: module interfaces are only supported with -enable-library-evolution
30+
// CHECK-EVOLUTION-ONLY-NOT: warning:
31+
32+
// NEGATIVE-NOT: warning:
33+
// NEGATIVE-NOT: error:

0 commit comments

Comments
 (0)