From ddc2ce808060473a5433db3199fdf80fe54f6111 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Thu, 18 Jun 2020 09:39:30 -0700 Subject: [PATCH] cranelift-wasm: Make `FuncEnvironment::translate_ref_func` take a `FuncIndex` It was previously taking a raw `u32`. This change makes it more clear what index space that index points into. --- cranelift/wasm/src/code_translator.rs | 3 ++- cranelift/wasm/src/environ/dummy.rs | 2 +- cranelift/wasm/src/environ/spec.rs | 6 +++++- crates/environ/src/func_environ.rs | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cranelift/wasm/src/code_translator.rs b/cranelift/wasm/src/code_translator.rs index 4baa7847b4cf..b2df7bb85381 100644 --- a/cranelift/wasm/src/code_translator.rs +++ b/cranelift/wasm/src/code_translator.rs @@ -1045,7 +1045,8 @@ pub fn translate_operator( state.push1(environ.translate_ref_is_null(builder.cursor(), value)?); } Operator::RefFunc { function_index } => { - state.push1(environ.translate_ref_func(builder.cursor(), *function_index)?); + let index = FuncIndex::from_u32(*function_index); + state.push1(environ.translate_ref_func(builder.cursor(), index)?); } Operator::AtomicNotify { .. } | Operator::I32AtomicWait { .. } diff --git a/cranelift/wasm/src/environ/dummy.rs b/cranelift/wasm/src/environ/dummy.rs index ca58b77158d1..76e47da91d1a 100644 --- a/cranelift/wasm/src/environ/dummy.rs +++ b/cranelift/wasm/src/environ/dummy.rs @@ -516,7 +516,7 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ fn translate_ref_func( &mut self, mut pos: FuncCursor, - _func_index: u32, + _func_index: FuncIndex, ) -> WasmResult { Ok(pos.ins().null(self.reference_type())) } diff --git a/cranelift/wasm/src/environ/spec.rs b/cranelift/wasm/src/environ/spec.rs index 8e85d49dfe8f..3f7d439be60d 100644 --- a/cranelift/wasm/src/environ/spec.rs +++ b/cranelift/wasm/src/environ/spec.rs @@ -456,7 +456,11 @@ pub trait FuncEnvironment: TargetEnvironment { } /// Translate a `ref.func` WebAssembly instruction. - fn translate_ref_func(&mut self, pos: FuncCursor, func_index: u32) -> WasmResult; + fn translate_ref_func( + &mut self, + pos: FuncCursor, + func_index: FuncIndex, + ) -> WasmResult; /// Translate a `global.get` WebAssembly instruction at `pos` for a global /// that is custom. diff --git a/crates/environ/src/func_environ.rs b/crates/environ/src/func_environ.rs index 3a51e838b23a..612a6f9bd556 100644 --- a/crates/environ/src/func_environ.rs +++ b/crates/environ/src/func_environ.rs @@ -687,7 +687,7 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m fn translate_ref_func( &mut self, _: cranelift_codegen::cursor::FuncCursor<'_>, - _: u32, + _: FuncIndex, ) -> WasmResult { Err(WasmError::Unsupported( "the `ref.func` instruction is not supported yet".into(),