Phase 22.1 WIP: SSOT resolver + TLV infrastructure + Hako MIR builder setup

Setup infrastructure for Phase 22.1 (TLV C shim & Resolver SSOT):

Core changes:
- Add nyash_tlv, nyash_c_core, nyash_kernel_min_c crates (opt-in)
- Implement SSOT resolver bridge (src/using/ssot_bridge.rs)
- Add HAKO_USING_SSOT=1 / HAKO_USING_SSOT_HAKO=1 env support
- Add HAKO_TLV_SHIM=1 infrastructure (requires --features tlv-shim)

MIR builder improvements:
- Fix using/alias consistency in Hako MIR builder
- Add hako.mir.builder.internal.{prog_scan,pattern_util} to nyash.toml
- Normalize LLVM extern calls: nyash.console.* → nyash_console_*

Smoke tests:
- Add phase2211 tests (using_ssot_hako_parity_canary_vm.sh)
- Add phase2220, phase2230, phase2231 test structure
- Add phase2100 S3 backend selector tests
- Improve test_runner.sh with quiet/timeout controls

Documentation:
- Add docs/ENV_VARS.md (Phase 22.1 env vars reference)
- Add docs/development/runtime/C_CORE_ABI.md
- Update de-rust-roadmap.md with Phase 22.x details

Tools:
- Add tools/hakorune_emit_mir.sh (Hako-first MIR emission wrapper)
- Add tools/tlv_roundtrip_smoke.sh placeholder
- Improve ny_mir_builder.sh with better backend selection

Known issues (to be fixed):
- Parser infinite loop in static method parameter parsing
- Stage-B output contamination with "RC: 0" (needs NYASH_JSON_ONLY=1)
- phase2211/using_ssot_hako_parity_canary_vm.sh fork bomb (needs recursion guard)

Next steps: Fix parser infinite loop + Stage-B quiet mode for green tests
This commit is contained in:
nyash-codex
2025-11-09 15:11:18 +09:00
parent 5d2cd5bad0
commit 981ddd890c
62 changed files with 1981 additions and 103 deletions

View File

@ -0,0 +1,58 @@
// UsingResolveSSOTBox — SSOT for using/modules resolution (Phase 22.1)
// Contract (MVP):
// - Pure function. IOfilesystem access禁止。与えられた ctx のみを参照。
// - 優先順: modulesnyash.toml 明示) > relative 推定cwd → using_paths の順) > 見つからないnull
// - relative 推定は ctx.relative_hint=="1" が有効時のみ既定OFF挙動不変
// - 曖昧(複数候補)の最終判断は Runner 側。strict=1 時は legacy へ委譲する(本箱は null を返すのが安全)。
// Extension points:
// - ctx.modules: Map<String,String>(厳密一致)
// - ctx.using_paths: Array<String>(将来のヒント/本箱では純粋合成のみ)
// - ctx.cwd: String相対の基準
static box UsingResolveSSOTBox {
/// Resolve a module name to a file path string (or null when not found).
/// name: requested module name (e.g., "hako.mir.builder.internal.lower_return_int")
/// ctx : optional map for extra hints. Supported keys (all optional):
/// - modules: Map<String,String> (exact name → path)
/// - using_paths: Array<String> (search bases; no IO here, used only for future hints)
/// - cwd: String (caller context dir)
method resolve(name, ctx) {
if name == null { return null }
// Strictly pure: do not access filesystem here. Consume only provided hints.
// 1) modules mapping has priority
if ctx != null {
local m = ctx.get("modules");
if m != null {
local hit = m.get(name);
if hit != null { return hit }
}
// 2) Relative hint (optional): synthesize a likely path using using_paths/cwd
// Gate via ctx.relative_hint == "1" to avoid behavior changes unless explicitly enabled.
local rh = ctx.get("relative_hint");
if rh != null && rh == "1" {
local leaf = me._dot_to_slash(name) + ".hako";
// prefer cwd
local cwd = ctx.get("cwd");
if cwd != null {
return me._join_path(cwd, leaf)
}
local ups = ctx.get("using_paths");
if ups != null {
local i = 0; while i < ups.size() {
local base = ups.get(i);
return me._join_path(base, leaf)
i = i + 1 }
}
}
}
// No IO side effects in MVP
return null
}
_dot_to_slash(s) { return s.replace(".", "/") }
_join_path(base, leaf) {
if base == null { return leaf }
if base.endsWith("/") { return base + leaf }
return base + "/" + leaf
}
}