forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproperty_behavior_init.swift
60 lines (49 loc) · 2.04 KB
/
property_behavior_init.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// RUN: %target-swift-frontend -enable-experimental-property-behaviors -emit-silgen %s | %FileCheck %s
protocol diBehavior {
associatedtype Value
var storage: Value { get set }
}
extension diBehavior {
var value: Value {
get { }
set { }
}
static func initStorage(_ initial: Value) -> Value { }
}
func whack<T>(_ x: inout T) {}
struct Foo {
var x: Int __behavior diBehavior
// FIXME: Hack because we can't find the synthesized associated type witness
// during witness matching.
typealias Value = Int
// TODO
// var xx: (Int, Int) __behavior diBehavior
// CHECK-LABEL: sil hidden @_TFV22property_behavior_init3FooC
// CHECK: bb0([[X:%.*]] : $Int,
init(x: Int) {
// CHECK: [[UNINIT_SELF:%.*]] = mark_uninitialized [rootself]
// CHECK: [[UNINIT_STORAGE:%.*]] = struct_element_addr [[UNINIT_SELF]]
// CHECK: [[UNINIT_BEHAVIOR:%.*]] = mark_uninitialized_behavior {{.*}}<Foo>([[UNINIT_STORAGE]]) : {{.*}}, {{%.*}}([[UNINIT_SELF]])
// Pure assignments undergo DI analysis so assign to the marking proxy.
// CHECK: assign [[X]] to [[UNINIT_BEHAVIOR]]
self.x = x
// CHECK: assign [[X]] to [[UNINIT_BEHAVIOR]]
self.x = x
// Reads or inouts use the accessors normally.
// CHECK: [[SELF:%.*]] = load [trivial] [[UNINIT_SELF]]
// CHECK: [[GETTER:%.*]] = function_ref @_TFV22property_behavior_init3Foog1xSi
// CHECK: apply [[GETTER]]([[SELF]])
_ = self.x
// CHECK: [[WHACK:%.*]] = function_ref @_TF22property_behavior_init5whackurFRxT_
// CHECK: [[INOUT:%.*]] = alloc_stack
// CHECK: [[SELF:%.*]] = load [trivial] [[UNINIT_SELF]]
// CHECK: [[GETTER:%.*]] = function_ref @_TFV22property_behavior_init3Foog1xSi
// CHECK: [[VALUE:%.*]] = apply [[GETTER]]([[SELF]])
// CHECK: store [[VALUE]] to [trivial] [[INOUT]]
// CHECK: apply [[WHACK]]<Int>([[INOUT]])
// CHECK: [[VALUE:%.*]] = load [trivial] [[INOUT]]
// CHECK: [[SETTER:%.*]] = function_ref @_TFV22property_behavior_init3Foos1xSi
// CHECK: apply [[SETTER]]([[VALUE]], [[UNINIT_SELF]])
whack(&self.x)
}
}