docs: ADR-48 accepted — implementation notes, measurements, README/ROADMAP
draft feat/name-resolution-v2
docs: ADR-48 accepted — implementation notes, measurements, README/ROADMAP Records where A–C deviate from the plan (trace-keyed cache, O(1) special-key pre-check, member runs stop at `.`, pinned compile_with_probe), the two list-selection bugs fixed on the way, known limits, and the before/after numbers for feel-core (criterion) and feel-pg (100 000 rows). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
| Changeset | 87c40d28207834537e7667a51a784d7c2ba35906 |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@gmail.com>, |
| Parents | 83570d661238 |
| Children | |
| Pushlog | by timo via ssh |
modified DECISIONS.md +76 −1
| @@ -2359,7 +2359,9 @@ | ||
| 2359 | 2359 | |
| 2360 | 2360 | ## ADR-48: Name-resolution levels, backtick-quoted names, candidate-keyed parse cache, path-member probe |
| 2361 | 2361 | |
| 2362 | -- **Status:** *Proposed* (2026-10-14) — planned, not implemented. Builds on ADR-47. | |
| 2362 | +- **Status:** *Accepted* (2026-10-14) — steps A–C implemented on `feat/name-resolution-v2` | |
| 2363 | + (stacked on ADR-47's branch); D (`Full`) open. See **Implementation** below for where the | |
| 2364 | + build deviates from the plan. Builds on ADR-47. | |
| 2363 | 2365 | |
| 2364 | 2366 | - **Context:** ADR-47 (v1) resolves special-character names against the root scope at parse |
| 2365 | 2367 | time. Its review and follow-up left four limits: |
| @@ -2483,3 +2485,76 @@ | ||
| 2483 | 2485 | intended and made visible. Fixture suite runs at `Symbols`; the special-name tests run at |
| 2484 | 2486 | all levels. Camunda-written expressions run unchanged (`Quoted` or `Symbols`); spec-full |
| 2485 | 2487 | keyword names remain the one documented gap until D. |
| 2488 | + | |
| 2489 | +- **Implementation (A–C, 2026-10-14) — deviations from the plan above:** | |
| 2490 | + - *Cache key = the fusion's probe-answer trace*, not a bitset over a fixed candidate list. | |
| 2491 | + Path-member candidates depend on earlier fusions (the static path of | |
| 2492 | + `Date-Time2.time-zone` exists only once `Date-Time2` fused), so no fixed list exists; the | |
| 2493 | + plan is a pure function of (base tokens, answers in query order), so the trace is an exact | |
| 2494 | + key. `CompiledExpr` keeps the base parse plus the pre-fusion tokens; per evaluation the | |
| 2495 | + fusion is replayed answer-only (nothing materialised) and an all-`false` trace returns the | |
| 2496 | + base parse. | |
| 2497 | + - *O(1) pre-check* (new): every candidate contains a name symbol, so `Context` counts keys | |
| 2498 | + containing `- + * / .`; with none — and no built-in has one (guard test) — no root | |
| 2499 | + candidate can be bound and the root lookups are skipped. A text without member runs then | |
| 2500 | + returns the base parse immediately. `FunctionRegistry::may_have_special_names` covers the | |
| 2501 | + registry (empty: `false`; the wrappers say `true` for any supplied registry). Without it | |
| 2502 | + the 190-candidate formula cost 19.4 µs per compiled evaluation (> a full re-parse). | |
| 2503 | + - *Member runs stop at `.`*: at a member position the dot is navigation, not a name symbol. | |
| 2504 | + Otherwise every plain path (`order.customer.name`) asked its host for `"customer.name"` | |
| 2505 | + first — extra lookups and, for lazy hosts (Python properties, ORM relations, Lua | |
| 2506 | + `__index`, JS getters), possible side effects; and an object answering every key (an | |
| 2507 | + unbounded lazy graph) fused whole paths into one bogus key. A dotted member key needs | |
| 2508 | + backticks (`` o.`a.b` ``). Root-level `x.y` keeps ADR-47's behaviour (a map lookup, no | |
| 2509 | + host call). | |
| 2510 | + - *API*: `compile`/`compile_with` are adaptive; `compile_with_probe(expr, probe, options)` | |
| 2511 | + **pins** one scope (single parse — what the one-shot `evaluate` uses); | |
| 2512 | + `has_name_runs()` is removed; `name_run_candidates` stays as a root-level diagnostic; | |
| 2513 | + `CompiledExpr::scoped_parses()`/`name_resolution()` added. `CompiledExpr::evaluate_with_env` | |
| 2514 | + probes `ScopeWithFunctions` with the env's registry, so the compiled wrapper classes reach | |
| 2515 | + hyphen-named host functions too. | |
| 2516 | + - *Lazy host lists*: a member probe on a lazy list answers with per-element selections; | |
| 2517 | + only when that answer is a list is the node forced one level to tell a list from a | |
| 2518 | + list-valued member. | |
| 2519 | + - *Two pre-existing bugs fixed on the way*: selection on a lazy **jsonb array** (feel-pg) and | |
| 2520 | + a lazy **Lua sequence** returned null instead of mapping over the elements | |
| 2521 | + (`orders.x` over `[{"x":1},{"x":2}]` → `[1, 2]`, §10.3.2.5). Python and JS arrays become | |
| 2522 | + lists at the boundary and were unaffected. | |
| 2523 | + - *Known limits*: the member probe navigates from the **root** binding, so a loop variable | |
| 2524 | + or parameter shadowing a root key (`for item in items return item.unit-price` with a root | |
| 2525 | + `item`) is probed against the root value; dynamic bases and filter-element keys stay | |
| 2526 | + arithmetic — backticks cover all of these. | |
| 2527 | + | |
| 2528 | +- **Measurements (2026-10-14; criterion medians, `cargo bench -p feel-core --bench names`; | |
| 2529 | + feel-pg: `count(feel_eval(…))` over 100 000 rows, best of 5, release build, PG 18.4).** | |
| 2530 | + "Before" is the ADR-47 branch head (`ce0d233`) with the same bench file. | |
| 2531 | + | |
| 2532 | + | feel-core | parse before → after | compiled eval before → after | one-shot `evaluate` before → after | | |
| 2533 | + |---|---|---|---| | |
| 2534 | + | `1 + 1` | 1.01 → 1.09 µs | 162 → 165 ns | 1.27 → 1.25 µs | | |
| 2535 | + | `applicant.age >= 18` | 1.84 → 2.03 µs | 288 → 281 ns | 2.56 → 2.14 µs | | |
| 2536 | + | `if applicant.age >= 18 then … else …` | 3.82 → 3.96 µs | 321 → 323 ns | 4.46 → 4.07 µs | | |
| 2537 | + | 190-candidate formula, none bound | 13.5 → 14.6 µs | 1.36 → 1.40 µs | 46.6 → 16.2 µs | | |
| 2538 | + | `a-b * 2`, `a-b` bound | 1.89 → 2.21 µs | 231¹ → 409 ns | 2.05 → 2.11 µs | | |
| 2539 | + | `applicant.net-income > 1000` | 2.44 → 2.77 µs | 337¹ → 692 ns | 3.26 → 3.17 µs | | |
| 2540 | + | one program, two alternating scopes (per pair) | — | 477¹ → 663 ns | 4.51 → 4.23 µs | | |
| 2541 | + | |
| 2542 | + ¹ before ADR-48 `compile` was probe-free: these numbers are the *arithmetic* (wrong) reading. | |
| 2543 | + The correct pre-ADR-48 path for them was the one-shot `evaluate` (≈ 2–3.3 µs). | |
| 2544 | + | |
| 2545 | + | feel-pg, 100 000 rows | before | after | | |
| 2546 | + |---|---|---| | |
| 2547 | + | `applicant.age >= 18` (`feel_eval` / `_immutable`) | 128 / 125 ms | 131 / 128 ms | | |
| 2548 | + | `applicant.net-income > 1000` | 111 ms¹ | 178 ms | | |
| 2549 | + | `a-b * 2`, half the rows bind `a-b` | 382 ms | 301 ms | | |
| 2550 | + | same via `feel_eval_immutable` | ERROR | 310 ms | | |
| 2551 | + | 190-candidate formula | 576 ms | 422 ms | | |
| 2552 | + | same, `name_resolution => 'quoted'` | — | 422 ms | | |
| 2553 | + | |
| 2554 | + Reading: simple expressions are unchanged within noise (parse +5–10 %: the pre-fusion | |
| 2555 | + tokens are kept and scanned once more). Scope-dependent shapes now pay only where a | |
| 2556 | + special name is actually in play — a few hundred ns per compiled evaluation, ~0.7 µs per | |
| 2557 | + row for a nested hyphen member — and are *correct* on the compiled path. feel-pg's mixed | |
| 2558 | + rows got 21 % faster (no per-row re-parse), the formula 27 % faster (no 190 lookups per | |
| 2559 | + row). `'quoted'` buys nothing extra once the pre-check applies; it matters for contexts | |
| 2560 | + that do carry special keys. | |
modified README.md +20 −13
| @@ -51,14 +51,21 @@ | ||
| 51 | 51 | - **String literals** decode the FEEL escapes (`\n \r \t \" \' \\`, `\uXXXX` |
| 52 | 52 | incl. UTF-16 surrogate pairs, `\UXXXXXX`); an unrecognised escape (e.g. a regex |
| 53 | 53 | `\d`) is preserved verbatim so it reaches the regex provider untouched. |
| 54 | -- **Special-character names (§10.3.1.6, ADR-47):** a name may contain the | |
| 54 | +- **Special-character names (§10.3.1.6, ADR-47/48):** a name may contain the | |
| 55 | 55 | additional name symbols `- + * / .` (`a-b`, `Date-Time`, `x.y` — including |
| 56 | - reserved words as non-initial parts, `x-in`; a name never starts with one). The ambiguity against arithmetic and path | |
| 57 | - access is resolved against the **scope**: longest in-scope match preferred, | |
| 58 | - left to right; spaces are not part of the name (`a - b` is the same candidate | |
| 59 | - as `a-b`); `(a)-(b)` forces the operator reading. One-shot `evaluate` resolves | |
| 60 | - names this way (the context is the scope); `compile` is probe-free — a compiled | |
| 61 | - program pins no scope (ADR-47). | |
| 56 | + reserved words as non-initial parts, `x-in`; a name never starts with one). | |
| 57 | + The ambiguity against arithmetic and path access is resolved against the | |
| 58 | + **scope**: longest in-scope match preferred, left to right; spaces are not | |
| 59 | + part of the name (`a - b` is the same candidate as `a-b`); `(a)-(b)` forces | |
| 60 | + the operator reading. On a static path the navigated value is the scope | |
| 61 | + (`applicant.first-name`). Both `evaluate` and `compile` resolve per context — | |
| 62 | + a compiled program caches one parse per distinct scope reading. | |
| 63 | +- **Backtick-quoted names** (`` `a-b` ``, `` `Profit and loss` ``, | |
| 64 | + `` applicant.`first-name` `` — a non-standard extension with feel-scala's | |
| 65 | + syntax, so Camunda expressions run unchanged): one name, decided by the text, | |
| 66 | + in every name slot. A `names` option selects `"symbols"` (default) or | |
| 67 | + `"quoted"` (backticks only, `a-b` always subtraction — Camunda semantics); | |
| 68 | + feel-pg takes it as the `name_resolution` argument (ADR-48). | |
| 62 | 69 | - **User-defined functions:** FEEL `function(a, b) a + b` closures, and |
| 63 | 70 | host-provided functions — a Python callable, JS function or Lua function passed in |
| 64 | 71 | the context (or an ambient `functions` registry) and invoked from the expression, |
| @@ -74,12 +81,12 @@ | ||
| 74 | 81 | `wasm-pack build crates/feel-wasm --target nodejs -- --features iana-tz` (~723 KB |
| 75 | 82 | vs the ~479 KB offset-only default, where a named zone evaluates to null). |
| 76 | 83 | |
| 77 | -Still out of scope: unary tests (the non-interval `in` forms), names in | |
| 78 | -*declaration* slots (`for a-b in …`, formal parameters, context keys), | |
| 79 | -special-character names in *inner* scopes (path members like | |
| 80 | -`applicant.first-name`, filter-element keys — only root-level names are probed), | |
| 81 | -space-joined reserved-word names (`Profit and loss`) and `?`/non-XID name | |
| 82 | -starts (`what if?`, grammar rule 28 — see ADR-47's deviations), typed | |
| 84 | +Still out of scope: unary tests (the non-interval `in` forms); *unquoted* | |
| 85 | +special-character names in declaration slots (`for a-b in …`, formal | |
| 86 | +parameters, context keys), on dynamic path bases (`f(x).a-b`) and as | |
| 87 | +filter-element keys, *unquoted* space-joined reserved-word names | |
| 88 | +(`Profit and loss`) and `?`/non-XID name starts (`what if?`) — all reachable | |
| 89 | +with backticks (ADR-48); typed | |
| 83 | 90 | function parameters, and general invocation on an arbitrary |
| 84 | 91 | expression that *holds* a function (`var(args)`, imported `lib.fn(args)`) — invoking |
| 85 | 92 | a non-function literal yields null per spec (ADR-38). See [DECISIONS.md](DECISIONS.md) for the |
modified ROADMAP.md +11 −9
| @@ -316,14 +316,16 @@ | ||
| 316 | 316 | documented scope-blindness); `?`/non-XID name starts (`what if?`, rule 28 — the |
| 317 | 317 | 0083-feel-unicode bucket); names in inner scopes (see v2 below). |
| 318 | 318 | |
| 319 | -### v2: levels, backticks, adaptive compile, path members (open — ADR-48, proposed) | |
| 320 | - | |
| 321 | -Remaining v1 limits: `compile()` cannot reach special names (probe-free); | |
| 322 | -feel-pg re-parses every row that binds a candidate and `feel_eval_immutable` | |
| 323 | -rejects it; only **root** keys are probed — `applicant.first-name` parses as | |
| 324 | -`applicant.first - name` (pinned by a feel-core test; workaround today: | |
| 325 | -`get value(applicant, "first-name")`); keyword names (`Profit and loss`) are | |
| 326 | -unsupported. Plan in [DECISIONS.md](DECISIONS.md) ADR-48, in this order: | |
| 319 | +### v2: levels, backticks, adaptive compile, path members (ADR-48 — A–C ✅ shipped, D open) | |
| 320 | + | |
| 321 | +**Status:** A–C implemented on branch `feat/name-resolution-v2` (stacked on | |
| 322 | +`feat/special-char-names`); measurements, deviations from the plan (trace-keyed | |
| 323 | +cache, O(1) special-key pre-check, member runs stop at `.`) and two | |
| 324 | +pre-existing list-selection bugs fixed on the way (feel-pg jsonb arrays, Lua | |
| 325 | +sequences) are recorded in [DECISIONS.md](DECISIONS.md) ADR-48. Remaining v1 | |
| 326 | +limits before this: `compile()` could not reach special names; feel-pg | |
| 327 | +re-parsed every row that bound a candidate and `feel_eval_immutable` rejected | |
| 328 | +it; only root keys were probed; keyword names were unsupported. Plan, in order: | |
| 327 | 329 | |
| 328 | 330 | - **A — Backtick-quoted names + resolution levels.** `` `a-b` ``, |
| 329 | 331 | `` `Profit and loss` ``, `` applicant.`first-name` `` — feel-scala's syntax |
| @@ -345,7 +347,7 @@ | ||
| 345 | 347 | path-qualified candidates join B's bitset; list steps check any element. |
| 346 | 348 | Dynamic bases and filter-element keys (`items[unit-price > 10]`) stay |
| 347 | 349 | deferred — backticks cover them. |
| 348 | -- **D — `Full` (keyword names), on demand only.** First measure whether the | |
| 350 | +- **D — `Full` (keyword names), on demand only — open.** First measure whether the | |
| 349 | 351 | TCK uses unquoted keyword names; decide which keywords may join (not `in`) |
| 350 | 352 | and the interplay with the fixed joins (`date and time`). |
| 351 | 353 | |