Open philipturner opened 2 years ago
Another reproducer. I don't know whether this is the same bug.
import _Differentiation
func curry<T, U, V>(
_ f: @differentiable(reverse) (T, U) -> V
) -> (T) -> (@differentiable(reverse) (U) -> V) {
{ x in { y in f(x, y) } }
}
This is a duplicate of #55966. The previous issue was closed because of an incorrect assumption: that the crash only happens when forward-mode differentiation is enabled. Here, no extra compiler flags are passed in.
As in https://github.com/apple/swift/issues/55966#issuecomment-1155535541, I only included the first line of each crash. The first two error diagnostics might be fixed by #41174. Should we add @escaping
to the code sample right above Differential Operators in the Differentiable Programming Manifesto?
import _Differentiation
// From the differentiable programming manifesto:
// Error diagnostic
func curry<T, U, V>(
_ f: @differentiable (T, U) -> V
) -> @differentiable (T) -> @differentiable (U) -> V {
{ x in { y in f(x, y) } }
}
// Error diagnostic
func curry<T, U, V>(
_ f: @escaping @differentiable(reverse) (T, U) -> V
) -> @differentiable(reverse) (T) -> (@differentiable(reverse) (U) -> V) {
{ x in { y in f(x, y) } }
}
// Compiles just fine
func curry<T, V>(
_ f: @escaping @differentiable(reverse) (T, T) -> V
) -> (T) -> (@differentiable(reverse) (T) -> V) {
{ x in { y in f(x, y) } }
}
// Assertion failed: (signature || !origType->hasTypeParameter()), function initSwiftType, file AbstractionPattern.h, line 528.
func curry<T, U, V>(
_ f: @escaping (T, U) -> V
) -> (T) -> (@differentiable(reverse) (U) -> V) {
{ x in { y in f(x, y) } }
}
The above reproducers still trigger various assertion and validation failures on top-of-tree Swift, so I'll reopen this in order to track a fix.
Describe the bug The following Swift code causes a compiler crash.
To Reproduce Steps to reproduce the behavior:
file.swift
.swift -DCRASH_2 file.swift
, where-DCRASH_2
corresponds to the number chosen in the previous step.Expected behavior A compiler crash with one of four possible stack traces.
Crash 1
``` (base) philipturner@m1-max-mbp Desktop % swift -DCRASH_1 file.swift Assertion failed: (signature || !origType->hasTypeParameter()), function initSwiftType, file AbstractionPattern.h, line 528. Stack dump: 0. Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-06-08-a.xctoolchain/usr/bin/swift-frontend -frontend -interpret file.swift -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -color-diagnostics -D CRASH_1 -new-driver-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-06-08-a.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-06-08-a.xctoolchain/usr/lib/swift -module-name file -target-sdk-version 12.3 1. Apple Swift version 5.8-dev (LLVM b2416e1165ab97c, Swift 965a54f037cfa76) 2. Compiling with the current language version 3. While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for file) 5. While running pass #159 SILModuleTransform "Differentiation". 6. While processing // differentiability witness for f(_:) sil_differentiability_witness hidden [reverse] [parameters 0] [results 0]Crash 2
``` (base) philipturner@m1-max-mbp Desktop % swift -DCRASH_2 file.swift SIL verification failed: Operand is of an ArchetypeType that does not exist in the Caller's generic param list.: isArchetypeValidInFunction(A, F) Verifying instruction: -> %3 = alloc_stack $T // users: %7, %6, %5 %5 = apply %4Crash 3
``` (base) philipturner@m1-max-mbp Desktop % swift -DCRASH_3 file.swift SIL verification failed: Replacement type of a substitution contains an ArchetypeType that does not exist in the Caller's generic param list.: isArchetypeValidInFunction(A, &F) Verifying instruction: %1 = argument of bb0 : $*_Double // users: %5, %4, %2 %3 = witness_method $T, #_AdditiveArithmetic.add2 :Crash 4
``` (base) philipturner@m1-max-mbp Desktop % swift -DCRASH_4 file.swift Assertion failed: (srcAddr->getType() == destAddr->getType()), function createCopyAddr, file SILBuilder.h, line 1034. Stack dump: 0. Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-06-08-a.xctoolchain/usr/bin/swift-frontend -frontend -interpret file.swift -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -color-diagnostics -D CRASH_4 -new-driver-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-06-08-a.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-06-08-a.xctoolchain/usr/lib/swift -module-name file -target-sdk-version 12.3 1. Apple Swift version 5.8-dev (LLVM b2416e1165ab97c, Swift 965a54f037cfa76) 2. Compiling with the current language version 3. While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for file) 4. While running pass #159 SILModuleTransform "Differentiation". 5. While processing // differentiability witness for f(_:) sil_differentiability_witness hidden [reverse] [parameters 0] [results 0]Environment (please complete the following information):