optimize: remove {StepResult,TailResult}::ForceThunk

This commit is contained in:
2026-04-20 15:10:55 +08:00
parent 98b07f00e4
commit 520bb7d75e
12 changed files with 132 additions and 188 deletions
+36 -36
View File
@@ -11,11 +11,11 @@ impl<'gc> crate::Vm<'gc> {
ctx: &mut impl crate::VmContext,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
if let Some(step) = self.try_force_resolved(1, reader.inst_start_pc(), mc) {
) -> StepResult {
if let Some(step) = self.try_force(1, reader, mc) {
return step;
}
if let Some(step) = self.try_force_resolved(0, reader.inst_start_pc(), mc) {
if let Some(step) = self.try_force(0, reader, mc) {
return step;
}
let rhs = self.pop_stack_forced();
@@ -43,8 +43,8 @@ impl<'gc> crate::Vm<'gc> {
&mut self,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
self.op_arith(mc, i64::wrapping_sub, |a, b| a - b, reader.inst_start_pc())
) -> StepResult {
self.op_arith(reader, mc, i64::wrapping_sub, |a, b| a - b)
}
#[inline(always)]
@@ -52,22 +52,22 @@ impl<'gc> crate::Vm<'gc> {
&mut self,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
self.op_arith(mc, i64::wrapping_mul, |a, b| a * b, reader.inst_start_pc())
) -> StepResult {
self.op_arith(reader, mc, i64::wrapping_mul, |a, b| a * b)
}
#[inline(always)]
fn op_arith(
&mut self,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
int_op: fn(i64, i64) -> i64,
float_op: fn(f64, f64) -> f64,
inst_start_pc: usize,
) -> StepResult<'gc> {
if let Some(step) = self.try_force_resolved(1, inst_start_pc, mc) {
) -> StepResult {
if let Some(step) = self.try_force(1, reader, mc) {
return step;
}
if let Some(step) = self.try_force_resolved(0, inst_start_pc, mc) {
if let Some(step) = self.try_force(0, reader, mc) {
return step;
}
let rhs = self.pop_stack_forced();
@@ -87,11 +87,11 @@ impl<'gc> crate::Vm<'gc> {
&mut self,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
if let Some(step) = self.try_force_resolved(1, reader.inst_start_pc(), mc) {
) -> StepResult {
if let Some(step) = self.try_force(1, reader, mc) {
return step;
}
if let Some(step) = self.try_force_resolved(0, reader.inst_start_pc(), mc) {
if let Some(step) = self.try_force(0, reader, mc) {
return step;
}
let rhs = self.pop_stack_forced();
@@ -120,11 +120,11 @@ impl<'gc> crate::Vm<'gc> {
ctx: &mut impl crate::VmContext,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
if let Some(step) = self.try_force_resolved(1, reader.inst_start_pc(), mc) {
) -> StepResult {
if let Some(step) = self.try_force(1, reader, mc) {
return step;
}
if let Some(step) = self.try_force_resolved(0, reader.inst_start_pc(), mc) {
if let Some(step) = self.try_force(0, reader, mc) {
return step;
}
let eq = match self.values_equal(ctx) {
@@ -141,11 +141,11 @@ impl<'gc> crate::Vm<'gc> {
ctx: &mut impl crate::VmContext,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
if let Some(step) = self.try_force_resolved(1, reader.inst_start_pc(), mc) {
) -> StepResult {
if let Some(step) = self.try_force(1, reader, mc) {
return step;
}
if let Some(step) = self.try_force_resolved(0, reader.inst_start_pc(), mc) {
if let Some(step) = self.try_force(0, reader, mc) {
return step;
}
let eq = match self.values_equal(ctx) {
@@ -162,7 +162,7 @@ impl<'gc> crate::Vm<'gc> {
ctx: &mut impl crate::VmContext,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
self.compare_values(ctx, reader, mc, Ordering::is_lt)
}
@@ -172,7 +172,7 @@ impl<'gc> crate::Vm<'gc> {
ctx: &mut impl crate::VmContext,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
self.compare_values(ctx, reader, mc, Ordering::is_gt)
}
@@ -182,7 +182,7 @@ impl<'gc> crate::Vm<'gc> {
ctx: &mut impl crate::VmContext,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
self.compare_values(ctx, reader, mc, Ordering::is_le)
}
@@ -192,7 +192,7 @@ impl<'gc> crate::Vm<'gc> {
ctx: &mut impl crate::VmContext,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
self.compare_values(ctx, reader, mc, Ordering::is_ge)
}
@@ -202,11 +202,11 @@ impl<'gc> crate::Vm<'gc> {
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
pred: fn(Ordering) -> bool,
) -> StepResult<'gc> {
if let Some(step) = self.try_force_resolved(1, reader.inst_start_pc(), mc) {
) -> StepResult {
if let Some(step) = self.try_force(1, reader, mc) {
return step;
}
if let Some(step) = self.try_force_resolved(0, reader.inst_start_pc(), mc) {
if let Some(step) = self.try_force(0, reader, mc) {
return step;
}
match self.compare_values_inner(ctx, pred) {
@@ -220,11 +220,11 @@ impl<'gc> crate::Vm<'gc> {
&mut self,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
if let Some(step) = self.try_force_resolved(1, reader.inst_start_pc(), mc) {
) -> StepResult {
if let Some(step) = self.try_force(1, reader, mc) {
return step;
}
if let Some(step) = self.try_force_resolved(0, reader.inst_start_pc(), mc) {
if let Some(step) = self.try_force(0, reader, mc) {
return step;
}
let rhs = self.pop_stack_forced();
@@ -249,13 +249,13 @@ impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_update(
&mut self,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
inst_start_pc: usize,
) -> StepResult<'gc> {
if let Some(step) = self.try_force_resolved(1, inst_start_pc, mc) {
) -> StepResult {
if let Some(step) = self.try_force(1, reader, mc) {
return step;
}
if let Some(step) = self.try_force_resolved(0, inst_start_pc, mc) {
if let Some(step) = self.try_force(0, reader, mc) {
return step;
}
let rhs = self.pop_stack_forced();
@@ -275,12 +275,12 @@ impl<'gc> crate::Vm<'gc> {
}
#[inline(always)]
pub(crate) fn op_neg(&mut self) -> StepResult<'gc> {
pub(crate) fn op_neg(&mut self) -> StepResult {
todo!("implement unary operation");
}
#[inline(always)]
pub(crate) fn op_not(&mut self) -> StepResult<'gc> {
pub(crate) fn op_not(&mut self) -> StepResult {
todo!("implement unary operation");
}
+7 -7
View File
@@ -5,13 +5,13 @@ use crate::{BytecodeReader, PrimOp, StepResult, Value};
impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_load_builtins(&mut self) -> StepResult<'gc> {
pub(crate) fn op_load_builtins(&mut self) -> StepResult {
self.push_stack(self.builtins);
StepResult::Continue
}
#[inline(always)]
pub(crate) fn op_load_builtin(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult<'gc> {
pub(crate) fn op_load_builtin(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult {
let Ok(id) = BuiltinId::try_from_primitive(reader.read_u8())
.map_err(|err| panic!("unknown builtin id: {}", err.number));
self.push_stack(Value::new_inline(PrimOp {
@@ -22,7 +22,7 @@ impl<'gc> crate::Vm<'gc> {
}
#[inline(always)]
pub(crate) fn op_mk_pos(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult<'gc> {
pub(crate) fn op_mk_pos(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult {
let _span_id = reader.read_u32();
todo!("MkPos");
}
@@ -31,7 +31,7 @@ impl<'gc> crate::Vm<'gc> {
pub(crate) fn op_load_repl_binding(
&mut self,
reader: &mut BytecodeReader<'_>,
) -> StepResult<'gc> {
) -> StepResult {
let _name = reader.read_string_id();
todo!("LoadReplBinding");
}
@@ -40,7 +40,7 @@ impl<'gc> crate::Vm<'gc> {
pub(crate) fn op_load_scoped_binding(
&mut self,
reader: &mut BytecodeReader<'_>,
) -> StepResult<'gc> {
) -> StepResult {
let _name = reader.read_string_id();
todo!("LoadScopedBinding");
}
@@ -51,7 +51,7 @@ impl<'gc> crate::Vm<'gc> {
ctx: &mut impl crate::VmContext,
reader: &mut BytecodeReader<'_>,
_mc: &gc_arena::Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
let _parts_count = reader.read_u16() as usize;
let _force_string = reader.read_u8() != 0;
let mut _operands: smallvec::SmallVec<[crate::OperandData; 4]> =
@@ -63,7 +63,7 @@ impl<'gc> crate::Vm<'gc> {
}
#[inline(always)]
pub(crate) fn op_resolve_path(&mut self, _ctx: &mut impl crate::VmContext) -> StepResult<'gc> {
pub(crate) fn op_resolve_path(&mut self, _ctx: &mut impl crate::VmContext) -> StepResult {
todo!("implement ResolvePath");
}
}
+4 -4
View File
@@ -10,8 +10,8 @@ impl<'gc> crate::Vm<'gc> {
ctx: &mut impl crate::VmContext,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
if let Some(step) = self.try_force_resolved(0, reader.inst_start_pc(), mc) {
) -> StepResult {
if let Some(step) = self.try_force(0, reader, mc) {
return step;
}
if self.call_depth > 10000 {
@@ -50,7 +50,7 @@ impl<'gc> crate::Vm<'gc> {
ctx: &mut impl crate::VmContext,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
self.handle_return(reader, ctx, mc)
}
@@ -59,7 +59,7 @@ impl<'gc> crate::Vm<'gc> {
reader: &mut BytecodeReader<'_>,
ctx: &C,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
let ret_inst_pc = reader.pc() - 1;
let Some(CallFrame {
pc: ret_pc,
+3 -3
View File
@@ -8,7 +8,7 @@ impl<'gc> crate::Vm<'gc> {
&mut self,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
let entry_point = reader.read_u32();
let thunk = Gc::new(
mc,
@@ -27,7 +27,7 @@ impl<'gc> crate::Vm<'gc> {
&mut self,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
let entry_point = reader.read_u32();
let n_locals = reader.read_u32();
let closure = Gc::new(
@@ -48,7 +48,7 @@ impl<'gc> crate::Vm<'gc> {
&mut self,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
let entry_point = reader.read_u32();
let n_locals = reader.read_u32();
let req_count = reader.read_u16() as usize;
+11 -11
View File
@@ -13,7 +13,7 @@ impl<'gc> crate::Vm<'gc> {
ctx: &mut impl crate::VmContext,
reader: &mut BytecodeReader<'_>,
mc: &gc_arena::Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
let count = reader.read_u32() as usize;
let mut entries: SmallVec<[AttrEntry; 4]> = SmallVec::with_capacity(count);
for _ in 0..count {
@@ -42,7 +42,7 @@ impl<'gc> crate::Vm<'gc> {
}
#[inline(always)]
pub(crate) fn op_make_empty_attrs(&mut self) -> StepResult<'gc> {
pub(crate) fn op_make_empty_attrs(&mut self) -> StepResult {
self.push_stack(self.empty_attrs);
StepResult::Continue
}
@@ -53,11 +53,11 @@ impl<'gc> crate::Vm<'gc> {
ctx: &mut impl crate::VmContext,
reader: &mut BytecodeReader<'_>,
mc: &gc_arena::Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
let _span_id = reader.read_u32();
let key = reader.read_string_id();
if let Some(step) = self.try_force_resolved(0, reader.inst_start_pc(), mc) {
if let Some(step) = self.try_force(0, reader, mc) {
return step;
}
@@ -98,13 +98,13 @@ impl<'gc> crate::Vm<'gc> {
ctx: &mut impl crate::VmContext,
reader: &mut BytecodeReader<'_>,
mc: &gc_arena::Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
let _span_id = reader.read_u32();
if let Some(step) = self.try_force_resolved(0, reader.inst_start_pc(), mc) {
if let Some(step) = self.try_force(0, reader, mc) {
return step;
}
if let Some(step) = self.try_force_resolved(1, reader.inst_start_pc(), mc) {
if let Some(step) = self.try_force(1, reader, mc) {
return step;
}
@@ -143,14 +143,14 @@ impl<'gc> crate::Vm<'gc> {
pub(crate) fn op_jump_if_select_succeeded(
&mut self,
reader: &mut BytecodeReader<'_>,
) -> StepResult<'gc> {
) -> StepResult {
let offset = reader.read_i32();
reader.set_pc(((reader.pc() as isize) + (offset as isize)) as usize);
StepResult::Continue
}
#[inline(always)]
pub(crate) fn op_has_attr(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult<'gc> {
pub(crate) fn op_has_attr(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult {
let _n = reader.read_u16() as usize;
todo!("HasAttr");
}
@@ -161,7 +161,7 @@ impl<'gc> crate::Vm<'gc> {
ctx: &mut impl crate::VmContext,
reader: &mut BytecodeReader<'_>,
mc: &gc_arena::Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
let count = reader.read_u32() as usize;
let mut items: SmallVec<[Value; 4]> = SmallVec::with_capacity(count);
for _ in 0..count {
@@ -173,7 +173,7 @@ impl<'gc> crate::Vm<'gc> {
}
#[inline(always)]
pub(crate) fn op_make_empty_list(&mut self) -> StepResult<'gc> {
pub(crate) fn op_make_empty_list(&mut self) -> StepResult {
self.push_stack(self.empty_list);
StepResult::Continue
}
+6 -6
View File
@@ -6,9 +6,9 @@ impl<'gc> crate::Vm<'gc> {
&mut self,
reader: &mut BytecodeReader<'_>,
mc: &gc_arena::Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
let offset = reader.read_i32();
if let Some(step) = self.try_force_resolved(0, reader.inst_start_pc(), mc) {
if let Some(step) = self.try_force(0, reader, mc) {
return step;
}
let cond = self.pop_stack();
@@ -23,9 +23,9 @@ impl<'gc> crate::Vm<'gc> {
&mut self,
reader: &mut BytecodeReader<'_>,
mc: &gc_arena::Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
let offset = reader.read_i32();
if let Some(step) = self.try_force_resolved(0, reader.inst_start_pc(), mc) {
if let Some(step) = self.try_force(0, reader, mc) {
return step;
}
let cond = self.pop_stack();
@@ -36,14 +36,14 @@ impl<'gc> crate::Vm<'gc> {
}
#[inline(always)]
pub(crate) fn op_jump(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult<'gc> {
pub(crate) fn op_jump(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult {
let offset = reader.read_i32();
reader.set_pc(((reader.pc() as isize) + (offset as isize)) as usize);
StepResult::Continue
}
#[inline(always)]
pub(crate) fn op_assert(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult<'gc> {
pub(crate) fn op_assert(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult {
let _raw_idx = reader.read_u32();
let _span_id = reader.read_u32();
todo!("implement Assert (force TOS)");
+7 -7
View File
@@ -4,7 +4,7 @@ use crate::{BytecodeReader, StepResult, Value};
impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_push_smi(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult<'gc> {
pub(crate) fn op_push_smi(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult {
let val = reader.read_i32();
self.push_stack(Value::new_inline(val));
StepResult::Continue
@@ -15,40 +15,40 @@ impl<'gc> crate::Vm<'gc> {
&mut self,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
let val = reader.read_i64();
self.push_stack(Value::new_gc(Gc::new(mc, val)));
StepResult::Continue
}
#[inline(always)]
pub(crate) fn op_push_float(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult<'gc> {
pub(crate) fn op_push_float(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult {
let val = reader.read_f64();
self.push_stack(Value::new_float(val));
StepResult::Continue
}
#[inline(always)]
pub(crate) fn op_push_string(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult<'gc> {
pub(crate) fn op_push_string(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult {
let sid = reader.read_string_id();
self.push_stack(Value::new_inline(sid));
StepResult::Continue
}
#[inline(always)]
pub(crate) fn op_push_null(&mut self) -> StepResult<'gc> {
pub(crate) fn op_push_null(&mut self) -> StepResult {
self.push_stack(Value::new_inline(crate::Null));
StepResult::Continue
}
#[inline(always)]
pub(crate) fn op_push_true(&mut self) -> StepResult<'gc> {
pub(crate) fn op_push_true(&mut self) -> StepResult {
self.push_stack(Value::new_inline(true));
StepResult::Continue
}
#[inline(always)]
pub(crate) fn op_push_false(&mut self) -> StepResult<'gc> {
pub(crate) fn op_push_false(&mut self) -> StepResult {
self.push_stack(Value::new_inline(false));
StepResult::Continue
}
+4 -4
View File
@@ -2,14 +2,14 @@ use crate::{BytecodeReader, Mutation, StepResult, Value};
impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_load_local(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult<'gc> {
pub(crate) fn op_load_local(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult {
let idx = reader.read_u32() as usize;
self.push_stack(self.env.borrow().locals[idx]);
StepResult::Continue
}
#[inline(always)]
pub(crate) fn op_load_outer(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult<'gc> {
pub(crate) fn op_load_outer(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult {
let layer = reader.read_u8();
let idx = reader.read_u32() as usize;
let mut cur = self.env;
@@ -27,7 +27,7 @@ impl<'gc> crate::Vm<'gc> {
&mut self,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
let idx = reader.read_u32() as usize;
let val = self.pop_stack();
self.env.borrow_mut(mc).locals[idx] = val;
@@ -39,7 +39,7 @@ impl<'gc> crate::Vm<'gc> {
&mut self,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
let count = reader.read_u32() as usize;
self.env
.borrow_mut(mc)
+5 -5
View File
@@ -11,7 +11,7 @@ impl<'gc> crate::Vm<'gc> {
ctx: &mut impl crate::VmContext,
reader: &mut BytecodeReader<'_>,
mc: &gc_arena::Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
let env = reader.read_operand_data(ctx).resolve(mc, self);
let scope = Gc::new(
mc,
@@ -25,7 +25,7 @@ impl<'gc> crate::Vm<'gc> {
}
#[inline(always)]
pub(crate) fn op_pop_with(&mut self) -> StepResult<'gc> {
pub(crate) fn op_pop_with(&mut self) -> StepResult {
let Some(scope) = self.with_env else {
unreachable!("no with_scope to pop");
};
@@ -34,7 +34,7 @@ impl<'gc> crate::Vm<'gc> {
}
#[inline(always)]
pub(crate) fn op_prepare_with(&mut self) -> StepResult<'gc> {
pub(crate) fn op_prepare_with(&mut self) -> StepResult {
self.call_stack.push(CallFrame {
pc: usize::MAX,
stack_depth: 0,
@@ -51,7 +51,7 @@ impl<'gc> crate::Vm<'gc> {
ctx: &mut impl crate::VmContext,
reader: &mut BytecodeReader<'_>,
mc: &gc_arena::Mutation<'gc>,
) -> StepResult<'gc> {
) -> StepResult {
let name = reader.read_string_id();
let Some(&WithEnv { env, prev }) = self.with_env.as_deref() else {
@@ -65,7 +65,7 @@ impl<'gc> crate::Vm<'gc> {
)));
};
self.push_stack(env);
if let Some(step) = self.try_force_resolved(0, reader.inst_start_pc(), mc) {
if let Some(step) = self.try_force(0, reader, mc) {
return step;
}