|
1 |
| -// RUN: %target-run-simple-swift(-enable-experimental-feature RawLayout -enable-builtin-module) | %FileCheck %s |
| 1 | +// RUN: %target-run-simple-swift(-enable-experimental-feature RawLayout) | %FileCheck %s |
2 | 2 | // REQUIRES: executable_test
|
3 | 3 |
|
4 |
| -import Builtin |
5 |
| - |
6 | 4 | @_rawLayout(like: T)
|
7 |
| -struct Cell<T>: ~Copyable { |
8 |
| - var address: UnsafeMutablePointer<T> { |
9 |
| - UnsafeMutablePointer<T>(Builtin.unprotectedAddressOfBorrow(self)) |
10 |
| - } |
11 |
| - |
12 |
| - init(_ value: consuming T) { |
13 |
| - address.initialize(to: value) |
14 |
| - } |
15 |
| - |
16 |
| - deinit { |
17 |
| - // FIXME: discard self should work with rawLayout types |
18 |
| - //address.deinitialize(count: 1) |
19 |
| - |
20 |
| - // Note: We don't need to deallocate the address here because the memory it |
21 |
| - // points to is being destroyed within this deinit. |
22 |
| - } |
23 |
| - |
24 |
| - borrowing func replace(with replacement: consuming T) -> T { |
25 |
| - let previous = address.move() |
26 |
| - address.initialize(to: replacement) |
27 |
| - return previous |
28 |
| - } |
29 |
| - |
30 |
| - borrowing func set(_ value: consuming T) { |
31 |
| - let previous = replace(with: value) |
32 |
| - _ = consume previous |
33 |
| - } |
| 5 | +struct Cell<T>: ~Copyable {} |
34 | 6 |
|
35 |
| - consuming func get() -> T { |
36 |
| - // Move the value out of self and don't call our deinitializer |
37 |
| - let previous = address.move() |
38 |
| - discard self |
39 |
| - return previous |
40 |
| - } |
| 7 | +struct Foo<T>: ~Copyable { |
| 8 | + let cell = Cell<T>() |
| 9 | + let myValue = 123 |
41 | 10 | }
|
42 | 11 |
|
43 |
| -@_eagerMove |
44 |
| -class SpecialInt { |
45 |
| - var value: Int |
46 |
| - |
47 |
| - init(_ value: Int) { |
48 |
| - self.value = value |
49 |
| - } |
50 |
| - |
51 |
| - deinit { |
52 |
| - print("Deinitializing \(value)!") |
53 |
| - } |
| 12 | +func something<T>(_ x: borrowing Foo<T>) -> Int { |
| 13 | + x.myValue |
54 | 14 | }
|
55 | 15 |
|
56 |
| -do { |
57 |
| - let specialInt0 = SpecialInt(128) |
58 |
| - let cell0 = Cell<SpecialInt>(specialInt0) |
59 |
| - |
60 |
| - let specialInt0Again = cell0.replace(with: SpecialInt(316)) |
| 16 | +// CHECK: 123 |
| 17 | +print(something(Foo<Bool>())) |
61 | 18 |
|
62 |
| - // CHECK: Deinitializing 316! |
63 |
| - cell0.set(SpecialInt(592)) |
64 |
| - |
65 |
| - let specialInt1 = cell0.get() |
66 |
| - |
67 |
| - // CHECK: Deinitializing 592! |
68 |
| - // CHECK: Deinitializing 128! |
69 |
| -} |
| 19 | +// CHECK: 123 |
| 20 | +print(something(Foo<Int>())) |
0 commit comments