Skip to content

Commit e5c43ab

Browse files
committed
Update access base for borrow/mutate accessors in SwiftCompilerSources
1 parent 6374f02 commit e5c43ab

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

SwiftCompilerSources/Sources/SIL/Utilities/WalkUtils.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,9 @@ extension AddressUseDefWalker {
838838
} else {
839839
return walkUp(address: ia.base, path: path.push(.anyIndexedElement, index: 0))
840840
}
841+
case let apply as ApplyInst:
842+
let selfArgument = apply.arguments.last!
843+
return walkUp(address: selfArgument, path: path.push(.anyValueFields, index: 0))
841844
case is BeginAccessInst,
842845
is MarkDependenceInst,
843846
is MarkUninitializedInst,

test/SILOptimizer/accessbase_unit.sil

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,33 @@ bb0(%0 : @owned $C):
8686
%9999 = tuple()
8787
return %9999 : $()
8888
}
89+
90+
public struct GenWrapper<T> {
91+
@_hasStorage var _prop: T { get set }
92+
public var prop: T
93+
}
94+
95+
sil @borrow_addressonly_prop : $@convention(method) <τ_0_0> (@in_guaranteed GenWrapper<τ_0_0>) -> @guaranteed_address τ_0_0
96+
// CHECK: begin running test 1 of 2 on test_borrow_base: get_access_base with: %2
97+
// CHECK: sil [ossa] @test_borrow_base : $@convention(thin) <T> (@in_guaranteed GenWrapper<T>) -> @guaranteed_address T {
98+
// CHECK: bb0(%0 : $*GenWrapper<T>):
99+
// CHECK: %1 = function_ref @borrow_addressonly_prop : $@convention(method) <τ_0_0> (@in_guaranteed GenWrapper<τ_0_0>) -> @guaranteed_address τ_0_0
100+
// CHECK: %2 = apply %1<T>(%0) : $@convention(method) <τ_0_0> (@in_guaranteed GenWrapper<τ_0_0>) -> @guaranteed_address τ_0_0
101+
// CHECK: return %2
102+
// CHECK: }
103+
// CHECK: Address: %2 = apply %1<T>(%0) : $@convention(method) <τ_0_0> (@in_guaranteed GenWrapper<τ_0_0>) -> @guaranteed_address τ_0_0
104+
// CHECK: Base: %0 = argument of bb0 : $*GenWrapper<T>
105+
// CHECK: end running test 1 of 2 on test_borrow_base: get_access_base with: %2
106+
// CHECK: begin running test 2 of 2 on test_borrow_base: swift_get_access_base with: %2
107+
// CHECK: Address: %2 = apply %1<T>(%0) : $@convention(method) <τ_0_0> (@in_guaranteed GenWrapper<τ_0_0>) -> @guaranteed_address τ_0_0
108+
// CHECK: Base: argument - %0 = argument of bb0 : $*GenWrapper<T>
109+
110+
sil [ossa] @test_borrow_base : $@convention(thin) <T> (@in_guaranteed GenWrapper<T>) -> @guaranteed_address T {
111+
bb0(%0 : $*GenWrapper<T>):
112+
%1 = function_ref @borrow_addressonly_prop : $@convention(method) <τ_0_0> (@in_guaranteed GenWrapper<τ_0_0>) -> @guaranteed_address τ_0_0
113+
%2 = apply %1<T>(%0) : $@convention(method) <τ_0_0> (@in_guaranteed GenWrapper<τ_0_0>) -> @guaranteed_address τ_0_0
114+
specify_test "get_access_base %2"
115+
specify_test "swift_get_access_base %2"
116+
return %2
117+
}
118+

0 commit comments

Comments
 (0)