forked from leanprover/LNSym
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring tactics for symbolic simulation
- Loading branch information
Showing
10 changed files
with
454 additions
and
132 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,34 @@ | ||
/- | ||
Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Author(s): Shilpi Goel | ||
-/ | ||
|
||
import Lean | ||
import Arm.Exec | ||
open Lean Elab Tactic Expr Meta | ||
open BitVec | ||
|
||
|
||
/- Obtain `Array α` from `Array (Option α)` by discarding any `none` | ||
elements. -/ | ||
private def optionArraytoArray (array : Array (Option α)) : Array α := | ||
Array.foldl (fun acc val => | ||
match val with | ||
| none => acc | ||
| some v => acc.append #[v]) | ||
#[] array | ||
|
||
/- Find all declarations in the `LocalContext` whose username begins | ||
with `pfxUserName`. -/ | ||
def filterDeclsWithPrefix (lctx : LocalContext) (pfxUserName : Name) | ||
: (Array LocalDecl) := | ||
optionArraytoArray | ||
(PersistentArray.toArray | ||
(PersistentArray.filter | ||
lctx.decls | ||
(fun decl => | ||
match decl with | ||
| none => false | ||
| some decl => String.isPrefixOf (toString pfxUserName) | ||
(toString decl.userName)))) |
This file contains 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,50 @@ | ||
/- | ||
Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Author(s): Shilpi Goel | ||
-/ | ||
import Arm.Exec | ||
import Tactics.Common | ||
import Tactics.Simp | ||
import Lean | ||
open Lean Elab Tactic Expr Meta | ||
open BitVec | ||
|
||
---------------------------------------------------------------------- | ||
|
||
def execInst (goal : MVarId) (h_step : Expr) (hyp_prefix : String) | ||
: TacticM Bool := goal.withContext do | ||
-- Find all the FVars in the local context whose name begins with | ||
-- hyp_prefix. | ||
let lctx ← getLCtx | ||
let matching_decls := filterDeclsWithPrefix lctx hyp_prefix.toName | ||
-- logInfo m!"matching_decls: {matching_decls[0]!.userName}" | ||
let (ctx, simprocs) ← | ||
LNSymSimpContext (config := {decide := true, ground := true}) | ||
(simp_attrs := #[`minimal_theory, `bitvec_rules, `state_simp_rules]) | ||
(decls_to_unfold := #[``exec_inst]) | ||
(thms := #[]) | ||
(decls := matching_decls) | ||
(simprocs := #[``reduceIte]) | ||
let maybe_goal ← LNSymSimp goal ctx simprocs (fvarid := h_step.fvarId!) | ||
match maybe_goal with | ||
| none => | ||
logInfo m!"[execInst] The goal appears to be solved, but this tactic \ | ||
is not a finishing tactic! Something went wrong?" | ||
return false | ||
| some goal' => | ||
replaceMainGoal [goal'] | ||
return true | ||
|
||
def execInstElab (h_step : Name) (hyp_prefix : String) : TacticM Unit := | ||
withMainContext | ||
(do | ||
let h_step ← getFVarFromUserName h_step | ||
let success ← execInst (← getMainGoal) h_step hyp_prefix | ||
if ! success then | ||
failure) | ||
|
||
elab "exec_inst" h_step:ident hyp_prefix:str : tactic => | ||
execInstElab (h_step.getId) (hyp_prefix.getString) | ||
|
||
---------------------------------------------------------------------- |
This file contains 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.