Skip to content

Compiler crash around generic result builder functions and constrained opaque types #61250

@stephencelis

Description

@stephencelis

Describe the bug

We hit a compiler crash when combining generic result builders and constrained opaque types.

Steps To Reproduce

Try to compile the following:

protocol P<A> {
  associatedtype A
}

struct S<A>: P {
}

@resultBuilder enum B<A> {
  static func buildExpression<C: P<A>>(_ c: C) -> C {
    c
  }
  static func buildBlock<C: P<A>>(_ c: C) -> C {
    c
  }
}

extension P {
  @B<A>
  func f() -> some P<A> {
    S<A>()
  }
}

And you'll get the following:

1.	Apple Swift version 5.7.1 (swiftlang-5.7.1.131.4 clang-1400.0.29.51)
2.	Compiling with the current language version
3.	While evaluating request IRGenRequest(IR Generation for file "test.swift")
4.	While emitting IR SIL function "@$s18Test1PPAAE1fQryF".
 for 'f()' (at test.swift:19:3)
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           0x0000000104e47780 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000104e46784 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000104e47e04 SignalHandler(int) + 344
3  libsystem_platform.dylib 0x000000019523f4a4 _sigtramp + 56
4  swift-frontend           0x00000001008ae11c swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 65060
5  swift-frontend           0x00000001008ae11c swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 65060
6  swift-frontend           0x000000010089936c swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 7860
7  swift-frontend           0x0000000100765a00 swift::irgen::IRGenerator::emitGlobalTopLevel(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) + 1552
8  swift-frontend           0x00000001008671d4 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 2556
9  swift-frontend           0x00000001008971ec swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 188
10 swift-frontend           0x00000001008736c8 llvm::Expected<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) + 744
11 swift-frontend           0x000000010086a5bc 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**) + 236
12 swift-frontend           0x0000000100494e68 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*) + 2160
13 swift-frontend           0x0000000100496bf4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 5932
14 swift-frontend           0x00000001004376e8 swift::mainEntry(int, char const**) + 3940
15 dyld                     0x00000001077b108c start + 520

Expected behavior

I expect it to compile (or provide better errors if something is wrong).

Environment (please fill out the following information)

  • Xcode Version/Tag/Branch: both 14.0.1 RC and 14.1 beta 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of software

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions