feat(phase285): Complete weak reference implementation (VM + LLVM harness)

Phase 285LLVM-1.1 to 1.4 + weak reference infrastructure:

**LLVM Harness** (Phase 285LLVM-1.x):
- 285LLVM-1.1: User Box registration & debug output
- 285LLVM-1.2: WeakRef basic operations (identity deferred)
- 285LLVM-1.3: InstanceBox field access (getField/setField)
- 285LLVM-1.4: print Handle resolution (type tag propagation)

**VM Runtime** (nyash_kernel):
- FFI functions: nyrt_weak_new, nyrt_weak_to_strong, nyrt_weak_drop
  (crates/nyash_kernel/src/lib.rs: +209 lines)
- WeakRef plugin invoke support
  (crates/nyash_kernel/src/plugin/invoke.rs: +250 lines)
- weak_handles.rs: WeakRef handle registry (NEW)

**LLVM Python Backend**:
- WeakRef instruction lowering (weak.py: NEW)
- Entry point integration (entry.py: +93 lines)
- Instruction lowering (instruction_lower.py: +13 lines)
- LLVM harness runner script (tools/run_llvm_harness.sh: NEW)

**MIR & Runtime**:
- WeakRef emission & validation
- MIR JSON export for weak instructions
- Environment variable support (NYASH_WEAK_*, HAKO_WEAK_*)

**Documentation**:
- CLAUDE.md: Phase 285 completion notes
- LANGUAGE_REFERENCE_2025.md: Weak reference syntax
- 10-Now.md & 30-Backlog.md: Phase 285 status updates

Total: +864 lines, 24 files changed

SSOT: docs/reference/language/lifecycle.md
Related: Phase 285W-Syntax-0, Phase 285W-Syntax-0.1
This commit is contained in:
2025-12-25 00:11:34 +09:00
parent cc05c37ae3
commit f740e6542f
27 changed files with 1176 additions and 41 deletions

View File

@ -3,6 +3,72 @@
//! Consolidates NYASH_* environment variables across subsystems and
//! optionally applies overrides from `nyash.toml`.
//!
//! # Global Environment Configuration (管理棟)
//!
//! ## 環境変数の集約と直読み禁止
//!
//! **Phase 286A/B** で、全システムの環境変数を `src/config/env/` 以下のモジュールに集約しました。
//!
//! - **直読み禁止**: `std::env::var()` / `std::env::set_var()` の直接呼び出しは禁止です。
//! - **必ず `src/config/env/*` 経由でアクセス**: 各サブシステムのフラグモジュール (`macro_flags`, `box_factory_flags`, etc.) を使用してください。
//!
//! ## モジュール構成
//!
//! | モジュール | 担当環境変数 | 用途 |
//! | --- | --- | --- |
//! | `macro_flags` | `NYASH_MACRO_*` | Macro システム設定 |
//! | `box_factory_flags` | `NYASH_BOX_FACTORY_*`, `NYASH_DISABLE_PLUGINS` | Box Factory / プラグイン設定 |
//! | `joinir_flags` | `NYASH_JOINIR_*` | JoinIR 設定 |
//! | `mir_flags` | `NYASH_MIR_*` | MIR 設定 |
//! | `vm_backend_flags` | `NYASH_VM_*` | VM / Backend 設定 |
//! | `parser_flags` | `NYASH_PARSER_*` | Parser 設定 |
//! | `using_flags` | `NYASH_USING_*` | Using / Namespace 設定 |
//! | `verification_flags` | `NYASH_VERIFY_*` | Verification 設定 |
//! | `selfhost_flags` | `NYASH_NY_COMPILER_*` | Selfhost compiler 設定 |
//!
//! ## 新規環境変数追加の手順
//!
//! 1. **モジュール選択**: 上記のモジュールから適切なものを選択。
//! 2. **関数定義**: 選択したモジュールに `fn env_var_name() -> type` 形式で関数を定義。
//! 3. **再export**: `src/config/env.rs` で `pub use module::*;` を確認(既に集約済み)。
//! 4. **ドキュメント追記**: `docs/reference/environment-variables.md` に必ず追記してください。
//!
//! ## 直読み禁止のチェック
//!
//! 置換漏れを確認するには、以下のコマンドを使用してください:
//!
//! ```bash
//! # std::env::var() の直接呼び出しを検索src/config/env/ 以外は禁止)
//! rg -n "std::env::(var|set_var|remove_var)\(" src | rg -v "src/config/env/"
//!
//! # NYASH_* 環境変数の直読みを検索src/config/env/ 以外は禁止)
//! rg -n "NYASH_(MACRO|BOX_FACTORY|DISABLE_PLUGINS)" src | rg -v "src/config/env/"
//! ```
//!
//! ## 再export ポリシー
//!
//! 全ての環境変数関数は `src/config/env.rs` で再exportされています
//!
//! ```rust
//! // Backward-compatible re-exports (NO BREAKING CHANGES!)
//! pub use box_factory_flags::*;
//! pub use joinir_flags::*;
//! pub use macro_flags::*;
//! pub use mir_flags::*;
//! pub use parser_flags::*;
//! pub use selfhost_flags::*;
//! pub use using_flags::*;
//! pub use verification_flags::*;
//! pub use vm_backend_flags::*;
//! ```
//!
//! 使用時は `crate::config::env::function_name()` でアクセスしてください。
//!
//! ## 参照
//!
//! - SSOT ドキュメント: `docs/reference/environment-variables.md`
//! - AGENTS.md 5.3: 環境変数スパロー防止ポリシー
//!
//! # Modular Organization
//!
//! Environment flags are now organized into focused Box modules:

View File

@ -216,3 +216,23 @@ pub fn test_return() -> Option<String> {
pub fn macro_syntax_sugar_level() -> Option<String> {
std::env::var("NYASH_SYNTAX_SUGAR_LEVEL").ok()
}
/// NYASH_MACRO_CAP_IO (capability: IO allowed)
pub fn macro_cap_io() -> Option<bool> {
std::env::var("NYASH_MACRO_CAP_IO")
.ok()
.map(|v| {
let lv = v.to_ascii_lowercase();
lv == "1" || lv == "true" || lv == "on"
})
}
/// NYASH_MACRO_CAP_NET (capability: NET allowed)
pub fn macro_cap_net() -> Option<bool> {
std::env::var("NYASH_MACRO_CAP_NET")
.ok()
.map(|v| {
let lv = v.to_ascii_lowercase();
lv == "1" || lv == "true" || lv == "on"
})
}