swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.58k stars 10.36k forks source link

Compiler crash when calling throwing function after initializing type with parameters pack #73044

Open martialln opened 6 months ago

martialln commented 6 months ago

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

protocol Initializer {
    func foo() -> Bool
    func bar() throws -> Bool
}
protocol Initializable {
    init(with initializer: inout Initializer) throws
}
struct Box<each Element: Initializable>: Initializable {
    let elements: (repeat each Element)

    init(with initializer: inout Initializer) throws {
        self.elements = (repeat try (each Element).init(with: &initializer))

        //_ = initializer.foo() // Compile successfully
        _ = try initializer.bar() // Compiler crash!
        //_ = try? initializer.bar() // Compile successfully
    }
}

Stack dump

SIL verification failed: tuple_element_addr cannot be used with tuples containing pack expansions: !tupleType.containsPackExpansionType()
Verifying instruction:
     %82 = struct_element_addr %4 : $*Box<repeat each Element>, #Box.elements // user: %83
->   %83 = tuple_element_addr %82 : $*(repeat each Element), 0 // user: %84
     destroy_addr %83 : $*repeat each Element     // id: %84
In function:
// Box.init(with:)
sil [ossa] @$s7vgtests3BoxV4withACyxxQp_QPGAA11Initializer_pz_tKcfC : $@convention(method) <each Element where repeat each Element : Initializable> (@inout any Initializer, @thin Box<repeat each Element>.Type) -> (@out Box<repeat each Element>, @error any Error) {
// %0 "$return_value"                             // user: %54
// %1 "initializer"                               // users: %44, %35, %21, %7
// %2 "$metatype"
bb0(%0 : $*Box<repeat each Element>, %1 : $*any Initializer, %2 : $@thin Box<repeat each Element>.Type):
  %3 = alloc_stack $Builtin.Int1                  // users: %80, %31, %6, %88, %57
  %4 = alloc_stack [dynamic_lifetime] [lexical] [var_decl] $Box<repeat each Element>, var, name "self" // users: %54, %28, %82, %87, %55
  %5 = integer_literal $Builtin.Int1, 0           // user: %6
  store %5 to [trivial] %3 : $*Builtin.Int1       // id: %6
  debug_value %1 : $*any Initializer, var, name "initializer", argno 1, expr op_deref // id: %7
  debug_value undef : $any Error, var, name "$error", argno 2 // id: %8
  %9 = alloc_stack $(repeat each Element)         // users: %34, %32, %73, %70, %19
  %10 = integer_literal $Builtin.Word, 0          // user: %13
  %11 = integer_literal $Builtin.Word, 1          // user: %26
  %12 = pack_length $Pack{repeat each Element}    // user: %15
  br bb1(%10 : $Builtin.Word)                     // id: %13

// %14                                            // users: %26, %63, %17, %15
bb1(%14 : $Builtin.Word):                         // Preds: bb3 bb0
  %15 = builtin "cmp_eq_Word"(%14 : $Builtin.Word, %12 : $Builtin.Word) : $Builtin.Int1 // user: %16
  cond_br %15, bb4, bb2                           // id: %16

bb2:                                              // Preds: bb1
  %17 = dynamic_pack_index %14 of $Pack{repeat each Element} // users: %19, %18
  %18 = open_pack_element %17 of <each Element where repeat each Element : Initializable> at <Pack{repeat each Element}>, shape $each Element, uuid "84FD5836-FBC6-11EE-8C65-9EF225039CA4" // users: %23, %22, %20, %19
  %19 = tuple_pack_element_addr %17 of %9 : $*(repeat each Element) as $*@pack_element("84FD5836-FBC6-11EE-8C65-9EF225039CA4") each Element // user: %23
  %20 = metatype $@thick (@pack_element("84FD5836-FBC6-11EE-8C65-9EF225039CA4") each Element).Type // type-defs: %18; user: %23
  %21 = begin_access [modify] [static] %1 : $*any Initializer // users: %25, %23, %60
  %22 = witness_method $@pack_element("84FD5836-FBC6-11EE-8C65-9EF225039CA4") each Element, #Initializable.init!allocator : <Self where Self : Initializable> (Self.Type) -> (inout any Initializer) throws -> Self, %18 : $Builtin.SILToken : $@convention(witness_method: Initializable) <τ_0_0 where τ_0_0 : Initializable> (@inout any Initializer, @thick τ_0_0.Type) -> (@out τ_0_0, @error any Error) // type-defs: %18; user: %23
  try_apply %22<(@pack_element("84FD5836-FBC6-11EE-8C65-9EF225039CA4") each Element)>(%19, %21, %20) : $@convention(witness_method: Initializable) <τ_0_0 where τ_0_0 : Initializable> (@inout any Initializer, @thick τ_0_0.Type) -> (@out τ_0_0, @error any Error), normal bb3, error bb6 // type-defs: %18; id: %23

bb3(%24 : $()):                                   // Preds: bb2
  end_access %21 : $*any Initializer              // id: %25
  %26 = builtin "add_Word"(%14 : $Builtin.Word, %11 : $Builtin.Word) : $Builtin.Word // user: %27
  br bb1(%26 : $Builtin.Word)                     // id: %27

bb4:                                              // Preds: bb1
  %28 = begin_access [modify] [static] %4 : $*Box<repeat each Element> // users: %33, %29
  %29 = struct_element_addr %28 : $*Box<repeat each Element>, #Box.elements // user: %32
  %30 = integer_literal $Builtin.Int1, -1         // user: %31
  store %30 to [trivial] %3 : $*Builtin.Int1      // id: %31
  copy_addr [take] %9 to [init] %29 : $*(repeat each Element) // id: %32
  end_access %28 : $*Box<repeat each Element>     // id: %33
  dealloc_stack %9 : $*(repeat each Element)      // id: %34
  %35 = begin_access [read] [static] %1 : $*any Initializer // users: %38, %37
  %36 = alloc_stack $any Initializer              // users: %43, %42, %39, %37
  copy_addr %35 to [init] %36 : $*any Initializer // id: %37
  end_access %35 : $*any Initializer              // id: %38
  %39 = open_existential_addr immutable_access %36 : $*any Initializer to $*@opened("84FD601A-FBC6-11EE-8C65-9EF225039CA4", any Initializer) Self // users: %41, %41, %40
  %40 = witness_method $@opened("84FD601A-FBC6-11EE-8C65-9EF225039CA4", any Initializer) Self, #Initializer.foo : <Self where Self : Initializer> (Self) -> () -> Bool, %39 : $*@opened("84FD601A-FBC6-11EE-8C65-9EF225039CA4", any Initializer) Self : $@convention(witness_method: Initializer) <τ_0_0 where τ_0_0 : Initializer> (@in_guaranteed τ_0_0) -> Bool // type-defs: %39; user: %41
  %41 = apply %40<@opened("84FD601A-FBC6-11EE-8C65-9EF225039CA4", any Initializer) Self>(%39) : $@convention(witness_method: Initializer) <τ_0_0 where τ_0_0 : Initializer> (@in_guaranteed τ_0_0) -> Bool // type-defs: %39
  destroy_addr %36 : $*any Initializer            // id: %42
  dealloc_stack %36 : $*any Initializer           // id: %43
  %44 = begin_access [read] [static] %1 : $*any Initializer // users: %47, %46
  %45 = alloc_stack $any Initializer              // users: %53, %52, %77, %76, %48, %46
  copy_addr %44 to [init] %45 : $*any Initializer // id: %46
  end_access %44 : $*any Initializer              // id: %47
  %48 = open_existential_addr immutable_access %45 : $*any Initializer to $*@opened("84FD631C-FBC6-11EE-8C65-9EF225039CA4", any Initializer) Self // users: %50, %50, %49
  %49 = witness_method $@opened("84FD631C-FBC6-11EE-8C65-9EF225039CA4", any Initializer) Self, #Initializer.bar : <Self where Self : Initializer> (Self) -> () throws -> Bool, %48 : $*@opened("84FD631C-FBC6-11EE-8C65-9EF225039CA4", any Initializer) Self : $@convention(witness_method: Initializer) <τ_0_0 where τ_0_0 : Initializer> (@in_guaranteed τ_0_0) -> (Bool, @error any Error) // type-defs: %48; user: %50
  try_apply %49<@opened("84FD631C-FBC6-11EE-8C65-9EF225039CA4", any Initializer) Self>(%48) : $@convention(witness_method: Initializer) <τ_0_0 where τ_0_0 : Initializer> (@in_guaranteed τ_0_0) -> (Bool, @error any Error), normal bb5, error bb10 // type-defs: %48; id: %50

bb5(%51 : $Bool):                                 // Preds: bb4
  destroy_addr %45 : $*any Initializer            // id: %52
  dealloc_stack %45 : $*any Initializer           // id: %53
  copy_addr [take] %4 to [init] %0 : $*Box<repeat each Element> // id: %54
  dealloc_stack %4 : $*Box<repeat each Element>   // id: %55
  %56 = tuple ()                                  // user: %58
  dealloc_stack %3 : $*Builtin.Int1               // id: %57
  return %56 : $()                                // id: %58

// %59                                            // user: %74
bb6(%59 : @owned $any Error):                     // Preds: bb2
  end_access %21 : $*any Initializer              // id: %60
  %61 = integer_literal $Builtin.Word, 0          // user: %65
  %62 = integer_literal $Builtin.Word, 1          // user: %67
  br bb7(%14 : $Builtin.Word)                     // id: %63

// %64                                            // users: %67, %65
bb7(%64 : $Builtin.Word):                         // Preds: bb8 bb6
  %65 = builtin "cmp_eq_Word"(%64 : $Builtin.Word, %61 : $Builtin.Word) : $Builtin.Int1 // user: %66
  cond_br %65, bb9, bb8                           // id: %66

bb8:                                              // Preds: bb7
  %67 = builtin "sub_Word"(%64 : $Builtin.Word, %62 : $Builtin.Word) : $Builtin.Word // users: %72, %68
  %68 = dynamic_pack_index %67 of $Pack{repeat each Element} // users: %70, %69
  %69 = open_pack_element %68 of <each Element where repeat each Element : Initializable> at <Pack{repeat each Element}>, shape $each Element, uuid "84FE470A-FBC6-11EE-8C65-9EF225039CA4" // user: %70
  %70 = tuple_pack_element_addr %68 of %9 : $*(repeat each Element) as $*@pack_element("84FE470A-FBC6-11EE-8C65-9EF225039CA4") each Element // user: %71
  destroy_addr %70 : $*@pack_element("84FE470A-FBC6-11EE-8C65-9EF225039CA4") each Element // id: %71
  br bb7(%67 : $Builtin.Word)                     // id: %72

bb9:                                              // Preds: bb7
  dealloc_stack %9 : $*(repeat each Element)      // id: %73
  br bb11(%59 : $any Error)                       // id: %74

// %75                                            // user: %78
bb10(%75 : @owned $any Error):                    // Preds: bb4
  destroy_addr %45 : $*any Initializer            // id: %76
  dealloc_stack %45 : $*any Initializer           // id: %77
  br bb11(%75 : $any Error)                       // id: %78

// %79                                            // user: %89
bb11(%79 : @owned $any Error):                    // Preds: bb10 bb9
  %80 = load [trivial] %3 : $*Builtin.Int1        // user: %81
  cond_br %80, bb12, bb13                         // id: %81

bb12:                                             // Preds: bb11
  %82 = struct_element_addr %4 : $*Box<repeat each Element>, #Box.elements // user: %83
  %83 = tuple_element_addr %82 : $*(repeat each Element), 0 // user: %84
  destroy_addr %83 : $*repeat each Element        // id: %84
  br bb14                                         // id: %85

bb13:                                             // Preds: bb11
  br bb14                                         // id: %86

bb14:                                             // Preds: bb13 bb12
  dealloc_stack %4 : $*Box<repeat each Element>   // id: %87
  dealloc_stack %3 : $*Builtin.Int1               // id: %88
  throw %79 : $any Error                          // id: %89
} // end sil function '$s7vgtests3BoxV4withACyxxQp_QPGAA11Initializer_pz_tKcfC'

Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-04-13-a.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file <homedir>/variadic-generic-tests/Sources/main.swift -emit-dependencies-path <homedir>/Library/Developer/Xcode/DerivedData/variadic-generic-tests-cvgynpsdlgsgsybdcgrgztjrnoge/Build/Intermediates.noindex/vgtests.build/Debug/vgtests.build/Objects-normal/arm64/main.d -emit-const-values-path <homedir>/Library/Developer/Xcode/DerivedData/variadic-generic-tests-cvgynpsdlgsgsybdcgrgztjrnoge/Build/Intermediates.noindex/vgtests.build/Debug/vgtests.build/Objects-normal/arm64/main.swiftconstvalues -emit-reference-dependencies-path <homedir>/Library/Developer/Xcode/DerivedData/variadic-generic-tests-cvgynpsdlgsgsybdcgrgztjrnoge/Build/Intermediates.noindex/vgtests.build/Debug/vgtests.build/Objects-normal/arm64/main.swiftdeps -serialize-diagnostics-path <homedir>/Library/Developer/Xcode/DerivedData/variadic-generic-tests-cvgynpsdlgsgsybdcgrgztjrnoge/Build/Intermediates.noindex/vgtests.build/Debug/vgtests.build/Objects-normal/arm64/main.dia -target arm64-apple-macos14.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -I <homedir>/Library/Developer/Xcode/DerivedData/variadic-generic-tests-cvgynpsdlgsgsybdcgrgztjrnoge/Build/Products/Debug -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F <homedir>/Library/Developer/Xcode/DerivedData/variadic-generic-tests-cvgynpsdlgsgsybdcgrgztjrnoge/Build/Products/Debug -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -no-color-diagnostics -enable-testing -g -module-cache-path <homedir>/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -package-name variadic_generic_tests -const-gather-protocols-file <homedir>/Library/Developer/Xcode/DerivedData/variadic-generic-tests-cvgynpsdlgsgsybdcgrgztjrnoge/Build/Intermediates.noindex/vgtests.build/Debug/vgtests.build/Objects-normal/arm64/vgtests_const_extract_protocols.json -empty-abi-descriptor -validate-clang-modules-once -clang-build-session-file <homedir>/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc <homedir>/variadic-generic-tests -resource-dir /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-04-13-a.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -I<homedir>/Library/Developer/Xcode/DerivedData/variadic-generic-tests-cvgynpsdlgsgsybdcgrgztjrnoge/Build/Products/Debug/include -Xcc -I<homedir>/Library/Developer/Xcode/DerivedData/variadic-generic-tests-cvgynpsdlgsgsybdcgrgztjrnoge/Build/Intermediates.noindex/vgtests.build/Debug/vgtests.build/DerivedSources-normal/arm64 -Xcc -I<homedir>/Library/Developer/Xcode/DerivedData/variadic-generic-tests-cvgynpsdlgsgsybdcgrgztjrnoge/Build/Intermediates.noindex/vgtests.build/Debug/vgtests.build/DerivedSources/arm64 -Xcc -I<homedir>/Library/Developer/Xcode/DerivedData/variadic-generic-tests-cvgynpsdlgsgsybdcgrgztjrnoge/Build/Intermediates.noindex/vgtests.build/Debug/vgtests.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -module-name vgtests -frontend-parseable-output -disable-clang-spi -disable-availability-checking -target-sdk-version 14.2 -target-sdk-name macosx14.2 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-04-13-a.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-04-13-a.xctoolchain/usr/local/lib/swift/host/plugins -o <homedir>/Library/Developer/Xcode/DerivedData/variadic-generic-tests-cvgynpsdlgsgsybdcgrgztjrnoge/Build/Intermediates.noindex/vgtests.build/Debug/vgtests.build/Objects-normal/arm64/main.o -index-unit-output-path /vgtests.build/Debug/vgtests.build/Objects-normal/arm64/main.o -index-store-path <homedir>/Library/Developer/Xcode/DerivedData/variadic-generic-tests-cvgynpsdlgsgsybdcgrgztjrnoge/Index.noindex/DataStore -index-system-modules
1.  Apple Swift version 6.0-dev (LLVM 01231f56c62f4c4, Swift abaa63821080b92)
2.  Compiling with effective version 5.10
3.  While verifying SIL function "@$s7vgtests3BoxV4withACyxxQp_QPGAA11Initializer_pz_tKcfC".
 for 'init(with:)' (at <homedir>/variadic-generic-tests/Sources/main.swift:11:5)
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           0x0000000107704e34 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000107703600 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010770547c SignalHandler(int) + 304
3  libsystem_platform.dylib 0x00000001841bf584 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000018418ec20 pthread_kill + 288
5  libsystem_c.dylib        0x000000018409ba20 abort + 180
6  swift-frontend           0x00000001031ffc58 swift::SILOptions::~SILOptions() + 0
7  swift-frontend           0x000000010320829c swift::SILVisitorBase<(anonymous namespace)::SILVerifier, void>::visitSILBasicBlock(swift::SILBasicBlock*) + 17528
8  swift-frontend           0x0000000103203d24 (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) + 28
9  swift-frontend           0x000000010320278c (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) + 9724
10 swift-frontend           0x00000001031fc0d8 swift::SILFunction::verify(swift::CalleeCache*, bool, bool, bool) const + 204
11 swift-frontend           0x00000001031ff1dc swift::SILModule::verify(swift::CalleeCache*, bool, bool) const + 192
12 swift-frontend           0x00000001031ff0b4 swift::SILModule::verify(bool, bool) const + 140
13 swift-frontend           0x00000001024f6474 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 136
14 swift-frontend           0x00000001022bb4c8 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*) + 796
15 swift-frontend           0x00000001022babdc swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 612
16 swift-frontend           0x00000001022cbe14 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
17 swift-frontend           0x00000001022bd1ec performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 708
18 swift-frontend           0x00000001022bc158 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2368
19 swift-frontend           0x00000001020d7870 swift::mainEntry(int, char const**) + 3096
20 dyld                     0x0000000183e060e0 start + 2360

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)"

martialln commented 6 months ago

I reproduced the error with:

Xcode Version 15.3 (15E204a) Toolchain: Swift 6.0 Development Snapshot 2024-04-17 (a)

AnthonyLatsis commented 6 months ago

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
martialln commented 1 month ago

Update still happening with:

macOS 15.0 (24A335) Version 16.0 (16A242)