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

Hotfix sortk equality issue #4074

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions booster/library/Booster/Syntax/Json/Internalise.hs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,11 @@ internalisePred allowAlias checkSubsorts sortVars definition@KoreDefinition{sort
else case sortOfTerm v of
Internal.SortInt ->
pure [BoolPred $ Internal.Predicate $ Internal.NotBool $ Internal.EqualsInt (Internal.Var k) v]
Internal.SortK ->
pure
[ BoolPred . Internal.Predicate . Internal.NotBool $
Internal.EqualsK (Internal.Var k) v
]
otherSort ->
pure
[ BoolPred $
Expand Down Expand Up @@ -630,6 +635,9 @@ internalisePred allowAlias checkSubsorts sortVars definition@KoreDefinition{sort
pure [SubstitutionPred x t]
(Internal.SortInt, _, _) ->
pure [BoolPred $ Internal.Predicate $ Internal.EqualsInt a b]
(Internal.SortK, _, _) ->
-- already SortK, so we must not apply the KSeq wrapper pattern
pure [BoolPred $ Internal.Predicate $ Internal.EqualsK a b]
(otherSort, _, _) ->
pure
[ BoolPred $
Expand Down
30 changes: 30 additions & 0 deletions booster/test/rpc-integration/resources/subk.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module SUBK
imports BOOL
imports K-EQUAL

syntax State ::= "ping" [token]
| "pong" [token]
| "peng" [token]

configuration <k> $PGM:State ~> .K </k>
<x> .K </x>

syntax State ::= f ( State ) [function]

syntax K ::= inK ( State) [function, total]

rule f(ping) => ping
rule f(pong) => pong
// f is not total

rule inK(STATE) => STATE ~> .K

rule [ping]: <k> ping => f(pong) ... </k>
<x> X </x>
requires notBool (X ==K inK(ping))

rule [pong]: <k> pong => f(ping) ... </k>
<x> X </x>
requires notBool (X ==K inK(pong))

endmodule
2,284 changes: 2,284 additions & 0 deletions booster/test/rpc-integration/resources/subk.kore

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions booster/test/rpc-integration/test-subk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Tests involving K sequences
---------------------------

The [definition `subk.k`](../resources/subk.k) for these tests rewrites `ping` to `pong` and vice-versa, while checking a second configuration cell to not contain a K sequence with the same state at the head.
In addition, the rewrite rules use a partial identity function on states, such that all rewrites will fall back to kore-rpc.

Interestingly, it is forbidden by `kompile` to use `A ~> .K` as a direct child of `==K`. However, functions that produce this expression are apparently fine.

* `sortk-var-branch.execute`: branches on whether the additional cell contains `ping` or not. If it contains `ping`, the state is stuck.
* `sortk-stuck.execute`: the additional cell is initialised with `pong`. Therefore, the rule `pong => ping` cannot be applied, the result is stuck.
* `sortk-equal.simplify`: simplify request for a predicate involving `==K` on arguments of sort `K`.

* `not-subsort.execute`: expects an error saying that `SortK` is not subsort of `SortKItem`.
111 changes: 111 additions & 0 deletions booster/test/rpc-integration/test-subk/response-sortk-equal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"state": {
"format": "KORE",
"version": 1,
"term": {
"tag": "Not",
"sort": {
"tag": "SortApp",
"name": "SortGeneratedTopCell",
"args": []
},
"arg": {
"tag": "Equals",
"argSort": {
"tag": "SortApp",
"name": "SortK",
"args": []
},
"sort": {
"tag": "SortApp",
"name": "SortGeneratedTopCell",
"args": []
},
"first": {
"tag": "App",
"name": "kseq",
"sorts": [],
"args": [
{
"tag": "App",
"name": "inj",
"sorts": [
{
"tag": "SortApp",
"name": "SortState",
"args": []
},
{
"tag": "SortApp",
"name": "SortKItem",
"args": []
}
],
"args": [
{
"tag": "EVar",
"sort": {
"tag": "SortApp",
"name": "SortState",
"args": []
},
"name": "STATE1"
}
]
},
{
"tag": "App",
"name": "dotk",
"sorts": [],
"args": []
}
]
},
"second": {
"tag": "App",
"name": "kseq",
"sorts": [],
"args": [
{
"tag": "App",
"name": "inj",
"sorts": [
{
"tag": "SortApp",
"name": "SortState",
"args": []
},
{
"tag": "SortApp",
"name": "SortKItem",
"args": []
}
],
"args": [
{
"tag": "DV",
"value": "init",
"sort": {
"tag": "SortApp",
"name": "SortState",
"args": []
}
}
]
},
{
"tag": "App",
"name": "dotk",
"sorts": [],
"args": []
}
]
}
}
}
}
}
}
131 changes: 131 additions & 0 deletions booster/test/rpc-integration/test-subk/response-sortk-stuck.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"reason": "stuck",
"depth": 1,
"state": {
"term": {
"format": "KORE",
"version": 1,
"term": {
"tag": "App",
"name": "Lbl'-LT-'generatedTop'-GT-'",
"sorts": [],
"args": [
{
"tag": "App",
"name": "Lbl'-LT-'k'-GT-'",
"sorts": [],
"args": [
{
"tag": "App",
"name": "kseq",
"sorts": [],
"args": [
{
"tag": "App",
"name": "inj",
"sorts": [
{
"tag": "SortApp",
"name": "SortState",
"args": []
},
{
"tag": "SortApp",
"name": "SortKItem",
"args": []
}
],
"args": [
{
"tag": "DV",
"sort": {
"tag": "SortApp",
"name": "SortState",
"args": []
},
"value": "pong"
}
]
},
{
"tag": "App",
"name": "dotk",
"sorts": [],
"args": []
}
]
}
]
},
{
"tag": "App",
"name": "Lbl'-LT-'x'-GT-'",
"sorts": [],
"args": [
{
"tag": "App",
"name": "kseq",
"sorts": [],
"args": [
{
"tag": "App",
"name": "inj",
"sorts": [
{
"tag": "SortApp",
"name": "SortState",
"args": []
},
{
"tag": "SortApp",
"name": "SortKItem",
"args": []
}
],
"args": [
{
"tag": "DV",
"sort": {
"tag": "SortApp",
"name": "SortState",
"args": []
},
"value": "pong"
}
]
},
{
"tag": "App",
"name": "dotk",
"sorts": [],
"args": []
}
]
}
]
},
{
"tag": "App",
"name": "Lbl'-LT-'generatedCounter'-GT-'",
"sorts": [],
"args": [
{
"tag": "EVar",
"name": "COUNTER",
"sort": {
"tag": "SortApp",
"name": "SortInt",
"args": []
}
}
]
}
]
}
}
}
}
}
Loading
Loading