StringLifting?
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
調査の方向性
既存の StringLowering pass と contexts.h から始め、代表的な WebAssembly ファイルで issue の --string-lowering-magic-imports のタイミングを再現します。import された externref 値が locals、globals、parameters、results、fields、tags を通じてどのように流れるかを追跡します。完了条件は、具体的で堅牢な lifting 設計を作成するか、追求しないという判断を文書化することです。
索引モデルが issue の本文から書いたものです。
説明
It would be nice to allow toolchains to emit magic JS string imports all the time, which would make the output immediately runnable in VMs. That would be instead of emitting stringref and letting Binaryen lower it. The benefit of stringref is that Binaryen can optimize strings (it has them in the IR), but in a debug build you don't need that, and just want to run the build. Right now, toolchains can do some work to emit either JS string imports or stringref, depending on build type (debug or optimized), but we could save them the effort if Binaryen could read JS string imports and turn them into optimizable stringref.
We already have a StringLowering pass that turns stringref into JS string imports, which works well, so we could have a StringLifting that does the inverse. However, the inverse problem is a lot harder, consider e.g.
(module
(import "\'" "foo" (global $string.foo externref))
(func $use
(local $temp externref)
(local.set $temp (global.get $string.foo))
)
)
We can turn that imported JS string into a string.const, but the type would change from externref to stringref, and no longer fit in the local.
The existing lowering pass handles this by just turning every stringref into externref, which is fine as the goal is to lower away all native wasm strings. But we can't do that in a lifting pass, as there might be legitimate and unrelated externref uses to keep.
Inferring the types to change (in locals, globals, params, results, struct and array fields, tags, etc. etc.) would be... challenging, and likely brittle.
If we used type imports this could work - toolchains would not use raw externref but something more specific. But that proposal is far off (phase 1), so toolchains can't depend on it.
We could use custom annotations instead. I looked a little into how that might work, but it seems like in contexts.h, where we get the annotations, we'd need to do something with them. That seems like a widespread and annoying change at the parsing level. Perhaps instead we could stash the annotations on the IR or on the side (like we do with debug info), and then a lifting pass could use that?
To be honest that doesn't seem very appealing either, both in terms of needed work on the Binaryen side, and toolchains - they'd need to add these annotations everywhere, and forgetting some annotation - say on some struct field - would lead to very odd errors.
As all of this is meant to save toolchains time, I looked at a huge 33MB wasm file from Java (the largest file I have that uses strings). Running --string-lowering-magic-imports (and reading and writing the binary) takes 14 seconds on my modest laptop - on a beefy machine it would be significantly faster. So we are talking single digits of seconds here, most likely. In that case, the benefit to toolchains seems pretty modest?
@tlively What are your thoughts here?
- 主要言語
- WebAssembly
- スター
- 8.6k
- フォーク
- 885
- 平均マージ
- 2日 1時間
- マージ済み PR(30日)
- 70
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
WebAssembly/binaryen のほかの issue
-
難易度 2/5 半日 初心者へのやさしさ 76/100
WebAssembly/binaryen#9018 · コメント 3 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
WebAssembly/binaryen#9123 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
WebAssembly/binaryen#9122 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
WebAssembly/binaryen#9086 · コメント 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
WebAssembly/binaryen#9038 · コメント 5 件 ·
WebAssembly/binaryen の issue をすべて見る
似ている issue
-
compiler/runtime
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
objectionary/eo#8869 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
EricSpencer00/Resilient#4824 · コメント 1 件 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
objectionary/jeo-maven-plugin#1758 ·
-
generics
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100