-
Notifications
You must be signed in to change notification settings - Fork 3
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
[gtlc] Optimize: remove unused parameters/variables #9
Comments
I realized this opt is always unsound. Due to cast semantics, elision of unused variables in general may make a program that has a cast error no longer have a cast error. this is similar to llvm’s old opt that could trivialize infinite pure loops into noops, which also breaks program semantics. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Finding unused variables is trivial, but removing them safely is trickier. If we remove an unused parameter, we need to update all places a value for that parameter is passed, which is non-trivial to figure out (consider using a graph representation of types here to make this easier; we only need to update the type once and then look at all values elaborated with that type).
The other issue to be careful of is the interaction with references. This is best illustrated by an example; consider the program
applying the optimization naively would yield
but the problem is that
a
now has the typeref ([] -> nat)
, but then assigned a value of type[nat] -> nat
, and the optimized-away call at the end is now unsound.Nevertheless there are ways to handle this; as an initial pass, we could simply avoid modifying functions later used inside references.
The text was updated successfully, but these errors were encountered: