wit-bindgen C++ passes the wrong enum value in option<list<variant>>

Offen
#1,683 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
52/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
cpp, wasm
Bereich
compilers, devtools

Rechercherichtung

Beginne mit den generierten C++-Consumer-Quellen in src/consumer-Cpp/ und dem WIT-Paket in wit/ und reproduziere anschließend die Build- und Kompositionsbefehle für Provider und Consumer aus dem Bericht. Vergleiche die verschachtelte option/variant-Ausgabe der komponierten Komponente mit dem erwarteten Ergebnis: Der enum-Payload sollte sowohl unter jco als auch unter wasmtime e3 bleiben, statt zu e1 zu werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Summary:wit-bindgen-cpp encodes wrong enum discriminant for enum payload inside variant inside option, producing incorrect values.

Bug report: C++ consumers generated by wit-bindgen-cpp lift/lower the enum case inside an option-wrapped variant with a wrong discriminant (e3 becomes e1), yielding wrong output values regardless of provider language.

Environment

component version
OS macOS 15.7 (Darwin 24.6.0), x86_64
jco 1.16.1 (source checkout, tag jco-v1.16.1)
Node.js v22.22.2
wac wac-cli 0.8.1
wasi-sdk 27.0 (wasm32-wasip2-clang/clang++)

Steps to reproduce

The full chain is: compile the guest sources into a provider component and a consumer component, compose them with wac, then run the composed component. Prebuilt copies of every artifact are included (components/provider.wasm, components/consumer.wasm, composed.wasm), so you can also skip straight to step 5.

Github repo:https://github.com/xiaozzzZZzzz240/G028-Cplusplus-bindings-return-e1-instead-of-e3-for-enum-payload-in-option

  1. Clone this repository:

    git clone <THIS_REPO_URL>
    cd <THIS_REPO_DIR>
    
  2. Compile the provider component from the C sources in src/provider-C/ (toolchain versions in the table above; the WIT package is in wit/):

    wasm32-wasip2-clang -o components/provider.wasm -mexec-model=reactor src/provider-C/world9-wi7n9u47_generated.c src/provider-C/world9_wi7n9u47.c src/provider-C/world9_wi7n9u47_component_type.o
    
  3. Compile the consumer component from the C++ sources in src/consumer-Cpp/:

    wasm32-wasip2-clang++ -std=c++23 -fno-exceptions -o components/consumer.wasm -mexec-model=reactor src/consumer-Cpp/world9b-mul38v8w_generated.cpp src/consumer-Cpp/world9b_mul38v8w.cpp src/consumer-Cpp/world9b_mul38v8w_component_type.o
    
  4. Compose the two components into one runnable component with wac 0.8.1:

    wac plug components/consumer.wasm --plug components/provider.wasm -o composed.wasm
    
  5. Run the composed component with jco:

    npm install -g @bytecodealliance/[email protected]
    jco run composed.wasm
    

Expected result

The composed component should print exactly the following, then exit 0:

"resinst0"
"resinst1"
"resinst2"
"resinst0"
resource("temres36")
"c2"
true
"c0"
resource("temres39")
(resource("temres40"), "bar")
"c2"
true
"temres39"
"temres44"
some([c1(enum(e3))])
resource("temres6")
"c0"
true
7
true

Actual result

Under jco the same composed.wasm exits with rc=0. stdout:

"resinst0"
"resinst1"
"resinst2"
"resinst0"
resource("temres36")
"c2"
true
"c0"
resource("temres39")
(resource("temres40"), "bar")
"c2"
true
"temres39"
"temres44"
some([c1(enum(e1))])
resource("temres6")
"c0"
true
7
true

stderr:

(empty)

wasmtime on the exact same file: rc=0

"resinst0"
"resinst1"
"resinst2"
"resinst0"
resource("temres36")
"c2"
true
"c0"
resource("temres39")
(resource("temres40"), "bar")
"c2"
true
"temres39"
"temres44"
some([c1(enum(e1))])
resource("temres6")
"c0"
true
7
true

Both executing result in jco and wasmtime are not as expected.

Vorherrschende Sprache
Rust
Sterne
1.5k
Forks
306
Ø Merge
1 T. 4 Std.
Gemergte PRs (30 T.)
21

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

  • Kein Dockerfile und keine Docker-Compose-Datei
  • Keine Pull-Request-Vorlage
  • Kein Beitragsleitfaden

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus bytecodealliance/wit-bindgen

Alle Issues in bytecodealliance/wit-bindgen

Ähnliche Issues

Weitere Issues zu Rust

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.