-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for syntactic simplifications #4579
Comments
@PetarMax Not familiar here - what explicitly counts as a clause / how is the numbering of clauses precisely defined? |
I am thinking of simplifications as follows:
where the |
I've implemented a prototype of this feature in Booster (runtimeverification/haskell-backend#4022). I've manually modified a I have one question for @Scott-Guest: do you know if the K compiler preserves the And another question for @PetarMax: what behavior you expecting when there are more than one syntactic clause? I.e. |
Left to right, yes please. |
Hmm, that's a good point - regardless of the current situation, it's very fragile to rely on At a minimum, we already do constant folding which could collapse the number of clauses. I'm not that familiar with the symbolic backends, so I don't know if this is feasible, but what about adding a special symbol? Something like
to mark
@PetarMax thoughts? |
As somebody who writes rules, I would expect to be able to refer to the specific clauses of the rule, in the specific order in which I write them. Before you start processing the clauses, you should be able to tag them and then process them tagged. The rules marked for syntactic matching will not disappear if written correctly by the user, and if written incorrectly... 🤷♂️ . For example, starting from:
you should be able to tag the first and third clause with an attribute of some kind indicating ordering in syntactic matching, say
and then work with them as such, permute, transmute, whatever you like. The backend would not have to receive them in order or think about order. It's not clear to me how your syntax would preserve the ordering in which the syntactic matching is to happen - perhaps we can work on that? |
My concern is that, as this attribute was originally proposed, "correctly" here means "in a way which won't trigger certain compiler optimizations / manipulations". Just on principle, we shouldn't be exposing compiler implementation details to the user - it can be finicky to reason about even in the relatively simple case of constant folding, and prone to breakage if the user does refactoring or if compiler internals change.
I definitely agree. The finickiness I mention above is solved by recording the information directly onto the expression itself, rather than non-locally as external meta-data that needs to be kept in-sync if the compiler manipulates the expression. However, KORE only supports attributes on sentences / declarations, not on sub-terms. Regardless of the difficulty of adding tagging infrastructure for sub-terms to the front-end (which AFAICT would require auditing the whole frontend pipeline), at the end of the day, our only option is to either change KORE or emit an actual symbol similar to what I proposed. We then have a few options:
2b) seems preferable over 2a). Otherwise, the backend needlessly has to care about ordering / do work to reconstruct info we already had in the frontend. I'm less certain about 1) versus 2b), and would be interested in your thoughts.
Ah I missed this part. We could update the syntax to also include an
Alternatively, we could even more broadly add syntax to name a sub-term like
where relevant attributes can then refer to names
Do you agree with my assessment? What're your thoughts on 1) vs 2b)? |
Yes, I agree. I would be happy with |
The idea with the
|
Yes, ok, understood. Do we have use cases other than |
Looking through the existing attributes, it doesn't appear broadly applicable - let's go with |
Yes please, thank you! While we-re doing this, could we please also add another simplification attribute,
Its meaning in the backnd would be that during its application we should not use the SMT solver. |
Thanks for the in-depth analysis @Scott-Guest and @PetarMax! We've discussed the proposal in the Haskell backend daily meeting with @jberthold and @goodlyrottenapple. Our consensus is that using inner syntax to drive a backend feature does not align well with K's design. Instead, the information regarding special treatment of parts of inner syntax should flow to the backend via attributes. This is already done for many cases such as the What happens inside the compiler is of course another story: we can have any sort of special-casing there, and we likely already do. With that in mind, one of the approaches @Scott-Guest suggests:
sounds suitable. @Scott-Guest what do you think? I'm happy to set-up a meeting to discuss this in more depth. |
@geo2a I don't really agree, but I'm happy to concede to the consensus. I'll open an initial PR adding I'll add the tagging under the hood to make it more robust in a follow-up PR. |
Thank you @Scott-Guest!
I don't think there's anything to do here, as rules like this:
are currently accepted and compiled as expected by |
Are they accepted even if the module that contains them is not marked as |
I have the PR just adding Presumably, the LLVM backend can't handle these syntactic simplifications, so wouldn't we want to only allow this in |
Yes, you are right, they belong only in |
No, I do not think we need anything. |
Part of #4579 Adds the `syntactic` attribute to the whitelist, and checks that it is only applied to simplification rules. Notably, we still need to: - Check that the arguments actually refer to existing clauses - Tag the underlying clauses and re-construct the attribute at the end of the compilation pipeline because the `requires` clauses may be manipulated during compilation
@geo2a @PetarMax @Scott-Guest can we close this issue now that #4597 has been merged, or is there anything else to it? |
@palinatolmach In the frontend, we still need to add tagging to track if the compiler modifies the term and update the attribute accordingly. I likely won't have time to get to this for awhile, so we can move this to the backlog. |
To improve the simplification mechanism of the backend, we require the addition of a
syntactic
attribute in simplifications, which takes a list of positive integers. These integers would then indicate to the backend that the corresponding clauses in therequires
should be checked only syntactically. Two examples of this would be:and
Note that, in the second example, there is a symbolic variable
Z
introduced in the first clause that is not present in the LHS. This appears to be supported by the front-end if the corresponding module is marked as[symbolic]
. Optionally, we would like such variables to be supported also if the clause in they first appear is marked as syntactic.The text was updated successfully, but these errors were encountered: