Stream: cranelift

Topic: ✔ ISLE compiler error when matching user-defined enum


view this post on Zulip Anton Kirilov (Aug 24 2022 at 19:26):

I wrote the following ISLE code (inside cranelift/codegen/src/isa/aarch64/inst.isle):

(type AModeNew
      (enum
        (RegOffset
         (rn Reg)
         (off i64)
         (ty Type))
))

(decl load_addr_new (AModeNew) Reg)
(rule (load_addr_new (AModeNew.RegOffset r 0 _)) (r))

and when I try to rebuild Cranelift, I get the following cryptic ISLE compiler error (which refers to the last line):

src/isa/aarch64/inst.isle:2545:1: type error: Unknown term in pattern: 'r'

The error message also suggests running:

cargo check -p cranelift-codegen --features isle-errors

but that doesn't help. It feels like I am missing something obvious, but I just can't figure out what; I would appreciate any suggestions.

view this post on Zulip Chris Fallin (Aug 24 2022 at 19:33):

@Anton Kirilov the "Unknown term in pattern" error is indicating that a "term" lookup (for the first symbol in a paren expression) failed; so I would expect source code like (r ...) to produce such an error (the r is the term here). I'm surprised it's picking up the r in the second position in that way. Do you have a branch (even just a WIP commit) somewhere I can reproduce this and play with it?

view this post on Zulip Chris Fallin (Aug 24 2022 at 19:34):

... oh, nevermind, I see it

view this post on Zulip Chris Fallin (Aug 24 2022 at 19:34):

the (r) in your right-hand side is the issue: it is invoking r as if it were a constructor

view this post on Zulip Chris Fallin (Aug 24 2022 at 19:34):

I think remove the parens around that and it'll work?

view this post on Zulip Chris Fallin (Aug 24 2022 at 19:35):

separately, this error message is I think the one that's firing and should say "Unknown term in expression" rather than "Unknown term in pattern"; that's part of the confusion here I think

A fast and secure runtime for WebAssembly. Contribute to bytecodealliance/wasmtime development by creating an account on GitHub.

view this post on Zulip Anton Kirilov (Aug 24 2022 at 19:39):

Indeed, it worked! Thanks a lot! My hunch that it was something obvious was correct, after all :smile:.

view this post on Zulip Chris Fallin (Aug 24 2022 at 19:41):

https://github.com/bytecodealliance/wasmtime/pull/4775 to fix the error message

This was likely a copy-paste from the ast::Pattern case, but here it is checking a term name in ast::Expr and so should say "... in expression", not "... in pattern".

view this post on Zulip Chris Fallin (Aug 24 2022 at 19:41):

thanks for asking here :-)

view this post on Zulip Anton Kirilov (Aug 24 2022 at 19:45):

However, I am not sure the updated error message would have helped - I guess I still have to wrap my head around the fact that I need to be careful with my usage of brackets.

view this post on Zulip Anton Kirilov (Aug 24 2022 at 19:48):

Or maybe it was just a long day :smile:.

view this post on Zulip Notification Bot (Aug 24 2022 at 19:48):

Anton Kirilov has marked this topic as resolved.

view this post on Zulip Chris Fallin (Aug 24 2022 at 20:13):

yeah, it is a bit of a case of "Lisp: use lots of parens, but not too many"

view this post on Zulip Chris Fallin (Aug 24 2022 at 20:13):

sorry about that :-)


Last updated: Dec 23 2024 at 13:07 UTC