Open dan-zheng opened 4 years ago
@slavapestov I was planning to fix this bug, whose reproducer is here. The end of its stack trace is somewhere in RQM. I was planning to read your entire research paper just to understand what was going on at the end, but that seems like an overblown amount of effort. Is it possible for you to examine the crash a little in LLDB and give me enough of an understanding that I can utilize my experience with other areas of the compiler to fix the bug?
Your generic signature is <τ_0_0, τ_0_1, τ_0_2, τ_0_3 where τ_0_0 == τ_0_1, τ_0_2 == τ_0_3>
.
τ_0_0.TangentVector
is not a valid type parameter in this signature because τ_0_0
does not conform to Differentiable
(which is where TangentVector
is declared).
That's your bug. The autodiff code is probably forgetting to add a requirement to the signature, which is probably coming from a call to buildGenericSignature()
somewhere in the autodiff code.
@slavapestov you're the best!
For future reference, I have narrowed down the reproducer to something smaller:
import _Differentiation
struct Box<Scalar> {
var x: Scalar
}
extension Box: Differentiable where Scalar: Differentiable {}
struct Box2<T> {
var x2: @differentiable(reverse) (Box<T>) -> Box<T>
}
The reproducer posted on 4/28 is still broken with 2023-01-02a through to 2023-01-18a. We get:
Invalid type parameter in getReducedType()
Original type: τ_0_0.TangentVector
Simplified term: τ_0_0.[Differentiable:TangentVector]
Longest valid prefix: τ_0_0
Prefix type: τ_0_0
Requirement machine for <τ_0_0, τ_0_1>
Rewrite system: {
}
}
Property map: {
}
Conformance paths: {
}
and
1. Apple Swift version 5.9-dev (LLVM 3f23b4ceaf01213, Swift 0763e4b98c74b5b)
2. Compiling with the current language version
3. While evaluating request ASTLoweringRequest(Lowering AST to SIL for module smallProject)
4. While emitting property descriptor for 'x2' (at /Users/user/smallProject/main.swift:10:7)
For future reference, I have narrowed down the reproducer to something smaller:
import _Differentiation struct Box<Scalar> { var x: Scalar } extension Box: Differentiable where Scalar: Differentiable {} struct Box2<T> { var x2: @differentiable(reverse) (Box<T>) -> Box<T> }
This reproducer does not cause any errors on 05/24 toolchain. The original reproducer still does.
Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, AutoDiff | |Assignee | None | |Priority | Medium | md5: 8635dba187654182d9292136d60a56fdrelates to:
Issue Description:
Curry thunks were recently rewritten as implicit AST closures instead of SILGen'd thunks: https://github.com/apple/swift/pull/28698.
This caused regressions in curry thunk differentiation. Extracted from
test/AutoDiff/downstream/generics.swift
:Before: no error.
After: error regarding differentiating fragile function in serialized function.
This error was introduced in https://github.com/apple/swift/pull/28582.