-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add --to-module, --minimize-proof, and --add-module CLI options #907
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 all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -91,11 +91,46 @@ def _digest_file(target_dir: Path) -> Path: | |
| return target_dir / 'smir-digest.json' | ||
|
|
||
|
|
||
| def _load_extra_module_rules(kmir: KMIR, module_path: Path) -> list[Sentence]: | ||
| """Load a K module from JSON and convert rules to Kore axioms. | ||
|
|
||
| Args: | ||
| kmir: KMIR instance with the definition | ||
| module_path: Path to JSON module file (from --to-module output.json) | ||
|
|
||
| Returns: | ||
| List of Kore axioms converted from the module rules | ||
| """ | ||
| from pyk.kast.outer import KFlatModule, KRule | ||
| from pyk.konvert import krule_to_kore | ||
|
|
||
| _LOGGER.info(f'Loading extra module rules: {module_path}') | ||
|
|
||
| if module_path.suffix != '.json': | ||
| _LOGGER.warning(f'Only JSON format is supported for --add-module: {module_path}') | ||
| return [] | ||
|
|
||
| module_dict = json.loads(module_path.read_text()) | ||
| k_module = KFlatModule.from_dict(module_dict) | ||
|
|
||
| axioms: list[Sentence] = [] | ||
| for sentence in k_module.sentences: | ||
| if isinstance(sentence, KRule): | ||
| try: | ||
| axiom = krule_to_kore(kmir.definition, sentence) | ||
| axioms.append(axiom) | ||
| except Exception: | ||
| _LOGGER.warning(f'Failed to convert rule to Kore: {sentence}', exc_info=True) | ||
|
|
||
| return axioms | ||
|
|
||
|
|
||
| def kompile_smir( | ||
| smir_info: SMIRInfo, | ||
| target_dir: Path, | ||
| bug_report: Path | None = None, | ||
| symbolic: bool = True, | ||
| extra_module: Path | None = None, | ||
| ) -> KompiledSMIR: | ||
| kompile_digest: KompileDigest | None = None | ||
| try: | ||
|
|
@@ -120,8 +155,18 @@ def kompile_smir( | |
| target_dir.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| kmir = KMIR(HASKELL_DEF_DIR) | ||
| rules = make_kore_rules(kmir, smir_info) | ||
| _LOGGER.info(f'Generated {len(rules)} function equations to add to `definition.kore') | ||
| smir_rules: list[Sentence] = list(make_kore_rules(kmir, smir_info)) | ||
| _LOGGER.info(f'Generated {len(smir_rules)} function equations to add to `definition.kore') | ||
|
|
||
| # Load and convert extra module rules if provided | ||
| # These are kept separate because LLVM backend doesn't support configuration rewrites | ||
| extra_rules: list[Sentence] = [] | ||
| if extra_module is not None: | ||
| extra_rules = _load_extra_module_rules(kmir, extra_module) | ||
| _LOGGER.info(f'Added {len(extra_rules)} rules from extra module: {extra_module}') | ||
|
|
||
| # Combined rules for Haskell backend (supports both function equations and rewrites) | ||
| all_rules = smir_rules + extra_rules | ||
|
|
||
| if symbolic: | ||
| # Create output directories | ||
|
|
@@ -131,11 +176,12 @@ def kompile_smir( | |
| target_llvmdt_path.mkdir(parents=True, exist_ok=True) | ||
| target_hs_path.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| # Process LLVM definition | ||
| # Process LLVM definition (only SMIR rules, not extra module rules) | ||
| # Extra module rules are configuration rewrites that LLVM backend doesn't support | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is getting a bit too complicated IMO. We should extract two helpers for the two cases of |
||
| _LOGGER.info('Writing LLVM definition file') | ||
| llvm_def_file = LLVM_LIB_DIR / 'definition.kore' | ||
| llvm_def_output = target_llvm_lib_path / 'definition.kore' | ||
| _insert_rules_and_write(llvm_def_file, rules, llvm_def_output) | ||
| _insert_rules_and_write(llvm_def_file, smir_rules, llvm_def_output) | ||
|
|
||
| # Run llvm-kompile-matching and llvm-kompile for LLVM | ||
| # TODO use pyk to do this if possible (subprocess wrapper, maybe llvm-kompile itself?) | ||
|
|
@@ -161,10 +207,10 @@ def kompile_smir( | |
| check=True, | ||
| ) | ||
|
|
||
| # Process Haskell definition | ||
| # Process Haskell definition (includes both SMIR rules and extra module rules) | ||
| _LOGGER.info('Writing Haskell definition file') | ||
| hs_def_file = HASKELL_DEF_DIR / 'definition.kore' | ||
| _insert_rules_and_write(hs_def_file, rules, target_hs_path / 'definition.kore') | ||
| _insert_rules_and_write(hs_def_file, all_rules, target_hs_path / 'definition.kore') | ||
|
|
||
| # Copy all files except definition.kore and binary from HASKELL_DEF_DIR to out/hs | ||
| _LOGGER.info('Copying other artefacts into HS output directory') | ||
|
|
@@ -183,11 +229,11 @@ def kompile_smir( | |
| _LOGGER.info(f'Creating directory {target_llvmdt_path}') | ||
| target_llvmdt_path.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| # Process LLVM definition | ||
| # Process LLVM definition (only SMIR rules for concrete execution) | ||
| _LOGGER.info('Writing LLVM definition file') | ||
| llvm_def_file = LLVM_LIB_DIR / 'definition.kore' | ||
| llvm_def_output = target_llvm_path / 'definition.kore' | ||
| _insert_rules_and_write(llvm_def_file, rules, llvm_def_output) | ||
| _insert_rules_and_write(llvm_def_file, smir_rules, llvm_def_output) | ||
|
|
||
| import subprocess | ||
|
|
||
|
|
||
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
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.