chore: Phase 25.1 完了 - LoopForm v2/Stage1 CLI/環境変数削減 + Phase 26-D からの変更
Phase 25.1 完了成果: - ✅ LoopForm v2 テスト・ドキュメント・コメント完備 - 4ケース(A/B/C/D)完全テストカバレッジ - 最小再現ケース作成(SSAバグ調査用) - SSOT文書作成(loopform_ssot.md) - 全ソースに [LoopForm] コメントタグ追加 - ✅ Stage-1 CLI デバッグ環境構築 - stage1_cli.hako 実装 - stage1_bridge.rs ブリッジ実装 - デバッグツール作成(stage1_debug.sh/stage1_minimal.sh) - アーキテクチャ改善提案文書 - ✅ 環境変数削減計画策定 - 25変数の完全調査・分類 - 6段階削減ロードマップ(25→5、80%削減) - 即時削除可能変数特定(NYASH_CONFIG/NYASH_DEBUG) Phase 26-D からの累積変更: - PHI実装改善(ExitPhiBuilder/HeaderPhiBuilder等) - MIRビルダーリファクタリング - 型伝播・最適化パス改善 - その他約300ファイルの累積変更 🎯 技術的成果: - SSAバグ根本原因特定(条件分岐内loop変数変更) - Region+next_iパターン適用完了(UsingCollectorBox等) - LoopFormパターン文書化・テスト化完了 - セルフホスティング基盤強化 Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: ChatGPT <noreply@openai.com> Co-Authored-By: Task Assistant <task@anthropic.com>
This commit is contained in:
@ -45,8 +45,10 @@ pub fn ensure(builder: &mut MirBuilder, v: ValueId, kind: LocalKind) -> ValueId
|
||||
// CRITICAL: Check for errors - if block creation fails, return original value.
|
||||
if let Err(e) = builder.ensure_block_exists(bb) {
|
||||
if std::env::var("NYASH_LOCAL_SSA_TRACE").ok().as_deref() == Some("1") {
|
||||
eprintln!("[local-ssa] ensure_block_exists FAILED bb={:?} kind={:?} v=%{} err={}",
|
||||
bb, kind, v.0, e);
|
||||
eprintln!(
|
||||
"[local-ssa] ensure_block_exists FAILED bb={:?} kind={:?} v=%{} err={}",
|
||||
bb, kind, v.0, e
|
||||
);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
@ -60,7 +62,9 @@ pub fn ensure(builder: &mut MirBuilder, v: ValueId, kind: LocalKind) -> ValueId
|
||||
// and then look up the current ValueId for that slot.
|
||||
let mut slot_name_opt: Option<String> = None;
|
||||
|
||||
let names_for_v: Vec<String> = builder.variable_map.iter()
|
||||
let names_for_v: Vec<String> = builder
|
||||
.variable_map
|
||||
.iter()
|
||||
.filter(|(k, &vid)| vid == v && k.starts_with("__pin$"))
|
||||
.map(|(k, _)| k.clone())
|
||||
.collect();
|
||||
@ -77,8 +81,10 @@ pub fn ensure(builder: &mut MirBuilder, v: ValueId, kind: LocalKind) -> ValueId
|
||||
// The slot has been updated (likely by a PHI or header rewrite).
|
||||
// Use the updated value instead of the stale pinned ValueId.
|
||||
if std::env::var("NYASH_LOCAL_SSA_TRACE").ok().as_deref() == Some("1") {
|
||||
eprintln!("[local-ssa] phi-redirect bb={:?} kind={:?} slot={} %{} -> %{}",
|
||||
bb, kind, slot_name, v.0, current_val.0);
|
||||
eprintln!(
|
||||
"[local-ssa] phi-redirect bb={:?} kind={:?} slot={} %{} -> %{}",
|
||||
bb, kind, slot_name, v.0, current_val.0
|
||||
);
|
||||
}
|
||||
builder.local_ssa_map.insert(key, current_val);
|
||||
return current_val;
|
||||
@ -89,7 +95,9 @@ pub fn ensure(builder: &mut MirBuilder, v: ValueId, kind: LocalKind) -> ValueId
|
||||
let loc = builder.next_value_id();
|
||||
// CRITICAL: Check emit_instruction result - if Copy fails, return original value
|
||||
// to avoid returning undefined ValueId.
|
||||
if let Err(e) = builder.emit_instruction(crate::mir::MirInstruction::Copy { dst: loc, src: v }) {
|
||||
if let Err(e) =
|
||||
builder.emit_instruction(crate::mir::MirInstruction::Copy { dst: loc, src: v })
|
||||
{
|
||||
if std::env::var("NYASH_LOCAL_SSA_TRACE").ok().as_deref() == Some("1") {
|
||||
eprintln!("[local-ssa] emit_instruction Copy FAILED bb={:?} kind={:?} v=%{} dst=%{} err={}",
|
||||
bb, kind, v.0, loc.0, e);
|
||||
@ -98,7 +106,10 @@ pub fn ensure(builder: &mut MirBuilder, v: ValueId, kind: LocalKind) -> ValueId
|
||||
return v;
|
||||
}
|
||||
if std::env::var("NYASH_LOCAL_SSA_TRACE").ok().as_deref() == Some("1") {
|
||||
eprintln!("[local-ssa] copy bb={:?} kind={:?} %{} -> %{}", bb, kind, v.0, loc.0);
|
||||
eprintln!(
|
||||
"[local-ssa] copy bb={:?} kind={:?} %{} -> %{}",
|
||||
bb, kind, v.0, loc.0
|
||||
);
|
||||
}
|
||||
// Success: register metadata and cache
|
||||
if let Some(t) = builder.value_types.get(&v).cloned() {
|
||||
@ -115,19 +126,29 @@ pub fn ensure(builder: &mut MirBuilder, v: ValueId, kind: LocalKind) -> ValueId
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn recv(builder: &mut MirBuilder, v: ValueId) -> ValueId { ensure(builder, v, LocalKind::Recv) }
|
||||
pub fn recv(builder: &mut MirBuilder, v: ValueId) -> ValueId {
|
||||
ensure(builder, v, LocalKind::Recv)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn arg(builder: &mut MirBuilder, v: ValueId) -> ValueId { ensure(builder, v, LocalKind::Arg) }
|
||||
pub fn arg(builder: &mut MirBuilder, v: ValueId) -> ValueId {
|
||||
ensure(builder, v, LocalKind::Arg)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn cond(builder: &mut MirBuilder, v: ValueId) -> ValueId { ensure(builder, v, LocalKind::Cond) }
|
||||
pub fn cond(builder: &mut MirBuilder, v: ValueId) -> ValueId {
|
||||
ensure(builder, v, LocalKind::Cond)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn field_base(builder: &mut MirBuilder, v: ValueId) -> ValueId { ensure(builder, v, LocalKind::FieldBase) }
|
||||
pub fn field_base(builder: &mut MirBuilder, v: ValueId) -> ValueId {
|
||||
ensure(builder, v, LocalKind::FieldBase)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn cmp_operand(builder: &mut MirBuilder, v: ValueId) -> ValueId { ensure(builder, v, LocalKind::CompareOperand) }
|
||||
pub fn cmp_operand(builder: &mut MirBuilder, v: ValueId) -> ValueId {
|
||||
ensure(builder, v, LocalKind::CompareOperand)
|
||||
}
|
||||
|
||||
/// Finalize only the args (legacy Call paths)
|
||||
pub fn finalize_args(builder: &mut MirBuilder, args: &mut Vec<ValueId>) {
|
||||
@ -141,7 +162,12 @@ pub fn finalize_args(builder: &mut MirBuilder, args: &mut Vec<ValueId>) {
|
||||
pub fn finalize_branch_cond(builder: &mut MirBuilder, condition_v: &mut ValueId) {
|
||||
*condition_v = cond(builder, *condition_v);
|
||||
if std::env::var("NYASH_LOCAL_SSA_TRACE").ok().as_deref() == Some("1") {
|
||||
if let Some(bb) = builder.current_block { eprintln!("[local-ssa] finalize-branch bb={:?} cond=%{}", bb, condition_v.0); }
|
||||
if let Some(bb) = builder.current_block {
|
||||
eprintln!(
|
||||
"[local-ssa] finalize-branch bb={:?} cond=%{}",
|
||||
bb, condition_v.0
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,15 +177,33 @@ pub fn finalize_compare(builder: &mut MirBuilder, lhs: &mut ValueId, rhs: &mut V
|
||||
*lhs = cmp_operand(builder, *lhs);
|
||||
*rhs = cmp_operand(builder, *rhs);
|
||||
if std::env::var("NYASH_LOCAL_SSA_TRACE").ok().as_deref() == Some("1") {
|
||||
if let Some(bb) = builder.current_block { eprintln!("[local-ssa] finalize-compare bb={:?} lhs=%{} rhs=%{}", bb, lhs.0, rhs.0); }
|
||||
if let Some(bb) = builder.current_block {
|
||||
eprintln!(
|
||||
"[local-ssa] finalize-compare bb={:?} lhs=%{} rhs=%{}",
|
||||
bb, lhs.0, rhs.0
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Finalize field use sites: ensure base and all args are in the current block.
|
||||
pub fn finalize_field_base_and_args(builder: &mut MirBuilder, base: &mut ValueId, args: &mut Vec<ValueId>) {
|
||||
pub fn finalize_field_base_and_args(
|
||||
builder: &mut MirBuilder,
|
||||
base: &mut ValueId,
|
||||
args: &mut Vec<ValueId>,
|
||||
) {
|
||||
*base = field_base(builder, *base);
|
||||
for a in args.iter_mut() { *a = arg(builder, *a); }
|
||||
for a in args.iter_mut() {
|
||||
*a = arg(builder, *a);
|
||||
}
|
||||
if std::env::var("NYASH_LOCAL_SSA_TRACE").ok().as_deref() == Some("1") {
|
||||
if let Some(bb) = builder.current_block { eprintln!("[local-ssa] finalize-field bb={:?} base=%{} argc={}", bb, base.0, args.len()); }
|
||||
if let Some(bb) = builder.current_block {
|
||||
eprintln!(
|
||||
"[local-ssa] finalize-field bb={:?} base=%{} argc={}",
|
||||
bb,
|
||||
base.0,
|
||||
args.len()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user