I’m seeing different destruction behavior for a move-only type (~Copyable) when compiling for native vs WebAssembly. Native behavior matches expectations, but the WASM build appears to destroy the value twice.
struct S: ~Copyable {
var v: Int
init(v: Int) {
print("S init v:\(v)")
self.v = v
}
deinit {
print("S deinit v:\(v)")
}
}
func go() {
var s = S(v: 5)
s.v += 1
s.v += 1
_ = consume s
}
go()
Native build output (expected)
S init v:5
S deinit v:7
WASM build output
S init v:5
S deinit v:5
S deinit v:7
I produced and ran the wasm build via: swift run -c release --swift-sdk swift-6.2.4-RELEASE_wasm
Are noncopyables even supported for WASM? This seems to be a major bug
Could you check what version of the compiler you're using for the native build? Just want to make sure the problem is in fact wasm-specific and not due to different compiler version bugs.
if you have a moment (and haven't yet done so), you should probably file a github issue for this, as it does seem like a miscompilation of some sort. FWIW disabling the dead object elimination pass (-Xllvm -sil-disable-pass=deadobject-elim) for some reason appears to prevent the issue from manifesting in this specific case (i mention this mostly out of curiosity, and doubt that it's a generally advisable workaround).
Thanks! This isn't reproducible with swift-DEVELOPMENT-SNAPSHOT-2026-02-23-a, and I need to run more checks to verify with 6.3 snapshots or to find a PR/commit to cherry-pick if that's possible.