Skip to content

Commit

Permalink
avm2: Add extra type propagation to astype
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian17 committed Mar 14, 2024
1 parent 88e5f9a commit 69ba551
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/src/avm2/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,19 @@ pub fn optimize<'gc>(
Op::AsType { class } => {
let stack_value = stack.pop_or_any();

let class_is_primitive = GcCell::ptr_eq(*class, types.int.inner_class_definition())
|| GcCell::ptr_eq(*class, types.uint.inner_class_definition())
|| GcCell::ptr_eq(*class, types.number.inner_class_definition())
|| GcCell::ptr_eq(*class, types.boolean.inner_class_definition());

let mut new_value = OptValue::any();
if !class_is_primitive {
// if T is non-nullable, we can assume the result is typed T
new_value = OptValue::of_type_from_class(*class);
}
if let Some(class_object) = stack_value.class {
if GcCell::ptr_eq(*class, class_object.inner_class_definition()) {
// If type check is guaranteed, preserve original type
// TODO: there are more cases when this can succeed,
// like inheritance and numbers (`x: Number = 1; x as int;`)
new_value = stack_value;
Expand Down

0 comments on commit 69ba551

Please sign in to comment.