fix: missing file
diff --git a/src/Lean/Meta/Sym/Util.lean b/src/Lean/Meta/Sym/Util.lean new file mode 100644 index 0000000..e55e39f --- /dev/null +++ b/src/Lean/Meta/Sym/Util.lean
@@ -0,0 +1,52 @@ +/- +Copyright (c) 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Leonardo de Moura +-/ +module +prelude +public import Lean.Meta.Tactic.Grind.Types +namespace Lean.Meta.Sym +open Grind + +/-- +Instantiates metavariables and applies `shareCommon`. +-/ +def preprocessExpr (e : Expr) : GrindM Expr := do + shareCommon (← instantiateMVars e) + +/-- +Helper function that removes gaps, instantiate metavariables, and applies `shareCommon`. +Gaps are `none` cells at `lctx.decls`. In `SymM`, we assume these cells don't exist. +-/ +def preprocessLCtx (lctx : LocalContext) : GrindM LocalContext := do + let auxDeclToFullName := lctx.auxDeclToFullName + let mut fvarIdToDecl := {} + let mut decls := {} + let mut index := 0 + for decl in lctx do + let decl ← match decl with + | .cdecl _ fvarId userName type bi kind => + let type ← preprocessExpr type + pure <| LocalDecl.cdecl index fvarId userName type bi kind + | .ldecl _ fvarId userName type value nondep kind => + let type ← preprocessExpr type + let value ← preprocessExpr value + pure <| LocalDecl.ldecl index fvarId userName type value nondep kind + decls := decls.push (some decl) + fvarIdToDecl := fvarIdToDecl.insert decl.fvarId decl + return { fvarIdToDecl, decls, auxDeclToFullName } + +/-- +Instantiates assigned metavariables, applies `shareCommon`, and eliminates holes (aka `none` cells) +in the local context. +-/ +public def preprocessMVar (mvarId : MVarId) : GrindM MVarId := do + let mvarDecl ← mvarId.getDecl + let lctx ← preprocessLCtx mvarDecl.lctx + let type ← preprocessExpr mvarDecl.type + let mvarNew ← mkFreshExprMVarAt lctx mvarDecl.localInstances type .syntheticOpaque mvarDecl.userName + mvarId.assign mvarNew + return mvarNew.mvarId! + +end Lean.Meta.Sym