From e5a34e8af63fcf89a6eb332b6bf9b6ee92f8a03d Mon Sep 17 00:00:00 2001 From: Sam Estep Date: Mon, 7 Aug 2023 09:50:11 -0400 Subject: [PATCH] Remove redundant `index` type from `Expr::For` (#66) --- crates/core/src/lib.rs | 4 +--- crates/frontend/src/translate.rs | 1 - crates/interp/src/lib.rs | 9 ++------- crates/web/src/lib.rs | 24 ++++++++---------------- 4 files changed, 11 insertions(+), 27 deletions(-) diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 1162bf6..5004798 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -155,9 +155,7 @@ pub enum Expr { args: Box<[id::Var]>, }, For { - /// Must satisfy `Constraint::Index`. - index: id::Ty, - /// has type `index`. + /// Type must satisfy `Constraint::Index`. arg: id::Var, body: Box<[Instr]>, /// Variable from `body` holding an array element. diff --git a/crates/frontend/src/translate.rs b/crates/frontend/src/translate.rs index 8d0db5b..ed0a4a6 100644 --- a/crates/frontend/src/translate.rs +++ b/crates/frontend/src/translate.rs @@ -341,7 +341,6 @@ impl<'input, 'a> BlockCtx<'input, 'a> { Ok(self.instr( v, ir::Expr::For { - index: i, arg, body, ret: elem, diff --git a/crates/interp/src/lib.rs b/crates/interp/src/lib.rs index 37f9ec9..866aa2b 100644 --- a/crates/interp/src/lib.rs +++ b/crates/interp/src/lib.rs @@ -231,13 +231,8 @@ impl<'a, F: FuncNode> Interpreter<'a, F> { let vals = args.iter().map(|id| self.vars[id.var()].clone().unwrap()); call(self.f.get(*id).unwrap(), self.typemap, &resolved, vals) } - Expr::For { - index, - arg, - body, - ret, - } => { - let n = match self.typemap[self.types[index.ty()].ty()] { + Expr::For { arg, body, ret } => { + let n = match self.typemap[self.types[self.f.def().vars[arg.var()].ty()].ty()] { Ty::Fin { size } => size, _ => unreachable!(), }; diff --git a/crates/web/src/lib.rs b/crates/web/src/lib.rs index c31d083..943fc0d 100644 --- a/crates/web/src/lib.rs +++ b/crates/web/src/lib.rs @@ -134,13 +134,13 @@ pub fn pprint(f: &Func) -> Result { print_elems(s, 'x', args.iter().map(|arg| arg.var()))?; writeln!(&mut s, ")")?; } - rose::Expr::For { - index, - arg, - body, - ret, - } => { - writeln!(&mut s, "for x{}: T{} {{", arg.var(), index.ty())?; + rose::Expr::For { arg, body, ret } => { + writeln!( + &mut s, + "for x{}: T{} {{", + arg.var(), + def.vars[arg.var()].ty() + )?; print_block(s, def, spaces + 2, body, *ret)?; for _ in 0..spaces { write!(&mut s, " ")?; @@ -768,14 +768,7 @@ impl Context { // `rose::Expr::For` #[wasm_bindgen] - pub fn arr( - &mut self, - b: &mut Block, - index: usize, - arg: usize, - body: Block, - out: usize, - ) -> usize { + pub fn arr(&mut self, b: &mut Block, arg: usize, body: Block, out: usize) -> usize { let arg = id::var(arg); let ret = id::var(out); let ty = self.ty(rose::Ty::Array { @@ -783,7 +776,6 @@ impl Context { elem: self.get(ret), }); let expr = rose::Expr::For { - index: id::ty(index), arg, body: body.code.into(), ret,