ItemId is the identity of a symbol or type: a (module, item) pair.
The fields are private on purpose: the module half reserves bit 30 as the "backend minted" marker, so all construction and inspection has to go through this module's API and the marker bit can never leak into module indexing or arithmetic.
Three id spaces coexist per module:
- Semantic-phase and NIF-loader ids: itemId(module, item) with item > 0.
- Backend-minted ids (IC codegen, nim nifc: transf labels and temps, lifted hooks): backendItemId sets BackendModuleBit, so these can never compare equal to a loader id even though both counters mint the same small item range in one process. They never cross a process boundary and must never be written to a NIF file.
- Derived env/tuple-field ids (lowerings.addField): the source local's id with item negated. derivedFieldId preserves the backend marker, keeping the derivation collision-free for both id spaces above.
Consts
PackageModuleId = -3'i32
- Source Edit
Procs
proc backendItemId(module, item: int32): ItemId {.inline, ...raises: [], tags: [], forbids: [].}
- An id minted during IC codegen; distinct from every itemId of the same module so that the loader's stub counter and the backend's counter cannot collide in id-keyed tables. Source Edit
proc derivedFieldId(source: ItemId): ItemId {.inline, ...raises: [], tags: [], forbids: [].}
- The id of the env/tuple field that lowerings.addField derives for a captured local: item negated, module bits (including the backend marker) preserved. Source Edit
proc isBackendMinted(x: ItemId): bool {.inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc matchesDerivedFieldId(field, source: ItemId): bool {.inline, ...raises: [], tags: [], forbids: [].}
- Does field carry the id derivedFieldId would derive for source? source may itself already be the derived field id. Source Edit