Skip to content
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

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

Open
dan-zheng opened this issue Aug 24, 2020 · 0 comments
Open
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself SILGen Area → compiler: The SIL generation stage

Comments

@dan-zheng
Copy link
Collaborator

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
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
asavonic added a commit to asavonic/swift that referenced this issue Feb 19, 2024
The patch fixes the issue apple#55882 and enables the nil coalescing operator
(aka `??`) for Optional type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoDiff bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself SILGen Area → compiler: The SIL generation stage
Projects
None yet
Development

No branches or pull requests

1 participant