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
// Copyright 2024-2026 Jonathan Shook
// SPDX-License-Identifier: Apache-2.0
//! Cascade-extern emission helpers — building blocks the scope
//! builders use to push individual lines of Polydat source into a
//! string that's later folded into a [`polydat::kernel::subcontext::PolydatMatter`]
//! and handed to the builder.
//!
//! These are the "build" half of walk + build + synthesize: the
//! walker has decided that a particular name should be cascaded;
//! these helpers do the per-name source-line emission consistent
//! with nmbrs-runtime's Polydat conventions (chain-aware lookup, type
//! widening rules, escape handling).
use HashSet;
use crateScopeKernel;
use ;
/// Emit `const NAME := <literal>` for one workload param into
/// `source`, choosing the literal value via the canonical
/// chain-aware lookup order:
///
/// 1. `parent_kernel.lookup(name)` — if `Some`, this is the
/// chain-resolved value. A `bindings:` / `set:` scope above
/// us may have shadowed the workload-param default; whichever
/// `const NAME := <override>` is closest in the chain wins
/// via the local-final transit-suppression rule
/// (SRD-13f §"Local-authoritative shadow"). If the lookup is
/// non-scalar (vectors etc.), skip the chain path and fall
/// back.
/// 2. `hashmap_default` — the workload-load-time default from
/// `params:` plus CLI overrides. Used when nothing in the
/// chain has a value for `name`.
///
/// Pre-marks `name` in `emitted` so subsequent cascade passes in
/// the caller skip it. Optionally appends to `inherited_names`
/// for the inherited-output bookkeeping consumers also do.
///
/// **Why this helper exists**: pre-helper, seven distinct
/// synthesizer sites each rolled their own `const NAME := <hashmap>`
/// emission, reading the HashMap directly without consulting the
/// chain. Any name a scenario-tree `set:` or `bindings:` scope
/// shadowed kept the stale HashMap default inside any sub-scope
/// synthesized via one of those sites — breaking the SRD-21 /
/// SRD-18 contract that the kernel chain is the single
/// resolution surface. Routing through this helper closes that
/// hole categorically.