swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.34k stars 10.34k forks source link

[SR-13529] Forward-mode differentiation: thunk generation crash #55966

Closed dan-zheng closed 3 years ago

dan-zheng commented 4 years ago
Previous ID SR-13529
Radar rdar://problem/73388885
Original Reporter @dan-zheng
Type Bug
Status Closed
Resolution Invalid
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, AutoDiff, CompilerCrash | |Assignee | None | |Priority | Medium | md5: bf77f0398bb89e022f17050e14447b10

Issue Description:

Reproducer:

import _Differentiation

struct Tensor<Scalar> {}
extension Tensor: Differentiable where Scalar: Differentiable {}

@differentiable
func foo<Scalar: Differentiable>(_ x: Tensor<Scalar>) -> Tensor<Scalar> { x }

@differentiable(wrt: x)
func bar<Scalar: Differentiable>(
  x: Tensor<Scalar>,
  body: @differentiable (Tensor<Scalar>) -> Tensor<Scalar> = foo
) -> Tensor<Scalar> {
  body(x)
}
$ swiftc -Xfrontend -enable-experimental-forward-mode-differentiation fwd.swift
Assertion failed: (signature || !origType->hasTypeParameter()), function initSwiftType, file include/swift/SIL/AbstractionPattern.h, line 395.
Stack dump:
0.  Program arguments: build/Ninja-ReleaseAssert+swift-DebugAssert/swift-macosx-x86_64/bin/swift-frontend -frontend -c -primary-file fwd.swift -target x86_64-apple-darwin19.4.0 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -color-diagnostics -enable-experimental-forward-mode-differentiation -target-sdk-version 10.16 -module-name fwd -o /var/folders/m_/6f7q8zfs3n9fr0c_4gy8840m00hc_q/T/fwd-db5651.o
1.  Swift version 5.3-dev (LLVM 14a10d635b229fb, Swift 39c6ee112f95980)
2.  While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for fwd.fwd)
3.  While running pass #&#8203;489 SILModuleTransform "Differentiation".
4.  While processing // differentiability witness for bar<A>(x:body:)
sil_differentiability_witness hidden [parameters 0] [results 0] <Scalar where Scalar : Differentiable> @$s3fwd3bar1x4bodyAA6TensorVyxGAG_A2GXFts14DifferentiableRzlF : $@convention(thin) <Scalar where Scalar : Differentiable> (Tensor<Scalar>, @differentiable @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (Tensor<τ_0_0>) -> Tensor<τ_0_1> for <Scalar, Scalar>) -> Tensor<Scalar> {
}

 on SIL function "@$s3fwd3bar1x4bodyAA6TensorVyxGAG_A2GXFts14DifferentiableRzlF".
 for 'bar(x:body:)' (at fwd.swift:10:1)
5.  While generating JVP and differential for SIL function "@$s3fwd3bar1x4bodyAA6TensorVyxGAG_A2GXFts14DifferentiableRzlF".
 for 'bar(x:body:)' (at fwd.swift:10:1)
0  swift-frontend           0x0000000113695ca5 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift-frontend           0x0000000113694c58 llvm::sys::RunSignalHandlers() + 248
2  swift-frontend           0x00000001136962a6 SignalHandler(int) + 262
3  libsystem_platform.dylib 0x00007fff6e0115fd _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603338670598688
5  libsystem_c.dylib        0x00007fff6dee7808 abort + 120
6  libsystem_c.dylib        0x00007fff6dee6ac6 err + 0
7  swift-frontend           0x000000010e907432 swift::Lowering::AbstractionPattern::initSwiftType(swift::CanGenericSignature, swift::CanType, swift::Lowering::AbstractionPattern::Kind) + 130
8  swift-frontend           0x000000010e90739f swift::Lowering::AbstractionPattern::AbstractionPattern(swift::CanGenericSignature, swift::CanType) + 111
9  swift-frontend           0x000000010e8f0b45 swift::Lowering::AbstractionPattern::AbstractionPattern(swift::CanGenericSignature, swift::CanType) + 37
10 swift-frontend           0x000000010e79e1a4 (anonymous namespace)::SILTypeSubstituter::visitType(swift::CanType) + 660
11 swift-frontend           0x000000010e79e5d8 swift::CanTypeVisitor<(anonymous namespace)::SILTypeSubstituter, swift::CanType>::visitNominalType(swift::CanTypeWrapper<swift::NominalType>) + 40
12 swift-frontend           0x000000010e79d7a8 swift::CanTypeVisitor<(anonymous namespace)::SILTypeSubstituter, swift::CanType>::visitStructType(swift::CanTypeWrapper<swift::StructType>) + 40
13 swift-frontend           0x000000010e79c983 swift::CanTypeVisitor<(anonymous namespace)::SILTypeSubstituter, swift::CanType>::visit(swift::CanType) + 1251
14 swift-frontend           0x000000010e79ee2d (anonymous namespace)::SILTypeSubstituter::substInterface(swift::SILResultInfo) + 61
15 swift-frontend           0x000000010e786654 (anonymous namespace)::SILTypeSubstituter::substSILFunctionType(swift::CanTypeWrapper<swift::SILFunctionType>, bool) + 2244
16 swift-frontend           0x000000010e79dd17 (anonymous namespace)::SILTypeSubstituter::visitSILFunctionType(swift::CanTypeWrapper<swift::SILFunctionType>) + 39
17 swift-frontend           0x000000010e79cedb swift::CanTypeVisitor<(anonymous namespace)::SILTypeSubstituter, swift::CanType>::visit(swift::CanType) + 2619
18 swift-frontend           0x000000010e785742 (anonymous namespace)::SILTypeSubstituter::subst(swift::SILType) + 50
19 swift-frontend           0x000000010e785626 swift::SILType::subst(swift::Lowering::TypeConverter&, llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<swift::ProtocolConformanceRef (swift::CanType, swift::Type, swift::ProtocolDecl*)>, swift::CanGenericSignature, bool) const + 486
20 swift-frontend           0x000000010e785805 swift::SILType::subst(swift::SILModule&, llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<swift::ProtocolConformanceRef (swift::CanType, swift::Type, swift::ProtocolDecl*)>, swift::CanGenericSignature, bool) const + 149
21 swift-frontend           0x000000010db486fe swift::autodiff::buildThunkType(swift::SILFunction*, swift::CanTypeWrapper<swift::SILFunctionType>&, swift::CanTypeWrapper<swift::SILFunctionType>&, swift::GenericEnvironment*&, swift::SubstitutionMap&, bool, swift::autodiff::DifferentiationThunkKind)::$_3::operator()(swift::CanTypeWrapper<swift::SILFunctionType>) const + 190
22 swift-frontend           0x000000010db47e98 swift::autodiff::buildThunkType(swift::SILFunction*, swift::CanTypeWrapper<swift::SILFunctionType>&, swift::CanTypeWrapper<swift::SILFunctionType>&, swift::GenericEnvironment*&, swift::SubstitutionMap&, bool, swift::autodiff::DifferentiationThunkKind) + 1112
23 swift-frontend           0x000000010db48988 swift::autodiff::getOrCreateReabstractionThunk(swift::SILOptFunctionBuilder&, swift::SILModule&, swift::SILLocation, swift::SILFunction*, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>) + 328
24 swift-frontend           0x000000010db4a78a swift::autodiff::reabstractFunction(swift::SILBuilder&, swift::SILOptFunctionBuilder&, swift::SILLocation, swift::SILValue, swift::CanTypeWrapper<swift::SILFunctionType>, std::__1::function<swift::SubstitutionMap (swift::SubstitutionMap)>) + 330
25 swift-frontend           0x000000010dae4d7d swift::autodiff::JVPCloner::Implementation::visitApplyInst(swift::ApplyInst*) + 6557

The crash occurs while attempting to generate a reabstraction thunk for a function-typed value (differential callee) during forward-mode differentiation.

airspeedswift commented 3 years ago

@swift-ci create

rxwei commented 3 years ago

Forward-mode is not supported and will be deprecated. Closing.

philipturner commented 2 years ago

I found the same crash in #59429, and it does not seem related to forward-mode differentiation. However, #59429 was found while investigating a separate crash involving forward-mode differentiation.

philipturner commented 2 years ago

I did come across this, which produced a similar error message under the -enable-experimental-forward-mode-differentiation flag.

func partial<T, U, V>(
  _ f: @differentiable(reverse) (T, T) -> V,
  y: U
) -> @differentiable(reverse) (T) -> V {
  { x in f(x, x) }
}
Stack Trace ``` /Users/philipturner/Downloads/BugReplay/Sources/BugReplay/BugReplay.swift:15:3: error: escaping closure captures non-escaping parameter 'f' { x in f(x, x) } ^ /Users/philipturner/Downloads/BugReplay/Sources/BugReplay/BugReplay.swift:12:5: note: parameter 'f' is implicitly non-escaping _ f: @differentiable(reverse) (T, T) -> V, ^ /Users/philipturner/Downloads/BugReplay/Sources/BugReplay/BugReplay.swift:15:10: note: captured here { x in f(x, x) } ^ Assertion failed: (signature || !origType->hasTypeParameter()), function initSwiftType, file AbstractionPattern.h, line 528. Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace. Stack dump: 0. Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-06-08-a.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/philipturner/Downloads/BugReplay/Sources/BugReplay/BugReplay.swift -emit-dependencies-path /Users/philipturner/Library/Developer/Xcode/DerivedData/BugReplay-blxdzleghndgtdgyxpflpgbtdvjy/Build/Intermediates.noindex/BugReplay.build/Debug-iphoneos/BugReplay.build/Objects-normal/arm64/BugReplay.d -emit-reference-dependencies-path /Users/philipturner/Library/Developer/Xcode/DerivedData/BugReplay-blxdzleghndgtdgyxpflpgbtdvjy/Build/Intermediates.noindex/BugReplay.build/Debug-iphoneos/BugReplay.build/Objects-normal/arm64/BugReplay.swiftdeps -serialize-diagnostics-path /Users/philipturner/Library/Developer/Xcode/DerivedData/BugReplay-blxdzleghndgtdgyxpflpgbtdvjy/Build/Intermediates.noindex/BugReplay.build/Debug-iphoneos/BugReplay.build/Objects-normal/arm64/BugReplay.dia -target arm64-apple-ios9.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.5.sdk -I /Users/philipturner/Library/Developer/Xcode/DerivedData/BugReplay-blxdzleghndgtdgyxpflpgbtdvjy/Build/Products/Debug-iphoneos -I /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib -F /Users/philipturner/Library/Developer/Xcode/DerivedData/BugReplay-blxdzleghndgtdgyxpflpgbtdvjy/Build/Products/Debug-iphoneos -F /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks -F /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.5.sdk/Developer/Library/Frameworks -enable-testing -g -module-cache-path /Users/philipturner/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -new-driver-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-06-08-a.xctoolchain/usr/bin/swift-driver -enable-experimental-forward-mode-differentiation -serialize-debugging-options -empty-abi-descriptor -resource-dir /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-06-08-a.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -I/Users/philipturner/Library/Developer/Xcode/DerivedData/BugReplay-blxdzleghndgtdgyxpflpgbtdvjy/Build/Intermediates.noindex/BugReplay.build/Debug-iphoneos/BugReplay.build/swift-overrides.hmap -Xcc -I/Users/philipturner/Library/Developer/Xcode/DerivedData/BugReplay-blxdzleghndgtdgyxpflpgbtdvjy/Build/Products/Debug-iphoneos/include -Xcc -I/Users/philipturner/Library/Developer/Xcode/DerivedData/BugReplay-blxdzleghndgtdgyxpflpgbtdvjy/Build/Intermediates.noindex/BugReplay.build/Debug-iphoneos/BugReplay.build/DerivedSources-normal/arm64 -Xcc -I/Users/philipturner/Library/Developer/Xcode/DerivedData/BugReplay-blxdzleghndgtdgyxpflpgbtdvjy/Build/Intermediates.noindex/BugReplay.build/Debug-iphoneos/BugReplay.build/DerivedSources/arm64 -Xcc -I/Users/philipturner/Library/Developer/Xcode/DerivedData/BugReplay-blxdzleghndgtdgyxpflpgbtdvjy/Build/Intermediates.noindex/BugReplay.build/Debug-iphoneos/BugReplay.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -Xcc -working-directory/Users/philipturner/Downloads/BugReplay -module-name BugReplay -target-sdk-version 15.5 -parse-as-library -o /Users/philipturner/Library/Developer/Xcode/DerivedData/BugReplay-blxdzleghndgtdgyxpflpgbtdvjy/Build/Intermediates.noindex/BugReplay.build/Debug-iphoneos/BugReplay.build/Objects-normal/arm64/BugReplay.o -index-unit-output-path /BugReplay.build/Debug-iphoneos/BugReplay.build/Objects-normal/arm64/BugReplay.o -index-store-path /Users/philipturner/Library/Developer/Xcode/DerivedData/BugReplay-blxdzleghndgtdgyxpflpgbtdvjy/Index/DataStore -index-system-modules 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 BugReplay) 4. While running pass #19 SILModuleTransform "Differentiation". 5. While canonicalizing `differentiable_function` SIL node %7 = differentiable_function [parameters 0] [results 0] %6 : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for // user: %8 6. While ...in SIL function "@$s9BugReplay7partial_1yq0_xYjrcq0_x_xtYjrXE_q_t16_Differentiation14DifferentiableRzAdER0_r1_lF". for 'partial(_:y:)' (at /Users/philipturner/Downloads/BugReplay/Sources/BugReplay/BugReplay.swift:11:1) 7. While processing // differentiability witness for closure #1 in partial(_:y:) sil_differentiability_witness private [reverse] [parameters 0] [results 0] <τ_0_0, τ_0_1, τ_0_2 where τ_0_0 : Differentiable, τ_0_2 : Differentiable> @$s9BugReplay7partial_1yq0_xYjrcq0_x_xtYjrXE_q_t16_Differentiation14DifferentiableRzAdER0_r1_lFq0_xcfU_ : $@convention(thin) (@in_guaranteed T, @differentiable(reverse) @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1, τ_0_2> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_1) -> @out τ_0_2 for ) -> @out V { } on SIL function "@$s9BugReplay7partial_1yq0_xYjrcq0_x_xtYjrXE_q_t16_Differentiation14DifferentiableRzAdER0_r1_lFq0_xcfU_". for expression at [/Users/philipturner/Downloads/BugReplay/Sources/BugReplay/BugReplay.swift:15:3 - line:15:18] RangeText="{ x in f(x, x) " 8. While generating JVP and differential for SIL function "@$s9BugReplay7partial_1yq0_xYjrcq0_x_xtYjrXE_q_t16_Differentiation14DifferentiableRzAdER0_r1_lFq0_xcfU_". for expression at [/Users/philipturner/Downloads/BugReplay/Sources/BugReplay/BugReplay.swift:15:3 - line:15:18] RangeText="{ x in f(x, x) " Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it): 0 swift-frontend 0x0000000108ba1848 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56 1 swift-frontend 0x0000000108ba0aa8 llvm::sys::RunSignalHandlers() + 128 2 swift-frontend 0x0000000108ba1eac SignalHandler(int) + 304 3 libsystem_platform.dylib 0x00000001a6a674a4 _sigtramp + 56 4 libsystem_pthread.dylib 0x00000001a6a4fee0 pthread_kill + 288 5 libsystem_c.dylib 0x00000001a698a340 abort + 168 6 libsystem_c.dylib 0x00000001a6989754 err + 0 7 swift-frontend 0x0000000108cf2b24 swift::Lowering::SILGenFunction::enterDebugScope(swift::SILLocation, bool) (.cold.1) + 0 8 swift-frontend 0x0000000104c12d64 swift::Lowering::SILGenFunction::enterDebugScope(swift::SILLocation, bool) + 0 9 swift-frontend 0x0000000104799248 (anonymous namespace)::SILTypeSubstituter::visitType(swift::CanType) + 248 10 swift-frontend 0x0000000104798e4c swift::CanTypeVisitor<(anonymous namespace)::SILTypeSubstituter, swift::CanType>::visit(swift::CanType) + 1544 11 swift-frontend 0x0000000104791c3c (anonymous namespace)::SILTypeSubstituter::substSILFunctionType(swift::CanTypeWrapper, bool) + 792 12 swift-frontend 0x0000000104798d58 swift::CanTypeVisitor<(anonymous namespace)::SILTypeSubstituter, swift::CanType>::visit(swift::CanType) + 1300 13 swift-frontend 0x00000001047914d4 swift::SILType::subst(swift::Lowering::TypeConverter&, llvm::function_ref, llvm::function_ref, swift::CanGenericSignature, bool) const + 336 14 swift-frontend 0x000000010478e000 swift::buildSILFunctionThunkType(swift::SILFunction*, swift::CanTypeWrapper&, swift::CanTypeWrapper&, swift::CanType&, swift::CanType&, swift::GenericEnvironment*&, swift::SubstitutionMap&, swift::CanType&, bool, llvm::Optional)::$_6::operator()(swift::CanTypeWrapper) const + 108 15 swift-frontend 0x000000010478d588 swift::buildSILFunctionThunkType(swift::SILFunction*, swift::CanTypeWrapper&, swift::CanTypeWrapper&, swift::CanType&, swift::CanType&, swift::GenericEnvironment*&, swift::SubstitutionMap&, swift::CanType&, bool, llvm::Optional) + 1440 16 swift-frontend 0x0000000104d7b160 swift::autodiff::getOrCreateReabstractionThunk(swift::SILOptFunctionBuilder&, swift::SILModule&, swift::SILLocation, swift::SILFunction*, swift::CanTypeWrapper, swift::CanTypeWrapper) + 196 17 swift-frontend 0x0000000104d7ccd4 swift::autodiff::reabstractFunction(swift::SILBuilder&, swift::SILOptFunctionBuilder&, swift::SILLocation, swift::SILValue, swift::CanTypeWrapper, std::__1::function) + 204 18 swift-frontend 0x0000000104d524b4 swift::autodiff::JVPCloner::Implementation::visitApplyInst(swift::ApplyInst*) + 4088 19 swift-frontend 0x0000000104d4ab2c swift::autodiff::JVPCloner::Implementation::visit(swift::SILInstruction*) + 248 20 swift-frontend 0x0000000104d4a79c swift::autodiff::JVPCloner::Implementation::visitInstructionsInBlock(swift::SILBasicBlock*) + 320 21 swift-frontend 0x0000000104d49ff0 swift::SILCloner::visitBlocksDepthFirst(swift::SILBasicBlock*) + 348 22 swift-frontend 0x0000000104d46a18 swift::SILCloner::cloneFunctionBody(swift::SILFunction*, swift::SILBasicBlock*, llvm::ArrayRef, bool) + 472 23 swift-frontend 0x0000000104d46534 swift::autodiff::JVPCloner::Implementation::run() + 1024 24 swift-frontend 0x0000000104d46c80 swift::autodiff::JVPCloner::run() + 24 25 swift-frontend 0x0000000104e835e4 (anonymous namespace)::DifferentiationTransformer::canonicalizeDifferentiabilityWitness(swift::SILDifferentiabilityWitness*, swift::autodiff::DifferentiationInvoker, swift::IsSerialized_t) + 3344 26 swift-frontend 0x0000000104e87a00 (anonymous namespace)::DifferentiationTransformer::promoteToDifferentiableFunction(swift::DifferentiableFunctionInst*, swift::SILBuilder&, swift::SILLocation, swift::autodiff::DifferentiationInvoker) + 7928 27 swift-frontend 0x0000000104e83fdc (anonymous namespace)::DifferentiationTransformer::processDifferentiableFunctionInst(swift::DifferentiableFunctionInst*) + 484 28 swift-frontend 0x0000000104e82068 (anonymous namespace)::Differentiation::run() + 1292 29 swift-frontend 0x0000000104efa0e4 swift::SILPassManager::runModulePass(unsigned int) + 956 30 swift-frontend 0x0000000104eff858 swift::SILPassManager::execute() + 624 31 swift-frontend 0x0000000104ef71ac swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 68 32 swift-frontend 0x0000000104ef7134 swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const + 68 33 swift-frontend 0x0000000104f18e38 swift::SimpleRequest (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 28 34 swift-frontend 0x0000000104f02690 llvm::Expected swift::Evaluator::getResultUncached(swift::ExecuteSILPipelineRequest const&) + 252 35 swift-frontend 0x0000000104ef73a8 swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) + 84 36 swift-frontend 0x0000000104f06d88 swift::runSILDiagnosticPasses(swift::SILModule&) + 92 37 swift-frontend 0x0000000104736610 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 68 38 swift-frontend 0x00000001046db540 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr >, llvm::PointerUnion, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 716 39 swift-frontend 0x00000001046dad18 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 540 40 swift-frontend 0x00000001046e89b8 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref, bool) + 160 41 swift-frontend 0x00000001046dca48 swift::performFrontend(llvm::ArrayRef, char const*, void*, swift::FrontendObserver*) + 3388 42 swift-frontend 0x00000001045c3124 swift::mainEntry(int, char const**) + 3764 43 dyld 0x00000001113a908c start + 520 error: Abort trap: 6 (in target 'BugReplay' from project 'BugReplay') ```

Toolchain: June 8, 2022 Development Snapshot

philipturner commented 2 years ago

Here is the full investigation of the new set of crashers. Above each one is the first line of the error message. Credit to @stevapple for spotting this crash.

import _Differentiation

// Bad generic parameter in τ_0_1
func process<T: Differentiable>(
  _ f: (T) -> T
) where T == T.TangentVector {
  pullback(at: .zero, of: { x in
    f(x)
  })(.zero)
}

// Assertion failed: (paramInfos.size() == arguments.size()), function OperandToInoutArgument, file SILInstruction.h, line 2716.
func partial<T, U, V>(
  _ f: @differentiable(reverse) (T, U) -> V,
  y: U
) -> @differentiable(reverse) (T) -> V {
  { x in f(x, y) }
}

// Assertion failed: (signature || !origType->hasTypeParameter()), function initSwiftType, file AbstractionPattern.h, line 528.
func partial<T, U, V>(
  _ f: @differentiable(reverse) (T, T) -> V,
  y: U
) -> @differentiable(reverse) (T) -> V {
  { x in f(x, x) }
}

// Bad generic parameter in τ_0_2
func partial<T, V>(
  _ f: @differentiable(reverse) (T, T) -> V,
  y: T
) -> @differentiable(reverse) (T) -> V {
  { x in f(x, x) }
}

// Bad generic parameter in τ_0_2
func partial<T, V>(
  _ f: @differentiable(reverse) (T, T) -> V
) -> @differentiable(reverse) (T) -> V {
  { x in f(x, x) }
}

// Bad generic parameter in τ_0_1
func partial<T>(
  _ f: @differentiable(reverse) (T, T) -> T
) -> @differentiable(reverse) (T) -> T {
  { x in f(x, x) }
}

// Bad generic parameter in τ_0_1
func partial<T>(
  _ f: (T) -> T
) -> @differentiable(reverse) (T) -> T {
  { x in f(x) }
}

Edit: I have started to reproduce this crash without having the forward-mode flag. Thus, it is probably an issue affecting reverse-mode differentiation.