chore: Code cleanup
This commit is contained in:
parent
4643992c3b
commit
678cc9b3c0
|
@ -72,12 +72,12 @@ def unfoldAuxLemmas : Expr → CoreM Expr :=
|
||||||
/-- Unfold all matcher applications -/
|
/-- Unfold all matcher applications -/
|
||||||
@[export pantograph_unfold_matchers_m]
|
@[export pantograph_unfold_matchers_m]
|
||||||
def unfoldMatchers (expr : Expr) : CoreM Expr :=
|
def unfoldMatchers (expr : Expr) : CoreM Expr :=
|
||||||
Core.transform expr λ e' => do
|
Core.transform expr λ e => do
|
||||||
let .some mapp ← Meta.matchMatcherApp? e' | return .continue e'
|
let .some mapp ← Meta.matchMatcherApp? e | return .continue e
|
||||||
let .some matcherInfo := (← getEnv).find? mapp.matcherName | panic! "Matcher must exist"
|
let .some matcherInfo := (← getEnv).find? mapp.matcherName | panic! "Matcher must exist"
|
||||||
let f ← Meta.instantiateValueLevelParams matcherInfo mapp.matcherLevels.toList
|
let f ← Meta.instantiateValueLevelParams matcherInfo mapp.matcherLevels.toList
|
||||||
let mdata := KVMap.empty.insert `matcher (DataValue.ofName mapp.matcherName)
|
let mdata := KVMap.empty.insert `matcher (DataValue.ofName mapp.matcherName)
|
||||||
return .visit $ .mdata mdata (f.betaRev e'.getAppRevArgs (useZeta := true))
|
return .visit $ .mdata mdata (f.betaRev e.getAppRevArgs (useZeta := true))
|
||||||
|
|
||||||
/--
|
/--
|
||||||
Force the instantiation of delayed metavariables even if they cannot be fully
|
Force the instantiation of delayed metavariables even if they cannot be fully
|
||||||
|
@ -94,10 +94,9 @@ This function ensures any metavariable in the result is either
|
||||||
1. Delayed assigned with its pending mvar not assigned in any form
|
1. Delayed assigned with its pending mvar not assigned in any form
|
||||||
2. Not assigned (delay or not)
|
2. Not assigned (delay or not)
|
||||||
-/
|
-/
|
||||||
partial def instantiateDelayedMVars (eOrig: Expr) : MetaM Expr :=
|
partial def instantiateDelayedMVars (expr : Expr) : MetaM Expr :=
|
||||||
--let padding := String.join $ List.replicate level "│ "
|
withTraceNode `Pantograph.Delate (λ _ex => return m!":= {← Meta.ppExpr expr}") do
|
||||||
withTraceNode `Pantograph.Delate (λ _ex => return m!":= {← Meta.ppExpr eOrig}") do
|
let mut result ← Meta.transform (← instantiateMVars expr)
|
||||||
let mut result ← Meta.transform (← instantiateMVars eOrig)
|
|
||||||
(pre := fun e => e.withApp fun f args => do
|
(pre := fun e => e.withApp fun f args => do
|
||||||
let .mvar mvarId := f | return .continue
|
let .mvar mvarId := f | return .continue
|
||||||
trace[Pantograph.Delate] "V {e}"
|
trace[Pantograph.Delate] "V {e}"
|
||||||
|
@ -127,7 +126,7 @@ partial def instantiateDelayedMVars (eOrig: Expr) : MetaM Expr :=
|
||||||
trace[Pantograph.Delate]"MD ?{mvarId.name} := ?{mvarIdPending.name} [{substTableStr}]"
|
trace[Pantograph.Delate]"MD ?{mvarId.name} := ?{mvarIdPending.name} [{substTableStr}]"
|
||||||
|
|
||||||
if args.size < fvars.size then
|
if args.size < fvars.size then
|
||||||
throwError "Not enough arguments to instantiate a delay assigned mvar. This is due to bad implementations of a tactic: {args.size} < {fvars.size}. Expr: {toString e}; Origin: {toString eOrig}"
|
throwError "Not enough arguments to instantiate a delay assigned mvar. This is due to bad implementations of a tactic: {args.size} < {fvars.size}. Expr: {toString e}; Origin: {toString expr}"
|
||||||
if !args.isEmpty then
|
if !args.isEmpty then
|
||||||
trace[Pantograph.Delate] "─ Arguments Begin"
|
trace[Pantograph.Delate] "─ Arguments Begin"
|
||||||
let args ← args.mapM self
|
let args ← args.mapM self
|
||||||
|
@ -139,7 +138,7 @@ partial def instantiateDelayedMVars (eOrig: Expr) : MetaM Expr :=
|
||||||
return .done result
|
return .done result
|
||||||
|
|
||||||
let pending ← mvarIdPending.withContext do
|
let pending ← mvarIdPending.withContext do
|
||||||
let inner ← instantiateDelayedMVars (.mvar mvarIdPending) --(level := level + 1)
|
let inner ← instantiateDelayedMVars (.mvar mvarIdPending)
|
||||||
trace[Pantograph.Delate] "Pre: {inner}"
|
trace[Pantograph.Delate] "Pre: {inner}"
|
||||||
pure <| (← inner.abstractM fvars).instantiateRev args
|
pure <| (← inner.abstractM fvars).instantiateRev args
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue