Open martialln opened 6 months ago
I reproduced the error with:
Xcode Version 15.3 (15E204a) Toolchain: Swift 6.0 Development Snapshot 2024-04-17 (a)
Reduced:
protocol Initable {
init() throws
}
func foo() throws {}
struct S<each Element: Initable> {
var elements: (repeat each Element)
init() throws {
self.elements = (repeat try (each Element).init())
try foo()
}
}
SIL verification failed: tuple_element_addr cannot be used with tuples containing pack expansions: !tupleType.containsPackExpansionType()
Verifying instruction:
%59 = struct_element_addr %3 : $*S<repeat each Element>, #S.elements // user: %60
-> %60 = tuple_element_addr %59 : $*(repeat each Element), 0 // user: %61
destroy_addr %60 : $*repeat each Element // id: %61
In function:
// S.init()
sil hidden [ossa] @$s4test1SVACyxxQp_QPGyKcfC : $@convention(method) <each Element where repeat each Element : Initable> (@thin S<repeat each Element>.Type) -> (@out S<repeat each Element>, @error any Error) {
// %0 "$return_value" // user: %34
// %1 "$metatype"
bb0(%0 : $*S<repeat each Element>, %1 : $@thin S<repeat each Element>.Type):
%2 = alloc_stack $Builtin.Int1 // users: %57, %27, %5, %65, %37
%3 = alloc_stack [dynamic_lifetime] [lexical] [var_decl] $S<repeat each Element>, var, name "self" // users: %34, %24, %59, %64, %35
%4 = integer_literal $Builtin.Int1, 0 // user: %5
store %4 to [trivial] %2 : $*Builtin.Int1 // id: %5
debug_value undef : $any Error, var, name "$error", argno 1 // id: %6
%7 = alloc_stack $(repeat each Element) // users: %30, %28, %52, %49, %17
%8 = integer_literal $Builtin.Word, 0 // user: %11
%9 = integer_literal $Builtin.Word, 1 // user: %22
%10 = pack_length $Pack{repeat each Element} // user: %13
br bb1(%8 : $Builtin.Word) // id: %11
// %12 // users: %22, %42, %15, %13
bb1(%12 : $Builtin.Word): // Preds: bb3 bb0
%13 = builtin "cmp_eq_Word"(%12 : $Builtin.Word, %10 : $Builtin.Word) : $Builtin.Int1 // user: %14
cond_br %13, bb4, bb2 // id: %14
bb2: // Preds: bb1
%15 = dynamic_pack_index %12 of $Pack{repeat each Element} // users: %17, %16
%16 = open_pack_element %15 of <each Element where repeat each Element : Initable> at <Pack{repeat each Element}>, shape $each Element, uuid "F8D979A4-FE61-11EE-851C-ACDE48001122" // users: %20, %19, %18, %17
%17 = tuple_pack_element_addr %15 of %7 : $*(repeat each Element) as $*@pack_element("F8D979A4-FE61-11EE-851C-ACDE48001122") each Element // user: %20
%18 = metatype $@thick (@pack_element("F8D979A4-FE61-11EE-851C-ACDE48001122") each Element).Type // type-defs: %16; user: %20
%19 = witness_method $@pack_element("F8D979A4-FE61-11EE-851C-ACDE48001122") each Element, #Initable.init!allocator : <Self where Self : Initable> (Self.Type) -> () throws -> Self, %16 : $Builtin.SILToken : $@convention(witness_method: Initable) <τ_0_0 where τ_0_0 : Initable> (@thick τ_0_0.Type) -> (@out τ_0_0, @error any Error) // type-defs: %16; user: %20
try_apply %19<(@pack_element("F8D979A4-FE61-11EE-851C-ACDE48001122") each Element)>(%17, %18) : $@convention(witness_method: Initable) <τ_0_0 where τ_0_0 : Initable> (@thick τ_0_0.Type) -> (@out τ_0_0, @error any Error), normal bb3, error bb6 // type-defs: %16; id: %20
bb3(%21 : $()): // Preds: bb2
%22 = builtin "add_Word"(%12 : $Builtin.Word, %9 : $Builtin.Word) : $Builtin.Word // user: %23
br bb1(%22 : $Builtin.Word) // id: %23
bb4: // Preds: bb1
%24 = begin_access [modify] [static] %3 : $*S<repeat each Element> // users: %29, %25
%25 = struct_element_addr %24 : $*S<repeat each Element>, #S.elements // user: %28
%26 = integer_literal $Builtin.Int1, -1 // user: %27
store %26 to [trivial] %2 : $*Builtin.Int1 // id: %27
copy_addr [take] %7 to [init] %25 : $*(repeat each Element) // id: %28
end_access %24 : $*S<repeat each Element> // id: %29
dealloc_stack %7 : $*(repeat each Element) // id: %30
// function_ref foo()
%31 = function_ref @$s4test3fooyyKF : $@convention(thin) () -> @error any Error // user: %32
try_apply %31() : $@convention(thin) () -> @error any Error, normal bb5, error bb10 // id: %32
bb5(%33 : $()): // Preds: bb4
copy_addr [take] %3 to [init] %0 : $*S<repeat each Element> // id: %34
dealloc_stack %3 : $*S<repeat each Element> // id: %35
%36 = tuple () // user: %38
dealloc_stack %2 : $*Builtin.Int1 // id: %37
return %36 : $() // id: %38
// %39 // user: %53
bb6(%39 : @owned $any Error): // Preds: bb2
%40 = integer_literal $Builtin.Word, 0 // user: %44
%41 = integer_literal $Builtin.Word, 1 // user: %46
br bb7(%12 : $Builtin.Word) // id: %42
// %43 // users: %46, %44
bb7(%43 : $Builtin.Word): // Preds: bb8 bb6
%44 = builtin "cmp_eq_Word"(%43 : $Builtin.Word, %40 : $Builtin.Word) : $Builtin.Int1 // user: %45
cond_br %44, bb9, bb8 // id: %45
bb8: // Preds: bb7
%46 = builtin "sub_Word"(%43 : $Builtin.Word, %41 : $Builtin.Word) : $Builtin.Word // users: %51, %47
%47 = dynamic_pack_index %46 of $Pack{repeat each Element} // users: %49, %48
%48 = open_pack_element %47 of <each Element where repeat each Element : Initable> at <Pack{repeat each Element}>, shape $each Element, uuid "F8DD56FA-FE61-11EE-851C-ACDE48001122" // user: %49
%49 = tuple_pack_element_addr %47 of %7 : $*(repeat each Element) as $*@pack_element("F8DD56FA-FE61-11EE-851C-ACDE48001122") each Element // user: %50
destroy_addr %49 : $*@pack_element("F8DD56FA-FE61-11EE-851C-ACDE48001122") each Element // id: %50
br bb7(%46 : $Builtin.Word) // id: %51
bb9: // Preds: bb7
dealloc_stack %7 : $*(repeat each Element) // id: %52
br bb11(%39 : $any Error) // id: %53
// %54 // user: %55
bb10(%54 : @owned $any Error): // Preds: bb4
br bb11(%54 : $any Error) // id: %55
// %56 // user: %66
bb11(%56 : @owned $any Error): // Preds: bb10 bb9
%57 = load [trivial] %2 : $*Builtin.Int1 // user: %58
cond_br %57, bb12, bb13 // id: %58
bb12: // Preds: bb11
%59 = struct_element_addr %3 : $*S<repeat each Element>, #S.elements // user: %60
%60 = tuple_element_addr %59 : $*(repeat each Element), 0 // user: %61
destroy_addr %60 : $*repeat each Element // id: %61
br bb14 // id: %62
bb13: // Preds: bb11
br bb14 // id: %63
bb14: // Preds: bb13 bb12
dealloc_stack %3 : $*S<repeat each Element> // id: %64
dealloc_stack %2 : $*Builtin.Int1 // id: %65
throw %56 : $any Error // id: %66
} // end sil function '$s4test1SVACyxxQp_QPGyKcfC'
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0. Program arguments: bin/swift-frontend -debug-diagnostic-names -diagnostic-style=llvm -emit-sil /Users/mac/Desktop/test.swift
1. Swift version 6.0-dev (LLVM beb75c68bf9e0fb, Swift eb40cc56777bae4)
2. Compiling with effective version 5.10
3. While verifying SIL function "@$s4test1SVACyxxQp_QPGyKcfC".
for 'init()' (at /Users/mac/Desktop/test.swift:241: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 0x000000010faeb5a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 40
1 swift-frontend 0x000000010fae99f5 llvm::sys::RunSignalHandlers() + 85
2 swift-frontend 0x000000010faebbfe SignalHandler(int) + 270
3 libsystem_platform.dylib 0x00007ff8058ea37d _sigtramp + 29
4 swift-frontend 0x0000000107160725 void std::__1::__libcpp_operator_delete[abi:v160006]<void*>(void*) + 21
5 libsystem_c.dylib 0x00007ff8057dba4d abort + 126
6 swift-frontend 0x0000000109633e37 (anonymous namespace)::SILVerifier::_require(bool, llvm::Twine const&, std::__1::function<void ()> const&) + 919
7 swift-frontend 0x000000010966a566 (anonymous namespace)::SILVerifier::checkTupleElementAddrInst(swift::TupleElementAddrInst*) + 358
8 swift-frontend 0x000000010964636e (anonymous namespace)::SILVerifierBase<(anonymous namespace)::SILVerifier>::visitTupleElementAddrInst(swift::TupleElementAddrInst*) + 46
9 swift-frontend 0x000000010963f715 swift::SILInstructionVisitor<(anonymous namespace)::SILVerifier, void>::visit(swift::SILInstruction*) + 2757
10 swift-frontend 0x000000010963e607 swift::SILVisitorBase<(anonymous namespace)::SILVerifier, void>::visitSILBasicBlock(swift::SILBasicBlock*) + 135
11 swift-frontend 0x000000010963e061 (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) + 33
12 swift-frontend 0x0000000109638733 (anonymous namespace)::SILVerifier::visitSILBasicBlocks(swift::SILFunction*) + 211
13 swift-frontend 0x00000001096362a1 (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) + 2561
14 swift-frontend 0x000000010962e3f8 (anonymous namespace)::SILVerifier::verify(bool) + 136
15 swift-frontend 0x000000010962e285 swift::SILFunction::verify(swift::CalleeCache*, bool, bool, bool) const + 181
16 swift-frontend 0x00000001096324e2 swift::SILModule::verify(swift::CalleeCache*, bool, bool) const + 450
17 swift-frontend 0x00000001096322ea swift::SILModule::verify(bool, bool) const + 122
18 swift-frontend 0x0000000107740e21 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 161
19 swift-frontend 0x00000001072a6a78 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*) + 840
20 swift-frontend 0x00000001072a605e swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 382
21 swift-frontend 0x00000001072d77c3 performAction(swift::CompilerInstance&, int&, swift::FrontendObserver*)::$_29::operator()(swift::CompilerInstance&) const + 147
22 swift-frontend 0x00000001072d771d bool llvm::function_ref<bool (swift::CompilerInstance&)>::callback_fn<performAction(swift::CompilerInstance&, int&, swift::FrontendObserver*)::$_29>(long, swift::CompilerInstance&) + 29
23 swift-frontend 0x00000001072d6ae1 llvm::function_ref<bool (swift::CompilerInstance&)>::operator()(swift::CompilerInstance&) const + 33
24 swift-frontend 0x00000001072d5a78 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 392
25 swift-frontend 0x00000001072cdf95 performAction(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1349
26 swift-frontend 0x00000001072a94a6 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 262
27 swift-frontend 0x00000001072a7e8a swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2794
28 swift-frontend 0x000000010715622a run_driver(llvm::StringRef, llvm::ArrayRef<char const*>, llvm::ArrayRef<char const*>) + 2410
29 swift-frontend 0x0000000107154e67 swift::mainEntry(int, char const**) + 1543
30 swift-frontend 0x0000000107154392 main + 34
31 dyld 0x00007ff8055343a6 start + 1942
Abort trap: 6
Update still happening with:
macOS 15.0 (24A335) Version 16.0 (16A242)
Description
I have a type which use parameter pack as generic parameter.
When initializing, I have to call a throwing function after initializing all properties. When doing so the compiler crash.
Not that if I'm calling a non-throwing function, the compilation succeed without error. Also if I use
try?
to ignore the thrown error, the compilation succeed without error.Reproduction
Stack dump
Expected behavior
The compiler doesn't crash and compile correctly
Environment
Xcode Version 15.2 (15C500b) Toolchain: Swift Development Snapshot 2024-04-13 (a)
macOS 14.4.1 (23E224)
Additional information
Also reproduced using the toolchain shipped with Xcode (stack dump is different though) and with toolchain "Swift 6.0 Development Snapshot 2024-04-14 (a)"