Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move most opts to runtime #64

Open
y21 opened this issue May 6, 2023 · 1 comment
Open

Move most opts to runtime #64

y21 opened this issue May 6, 2023 · 1 comment

Comments

@y21
Copy link
Owner

y21 commented May 6, 2023

Currently dash tries to apply some optimizations at compile time, e.g. given

for (let i = 0; i < 1000; i++);

The comparison and increment get special opcodes that are faster than the generic cmp/inc opcodes as it skips the type check and is optimized specifically to work with integers.
However, doing this statically is very limited and leads to many missed optimizations.

It would be better if we applied these at runtime since we have far more information at runtime as it executes the code.
We already have some amount of infrastructure required for doing this from the JIT, namely the dash_typed_cfg crate for getting a CFG with type information from bytecode, which should already allow for some really nice optimizations that we couldn't do at compile time.
Opts like constant propagation should still run at compile time since there isn't any benefit to not doing it right away.

@y21
Copy link
Owner Author

y21 commented Oct 10, 2023

The current opts that rely on type inference at compile time will also be unsound in presence of dynamic code execution (eval, Function), so we should try to move away from this soon.

let i = 0;
globalThis[k1](k2);
i++;

The i++ is currently an ipostinclocal, exploiting the fact that i must be an integer, but when k1 = 'eval', we end up executing arbitrary code which may well change the type of i, breaking all the assumptions...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant