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:
@ -1,10 +1,8 @@
|
||||
use super::merge::new_block;
|
||||
use super::BridgeEnv;
|
||||
use super::ternary;
|
||||
use super::match_expr;
|
||||
use crate::mir::{
|
||||
BasicBlockId, ConstValue, EffectMask, MirFunction, MirInstruction, ValueId,
|
||||
};
|
||||
use super::merge::new_block;
|
||||
use super::ternary;
|
||||
use super::BridgeEnv;
|
||||
use crate::mir::{BasicBlockId, ConstValue, EffectMask, MirFunction, MirInstruction, ValueId};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use super::super::ast::ExprV0;
|
||||
@ -140,7 +138,10 @@ fn lower_throw(
|
||||
} else {
|
||||
let dst = f.next_value_id();
|
||||
if let Some(bb) = f.get_block_mut(cur_bb) {
|
||||
bb.add_instruction(MirInstruction::Const { dst, value: ConstValue::Integer(0) });
|
||||
bb.add_instruction(MirInstruction::Const {
|
||||
dst,
|
||||
value: ConstValue::Integer(0),
|
||||
});
|
||||
}
|
||||
(dst, cur_bb)
|
||||
}
|
||||
@ -264,8 +265,15 @@ pub(super) fn lower_expr_with_scope<S: VarScope>(
|
||||
// );
|
||||
let cdst = f.next_value_id();
|
||||
if let Some(bb) = f.get_block_mut(fall_bb) {
|
||||
let cval = if is_and { ConstValue::Bool(false) } else { ConstValue::Bool(true) };
|
||||
bb.add_instruction(MirInstruction::Const { dst: cdst, value: cval });
|
||||
let cval = if is_and {
|
||||
ConstValue::Bool(false)
|
||||
} else {
|
||||
ConstValue::Bool(true)
|
||||
};
|
||||
bb.add_instruction(MirInstruction::Const {
|
||||
dst: cdst,
|
||||
value: cval,
|
||||
});
|
||||
}
|
||||
crate::mir::ssot::cf_common::set_jump(f, fall_bb, merge_bb);
|
||||
let (rval, rhs_end) = lower_expr_with_scope(env, f, rhs_bb, rhs, vars)?;
|
||||
@ -277,7 +285,11 @@ pub(super) fn lower_expr_with_scope<S: VarScope>(
|
||||
let out = f.next_value_id();
|
||||
// フェーズM.2: PHI統一処理(no_phi分岐削除)
|
||||
let mut inputs: Vec<(BasicBlockId, ValueId)> = vec![(fall_bb, cdst)];
|
||||
if rhs_end != fall_bb { inputs.push((rhs_end, rval)); } else { inputs.push((fall_bb, rval)); }
|
||||
if rhs_end != fall_bb {
|
||||
inputs.push((rhs_end, rval));
|
||||
} else {
|
||||
inputs.push((fall_bb, rval));
|
||||
}
|
||||
crate::mir::ssot::cf_common::insert_phi_at_head(f, merge_bb, out, inputs);
|
||||
Ok((out, merge_bb))
|
||||
}
|
||||
@ -346,7 +358,10 @@ pub(super) fn lower_expr_with_scope<S: VarScope>(
|
||||
let (arg_ids, cur) = lower_args_with_scope(env, f, cur_bb, args, vars)?;
|
||||
let fun_val = f.next_value_id();
|
||||
if let Some(bb) = f.get_block_mut(cur) {
|
||||
bb.add_instruction(MirInstruction::Const { dst: fun_val, value: ConstValue::String(name.clone()) });
|
||||
bb.add_instruction(MirInstruction::Const {
|
||||
dst: fun_val,
|
||||
value: ConstValue::String(name.clone()),
|
||||
});
|
||||
}
|
||||
let dst = f.next_value_id();
|
||||
if let Some(bb) = f.get_block_mut(cur) {
|
||||
@ -361,8 +376,10 @@ pub(super) fn lower_expr_with_scope<S: VarScope>(
|
||||
Ok((dst, cur))
|
||||
}
|
||||
ExprV0::Method { recv, method, args } => {
|
||||
let recv_is_console_new = matches!(&**recv, ExprV0::New { class, .. } if class == "ConsoleBox");
|
||||
if recv_is_console_new && (method == "println" || method == "print" || method == "log") {
|
||||
let recv_is_console_new =
|
||||
matches!(&**recv, ExprV0::New { class, .. } if class == "ConsoleBox");
|
||||
if recv_is_console_new && (method == "println" || method == "print" || method == "log")
|
||||
{
|
||||
let (arg_ids, cur2) = lower_args_with_scope(env, f, cur_bb, args, vars)?;
|
||||
let dst = f.next_value_id();
|
||||
if let Some(bb) = f.get_block_mut(cur2) {
|
||||
@ -378,11 +395,16 @@ pub(super) fn lower_expr_with_scope<S: VarScope>(
|
||||
}
|
||||
// Phase 25.1b: Handle env.box_introspect.kind(value) pattern
|
||||
// Pattern: Method { recv: Method { recv: Var("env"), method: "box_introspect" }, method: "kind", args }
|
||||
if let ExprV0::Method { recv: inner_recv, method: inner_method, args: inner_args } = &**recv {
|
||||
if let ExprV0::Method {
|
||||
recv: inner_recv,
|
||||
method: inner_method,
|
||||
args: inner_args,
|
||||
} = &**recv
|
||||
{
|
||||
if matches!(&**inner_recv, ExprV0::Var { name } if name == "env")
|
||||
&& inner_method == "box_introspect"
|
||||
&& inner_args.is_empty() {
|
||||
|
||||
&& inner_args.is_empty()
|
||||
{
|
||||
// Lower args for the final method call
|
||||
let (arg_ids, cur2) = lower_args_with_scope(env, f, cur_bb, args, vars)?;
|
||||
let dst = f.next_value_id();
|
||||
@ -418,7 +440,11 @@ pub(super) fn lower_expr_with_scope<S: VarScope>(
|
||||
let (arg_ids, cur) = lower_args_with_scope(env, f, cur_bb, args, vars)?;
|
||||
let dst = f.next_value_id();
|
||||
if let Some(bb) = f.get_block_mut(cur) {
|
||||
bb.add_instruction(MirInstruction::NewBox { dst, box_type: class.clone(), args: arg_ids });
|
||||
bb.add_instruction(MirInstruction::NewBox {
|
||||
dst,
|
||||
box_type: class.clone(),
|
||||
args: arg_ids,
|
||||
});
|
||||
}
|
||||
Ok((dst, cur))
|
||||
}
|
||||
@ -430,10 +456,14 @@ pub(super) fn lower_expr_with_scope<S: VarScope>(
|
||||
let (exc, cur) = lower_expr_with_scope(env, f, cur_bb, expr, vars)?;
|
||||
Ok(lower_throw(env, f, cur, exc))
|
||||
}
|
||||
ExprV0::Ternary { cond, then, r#else } =>
|
||||
ternary::lower_ternary_expr_with_scope(env, f, cur_bb, cond, then, r#else, vars),
|
||||
ExprV0::Match { scrutinee, arms, r#else } =>
|
||||
match_expr::lower_match_expr_with_scope(env, f, cur_bb, scrutinee, arms, r#else, vars),
|
||||
ExprV0::Ternary { cond, then, r#else } => {
|
||||
ternary::lower_ternary_expr_with_scope(env, f, cur_bb, cond, then, r#else, vars)
|
||||
}
|
||||
ExprV0::Match {
|
||||
scrutinee,
|
||||
arms,
|
||||
r#else,
|
||||
} => match_expr::lower_match_expr_with_scope(env, f, cur_bb, scrutinee, arms, r#else, vars),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user