Skip to content

[SR-13440] SILGen crash for ?? nil coalescing derivative registration #55882

Closed
@dan-zheng

Description

@dan-zheng
Previous ID SR-13440
Radar None
Original Reporter @dan-zheng
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, AutoDiff, SILGen
Assignee None
Priority Medium

md5: 45e845b27c2d77c6964860dd086d124d

Issue Description:

import _Differentiation

@derivative(of: ??)
@usableFromInline
func _vjpNilCoalescing<T: Differentiable>(optional: T?, defaultValue: @autoclosure () throws -> T)
 rethrows -> (value: T, pullback: (T.TangentVector) -> Optional<T>.TangentVector)
{
 let hasValue = optional != nil
 let value = try optional ?? defaultValue()
 func pullback(_ v: T.TangentVector) -> Optional<T>.TangentVector {
   return hasValue ? .init(v) : .zero
 }
 return (value, pullback)
}
$ swift nil.swift
Assertion failed: (sig || !type.getASTType()->hasTypeParameter()), function getTypeLowering, file lib/SIL/IR/TypeLowering.cpp, line 2084.
Stack dump:
0.  Program arguments: build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift-frontend -frontend -interpret nil.swift -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -color-diagnostics -target-sdk-version 10.16 -module-name nil
1.  Swift version 5.3-dev (LLVM b6306aaf821d359, Swift 4e5ae00c2a933bc)
2.  While evaluating request ASTLoweringRequest(Lowering AST to SIL for module nil)
3.  While silgen emitFunction SIL function "@$s3nil17_vjpNilCoalescing8optional12defaultValuex5value_Sq16_DifferentiationAF14DifferentiableRzlE13TangentVectorVyx_GAHQzc8pullbacktxSg_xyKXKtKAfGRzlF".
 for '_vjpNilCoalescing(optional:defaultValue:)' (at nil.swift:5:1)
0  swift-frontend           0x0000000114330e05 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift-frontend           0x000000011432fdd8 llvm::sys::RunSignalHandlers() + 248
2  swift-frontend           0x00000001143313e6 SignalHandler(int) + 262
3  libsystem_platform.dylib 0x00007fff6af545fd _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603338721704480
5  libsystem_c.dylib        0x00007fff6ae2a808 abort + 120
6  libsystem_c.dylib        0x00007fff6ae29ac6 err + 0
7  swift-frontend           0x00000001146a8423 swift::Lowering::TypeConverter::getTypeLowering(swift::SILType, swift::TypeExpansionContext, swift::CanGenericSignature) (.cold.3) + 35
8  swift-frontend           0x00000001108ed762 swift::Lowering::TypeConverter::getTypeLowering(swift::SILType, swift::TypeExpansionContext, swift::CanGenericSignature) + 242
9  swift-frontend           0x000000011085e597 swift::SILFunction::getTypeLowering(swift::SILType) const + 71
10 swift-frontend           0x0000000110229a6a swift::Lowering::SILGenFunction::emitManagedRValueWithCleanup(swift::SILValue) + 26
11 swift-frontend           0x000000011028b46f swift::Lowering::SILGenModule::getOrCreateCustomDerivativeThunk(swift::SILFunction*, swift::SILFunction*, swift::AutoDiffConfig const&, swift::AutoDiffDerivativeFunctionKind) + 3775
12 swift-frontend           0x00000001101c55b8 swift::Lowering::SILGenModule::emitDifferentiabilityWitness(swift::AbstractFunctionDecl*, swift::SILFunction*, swift::AutoDiffConfig const&, swift::SILFunction*, swift::SILFunction*, swift::DeclAttribute const*) + 552

Metadata

Metadata

Assignees

No one assigned

    Labels

    AutoDiffSILGenArea → compiler: The SIL generation stagebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareexpressionsFeature: expressionsgenericsFeature: generic declarations and typesnil-coalescing operatorFeature → operators: The nil-coalescing operator `??`operatorsFeature: operatorsswift 6.0

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions