File: Mathlib/Tactic/Variable.lean

full_name: Mathlib.Command.Variable.initFn._@.Mathlib.Tactic.Variable._hyg.6
code: initialize registerTraceClass `variable?
goal: IO Unit

full_name: Mathlib.Command.Variable.variable?.maxSteps
code: register_option variable?.maxSteps : Nat :=
  { defValue := 15
    group := "variable?"
    descr :=
      "The maximum number of instance arguments `variable?` will try to insert before giving up" }
goal: Lean.Option Nat

full_name: Mathlib.Command.Variable.initFn._@.Mathlib.Tactic.Variable._hyg.49
code: register_option variable?.maxSteps : Nat :=
  { defValue := 15
    group := "variable?"
    descr :=
      "The maximum number of instance arguments `variable?` will try to insert before giving up" }
goal: IO (Lean.Option Nat)

full_name: Mathlib.Command.Variable.variable?.checkRedundant
code: register_option variable?.checkRedundant : Bool :=
  { defValue := true
    group := "variable?"
    descr := "Warn if instance arguments can be inferred from preceding ones" }
goal: Lean.Option Bool

full_name: Mathlib.Command.Variable.initFn._@.Mathlib.Tactic.Variable._hyg.91
code: register_option variable?.checkRedundant : Bool :=
  { defValue := true
    group := "variable?"
    descr := "Warn if instance arguments can be inferred from preceding ones" }
goal: IO (Lean.Option Bool)

full_name: Mathlib.Command.Variable.bracketedBinderType
code: /-- Get the type out of a bracketed binder. -/
def bracketedBinderType : Syntax → Option Term
  
goal: Lean.Syntax → Option Lean.Term

full_name: Mathlib.Command.Variable.variable?
code: /-- The `variable?` command has the same syntax as `variable`, but it will auto-insert
missing instance arguments wherever they are needed.
It does not add variables that can already be deduced from others in the current context.
By default the command checks that variables aren't implied by earlier ones, but it does *not*
check that earlier variables aren't implied by later ones.
Unlike `variable`, the `variable?` command does not support changing variable binder types.

The `variable?` command will give a suggestion to replace itself with a command of the form
`variable? ...binders... => ...binders...`.  The binders after the `=>` are the completed
list of binders. When this `=>` clause is present, the command verifies that the expanded
binders match the post-`=>` binders.  The purpose of this is to help keep code that uses
`variable?` resilient against changes to the typeclass hierarchy, at least in the sense
that this additional information can be used to debug issues that might arise.
One can also replace `variable? ...binders... =>` with `variable`.

The core algorithm is to try elaborating binders one at a time, and whenever there is a
typeclass instance inference failure, it synthesizes binder syntax for it and adds it to
the list of binders and tries again, recursively. There are no guarantees that this
process gives the "correct" list of binders.

Structures tagged with the `variable_alias` attribute can serve as aliases for a collection
of typeclasses. For example, given
```lean
@[variable_alias]
structure VectorSpace (k V : Type*) [Field k] [AddCommGroup V] [Module k V]
```
then `variable? [VectorSpace k V]` is
equivalent to `variable {k V : Type*} [Field k] [AddCommGroup V] [Module k V]`, assuming
that there are no pre-existing instances on `k` and `V`.
Note that this is not a simple replacement: it only adds instances not inferrable
from others in the current scope.

A word of warning: the core algorithm depends on pretty printing, so if terms that appear
in binders do not round trip, this algorithm can fail. That said, it has some support
for quantified binders such as `[∀ i, F i]`. -/
syntax (name := «variable?»)
  "variable?" (ppSpace bracketedBinder)* (" =>" (ppSpace bracketedBinder)*)? : command
goal: Lean.ParserDescr

full_name: Mathlib.Command.Variable.initFn._@.Mathlib.Tactic.Variable._hyg.804
code: /--
Attribute to record aliases for the `variable?` command. Aliases are structures that have no
fields, and additional typeclasses are recorded as *arguments* to the structure.

Example:
```
@[variable_alias]
structure VectorSpace (k V : Type*)
  [Field k] [AddCommGroup V] [Module k V]
```
Then `variable? [VectorSpace k V]` ensures that these three typeclasses are present in
the current scope. Notice that it's looking at the arguments to the `VectorSpace` type
constructor. You should not have any fields in `variable_alias` structures.

Notice that `VectorSpace` is not a class; the `variable?` command allows non-classes with the
`variable_alias` attribute to use instance binders.
-/
initialize variableAliasAttr : TagAttribute ←
  registerTagAttribute `variable_alias "Attribute to record aliases for the `variable?` command."
goal: IO Lean.TagAttribute

full_name: Mathlib.Command.Variable.variableAliasAttr
code: /--
Attribute to record aliases for the `variable?` command. Aliases are structures that have no
fields, and additional typeclasses are recorded as *arguments* to the structure.

Example:
```
@[variable_alias]
structure VectorSpace (k V : Type*)
  [Field k] [AddCommGroup V] [Module k V]
```
Then `variable? [VectorSpace k V]` ensures that these three typeclasses are present in
the current scope. Notice that it's looking at the arguments to the `VectorSpace` type
constructor. You should not have any fields in `variable_alias` structures.

Notice that `VectorSpace` is not a class; the `variable?` command allows non-classes with the
`variable_alias` attribute to use instance binders.
-/
initialize variableAliasAttr : TagAttribute ←
  registerTagAttribute `variable_alias "Attribute to record aliases for the `variable?` command."
goal: Lean.TagAttribute

full_name: Mathlib.Command.Variable.pendingActionableSynthMVar
code: /-- Find a synthetic typeclass metavariable with no expr metavariables in its type. -/
def pendingActionableSynthMVar (binder : TSyntax ``bracketedBinder) :
    TermElabM (Option MVarId) 
goal: Lean.Elab.TermElabM (Option Lean.MVarId)

full_name: Mathlib.Command.Variable.getSubproblem
code: /-- Try elaborating `ty`. Returns `none` if it doesn't need any additional typeclasses,
or it returns a new binder that needs to come first. Does not add info unless it throws
an exception. -/
partial def getSubproblem
    (binder : TSyntax ``bracketedBinder) (ty : Term) :
    TermElabM (Option (MessageData × TSyntax ``bracketedBinder)) 
goal: Lean.Elab.TermElabM (Option (Lean.MessageData × Lean.TSyntax `Lean.Parser.Term.bracketedBinder))

full_name: Mathlib.Command.Variable.completeBinders'
code: /-- Tries elaborating binders, inserting new binders whenever typeclass inference fails.
`i` is the index of the next binder that needs to be checked.

The `toOmit` array keeps track of which binders should be removed at the end,
in particular the `variable_alias` binders and any redundant binders. -/
partial def completeBinders' (maxSteps : Nat) (gas : Nat)
    (checkRedundant : Bool)
    (binders : TSyntaxArray ``bracketedBinder)
    (toOmit : Array Bool) (i : Nat) :
    TermElabM (TSyntaxArray ``bracketedBinder × Array Bool) 
goal: Lean.Elab.TermElabM (Lean.TSyntaxArray `Lean.Parser.Term.bracketedBinder × Array Bool)

full_name: Mathlib.Command.Variable.completeBinders'.isVariableAlias
code: /-- Tries elaborating binders, inserting new binders whenever typeclass inference fails.
`i` is the index of the next binder that needs to be checked.

The `toOmit` array keeps track of which binders should be removed at the end,
in particular the `variable_alias` binders and any redundant binders. -/
partial def completeBinders' (maxSteps : Nat) (gas : Nat)
    (checkRedundant : Bool)
    (binders : TSyntaxArray ``bracketedBinder)
    (toOmit : Array Bool) (i : Nat) :
    TermElabM (TSyntaxArray ``bracketedBinder × Array Bool) 
goal: Lean.MetaM Bool

full_name: Mathlib.Command.Variable.completeBinders
code: def completeBinders (maxSteps : Nat) (checkRedundant : Bool)
    (binders : TSyntaxArray ``bracketedBinder) :
    TermElabM (TSyntaxArray ``bracketedBinder × Array Bool) 
goal: Lean.Elab.TermElabM (Lean.TSyntaxArray `Lean.Parser.Term.bracketedBinder × Array Bool)

full_name: Mathlib.Command.Variable.cleanBinders
code: /-- Strip off whitespace and comments. -/
def cleanBinders (binders : TSyntaxArray ``bracketedBinder) :
    TSyntaxArray ``bracketedBinder 
goal: Lean.TSyntaxArray `Lean.Parser.Term.bracketedBinder

full_name: Mathlib.Command.Variable.elabVariables
code: @[command_elab «variable?», inherit_doc «variable?»]
def elabVariables : CommandElab 
goal: Lean.Elab.Command.CommandElab

full_name: Mathlib.Command.Variable.elabVariables.extendScope
code: @[command_elab «variable?», inherit_doc «variable?»]
def elabVariables : CommandElab 
goal: Lean.Elab.Command.CommandElabM Unit

full_name: Mathlib.Command.Variable.elabVariables.process
code: @[command_elab «variable?», inherit_doc «variable?»]
def elabVariables : CommandElab 
goal: Lean.Elab.Command.CommandElabM Unit

full_name: Mathlib.Command.Variable.ignorevariable?
code: /-- Hint for the unused variables linter. Copies the one for `variable`. -/
@[unused_variables_ignore_fn]
def ignorevariable? : Lean.Linter.IgnoreFunction 
goal: Lean.Linter.IgnoreFunction