swiftwasm / swift

WebAssembly support for the Swift programming language

Home Page:https://swiftwasm.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Workaround wasm platform compiler issue

Kyle-Ye opened this issue · comments

commented

I found WASM CI failure recently due to a swift compile issue here.

RangeText="OGGraph.typeIndex(
            ctx: context,
            body: Body.self,
            valueType: OGTypeID(Value.self),
            flags: flags,
            update: update
        "
  argument value: %21 = argument of bb2 : $Unmanaged<OGGraphContext> // user: %22
  argument type: $Unmanaged<OGGraphContext>
  parameter type: $OGGraphContext
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.

I don't have time to investigate for the time being. And I feel that there is a high probability that the subsequent Swift-wasm will fix it, so I'm trying to use some workarounds here.

#if os(WASI)
fatalError("xx")
#else
let index = OGGraph.typeIndex(
    ctx: context,
    body: Body.self,
    valueType: OGTypeID(Value.self),
    flags: flags,
    update: update
)
#endif

https://github.com/OpenSwiftUIProject/OpenGraph/actions/runs/7948140518/job/21697819791?pr=25

But even I add such macro to block it, the CI is still complaining about the type mismatch here. What should I do to fix/workaround it? Is #if os(WASI) the correct way to detect swiftwasm toolchain?

  1. Your CI configuration (swift build step) does not build for WebAssembly. It's building for host platform. It would help if you used swift build --triple wasm32-unknown-wasi instead.
  2. The code hits compiler internal assertions. swift.org toolchains are built without assertions, so it just ignored the violation, but SwiftWasm is built with assertion enabled, so crashing.

So this is not WebAssembly target-dependent stuff at all, but a build configuration issue.

commented
  1. Your CI configuration (swift build step) does not build for WebAssembly. It's building for host platform. It would help if you used swift build --triple wasm32-unknown-wasi instead.
  2. The code hits compiler internal assertions. swift.org toolchains are built without assertions, so it just ignored the violation, but SwiftWasm is built with assertion enabled, so crashing.

So this is not WebAssembly target-dependent stuff at all, but a build configuration issue.

  1. Got it. I forgot to pass "--triple wasm32-unknown-wasi" here. Thanks for the point.

The old cargo based action https://github.com/swiftwasm/swiftwasm-action does not need pass any param here. So after I switched to https://github.com/swiftwasm/setup-swiftwasm, I forgot to add it. Maybe we can add this info (swift build --triple wasm32-unknown-wasi) in setup-swiftwasm repo's README to help prevent other newcomers from making similar mistakes.

  1. That said, I still do not know how to fix the issue. It is running fine and the type are actually match. I do not know where the Unmanaged<OGGraphContext> come from here. Maybe it is an internal type checking compiler bug.
commented

Anyway I finally fixed(workaround) it temporarily as you suggest. Thanks for your help.

I'll dig the type mismatch assert issue later.

OpenSwiftUIProject/OpenGraph#25

Hitting internal assertions rather than compilation errors is definitely a compiler issue. Will have a closer look when iI get a time.

commented

Hitting internal assertions rather than compilation errors is definitely a compiler issue. Will have a closer look when iI get a time.

Actually this will also appear on Linux with the latest nightly toolchain (assertion on).

I believe this is not a WASM specific issue but a universal issue for non-Darwin/non-ObjectiveC platform since OGGraphContext is defined in a header file via typedef struct CF_BRIDGED_TYPE(id) OGGraphContextStorage * OGGraphContextRef;.