-
Notifications
You must be signed in to change notification settings - Fork 162
pyk: fix add_cell_map_items over-wrapping, add --parser to pyk run #4918
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
aaa6752
test_definition: add unit tests for add_cell_map_items guard
ehildenb db94185
outer: add_cell_map_items wraps only when parent expects cell map sort
ehildenb 82117ea
pyk/test_definition: minimize to test definition just for cell map items
ehildenb 5747b83
__main__, cli/pyk, ktool/krun: add --parser flag to pyk run
ehildenb f0132ab
regression-new: enable star-multiplicity, issue-582, krun-deserialize
ehildenb d31f9c1
outer: extract cell_map_item_info from add/remove_cell_map_items
ehildenb 8ae515a
outer: simplify _wrap_elements in add_cell_map_items
ehildenb ed130c6
pyk/kast/outer: move comment
ehildenb b869e6c
pyk/kast/outer: rename _wrap_elements => _unwrap_elements in remove_c…
ehildenb f5f9abf
pyproject.toml: suppress pydocstyle D202 to resolve black conflict
ehildenb 84a24cf
pyk/pyproject, pyk/kast/outer: adjust comments to be docstrings
ehildenb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| <k> | ||
| 7 ~> .K | ||
| </k> | ||
| <generatedTop> | ||
| <k> | ||
| 7 ~> .K | ||
| </k> | ||
| <generatedCounter> | ||
| 0 | ||
| </generatedCounter> | ||
| </generatedTop> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| <T> | ||
| <k> | ||
| .K | ||
| </k> | ||
| <state> | ||
| n |-> 0 | ||
| sum |-> 5050 | ||
| </state> | ||
| </T> | ||
| <generatedTop> | ||
| <T> | ||
| <k> | ||
| .K | ||
| </k> | ||
| <state> | ||
| sum |-> 5050 n |-> 0 | ||
| </state> | ||
| </T> | ||
| <generatedCounter> | ||
| 0 | ||
| </generatedCounter> | ||
| </generatedTop> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| import pytest | ||
|
|
||
| from pyk.kast.att import Atts, KAtt | ||
| from pyk.kast.inner import KApply, KSort, KVariable | ||
| from pyk.kast.outer import KDefinition, KFlatModule, KNonTerminal, KProduction, KTerminal | ||
|
|
||
| if TYPE_CHECKING: | ||
| from typing import Final | ||
|
|
||
| from pyk.kast.inner import KInner | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Minimal test definition | ||
| # | ||
| # Cell map fragment: | ||
| # AccountCellMap ::= AccountCellMap AccountCellMap [cellCollection, element(AccountCellMapItem), wrapElement(<account>)] | ||
| # AccountCellMap ::= AccountCellMapItem(Int, AccountCell) | ||
| # AccountCell ::= <account>(Int, Int) | ||
| # AccountCell ::= getEntry(AccountCell) -- takes element sort, NOT map sort | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| INT: Final = KSort('Int') | ||
| ACCOUNT_CELL_MAP: Final = KSort('AccountCellMap') | ||
| ACCOUNT_CELL: Final = KSort('AccountCell') | ||
|
|
||
| _ACCT_MAP_CONCAT: Final = KProduction( | ||
| sort=ACCOUNT_CELL_MAP, | ||
| items=[KNonTerminal(ACCOUNT_CELL_MAP), KNonTerminal(ACCOUNT_CELL_MAP)], | ||
| klabel='_AccountCellMap_', | ||
| att=KAtt(entries=[Atts.CELL_COLLECTION(None), Atts.ELEMENT('AccountCellMapItem'), Atts.WRAP_ELEMENT('<account>')]), | ||
| ) | ||
|
|
||
| _ACCT_MAP_ITEM: Final = KProduction( | ||
| sort=ACCOUNT_CELL_MAP, | ||
| items=[ | ||
| KTerminal('AccountCellMapItem'), | ||
| KTerminal('('), | ||
| KNonTerminal(INT), | ||
| KTerminal(','), | ||
| KNonTerminal(ACCOUNT_CELL), | ||
| KTerminal(')'), | ||
| ], | ||
| klabel='AccountCellMapItem', | ||
| ) | ||
|
|
||
| _ACCOUNT_CELL: Final = KProduction( | ||
| sort=ACCOUNT_CELL, | ||
| items=[ | ||
| KTerminal('<account>'), | ||
| KTerminal('('), | ||
| KNonTerminal(INT), | ||
| KTerminal(','), | ||
| KNonTerminal(INT), | ||
| KTerminal(')'), | ||
| ], | ||
| klabel='<account>', | ||
| ) | ||
|
|
||
| _GET_ENTRY: Final = KProduction( | ||
| sort=ACCOUNT_CELL, | ||
| items=[KTerminal('getEntry'), KTerminal('('), KNonTerminal(ACCOUNT_CELL), KTerminal(')')], | ||
| klabel='getEntry', | ||
| ) | ||
|
|
||
| DEFN: Final = KDefinition( | ||
| 'TEST', | ||
| [KFlatModule('TEST', [_ACCT_MAP_CONCAT, _ACCT_MAP_ITEM, _ACCOUNT_CELL, _GET_ENTRY])], | ||
| ) | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # KDefinition.add_cell_map_items | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| _ACCT_1: Final = KApply('<account>', [KVariable('X', sort=INT), KVariable('Y', sort=INT)]) | ||
| _ACCT_2: Final = KApply('<account>', [KVariable('A', sort=INT), KVariable('B', sort=INT)]) | ||
|
|
||
| ADD_CELL_MAP_ITEMS_DATA: Final = ( | ||
| # Parent expects AccountCellMap (the map sort) — children are wrapped in AccountCellMapItem. | ||
| ( | ||
| 'wraps_when_parent_expects_cell_map_sort', | ||
| KApply('_AccountCellMap_', [_ACCT_1, _ACCT_2]), | ||
| KApply( | ||
| '_AccountCellMap_', | ||
| [ | ||
| KApply('AccountCellMapItem', [KVariable('X', sort=INT), _ACCT_1]), | ||
| KApply('AccountCellMapItem', [KVariable('A', sort=INT), _ACCT_2]), | ||
| ], | ||
| ), | ||
| ), | ||
| # Parent expects AccountCell (the element sort) — the <account> child must NOT be wrapped. | ||
| # Before the guard fix, _wrap_elements would incorrectly wrap here too. | ||
| ( | ||
| 'no_wrap_when_parent_expects_cell_element_sort', | ||
| KApply('getEntry', [_ACCT_1]), | ||
| KApply('getEntry', [_ACCT_1]), | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| 'test_id,term,expected', | ||
| ADD_CELL_MAP_ITEMS_DATA, | ||
| ids=[test_id for test_id, *_ in ADD_CELL_MAP_ITEMS_DATA], | ||
| ) | ||
| def test_add_cell_map_items(test_id: str, term: KInner, expected: KInner) -> None: | ||
| assert DEFN.add_cell_map_items(term) == expected |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.