Skip to content

Commit

Permalink
Support NULL return from requires binding of get_requires() (#4326)
Browse files Browse the repository at this point in the history
The llvm function `get_requires()` can return either the Pattern in the
requires clause or nullptr. However, our binding only accepted the first
case, and this PR fixes that behavior by testing if the result of
`axiom.requires` returned a pattern. If not, we return None instead of
trying to convert None to a LLVM Pattern.

A unit test was added to ensure this behavior was documented and tested.
  • Loading branch information
Robertorosmaninho authored May 8, 2024
1 parent 3c8e94f commit 313aaba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pyk/src/pyk/kllvm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from ..kore.syntax import Axiom, Pattern


def get_requires(axiom: Axiom) -> Pattern:
def get_requires(axiom: Axiom) -> Pattern | None:
llvm_axiom = convert.sentence_to_llvm(axiom)
llvm_pattern = llvm_axiom.requires
if llvm_pattern is None:
return None
return convert.llvm_to_pattern(llvm_pattern)
11 changes: 10 additions & 1 deletion pyk/src/tests/integration/kllvm/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
r'W{}(VarA : SortInt{},\dv{SortInt{}}("1"))',
r'axiom {} \rewrites{SortGeneratedTopCell{}}(\and{SortGeneratedTopCell{}}(X{}(Y{}(kseq{}(inj{SortInt{}, SortKItem{}}(VarA : SortInt{}),dotk{}())), Z : SortGeneratedCounterCell{}),\equals{SortBool{}, SortGeneratedTopCell{}}(W{}(VarA : SortInt{},\dv{SortInt{}}("1")),\dv{SortBool{}}("true"))),\and{SortGeneratedTopCell{}}(X{}(Y{}(kseq{}(inj{SortInt{}, SortKItem{}}(\dv{SortInt{}}("1")),dotk{}())),),\top{SortGeneratedTopCell{}}())) []',
),
(
'axiom2',
r'',
r'axiom {} \rewrites{SortGeneratedTopCell{}}(\and{SortGeneratedTopCell{}}(V{}(X{}(kseq{}(inj{SortFoo{}, SortKItem{}}(W{}(Y{}(VarX : SortInt{}))), A : SortK{})), B : SortGeneratedCounterCell{}), \top{SortGeneratedTopCell{}}()), \and{SortGeneratedTopCell{}}(V{}(X{}(kseq{}(inj{SortFoo{}, SortKItem{}}(Y{}(Z{}(VarX : SortInt{}))), A : SortK{})), B : SortGeneratedCounterCell{}), \top{SortGeneratedTopCell{}}())) []',
),
)


Expand All @@ -26,7 +31,11 @@
def test_get_requires(test_id: str, kore_requires: str, kore_axiom: str) -> None:
# Given
axiom = KoreParser(kore_axiom).axiom()
expected_requires = KoreParser(kore_requires).pattern()

if kore_requires == '':
expected_requires = None
else:
expected_requires = KoreParser(kore_requires).pattern()

# When
actual_requires = get_requires(axiom)
Expand Down

0 comments on commit 313aaba

Please sign in to comment.