optimize: avoid generating drop glue for StepResult

This commit is contained in:
2026-04-19 19:17:43 +08:00
parent e527d31450
commit 800249cb1e
6 changed files with 69 additions and 50 deletions
+16 -21
View File
@@ -32,7 +32,7 @@ impl<'gc> crate::Vm<'gc> {
self.push_stack(val);
StepResult::Continue
}
Err(e) => e.into_step_result(),
Err(e) => self.finish_vm_err(e),
}
}
@@ -76,7 +76,7 @@ impl<'gc> crate::Vm<'gc> {
self.push_stack(val);
StepResult::Continue
}
Err(e) => e.into_step_result(),
Err(e) => self.finish_vm_err(e),
}
}
@@ -96,10 +96,9 @@ impl<'gc> crate::Vm<'gc> {
let lhs = self.pop_stack_forced();
match (get_num(rhs), get_num(lhs)) {
(_, Some(NixNum::Int(0))) | (_, Some(NixNum::Float(0.))) => {
return VmError::Uncatchable(fix_error::Error::eval_error(
return self.finish_vm_err(VmError::Uncatchable(fix_error::Error::eval_error(
"division by zero",
))
.into_step_result();
)));
}
_ => {}
}
@@ -109,7 +108,7 @@ impl<'gc> crate::Vm<'gc> {
self.push_stack(val);
StepResult::Continue
}
Err(e) => e.into_step_result(),
Err(e) => self.finish_vm_err(e),
}
}
@@ -128,7 +127,7 @@ impl<'gc> crate::Vm<'gc> {
}
let eq = match self.values_equal(ctx) {
Ok(eq) => eq,
Err(e) => return e.into_step_result(),
Err(e) => return self.finish_vm_err(e),
};
self.push_stack(Value::new_inline(eq));
StepResult::Continue
@@ -149,7 +148,7 @@ impl<'gc> crate::Vm<'gc> {
}
let eq = match self.values_equal(ctx) {
Ok(eq) => eq,
Err(e) => return e.into_step_result(),
Err(e) => return self.finish_vm_err(e),
};
self.push_stack(Value::new_inline(!eq));
StepResult::Continue
@@ -210,7 +209,7 @@ impl<'gc> crate::Vm<'gc> {
}
match self.compare_values_inner(ctx, pred) {
Ok(()) => StepResult::Continue,
Err(e) => e.into_step_result(),
Err(e) => self.finish_vm_err(e),
}
}
@@ -229,16 +228,14 @@ impl<'gc> crate::Vm<'gc> {
let rhs = self.pop_stack_forced();
let lhs = self.pop_stack_forced();
let Some(l) = lhs.as_gc::<crate::List>() else {
return VmError::Uncatchable(fix_error::Error::eval_error(
return self.finish_err(fix_error::Error::eval_error(
"cannot concatenate: left operand is not a list",
))
.into_step_result();
));
};
let Some(r) = rhs.as_gc::<crate::List>() else {
return VmError::Uncatchable(fix_error::Error::eval_error(
return self.finish_err(fix_error::Error::eval_error(
"cannot concatenate: right operand is not a list",
))
.into_step_result();
));
};
let mut items = smallvec::SmallVec::new();
items.extend_from_slice(&l);
@@ -262,16 +259,14 @@ impl<'gc> crate::Vm<'gc> {
let rhs = self.pop_stack_forced();
let lhs = self.pop_stack_forced();
let Some(l) = lhs.as_gc::<crate::AttrSet>() else {
return VmError::Uncatchable(fix_error::Error::eval_error(
return self.finish_err(fix_error::Error::eval_error(
"cannot update: left operand is not a set",
))
.into_step_result();
));
};
let Some(r) = rhs.as_gc::<crate::AttrSet>() else {
return VmError::Uncatchable(fix_error::Error::eval_error(
return self.finish_err(fix_error::Error::eval_error(
"cannot update: right operand is not a set",
))
.into_step_result();
));
};
self.push_stack(Value::new_gc(l.merge(&r, mc)));
StepResult::Continue