Skip to content

Generalize KAST-to-KORE conversion for KSequence#4874

Merged
automergerpr-permission-manager[bot] merged 5 commits intodevelopfrom
kast-to-kore-kseq
Oct 30, 2025
Merged

Generalize KAST-to-KORE conversion for KSequence#4874
automergerpr-permission-manager[bot] merged 5 commits intodevelopfrom
kast-to-kore-kseq

Conversation

@tothtamas28
Copy link
Contributor

  • Allow items of sort K to appear at any position within a KSequence, not just at the end. During _kast_to_kore, an application of append is generated in such cases.
  • Conversely, during _kore_to_kast, generate a KSequence for each append.
  • Fix KVariable sort inference so that it does not override declared sorts of KSequence items.
  • Update test_kast_to_kore_frontend to compare the Frontend’s result against expected outputs, rather than pyk's results. This makes it easier to add new tests based on the Frontend’s output.

@tothtamas28 tothtamas28 self-assigned this Oct 29, 2025
Comment on lines +7 to +9
kseq-with-k-head
kseq-with-k-middle
kseq-with-multiple-ks
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, these need to be excluded from kast tests (similarly to other KSequence tests), because for some reason when converting from json to kore, the result is wrapped in an inj into SortKItem:

% kast --definition /tmp/pytest-of-ttoth/pytest-current/kompiled0/simple-proofs-llvm-0 --input json --output kore --expression '{"format": "KAST", "version": 3, "term": {"node": "KSequence", "items": [{"node": "KToken", "token": "1", "sort": {"node": "KSort", "name": "Int"}}, {"node": "KVariable", "name": "X1", "sort": {"node": "KSort", "name": "K"}}, {"node": "KVariable", "name": "X2", "sort": {"node": "KSort", "name": "K"}}, {"node": "KVariable", "name": "X3", "sort": {"node": "KSort", "name": "K"}}, {"node": "KToken", "token": "2", "sort": {"node": "KSort", "name": "Int"}}, {"node": "KVariable", "name": "X4", "sort": {"node": "KSort", "name": "K"}}], "arity": 6}}' --sort K
inj{SortK{}, SortKItem{}}(kseq{}(inj{SortInt{}, SortKItem{}}(\dv{SortInt{}}("1")),append{}(VarX1:SortK{},append{}(VarX2:SortK{},append{}(VarX3:SortK{},kseq{}(inj{SortInt{}, SortKItem{}}(\dv{SortInt{}}("2")),VarX4:SortK{}))))))

Funnily enough, kast is happy to inject the result into any sort (including undefined ones), except for K:

% kast --definition /tmp/pytest-of-ttoth/pytest-current/kompiled0/simple-proofs-llvm-0 --input json --output kore --expression '{"format": "KAST", "version": 3, "term": "..."}' --sort Whatever
inj{SortK{}, SortWhatever{}}(...)

For conversion from rule syntax, kast works as expected:

$ kast --definition /tmp/pytest-of-ttoth/pytest-current/kompiled0/simple-proofs-llvm-0 --input rule --output kore --expression '1 ~> X1:K ~> X2:K ~> X3:K ~> 2 ~> X4:K' --sort K
kseq{}(inj{SortInt{}, SortKItem{}}(\dv{SortInt{}}("1")),append{}(VarX1:SortK{},append{}(VarX2:SortK{},append{}(VarX3:SortK{},kseq{}(inj{SortInt{}, SortKItem{}}(\dv{SortInt{}}("2")),VarX4:SortK{})))))%

Copy link
Member

@jberthold jberthold left a comment

Choose a reason for hiding this comment

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

LGTM. Funny behaviour with the KItem injection, though.

@automergerpr-permission-manager automergerpr-permission-manager bot merged commit 660b841 into develop Oct 30, 2025
20 checks passed
@automergerpr-permission-manager automergerpr-permission-manager bot deleted the kast-to-kore-kseq branch October 30, 2025 09:29
automergerpr-permission-manager bot pushed a commit to runtimeverification/mir-semantics that referenced this pull request Oct 30, 2025
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.

2 participants