Files
hakorune/tools/smokes/v2/profiles/integration/selfhost/selfhost_minimal.sh
tomoaki a2c5fd90fe feat(joinir): Phase 188.3 - Pattern6 (NestedLoopMinimal) 選択ロジック実装
## Phase 188.3 進捗: Phase 2 完了 (6/13 tasks)

### 実装完了 

**Phase 1: Fixture作成**
- apps/tests/phase1883_nested_minimal.hako 追加
  - Add/Compare のみ(乗算なし)
  - 期待 exit code: 9 (3×3 nested loops)
- 既存 lowering で fallback 動作確認

**Phase 2: 選択ロジック (SSOT)**
- LoopPatternContext に step_tree_max_loop_depth フィールド追加
- choose_pattern_kind() に Pattern6 選択ロジック実装:
  1. Cheap check (has_inner_loop)
  2. StepTree 構築 (max_loop_depth 取得)
  3. AST validation (is_pattern6_lowerable)
- pattern6_nested_minimal.rs モジュール作成 (stub)
- LOOP_PATTERNS に Pattern6 entry 追加
- **検証**: Pattern6 が正しく選択される 

### 設計原則 (確認済み)

1. **Fail-Fast**: Pattern6 選択後は Ok(None) で逃げない
2. **outer 変数 write-back 検出 → validation false** (Phase 188.4+)
3. **最小実装**: inner local だけ、Pattern1 モデル二重化
4. **cfg! 依存なし**: production で動作

### 検証結果

```
[choose_pattern_kind] has_inner_loop=true
[choose_pattern_kind] max_loop_depth=2
[choose_pattern_kind] is_pattern6_lowerable=true
 Pattern6 SELECTED!
```

Stub からの期待エラー:
```
[ERROR]  [Pattern6] Nested loop lowering not yet implemented
```

### 次: Phase 3 (Lowering 実装 - 推定4時間)

残りタスク:
- Phase 3-1: AST 抽出ヘルパー
- Phase 3-2: Validation ヘルパー
- Phase 3-3: Continuation 生成 (outer_step, inner_step, k_inner_exit)
- Phase 3-4: fixture が exit=9 を返すことを検証

### 変更ファイル

**新規**:
- apps/tests/phase1883_nested_minimal.hako
- src/mir/builder/control_flow/joinir/patterns/pattern6_nested_minimal.rs
- docs/development/current/main/phases/phase-188.{1,2,3}/README.md

**変更**:
- src/mir/builder/control_flow/joinir/routing.rs (Pattern6 選択)
- src/mir/builder/control_flow/joinir/patterns/router.rs (Context 拡張)
- src/mir/builder/control_flow/joinir/patterns/mod.rs (module 宣言)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-27 05:45:12 +09:00

74 lines
2.5 KiB
Bash
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.

#!/bin/bash
# selfhost_minimal.sh — Minimal selfhost StageB→VM path using stage1_run_min.hako
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
if ROOT_GIT=$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel 2>/dev/null); then
ROOT="$ROOT_GIT"
else
ROOT="$(cd "$SCRIPT_DIR/../../../../.." && pwd)"
fi
BIN="${NYASH_BIN:-$ROOT/target/release/nyash}"
SELFHOST="$ROOT/tools/selfhost/selfhost_build.sh"
TARGET="$ROOT/apps/tests/stage1_run_min.hako"
warn() { echo -e "[WARN] $*" >&2; }
info() { echo -e "[INFO] $*" >&2; }
fail() { echo -e "[FAIL] $*" >&2; exit 1; }
pass() { echo -e "[PASS] $*" >&2; }
if [ ! -x "$BIN" ]; then
warn "[SKIP] nyash binary not found at $BIN (build release first)"
exit 0
fi
if [ ! -x "$SELFHOST" ]; then
warn "[SKIP] selfhost_build.sh missing at $SELFHOST"
exit 0
fi
if [ ! -f "$TARGET" ]; then
warn "[SKIP] target fixture not found: $TARGET"
exit 0
fi
info "Running minimal selfhost path via selfhost_build.sh"
set +e
output=$(NYASH_FEATURES="${NYASH_FEATURES:-stage3}" \
NYASH_USE_NY_COMPILER="${NYASH_USE_NY_COMPILER:-1}" \
NYASH_NY_COMPILER_EMIT_ONLY="${NYASH_NY_COMPILER_EMIT_ONLY:-1}" \
"$SELFHOST" --in "$TARGET" --run 2>&1)
rc=$?
set -e
# Phase S0: Conditional SKIP for known patterns (該当ログの時だけ)
# SSOT: docs/development/current/main/investigations/selfhost-integration-limitations.md
if [ $rc -ne 0 ]; then
# Pattern 4: Argument list too long (OS limitation)
if echo "$output" | grep -q "Argument list too long"; then
warn "[SKIP] selfhost_minimal: Pattern 4 (OS limitation - Argument list too long)"
echo "# SSOT: docs/development/current/main/investigations/selfhost-integration-limitations.md" >&2
exit 0
fi
# Pattern 1: Loop lowering failed / StepTree lowering returned None (JoinIR pattern gap)
if echo "$output" | grep -qE "(Loop lowering failed|StepTree lowering returned None)"; then
warn "[SKIP] selfhost_minimal: Pattern 1 (JoinIR loop pattern gap - Phase 188 limitation)"
echo "# SSOT: docs/development/current/main/investigations/selfhost-integration-limitations.md" >&2
exit 0
fi
# Phase 188.1: Pattern 6 (NestedLoop Minimal) now supported!
# Removed conditional SKIP - if BundleResolver.resolve/4 uses unsupported nested form,
# explicit error will occur (not SKIP)
# Unknown error - FAIL (回帰を隠さない、Fail-Fast原則)
echo "$output" >&2
fail "selfhost_minimal failed (rc=$rc) - unknown error, possible regression"
fi
pass "selfhost_minimal passed (stage1_run_min.hako)"
exit 0