Split StrataMain.lean into importable library and thin executable root#1164
Conversation
…#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.
|
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
left a comment
There was a problem hiding this comment.
🔍 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.
| | .some dir => { baseOptions with vcDirectory := some (dir : System.FilePath) } | ||
| | .none => baseOptions | ||
| let vcResults ← | ||
| match ← Strata.verifyCore coreProgram options moreFns |>.toBaseIO with |
There was a problem hiding this comment.
🔍 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.
There was a problem hiding this comment.
🤖 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
|
🤖 Acknowledged — the base branch is |
|
The split looks great — thanks for the quick turnaround. One follow-up request: could you also parameterize The change is 4 lines: -def pyAnalyzeLaurelCommand : Command where
+def pyAnalyzeLaurelCommand (mkDischarge : Core.MkDischargeFn := Core.mkDischargeFn) : Command whereand inside its callback, at the (keepAllFilesPrefix := keepPrefix)
+ (mkDischarge := mkDischarge)
|>.toBaseIO with-def verifyCommand : Command where
+def verifyCommand (mkDischarge : Core.MkDischargeFn := Core.mkDischargeFn) : Command whereand 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 argsNo 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.
|
🤖 Done in 4586b49 — both |
…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
Fixes #1163
Summary
Splits
StrataMain.leaninto 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(newlean_lib): Contains all command definitions, helpers,commandGroups,commandList,commandMap, and a sharedrunCommandMapdispatcher.StrataMain.lean: Now a 3-line executable root that importsStrataMainLiband callsrunCommandMap.lakefile.toml: AddsStrataMainLibas alean_liband todefaultTargets.verifyCommandandpyAnalyzeLaurelCommandare parameterized withmkDischarge(defaulting toCore.mkDischargeFn), allowing downstream executables to plug in a custom solver backend.This is a pure refactor — no behavioral changes.
Downstream usage
No code duplication, stays in sync automatically.
Testing
All existing tests pass unchanged.