Open slice opened 4 months ago
Target: x86_64-apple-macosx14.0
I installed a trunk toolchain (with symbols) in an effort to build with the latest version of the compiler, but it's going through Rosetta (?) for some reason; I am on an Mac with Apple silicon.
The code still intermittently crashes (or suceeds) on the latest stable Xcode at the time of writing, but with (yet) another different stack dump. Luckily, there only seems to be one failure path here:
swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5) Target: arm64-apple-macosx14.0 Stack dump: run_swift592.txt
Again, it could be an unrelated or since-solved issue, but I figured I'd note it anyways.
No apparent non-determinism to the crash with a 8bb684628593220 compiler (although this still smells like a memory issue). Reduced example:
struct S<each A> {
let metatypes: (repeat (each A).Type)
init() {
self.metatypes = (repeat (each A).self)
}
}
let _ = S<Int, Bool>().metatypes
Stack dump:
0. Program arguments: bin/swift-frontend -debug-diagnostic-names -interpret /Users/mac/Desktop/test.swift
1. Swift version 5.11-dev (LLVM 87ace14daa2139a, Swift 8bb684628593220)
2. Compiling with the current language version
3. While evaluating request ASTLoweringRequest(Lowering AST to SIL for module test)
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 0x000000011586fad8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 40
1 swift-frontend 0x000000011586df25 llvm::sys::RunSignalHandlers() + 85
2 swift-frontend 0x000000011587012e SignalHandler(int) + 270
3 libsystem_platform.dylib 0x00007ff81bbae37d _sigtramp + 29
4 libsystem_platform.dylib 0x0000000000000001 _sigtramp + 18446603370115701921
5 swift-frontend 0x000000010ce50f4a swift::CanType::isActuallyCanonicalOrNull() const + 138
6 swift-frontend 0x000000010ce50e60 swift::CanType::CanType(swift::Type) + 32
7 swift-frontend 0x000000010ce50e2d swift::CanType::CanType(swift::Type) + 29
8 swift-frontend 0x000000010d5b81e4 swift::CanTypeWrapper<swift::TupleType>::getElementType(unsigned int) const + 52
9 swift-frontend 0x000000010ef58d86 getCanTupleElementType(swift::CanType, unsigned int) + 70
10 swift-frontend 0x000000010ef58af9 swift::Lowering::AbstractionPattern::getTupleElementType(unsigned int) const + 553
11 swift-frontend 0x000000010df4ada3 (anonymous namespace)::Transform::transform(swift::Lowering::RValue&&, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 1875
12 swift-frontend 0x000000010df47947 swift::Lowering::SILGenFunction::emitTransformedValue(swift::SILLocation, swift::Lowering::RValue&&, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 391
13 swift-frontend 0x000000010df4778e swift::Lowering::SILGenFunction::emitOrigToSubstValue(swift::SILLocation, swift::Lowering::RValue&&, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 366
14 swift-frontend 0x000000010df475e8 swift::Lowering::SILGenFunction::emitOrigToSubstValue(swift::SILLocation, swift::Lowering::RValue&&, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::SGFContext) + 296
15 swift-frontend 0x000000010dee192a (anonymous namespace)::OrigToSubstComponent::translate(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::RValue&&, swift::Lowering::SGFContext) && + 266
16 swift-frontend 0x000000010dec4a43 swift::Lowering::TranslationPathComponent::get(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::SGFContext) && + 227
17 swift-frontend 0x000000010decd55d swift::Lowering::SILGenFunction::emitLoadOfLValue(swift::SILLocation, swift::Lowering::LValue&&, swift::Lowering::SGFContext, bool) + 1757
18 swift-frontend 0x000000010de643e0 (anonymous namespace)::RValueEmitter::visitMemberRefExpr(swift::MemberRefExpr*, swift::Lowering::SGFContext) + 496
19 swift-frontend 0x000000010de53a90 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 976
20 swift-frontend 0x000000010de44271 swift::Lowering::SILGenFunction::emitRValue(swift::Expr*, swift::Lowering::SGFContext) + 209
21 swift-frontend 0x000000010de44075 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, std::__1::optional<swift::SILLocation>) + 357
22 swift-frontend 0x000000010de0f51f swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int, bool)::$_0::operator()(swift::Expr*, swift::VarDecl*, bool, std::__1::unique_ptr<swift::Lowering::Initialization, std::__1::default_delete<swift::Lowering::Initialization>>&) const + 671
23 swift-frontend 0x000000010de0ef09 swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int, bool) + 1481
24 swift-frontend 0x000000010de0f5f6 swift::Lowering::SILGenFunction::visitPatternBindingDecl(swift::PatternBindingDecl*, bool) + 150
25 swift-frontend 0x000000010de244e2 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Decl*) + 1522
26 swift-frontend 0x000000010dfba9ea swift::Lowering::SILGenTopLevel::visitTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 714
27 swift-frontend 0x000000010dfba1ef swift::ASTVisitor<swift::Lowering::SILGenTopLevel, void, void, void, void, void, void>::visit(swift::Decl*) + 1391
28 swift-frontend 0x000000010dfb798d swift::Lowering::SILGenTopLevel::visitSourceFile(swift::SourceFile*) + 189
29 swift-frontend 0x000000010dfb6d68 swift::Lowering::SILGenModule::emitEntryPoint(swift::SourceFile*, swift::SILFunction*) + 1800
30 swift-frontend 0x000000010dfb999c swift::Lowering::SILGenModule::emitEntryPoint(swift::SourceFile*) + 316
31 swift-frontend 0x000000010dd394ab (anonymous namespace)::SILGenModuleRAII::emitSourceFile(swift::SourceFile*) + 91
32 swift-frontend 0x000000010dd3911e swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 910
33 swift-frontend 0x000000010df96bae std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::callDerived<0ul>(swift::Evaluator&, std::__1::integer_sequence<unsigned long, 0ul>) const + 142
34 swift-frontend 0x000000010df96ac8 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 40
35 swift-frontend 0x000000010dd56d0a llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 330
36 swift-frontend 0x000000010dd39d88 llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::operator()<swift::ASTLoweringRequest, (void*)0>(swift::ASTLoweringRequest const&) + 40
37 swift-frontend 0x000000010dd39c80 swift::performASTLowering(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions const&, swift::IRGenOptions const*) + 256
38 swift-frontend 0x000000010cfa040b swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 283
39 swift-frontend 0x000000010cfd1863 performAction(swift::CompilerInstance&, int&, swift::FrontendObserver*)::$_28::operator()(swift::CompilerInstance&) const + 147
40 swift-frontend 0x000000010cfd17bd bool llvm::function_ref<bool (swift::CompilerInstance&)>::callback_fn<performAction(swift::CompilerInstance&, int&, swift::FrontendObserver*)::$_28>(long, swift::CompilerInstance&) + 29
41 swift-frontend 0x000000010cfd0c81 llvm::function_ref<bool (swift::CompilerInstance&)>::operator()(swift::CompilerInstance&) const + 33
42 swift-frontend 0x000000010cfcfba8 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 392
43 swift-frontend 0x000000010cfc8286 performAction(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1222
44 swift-frontend 0x000000010cfa38a6 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 262
45 swift-frontend 0x000000010cfa228f swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2783
46 swift-frontend 0x000000010ce4f9ff run_driver(llvm::StringRef, llvm::ArrayRef<char const*>, llvm::ArrayRef<char const*>) + 2431
47 swift-frontend 0x000000010ce4e627 swift::mainEntry(int, char const**) + 1543
48 swift-frontend 0x000000010ce4dbd2 main + 34
49 dyld 0x00007ff81b7f83a6 start + 1942
Segmentation fault: 11
Revisiting this with the Swift 5.10 toolchain shipping in Xcode 15.3 (15E204a), the compiler crashes seem to be non-determinate on my end with the original reproduction code:
swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0
However, your minimized example crashes in a deterministic fashion.
Thanks for looking into this.
Description
Performing a pack expansion on a type parameter pack present within a closure's parameters in order to materialize a tuple of its metatypes sometimes crashes the compiler. Compilation can succeed and print
(DiscordLib2CrashingSometimes.T, DiscordLib2CrashingSometimes.T)
, or crash and result in two distinct backtraces. (There can potentially be more, but I have personally only observed two.)Also, I should note that I have no idea whether this code is actually "supposed" to compile or not—I ran into the crash while experimentally designing an API that uses parameter packs. Assuming that it'd be necessary to conditionalize code at runtime depending on the types in the pack, I instinctually reached for metatypes. I think what I'm aiming to achieve likely won't require this, though, but I haven't sorted all of the details just yet.
Reproduction
Stack dump
Expected behavior
I expect the code to print
(DiscordLib2CrashingSometimes.T, DiscordLib2CrashingSometimes.T)
all the time.Environment
Apple Swift version 5.11-dev (LLVM 1bcf1d71b715d0d, Swift 009a93a0f83dd5c) Target: x86_64-apple-macosx14.0
Additional information
The stack dump provided is only one of the observed stack traces. Here is the other one: run_other.txt
Also, I noticed that by removing the second parameter in the code like this:
You get a different (albeit consistent, phew) compilation error. This might be a separate issue, but I figured I'd note it.