docs+runner+parser: SSOT+AST using finalized (legacy text inlining removed); provider verify reads nyash.toml; preflight warn hook; method-body guard removed; CURRENT_TASK updated for next JSON work

This commit is contained in:
Selfhosting Dev
2025-09-26 00:27:02 +09:00
parent d9f26d4549
commit 85084664c2
77 changed files with 1259 additions and 1026 deletions

View File

@ -114,5 +114,5 @@ Nyash Source ──▶ MIR (Builder)
- `docs/reference/architecture/mir-26-instruction-diet.md`
See also
- `docs/examples/http_result_patterns.md` - HTTPのResult挙動unreachable/404/500のE2E例
- `docs/guides/examples/http_result_patterns.md` - HTTPのResult挙動unreachable/404/500のE2E例
- `docs/VM_README.md` - VM統計とプラグイン周りの既知制約

View File

@ -0,0 +1,23 @@
# PHI and SSA in Nyash
Overview
- Nyash lowers high-level control flow (If/Loop/Match) to MIR and backends that rely on SSA form.
- We prioritize IR hygiene and observability while keeping runtime cost at zero.
Design points
- PHI hygiene: no empty PHIs; PHIs at block head only.
- JoinResult hint: when both branches assign the same variable, we emit a MIR hint for diagnostics.
- Loop carriers: loops may expose a carrier observation (≤ N variables, where N is unconstrained by design; smokes emphasize common cases).
Normalization
- If: may optionally wrap into LoopForm under a conservative gate (dev only). Semantics remain unchanged.
- Match: scrutinee evaluated once, guard fused; normalized to nested Ifchain in macro/core pass.
Testing
- LLVM smokes: fixed small cases ensure no empty PHIs and head placement.
- MIR smokes: trace `scope|join|loop` to validate shaping without peeking into IR details.
Roadmap
- Remove text-level sanitization once finalizePHI is trustworthy across Loop/If/Match.
- Expand goldens to cover nested joins and multicarrier loops while keeping CI light.

View File

@ -0,0 +1,85 @@
# nyash.toml — Configuration Reference (Phase 15.5)
Status: Proposed受け口から段階導入。未指定時は現行既定を維持
## 目的
- 依存関係・実行方針の**唯一の真実SSOT**。
- using の解決AST プレリュード)と、将来の Provider/Type 分離(受け口)を一元管理。
## セクション一覧
### [env]
任意の既定環境変数(`NYASH_*`。CI/ローカルで上書き可。
### [using]
検索ルート `paths = ["apps","lib","."]`、名前付きパッケージ `[using.<name>]`、エイリアス `[using.aliases]`
例:
```toml
[using]
paths = ["apps", "lib", "."]
[using.json_native]
path = "apps/lib/json_native/"
main = "parser/parser.nyash"
[using.string_utils]
path = "apps/lib/json_native/utils/string.nyash"
[using.aliases]
json = "json_native"
StringUtils = "string_utils"
```
### Provider/Type受け口・既定OFF
Stable Type NameSTNを Provider IDPVNにマッピング。未指定時は現行ランタイム既定。
```toml
[types.StringBox]
provider = "kernel:string@1.0"
interop = "forbid" # forbid|explicit|auto既定: forbid
[providers."kernel:string@1.0"]
crate = "nyash-plugin-base-string" # 静的リンクのブートストラップ提供者
[providers."acme:string@2.1"]
path = "./plugins/libacme_string.so"
override = true
[policy]
factory = "plugin-first" # plugin-first|compat_plugin_first|static_only
```
注意:
- 本仕様は「受け口」の段階。実行挙動は段階導入Verify→Lock→実行
- 互換性重視のため、未指定時は現行と同じ既定にフォールバックする。
### [plugins.bootstrap] / [plugins.dynamic](提案)
静的リンクのブートストラップ束/動的ロード(開発)を明示。
```toml
[plugins.bootstrap]
string = { crate = "nyash-plugin-base-string", version = "2.3.0" }
integer = { crate = "nyash-plugin-base-integer", version = "1.5.1" }
[plugins.dynamic]
# string = { path = "./plugins/libnyash_string_plugin.so", override = true }
```
## Profilesusing / AST
`NYASH_USING_PROFILE={dev|ci|prod}`
- dev/ci: AST プレリュード既定ONfile-usingはdevで許可、ciは警告/限定)
- prod: AST 既定OFFtoml 由来のみ、file-using はエラー)
実装ノート:
- AST 既定は `src/config/env.rs: using_ast_enabled()` でプロファイルに従い決定。
- 既存のレガシー前置きは prod で禁止、dev/ci でも段階的に削除予定。
## Verifyplugin-tester
CI/起動前に最低限の契約を検査(例: String の `birth/fini/toUtf8/fromUtf8/equals/length/concat`)。欠落時は即停止。
## 参考
- Kernel/Plugin 方針: docs/reference/runtime/kernel-and-plugins.md
- ADR: docs/development/adr/adr-001-no-corebox-everything-is-plugin.md

View File

@ -64,7 +64,7 @@ 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`.
- 実体の結合は AST マージのみ。テキストの前置き/連結は行わない(移行完了後に完全廃止)。
- 実体の結合は 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.
@ -191,15 +191,18 @@ 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 はエラー追記ガイドを表示
- dev: AST マージ 既定ON、legacy前置きは既定で無効必要時は `NYASH_LEGACY_USING_ALLOW=1` で一時許可)
- ci: AST マージ 既定ON、legacy前置きは既定で無効同上の一時許可
- prod: AST マージ 既定OFF、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.
Note: Provider/Type 分離(型名は不変で提供者のみを切替)については ADR を参照。
docs/development/adr/adr-001-no-corebox-everything-is-plugin.md
## 🔬 Quick SmokesAST + Profiles
開発・CIで最小コストに確認できるスモークを用意しています。AST プレリュードとプロファイルdev/prodの基本動作をカバーします。

View File

@ -0,0 +1,51 @@
# NyKernel と Plugins — 最小ランタイムとプラグイン体系Phase 15.5
Status: Proposed (受け口のみ; 既定OFF)
ADR: docs/development/adr/adr-001-no-corebox-everything-is-plugin.md
## 目的
- Kernel を最小化(箱を持たない)し、機能はすべて Plugin で提供する。
- VM/LLVM 双方から同一 ABI`ny_new_box` / `ny_call_method`)で箱を扱う。
## 起動シーケンス(標準形)
1) NyKernel initGC/Handle/TLV/Extern/PluginRegistry
2) nyash.toml 読み込み
- `plugins.bootstrap`(静的束)を登録
- `plugins.dynamic`.so/.dllがあれば dlopen 登録
3) Plugin Verify必須メソッド/TLV/ABI
4) 実行VM/LLVM → `ny_call_method`
ブートの不変条件(重要)
- Provider Lock型→提供者の対応表が確定するまで、いかなる Box 生成も禁止。
- Kernel ログ(生バイト)で初期エラーを出力し、`StringBox` 等の Box をログ用途に使わない。
- Verify に失敗した場合は、Kernel ログで理由を表示して即終了する。
## Provider/Type 分離(概要)
- Stable Type NameSTN: `StringBox`, `IntegerBox` など。コード上の型名は不変。
- Provider IDPVN: `kernel:string@1.0` / `acme:string@2.1` など実装提供者。
- TOML で STN→PVN をバインドし、置換は TOML 側で行う。
Provider Lockロック
- 起動時に `types.<Type>` の provider を決定し、Provider Lock を作成・固定する。
- Lock 前の `ny_new_box` / `ny_call_method` はエラーE_PROVIDER_NOT_LOCKED
- Handle は `{ type_id, provider_id }` を保持し、デバッグビルドでは不一致検知時に panic本番では混入しない設計
## ポリシー(例)
- `plugin-first`(デフォルト): 動的プラグインの上書きを許可
- `compat_plugin_first`: 静的→動的のフォールバックを許可(移行期)
- `static_only`(本番): 静的のみ許可
Interop同一型の異 Provider 混在)
- 既定は混在禁止forbid。同一プロセス内で 1 Type = 1 Provider を維持する。
- 研究・開発用途でのみ `explicit/auto` を許可できるが、本番非推奨。
- explicit: 明示 API による変換のみ許可UTF8 などの正規形式を介する)
- auto: 暗黙変換を許可し、変換回数・バイト数をメトリクスに集計(本番非推奨)
## 現状の段階
- 受け口/ドキュメントの整備を先行(挙動は不変)。
- using は SSOT+AST に移行済みprod は file-using 禁止)。
- VM fallback の個別救済は暫定(短期で Bootstrap Pack へ移行し撤去)。
関連ドキュメント
- nyash.toml のスキーマと例: docs/reference/config/nyash-toml.md
- usingSSOT/AST/Profiles: docs/reference/language/using.md