File: Mathlib/Tactic/MinImports.lean

full_name: Mathlib.Command.MinImports.getSyntaxNodeKinds
code: /-- `getSyntaxNodeKinds stx` takes a `Syntax` input `stx` and returns the `NameSet` of all the
`SyntaxNodeKinds` and all the identifiers contained in `stx`. -/
partial
def getSyntaxNodeKinds : Syntax → NameSet
  
goal: Lean.Syntax → Lean.NameSet

full_name: Mathlib.Command.MinImports.getVisited
code: /-- extracts the names of the declarations in `env` on which `decl` depends. -/
-- source:
-- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Counting.20prerequisites.20of.20a.20theorem/near/425370265
def getVisited (env : Environment) (decl : Name) : NameSet 
goal: Lean.NameSet

full_name: Mathlib.Command.MinImports.getId
code: /-- `getId stx` takes as input a `Syntax` `stx`.
If `stx` contains a `declId`, then it returns the `ident`-syntax for the `declId`.
If `stx` is a nameless instance, then it also tries to fetch the `ident` for the instance.
Otherwise it returns `.missing`. -/
def getId (stx : Syntax) : CommandElabM Syntax 
goal: Lean.Elab.Command.CommandElabM Lean.Syntax

full_name: Mathlib.Command.MinImports.getIds
code: /-- `getIds stx` extracts all identifiers, collecting them in a `NameSet`. -/
partial
def getIds : Syntax → NameSet
  
goal: Lean.Syntax → Lean.NameSet

full_name: Mathlib.Command.MinImports.getAttrNames
code: /-- `getAttrNames stx` extracts `attribute`s from `stx`.
It does not collect `simp`, `ext`, `to_additive`.
It should collect almost all other attributes, e.g., `fun_prop`. -/
def getAttrNames (stx : Syntax) : NameSet 
goal: Lean.NameSet

full_name: Mathlib.Command.MinImports.getAttrs
code: /-- `getAttrs env stx` returns all attribute declaration names contained in `stx` and registered
in the `Environment `env`. -/
def getAttrs (env : Environment) (stx : Syntax) : NameSet 
goal: Lean.NameSet

full_name: Mathlib.Command.MinImports.previousInstName
code: /-- `previousInstName nm` takes as input a name `nm`, assuming that it is the name of an
auto-generated "nameless" `instance`.
If `nm` ends in `..._n`, where `n` is a number, it returns the same name, but with `_n` replaced
by `_(n-1)`, unless `n ≤ 1`, in which case it simply removes the `_n` suffix.
-/
def previousInstName : Name → Name
  
goal: Lean.Name → Lean.Name

full_name: Mathlib.Command.MinImports.getAllImports
code: /--`getAllImports cmd id` takes a `Syntax` input `cmd` and returns the `NameSet` of all the
module names that are implied by
* the `SyntaxNodeKinds`,
* the attributes of `cmd` (if there are any),
* the identifiers contained in `cmd`,
* if `cmd` adds a declaration `d` to the environment, then also all the module names implied by `d`.
The argument `id` is expected to be an identifier.
It is used either for the internally generated name of a "nameless" `instance` or when parsing
an identifier representing the name of a declaration.
-/
def getAllImports (cmd id : Syntax) (dbg? : Bool := false) :
    CommandElabM NameSet 
goal: Lean.Elab.Command.CommandElabM Lean.NameSet

full_name: Mathlib.Command.MinImports.getIrredundantImports
code: /-- `getIrredundantImports env importNames` takes an `Environment` and a `NameSet` as inputs.
Assuming that `importNames` are module names,
it returns the `NameSet` consisting of a minimal collection of module names whose transitive
closure is enough to parse (and elaborate) `cmd`. -/
def getIrredundantImports (env : Environment) (importNames : NameSet) : NameSet 
goal: Lean.NameSet

full_name: Mathlib.Command.MinImports.minImpsCore
code: /-- `minImpsCore stx id` is the internal function to elaborate the `#min_imports in` command.
It collects the irredundant imports to parse and elaborate `stx` and logs
```lean
import A
import B
...
import Z
```
The `id` input is expected to be the name of the declaration that is currently processed.
It is used to provide the internally generated name for "nameless" `instance`s.
-/
def minImpsCore (stx id : Syntax) : CommandElabM Unit 
goal: Lean.Elab.Command.CommandElabM Unit

full_name: Mathlib.Command.MinImports.minImpsStx
code: /-- `#min_imports in cmd` scans the syntax `cmd` and the declaration obtained by elaborating `cmd`
to find a collection of minimal imports that should be sufficient for `cmd` to work. -/
syntax (name := minImpsStx) "#min_imports in" command : command
goal: Lean.ParserDescr

full_name: Mathlib.Command.MinImports.«command#min_imports_in_»
code: @[inherit_doc minImpsStx]
syntax "#min_imports in" term : command
goal: Lean.ParserDescr

full_name: Mathlib.Command.MinImports.«_aux_Mathlib_Tactic_MinImports___elabRules_Mathlib_Command_MinImports_command#min_imports_in__1»
code: elab_rules : command
  | `(#min_imports in $cmd:command) => do
    -- In case `cmd` is a "nameless" `instance`, we produce its name.
    -- It is important that this is collected *before* adding the declaration to the environment,
    -- since `getId` probes the name-generator using the current environment: if the declaration
    -- were already present, `getId` would return a new name that does not clash with it!
    let id ← getId cmd
    Elab.Command.elabCommand cmd <|> pure ()
    minImpsCore cmd id
  | `(#min_imports in $cmd:term) => minImpsCore cmd cmd
goal: Lean.Elab.Command.CommandElab

full_name: Mathlib.Command.MinImports._aux_Mathlib_Tactic_MinImports___elabRules_Mathlib_Command_MinImports_minImpsStx_1
code: elab_rules : command
  | `(#min_imports in $cmd:command) => do
    -- In case `cmd` is a "nameless" `instance`, we produce its name.
    -- It is important that this is collected *before* adding the declaration to the environment,
    -- since `getId` probes the name-generator using the current environment: if the declaration
    -- were already present, `getId` would return a new name that does not clash with it!
    let id ← getId cmd
    Elab.Command.elabCommand cmd <|> pure ()
    minImpsCore cmd id
  | `(#min_imports in $cmd:term) => minImpsCore cmd cmd
goal: Lean.Elab.Command.CommandElab