Skip to content

SIL: Workaround for GenericSignatureBuilder bug #40583

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
merged 1 commit into from
Dec 16, 2021
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
4 changes: 2 additions & 2 deletions lib/SIL/IR/AbstractionPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1649,8 +1649,8 @@ class SubstFunctionTypePatternVisitor
newGPMapping.insert({gp, newParamTy});
auto substGPTy = Type(gp).subst(substGPMap)->castTo<GenericTypeParamType>();
substRequirements.push_back(Requirement(RequirementKind::SameType,
substGPTy,
newParamTy));
newParamTy,
substGPTy));
assert(!substReplacementTypes[substGPTy->getIndex()]);
substReplacementTypes[substGPTy->getIndex()] = substParamTy;
}
Expand Down
22 changes: 22 additions & 0 deletions test/Generics/rdar86431977.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-inferred-signatures=on 2>&1 | %FileCheck %s

protocol P1 {
associatedtype A
associatedtype B : P1 where B.A == A, B.B == B
}

protocol P2 : P1 where A == Self {}

struct G<T, U> {}

// The GSB used to get the signature of bar() wrong.

extension G {
// CHECK-LABEL: rdar86431977.(file).G extension.foo()@
// CHECK: Generic signature: <T, U where T : P2, T == U>
func foo() where T : P2, U == T {}

// CHECK-LABEL: rdar86431977.(file).G extension.bar()@
// CHECK: Generic signature: <T, U where T : P2, T == U>
func bar() where T : P2, T == U {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// RUN: %target-swift-emit-silgen %s -requirement-machine-abstract-signatures=verify | %FileCheck %s

struct G<Key: CaseIterable, Value> where Key: RawRepresentable, Value: Codable {
var key: Key.RawValue
}

protocol P: CaseIterable, RawRepresentable {}

struct Value: Codable {}

enum Key: Int, P {
case elt
}

func callee<Key: P>(_: Key.Type, _: @escaping (G<Key, Value>) -> Void) {}

// CHECK-LABEL: sil hidden [ossa] @$s029type_lowering_subst_function_A20_requirement_machine6calleryyF : $@convention(thin) () -> () {
// CHECK: function_ref @$s029type_lowering_subst_function_A20_requirement_machine6calleryyFyAA1GVyAA3KeyOAA5ValueVGcfU_ : $@convention(thin) @substituted <τ_0_0, τ_0_1, τ_0_2 where τ_0_0 : CaseIterable, τ_0_0 : RawRepresentable, τ_0_0 == τ_0_2, τ_0_1 == Value> (@in_guaranteed G<τ_0_0, Value>) -> () for <Key, Value, Key>
func caller() {
callee(Key.self, { _ in })
}