Avatar
protocol HasInt { var intValue : Int {get set} } func mod(_ val: inout Int) throws {} func testing<T: HasInt>(x: inout T) throws { try mod(&x.intValue) }
6:58 AM
で、 // testing<A>(x:) sil hidden @$S4test7testing1xyxz_tKAA6HasIntRzlF : $@convention(thin) <T where T : HasInt> (@inout T) -> @error Error { // %0 // users: %3, %1 bb0(%0 : $*T): %3 = begin_access [modify] [static] %0 : $*T // users: %11, %16, %5 %4 = witness_method $T, #HasInt.intValue!modify.1 : <Self where Self : HasInt> (inout Self) -> () -> () : $@yield_once @convention(witness_method: HasInt) <τ_0_0 where τ_0_0 : HasInt> (@inout τ_0_0) -> @yields @inout Int // user: %5 (%5, %6) = begin_apply %4<T>(%3) : $@yield_once @convention(witness_method: HasInt) <τ_0_0 where τ_0_0 : HasInt> (@inout τ_0_0) -> @yields @inout Int // users: %8, %10, %15 // function_ref mod(_:) %7 = function_ref @$S4test3modyySizKF : $@convention(thin) (@inout Int) -> @error Error // user: %8 try_apply %7(%5) : $@convention(thin) (@inout Int) -> @error Error, normal bb1, error bb2 // id: %8 bb1(%9 : $()): // Preds: bb0 end_apply %6 // id: %10 end_access %3 : $*T // id: %11 %12 = tuple () // user: %13 return %12 : $() // id: %13 // %14 // user: %17 bb2(%14 : $Error): // Preds: bb0 abort_apply %6 // id: %15 end_access %3 : $*T // id: %16 throw %14 : $Error // id: %17 } // end sil function '$S4test7testing1xyxz_tKAA6HasIntRzlF' なので、アクセス中に throw したときみたいです。