There isn't a single "correct" way, but this is an ideal case for an "external extractor", where you define your own logic as needed. Cranelift's use of ISLE has a bunch of examples of those -- grep for (extern extractor ...) -- including for some cases with constants predicated on types, etc. Or, if you need an input (say, width above), then a fallible constructor with an if-let is another option:
(decl is_all_ones_of_width (u64 u8) Unit)
(extern constructor is_all_ones_of_width is_all_ones_of_width)
(rule (lower (Ast.Or (Ast.Constant value width) a))
(if-let _ (is_all_ones_of_width value width))
...)
then define is_all_ones_of_width in your environment trait to return Some(()) if true or None if not.
This is exactly what I was looking for. Thanks Chris!
Colton has marked this topic as resolved.
Last updated: Dec 06 2025 at 07:03 UTC