Skip to content

Commit

Permalink
Reorganize a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
sonmarcho committed Dec 11, 2023
1 parent 10a77d1 commit cb332ff
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 94 deletions.
47 changes: 47 additions & 0 deletions backends/lean/Base/Extensions.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import Lean
import Std.Lean.HashSet
import Base.Utils
import Base.Primitives.Base

import Lean.Meta.DiscrTree
import Lean.Meta.Tactic.Simp

/-! Various state extensions used in the library -/
namespace Extensions

open Lean Elab Term Meta
open Utils

-- This is not used anymore but we keep it here.
-- TODO: the original function doesn't define correctly the `addImportedFn`. Do a PR?
def mkMapDeclarationExtension [Inhabited α] (name : Name := by exact decl_name%) :
IO (MapDeclarationExtension α) :=
registerSimplePersistentEnvExtension {
name := name,
addImportedFn := fun a => a.foldl (fun s a => a.foldl (fun s (k, v) => s.insert k v) s) RBMap.empty,
addEntryFn := fun s n => s.insert n.1 n.2 ,
toArrayFn := fun es => es.toArray.qsort (fun a b => Name.quickLt a.1 b.1)
}

/- Discrimination trees map expressions to values. When storing an expression
in a discrimination tree, the expression is first converted to an array
of `DiscrTree.Key`, which are the keys actually used by the discrimination
trees. The conversion operation is monadic, however, and extensions require
all the operations to be pure. For this reason, in the state extension, we
store the keys from *after* the transformation (i.e., the `DiscrTreeKey`
below). The transformation itself can be done elsewhere.
-/
abbrev DiscrTreeKey (simpleReduce : Bool) := Array (DiscrTree.Key simpleReduce)

abbrev DiscrTreeExtension (α : Type) (simpleReduce : Bool) :=
SimplePersistentEnvExtension (DiscrTreeKey simpleReduce × α) (DiscrTree α simpleReduce)

def mkDiscrTreeExtention [Inhabited α] [BEq α] (name : Name := by exact decl_name%) (simpleReduce : Bool) :
IO (DiscrTreeExtension α simpleReduce) :=
registerSimplePersistentEnvExtension {
name := name,
addImportedFn := fun a => a.foldl (fun s a => a.foldl (fun s (k, v) => s.insertCore k v) s) DiscrTree.empty,
addEntryFn := fun s n => s.insertCore n.1 n.2 ,
}

end Extensions
70 changes: 0 additions & 70 deletions backends/lean/Base/Lookup/Base.lean

This file was deleted.

26 changes: 2 additions & 24 deletions backends/lean/Base/Progress/Base.lean
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,20 @@ import Lean
import Std.Lean.HashSet
import Base.Utils
import Base.Primitives.Base
import Base.Lookup.Base

import Base.Extensions
import Lean.Meta.DiscrTree
import Lean.Meta.Tactic.Simp

namespace Progress

open Lean Elab Term Meta
open Utils
open Utils Extensions

-- We can't define and use trace classes in the same file
initialize registerTraceClass `Progress

/- # Progress tactic -/

/- Discrimination trees map expressions to values. When storing an expression
in a discrimination tree, the expression is first converted to an array
of `DiscrTree.Key`, which are the keys actually used by the discrimination
trees. The conversion operation is monadic, however, and extensions require
all the operations to be pure. For this reason, in the state extension, we
store the keys from *after* the transformation (i.e., the `DiscrTreeKey`
below).
-/
abbrev DiscrTreeKey (simpleReduce : Bool) := Array (DiscrTree.Key simpleReduce)

abbrev DiscrTreeExtension (α : Type) (simpleReduce : Bool) :=
SimplePersistentEnvExtension (DiscrTreeKey simpleReduce × α) (DiscrTree α simpleReduce)

def mkDiscrTreeExtention [Inhabited α] [BEq α] (name : Name := by exact decl_name%) (simpleReduce : Bool) :
IO (DiscrTreeExtension α simpleReduce) :=
registerSimplePersistentEnvExtension {
name := name,
addImportedFn := fun a => a.foldl (fun s a => a.foldl (fun s (k, v) => s.insertCore k v) s) DiscrTree.empty,
addEntryFn := fun s n => s.insertCore n.1 n.2 ,
}

structure PSpecDesc where
-- The universally quantified variables
-- Can be fvars or mvars
Expand Down

0 comments on commit cb332ff

Please sign in to comment.