From 922a3886d5c7ce39fcb5c8a029f68603ef941a18 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Tue, 28 Sep 2021 12:03:11 -0700 Subject: [PATCH] Fix `let` variable typing rules --- cranelift/isle/isle/src/sema.rs | 2 +- cranelift/isle/isle_examples/let.isle | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 cranelift/isle/isle_examples/let.isle diff --git a/cranelift/isle/isle/src/sema.rs b/cranelift/isle/isle/src/sema.rs index 61f19cd9d9..71491f84c6 100644 --- a/cranelift/isle/isle/src/sema.rs +++ b/cranelift/isle/isle/src/sema.rs @@ -1251,7 +1251,7 @@ impl TermEnv { }; // Evaluate the variable's value. - let val = Box::new(match self.translate_expr(tyenv, &def.val, ty, bindings) { + let val = Box::new(match self.translate_expr(tyenv, &def.val, tid, bindings) { Some(e) => e, None => { // Keep going for more errors. diff --git a/cranelift/isle/isle_examples/let.isle b/cranelift/isle/isle_examples/let.isle new file mode 100644 index 0000000000..c43d1ec668 --- /dev/null +++ b/cranelift/isle/isle_examples/let.isle @@ -0,0 +1,21 @@ +(type u32 (primitive u32)) +(type A (enum (Add (x u32) (y u32)) (Sub (x u32) (y u32)))) +(type B (enum (B (z u32)))) + +(decl Sub (u32 u32) u32) +(extern constructor Sub sub) + +(decl Add (u32 u32) u32) +(extern constructor Add add) + +(decl Lower (A) B) + +(rule + (Lower (A.Add x y)) + (let ((z u32 (Add x y))) + (B.B z))) + +(rule + (Lower (A.Sub x y)) + (let ((z u32 (Sub x y))) + (B.B z)))