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-9458] [AD] Crash when emitting @autodiff function arguments in IRGen #51921

Closed
rxwei opened this issue Dec 10, 2018 · 1 comment
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. swift for tensorflow

Comments

@rxwei
Copy link
Member

rxwei commented Dec 10, 2018

Previous ID SR-9458
Radar None
Original Reporter @rxwei
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Swift for TensorFlow
Labels Bug
Assignee @marcrasi
Priority Medium

md5: 22c63d2ecbde7ad51f0f1543388aa7ee

Issue Description:

A strong_retain on an @autodiff function causes IRGenSILFunction::visitStrongRetainInst to crash because it expects the argument type info to be `ReferenceTypeInfo`.

test.swift:

import Swift
public func diff<T : Differentiable, R : Differentiable>(
  _ f: @escaping @autodiff (T) -> R
) -> (T) -> (R, (T.TangentVector) -> R.TangentVector) {
  return Builtin.autodiffGetJVP(f)
}

public func diff2<T : Differentiable, R : Differentiable>(
  _ f: @escaping @autodiff (T) -> R, _ x: T
) {
  diff(f)(x)
}
swiftc -parse-stdlib -emit-ir test.swift
Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file /Users/rxwei/Development/Swift/swift-tf-source/llvm/include/llvm/Support/Casting.h, line 248.
Stack dump:
0.  Program arguments: /Users/rxwei/Development/Swift/swift-tf-source/build/Ninja-ReleaseAssert+stdlib-Release/swift-macosx-x86_64/bin/swift -frontend -emit-ir -primary-file test.swift -disable-objc-attr-requires-foundation-module -target x86_64-apple-darwin18.2.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -parse-stdlib -color-diagnostics -module-name test -o -
1.  While emitting IR SIL function "@$s4test4diffyq__13TangentVectorQy_ACQzctxcq_xcs14DifferentiableRzsAFR_r0_lF".
 for 'diff(_:)' at test.swift:2:8
0  swift                    0x00000001064e0558 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x00000001064df528 llvm::sys::RunSignalHandlers() + 248
2  swift                    0x00000001064e0b72 SignalHandler(int) + 258
3  libsystem_platform.dylib 0x00007fff5b59cb3d _sigtramp + 29
4  swift                    0x000000010719f462 cmark_strbuf__initbuf + 117613
5  libsystem_c.dylib        0x00007fff5b45b1c9 abort + 127
6  libsystem_c.dylib        0x00007fff5b423868 basename_r + 0
7  swift                    0x0000000102d39d74 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 57876
8  swift                    0x0000000102d28192 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 7938
9  swift                    0x0000000102c33ae2 swift::irgen::IRGenerator::emitGlobalTopLevel(bool) + 674
10 swift                    0x0000000102d000db performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**) + 1067
11 swift                    0x0000000102d00616 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, llvm::GlobalVariable**) + 86
12 swift                    0x0000000102b8b9bb performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 13739
13 swift                    0x0000000102b873a0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2848
14 swift                    0x0000000102b391de main + 686
15 libdyld.dylib            0x00007fff5b3b308d start + 1
[1]    97501 abort      $SWIFT_NINJA_BUILD_PATH/bin/swiftc -emit-ir -parse-stdlib test.swift
@rxwei
Copy link
Member Author

rxwei commented Dec 17, 2018

Marc fixed this by reversing FunctionConversionExpr and AutoDiffFunctionExpr in #21367

@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
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. swift for tensorflow
Projects
None yet
Development

No branches or pull requests

1 participant