2025-11-23 16:49:49 +09:00
|
|
|
|
//! JoinIR Lowering Functions
|
|
|
|
|
|
//!
|
|
|
|
|
|
//! Phase 27.9: Modular separation of MIR → JoinIR lowering implementations.
|
2025-12-07 03:26:06 +09:00
|
|
|
|
//! Phase 33-12: Router-based If/Loop lowering organization.
|
2025-11-23 16:49:49 +09:00
|
|
|
|
//!
|
|
|
|
|
|
//! このモジュールは各種 MIR 関数を JoinIR に変換する lowering 関数を提供します。
|
|
|
|
|
|
//!
|
|
|
|
|
|
//! ## 構成:
|
2025-11-23 22:51:30 +09:00
|
|
|
|
//! - `common.rs`: CFG sanity checks と lowering 共通ユーティリティ(Phase 27.10)
|
2025-11-24 03:58:30 +09:00
|
|
|
|
//! - `value_id_ranges.rs`: ValueId 範囲管理(Phase 27.13+)
|
2025-11-23 16:49:49 +09:00
|
|
|
|
//! - `min_loop.rs`: JoinIrMin.main/0 専用の最小ループ lowering
|
|
|
|
|
|
//! - `skip_ws.rs`: Main.skip/1 の空白スキップ lowering(手書き版+MIR自動解析版)
|
|
|
|
|
|
//! - `funcscanner_trim.rs`: FuncScannerBox.trim/1 の trim lowering
|
2025-11-24 02:34:36 +09:00
|
|
|
|
//! - `stage1_using_resolver.rs`: Stage1UsingResolverBox.resolve_for_source entries loop lowering(Phase 27.12)
|
2025-11-24 05:23:26 +09:00
|
|
|
|
//! - `funcscanner_append_defs.rs`: FuncScannerBox._append_defs/2 の配列結合 lowering(Phase 27.14)
|
2025-11-27 02:58:38 +09:00
|
|
|
|
//! - `if_select.rs`: Phase 33 If/Else → Select lowering
|
2025-11-27 17:05:46 +09:00
|
|
|
|
//! - `if_dry_runner.rs`: Phase 33-10 If lowering dry-run スキャナー(箱化版)
|
2025-12-07 01:45:03 +09:00
|
|
|
|
//! - `bool_expr_lowerer.rs`: Phase 168 Boolean expression lowering (AST → SSA)
|
2025-12-07 03:26:06 +09:00
|
|
|
|
//! - `if_lowering_router.rs`: Phase 33-12 If-expression routing (Select/IfMerge dispatcher)
|
|
|
|
|
|
//! - `loop_pattern_router.rs`: Phase 33-12 Loop pattern routing (Pattern 1-4 dispatcher)
|
2025-11-23 16:49:49 +09:00
|
|
|
|
|
refactor(joinir): Restrict visibility of internal lowering modules (Task 3)
Task 3: Unused public exports visibility restriction
- Changed 15 modules from 'pub mod' to 'pub(crate) mod'
- Modules changed: bool_expr_lowerer, carrier_update_emitter, common,
condition_lowerer, condition_var_extractor, exit_args_resolver,
generic_case_a, if_lowering_router, if_select, loop_form_intake,
loop_pattern_router, loop_pattern_validator, loop_patterns,
loop_view_builder, value_id_ranges
- All changed modules have 0 external uses outside src/mir/join_ir/lowering/
- Kept public re-exports for functions that need backward compatibility
- Build verified: cargo build --release passes with 0 errors
Result: Improved API encapsulation without breaking external users
2025-12-08 19:19:58 +09:00
|
|
|
|
pub(crate) mod bool_expr_lowerer; // Phase 168: Boolean expression lowering (unused - candidate for removal)
|
2025-12-06 02:05:19 +09:00
|
|
|
|
pub mod carrier_info; // Phase 196: Carrier metadata for loop lowering
|
refactor(joinir): Restrict visibility of internal lowering modules (Task 3)
Task 3: Unused public exports visibility restriction
- Changed 15 modules from 'pub mod' to 'pub(crate) mod'
- Modules changed: bool_expr_lowerer, carrier_update_emitter, common,
condition_lowerer, condition_var_extractor, exit_args_resolver,
generic_case_a, if_lowering_router, if_select, loop_form_intake,
loop_pattern_router, loop_pattern_validator, loop_patterns,
loop_view_builder, value_id_ranges
- All changed modules have 0 external uses outside src/mir/join_ir/lowering/
- Kept public re-exports for functions that need backward compatibility
- Build verified: cargo build --release passes with 0 errors
Result: Improved API encapsulation without breaking external users
2025-12-08 19:19:58 +09:00
|
|
|
|
pub(crate) mod carrier_update_emitter; // Phase 179: Carrier update instruction emission
|
|
|
|
|
|
pub(crate) mod common; // Internal lowering utilities
|
2025-12-09 04:20:28 +09:00
|
|
|
|
pub mod complex_addend_normalizer; // Phase 192: Complex addend normalization (AST preprocessing)
|
2025-12-08 00:30:17 +09:00
|
|
|
|
pub mod condition_env; // Phase 171-fix: Condition expression environment
|
feat(joinir): Phase 184 - Body-local MIR Lowering Infrastructure
Phase 184 implements the foundation for body-local variable support in
update expressions, completing the three-box architecture:
LoopBodyLocalEnv (storage), UpdateEnv (composition), and
CarrierUpdateEmitter (emission).
## Implementation Summary
### Task 184-1: Design Document
- Created phase184-body-local-mir-lowering.md
- Two-Environment System design (ConditionEnv + LoopBodyLocalEnv)
- Box-First design principles documented
### Task 184-2: LoopBodyLocalEnv Implementation
- New file: src/mir/join_ir/lowering/loop_body_local_env.rs (216 lines)
- Storage box for body-local variable name → ValueId mappings
- BTreeMap for deterministic ordering (PHI consistency)
- 7 unit tests: empty env, single/multiple locals, get/contains, iteration
### Task 184-3: UpdateEnv Implementation
- New file: src/mir/join_ir/lowering/update_env.rs (237 lines)
- Composition box for unified variable resolution
- Priority order: ConditionEnv (condition vars) → LoopBodyLocalEnv (body-local)
- 8 unit tests: priority, fallback, not found, combined lookup
### Task 184-4: CarrierUpdateEmitter Integration
- Modified: src/mir/join_ir/lowering/carrier_update_emitter.rs
- Added emit_carrier_update_with_env() (UpdateEnv version)
- Kept emit_carrier_update() for backward compatibility
- 4 new unit tests: body-local variable, priority, not found, const update
- Total 10 tests PASS (6 existing + 4 new)
### Task 184-5: Representative Test Cases
- apps/tests/phase184_body_local_update.hako (Pattern1 baseline)
- apps/tests/phase184_body_local_with_break.hako (Pattern2, Phase 185 target)
### Task 184-6: Documentation Updates
- Updated: docs/development/current/main/joinir-architecture-overview.md
- Updated: CURRENT_TASK.md (Phase 184 completion record)
## Test Results
All 25 unit tests PASS:
- LoopBodyLocalEnv: 7 tests
- UpdateEnv: 8 tests
- CarrierUpdateEmitter: 10 tests (6 existing + 4 new)
Build: ✅ Success (0 errors)
## Design Constraints
Following 箱理論 (Box Theory) principles:
- Single Responsibility: Each box has one clear purpose
- Deterministic: BTreeMap ensures consistent ordering
- Conservative: Pattern5 (Trim) integration deferred to Phase 185
- Fail-Fast: Explicit errors for unsupported patterns
## Scope Limitation
Phase 184 provides the **infrastructure only**:
- ✅ Storage box (LoopBodyLocalEnv)
- ✅ Composition box (UpdateEnv)
- ✅ Emission support (CarrierUpdateEmitter)
- ❌ Pattern2/4 integration (requires body-local collection, Phase 185)
## Next Steps
Phase 185: Pattern2/4 Integration
- Integrate LoopBodyLocalEnv into Pattern2/4 lowerers
- Add body-local variable collection from loop body AST
- Enable full E2E body-local variable support in update expressions
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-08 23:59:19 +09:00
|
|
|
|
pub mod loop_body_local_env; // Phase 184: Body-local variable environment
|
2025-12-09 00:59:38 +09:00
|
|
|
|
pub mod loop_body_local_init; // Phase 186: Body-local init expression lowering
|
refactor(joinir): Restrict visibility of internal lowering modules (Task 3)
Task 3: Unused public exports visibility restriction
- Changed 15 modules from 'pub mod' to 'pub(crate) mod'
- Modules changed: bool_expr_lowerer, carrier_update_emitter, common,
condition_lowerer, condition_var_extractor, exit_args_resolver,
generic_case_a, if_lowering_router, if_select, loop_form_intake,
loop_pattern_router, loop_pattern_validator, loop_patterns,
loop_view_builder, value_id_ranges
- All changed modules have 0 external uses outside src/mir/join_ir/lowering/
- Kept public re-exports for functions that need backward compatibility
- Build verified: cargo build --release passes with 0 errors
Result: Improved API encapsulation without breaking external users
2025-12-08 19:19:58 +09:00
|
|
|
|
pub(crate) mod condition_lowerer; // Phase 171-fix: Core condition lowering logic
|
2025-12-08 00:30:17 +09:00
|
|
|
|
pub mod condition_to_joinir; // Phase 169: JoinIR condition lowering orchestrator (refactored)
|
refactor(joinir): Restrict visibility of internal lowering modules (Task 3)
Task 3: Unused public exports visibility restriction
- Changed 15 modules from 'pub mod' to 'pub(crate) mod'
- Modules changed: bool_expr_lowerer, carrier_update_emitter, common,
condition_lowerer, condition_var_extractor, exit_args_resolver,
generic_case_a, if_lowering_router, if_select, loop_form_intake,
loop_pattern_router, loop_pattern_validator, loop_patterns,
loop_view_builder, value_id_ranges
- All changed modules have 0 external uses outside src/mir/join_ir/lowering/
- Kept public re-exports for functions that need backward compatibility
- Build verified: cargo build --release passes with 0 errors
Result: Improved API encapsulation without breaking external users
2025-12-08 19:19:58 +09:00
|
|
|
|
pub(crate) mod condition_var_extractor; // Phase 171-fix: Variable extraction from condition AST
|
2025-12-07 19:00:12 +09:00
|
|
|
|
pub mod continue_branch_normalizer; // Phase 33-19: Continue branch normalization for Pattern B
|
2025-12-06 14:46:33 +09:00
|
|
|
|
pub mod loop_update_analyzer; // Phase 197: Update expression analyzer for carrier semantics
|
2025-12-07 14:17:58 +09:00
|
|
|
|
pub mod loop_update_summary; // Phase 170-C-2: Update pattern summary for shape detection
|
refactor(joinir): Restrict visibility of internal lowering modules (Task 3)
Task 3: Unused public exports visibility restriction
- Changed 15 modules from 'pub mod' to 'pub(crate) mod'
- Modules changed: bool_expr_lowerer, carrier_update_emitter, common,
condition_lowerer, condition_var_extractor, exit_args_resolver,
generic_case_a, if_lowering_router, if_select, loop_form_intake,
loop_pattern_router, loop_pattern_validator, loop_patterns,
loop_view_builder, value_id_ranges
- All changed modules have 0 external uses outside src/mir/join_ir/lowering/
- Kept public re-exports for functions that need backward compatibility
- Build verified: cargo build --release passes with 0 errors
Result: Improved API encapsulation without breaking external users
2025-12-08 19:19:58 +09:00
|
|
|
|
pub(crate) mod exit_args_resolver; // Internal exit argument resolution
|
2025-11-24 05:23:26 +09:00
|
|
|
|
pub mod funcscanner_append_defs;
|
2025-11-23 16:49:49 +09:00
|
|
|
|
pub mod funcscanner_trim;
|
refactor(joinir): Restrict visibility of internal lowering modules (Task 3)
Task 3: Unused public exports visibility restriction
- Changed 15 modules from 'pub mod' to 'pub(crate) mod'
- Modules changed: bool_expr_lowerer, carrier_update_emitter, common,
condition_lowerer, condition_var_extractor, exit_args_resolver,
generic_case_a, if_lowering_router, if_select, loop_form_intake,
loop_pattern_router, loop_pattern_validator, loop_patterns,
loop_view_builder, value_id_ranges
- All changed modules have 0 external uses outside src/mir/join_ir/lowering/
- Kept public re-exports for functions that need backward compatibility
- Build verified: cargo build --release passes with 0 errors
Result: Improved API encapsulation without breaking external users
2025-12-08 19:19:58 +09:00
|
|
|
|
pub(crate) mod generic_case_a; // Phase 192: Modularized Case A lowering
|
2025-12-01 11:10:46 +09:00
|
|
|
|
pub mod generic_type_resolver; // Phase 66: P3-C ジェネリック型推論箱
|
2025-12-02 18:09:04 +09:00
|
|
|
|
pub mod method_return_hint; // Phase 83: P3-D 既知メソッド戻り値型推論箱
|
2025-11-27 17:05:46 +09:00
|
|
|
|
pub mod if_dry_runner; // Phase 33-10.0
|
refactor(joinir): Restrict visibility of internal lowering modules (Task 3)
Task 3: Unused public exports visibility restriction
- Changed 15 modules from 'pub mod' to 'pub(crate) mod'
- Modules changed: bool_expr_lowerer, carrier_update_emitter, common,
condition_lowerer, condition_var_extractor, exit_args_resolver,
generic_case_a, if_lowering_router, if_select, loop_form_intake,
loop_pattern_router, loop_pattern_validator, loop_patterns,
loop_view_builder, value_id_ranges
- All changed modules have 0 external uses outside src/mir/join_ir/lowering/
- Kept public re-exports for functions that need backward compatibility
- Build verified: cargo build --release passes with 0 errors
Result: Improved API encapsulation without breaking external users
2025-12-08 19:19:58 +09:00
|
|
|
|
pub(crate) mod if_lowering_router; // Phase 33-12: If-expression routing (re-exported)
|
2025-11-27 08:18:09 +09:00
|
|
|
|
pub mod if_merge; // Phase 33-7
|
2025-11-29 11:53:57 +09:00
|
|
|
|
pub mod if_phi_context; // Phase 61-1
|
2025-11-29 12:26:02 +09:00
|
|
|
|
pub mod if_phi_spec; // Phase 61-2
|
refactor(joinir): Restrict visibility of internal lowering modules (Task 3)
Task 3: Unused public exports visibility restriction
- Changed 15 modules from 'pub mod' to 'pub(crate) mod'
- Modules changed: bool_expr_lowerer, carrier_update_emitter, common,
condition_lowerer, condition_var_extractor, exit_args_resolver,
generic_case_a, if_lowering_router, if_select, loop_form_intake,
loop_pattern_router, loop_pattern_validator, loop_patterns,
loop_view_builder, value_id_ranges
- All changed modules have 0 external uses outside src/mir/join_ir/lowering/
- Kept public re-exports for functions that need backward compatibility
- Build verified: cargo build --release passes with 0 errors
Result: Improved API encapsulation without breaking external users
2025-12-08 19:19:58 +09:00
|
|
|
|
pub(crate) mod if_select; // Phase 33: Internal If/Select lowering
|
2025-12-05 13:46:44 +09:00
|
|
|
|
pub mod inline_boundary; // Phase 188-Impl-3: JoinIR→Host boundary
|
2025-12-08 04:25:58 +09:00
|
|
|
|
pub mod inline_boundary_builder; // Phase 200-2: Builder pattern for JoinInlineBoundary
|
2025-12-09 18:44:31 +09:00
|
|
|
|
pub mod join_value_space; // Phase 201: Unified JoinIR ValueId allocation
|
refactor(joinir): Restrict visibility of internal lowering modules (Task 3)
Task 3: Unused public exports visibility restriction
- Changed 15 modules from 'pub mod' to 'pub(crate) mod'
- Modules changed: bool_expr_lowerer, carrier_update_emitter, common,
condition_lowerer, condition_var_extractor, exit_args_resolver,
generic_case_a, if_lowering_router, if_select, loop_form_intake,
loop_pattern_router, loop_pattern_validator, loop_patterns,
loop_view_builder, value_id_ranges
- All changed modules have 0 external uses outside src/mir/join_ir/lowering/
- Kept public re-exports for functions that need backward compatibility
- Build verified: cargo build --release passes with 0 errors
Result: Improved API encapsulation without breaking external users
2025-12-08 19:19:58 +09:00
|
|
|
|
pub(crate) mod loop_form_intake; // Internal loop form intake
|
|
|
|
|
|
pub(crate) mod loop_pattern_router; // Phase 33-12: Loop pattern routing (re-exported)
|
|
|
|
|
|
pub(crate) mod loop_pattern_validator; // Phase 33-23: Loop structure validation
|
|
|
|
|
|
pub(crate) mod loop_patterns; // Phase 188: Pattern-based loop lowering (3 patterns)
|
2025-11-25 06:32:08 +09:00
|
|
|
|
pub mod loop_scope_shape;
|
2025-11-26 01:18:32 +09:00
|
|
|
|
pub mod loop_to_join;
|
refactor(joinir): Restrict visibility of internal lowering modules (Task 3)
Task 3: Unused public exports visibility restriction
- Changed 15 modules from 'pub mod' to 'pub(crate) mod'
- Modules changed: bool_expr_lowerer, carrier_update_emitter, common,
condition_lowerer, condition_var_extractor, exit_args_resolver,
generic_case_a, if_lowering_router, if_select, loop_form_intake,
loop_pattern_router, loop_pattern_validator, loop_patterns,
loop_view_builder, value_id_ranges
- All changed modules have 0 external uses outside src/mir/join_ir/lowering/
- Kept public re-exports for functions that need backward compatibility
- Build verified: cargo build --release passes with 0 errors
Result: Improved API encapsulation without breaking external users
2025-12-08 19:19:58 +09:00
|
|
|
|
pub(crate) mod loop_view_builder; // Phase 33-23: Loop lowering dispatch
|
2025-12-05 15:28:54 +09:00
|
|
|
|
pub mod loop_with_break_minimal; // Phase 188-Impl-2: Pattern 2 minimal lowerer
|
2025-12-06 00:20:45 +09:00
|
|
|
|
pub mod loop_with_continue_minimal; // Phase 195: Pattern 4 minimal lowerer
|
feat(joinir): Phase 188-Impl-3 Pattern 3 (Loop with If-Else PHI) implementation
Add Pattern 3 lowerer for `loop { if cond { x = a } else { x = b } ... }` pattern.
New files:
- loop_with_if_phi_minimal.rs (381 lines): JoinIR lowerer for Pattern 3
- Multiple loop variables (counter + accumulator)
- In-loop if/else PHI using Select instruction
- Carriers passed to next iteration via tail recursion
Modified files:
- join_ir/mod.rs: Add Mod to BinOpKind, Select to MirLikeInst
- loop_pattern_detection.rs: Add is_loop_with_conditional_phi_pattern() detection
- lowering/mod.rs: Pattern 3 router integration
- loop_patterns.rs: Pattern 3 entry point delegation
- json.rs: Mod/Select JSON serialization
- join_ir_ops.rs: Mod operation evaluation (a % b)
- join_ir_runner.rs: Select instruction execution
- join_ir_vm_bridge/convert.rs: Mod/Select conversion handlers
Implementation:
- Pattern 3 generates 3 JoinIR functions: main, loop_step(i, sum), k_exit(sum_final)
- Exit condition: !(i <= 5) with Jump to k_exit
- In-loop if/else: if (i % 2 == 1) { sum + i } else { sum + 0 }
- Select instruction: sum_new = Select(if_cond, sum_then, sum_else)
- Both carriers updated: Call(loop_step, [i_next, sum_new])
Build status: ✅ Compiles successfully (0 errors, 34 warnings)
Integration: Infrastructure complete, MIR boundary mapping pending
All 3 patterns now have lowering infrastructure in place for Phase 188.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 15:45:42 +09:00
|
|
|
|
pub mod loop_with_if_phi_minimal; // Phase 188-Impl-3: Pattern 3 minimal lowerer
|
2025-12-05 07:47:22 +09:00
|
|
|
|
pub mod simple_while_minimal; // Phase 188-Impl-1: Pattern 1 minimal lowerer
|
2025-11-23 16:49:49 +09:00
|
|
|
|
pub mod min_loop;
|
|
|
|
|
|
pub mod skip_ws;
|
2025-11-24 02:34:36 +09:00
|
|
|
|
pub mod stage1_using_resolver;
|
2025-11-24 14:17:02 +09:00
|
|
|
|
pub mod stageb_body;
|
|
|
|
|
|
pub mod stageb_funcscanner;
|
2025-11-30 06:37:34 +09:00
|
|
|
|
pub mod type_hint_policy; // Phase 65.5: 型ヒントポリシー箱化
|
2025-11-30 06:10:58 +09:00
|
|
|
|
pub mod type_inference; // Phase 65-2-A
|
feat(joinir): Phase 184 - Body-local MIR Lowering Infrastructure
Phase 184 implements the foundation for body-local variable support in
update expressions, completing the three-box architecture:
LoopBodyLocalEnv (storage), UpdateEnv (composition), and
CarrierUpdateEmitter (emission).
## Implementation Summary
### Task 184-1: Design Document
- Created phase184-body-local-mir-lowering.md
- Two-Environment System design (ConditionEnv + LoopBodyLocalEnv)
- Box-First design principles documented
### Task 184-2: LoopBodyLocalEnv Implementation
- New file: src/mir/join_ir/lowering/loop_body_local_env.rs (216 lines)
- Storage box for body-local variable name → ValueId mappings
- BTreeMap for deterministic ordering (PHI consistency)
- 7 unit tests: empty env, single/multiple locals, get/contains, iteration
### Task 184-3: UpdateEnv Implementation
- New file: src/mir/join_ir/lowering/update_env.rs (237 lines)
- Composition box for unified variable resolution
- Priority order: ConditionEnv (condition vars) → LoopBodyLocalEnv (body-local)
- 8 unit tests: priority, fallback, not found, combined lookup
### Task 184-4: CarrierUpdateEmitter Integration
- Modified: src/mir/join_ir/lowering/carrier_update_emitter.rs
- Added emit_carrier_update_with_env() (UpdateEnv version)
- Kept emit_carrier_update() for backward compatibility
- 4 new unit tests: body-local variable, priority, not found, const update
- Total 10 tests PASS (6 existing + 4 new)
### Task 184-5: Representative Test Cases
- apps/tests/phase184_body_local_update.hako (Pattern1 baseline)
- apps/tests/phase184_body_local_with_break.hako (Pattern2, Phase 185 target)
### Task 184-6: Documentation Updates
- Updated: docs/development/current/main/joinir-architecture-overview.md
- Updated: CURRENT_TASK.md (Phase 184 completion record)
## Test Results
All 25 unit tests PASS:
- LoopBodyLocalEnv: 7 tests
- UpdateEnv: 8 tests
- CarrierUpdateEmitter: 10 tests (6 existing + 4 new)
Build: ✅ Success (0 errors)
## Design Constraints
Following 箱理論 (Box Theory) principles:
- Single Responsibility: Each box has one clear purpose
- Deterministic: BTreeMap ensures consistent ordering
- Conservative: Pattern5 (Trim) integration deferred to Phase 185
- Fail-Fast: Explicit errors for unsupported patterns
## Scope Limitation
Phase 184 provides the **infrastructure only**:
- ✅ Storage box (LoopBodyLocalEnv)
- ✅ Composition box (UpdateEnv)
- ✅ Emission support (CarrierUpdateEmitter)
- ❌ Pattern2/4 integration (requires body-local collection, Phase 185)
## Next Steps
Phase 185: Pattern2/4 Integration
- Integrate LoopBodyLocalEnv into Pattern2/4 lowerers
- Add body-local variable collection from loop body AST
- Enable full E2E body-local variable support in update expressions
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-08 23:59:19 +09:00
|
|
|
|
pub mod update_env; // Phase 184: Unified variable resolution for update expressions
|
refactor(joinir): Restrict visibility of internal lowering modules (Task 3)
Task 3: Unused public exports visibility restriction
- Changed 15 modules from 'pub mod' to 'pub(crate) mod'
- Modules changed: bool_expr_lowerer, carrier_update_emitter, common,
condition_lowerer, condition_var_extractor, exit_args_resolver,
generic_case_a, if_lowering_router, if_select, loop_form_intake,
loop_pattern_router, loop_pattern_validator, loop_patterns,
loop_view_builder, value_id_ranges
- All changed modules have 0 external uses outside src/mir/join_ir/lowering/
- Kept public re-exports for functions that need backward compatibility
- Build verified: cargo build --release passes with 0 errors
Result: Improved API encapsulation without breaking external users
2025-12-08 19:19:58 +09:00
|
|
|
|
pub(crate) mod value_id_ranges; // Internal ValueId range management
|
2025-11-23 16:49:49 +09:00
|
|
|
|
|
|
|
|
|
|
// Re-export public lowering functions
|
2025-11-24 05:23:26 +09:00
|
|
|
|
pub use funcscanner_append_defs::lower_funcscanner_append_defs_to_joinir;
|
2025-11-23 16:49:49 +09:00
|
|
|
|
pub use funcscanner_trim::lower_funcscanner_trim_to_joinir;
|
2025-12-08 04:25:58 +09:00
|
|
|
|
// Phase 200-2: Builder pattern
|
|
|
|
|
|
pub use inline_boundary_builder::JoinInlineBoundaryBuilder;
|
2025-11-26 01:18:32 +09:00
|
|
|
|
// Phase 31: LoopToJoinLowerer 統一箱
|
|
|
|
|
|
pub use loop_to_join::LoopToJoinLowerer;
|
2025-11-25 23:25:39 +09:00
|
|
|
|
// Phase 30 F-3: 旧 lower_case_a_loop_to_joinir_for_minimal_skip_ws は _with_scope に置き換え済みのため削除
|
2025-11-23 16:49:49 +09:00
|
|
|
|
pub use min_loop::lower_min_loop_to_joinir;
|
|
|
|
|
|
pub use skip_ws::lower_skip_ws_to_joinir;
|
2025-11-24 02:34:36 +09:00
|
|
|
|
pub use stage1_using_resolver::lower_stage1_usingresolver_to_joinir;
|
2025-11-24 14:17:02 +09:00
|
|
|
|
pub use stageb_body::lower_stageb_body_to_joinir;
|
|
|
|
|
|
pub use stageb_funcscanner::lower_stageb_funcscanner_to_joinir;
|
2025-11-27 03:28:32 +09:00
|
|
|
|
|
2025-12-07 03:26:06 +09:00
|
|
|
|
// Phase 33-12: Re-export router functions (backward compatibility)
|
|
|
|
|
|
pub use if_lowering_router::try_lower_if_to_joinir;
|
|
|
|
|
|
pub use loop_pattern_router::try_lower_loop_pattern_to_joinir;
|
2025-11-27 03:28:32 +09:00
|
|
|
|
|
2025-11-27 10:58:56 +09:00
|
|
|
|
/// Phase 33-9.1: Loop lowering対象関数の判定
|
|
|
|
|
|
///
|
|
|
|
|
|
/// これらの関数は Phase 32/33 で LoopToJoinLowerer によって処理されます。
|
|
|
|
|
|
/// If lowering (Select/IfMerge) の対象から除外することで、Loop/If の責務を明確に分離します。
|
|
|
|
|
|
///
|
2025-12-02 14:01:44 +09:00
|
|
|
|
/// Phase 82 SSOT: JOINIR_TARGETS テーブルから Exec 対象を参照
|
|
|
|
|
|
/// (テーブルは vm_bridge_dispatch/targets.rs で一元管理)
|
|
|
|
|
|
///
|
2025-11-27 10:58:56 +09:00
|
|
|
|
/// ## 対象関数(6本)
|
|
|
|
|
|
/// - Main.skip/1: 空白スキップループ
|
|
|
|
|
|
/// - FuncScannerBox.trim/1: 前後空白削除ループ
|
|
|
|
|
|
/// - FuncScannerBox.append_defs/2: 配列結合ループ
|
|
|
|
|
|
/// - Stage1UsingResolverBox.resolve_for_source/5: using解析ループ
|
|
|
|
|
|
/// - StageBBodyExtractorBox.build_body_src/2: Stage-B本体抽出ループ
|
|
|
|
|
|
/// - StageBFuncScannerBox.scan_all_boxes/1: Stage-B Box走査ループ
|
|
|
|
|
|
///
|
|
|
|
|
|
/// ## 将来の拡張
|
|
|
|
|
|
/// NYASH_JOINIR_LOWER_GENERIC=1 で汎用 Case-A ループにも拡張可能
|
|
|
|
|
|
pub(crate) fn is_loop_lowered_function(name: &str) -> bool {
|
2025-12-02 14:01:44 +09:00
|
|
|
|
// Phase 82 SSOT: vm_bridge_dispatch テーブルから Loop 関数を抽出
|
|
|
|
|
|
// Phase 33-9.1: If lowering の除外対象は、JOINIR_TARGETS に登録されたすべての関数
|
|
|
|
|
|
// (Exec/LowerOnly 問わず、ループ専任関数として Loop lowering で処理)
|
|
|
|
|
|
crate::mir::join_ir_vm_bridge_dispatch::JOINIR_TARGETS
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.any(|t| t.func_name == name)
|
2025-11-27 10:58:56 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-02 13:45:47 +09:00
|
|
|
|
// ============================================================================
|
|
|
|
|
|
// Phase 80: JoinIR Mainline Unification - Core ON 時の本線化判定
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
/// Phase 80: JoinIR 本線化対象(Loop)の判定
|
|
|
|
|
|
///
|
|
|
|
|
|
/// `joinir_core_enabled()=true` の時、これらの関数のループは
|
|
|
|
|
|
/// 必ず JoinIR → MIR 経路を本線として試行します。
|
|
|
|
|
|
pub fn is_loop_mainline_target(name: &str) -> bool {
|
|
|
|
|
|
is_loop_lowered_function(name)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-04 21:58:45 +09:00
|
|
|
|
/// Phase 80/184: JoinIR 本線化対象(If)の判定
|
2025-12-02 13:45:47 +09:00
|
|
|
|
///
|
|
|
|
|
|
/// `joinir_core_enabled()=true` の時、これらの関数の if/else は
|
|
|
|
|
|
/// 必ず JoinIR → MIR 経路を本線として試行します。
|
2025-12-04 21:58:45 +09:00
|
|
|
|
///
|
|
|
|
|
|
/// Phase 184: JOINIR_IF_TARGETS テーブルからの参照に変更
|
2025-12-02 13:45:47 +09:00
|
|
|
|
pub fn is_if_mainline_target(name: &str) -> bool {
|
2025-12-04 21:58:45 +09:00
|
|
|
|
crate::mir::join_ir_vm_bridge_dispatch::is_if_lowered_function(name)
|
2025-12-02 13:45:47 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Phase 80: Core ON 時に JoinIR を本線として試行すべきか判定
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Returns true if:
|
|
|
|
|
|
/// - `joinir_core_enabled()=true` AND
|
|
|
|
|
|
/// - 関数が本線化対象 (Loop or If)
|
|
|
|
|
|
pub fn should_try_joinir_mainline(func_name: &str, is_loop: bool) -> bool {
|
|
|
|
|
|
if !crate::config::env::joinir_core_enabled() {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if is_loop {
|
|
|
|
|
|
is_loop_mainline_target(func_name)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
is_if_mainline_target(func_name)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Phase 80/81: Strict モードで JoinIR lowering 失敗時にパニックすべきか判定
|
|
|
|
|
|
pub fn should_panic_on_joinir_failure(func_name: &str, is_loop: bool) -> bool {
|
|
|
|
|
|
if !crate::config::env::joinir_strict_enabled() {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
should_try_joinir_mainline(func_name, is_loop)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-04 21:58:45 +09:00
|
|
|
|
/// Phase 61-4/184: ループ外 If の JoinIR 対象関数判定
|
2025-11-29 15:15:22 +09:00
|
|
|
|
///
|
|
|
|
|
|
/// HAKO_JOINIR_IF_TOPLEVEL=1 有効時に、ループ外 if の JoinIR 経路を試行する関数。
|
2025-12-04 21:58:45 +09:00
|
|
|
|
/// Phase 184: JOINIR_IF_TARGETS テーブルに統一(SSOT化)
|
2025-11-29 15:15:22 +09:00
|
|
|
|
///
|
2025-12-04 21:58:45 +09:00
|
|
|
|
/// ## 対象関数(テーブル管理)
|
2025-11-29 15:15:22 +09:00
|
|
|
|
/// - IfSelectTest.*: テスト専用関数群
|
2025-12-04 21:58:45 +09:00
|
|
|
|
/// - IfMergeTest.*: 複数変数テスト(Phase 33-7)
|
2025-11-29 15:15:22 +09:00
|
|
|
|
/// - IfToplevelTest.*: ループ外 if テスト専用(Phase 61-4)
|
2025-12-04 21:58:45 +09:00
|
|
|
|
/// - JsonShapeToMap._read_value_from_pair/1: Phase 33-4 Stage-1 実用関数
|
|
|
|
|
|
/// - Stage1JsonScannerBox.value_start_after_key_pos/2: Phase 33-4 Stage-B 実用関数
|
2025-11-29 15:15:22 +09:00
|
|
|
|
///
|
|
|
|
|
|
/// ## 使用方法
|
2025-12-04 21:58:45 +09:00
|
|
|
|
/// if_form.rs から呼び出され、関数名がテーブルに含まれる場合のみ
|
2025-11-29 15:15:22 +09:00
|
|
|
|
/// JoinIR 経路を試行する。
|
2025-12-04 21:58:45 +09:00
|
|
|
|
///
|
|
|
|
|
|
/// Phase 184: テーブル参照に変更(プレフィックス判定は併用)
|
2025-11-29 15:15:22 +09:00
|
|
|
|
pub fn is_joinir_if_toplevel_target(name: &str) -> bool {
|
2025-12-04 21:58:45 +09:00
|
|
|
|
// Phase 184: JOINIR_IF_TARGETS テーブルから参照(exact match)
|
|
|
|
|
|
if crate::mir::join_ir_vm_bridge_dispatch::JOINIR_IF_TARGETS
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.any(|t| t.func_name == name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test prefixes (backward compatibility - allows any test function)
|
2025-11-29 15:15:22 +09:00
|
|
|
|
if name.starts_with("IfSelectTest.")
|
|
|
|
|
|
|| name.starts_with("IfToplevelTest.")
|
|
|
|
|
|
|| name.starts_with("IfMergeTest.")
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-04 21:58:45 +09:00
|
|
|
|
false
|
2025-11-29 15:15:22 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-27 10:58:56 +09:00
|
|
|
|
#[cfg(test)]
|
|
|
|
|
|
mod tests {
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
|
|
/// Phase 33-9.1: is_loop_lowered_function() の動作確認
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_is_loop_lowered_function() {
|
|
|
|
|
|
// Loop 専任関数(6本)は true を返す
|
|
|
|
|
|
assert!(is_loop_lowered_function("Main.skip/1"));
|
|
|
|
|
|
assert!(is_loop_lowered_function("FuncScannerBox.trim/1"));
|
|
|
|
|
|
assert!(is_loop_lowered_function("FuncScannerBox.append_defs/2"));
|
|
|
|
|
|
assert!(is_loop_lowered_function(
|
|
|
|
|
|
"Stage1UsingResolverBox.resolve_for_source/5"
|
|
|
|
|
|
));
|
|
|
|
|
|
assert!(is_loop_lowered_function(
|
|
|
|
|
|
"StageBBodyExtractorBox.build_body_src/2"
|
|
|
|
|
|
));
|
|
|
|
|
|
assert!(is_loop_lowered_function(
|
|
|
|
|
|
"StageBFuncScannerBox.scan_all_boxes/1"
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
// If lowering 対象関数は false を返す
|
|
|
|
|
|
assert!(!is_loop_lowered_function("IfSelectTest.simple_return/0"));
|
|
|
|
|
|
assert!(!is_loop_lowered_function("IfMergeTest.multiple_true/0"));
|
|
|
|
|
|
assert!(!is_loop_lowered_function(
|
|
|
|
|
|
"JsonShapeToMap._read_value_from_pair/1"
|
|
|
|
|
|
));
|
|
|
|
|
|
assert!(!is_loop_lowered_function(
|
|
|
|
|
|
"Stage1JsonScannerBox.value_start_after_key_pos/2"
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
// 一般的な関数も false を返す
|
|
|
|
|
|
assert!(!is_loop_lowered_function("SomeBox.some_method/3"));
|
|
|
|
|
|
assert!(!is_loop_lowered_function("Main.main/0"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|