Skip to content

Commit 7150a8b

Browse files
authored
Merge pull request #40347 from rxwei/sr15530
2 parents 50ddd7c + 6999c8a commit 7150a8b

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4069,9 +4069,15 @@ static bool checkFunctionSignature(
40694069
// Check that generic signatures match.
40704070
auto requiredGenSig = required.getOptGenericSignature();
40714071
auto candidateGenSig = candidateFnTy.getOptGenericSignature();
4072-
if (!candidateGenSig.requirementsNotSatisfiedBy(requiredGenSig).empty()) {
4072+
// Check that the candidate signature's generic parameters are a subset of
4073+
// those of the required signature.
4074+
if (requiredGenSig && candidateGenSig &&
4075+
candidateGenSig.getGenericParams().size()
4076+
> requiredGenSig.getGenericParams().size())
4077+
return false;
4078+
// Check that the requirements are satisfied.
4079+
if (!candidateGenSig.requirementsNotSatisfiedBy(requiredGenSig).empty())
40734080
return false;
4074-
}
40754081

40764082
// Check that parameter types match, disregarding labels.
40774083
if (required->getNumParams() != candidateFnTy->getNumParams())

test/AutoDiff/Sema/derivative_attr_type_checking.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,27 @@ extension Struct where T: Differentiable & AdditiveArithmetic {
573573
}
574574
}
575575

576+
struct SR15530_Struct<T> {}
577+
extension SR15530_Struct: Differentiable where T: Differentiable {}
578+
579+
extension SR15530_Struct {
580+
// expected-note @+1 {{candidate instance method does not have type equal to or less constrained than '<T where T : Differentiable> (inout SR15530_Struct<T>) -> (Int, @differentiable(reverse) (inout T) -> Void) -> Void'}}
581+
mutating func sr15530_update<D>(at index: Int, byCalling closure: (inout T, D) -> Void, withArgument: D) {
582+
fatalError("Stop")
583+
}
584+
}
585+
586+
extension SR15530_Struct where T: Differentiable {
587+
// expected-error @+1 {{referenced declaration 'sr15530_update' could not be resolved}}
588+
@derivative(of: sr15530_update)
589+
mutating func vjp_sr15530_update(
590+
at index: Int,
591+
byCalling closure: @differentiable(reverse) (inout T) -> Void
592+
) -> (value: Void, pullback: (inout Self.TangentVector) -> Void) {
593+
fatalError("Stop")
594+
}
595+
}
596+
576597
extension Class {
577598
subscript() -> Float {
578599
get { 1 }

test/AutoDiff/compiler_crashers/tf1181-apply-opened-opened-existential-argument.swift renamed to test/AutoDiff/compiler_crashers/sr14223-apply-opened-opened-existential-argument.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: not --crash %target-swift-frontend -disable-availability-checking -emit-sil -verify %s
22

3-
// TF-1181: Differentiation transform crash for `apply` with opened existential arguments.
3+
// SR-14223: Differentiation transform crash for `apply` with opened existential arguments.
44

55
import _Differentiation
66

0 commit comments

Comments
 (0)