1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! 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.
use RefCell;
use OnceLock;
use ;
/// One-time read of `SUI_RESOLVE`. `true` iff `SUI_RESOLVE=1`.
static ENABLED: = new;
/// Whether the ENV-RESOLVE M0 fast path is enabled (`SUI_RESOLVE=1`).
///
/// Read once and cached — matches `perf::enabled()`'s one-way latch. When
/// `false`, every consume site takes today's exact unchanged runtime path.
thread_local!
/// Merge a freshly-computed [`ResolveTable`] (for the parse tree tagged
/// `source_id`) into the thread-local table. No-op when the flag is off.
///
/// Called once per `eval_with_file` parse, right after `next_source_id()`
/// assigns the tree its id — so imports (which re-enter `eval_with_file`
/// with their own id) contribute their own resolutions without clobbering
/// the outer file's.
/// 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).
/// 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.