Files
hakorune/src/mir/builder/emission/constant.rs
nyash-codex 40dfbc68a8 feat(constant): Phase 84-1 Add type annotations for all constant types
Const命令の型アノテーション欠如を根本的に修正。

## 変更内容

5つの emit 関数に型登録を追加:
- emit_integer → MirType::Integer
- emit_bool → MirType::Bool
- emit_float → MirType::Float
- emit_null → MirType::Unknown (Null型が存在しないため)
- emit_void → MirType::Void

emit_string は既に実装済み (Phase 3-A)。

## 成果

- Case D 大幅削減 (詳細は Phase 84 テスト結果で確認)
- 残り 12 件は edge copy / loop break/continue 関連
- Task先生予測の GroupA (Const欠如) を完全解決

## 設計原則

emit_string と同じパターンを踏襲:
```rust
b.value_types.insert(dst, crate::mir::MirType::Integer);
```

## 次のステップ

Phase 84-2: Copy命令型伝播の徹底

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-02 18:42:21 +09:00

84 lines
2.5 KiB
Rust

//! ConstantEmissionBox — Const 命令の発行を集約(仕様不変)
//!
//! ✅ Phase 25.1b Fix: All constant emission now uses function-local ID generator
//! when inside a function context to ensure proper SSA verification.
use crate::mir::builder::MirBuilder;
use crate::mir::{ConstValue, MirInstruction, ValueId};
#[inline]
pub fn emit_integer(b: &mut MirBuilder, val: i64) -> ValueId {
let dst = b.next_value_id();
let _ = b.emit_instruction(MirInstruction::Const {
dst,
value: ConstValue::Integer(val),
});
// Phase 84-1: Integer constant type annotation
b.value_types.insert(dst, crate::mir::MirType::Integer);
dst
}
#[inline]
pub fn emit_bool(b: &mut MirBuilder, val: bool) -> ValueId {
let dst = b.next_value_id();
let _ = b.emit_instruction(MirInstruction::Const {
dst,
value: ConstValue::Bool(val),
});
// Phase 84-1: Bool constant type annotation
b.value_types.insert(dst, crate::mir::MirType::Bool);
dst
}
#[inline]
pub fn emit_float(b: &mut MirBuilder, val: f64) -> ValueId {
let dst = b.next_value_id();
let _ = b.emit_instruction(MirInstruction::Const {
dst,
value: ConstValue::Float(val),
});
// Phase 84-1: Float constant type annotation
b.value_types.insert(dst, crate::mir::MirType::Float);
dst
}
#[inline]
pub fn emit_string<S: Into<String>>(b: &mut MirBuilder, s: S) -> ValueId {
let dst = b.next_value_id();
let _ = b.emit_instruction(MirInstruction::Const {
dst,
value: ConstValue::String(s.into()),
});
// 🎯 Phase 3-A: String constant type annotation
// Ensures string constants have proper Box type for method resolution
b.value_types
.insert(dst, crate::mir::MirType::Box("StringBox".to_string()));
b.value_origin_newbox.insert(dst, "StringBox".to_string());
dst
}
#[inline]
pub fn emit_null(b: &mut MirBuilder) -> ValueId {
let dst = b.next_value_id();
let _ = b.emit_instruction(MirInstruction::Const {
dst,
value: ConstValue::Null,
});
// Phase 84-1: Null constant type annotation
// Note: MirType has no Null variant, using Unknown as fallback
b.value_types.insert(dst, crate::mir::MirType::Unknown);
dst
}
#[inline]
pub fn emit_void(b: &mut MirBuilder) -> ValueId {
let dst = b.next_value_id();
let _ = b.emit_instruction(MirInstruction::Const {
dst,
value: ConstValue::Void,
});
// Phase 84-1: Void constant type annotation
b.value_types.insert(dst, crate::mir::MirType::Void);
dst
}