|
| 1 | +// RUN: %target-swift-emit-silgen -enable-sil-ownership -emit-verbose-sil %s | %FileCheck %s |
| 2 | + |
| 3 | +// REQUIRES: plus_zero_runtime |
| 4 | + |
| 5 | +protocol OwnershipProto { |
| 6 | + __consuming func elided(_ default: String, _ shared: __shared String, _ owned: __owned String) |
| 7 | + |
| 8 | + __consuming func explicit(_ default: String, _ shared: __shared String, _ owned: __owned String) |
| 9 | +} |
| 10 | + |
| 11 | +struct Witness: OwnershipProto { |
| 12 | + func elided(_ default: String, _ shared: String, _ owned: String) { } |
| 13 | + |
| 14 | + __consuming func explicit(_ default: String, _ toShared: __shared String, _ toOwned: __owned String) { } |
| 15 | +} |
| 16 | + |
| 17 | +// Check the conventions of the witnesses |
| 18 | + |
| 19 | +// CHECK-LABEL: sil hidden @$S15value_ownership7WitnessV6elidedyySS_S2StF : $@convention(method) (@guaranteed String, @guaranteed String, @guaranteed String, Witness) -> () { |
| 20 | +// CHECK: } // end sil function '$S15value_ownership7WitnessV6elidedyySS_S2StF' |
| 21 | + |
| 22 | +// CHECK-LABEL: sil hidden @$S15value_ownership7WitnessV8explicityySS_SShSSntF : $@convention(method) (@guaranteed String, @guaranteed String, @owned String, Witness) -> () { |
| 23 | +// CHECK: } // end sil function '$S15value_ownership7WitnessV8explicityySS_SShSSntF' |
| 24 | + |
| 25 | +// Check the elided witness' thunk has the right conventions and borrows where necessary |
| 26 | + |
| 27 | +// CHECK-LABEL: @$S15value_ownership7WitnessVAA14OwnershipProtoA2aDP6elidedyySS_SShSSntFTW : $@convention(witness_method: OwnershipProto) (@guaranteed String, @guaranteed String, @owned String, @in_guaranteed Witness) -> () |
| 28 | +// CHECK: bb0([[DEFAULT2DEFAULT:%.*]] : @guaranteed $String, [[SHARED2DEFAULT:%.*]] : @guaranteed $String, [[OWNED2DEFAULT:%.*]] : @owned $String, [[WITNESS_VALUE:%.*]] : @trivial $*Witness): |
| 29 | +// CHECK: [[LOAD_WITNESS:%.*]] = load [trivial] [[WITNESS_VALUE]] : $*Witness |
| 30 | +// CHECK: [[WITNESS_FUNC:%.*]] = function_ref @$S15value_ownership7WitnessV6elidedyySS_S2StF |
| 31 | +// CHECK: [[BORROWOWNED2DEFAULT:%.*]] = begin_borrow [[OWNED2DEFAULT]] : $String |
| 32 | +// CHECK: apply [[WITNESS_FUNC]]([[DEFAULT2DEFAULT]], [[SHARED2DEFAULT]], [[BORROWOWNED2DEFAULT]], [[LOAD_WITNESS]]) |
| 33 | +// CHECK: end_borrow [[BORROWOWNED2DEFAULT]] from [[OWNED2DEFAULT]] : $String, $String |
| 34 | +// CHECK: } // end sil function '$S15value_ownership7WitnessVAA14OwnershipProtoA2aDP6elidedyySS_SShSSntFTW' |
| 35 | + |
| 36 | +// Check that the explicit witness' thunk doesn't copy or borrow |
| 37 | + |
| 38 | +// CHECK-LABEL: @$S15value_ownership7WitnessVAA14OwnershipProtoA2aDP8explicityySS_SShSSntFTW : $@convention(witness_method: OwnershipProto) (@guaranteed String, @guaranteed String, @owned String, @in_guaranteed Witness) -> () { |
| 39 | +// CHECK: bb0([[ARG0:%.*]] : @guaranteed $String, [[ARG1:%.*]] : @guaranteed $String, [[ARG2:%.*]] : @owned $String, [[WITNESS_VALUE:%.*]] : @trivial $*Witness): |
| 40 | +// CHECK-NEXT: [[LOAD_WITNESS:%.*]] = load [trivial] [[WITNESS_VALUE]] : $*Witness |
| 41 | +// CHECK-NEXT: // function_ref Witness.explicit(_:_:_:) |
| 42 | +// CHECK-NEXT: [[WITNESS_FUNC:%.*]] = function_ref @$S15value_ownership7WitnessV8explicityySS_SShSSntF |
| 43 | +// CHECK-NEXT: apply [[WITNESS_FUNC]]([[ARG0]], [[ARG1]], [[ARG2]], [[LOAD_WITNESS]]) |
| 44 | +// CHECK: } // end sil function '$S15value_ownership7WitnessVAA14OwnershipProtoA2aDP8explicityySS_SShSSntFTW' |
0 commit comments