docs(joinir): Phase 43/245B Normalized JoinIR completion summary
Complete documentation consolidation for Phases 26-45 Normalized JoinIR
infrastructure. All components are implemented and tested (937/937 PASS).
Key additions:
- PHASE_43_245B_NORMALIZED_COMPLETION.md: Master completion summary
- Architecture components (Mode, Capability, Carriers, DigitPos, etc.)
- Supported loop patterns (P1, P2 variants including JsonParser)
- Complete file reference guide
- Test coverage documentation
- Future expansion roadmap
Updates:
- CURRENT_TASK.md: Moved Phase 43/245B to completed section
- joinir-architecture-overview.md: Phases 43-45 marked complete
- Historical docs: Added completion banners with links
- phase223-loopbodylocal-condition-design.md
- phase223-loopbodylocal-condition-inventory.md
- PHASE_223_SUMMARY.md
- phase245b-num_str-carrier-design.md
- phase245c-function-param-capture-summary.md
Documentation hierarchy established:
- Master summary → individual design docs
- Historical docs → completion summary
- Cross-references complete across all docs
Status: Phase 43/245B Normalized infrastructure COMPLETE ✅
This commit is contained in:
@ -6,9 +6,29 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🎯 今フォーカスしているテーマ(2025-12-10 時点のスナップショット)
|
## 🎯 今フォーカスしているテーマ(2025-12-12 時点のスナップショット)
|
||||||
|
|
||||||
### 0. JoinIR / ExprLowerer / Pattern2–4 + JsonParser `_parse_number` / DigitPos ライン(Phase 230–247-EX 完了)✅
|
### 0. ✅ Phase 43/245B Normalized JoinIR Infrastructure COMPLETE (Phase 26-45)
|
||||||
|
|
||||||
|
**完全サマリ**: [PHASE_43_245B_NORMALIZED_COMPLETION.md](docs/development/current/main/PHASE_43_245B_NORMALIZED_COMPLETION.md)
|
||||||
|
|
||||||
|
- **達成内容**:
|
||||||
|
- Structured→Normalized→MIR(direct) パイプライン確立
|
||||||
|
- P1/P2 + JsonParser (skip_ws/atoi/parse_number) 全対応
|
||||||
|
- Mode system (Phase 45), Capability system (Phase 44) 完成
|
||||||
|
- 937/937 tests PASS
|
||||||
|
- **主要コンポーネント**:
|
||||||
|
- JoinIrMode enum (StructuredOnly/NormalizedDev/NormalizedCanonical)
|
||||||
|
- ShapeCapabilityKind (P2CoreSimple/P2CoreSkipWs/P2CoreAtoi/P2MidParseNumber)
|
||||||
|
- CarrierRole (LoopState/ConditionOnly), CarrierInit
|
||||||
|
- DigitPos dual-value (is_digit_pos + digit_value)
|
||||||
|
- NumberAccumulation, Step scheduling, Exit PHI & Jump args
|
||||||
|
- **今後の拡張候補**(計画のみ):
|
||||||
|
- Phase 46+: Canonical set 拡張 (capability-based)
|
||||||
|
- Pattern3/4 Normalized 適用
|
||||||
|
- Selfhost loops 対応
|
||||||
|
|
||||||
|
### 0-B. JoinIR / ExprLowerer / Pattern2–4 + JsonParser `_parse_number` / DigitPos ライン(Phase 230–247-EX 完了)✅
|
||||||
|
|
||||||
- Pattern1–4(while / break / if‑PHI / continue)+ P5(Trim) でループ lowering を JoinIR 経路に一本化。
|
- Pattern1–4(while / break / if‑PHI / continue)+ P5(Trim) でループ lowering を JoinIR 経路に一本化。
|
||||||
- Phase 231/236/240-EX:
|
- Phase 231/236/240-EX:
|
||||||
@ -74,13 +94,11 @@
|
|||||||
|
|
||||||
### 1. いまコード側で意識しておきたいフォーカス
|
### 1. いまコード側で意識しておきたいフォーカス
|
||||||
|
|
||||||
- JoinIR ループ基盤(Pattern1–4 + ExprLowerer + ScopeManager + CapturedEnv)は一応の完成状態に入ったので、当面は:
|
- **Phase 43/245B Normalized 完了** により JoinIR ループ基盤(Pattern1–4 + ExprLowerer + ScopeManager + CapturedEnv + Normalized layer)は一応の完成状態に入ったので、当面は:
|
||||||
- 既存パターン/箱の範囲内での **バグ修正・Fail‑Fast/invariant 追加・テスト強化** を優先する。
|
- 既存パターン/箱の範囲内での **バグ修正・Fail‑Fast/invariant 追加・テスト強化** を優先する。
|
||||||
- JsonParser/selfhost への新しい適用や大きな仕様拡張は、docs 側で Phase 設計が固まってからコード側に持ち込む。
|
- JsonParser/selfhost への新しい適用や大きな仕様拡張は、docs 側で Phase 設計が固まってからコード側に持ち込む。
|
||||||
- 直近のコード側フォーカス候補:
|
- 直近のコード側フォーカス候補:
|
||||||
- Phase 246-EX(コード): JsonParser `_atoi` のループを Pattern2 + NumberAccumulation + DigitPos 二重値インフラ上に載せる。
|
- ~~Phase 246-EX(コード)~~: ✅ 完了(_atoi Integration, Phase 43/245B の一部)
|
||||||
- header/break 条件を ExprLowerer/ConditionEnv/FunctionScopeCapture 経由で JoinIR に lower。
|
|
||||||
- `result = result * 10 + digit_pos` を NumberAccumulation + `digit_value` carrier で扱い、従来の意味論を E2E テストで固定する。
|
|
||||||
- Pattern1–4 / ExprLowerer / ScopeManager まわりで、by-name ハードコードやサイレントフォールバックが見つかった場合は、
|
- Pattern1–4 / ExprLowerer / ScopeManager まわりで、by-name ハードコードやサイレントフォールバックが見つかった場合は、
|
||||||
CarrierInfo / ConditionEnv / Scope 情報を使って「構造で」直す。
|
CarrierInfo / ConditionEnv / Scope 情報を使って「構造で」直す。
|
||||||
|
|
||||||
@ -128,26 +146,31 @@
|
|||||||
|
|
||||||
このあたりが「JoinIR ループ基盤の芯」で、以降の Phase は JsonParser/selfhost の各ループへの適用フェーズ、という位置づけだよ。
|
このあたりが「JoinIR ループ基盤の芯」で、以降の Phase は JsonParser/selfhost の各ループへの適用フェーズ、という位置づけだよ。
|
||||||
|
|
||||||
|
- **Phase 43/245B Normalized JoinIR(Phase 26–45 完了)** ✅
|
||||||
|
- Structured→Normalized→MIR(direct) パイプライン確立
|
||||||
|
- Mode system (JoinIrMode) + Capability system (ShapeCapabilityKind)
|
||||||
|
- Pattern1/2 + JsonParser (_skip_whitespace, _atoi, _parse_number) 全対応
|
||||||
|
- 詳細: [PHASE_43_245B_NORMALIZED_COMPLETION.md](docs/development/current/main/PHASE_43_245B_NORMALIZED_COMPLETION.md)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🧭 これからの候補(まだ「やる」とは決めていないメモ)
|
## 🧭 これからの候補(まだ「やる」とは決めていないメモ)
|
||||||
|
|
||||||
ここは「やることリスト」ではなく「今後やるとしたらこの辺」というメモだよ。
|
ここは「やることリスト」ではなく「今後やるとしたらこの辺」というメモだよ。
|
||||||
実際に着手するタイミングで、別途 Phase/タスクを切る想定。
|
実際に着手するタイミングで、別途 Phase/タスクを切る想定。
|
||||||
|
|
||||||
1. Phase 245B(コード): JsonParser `_parse_number` の `num_str` を LoopState carrier として Pattern2/P5 ラインに統合
|
1. ~~Phase 245B(コード)~~: ✅ 完了(Phase 43/245B の一部)
|
||||||
- UpdateExpr で `num_str = num_str + ch` 1 形だけを許可し、StringAppend 経路で JoinIR に落とす。
|
2. ~~Phase 246-EX(コード)~~: ✅ 完了(Phase 43/245B の一部)
|
||||||
- ExitMeta/JoinIR/E2E テストで num_str/p/戻り値の意味論を従来どおり固定する。
|
3. **Phase 46+**: Canonical set 拡張(capability-based filtering)
|
||||||
2. Phase 246-EX(コード): JsonParser `_atoi` を Pattern2 + NumberAccumulation ラインに統合
|
- 現在の canonical set を段階的に拡張
|
||||||
- `_atoi` のループを Pattern2 detect → Pattern2 lowerer に接続し、DigitPos 二重値 + NumberAccumulation で数値更新を扱う。
|
- ShapeCapability インフラを活用
|
||||||
- JsonParser の `_atoi` 呼び出しテスト(既存 or 追加)で、JoinIR 経路でも従来どおりのパース結果になることを固定する。
|
4. JsonParser 残りループへの JoinIR 展開
|
||||||
3. JsonParser 残りループへの JoinIR 展開
|
|
||||||
- `_parse_array` / `_parse_object` / `_unescape_string` / 本体 `_parse_string` など。
|
- `_parse_array` / `_parse_object` / `_unescape_string` / 本体 `_parse_string` など。
|
||||||
- 既存の P2/P3/P4+P5 パイプラインをどこまで延ばせるかを docs 側で設計 → コード側はその設計に沿って小さく実装。
|
- 既存の P2/P3/P4+P5 パイプラインをどこまで延ばせるかを docs 側で設計 → コード側はその設計に沿って小さく実装。
|
||||||
4. selfhost depth‑2 ラインの再開
|
5. selfhost depth‑2 ラインの再開
|
||||||
- `.hako` 側で Program/MIR JSON を読んで JoinIR/MIR/VM/LLVM に流すライン。
|
- `.hako` 側で Program/MIR JSON を読んで JoinIR/MIR/VM/LLVM に流すライン。
|
||||||
- JsonParser 側のカバレッジが上がったあとに、小さいループから順に移植する。
|
- JsonParser 側のカバレッジが上がったあとに、小さいループから順に移植する。
|
||||||
5. JoinIR Verify / 最適化まわり
|
6. JoinIR Verify / 最適化まわり
|
||||||
- すでに PHI/ValueId 契約は debug ビルドで検証しているので、
|
- すでに PHI/ValueId 契約は debug ビルドで検証しているので、
|
||||||
必要なら SSA‑DFA や軽い最適化(Loop invariant / Strength reduction)を検討。
|
必要なら SSA‑DFA や軽い最適化(Loop invariant / Strength reduction)を検討。
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
# Phase 223: LoopBodyLocal Condition Promotion - Summary
|
# Phase 223: LoopBodyLocal Condition Promotion - Summary
|
||||||
|
|
||||||
|
---
|
||||||
|
**Phase 26-45 Completion**: このフェーズで設計した機能は Phase 43/245B で実装完了。最終状態は [PHASE_43_245B_NORMALIZED_COMPLETION.md](./PHASE_43_245B_NORMALIZED_COMPLETION.md) を参照。
|
||||||
|
---
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
Phase 223 addresses the "LoopBodyLocal in condition" constraint that blocks JsonParser loops (discovered in Phase 221). This phase enables Pattern2/Pattern4 to handle loops where loop-body-local variables appear in break/continue conditions.
|
Phase 223 addresses the "LoopBodyLocal in condition" constraint that blocks JsonParser loops (discovered in Phase 221). This phase enables Pattern2/Pattern4 to handle loops where loop-body-local variables appear in break/continue conditions.
|
||||||
|
|||||||
@ -0,0 +1,326 @@
|
|||||||
|
# Phase 43/245B: Normalized JoinIR Completion Summary
|
||||||
|
|
||||||
|
**Status**: ✅ COMPLETE (Phases 26-45)
|
||||||
|
**Date**: 2025-12-12
|
||||||
|
**Test Coverage**: 937/937 PASS
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
The Normalized JoinIR infrastructure is **complete**. All Pattern1/Pattern2 loops plus JsonParser real-world loops (_skip_whitespace, _atoi, _parse_number) flow through:
|
||||||
|
|
||||||
|
1. **Structured JoinIR** (AST → JoinIR lowering)
|
||||||
|
2. **Normalized JoinIR** (Optional normalization layer)
|
||||||
|
3. **MIR** (via direct generation or legacy bridge)
|
||||||
|
4. **VM** (execution)
|
||||||
|
|
||||||
|
Both **canonical** (always Normalized→MIR direct) and **dev** (feature-gated Normalized dev) paths are verified.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Architecture Components
|
||||||
|
|
||||||
|
### 1. JoinIR Mode System (Phase 45)
|
||||||
|
|
||||||
|
**`JoinIrMode` enum** (in `src/config/env/joinir_dev.rs`):
|
||||||
|
- `StructuredOnly` - Legacy path only
|
||||||
|
- `NormalizedDev` - Normalized dev (feature-gated)
|
||||||
|
- `NormalizedCanonical` - Always Normalized→MIR(direct) for P2-Core
|
||||||
|
|
||||||
|
**Routing**:
|
||||||
|
```rust
|
||||||
|
fn current_joinir_mode() -> JoinIrMode {
|
||||||
|
if cfg!(feature = "normalized_dev") {
|
||||||
|
NormalizedDev
|
||||||
|
} else {
|
||||||
|
StructuredOnly
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Bridge routing** (canonical-first):
|
||||||
|
- P2-Core canonical shapes → **always** Normalized→MIR(direct) (mode ignored)
|
||||||
|
- Other shapes → follow `current_joinir_mode()`
|
||||||
|
|
||||||
|
### 2. Shape Capability System (Phase 44)
|
||||||
|
|
||||||
|
**`ShapeCapabilityKind` enum** (in `src/mir/join_ir/normalized/shape_guard.rs`):
|
||||||
|
- `P2CoreSimple` - Pattern1Mini, Pattern2Mini
|
||||||
|
- `P2CoreSkipWs` - skip_whitespace mini/real
|
||||||
|
- `P2CoreAtoi` - _atoi mini/real
|
||||||
|
- `P2MidParseNumber` - _parse_number real
|
||||||
|
|
||||||
|
**API**:
|
||||||
|
- `capability_for_shape(shape)` - Map shape to capability
|
||||||
|
- `is_canonical_shape(shape)` - Exact shape-level check
|
||||||
|
- `is_p2_core_capability(cap)` - Broad capability family check
|
||||||
|
- `is_supported_by_normalized(cap)` - Normalized dev support
|
||||||
|
|
||||||
|
**Canonical Set** (Phase 41):
|
||||||
|
- Pattern2Mini
|
||||||
|
- JsonparserSkipWsMini
|
||||||
|
- JsonparserSkipWsReal
|
||||||
|
- JsonparserAtoiMini
|
||||||
|
|
||||||
|
### 3. Carrier Infrastructure
|
||||||
|
|
||||||
|
**CarrierRole enum** (Phase 227):
|
||||||
|
- `LoopState` - Accumulator variables (sum, result) - exit PHI needed
|
||||||
|
- `ConditionOnly` - Boolean flags (is_digit_pos) - header PHI only, no exit PHI
|
||||||
|
|
||||||
|
**CarrierInit enum** (Phase 228):
|
||||||
|
- `DefaultZero` - Initialize to 0/false
|
||||||
|
- `ExplicitValue(ValueId)` - Explicit initial value
|
||||||
|
|
||||||
|
**Key components**:
|
||||||
|
- `CarrierInfo` - Tracks promoted variables with role/init
|
||||||
|
- `ConditionPromotionRequest` - Request structure for promotion
|
||||||
|
- `LoopBodyCondPromoter` - Two-tier orchestrator (A-3 Trim → A-4 DigitPos)
|
||||||
|
|
||||||
|
### 4. DigitPos Dual-Value (Phase 247-EX)
|
||||||
|
|
||||||
|
**Pattern**: One `indexOf()` → two carriers:
|
||||||
|
- `is_digit_pos: bool` (ConditionOnly) - for condition: `!is_digit_pos` (break)
|
||||||
|
- `digit_value: int` (LoopState) - for update: `result = result * 10 + digit_value`
|
||||||
|
|
||||||
|
**Components**:
|
||||||
|
- `DigitPosPromoter` - Detects indexOf pattern, generates dual carriers
|
||||||
|
- `DigitPosConditionNormalizer` - AST transform: `digit_pos < 0` → `!is_digit_pos`
|
||||||
|
- `UpdateEnv` - Context-aware resolution (promoted variables vs bool aliases)
|
||||||
|
|
||||||
|
### 5. NumberAccumulation (Phase 190)
|
||||||
|
|
||||||
|
**Pattern**: `result = result * base + digit`
|
||||||
|
|
||||||
|
**Detection**: Handles nested BinaryOp perfectly (no extensions needed for Phase 246-EX):
|
||||||
|
```rust
|
||||||
|
pub enum UpdateExpr {
|
||||||
|
BinOp { op, lhs, rhs },
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum NumberAccumulation {
|
||||||
|
Base10 { digit_var: String },
|
||||||
|
BaseN { base: i64, digit_var: String },
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6. Step Scheduling (Phase 246-EX Part 2)
|
||||||
|
|
||||||
|
**Purpose**: Control evaluation order in Pattern2 loops to avoid "undefined variable" errors.
|
||||||
|
|
||||||
|
**Key insight**: Body-local initialization must occur BEFORE break condition check.
|
||||||
|
|
||||||
|
**Components** (extracted to `pattern2_step_schedule.rs`):
|
||||||
|
- `StepScheduleBox` - Determines step order (init → check → update)
|
||||||
|
- `emit_steps()` - Generates JoinIR in correct order
|
||||||
|
|
||||||
|
**Example**:
|
||||||
|
```
|
||||||
|
// Correct order:
|
||||||
|
1. Init ch (body-local)
|
||||||
|
2. Check break condition (uses ch)
|
||||||
|
3. Update loop state
|
||||||
|
```
|
||||||
|
|
||||||
|
### 7. Exit PHI & Jump Args (Phase 246-EX Part 2)
|
||||||
|
|
||||||
|
**Problem**: Exit PHI connections used wrong ValueIds (header PHI dst instead of exit PHI dst).
|
||||||
|
|
||||||
|
**Solution**:
|
||||||
|
1. Added `jump_args: Option<Vec<ValueId>>` to `BasicBlock` struct
|
||||||
|
2. `joinir_block_converter.rs` stores args during Jump instruction handling
|
||||||
|
3. `instruction_rewriter.rs` reads `jump_args`, remaps carriers correctly
|
||||||
|
|
||||||
|
**Files modified**:
|
||||||
|
- `src/mir/basic_block.rs`
|
||||||
|
- `src/mir/join_ir_vm_bridge/joinir_block_converter.rs`
|
||||||
|
- `src/mir/builder/control_flow/joinir/merge/instruction_rewriter.rs`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Supported Loop Patterns
|
||||||
|
|
||||||
|
### Pattern1: Simple While (P1-Core)
|
||||||
|
|
||||||
|
**Example**: `loop_min_while.hako`
|
||||||
|
```
|
||||||
|
loop(i < n) {
|
||||||
|
i = i + 1
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Status**: ✅ Normalized→MIR(direct) working
|
||||||
|
|
||||||
|
### Pattern2: Break (P2-Core/Mid)
|
||||||
|
|
||||||
|
#### P2-Core Simple
|
||||||
|
**Example**: `phase2_break_minimal.hako`
|
||||||
|
```
|
||||||
|
loop(i < n) {
|
||||||
|
if (break_condition) { break }
|
||||||
|
acc = acc + 1
|
||||||
|
i = i + 1
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### P2-Core skip_whitespace
|
||||||
|
**Example**: JsonParser `_skip_whitespace`
|
||||||
|
```
|
||||||
|
loop(p < s.length()) {
|
||||||
|
local ch = s.substring(p, p+1)
|
||||||
|
if (ch != " " && ch != "\t" && ch != "\n") { break }
|
||||||
|
p = p + 1
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Carriers**: `is_ch_match: bool` (Trim pattern, ConditionOnly)
|
||||||
|
|
||||||
|
#### P2-Core _atoi
|
||||||
|
**Example**: JsonParser `_atoi`
|
||||||
|
```
|
||||||
|
loop(p < s.length()) {
|
||||||
|
local ch = s.substring(p, p+1)
|
||||||
|
local digit_pos = "0123456789".indexOf(ch)
|
||||||
|
if (digit_pos < 0) { break }
|
||||||
|
result = result * 10 + digit_pos
|
||||||
|
p = p + 1
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Carriers**:
|
||||||
|
- `is_digit_pos: bool` (ConditionOnly) - from `indexOf(ch) < 0`
|
||||||
|
- `digit_value: int` (LoopState) - from same `indexOf(ch)`
|
||||||
|
|
||||||
|
**Features**: DigitPos dual-value, NumberAccumulation (base 10)
|
||||||
|
|
||||||
|
#### P2-Mid _parse_number
|
||||||
|
**Example**: JsonParser `_parse_number`
|
||||||
|
```
|
||||||
|
loop(p < s.length()) {
|
||||||
|
local ch = s.substring(p, p+1)
|
||||||
|
local digit_pos = "0123456789".indexOf(ch)
|
||||||
|
if (digit_pos < 0) { break }
|
||||||
|
num_str = num_str + ch
|
||||||
|
result = result * 10 + digit_pos
|
||||||
|
p = p + 1
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Carriers**:
|
||||||
|
- `is_digit_pos: bool` (ConditionOnly)
|
||||||
|
- `digit_value: int` (LoopState)
|
||||||
|
- `num_str: StringBox` (LoopState) - String accumulation
|
||||||
|
|
||||||
|
**Status**: ✅ All working, Normalized→MIR(direct) verified
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Key Implementation Files
|
||||||
|
|
||||||
|
### JoinIR Frontend
|
||||||
|
- `src/mir/join_ir/lowering/loop_with_break_minimal.rs` - Pattern2 JoinIR generation
|
||||||
|
- `src/mir/join_ir/lowering/pattern2_step_schedule.rs` - Step scheduling (extracted Phase 246-EX)
|
||||||
|
- `src/mir/join_ir/lowering/carrier_info.rs` - CarrierRole/CarrierInit enums
|
||||||
|
- `src/mir/join_ir/lowering/digitpos_condition_normalizer.rs` - AST transform
|
||||||
|
- `src/mir/join_ir/lowering/update_env.rs` - Context-aware variable resolution
|
||||||
|
|
||||||
|
### Pattern Detection
|
||||||
|
- `src/mir/loop_pattern_detection/loop_body_cond_promoter.rs` - Two-tier orchestrator
|
||||||
|
- `src/mir/loop_pattern_detection/loop_body_digitpos_promoter.rs` - DigitPos pattern
|
||||||
|
- `src/mir/loop_pattern_detection/loop_update_analyzer.rs` - NumberAccumulation detection
|
||||||
|
|
||||||
|
### Normalized Infrastructure
|
||||||
|
- `src/mir/join_ir/normalized.rs` - Core normalized types
|
||||||
|
- `src/mir/join_ir/normalized/shape_guard.rs` - Shape + Capability system
|
||||||
|
- `src/mir/join_ir/normalized/dev_env.rs` - Dev environment
|
||||||
|
- `src/mir/join_ir/normalized/fixtures.rs` - Test fixtures
|
||||||
|
- `src/mir/join_ir_vm_bridge/normalized_bridge.rs` - Bridge
|
||||||
|
- `src/mir/join_ir_vm_bridge/normalized_bridge/direct.rs` - Direct MIR generation
|
||||||
|
|
||||||
|
### Mode & Config
|
||||||
|
- `src/config/env/joinir_dev.rs` - JoinIrMode enum, current_joinir_mode()
|
||||||
|
- `src/mir/join_ir_vm_bridge/bridge.rs` - Canonical-first routing
|
||||||
|
- `src/mir/join_ir_runner.rs` - Mode pattern matching
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Test Coverage
|
||||||
|
|
||||||
|
**Total**: 937/937 PASS
|
||||||
|
|
||||||
|
**Key test groups**:
|
||||||
|
- Pattern1/2 mini tests
|
||||||
|
- JsonParser smoke tests (skip_ws, atoi, parse_number)
|
||||||
|
- DigitPos dual-value tests (11 tests)
|
||||||
|
- Promoted variable resolution tests (3 tests)
|
||||||
|
- Normalized dev integration tests (+6 from baseline)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Completed Phases
|
||||||
|
|
||||||
|
### Phase 26-42: Foundation
|
||||||
|
- Pattern1/2 infrastructure
|
||||||
|
- JoinIR → MIR bridge
|
||||||
|
- Carrier system basics
|
||||||
|
- ExitLine/Boundary architecture
|
||||||
|
|
||||||
|
### Phase 43: Normalized Pipeline
|
||||||
|
- Structured→Normalized→MIR(direct) pipeline
|
||||||
|
- JsonParser _parse_number fixture
|
||||||
|
- dev_env.rs, fixtures.rs created
|
||||||
|
|
||||||
|
### Phase 44: Shape Capabilities
|
||||||
|
- ShapeCapabilityKind enum (4 kinds)
|
||||||
|
- Capability-based filtering
|
||||||
|
- Extensible architecture
|
||||||
|
|
||||||
|
### Phase 45: Mode Unification
|
||||||
|
- JoinIrMode enum (3 modes)
|
||||||
|
- current_joinir_mode() centralized
|
||||||
|
- Canonical-first routing
|
||||||
|
|
||||||
|
### Phase 190: NumberAccumulation
|
||||||
|
- Detects `result = result * base + digit` patterns
|
||||||
|
- Handles nested BinaryOp
|
||||||
|
|
||||||
|
### Phase 227: CarrierRole
|
||||||
|
- LoopState vs ConditionOnly separation
|
||||||
|
- Exit PHI skips ConditionOnly
|
||||||
|
|
||||||
|
### Phase 228: CarrierInit
|
||||||
|
- Explicit initialization values
|
||||||
|
- Header PHI bool constant allocation
|
||||||
|
|
||||||
|
### Phase 246-EX: _atoi Integration
|
||||||
|
- FromHost carrier fixes (4-fix sequence)
|
||||||
|
- Exit PHI connection fixes
|
||||||
|
- Jump args preservation
|
||||||
|
- Step scheduling extraction
|
||||||
|
|
||||||
|
### Phase 247-EX: DigitPos Dual-Value
|
||||||
|
- One indexOf() → two carriers
|
||||||
|
- Context-aware resolution (UpdateEnv)
|
||||||
|
- AST normalization (ConditionNormalizer)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Future Expansion
|
||||||
|
|
||||||
|
The infrastructure is ready for:
|
||||||
|
|
||||||
|
1. **Phase 46+**: Expand canonical set using capability-based filtering
|
||||||
|
2. **Carrier role analysis**: Enable `carrier_roles` field for automatic detection
|
||||||
|
3. **Method signature tracking**: Enable `method_calls` field for Box API requirements
|
||||||
|
4. **Pattern3/4 Normalized**: Apply infrastructure to if-sum/continue patterns
|
||||||
|
5. **Selfhost loops**: Complex loops from selfhost compiler
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- **Architecture**: `docs/development/current/main/joinir-architecture-overview.md`
|
||||||
|
- **Phase 44 Capabilities**: `docs/development/current/main/phase44-shape-capabilities-design.md`
|
||||||
|
- **Phase 45 Mode**: `docs/development/current/main/phase45-norm-mode-design.md`
|
||||||
|
- **Phase 247-EX DigitPos**: `docs/development/current/main/phase247-digitpos-dual-value-design.md`
|
||||||
|
- **Phase 246-EX _atoi**: `docs/development/current/main/phase246-jsonparser-atoi-joinir-integration.md`
|
||||||
@ -1285,23 +1285,33 @@ Normalized JoinIR を 1 段挟むと、開発の手触りがどう変わるか
|
|||||||
- P2-Core については Phase 41 で canonical Normalized 化が完了しており、Structured→MIR は比較テスト用 / フォールバック用の経路として扱う。
|
- P2-Core については Phase 41 で canonical Normalized 化が完了しており、Structured→MIR は比較テスト用 / フォールバック用の経路として扱う。
|
||||||
- P2-Mid のうち、Phase 43 ではまず `_parse_number` を第 1 候補、`_atoi` 本体を第 2 候補として扱い、Normalized→MIR(direct) に必要な追加インフラ(EnvLayout 拡張 / JpInst パターン拡張)を段階的に入れていく前提を整理した。
|
- P2-Mid のうち、Phase 43 ではまず `_parse_number` を第 1 候補、`_atoi` 本体を第 2 候補として扱い、Normalized→MIR(direct) に必要な追加インフラ(EnvLayout 拡張 / JpInst パターン拡張)を段階的に入れていく前提を整理した。
|
||||||
|
|
||||||
### 3.20 Phase 43-NORM-CANON-P2-MID – JsonParser 本命 P2(_parse_number/_atoi)への適用
|
### 3.20 Phase 43-NORM-CANON-P2-MID – JsonParser 本命 P2(_parse_number/_atoi)への適用 ✅ COMPLETE
|
||||||
|
|
||||||
|
**完全サマリ**: [PHASE_43_245B_NORMALIZED_COMPLETION.md](./PHASE_43_245B_NORMALIZED_COMPLETION.md)
|
||||||
|
|
||||||
- JsonParser `_parse_number` / `_atoi` 本体の Pattern2 ループを、既存インフラ(DigitPos dual 値, LoopLocalZero, StepScheduleBox, ExprLowerer/MethodCall, Normalized ブリッジ)上で Structured→Normalized→MIR(direct) に載せる。
|
- JsonParser `_parse_number` / `_atoi` 本体の Pattern2 ループを、既存インフラ(DigitPos dual 値, LoopLocalZero, StepScheduleBox, ExprLowerer/MethodCall, Normalized ブリッジ)上で Structured→Normalized→MIR(direct) に載せる。
|
||||||
- dev で Structured 直経路との VM 実行結果一致を固定した上で、段階的に「この関数だけ Normalized canonical」とみなすプロファイル/フラグを導入し、最終的に JsonParser P2 の canonical route を Normalized 側に寄せるための足場にする。
|
- dev で Structured 直経路との VM 実行結果一致を固定した上で、段階的に「この関数だけ Normalized canonical」とみなすプロファイル/フラグを導入し、最終的に JsonParser P2 の canonical route を Normalized 側に寄せるための足場にする。
|
||||||
- Phase 43-A(dev 専用): `_atoi` 本体を Program(JSON) フィクスチャ `jsonparser_atoi_real` で Structured→Normalized→MIR(direct) に通し、Structured 直経路との VM 出力一致を比較テストで固定(符号あり/なしの簡易パスまで対応。canonical 化は後続フェーズで検討)。
|
- Phase 43-A(dev 専用): `_atoi` 本体を Program(JSON) フィクスチャ `jsonparser_atoi_real` で Structured→Normalized→MIR(direct) に通し、Structured 直経路との VM 出力一致を比較テストで固定(符号あり/なしの簡易パスまで対応。canonical 化は後続フェーズで検討)。
|
||||||
- Phase 43-C(dev 専用): `_parse_number` 本体を Program(JSON) フィクスチャ `jsonparser_parse_number_real` で Structured→Normalized→MIR(direct) に通し、`num_str = num_str + ch` の LoopState キャリアを含めた状態で Structured 直経路との VM 出力一致を比較テストで固定。
|
- Phase 43-C(dev 専用): `_parse_number` 本体を Program(JSON) フィクスチャ `jsonparser_parse_number_real` で Structured→Normalized→MIR(direct) に通し、`num_str = num_str + ch` の LoopState キャリアを含めた状態で Structured 直経路との VM 出力一致を比較テストで固定。
|
||||||
|
|
||||||
### 3.21 Phase 44-SHAPE-CAP – shape_guard の能力ベース化(計画)
|
### 3.21 Phase 44-SHAPE-CAP – shape_guard の能力ベース化 ✅ COMPLETE (2025-12-12)
|
||||||
|
|
||||||
- 現状の shape_guard は `JsonparserSkipWsMini/Real`, `JsonparserAtoiMini/Real` など「関数名ベースの個別 shape」が増えつつあるため、将来的には:
|
**完全サマリ**: [PHASE_43_245B_NORMALIZED_COMPLETION.md](./PHASE_43_245B_NORMALIZED_COMPLETION.md)
|
||||||
- 「P2 / LoopParam1 / Carrier≤N / MethodCall パターン = このセット」のような **能力ベースの ShapeCapability テーブル** に寄せる。
|
**設計詳細**: [phase44-shape-capabilities-design.md](./phase44-shape-capabilities-design.md)
|
||||||
- JsonParser/selfhost の各ループは「どの capability を満たしているか」を参照するだけにし、関数名ベタ書き依存を減らす。
|
|
||||||
- この Phase では docs 上で API/テーブル設計を固め、コード側では shape_guard の内部表現を Capability 中心に書き換える前段として扱う。
|
|
||||||
|
|
||||||
### 3.22 Phase 45-NORM-MODE – JoinIR モードの一本化(計画)
|
- ✅ **ShapeCapabilityKind 導入完了**: P2CoreSimple / P2CoreSkipWs / P2CoreAtoi / P2MidParseNumber の 4 種類
|
||||||
|
- ✅ **Capability-based API**: `capability_for_shape()`, `is_canonical_shape()`, `is_p2_core_capability()`, `is_supported_by_normalized()`
|
||||||
|
- ✅ **Shape-level と Capability-level の二層 API**: 正確なマッチング vs 広い能力ファミリ判定
|
||||||
|
- ✅ **拡張性確保**: 将来の carrier_roles, method_calls フィールド用の struct 設計
|
||||||
|
- ✅ **既存挙動完全保持**: 937/937 tests PASS
|
||||||
|
|
||||||
- 現状は `normalized_dev_enabled()`, `NYASH_JOINIR_NORMALIZED_DEV_RUN`, `JOINIR_TEST_DEBUG` など複数の env/feature でモードを切り替えているため、将来的には:
|
### 3.22 Phase 45-NORM-MODE – JoinIR モードの一本化 ✅ COMPLETE (2025-12-12)
|
||||||
- `JoinIrMode = { StructuredOnly, NormalizedDev, NormalizedCanonical }` のような enum を導入し、
|
|
||||||
- env/feature はこのモードの初期値を決めるだけに寄せる(コード側の `if`/分岐を減らす)。
|
**完全サマリ**: [PHASE_43_245B_NORMALIZED_COMPLETION.md](./PHASE_43_245B_NORMALIZED_COMPLETION.md)
|
||||||
- この Phase では JoinIR パイプラインの「モード遷移図」と `JoinIrMode` API を docs で設計し、後続フェーズで実装に反映する計画を置いておく。
|
**設計詳細**: [phase45-norm-mode-design.md](./phase45-norm-mode-design.md)
|
||||||
|
|
||||||
|
- ✅ **JoinIrMode enum 導入完了**: StructuredOnly / NormalizedDev / NormalizedCanonical
|
||||||
|
- ✅ **current_joinir_mode() 統一**: バラバラだったフラグ/feature を一箇所に集約
|
||||||
|
- ✅ **Canonical-first routing**: P2-Core canonical shapes は mode 無視で常に Normalized→MIR(direct)
|
||||||
|
- ✅ **Mode-based 分岐統一**: bridge/runner の pattern matching で一貫した挙動
|
||||||
|
- ✅ **既存挙動完全保持**: 937/937 tests PASS
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
# Phase 223-2: LoopBodyLocal Condition Promotion Design
|
# Phase 223-2: LoopBodyLocal Condition Promotion Design
|
||||||
|
|
||||||
|
---
|
||||||
|
**Phase 26-45 Completion**: このフェーズで設計した機能は Phase 43/245B で実装完了。最終状態は [PHASE_43_245B_NORMALIZED_COMPLETION.md](./PHASE_43_245B_NORMALIZED_COMPLETION.md) を参照。
|
||||||
|
---
|
||||||
|
|
||||||
## Purpose
|
## Purpose
|
||||||
|
|
||||||
This document defines the **API-level design** for promoting LoopBodyLocal variables used in loop conditions (header, break, continue) to bool carriers. This enables Pattern2/Pattern4 to handle loops like JsonParser's `_skip_whitespace` which currently Fail-Fast.
|
This document defines the **API-level design** for promoting LoopBodyLocal variables used in loop conditions (header, break, continue) to bool carriers. This enables Pattern2/Pattern4 to handle loops like JsonParser's `_skip_whitespace` which currently Fail-Fast.
|
||||||
|
|||||||
@ -1,6 +1,10 @@
|
|||||||
# Phase 223-1: LoopBodyLocal in Condition - Comprehensive Inventory
|
# Phase 223-1: LoopBodyLocal in Condition - Comprehensive Inventory
|
||||||
|
|
||||||
Status: Historical(Phase 26-H 以降の Normalized / DigitPos 導入で一部内容が古くなっています)
|
---
|
||||||
|
**Phase 26-45 Completion**: このフェーズで設計した機能は Phase 43/245B で実装完了。最終状態は [PHASE_43_245B_NORMALIZED_COMPLETION.md](./PHASE_43_245B_NORMALIZED_COMPLETION.md) を参照。
|
||||||
|
---
|
||||||
|
|
||||||
|
Status: Historical(Phase 26-H 以降の Normalized / DigitPos 導入で一部内容が古くなっています)
|
||||||
Note: LoopBodyLocal が原因で Fail-Fast していたループの在庫を Phase 223 時点で一覧化したメモだよ。DigitPos 系などの一部ループはその後の Phase 224/26-H/34 系で解消済みなので、最新の対応状況は `joinir-architecture-overview.md` と Phase 42 の P2 インベントリを合わせて参照してね。
|
Note: LoopBodyLocal が原因で Fail-Fast していたループの在庫を Phase 223 時点で一覧化したメモだよ。DigitPos 系などの一部ループはその後の Phase 224/26-H/34 系で解消済みなので、最新の対応状況は `joinir-architecture-overview.md` と Phase 42 の P2 インベントリを合わせて参照してね。
|
||||||
|
|
||||||
## Purpose
|
## Purpose
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
# Phase 245B: num_str Carrier Design Document
|
# Phase 245B: num_str Carrier Design Document
|
||||||
|
|
||||||
|
---
|
||||||
|
**Phase 26-45 Completion**: このフェーズで設計した機能は Phase 43/245B で実装完了。最終状態は [PHASE_43_245B_NORMALIZED_COMPLETION.md](./PHASE_43_245B_NORMALIZED_COMPLETION.md) を参照。
|
||||||
|
---
|
||||||
|
|
||||||
**Status**: Implemented (Phase 245B-IMPL)
|
**Status**: Implemented (Phase 245B-IMPL)
|
||||||
**Target**: `_parse_number` loop の `num_str` 文字列キャリア対応
|
**Target**: `_parse_number` loop の `num_str` 文字列キャリア対応
|
||||||
**Scope**: Pattern 2 (loop with break) + 既存インフラ活用
|
**Scope**: Pattern 2 (loop with break) + 既存インフラ活用
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
# Phase 245C: Function Parameter Capture - Implementation Summary
|
# Phase 245C: Function Parameter Capture - Implementation Summary
|
||||||
|
|
||||||
|
---
|
||||||
|
**Phase 26-45 Completion**: このフェーズで設計した機能は Phase 43/245B で実装完了。最終状態は [PHASE_43_245B_NORMALIZED_COMPLETION.md](./PHASE_43_245B_NORMALIZED_COMPLETION.md) を参照。
|
||||||
|
---
|
||||||
|
|
||||||
**Status**: ✅ COMPLETE
|
**Status**: ✅ COMPLETE
|
||||||
**Date**: 2025-12-11
|
**Date**: 2025-12-11
|
||||||
**Scope**: Extend CapturedEnv to include function parameters used in loop conditions/body
|
**Scope**: Extend CapturedEnv to include function parameters used in loop conditions/body
|
||||||
|
|||||||
Reference in New Issue
Block a user