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

Add a "volatile" pragma #2907

Open
lukaszcz opened this issue Jul 18, 2024 · 0 comments
Open

Add a "volatile" pragma #2907

lukaszcz opened this issue Jul 18, 2024 · 0 comments
Labels
enhancement New feature or request optimization
Milestone

Comments

@lukaszcz
Copy link
Collaborator

lukaszcz commented Jul 18, 2024

Currently, the optimisation phases on Core assume all Juvix functions are pure. This might not be the case with some builtins, which might lead to incorrect code transformations.

For example, for the code

let x := random n;
     y := random n;
in
f x y

the optimiser might decide that it's equivalent to

let x := random n
in
f x x

which is incorrect, because random has a side-effect (it's not referentially transparent).

This actually won't happen for now, because we don't yet have common subexpression elimination, but a duplication will happen if random has zero arguments:

let x := random
in
f x x

will be transformed to

f random random

We should add a "volatile" pragma to mark certain functions as not referentially transparent and then respect this in the optimiser (this requires also adjusting the optimisations)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request optimization
Projects
None yet
Development

No branches or pull requests

2 participants