feat: nyash.toml SSOT + using AST統合完了(12時間の戦い)

- nyash.tomlを唯一の真実(SSOT)として依存管理確立
- dev/ci/prodプロファイルによる段階的厳格化実装
- AST結合で宣言/式の曖昧性を根本解決
- Fail-Fast原則をCLAUDE.md/AGENTS.mdに明文化
- VM fallbackでもASTベース using有効化(NYASH_USING_AST=1)
- 静的メソッドの is_static=true 修正で解決安定化
- STATICブレークハック既定OFF化で堅牢性向上

🎉 usingシステム完全体への道筋確立!JSONライブラリ・Nyash VM開発が可能に

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Selfhosting Dev
2025-09-25 16:03:29 +09:00
parent 2f5723b56d
commit d9f26d4549
19 changed files with 762 additions and 97 deletions

View File

@ -4,6 +4,14 @@
Status: Accepted (Runnerside resolution). Selfhost parser accepts using as noop and attaches `meta.usings` for future use.
> Phase 15.5 指針(いいとこ取り)
> - 依存の唯一の真実SSOT: `nyash.toml` の `[using]`aliases/packages/paths
> - 実体の合成: テキスト結合は廃止し、AST マージに一本化(曖昧さ根絶)
> - プロファイル運用: `NYASH_USING_PROFILE={dev|ci|prod}` で厳格度を段階的に切替
> - dev: toml + ファイル内 using を許可(実験/便利)
> - ci: toml 優先、ファイル using は警告または限定許可
> - prod: toml のみ。ファイル using/path はエラー(追記ガイドを提示)
## 🎯 設計思想Everything has Namespace
### **核心コンセプト**
@ -56,8 +64,8 @@ pub enum QualifiedCallee {
Policy
- Accept `using` lines at the top of the file to declare module namespaces or file imports.
- Resolution is performed by the Rust Runner when `NYASH_ENABLE_USING=1`.
- Runner strips `using` lines from the source before parsing/execution.
- Registers modules into an internal registry for path/namespace hints.
- 実体の結合は AST マージのみ。テキストの前置き/連結は行わない(移行完了後に完全廃止)。
- Runner は `nyash.toml``[using]` を唯一の真実として参照prod。dev/ci は段階的に緩和可能。
- Selfhost compiler (Ny→JSON v0) collects using lines and emits `meta.usings` when present. The bridge currently ignores this meta field.
## Namespace Resolution (Runnerside)
@ -84,7 +92,7 @@ Policy
- Treated as a synonym to `using` on the Runner side; registers aliases only.
- Examples: `needs utils.StringHelper`, `needs plugin.network.HttpClient as HttpClient`, `needs plugin.network.*`
## nyash.toml — Unified Using (Phase 15)
## nyash.toml — Unified Using(唯一の真実 / SSOT
Using resolution is centralized under the `[using]` table. Three forms are supported:
@ -98,7 +106,7 @@ Using resolution is centralized under the `[using]` table. Three forms are suppo
Notes
- Aliases are fully resolved: `using json` first rewrites to `json_native`, then resolves to a concrete path via `[using.json_native]`.
- `include` is deprecated. Use `using "./path/to/file.nyash" as Name` instead.
- `include` は廃止。代替は `using "./path/to/file.nyash" as Name`。prod では `nyash.toml` への登録が必須。
### Dylib autoload (dev guard)
- Enable autoload during using resolution: set env `NYASH_USING_DYLIB_AUTOLOAD=1`.
@ -182,12 +190,45 @@ static box Main {
Runner Configuration
- Enable using preprocessing: `NYASH_ENABLE_USING=1`
- CLI from-the-top registration: `--using "ns as Alias"` or `--using '"apps/foo.nyash" as Foo'` (repeatable)
- Using profiles (phasein): `NYASH_USING_PROFILE={dev|ci|prod}`
- dev: toml + file usingpath可、AST マージ、候補提示 ON
- ci: toml 優先、file using は警告/限定、AST マージ、フォールバック OFF
- prod: toml のみ、file using/path はエラー(追記ガイドを表示)
- Strict mode (plugin prefix required): `NYASH_PLUGIN_REQUIRE_PREFIX=1` または `nyash.toml``[plugins] require_prefix=true`
- Aliases from env: `NYASH_ALIASES="Foo=apps/foo/main.nyash,Bar=lib/bar.nyash"`
- Additional search paths: `NYASH_USING_PATH="apps:lib:."`
- Selfhost pipeline keeps child stdout quiet and extracts JSON only: `NYASH_JSON_ONLY=1` (set by Runner automatically for child)
- Selfhost emits `meta.usings` automatically when present; no additional flags required.
## 🔬 Quick SmokesAST + Profiles
開発・CIで最小コストに確認できるスモークを用意しています。AST プレリュードとプロファイルdev/prodの基本動作をカバーします。
- dev: `using "file"` 許可 + AST マージ
- prod: `using "file"` 禁止toml へ誘導) / alias・package は許可
実行例quick プロファイル)
```
# 1) dev で file using が通るAST マージ)
./tools/smokes/v2/run.sh --profile quick --filter "using_profiles_ast.sh$"
# 2) 相対パス usingサブディレクトリ
./tools/smokes/v2/run.sh --profile quick --filter "using_relative_file_ast.sh$"
# 3) 複数プレリュードtoml packages+ 依存B→A
./tools/smokes/v2/run.sh --profile quick --filter "using_multi_prelude_dep_ast.sh$"
```
テストソース
- `tools/smokes/v2/profiles/quick/core/using_profiles_ast.sh`
- `tools/smokes/v2/profiles/quick/core/using_relative_file_ast.sh`
- `tools/smokes/v2/profiles/quick/core/using_multi_prelude_dep_ast.sh`
注意
- ログに `[using] stripped line:` が出力されますが、これは AST マージ前の using 行の除去ログです(機能上問題ありません)。
- 実行バイナリは `target/release/nyash` を前提とします。未ビルド時は `cargo build --release` を実行してください。
## 🔗 関連ドキュメント
### **設計・アーキテクチャ**
@ -204,6 +245,8 @@ Runner Configuration
Notes
- Phase 15 keeps resolution in the Runner to minimize parser complexity. Future phases may leverage `meta.usings` for compiler decisions.
- レガシー実装の扱い: テキスト前置き/括弧補正などのシムは段階的に削除prod プロファイルから先に無効化)。
- AST マージは dev/ci/prod の全プロファイルで共通基盤とし、曖昧性(宣言≻式)問題の再発を原理的に回避する。
- Unknown fields in the toplevel JSON (like `meta`) are ignored by the current bridge.
- 未解決時非strictは実行を継続し、`NYASH_RESOLVE_TRACE=1` で候補を提示。strict時はエラーで候補を表示。
- **Phase 15.5完了により、現代的な名前空間システムを実現予定**