-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add mangling support for @differentiable
function types.
#26595
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// RUN: %target-swift-frontend -c %s -g -O -parse-stdlib -parse-as-library -module-name Swift | ||
|
||
// TF-597: Exact minimal reproducer for IRGenDebugInfo crash. | ||
// Crash occurred only with `-g` and `-O`. | ||
// | ||
// ``` | ||
// Assertion failed: (OffsetInBits + SizeInBits <= getSizeInBits(Var) && "pars > totum"), | ||
// function emitVariableDeclaration, file swift/lib/IRGen/IRGenDebugInfo.cpp, line 2216. | ||
// Stack dump: | ||
// 1. Swift version 5.1-dev (LLVM 200186e28b, Swift c09c14dec5) | ||
// 2. While emitting IR SIL function "@$ss8pullback2at2inyx_q_xXFts14DifferentiableRzsADR_r0_lF". | ||
// for 'pullback(at:in:)' (at swift/test/AutoDiff/differentiable_func_debuginfo.swift:21:8) | ||
// ``` | ||
// | ||
// The crash was because `IRGenDebugInfoImpl::getOrCreateType` computes | ||
// `llvm::DIType` type debug info by demangling type names. | ||
// | ||
// Since `@differentiable` and `@differentiable(linear)` function types did | ||
// not have mangling support, `getOrCreateType` computed a regular `(A) -> B` | ||
// function type instead of a `@differentiable (A) -> B` function type, leading | ||
// to a type size inconsistency. | ||
// | ||
// Conclusion: mangling coverage is important. | ||
|
||
// Minimal dummy compiler-known `Differentiable` protocol. | ||
public protocol Differentiable { | ||
associatedtype TangentVector | ||
} | ||
|
||
// This declaration is necessary to reproduce the crash for some reason. | ||
dan-zheng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public func blackHole<T, U>(_: (T) -> U) {} | ||
|
||
public func pullback<T, R>( | ||
at x: T, in tf597ProblematicVarDecl: @differentiable (T) -> R | ||
) { | ||
let _ = Builtin.autodiffApply_vjp(tf597ProblematicVarDecl, x) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,3 +184,11 @@ func varargsVsArray(arr: [Int], n: String) { } | |
|
||
// CHECK-LABEL: sil hidden [ossa] @$s8mangling14varargsVsArray3arr1nySaySiGd_SStF : $@convention(thin) (@guaranteed Array<Array<Int>>, @guaranteed String) -> () | ||
func varargsVsArray(arr: [Int]..., n: String) { } | ||
|
||
// SWIFT_ENABLE_TENSORFLOW | ||
// CHECK-LABEL: sil hidden [ossa] @$s8mangling15funcVsDiffFunc12fnyS2fXE_tF : $@convention(thin) (@noescape @callee_guaranteed (Float) -> Float) -> () | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: these newly added tests actually test That logic is different from the mangling logic added in this patch (mangling modifiers for cc @slavapestov, wonder if you can clarify |
||
func funcVsDiffFunc1(fn: (Float) -> Float) {} | ||
|
||
// SWIFT_ENABLE_TENSORFLOW | ||
dan-zheng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// CHECK-LABEL: sil hidden [ossa] @$s8mangling15funcVsDiffFunc22fnyS2fXF_tF : $@convention(thin) (@differentiable @noescape @callee_guaranteed (Float) -> Float) -> () | ||
func funcVsDiffFunc2(fn: @differentiable (Float) -> Float) {} |
Uh oh!
There was an error while loading. Please reload this page.