ITADN

Swift 6.3.2 Compiler Bug unter Windows ARM64

#89935Openbastie 创建于 2026-06-13
triage needed
B
bastiecommented
### Description Compiler Crash under Windows but works under macOS. ### Reproduction ```swift // Minimal reproducer for Windows Swift 6.3.2 compiler bug // // Symptoms on aarch64-unknown-windows-msvc (Swift 6.3.2): // error: type '((Optional<Int>) throws(E) -> Bool) throws(E) -> Int' // cannot conform to 'BinaryInteger' // error: generic parameter 'E' could not be inferred // error: value of type 'Box<Int>' has no subscripts // // Works correctly on arm64-apple-macosx (Swift 6.3.2). // // Root cause hypothesis: When a concrete class conforms to both a custom // protocol that inherits Sequence AND provides a throwing overload of a // method (here: add), the Windows compiler loses the type context for the // variable and misresolves subsequent method calls against Sequence extensions // (specifically Sequence.count(where:) typed-throws variant from Swift 6). // // Compile with: swift windows_compiler_bug_repro.swift // --- Minimal protocol hierarchy --- protocol JavaIterator<Element>: Sequence { func hasNext() -> Bool func next() throws -> Element } extension JavaIterator { public func makeIterator() -> AnyIterator<Element?> { let it = self return AnyIterator { guard it.hasNext() else { return nil } return try? it.next() } } } protocol JavaCollection<E>: Sequence where E: Equatable { associatedtype E func size() -> Int func add(_ element: E?) throws -> Bool } // --- Minimal concrete class --- class Box<E: Equatable>: JavaCollection { var elements: [E?] = [] func makeIterator() -> AnyIterator<E?> { var index = 0 return AnyIterator { guard index < self.elements.count else { return nil } defer { index += 1 } return self.elements[index] } } func size() -> Int { elements.count } @discardableResult func add(_ element: E?) throws -> Bool { elements.append(element) return true } } // --- Reproducer --- let box = Box<Int>() _ = try? box.add(42) // triggers overload ambiguity on Windows print(box.size() == 1) // Windows: cannot conform to 'BinaryInteger' ``` **macOS result:** ```bash swift windows_compiler_bug_repro.swift true ``` **Windows result:** ```cmd >swift -version & swift windows_compiler_bug_repro.swift Swift version 6.3.2 (swift-6.3.2-RELEASE) Target: aarch64-unknown-windows-msvc Build config: +assertions JIT session error: Symbols not found: [ $ss27_allocateUninitializedArrayySayxG_BptBwlFyp_Tg5 ] Failed to materialize symbols: { (main, { $s26windows_compiler_bug_repro3BoxCfd, symbolic _____yxSgG s11AnyIteratorV, symbolic xSg, symbolic SayxSgG, $s26windows_compiler_bug_repro3BoxCACyxGycfc, $s26windows_compiler_bug_repro14JavaCollectionP1EAC_SQTn, associated conformance 26windows_compiler_bug_repro3BoxCyxGSTAA8IteratorST_St, $s26windows_compiler_bug_reproMXM, $s26windows_compiler_bug_repro3BoxC8elementsSayxSgGvMTq, symbolic $s26windows_compiler_bug_repro12JavaIteratorP, $ss5print_9separator10terminatoryypd_S2StFfA1_, $s26windows_compiler_bug_repro12JavaIteratorMp, associated conformance 26windows_compiler_bug_repro3BoxCyxGAA14JavaCollectionAA1EAaEP_SQ, $ss5print_9separator10terminatoryypd_S2StFfA0_, $s26windows_compiler_bug_repro3BoxC4sizeSiyF, symbolic G0R1_, $s26windows_compiler_bug_repro3BoxC12makeIterators03AnyG0VyxSgGyF, $s26windows_compiler_bug_repro3BoxCyxGSTAAMc, symbolic B0, $ss27_finalizeUninitializedArrayySayxGABnlF, $s26windows_compiler_bug_repro3BoxC8elementsSayxSgGvsTq, $s26windows_compiler_bug_repro3BoxCACyxGycfC, $sSa12_endMutationyyF, symbolic $s26windows_compiler_bug_repro14JavaCollectionP, $s26windows_compiler_bug_repro3BoxCySiGMD, symbolic x, $s26windows_compiler_bug_repro14JavaCollectionMp, __swift_instantiateConcreteTypeFromMangledName, symbolic $sST, $s26windows_compiler_bug_repro12JavaIteratorPAAE04makeF0s03AnyF0Vy7ElementQzSgGyF, __swift_instantiateGenericMetadata, symbolic 1E_____Qz 26windows_compiler_bug_repro14JavaCollectionP, symbolic _____ 26windows_compiler_bug_repro3BoxC, symbolic _____yxG 26windows_compiler_bug_repro3BoxC, $s26windows_compiler_bug_repro3BoxCACyxGycfCTq, $s26windows_compiler_bug_repro3boxAA3BoxCySiGvp, $sSayxSgGSQRzlWOh, $s26windows_compiler_bug_repro14JavaCollectionTL, $s26windows_compiler_bug_repro3BoxC8elementsSayxSgGvM, symbolic Siz_Xx, $s1E26windows_compiler_bug_repro14JavaCollectionPTl, $s26windows_compiler_bug_repro3BoxC3addySbxSgKF, symbolic _____ySiG 26windows_compiler_bug_repro3BoxC, $s26windows_compiler_bug_repro3BoxC3addySbxSgKFTq, main, $s26windows_compiler_bug_repro3BoxCMa, $s26windows_compiler_bug_repro3BoxCfD, $s26windows_compiler_bug_repro3BoxC8elementsSayxSgGvg, $s26windows_compiler_bug_repro3BoxC8elementsSayxSgGvs, $s26windows_compiler_bug_repro14JavaCollectionPSTTb, $s26windows_compiler_bug_repro3BoxCMn, $s26windows_compiler_bug_repro3BoxC8elementsSayxSgGvpWvd, $s26windows_compiler_bug_repro3BoxC12makeIterators03AnyG0VyxSgGyFTq, $sxSgSQRzlWOc, $s26windows_compiler_bug_repro3BoxC4sizeSiyFTq, $s26windows_compiler_bug_repro3BoxC8elementsSayxSgGvgTq, $s26windows_compiler_bug_repro12JavaIteratorPSTTb, symbolic Si, $s26windows_compiler_bug_repro3BoxCyxGAA14JavaCollectionAAMc, $s26windows_compiler_bug_repro12JavaIteratorTL }) } ``` ### Expected behavior like macOS compile without crash ### Environment Swift version 6.3.2 (swift-6.3.2-RELEASE) Target: aarch64-unknown-windows-msvc Build config: +assertions ### Additional information _No response_
5 条评论