-
Notifications
You must be signed in to change notification settings - Fork 9
SyntaxGraph utils: unalias_nodes, annotate_parent, prune
#35
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
Open
mlechu
wants to merge
2
commits into
main
Choose a base branch
from
ec/prune-trees
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unalias_nodes, annotate_parent, prune
|
I like this. Some high level comments:
|
10db904 to
efe3b63
Compare
ef1749b to
5a1dbe8
Compare
cf0cd4f to
7e28e09
Compare
b72226d to
a178904
Compare
|
Marking ready for review! Changes since the original version:
I won't optimize for space too much until we know what provenance will look like on disk, but this PR includes some easy savings without changes to Possible IR-specific improvements:
|
d5f82aa to
d29a684
Compare
Exactly what information we want to prune in the final implementation is not
determined, but `green_tree` is probably part of it.
d29a684 to
59a7cb7
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Three simple
SyntaxGraph/SyntaxTreeutilities. The semantics described inthe docstrings are probably worth reading first; this PR description is mainly
justification.
Let me know if I guessed the division between syntax_graph.jl and ast.jl wrong
(Underlying data structure vs. julia syntax-y stuff? There is some overlap).
pruneI'm considering different ways of making JuliaLowering's provenance usable for
the rest of the compiler. One such way would be to store SyntaxTrees directly
in the sysimage, but they are currently far too large for that. One reason is
that nodes are never deleted through lowering (good thing). This change adds
the ability to extract a useful subset of nodes from a SyntaxTree once we're
done lowering.
This is implemented in two ways so we can see which we like better.
prune_aleaves nodes with multiple parents the same, and
prune_uensures that nodesdon't have more than one parent first (see
unalias_nodesbelow). This losesspace saved by the DAG representation, but allows us to store a level-order
traversal of the graph in the
edge_rangesfield and remove theedgesfieldentirely. The algorithm for
prune_uis also simpler. Feedback welcome onwhich you prefer @c42f; I don't intend to keep both.
Worst case (i.e. SyntaxTrees are too large or otherwise not usable in the
sysimage) we still get a handy utility for tools like the language server, which
will probably be caching a lot of syntax trees. In general, I don't think most
consumers will need a chain of provenance that includes intermediate
lowering-produced nodes, so we might benefit from omitting them by default.
annotate_parent!This is information present in
SyntaxNodenot carried over toSyntaxTreeforobvious DAG reasons, but the utility below makes it trivial to add. Given that
syntaxnode.parentis used extensively in the wild (I've missed it in languageserver development), I lean towards including this function in JuliaLowering
before a hundred packages need to implement it separately.
unalias_nodesGenerally useful for analyzing SyntaxTrees. Examples where I've wanted this:
I don't think it's correct to annotate nodes with types without unaliasing
first.
simple formatter that produces deterministic output text given a syntax tree.
This would involve a pass annotating each node with an indent level, which is
an example of a property that would be different with different references to
the same node.
TODO
pruneto use; experiment with sizeprunetests