Skip to content
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

Merged
merged 33 commits into from
Dec 3, 2019
Merged

new MINT module and polymorphic sort support #839

merged 33 commits into from
Dec 3, 2019

Conversation

dwightguth
Copy link
Collaborator

@dwightguth dwightguth commented Oct 10, 2019

Essentially, the design is as follows:

  • Instantiations of parametric sorts must be explicitly declared in order to be used in the frontend.
  • natural numbers are implicitly sorts, but they have no productions and simply serve as placeholders for actual natural numbers
  • sort inference picks the correct parameters for the widths based on the declared subsort relations, which are over parametrized sorts, not sort heads.
  • the kore generated has a concrete width for all axioms that use MINT symbols, and that width is a sort with a nat attribute specifying the width in bits that it corresponds to.
  • the MINT module has been substantially refactored in order to bring it stylistically into alignment with the rest of the frontend.

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.

/*@\section{Description} The MInt implements machine integers of arbitrary
* bit width represented in 2's complement. */

syntax {Width} MInt{Width} [hook(MINT.MInt)]
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

@dwightguth dwightguth changed the base branch from nopoly to master November 5, 2019 20:30
@dwightguth dwightguth marked this pull request as ready for review November 26, 2019 22:35
@ehildenb
Copy link
Member

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.

k-distribution/include/builtin/domains.k Show resolved Hide resolved
@@ -105,6 +105,9 @@ public K apply(KRewrite k) {

private int counter = 0;
KVariable newDotVariable(Sort s) {
if (s == null) {
s = Sorts.K();
}
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

@dwightguth
Copy link
Collaborator Author

@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.

@dwightguth
Copy link
Collaborator Author

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.

@dwightguth dwightguth requested a review from ttuegel November 27, 2019 21:53
Copy link
Contributor

@ttuegel ttuegel left a 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!

@yzhang90
Copy link
Contributor

yzhang90 commented Dec 2, 2019

I only reviewed ModuleToKore.java and it looks good to me.

@rv-jenkins rv-jenkins merged commit f041eae into master Dec 3, 2019
@rv-jenkins rv-jenkins deleted the polysort branch December 3, 2019 20:26
Baltoli pushed a commit that referenced this pull request Apr 9, 2024
Baltoli pushed a commit that referenced this pull request Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants