Skip to content

Conversation

@tautschnig
Copy link

Description of changes:

Extended transformation to handle all Stmt constructors (.block, .ite, .loop, .goto in addition to .cmd, which was already being handled).

Ten new tests cover basic, nested, and edge-case scenarios.

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

Extended transformation to handle all `Stmt` constructors (`.block`, `.ite`,
`.loop`, `.goto` in addition to `.cmd`, which was already being handled).

Ten new tests cover basic, nested, and edge-case scenarios.
@tautschnig tautschnig force-pushed the tautschnig/ToCProverGOTO-Stmt branch from b7a830b to 7b8e91f Compare December 22, 2025 18:02
nextLoc := trans.nextLoc + 1 }
Block.toGotoInstructions trans.T functionName body trans

| .ite cond thenb elseb _md =>
Copy link
Contributor

Choose a reason for hiding this comment

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

This case is getting a bit long and hard to read. I'd recommend using helper functions. Perhaps use Lean's where clauses? E.g.,:

def foo (x : Nat) : Nat := 
  x + bar x + baz x
 where 
  bar x := x
  baz x := x


return { trans with instructions := insts }

| .loop guard _measure _invariant body _md =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Another place where helper functions can improve readability.

@atomb
Copy link
Contributor

atomb commented Jan 6, 2026

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.

@tautschnig
Copy link
Author

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).

@tautschnig tautschnig marked this pull request as ready for review January 7, 2026 11:16
@tautschnig tautschnig requested a review from atomb as a code owner January 7, 2026 11:16
Copilot AI review requested due to automatic review settings January 7, 2026 11:16
@tautschnig tautschnig requested review from a team and aqjune-aws as code owners January 7, 2026 11:16
Copy link

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

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.toGotoInstructions and Block.toGotoInstructions to 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.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@shigoel shigoel enabled auto-merge January 7, 2026 15:31
@atomb
Copy link
Contributor

atomb commented Jan 7, 2026

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).

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants