Closed world optimization of wasm modules that have function types in import/export boundary
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 18/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- wasm
- Lĩnh vực
- compilers
Hướng nghiên cứu
Start from the repro in the issue: the module exports callForeignUninhabited and callForeignDevirtualized, which take function references from outside, and the bug appears when wasm-opt --closed-world --traps-never-happen --gufa runs on it. Trace how closed-world and GUFA decide which functions can reach a given type, since the wrong unreachable and devirtualized target both come from that. Done means the optimizer no longer assumes it knows every function of an externally passed signature, and the repro's call_ref sites keep their real targets. The maintainers have not yet settled the fix, so check the comments first.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Let's say we have a module that can be optimized under closed world assumptions but we want to export some functions that the outside can invoke and pass callbacks of a specific type in. Concretely:
(module
(type $sig1 (func (param i32 i64 f64) (result i32)))
(type $sig2 (func (param i32 i32 i64) (result i32)))
(func $unrelated (type $sig2) (param i32 i32 i64) (result i32)
(i32.const 12345)
)
(export "getUnrelated" (func $getUnrelated))
(func $getUnrelated (result (ref $sig2))
(ref.func $unrelated)
)
;; Takes a (ref $sig1) directly from outside and calls it.
(export "callForeignUninhabited" (func $callForeignUninhabited))
(func $callForeignUninhabited (param $fn (ref $sig1)) (param $a i32) (param $b i64) (param $c f64) (result i32)
(call_ref $sig1 (local.get $a) (local.get $b) (local.get $c) (local.get $fn))
)
;; Takes a (ref $sig2) directly from outside and calls it.
(export "callForeignDevirtualized" (func $callForeignDevirtualized))
(func $callForeignDevirtualized (param $fn (ref $sig2)) (param $a i32) (param $b i32) (param $c i64) (result i32)
(call_ref $sig2 (local.get $a) (local.get $b) (local.get $c) (local.get $fn))
)
)
If we compile this with
% wasm-opt -all --closed-world --traps-never-happen --gufa -Os -S repro.wat -o repro.opt.wat
we get
(module
(type $sig2 (func (param i32 i32 i64) (result i32)))
(type $sig1 (func (param i32 i64 f64) (result i32)))
(type $2 (func (result (ref $sig2))))
(type $3 (func (param (ref $sig1) i32 i64 f64) (result i32)))
(type $4 (func (param (ref $sig2) i32 i32 i64) (result i32)))
(elem declare func $unrelated)
(export "getUnrelated" (func $getUnrelated))
(export "callForeignUninhabited" (func $callForeignUninhabited))
(export "callForeignDevirtualized" (func $callForeignDevirtualized))
(func $unrelated (type $sig2) (param $0 i32) (param $1 i32) (param $2 i64) (result i32)
(unreachable)
)
(func $getUnrelated (type $2) (result (ref $sig2))
(ref.func $unrelated)
)
(func $callForeignUninhabited (type $3) (param $0 (ref $sig1)) (param $1 i32) (param $2 i64) (param $3 f64) (result i32)
(unreachable)
)
(func $callForeignDevirtualized (type $4) (param $0 (ref $sig2)) (param $1 i32) (param $2 i32) (param $3 i64) (result i32)
(i32.const 12345)
)
)
So the call_ref may either be turned into an unreachable trap or devirtualized to the wrong target.
I would assume that even under --closed-world assumptions, if binaryen sees that outside world passes a function reference in that it may pass a function from a different module in (i.e. that binaryen cannot assume it knows all functions of said signature type).
Note: For the other way around, where we take the reference of a wasm function defined in our module and pass it to the outside world, we can annotate it with the (binaryen.js-called) annotation and that will prevent binaryen from changing the function type. Isn't there a mechanism for the reverse: An outside function enters our module and we call it?
/cc @tlively @kripken Is this expected? Is there a way around this?
- Ngôn ngữ chính
- WebAssembly
- Star
- 8.7k
- Fork
- 893
- Merge trung bình
- 1 ngày 18 giờ
- Pull request đã merge (30 ngày)
- 95
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của WebAssembly/binaryen
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
WebAssembly/binaryen#9135 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 76/100
WebAssembly/binaryen#9018 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Memory64Lowering: table.get/table.set keep i64 index on lowered table64, output fails validationĐang mở
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 66/100
WebAssembly/binaryen#9245 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
WebAssembly/binaryen#9244 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 62/100
WebAssembly/binaryen#9243 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của WebAssembly/binaryen
Issue tương tự
-
IO.get_env on Node truncates names at embedded NULCó thể đã có người làm @Yi-111-a đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
HigherOrderCO/Bend#1449 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
grame-cncm/faust#1344 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
handsontable/hyperformula#1803 ·
Maintainer thường phản hồi trong vòng 1 ngày