Skip to content

Conversation

@jberthold
Copy link
Member

Sort predicates in K (isMySort : KItem -> Bool) only match on the sort injection of the argument into KItem.

Paraphrased:

rule isMySort(inj{MySort,KItem}(VAR)) => true
rule isMySort(         VAR          ) => false [owise]

Therefore, the result is wrong in the presence of a function that may return a super-sort of the target sort.

  syntax SuperSort ::= MySort | SomethingElse
  syntax SuperSort ::= f ( Int ) [function, total]

leads to a wrong matching result for a term isMySort(f(0)), which in kore would be LblisMySort(kseq{}(inj{SortSuperSort{},SortKItem{}}(Lblf{}(\dv{SortInt}("0"))),dotk{}())).

The matching routine would report a failed match due to the sorts being different in the sort injections. However, the sort injection would change as soon as f(0) gets evaluated (to an A:MySort).

See added test for an example K program going wrong without the fix.

The PR changes the evaluation routine to return an indeterminate match in case it detects a sort predicate applied to a function call. The iterative evaluation will (bottom-up) evaluate the function call in the next round and is ultimately able to evaluate the predicate.

Fixes #4132

Sort predicates in K (`isMySort : KItem -> Bool`) only match on the
sort injection of the argument into `KItem`.

Paraphrased:
```
rule isMySort(inj{MySort,KItem}(VAR)) => true
rule isMySort(         VAR          ) => false [owise]
```

Therefore, the result is wrong in the presence of a function that may
return a super-sort of the target sort.

```
  syntax SuperSort ::= MySort | SomethingElse
  syntax SuperSort ::= f ( Int ) [function, total]
```

leads to a wrong matching result for a term `isMySort(f(0))`, which in kore would be
`LblisMySort(kseq{}(inj{SortSuperSort{},SortKItem{}}(Lblf{}(\dv{SortInt}("0"))),dotk{}()))`.

The matching routine would report a failed match due to the sorts
being different in the sort injections. However, the sort injection
would change as soon as f(0) gets evaluated (to an `A:MySort`).

See added test for an example K program going wrong without the fix.

The PR changes the evaluation routine to return an indeterminate match
in case it detects a sort predicate applied to a function call.  The
iterative evaluation will (bottom-up) evaluate the function call in
the next round and is ultimately able to evaluate the predicate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Booster RPC server deficiency related to isX sort predicates

2 participants