From 0b72e1df5a03926b7f5762083f9610d610089778 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Sat, 11 May 2024 21:42:27 -0700 Subject: [PATCH] better asserts and errors in various places --- src/backend/mod.rs | 55 +++++++++++++++++++++++++++++++++------------- src/ir/func.rs | 4 ++-- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 7d1cdb2..9b6bcaa 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -153,21 +153,21 @@ impl<'a> WasmFuncBackend<'a> { } } } - WasmBlock::BlockParams { from, to } => { - debug_assert_eq!(from.len(), to.len()); - for (&from, &(_, to)) in from.iter().zip(to.iter()) { - if self.locals.values[to].is_empty() { - continue; - } - self.lower_value(from, func); - } - for &(_, to) in to.iter().rev() { - if self.locals.values[to].is_empty() { - continue; - } - self.lower_set_value(to, func); - } - } + // WasmBlock::BlockParams { from, to } => { + // debug_assert_eq!(from.len(), to.len()); + // for (&from, &(_, to)) in from.iter().zip(to.iter()) { + // if self.locals.values[to].is_empty() { + // continue; + // } + // self.lower_value(from, func); + // } + // for &(_, to) in to.iter().rev() { + // if self.locals.values[to].is_empty() { + // continue; + // } + // self.lower_set_value(to, func); + // } + // } WasmBlock::Return { values } => { for &value in &values[..] { self.lower_value(value, func); @@ -180,6 +180,31 @@ impl<'a> WasmFuncBackend<'a> { } func.instruction(&wasm_encoder::Instruction::ReturnCall(f.index() as u32)); } + WasmBlock::BlockParams { from, to } => { + debug_assert_eq!(from.len(), to.len()); + for (&from, &(to_ty, to)) in from.iter().zip(to.iter()) { + if self.locals.values[to].is_empty() { + continue; + } + let from_ty = self.body.values[self.body.resolve_alias(from)] + .ty(&self.body.type_pool) + .unwrap(); + assert_eq!(from_ty, to_ty); + if self.locals.values[from].len() == 1 { + assert_eq!(from_ty, self.locals.locals[self.locals.values[from][0]]); + } + self.lower_value(from, func); + } + for &(to_ty, to) in to.iter().rev() { + if self.locals.values[to].is_empty() { + continue; + } + if self.locals.values[to].len() == 1 { + assert_eq!(to_ty, self.locals.locals[self.locals.values[to][0]]); + } + self.lower_set_value(to, func); + } + } WasmBlock::ReturnCallIndirect { sig, table, values } => { for &value in &values[..] { self.lower_value(value, func); diff --git a/src/ir/func.rs b/src/ir/func.rs index ccbea77..7d63fcf 100644 --- a/src/ir/func.rs +++ b/src/ir/func.rs @@ -423,8 +423,8 @@ impl FunctionBody { let u = self.resolve_alias(u); if block_inst[u].is_none() { bad.push(format!( - "Use of arg {} at {:?} illegal: not defined", - u, inst + "Use of arg {} at {:?} in {} illegal: not defined", + u, inst, block )); return; }