P3(if-sum) 本番ルートに OwnershipPlan 解析を接続(analysis-only)。 Key changes: - ast_analyzer.rs: Added analyze_loop() helper - Loop-specific analysis API for production integration - build_plan_for_scope() helper for single-scope extraction - pattern3_with_if_phi.rs: P3 production integration - OwnershipPlan analysis after ConditionEnv building - check_ownership_plan_consistency() for validation - Feature-gated #[cfg(feature = "normalized_dev")] Consistency checks: - Fail-Fast: Multi-hop relay (relay_path.len() > 1) - Warn-only: Carrier set mismatch (order SSOT deferred) - Warn-only: Condition captures (some patterns have extras) Tests: 49/49 PASS (2 new Phase 64 tests) - test_phase64_p3_ownership_prod_integration - test_phase64_p3_multihop_relay_detection - Zero regressions Design: Analysis-only, no behavior change - Integration point: After ConditionEnv, before JoinIR lowering - Dev-only validation for future SSOT migration Next: Phase 65+ - Carrier order SSOT, owner-based init 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
3.8 KiB
3.8 KiB
Phase 64 Summary: Ownership P3 Production Integration (dev-only)
Goal
Connect OwnershipPlan analysis to production P3(if-sum) route for dev-only validation.
Changes
1. ast_analyzer.rs: Added analyze_loop() helper
- Purpose: Analyze a single loop (condition + body) with parent context
- Signature:
analyze_loop(condition, body, parent_defined) -> Result<OwnershipPlan> - Usage: Called from P3 production route in
pattern3_with_if_phi.rs - Features:
- Creates temporary function scope for parent-defined variables
- Analyzes loop scope with condition/body AST
- Returns OwnershipPlan for loop scope only
2. pattern3_with_if_phi.rs: Added dev-only OwnershipPlan call + consistency checks
- Location: Inside
lower_pattern3_if_sum()method, after ConditionEnv building - Feature gate:
#[cfg(feature = "normalized_dev")] - Workflow:
- Collect parent-defined variables from
variable_map - Call
analyze_loop()to produce OwnershipPlan - Run
check_ownership_plan_consistency()checks - Continue with existing lowering (analysis-only, no behavior change)
- Collect parent-defined variables from
3. Consistency checks (check_ownership_plan_consistency())
Check 1: Multi-hop relay rejection (Fail-Fast)
- What:
relay_path.len() > 1→ Err - Why: Multi-hop relay is out of scope for Phase 64
- Action: Return error immediately (Fail-Fast principle)
Check 2: Carrier set consistency (warn-only)
- What: Compare
plan.owned_vars(written) vscarrier_info.carriers - Why: Verify OwnershipPlan matches existing CarrierInfo
- Action: Warn if mismatch (order SSOT deferred to Phase 65+)
Check 3: Condition captures consistency (warn-only)
- What: Verify
plan.condition_captures⊆condition_bindings - Why: Ensure OwnershipPlan condition captures are tracked
- Action: Warn if extra captures found
4. Regression tests (normalized_joinir_min.rs)
Test 1: test_phase64_p3_ownership_prod_integration()
- Purpose: Verify
analyze_loop()works for simple P3 loops - Pattern:
loop(i < 10) { local sum=0; sum=sum+i; i=i+1; } - Checks:
- Owned vars: sum (is_written=true), i (is_written=true, is_condition_only=true)
- No relay writes (all loop-local)
- Single-hop relay constraint verified
Test 2: test_phase64_p3_multihop_relay_rejection()
- Purpose: Verify multi-hop relay detection
- Pattern: Nested loops with relay write to function-scoped variable
- Checks:
- Detects multi-hop relay (
relay_path.len() > 1) - Documents that rejection happens in consistency check (not analyze_loop)
- Detects multi-hop relay (
Constraints
- Dev-only:
#[cfg(feature = "normalized_dev")]throughout - Analysis-only: No behavior change to lowering
- Fail-Fast: Multi-hop relay (
relay_path.len() > 1) - Warn-only: Carrier set mismatch (order SSOT deferred)
Build and Test
# Build with normalized_dev feature
cargo build --release --features normalized_dev
# Run Phase 64 tests
cargo test --features normalized_dev --test normalized_joinir_min phase64
# Run ownership module tests
cargo test --features normalized_dev --lib ownership
Expected: All tests pass, no regressions.
Next Steps
Phase 65+: Future Enhancements
- Multi-hop relay support: Remove
relay_path.len() > 1limitation - Carrier order SSOT: Use OwnershipPlan to determine carrier order (upgrade warn to error)
- Owner-based init: Replace legacy
FromHostwith owner-based initialization - Full AST coverage: Extend
analyze_loop()to handle more complex patterns