feat(joinir): Phase 171-C-2 Trim pattern detection in LoopBodyCarrierPromoter
Implements the Trim pattern detection logic for carrier promotion:
- find_definition_in_body(): Iterative AST traversal to locate variable definitions
- is_substring_method_call(): Detects substring() method calls
- extract_equality_literals(): Extracts string literals from OR chains (ch == " " || ch == "\t")
- TrimPatternInfo: Captures detected pattern details for carrier promotion
This enables Pattern 5 to detect trim-style loops:
```hako
loop(start < end) {
local ch = s.substring(start, start+1)
if ch == " " || ch == "\t" || ch == "\n" || ch == "\r" {
start = start + 1
} else {
break
}
}
```
Unit tests cover:
- Simple and nested definition detection
- substring method call detection
- Single and chained equality literal extraction
- Full Trim pattern detection with 2-4 whitespace characters
Next: Phase 171-C-3 integration with Pattern 2/4 routing
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
# Phase 170: JsonParserBox JoinIR Preparation & Re-validation - Completion Report
|
||||
|
||||
**Date**: 2025-12-07
|
||||
**Duration**: 1 session (autonomous work)
|
||||
**Status**: ✅ **Complete** - Environment prepared, blockers identified, next phase planned
|
||||
**Duration**: 2 sessions (autonomous work + bug fix verification)
|
||||
**Status**: ✅ **Complete** - Environment prepared, bug fix verified, next phase planned
|
||||
|
||||
---
|
||||
|
||||
@ -374,5 +374,77 @@ match update.kind {
|
||||
- 代表的な ループスモーク 16 本のうち 15 本が PASS(1 本は既知の別問題)で、
|
||||
既存パターンへの回帰は維持されている。
|
||||
|
||||
この状態を起点に、今後 Phase 170‑C‑3 以降で `LoopUpdateSummary` の中身(AST/MIR ベースの解析)だけを差し替えることで、
|
||||
この状態を起点に、今後 Phase 170‑C‑3 以降で `LoopUpdateSummary` の中身(AST/MIR ベースの解析)だけを差し替えることで、
|
||||
段階的に carrier 名ヒューリスティックを薄めていく計画。
|
||||
|
||||
---
|
||||
|
||||
## Phase 170-D: Loop Condition Scope Analysis - Bug Fix Verification ✅
|
||||
|
||||
**Date**: 2025-12-07 (Session 2)
|
||||
**Status**: ✅ **Bug Fix Complete and Verified**
|
||||
|
||||
### Bug Fix: Function Parameter Misclassification
|
||||
|
||||
**Issue**: Function parameters (`s`, `pos` in JsonParser methods) were incorrectly classified as **LoopBodyLocal** when used in loop conditions.
|
||||
|
||||
**Root Cause**: `is_outer_scope_variable()` in `condition_var_analyzer.rs` defaulted unknown variables (not in `variable_definitions`) to LoopBodyLocal.
|
||||
|
||||
**Fix** (User Implemented):
|
||||
```rust
|
||||
// File: src/mir/loop_pattern_detection/condition_var_analyzer.rs (lines 175-184)
|
||||
|
||||
// At this point:
|
||||
// - Variable is NOT in body_locals
|
||||
// - No explicit definition info
|
||||
// This typically means "function parameter" or "outer local"
|
||||
true // ✅ Default to OuterLocal for function parameters
|
||||
```
|
||||
|
||||
### Verification Results
|
||||
|
||||
**Test 1: Function Parameter Loop** ✅
|
||||
- **File**: `/tmp/test_jsonparser_simple.hako`
|
||||
- **Result**: `Phase 170-D: Condition variables verified: {"pos", "s", "len"}`
|
||||
- **Analysis**: Function parameters correctly classified as OuterLocal
|
||||
- **New blocker**: Method calls (Pattern 5+ feature, not a bug)
|
||||
|
||||
**Test 2: LoopBodyLocal Correct Rejection** ✅
|
||||
- **File**: `local_tests/test_trim_main_pattern.hako`
|
||||
- **Result**: `Phase 170-D: Condition variables verified: {"ch", "end", "start"}`
|
||||
- **Error**: "Variable 'ch' not bound in ConditionEnv" (correct rejection)
|
||||
- **Analysis**: `ch` is defined inside loop, correctly rejected by Pattern 2
|
||||
|
||||
**Test 3: JsonParser Full File** ✅
|
||||
- **File**: `tools/hako_shared/json_parser.hako`
|
||||
- **Result**: Error about MethodCall, not variable classification
|
||||
- **Analysis**: Variable scope classification now correct, remaining errors are legitimate feature gaps
|
||||
|
||||
### Impact
|
||||
|
||||
**What the Fix Achieves**:
|
||||
- ✅ Function parameters work correctly: `s`, `pos` in JsonParser
|
||||
- ✅ Carrier variables work correctly: `start`, `end` in trim loops
|
||||
- ✅ Outer locals work correctly: `len`, `maxLen` from outer scope
|
||||
- ✅ Correct rejection: LoopBodyLocal `ch` properly rejected (not a bug)
|
||||
|
||||
**Remaining Blockers** (Pattern 5+ features, not bugs):
|
||||
- ⚠️ Method calls in conditions: `loop(pos < s.length())`
|
||||
- ⚠️ Method calls in loop body: `s.substring(pos, pos+1)`
|
||||
- ⚠️ LoopBodyLocal in break conditions: `if ch == " " { break }`
|
||||
|
||||
### Documentation
|
||||
|
||||
**Created**:
|
||||
1. ✅ `phase170-d-fix-verification.md` - Comprehensive verification report
|
||||
2. ✅ `phase170-d-fix-summary.md` - Executive summary
|
||||
3. ✅ Updated `CURRENT_TASK.md` - Bug fix section added
|
||||
4. ✅ Updated `phase170-d-impl-design.md` - Bug fix notes
|
||||
|
||||
### Next Steps
|
||||
|
||||
**Priority 1**: Pattern 5+ implementation for LoopBodyLocal in break conditions
|
||||
**Priority 2**: .hako rewrite strategy for complex method calls
|
||||
**Priority 3**: Coverage metrics for JsonParser loop support
|
||||
|
||||
**Build Status**: ✅ `cargo build --release` successful (0 errors, 50 warnings)
|
||||
|
||||
Reference in New Issue
Block a user