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

[compiler] rewrite FreeVariables to not duplicate binding structure #14451

Merged
merged 3 commits into from
Apr 11, 2024

Conversation

patrick-schultz
Copy link
Collaborator

@patrick-schultz patrick-schultz commented Apr 8, 2024

Before we can simplify the binding structure, we need to stop duplicating it all over the place. This PR rewrites FreeVariables so that it no longer needs special logic for particular nodes, hard coding binding structure (redundantly). To do this, it takes advantage of the new Bindings, which operates on a GenericBindingEnv interface. It adds a new implementation of this interface specifically for computing free variables, then simply does a generic traversal of the IR using this custom binging environment.

While I find the new implementation far simpler and more obviously correct than the old, I do expect it to further simplify once I'm able to start modifying the core binding structure.

env.getFreeVars
}

assert(old == new_, s"old: $old\nnew: ${new_}\nir:\n${Pretty.sexprStyle(ir, allowUnboundRefs = true)}")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note that all tests passed with this assertion, checking that the new free variables implementation always agrees with the old.

Comment on lines 53 to 132
val combEval = Env.fromSeq(IndexedSeq((accumName, {}), (otherAccumName, {})))
val combOpFreeVarsCompute = compute(combOp, baseEnv.copy(eval = combEval))
val combOpFreeVars = combOpFreeVarsCompute.copy(
eval = Env.empty[Unit],
scan = Some(combOpFreeVarsCompute.eval),
)
zeroFreeVars.merge(seqOpFreeVars).merge(combOpFreeVars)
// the comb op can't refer to anything bound outside, so it can't have free variables
zeroFreeVars.merge(seqOpFreeVars)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The assertion caught one place where the old implementation was wrong: AggFold always added accumName and otherAccumName to the free variables, even though they are never free.

@patrick-schultz patrick-schultz marked this pull request as ready for review April 9, 2024 13:21
Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @patrick-schultz and the rest of your teammates on Graphite Graphite

ehigham
ehigham previously approved these changes Apr 9, 2024
Copy link
Member

@ehigham ehigham left a comment

Choose a reason for hiding this comment

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

Great change, just a question about the test

@ehigham ehigham dismissed their stale review April 9, 2024 17:47

need to request changes

Copy link
Member

@ehigham ehigham left a comment

Choose a reason for hiding this comment

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

See review comments above

Copy link
Member

@ehigham ehigham left a comment

Choose a reason for hiding this comment

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

laaavely

@hail-ci-robot hail-ci-robot merged commit 1f3a050 into hail-is:main Apr 11, 2024
2 checks passed
@patrick-schultz patrick-schultz deleted the agg-freevars branch April 11, 2024 14:45
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.

3 participants