cfallin opened PR #4908 from isle-multi-extractors
to main
:
This support allows for rules that process multiple matching values per extractor call on the left-hand side, and as a result, can produce multiple values from the constructor whose body they define.
This is useful in situations where we are matching on an input data structure that can have multiple "nodes" for a given value or ID, for example in an e-graph.
This is the first piece of the implementation of bytecodealliance/rfcs#27.
<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
cfallin requested fitzgen for a review on PR #4908.
fitzgen submitted PR review.
fitzgen submitted PR review.
fitzgen created PR review comment:
These comments don't seem to reflect the current truth. Both extractors and constructors seem to be using
ContextIter
now, based on the test cases.
fitzgen created PR review comment:
When is this used? I don't see any examples in the test cases, so if this isn't dead code now, then we should add test cases.
fitzgen created PR review comment:
Ah okay here is an example of returning a vector.
But yeah, I think we should only use
ContextIter
:
- It is general enough to subsume vector returns since you can always use
std::vec::Iter
as your iterator type.- It doesn't require computing all the values ahead of time, which can be more efficient if we ever allow short circuiting.
- It simplifies authoring the glue code (only one case for multi things instead of two) which makes it easier for users to grok the compilation model.
As far as internal constructors go, we could have a blanket implementation of
ContextIter
forVec<T>
andSmallVec<T>
so that the generated code doesn't need to change.
fitzgen created PR review comment:
Also, if this is still used, it seems like we could just have
ContextIter
and it can generalize and subsume theVec
case? That would simplify things a bit, especially for programmer mental model of what a multi compiles down into, since there won't be different cases.
cfallin created PR review comment:
I would love for that to work out, but the problem here is ownership: there is not necessarily any other owner for a newly-generated set of return values from a multi-constructor. Take for example a top-level "simplify" entry point that returns multiple equivalent expressions for a given input expression: it will need to return a vector of expression/node/eclass IDs, but this vec doesn't exist anywhere else (and stashing it in a side-table just to return an iterator over it would be awkward because it doesn't need to persist beyond the postprocessing we do on it).
cfallin submitted PR review.
jameysharp submitted PR review.
jameysharp created PR review comment:
I haven't read the surrounding code, but in general, an
Iterator
can itself own the data over which it's iterating. In particular,Vec::into_iter
returns an iterator that owns the vector and will drop it when the iterator is dropped.
cfallin created PR review comment:
Ah, that's a good point! I'll rework in this direction.
cfallin submitted PR review.
cfallin updated PR #4908 from isle-multi-extractors
to main
.
cfallin created PR review comment:
Updated just now. It's a little awkward with the
ContextIter
adapters (this is necessary to allow the lowering trait to provide multi-etor iterators without holding a borrow on the wholeContext
) but it seems to work.
cfallin submitted PR review.
cfallin updated PR #4908 from isle-multi-extractors
to main
.
jameysharp submitted PR review.
cfallin updated PR #4908 from isle-multi-extractors
to main
.
cfallin has enabled auto merge for PR #4908.
cfallin merged PR #4908.
Last updated: Dec 23 2024 at 12:05 UTC