Files
swift-mirror/test/SILOptimizer/specialize_dynamic_self.swift
Slava Pestov a8452b4076 AST: Fix crash in ProtocolConformance::subst() when specializing with dynamic Self
Looking up the conformance @dynamic_self C<T> : P simply returns
the normal conformance C<T> : P.

If we later apply a substitution map to the conformance to
specialize T, we would call isSpecialized() on the substituted
type, which would return false. We would then hit an assertion
because the type type @dynamic_self C<Int> is not equal to the
(erroneously unsubstituted) conformance type C<T>.

Tweak the logic slightly to avoid this.
2017-04-23 01:49:00 -07:00

30 lines
1.2 KiB
Swift

// RUN: %target-swift-frontend -emit-sil -O -primary-file %s | %FileCheck %s
protocol P {}
extension P {
@_semantics("optimize.sil.never") func method1() {}
@inline(__always) func method2() { method1() }
}
class C<T> : P {
// CHECK-LABEL: sil shared [always_inline] @_T023specialize_dynamic_self1CC11returnsSelfACyxGXDyFSi_Tg5 : $@convention(method) (@guaranteed C<Int>) -> @owned C<Int>
// CHECK: [[RESULT:%.*]] = alloc_stack $C<Int>
// CHECK: [[FN:%.*]] = function_ref @_T023specialize_dynamic_self1PPAAE7method1yyF : $@convention(method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> ()
// CHECK: apply [[FN]]<@dynamic_self C<Int>>([[RESULT]]) : $@convention(method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> ()
// CHECK: return %0 : $C<Int>
@inline(__always)
final func returnsSelf() -> Self {
method2()
return self
}
}
// CHECK-LABEL: sil hidden [thunk] [always_inline] @_T023specialize_dynamic_self8usesCIntyAA1CCySiG1c_tF : $@convention(thin) (@owned C<Int>) -> () {
// CHECK: function_ref @_T023specialize_dynamic_self1CC11returnsSelfACyxGXDyFSi_Tg5 : $@convention(method) (@guaranteed C<Int>) -> @owned C<Int>
// CHECK: return
func usesCInt(c: C<Int>) {
_ = c.returnsSelf()
}