Skip to main content

Module resolve_env

Module resolve_env 

Source
Expand description

ENV-RESOLVE M0 flag + per-source resolution-table plumbing (the tree-walker’s consume side of the sui-resolve side-table). ENV-RESOLVE M0 — the tree-walker’s consume side of the sui-resolve parse-time variable-resolution side-table.

This module owns three things:

  1. The SUI_RESOLVE=1 env flag (read once via a OnceLock, default off) — mirrors perf::enabled()’s one-way latch.
  2. A thread-local resolution table keyed by (source_id, text_offset) — the identical key shape value::intern_cached uses for the ident symbol cache, so a resolution recorded during bind_vars on one parse tree never collides with an ident at the same offset in a different (imported) parse tree.
  3. The hot-path lookup resolution_for(offset) that the eval Ident arm consults, plus populate/clear lifecycle hooks wired into eval_with_file.

§Parity by construction

Enabling this flag only changes the tree-walker’s hot Ident arm: on a Resolution::Lexical{sym} it probes the environment’s lexical bindings with the precomputed Symbol and returns on a hit — the byte-identical value the unchanged lookup_fast returns (which probes the same lexical map, by the same Symbol, first). On ANY miss (blackhole / unrecorded / Dynamic) it falls back to today’s exact runtime path. See sui-resolve’s crate docs.

Functions§

clear
Clear the thread-local resolution table. Called at the top-level (nesting == 0) re-entry of eval_with_file, alongside clear_ident_cache(), so offsets from previous top-level evals don’t persist. No-op when the flag is off.
enabled
Whether the ENV-RESOLVE M0 fast path is enabled (SUI_RESOLVE=1).
populate
Merge a freshly-computed ResolveTable (for the parse tree tagged source_id) into the thread-local table. No-op when the flag is off.
resolution_for
Resolution recorded for the ident at (source_id, text_offset). Returns Resolution::Dynamic for any unrecorded key — the fail-safe path (the caller then takes today’s exact runtime lookup).