generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 27
feat(core): Add CoreSMT verification pipeline with incremental solver and diagnosis #475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MikaelMayer
wants to merge
201
commits into
main
Choose a base branch
from
migrate-b3-smt-pipeline-core-to-core
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,575
−1,885
Open
Changes from all commits
Commits
Show all changes
201 commits
Select commit
Hold shift + click to select a range
99ba9b8
Add support for function declarations within statement blocks
MikaelMayer 6b1cdc2
Fix Factory_wf proof using rotate_left to reorder goals
MikaelMayer a8a4a0c
Remove unnecessary Lambda namespace opening in Statement.lean
MikaelMayer b8ec252
Remove unnecessary Lambda namespace opening in Program.lean
MikaelMayer d666882
Restore proper function body formatting by adding ToFormat instance f…
MikaelMayer ed1f8ac
Remove B3 .gitignore (moved to .git/info/exclude for local use)
MikaelMayer c6ede80
Clean up: revert ProcedureWF.lean to main, remove unnecessary comment
MikaelMayer 77eb4fa
Merge main into add-func-decl-to-statements
MikaelMayer 62a5f70
Fix merge: add missing funcDecl cases in ProcedureInlining and apply …
MikaelMayer 5f65da9
Update funcDecl test to demonstrate variable capture semantics
MikaelMayer a13b470
Merge branch 'main' into add-func-decl-to-statements
MikaelMayer 6797599
Fix merge: convert Format to String for EvalError.Misc
MikaelMayer 5ceddf3
Implement value capture for funcDecl: substitute free variables at de…
MikaelMayer 86f6c90
Fix merge: convert Format errors to DiagnosticModel in funcDecl type …
MikaelMayer 776a87d
Merge branch 'main' into add-func-decl-to-statements
shigoel dbfe96e
Add polymorphic function test for funcDecl with evaluation verification
MikaelMayer ebbab10
Update semantics and proofs for FuncContext parameter in EvalStmt/Eva…
MikaelMayer 494dedc
Merge branch 'main' into add-func-decl-to-statements
MikaelMayer c588f0c
Fix eval_stmts_set_comm proof after FuncContext refactor
MikaelMayer 93914c6
Thread δ through semantics instead of FuncContext
MikaelMayer 95a3386
Merge branch 'main' into add-func-decl-to-statements
MikaelMayer dfd9dcc
Address PR review comments: refactor Func, fix type checking, remove …
MikaelMayer a86b658
Fix getVarsTrans to exclude formal parameters for funcDecl
MikaelMayer 92ab1f8
Fix funcDecl_sem case in EvalStmtRefinesContract theorem
MikaelMayer dc17906
Update comment: funcDecl WF checks are TODO, not always true
MikaelMayer 117aeab
Add well-formedness checks for funcDecl in StatementWF
MikaelMayer e673135
Add extendEval parameter to DetToNondetCorrect theorems
MikaelMayer e1ce657
Merge main into add-func-decl-to-statements
MikaelMayer 049bff4
Fix FactoryWF.lean to use LFuncWF instead of FuncWF after merge
MikaelMayer 3183890
Merge branch 'main' into add-func-decl-to-statements
MikaelMayer 80c1833
Fix unused section variable warning in LFunc.type_inputs_nodup
MikaelMayer a8e9809
Add DDM support for function declaration statements
MikaelMayer b05a3b4
Remove incorrect test file
MikaelMayer e188726
Fix DDM translateExpr to support bound function calls with arguments
MikaelMayer c0e5d13
Fix function declaration statement bound variable scoping
MikaelMayer d415650
Fix bound variable issue in function declaration translation
MikaelMayer f630000
Fix function declaration DDM transform bound variable issues
MikaelMayer b52d16f
Fix function declaration statement parsing in DDM transform
MikaelMayer 34ccb82
Merge main into add-function-statements-ddm
MikaelMayer a7c50c1
Merge branch 'main' into add-function-statements-ddm
MikaelMayer 8455248
Remove trivial EvalCmd_eval_cst theorem
MikaelMayer 6cacee5
Add support for parsing top-level blocks directly
MikaelMayer 117b3fd
Refactor: merge duplicate bvar handling cases
MikaelMayer f7088a8
Fix: use func.opExpr for correct function type in fvar translation
MikaelMayer bf9a6c9
Add requirements for Core SMT verifier pipeline
MikaelMayer f46e006
Add CoreSMT verifier requirements and design specs
MikaelMayer b1c68d8
Add implementation tasks for CoreSMT Verifier spec
MikaelMayer ebaa2df
Task 1: Extend Cmd.init to support optional RHS expression
MikaelMayer 0d15757
Task 1: Extend Cmd.init to support optional RHS expression
MikaelMayer e48d39c
Merge feat/optional-init-rhs into migrate-b3-smt-pipeline-core-to-core
MikaelMayer 4f558be
feat: Support optional RHS in Cmd.init for unconstrained variable dec…
MikaelMayer 925cead
Merge feat/optional-init-rhs
MikaelMayer 11d8c04
feat: Support optional RHS in Cmd.init for unconstrained variable dec…
MikaelMayer e9786ed
Merge feat/optional-init-rhs
MikaelMayer 32fc046
Add DDM parser support for init without RHS
MikaelMayer a730eb6
Fix CI errors
MikaelMayer 91c9531
Merge branch 'feat/optional-init-rhs' into migrate-b3-smt-pipeline-co…
MikaelMayer f52347a
Merge branch 'main' into feat/optional-init-rhs
MikaelMayer 2caff99
Fix remaining CI errors after merge with main
MikaelMayer 564d427
Merge branch 'feat/optional-init-rhs' into migrate-b3-smt-pipeline-co…
MikaelMayer 6eadd55
Add SMT Solver Interface for CoreSMT Verifier (Task 3)
MikaelMayer 875e064
Add isCoreSMT predicate for CoreSMT subset (Task 4)
MikaelMayer 9f234e5
Add CoreSMT state/context management and fix namespaces (Task 5)
MikaelMayer 74083d9
Add expression translator for CoreSMT (Task 6)
MikaelMayer 01a39e6
Add statement processor, verifier interface, and main module (Tasks 8…
MikaelMayer de87707
Fix C_Simp Verify for optional init RHS
MikaelMayer 3101195
Merge branch 'main' into migrate-b3-smt-pipeline-core-to-core
MikaelMayer fd89d26
Update task list with completed items
MikaelMayer 83f17d4
Add diagnosis engine, fix CBMC build failures (Tasks 9, 11)
MikaelMayer 783c6c6
Add B3 to Core converter (Task 14)
MikaelMayer f893264
Fix CoreToCProverGOTO for optional init RHS
MikaelMayer a1922ac
Update task list - all CoreSMT implementation tasks complete
MikaelMayer 42b48fd
Remove initStatementNoRhs - varStatement already handles var declarat…
MikaelMayer b0fab71
Remove scratch experiment files
MikaelMayer 70c4f8f
Fix test files for optional init RHS and remove initStatementNoRhs
MikaelMayer a6f9d72
Update tasks.md - mark task 14 complete
MikaelMayer 746a98f
Fix B3→Core quantifier conversion to use bvar, add test harness, upda…
MikaelMayer 49a2459
feat(core): Add diagnosis field to VCResult for refuted assertions
MikaelMayer 2c60c01
test(b3): Add CoreSMT pipeline tests for B3 verifier
MikaelMayer f0cfc4c
wip(b3): Begin migration to CoreSMT pipeline
MikaelMayer 977c3c1
feat(b3): Complete migration to CoreSMT pipeline
MikaelMayer 3289a42
test(b3): Add integration test for CoreSMT pipeline
MikaelMayer 02ce10d
Merge main into migrate-b3-smt-pipeline-core-to-core
MikaelMayer fc66261
chore: Remove development artifacts
MikaelMayer 1f667ce
fix: Restore accidentally deleted code and remove duplicate VerboseMode
MikaelMayer 5658c04
fix: Reuse existing types and fix CoreSMT issues
MikaelMayer 3895dd8
fix: Complete type reuse and build fixes
MikaelMayer d188d3f
fix: Restore accidentally deleted B3/Verifier/Program.lean
MikaelMayer f52b554
fix: Update B3 tests to use CoreSMT pipeline
MikaelMayer 73c4402
fix: Restore old B3 verifier files for existing tests
MikaelMayer a3869cf
Merge branch 'main' into migrate-b3-smt-pipeline-core-to-core
MikaelMayer d26a674
fix: Address PR feedback - proper error handling and cleanup
MikaelMayer 0ce4729
refactor: Improve error handling and fix test expectations
MikaelMayer 29acc8d
refactor: Complete translateOrThrow removal - use error collection
MikaelMayer 4547dee
docs: Add TODO comments for remaining architectural improvements
MikaelMayer d71be51
refactor: Move SolverInterface to SMT dialect and use check-sat-assuming
MikaelMayer f86f5dd
test: Fix remaining test expectations for optional RHS
MikaelMayer c8f37f0
refactor: Use ConvResult for proper error collection in B3→Core
MikaelMayer 6c43d2f
refactor: Move State to SMT dialect and rename StmtProcessor to StmtV…
MikaelMayer 639c4b2
refactor: Move accumulateErrors to CoreSMT, remove unused config from…
MikaelMayer a6250f8
docs: Update State.lean comment to remove configuration reference
MikaelMayer 4b07317
refactor: Remove unused resultCount from VerifierState
MikaelMayer 18444ce
refactor: Delete old B3→SMT verifier, keep API stubs for test compati…
MikaelMayer 2757afa
feat: Implement CoreSMT to B3 result conversion for test compatibility
MikaelMayer 587ba53
fix: Add type annotations for solver accessor calls
MikaelMayer e996495
fix: Rename parameter to avoid shadowing in processStatements
MikaelMayer 058224a
refactor: Remove FunctionToAxiom, add CoreSMT State, create B3 Format…
MikaelMayer ae53d98
feat: Implement diagnosis in CoreSMT verifier
MikaelMayer 18c289a
feat: Add Core→B3 expression converter stub
MikaelMayer d9b0e8d
feat: Implement Core→B3 expression converter
MikaelMayer 8dac950
fix: Correct function calls in Diagnosis module
MikaelMayer 4288d10
feat: Change Core metadata from Unit to SourceRange
MikaelMayer 18c550f
feat: Preserve source locations in B3↔Core conversion
MikaelMayer 52f03b5
fix: Replace all () metadata with SourceRange.none
MikaelMayer 597ab05
fix: Complete metadata replacement in Transform and Python files
MikaelMayer 797ab4b
fix: Complete metadata replacement across all files
MikaelMayer dcd64f9
fix: Fix remaining metadata issues in CoreSMT
MikaelMayer 2b69f5d
feat: Add diagnosis support to CoreSMT verifier
MikaelMayer 38e5e5a
fix: Use proper solver initialization and fix cvc5 PATH
MikaelMayer a8a553b
fix: Pass procedure name as label in B3→Core conversion
MikaelMayer 7f1642f
fix: Add Core→B3 conversion in test diagnosis display
MikaelMayer ec29757
feat: Implement Core→B3 expression conversion for diagnosis
MikaelMayer 0a21a7f
feat: Add statement display and multi-result support
MikaelMayer e8a17c8
fix: Update test expectations and fix assert semantics
MikaelMayer aa45292
fix: Correct source location offsets for statements vs expressions
MikaelMayer f466772
feat: Complete diagnosis with assumptions and fix HO_ error
MikaelMayer 75bc7d1
feat: Migrate commented-out exampleVerification test
MikaelMayer e9da659
merge: Merge main into branch and fix all conflicts
MikaelMayer 5514121
fix: Fix all test failures after merge with main
MikaelMayer e385ffd
fix: Fix CI failures - StrataVerify import and CBMC metadata
MikaelMayer 2e294c6
refactor: Use csimpMetaToCore conversion function in C_Simp/Verify
MikaelMayer 69fe2e8
refactor: Extract TermType.toSMTString to TermType.lean
MikaelMayer d2fa219
ci: Trigger CI build
MikaelMayer 055fb5a
ci: Trigger CI build (2)
MikaelMayer f9de856
merge: Merge latest main into branch
MikaelMayer 72e2a0b
merge: Merge main (multiple invariants in Core loop)
MikaelMayer fd9e258
refactor: Remove dead code identified in review
MikaelMayer 887b160
merge: Merge main + address PR review comments
MikaelMayer ad921d6
merge: Merge main (mandatory Cmd/Stmt metadata) + fix all () metadata
MikaelMayer 9fd1a7d
fix: Check procedure params/specs are empty in B3→Core conversion
MikaelMayer f90f8ff
refactor: Remove dead fields from DiagnosisResult and DiagnosedFailure
MikaelMayer a3e6b79
merge: Merge main (goto→exit) + fix IsCoreSMT
MikaelMayer cc982d3
merge: Auto-merge latest main
MikaelMayer 44fa111
merge: Auto-merge latest main
MikaelMayer dfe079d
fix: Use createInteractiveSolver in StrataVerify for solver-agnostic …
MikaelMayer 3a58a11
merge: Merge main (Laurel function/procedure split)
MikaelMayer 524f4e6
ci: Force cache invalidation for Laurel grammar rebuild
MikaelMayer e184d23
fix: Invalidate Laurel/DDM .olean cache before build
MikaelMayer 623b404
fix: Include .st files in lake cache key to prevent stale Laurel .olean
MikaelMayer 8732c61
merge: Merge main (fix duplicate loop labels)
MikaelMayer a30c263
fix: Apply .st cache fix to CBMC workflow as well
MikaelMayer b3f7086
refactor: Remove stateful comment from Identifiers.lean
MikaelMayer af084db
refactor: Extract formatOp helper to remove duplication in Format.lean
MikaelMayer 31b6fcc
refactor: Simplify StmtVerifier - unify proveCheck/coverCheck, extrac…
MikaelMayer 391b9c7
fix: Address reviewer comments on TranslationTests and VerifierTests
MikaelMayer 197bd1f
fix: Restore push/pop in TranslationTests, only filter prelude commands
MikaelMayer f516193
fix: Remove Option datatype from CoreSMT prelude
MikaelMayer 4610ccc
fix: Fix diagnosis to correctly identify proved/refuted sub-expressions
MikaelMayer 36e01a5
ci: Revert CI cache changes (extracted to PR #498)
MikaelMayer ff0b7ac
fix: Thread conjunction path conditions through diagnosis
MikaelMayer b76a40a
fix: Show 'assert' instead of 'check' for assert statement failures
MikaelMayer 9a9173a
fix: Restore Identifiers tests and propagate DDM source ranges in Tra…
MikaelMayer de62017
fix: Address remaining reviewer comments
MikaelMayer e36f56f
merge: Merge main (SimpleAPI refactor + CI cache fix)
MikaelMayer bf36915
fix: Make SourceRange Repr always show () and erase metadata in erase…
MikaelMayer a04e796
feat: Add --interactive flag for in-memory CoreSMT verification
MikaelMayer 91dbc61
merge: Merge main (PyLaurel class support, remove Visibility from Cor…
MikaelMayer eddbf0a
fix: Add test_interactive_simple to expected_laurel to debug translation
MikaelMayer a1c155d
fix: Rename --interactive to --incremental, add debug output for incr…
MikaelMayer 7935d24
Improve incremental CoreSMT verifier: better errors, dead var elimina…
MikaelMayer 1169d8f
Replace test_interactive_simple with test_incremental_simple, fix --i…
MikaelMayer 2de9e54
Remove unnecessary skip for test_incremental_simple in laurel mode
MikaelMayer cc32c8d
fix: Rename interactive→incremental in script/CI, fix expected dir name
MikaelMayer bcbb96f
merge: Integrate reviewer's incremental verifier improvements
MikaelMayer 112243f
fix: Fix indentation in pyAnalyzeLaurel non-incremental print loop
MikaelMayer 2e4d6de
fix: Update test_incremental_simple expected byte offsets
MikaelMayer f2264f2
fix: Update expected_interactive byte offsets for test_incremental_si…
MikaelMayer dc8dcb0
fix: Skip test_incremental_simple in pyAnalyze and SARIF tests
MikaelMayer bcf1939
merge: Merge main (LExpr named quantifiers, datatype destructors)
MikaelMayer 1c68d0e
fix: Address review comments
MikaelMayer 24a07f2
refactor: Move DiagnosisTypes out of CoreSMT namespace
MikaelMayer 81717b5
fix: Address remaining review comments
MikaelMayer 9cf672e
merge: Merge main (LExprModel counterexample support)
MikaelMayer 1df67f9
fix: Qualify Lean.FileMap in extracted verify functions
MikaelMayer d3e7702
fix: Address review comments
MikaelMayer fa00716
merge: Merge main
MikaelMayer e2b8ac0
fix: Address review comments
MikaelMayer e8d8bb5
fix: Make --incremental independent of laurel in run_py_analyze.sh
MikaelMayer 1ae0a7a
merge: Merge main (exit statement for Laurel return)
MikaelMayer 74c0054
merge: Merge main (Laurel exit statement, isPureExpr cases)
MikaelMayer d338480
fix: --incremental requires laurel mode
MikaelMayer 884bc01
merge: Merge main (public imports, fileMap changes)
MikaelMayer e968fc7
fix: Apply SourceRange.none to all merged files
MikaelMayer f988f3b
fix: Update pySourceOpt to use source text instead of FileMap
MikaelMayer 0e488e7
fix: Use expr metadata for Laurel literals
MikaelMayer 8610c0f
Merge branch 'main' into migrate-b3-smt-pipeline-core-to-core
MikaelMayer 6452cee
fix: Add typeDecl case to CoreSMT predicates
MikaelMayer 5014be6
Merge branch 'main' into migrate-b3-smt-pipeline-core-to-core
MikaelMayer 83d9942
merge: Merge main (typeDecl, propType for division by zero)
MikaelMayer 7b4cded
merge: Merge main (regex helper refactor)
MikaelMayer d112689
Merge branch 'main' into migrate-b3-smt-pipeline-core-to-core
MikaelMayer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /- | ||
| Copyright Strata Contributors | ||
|
|
||
| SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| -/ | ||
|
|
||
| import Strata.DL.SMT.Solver | ||
| import Strata.DL.SMT.Term | ||
| import Strata.DL.SMT.TermType | ||
| import Strata.DL.SMT.DDMTransform.Translate | ||
| import Strata.Languages.Core.Options | ||
|
|
||
| /-! | ||
| # SMT Solver Interface | ||
|
|
||
| Abstract interface for SMT solvers using `Strata.SMT.Term` and `Strata.SMT.TermType`. | ||
| Converts to SMT-LIB strings via `SMTDDM.toString` when communicating with solvers. | ||
|
|
||
| The interface is a structure (not a type class) to allow runtime selection of | ||
| different solver backends. | ||
| -/ | ||
|
|
||
| namespace Strata.SMT | ||
|
|
||
| open Strata.SMT | ||
|
|
||
| /-- Abstract interface for SMT solvers. | ||
| Uses Strata.SMT.Term which can be converted to SMT-LIB strings via SMTDDM.toString -/ | ||
| structure SolverInterface where | ||
| /-- Push a new scope onto the solver stack -/ | ||
| push : IO Unit | ||
| /-- Pop the top scope from the solver stack -/ | ||
| pop : IO Unit | ||
| /-- Declare an uninterpreted sort -/ | ||
| declareSort : String → Nat → IO Unit | ||
| /-- Declare an uninterpreted function -/ | ||
| declareFun : String → List TermType → TermType → IO Unit | ||
| /-- Define a function with a body -/ | ||
| defineFun : String → List (String × TermType) → TermType → Term → IO Unit | ||
| /-- Assert a term -/ | ||
| assert : Term → IO Unit | ||
| /-- Check satisfiability -/ | ||
| checkSat : IO Decision | ||
| /-- Check satisfiability with assumptions (check-sat-assuming) -/ | ||
| checkSatAssuming : List Term → IO Decision | ||
| /-- Get model values for variables -/ | ||
| getModel : List String → IO (List (String × String)) | ||
| /-- Reset the solver state -/ | ||
| reset : IO Unit | ||
|
|
||
| /-- Helper to convert Term to SMT-LIB string -/ | ||
| private def termToString (t : Term) : Except String String := | ||
| Strata.SMTDDM.termToString t | ||
|
|
||
| /-- Helper to create an SMTSolverInterface from an initialized Solver -/ | ||
| def mkSolverInterfaceFromSolver (solver : Solver) : IO SolverInterface := do | ||
| let solverRef ← IO.mkRef solver | ||
| return { | ||
| push := do | ||
| let s ← solverRef.get | ||
| s.smtLibInput.putStr "(push 1)\n" | ||
| s.smtLibInput.flush | ||
| pop := do | ||
| let s ← solverRef.get | ||
| s.smtLibInput.putStr "(pop 1)\n" | ||
| s.smtLibInput.flush | ||
| declareSort := fun name arity => do | ||
| let _ ← (Solver.declareSort name arity).run (← solverRef.get) | ||
| declareFun := fun name argTypes retType => do | ||
| let _ ← (Solver.declareFun name argTypes retType).run (← solverRef.get) | ||
| defineFun := fun name args retType body => do | ||
| let _ ← (Solver.defineFunTerm name args retType body).run (← solverRef.get) | ||
| assert := fun term => do | ||
| let _ ← (Solver.assert term).run (← solverRef.get) | ||
| checkSat := do | ||
| (Solver.checkSat []).run (← solverRef.get) >>= fun (d, _) => pure d | ||
| checkSatAssuming := fun assumptions => do | ||
| let s ← solverRef.get | ||
| let assumptionStrs ← assumptions.mapM fun a => | ||
| match termToString a with | ||
| | .ok str => pure str | ||
| | .error e => throw (IO.userError s!"Failed to convert term to string: {e}") | ||
| let assumptionsStr := String.intercalate " " assumptionStrs | ||
| s.smtLibInput.putStr s!"(check-sat-assuming ({assumptionsStr}))\n" | ||
| s.smtLibInput.flush | ||
| match s.smtLibOutput with | ||
| | .some stdout => | ||
| let result := (← stdout.getLine).trimAscii.toString | ||
| match result with | ||
| | "sat" => return .sat | ||
| | "unsat" => return .unsat | ||
| | "unknown" => return .unknown | ||
| | other => throw (IO.userError s!"Unrecognized solver output: {other}") | ||
| | .none => return .unsat -- Buffer solver: assume proved (no diagnosis) | ||
| getModel := fun vars => do | ||
| let s ← solverRef.get | ||
| let varsStr := String.intercalate " " vars | ||
| s.smtLibInput.putStr s!"(get-value ({varsStr}))\n" | ||
| s.smtLibInput.flush | ||
| match s.smtLibOutput with | ||
| | .some stdout => | ||
| let response ← stdout.getLine | ||
| return vars.map fun v => (v, response) | ||
| | .none => return [] | ||
| reset := do | ||
| let _ ← (Solver.reset).run (← solverRef.get) | ||
| let _ ← (Solver.setLogic "ALL").run (← solverRef.get) | ||
| : SolverInterface } | ||
|
|
||
| end Strata.SMT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /- | ||
| Copyright Strata Contributors | ||
|
|
||
| SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| -/ | ||
|
|
||
| import Strata.DL.SMT.SolverInterface | ||
| import Strata.Languages.Core.Expressions | ||
|
|
||
| /-! | ||
| # SMT State and Context Management | ||
|
|
||
| Defines the SMT solver state and context tracking. The state is returned from | ||
| verify calls to enable reuse across multiple verification sessions. | ||
| -/ | ||
|
|
||
| namespace Strata.SMT | ||
|
|
||
| open Strata.SMT | ||
|
|
||
| /-- A context item represents something added to the SMT solver state -/ | ||
| inductive ContextItem where | ||
| /-- An assumed expression (as SMT term) -/ | ||
| | assumption : Term → ContextItem | ||
| /-- A declared sort (name, arity) -/ | ||
| | sortDecl : String → Nat → ContextItem | ||
| /-- A declared function (name, arg types, return type) -/ | ||
| | funcDecl : String → List TermType → TermType → ContextItem | ||
| /-- A defined function (name, args, return type, body) -/ | ||
| | funcDef : String → List (String × TermType) → TermType → Term → ContextItem | ||
| /-- A declared variable (name, type) -/ | ||
| | varDecl : String → TermType → ContextItem | ||
| /-- A defined variable (name, type, value) -/ | ||
| | varDef : String → TermType → Term → ContextItem | ||
|
|
||
| /-- A scope is a list of context items added at the same push level -/ | ||
| abbrev ContextScope := List ContextItem | ||
|
|
||
| /-- Context stack: a stack of scopes, where each scope corresponds to a push level. | ||
| The head of the list is the current (innermost) scope. -/ | ||
| abbrev ContextStack := List ContextScope | ||
|
|
||
| /-- Verification state that can be reused across calls -/ | ||
| structure VerifierState where | ||
| /-- The SMT solver interface -/ | ||
| solver : SMT.SolverInterface | ||
| /-- Stack of context scopes (for push/pop support) -/ | ||
| contextStack : ContextStack | ||
|
|
||
| /-- Create initial state from a solver interface -/ | ||
| def VerifierState.init (solver : SMT.SolverInterface) : VerifierState := | ||
| { solver, contextStack := [[]] } | ||
|
|
||
| /-- Push a new scope onto the context stack -/ | ||
| def VerifierState.push (state : VerifierState) : IO VerifierState := do | ||
| state.solver.push | ||
| return { state with contextStack := [] :: state.contextStack } | ||
|
|
||
| /-- Pop the top scope from the context stack -/ | ||
| def VerifierState.pop (state : VerifierState) : IO VerifierState := do | ||
| state.solver.pop | ||
| match state.contextStack with | ||
| | [] => return state | ||
| | _ :: rest => return { state with contextStack := rest } | ||
|
|
||
| /-- Add an item to the current scope -/ | ||
| def VerifierState.addItem (state : VerifierState) (item : ContextItem) : VerifierState := | ||
| match state.contextStack with | ||
| | [] => { state with contextStack := [[item]] } | ||
| | scope :: rest => { state with contextStack := (item :: scope) :: rest } | ||
|
|
||
| /-- Get all context items (flattened from all scopes) for error reporting -/ | ||
| def VerifierState.allContextItems (state : VerifierState) : List ContextItem := | ||
| state.contextStack.flatten | ||
|
|
||
| end Strata.SMT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /- | ||
| Copyright Strata Contributors | ||
|
|
||
| SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| -/ | ||
|
|
||
| import Strata.Languages.B3.DDMTransform.Conversion | ||
| import Strata.Languages.B3.DDMTransform.DefinitionAST | ||
|
|
||
| /-! | ||
| # B3 Formatting Utilities | ||
|
|
||
| Helper functions for formatting B3 AST nodes to strings using DDM. | ||
| -/ | ||
|
|
||
| namespace B3 | ||
|
|
||
| open Strata | ||
|
|
||
| /-- Get metadata from B3 expression -/ | ||
| def getExpressionMetadata (expr : B3AST.Expression SourceRange) : SourceRange := | ||
| match expr with | ||
| | .literal m _ => m | ||
| | .id m _ => m | ||
| | .ite m _ _ _ => m | ||
| | .binaryOp m _ _ _ => m | ||
| | .unaryOp m _ _ => m | ||
| | .functionCall m _ _ => m | ||
| | .labeledExpr m _ _ => m | ||
| | .letExpr m _ _ _ => m | ||
| | .quantifierExpr m _ _ _ _ => m | ||
|
|
||
| /-- Format a DDM operation AST node to string -/ | ||
| private def formatOp (prog : Program) (op : Operation) : String := | ||
| let fmtCtx := FormatContext.ofDialects prog.dialects prog.globalContext {} | ||
| let fmtState : FormatState := { openDialects := prog.dialects.toList.foldl (init := {}) fun a (dialect : Dialect) => a.insert dialect.name } | ||
| (mformat (ArgF.op op) fmtCtx fmtState).format.pretty.trimAscii.toString | ||
|
|
||
| /-- Format B3 statement to string -/ | ||
| def formatStatement (prog : Program) (stmt : B3AST.Statement SourceRange) (ctx : ToCSTContext) : String := | ||
| let (cstStmt, _) := B3.stmtToCST ctx stmt | ||
| formatOp prog cstStmt.toAst | ||
|
|
||
| /-- Format B3 expression to string -/ | ||
| def formatExpression (prog : Program) (expr : B3AST.Expression SourceRange) (ctx : ToCSTContext) : String := | ||
| let (cstExpr, _) := B3.expressionToCST ctx expr | ||
| formatOp prog cstExpr.toAst | ||
|
|
||
| end B3 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.