Open dabrahams opened 5 months ago
And of course, you can't do a clean build with the -no-whole-module-optimization
patch applied, because of https://github.com/apple/swift-package-manager/issues/7274
Applying -no-whole-module-optimization
just to the Core
module is enough to suppress the fatalError
.
Hi! This may also be the cause of https://github.com/fumoboy007/msgpack-swift/issues/4. Hmm maybe not; this issue was for Swift 5.9.2 but my issue is only for Swift 5.10.
Hmm maybe not; this issue was for Swift 5.9.2 but my issue is only for Swift 5.10.
Actually I was mistaken. https://github.com/fumoboy007/msgpack-swift/issues/4 does seem to be caused by some change in Swift 5.9.
I moved the relevant code to its own Swift package: OptimizationBugRepro.zip. The smaller package exhibits unexpected behavior with Swift 5.9.2 (release configuration, WMO enabled) but succeeds with Swift 5.8.1.
Using the prebuilt Swift development snapshots, I narrowed down the culprit to one of 85 commits. I was unable to narrow it down further because I couldn’t solve some issues with manually building the Swift compiler from source.
Sorry for hijacking this thread… hopefully my small reproduction test case (396 lines) can help a Swift compiler engineer easily find the culprit.
Here is main.swift
:
var messageWriter = MessageWriter()
try EncodableMessagePackValue.nil.encode(to: &messageWriter)
// Should print "[192]".
print(Array(messageWriter.message))
The relevant stack looks like this:
main.swift
calls encode(to:)
.encode(to:)
calls encodeNil(to:)
.encodeNil(to:)
calls messageWriter.write(byte: 0xC0)
write(byte:)
calls Data.append(_:count:)
.As you can see, the logic is quite straightforward. The rest of the code in the package unfortunately needs to be there; otherwise the issue disappears!
Description
Tests fail in release mode unless
-no-whole-module-optimization
is passed.Reproduction
Sorry, it's not a small repro, but then a WMO bug would tend not to be, right?
possible-swift-wmo-bug
tag of https://github.com/hylo-lang/hylogit submodule update --init
swift test --filter Execution
to see a test passswift test -Xswiftc -enable-testing -c release --filter Execution
to see the failure (afatalError
call).Apply this patch:
Repeat the command to see it not fail.
Alternatively, apply this patch
and repeat the command to see it not fail.
Expected behavior
Same behavior in debug and release builds; no observable change from turning on/off WMO; round-trip serialization makes no difference, or at least has the same effect in debug and release builds.
Environment
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
Additional information
No response