Skip to content

Commit a445cf2

Browse files
committed
Use a simpler interpreter test
1 parent f840191 commit a445cf2

File tree

1 file changed

+11
-60
lines changed

1 file changed

+11
-60
lines changed

test/Interpreter/raw_layout.swift

Lines changed: 11 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,20 @@
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
22
// REQUIRES: executable_test
33

4-
import Builtin
5-
64
@_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 {}
346

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
4110
}
4211

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
5414
}
5515

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>()))
6118

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

Comments
 (0)