Skip to content

Variable type analysis can be better #36

Open
@GarboMuffin

Description

@GarboMuffin

Expected Behavior

Given this script:

image

The compiler should be able to conclude that first, second, nth, i will always be numbers and optimize accordingly:

b1.value = 0;
b2.value = 1;
b3.value = 1;
b4.value = 2;
while (b4.value > p0) {
    b3.value = b1.value + b2.value;
    b1.value = b2.value;
    b2.value = b3.value;
    b4.value = b4.value + 1;
}
b0.value = b3.value;

Actual Behavior

It's not very smart. The script is compiled as:

b1.value = 0;
b2.value = 1;
b3.value = 1;
b4.value = 2;
while (!compareGreaterThan(b4.value, p0)) {
    b3.value = ((+b1.value || 0) + (+b2.value || 0));
    b1.value = b2.value;
    b2.value = b3.value;
    b4.value = ((+b4.value || 0) + 1);
}

https://share.firefox.dev/2V2lI9z

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions