Stable named-int identifier minted by Tracer for each distinct TensorImpl observed during a trace. Unique within one TraceGraph only — never reused, never persisted.
Design. TraceId is a named std::int64_t rather than a
raw alias so that:
- The trace-id namespace is greppable as a type (e.g. find every
function that takes a
TraceIdparameter).- Hash specialization is bound to this type (no accidental overload conflicts with other 64-bit identifiers).
- Future strict-typing upgrades (e.g. removing implicit
conversion to
int64_tto prevent passing a raw int where a TraceId is expected) only require flipping theoperator std::int64_t()conversion. All call sites are already compile-time-verified to use the named type.
Implicit conversion. We deliberately preserve implicit
conversion to/from std::int64_t for the first pass — there are
~400 call sites across the compile path that mix raw ints (Python
bindings, monotonic counter arithmetic, sentinel -1 checks)
with TraceId. Switching to explicit would force a parallel
migration we can do in a follow-up. The named type still moves
the codebase forward and unblocks the audit-flagged improvement.
Sentinel. TraceId::external_feed() (== -1) signals "not
produced by any traced op" — i.e. an external feed (model
parameter or user input). Use id == TraceId::external_feed()
in new code; id.v < 0 still works for backwards compat.