optimize: avoid generating drop glue for StepResult
This commit is contained in:
+31
-5
@@ -38,10 +38,10 @@ impl From<Box<Error>> for VmError {
|
||||
}
|
||||
|
||||
impl VmError {
|
||||
fn into_step_result<'gc>(self) -> StepResult<'gc> {
|
||||
fn into_error(self) -> Box<Error> {
|
||||
match self {
|
||||
VmError::Catchable(_) => todo!("Check for tryEval catch frames"),
|
||||
VmError::Uncatchable(e) => StepResult::Done(Err(e)),
|
||||
VmError::Uncatchable(e) => e,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,7 +128,7 @@ impl<T: VmContext> VmContextExt for T {
|
||||
pub(crate) enum StepResult<'gc> {
|
||||
Continue,
|
||||
ForceThunk(ForceInfo<'gc>),
|
||||
Done(Result<fix_common::Value>),
|
||||
Done,
|
||||
}
|
||||
|
||||
pub(crate) struct ForceInfo<'gc> {
|
||||
@@ -159,6 +159,9 @@ pub struct Vm<'gc> {
|
||||
pub(crate) empty_attrs: Value<'gc>,
|
||||
|
||||
pub(crate) force_mode: ForceMode,
|
||||
|
||||
#[collect(require_static)]
|
||||
pub(crate) result: Option<Result<fix_common::Value>>,
|
||||
}
|
||||
|
||||
pub(crate) enum OperandData {
|
||||
@@ -264,9 +267,28 @@ impl<'gc> Vm<'gc> {
|
||||
empty_attrs: Value::new_gc(Gc::new(mc, AttrSet::default())),
|
||||
|
||||
force_mode,
|
||||
|
||||
result: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn finish_ok(&mut self, val: fix_common::Value) -> StepResult<'gc> {
|
||||
self.result = Some(Ok(val));
|
||||
StepResult::Done
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn finish_err(&mut self, err: Box<Error>) -> StepResult<'gc> {
|
||||
self.result = Some(Err(err));
|
||||
StepResult::Done
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn finish_vm_err(&mut self, err: VmError) -> StepResult<'gc> {
|
||||
self.finish_err(err.into_error())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn push_stack(&mut self, val: Value<'gc>) {
|
||||
self.stack.push(val);
|
||||
@@ -339,7 +361,7 @@ impl<'gc> Vm<'gc> {
|
||||
}
|
||||
ThunkState::Apply { .. } => todo!("force apply"),
|
||||
ThunkState::Blackhole => {
|
||||
StepResult::Done(Err(Error::eval_error("infinite recursion encountered")))
|
||||
self.finish_err(Error::eval_error("infinite recursion encountered"))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -526,7 +548,11 @@ impl<'gc> Vm<'gc> {
|
||||
self.env = info.env;
|
||||
self.with_env = info.with_env;
|
||||
}
|
||||
StepResult::Done(result) => return Action::Done(result),
|
||||
StepResult::Done => {
|
||||
return Action::Done(
|
||||
self.result.take().expect("StepResult::Done without result"),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user