Module rustc_hir::definitions

source ·
Expand description

For each definition, we track the following data. A definition here is defined somewhat circularly as “something with a DefId”, but it generally corresponds to things like structs, enums, etc. There are also some rather random cases (like const initializer expressions) that are mostly just leftovers.

Structs

  • A unique identifier that we can use to lookup a definition precisely. It combines the index of the definition’s parent (if any) with a DisambiguatedDefPathData.
  • A DefPathHash is a fixed-size representation of a DefPath that is stable across crate and compilation session boundaries. It consists of two separate 64-bit hashes. The first uniquely identifies the crate this DefPathHash originates from (see StableCrateId), and the second uniquely identifies the corresponding DefPath within that crate. Together they form a unique identifier within an entire crate graph.
  • The DefPathTable maps DefIndexes to DefKeys and vice versa. Internally the DefPathTable holds a tree of DefKeys, where each DefKey stores the DefIndex of its parent. There is one DefPathTable for each crate.
  • The definition table containing node definitions. It holds the DefPathTable for LocalDefIds/DefPaths. It also stores mappings to convert LocalDefIds to/from HirIds.
  • A pair of DefPathData and an integer disambiguator. The integer is normally 0, but in the event that there are multiple defs with the same parent and data, we use this field to disambiguate between them. This introduces some artificial ordering dependency but means that if you have, e.g., two impls for the same type in the same module, they do get distinct DefIds.

Enums