Files
hakorune/docs/development/current/main/investigations
tomoaki 757193891f feat(llvm/phi): Phase 277 P1 - fail-fast validation for PHI strict mode
## Summary
Implemented fail-fast validation for PHI ordering and value resolution in strict mode.

## Changes

### P1-1: Strict mode for "PHI after terminator"
- File: `src/llvm_py/phi_wiring/wiring.py::ensure_phi`
- Behavior: `NYASH_LLVM_PHI_STRICT=1` → RuntimeError if PHI created after terminator
- Default: Warning only (no regression)

### P1-2: Strict mode for "fallback 0"
- File: `src/llvm_py/phi_wiring/wiring.py::wire_incomings`
- Behavior: Strict mode forbids silent fallback to 0 (2 locations)
  - Location 1: Unresolvable incoming value
  - Location 2: Type coercion failure
- Error messages point to next debug file: `llvm_builder.py::_value_at_end_i64`

### P1-3: Connect verify_phi_ordering() to execution path
- File: `src/llvm_py/builders/function_lower.py`
- Behavior: Verify PHI ordering after all instructions emitted
- Debug mode: Shows " All N blocks have correct PHI ordering"
- Strict mode: Raises RuntimeError with block list if violations found

## Testing
 Test 1: strict=OFF - passes without errors
 Test 2: strict=ON - passes without errors (no violations in test fixtures)
 Test 3: debug mode - verify_phi_ordering() connected and running

## Scope
- LLVM harness (Python) changes only
- No new environment variables (uses existing 3 from Phase 277 P2)
- No JoinIR/Rust changes (root fix is Phase 279)
- Default behavior unchanged (strict mode opt-in)

## Next Steps
- Phase 278: Remove deprecated env var support
- Phase 279: Root fix - unify "2本のコンパイラ" pipelines

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-22 14:48:37 +09:00
..

Investigations Folder

This folder contains investigation notes and analysis for debugging sessions.

Active Investigations

Phase 131-12: LLVM Wrong Result (Case C)

Status: Root cause identified Problem: LLVM backend returns wrong results for loop exit values Root Cause: vmap object identity mismatch between Pass A and Pass C

Key Documents:

  1. phase131-12-case-c-llvm-wrong-result.md - Initial investigation scope
  2. phase131-12-p1-vmap-identity-analysis.md - Detailed trace analysis
  3. phase131-12-p1-trace-summary.md - Executive summary with fix recommendations

Quick Summary:

  • Bug: Pass A deletes _current_vmap before Pass C runs
  • Impact: Terminators use wrong vmap object, missing all Pass A writes
  • Fix: Store vmap_cur in deferred_terminators tuple (Option 3)

Next Steps:

  1. Implement Option 3 fix in block_lower.py
  2. Add Fail-Fast check in instruction_lower.py
  3. Verify with NYASH_LLVM_VMAP_TRACE=1
  4. Run full test suite

Trace Environment Variables

Phase 131-12-P1 Traces

NYASH_LLVM_VMAP_TRACE=1    # Object identity and vmap keys tracing
NYASH_LLVM_USE_HARNESS=1   # Enable llvmlite harness
NYASH_LLVM_DUMP_IR=<path>  # Save LLVM IR to file

Investigation Workflow

  1. Scope - Define problem and test case (phase131-12-case-c-*.md)
  2. Trace - Add instrumentation and collect data (phase131-12-p1-vmap-identity-*.md)
  3. Analysis - Identify root cause with evidence (phase131-12-p1-trace-summary.md)
  4. Fix - Implement solution with validation
  5. Document - Update investigation notes with results

Archive

Completed investigations are kept for reference and pattern recognition.

JoinIR Generalization Study (Historical)

  • joinir-generalization-study.mdPhase 131138 の状況と一般化案の相談用コンテキスト。SSOT は design/ を参照)