File: Mathlib/Mathport/Rename.lean

full_name: Mathlib.Prelude.Rename.instInhabitedRenameMap
code: /-- This structure keeps track of alignments from lean 3 names to lean 4 names and vice versa. -/
structure RenameMap where
  /-- This maps `n3 ↦ (dubious, n4)` where `n3` is the lean 3 name and `n4` is the corresponding
  lean 4 name. `dubious` is either empty, or a warning message to be displayed when `n3` is
  translated, which indicates that the translation from `n3` to `n4` is approximate and may cause
  downstream errors. -/
  toLean4 : NameMap (String × Name) := {}
  /-- This maps `n4 ↦ (n3, clashes)` where `n4` is the lean 4 name and `n3::clashes` is the list of
  all (non-`synthetic`) declarations that map to `n4`. (That is, we do not assume the mapping
  from lean 3 to lean 4 name is injective.) -/
  toLean3 : NameMap (Name × List Name) := {}
  deriving Inhabited
goal: Inhabited Mathlib.Prelude.Rename.RenameMap

full_name: Mathlib.Prelude.Rename.RenameMap.toLean4
code: /-- This structure keeps track of alignments from lean 3 names to lean 4 names and vice versa. -/
structure RenameMap where
  /-- This maps `n3 ↦ (dubious, n4)` where `n3` is the lean 3 name and `n4` is the corresponding
  lean 4 name. `dubious` is either empty, or a warning message to be displayed when `n3` is
  translated, which indicates that the translation from `n3` to `n4` is approximate and may cause
  downstream errors. -/
  toLean4 : NameMap (String × Name) := {}
  /-- This maps `n4 ↦ (n3, clashes)` where `n4` is the lean 4 name and `n3::clashes` is the list of
  all (non-`synthetic`) declarations that map to `n4`. (That is, we do not assume the mapping
  from lean 3 to lean 4 name is injective.) -/
  toLean3 : NameMap (Name × List Name) := {}
  deriving Inhabited
goal: Lean.NameMap (String × Lean.Name)

full_name: Mathlib.Prelude.Rename.RenameMap.toLean3
code: /-- This structure keeps track of alignments from lean 3 names to lean 4 names and vice versa. -/
structure RenameMap where
  /-- This maps `n3 ↦ (dubious, n4)` where `n3` is the lean 3 name and `n4` is the corresponding
  lean 4 name. `dubious` is either empty, or a warning message to be displayed when `n3` is
  translated, which indicates that the translation from `n3` to `n4` is approximate and may cause
  downstream errors. -/
  toLean4 : NameMap (String × Name) := {}
  /-- This maps `n4 ↦ (n3, clashes)` where `n4` is the lean 4 name and `n3::clashes` is the list of
  all (non-`synthetic`) declarations that map to `n4`. (That is, we do not assume the mapping
  from lean 3 to lean 4 name is injective.) -/
  toLean3 : NameMap (Name × List Name) := {}
  deriving Inhabited
goal: Lean.NameMap (Lean.Name × List Lean.Name)

full_name: Mathlib.Prelude.Rename.RenameMap
code: /-- This structure keeps track of alignments from lean 3 names to lean 4 names and vice versa. -/
structure RenameMap where
  /-- This maps `n3 ↦ (dubious, n4)` where `n3` is the lean 3 name and `n4` is the corresponding
  lean 4 name. `dubious` is either empty, or a warning message to be displayed when `n3` is
  translated, which indicates that the translation from `n3` to `n4` is approximate and may cause
  downstream errors. -/
  toLean4 : NameMap (String × Name) := {}
  /-- This maps `n4 ↦ (n3, clashes)` where `n4` is the lean 4 name and `n3::clashes` is the list of
  all (non-`synthetic`) declarations that map to `n4`. (That is, we do not assume the mapping
  from lean 3 to lean 4 name is injective.) -/
  toLean3 : NameMap (Name × List Name) := {}
  deriving Inhabited
goal: Type

full_name: Mathlib.Prelude.Rename.NameEntry
code: /-- An `olean` entry for the rename extension. -/
structure NameEntry where
  /-- The lean 3 name. -/
  n3 : Name
  /-- The lean 4 name, or `.anonymous` for a `#noalign`. -/
  n4 : Name
  /-- If true, this lean 3 -> lean 4 mapping will not be entered into the converse map.
  This is used for "internal" definitions that should never be referred to in the source syntax. -/
  synthetic := false
  /-- A dubious translation is one where there is a type mismatch
  from the translated lean 3 definition to a pre-existing lean 4 definition.
  Type errors are likely in downstream theorems.
  The string stored here is printed in the event that `n3` is encountered by synport. -/
  dubious := ""
goal: Type

full_name: Mathlib.Prelude.Rename.NameEntry.synthetic
code: /-- An `olean` entry for the rename extension. -/
structure NameEntry where
  /-- The lean 3 name. -/
  n3 : Name
  /-- The lean 4 name, or `.anonymous` for a `#noalign`. -/
  n4 : Name
  /-- If true, this lean 3 -> lean 4 mapping will not be entered into the converse map.
  This is used for "internal" definitions that should never be referred to in the source syntax. -/
  synthetic := false
  /-- A dubious translation is one where there is a type mismatch
  from the translated lean 3 definition to a pre-existing lean 4 definition.
  Type errors are likely in downstream theorems.
  The string stored here is printed in the event that `n3` is encountered by synport. -/
  dubious := ""
goal: Bool

full_name: Mathlib.Prelude.Rename.NameEntry.n4
code: /-- An `olean` entry for the rename extension. -/
structure NameEntry where
  /-- The lean 3 name. -/
  n3 : Name
  /-- The lean 4 name, or `.anonymous` for a `#noalign`. -/
  n4 : Name
  /-- If true, this lean 3 -> lean 4 mapping will not be entered into the converse map.
  This is used for "internal" definitions that should never be referred to in the source syntax. -/
  synthetic := false
  /-- A dubious translation is one where there is a type mismatch
  from the translated lean 3 definition to a pre-existing lean 4 definition.
  Type errors are likely in downstream theorems.
  The string stored here is printed in the event that `n3` is encountered by synport. -/
  dubious := ""
goal: Lean.Name

full_name: Mathlib.Prelude.Rename.NameEntry.dubious
code: /-- An `olean` entry for the rename extension. -/
structure NameEntry where
  /-- The lean 3 name. -/
  n3 : Name
  /-- The lean 4 name, or `.anonymous` for a `#noalign`. -/
  n4 : Name
  /-- If true, this lean 3 -> lean 4 mapping will not be entered into the converse map.
  This is used for "internal" definitions that should never be referred to in the source syntax. -/
  synthetic := false
  /-- A dubious translation is one where there is a type mismatch
  from the translated lean 3 definition to a pre-existing lean 4 definition.
  Type errors are likely in downstream theorems.
  The string stored here is printed in the event that `n3` is encountered by synport. -/
  dubious := ""
goal: String

full_name: Mathlib.Prelude.Rename.NameEntry.n3
code: /-- An `olean` entry for the rename extension. -/
structure NameEntry where
  /-- The lean 3 name. -/
  n3 : Name
  /-- The lean 4 name, or `.anonymous` for a `#noalign`. -/
  n4 : Name
  /-- If true, this lean 3 -> lean 4 mapping will not be entered into the converse map.
  This is used for "internal" definitions that should never be referred to in the source syntax. -/
  synthetic := false
  /-- A dubious translation is one where there is a type mismatch
  from the translated lean 3 definition to a pre-existing lean 4 definition.
  Type errors are likely in downstream theorems.
  The string stored here is printed in the event that `n3` is encountered by synport. -/
  dubious := ""
goal: Lean.Name

full_name: Mathlib.Prelude.Rename.RenameMap.insert
code: /-- Insert a name entry into the `RenameMap`. -/
def RenameMap.insert (m : RenameMap) (e : NameEntry) : RenameMap 
goal: Mathlib.Prelude.Rename.RenameMap

full_name: Mathlib.Prelude.Rename.RenameMap.find?
code: /-- Look up a lean 4 name from the lean 3 name. Also return the `dubious` error message. -/
def RenameMap.find? (m : RenameMap) : Name → Option (String × Name) 
goal: Lean.Name → Option (String × Lean.Name)

full_name: Mathlib.Prelude.Rename.instInhabitedThunk_mathlib
code: instance {α : Type u} [Inhabited α] : Inhabited (Thunk α) 
goal: Inhabited (Thunk α)

full_name: Mathlib.Prelude.Rename.renameExtension
code: /-- This extension stores the lookup data generated from `#align` commands. -/
-- wrap state in `Thunk` as downstream projects rarely actually query it; it only
-- gets queried when new `#align`s are added.
initialize renameExtension : SimplePersistentEnvExtension NameEntry (Thunk RenameMap) ←
  registerSimplePersistentEnvExtension {
    addEntryFn := fun t e => t.map (·.insert e)
    addImportedFn := fun es => ⟨fun _ => mkStateFromImportedEntries (·.insert) {} es⟩
  }
goal: Lean.SimplePersistentEnvExtension Mathlib.Prelude.Rename.NameEntry (Thunk Mathlib.Prelude.Rename.RenameMap)

full_name: Mathlib.Prelude.Rename.initFn._@.Mathlib.Mathport.Rename._hyg.259
code: /-- This extension stores the lookup data generated from `#align` commands. -/
-- wrap state in `Thunk` as downstream projects rarely actually query it; it only
-- gets queried when new `#align`s are added.
initialize renameExtension : SimplePersistentEnvExtension NameEntry (Thunk RenameMap) ←
  registerSimplePersistentEnvExtension {
    addEntryFn := fun t e => t.map (·.insert e)
    addImportedFn := fun es => ⟨fun _ => mkStateFromImportedEntries (·.insert) {} es⟩
  }
goal: IO (Lean.SimplePersistentEnvExtension Mathlib.Prelude.Rename.NameEntry (Thunk Mathlib.Prelude.Rename.RenameMap))

full_name: Mathlib.Prelude.Rename.addNameAlignment
code: /-- Insert a new name alignment into the rename extension. -/
def addNameAlignment (n3 : Name) (n4 : Name) (synthetic := false) (dubious := "") : CoreM Unit 
goal: Lean.CoreM Unit

full_name: Mathlib.Prelude.Rename.initFn._@.Mathlib.Mathport.Rename._hyg.390
code: /-- The `@[binport]` attribute should not be added manually, it is added automatically by mathport
to definitions that it created based on a lean 3 definition (as opposed to pre-existing
definitions). -/
initialize binportTag : TagAttribute ←
  registerTagAttribute `binport "this definition was autogenerated by mathport"
goal: IO Lean.TagAttribute

full_name: Mathlib.Prelude.Rename.binportTag
code: /-- The `@[binport]` attribute should not be added manually, it is added automatically by mathport
to definitions that it created based on a lean 3 definition (as opposed to pre-existing
definitions). -/
initialize binportTag : TagAttribute ←
  registerTagAttribute `binport "this definition was autogenerated by mathport"
goal: Lean.TagAttribute

full_name: Mathlib.Prelude.Rename.removeX
code: /--
Removes all occurrences of `ₓ` from the name.
This is the same processing used by mathport to generate name references,
and declarations with `ₓ` are used to align declarations that do not defeq match the originals.
-/
def removeX : Name → Name
  
goal: Lean.Name → Lean.Name

full_name: Mathlib.Prelude.Rename.linter.uppercaseLean3
code: /-- Because lean 3 uses a lowercase snake case convention, it is expected that all lean 3
declaration names should use lowercase, with a few rare exceptions for categories and the set union
operator. This linter warns if you use uppercase in the lean 3 part of an `#align` statement,
because this is most likely a typo. But if the declaration actually uses capitals it is not unusual
to disable this lint locally or at file scope. -/
register_option linter.uppercaseLean3 : Bool := {
  defValue := true
  descr := "enable the lean 3 casing lint"
}
goal: Lean.Option Bool

full_name: Mathlib.Prelude.Rename.initFn._@.Mathlib.Mathport.Rename._hyg.509
code: /-- Because lean 3 uses a lowercase snake case convention, it is expected that all lean 3
declaration names should use lowercase, with a few rare exceptions for categories and the set union
operator. This linter warns if you use uppercase in the lean 3 part of an `#align` statement,
because this is most likely a typo. But if the declaration actually uses capitals it is not unusual
to disable this lint locally or at file scope. -/
register_option linter.uppercaseLean3 : Bool := {
  defValue := true
  descr := "enable the lean 3 casing lint"
}
goal: IO (Lean.Option Bool)

full_name: Mathlib.Prelude.Rename.align.precheck
code: /-- Check that the referenced lean 4 definition exists in an `#align` directive. -/
register_option align.precheck : Bool := {
  defValue := true
  descr := "Check that the referenced lean 4 definition exists in an `#align` directive."
}
goal: Lean.Option Bool

full_name: Mathlib.Prelude.Rename.initFn._@.Mathlib.Mathport.Rename._hyg.550
code: /-- Check that the referenced lean 4 definition exists in an `#align` directive. -/
register_option align.precheck : Bool := {
  defValue := true
  descr := "Check that the referenced lean 4 definition exists in an `#align` directive."
}
goal: IO (Lean.Option Bool)

full_name: Mathlib.Prelude.Rename.align
code: /--
`#align lean_3.def_name Lean4.defName` will record an "alignment" from the lean 3 name
to the corresponding lean 4 name. This information is used by the
[mathport](https://github.com/leanprover-community/mathport) utility to translate later uses of
the definition.

If there is no alignment for a given definition, mathport will attempt to convert
from the lean 3 `snake_case` style to `UpperCamelCase` for namespaces and types and
`lowerCamelCase` for definitions, and `snake_case` for theorems. But for various reasons,
it may fail either to determine whether it is a type, definition, or theorem, or to determine
that a specific definition is in fact being called. Or a specific definition may need a different
name altogether because the existing name is already taken in lean 4 for something else. For
these reasons, you should use `#align` on any theorem that needs to be renamed from the default.
-/
syntax (name := align) "#align " ident ppSpace ident : command
goal: Lean.ParserDescr

full_name: Mathlib.Prelude.Rename.ensureUnused
code: /-- Checks that `id` has not already been `#align`ed or `#noalign`ed. -/
def ensureUnused {m : Type → Type} [Monad m] [MonadEnv m] [MonadError m] (id : Name) : m Unit 
goal: m Unit

full_name: Mathlib.Prelude.Rename.suspiciousLean3Name
code: /--
Purported Lean 3 names containing capital letters are suspicious.
However, we disregard capital letters occurring in a few common names.
-/
def suspiciousLean3Name (s : String) : Bool 
goal: Bool

full_name: Mathlib.Prelude.Rename.elabAlign
code: /-- Elaborate an `#align` command. -/
@[command_elab align] def elabAlign : CommandElab
  
goal: Lean.Elab.Command.CommandElab

full_name: Mathlib.Prelude.Rename.noalign
code: /--
`#noalign lean_3.def_name` will record that `lean_3.def_name` has been marked for non-porting.
This information is used by the [mathport](https://github.com/leanprover-community/mathport)
utility, which will remove the declaration from the corresponding mathport file, and later
uses of the definition will be replaced by `sorry`.
-/
syntax (name := noalign) "#noalign " ident : command
goal: Lean.ParserDescr

full_name: Mathlib.Prelude.Rename.elabNoAlign
code: /-- Elaborate a `#noalign` command. -/
@[command_elab noalign] def elabNoAlign : CommandElab
  
goal: Lean.Elab.Command.CommandElab

full_name: Mathlib.Prelude.Rename.lookup3
code: /-- Show information about the alignment status of a lean 3 definition. -/
syntax (name := lookup3) "#lookup3 " ident : command
goal: Lean.ParserDescr

full_name: Mathlib.Prelude.Rename.elabLookup3
code: /-- Elaborate a `#lookup3` command. -/
@[command_elab lookup3] def elabLookup3 : CommandElab
  
goal: Lean.Elab.Command.CommandElab

full_name: Mathlib.Prelude.Rename.ImportEntry
code: /-- An entry in the `#align_import` extension, containing all the data in the command. -/
structure ImportEntry where
  /-- The lean 3 name of the module. -/
  mod3 : Name
  /-- The original repository from which this module was derived. -/
  origin : Option (String × String)
goal: Type

full_name: Mathlib.Prelude.Rename.ImportEntry.mod3
code: /-- An entry in the `#align_import` extension, containing all the data in the command. -/
structure ImportEntry where
  /-- The lean 3 name of the module. -/
  mod3 : Name
  /-- The original repository from which this module was derived. -/
  origin : Option (String × String)
goal: Lean.Name

full_name: Mathlib.Prelude.Rename.ImportEntry.origin
code: /-- An entry in the `#align_import` extension, containing all the data in the command. -/
structure ImportEntry where
  /-- The lean 3 name of the module. -/
  mod3 : Name
  /-- The original repository from which this module was derived. -/
  origin : Option (String × String)
goal: Option (String × String)

full_name: Mathlib.Prelude.Rename.ImportState
code: /-- The data for `#align_import` that is stored in memory while processing a lean file. -/
structure ImportState where
  /-- This is the same as `(← getEnv).header.mainModule`,
  but we need access to it in `exportEntriesFn` where the environment is not available. -/
  mod4 : Name := .anonymous
  /-- The original list of import entries from imported files. We do not process these because
  only mathport actually uses it. -/
  extern : Array (Array (Name × ImportEntry)) := #[]
  /-- The import entries from the current file. -/
  entries : List ImportEntry := []
  deriving Inhabited
goal: Type

full_name: Mathlib.Prelude.Rename.instInhabitedImportState
code: /-- The data for `#align_import` that is stored in memory while processing a lean file. -/
structure ImportState where
  /-- This is the same as `(← getEnv).header.mainModule`,
  but we need access to it in `exportEntriesFn` where the environment is not available. -/
  mod4 : Name := .anonymous
  /-- The original list of import entries from imported files. We do not process these because
  only mathport actually uses it. -/
  extern : Array (Array (Name × ImportEntry)) := #[]
  /-- The import entries from the current file. -/
  entries : List ImportEntry := []
  deriving Inhabited
goal: Inhabited Mathlib.Prelude.Rename.ImportState

full_name: Mathlib.Prelude.Rename.ImportState.mod4
code: /-- The data for `#align_import` that is stored in memory while processing a lean file. -/
structure ImportState where
  /-- This is the same as `(← getEnv).header.mainModule`,
  but we need access to it in `exportEntriesFn` where the environment is not available. -/
  mod4 : Name := .anonymous
  /-- The original list of import entries from imported files. We do not process these because
  only mathport actually uses it. -/
  extern : Array (Array (Name × ImportEntry)) := #[]
  /-- The import entries from the current file. -/
  entries : List ImportEntry := []
  deriving Inhabited
goal: Lean.Name

full_name: Mathlib.Prelude.Rename.ImportState.entries
code: /-- The data for `#align_import` that is stored in memory while processing a lean file. -/
structure ImportState where
  /-- This is the same as `(← getEnv).header.mainModule`,
  but we need access to it in `exportEntriesFn` where the environment is not available. -/
  mod4 : Name := .anonymous
  /-- The original list of import entries from imported files. We do not process these because
  only mathport actually uses it. -/
  extern : Array (Array (Name × ImportEntry)) := #[]
  /-- The import entries from the current file. -/
  entries : List ImportEntry := []
  deriving Inhabited
goal: List Mathlib.Prelude.Rename.ImportEntry

full_name: Mathlib.Prelude.Rename.ImportState.extern
code: /-- The data for `#align_import` that is stored in memory while processing a lean file. -/
structure ImportState where
  /-- This is the same as `(← getEnv).header.mainModule`,
  but we need access to it in `exportEntriesFn` where the environment is not available. -/
  mod4 : Name := .anonymous
  /-- The original list of import entries from imported files. We do not process these because
  only mathport actually uses it. -/
  extern : Array (Array (Name × ImportEntry)) := #[]
  /-- The import entries from the current file. -/
  entries : List ImportEntry := []
  deriving Inhabited
goal: Array (Array (Lean.Name × Mathlib.Prelude.Rename.ImportEntry))

full_name: Mathlib.Prelude.Rename.initFn._@.Mathlib.Mathport.Rename._hyg.2132
code: /-- This extension stores the lookup data generated from `#align_import` commands. -/
initialize renameImportExtension :
    PersistentEnvExtension (Name × ImportEntry) (Name × ImportEntry) ImportState ←
  registerPersistentEnvExtension {
    mkInitial := pure {}
    addEntryFn := fun s (mod4, e) => { s with mod4, entries := e :: s.entries }
    addImportedFn := fun extern => return { mod4 := (← read).env.header.mainModule, extern }
    exportEntriesFn := fun s => s.entries.reverse.foldl (fun a b => a.push (s.mod4, b)) #[]
  }
goal: IO
  (Lean.PersistentEnvExtension (Lean.Name × Mathlib.Prelude.Rename.ImportEntry)
    (Lean.Name × Mathlib.Prelude.Rename.ImportEntry) Mathlib.Prelude.Rename.ImportState)

full_name: Mathlib.Prelude.Rename.renameImportExtension
code: /-- This extension stores the lookup data generated from `#align_import` commands. -/
initialize renameImportExtension :
    PersistentEnvExtension (Name × ImportEntry) (Name × ImportEntry) ImportState ←
  registerPersistentEnvExtension {
    mkInitial := pure {}
    addEntryFn := fun s (mod4, e) => { s with mod4, entries := e :: s.entries }
    addImportedFn := fun extern => return { mod4 := (← read).env.header.mainModule, extern }
    exportEntriesFn := fun s => s.entries.reverse.foldl (fun a b => a.push (s.mod4, b)) #[]
  }
goal: Lean.PersistentEnvExtension (Lean.Name × Mathlib.Prelude.Rename.ImportEntry)
  (Lean.Name × Mathlib.Prelude.Rename.ImportEntry) Mathlib.Prelude.Rename.ImportState

full_name: Mathlib.Prelude.Rename.alignImport
code: /-- Declare the corresponding mathlib3 module for the current mathlib4 module. -/
syntax (name := alignImport) "#align_import " ident (" from " str "@" str)? : command
goal: Lean.ParserDescr

full_name: Mathlib.Prelude.Rename.elabAlignImport
code: /-- Elaborate a `#align_import` command. -/
@[command_elab alignImport] def elabAlignImport : CommandElab
  
goal: Lean.Elab.Command.CommandElab