Skip to content

Commit 990d1e0

Browse files
Lord-McSweeneyLord-McSweeney
authored andcommitted
avm2: Significantly improve optimizer
1 parent e08cb9e commit 990d1e0

File tree

9 files changed

+2024
-1984
lines changed

9 files changed

+2024
-1984
lines changed

core/src/avm2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ mod multiname;
5757
mod namespace;
5858
pub mod object;
5959
mod op;
60-
mod optimize;
60+
mod optimizer;
6161
mod parameters;
6262
pub mod property;
6363
mod property_map;

core/src/avm2/activation.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
849849
multiname,
850850
num_args,
851851
} => self.op_call_super(*multiname, *num_args),
852-
Op::ReturnValue => self.op_return_value(method),
853-
Op::ReturnValueNoCoerce => self.op_return_value_no_coerce(),
852+
Op::ReturnValue { return_type } => self.op_return_value(*return_type),
854853
Op::ReturnVoid => self.op_return_void(),
855854
Op::GetProperty { multiname } => self.op_get_property(*multiname),
856855
Op::SetProperty { multiname } => self.op_set_property(*multiname),
@@ -1208,10 +1207,9 @@ impl<'a, 'gc> Activation<'a, 'gc> {
12081207

12091208
fn op_return_value(
12101209
&mut self,
1211-
method: Gc<'gc, BytecodeMethod<'gc>>,
1210+
return_type: Option<Class<'gc>>,
12121211
) -> Result<FrameControl<'gc>, Error<'gc>> {
12131212
let return_value = self.pop_stack();
1214-
let return_type = method.resolved_return_type();
12151213

12161214
let coerced = if let Some(return_type) = return_type {
12171215
return_value.coerce_to_type(self, return_type)?
@@ -1222,12 +1220,6 @@ impl<'a, 'gc> Activation<'a, 'gc> {
12221220
Ok(FrameControl::Return(coerced))
12231221
}
12241222

1225-
fn op_return_value_no_coerce(&mut self) -> Result<FrameControl<'gc>, Error<'gc>> {
1226-
let return_value = self.pop_stack();
1227-
1228-
Ok(FrameControl::Return(return_value))
1229-
}
1230-
12311223
fn op_return_void(&mut self) -> Result<FrameControl<'gc>, Error<'gc>> {
12321224
Ok(FrameControl::Return(Value::Undefined))
12331225
}
@@ -1547,24 +1539,22 @@ impl<'a, 'gc> Activation<'a, 'gc> {
15471539
Ok(FrameControl::Continue)
15481540
}
15491541

1550-
fn op_get_outer_scope(&mut self, index: u32) -> Result<FrameControl<'gc>, Error<'gc>> {
1542+
fn op_get_outer_scope(&mut self, index: usize) -> Result<FrameControl<'gc>, Error<'gc>> {
15511543
// Verifier ensures that this points to a valid outer scope
15521544

1553-
let scope = self.outer.get_unchecked(index as usize);
1545+
let scope = self.outer.get_unchecked(index);
15541546

15551547
self.push_stack(scope.values());
15561548

15571549
Ok(FrameControl::Continue)
15581550
}
15591551

1560-
fn op_get_scope_object(&mut self, index: u8) -> Result<FrameControl<'gc>, Error<'gc>> {
1561-
let scope = self.scope_frame().get(index as usize).copied();
1552+
fn op_get_scope_object(&mut self, index: usize) -> Result<FrameControl<'gc>, Error<'gc>> {
1553+
// Verifier ensures that this points to a valid local scope
15621554

1563-
if let Some(scope) = scope {
1564-
self.push_stack(scope.values());
1565-
} else {
1566-
self.push_stack(Value::Undefined);
1567-
};
1555+
let scope = self.scope_frame()[index];
1556+
1557+
self.push_stack(scope.values());
15681558

15691559
Ok(FrameControl::Continue)
15701560
}

core/src/avm2/op.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ pub enum Op<'gc> {
136136
index: u32,
137137
},
138138
GetOuterScope {
139-
index: u32,
139+
index: usize,
140140
},
141141
GetProperty {
142142
multiname: Gc<'gc, Multiname<'gc>>,
143143
},
144144
GetScopeObject {
145-
index: u8,
145+
index: usize,
146146
},
147147
GetScriptGlobals {
148148
script: Script<'gc>,
@@ -253,8 +253,9 @@ pub enum Op<'gc> {
253253
},
254254
PushUndefined,
255255
PushWith,
256-
ReturnValue,
257-
ReturnValueNoCoerce,
256+
ReturnValue {
257+
return_type: Option<Class<'gc>>,
258+
},
258259
ReturnVoid,
259260
RShift,
260261
SetGlobalSlot {
@@ -297,18 +298,6 @@ pub enum Op<'gc> {
297298
}
298299

299300
impl Op<'_> {
300-
pub fn is_block_terminating(&self) -> bool {
301-
matches!(
302-
self,
303-
Op::Jump { .. }
304-
| Op::LookupSwitch { .. }
305-
| Op::ReturnValue
306-
| Op::ReturnValueNoCoerce
307-
| Op::ReturnVoid
308-
| Op::Throw
309-
)
310-
}
311-
312301
pub fn can_throw_error(&self) -> bool {
313302
!matches!(
314303
self,

0 commit comments

Comments
 (0)