Skip to content

Commit

Permalink
Merge branch 'master' into remove-duplicated-checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbepop authored Dec 2, 2023
2 parents f7304a2 + 6abc951 commit 62252d1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 32 deletions.
4 changes: 2 additions & 2 deletions crates/wasmi/src/engine/translator/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator<'a> {
let provider_params = &mut self.alloc.buffer;
self.alloc.stack.pop_n(params.len(), provider_params);
let results = self.alloc.stack.push_dynamic_n(results.len())?;
let instr = match self.res.get_compiled_func_2(func_idx) {
let instr = match self.res.get_compiled_func(func_idx) {
Some(compiled_func) => {
// Case: We are calling an internal function and can optimize
// this case by using the special instruction for it.
Expand Down Expand Up @@ -700,7 +700,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator<'a> {
let params = func_type.params();
let provider_params = &mut self.alloc.buffer;
self.alloc.stack.pop_n(params.len(), provider_params);
let instr = match self.res.get_compiled_func_2(func_idx) {
let instr = match self.res.get_compiled_func(func_idx) {
Some(compiled_func) => {
// Case: We are calling an internal function and can optimize
// this case by using the special instruction for it.
Expand Down
20 changes: 4 additions & 16 deletions crates/wasmi/src/module/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct ModuleBuilder<'engine> {
pub globals_init: Vec<ConstExpr>,
pub exports: BTreeMap<Box<str>, ExternIdx>,
pub start: Option<FuncIdx>,
pub compiled_funcs_2: Vec<CompiledFunc>,
pub compiled_funcs: Vec<CompiledFunc>,
pub element_segments: Vec<ElementSegment>,
pub data_segments: Vec<DataSegment>,
}
Expand Down Expand Up @@ -103,19 +103,7 @@ impl<'a> ModuleResources<'a> {
let index = index.checked_sub(len_imported)?;
// Note: It is a bug if this index access is out of bounds
// therefore we panic here instead of using `get`.
Some(self.res.compiled_funcs_2[index])
}

/// Returns the [`CompiledFunc`] for the given [`FuncIdx`].
///
/// Returns `None` if [`FuncIdx`] refers to an imported function.
pub fn get_compiled_func_2(&self, func_idx: FuncIdx) -> Option<CompiledFunc> {
let index = func_idx.into_u32() as usize;
let len_imported = self.res.imports.len_funcs();
let index = index.checked_sub(len_imported)?;
// Note: It is a bug if this index access is out of bounds
// therefore we panic here instead of using `get`.
Some(self.res.compiled_funcs_2[index])
Some(self.res.compiled_funcs[index])
}

/// Returns the global variable type and optional initial value.
Expand Down Expand Up @@ -148,7 +136,7 @@ impl<'engine> ModuleBuilder<'engine> {
globals_init: Vec::new(),
exports: BTreeMap::new(),
start: None,
compiled_funcs_2: Vec::new(),
compiled_funcs: Vec::new(),
element_segments: Vec::new(),
data_segments: Vec::new(),
}
Expand Down Expand Up @@ -245,7 +233,7 @@ impl<'engine> ModuleBuilder<'engine> {
let func_type_idx = func?;
let func_type = self.func_types[func_type_idx.into_u32() as usize];
self.funcs.push(func_type);
self.compiled_funcs_2.push(self.engine.alloc_func());
self.compiled_funcs.push(self.engine.alloc_func());
}
Ok(())
}
Expand Down
17 changes: 5 additions & 12 deletions crates/wasmi/src/module/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,14 @@ mod block_type;
/// If the function body fails to validate.
pub fn translate<'parser>(
func: FuncIdx,
compiled_func_2: CompiledFunc,
compiled_func: CompiledFunc,
func_body: FunctionBody<'parser>,
validator: FuncValidator<ValidatorResources>,
res: ModuleResources<'parser>,
allocations: FuncTranslatorAllocations,
) -> Result<ReusableAllocations, ModuleError> {
FunctionTranslator::new(
func,
compiled_func_2,
func_body,
validator,
res,
allocations,
)?
.translate()
FunctionTranslator::new(func, compiled_func, func_body, validator, res, allocations)?
.translate()
}

/// Translates Wasm bytecode into `wasmi` bytecode for a single Wasm function.
Expand All @@ -52,14 +45,14 @@ impl<'parser> FunctionTranslator<'parser> {
/// Creates a new Wasm to `wasmi` bytecode function translator.
fn new(
func: FuncIdx,
compiled_func_2: CompiledFunc,
compiled_func: CompiledFunc,
func_body: FunctionBody<'parser>,
validator: FuncValidator<ValidatorResources>,
res: ModuleResources<'parser>,
allocations: FuncTranslatorAllocations,
) -> Result<Self, ModuleError> {
let func_builder =
ValidatingFuncTranslator::new(func, compiled_func_2, res, validator, allocations)?;
ValidatingFuncTranslator::new(func, compiled_func, res, validator, allocations)?;
Ok(Self {
func_body,
func_builder,
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl Module {
globals_init: builder.globals_init.into(),
exports: builder.exports,
start: builder.start,
compiled_funcs: builder.compiled_funcs_2.into(),
compiled_funcs: builder.compiled_funcs.into(),
element_segments: builder.element_segments.into(),
data_segments: builder.data_segments.into(),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/module/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ impl<'engine> ModuleParser<'engine> {
/// Returns the next `FuncIdx` for processing of its function body.
fn next_func(&mut self) -> (FuncIdx, CompiledFunc) {
let index = self.compiled_funcs;
let compiled_func_2 = self.builder.compiled_funcs_2[index as usize];
let compiled_func_2 = self.builder.compiled_funcs[index as usize];
self.compiled_funcs += 1;
// We have to adjust the initial func reference to the first
// internal function before we process any of the internal functions.
Expand Down

0 comments on commit 62252d1

Please sign in to comment.