ISLE: Allow shadowing in let expressions (#4562)
* Support shadowing in isle * Re-run the isle build.rs if the examples change * Print error messages when isle tests fail * Move run tests * Refactor `let` uses that don't need to introduce unique names
This commit is contained in:
38
cranelift/isle/isle/isle_examples/run/let_shadowing.isle
Normal file
38
cranelift/isle/isle/isle_examples/run/let_shadowing.isle
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
(type u64 (primitive u64))
|
||||
|
||||
(decl foo (u64) u64)
|
||||
(rule (foo x) x)
|
||||
|
||||
;; Shadowing of a global name
|
||||
(decl test1 (u64) u64)
|
||||
(rule (test1 x)
|
||||
(let ((foo u64 x))
|
||||
foo))
|
||||
|
||||
;; Shadowing of a parameter
|
||||
(decl test2 (u64) u64)
|
||||
(rule (test2 x)
|
||||
(let ((x u64 x))
|
||||
x))
|
||||
|
||||
;; Shadowing of this binding's name
|
||||
(decl test3 (u64) u64)
|
||||
(rule (test3 x)
|
||||
(let ((test3 u64 x))
|
||||
test3))
|
||||
|
||||
;; Shadowing another let-bound name
|
||||
(decl test4 (u64) u64)
|
||||
(rule (test4 x)
|
||||
(let ((val u64 x)
|
||||
(val u64 23))
|
||||
val))
|
||||
|
||||
;; Shadowing a global with a parameter name
|
||||
(decl test5 (u64) u64)
|
||||
(rule (test5 foo) foo)
|
||||
|
||||
;; Using a previously shadowed global
|
||||
(decl test6 (u64) u64)
|
||||
(rule (test6 x) (foo x))
|
||||
27
cranelift/isle/isle/isle_examples/run/let_shadowing_main.rs
Normal file
27
cranelift/isle/isle/isle_examples/run/let_shadowing_main.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
mod let_shadowing;
|
||||
|
||||
struct Context;
|
||||
|
||||
impl let_shadowing::Context for Context {}
|
||||
|
||||
fn main() {
|
||||
let mut ctx = Context;
|
||||
|
||||
assert_eq!(Some(20), let_shadowing::constructor_test1(&mut ctx, 20));
|
||||
assert_eq!(Some(97), let_shadowing::constructor_test1(&mut ctx, 97));
|
||||
|
||||
assert_eq!(Some(20), let_shadowing::constructor_test2(&mut ctx, 20));
|
||||
assert_eq!(Some(97), let_shadowing::constructor_test2(&mut ctx, 97));
|
||||
|
||||
assert_eq!(Some(20), let_shadowing::constructor_test3(&mut ctx, 20));
|
||||
assert_eq!(Some(97), let_shadowing::constructor_test3(&mut ctx, 97));
|
||||
|
||||
assert_eq!(Some(23), let_shadowing::constructor_test4(&mut ctx, 20));
|
||||
assert_eq!(Some(23), let_shadowing::constructor_test4(&mut ctx, 97));
|
||||
|
||||
assert_eq!(Some(20), let_shadowing::constructor_test5(&mut ctx, 20));
|
||||
assert_eq!(Some(97), let_shadowing::constructor_test5(&mut ctx, 97));
|
||||
|
||||
assert_eq!(Some(20), let_shadowing::constructor_test6(&mut ctx, 20));
|
||||
assert_eq!(Some(97), let_shadowing::constructor_test6(&mut ctx, 97));
|
||||
}
|
||||
Reference in New Issue
Block a user