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

Avoid unnecessary capture of PC variables when hoisting functions #1265

Merged
merged 3 commits into from
May 30, 2022

Conversation

mario-bucev
Copy link
Collaborator

@mario-bucev mario-bucev commented May 19, 2022

Addresses #1259
Edit: marked as a draft as I've found some bugs (that seem to be related to not taking into account function specifications)
Edit 2: the bug I've encountered has nothing to do with this PR... so I'm going to re-ready it (I'll try to fix the big in a separate PR).

@mario-bucev mario-bucev marked this pull request as draft May 19, 2022 09:08
@mario-bucev mario-bucev marked this pull request as ready for review May 20, 2022 07:24
val varsCond = exprOps.variablesOf(cond)
if (varsCond.intersect(fdsFreeVars).nonEmpty) varsCond
else Set.empty[Variable]
case _ => Set.empty[Variable]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: what about dependent types? Shouldn't we also include their free variables?

This might also affect the CloseBound cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't variablesOf also take into consideration the FVs occurring in types? Having a look at it, it calls typeOps.variablesOf, but maybe I've missed something.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does. But you need to actually call it on vd.tpe to get the free variables, e.g.

case Path.OpenBound(vd) => exprOps.variablesOf(vd.tpe)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks for the clarification!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully the pushed changes cover the dependent types. The fdsFreeVars now includes the FVs of types (if any).
For CloseBound (1st case), we do not need to take the FVs of vd.tpe as it's already in fdsFreeVars.
For the 2nd case, the FVs of vd.tpe will be picked up by the next iteration of step.
Otherwise, the vd is not relevant for this inner function and is dropped.

case Path.CloseBound(vd, e) if fdsFreeVars.contains(vd.toVariable) =>
exprOps.variablesOf(e)
case Path.CloseBound(vd, e) if exprOps.variablesOf(e).intersect(fdsFreeVars).nonEmpty =>
// `vd` may occur in a constraint somewhere, which can also transitively constraint the FVs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the second 'constraint' should be 'constrain'

@mario-bucev
Copy link
Collaborator Author

Thanks for the review! I'll address the remarks, in the meantime, I mark the PR as a draft to avoid any accidental merge...

@mario-bucev mario-bucev marked this pull request as draft May 27, 2022 13:12
exprOps.variablesOf(e)
case Path.CloseBound(vd, e) if exprOps.variablesOf(e).intersect(fdsFreeVars).nonEmpty =>
// `vd` may occur in a constraint somewhere, which can also transitively constraint the FVs
// `vd` may occur in a constrain somewhere, which can also transitively constraint the FVs
Copy link
Member

@samarion samarion May 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oups, I meant the other 'constraint' :) the sentence should be "vd may occur in a constraint somewhere, which can also transitively constrain the FVs"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha my bad!

@mario-bucev mario-bucev marked this pull request as ready for review May 30, 2022 09:55
@vkuncak vkuncak merged commit 9290a38 into epfl-lara:main May 30, 2022
@mario-bucev mario-bucev deleted the trim-innerfuns-signature branch May 30, 2022 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid capturing unnecessary constrained variables in FunctionClosure phase
3 participants