Closed
Description
Previous ID | SR-12853 |
Radar | None |
Original Reporter | @dan-zheng |
Type | Bug |
Status | Resolved |
Resolution | Done |
Environment
swift-DEVELOPMENT-SNAPSHOT-2020-05-20-a
Additional Detail from JIRA
Votes | 1 |
Component/s | Compiler |
Labels | Bug, CompilerCrash, IRGen |
Assignee | @aschwaighofer |
Priority | Medium |
md5: 91dbff88c7312b05f62764755ce2b087
relates to:
- SR-10697 IRGen assertion failure when partially applying a generic function to a type whose conformance is not available locally
- TF-507 Revert SR-10697 workaround for
SimpleRNNCell
in swift-apis
Issue Description:
import _Differentiation
struct RNNCellOutput<State: Differentiable>: Differentiable {
var state: State
}
struct Tensor<Shape, Element> {} // NOTE 1
extension Tensor: Differentiable where Element: Differentiable {} // NOTE 2
typealias TensorR2<Element> = Tensor<SIMD2<Int>, Element>
struct GRUCell<Element: Differentiable> {
typealias Input = TensorR2<Element>
typealias Output = RNNCellOutput<TensorR2<Element>>
@differentiable // TRIGGER
func callAsFunction(_ input: Input) -> Output {
return Output(state: input)
}
}
// TRIGGER: The crash happens in `IRGenSILFunction::visitPartialApplyInst` for a function
// cloned by the differentiation transform.
// NOTE 1: The crash reproduces only if `Tensor` has the ~unused `Shape` generic parameter.
// NOTE 2: The crash reproduces only if `Tensor`'s conformance to `Differentiable` is conditional.
IRGen crashes while visiting a partial_apply
in a function cloned by the differentiation transform:
IRGenSILFunction::visitPartialApplyInst: AD__$s4main7GRUCellV14callAsFunctionyAA13RNNCellOutputVyAA6TensorVys5SIMD2VySiGxGGALF__vjp_src_0_wrt_0_4main21DifferentiableElementRzl
%9 = partial_apply [callee_guaranteed] %8<Tensor<SIMD2<Int>, τ_0_0>>() : $@convention(method) <τ_0_0 where τ_0_0 : Differentiable> (@in τ_0_0, @thin RNNCellOutput<τ_0_0>.Type) -> @out RNNCellOutput<τ_0_0> // user: %14
sil hidden @AD__$s4main7GRUCellV14callAsFunctionyAA13RNNCellOutputVyAA6TensorVys5SIMD2VySiGxGGALF__vjp_src_0_wrt_0_s14DifferentiableRzl : $@convention(method) <τ_0_0 where τ_0_0 : Differentiable> (Tensor<SIMD2<Int>, τ_0_0>, GRUCell<τ_0_0>) -> (RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (τ_0_0) -> τ_0_1 for <RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector, Tensor<SIMD2<Int>, τ_0_0>.TangentVector>) {
// %0 // users: %7, %2
// %1 // user: %3
bb0(%0 : $Tensor<SIMD2<Int>, τ_0_0>, %1 : $GRUCell<τ_0_0>):
debug_value %0 : $Tensor<SIMD2<Int>, τ_0_0>, let, name "input", argno 1 // id: %2
debug_value %1 : $GRUCell<τ_0_0>, let, name "self", argno 2 // id: %3
%4 = alloc_stack $RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>> // users: %28, %18
%5 = metatype $@thin RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.Type // user: %18
%6 = alloc_stack $Tensor<SIMD2<Int>, τ_0_0> // users: %7, %25, %18
store %0 to %6 : $*Tensor<SIMD2<Int>, τ_0_0> // id: %7
// function_ref RNNCellOutput.init(state:)
%8 = function_ref @$s4main13RNNCellOutputV5stateACyxGx_tcfC : $@convention(method) <τ_0_0 where τ_0_0 : Differentiable> (@in τ_0_0, @thin RNNCellOutput<τ_0_0>.Type) -> @out RNNCellOutput<τ_0_0> // user: %9
%9 = partial_apply [callee_guaranteed] %8<Tensor<SIMD2<Int>, τ_0_0>>() : $@convention(method) <τ_0_0 where τ_0_0 : Differentiable> (@in τ_0_0, @thin RNNCellOutput<τ_0_0>.Type) -> @out RNNCellOutput<τ_0_0> // user: %14
%10 = differentiability_witness_function [jvp] [parameters 0] [results 0] <τ_0_0 where τ_0_0 : Differentiable> @$s4main13RNNCellOutputV5stateACyxGx_tcfC : $@convention(method) <State where State : Differentiable> (@in State, @thin RNNCellOutput<State>.Type) -> @out RNNCellOutput<State> // user: %11
%11 = partial_apply [callee_guaranteed] %10<Tensor<SIMD2<Int>, τ_0_0>>() : $@convention(method) <τ_0_0 where τ_0_0 : Differentiable> (@in τ_0_0, @thin RNNCellOutput<τ_0_0>.Type) -> (@out RNNCellOutput<τ_0_0>, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in τ_0_0) -> @out τ_0_1 for <τ_0_0.TangentVector, RNNCellOutput<τ_0_0>.TangentVector>) // user: %14
%12 = differentiability_witness_function [vjp] [parameters 0] [results 0] <τ_0_0 where τ_0_0 : Differentiable> @$s4main13RNNCellOutputV5stateACyxGx_tcfC : $@convention(method) <State where State : Differentiable> (@in State, @thin RNNCellOutput<State>.Type) -> @out RNNCellOutput<State> // user: %13
%13 = partial_apply [callee_guaranteed] %12<Tensor<SIMD2<Int>, τ_0_0>>() : $@convention(method) <τ_0_0 where τ_0_0 : Differentiable> (@in τ_0_0, @thin RNNCellOutput<τ_0_0>.Type) -> (@out RNNCellOutput<τ_0_0>, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <RNNCellOutput<τ_0_0>.TangentVector, τ_0_0.TangentVector>) // user: %14
%14 = differentiable_function [parameters 0] %9 : $@callee_guaranteed (@in Tensor<SIMD2<Int>, τ_0_0>, @thin RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.Type) -> @out RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>> with_derivative {%11 : $@callee_guaranteed (@in Tensor<SIMD2<Int>, τ_0_0>, @thin RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.Type) -> (@out RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in τ_0_0) -> @out τ_0_1 for <Tensor<SIMD2<Int>, τ_0_0>.TangentVector, RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector>), %13 : $@callee_guaranteed (@in Tensor<SIMD2<Int>, τ_0_0>, @thin RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.Type) -> (@out RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector, Tensor<SIMD2<Int>, τ_0_0>.TangentVector>)} // users: %15, %17
%15 = differentiable_function_extract [vjp] %14 : $@differentiable @callee_guaranteed (@in Tensor<SIMD2<Int>, τ_0_0>, @noDerivative @thin RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.Type) -> @out RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>> as $@callee_guaranteed (@in Tensor<SIMD2<Int>, τ_0_0>, @thin RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.Type) -> (@out RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector, Tensor<SIMD2<Int>, τ_0_0>.TangentVector>) // users: %16, %18, %19
strong_retain %15 : $@callee_guaranteed (@in Tensor<SIMD2<Int>, τ_0_0>, @thin RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.Type) -> (@out RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector, Tensor<SIMD2<Int>, τ_0_0>.TangentVector>) // id: %16
release_value %14 : $@differentiable @callee_guaranteed (@in Tensor<SIMD2<Int>, τ_0_0>, @noDerivative @thin RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.Type) -> @out RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>> // id: %17
%18 = apply %15(%4, %6, %5) : $@callee_guaranteed (@in Tensor<SIMD2<Int>, τ_0_0>, @thin RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.Type) -> (@out RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector, Tensor<SIMD2<Int>, τ_0_0>.TangentVector>) // user: %21
strong_release %15 : $@callee_guaranteed (@in Tensor<SIMD2<Int>, τ_0_0>, @thin RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.Type) -> (@out RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>, @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector, Tensor<SIMD2<Int>, τ_0_0>.TangentVector>) // id: %19
%20 = tuple ()
%21 = convert_function %18 : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector, Tensor<SIMD2<Int>, τ_0_0>.TangentVector> to $@callee_guaranteed (@in_guaranteed RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector) -> @out Tensor<SIMD2<Int>, τ_0_0>.TangentVector // user: %23
// function_ref thunk for @escaping @callee_guaranteed (@in_guaranteed RNNCellOutput<Tensor<SIMD2<Int>, A>>.TangentVector) -> (@out Tensor<SIMD2<Int>, A><>.TangentVector)
%22 = function_ref @$s4main13RNNCellOutputV13TangentVectorVyAA6TensorVys5SIMD2VySiGxG_GAgAs14DifferentiableR_rlEADVyAJx_GIegnr_AlOIegyd_sAMRzlTR : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector, @guaranteed @callee_guaranteed (@in_guaranteed RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector) -> @out Tensor<SIMD2<Int>, τ_0_0>.TangentVector) -> Tensor<SIMD2<Int>, τ_0_0>.TangentVector // user: %23
%23 = partial_apply [callee_guaranteed] %22<τ_0_0>(%21) : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector, @guaranteed @callee_guaranteed (@in_guaranteed RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector) -> @out Tensor<SIMD2<Int>, τ_0_0>.TangentVector) -> Tensor<SIMD2<Int>, τ_0_0>.TangentVector // user: %24
%24 = convert_function %23 : $@callee_guaranteed (RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector) -> Tensor<SIMD2<Int>, τ_0_0>.TangentVector to $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector) -> Tensor<SIMD2<Int>, τ_0_1>.TangentVector for <τ_0_0, τ_0_0> // user: %29
dealloc_stack %6 : $*Tensor<SIMD2<Int>, τ_0_0> // id: %25
%26 = struct $Tensor<SIMD2<Int>, τ_0_0> () // user: %27
%27 = struct $RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>> (%26 : $Tensor<SIMD2<Int>, τ_0_0>) // user: %33
dealloc_stack %4 : $*RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>> // id: %28
%29 = struct $_AD__$s4main7GRUCellV14callAsFunctionyAA13RNNCellOutputVyAA6TensorVys5SIMD2VySiGxGGALF_bb0__PB__src_0_wrt_0_s14DifferentiableRzl<τ_0_0> (%24 : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector) -> Tensor<SIMD2<Int>, τ_0_1>.TangentVector for <τ_0_0, τ_0_0>) // user: %31
// function_ref AD__$s4main7GRUCellV14callAsFunctionyAA13RNNCellOutputVyAA6TensorVys5SIMD2VySiGxGGALF__pullback_src_0_wrt_0_s14DifferentiableRzl
%30 = function_ref @AD__$s4main7GRUCellV14callAsFunctionyAA13RNNCellOutputVyAA6TensorVys5SIMD2VySiGxGGALF__pullback_src_0_wrt_0_s14DifferentiableRzl : $@convention(method) <τ_0_0 where τ_0_0 : Differentiable> (RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector, @owned _AD__$s4main7GRUCellV14callAsFunctionyAA13RNNCellOutputVyAA6TensorVys5SIMD2VySiGxGGALF_bb0__PB__src_0_wrt_0_s14DifferentiableRzl<τ_0_0>) -> Tensor<SIMD2<Int>, τ_0_0>.TangentVector // user: %31
%31 = partial_apply [callee_guaranteed] %30<τ_0_0>(%29) : $@convention(method) <τ_0_0 where τ_0_0 : Differentiable> (RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector, @owned _AD__$s4main7GRUCellV14callAsFunctionyAA13RNNCellOutputVyAA6TensorVys5SIMD2VySiGxGGALF_bb0__PB__src_0_wrt_0_s14DifferentiableRzl<τ_0_0>) -> Tensor<SIMD2<Int>, τ_0_0>.TangentVector // user: %32
%32 = convert_function %31 : $@callee_guaranteed (RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector) -> Tensor<SIMD2<Int>, τ_0_0>.TangentVector to $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (τ_0_0) -> τ_0_1 for <RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector, Tensor<SIMD2<Int>, τ_0_0>.TangentVector> // user: %33
%33 = tuple (%27 : $RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>, %32 : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (τ_0_0) -> τ_0_1 for <RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector, Tensor<SIMD2<Int>, τ_0_0>.TangentVector>) // user: %34
return %33 : $(RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>, @callee_guaranteed @substituted <τ_0_0, τ_0_1> (τ_0_0) -> τ_0_1 for <RNNCellOutput<Tensor<SIMD2<Int>, τ_0_0>>.TangentVector, Tensor<SIMD2<Int>, τ_0_0>.TangentVector>) // id: %34
} // end sil function 'AD__$s4main7GRUCellV14callAsFunctionyAA13RNNCellOutputVyAA6TensorVys5SIMD2VySiGxGGALF__vjp_src_0_wrt_0_s14DifferentiableRzl'
$ swiftc tf-507.swift
Assertion failed: (rootWTable && "root witness table not bound in local context!"), function emitArchetypeWitnessTableRef, file /Users/danielzheng/swift-master/swift/lib/IRGen/GenArchetype.cpp, line 250.
Stack dump:
0. Program arguments: /Users/danielzheng/swift-master/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift -frontend -interpret tf-507.swift -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 main
1. Apple Swift version 5.3-dev (LLVM cb105acb24, Swift 97f67393b5)
2. While running user code "tf-507.swift"
3. While evaluating request IRGenWholeModuleRequest(IR Generation for module main)
4. While emitting IR SIL function "@AD__$s4main7GRUCellV14callAsFunctionyAA13RNNCellOutputVyAA6TensorVys5SIMD2VySiGxGGALF__vjp_src_0_wrt_0_4main21DifferentiableElementRzl".
for 'callAsFunction(_:)' (at tf-507.swift:21:3)
0 swift 0x000000011278d418 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 swift 0x000000011278c398 llvm::sys::RunSignalHandlers() + 248
2 swift 0x000000011278da0d SignalHandler(int) + 285
3 libsystem_platform.dylib 0x00007fff6d6115fd _sigtramp + 29
4 libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603338681084448
5 libsystem_c.dylib 0x00007fff6d4e7808 abort + 120
6 libsystem_c.dylib 0x00007fff6d4e6ac6 err + 0
7 swift 0x000000011285bd13 swift::irgen::emitArchetypeWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::ArchetypeType>, swift::ProtocolDecl*) (.cold.6) + 35
8 swift 0x000000010e3a01d4 swift::irgen::emitArchetypeWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::ArchetypeType>, swift::ProtocolDecl*) + 1204
9 swift 0x000000010e4856dd swift::irgen::emitWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanType, llvm::Value**, swift::ProtocolConformanceRef) + 189
10 swift 0x000000010e48894b bool llvm::function_ref<bool (unsigned int, swift::CanType, swift::ProtocolDecl*)>::callback_fn<emitConditionalConformancesBuffer(swift::irgen::IRGenFunction&, swift::ProtocolConformance const*)::$_15>(long, unsigned int, swift::CanType, swift::ProtocolDecl*) + 171
11 swift 0x000000010ecae689 swift::SILWitnessTable::enumerateWitnessTableConditionalConformances(swift::ProtocolConformance const*, llvm::function_ref<bool (unsigned int, swift::CanType, swift::ProtocolDecl*)>) + 233
12 swift 0x000000010e4886b8 emitWitnessTableAccessorCall(swift::irgen::IRGenFunction&, swift::ProtocolConformance const*, llvm::Value**) + 248
13 swift 0x000000010e485754 swift::irgen::emitWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanType, llvm::Value**, swift::ProtocolConformanceRef) + 308
14 swift 0x000000010e4861dd swift::irgen::emitGenericRequirementFromSubstitutions(swift::irgen::IRGenFunction&, swift::CanGenericSignature, swift::ModuleDecl&, swift::irgen::GenericRequirement, swift::SubstitutionMap) + 173
15 swift 0x000000010e48af72 void llvm::function_ref<void (swift::irgen::GenericRequirement)>::callback_fn<(anonymous namespace)::EmitPolymorphicArguments::emit(swift::SubstitutionMap, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&)::$_21>(long, swift::irgen::GenericRequirement) + 34
16 swift 0x000000010e48b063 void llvm::function_ref<void (swift::irgen::GenericRequirement)>::callback_fn<(anonymous namespace)::PolymorphicConvention::enumerateUnfulfilledRequirements(llvm::function_ref<void (swift::irgen::GenericRequirement)> const&)::$_11>(long, swift::irgen::GenericRequirement) + 211
17 swift 0x000000010e47e974 swift::irgen::enumerateGenericSignatureRequirements(swift::CanGenericSignature, llvm::function_ref<void (swift::irgen::GenericRequirement)> const&) + 100
18 swift 0x000000010e4858e1 swift::irgen::emitPolymorphicArguments(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::SILFunctionType>, swift::SubstitutionMap, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&) + 305
19 swift 0x000000010e43bf8e emitPartialApplicationForwarder(swift::irgen::IRGenModule&, llvm::Optional<swift::irgen::FunctionPointer> const&, bool, swift::irgen::Signature const&, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::SubstitutionMap, swift::irgen::HeapLayout const*, llvm::ArrayRef<swift::ParameterConvention>) + 8302
20 swift 0x000000010e439901 swift::irgen::emitFunctionPartialApplication(swift::irgen::IRGenFunction&, swift::SILFunction&, swift::irgen::FunctionPointer const&, llvm::Value*, swift::irgen::Explosion&, llvm::ArrayRef<swift::SILParameterInfo>, swift::SubstitutionMap, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::irgen::Explosion&, bool) + 4977
21 swift 0x000000010e500c3b swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 66651
22 swift 0x000000010e4eccdf swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 7199
23 swift 0x000000010e3ec36b swift::irgen::IRGenerator::emitLazyDefinitions() + 1515
24 swift 0x000000010e4c248b performIRGeneration(swift::IRGenOptions const&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, swift::SourceFile*, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 1643