Closed
Description
Description
This is triggered only in release mode.
Changing Array: FromIterator
to Array
will compile successfully, or removing consuming
from the parameters and adding var iterator = iterator
will also compile successfully.
error: compile command failed due to signal 6 (use -v to see invocation)
SIL verification failed: Found mutating or consuming use of an in_guaranteed parameter?!: !ImmutableAddressUseVerifier().isMutatingOrConsuming(fArg)
Verifying argument:
-> %0 = argument of bb0 : $*Iterator // users: %3, %11
debug_value %0 : $*Iterator, var, name "iterator", type $@moveOnly Iterator, expr op_deref // id: %3
%11 = apply %7<Iterator>(%10, %0) : $@convention(witness_method: IteratorProtocol) <τ_0_0 where τ_0_0 : IteratorProtocol> (@inout τ_0_0) -> @out Optional<τ_0_0.Element>
In function:
// specialized Array.init<A>(iterator:)
Reproduction
Compilation in release mode will trigger it, but not in debug mode. Can be reproduced on swift 6.0.3 and swift 6.2 (DEVELOPMENT-SNAPSHOT-2025-05-08), Xcode version (swift 6.0.3) can be successfully compiled in release mode.
swiftc -O Bug.swift
public protocol FromIterator<Element> {
associatedtype Element
init<Iterator>(
iterator: consuming Iterator
) where Iterator: IteratorProtocol, Iterator.Element == Element
}
extension Array: FromIterator {
public init<Iterator>(
iterator: consuming Iterator
) where Iterator: IteratorProtocol, Iterator.Element == Element {
self.init()
while let next = iterator.next() {
append(next)
}
}
}
Stack dump
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0. Program arguments: <REDACTED>/usr/bin/swift-frontend -frontend -c <REDACTED>/Sources/IteratorBug/IteratorBug.swift -emit-module-path <REDACTED>/.build/arm64-apple-macosx/release/Modules/IteratorBug.swiftmodule -emit-module-doc-path <REDACTED>/.build/arm64-apple-macosx/release/Modules/IteratorBug.swiftdoc -emit-module-source-info-path <REDACTED>/.build/arm64-apple-macosx/release/Modules/IteratorBug.swiftsourceinfo -emit-dependencies-path <REDACTED>/.build/arm64-apple-macosx/release/IteratorBug.build/IteratorBug.d -serialize-diagnostics-path <REDACTED>/.build/arm64-apple-macosx/release/IteratorBug.build/IteratorBug.dia -emit-objc-header-path <REDACTED>/.build/arm64-apple-macosx/release/IteratorBug.build/IteratorBug-Swift.h -emit-abi-descriptor-path <REDACTED>/.build/arm64-apple-macosx/release/Modules/IteratorBug.abi.json -target arm64-apple-macosx10.13 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -I <REDACTED>/.build/arm64-apple-macosx/release/Modules -I <REDACTED>/usr/lib/swift/macosx/testing -I /Applications/Xcode16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -F /Applications/Xcode16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/PrivateFrameworks -color-diagnostics -Xcc -fcolor-diagnostics -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path <REDACTED>/.build/arm64-apple-macosx/release/ModuleCache -swift-version 6 -O -diagnostic-style=llvm -D SWIFT_PACKAGE -D SWIFT_MODULE_RESOURCE_BUNDLE_UNAVAILABLE -empty-abi-descriptor -plugin-path <REDACTED>/usr/lib/swift/host/plugins/testing -file-compilation-dir <REDACTED> -Xcc -isysroot -Xcc /Applications/Xcode16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -Xcc -F -Xcc /Applications/Xcode16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -F -Xcc /Applications/Xcode16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/PrivateFrameworks -Xcc -fPIC -Xcc -g -no-auto-bridging-header-chaining -module-name IteratorBug -package-name bugfix -in-process-plugin-server-path <REDACTED>/usr/lib/swift/host/libSwiftInProcPluginServer.dylib -plugin-path <REDACTED>/usr/lib/swift/host/plugins -plugin-path <REDACTED>/usr/local/lib/swift/host/plugins -target-sdk-version 15.2 -target-sdk-name macosx15.2 -external-plugin-path /Applications/Xcode16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -enable-default-cmo -parse-as-library -num-threads 12 -o <REDACTED>/.build/arm64-apple-macosx/release/IteratorBug.build/IteratorBug.swift.o
1. Apple Swift version 6.2-dev (LLVM 497b5adfd931d92, Swift f861cfcb729d834)
2. Compiling with the current language version
3. While verifying SIL function "@$sSa11IteratorBugE8iteratorSayxGqd___tc7ElementQyd__RszStRd__lufCTf4gn_n".
for 'init(iterator:)' (at <REDACTED>/Sources/IteratorBug/IteratorBug.swift:10:12)
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 0x000000010868bf8c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 swift-frontend 0x000000010868a6b8 llvm::sys::RunSignalHandlers() + 112
2 swift-frontend 0x000000010868c5d4 SignalHandler(int, __siginfo*, void*) + 296
3 libsystem_platform.dylib 0x0000000193487624 _sigtramp + 56
4 libsystem_pthread.dylib 0x000000019344d88c pthread_kill + 296
5 libsystem_c.dylib 0x0000000193356c60 abort + 124
6 swift-frontend 0x0000000103e09994 swift::SILModule::print(llvm::raw_ostream&, swift::ModuleDecl*, swift::SILOptions const&, bool) const + 0
7 swift-frontend 0x0000000103e10dc0 swift::SILVisitorBase<(anonymous namespace)::SILVerifier, void>::visitSILBasicBlock(swift::SILBasicBlock*) + 476
8 swift-frontend 0x0000000103e10b24 (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) + 24
9 swift-frontend 0x0000000103e0f484 (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) + 10464
10 swift-frontend 0x0000000103e09b4c swift::SILFunction::verify(swift::CalleeCache*, bool, bool, bool) const + 224
11 swift-frontend 0x0000000103e0c458 swift::SILModule::verify(swift::CalleeCache*, bool, bool) const + 192
12 swift-frontend 0x0000000103e0c330 swift::SILModule::verify(bool, bool) const + 140
13 swift-frontend 0x000000010319dd34 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 580
14 swift-frontend 0x0000000102f65be4 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*) + 820
15 swift-frontend 0x0000000102f655a0 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1328
16 swift-frontend 0x0000000102f71914 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 164
17 swift-frontend 0x0000000102f6703c performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 716
18 swift-frontend 0x0000000102f667f8 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2312
19 swift-frontend 0x0000000102cfef14 swift::mainEntry(int, char const**) + 3064
20 dyld 0x00000001930aeb4c start + 6000
Expected behavior
No compiler crash.
Environment
- swift 6.0.3
Apple Swift version 6.0.3 (swift-6.0.3-RELEASE)
Target: arm64-apple-macosx15.0 - swift 6.2
Apple Swift version 6.2-dev (LLVM 497b5adfd931d92, Swift f861cfc)
Target: arm64-apple-macosx15.0
Build config: +assertions
Additional information
No response