Fix failing pipeline checks

This commit is contained in:
Dmitry Sinyavin
2022-07-26 11:38:58 +02:00
parent c55ea7bfb7
commit 8a552c033c
2 changed files with 30 additions and 30 deletions
+1 -3
View File
@@ -8,6 +8,4 @@ mod stack_limiter;
pub use export_globals::export_mutable_globals; pub use export_globals::export_mutable_globals;
pub use parity_wasm; pub use parity_wasm;
pub use stack_limiter::inject as inject_stack_limiter; pub use stack_limiter::{compute_stack_cost, compute_stack_costs, inject as inject_stack_limiter};
pub use stack_limiter::compute_stack_cost;
pub use stack_limiter::compute_stack_costs;
+29 -27
View File
@@ -145,8 +145,9 @@ pub fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, &'static
// Get globals to resove their types // Get globals to resove their types
let globals: Vec<ValueType> = if let Some(global_section) = module.global_section() { let globals: Vec<ValueType> = if let Some(global_section) = module.global_section() {
global_section.entries() global_section
.into_iter() .entries()
.iter()
.map(|g| g.global_type().content_type()) .map(|g| g.global_type().content_type())
.collect() .collect()
} else { } else {
@@ -155,13 +156,10 @@ pub fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, &'static
let locals: Vec<ValueType> = func_signature let locals: Vec<ValueType> = func_signature
.params() .params()
.into_iter() .iter()
.cloned() .cloned()
.chain( .chain(body.locals().iter().flat_map(|l| vec![l.value_type(); l.count() as usize]))
body.locals() .collect();
.iter()
.flat_map(|l| vec![l.value_type(); l.count() as usize])
).collect();
let mut stack = Stack::new(); let mut stack = Stack::new();
let mut max_weight: u32 = 0; let mut max_weight: u32 = 0;
@@ -170,12 +168,9 @@ pub fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, &'static
// Add implicit frame for the function. Breaks to this frame and execution of // Add implicit frame for the function. Breaks to this frame and execution of
// the last end should deal with this frame. // the last end should deal with this frame.
let func_results = func_signature.results(); let func_results = func_signature.results();
let param_weight: u32 = func_signature let param_weight: u32 = func_signature.params().iter().map(|v| value_cost(*v)).sum();
.params().iter()
.map(|v| value_cost(*v))
.sum();
let func_result_type = if func_results.len() == 0 { None } else { Some(func_results[0]) }; let func_result_type = if func_results.is_empty() { None } else { Some(func_results[0]) };
stack.push_frame(Frame { stack.push_frame(Frame {
is_polymorphic: false, is_polymorphic: false,
@@ -222,7 +217,7 @@ pub fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, &'static
}, },
Br(target) => { Br(target) => {
// Pop values for the destination block result. // Pop values for the destination block result.
if let Some(_) = stack.frame(*target)?.branch_type { if stack.frame(*target)?.branch_type.is_some() {
stack.pop_value()?; stack.pop_value()?;
} }
@@ -283,7 +278,7 @@ pub fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, &'static
// Push result of the function execution to the stack. // Push result of the function execution to the stack.
let callee_results = ty.results(); let callee_results = ty.results();
if callee_results.len() > 0 { if !callee_results.is_empty() {
stack.push_value(callee_results[0])?; stack.push_value(callee_results[0])?;
} }
}, },
@@ -301,7 +296,7 @@ pub fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, &'static
// Push result of the function execution to the stack. // Push result of the function execution to the stack.
let callee_results = ty.results(); let callee_results = ty.results();
if callee_results.len() > 0 { if !callee_results.is_empty() {
stack.push_value(callee_results[0])?; stack.push_value(callee_results[0])?;
} }
}, },
@@ -402,10 +397,18 @@ pub fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, &'static
stack.push_value(ValueType::I32)?; stack.push_value(ValueType::I32)?;
}, },
I32Const(_) => { stack.push_value(ValueType::I32)?; }, I32Const(_) => {
I64Const(_) => { stack.push_value(ValueType::I64)?; }, stack.push_value(ValueType::I32)?;
F32Const(_) => { stack.push_value(ValueType::F32)?; }, },
F64Const(_) => { stack.push_value(ValueType::F64)?; }, I64Const(_) => {
stack.push_value(ValueType::I64)?;
},
F32Const(_) => {
stack.push_value(ValueType::F32)?;
},
F64Const(_) => {
stack.push_value(ValueType::F64)?;
},
I32Eqz | I64Eqz => { I32Eqz | I64Eqz => {
// These instructions pop the value and compare it against zero, and pushes // These instructions pop the value and compare it against zero, and pushes
@@ -458,14 +461,14 @@ pub fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, &'static
stack.pop_value()?; stack.pop_value()?;
stack.push_value(ValueType::I64)?; stack.push_value(ValueType::I64)?;
}, },
F32ConvertSI32 | F32ConvertUI32 | F32ConvertSI64 | F32ConvertUI64 | F32ConvertSI32 | F32ConvertUI32 | F32ConvertSI64 | F32ConvertUI64 | F32DemoteF64 |
F32DemoteF64 | F32ReinterpretI32 => { F32ReinterpretI32 => {
stack.pop_value()?; stack.pop_value()?;
stack.push_value(ValueType::F32)?; stack.push_value(ValueType::F32)?;
}, },
F64ConvertSI32 | F64ConvertUI32 | F64ConvertSI64 | F64ConvertUI64 | F64ConvertSI32 | F64ConvertUI32 | F64ConvertSI64 | F64ConvertUI64 | F64PromoteF32 |
F64PromoteF32 | F64ReinterpretI64 => { F64ReinterpretI64 => {
stack.pop_value()?; stack.pop_value()?;
stack.push_value(ValueType::F64)?; stack.push_value(ValueType::F64)?;
}, },
@@ -475,11 +478,10 @@ pub fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, &'static
SignExt(SignExtInstruction::I32Extend16S) | SignExt(SignExtInstruction::I32Extend16S) |
SignExt(SignExtInstruction::I64Extend8S) | SignExt(SignExtInstruction::I64Extend8S) |
SignExt(SignExtInstruction::I64Extend16S) | SignExt(SignExtInstruction::I64Extend16S) |
SignExt(SignExtInstruction::I64Extend32S) => { SignExt(SignExtInstruction::I64Extend32S) =>
if let Some(vt) = stack.pop_value()? { if let Some(vt) = stack.pop_value()? {
stack.push_value(vt)?; stack.push_value(vt)?;
} },
},
} }
// If current value stack is heavier than maximal weight observed so far, // If current value stack is heavier than maximal weight observed so far,