Skip to content

Split StrataMain.lean into importable library and thin executable root#1164

Draft
MikaelMayer wants to merge 9 commits into
issue-1045-feature-request-parallel-solvingfrom
issue-1163-split-stratamain-lean-into-importable-li
Draft

Split StrataMain.lean into importable library and thin executable root#1164
MikaelMayer wants to merge 9 commits into
issue-1045-feature-request-parallel-solvingfrom
issue-1163-split-stratamain-lean-into-importable-li

Conversation

@MikaelMayer
Copy link
Copy Markdown
Contributor

@MikaelMayer MikaelMayer commented May 14, 2026

Fixes #1163

Summary

Splits StrataMain.lean into an importable library (StrataMainLib.lean) and a thin executable root, enabling downstream packages to reuse and customize the CLI command definitions without copying code.

Changes

  • StrataMainLib.lean (new lean_lib): Contains all command definitions, helpers, commandGroups, commandList, commandMap, and a shared runCommandMap dispatcher.
  • StrataMain.lean: Now a 3-line executable root that imports StrataMainLib and calls runCommandMap.
  • lakefile.toml: Adds StrataMainLib as a lean_lib and to defaultTargets.
  • verifyCommand and pyAnalyzeLaurelCommand are parameterized with mkDischarge (defaulting to Core.mkDischargeFn), allowing downstream executables to plug in a custom solver backend.

This is a pure refactor — no behavioral changes.

Downstream usage

import StrataMainLib
import MySolver

def myCommandMap : Std.HashMap String Command :=
  commandMap
    |>.insert "verify" (verifyCommand (mkDischarge := myDischargeFn))
    |>.insert "pyAnalyzeLaurel" (pyAnalyzeLaurelCommand (mkDischarge := myDischargeFn))

def main (args : List String) : IO Unit :=
  runCommandMap myCommandMap commandGroups args

No code duplication, stays in sync automatically.

Testing

All existing tests pass unchanged.

…#1163)

Extract all command definitions, helpers, and dispatch logic into
StrataMainLib.lean (a lean_lib that downstream packages can import).
StrataMain.lean becomes a thin executable root that imports StrataMainLib
and calls runCommandMap.

Parameterize pyAnalyzeCommand and pyAnalyzeLaurelCommand with moreFns
(the Lambda.Factory extension point) so downstream users can plug in
custom solver backends without copying the entire file.

Add runCommandMap as the shared dispatcher entry point.
@github-actions github-actions Bot added dependencies Pull requests that update a dependency file Git conflicts labels May 14, 2026
@MikaelMayer MikaelMayer changed the base branch from main to issue-917-abstract-solver-interface-decouple-term May 14, 2026 16:57
@MikaelMayer
Copy link
Copy Markdown
Contributor Author

Note: I changed the upstream because the original issue specifically mentioned functions that were not in main yet so you can't just solve this by updating main.

@MikaelMayer MikaelMayer changed the base branch from issue-917-abstract-solver-interface-decouple-term to issue-1045-feature-request-parallel-solving May 14, 2026 16:59
Copy link
Copy Markdown
Contributor Author

@MikaelMayer MikaelMayer left a comment

Choose a reason for hiding this comment

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

🔍 Clean refactoring. The split is well-structured: a thin executable root importing a reusable library, with moreFns parameterized for downstream customization.

One behavioral change to confirm: pyAnalyzeLaurelCommand now receives moreFns (which is Strata.Python.ReFactory in the default executable), whereas on main it called Strata.verifyCore with the default Lambda.Factory.default. If this is intentional (making the Laurel pipeline consistent with the direct Python pipeline), it's a good improvement — but it should be called out in the PR description since it's not a pure refactor.

Comment thread StrataMainLib.lean Outdated
| .some dir => { baseOptions with vcDirectory := some (dir : System.FilePath) }
| .none => baseOptions
let vcResults ←
match ← Strata.verifyCore coreProgram options moreFns |>.toBaseIO with
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🔍 Behavioral change: on main, verifyCore was called here without moreFns (using the default Lambda.Factory.default). Now it receives the parameterized moreFns, which in the default executable is Strata.Python.ReFactory. This means the Laurel verification pipeline now uses the Python solver factory instead of the default. Is this intentional? If so, please mention it in the PR description — it's not a pure refactor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🤖 No code change needed. After the merge with the base branch (issue-1045-feature-request-parallel-solving), the pyAnalyzeLaurelCommand no longer takes a parameterized moreFns — it hardcodes Strata.Python.ReFactory directly, which matches what the base branch already does. The original concern about the parameterization introducing a behavioral change is moot since the merge resolved it: the code now simply moves the same Core.verifyProgram coreProgram options (moreFns := Strata.Python.ReFactory) call from StrataMain.lean into StrataMainLib.lean without any semantic difference relative to the base branch.

…lel-solving' into issue-1163-split-stratamain-lean-into-importable-li

# Conflicts:
#	StrataMain.lean
#	lakefile.toml
@MikaelMayer
Copy link
Copy Markdown
Contributor Author

🤖 Acknowledged — the base branch is issue-1045-feature-request-parallel-solving because the functions referenced in issue #1163 (like Core.verifyProgram, pyAnalyzeLaurelCommand with the new flags, etc.) only exist on that branch. The PR diff is relative to that upstream.

@MikaelMayer
Copy link
Copy Markdown
Contributor Author

The split looks great — thanks for the quick turnaround.

One follow-up request: could you also parameterize verifyCommand and pyAnalyzeLaurelCommand with mkDischarge? This is the last piece needed for a downstream exe to plug in a custom solver backend without copying any command code.

The change is 4 lines:

-def pyAnalyzeLaurelCommand : Command where
+def pyAnalyzeLaurelCommand (mkDischarge : Core.MkDischargeFn := Core.mkDischargeFn) : Command where

and inside its callback, at the Core.verifyProgram call (line ~750):

                 (keepAllFilesPrefix := keepPrefix)
+                (mkDischarge := mkDischarge)
                 |>.toBaseIO with
-def verifyCommand : Command where
+def verifyCommand (mkDischarge : Core.MkDischargeFn := Core.mkDischargeFn) : Command where

and inside its callback (line ~1340):

-          verify pgm inputCtx proceduresToVerify opts
+          verify pgm inputCtx proceduresToVerify opts (mkDischarge := mkDischarge)

With this, a downstream exe becomes:

import StrataMainLib
import MySolver

def myCommandMap : Std.HashMap String Command :=
  commandMap
    |>.insert "verify" (verifyCommand (mkDischarge := myDischargeFn))
    |>.insert "pyAnalyzeLaurel" (pyAnalyzeLaurelCommand (mkDischarge := myDischargeFn))

def main (args : List String) : IO Unit :=
  runCommandMap myCommandMap commandGroups args

No code duplication, stays in sync automatically.

…scharge

Allows downstream executables to plug in a custom solver backend by
passing a custom MkDischargeFn to these commands without copying code.
@MikaelMayer
Copy link
Copy Markdown
Contributor Author

🤖 Done in 4586b49 — both verifyCommand and pyAnalyzeLaurelCommand now accept an optional mkDischarge parameter (defaulting to Core.mkDischargeFn), threaded through to the underlying verify/Core.verifyProgram calls.

…lel-solving' into issue-1163-split-stratamain-lean-into-importable-li
…lel-solving' into issue-1163-split-stratamain-lean-into-importable-li
…lel-solving' into issue-1163-split-stratamain-lean-into-importable-li
…lel-solving' into issue-1163-split-stratamain-lean-into-importable-li
…lel-solving' into issue-1163-split-stratamain-lean-into-importable-li
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split StrataMain.lean into importable library and thin executable root

1 participant