GOTO backend: Core-to-GOTO translation, CBMC pipeline tests, and CI#289
GOTO backend: Core-to-GOTO translation, CBMC pipeline tests, and CI#289tautschnig wants to merge 8 commits intomainfrom
Conversation
b7a830b to
7b8e91f
Compare
|
One general comment on this: I have plans to add unstructured CFGs in Strata (started in #202), and it would probably make sense in the long run to have a a pipeline that does Strata Stmt -> Strata CFG -> GOTO instruction CFG. I'd paused work on #202 because it wasn't clear what we'd use it for right now, but I could finish it up and merge it if you think it'd be useful for this PR. |
There'll certainly be interactions between your PR and this one, but I'm happy for these to be worked on in either order: if #202 goes in first, this PR will be updated, else #202 should likely include changes to GOTO instruction support (which I'm then happy to contribute myself). |
There was a problem hiding this comment.
Pull request overview
This PR extends the transformation functionality from imperative commands to GOTO instructions by adding support for all statement types (.block, .ite, .loop, and .goto), not just the previously-supported .cmd statements.
Key Changes:
- Implemented mutual recursive functions
Stmt.toGotoInstructionsandBlock.toGotoInstructionsto handle all statement constructors - Added comprehensive test coverage with 10 test cases covering basic, nested, and edge-case scenarios
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
Strata/DL/Imperative/ToCProverGOTO.lean |
Adds mutual recursive transformation functions for statements and blocks, handling control flow constructs (blocks, conditionals, loops, gotos) with proper label generation and GOTO instruction patching |
StrataTest/Backends/CBMC/ToCProverGOTO.lean |
Adds 10 comprehensive test cases covering all new statement types including basic transformations, nested control flow, empty branches/bodies, and assertions/assumptions within control structures |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
I mostly just wanted to make sure we're both aware of each other's work. Since this PR seems just about ready to go, and #202 still needs some tests which I won't have a chance to add right away, let's go ahead and merge this one and update #202 later. |
Pull request was converted to draft
Pull request was converted to draft
f74b7a5 to
af9b21d
Compare
af9b21d to
32db60d
Compare
| skipped=0 | ||
| errors=0 | ||
|
|
||
| for ion_file in "$TESTS_DIR"/*.py.ion; do |
There was a problem hiding this comment.
I'd expect .py or .python.st.ion
There was a problem hiding this comment.
What's wrong with .py.ion?
|
I think #472 is basically ready to merge, and it replaces |
| | some fm => | ||
| let pos := fm.toPosition fr.range.start | ||
| (pos.line, pos.column) | ||
| | none => (0, 0) |
There was a problem hiding this comment.
Do you think there's a different default for when the fileMap isn't available that'd be sensible here? I think we've run into this elsewhere too.
There was a problem hiding this comment.
It's now using byte offset as a rough indicator, but I'm not sure what else can be done when no information is available.?
9425663 to
c7c51e0
Compare
Those changes are now included. |
c7c51e0 to
8729ce8
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 48 out of 49 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
StrataTest/Languages/Python/tests/test_arithmetic.py.ion.core.st
Outdated
Show resolved
Hide resolved
| let decl_inst := | ||
| { type := .DECL, locationNum := trans.nextLoc, | ||
| sourceLoc := { SourceLocation.nil with function := functionName }, | ||
| sourceLoc := srcLoc, |
There was a problem hiding this comment.
Can't you pass 1d source locations to the back-end? In the common case, a FileMap will not be available at this point so you can not generate the 2d locations.
There was a problem hiding this comment.
The current code already falls back to 1D byte offsets when no FileMap is available. All current callers (coreAnalyzeToGoto, laurelAnalyzeToGoto, pyAnalyzeToGoto) do provide a FileMap built from the source file.
There was a problem hiding this comment.
All current callers (coreAnalyzeToGoto, laurelAnalyzeToGoto, pyAnalyzeToGoto) do provide a FileMap built from the source file.
Front-ends generally will not pass a FileMap to Strata. They will pass Ion without a FileMap. The FileMap might not even be available on the machine where Strata is executing.
The current code already falls back to 1D byte offsets when no FileMap is available.
Shouldn't that be the default? Does it enable reconstructing 2D locations near the front of Strata?
b2178a8 to
2de1f04
Compare
Translate Strata Core programs to CProver GOTO binary format for CBMC verification. Covers all Imperative statement types, Core commands, procedure contracts, calls, axioms, datatypes, and source locations. ToCProverGOTO.lean: - Handle block, ite, loop, exit, funcDecl statements - Emit loop invariants (#spec_loop_invariant) and measures (#spec_decreases) - Extract helpers: emitGoto, emitCondGoto, emitLabel, patchGotoTargets Expr.lean: - Map all arithmetic, comparison, boolean, bitvector, real, string, and regex operators to GOTO equivalents - Support BV extract, old(expr), quantifiers, ternary InstToJson.lean: - Extend JSON serialization for GOTO programs with function entries - Deduplicate symbol collection and operator JSON generation StrataMain.lean: - Add coreAnalyzeToGoto, laurelAnalyzeToGoto, pyAnalyzeToGoto commands - Translate procedure calls to FUNCTION_CALL instructions at any nesting - Lift local funcDecl to top-level GOTO functions - Emit contracts, axioms, distinct decls, global variables - Propagate source locations from metadata to GOTO instructions
Move test files to StrataTest/Backends/CBMC/GOTO/ subdirectory. Add tests for all statement types, operator mappings, procedure translation, funcDecl lifting, and source location propagation.
Test the full pipeline: strata → process_json.py → symtab2gb → goto-cc → goto-instrument --dfcc → cbmc. Covers contracts, assertions, ensures, loops, calls, nested calls, and call-inside-loop/if patterns.
CI: build CBMC from source with string/regex support. Laurel: shell scripts and test programs for Laurel-to-CBMC pipeline. Python: shell scripts and test programs for Python-to-CBMC pipeline, with generation step for .py.ion files from .py sources.
Track implemented features, open gaps (exit statement, unhandled types/ expressions, Map.const), DFCC integer limitation, and DDM parser issue #490.
- exit statement: emit unconditional GOTO, patch target when enclosing block ends. Track pending exits in GotoTransform.pendingExits. - Map.const: map to GOTO array_of unary expression (constant-valued array). - modifies clause: look up actual variable types from program declarations instead of hardcoding Integer, fixing DFCC 'no definite size' errors for programs using bounded types.
…ions - Remove committed .py.ion.core.st files (generated pipeline intermediates, not human-readable). Add *.py.ion and *.py.ion.core.st to .gitignore. - Clarify metadataToSourceLoc comment: document that all current callers provide a FileMap, and the byte-offset fallback is for library reuse.
780e316 to
8a771b6
Compare
CBMC's SSA renaming and simplifier transform quantifier bound variables into non-symbol expressions, violating the quantifier_exprt invariant. Add cbmc-quantifier-simplify.patch to skip bound variables during renaming and simplification. Restore axiom emission in Python pipelines (previously stripped as workaround). Mark test_missing_models, test_precondition_verification, and test_strings as SKIP due to a separate CBMC SMT2 convert_type crash on struct_tag types.
8a771b6 to
9924b36
Compare
Description of changes:
Core-to-GOTO translation
Translate Strata Core programs to CProver GOTO binary format for CBMC
verification. Covers all Imperative statement types, Core commands,
procedure contracts, calls, axioms, datatypes, and source locations.
ToCProverGOTO.lean:
LambdaToCProverGOTO.lean (new, in Strata/Backends/CBMC/GOTO/):
and regex operators to GOTO equivalents
to signedbv via typecast so CBMC interprets them correctly
Int.SafeMod): encode as compound expressions built from truncating
div/mod with correction terms
CoreToCProverGOTO.lean (new, in Strata/Backends/CBMC/GOTO/):
InstToJson.lean:
StrataMain.lean:
Code reorganization
Production GOTO translation code moved from StrataTest/ to
Strata/Backends/CBMC/GOTO/ (LambdaToCProverGOTO.lean,
CoreToCProverGOTO.lean). Test files in StrataTest/ now import from
the production modules and contain only test code.
Tests and CI
expected output matching (CBMC properties checked by line number)
regex, and bounds-check patches; runs all CBMC test suites
Documentation
operator semantics decisions, and remaining open gaps
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.