-
Notifications
You must be signed in to change notification settings - Fork 151
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
new MINT module and polymorphic sort support #839
Conversation
24d175d
to
55b85d2
Compare
/*@\section{Description} The MInt implements machine integers of arbitrary | ||
* bit width represented in 2's complement. */ | ||
|
||
syntax {Width} MInt{Width} [hook(MINT.MInt)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parameterization should be fine for the Haskell backend, but what will Width
be instantiated with in practice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference, here is a subset of a K definition I wrote for testing purposes that uses the MINT module:
module TEST
imports MINT
syntax MInt{8}
syntax Number ::= Int | MInt{8}
syntax AExp ::= Number
| AExp "+" AExp [strict]
syntax KResult ::= MInt{8}
rule I:Int => Int2Signed(I)::MInt{8}
rule I + J => I +MInt J
endmodule
In this case the frontend treats 8 like a sort, but the kore generation will generate a sort declaration containing an attribute annotating the sort with its corresponding bitwidth, which the backend will understand. This is basically just a workaround until we reach the point where we can have natural numbers as parameters of sorts.
This is a pretty huge change, is there a reasonable way to separate it out into 2 or 3 PRs? Would make reviewing it easier. |
@@ -105,6 +105,9 @@ public K apply(KRewrite k) { | |||
|
|||
private int counter = 0; | |||
KVariable newDotVariable(Sort s) { | |||
if (s == null) { | |||
s = Sorts.K(); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Encoding null
with some sort of information seems odd to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is already to a certain extent how the sort injection pass deals with there not being an expected sort. We could probably make it an optional instead, but it really doesn't get a lot better by doing so. I'm going to leave this as is and someone can refactor the whole thing later if they want to.
@ehildenb we could probably break out the changes to the AST and the parser from the changes to kore generation, but it wouldn't make the first of those two PRs very much smaller and then we wouldn't have any test for it. Do you still want me to? I'm not sure it's going to be possible to separate the changes to the parser from the changes to the AST, because they very much go hand in hand. |
With that being said, if you look at the commits one at a time, it should give you a pretty good idea of the evolution of changes required; I can try to refactor the history some so that it's more concise before you do that if you want though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generated Kore looks good to me!
I only reviewed ModuleToKore.java and it looks good to me. |
Co-authored-by: devops <[email protected]>
Co-authored-by: devops <[email protected]>
Essentially, the design is as follows:
nat
attribute specifying the width in bits that it corresponds to.Code passes all tests and seems to generate the right kore when I inspect it manually, but the backend isn't implemented yet so we can't actually run anything or build an llvm backend interpreter yet. That will come in a pr to the backend next.