Skip to content

Commit

Permalink
add more options to monomorphization
Browse files Browse the repository at this point in the history
  • Loading branch information
PratherConid committed Dec 18, 2024
1 parent b767264 commit 027d8de
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
20 changes: 17 additions & 3 deletions Auto/Translation/Monomorphization.lean
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ register_option auto.mono.recordInstInst : Bool := {
descr := "Whether to record instances of constants with the `instance` attribute"
}

register_option auto.mono.ciInstDefEq.mode : Meta.TransparencyMode := {
defValue := .default
descr := "Transparency level used when collecting definitional equality" ++
" arising from instance relations between `ConstInst`s"
}

register_option auto.mono.tyCan.mode : Meta.TransparencyMode := {
defValue := .reducible
descr := "Transparency level used when canonicalizing types"
}

namespace Auto

inductive MonoMode where
Expand Down Expand Up @@ -463,6 +474,7 @@ where
return false
leadingForallQuasiMonomorphicAux (fvars.push xid) bodyi
| _ => return true

/--
Test whether a lemma is type monomorphic && universe monomorphic
By universe monomorphic we mean `lem.params = #[]`
Expand Down Expand Up @@ -682,8 +694,9 @@ where
let newCis ← collectConstInsts li.params #[] li.type
for newCi in newCis do
processConstInst newCi
bidirectionalOfInstanceEq (ci₁ ci₂ : ConstInst) : MetaM (Option (Expr × Expr)) :=
Meta.withNewMCtxDepth <| Meta.withDefault <| do
bidirectionalOfInstanceEq (ci₁ ci₂ : ConstInst) : MetaM (Option (Expr × Expr)) := do
let mode := auto.mono.ciInstDefEq.mode.get (← getOptions)
Meta.withNewMCtxDepth <| Meta.withTransparency mode <| do
return (← Expr.instanceOf? (← ci₁.toExpr) (← ci₂.toExpr)) <|>
(← Expr.instanceOf? (← ci₂.toExpr) (← ci₁.toExpr))
isTrigger (cih : CiHead) :=
Expand Down Expand Up @@ -745,7 +758,8 @@ namespace FVarRep

/-- Return : (reduce(e), whether reduce(e) contain bfvars) -/
def processType (e : Expr) : FVarRepM (Expr × Bool) := do
let e ← MetaState.runMetaM <| prepReduceExpr e
let mode := auto.mono.tyCan.mode.get (← getOptions)
let e ← MetaState.runMetaM <| prepReduceExprWithMode e mode
let bfvarSet ← getBfvarSet
-- If `e` contains no bound variables
if !e.hasAnyFVar bfvarSet.contains then
Expand Down
11 changes: 7 additions & 4 deletions Auto/Translation/Reduction.lean
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,22 @@ def unfoldProj (e : Expr) : MetaM Expr :=
Meta.mkAppOptM sfi.projFn ((Array.mk nones).push struct)
| _ => return e

/-- This function is expensive -/
partial def prepReduceExpr (term : Expr) : MetaM Expr := do
def prepReduceExprWithMode (term : Expr) (mode : TransparencyMode) : MetaM Expr := do
let red (e : Expr) : MetaM TransformStep := do
let e := e.consumeMData
let e ← Meta.whnf e
return .continue e
let trMode := auto.redMode.get (← getOptions)
-- Reduce
let term ← Meta.withTransparency trMode <| Meta.transform term (pre := red) (usedLetOnly := false)
let term ← Meta.withTransparency mode <| Meta.transform term (pre := red) (usedLetOnly := false)
-- Unfold projection
let term ← Meta.transform term (pre := fun e => do return .continue (← unfoldProj e))
return term

/-- This function is expensive -/
def prepReduceExpr (term : Expr) : MetaM Expr := do
let mode := auto.redMode.get (← getOptions)
prepReduceExprWithMode term mode

/--
We assume that all defeq facts have the form
`∀ (x₁ : ⋯) ⋯ (xₙ : ⋯), c ... = ...`
Expand Down

0 comments on commit 027d8de

Please sign in to comment.