From 6656acc149bc1b2baba32cd4fd24c1fdae7475c4 Mon Sep 17 00:00:00 2001 From: Lukas Lihotzki Date: Mon, 22 May 2023 17:19:21 +0200 Subject: [PATCH] Use `table.fill` in externref-xform (`TODO`) --- crates/externref-xform/src/lib.rs | 15 ++++----------- crates/externref-xform/tests/anyref-param.wat | 3 ++- crates/externref-xform/tests/mixed-export.wat | 3 ++- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/crates/externref-xform/src/lib.rs b/crates/externref-xform/src/lib.rs index ab9ee589173..faa2b1ac1ca 100644 --- a/crates/externref-xform/src/lib.rs +++ b/crates/externref-xform/src/lib.rs @@ -652,19 +652,12 @@ impl Transform<'_> { // Note that we pave over all our stack slots with `ref.null` to ensure // that the table doesn't accidentally hold a strong reference to items // no longer in use by our wasm instance. - // - // TODO: use `table.fill` once that's spec'd if externref_stack > 0 { - for i in 0..externref_stack { - body.local_get(fp); - if i > 0 { - body.i32_const(i).binop(BinaryOp::I32Add); - } - body.ref_null(ValType::Externref); - body.table_set(self.table); - } - body.local_get(fp) + .ref_null(ValType::Externref) + .i32_const(externref_stack) + .table_fill(self.table) + .local_get(fp) .i32_const(externref_stack) .binop(BinaryOp::I32Add) .global_set(self.stack_pointer); diff --git a/crates/externref-xform/tests/anyref-param.wat b/crates/externref-xform/tests/anyref-param.wat index 02e1eb4c050..715d908e892 100644 --- a/crates/externref-xform/tests/anyref-param.wat +++ b/crates/externref-xform/tests/anyref-param.wat @@ -25,7 +25,8 @@ call $foo local.get 1 ref.null extern - table.set 0 + i32.const 1 + table.fill 0 local.get 1 i32.const 1 i32.add diff --git a/crates/externref-xform/tests/mixed-export.wat b/crates/externref-xform/tests/mixed-export.wat index e1ed4014c42..02327414562 100644 --- a/crates/externref-xform/tests/mixed-export.wat +++ b/crates/externref-xform/tests/mixed-export.wat @@ -34,7 +34,8 @@ call $a local.get 5 ref.null extern - table.set 0 + i32.const 1 + table.fill 0 local.get 5 i32.const 1 i32.add