Skip to content

[SR-12641] SILGen verification error regarding differentiable function reabstraction #55085

Closed
@dan-zheng

Description

@dan-zheng
Previous ID SR-12641
Radar None
Original Reporter @dan-zheng
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, AutoDiff
Assignee @marcrasi
Priority Medium

md5: e0729e1a8814f0c9916ce41df6a73a0b

Issue Description:

import _Differentiation
import DifferentiationUnittest

class Class: Differentiable {
  var x: Tracked<Float>
  init(_ x: Tracked<Float>) {
    self.x = x
  }
}

func getter(_ c: Class) -> Tracked<Float> {
  return c.x
}
print(gradient(at: Class(10), in: getter))
$ swiftc cls.swift
Assertion failed: (conv.isIndirectConvention() && "Expect an indirect convention"), function isConsumingOrMutatingArgumentConvention, file /Users/danielzheng/swift-merge/swift/lib/SIL/Verifier/SILVerifier.cpp, line 453.
Stack dump:
0.  Program arguments: /Users/danielzheng/swift-merge/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift -frontend -c -primary-file cls.swift -target x86_64-apple-darwin19.4.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -target-sdk-version 10.15.4 -module-name cls -o /var/folders/m_/6f7q8zfs3n9fr0c_4gy8840m00hc_q/T/cls-8f76c1.o
1.  Swift version 5.3-dev (LLVM ca0260ddec, Swift b17e1b23fe)
2.  While evaluating request SILGenSourceFileRequest(SIL Generation for file "cls.swift")
3.  While verifying SIL function "@$s3cls5ClassC13TangentVectorV23DifferentiationUnittest7TrackedVySfGIeggr_AeIIegnr_TR".
 for <<debugloc at "<compiler-generated>":0:0>>0  swift                    0x000000010956a138 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x00000001095690b8 llvm::sys::RunSignalHandlers() + 248
2  swift                    0x000000010956a72d SignalHandler(int) + 285
3  libsystem_platform.dylib 0x00007fff718335fd _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603338611739168
5  libsystem_c.dylib        0x00007fff71709808 abort + 120
6  libsystem_c.dylib        0x00007fff71708ac6 err + 0
7  swift                    0x00000001098e7c23 (anonymous namespace)::ImmutableAddressUseVerifier::isConsumingOrMutatingApplyUse(swift::Operand*) (.cold.4) + 35
8  swift                    0x0000000105b2ad11 (anonymous namespace)::ImmutableAddressUseVerifier::isConsumingOrMutatingApplyUse(swift::Operand*) + 289
9  swift                    0x0000000105b29c1d (anonymous namespace)::ImmutableAddressUseVerifier::isMutatingOrConsuming(swift::SILValue) + 157
10 swift                    0x0000000105b12ea9 (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) + 1161

I believe the issue related to differentiable function reabstraction thunking. Verification fails for this function:

// thunk for @escaping @callee_guaranteed (@guaranteed Class.TangentVector) -> (@out Tracked<Float>)
sil shared [transparent] [serializable] [reabstraction_thunk] [ossa] @$s7sr126415ClassC13TangentVectorV23DifferentiationUnittest7TrackedVySfGIeggr_AeIIegnr_TR : $@convention(thin) (@in_guaranteed Class.TangentVector, @guaranteed @callee_guaranteed (@guaranteed Class.TangentVector) -> @out Tracked<Float>) -> @out Tracked<Float> {
// %0                                             // user: %3
// %1                                             // user: %3
// %2                                             // user: %3
bb0(%0 : $*Tracked<Float>, %1 : $*Class.TangentVector, %2 : @guaranteed $@callee_guaranteed (@guaranteed Class.TangentVector) -> @out Tracked<Float>):
  %3 = apply %2(%0, %1) : $@callee_guaranteed (@guaranteed Class.TangentVector) -> @out Tracked<Float>
  %4 = tuple ()                                   // user: %5
  return %4 : $()                                 // id: %5
} // end sil function '$s7sr126415ClassC13TangentVectorV23DifferentiationUnittest7TrackedVySfGIeggr_AeIIegnr_TR'

To be further minimized.

Metadata

Metadata

Assignees

Labels

AutoDiffbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions