|
|
e0fb6fecf6
|
refactor(llvm): Phase 132-P1 - FunctionLowerContext Box isolation
Structural fix for cross-function state leakage bugs discovered in Phase 131-132.
Problem:
- Function-local state (block_end_values, def_blocks, phi_manager, caches)
was globally managed, causing collisions across functions
- Required manual clearing via _clear_function_local_state() (~80 lines)
- Tuple-key workaround (func_name, block_id) added complexity
Solution: FunctionLowerContext Box
- Encapsulates all function-scoped state in a dedicated Box
- Automatic lifetime management (created at entry, destroyed at exit)
- Eliminates manual state clearing
- Simplifies from tuple-key to simple block_id access
Implementation:
1. Created src/llvm_py/context/function_lower_context.py (150+ lines)
- block_end_values, def_blocks, jump_only_blocks
- phi_manager, resolver_caches
- Helper methods: get/set_block_snapshot(), register_def(), etc.
2. Updated function_lower.py
- Creates context at function entry
- Binds resolver to context for cache isolation
- Removed _clear_function_local_state() (~80 lines)
3. Updated block_lower.py
- Changed tuple-key (func_name, block_id) to simple block_id
- Access via context.get_block_snapshot() / context.set_block_snapshot()
4. Updated resolver.py, phi_wiring/wiring.py, phi_wiring/tagging.py
- All state access now through context
5. Fixed critical bug in phi_wiring/tagging.py
- setup_phi_placeholders() was breaking context connection
- Changed reassignment to .clear()/.update() to preserve reference
Benefits:
- ✅ Automatic state isolation (no manual clearing)
- ✅ Clear ownership (one context per function)
- ✅ Eliminated tuple-keys (simpler code)
- ✅ Prevents bugs by design (cross-function leakage impossible)
Test results:
- ✅ Phase 87 smoke test: PASS
- ✅ Phase 132 smoke test: PASS (both cases)
- ✅ STRICT mode: Works with multi-function inputs
- ✅ No regression
Files modified: 8 (2 new, 6 updated)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
2025-12-15 11:26:10 +09:00 |
|