Skip to content

Commit d653a01

Browse files
authored
Merge pull request #76278 from swiftlang/elsh/pcmo-diags
2 parents d71bd2d + f8cbe89 commit d653a01

File tree

6 files changed

+56
-6
lines changed

6 files changed

+56
-6
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+
ERROR(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
@@ -2687,6 +2687,8 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
26872687
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
26882688
"-package-cmo",
26892689
"-allow-non-resilient-access");
2690+
} else if (!FEOpts.EnableLibraryEvolution) {
2691+
Diags.diagnose(SourceLoc(), diag::package_cmo_requires_library_evolution);
26902692
} else {
26912693
Opts.EnableSerializePackage = true;
26922694
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

test/SILOptimizer/package-cmo-non-resilient-mode.swift renamed to test/SILOptimizer/cmo-with-package-decls.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-build-swift -O -wmo -Xfrontend -experimental-package-cmo -Xfrontend -experimental-allow-non-resilient-access -parse-as-library -emit-module -emit-module-path=%t/Submodule.swiftmodule -module-name=Submodule -package-name Pkg %S/Inputs/cross-module/default-submodule.swift -c -o %t/submodule.o
3-
// RUN: %target-build-swift -O -wmo -Xfrontend -experimental-package-cmo -Xfrontend -experimental-allow-non-resilient-access -parse-as-library -emit-module -emit-module-path=%t/Module.swiftmodule -module-name=Module -package-name Pkg -I%t -I%S/Inputs/cross-module %S/Inputs/cross-module/default-module.swift -c -o %t/module.o
4-
// RUN: %target-build-swift -O -wmo -Xfrontend -experimental-package-cmo -Xfrontend -experimental-allow-non-resilient-access -parse-as-library -emit-tbd -emit-tbd-path %t/ModuleTBD.tbd -emit-module -emit-module-path=%t/ModuleTBD.swiftmodule -module-name=ModuleTBD -package-name Pkg -I%t -I%S/Inputs/cross-module %S/Inputs/cross-module/default-module.swift -c -o %t/moduletbd.o -Xfrontend -tbd-install_name -Xfrontend module
2+
// RUN: %target-build-swift -O -wmo -Xfrontend -enable-default-cmo -parse-as-library -emit-module -emit-module-path=%t/Submodule.swiftmodule -module-name=Submodule -package-name Pkg %S/Inputs/cross-module/default-submodule.swift -c -o %t/submodule.o
3+
// RUN: %target-build-swift -O -wmo -Xfrontend -enable-default-cmo -parse-as-library -emit-module -emit-module-path=%t/Module.swiftmodule -module-name=Module -package-name Pkg -I%t -I%S/Inputs/cross-module %S/Inputs/cross-module/default-module.swift -c -o %t/module.o
4+
// RUN: %target-build-swift -O -wmo -Xfrontend -enable-default-cmo -parse-as-library -emit-tbd -emit-tbd-path %t/ModuleTBD.tbd -emit-module -emit-module-path=%t/ModuleTBD.swiftmodule -module-name=ModuleTBD -package-name Pkg -I%t -I%S/Inputs/cross-module %S/Inputs/cross-module/default-module.swift -c -o %t/moduletbd.o -Xfrontend -tbd-install_name -Xfrontend module
55

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

test/SILOptimizer/package-cmo-resilient-mode.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: split-file %s %t
33

4+
/// Enable Package CMO; conservative mode on resilient module.
45
// RUN: %target-build-swift %t/Lib.swift \
56
// RUN: -module-name=Lib -package-name Pkg \
67
// RUN: -parse-as-library -emit-module -emit-module-path %t/Lib.swiftmodule -I%t \
@@ -18,10 +19,12 @@
1819

1920
// RUN: rm -rf %t/Lib.swiftmodule
2021

22+
/// Enable non-package CMO; conservative mode on non-resilient module,
23+
/// and compare results with Package CMO.
2124
// RUN: %target-build-swift %t/Lib.swift \
2225
// RUN: -module-name=Lib -package-name Pkg \
2326
// RUN: -parse-as-library -emit-module -emit-module-path %t/Lib.swiftmodule -I%t \
24-
// RUN: -Xfrontend -experimental-package-cmo -Xfrontend -experimental-allow-non-resilient-access \
27+
// RUN: -Xfrontend -enable-default-cmo \
2528
// RUN: -O -wmo
2629

2730
// RUN: %target-sil-opt %t/Lib.swiftmodule -sil-verify-all -o %t/Lib-non-res.sil

0 commit comments

Comments
 (0)