feat(mir): Phase 25.1f完了 - Conservative PHI + ControlForm観測レイヤー
🎉 Conservative PHI Box理論による完全SSA構築 **Phase 7-B: Conservative PHI実装** - 片方branchのみ定義変数に対応(emit_void使用) - 全変数にPHI生成(Conservative Box理論) - Stage-1 resolver全テスト緑化(3/3 PASS) **Phase 25.1f: ControlForm観測レイヤー** - LoopShape/IfShape/ControlForm構造定義 - Loop/If統一インターフェース実装 - debug_dump/debug_validate機能追加 - NYASH_CONTROL_FORM_TRACE環境変数対応 **主な変更**: - src/mir/builder/phi.rs: Conservative PHI実装 - src/mir/control_form.rs: ControlForm構造(NEW) - src/mir/loop_builder.rs: LoopForm v2デフォルト化 **テスト結果**: ✅ mir_stage1_using_resolver_min_fragment_verifies ✅ mir_stage1_using_resolver_full_collect_entries_verifies ✅ mir_parserbox_parse_program2_harness_parses_minimal_source 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: ChatGPT <chatgpt@openai.com>
This commit is contained in:
@ -36,9 +36,6 @@ impl MirInterpreter {
|
||||
let saved_fn = self.cur_fn.clone();
|
||||
self.cur_fn = Some(func.signature.name.clone());
|
||||
|
||||
// Check if this is a static box method call
|
||||
let static_box_name = self.is_static_box_method(&func.signature.name);
|
||||
|
||||
match arg_vals {
|
||||
Some(args) => {
|
||||
// Regular parameter binding: params and args are 1:1
|
||||
|
||||
@ -278,6 +278,7 @@ impl MirInterpreter {
|
||||
}
|
||||
|
||||
// moved: try_handle_map_box → handlers/boxes_map.rs
|
||||
#[allow(dead_code)]
|
||||
fn try_handle_map_box(
|
||||
&mut self,
|
||||
dst: Option<ValueId>,
|
||||
@ -289,6 +290,7 @@ impl MirInterpreter {
|
||||
}
|
||||
|
||||
// moved: try_handle_string_box → handlers/boxes_string.rs
|
||||
#[allow(dead_code)]
|
||||
fn try_handle_string_box(
|
||||
&mut self,
|
||||
dst: Option<ValueId>,
|
||||
@ -300,6 +302,7 @@ impl MirInterpreter {
|
||||
}
|
||||
|
||||
// moved: try_handle_array_box → handlers/boxes_array.rs
|
||||
#[allow(dead_code)]
|
||||
fn try_handle_array_box(
|
||||
&mut self,
|
||||
dst: Option<ValueId>,
|
||||
|
||||
@ -102,7 +102,7 @@ pub(super) fn try_handle_instance_box(
|
||||
} else {
|
||||
// Conservative fallback: search unique function by name tail ".method/arity"
|
||||
let tail = format!(".{}{}", method, format!("/{}", args.len()));
|
||||
let mut cands: Vec<String> = this
|
||||
let cands: Vec<String> = this
|
||||
.functions
|
||||
.keys()
|
||||
.filter(|k| k.ends_with(&tail))
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
use super::*;
|
||||
use crate::box_trait::NyashBox;
|
||||
|
||||
pub(super) fn try_handle_object_fields(
|
||||
this: &mut MirInterpreter,
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
use super::*;
|
||||
use crate::box_trait::NyashBox;
|
||||
|
||||
pub(super) fn try_handle_string_box(
|
||||
this: &mut MirInterpreter,
|
||||
|
||||
@ -3,6 +3,7 @@ use serde_json::Value as JsonValue;
|
||||
|
||||
impl MirInterpreter {
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
fn ensure_mir_json_version_field(s: &str) -> String {
|
||||
match serde_json::from_str::<JsonValue>(s) {
|
||||
Ok(mut v) => {
|
||||
@ -28,6 +29,12 @@ impl MirInterpreter {
|
||||
let mbase = super::super::utils::normalize_arity_suffix(method);
|
||||
match (iface, mbase) {
|
||||
("env", "get") => {
|
||||
// Prefer provider-based resolution when available, fall back to process env.
|
||||
if let Some(provider_res) = self.extern_provider_dispatch("env.get", args) {
|
||||
let result = provider_res?;
|
||||
self.write_result(dst, result);
|
||||
return Ok(());
|
||||
}
|
||||
if let Some(a0) = args.get(0) {
|
||||
let key = self.reg_load(*a0)?.to_string();
|
||||
let val = std::env::var(&key).ok();
|
||||
@ -135,14 +142,6 @@ impl MirInterpreter {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
("env", "get") => {
|
||||
// Delegate to provider
|
||||
let ret = self
|
||||
.extern_provider_dispatch("env.get", args)
|
||||
.unwrap_or(Ok(VMValue::Void))?;
|
||||
self.write_result(dst, ret);
|
||||
Ok(())
|
||||
}
|
||||
("env", "set") => {
|
||||
// Delegate to provider
|
||||
let ret = self
|
||||
|
||||
@ -110,6 +110,7 @@ impl MirInterpreter {
|
||||
|
||||
/// Check if a function name represents a static box method
|
||||
/// Format: "BoxName.method/Arity"
|
||||
#[allow(dead_code)]
|
||||
fn is_static_box_method(&self, func_name: &str) -> Option<String> {
|
||||
if let Some((box_name, _rest)) = func_name.split_once('.') {
|
||||
if self.static_box_decls.contains_key(box_name) {
|
||||
|
||||
@ -44,6 +44,7 @@ impl MirInterpreter {
|
||||
/// # Returns
|
||||
/// 引数数が範囲内の場合はOk(())、そうでない場合はエラー
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn validate_args_range(
|
||||
&self,
|
||||
method: &str,
|
||||
@ -71,6 +72,7 @@ impl MirInterpreter {
|
||||
/// # Returns
|
||||
/// 引数数が最小値以上の場合はOk(())、そうでない場合はエラー
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn validate_args_min(
|
||||
&self,
|
||||
method: &str,
|
||||
|
||||
@ -42,6 +42,7 @@ impl MirInterpreter {
|
||||
/// # Errors
|
||||
/// * 値が整数でない場合はエラー
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn load_as_int(&mut self, vid: ValueId) -> Result<i64, VMError> {
|
||||
match self.reg_load(vid)? {
|
||||
VMValue::Integer(i) => Ok(i),
|
||||
@ -71,6 +72,7 @@ impl MirInterpreter {
|
||||
/// # Errors
|
||||
/// * 値がboolでない場合はエラー
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn load_as_bool(&mut self, vid: ValueId) -> Result<bool, VMError> {
|
||||
match self.reg_load(vid)? {
|
||||
VMValue::Bool(b) => Ok(b),
|
||||
@ -112,6 +114,7 @@ impl MirInterpreter {
|
||||
/// # Returns
|
||||
/// * `Result<Vec<VMValue>, VMError>` - 読み込んだVMValueのVec
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn load_args_as_values(
|
||||
&mut self,
|
||||
vids: &[ValueId],
|
||||
|
||||
@ -13,6 +13,7 @@ impl MirInterpreter {
|
||||
/// * `dst` - 書き込み先のValueId (Noneの場合は何もしない)
|
||||
/// * `result` - 書き込むBox
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn write_box_result(
|
||||
&mut self,
|
||||
dst: Option<ValueId>,
|
||||
|
||||
@ -40,6 +40,7 @@ impl ErrorBuilder {
|
||||
/// // => "get expects Integer type, got String"
|
||||
/// ```
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub fn type_mismatch(method: &str, expected: &str, actual: &str) -> VMError {
|
||||
VMError::InvalidInstruction(format!("{} expects {} type, got {}", method, expected, actual))
|
||||
}
|
||||
@ -57,6 +58,7 @@ impl ErrorBuilder {
|
||||
/// // => "get index out of bounds: 5 >= 3"
|
||||
/// ```
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub fn out_of_bounds(method: &str, index: usize, len: usize) -> VMError {
|
||||
VMError::InvalidInstruction(format!("{} index out of bounds: {} >= {}", method, index, len))
|
||||
}
|
||||
@ -93,6 +95,7 @@ impl ErrorBuilder {
|
||||
/// // => "receiver must be ArrayBox"
|
||||
/// ```
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub fn receiver_type_error(expected: &str) -> VMError {
|
||||
VMError::InvalidInstruction(format!("receiver must be {}", expected))
|
||||
}
|
||||
@ -123,6 +126,7 @@ impl ErrorBuilder {
|
||||
/// // => "link_object expects at least 1 arg, got 0"
|
||||
/// ```
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub fn arg_count_min(method: &str, min: usize, actual: usize) -> VMError {
|
||||
VMError::InvalidInstruction(format!(
|
||||
"{} expects at least {} arg{}, got {}",
|
||||
@ -153,6 +157,7 @@ impl ErrorBuilder {
|
||||
/// // => "link_object: <error message>"
|
||||
/// ```
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub fn from_error(operation: &str, error: &dyn std::error::Error) -> VMError {
|
||||
VMError::InvalidInstruction(format!("{}: {}", operation, error))
|
||||
}
|
||||
@ -178,6 +183,7 @@ impl super::super::MirInterpreter {
|
||||
/// return Err(self.err_type_mismatch("get", "Integer", actual_type));
|
||||
/// ```
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn err_type_mismatch(&self, method: &str, expected: &str, actual: &str) -> VMError {
|
||||
ErrorBuilder::type_mismatch(method, expected, actual)
|
||||
}
|
||||
@ -189,6 +195,7 @@ impl super::super::MirInterpreter {
|
||||
/// return Err(self.err_out_of_bounds("get", idx, len));
|
||||
/// ```
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn err_out_of_bounds(&self, method: &str, index: usize, len: usize) -> VMError {
|
||||
ErrorBuilder::out_of_bounds(method, index, len)
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@ impl MirInterpreter {
|
||||
/// # Returns
|
||||
/// 変換成功時はBox、失敗時はエラー
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn convert_to_box(
|
||||
&mut self,
|
||||
receiver: ValueId,
|
||||
|
||||
@ -33,7 +33,10 @@ impl BenchmarkSuite {
|
||||
|
||||
/// Run comprehensive benchmark across all backends
|
||||
pub fn run_all(&self) -> Vec<BenchmarkResult> {
|
||||
#[cfg(feature = "wasm-backend")]
|
||||
let mut results = Vec::new();
|
||||
#[cfg(not(feature = "wasm-backend"))]
|
||||
let results = Vec::new();
|
||||
|
||||
let benchmarks = [
|
||||
("bench_light", "benchmarks/bench_light.hako"),
|
||||
@ -45,14 +48,14 @@ impl BenchmarkSuite {
|
||||
println!("🚀 Running benchmark: {}", name);
|
||||
|
||||
// Test if file exists and is readable
|
||||
if let Ok(source) = fs::read_to_string(file_path) {
|
||||
if let Ok(_source) = fs::read_to_string(file_path) {
|
||||
// Run on all backends
|
||||
// Interpreter benchmark removed with legacy interpreter
|
||||
|
||||
// VM benchmark removed with vm-legacy
|
||||
|
||||
#[cfg(feature = "wasm-backend")]
|
||||
if let Ok(wasm_result) = self.run_wasm_benchmark(name, &source) {
|
||||
if let Ok(wasm_result) = self.run_wasm_benchmark(name, &_source) {
|
||||
results.push(wasm_result);
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -27,7 +27,6 @@ mod static_ops;
|
||||
|
||||
pub use helpers::{concat_result, can_repeat};
|
||||
pub use macros::impl_static_numeric_ops;
|
||||
use crate::operator_traits::{NyashAdd, NyashMul};
|
||||
|
||||
// Phase 2: Static implementations are now in static_ops.rs
|
||||
|
||||
@ -514,6 +513,7 @@ impl OperatorResolver {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::operator_traits::{NyashAdd, NyashMul};
|
||||
|
||||
#[test]
|
||||
fn test_integer_addition() {
|
||||
|
||||
@ -11,14 +11,14 @@ use crate::impl_static_numeric_ops;
|
||||
|
||||
// ===== Macro-generated static implementations =====
|
||||
|
||||
/// Static numeric operations for IntegerBox
|
||||
///
|
||||
/// Generates implementations for: Add, Sub, Mul, Div with zero-division error handling
|
||||
// Static numeric operations for IntegerBox
|
||||
//
|
||||
// Generates implementations for: Add, Sub, Mul, Div with zero-division error handling
|
||||
impl_static_numeric_ops!(IntegerBox, 0);
|
||||
|
||||
/// Static numeric operations for FloatBox
|
||||
///
|
||||
/// Generates implementations for: Add, Sub, Mul, Div with zero-division error handling
|
||||
// Static numeric operations for FloatBox
|
||||
//
|
||||
// Generates implementations for: Add, Sub, Mul, Div with zero-division error handling
|
||||
impl_static_numeric_ops!(FloatBox, 0.0);
|
||||
|
||||
// ===== Manual static implementations for special cases =====
|
||||
@ -57,4 +57,4 @@ impl NyashAdd<BoolBox> for BoolBox {
|
||||
}
|
||||
|
||||
// Note: Additional static implementations can be added here as needed
|
||||
// for cross-type operations or special Box types
|
||||
// for cross-type operations or special Box types
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
//! Implements modulo operations between integer types with error handling.
|
||||
|
||||
use crate::box_trait::{BoolBox, BoxBase, BoxCore, IntegerBox, NyashBox, StringBox};
|
||||
use std::any::Any;
|
||||
use std::fmt::{Debug, Display};
|
||||
|
||||
/// Modulo operations between boxes
|
||||
@ -124,4 +123,4 @@ impl Display for ModuloBox {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
self.fmt_box(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ use crate::runner;
|
||||
use serde_json::Value as JsonValue;
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
use std::io::Write;
|
||||
// use std::io::Write; // kept for future pretty-print extensions
|
||||
|
||||
/// Convert Program(JSON v0) to MIR(JSON v0) and return it as a String.
|
||||
/// Fail-Fast: prints stable tags on stderr and returns Err with the same tag text.
|
||||
@ -52,7 +52,7 @@ pub fn program_json_to_mir_json_with_imports(program_json: &str, imports: HashMa
|
||||
let _ = fs::remove_file(&tmp_path);
|
||||
// Ensure v1 schema: if output lacks schema_version but has functions, wrap minimally
|
||||
let s = match serde_json::from_str::<JsonValue>(&s0) {
|
||||
Ok(JsonValue::Object(mut m)) => {
|
||||
Ok(JsonValue::Object(m)) => {
|
||||
if m.get("schema_version").is_none() {
|
||||
if let Some(funcs) = m.get("functions").cloned() {
|
||||
let v1 = serde_json::json!({"schema_version":"1.0","functions": funcs});
|
||||
|
||||
@ -510,11 +510,11 @@ impl MirBuilder {
|
||||
let mut instruction = instruction;
|
||||
|
||||
// Precompute debug metadata to avoid borrow conflicts later
|
||||
let dbg_fn_name = self
|
||||
let _dbg_fn_name = self
|
||||
.current_function
|
||||
.as_ref()
|
||||
.map(|f| f.signature.name.clone());
|
||||
let dbg_region_id = self.debug_current_region_id();
|
||||
let _dbg_region_id = self.debug_current_region_id();
|
||||
// P0: PHI の軽量補強と観測は、関数ブロック取得前に実施して借用競合を避ける
|
||||
if let MirInstruction::Phi { dst, inputs } = &instruction {
|
||||
origin::phi::propagate_phi_meta(self, *dst, inputs);
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
//! 4. ✅ 巨大関数は分割: 100行超える関数を30-50行目標で分割
|
||||
|
||||
// Import from new modules (refactored with Box Theory)
|
||||
use super::calls::*;
|
||||
pub use super::calls::call_target::CallTarget;
|
||||
|
||||
// ========================================
|
||||
|
||||
@ -46,6 +46,7 @@ pub fn suggest_resolution(name: &str) -> String {
|
||||
|
||||
/// Check if a method name is commonly shadowed by global functions
|
||||
/// Used for generating warnings about potential self-recursion
|
||||
#[allow(dead_code)]
|
||||
pub fn is_commonly_shadowed_method(method: &str) -> bool {
|
||||
matches!(
|
||||
method,
|
||||
@ -57,6 +58,7 @@ pub fn is_commonly_shadowed_method(method: &str) -> bool {
|
||||
}
|
||||
|
||||
/// Generate warning message for potential self-recursion
|
||||
#[allow(dead_code)]
|
||||
pub fn generate_self_recursion_warning(box_name: &str, method: &str) -> String {
|
||||
format!(
|
||||
"Warning: Potential self-recursion detected in {}.{}(). \
|
||||
@ -102,4 +104,4 @@ mod tests {
|
||||
assert!(warning.contains("::print()"));
|
||||
assert!(warning.contains("self-recursion"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,11 +5,8 @@
|
||||
* Replaces 6 different call instructions with a single unified system
|
||||
*/
|
||||
|
||||
use crate::mir::{Callee, Effect, EffectMask, ValueId};
|
||||
use crate::mir::definitions::call_unified::{CallFlags, MirCall, TypeCertainty};
|
||||
use super::call_target::CallTarget;
|
||||
use super::method_resolution;
|
||||
use super::extern_calls;
|
||||
use crate::mir::{Callee, EffectMask, ValueId};
|
||||
use crate::mir::definitions::call_unified::{CallFlags, MirCall};
|
||||
|
||||
/// Check if unified call system is enabled
|
||||
pub fn is_unified_call_enabled() -> bool {
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
//! - emit_legacy_call: レガシーCall発行(既存互換)
|
||||
//! - emit_global_call/emit_method_call/emit_constructor_call: 便利ラッパー
|
||||
|
||||
use super::super::{Effect, EffectMask, MirBuilder, MirInstruction, ValueId};
|
||||
use super::super::{EffectMask, MirBuilder, MirInstruction, ValueId};
|
||||
use crate::mir::definitions::call_unified::Callee;
|
||||
use super::{CallTarget, call_unified};
|
||||
use super::CallTarget;
|
||||
|
||||
impl MirBuilder {
|
||||
/// Unified call emission - delegates to UnifiedCallEmitterBox
|
||||
@ -139,6 +139,7 @@ impl MirBuilder {
|
||||
// ========================================
|
||||
|
||||
/// Try fallback handlers for global functions (delegates to CallMaterializerBox)
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn try_global_fallback_handlers(
|
||||
&mut self,
|
||||
dst: Option<ValueId>,
|
||||
@ -149,6 +150,7 @@ impl MirBuilder {
|
||||
}
|
||||
|
||||
/// Ensure receiver is materialized in Callee::Method (delegates to CallMaterializerBox)
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn materialize_receiver_in_callee(
|
||||
&mut self,
|
||||
callee: Callee,
|
||||
|
||||
@ -155,6 +155,7 @@ pub fn parse_extern_name(name: &str) -> (String, String) {
|
||||
}
|
||||
|
||||
/// Check if a name refers to an environment interface
|
||||
#[allow(dead_code)]
|
||||
pub fn is_env_interface(name: &str) -> bool {
|
||||
matches!(name,
|
||||
"env" | "env.console" | "env.fs" | "env.net" |
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
/*!
|
||||
* Function Lowering Utilities
|
||||
*
|
||||
@ -147,4 +149,4 @@ pub fn method_likely_returns_value(method_name: &str) -> bool {
|
||||
"add" | "sub" | "mul" | "div" |
|
||||
"min" | "max" | "abs"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,6 +96,7 @@ impl<'a> CalleeGuardBox<'a> {
|
||||
/// receiver型の検証(ヘルパー)
|
||||
///
|
||||
/// 指定されたreceiverがBox型を持っているか確認
|
||||
#[allow(dead_code)]
|
||||
pub fn has_box_type(&self, receiver: ValueId) -> bool {
|
||||
matches!(self.value_types.get(&receiver), Some(MirType::Box(_)))
|
||||
}
|
||||
@ -103,6 +104,7 @@ impl<'a> CalleeGuardBox<'a> {
|
||||
/// receiver型の取得(ヘルパー)
|
||||
///
|
||||
/// 指定されたreceiverのBox型名を返す(存在しない場合はNone)
|
||||
#[allow(dead_code)]
|
||||
pub fn get_box_type(&self, receiver: ValueId) -> Option<&String> {
|
||||
match self.value_types.get(&receiver) {
|
||||
Some(MirType::Box(box_name)) => Some(box_name),
|
||||
@ -114,6 +116,7 @@ impl<'a> CalleeGuardBox<'a> {
|
||||
///
|
||||
/// box_name と receiver型が一致するか判定
|
||||
/// (静的メソッド呼び出しの検出用)
|
||||
#[allow(dead_code)]
|
||||
pub fn is_me_call(&self, box_name: &str, receiver: ValueId) -> bool {
|
||||
match self.get_box_type(receiver) {
|
||||
Some(recv_box) => recv_box == box_name,
|
||||
|
||||
@ -28,8 +28,13 @@ pub mod effects_analyzer; // Phase 3-B: Effects analyzer (エフェクト解析
|
||||
pub mod materializer; // Phase 3-C: Call materializer (Call前処理・準備専用箱)
|
||||
|
||||
// Re-export public interfaces
|
||||
#[allow(unused_imports)]
|
||||
pub use call_target::CallTarget;
|
||||
#[allow(unused_imports)]
|
||||
pub use lowering::*;
|
||||
#[allow(unused_imports)]
|
||||
pub use utils::*;
|
||||
#[allow(unused_imports)]
|
||||
pub use emit::*;
|
||||
#[allow(unused_imports)]
|
||||
pub use build::*;
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
/*!
|
||||
* Special Call Handlers
|
||||
*
|
||||
@ -137,4 +139,4 @@ pub fn suggest_alternative_for_reserved(name: &str) -> String {
|
||||
"from" => "Use 'from Parent.method()' syntax for delegation".to_string(),
|
||||
_ => format!("'{}' is a reserved keyword", name),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,16 +23,19 @@ use std::collections::HashMap;
|
||||
pub struct BoxCompilationContext {
|
||||
/// 変数名 → ValueId マッピング
|
||||
/// 例: "args" → ValueId(0), "result" → ValueId(42)
|
||||
#[allow(dead_code)]
|
||||
pub variable_map: HashMap<String, ValueId>,
|
||||
|
||||
/// ValueId → 起源Box名 マッピング
|
||||
/// NewBox命令で生成されたValueIdがどのBox型から来たかを追跡
|
||||
/// 例: ValueId(10) → "ParserBox"
|
||||
#[allow(dead_code)]
|
||||
pub value_origin_newbox: HashMap<ValueId, String>,
|
||||
|
||||
/// ValueId → MIR型 マッピング
|
||||
/// 各ValueIdの型情報を保持
|
||||
/// 例: ValueId(5) → MirType::Integer
|
||||
#[allow(dead_code)]
|
||||
pub value_types: HashMap<ValueId, MirType>,
|
||||
}
|
||||
|
||||
@ -43,6 +46,7 @@ impl BoxCompilationContext {
|
||||
}
|
||||
|
||||
/// コンテキストが空(未使用)かどうかを判定
|
||||
#[allow(dead_code)]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.variable_map.is_empty()
|
||||
&& self.value_origin_newbox.is_empty()
|
||||
@ -50,6 +54,7 @@ impl BoxCompilationContext {
|
||||
}
|
||||
|
||||
/// デバッグ用:コンテキストのサイズ情報を取得
|
||||
#[allow(dead_code)]
|
||||
pub fn size_info(&self) -> (usize, usize, usize) {
|
||||
(
|
||||
self.variable_map.len(),
|
||||
|
||||
@ -38,11 +38,6 @@ impl super::MirBuilder {
|
||||
let _ = self.lower_static_method_as_function(func_name, params.clone(), body.clone());
|
||||
eprintln!("[DEBUG] build_static_main_box: After lower_static_method_as_function");
|
||||
eprintln!("[DEBUG] variable_map = {:?}", self.variable_map);
|
||||
// Convert the method body to a Program AST node and lower it
|
||||
let program_ast = ASTNode::Program {
|
||||
statements: body.clone(),
|
||||
span: crate::ast::Span::unknown(),
|
||||
};
|
||||
// Initialize local variables for Main.main() parameters
|
||||
// Note: These are local variables in the wrapper main() function, NOT parameters
|
||||
let saved_var_map = std::mem::take(&mut self.variable_map);
|
||||
@ -117,7 +112,7 @@ impl super::MirBuilder {
|
||||
weak_fields: Vec<String>,
|
||||
) -> Result<(), String> {
|
||||
// Create a type registration constant (marker)
|
||||
let type_id = crate::mir::builder::emission::constant::emit_string(self, format!("__box_type_{}", name));
|
||||
crate::mir::builder::emission::constant::emit_string(self, format!("__box_type_{}", name));
|
||||
|
||||
// Emit field metadata markers
|
||||
for field in fields {
|
||||
|
||||
@ -17,11 +17,13 @@ pub fn emit_to(b: &mut MirBuilder, dst: ValueId, op: CompareOp, lhs: ValueId, rh
|
||||
|
||||
// Convenience wrappers (明示関数名が読みやすい箇所用)
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub fn emit_eq_to(b: &mut MirBuilder, dst: ValueId, lhs: ValueId, rhs: ValueId) -> Result<(), String> {
|
||||
emit_to(b, dst, CompareOp::Eq, lhs, rhs)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub fn emit_ne_to(b: &mut MirBuilder, dst: ValueId, lhs: ValueId, rhs: ValueId) -> Result<(), String> {
|
||||
emit_to(b, dst, CompareOp::Ne, lhs, rhs)
|
||||
}
|
||||
|
||||
@ -288,7 +288,7 @@ impl super::MirBuilder {
|
||||
MirInstruction::Const { value, .. } => {
|
||||
if let super::ConstValue::String(s) = value { last_const_name = Some(s.clone()); }
|
||||
}
|
||||
MirInstruction::Call { func, .. } => {
|
||||
MirInstruction::Call { func: _, .. } => {
|
||||
// If immediately preceded by matching Const String, accept
|
||||
if let Some(prev) = last_const_name.as_ref() {
|
||||
if prev == &expect_tail { ok = true; break; }
|
||||
@ -318,7 +318,7 @@ impl super::MirBuilder {
|
||||
// Dev stub: provide condition_fn when missing to satisfy predicate calls in JSON lexers
|
||||
// Returns integer 1 (truthy) and accepts one argument (unused).
|
||||
if module.functions.get("condition_fn").is_none() {
|
||||
let mut sig = FunctionSignature {
|
||||
let sig = FunctionSignature {
|
||||
name: "condition_fn".to_string(),
|
||||
params: vec![MirType::Integer], // accept one i64-like arg
|
||||
return_type: MirType::Integer,
|
||||
|
||||
@ -32,6 +32,7 @@ pub fn propagate(builder: &mut MirBuilder, src: ValueId, dst: ValueId) {
|
||||
/// dst に型注釈を明示的に設定し、必要ならば起源情報を消去/維持する。
|
||||
/// 🎯 TypeRegistry 経由モード対応(NYASH_USE_TYPE_REGISTRY=1)
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub fn propagate_with_override(builder: &mut MirBuilder, dst: ValueId, ty: MirType) {
|
||||
let use_registry = std::env::var("NYASH_USE_TYPE_REGISTRY")
|
||||
.ok()
|
||||
@ -45,4 +46,3 @@ pub fn propagate_with_override(builder: &mut MirBuilder, dst: ValueId, ty: MirTy
|
||||
builder.value_types.insert(dst, ty);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -62,6 +62,7 @@ impl MirBuilder {
|
||||
}
|
||||
|
||||
/// Check if this is a TypeOp method call
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn is_typeop_method(method: &str, arguments: &[ASTNode]) -> Option<String> {
|
||||
if (method == "is" || method == "as") && arguments.len() == 1 {
|
||||
Self::extract_string_literal(&arguments[0])
|
||||
|
||||
@ -12,7 +12,7 @@ impl MirBuilder {
|
||||
pub(super) fn merge_modified_vars(
|
||||
&mut self,
|
||||
_then_block: super::BasicBlockId,
|
||||
else_block: super::BasicBlockId,
|
||||
_else_block: super::BasicBlockId,
|
||||
then_exit_block_opt: Option<super::BasicBlockId>,
|
||||
else_exit_block_opt: Option<super::BasicBlockId>,
|
||||
pre_if_snapshot: &std::collections::HashMap<String, super::ValueId>,
|
||||
@ -179,8 +179,8 @@ impl MirBuilder {
|
||||
/// This handles variable reassignment patterns and ensures a single exit value.
|
||||
pub(super) fn normalize_if_else_phi(
|
||||
&mut self,
|
||||
then_block: BasicBlockId,
|
||||
else_block: BasicBlockId,
|
||||
_then_block: BasicBlockId,
|
||||
_else_block: BasicBlockId,
|
||||
then_exit_block_opt: Option<BasicBlockId>,
|
||||
else_exit_block_opt: Option<BasicBlockId>,
|
||||
then_value_raw: ValueId,
|
||||
|
||||
@ -19,6 +19,7 @@ fn rewrite_enabled() -> bool {
|
||||
|
||||
/// Try Known‑route instance→function rewrite.
|
||||
/// 既存の安全ガード(user_defined/存在確認/ENV)を尊重して関数化する。
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn try_known_rewrite(
|
||||
builder: &mut MirBuilder,
|
||||
object_value: ValueId,
|
||||
@ -119,6 +120,7 @@ pub(crate) fn try_known_rewrite_to_dst(
|
||||
|
||||
/// Fallback: when exactly one user-defined method matches by name/arity across the module,
|
||||
/// resolve to that even if class inference failed. Deterministic via uniqueness and user-box prefix.
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn try_unique_suffix_rewrite(
|
||||
builder: &mut MirBuilder,
|
||||
object_value: ValueId,
|
||||
@ -183,7 +185,7 @@ pub(crate) fn try_unique_suffix_rewrite_to_dst(
|
||||
if cands.len() != 1 { return None; }
|
||||
let fname = cands.remove(0);
|
||||
if let Some((bx, _)) = fname.split_once('.') { if !builder.user_defined_boxes.contains(bx) { return None; } } else { return None; }
|
||||
let name_const = match crate::mir::builder::name_const::make_name_const_result(builder, &fname) {
|
||||
let _name_const = match crate::mir::builder::name_const::make_name_const_result(builder, &fname) {
|
||||
Ok(v) => v,
|
||||
Err(e) => return Some(Err(e)),
|
||||
};
|
||||
@ -212,6 +214,7 @@ pub(crate) fn try_unique_suffix_rewrite_to_dst(
|
||||
}
|
||||
|
||||
/// Unified entry: try Known rewrite first, then unique-suffix fallback.
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn try_known_or_unique(
|
||||
builder: &mut MirBuilder,
|
||||
object_value: ValueId,
|
||||
|
||||
@ -2,6 +2,7 @@ use super::super::MirBuilder;
|
||||
|
||||
/// Early special-case: toString/stringify → str(互換)を処理。
|
||||
/// 戻り値: Some(result_id) なら処理済み。None なら通常経路へ委譲。
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn try_early_str_like(
|
||||
builder: &mut MirBuilder,
|
||||
object_value: super::super::ValueId,
|
||||
@ -104,6 +105,7 @@ pub(crate) fn try_early_str_like(
|
||||
|
||||
/// Special-case for equals/1: prefer Known rewrite; otherwise allow unique-suffix fallback
|
||||
/// when it is deterministic (single candidate). This centralizes equals handling.
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn try_special_equals(
|
||||
builder: &mut MirBuilder,
|
||||
object_value: super::super::ValueId,
|
||||
@ -151,7 +153,7 @@ pub(crate) fn try_early_str_like_to_dst(
|
||||
"certainty": "Known",
|
||||
});
|
||||
super::super::observe::resolve::emit_choose(builder, meta);
|
||||
let name_const = match crate::mir::builder::name_const::make_name_const_result(builder, &chosen) {
|
||||
let _name_const = match crate::mir::builder::name_const::make_name_const_result(builder, &chosen) {
|
||||
Ok(v) => v,
|
||||
Err(e) => return Some(Err(e)),
|
||||
};
|
||||
@ -182,7 +184,7 @@ pub(crate) fn try_early_str_like_to_dst(
|
||||
"certainty": "Heuristic",
|
||||
});
|
||||
super::super::observe::resolve::emit_choose(builder, meta);
|
||||
let name_const = match crate::mir::builder::name_const::make_name_const_result(builder, &fname) {
|
||||
let _name_const = match crate::mir::builder::name_const::make_name_const_result(builder, &fname) {
|
||||
Ok(v) => v,
|
||||
Err(e) => return Some(Err(e)),
|
||||
};
|
||||
@ -209,7 +211,7 @@ pub(crate) fn try_early_str_like_to_dst(
|
||||
"certainty": "Heuristic",
|
||||
});
|
||||
super::super::observe::resolve::emit_choose(builder, meta);
|
||||
let name_const = match crate::mir::builder::name_const::make_name_const_result(builder, &fname) {
|
||||
let _name_const = match crate::mir::builder::name_const::make_name_const_result(builder, &fname) {
|
||||
Ok(v) => v,
|
||||
Err(e) => return Some(Err(e)),
|
||||
};
|
||||
|
||||
@ -7,6 +7,7 @@ pub struct BlockScheduleBox;
|
||||
|
||||
impl BlockScheduleBox {
|
||||
/// Insert a Copy immediately after PHI nodes. Returns the local value id.
|
||||
#[allow(dead_code)]
|
||||
pub fn ensure_after_phis_copy(builder: &mut MirBuilder, src: ValueId) -> Result<ValueId, String> {
|
||||
if let Some(bb) = builder.current_block {
|
||||
if let Some(&cached) = builder.schedule_mat_map.get(&(bb, src)) {
|
||||
@ -29,6 +30,7 @@ impl BlockScheduleBox {
|
||||
|
||||
/// Emit a Copy right before the next emitted instruction (best-effort):
|
||||
/// place it at the tail of the current block. Returns the local value id.
|
||||
#[allow(dead_code)]
|
||||
pub fn emit_before_call_copy(builder: &mut MirBuilder, src: ValueId) -> Result<ValueId, String> {
|
||||
// Prefer to reuse the after-phis materialized id for this src in this block
|
||||
let base = Self::ensure_after_phis_copy(builder, src)?;
|
||||
|
||||
@ -13,6 +13,7 @@ use std::collections::HashMap;
|
||||
pub struct TraceEntry {
|
||||
pub vid: ValueId,
|
||||
pub source: String, // "newbox:MapBox", "param:args", "propagate:from_%123"
|
||||
#[allow(dead_code)]
|
||||
pub timestamp: usize,
|
||||
}
|
||||
|
||||
@ -52,6 +53,7 @@ impl TypeRegistry {
|
||||
// ============================================================
|
||||
|
||||
/// NewBox起源を記録
|
||||
#[allow(dead_code)]
|
||||
pub fn record_newbox(&mut self, vid: ValueId, class: String) {
|
||||
self.origins.insert(vid, class.clone());
|
||||
|
||||
@ -67,6 +69,7 @@ impl TypeRegistry {
|
||||
}
|
||||
|
||||
/// パラメータ型を記録
|
||||
#[allow(dead_code)]
|
||||
pub fn record_param(&mut self, vid: ValueId, param_name: &str, param_type: Option<MirType>) {
|
||||
if let Some(ty) = param_type.clone() {
|
||||
self.types.insert(vid, ty.clone());
|
||||
@ -107,6 +110,7 @@ impl TypeRegistry {
|
||||
}
|
||||
|
||||
/// 起源を明示的に設定(推論結果など)
|
||||
#[allow(dead_code)]
|
||||
pub fn record_origin(&mut self, vid: ValueId, origin: String, reason: &str) {
|
||||
self.origins.insert(vid, origin.clone());
|
||||
|
||||
@ -164,11 +168,13 @@ impl TypeRegistry {
|
||||
// ============================================================
|
||||
|
||||
/// 起源クラス名を取得
|
||||
#[allow(dead_code)]
|
||||
pub fn get_origin(&self, vid: ValueId) -> Option<&String> {
|
||||
self.origins.get(&vid)
|
||||
}
|
||||
|
||||
/// 型情報を取得
|
||||
#[allow(dead_code)]
|
||||
pub fn get_type(&self, vid: ValueId) -> Option<&MirType> {
|
||||
self.types.get(&vid)
|
||||
}
|
||||
@ -214,6 +220,7 @@ impl TypeRegistry {
|
||||
}
|
||||
|
||||
/// 全トレースログを表示
|
||||
#[allow(dead_code)]
|
||||
pub fn dump_trace(&self) {
|
||||
eprintln!("[type-registry] === Trace Log ({} entries) ===", self.trace_log.len());
|
||||
for entry in &self.trace_log {
|
||||
@ -222,6 +229,7 @@ impl TypeRegistry {
|
||||
}
|
||||
|
||||
/// 統計情報を表示
|
||||
#[allow(dead_code)]
|
||||
pub fn dump_stats(&self) {
|
||||
eprintln!("[type-registry] === Statistics ===");
|
||||
eprintln!("[type-registry] Origins: {} entries", self.origins.len());
|
||||
@ -234,6 +242,7 @@ impl TypeRegistry {
|
||||
// ============================================================
|
||||
|
||||
/// 起源情報のみクリア(型情報は保持)
|
||||
#[allow(dead_code)]
|
||||
pub fn clear_origins(&mut self) {
|
||||
self.origins.clear();
|
||||
if self.trace_enabled {
|
||||
@ -242,6 +251,7 @@ impl TypeRegistry {
|
||||
}
|
||||
|
||||
/// 全情報クリア
|
||||
#[allow(dead_code)]
|
||||
pub fn clear_all(&mut self) {
|
||||
self.origins.clear();
|
||||
self.types.clear();
|
||||
|
||||
@ -5,6 +5,7 @@ use crate::mir::builder::MirBuilder;
|
||||
|
||||
/// 直接的に MirType を設定する(仕様不変)。
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub fn set_type(builder: &mut MirBuilder, dst: ValueId, ty: MirType) {
|
||||
builder.value_types.insert(dst, ty);
|
||||
}
|
||||
|
||||
@ -334,6 +334,7 @@ impl super::MirBuilder {
|
||||
}
|
||||
|
||||
/// Ensure a value has a local definition in the current block by inserting a Copy.
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn materialize_local(&mut self, v: super::ValueId) -> Result<super::ValueId, String> {
|
||||
// Phase 25.1b: Use function-local ID allocator to avoid SSA verification failures
|
||||
let dst = if let Some(ref mut f) = self.current_function {
|
||||
@ -348,6 +349,7 @@ impl super::MirBuilder {
|
||||
}
|
||||
|
||||
/// Insert a Copy immediately after PHI nodes in the current block (position-stable).
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn insert_copy_after_phis(&mut self, dst: super::ValueId, src: super::ValueId) -> Result<(), String> {
|
||||
if let (Some(ref mut function), Some(bb)) = (&mut self.current_function, self.current_block) {
|
||||
if std::env::var("NYASH_SCHEDULE_TRACE").ok().as_deref() == Some("1") {
|
||||
|
||||
222
src/mir/control_form.rs
Normal file
222
src/mir/control_form.rs
Normal file
@ -0,0 +1,222 @@
|
||||
/*!
|
||||
* ControlForm – 共通制御構造ビュー(Loop / If の箱化レイヤ)
|
||||
*
|
||||
* 目的:
|
||||
* - LoopForm v2(ループ)と If 降下を、1段上の「制御構造の形」として統一的に眺めるための薄いレイヤだよ。
|
||||
* - Conservative PHI Box や将来の可視化/検証ロジックが、Loop 専用 / If 専用に分かれず、
|
||||
* ControlForm という SSOT から情報を取れるようにするのがねらいだよ。
|
||||
*
|
||||
* このモジュール自体は構造定義とデバッグ用のユーティリティのみを提供し、
|
||||
* 既存の LoopBuilder / If 降下の挙動は変えないよ(Phase 25.1f では観測レイヤ専用)。
|
||||
*/
|
||||
|
||||
use crate::mir::{BasicBlock, BasicBlockId, MirFunction};
|
||||
|
||||
/// ループ構造の形だけを表す箱だよ。
|
||||
///
|
||||
/// - `preheader` : ループ直前のブロック(キャリア/ピン変数のコピー元)
|
||||
/// - `header` : ループヘッダ(条件判定と header PHI が置かれる)
|
||||
/// - `body` : 代表的なループ本体ブロック(最初の body など)
|
||||
/// - `latch` : ヘッダへ戻るバックエッジを張るブロック
|
||||
/// - `exit` : ループを抜けた先のブロック
|
||||
/// - `continue_targets` : continue がジャンプするブロック群(通常は latch か header)
|
||||
/// - `break_targets` : break がジャンプするブロック群(通常は exit)
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct LoopShape {
|
||||
pub preheader: BasicBlockId,
|
||||
pub header: BasicBlockId,
|
||||
pub body: BasicBlockId,
|
||||
pub latch: BasicBlockId,
|
||||
pub exit: BasicBlockId,
|
||||
pub continue_targets: Vec<BasicBlockId>,
|
||||
pub break_targets: Vec<BasicBlockId>,
|
||||
}
|
||||
|
||||
/// if/else 構造の形だけを表す箱だよ。
|
||||
///
|
||||
/// - `cond_block` : 条件式を評価するブロック
|
||||
/// - `then_block` : then ブランチの先頭ブロック
|
||||
/// - `else_block` : else ブランチの先頭ブロック(無ければ None)
|
||||
/// - `merge_block`: then/else の合流ブロック
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct IfShape {
|
||||
pub cond_block: BasicBlockId,
|
||||
pub then_block: BasicBlockId,
|
||||
pub else_block: Option<BasicBlockId>,
|
||||
pub merge_block: BasicBlockId,
|
||||
}
|
||||
|
||||
/// 制御構造の種別だよ。
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ControlKind {
|
||||
Loop(LoopShape),
|
||||
If(IfShape),
|
||||
}
|
||||
|
||||
/// ループ / if / 将来の switch などを、共通のビューとして扱う箱だよ。
|
||||
///
|
||||
/// - `entry` : 構造に入る入口ブロック
|
||||
/// - `exits` : 構造を抜けたあとのブロック群
|
||||
/// - `kind` : Loop / If などの種別ごとの Shape
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ControlForm {
|
||||
pub entry: BasicBlockId,
|
||||
pub exits: Vec<BasicBlockId>,
|
||||
pub kind: ControlKind,
|
||||
}
|
||||
|
||||
impl ControlForm {
|
||||
/// ループ用 Shape から ControlForm を生成するよ。
|
||||
///
|
||||
/// ループの entry は preheader、exit は exit ブロック 1 つとみなす。
|
||||
pub fn from_loop(shape: LoopShape) -> Self {
|
||||
ControlForm {
|
||||
entry: shape.preheader,
|
||||
exits: vec![shape.exit],
|
||||
kind: ControlKind::Loop(shape),
|
||||
}
|
||||
}
|
||||
|
||||
/// If 用 Shape から ControlForm を生成するよ。
|
||||
///
|
||||
/// If の entry は cond_block、exit は merge_block 1 つとみなす。
|
||||
pub fn from_if(shape: IfShape) -> Self {
|
||||
ControlForm {
|
||||
entry: shape.cond_block,
|
||||
exits: vec![shape.merge_block],
|
||||
kind: ControlKind::If(shape),
|
||||
}
|
||||
}
|
||||
|
||||
/// これはループかな?という軽い判定だよ。
|
||||
pub fn is_loop(&self) -> bool {
|
||||
matches!(self.kind, ControlKind::Loop(_))
|
||||
}
|
||||
|
||||
/// これは if 構造かな?という軽い判定だよ。
|
||||
pub fn is_if(&self) -> bool {
|
||||
matches!(self.kind, ControlKind::If(_))
|
||||
}
|
||||
|
||||
/// デバッグ用に構造をダンプするよ。
|
||||
///
|
||||
/// 呼び出し側で `NYASH_CONTROL_FORM_TRACE=1` を見る想定なので、
|
||||
/// ここでは単純に eprintln! するだけにしておく。
|
||||
pub fn debug_dump(&self) {
|
||||
match &self.kind {
|
||||
ControlKind::Loop(shape) => {
|
||||
eprintln!(
|
||||
"[ControlForm::Loop] entry={:?} preheader={:?} header={:?} body={:?} latch={:?} exit={:?} continue={:?} break={:?}",
|
||||
self.entry,
|
||||
shape.preheader,
|
||||
shape.header,
|
||||
shape.body,
|
||||
shape.latch,
|
||||
shape.exit,
|
||||
shape.continue_targets,
|
||||
shape.break_targets,
|
||||
);
|
||||
}
|
||||
ControlKind::If(shape) => {
|
||||
eprintln!(
|
||||
"[ControlForm::If] entry={:?} cond={:?} then={:?} else={:?} merge={:?} exits={:?}",
|
||||
self.entry,
|
||||
shape.cond_block,
|
||||
shape.then_block,
|
||||
shape.else_block,
|
||||
shape.merge_block,
|
||||
self.exits,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// ControlForm の invariant を軽く検査するための CFG 抽象だよ。
|
||||
///
|
||||
/// 実装は MirFunction などに持たせて、`debug_validate` から使う想定。
|
||||
pub trait CfgLike {
|
||||
fn has_edge(&self, from: BasicBlockId, to: BasicBlockId) -> bool;
|
||||
fn predecessors_len(&self, block: BasicBlockId) -> usize;
|
||||
}
|
||||
|
||||
impl CfgLike for MirFunction {
|
||||
fn has_edge(&self, from: BasicBlockId, to: BasicBlockId) -> bool {
|
||||
self.blocks
|
||||
.get(&from)
|
||||
.map(|bb: &BasicBlock| bb.successors.contains(&to))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn predecessors_len(&self, block: BasicBlockId) -> usize {
|
||||
self.blocks
|
||||
.get(&block)
|
||||
.map(|bb: &BasicBlock| bb.predecessors.len())
|
||||
.unwrap_or(0)
|
||||
}
|
||||
}
|
||||
|
||||
/// ControlForm トレース用の環境フラグを判定するヘルパーだよ。
|
||||
///
|
||||
/// - 未設定 → 既定で ON
|
||||
/// - "0" / "false" → OFF
|
||||
/// - それ以外 → ON
|
||||
pub fn is_control_form_trace_on() -> bool {
|
||||
std::env::var("NYASH_CONTROL_FORM_TRACE")
|
||||
.map(|v| v != "0" && v.to_lowercase() != "false")
|
||||
.unwrap_or(true)
|
||||
}
|
||||
|
||||
impl LoopShape {
|
||||
/// Debug ビルドでだけ呼ぶ用の簡易 invariant チェックだよ。
|
||||
///
|
||||
/// - preheader → header にエッジがあること
|
||||
/// - latch → header にバックエッジがあること
|
||||
#[cfg(debug_assertions)]
|
||||
pub fn debug_validate<C: CfgLike>(&self, cfg: &C) {
|
||||
debug_assert!(
|
||||
cfg.has_edge(self.preheader, self.header),
|
||||
"LoopShape invalid: preheader -> header edge missing: {:?} -> {:?}",
|
||||
self.preheader,
|
||||
self.header
|
||||
);
|
||||
debug_assert!(
|
||||
cfg.has_edge(self.latch, self.header),
|
||||
"LoopShape invalid: latch -> header backedge missing: {:?} -> {:?}",
|
||||
self.latch,
|
||||
self.header
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
impl IfShape {
|
||||
/// Debug ビルドでだけ呼ぶ用の簡易 invariant チェックだよ。
|
||||
///
|
||||
/// - cond → then / else にエッジがあること
|
||||
/// - merge については、predecessor 情報がまだ配線途中のケースもあるので
|
||||
/// ここでは「0 ならログだけ出す(panic しない)」ことにするよ。
|
||||
#[cfg(debug_assertions)]
|
||||
pub fn debug_validate<C: CfgLike>(&self, cfg: &C) {
|
||||
debug_assert!(
|
||||
cfg.has_edge(self.cond_block, self.then_block),
|
||||
"IfShape invalid: cond -> then edge missing: {:?} -> {:?}",
|
||||
self.cond_block,
|
||||
self.then_block
|
||||
);
|
||||
if let Some(else_blk) = self.else_block {
|
||||
debug_assert!(
|
||||
cfg.has_edge(self.cond_block, else_blk),
|
||||
"IfShape invalid: cond -> else edge missing: {:?} -> {:?}",
|
||||
self.cond_block,
|
||||
else_blk
|
||||
);
|
||||
}
|
||||
let preds = cfg.predecessors_len(self.merge_block);
|
||||
if preds == 0 && std::env::var("NYASH_CONTROL_FORM_TRACE").ok().as_deref() == Some("1") {
|
||||
eprintln!(
|
||||
"[ControlForm::IfShape] WARN: merge block {:?} has no predecessors yet",
|
||||
self.merge_block
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
use super::{BasicBlockId, ConstValue, MirInstruction, ValueId};
|
||||
use crate::mir::control_form::{ControlForm, IfShape, LoopShape, is_control_form_trace_on};
|
||||
use crate::mir::phi_core::loop_phi::IncompletePhi;
|
||||
use crate::mir::phi_core::loopform_builder::{LoopFormBuilder, LoopFormOps};
|
||||
use crate::ast::ASTNode;
|
||||
@ -342,7 +343,6 @@ impl<'a> LoopBuilder<'a> {
|
||||
|
||||
// Jump to latch if not already terminated
|
||||
let actual_latch_id = if !is_current_block_terminated(self.parent_builder)? {
|
||||
let cur_body_end = self.current_block()?;
|
||||
self.emit_jump(latch_id)?;
|
||||
latch_id
|
||||
} else {
|
||||
@ -375,6 +375,38 @@ impl<'a> LoopBuilder<'a> {
|
||||
// Pop loop context
|
||||
crate::mir::builder::loops::pop_loop_context(self.parent_builder);
|
||||
|
||||
// ControlForm 観測: 環境フラグ(未設定時は既定ON)のとき LoopShape をダンプ
|
||||
if is_control_form_trace_on() {
|
||||
// continue / break のターゲットブロックをユニーク化して収集
|
||||
use std::collections::HashSet;
|
||||
let mut cont_set: HashSet<BasicBlockId> = HashSet::new();
|
||||
let mut break_set: HashSet<BasicBlockId> = HashSet::new();
|
||||
for (bb, _) in &self.continue_snapshots {
|
||||
cont_set.insert(*bb);
|
||||
}
|
||||
for (bb, _) in &self.exit_snapshots {
|
||||
break_set.insert(*bb);
|
||||
}
|
||||
let continue_targets: Vec<BasicBlockId> = cont_set.into_iter().collect();
|
||||
let break_targets: Vec<BasicBlockId> = break_set.into_iter().collect();
|
||||
|
||||
let loop_shape = LoopShape {
|
||||
preheader: preheader_id,
|
||||
header: header_id,
|
||||
body: body_id,
|
||||
latch: latch_id,
|
||||
exit: exit_id,
|
||||
continue_targets,
|
||||
break_targets,
|
||||
};
|
||||
let form = ControlForm::from_loop(loop_shape.clone());
|
||||
form.debug_dump();
|
||||
#[cfg(debug_assertions)]
|
||||
if let Some(ref func) = self.parent_builder.current_function {
|
||||
loop_shape.debug_validate(func);
|
||||
}
|
||||
}
|
||||
|
||||
// Return void value
|
||||
let void_dst = self.new_value();
|
||||
self.emit_const(void_dst, ConstValue::Void)?;
|
||||
@ -486,7 +518,7 @@ impl<'a> LoopBuilder<'a> {
|
||||
}
|
||||
|
||||
// Add PHI nodes for new pinned variables in header block
|
||||
for (name, value, preheader_value) in new_pinned_vars {
|
||||
for (name, _value, preheader_value) in new_pinned_vars {
|
||||
let phi_id = self.new_value();
|
||||
self.emit_phi_at_block_start(header_id, phi_id, vec![(preheader_id, preheader_value)])?;
|
||||
// Update variable map to use PHI value
|
||||
@ -1156,6 +1188,22 @@ impl<'a> LoopBuilder<'a> {
|
||||
&else_var_map_end_opt,
|
||||
None,
|
||||
)?;
|
||||
|
||||
// ControlForm 観測: 環境フラグ(未設定時は既定ON)のとき IfShape をダンプ
|
||||
if is_control_form_trace_on() {
|
||||
let if_shape = IfShape {
|
||||
cond_block: pre_branch_bb,
|
||||
then_block: then_bb,
|
||||
else_block: Some(else_bb),
|
||||
merge_block: merge_bb,
|
||||
};
|
||||
let form = ControlForm::from_if(if_shape.clone());
|
||||
form.debug_dump();
|
||||
#[cfg(debug_assertions)]
|
||||
if let Some(ref func) = self.parent_builder.current_function {
|
||||
if_shape.debug_validate(func);
|
||||
}
|
||||
}
|
||||
let void_id = self.new_value();
|
||||
self.emit_const(void_id, ConstValue::Void)?;
|
||||
// Pop merge debug region
|
||||
|
||||
@ -34,6 +34,7 @@ pub mod slot_registry; // Phase 9.79b.1: method slot resolution (IDs)
|
||||
pub mod value_id;
|
||||
pub mod verification;
|
||||
pub mod verification_types; // extracted error types // Optimization subpasses (e.g., type_hints)
|
||||
pub mod control_form; // Phase 25.1f: Loop/If 共通ビュー(ControlForm)
|
||||
|
||||
// Re-export main types for easy access
|
||||
pub use basic_block::{BasicBlock, BasicBlockId, BasicBlockIdGenerator};
|
||||
|
||||
@ -145,7 +145,7 @@ pub fn merge_modified_at_merge_with<O: PhiMergeOps>(
|
||||
ops: &mut O,
|
||||
merge_bb: crate::mir::BasicBlockId,
|
||||
_then_block: crate::mir::BasicBlockId,
|
||||
else_block: crate::mir::BasicBlockId,
|
||||
_else_block: crate::mir::BasicBlockId,
|
||||
then_pred_opt: Option<crate::mir::BasicBlockId>,
|
||||
else_pred_opt: Option<crate::mir::BasicBlockId>,
|
||||
pre_if_snapshot: &HashMap<String, ValueId>,
|
||||
|
||||
@ -193,7 +193,7 @@ pub fn prepare_loop_variables_with<O: LoopPhiOps>(
|
||||
ops.emit_copy_at_preheader(preheader_id, pre_copy, value_before)?;
|
||||
|
||||
let phi_id = ops.new_value();
|
||||
let mut inc = IncompletePhi {
|
||||
let inc = IncompletePhi {
|
||||
phi_id,
|
||||
var_name: var_name.clone(),
|
||||
known_inputs: vec![(preheader_id, pre_copy)], // ensure def at preheader
|
||||
|
||||
@ -67,6 +67,7 @@ pub fn compute_dominators(function: &MirFunction) -> HashMap<BasicBlockId, HashS
|
||||
dom
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn compute_reachable_blocks(function: &MirFunction) -> HashSet<BasicBlockId> {
|
||||
let mut reachable = HashSet::new();
|
||||
let mut worklist = vec![function.entry_block];
|
||||
|
||||
@ -43,6 +43,7 @@ impl<'a> TokenCursor<'a> {
|
||||
}
|
||||
|
||||
/// 次のトークンをピーク
|
||||
#[allow(dead_code)]
|
||||
pub fn peek(&self) -> &Token {
|
||||
self.tokens.get(self.idx + 1).unwrap_or(&Token {
|
||||
token_type: TokenType::EOF,
|
||||
@ -52,6 +53,7 @@ impl<'a> TokenCursor<'a> {
|
||||
}
|
||||
|
||||
/// N番目のトークンをピーク
|
||||
#[allow(dead_code)]
|
||||
pub fn peek_nth(&self, n: usize) -> &Token {
|
||||
self.tokens.get(self.idx + n).unwrap_or(&Token {
|
||||
token_type: TokenType::EOF,
|
||||
@ -220,11 +222,13 @@ impl<'a> TokenCursor<'a> {
|
||||
}
|
||||
|
||||
/// モードを取得
|
||||
#[allow(dead_code)]
|
||||
pub fn get_mode(&self) -> NewlineMode {
|
||||
self.mode
|
||||
}
|
||||
|
||||
/// モードを設定
|
||||
#[allow(dead_code)]
|
||||
pub fn set_mode(&mut self, mode: NewlineMode) {
|
||||
self.mode = mode;
|
||||
}
|
||||
@ -294,4 +298,4 @@ mod tests {
|
||||
assert!(c.match_token(&TokenType::PLUS));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,6 +59,7 @@ impl NyashParser {
|
||||
}
|
||||
|
||||
/// Small helper: build UnexpectedToken with current token and line
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn err_unexpected<S: Into<String>>(&self, expected: S) -> ParseError {
|
||||
ParseError::UnexpectedToken {
|
||||
found: self.current_token().token_type.clone(),
|
||||
@ -68,6 +69,7 @@ impl NyashParser {
|
||||
}
|
||||
|
||||
/// Expect an identifier and advance. Returns its string or an UnexpectedToken error
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn expect_identifier(&mut self, what: &str) -> Result<String, ParseError> {
|
||||
if let TokenType::IDENTIFIER(name) = &self.current_token().token_type {
|
||||
let out = name.clone();
|
||||
@ -77,4 +79,4 @@ impl NyashParser {
|
||||
Err(self.err_unexpected(what))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ impl NyashParser {
|
||||
let mut statements = Vec::new();
|
||||
|
||||
// Helper: lookahead for `ident '(' ... ')' [NEWLINE*] '{'`
|
||||
let mut looks_like_method_head = |this: &Self| -> bool {
|
||||
let looks_like_method_head = |this: &Self| -> bool {
|
||||
// Only meaningful when starting at a new statement head
|
||||
match &this.current_token().token_type {
|
||||
TokenType::IDENTIFIER(_) => {
|
||||
|
||||
@ -8,6 +8,7 @@ pub fn pre_run_reset_oob_if_strict() {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn post_run_exit_if_oob_strict_triggered() -> ! {
|
||||
if crate::config::env::oob_strict_fail() && crate::runtime::observe::oob_seen() {
|
||||
eprintln!("[gate-c][oob-strict] Out-of-bounds observed → exit(1)");
|
||||
|
||||
@ -90,6 +90,7 @@ pub(super) fn demo_parser_system() {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn demo_interpreter_system() {
|
||||
println!("\n🎭 7. Interpreter System:");
|
||||
println!(" ⚠️ Legacy interpreter removed - use VM or LLVM backends instead");
|
||||
|
||||
@ -129,18 +129,17 @@ pub fn run_json_v1_inline(json: &str) -> i32 {
|
||||
|
||||
let sval = regs.get(&src).cloned();
|
||||
let is_integer = sval.is_some(); // hv1 inline stores i64 only → integer
|
||||
let mut out = 0i64;
|
||||
if operation == "check" || operation == "is" {
|
||||
if target == "i64" || target == "int" || target == "integer" {
|
||||
out = if is_integer { 1 } else { 0 };
|
||||
let out: i64 = if target == "i64" || target == "int" || target == "integer" {
|
||||
if is_integer { 1 } else { 0 }
|
||||
} else if target == "bool" {
|
||||
// Inline model uses integer registers; treat 0/1 as bool when present
|
||||
out = if let Some(v) = sval { if v == 0 || v == 1 { 1 } else { 0 } } else { 0 };
|
||||
if let Some(v) = sval { if v == 0 || v == 1 { 1 } else { 0 } } else { 0 }
|
||||
} else if target == "string" {
|
||||
out = 0; // no string registers in inline model
|
||||
0 // no string registers in inline model
|
||||
} else {
|
||||
out = 0;
|
||||
}
|
||||
0
|
||||
};
|
||||
regs.insert(dst, out);
|
||||
} else {
|
||||
// cast/as: pass-through (MVP)
|
||||
|
||||
@ -2,7 +2,7 @@ use super::ast::{ProgramV0, StmtV0, ExprV0};
|
||||
use crate::mir::Callee;
|
||||
use crate::mir::{
|
||||
BasicBlockId, ConstValue, EffectMask, FunctionSignature, MirFunction, MirInstruction, MirModule,
|
||||
MirPrinter, MirType, ValueId, BinaryOp,
|
||||
MirPrinter, MirType, ValueId,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::cell::RefCell;
|
||||
@ -103,6 +103,7 @@ pub(super) struct BridgeEnv {
|
||||
}
|
||||
|
||||
impl BridgeEnv {
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn load() -> Self {
|
||||
Self::with_imports(HashMap::new())
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ use super::BridgeEnv;
|
||||
use super::ternary;
|
||||
use super::match_expr;
|
||||
use crate::mir::{
|
||||
BasicBlockId, BinaryOp, ConstValue, EffectMask, MirFunction, MirInstruction, ValueId,
|
||||
BasicBlockId, ConstValue, EffectMask, MirFunction, MirInstruction, ValueId,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use super::{lower_stmt_list_with_vars, merge_var_maps, new_block, BridgeEnv, LoopContext};
|
||||
use crate::mir::{BasicBlockId, MirFunction, MirInstruction, ValueId};
|
||||
use crate::mir::{BasicBlockId, MirFunction, ValueId};
|
||||
use std::collections::HashMap;
|
||||
use super::super::ast::StmtV0;
|
||||
use super::super::ast::ExprV0;
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
use super::merge::new_block;
|
||||
use super::BridgeEnv;
|
||||
use crate::mir::{BasicBlockId, MirFunction, MirInstruction, ValueId};
|
||||
use crate::mir::{BasicBlockId, MirFunction, ValueId};
|
||||
use super::super::ast::ExprV0;
|
||||
|
||||
use super::expr::{lower_expr_with_scope, VarScope};
|
||||
@ -35,7 +35,7 @@ pub(super) fn lower_ternary_expr_with_scope<S: VarScope>(
|
||||
}
|
||||
let out = f.next_value_id();
|
||||
// フェーズM.2: PHI統一処理(no_phi分岐削除)
|
||||
let mut inputs = vec![(tend, tval), (eend, eval)];
|
||||
let inputs = vec![(tend, tval), (eend, eval)];
|
||||
crate::mir::ssot::cf_common::insert_phi_at_head(f, merge_bb, out, inputs);
|
||||
Ok((out, merge_bb))
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use crate::mir::{BasicBlockId, MirFunction, MirInstruction, ValueId};
|
||||
use crate::mir::{BasicBlockId, MirFunction, ValueId};
|
||||
use std::cell::RefCell;
|
||||
|
||||
thread_local! {
|
||||
|
||||
@ -511,27 +511,6 @@ pub fn try_parse_v1_to_module(json: &str) -> Result<Option<MirModule>, String> {
|
||||
if let Some(d) = dst_opt { max_value_id = max_value_id.max(d.as_u32() + 1); }
|
||||
}
|
||||
}
|
||||
"Constructor" => {
|
||||
// box_type: string, dst: required
|
||||
let dst = dst_opt.ok_or_else(|| format!(
|
||||
"mir_call Constructor requires dst in function '{}'",
|
||||
func_name
|
||||
))?;
|
||||
let bt = callee_obj
|
||||
.get("box_type")
|
||||
.and_then(Value::as_str)
|
||||
.ok_or_else(|| format!(
|
||||
"mir_call Constructor missing box_type in function '{}'",
|
||||
func_name
|
||||
))?
|
||||
.to_string();
|
||||
block_ref.add_instruction(MirInstruction::NewBox {
|
||||
dst,
|
||||
box_type: bt,
|
||||
args: argv.clone(),
|
||||
});
|
||||
max_value_id = max_value_id.max(dst.as_u32() + 1);
|
||||
}
|
||||
"Extern" => {
|
||||
let name = callee_obj
|
||||
.get("name")
|
||||
|
||||
@ -31,6 +31,7 @@ fn create_json_v1_root(functions: serde_json::Value) -> serde_json::Value {
|
||||
/// Helper: detect residual numeric-core boxcalls that should have been lowered by AotPrepNumericCoreBox.
|
||||
/// Currently we only check for `boxcall` with `method:"mul_naive"` which should become
|
||||
/// `call("NyNumericMatI64.mul_naive", ...)` when NYASH_AOT_NUMERIC_CORE=1 is effective.
|
||||
#[allow(dead_code)]
|
||||
fn has_numeric_core_boxcall(root: &serde_json::Value) -> bool {
|
||||
let funs = match root.get("functions") {
|
||||
Some(v) => v.as_array().cloned().unwrap_or_default(),
|
||||
@ -61,6 +62,7 @@ fn has_numeric_core_boxcall(root: &serde_json::Value) -> bool {
|
||||
/// Helper: enforce numeric_core invariants when NYASH_AOT_NUMERIC_CORE=1 is set.
|
||||
/// - Default: emit a warning if mul_naive boxcalls are still present.
|
||||
/// - Strict: if NYASH_AOT_NUMERIC_CORE_STRICT=1, return Err to fail fast.
|
||||
#[allow(dead_code)]
|
||||
fn check_numeric_core_invariants(root: &serde_json::Value) -> Result<(), String> {
|
||||
let numeric_on = matches!(std::env::var("NYASH_AOT_NUMERIC_CORE").ok().as_deref(), Some("1"));
|
||||
if !numeric_on {
|
||||
|
||||
@ -22,7 +22,7 @@ pub fn gather_required_providers() -> Vec<String> {
|
||||
return v;
|
||||
}
|
||||
// Default conservative set
|
||||
let mut v = vec![
|
||||
let v = vec![
|
||||
"FileBox".to_string(),
|
||||
"ConsoleBox".to_string(),
|
||||
"ArrayBox".to_string(),
|
||||
@ -86,4 +86,3 @@ pub fn check_and_report(strict: bool, quiet_pipe: bool, label: &str) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -111,7 +111,7 @@ impl<'a> PreludeManagerBox<'a> {
|
||||
fn build_text_merged(
|
||||
&self,
|
||||
source: &str,
|
||||
filename: &str,
|
||||
_filename: &str,
|
||||
prelude_paths: &[String],
|
||||
trace: bool,
|
||||
) -> Result<String, String> {
|
||||
@ -123,7 +123,7 @@ impl<'a> PreludeManagerBox<'a> {
|
||||
.map_err(|e| format!("using: failed to read '{}': {}", path, e))?;
|
||||
|
||||
// using行を除去して正規化
|
||||
let using_resolver = UsingResolutionBox::new(&self.runner, path)?;
|
||||
let _using_resolver = UsingResolutionBox::new(&self.runner, path)?;
|
||||
let (cleaned_raw, _nested) = self.collect_using_and_strip_internal(&content, path)?;
|
||||
let cleaned = self.normalize_text_for_inline(&cleaned_raw);
|
||||
|
||||
|
||||
@ -129,7 +129,7 @@ impl<'a> SelfhostPipelineBox<'a> {
|
||||
&self,
|
||||
error: &str,
|
||||
original_code: &str,
|
||||
filename: &str,
|
||||
_filename: &str,
|
||||
) -> CompilationResult {
|
||||
eprintln!("[selfhost-pipeline] ⚠️ Error: {}", error);
|
||||
eprintln!("[selfhost-pipeline] 🔄 Falling back to original code");
|
||||
@ -179,8 +179,8 @@ impl<'a> SelfhostPipelineBox<'a> {
|
||||
/// 📊 パフォーマンスプロファイリングするにゃ!
|
||||
pub fn profile_pipeline(
|
||||
&mut self,
|
||||
code: &str,
|
||||
filename: &str,
|
||||
_code: &str,
|
||||
_filename: &str,
|
||||
) -> Result<String, String> {
|
||||
// プロファイル機能を実装(別途)
|
||||
// TODO: プロファイル機能を追加
|
||||
|
||||
@ -448,7 +448,7 @@ pub fn resolve_prelude_paths_profiled(
|
||||
// must be discovered so that their definitions are present at runtime
|
||||
// (e.g., runner_min -> lower_* boxes). Previously this only ran when
|
||||
// NYASH_USING_AST=1, which caused unresolved calls in inline flows.
|
||||
let ast_on = crate::config::env::env_bool("NYASH_USING_AST");
|
||||
let _ast_on = crate::config::env::env_bool("NYASH_USING_AST");
|
||||
let mut out: Vec<String> = Vec::new();
|
||||
let mut seen: std::collections::HashSet<String> = std::collections::HashSet::new();
|
||||
fn normalize_path(path: &str) -> (String, String) {
|
||||
|
||||
@ -14,6 +14,7 @@ pub struct UsingResolutionBox<'a> {
|
||||
runner: &'a NyashRunner,
|
||||
config: UsingConfig,
|
||||
ctx_dir: Option<PathBuf>,
|
||||
#[allow(dead_code)]
|
||||
filename_canon: Option<PathBuf>,
|
||||
inside_pkg: bool,
|
||||
seen_paths: HashMap<String, (String, usize)>, // canon_path -> (alias/label, first_line)
|
||||
|
||||
@ -476,7 +476,7 @@ impl NyashRunner {
|
||||
|
||||
match vm.execute_module(&module_vm) {
|
||||
Ok(ret) => {
|
||||
use crate::box_trait::{NyashBox, IntegerBox, BoolBox};
|
||||
use crate::box_trait::{IntegerBox, BoolBox};
|
||||
|
||||
// Extract exit code from return value
|
||||
let exit_code = if let Some(ib) = ret.as_any().downcast_ref::<IntegerBox>() {
|
||||
|
||||
@ -321,7 +321,7 @@ impl NyashRunner {
|
||||
}
|
||||
match vm.execute_module(&module_vm) {
|
||||
Ok(ret) => {
|
||||
use crate::box_trait::{NyashBox, IntegerBox, BoolBox};
|
||||
use crate::box_trait::{IntegerBox, BoolBox};
|
||||
|
||||
// Extract exit code from return value
|
||||
let exit_code = if let Some(ib) = ret.as_any().downcast_ref::<IntegerBox>() {
|
||||
@ -346,7 +346,8 @@ impl NyashRunner {
|
||||
|
||||
impl NyashRunner {
|
||||
/// Small helper to continue fallback execution once AST is prepared
|
||||
fn execute_vm_fallback_from_ast(&self, filename: &str, ast: nyash_rust::ast::ASTNode) {
|
||||
#[allow(dead_code)]
|
||||
fn execute_vm_fallback_from_ast(&self, _filename: &str, ast: nyash_rust::ast::ASTNode) {
|
||||
use crate::{
|
||||
backend::MirInterpreter,
|
||||
box_factory::{BoxFactory, RuntimeError},
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
*/
|
||||
|
||||
use super::*;
|
||||
use crate::runner::child_env;
|
||||
|
||||
impl NyashRunner {
|
||||
/// Try to handle `--ny-parser-pipe` / `--json-file` flow.
|
||||
@ -20,7 +19,7 @@ impl NyashRunner {
|
||||
if !(groups.parser.ny_parser_pipe || groups.parser.json_file.is_some()) {
|
||||
return false;
|
||||
}
|
||||
let mut json = if let Some(path) = &groups.parser.json_file {
|
||||
let json = if let Some(path) = &groups.parser.json_file {
|
||||
match std::fs::read_to_string(path) {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
|
||||
@ -84,6 +84,7 @@ impl NyashRunner {
|
||||
}
|
||||
|
||||
/// Suggest candidate files by leaf name within limited bases (apps/lib/.)
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn suggest_in_base(base: &str, leaf: &str, out: &mut Vec<String>) {
|
||||
use std::fs;
|
||||
fn walk(dir: &std::path::Path, leaf: &str, out: &mut Vec<String>, depth: usize) {
|
||||
|
||||
@ -58,7 +58,7 @@ impl NyashRunner {
|
||||
for p in list {
|
||||
if list_only { println!(" • {}", p); continue; }
|
||||
match std::fs::read_to_string(&p) {
|
||||
Ok(code) => {
|
||||
Ok(_code) => {
|
||||
// Legacy interpreter removed - ny_plugins execution disabled
|
||||
println!("[ny_plugins] {}: SKIP (legacy interpreter removed)", p);
|
||||
}
|
||||
|
||||
@ -403,21 +403,22 @@ impl NyashRunner {
|
||||
// パイプライン(tools/ny_selfhost_inline.sh など)を使う想定とし、ここでは常に Rust 既定
|
||||
// パスへフォールバックする。
|
||||
crate::cli_v!("[ny-compiler] inline selfhost pipeline disabled (Phase 25.1b); falling back to default path");
|
||||
return false;
|
||||
|
||||
match super::json_v0_bridge::parse_json_v0_to_module("") {
|
||||
Ok(module) => {
|
||||
if crate::config::env::cli_verbose() {
|
||||
// Dev-only escape hatch: allow forcing the old inline path when explicitly requested.
|
||||
if std::env::var("NYASH_SELFHOST_INLINE_FORCE").ok().as_deref() == Some("1") {
|
||||
match super::json_v0_bridge::parse_json_v0_to_module("") {
|
||||
Ok(module) => {
|
||||
if crate::config::env::cli_verbose() {
|
||||
super::json_v0_bridge::maybe_dump_mir(&module);
|
||||
if crate::config::env::cli_verbose() {
|
||||
super::json_v0_bridge::maybe_dump_mir(&module);
|
||||
}
|
||||
}
|
||||
let emit_only = std::env::var("NYASH_NY_COMPILER_EMIT_ONLY")
|
||||
.unwrap_or_else(|_| "1".to_string())
|
||||
== "1";
|
||||
if emit_only {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
let emit_only = std::env::var("NYASH_NY_COMPILER_EMIT_ONLY")
|
||||
.unwrap_or_else(|_| "1".to_string())
|
||||
== "1";
|
||||
if emit_only {
|
||||
return false;
|
||||
}
|
||||
// Phase-15 policy: when NYASH_VM_USE_PY=1, prefer PyVM as reference executor
|
||||
// regardless of BoxCall presence to ensure semantics parity (e.g., PHI merges).
|
||||
let prefer_pyvm = std::env::var("NYASH_VM_USE_PY").ok().as_deref() == Some("1");
|
||||
@ -430,25 +431,29 @@ impl NyashRunner {
|
||||
})
|
||||
})
|
||||
});
|
||||
if prefer_pyvm || needs_pyvm {
|
||||
let label = if prefer_pyvm { "selfhost" } else { "selfhost-fallback" };
|
||||
if let Some(code) = crate::runner::modes::common_util::selfhost::json::run_pyvm_module(&module, label) {
|
||||
println!("Result: {}", code);
|
||||
std::process::exit(code);
|
||||
if prefer_pyvm || needs_pyvm {
|
||||
let label = if prefer_pyvm { "selfhost" } else { "selfhost-fallback" };
|
||||
if let Some(code) = crate::runner::modes::common_util::selfhost::json::run_pyvm_module(&module, label) {
|
||||
println!("Result: {}", code);
|
||||
std::process::exit(code);
|
||||
}
|
||||
}
|
||||
crate::runner::child_env::pre_run_reset_oob_if_strict();
|
||||
self.execute_mir_module(&module);
|
||||
if crate::config::env::oob_strict_fail() && crate::runtime::observe::oob_seen() {
|
||||
eprintln!("[selfhost][oob-strict] Out-of-bounds observed → exit(1)");
|
||||
std::process::exit(1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
crate::runner::child_env::pre_run_reset_oob_if_strict();
|
||||
self.execute_mir_module(&module);
|
||||
if crate::config::env::oob_strict_fail() && crate::runtime::observe::oob_seen() {
|
||||
eprintln!("[selfhost][oob-strict] Out-of-bounds observed → exit(1)");
|
||||
std::process::exit(1);
|
||||
Err(e) => {
|
||||
eprintln!("❌ JSON v0 bridge error: {}", e);
|
||||
return false;
|
||||
}
|
||||
true
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("❌ JSON v0 bridge error: {}", e);
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
// Default path: always fall back to existing Rust runner.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
use super::library;
|
||||
use super::PluginLoaderV2;
|
||||
use crate::bid::{BidError, BidResult};
|
||||
|
||||
|
||||
@ -6,8 +6,8 @@ mod specs;
|
||||
mod util;
|
||||
|
||||
use super::host_bridge::BoxInvokeFn;
|
||||
use super::types::{LoadedPluginV2, PluginBoxMetadata, PluginBoxV2, PluginHandleInner};
|
||||
use crate::bid::{BidError, BidResult};
|
||||
use super::types::{LoadedPluginV2, PluginBoxMetadata, PluginHandleInner};
|
||||
use crate::bid::BidResult;
|
||||
use crate::box_trait::NyashBox;
|
||||
use crate::config::nyash_toml_v2::{LibraryDefinition, NyashConfigV2};
|
||||
use specs::LoadedBoxSpec;
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
use super::specs;
|
||||
use super::PluginLoaderV2;
|
||||
use crate::bid::{BidError, BidResult};
|
||||
use crate::runtime::plugin_loader_v2::enabled::{errors, host_bridge, types};
|
||||
|
||||
@ -18,6 +18,7 @@ pub(crate) struct LoadedBoxSpec {
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub(crate) struct MethodSpec {
|
||||
pub(crate) method_id: u32,
|
||||
#[allow(dead_code)]
|
||||
pub(crate) returns_result: bool,
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
|
||||
use crate::bid::{BidError, BidResult};
|
||||
use crate::runtime::plugin_loader_v2::enabled::PluginLoaderV2;
|
||||
use std::collections::HashMap;
|
||||
|
||||
impl PluginLoaderV2 {
|
||||
/// Resolve a method ID for a given box type and method name
|
||||
@ -37,7 +36,7 @@ impl PluginLoaderV2 {
|
||||
// Fallback to TypeBox FFI spec
|
||||
if let Ok(map) = self.box_specs.read() {
|
||||
// Try direct lookup first
|
||||
for ((lib, bt), spec) in map.iter() {
|
||||
for ((_lib, bt), spec) in map.iter() {
|
||||
if bt == box_type {
|
||||
// Check methods map
|
||||
if let Some(ms) = spec.methods.get(method_name) {
|
||||
@ -47,7 +46,7 @@ impl PluginLoaderV2 {
|
||||
// Try resolve function
|
||||
if let Some(res_fn) = spec.resolve_fn {
|
||||
if let Ok(cstr) = std::ffi::CString::new(method_name) {
|
||||
let mid = unsafe { res_fn(cstr.as_ptr()) };
|
||||
let mid = res_fn(cstr.as_ptr());
|
||||
if mid != 0 {
|
||||
return Ok(mid);
|
||||
}
|
||||
@ -130,11 +129,13 @@ impl PluginLoaderV2 {
|
||||
}
|
||||
|
||||
/// Helper functions for method resolution
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn is_special_method(method_name: &str) -> bool {
|
||||
matches!(method_name, "birth" | "fini" | "toString")
|
||||
}
|
||||
|
||||
/// Get default method IDs for special methods
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn get_special_method_id(method_name: &str) -> Option<u32> {
|
||||
match method_name {
|
||||
"birth" => Some(1),
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
use crate::box_factory::builtin::BuiltinBoxFactory;
|
||||
#[cfg(feature = "plugins")]
|
||||
use crate::box_factory::plugin::PluginBoxFactory;
|
||||
use crate::box_factory::{UnifiedBoxRegistry, FactoryPolicy};
|
||||
use crate::box_factory::UnifiedBoxRegistry;
|
||||
use std::sync::{Arc, Mutex, OnceLock};
|
||||
|
||||
/// Global registry instance
|
||||
|
||||
Reference in New Issue
Block a user