Skip to content

GSB: Teach 'derived via concrete' computation about superclass constraints [5.3] #32489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,11 @@ const RequirementSource *RequirementSource::getMinimalConformanceSource(

if (parentEquivClass->concreteType)
derivedViaConcrete = true;
else if (parentEquivClass->superclass &&
builder.lookupConformance(parentType->getCanonicalType(),
parentEquivClass->superclass,
source->getProtocolDecl()))
derivedViaConcrete = true;

// The parent potential archetype must conform to the protocol in which
// this requirement resides. Add this constraint.
Expand Down
25 changes: 25 additions & 0 deletions test/Generics/superclass_constraint_self_derived.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %target-typecheck-verify-swift

protocol P {
associatedtype T : Q
}

protocol Q {
associatedtype T : R

var t: T { get }
}

protocol R {}

func takesR<T : R>(_: T) {}

class C<T : Q> : P {}

struct Outer<T : P> {
struct Inner<U> where T : C<U> {
func doStuff(_ u: U) {
takesR(u.t)
}
}
}
48 changes: 48 additions & 0 deletions test/SILGen/class_conforms_with_default_implementation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// RUN: %target-swift-emit-silgen %s | %FileCheck %s

protocol P {
associatedtype T : Q
func foo()
}

extension P {
func foo() {}
}

protocol Q {}

class C<T : Q> : P {}

protocol PP {
associatedtype T : QQ
func foo()
}

extension PP {
func foo() {}
}

class QQ {}

class CC<T : QQ> : PP {}

// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s42class_conforms_with_default_implementation1CCyqd__GAA1PA2aEP3fooyyFTW : $@convention(witness_method: P) <τ_0_0><τ_1_0 where τ_0_0 : C<τ_1_0>, τ_1_0 : Q> (@in_guaranteed τ_0_0) -> () {
// CHECK: [[WITNESS:%.*]] = function_ref @$s42class_conforms_with_default_implementation1PPAAE3fooyyF : $@convention(method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> ()
// CHECK: apply [[WITNESS]]<τ_0_0>(%0) : $@convention(method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> ()
// CHECK: return

// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s42class_conforms_with_default_implementation2CCCyqd__GAA2PPA2aEP3fooyyFTW : $@convention(witness_method: PP) <τ_0_0><τ_1_0 where τ_0_0 : CC<τ_1_0>, τ_1_0 : QQ> (@in_guaranteed τ_0_0) -> () {
// CHECK: [[WITNESS:%.*]] = function_ref @$s42class_conforms_with_default_implementation2PPPAAE3fooyyF : $@convention(method) <τ_0_0 where τ_0_0 : PP> (@in_guaranteed τ_0_0) -> ()
// CHECK: apply [[WITNESS]]<τ_0_0>(%0) : $@convention(method) <τ_0_0 where τ_0_0 : PP> (@in_guaranteed τ_0_0) -> ()
// CHECK: return

// CHECK-LABEL: sil_witness_table hidden <T where T : Q> C<T>: P module class_conforms_with_default_implementation {
// CHECK-NEXT: associated_type_protocol (T: Q): dependent
// CHECK-NEXT: associated_type T: T
// CHECK-NEXT: method #P.foo: <Self where Self : P> (Self) -> () -> () : @$s42class_conforms_with_default_implementation1CCyqd__GAA1PA2aEP3fooyyFTW
// CHECK-NEXT: }

// CHECK-LABEL: sil_witness_table hidden <T where T : QQ> CC<T>: PP module class_conforms_with_default_implementation {
// CHECK-NEXT: associated_type T: T
// CHECK-NEXT: method #PP.foo: <Self where Self : PP> (Self) -> () -> () : @$s42class_conforms_with_default_implementation2CCCyqd__GAA2PPA2aEP3fooyyFTW
// CHECK-NEXT: }
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// RUN: not --crash %target-swift-emit-silgen %s

// REQUIRES: asserts
// RUN: %target-swift-emit-silgen %s

protocol Example {
associatedtype Signed: SignedInteger
Expand Down