Phase 1 Complete: Remove critical debug statements - Major performance improvement

Co-authored-by: moe-charm <217100418+moe-charm@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-08-20 00:07:47 +00:00
parent f07d3d89e8
commit ce16f592b8
5 changed files with 2 additions and 70 deletions

View File

@ -256,28 +256,22 @@ impl NyashInterpreter {
/// ASTを実行
pub fn execute(&mut self, ast: ASTNode) -> Result<Box<dyn NyashBox>, RuntimeError> {
debug_log("=== NYASH EXECUTION START ===");
eprintln!("🔍 DEBUG: Starting interpreter execution...");
let result = self.execute_node(&ast);
if let Err(ref e) = result {
eprintln!("❌ Interpreter error: {}", e);
}
debug_log("=== NYASH EXECUTION END ===");
eprintln!("🔍 DEBUG: Interpreter execution completed");
result
}
/// ノードを実行
fn execute_node(&mut self, node: &ASTNode) -> Result<Box<dyn NyashBox>, RuntimeError> {
eprintln!("🔍 DEBUG: execute_node called with node type: {}", node.node_type());
match node {
ASTNode::Program { statements, .. } => {
eprintln!("🔍 DEBUG: Executing program with {} statements", statements.len());
let mut result: Box<dyn NyashBox> = Box::new(VoidBox::new());
for (i, statement) in statements.iter().enumerate() {
eprintln!("🔍 DEBUG: Executing statement {} of {}: {}", i + 1, statements.len(), statement.node_type());
for statement in statements.iter() {
result = self.execute_statement(statement)?;
eprintln!("🔍 DEBUG: Statement {} completed", i + 1);
// 制御フローチェック
match &self.control_flow {
@ -343,88 +337,51 @@ impl NyashInterpreter {
let log_msg = format!("resolve_variable: name='{}', local_vars={:?}",
name, self.local_vars.keys().collect::<Vec<_>>());
debug_log(&log_msg);
eprintln!("🔍 DEBUG: {}", log_msg);
// 1. outbox変数を最初にチェックstatic関数内で優先
if let Some(outbox_value) = self.outbox_vars.get(name) {
eprintln!("🔍 DEBUG: Found '{}' in outbox_vars", name);
// 🔧 修正clone_box() → Arc::clone() で参照共有
let shared_value = Arc::clone(outbox_value);
eprintln!("✅ RESOLVE_VARIABLE shared reference: {} id={}",
name, shared_value.box_id());
return Ok(shared_value);
}
// 2. local変数をチェック
if let Some(local_value) = self.local_vars.get(name) {
eprintln!("🔍 DEBUG: Found '{}' in local_vars", name);
// 🔧 修正clone_box() → Arc::clone() で参照共有
let shared_value = Arc::clone(local_value);
eprintln!("✅ RESOLVE_VARIABLE shared reference: {} id={}",
name, shared_value.box_id());
return Ok(shared_value);
}
// 3. GlobalBoxのフィールドをチェック
eprintln!("🔍 DEBUG: Checking GlobalBox for '{}'...", name);
let global_box = self.shared.global_box.lock().unwrap();
if let Some(field_value) = global_box.get_field(name) {
eprintln!("🔍 DEBUG: Found '{}' in GlobalBox", name);
return Ok(field_value);
}
// 4. statics名前空間内のstatic boxをチェック
eprintln!("🔍 DEBUG: Checking statics namespace for '{}'...", name);
if let Some(statics_namespace) = global_box.get_field("statics") {
eprintln!("🔍 DEBUG: statics namespace type: {}", statics_namespace.type_name());
// MapBoxとして試す
if let Some(map_box) = statics_namespace.as_any().downcast_ref::<crate::boxes::map_box::MapBox>() {
eprintln!("🔍 DEBUG: statics is a MapBox, looking for '{}'", name);
let key_box: Box<dyn NyashBox> = Box::new(StringBox::new(name));
let static_box_result = map_box.get(key_box);
// NullBoxでないかチェックMapBoxは見つからない場合NullBoxを返す
if static_box_result.type_name() != "NullBox" {
eprintln!("🔍 DEBUG: Found '{}' in statics namespace", name);
return Ok(Arc::from(static_box_result));
} else {
eprintln!("🔍 DEBUG: '{}' not found in statics MapBox", name);
}
} else if let Some(instance) = statics_namespace.as_any().downcast_ref::<InstanceBox>() {
eprintln!("🔍 DEBUG: statics is an InstanceBox, looking for '{}'", name);
if let Some(static_box) = instance.get_field(name) {
eprintln!("🔍 DEBUG: Found '{}' in statics namespace", name);
return Ok(static_box);
} else {
eprintln!("🔍 DEBUG: '{}' not found in statics InstanceBox", name);
}
} else {
eprintln!("🔍 DEBUG: statics namespace is neither MapBox nor InstanceBox");
}
}
drop(global_box); // lockを解放してからstdlibチェック
// 5. nyashstd標準ライブラリ名前空間をチェック
eprintln!("🔍 DEBUG: Checking nyashstd stdlib for '{}'...", name);
if let Some(ref stdlib) = self.stdlib {
eprintln!("🔍 DEBUG: stdlib is initialized, checking namespaces...");
eprintln!("🔍 DEBUG: Available namespaces: {:?}", stdlib.namespaces.keys().collect::<Vec<_>>());
if let Some(nyashstd_namespace) = stdlib.namespaces.get("nyashstd") {
eprintln!("🔍 DEBUG: nyashstd namespace found, checking static boxes...");
eprintln!("🔍 DEBUG: Available static boxes: {:?}", nyashstd_namespace.static_boxes.keys().collect::<Vec<_>>());
if let Some(_static_box) = nyashstd_namespace.static_boxes.get(name) {
eprintln!("🔍 DEBUG: Found '{}' in nyashstd namespace", name);
// BuiltinStaticBoxをInstanceBoxとしてラップ
let static_instance = InstanceBox::new(
format!("{}_builtin", name),
@ -433,14 +390,8 @@ impl NyashInterpreter {
);
return Ok(Arc::new(static_instance));
} else {
eprintln!("🔍 DEBUG: '{}' not found in nyashstd namespace", name);
}
} else {
eprintln!("🔍 DEBUG: nyashstd namespace not found in stdlib");
}
} else {
eprintln!("🔍 DEBUG: stdlib not initialized");
}
// 6. エラー:見つからない

View File

@ -45,13 +45,10 @@ impl NyashInterpreter {
message: format!("Field '{}' not found in {}", field, instance.class_name),
})?;
eprintln!("✅ FIELD ACCESS: Returning shared reference id={}", field_value.box_id());
// 🔗 Weak Reference Check: Use unified accessor for weak fields
let box_decls = self.shared.box_declarations.read().unwrap();
if let Some(box_decl) = box_decls.get(&instance.class_name) {
if box_decl.weak_fields.contains(&field.to_string()) {
eprintln!("🔗 DEBUG: Accessing weak field '{}' in class '{}'", field, instance.class_name);
// 🎯 PHASE 2: Use unified accessor for auto-nil weak reference handling
if let Some(weak_value) = instance.get_weak_field(field, self) { // Pass self

View File

@ -22,31 +22,22 @@ fn unwrap_instance(boxed: &dyn NyashBox) -> &dyn NyashBox {
boxed
}
pub(super) fn try_add_operation(left: &dyn NyashBox, right: &dyn NyashBox) -> Option<Box<dyn NyashBox>> {
// 🔍 デバッグ出力追加
eprintln!("🔍 try_add_operation: left={}, right={}", left.type_name(), right.type_name());
// 🎯 InstanceBoxのunwrap処理
let left = unwrap_instance(left);
let right = unwrap_instance(right);
eprintln!("🔍 After unwrap: left={}, right={}", left.type_name(), right.type_name());
// IntegerBox + IntegerBox
if let (Some(left_int), Some(right_int)) = (
left.as_any().downcast_ref::<IntegerBox>(),
right.as_any().downcast_ref::<IntegerBox>()
) {
eprintln!("🔍 IntegerBox + IntegerBox detected");
return Some(Box::new(IntegerBox::new(left_int.value + right_int.value)));
}
// StringBox + anything -> concatenation
eprintln!("🔍 Checking StringBox downcast...");
if let Some(left_str) = left.as_any().downcast_ref::<StringBox>() {
eprintln!("🔍 StringBox downcast SUCCESS!");
let right_str = right.to_string_box();
return Some(Box::new(StringBox::new(format!("{}{}", left_str.value, right_str.value))));
} else {
eprintln!("🔍 StringBox downcast FAILED!");
}
// BoolBox + BoolBox -> IntegerBox
@ -139,7 +130,7 @@ impl NyashInterpreter {
-> Result<Box<dyn NyashBox>, RuntimeError> {
let left_val = self.execute_expression(left)?;
let right_val = self.execute_expression(right)?;
eprintln!("🔧 execute_binary_op: op={:?}, left={}, right={}", op, left_val.type_name(), right_val.type_name());
// Binary operation execution
match op {
BinaryOperator::Add => {

View File

@ -16,10 +16,8 @@ impl NyashInterpreter {
/// new式を実行 - Object creation engine
pub(super) fn execute_new(&mut self, class: &str, arguments: &[ASTNode], type_arguments: &[String])
-> Result<Box<dyn NyashBox>, RuntimeError> {
eprintln!("🔍 execute_new called for class: {}, with {} arguments", class, arguments.len());
// 🏭 Phase 9.78b: Try unified registry first
eprintln!("🔍 Trying unified registry for class: {}", class);
// Convert ASTNode arguments to Box<dyn NyashBox>
let nyash_args: Result<Vec<Box<dyn NyashBox>>, RuntimeError> = arguments.iter()
@ -35,7 +33,6 @@ impl NyashInterpreter {
match registry_lock.create_box(class, &args) {
Ok(box_instance) => {
eprintln!("🏭 Unified registry created: {}", class);
// Check if this is a user-defined box that needs constructor execution
if let Some(_instance_box) = box_instance.as_any().downcast_ref::<crate::instance_v2::InstanceBox>() {

View File

@ -13,10 +13,8 @@ use std::sync::Arc;
impl NyashInterpreter {
/// 文を実行 - Core statement execution engine
pub(super) fn execute_statement(&mut self, statement: &ASTNode) -> Result<Box<dyn NyashBox>, RuntimeError> {
eprintln!("🔍 execute_statement called with node type: {:?}", statement.node_type());
match statement {
ASTNode::Assignment { target, value, .. } => {
eprintln!("🔍 About to call execute_assignment...");
self.execute_assignment(target, value)
}
@ -246,9 +244,7 @@ impl NyashInterpreter {
/// 代入処理を実行 - Assignment processing
pub(super) fn execute_assignment(&mut self, target: &ASTNode, value: &ASTNode) -> Result<Box<dyn NyashBox>, RuntimeError> {
eprintln!("🔍 execute_assignment called, evaluating value expression...");
let val = self.execute_expression(value)?;
eprintln!("🔍 execute_assignment: value expression evaluated successfully");
match target {
ASTNode::Variable { name, .. } => {