plotnik_lib/ir/ids.rs
1//! ID types for the compiled query IR.
2//!
3//! These are lightweight wrappers/aliases for indices and identifiers
4//! used throughout the IR. They provide type safety without runtime cost.
5
6use std::num::NonZeroU16;
7
8/// Index into the transitions segment.
9pub type TransitionId = u32;
10
11/// Node type ID from tree-sitter. Do not change the underlying type.
12pub type NodeTypeId = u16;
13
14/// Node field ID from tree-sitter. Uses `NonZeroU16` so `Option<NodeFieldId>`
15/// is the same size as `NodeFieldId` (niche optimization with 0 = None).
16pub type NodeFieldId = NonZeroU16;
17
18/// Index into the string_refs segment.
19pub type StringId = u16;
20
21/// Sentinel value for unnamed types (wrapper types have no explicit name).
22pub const STRING_NONE: StringId = 0xFFFF;
23
24/// Field name in effects (alias for type safety).
25pub type DataFieldId = StringId;
26
27/// Variant tag in effects (alias for type safety).
28pub type VariantTagId = StringId;
29
30/// Index for definition references (Enter/Exit).
31pub type RefId = u16;
32
33/// Index into type_defs segment (with reserved primitives 0-2).
34pub type TypeId = u16;
35
36// TypeId reserved constants
37pub const TYPE_VOID: TypeId = 0;
38pub const TYPE_NODE: TypeId = 1;
39pub const TYPE_STR: TypeId = 2;
40pub const TYPE_INVALID: TypeId = 0xFFFF;