-
Notifications
You must be signed in to change notification settings - Fork 45
Move Boole dialect to the StrataBoole package #1210
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
atomb
wants to merge
3
commits into
main
Choose a base branch
from
boole-package
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.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 @@ | ||
| .lake |
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,9 @@ | ||
| /- | ||
| Copyright Strata Contributors | ||
| SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| -/ | ||
| import StrataBoole.Boole | ||
| import StrataBoole.Grammar | ||
| import StrataBoole.MetaVerifier | ||
| import StrataBoole.Verify |
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
File renamed without changes.
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,118 @@ | ||
| /- | ||
| Copyright Strata Contributors | ||
|
|
||
| SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| -/ | ||
| module | ||
|
|
||
| public import Strata.MetaVerifier -- shake: keep | ||
| public import StrataBoole.Verify | ||
| meta import Lean.Meta.Eval | ||
| import Lean.Meta.Eval -- shake: keep | ||
| import Lean.Meta.Tactic.Rewrite -- shake: keep | ||
| meta import Lean.Meta.Tactic.Rewrite | ||
| import Lean.Meta.Tactic.Unfold -- shake: keep | ||
| meta import Lean.Meta.Tactic.Unfold | ||
|
|
||
| /-! | ||
| # Boole MetaVerifier | ||
|
|
||
| Extends `Strata.MetaVerifier` with Boole dialect support for `genCoreVCs` and | ||
| `smtVCsCorrect`. Test files in the `StrataBoole` package should import this | ||
| module instead of `Strata.MetaVerifier` directly. | ||
| -/ | ||
|
|
||
| public section | ||
|
|
||
| namespace Strata.Boole | ||
|
|
||
| def genVCs (program : Strata.Boole.Program) (gctx : Strata.GlobalContext) (options : Core.VerifyOptions := .default) : Option Core.coreVCs := do | ||
| let program ← (Strata.Boole.toCoreProgram program gctx).toOption | ||
| Core.genVCs program options | ||
|
|
||
| end Strata.Boole | ||
|
|
||
| namespace Strata | ||
|
|
||
| /-- | ||
| Generate verification conditions for a `Strata.Program`, with Boole support. | ||
| Extends `Strata.genCoreVCs` to handle the Boole dialect. | ||
| -/ | ||
| def genCoreVCsBoole (program : Program) : Option Core.coreVCs := do | ||
| if program.dialect == "Boole" then | ||
| match Boole.getProgram program with | ||
| | .ok booleProgram => | ||
| Boole.genVCs booleProgram program.globalContext { (default : Core.VerifyOptions) with verbose := .quiet : Core.VerifyOptions } | ||
| | .error _ => none | ||
| else | ||
| genCoreVCs program | ||
|
|
||
| /-- | ||
| Generate SMT verification conditions for a `Strata.Program`, with Boole support. | ||
| -/ | ||
| def genSMTVCsBoole (program : Program) : Option SMT.SMTVCs := do | ||
| let coreVCs ← genCoreVCsBoole program | ||
| toSMTVCs coreVCs | ||
|
|
||
| /-- | ||
| State semantic correctness of the SMT verification conditions generated for a | ||
| program, with Boole dialect support. | ||
| -/ | ||
| def smtVCsCorrectBoole (program : Program) : Prop := | ||
| match genSMTVCsBoole program with | ||
| | some vcs => (denoteQueries vcs).getD False | ||
| | none => False | ||
|
|
||
| end Strata | ||
|
|
||
| namespace Strata.Meta | ||
|
|
||
| open Lean hiding Options | ||
|
|
||
| private unsafe def genSMTVCsBooleUnsafe (mv : MVarId) : MetaM (List MVarId) := do | ||
| let type ← mv.getType | ||
| let some program := type.app1? ``Strata.smtVCsCorrectBoole | throwError "Expected a Strata.smtVCsCorrectBoole goal" | ||
| trace[debug] m!"Generating SMT VCs for {program}" | ||
| let mv ← Meta.unfoldTarget mv ``Strata.smtVCsCorrectBoole | ||
| let ovcs := .app (.const ``Strata.genSMTVCsBoole []) program | ||
| let ovcsType := .app (.const ``Option [0]) (.const ``Strata.SMT.SMTVCs []) | ||
| let some evcs ← Meta.evalExpr (Option Strata.SMT.SMTVCs) ovcsType ovcs | ||
| | throwError "Failed to generate VCs" | ||
| trace[debug] m!"Generated {repr evcs}" | ||
| let rhs := toExpr (some evcs) | ||
| let eqVCs := mkApp3 (.const ``Eq [1]) ovcsType ovcs rhs | ||
| let hEQVCs ← nativeDecide eqVCs | ||
| let r ← mv.rewrite (← mv.getType) hEQVCs | ||
| let mv ← mv.replaceTargetEq r.eNew r.eqProof | ||
| let mvs ← evcs.mapM SMT.createGoal | ||
| trace[debug] m!"Created {mvs.length} SMT VC goals: {mvs}" | ||
| let ps ← mvs.mapM MVarId.getType | ||
| let hP := andNIntro (List.zip ps (mvs.map Expr.mvar)) | ||
| mv.assign hP | ||
| return mvs | ||
|
|
||
| @[implemented_by genSMTVCsBooleUnsafe] | ||
| meta opaque genSMTVCsBoole (mv : MVarId) : MetaM (List MVarId) | ||
|
|
||
| end Strata.Meta | ||
|
|
||
| namespace Strata.Tactic | ||
|
|
||
| open Lean Elab Tactic in | ||
| /-- | ||
| Generate one Lean goal per SMT verification condition in a goal of the form | ||
| `Strata.smtVCsCorrectBoole program`. Boole-aware variant of `gen_smt_vcs`. | ||
| -/ | ||
| syntax (name := genSMTVCsBoole) "gen_smt_vcs_boole" : tactic | ||
|
|
||
| open Lean Elab Tactic in | ||
| @[tactic genSMTVCsBoole] meta def evalGenSMTVCsBoole : Tactic := fun stx => do | ||
| match stx with | ||
| | `(tactic| gen_smt_vcs_boole) => | ||
| let mvs ← Meta.genSMTVCsBoole (← Tactic.getMainGoal) | ||
| Tactic.replaceMainGoal mvs | ||
| | _ => throwUnsupportedSyntax | ||
|
|
||
| end Strata.Tactic | ||
|
|
||
| end -- public section |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /- | ||
| Copyright Strata Contributors | ||
|
|
||
| SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| -/ | ||
| import StrataBooleTest.array_2d | ||
| import StrataBooleTest.array_assignment | ||
| import StrataBooleTest.bit_vectors | ||
| import StrataBooleTest.code_expression | ||
| import StrataBooleTest.demo | ||
| import StrataBooleTest.deterministic | ||
| import StrataBooleTest.find_max | ||
| import StrataBooleTest.find_max_verus | ||
| import StrataBooleTest.format_program | ||
| import StrataBooleTest.function_definitions | ||
| import StrataBooleTest.global_readonly_call | ||
| import StrataBooleTest.grammar_extensions | ||
| import StrataBooleTest.insertion_sort | ||
| import StrataBooleTest.loop_simple | ||
| import StrataBooleTest.procedure_signatures | ||
| import StrataBooleTest.square_matrix_multiply | ||
| import StrataBooleTest.stack_array_based | ||
| import StrataBooleTest.string_operators | ||
| import StrataBooleTest.top_level_block_selection | ||
| import StrataBooleTest.verification_coverage | ||
| import StrataBooleTest.FeatureRequests.abstract_types_and_stubs | ||
| import StrataBooleTest.FeatureRequests.bitvector_ops | ||
| import StrataBooleTest.FeatureRequests.bitvector_proof_mode | ||
| import StrataBooleTest.FeatureRequests.choose_operator | ||
| import StrataBooleTest.FeatureRequests.datatypes_and_selectors | ||
| import StrataBooleTest.FeatureRequests.decreases_metadata | ||
| import StrataBooleTest.FeatureRequests.early_return | ||
| import StrataBooleTest.FeatureRequests.higher_order_encoding | ||
| import StrataBooleTest.FeatureRequests.horner_poly_eval | ||
| import StrataBooleTest.FeatureRequests.lambda_closure | ||
| import StrataBooleTest.FeatureRequests.map_extensionality | ||
| import StrataBooleTest.FeatureRequests.mutual_recursion | ||
| import StrataBooleTest.FeatureRequests.nat_int_boundary | ||
| import StrataBooleTest.FeatureRequests.opaque_reveal_hide | ||
| import StrataBooleTest.FeatureRequests.option_matches | ||
| import StrataBooleTest.FeatureRequests.overflow_guard | ||
| import StrataBooleTest.FeatureRequests.reveal_with_fuel | ||
| import StrataBooleTest.FeatureRequests.seq_slicing | ||
| import StrataBooleTest.FeatureRequests.struct_field_access | ||
| import StrataBooleTest.FeatureRequests.trait_spec_methods | ||
| import StrataBooleTest.FeatureRequests.widening_casts |
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
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
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.