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-13348] SILGen crash involving optionals and @differentiable function reabstraction #55788

Open
dan-zheng opened this issue Aug 4, 2020 · 1 comment

Comments

@dan-zheng
Copy link
Collaborator

@dan-zheng dan-zheng commented Aug 4, 2020

Previous ID SR-13348
Radar rdar://problem/74094128
Original Reporter @dan-zheng
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, AutoDiff, CompilerCrash, SILGen
Assignee @rxwei
Priority Medium

md5: 44e508bb9deac7742061973fca493ddf

Issue Description:

The reproducer tries to reabstract a @differentiable (T??) -> T function to a @differentiable (Float?) -> Float function.

import _Differentiation

func foo<T: Differentiable>(_ x: T??) -> T {
  fatalError()
}

func identity<T>(_ x: T) {}

func bar() {
  let diffFn: @differentiable (Float?) -> Float = foo
  identity(diffFn)
}
$ unsupported collection upcast kind
UNREACHABLE executed at /Users/danielzheng/swift-merge/swift/lib/SILGen/SILGenPoly.cpp:522!
Stack dump:
0.  Program arguments: /Users/danielzheng/swift-merge/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift-frontend -frontend -c -primary-file sr-13348.swift -target x86_64-apple-darwin19.4.0 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.16.sdk -color-diagnostics -target-sdk-version 10.16 -module-name main -o /var/folders/m_/6f7q8zfs3n9fr0c_4gy8840m00hc_q/T/sr-13348-4ca19a.o
1.  Swift version 5.3-dev (LLVM 5b20e5d73717a73, Swift e36317d53a67546)
2.  While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "sr-13348.swift")
3.  While silgen emitFunction SIL function "@$s4main3baryyF".
 for 'bar()' (at sr-13348.swift:9:1)
4.  While emitting reabstraction thunk in SIL function "@$sSfSgSgSfIegyd_AASfIegnr_TR".
 for <<debugloc at "<compiler-generated>":0:0>>0  swift-frontend           0x000000010d828745 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift-frontend           0x000000010d827718 llvm::sys::RunSignalHandlers() + 248
2  swift-frontend           0x000000010d828d26 SignalHandler(int) + 262
3  libsystem_platform.dylib 0x00007fff6a3e15fd _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603338733709856
5  libsystem_c.dylib        0x00007fff6a2b7808 abort + 120
6  swift-frontend           0x000000010d7960e2 llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) + 482
7  swift-frontend           0x0000000109790f0b (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 13179
8  swift-frontend           0x0000000109797061 swift::Lowering::ManagedValue llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::SILType, swift::Lowering::SGFContext)>::callback_fn<(anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext)::$_12>(long, swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::SILType, swift::Lowering::SGFContext) + 177
9  swift-frontend           0x0000000109719a7c std::__1::__function::__func<swift::Lowering::SILGenFunction::emitOptionalToOptional(swift::SILLocation, swift::Lowering::ManagedValue, swift::SILType, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::SILType, swift::Lowering::SGFContext)>, swift::Lowering::SGFContext)::$_1, std::__1::allocator<swift::Lowering::SILGenFunction::emitOptionalToOptional(swift::SILLocation, swift::Lowering::ManagedValue, swift::SILType, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::SILType, swift::Lowering::SGFContext)>, swift::Lowering::SGFContext)::$_1>, void (swift::Lowering::ManagedValue, swift::Lowering::SwitchCaseFullExpr&&)>::operator()(swift::Lowering::ManagedValue&&, swift::Lowering::SwitchCaseFullExpr&&) + 348
10 swift-frontend           0x00000001096c1825 swift::Lowering::SwitchEnumBuilder::emit() && + 1989
11 swift-frontend           0x0000000109714e18 swift::Lowering::SILGenFunction::emitOptionalToOptional(swift::SILLocation, swift::Lowering::ManagedValue, swift::SILType, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::SILType, swift::Lowering::SGFContext)>, swift::Lowering::SGFContext) + 1176
12 swift-frontend           0x000000010978e0c1 (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 1329
13 swift-frontend           0x000000010979af63 (anonymous namespace)::TranslateArguments::translateSingle(swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::ManagedValue, swift::SILParameterInfo) + 371
14 swift-frontend           0x0000000109799cef (anonymous namespace)::TranslateArguments::translate(swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType) + 2367
15 swift-frontend           0x000000010979a562 (anonymous namespace)::TranslateArguments::translate(llvm::ArrayRef<swift::Lowering::AbstractionPattern>, swift::ArrayRefView<swift::AnyFunctionType::Param, swift::AnyFunctionType::CanParam, swift::AnyFunctionType::CanParam::getFromParam(swift::AnyFunctionType::Param const&), true>, llvm::ArrayRef<swift::Lowering::AbstractionPattern>, swift::ArrayRefView<swift::AnyFunctionType::Param, swift::AnyFunctionType::CanParam, swift::AnyFunctionType::CanParam::getFromParam(swift::AnyFunctionType::Param const&), true>) + 194
16 swift-frontend           0x0000000109792b7d (anonymous namespace)::TranslateArguments::translate(swift::Lowering::AbstractionPattern, swift::ArrayRefView<swift::AnyFunctionType::Param, swift::AnyFunctionType::CanParam, swift::AnyFunctionType::CanParam::getFromParam(swift::AnyFunctionType::Param const&), true>, swift::Lowering::AbstractionPattern, swift::ArrayRefView<swift::AnyFunctionType::Param, swift::AnyFunctionType::CanParam, swift::AnyFunctionType::CanParam::getFromParam(swift::AnyFunctionType::Param const&), true>) + 845
17 swift-frontend           0x00000001097983ba createThunk(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::TypeLowering const&) + 4922
18 swift-frontend           0x0000000109797cc3 createThunk(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::TypeLowering const&) + 3139
19 swift-frontend           0x000000010978e794 (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 3076
@rxwei
Copy link
Member

@rxwei rxwei commented Feb 8, 2021

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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

2 participants