Files
hakorune/apps/tests/phase264_p0_bundle_resolver_loop_min.hako
tomoaki be4de67601 fix(joinir): improve Pattern3 classification to exclude simple conditional assignment (Phase 264 P0)
Problem:
- Pattern3 heuristic was too conservative: detect_if_in_body() returned
  true for ANY if statement, causing simple conditional assignments to be
  misclassified as Pattern3IfPhi
- Example: `if i == 0 then seg = "first" else seg = "other"` was routed
  to Pattern3, but Pattern3 only handles if-sum patterns like
  `sum = sum + (if x then 1 else 0)`
- This caused loops with conditional assignment to fail Pattern3 check
  and exhaust all routing paths

Solution (Conservative, Phase 264 P0):
- ast_feature_extractor.rs:
  - detect_if_else_phi_in_body(): Always return false
  - has_if = has_if_else_phi (don't use detect_if_in_body())
- loop_pattern_detection/mod.rs:
  - Add has_if_sum_signature() (returns false for P0)
  - has_if_else_phi = carrier_count > 1 && has_if_sum_signature(scope)

Effect:
- Simple conditional assignment loops now fall through to Pattern1 
- Pattern3 misrouting prevented 

Results:
- Lib tests: 1368/1368 PASS (no regression)
- Minimal repro: phase264_p0_bundle_resolver_loop_min.hako PASS 
- Quick smoke: 45/46 (unchanged - complex BundleResolver loop needs P1)

Phase 264 P1 TODO:
- Implement accurate if-sum signature detection (AST/CFG analysis)
- Support complex nested loops in Pattern2 or new pattern

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-21 11:49:03 +09:00

33 lines
879 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Phase 264 P0: BundleResolver.resolve/4 ループ問題の最小再現
//
// 目的:
// - non-unit increment + conditional assignment のループを Pattern2/fallback で受理
// - 現状: Pattern2 rejection で FAIL全経路 exhaust
// - 期待: 修正後に PASSいずれかの経路で受理
//
// ループの特徴:
// - Non-unit increment: i = i + 2 (not i = i + 1)
// - Conditional variable assignment: seg = ... (if) ... else seg = ...
// - LoopBodyLocal: seg 変数が loop body で代入される
static box Main {
main() {
local i = 0
local seg = ""
loop(i < 10) {
// Conditional assignment to seg
if i == 0 {
seg = "first"
} else {
seg = "other"
}
// Non-unit increment
i = i + 2
}
return 0
}
}