Skip to content

Commit a09e258

Browse files
committed
Enable SIL parsing of borrow and mutate accessors
1 parent 518c3ac commit a09e258

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

include/swift/AST/TypeAttr.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ SIMPLE_SIL_TYPE_ATTR(pack_out, PackOut)
9595
SIMPLE_SIL_TYPE_ATTR(owned, Owned)
9696
SIMPLE_SIL_TYPE_ATTR(unowned_inner_pointer, UnownedInnerPointer)
9797
SIMPLE_SIL_TYPE_ATTR(guaranteed, Guaranteed)
98+
SIMPLE_SIL_TYPE_ATTR(guaranteed_addr, GuaranteedAddress)
9899
SIMPLE_SIL_TYPE_ATTR(autoreleased, Autoreleased)
99100
SIMPLE_SIL_TYPE_ATTR(callee_owned, CalleeOwned)
100101
SIMPLE_SIL_TYPE_ATTR(callee_guaranteed, CalleeGuaranteed)

lib/ASTGen/Sources/ASTGen/TypeAttrs.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ extension ASTGenVisitor {
104104
.ErrorIndirect,
105105
.ErrorUnowned,
106106
.Guaranteed,
107+
.GuaranteedAddress,
107108
.In,
108109
.InConstant,
109110
.InGuaranteed,

lib/Sema/TypeCheckType.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3172,6 +3172,7 @@ TypeAttrKind TypeAttrSet::getRepresentative(TypeAttrKind kind) {
31723172
case TypeAttrKind::InoutAliasable:
31733173
case TypeAttrKind::Owned:
31743174
case TypeAttrKind::Guaranteed:
3175+
case TypeAttrKind::GuaranteedAddress:
31753176
case TypeAttrKind::PackOwned:
31763177
case TypeAttrKind::PackGuaranteed:
31773178
case TypeAttrKind::PackInout:
@@ -4904,6 +4905,8 @@ bool TypeResolver::resolveSingleSILResult(
49044905
ERROR(ErrorUnowned, Unowned)
49054906
NORMAL(Out, Indirect)
49064907
NORMAL(Owned, Owned)
4908+
NORMAL(Guaranteed, Guaranteed)
4909+
NORMAL(GuaranteedAddress, GuaranteedAddress)
49074910
NORMAL(UnownedInnerPointer, UnownedInnerPointer)
49084911
NORMAL(Autoreleased, Autoreleased)
49094912
NORMAL(PackOut, Pack)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// RUN: %target-sil-opt %s | %FileCheck %s
2+
3+
class Klass {}
4+
5+
public struct Wrapper {
6+
@_hasStorage var _k: Klass { get set }
7+
var k: Klass
8+
}
9+
10+
public struct GenWrapper<T> {
11+
@_hasStorage var _prop: T { get set }
12+
public var prop: T
13+
}
14+
15+
// CHECK-LABEL: sil [ossa] @borrow_loadable_prop : $@convention(method) (@guaranteed Wrapper) -> @guaranteed Klass {
16+
sil [ossa] @borrow_loadable_prop : $@convention(method) (@guaranteed Wrapper) -> @guaranteed Klass {
17+
bb0(%0 : @guaranteed $Wrapper):
18+
%2 = struct_extract %0, #Wrapper._k
19+
return %2
20+
}
21+
22+
// CHECK-LABEL: sil [ossa] @borrow_addressonly_prop : $@convention(method) <T> (@in_guaranteed GenWrapper<T>) -> @guaranteed_addr T {
23+
sil [ossa] @borrow_addressonly_prop : $@convention(method) <T> (@in_guaranteed GenWrapper<T>) -> @guaranteed_addr T {
24+
bb0(%0 : $*GenWrapper<T>):
25+
%2 = struct_element_addr %0, #GenWrapper._prop
26+
return %2
27+
}
28+
29+
sil @get_wrapper : $@convention(thin) () -> @owned Klass
30+
sil @use_klass : $@convention(thin) (@guaranteed Klass) -> ()
31+
sil @use_T : $@convention(thin) <T> (@in_guaranteed T) -> ()
32+
33+
sil [ossa] @test1 : $@convention(thin) (@owned Wrapper) -> () {
34+
bb0(%0 : @owned $Wrapper):
35+
%1 = begin_borrow %0
36+
%2 = function_ref @borrow_loadable_prop : $@convention(method) (@guaranteed Wrapper) -> @guaranteed Klass
37+
%3 = apply %2(%1) : $@convention(method) (@guaranteed Wrapper) -> @guaranteed Klass
38+
%4 = copy_value %3
39+
%5 = function_ref @use_klass : $@convention(thin) (@guaranteed Klass) -> ()
40+
%6 = apply %5(%4) : $@convention(thin) (@guaranteed Klass) -> ()
41+
destroy_value %4
42+
end_borrow %1
43+
destroy_value %0
44+
%10 = tuple ()
45+
return %10
46+
}
47+
48+
sil [ossa] @test2 : $@convention(thin) <T> (@in GenWrapper<T>) -> () {
49+
bb0(%0 : $*GenWrapper<T>):
50+
%1 = function_ref @borrow_addressonly_prop : $@convention(method) <τ_0_0> (@in_guaranteed GenWrapper<τ_0_0>) -> @guaranteed_addr τ_0_0
51+
%2 = apply %1<T>(%0) : $@convention(method) <τ_0_0> (@in_guaranteed GenWrapper<τ_0_0>) -> @guaranteed_addr τ_0_0
52+
%3 = function_ref @use_T : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
53+
%4 = apply %3<T>(%2) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
54+
destroy_addr %0
55+
%6 = tuple ()
56+
return %6
57+
}
58+

0 commit comments

Comments
 (0)