| // RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -O | %FileCheck %s |
| |
| // Check some corner cases related to tracking of opened archetypes. |
| // For example, the compiler used to crash compiling the "process" function (rdar://28024272) |
| |
| sil_stage canonical |
| |
| import Builtin |
| import Swift |
| import SwiftShims |
| |
| public protocol P { |
| } |
| |
| extension P { |
| func invokeClosure(_ closure: () throws -> ()) rethrows |
| } |
| |
| public func process(s: P) |
| |
| sil [noinline] @invokeClosure : $@convention(method) <Self where Self : P> (@owned @callee_owned () -> @error Error, @in_guaranteed Self) -> @error Error { |
| bb0(%0 : $@callee_owned () -> @error Error, %1 : $*Self): |
| strong_release %0 : $@callee_owned () -> @error Error |
| %5 = tuple () |
| return %5 : $() |
| } |
| |
| sil @closure : $@convention(thin) () -> () { |
| bb0: |
| %0 = tuple () |
| debug_value %0 : $() |
| %2 = tuple () |
| return %2 : $() |
| } |
| |
| // CHECK-LABEL: sil @process |
| // CHECK: bb0 |
| // CHECK-NOT: try_apply |
| // CHECK-NOT: unreachable |
| // CHECK: apply |
| // CHECK-NOT: unreachable |
| // CHECK: return |
| sil @process : $@convention(thin) (@in P) -> () { |
| bb0(%0 : $*P): |
| %2 = open_existential_addr immutable_access %0 : $*P to $*@opened("4C22C24E-6BAA-11E6-B904-B8E856428C60") P |
| %3 = function_ref @invokeClosure : $@convention(method) <τ_0_0 where τ_0_0 : P> (@owned @callee_owned () -> @error Error, @in_guaranteed τ_0_0) -> @error Error |
| // function_ref (process(s : P) -> ()).(closure #1) |
| %4 = function_ref @closure : $@convention(thin) () -> () |
| %5 = thin_to_thick_function %4 : $@convention(thin) () -> () to $@callee_owned () -> () |
| %6 = convert_function %5 : $@callee_owned () -> () to $@callee_owned () -> @error Error |
| try_apply %3<@opened("4C22C24E-6BAA-11E6-B904-B8E856428C60") P>(%6, %2) : $@convention(method) <τ_0_0 where τ_0_0 : P> (@owned @callee_owned () -> @error Error, @in_guaranteed τ_0_0) -> @error Error, normal bb1, error bb2 |
| |
| bb1(%8 : $()): |
| destroy_addr %0 : $*P |
| %10 = tuple () |
| return %10 : $() |
| |
| bb2(%12 : $Error): |
| unreachable |
| } |
| |
| sil_default_witness_table P { |
| } |
| |