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-3021] IRGen crash: should not be asking for metadata of a lowered SIL function type #45611

Closed
rxwei opened this issue Oct 22, 2016 · 5 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software IRGen LLVM IR generation SILGen Area → compiler: The SIL generation stage

Comments

@rxwei
Copy link
Member

rxwei commented Oct 22, 2016

Previous ID SR-3021
Radar rdar://problem/28962465
Original Reporter @rxwei
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Fedora 24 & macOS

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, IRGen, SILGen
Assignee @rxwei
Priority Medium

md5: d2c43862690a34c95ec8f68d07a17d71

Issue Description:

Fresh master build from 10/21/2016.

Test case:

extension Optional {
    func apply<U>(_ transform: ((Wrapped) -> U)?) -> U? {
        return try! transform.flatMap(map)
    }
}

func f(_ x: Int) -> Int {
    return x + 1
}

let x: Int? = 10

_ = x.apply(f)
should not be asking for metadata of a lowered SIL function type--SILGen should have used the AST type
UNREACHABLE executed at /home/rxwei/rpmbuild/BUILD/swift/lib/IRGen/GenMeta.cpp:994!
#&#8203;0 0x00000000034b4a85 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/local/swift/usr/bin/swift+0x34b4a85)
#&#8203;1 0x00000000034b5166 SignalHandler(int) (/usr/local/swift/usr/bin/swift+0x34b5166)
#&#8203;2 0x00007f70bbcefc30 __restore_rt (/lib64/libpthread.so.0+0x10c30)
#&#8203;3 0x00007f70ba41f6f5 __GI_raise (/lib64/libc.so.6+0x346f5)
#&#8203;4 0x00007f70ba4212fa __GI_abort (/lib64/libc.so.6+0x362fa)
#&#8203;5 0x000000000345a1d7 (/usr/local/swift/usr/bin/swift+0x345a1d7)
#&#8203;6 0x00000000008d0f85 llvm::Value* swift::CanTypeVisitor<(anonymous namespace)::EmitTypeMetadataRef, llvm::Value*>::visit<>(swift::CanType) (/usr/local/swift/usr/bin/swift+0x8d0f85)
#&#8203;7 0x00000000008bc0a3 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) (/usr/local/swift/usr/bin/swift+0x8bc0a3)
#&#8203;8 0x00000000008d1c64 void llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>::callback_fn<(anonymous namespace)::GenericArguments::collect(swift::irgen::IRGenFunction&, swift::CanType)::{lambda(unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)#1}>(long, unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>) (/usr/local/swift/usr/bin/swift+0x8d1c64)
#&#8203;9 0x00000000008f2539 swift::irgen::GenericTypeRequirements::enumerateFulfillments(swift::irgen::IRGenModule&, llvm::ArrayRef<swift::Substitution>, llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>) (/usr/local/swift/usr/bin/swift+0x8f2539)
#&#8203;10 0x00000000008d17e6 emitNominalMetadataRef(swift::irgen::IRGenFunction&, swift::NominalTypeDecl*, swift::CanType) (/usr/local/swift/usr/bin/swift+0x8d17e6)
#&#8203;11 0x00000000008cf97c llvm::Value* swift::CanTypeVisitor<(anonymous namespace)::EmitTypeMetadataRef, llvm::Value*>::visit<>(swift::CanType) (/usr/local/swift/usr/bin/swift+0x8cf97c)
#&#8203;12 0x00000000008bc0a3 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) (/usr/local/swift/usr/bin/swift+0x8bc0a3)
#&#8203;13 0x00000000008f19dd swift::irgen::emitPolymorphicArguments(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::ArrayRef<swift::Substitution>, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&) (/usr/local/swift/usr/bin/swift+0x8f19dd)
#&#8203;14 0x00000000009468fb (anonymous namespace)::IRGenSILFunction::visitFullApplySite(swift::FullApplySite) (/usr/local/swift/usr/bin/swift+0x9468fb)
#&#8203;15 0x000000000092fe6e (anonymous namespace)::IRGenSILFunction::emitSILFunction() (/usr/local/swift/usr/bin/swift+0x92fe6e)
#&#8203;16 0x000000000092d712 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) (/usr/local/swift/usr/bin/swift+0x92d712)
#&#8203;17 0x0000000000874af5 swift::irgen::IRGenerator::emitGlobalTopLevel() (/usr/local/swift/usr/bin/swift+0x874af5)
#&#8203;18 0x000000000084ab52 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) (/usr/local/swift/usr/bin/swift+0x84ab52)
#&#8203;19 0x000000000084b119 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, unsigned int) (/usr/local/swift/usr/bin/swift+0x84b119)
#&#8203;20 0x000000000084036e performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) (/usr/local/swift/usr/bin/swift+0x84036e)
#&#8203;21 0x000000000083b81b swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/usr/local/swift/usr/bin/swift+0x83b81b)
#&#8203;22 0x00000000007fec67 main (/usr/local/swift/usr/bin/swift+0x7fec67)
#&#8203;23 0x00007f70ba40b731 __libc_start_main (/lib64/libc.so.6+0x20731)
#&#8203;24 0x00000000007fbf29 _start (/usr/local/swift/usr/bin/swift+0x7fbf29)
Stack dump:
0.  Program arguments: /usr/local/swift/usr/bin/swift -frontend -c -primary-file main.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -module-name main -o /tmp/main-8affac.o 
1.  While emitting IR SIL function @_TFE4mainSq5applyurfGSqFxqd___GSqqd___ for 'apply' at main.swift:2:5
@belkadan
Copy link
Contributor

Seeing a handful of these assertions. @jckarter, any insights?

@jckarter
Copy link
Member

Might be fallout from @rjmccall's change to lower Optional parameter types. If we aren't holding on to the formal function type Optional<(T...) -> U>, we wouldn't be able to form the metadata for an unspecialized generic Optional operation like this.

@rjmccall
Copy link
Member

Maybe. It looks to me like we're emitting the generic arguments to a function, though, implying that there's a substitution using a SILFunctionType as the argument. Maybe there's something in SILGen that's harvesting substitutions from the SILType of the base instead of taking them from the ConcreteDeclRef.

@jckarter
Copy link
Member

Trying a fix: #5492

@jckarter
Copy link
Member

Should be fixed in master now.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software IRGen LLVM IR generation SILGen Area → compiler: The SIL generation stage
Projects
None yet
Development

No branches or pull requests

5 participants