Skip to content

silgen_name does not work with opaque types #78736

@benpious

Description

@benpious

Description

When trying to use this to indicate that the implementation of a function will be provided later. This works for a simple function declaration like f(), but an opaque type causes the compiler to segfault.

My hope, based on a reading of the language reference, is that this happens because inside the current translation unit the compiler is still expecting to know the type, and that if that code path just wasn't taken in the silgen_name case then this would work fine. But I'm probably wrong about that.

It would be cool if this worked though, code could declare that a type implemented a protocol in one module, and write out a much more complex implementation that depended on types that weren't available at that level of the module hierarchy in a higher level module (to be fair, it kind of looks like this already works for protocols that don't use this feature, but for one of my specific use cases I need opaque types too).

Reproduction

public protocol Q {
    
}

public class C {
    
    @_silgen_name("ff")
    public func f() -> some Q
    
    public init() {
        
    }
    
}

The above in any Swift target should be enough to get a crash.

1.	Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
2.	Compiling with the current language version
3.	While evaluating request IRGenRequest(IR Generation for file "/Users/benjaminpious/Documents/ExternImpls/Sources/ExternImpls/ExternImpls.swift")
4.	While emitting IR for source file /Users/benjaminpious/Documents/ExternImpls/Sources/ExternImpls/ExternImpls.swift
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x0000000105f42a9c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000105f40cf0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000105f43068 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x000000018a502e04 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000018a4cbf70 pthread_kill + 288
5  libsystem_c.dylib        0x000000018a3d8908 abort + 128
6  swift-frontend           0x0000000100875960 swift::Diagnostic::operator=(swift::Diagnostic const&) + 0
7  swift-frontend           0x0000000100e354e0 swift::irgen::methodRequiresReifiedVTableEntry(swift::irgen::IRGenModule&, swift::SILVTable const*, swift::SILDeclRef) + 0
8  swift-frontend           0x0000000100d69314 swift::irgen::IRGenModule::emitSourceFile(swift::SourceFile&) + 524
9  swift-frontend           0x0000000100edd654 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 4872
10 swift-frontend           0x0000000100f25ba8 swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 176
11 swift-frontend           0x0000000100ee6394 swift::IRGenRequest::OutputType swift::Evaluator::getResultUncached<swift::IRGenRequest, swift::IRGenRequest::OutputType swift::evaluateOrFatal<swift::IRGenRequest>(swift::Evaluator&, swift::IRGenRequest)::'lambda'()>(swift::IRGenRequest const&, swift::IRGenRequest::OutputType swift::evaluateOrFatal<swift::IRGenRequest>(swift::Evaluator&, swift::IRGenRequest)::'lambda'()) + 784
12 swift-frontend           0x0000000100edfe90 swift::performIRGeneration(swift::FileUnit*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**) + 180
13 swift-frontend           0x00000001008ef4bc generateIR(swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, llvm::GlobalVariable*&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>) + 156
14 swift-frontend           0x00000001008eace4 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 2176
15 swift-frontend           0x00000001008e9bd0 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 984
16 swift-frontend           0x00000001008ece88 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1684
17 swift-frontend           0x00000001008ebbb4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3572
18 swift-frontend           0x0000000100872a5c swift::mainEntry(int, char const**) + 3680
19 dyld                     0x000000018a14c274 start + 2840

Expected behavior

This does not crash, or has an error message that explains what went wrong.

Environment

Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @_silgen_nameFeature → attributes: The @_silgen_name attributeIRGenLLVM IR generationattributesFeature: Declaration and type attributesbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareopaque result typesFeature → types → opaque types: opaque result typesopaque typesFeature → types: opaque typesswift 6.0typesFeature: typeswithdrawnResolution: the issue was withdrawn by the author due to not being relevant

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions