Skip to content

Commit b9f00ef

Browse files
committed
Warn about the use of internal bridging headers without library evolution
It's very, very easy to make a mistake that will cause broken serialized modules. Until that's no longer true, at least tell folks that they are heading into uncharted waters, as we do with `@_implementationOnly` imports.
1 parent 903937a commit b9f00ef

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,9 @@ ERROR(no_swift_sources_with_embedded,none,
609609
ERROR(package_cmo_requires_library_evolution, none,
610610
"Library evolution must be enabled for Package CMO", ())
611611

612+
WARNING(internal_bridging_header_without_library_evolution,none,
613+
"using internal bridging headers without library evolution can cause instability", ())
614+
612615
ERROR(experimental_not_supported_in_production,none,
613616
"experimental feature '%0' cannot be enabled in production compiler",
614617
(StringRef))

lib/Frontend/CompilerInvocation.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,6 +2129,13 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts, ArgList &Args,
21292129
Opts.BridgingHeaderIsInternal = importAsInternal;
21302130
}
21312131

2132+
// Until we have some checking in place, internal bridging headers are a
2133+
// bit unsafe without library evolution.
2134+
if (Opts.BridgingHeaderIsInternal && !FrontendOpts.EnableLibraryEvolution) {
2135+
Diags.diagnose(SourceLoc(),
2136+
diag::internal_bridging_header_without_library_evolution);
2137+
}
2138+
21322139
Opts.DisableSwiftBridgeAttr |= Args.hasArg(OPT_disable_swift_bridge_attr);
21332140

21342141
Opts.DisableOverlayModules |= Args.hasArg(OPT_emit_imported_modules);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -internal-import-bridging-header %S/../Inputs/c-bridging-header.h -sdk %clang-importer-sdk %s 2>&1 | %FileCheck -check-prefix NONRESILIENT %s
2+
3+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -internal-import-bridging-header %S/../Inputs/c-bridging-header.h -sdk %clang-importer-sdk %s -enable-library-evolution 2>&1 | %FileCheck -check-prefix EVOLUTION %s
4+
5+
// NONRESILIENT: warning: using internal bridging headers without library evolution can cause instability
6+
7+
// EVOLUTION-NOT: internal bridging head
8+
9+
@available(*, deprecated)
10+
func f() { }
11+
12+
func g(){
13+
f() // make sure we emit something
14+
}

0 commit comments

Comments
 (0)