Skip to content

Commit 66b504a

Browse files
committed
[Package CMO] Diagnose missing library-evolution flag.
This PR ensures library-evolution is enabled for Package CMO; without it, it previously fell back to regular CMO, which caused mismatching serialization attributes if importing another module that had Package CMO enbaled, causing an assert fail for loadable types. Resolves rdar://135308288
1 parent 9ac56f2 commit 66b504a

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,9 @@ ERROR(no_allocations_without_embedded,none,
576576
ERROR(no_swift_sources_with_embedded,none,
577577
"embedded swift cannot be enabled in a compiler built without Swift sources", ())
578578

579+
WARNING(package_cmo_requires_library_evolution, none,
580+
"Library evolution must be enabled for Package CMO", ())
581+
579582
ERROR(experimental_not_supported_in_production,none,
580583
"experimental feature '%0' cannot be enabled in production compiler",
581584
(StringRef))

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,6 +2688,8 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
26882688
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
26892689
"-package-cmo",
26902690
"-allow-non-resilient-access");
2691+
} else if (!FEOpts.EnableLibraryEvolution) {
2692+
Diags.diagnose(SourceLoc(), diag::package_cmo_requires_library_evolution);
26912693
} else {
26922694
Opts.EnableSerializePackage = true;
26932695
Opts.CMOMode = CrossModuleOptimizationMode::Default;

lib/SILOptimizer/IPO/CrossModuleOptimization.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,9 +947,15 @@ void CrossModuleOptimization::makeSubstUsableFromInline(
947947
class CrossModuleOptimizationPass: public SILModuleTransform {
948948
void run() override {
949949
auto &M = *getModule();
950-
if (M.getSwiftModule()->isResilient() &&
951-
!M.getSwiftModule()->serializePackageEnabled())
950+
if (M.getSwiftModule()->serializePackageEnabled()) {
951+
assert(M.getSwiftModule()->isResilient() &&
952+
"Package CMO requires library-evolution");
953+
} else if (M.getSwiftModule()->isResilient()) {
954+
// If no Package CMO flags are passed and library
955+
// evolution is enabled, just return.
952956
return;
957+
}
958+
953959
if (!M.isWholeModule())
954960
return;
955961

@@ -974,6 +980,9 @@ class CrossModuleOptimizationPass: public SILModuleTransform {
974980
return;
975981
}
976982

983+
if (isPackageCMOEnabled(M.getSwiftModule()))
984+
assert(conservative && "Package CMO requires conservative CMO mode");
985+
977986
CrossModuleOptimization CMO(M, conservative, everything);
978987
CMO.serializeFunctionsInModule(PM);
979988

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-build-swift %s \
4+
// RUN: -module-name=Lib -package-name Pkg \
5+
// RUN: -emit-module -o %t/Lib.swiftmodule -I%t \
6+
// RUN: -Xfrontend -package-cmo \
7+
// RUN: -Xfrontend -allow-non-resilient-access \
8+
// RUN: -O -wmo 2>&1 | %FileCheck %s --check-prefix CHECK-WARNING
9+
// CHECK-WARNING: warning: Library evolution must be enabled for Package CMO
10+
11+
// RUN: llvm-bcanalyzer %t/Lib.swiftmodule | %FileCheck %s -check-prefix=CHECK-BC
12+
// CHECK-BC-NOT: SERIALIZE_PACKAGE_ENABLED
13+
14+
// RUN: rm -rf %t/Lib.swiftmodule
15+
16+
// RUN: %target-build-swift %s \
17+
// RUN: -module-name=Lib -package-name Pkg \
18+
// RUN: -emit-module -o %t/Lib.swiftmodule -I%t \
19+
// RUN: -Xfrontend -package-cmo \
20+
// RUN: -Xfrontend -allow-non-resilient-access \
21+
// RUN: -enable-library-evolution \
22+
// RUN: -O -wmo
23+
24+
// RUN: llvm-bcanalyzer %t/Lib.swiftmodule | %FileCheck %s -check-prefix=CHECK-OK
25+
// CHECK-OK: SERIALIZE_PACKAGE_ENABLED
26+
27+
// REQUIRES: swift_in_compiler
28+
29+
public struct S {
30+
public init() {}
31+
package var x: Int {
32+
get { return 0 }
33+
set {}
34+
}
35+
package func f() -> Int {
36+
return 1
37+
}
38+
}

0 commit comments

Comments
 (0)