diff --git a/src/backend/vm.rs b/src/backend/vm.rs index e596cdfd..9b620bd3 100644 --- a/src/backend/vm.rs +++ b/src/backend/vm.rs @@ -364,67 +364,27 @@ impl VM { Ok(ControlFlow::Continue) }, - MirInstruction::TypeCheck { dst, value: _, expected_type: _ } => { - // For now, type checks always return true - // TODO: Implement proper type checking - self.values.insert(*dst, VMValue::Bool(true)); - Ok(ControlFlow::Continue) - }, - - MirInstruction::Cast { dst, value, target_type: _ } => { - // For now, casting just copies the value - // TODO: Implement proper type casting - let val = self.get_value(*value)?; - self.values.insert(*dst, val); - Ok(ControlFlow::Continue) - }, - - MirInstruction::ArrayGet { dst, array: _, index: _ } => { - // For now, array access returns a placeholder - // TODO: Implement proper array access - self.values.insert(*dst, VMValue::Integer(0)); - Ok(ControlFlow::Continue) - }, - - MirInstruction::ArraySet { array: _, index: _, value: _ } => { - // For now, array setting is a no-op - // TODO: Implement proper array setting - Ok(ControlFlow::Continue) - }, - - MirInstruction::Copy { dst, src } => { - // Copy instruction - duplicate the source value - let val = self.get_value(*src)?; - self.values.insert(*dst, val); - Ok(ControlFlow::Continue) - }, - - MirInstruction::Debug { value, message: _ } => { - // Debug instruction - print value for debugging - let val = self.get_value(*value)?; - println!("DEBUG: {}", val.to_string()); - Ok(ControlFlow::Continue) - }, - + // Phase 5: Removed instructions - TypeCheck, Cast, ArrayGet, ArraySet, Copy, Debug, Nop + #[allow(deprecated)] + MirInstruction::TypeCheck { .. } | + MirInstruction::Cast { .. } | + MirInstruction::ArrayGet { .. } | + MirInstruction::ArraySet { .. } | + MirInstruction::Copy { .. } | + MirInstruction::Debug { .. } | MirInstruction::Nop => { - // No-op instruction - Ok(ControlFlow::Continue) + Err(VMError::InvalidInstruction( + "Phase 5: Deprecated instruction - use 26-instruction set replacements".to_string() + )) }, - // Phase 5: Control flow & exception handling - MirInstruction::Throw { exception, effects: _ } => { - let exception_val = self.get_value(*exception)?; - // For now, convert throw to error return (simplified exception handling) - // In a full implementation, this would unwind the stack looking for catch handlers - println!("Exception thrown: {}", exception_val.to_string()); - Err(VMError::InvalidInstruction(format!("Unhandled exception: {}", exception_val.to_string()))) - }, - - MirInstruction::Catch { exception_type: _, exception_value, handler_bb: _ } => { - // For now, catch is a no-op since we don't have full exception handling - // In a real implementation, this would set up exception handling metadata - self.values.insert(*exception_value, VMValue::Void); - Ok(ControlFlow::Continue) + // Phase 5: Removed instructions - Throw, Catch + #[allow(deprecated)] + MirInstruction::Throw { .. } | + MirInstruction::Catch { .. } => { + Err(VMError::InvalidInstruction( + "Phase 5: Exception handling via intrinsics - use Call with @throw/@catch".to_string() + )) }, MirInstruction::Safepoint => { @@ -433,34 +393,12 @@ impl VM { Ok(ControlFlow::Continue) }, - // Phase 6: Box reference operations - MirInstruction::RefNew { dst, box_val } => { - // Get the box type/value from the previous Const instruction - let box_value = self.get_value(*box_val)?; - - // If this is a Box type name (like "StringBox", "IntegerBox"), create an appropriate default value - // In the context of Everything is Box, this should create the actual Box instance - let ref_value = match &box_value { - VMValue::String(type_name) => { - match type_name.as_str() { - "StringBox" => { - // For StringBox, we need the actual string content from previous context - // For now, create an empty string - this should be improved to use the actual value - VMValue::String(String::new()) - }, - "IntegerBox" => VMValue::Integer(0), - "BoolBox" => VMValue::Bool(false), - _ => { - // If it's a regular string (not a type name), use it as-is - VMValue::String(type_name.clone()) - } - } - }, - _ => box_value, // For non-string values, use as-is - }; - - self.values.insert(*dst, ref_value); - Ok(ControlFlow::Continue) + // Phase 5: Removed instruction - RefNew + #[allow(deprecated)] + MirInstruction::RefNew { .. } => { + Err(VMError::InvalidInstruction( + "Phase 5: RefNew deprecated - RefGet is sufficient".to_string() + )) }, // Phase 3: RefGet/RefSet removed - now handled by BoxFieldLoad/BoxFieldStore @@ -481,61 +419,23 @@ impl VM { Ok(ControlFlow::Continue) }, - MirInstruction::BarrierRead { ptr: _ } => { - // Memory barrier read is a no-op for now - // In a real implementation, this would ensure memory ordering - Ok(ControlFlow::Continue) + // Phase 5: Removed instructions - BarrierRead, BarrierWrite + #[allow(deprecated)] + MirInstruction::BarrierRead { .. } | + MirInstruction::BarrierWrite { .. } => { + Err(VMError::InvalidInstruction( + "Phase 5: Memory barriers deprecated - use AtomicFence".to_string() + )) }, - MirInstruction::BarrierWrite { ptr: _ } => { - // Memory barrier write is a no-op for now - // In a real implementation, this would ensure memory ordering - Ok(ControlFlow::Continue) - }, - - // Phase 7: Async/Future Operations - MirInstruction::FutureNew { dst, value } => { - let initial_value = self.get_value(*value)?; - println!("FutureNew: initial_value = {:?}", initial_value); - let future = crate::boxes::future::FutureBox::new(); - // Convert VMValue to NyashBox and set it in the future - let nyash_box = initial_value.to_nyash_box(); - println!("FutureNew: converted to NyashBox type = {}", nyash_box.type_name()); - future.set_result(nyash_box); - self.values.insert(*dst, VMValue::Future(future)); - println!("FutureNew: stored Future in dst = {:?}", dst); - Ok(ControlFlow::Continue) - }, - - MirInstruction::FutureSet { future, value } => { - let future_val = self.get_value(*future)?; - let new_value = self.get_value(*value)?; - - if let VMValue::Future(ref future_box) = future_val { - future_box.set_result(new_value.to_nyash_box()); - Ok(ControlFlow::Continue) - } else { - Err(VMError::TypeError(format!("Expected Future, got {:?}", future_val))) - } - }, - - MirInstruction::Await { dst, future } => { - let future_val = self.get_value(*future)?; - println!("Await: future_val = {:?}", future_val); - - if let VMValue::Future(ref future_box) = future_val { - // This blocks until the future is ready - let result = future_box.get(); - println!("Await: future.get() returned type = {}", result.type_name()); - println!("Await: future.get() string = {}", result.to_string_box().value); - // Convert NyashBox back to VMValue - let vm_value = VMValue::from_nyash_box(result); - println!("Await: converted back to VMValue = {:?}", vm_value); - self.values.insert(*dst, vm_value); - Ok(ControlFlow::Continue) - } else { - Err(VMError::TypeError(format!("Expected Future, got {:?}", future_val))) - } + // Phase 5: Removed instructions - FutureNew, FutureSet, Await + #[allow(deprecated)] + MirInstruction::FutureNew { .. } | + MirInstruction::FutureSet { .. } | + MirInstruction::Await { .. } => { + Err(VMError::InvalidInstruction( + "Phase 5: Future operations deprecated - use NewBox + BoxCall".to_string() + )) }, // Phase 9.7: External Function Calls diff --git a/src/backend/wasm/codegen.rs b/src/backend/wasm/codegen.rs index 8514b39c..b537c05c 100644 --- a/src/backend/wasm/codegen.rs +++ b/src/backend/wasm/codegen.rs @@ -247,13 +247,12 @@ impl WasmCodegen { // Phase 3: Print removed - now handled by Call intrinsic (@print) // Phase 8.3 PoC2: Reference operations - MirInstruction::RefNew { dst, box_val } => { - // Create a new reference to a Box by copying the Box value - // This assumes box_val contains a Box pointer already - Ok(vec![ - format!("local.get ${}", self.get_local_index(*box_val)?), - format!("local.set ${}", self.get_local_index(*dst)?), - ]) + // Phase 5: RefNew deprecated - just use the value directly + #[allow(deprecated)] + MirInstruction::RefNew { .. } => { + Err(WasmError::UnsupportedInstruction( + "Phase 5: RefNew deprecated - references are handled implicitly".to_string() + )) }, // Phase 3: RefGet/RefSet removed - now handled by BoxFieldLoad/BoxFieldStore @@ -295,29 +294,54 @@ impl WasmCodegen { }, // Phase 8.4 PoC3: Extension stubs - MirInstruction::WeakNew { dst, box_val } | - MirInstruction::FutureNew { dst, value: box_val } => { - // Treat as regular reference for now + MirInstruction::WeakNew { dst, box_val } => { + // WeakNew is still part of 26-instruction set Ok(vec![ format!("local.get ${}", self.get_local_index(*box_val)?), format!("local.set ${}", self.get_local_index(*dst)?), ]) }, - MirInstruction::WeakLoad { dst, weak_ref } | - MirInstruction::Await { dst, future: weak_ref } => { - // Always succeed for now + // Phase 5: FutureNew deprecated - use NewBox "Future" + #[allow(deprecated)] + MirInstruction::FutureNew { .. } => { + Err(WasmError::UnsupportedInstruction( + "Phase 5: FutureNew deprecated - use 'NewBox \"Future\"' instead".to_string() + )) + }, + + MirInstruction::WeakLoad { dst, weak_ref } => { + // WeakLoad is still part of 26-instruction set Ok(vec![ format!("local.get ${}", self.get_local_index(*weak_ref)?), format!("local.set ${}", self.get_local_index(*dst)?), ]) }, - MirInstruction::BarrierRead { .. } | - MirInstruction::BarrierWrite { .. } | - MirInstruction::FutureSet { .. } | + // Phase 5: Await deprecated - use BoxCall Future.await() + #[allow(deprecated)] + MirInstruction::Await { .. } => { + Err(WasmError::UnsupportedInstruction( + "Phase 5: Await deprecated - use 'BoxCall Future.await()' instead".to_string() + )) + }, + + // Phase 5: BarrierRead/BarrierWrite deprecated - use AtomicFence + #[allow(deprecated)] + MirInstruction::BarrierRead { .. } => { + Err(WasmError::UnsupportedInstruction( + "Phase 5: BarrierRead deprecated - use AtomicFence with acquire ordering".to_string() + )) + }, + #[allow(deprecated)] + MirInstruction::BarrierWrite { .. } => { + Err(WasmError::UnsupportedInstruction( + "Phase 5: BarrierWrite deprecated - use AtomicFence with release ordering".to_string() + )) + }, + MirInstruction::Safepoint => { - // No-op for now + // Safepoint is still valid - no-op for now Ok(vec!["nop".to_string()]) }, @@ -497,6 +521,72 @@ impl WasmCodegen { self.generate_call_instruction(dst.as_ref(), *func, args) }, + // Phase 5: Removed instructions - TypeCheck, Cast, ArrayGet, ArraySet, Copy, Debug, Nop + #[allow(deprecated)] + MirInstruction::TypeCheck { .. } | + MirInstruction::Cast { .. } | + MirInstruction::ArrayGet { .. } | + MirInstruction::ArraySet { .. } | + MirInstruction::Copy { .. } | + MirInstruction::Debug { .. } | + MirInstruction::Nop => { + Err(WasmError::UnsupportedInstruction( + "Phase 5: Deprecated instruction - use 26-instruction set replacements".to_string() + )) + }, + + // Phase 5: Removed instructions - UnaryOp (use BinOp instead) + #[allow(deprecated)] + MirInstruction::UnaryOp { .. } => { + Err(WasmError::UnsupportedInstruction( + "Phase 5: UnaryOp deprecated - use BinOp (e.g., 'not x' -> 'x xor true', 'neg x' -> '0 sub x')".to_string() + )) + }, + + // Phase 5: Removed instructions - Load/Store (use BoxFieldLoad/BoxFieldStore) + #[allow(deprecated)] + MirInstruction::Load { .. } => { + Err(WasmError::UnsupportedInstruction( + "Phase 5: Load deprecated - use BoxFieldLoad for field access".to_string() + )) + }, + #[allow(deprecated)] + MirInstruction::Store { .. } => { + Err(WasmError::UnsupportedInstruction( + "Phase 5: Store deprecated - use BoxFieldStore for field updates".to_string() + )) + }, + + // Phase 5: Removed instructions - Print (use Call @print) + #[allow(deprecated)] + MirInstruction::Print { .. } => { + Err(WasmError::UnsupportedInstruction( + "Phase 5: Print deprecated - use 'Call @print' intrinsic function".to_string() + )) + }, + + // Phase 5: Removed instructions - Throw/Catch (use Call @throw/@catch) + #[allow(deprecated)] + MirInstruction::Throw { .. } => { + Err(WasmError::UnsupportedInstruction( + "Phase 5: Throw deprecated - use 'Call @throw' intrinsic function".to_string() + )) + }, + #[allow(deprecated)] + MirInstruction::Catch { .. } => { + Err(WasmError::UnsupportedInstruction( + "Phase 5: Catch deprecated - use 'Call @catch' intrinsic function".to_string() + )) + }, + + // Phase 5: Removed FutureSet - use BoxCall instead + #[allow(deprecated)] + MirInstruction::FutureSet { .. } => { + Err(WasmError::UnsupportedInstruction( + "Phase 5: FutureSet deprecated - use BoxCall method for Future.set()".to_string() + )) + }, + // Unsupported instructions _ => Err(WasmError::UnsupportedInstruction( format!("Instruction not yet supported: {:?}", instruction) diff --git a/src/mir/instruction.rs b/src/mir/instruction.rs index afe121c7..8cebfeca 100644 --- a/src/mir/instruction.rs +++ b/src/mir/instruction.rs @@ -31,6 +31,8 @@ pub enum MirInstruction { /// Unary operation /// `%dst = op %operand` + /// DEPRECATED: Phase 5 - Use BinOp instead (e.g., `not %a` → `%a xor true`, `neg %a` → `0 sub %a`) + #[deprecated(since = "Phase 5", note = "Use BinOp instead")] UnaryOp { dst: ValueId, op: UnaryOp, @@ -50,6 +52,8 @@ pub enum MirInstruction { // === Memory Operations === /// Load from memory/variable /// `%dst = load %ptr` + /// DEPRECATED: Phase 5 - Use BoxFieldLoad instead + #[deprecated(since = "Phase 5", note = "Use BoxFieldLoad instead")] Load { dst: ValueId, ptr: ValueId, @@ -57,6 +61,8 @@ pub enum MirInstruction { /// Store to memory/variable /// `store %value -> %ptr` + /// DEPRECATED: Phase 5 - Use BoxFieldStore instead + #[deprecated(since = "Phase 5", note = "Use BoxFieldStore instead")] Store { value: ValueId, ptr: ValueId, @@ -122,6 +128,8 @@ pub enum MirInstruction { /// Check Box type /// `%dst = type_check %box "BoxType"` + /// DEPRECATED: Phase 5 - Use Call with @type_check intrinsic + #[deprecated(since = "Phase 5", note = "Use Call with @type_check intrinsic")] TypeCheck { dst: ValueId, value: ValueId, @@ -131,6 +139,8 @@ pub enum MirInstruction { // === Type Conversion === /// Convert between types /// `%dst = cast %value as Type` + /// DEPRECATED: Phase 5 - Use Call with @cast intrinsic + #[deprecated(since = "Phase 5", note = "Use Call with @cast intrinsic")] Cast { dst: ValueId, value: ValueId, @@ -140,6 +150,8 @@ pub enum MirInstruction { // === Array Operations === /// Get array element /// `%dst = %array[%index]` + /// DEPRECATED: Phase 5 - Use BoxFieldLoad or Call with @array_get intrinsic + #[deprecated(since = "Phase 5", note = "Use BoxFieldLoad or Call with @array_get intrinsic")] ArrayGet { dst: ValueId, array: ValueId, @@ -148,6 +160,8 @@ pub enum MirInstruction { /// Set array element /// `%array[%index] = %value` + /// DEPRECATED: Phase 5 - Use BoxFieldStore or Call with @array_set intrinsic + #[deprecated(since = "Phase 5", note = "Use BoxFieldStore or Call with @array_set intrinsic")] ArraySet { array: ValueId, index: ValueId, @@ -157,6 +171,8 @@ pub enum MirInstruction { // === Special Operations === /// Copy a value (for optimization passes) /// `%dst = copy %src` + /// DEPRECATED: Phase 5 - Optimization pass only, not needed in IR + #[deprecated(since = "Phase 5", note = "Optimization pass only, not needed in IR")] Copy { dst: ValueId, src: ValueId, @@ -164,6 +180,8 @@ pub enum MirInstruction { /// Debug/introspection instruction /// `debug %value "message"` + /// DEPRECATED: Phase 5 - Use Call with @debug intrinsic + #[deprecated(since = "Phase 5", note = "Use Call with @debug intrinsic")] Debug { value: ValueId, message: String, @@ -171,18 +189,24 @@ pub enum MirInstruction { /// Print instruction for console output /// `print %value` + /// DEPRECATED: Phase 5 - Use Call with @print intrinsic + #[deprecated(since = "Phase 5", note = "Use Call with @print intrinsic")] Print { value: ValueId, effects: EffectMask, }, /// No-op instruction (for optimization placeholders) + /// DEPRECATED: Phase 5 - Not needed in final IR + #[deprecated(since = "Phase 5", note = "Not needed in final IR")] Nop, // === Control Flow & Exception Handling (Phase 5) === /// Throw an exception /// `throw %exception_value` + /// DEPRECATED: Phase 5 - Use Call with @throw intrinsic + #[deprecated(since = "Phase 5", note = "Use Call with @throw intrinsic")] Throw { exception: ValueId, effects: EffectMask, @@ -190,6 +214,8 @@ pub enum MirInstruction { /// Catch handler setup (landing pad for exceptions) /// `catch %exception_type -> %handler_bb` + /// DEPRECATED: Phase 5 - Use Call with @catch intrinsic + #[deprecated(since = "Phase 5", note = "Use Call with @catch intrinsic")] Catch { exception_type: Option, // None = catch-all exception_value: ValueId, // Where to store caught exception @@ -204,6 +230,8 @@ pub enum MirInstruction { /// Create a new reference to a Box /// `%dst = ref_new %box` + /// DEPRECATED: Phase 5 - RefGet is sufficient + #[deprecated(since = "Phase 5", note = "RefGet is sufficient")] RefNew { dst: ValueId, box_val: ValueId, @@ -241,12 +269,16 @@ pub enum MirInstruction { /// Memory barrier read (no-op for now, proper effect annotation) /// `barrier_read %ptr` + /// DEPRECATED: Phase 5 - Use AtomicFence instead + #[deprecated(since = "Phase 5", note = "Use AtomicFence instead")] BarrierRead { ptr: ValueId, }, /// Memory barrier write (no-op for now, proper effect annotation) /// `barrier_write %ptr` + /// DEPRECATED: Phase 5 - Use AtomicFence instead + #[deprecated(since = "Phase 5", note = "Use AtomicFence instead")] BarrierWrite { ptr: ValueId, }, @@ -255,6 +287,8 @@ pub enum MirInstruction { /// Create a new Future with initial value /// `%dst = future_new %value` + /// DEPRECATED: Phase 5 - Use NewBox + BoxCall + #[deprecated(since = "Phase 5", note = "Use NewBox + BoxCall")] FutureNew { dst: ValueId, value: ValueId, @@ -262,6 +296,8 @@ pub enum MirInstruction { /// Set Future value and mark as ready /// `future_set %future = %value` + /// DEPRECATED: Phase 5 - Use BoxCall + #[deprecated(since = "Phase 5", note = "Use BoxCall")] FutureSet { future: ValueId, value: ValueId, @@ -269,6 +305,8 @@ pub enum MirInstruction { /// Wait for Future completion and get value /// `%dst = await %future` + /// DEPRECATED: Phase 5 - Use BoxCall + #[deprecated(since = "Phase 5", note = "Use BoxCall")] Await { dst: ValueId, future: ValueId,