File: Mathlib/Tactic/DeriveToExpr.lean

full_name: Mathlib.Deriving.ToExpr.mkToExprHeader
code: /-- Specialization of `Lean.Elab.Deriving.mkHeader` for `ToExpr`. -/
def mkToExprHeader (indVal : InductiveVal) : TermElabM Header 
goal: Lean.Elab.TermElabM Lean.Elab.Deriving.Header

full_name: Mathlib.Deriving.ToExpr.mkAppNTerm
code: /-- Give a term that is equivalent to `(term| mkAppN $f #[$args,*])`.
As an optimization, `mkAppN` is pre-expanded out to use `Expr.app` directly. -/
def mkAppNTerm (f : Term) (args : Array Term) : MetaM Term 
goal: Lean.MetaM Lean.Term

full_name: Mathlib.Deriving.ToExpr.mkToExprBody.mkAlts
code: /-- Create the body of the `toExpr` function
for the `ToExpr` instance, which is a `match` expression
that calls `toExpr` and `toTypeExpr` to assemble an expression for a given term.
For recursive inductive types, `auxFunName` refers to the `ToExpr` instance
for the current type.
For mutually recursive types, we rely on the local instances set up by `mkLocalInstanceLetDecls`. -/
def mkToExprBody (header : Header) (indVal : InductiveVal) (auxFunName : Name) :
    TermElabM Term 
goal: Lean.Elab.TermElabM (Array (Lean.TSyntax `Lean.Parser.Term.matchAlt))

full_name: Mathlib.Deriving.ToExpr.mkToExprBody
code: /-- Create the body of the `toExpr` function
for the `ToExpr` instance, which is a `match` expression
that calls `toExpr` and `toTypeExpr` to assemble an expression for a given term.
For recursive inductive types, `auxFunName` refers to the `ToExpr` instance
for the current type.
For mutually recursive types, we rely on the local instances set up by `mkLocalInstanceLetDecls`. -/
def mkToExprBody (header : Header) (indVal : InductiveVal) (auxFunName : Name) :
    TermElabM Term 
goal: Lean.Elab.TermElabM Lean.Term

full_name: Mathlib.Deriving.ToExpr.mkToTypeExpr
code: /-- Create the body of the `toTypeExpr` function for the `ToExpr` instance.
Calls `toExpr` and `toTypeExpr` to the arguments to the type constructor. -/
def mkToTypeExpr (argNames : Array Name) (indVal : InductiveVal) : TermElabM Term 
goal: Lean.Elab.TermElabM Lean.Term

full_name: Mathlib.Deriving.ToExpr.mkLocalInstanceLetDecls
code: /--
For mutually recursive inductive types, the strategy is to have local `ToExpr` instances in scope
for each of the inductives when defining each instance.
This way, each instance can freely use `toExpr` and `toTypeExpr` for each of the other types.

Note that each instance gets its own definition of each of the others' `toTypeExpr` fields.
(This is working around the fact that the `Deriving.Context` API assumes
that each instance in mutual recursion only has a single auxiliary definition.
There are other ways to work around it, but `toTypeExpr` implementations
are very simple, so duplicating them seemed to be OK.) -/
def mkLocalInstanceLetDecls (ctx : Deriving.Context) (argNames : Array Name) :
    TermElabM (Array (TSyntax ``Parser.Term.letDecl)) 
goal: Lean.Elab.TermElabM (Array (Lean.TSyntax `Lean.Parser.Term.letDecl))

full_name: Mathlib.Deriving.ToExpr.fixIndType
code: /-- Fix the output of `mkInductiveApp` to explicitly reference universe levels. -/
def fixIndType (indVal : InductiveVal) (t : Term) : TermElabM Term 
goal: Lean.Elab.TermElabM Lean.Term

full_name: Mathlib.Deriving.ToExpr.mkToLevelBinders
code: /-- Make `ToLevel` instance binders for all the level variables. -/
def mkToLevelBinders (indVal : InductiveVal) : TermElabM (TSyntaxArray ``instBinderF) 
goal: Lean.Elab.TermElabM (Lean.TSyntaxArray `Lean.Elab.Deriving.instBinderF)

full_name: Mathlib.Deriving.ToExpr.mkAuxFunction
code: /-- Make a `toExpr` function for the given inductive type.
The implementations of each `toExpr` function for a (mutual) inductive type
are given as top-level private definitions.
These end up being assembled into `ToExpr` instances in `mkInstanceCmds`.
For mutual inductive types,
then each of the other types' `ToExpr` instances are provided as local instances,
to wire together the recursion (this necessitates these auxiliary definitions being `partial`). -/
def mkAuxFunction (ctx : Deriving.Context) (i : Nat) : TermElabM Command 
goal: Lean.Elab.TermElabM Lean.Command

full_name: Mathlib.Deriving.ToExpr.mkMutualBlock
code: /-- Create all the auxiliary functions using `mkAuxFunction` for the (mutual) inductive type(s).
Wraps the resulting definition commands in `mutual ... end`. -/
def mkMutualBlock (ctx : Deriving.Context) : TermElabM Syntax 
goal: Lean.Elab.TermElabM Lean.Syntax

full_name: Mathlib.Deriving.ToExpr.mkInstanceCmds
code: /-- Assuming all of the auxiliary definitions exist, create all the `instance` commands
for the `ToExpr` instances for the (mutual) inductive type(s). -/
def mkInstanceCmds (ctx : Deriving.Context) (typeNames : Array Name) :
    TermElabM (Array Command) 
goal: Lean.Elab.TermElabM (Array Lean.Command)

full_name: Mathlib.Deriving.ToExpr.mkToExprInstanceCmds
code: /-- Returns all the commands generated by `mkMutualBlock` and `mkInstanceCmds`. -/
def mkToExprInstanceCmds (declNames : Array Name) : TermElabM (Array Syntax) 
goal: Lean.Elab.TermElabM (Array Lean.Syntax)

full_name: Mathlib.Deriving.ToExpr.mkToExprInstanceHandler
code: /-- The main entry point to the `ToExpr` derive handler. -/
def mkToExprInstanceHandler (declNames : Array Name) : CommandElabM Bool 
goal: Lean.Elab.Command.CommandElabM Bool

full_name: Mathlib.Deriving.ToExpr.initFn._@.Mathlib.Tactic.DeriveToExpr._hyg.4565
code: initialize
  registerDerivingHandler `Lean.ToExpr mkToExprInstanceHandler
  registerTraceClass `Elab.Deriving.toExpr
goal: IO Unit