File: .lake/packages/batteries/Batteries/Tactic/Alias.lean

full_name: Batteries.Tactic.Alias.instInhabitedAliasInfo
code: /-- An alias can be in one of three forms -/
inductive AliasInfo where
  /-- Plain alias -/
  | plain (n : Name)
  /-- Forward direction of an iff alias -/
  | forward (n : Name)
  /-- Reverse direction of an iff alias -/
  | reverse (n : Name)
deriving Inhabited
goal: Inhabited Batteries.Tactic.Alias.AliasInfo

full_name: Batteries.Tactic.Alias.AliasInfo
code: /-- An alias can be in one of three forms -/
inductive AliasInfo where
  /-- Plain alias -/
  | plain (n : Name)
  /-- Forward direction of an iff alias -/
  | forward (n : Name)
  /-- Reverse direction of an iff alias -/
  | reverse (n : Name)
deriving Inhabited
goal: Type

full_name: Batteries.Tactic.Alias.AliasInfo.plain
code: /-- An alias can be in one of three forms -/
inductive AliasInfo where
  /-- Plain alias -/
  | plain (n : Name)
  /-- Forward direction of an iff alias -/
  | forward (n : Name)
  /-- Reverse direction of an iff alias -/
  | reverse (n : Name)
deriving Inhabited
goal: Batteries.Tactic.Alias.AliasInfo

full_name: Batteries.Tactic.Alias.AliasInfo.forward
code: /-- An alias can be in one of three forms -/
inductive AliasInfo where
  /-- Plain alias -/
  | plain (n : Name)
  /-- Forward direction of an iff alias -/
  | forward (n : Name)
  /-- Reverse direction of an iff alias -/
  | reverse (n : Name)
deriving Inhabited
goal: Batteries.Tactic.Alias.AliasInfo

full_name: Batteries.Tactic.Alias.AliasInfo.reverse
code: /-- An alias can be in one of three forms -/
inductive AliasInfo where
  /-- Plain alias -/
  | plain (n : Name)
  /-- Forward direction of an iff alias -/
  | forward (n : Name)
  /-- Reverse direction of an iff alias -/
  | reverse (n : Name)
deriving Inhabited
goal: Batteries.Tactic.Alias.AliasInfo

full_name: Batteries.Tactic.Alias.AliasInfo.name
code: /-- The name underlying an alias target -/
def AliasInfo.name : AliasInfo → Name
  
goal: Batteries.Tactic.Alias.AliasInfo → Lean.Name

full_name: Batteries.Tactic.Alias.AliasInfo.toString
code: /-- The docstring for an alias. -/
def AliasInfo.toString : AliasInfo → String
  
goal: Batteries.Tactic.Alias.AliasInfo → String

full_name: Batteries.Tactic.Alias.aliasExt
code: /-- Environment extension for registering aliases -/
initialize aliasExt : SimpleScopedEnvExtension (Name × AliasInfo) (NameMap AliasInfo) ←
  registerSimpleScopedEnvExtension {
    addEntry := fun st (n, i) => st.insert n i
    initial := {}
  }
goal: Lean.SimpleScopedEnvExtension (Lean.Name × Batteries.Tactic.Alias.AliasInfo)
  (Lean.NameMap Batteries.Tactic.Alias.AliasInfo)

full_name: Batteries.Tactic.Alias.initFn._@..lake.packages.batteries.Batteries.Tactic.Alias._hyg.173
code: /-- Environment extension for registering aliases -/
initialize aliasExt : SimpleScopedEnvExtension (Name × AliasInfo) (NameMap AliasInfo) ←
  registerSimpleScopedEnvExtension {
    addEntry := fun st (n, i) => st.insert n i
    initial := {}
  }
goal: IO
  (Lean.SimpleScopedEnvExtension (Lean.Name × Batteries.Tactic.Alias.AliasInfo)
    (Lean.NameMap Batteries.Tactic.Alias.AliasInfo))

full_name: Batteries.Tactic.Alias.getAliasInfo
code: /-- Get the alias information for a name -/
def getAliasInfo [Monad m] [MonadEnv m] (name : Name) : m (Option AliasInfo) 
goal: m (Option Batteries.Tactic.Alias.AliasInfo)

full_name: Batteries.Tactic.Alias.setAliasInfo
code: /-- Set the alias info for a new declaration -/
def setAliasInfo [MonadEnv m] (info : AliasInfo) (declName : Name) : m Unit 
goal: m Unit

full_name: Batteries.Tactic.Alias.setDeprecatedTarget
code: /-- Updates the `deprecated` declaration to point to `target` if no target is provided. -/
def setDeprecatedTarget (target : Name) (arr : Array Attribute) : Array Attribute × Bool 
goal: Array Lean.Elab.Attribute × Bool

full_name: Batteries.Tactic.Alias.«_aux_.lake_packages_batteries_Batteries_Tactic_Alias___elabRules_Batteries_Tactic_Alias_alias_1»
code: /--
  The command `alias name := target` creates a synonym of `target` with the given name.

  The command `alias ⟨fwd, rev⟩ := target` creates synonyms for the forward and reverse directions
  of an iff theorem. Use `_` if only one direction is required.

  These commands accept all modifiers and attributes that `def` and `theorem` do.
 -/
elab (name := alias) mods:declModifiers "alias " alias:ident " := " name:ident : command =>
  Command.liftTermElabM do
    let name ← realizeGlobalConstNoOverloadWithInfo name
    let cinfo ← getConstInfo name
    let declMods ← elabModifiers mods
    let (attrs, machineApplicable) := setDeprecatedTarget name declMods.attrs
    let declMods := { declMods with
      isNoncomputable := declMods.isNoncomputable || isNoncomputable (← getEnv) name
      isUnsafe := declMods.isUnsafe || cinfo.isUnsafe
      attrs
    }
    let (declName, _) ← mkDeclName (← getCurrNamespace) declMods alias.getId
    let decl : Declaration := if let .thmInfo t := cinfo then
      .thmDecl { t with
        name := declName
        value := mkConst name (t.levelParams.map mkLevelParam)
      }
    else
      .defnDecl { cinfo.toConstantVal with
        name := declName
        value := mkConst name (cinfo.levelParams.map mkLevelParam)
        hints := .regular 0 -- FIXME
        safety := if declMods.isUnsafe then .unsafe else .safe
      }
    checkNotAlreadyDeclared declName
    if declMods.isNoncomputable then
      addDecl decl
    else
      addAndCompile decl
    Lean.addDeclarationRanges declName {
      range := ← getDeclarationRange (← getRef)
      selectionRange := ← getDeclarationRange alias
    }
    Term.addTermInfo' alias (← mkConstWithLevelParams declName) (isBinder := true)
    addDocString' declName declMods.docString?
    Term.applyAttributes declName declMods.attrs
    let info := (← getAliasInfo name).getD <| AliasInfo.plain name
    setAliasInfo info declName
    if machineApplicable then
      modifyEnv (machineApplicableDeprecated.tag · declName)
    /- alias doesn't trigger the missing docs linter so we add a default. We can't just check
      `declMods` because a docstring may have been added by an attribute. -/
    if (← findDocString? (← getEnv) declName).isNone then
      let mut doc := info.toString
      if let some origDoc ← findDocString? (← getEnv) name then
        doc := s!"{doc}\n\n---\n\n{origDoc}"
      addDocString declName doc
goal: Lean.Elab.Command.CommandElab

full_name: Batteries.Tactic.Alias.alias
code: /--
  The command `alias name := target` creates a synonym of `target` with the given name.

  The command `alias ⟨fwd, rev⟩ := target` creates synonyms for the forward and reverse directions
  of an iff theorem. Use `_` if only one direction is required.

  These commands accept all modifiers and attributes that `def` and `theorem` do.
 -/
elab (name := alias) mods:declModifiers "alias " alias:ident " := " name:ident : command =>
  Command.liftTermElabM do
    let name ← realizeGlobalConstNoOverloadWithInfo name
    let cinfo ← getConstInfo name
    let declMods ← elabModifiers mods
    let (attrs, machineApplicable) := setDeprecatedTarget name declMods.attrs
    let declMods := { declMods with
      isNoncomputable := declMods.isNoncomputable || isNoncomputable (← getEnv) name
      isUnsafe := declMods.isUnsafe || cinfo.isUnsafe
      attrs
    }
    let (declName, _) ← mkDeclName (← getCurrNamespace) declMods alias.getId
    let decl : Declaration := if let .thmInfo t := cinfo then
      .thmDecl { t with
        name := declName
        value := mkConst name (t.levelParams.map mkLevelParam)
      }
    else
      .defnDecl { cinfo.toConstantVal with
        name := declName
        value := mkConst name (cinfo.levelParams.map mkLevelParam)
        hints := .regular 0 -- FIXME
        safety := if declMods.isUnsafe then .unsafe else .safe
      }
    checkNotAlreadyDeclared declName
    if declMods.isNoncomputable then
      addDecl decl
    else
      addAndCompile decl
    Lean.addDeclarationRanges declName {
      range := ← getDeclarationRange (← getRef)
      selectionRange := ← getDeclarationRange alias
    }
    Term.addTermInfo' alias (← mkConstWithLevelParams declName) (isBinder := true)
    addDocString' declName declMods.docString?
    Term.applyAttributes declName declMods.attrs
    let info := (← getAliasInfo name).getD <| AliasInfo.plain name
    setAliasInfo info declName
    if machineApplicable then
      modifyEnv (machineApplicableDeprecated.tag · declName)
    /- alias doesn't trigger the missing docs linter so we add a default. We can't just check
      `declMods` because a docstring may have been added by an attribute. -/
    if (← findDocString? (← getEnv) declName).isNone then
      let mut doc := info.toString
      if let some origDoc ← findDocString? (← getEnv) name then
        doc := s!"{doc}\n\n---\n\n{origDoc}"
      addDocString declName doc
goal: Lean.ParserDescr

full_name: Batteries.Tactic.Alias.mkIffMpApp
code: /--
Given a possibly forall-quantified iff expression `prf`, produce a value for one
of the implication directions (determined by `mp`).
-/
def mkIffMpApp (mp : Bool) (ty prf : Expr) : MetaM Expr 
goal: Lean.MetaM Lean.Expr

full_name: _private.«.lake».packages.batteries.Batteries.Tactic.Alias.0.Batteries.Tactic.Alias.addSide
code: private def addSide (mp : Bool) (declName : Name) (declMods : Modifiers) (thm : TheoremVal) :
    TermElabM Unit 
goal: Lean.Elab.TermElabM Unit

full_name: Batteries.Tactic.Alias.aliasLR
code: @[inherit_doc «alias»]
elab (name := aliasLR) mods:declModifiers "alias "
    "⟨" aliasFwd:binderIdent ", " aliasRev:binderIdent "⟩" " := " name:ident : command =>
  Command.liftTermElabM do
    let name ← realizeGlobalConstNoOverloadWithInfo name
    let declMods ← elabModifiers mods
    let declMods := { declMods with attrs := (setDeprecatedTarget name declMods.attrs).1 }
    let .thmInfo thm ← getConstInfo name | throwError "Target must be a theorem"
    if let `(binderIdent| $idFwd:ident) := aliasFwd then
      let (declName, _) ← mkDeclName (← getCurrNamespace) declMods idFwd.getId
      addSide true declName declMods thm
      Lean.addDeclarationRanges declName {
        range := ← getDeclarationRange (← getRef)
        selectionRange := ← getDeclarationRange idFwd
      }
      Term.addTermInfo' idFwd (← mkConstWithLevelParams declName) (isBinder := true)
    if let `(binderIdent| $idRev:ident) := aliasRev then
      let (declName, _) ← mkDeclName (← getCurrNamespace) declMods idRev.getId
      addSide false declName declMods thm
      Lean.addDeclarationRanges declName {
        range := ← getDeclarationRange (← getRef)
        selectionRange := ← getDeclarationRange idRev
      }
      Term.addTermInfo' idRev (← mkConstWithLevelParams declName) (isBinder := true)
goal: Lean.ParserDescr

full_name: Batteries.Tactic.Alias.«_aux_.lake_packages_batteries_Batteries_Tactic_Alias___elabRules_Batteries_Tactic_Alias_aliasLR_1»
code: @[inherit_doc «alias»]
elab (name := aliasLR) mods:declModifiers "alias "
    "⟨" aliasFwd:binderIdent ", " aliasRev:binderIdent "⟩" " := " name:ident : command =>
  Command.liftTermElabM do
    let name ← realizeGlobalConstNoOverloadWithInfo name
    let declMods ← elabModifiers mods
    let declMods := { declMods with attrs := (setDeprecatedTarget name declMods.attrs).1 }
    let .thmInfo thm ← getConstInfo name | throwError "Target must be a theorem"
    if let `(binderIdent| $idFwd:ident) := aliasFwd then
      let (declName, _) ← mkDeclName (← getCurrNamespace) declMods idFwd.getId
      addSide true declName declMods thm
      Lean.addDeclarationRanges declName {
        range := ← getDeclarationRange (← getRef)
        selectionRange := ← getDeclarationRange idFwd
      }
      Term.addTermInfo' idFwd (← mkConstWithLevelParams declName) (isBinder := true)
    if let `(binderIdent| $idRev:ident) := aliasRev then
      let (declName, _) ← mkDeclName (← getCurrNamespace) declMods idRev.getId
      addSide false declName declMods thm
      Lean.addDeclarationRanges declName {
        range := ← getDeclarationRange (← getRef)
        selectionRange := ← getDeclarationRange idRev
      }
      Term.addTermInfo' idRev (← mkConstWithLevelParams declName) (isBinder := true)
goal: Lean.Elab.Command.CommandElab