Skip to content

Allow macros on hooked sorts#2489

Merged
rv-jenkins merged 4 commits intoruntimeverification:masterfrom
SchmErik:allow-macro-on-hooked-sorts
Mar 22, 2022
Merged

Allow macros on hooked sorts#2489
rv-jenkins merged 4 commits intoruntimeverification:masterfrom
SchmErik:allow-macro-on-hooked-sorts

Conversation

@SchmErik
Copy link
Copy Markdown
Contributor

@SchmErik SchmErik commented Mar 17, 2022

The previous implementation of macros on productions forgot to account for
macros on hooked sorts. This led kompile to assume that macro productions on
hooked sorts implied that the productions were constructors. Code like this

syntax Int ::= "LABEL" [macro]
rule LABEL => 4 // or some other number

would result in errors like this:

$ kompile test.k
[Error] Compiler: Cannot add new constructors to hooked sort Int

However, "LABEL" in this case is not a constructor but a term that
would be translated to 4 during compilation so this error is not
applicable to productions that are macros. This change add changes to
the CheckAtt class to allow macros on hooked sorts.

Fixes: #2488

Erik Kaneda added 3 commits March 17, 2022 14:38
The previous implementation of macros on productions forgot to account for
macros on hooked sorts. This led kompile to assume that macro productions on
hooked sorts implied that the productions were constructors. Code like this

```
syntax Int ::= "LABEL" [macro]
rule LABEL => 4 // or some other number
```
would result in errors like this:

```
$ kompile test.k
[Error] Compiler: Cannot add new constructors to hooked sort Int
```

However, `"LABEL"` in this case is not a constructor but a term that
would be translated to `4` during compilation so this error is not
applicable to productions that are macros. This change add changes to
the CheckAtt class to allow macros on hooked sorts.
if (sortAtt.contains(Att.HOOK()) && !sortAtt.get(Att.HOOK()).equals("ARRAY.Array") && !(sortAtt.get(Att.HOOK()).equals("KVAR.KVar") && isSymbolicKast)) {
if (!prod.att().contains(Att.FUNCTION()) && !prod.att().contains(Att.BRACKET()) &&
!prod.att().contains("token") && !(prod.klabel().isDefined() && macros.contains(prod.klabel().get()))) {
!prod.att().contains("token") && !prod.att().contains("macro") && !(prod.klabel().isDefined() && macros.contains(prod.klabel().get()))) {
Copy link
Copy Markdown
Contributor

@Baltoli Baltoli Mar 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a change to this specific PR (which looks good to me), but it would be nice in general to have this kind of deeply nested / long chain code factored out into a helper method with a comment explaining the logic. Perhaps it would be worth someone spending some time on the API design of the frontend to make this kind of code easier to write

Copy link
Copy Markdown
Contributor

@Baltoli Baltoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@rv-jenkins rv-jenkins merged commit 44d1f82 into runtimeverification:master Mar 22, 2022
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.

[Bug] kompile should allow macro productions on hooked sort

3 participants