Skip to content
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

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

Closed
dan-zheng opened this issue Sep 9, 2020 · 2 comments
Closed

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

dan-zheng opened this issue Sep 9, 2020 · 2 comments

Comments

@dan-zheng
Copy link
Collaborator

@dan-zheng dan-zheng commented Sep 9, 2020

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
Copy link
Member

@airspeedswift airspeedswift commented Jan 20, 2021

@swift-ci create

@rxwei
Copy link
Member

@rxwei rxwei commented Feb 8, 2021

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

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants