|
| 1 | +// RUN: %target-swift-frontend -enable-resilience -emit-sil -verify %s |
| 2 | +// REQUIRES: asserts |
| 3 | + |
| 4 | +// SR-12641: SILGen verification error regarding `ImmutableAddressUseVerifier` and AutoDiff-generated code. |
| 5 | + |
| 6 | +import _Differentiation |
| 7 | + |
| 8 | +public struct Resilient: Differentiable { |
| 9 | + var x: Float |
| 10 | +} |
| 11 | + |
| 12 | +public class Class: Differentiable { |
| 13 | + var x: Resilient |
| 14 | + init(_ x: Resilient) { |
| 15 | + self.x = x |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +public func f(_ c: Class) -> Resilient { |
| 20 | + return Resilient(x: 0) |
| 21 | +} |
| 22 | + |
| 23 | +_ = pullback(at: Class(Resilient(x: 10)), in: f) |
| 24 | + |
| 25 | +// swift/lib/SIL/Verifier/SILVerifier.cpp:456: bool (anonymous namespace)::ImmutableAddressUseVerifier::isConsumingOrMutatingArgumentConvention(swift::SILArgumentConvention): Assertion `conv.isIndirectConvention() && "Expect an indirect convention"' failed. |
| 26 | +// Stack dump: |
| 27 | +// ... |
| 28 | +// 1. Swift version 5.3-dev (LLVM be43a34c3c, Swift 6d5b2f5220) |
| 29 | +// 2. While evaluating request SILGenWholeModuleRequest(SIL Generation for module main) |
| 30 | +// 3. While verifying SIL function "@$s4main5ClassC13TangentVectorVAA9ResilientVADVIeggr_AeHIegnr_TR". |
| 31 | +// ... |
| 32 | +// #8 0x00000000011e7a3e (anonymous namespace)::ImmutableAddressUseVerifier::isConsumingOrMutatingApplyUse(swift::Operand*) |
| 33 | +// #9 0x00000000011e6add (anonymous namespace)::ImmutableAddressUseVerifier::isMutatingOrConsuming(swift::SILValue) |
| 34 | +// #10 0x00000000011ce0b4 (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) |
| 35 | + |
| 36 | +// Related crasher discovered while fixing SR-12641. |
| 37 | + |
| 38 | +class LoadableOriginal<T: Differentiable>: Differentiable { |
| 39 | + var x: T |
| 40 | + init(_ x: T) { self.x = x } |
| 41 | +} |
| 42 | + |
| 43 | +@differentiable |
| 44 | +func loadableOriginal<T: AdditiveArithmetic>(_ loadable: LoadableOriginal<T>) -> T { |
| 45 | + return T.zero |
| 46 | +} |
| 47 | + |
| 48 | +// swift/include/swift/SIL/TypeLowering.h:845: swift::SILType swift::Lowering::TypeConverter::getLoweredLoadableType(swift::Type, swift::TypeExpansionContext, swift::SILModule &): Assertion `(ti.isLoadable() || !SILModuleConventions(M).useLoweredAddresses()) && "unexpected address-only type"' failed. |
| 49 | +// Stack dump: |
| 50 | +// ... |
| 51 | +// 2. While evaluating request ExecuteSILPipelineRequest(Run pipelines { Guaranteed Passes } on SIL for main.main) |
| 52 | +// 3. While running pass #153 SILModuleTransform "Differentiation". |
| 53 | +// 4. While processing // differentiability witness for loadableOriginal<A>(_:) |
| 54 | +// sil_differentiability_witness hidden [parameters 0] [results 0] <T where T : AdditiveArithmetic, T : Differentiable> @$s4main16loadableOriginalyxAA08LoadableC0CyxGs18AdditiveArithmeticRz16_Differentiation14DifferentiableRzlF : $@convention(thin) <T where T : Additive |
| 55 | +// Arithmetic, T : Differentiable> (@guaranteed LoadableOriginal<T>) -> @out T { |
| 56 | +// } |
| 57 | +// |
| 58 | +// on SIL function "@$s4main16loadableOriginalyxAA08LoadableC0CyxGs18AdditiveArithmeticRz16_Differentiation14DifferentiableRzlF". |
| 59 | +// for 'loadableOriginal(_:)' |
| 60 | +// 5. While generating VJP for SIL function "@$s4main16loadableOriginalyxAA08LoadableC0CyxGs18AdditiveArithmeticRz16_Differentiation14DifferentiableRzlF". |
| 61 | +// for 'loadableOriginal(_:)' |
| 62 | +// 6. While generating pullback for SIL function "@$s4main16loadableOriginalyxAA08LoadableC0CyxGs18AdditiveArithmeticRz16_Differentiation14DifferentiableRzlF". |
| 63 | +// for 'loadableOriginal(_:)' |
| 64 | +// ... |
| 65 | +// #9 0x0000000000f83fbb swift::autodiff::PullbackEmitter::emitZeroDirect(swift::CanType, swift::SILLocation) |
| 66 | +// #10 0x0000000000f8248b swift::autodiff::PullbackEmitter::emitZeroDerivativesForNonvariedResult(swift::SILValue) |
| 67 | +// #11 0x0000000000f7fcae swift::autodiff::PullbackEmitter::run() |
| 68 | +// #12 0x0000000000f3fba4 swift::autodiff::VJPEmitter::run() |
| 69 | +// #13 0x0000000000eb1669 (anonymous namespace)::DifferentiationTransformer::canonicalizeDifferentiabilityWitness(swift::SILFunction*, swift::SILDifferentiabilityWitness*, swift::autodiff::DifferentiationInvoker, swift::IsSerialized_t) |
| 70 | +// #14 0x0000000000eaea5e (anonymous namespace)::Differentiation::run() |
0 commit comments