Skip to content

Rewrite StrataCoreToGoto for multi-procedure programs with contracts#657

Draft
tautschnig wants to merge 4 commits intomainfrom
tautschnig/stratacoretogoto
Draft

Rewrite StrataCoreToGoto for multi-procedure programs with contracts#657
tautschnig wants to merge 4 commits intomainfrom
tautschnig/stratacoretogoto

Conversation

@tautschnig
Copy link
Copy Markdown
Contributor

  • Iterate over all procedures and functions in the Core program
  • Apply call elimination to inline contracts (configurable via --no-call-elim)
  • Re-type-check after call elimination for new variable discovery
  • Seed type environment with global variable types
  • Apply GOTO pipeline passes: function inlining, recursive inlining, datatype partial evaluation, datatype axiom/recursive function axiom generation, datatype expression rewriting
  • Deduplicate symbol table, add default symbols

Tests:

  • test_multi_proc.core.st: multi-procedure Core program with contracts
  • test_strata_core_to_goto.sh: verifies translation, symbol table, contract annotations, and GOTO assertions

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

- Iterate over all procedures and functions in the Core program
- Apply call elimination to inline contracts (configurable via --no-call-elim)
- Re-type-check after call elimination for new variable discovery
- Seed type environment with global variable types
- Apply GOTO pipeline passes: function inlining, recursive inlining,
  datatype partial evaluation, datatype axiom/recursive function axiom
  generation, datatype expression rewriting
- Deduplicate symbol table, add default symbols

Tests:
- test_multi_proc.core.st: multi-procedure Core program with contracts
- test_strata_core_to_goto.sh: verifies translation, symbol table,
  contract annotations, and GOTO assertions

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates StrataCoreToGoto to support translating multi-procedure Strata Core programs (including procedure contracts) into aggregated CBMC GOTO JSON outputs, and adds a regression test exercising the new behavior.

Changes:

  • Reworks StrataCoreToGoto to iterate over all procedures/functions, optionally run call elimination, re-type-check, run GOTO pipeline passes, and emit combined symtab/goto JSON.
  • Adds a --no-call-elim flag to optionally skip call elimination.
  • Adds a multi-procedure Core test input plus a bash test that validates translation output, symbol table content, contract annotations, and presence of ASSERT instructions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.

File Description
StrataCoreToGoto.lean New multi-procedure translation + pipeline passes, symbol table aggregation/dedup, default symbol injection, new CLI flag.
StrataTest/Backends/CBMC/GOTO/test_strata_core_to_goto.sh New end-to-end-ish test script validating multi-proc translation artifacts.
StrataTest/Backends/CBMC/GOTO/test_multi_proc.core.st New Core input program with two procedures, contracts, a global var, and an assert.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tautschnig tautschnig self-assigned this Mar 25, 2026
github-merge-queue bot pushed a commit that referenced this pull request Mar 26, 2026
FUNCTION_CALL callees (e.g., print) had Empty type in the symbol table
because coreStmtsToGoto created the callee expression with .Empty type.
CBMC instrument_preconditions crashed trying to_code_type on Empty.

Fix: add Ty.Identifier.code and Ty.mkCode, use it for the callee
expression in coreStmtsToGoto. The code type flows through
collectSymbolRefs into the symbol table naturally.

Fixes 16 Python CBMC tests that use class-related function calls. See
PRs like #657 for current failures on that.

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Co-authored-by: Josh Cohen <36058610+joscoh@users.noreply.github.com>
tautschnig and others added 2 commits March 27, 2026 23:00
- Sanitize programName to prevent path traversal in output filenames
- Remove unused Ctx variable
- Use Array instead of List for symtabPairs to avoid quadratic append
- Track translation errors and return non-zero exit code on failure
- Use HashMap for symbol table dedup with last-wins semantics so that
  collectExtraSymbols globals/datatypes override per-procedure entries
- Strengthen test to verify global variable has isStaticLifetime attribute
- Use set -euo pipefail in test script for consistency

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig tautschnig marked this pull request as draft March 27, 2026 23:15
Follow the pattern of PR #691 (StrataVerify → strata verify) and migrate
the standalone StrataCoreToGoto executable into a coreToGoto subcommand
of the strata CLI.

- Delete StrataCoreToGoto.lean, move logic into StrataMain.lean
- Use the shared Command/ParsedFlags infrastructure and exit code scheme
- Add .core.st to deriveBaseName suffix list
- Remove StrataCoreToGoto from lakefile.toml and defaultTargets
- Update test script, mkGotoBin.sh, README, and steering doc

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
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