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

Fixes and improvements in module_to_kore #4704

Merged
merged 11 commits into from
Dec 10, 2024
Merged

Conversation

tothtamas28
Copy link
Contributor

  • Enable checking of non-rule axioms in the test
  • Fix assoc, no-junk and no-confusion axiom generation
  • Fix sort generation
  • Fix a bug in collection attribute generation
  • Add support for the impure attribute
  • Filter out some internal attributes

@tothtamas28 tothtamas28 added the pyk label Dec 9, 2024
@tothtamas28 tothtamas28 requested a review from jberthold December 9, 2024 14:50
@tothtamas28 tothtamas28 self-assigned this Dec 9, 2024
Comment on lines 471 to 480
res: list[Axiom] = []
for sentence in module.sentences:
if not isinstance(sentence, KProduction):
for prod in module.productions:
if not prod.klabel:
continue
if not sentence.klabel:
if prod.klabel.name in BUILTIN_LABELS:
continue
if sentence.klabel.name in BUILTIN_LABELS:
if not Atts.FUNCTIONAL in prod.att:
continue
if not Atts.FUNCTIONAL in sentence.att:
continue
res.append(functional_axiom(sentence))
res.append(functional_axiom(prod))
return res
Copy link
Member

Choose a reason for hiding this comment

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

There is a clear pattern of repeated code here:

  • for each production prod in the module
    • if not prod.klabel: skip
    • if prod.klabel.name in BUILTIN_LABELS: skip
    • if TARGET in prod.att: call TARGET_axiom (some instances have different criteria, sometimes several ones)

Since each productions should be part of exactly one group with a certain criterion, would it make sense to iterate over all productions just once, to classify them into TARGET groups and and dispatch to each TARGET_axiom in just one place?
(That place would be https://github.com/runtimeverification/k/pull/4704/files#diff-0e99d64ff2ae75d6aa4d5eb3c1822e330e1f2d1f8b69fb19bbb399e5780e2591R107-R119 )

Comment on lines +988 to +989
class AddImpureAtts(SingleModulePass):
"""Add the `impure` attribute to all function symbol productions whose definition transitively contains `impure`."""
Copy link
Member

Choose a reason for hiding this comment

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

While reading through this the question arose in my head whether this is really a "single-module" property.
Maybe it is only single-module because the compiler is smashing all user code into a single module? Because if imports are admitted one could easily import an impure "function" from a different module and call it on the RHS of a rule, or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is not single module in that sense. The name is probably misleading, but SingleModulePass means that it transforms a definition with a single module into another definition with a single module.

@@ -1063,6 +1196,7 @@ class DiscardHookAtts(SingleModulePass):
'SET',
'STRING',
'SUBSTITUTION',
'TIMER',
'UNIFICATION',
)

Copy link
Member

Choose a reason for hiding this comment

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

At ~1300 lines for this file, maybe worth refactoring into separate modules...
What comes to mind is a split into compiler passes and final axiom rendering.

@tothtamas28 tothtamas28 changed the title Fixes an improvements in module_to_kore Fixes and improvements in module_to_kore Dec 10, 2024
@tothtamas28 tothtamas28 marked this pull request as ready for review December 10, 2024 09:00
@tothtamas28
Copy link
Contributor Author

I opened an issue for the refactorings: #4707

@tothtamas28 tothtamas28 merged commit 50b7071 into develop Dec 10, 2024
35 checks passed
@tothtamas28 tothtamas28 deleted the module-to-kore-fixes branch December 10, 2024 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants