Skip to content

Commit 4dc593d

Browse files
committed
[move-only] Do not attempt to lazily deserialize the moveonly deinit table in IRGen.
The reason to avoid this is if we attempt to lazily deserialize the moveonly deinit table, we may also attempt to deserialize a deinit function. This would result in us breaking the invariant that we no longer deserialize SILFunctions once we are in LoweredSIL. If we fail to lazily deserialize, we instead just call the deinit via the destroy value witness of the type. This only affects builds built with asserts enabled since llvm_unreachable is compiled out when NDEBUG is set. rdar://110496872
1 parent 9991468 commit 4dc593d

File tree

4 files changed

+41
-21
lines changed

4 files changed

+41
-21
lines changed

lib/IRGen/GenType.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2897,9 +2897,11 @@ static bool tryEmitDeinitCall(IRGenFunction &IGF,
28972897
return false;
28982898
}
28992899

2900-
auto deinitTable = IGF.getSILModule().lookUpMoveOnlyDeinit(nominal);
2900+
auto deinitTable = IGF.getSILModule().lookUpMoveOnlyDeinit(
2901+
nominal, false /*deserialize lazily*/);
29012902

2902-
// If we do not have a deinit table, call the value witness instead.
2903+
// If we do not have a deinit table already deserialized, call the value
2904+
// witness instead.
29032905
if (!deinitTable) {
29042906
irgen::emitDestroyCall(IGF, T, indirect());
29052907
indirectCleanup();
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11

2-
#if TEST_LIBRARY_EVOLUTION
2+
#if TEST_LIBRARY_WITH_LIBRARY_EVOLUTION
33
public struct MoveOnly : ~Copyable {
44
var name = "John"
55
public init() {}
66
deinit {
7-
print("==> I am in the deinit resiliently!")
7+
print("==> LIBRARY_EVOLUTION: I am in the deinit!")
88
print("==> My name is: \(name)!")
99
}
1010
}
1111
#else
12+
13+
#if TEST_LIBRARY_WITHOUT_LIBRARY_EVOLUTION
14+
15+
public class MoveOnly {
16+
var name = "John"
17+
public init() {}
18+
deinit {
19+
print("==> LIBRARY: I am in the deinit!")
20+
print("==> My name is: \(name)!")
21+
}
22+
}
23+
24+
#else
25+
1226
struct MoveOnly : ~Copyable {
1327
var name = "John"
1428
deinit {
1529
print("==> I am in the deinit!")
1630
print("==> My name is: \(name)!")
1731
}
1832
}
33+
34+
#endif
1935
#endif
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %empty-directory(%t/normal)
2+
// RUN: %target-build-swift-dylib(%t/normal/%target-library-name(MoveOnlySplit)) %S/Inputs/moveonly_split_module_source_input.swift -emit-module -emit-module-path %t/normal/MoveOnlySplit.swiftmodule -module-name MoveOnlySplit -DTEST_LIBRARY_WITHOUT_LIBRARY_EVOLUTION
3+
// RUN: %target-codesign %t/normal/%target-library-name(MoveOnlySplit)
4+
5+
// RUN: %target-build-swift %s -lMoveOnlySplit -I %t/normal -L %t/normal -o %t/normal/main %target-rpath(%t/normal)
6+
// RUN: %target-codesign %t/normal/main
7+
// RUN: %target-run %t/normal/main %t/normal/%target-library-name(MoveOnlySplit) | %FileCheck %s
8+
9+
// REQUIRES: executable_test
10+
11+
import MoveOnlySplit
12+
13+
func main() {
14+
// CHECK: ==> LIBRARY: I am in the deinit!
15+
// CHECK-LIBRARY-EVOLUTION: ==> LIBRARY_EVOLUTION: I am in the deinit!
16+
let server = MoveOnly()
17+
}
18+
19+
main()

test/Interpreter/moveonly_split_module_source_deinit_library_evolution.swift

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)