Skip to content

Commit 7dcb530

Browse files
committed
SIL: serialize computed effects for @alwaysEmitIntoClient functions, even if library evolution is turned on.
This is possible because no copy of the function is emitted in the original module.
1 parent 6517817 commit 7dcb530

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

lib/Serialization/SerializeSIL.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,16 @@ void SILSerializer::writeSILFunction(const SILFunction &F, bool DeclOnly) {
529529

530530
unsigned numAttrs = NoBody ? 0 : F.getSpecializeAttrs().size();
531531
auto resilience = F.getModule().getSwiftModule()->getResilienceStrategy();
532-
bool serializeDerivedEffects = (resilience != ResilienceStrategy::Resilient) &&
533-
!F.hasSemanticsAttr("optimize.no.crossmodule");
532+
bool serializeDerivedEffects =
533+
// We must not serialize computed effects if library evolution is turned on,
534+
// because the copy of the function, which is emitted into the current module,
535+
// might have different effects in different versions of the library.
536+
(resilience != ResilienceStrategy::Resilient ||
537+
// But we can serialize computed effects for @alwaysEmitIntoClient functions,
538+
// even when library evolution is enabled, because no copy of the function is
539+
// emitted in the original module.
540+
F.getLinkage() == SILLinkage::PublicNonABI) &&
541+
!F.hasSemanticsAttr("optimize.no.crossmodule");
534542

535543
F.visitArgEffects(
536544
[&](int effectIdx, int argumentIndex, bool isDerived) {

test/SIL/Serialization/effects.sil

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %s -module-name=NonLE -emit-module -o %t/NonLE.swiftmodule
3+
// RUN: %target-swift-frontend %s -module-name=LE -enable-library-evolution -emit-module -o %t/LE.swiftmodule
4+
// RUN: %target-sil-opt %t/NonLE.swiftmodule | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NONLE
5+
// RUN: %target-sil-opt %t/LE.swiftmodule | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-LE
6+
7+
sil_stage canonical
8+
9+
import Swift
10+
import Builtin
11+
12+
// CHECK-LABEL: sil [serialized] [canonical] [ossa] @public_func :
13+
// CHECK-NONLE-NEXT: [global: ]
14+
// CHECK-NEXT: bb0:
15+
sil [serialized] [ossa] @public_func : $@convention(thin) () -> () {
16+
[global: ]
17+
bb0:
18+
%r = tuple ()
19+
return %r
20+
}
21+
22+
// CHECK-LABEL: sil non_abi [serialized] [canonical] [ossa] @public_non_abi_func :
23+
// CHECK-NEXT: [global: ]
24+
// CHECK-NEXT: bb0:
25+
sil non_abi [serialized] [ossa] @public_non_abi_func : $@convention(thin) () -> () {
26+
[global: ]
27+
bb0:
28+
%r = tuple ()
29+
return %r
30+
}
31+

0 commit comments

Comments
 (0)