Skip to content

Opaque types and variadic/pack iteration crashes the compiler #79281

@dehesa

Description

@dehesa

Description

The simple snippet pasted below crashes the Swift compiler. The key is the return type of the object function; when it is an opaque type, the compiler crashes, when it is an existential, the compiler happily/successfully compiles.

Reproduction

protocol Tangible {
  init?(_ name: String)
}

struct UnknownObject: Swift.Error {}

func object<each T: Tangible>(name: String, domains: repeat (each T).Type) throws -> some Tangible {
  for domain in repeat each domains {
    guard let result = domain.init(name) else { continue }
    return result
  }
  throw UnknownObject()
}

Stack dump

Stack dump:
0.	Program arguments: /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/marcos/Developer/Github/Private/swift-belt/cmd/sources/App.swift -emit-dependencies-path /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/Playground.build/Debug/Playground.build/Objects-normal/arm64/App.d -emit-const-values-path /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/Playground.build/Debug/Playground.build/Objects-normal/arm64/App.swiftconstvalues -emit-reference-dependencies-path /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/Playground.build/Debug/Playground.build/Objects-normal/arm64/App.swiftdeps -serialize-diagnostics-path /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/Playground.build/Debug/Playground.build/Objects-normal/arm64/App.dia -target arm64-apple-macos15.2 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -I /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/PackageFrameworks -F /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug -no-color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=5 -module-cache-path /Users/marcos/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -const-gather-protocols-file /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/Playground.build/Debug/Playground.build/Objects-normal/arm64/Playground_const_extract_protocols.json -enable-experimental-feature DebugDescriptionMacro -enable-experimental-feature OpaqueTypeErasure -enable-upcoming-feature ConciseMagicFile -enable-upcoming-feature ForwardTrailingClosures -enable-upcoming-feature StrictConcurrency -enable-upcoming-feature DeprecateApplicationMain -enable-upcoming-feature ImportObjcForwardDeclarations -enable-upcoming-feature DisableOutwardActorInference -enable-upcoming-feature InternalImportsByDefault -enable-upcoming-feature IsolatedDefaultValues -enable-upcoming-feature GlobalConcurrency -enable-upcoming-feature InferSendableFromCaptures -enable-upcoming-feature ImplicitOpenExistentials -enable-upcoming-feature RegionBasedIsolation -enable-upcoming-feature ExistentialAny -enable-bare-slash-regex -empty-abi-descriptor -validate-clang-modules-once -clang-build-session-file /Users/marcos/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc /Users/marcos/Developer/Github/Private/swift-belt/cmd -resource-dir /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/marcos/Developer/Github/Private/swift-belt/cmd -Xcc -fmodule-map-file=/Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/GeneratedModuleMaps/FoundationObjCUtils.modulemap -Xcc -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG -Xcc -ivfsstatcache -Xcc /Users/marcos/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx15.2-24C94-e9512ba338551096f4c3ebf3c3012957.sdkstatcache -Xcc -I/Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/Playground.build/Debug/Playground.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/Playground.build/Debug/Playground.build/Playground-generated-files.hmap -Xcc -I/Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/Playground.build/Debug/Playground.build/Playground-own-target-headers.hmap -Xcc -I/Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/Playground.build/Debug/Playground.build/Playground-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/Playground.build/Debug/Playground-d96684824369c6d3eb73265da35f1dd1-VFS/all-product-headers.yaml -Xcc -iquote -Xcc /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/Playground.build/Debug/Playground.build/Playground-project-headers.hmap -Xcc -I/Users/marcos/Developer/Github/Private/swift-belt/foundation-utils/sources/objc/include -Xcc -I/Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/SourcePackages/checkouts/swift-numerics/Sources/_NumericsShims/include -Xcc -I/Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Products/Debug/include -Xcc -I/Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/Playground.build/Debug/Playground.build/DerivedSources-normal/arm64 -Xcc -I/Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/Playground.build/Debug/Playground.build/DerivedSources/arm64 -Xcc -I/Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/Playground.build/Debug/Playground.build/DerivedSources -Xcc -DDEBUG=1 -module-name Playground -frontend-parseable-output -disable-clang-spi -target-sdk-version 15.2 -target-sdk-name macosx15.2 -external-plugin-path /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -parse-as-library -o /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Build/Intermediates.noindex/Playground.build/Debug/Playground.build/Objects-normal/arm64/App.o -index-unit-output-path /Playground.build/Debug/Playground.build/Objects-normal/arm64/App.o -index-store-path /Users/marcos/Library/Developer/Xcode/DerivedData/Swift-cjsehycdxjrugnaogsxofvkblzer/Index.noindex/DataStore -index-system-modules
1.	Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
2.	Compiling with effective version 5.10
3.	While evaluating request IRGenRequest(IR Generation for file "/Users/marcos/Developer/Github/Private/swift-belt/cmd/sources/App.swift")
4.	While emitting IR for source file /Users/marcos/Developer/Github/Private/swift-belt/cmd/sources/App.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           0x00000001084aaa9c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001084a8cf0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001084ab068 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x000000018d15ede4 _sigtramp + 56
4  swift-frontend           0x000000010346acf4 swift::irgen::IRGenMangler::withSymbolicReferences(swift::irgen::IRGenModule&, llvm::function_ref<void ()>) + 396
5  swift-frontend           0x000000010346acf4 swift::irgen::IRGenMangler::withSymbolicReferences(swift::irgen::IRGenModule&, llvm::function_ref<void ()>) + 396
6  swift-frontend           0x000000010346af68 swift::irgen::IRGenMangler::mangleTypeForReflection(swift::irgen::IRGenModule&, swift::CanGenericSignature, swift::CanType) + 264
7  swift-frontend           0x00000001033e7d44 getTypeRefImpl(swift::irgen::IRGenModule&, swift::CanType, swift::CanGenericSignature, swift::irgen::MangledTypeRefRole) + 700
8  swift-frontend           0x000000010339cf64 swift::irgen::IRGenModule::emitOpaqueTypeDecl(swift::OpaqueTypeDecl*) + 4452
9  swift-frontend           0x00000001032d1314 swift::irgen::IRGenModule::emitSourceFile(swift::SourceFile&) + 524
10 swift-frontend           0x0000000103445654 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 4872
11 swift-frontend           0x000000010348dba8 swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 176
12 swift-frontend           0x000000010344e394 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
13 swift-frontend           0x0000000103447e90 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
14 swift-frontend           0x0000000102e574bc 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
15 swift-frontend           0x0000000102e52ce4 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
16 swift-frontend           0x0000000102e51bd0 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 984
17 swift-frontend           0x0000000102e54e88 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1684
18 swift-frontend           0x0000000102e53bb4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3572
19 swift-frontend           0x0000000102ddaa5c swift::mainEntry(int, char const**) + 3680
20 dyld                     0x000000018cda8274 start + 2840
Command SwiftCompile failed with a nonzero exit code

Expected behavior

Be able to use opaque types as return type instead of existentials.

Environment

swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0

Additional information

No response

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwareparameter packsFeature → generics: Parameter packs

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions