Binary reader rebuilds tag types from Signature, dropping rec group and supertype (follow-up to #7219)

オープン
#9,365 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp, wasm
領域
compilers

調査の方向性

Read readTagImport at src/wasm/wasm-binary.cpp:3303 and readTags at src/wasm/wasm-binary.cpp:5522, where the issue says tag types are obtained through getSignatureByTypeIndex(...) instead of getTypeByIndex(...). Use the supplied WAT examples and wasm-opt commands to reproduce and compare text and binary round trips. Done when binary reading preserves the declared recursive group type and the reproduced tag import links successfully.

索引モデルが issue の本文から書いたものです。

説明

When a tag's type is part of a rec group, reading the module from a binary gives the tag a fresh canonical (func) type. The text reader keeps the declared type. After a binary round trip through wasm-opt, the tag no longer links against importers that use the original type. #7220 fixed Tag::type and the writer, but the reader still goes through Signature.

;; exp.wat
(module
  (rec (type $t1 (func)) (type $t2 (func)))
  (tag (export "x") (type $t1)))
wasm-opt --all-features exp.wat -o exp.wasm
wasm-opt --all-features --emit-text exp.wat -o -
wasm-opt --all-features --emit-text exp.wasm -o -

From the .wat:

(module
 (rec
  (type $t1 (func))
  (type $t2 (func))
 )
 (tag $tag$0 (type $t1))
 (export "x" (tag $tag$0))
)

From the .wasm:

(module
 (type $0 (func))
 (tag $tag$0 (type $0))
 (export "x" (tag $tag$0))
)

Linking: with imp.wat = (module (rec (type $t1 (func)) (type $t2 (func))) (tag (import "m" "x") (type $t1))), instantiating imp.wasm with the tag exported by exp.wasm works in Node v26.13.0, but with the tag from wasm-opt --all-features exp.wasm -o out.wasm it fails:

WebAssembly.Instance(): Import #0 "m" "x": imported tag does not match the expected type

Tested with wasm-opt version 133 (version_133). On main (95a214d) the reader code is the same: readTagImport (src/wasm/wasm-binary.cpp:3303) and readTags (:5522) pass getSignatureByTypeIndex(...) to makeTag instead of the HeapType from getTypeByIndex(...).

Credit: https://ucsbplse.github.io/

主要言語
WebAssembly
スター
8.7k
フォーク
905
平均マージ
1日 23時間
マージ済み PR(30日)
86

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

WebAssembly/binaryen のほかの issue

WebAssembly/binaryen の issue をすべて見る

似ている issue

Compilers の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。