Skip to content

ISLE: add support for multi-extractors and multi-constructors. #4908

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

Merged
merged 3 commits into from
Sep 21, 2022

Conversation

cfallin
Copy link
Member

@cfallin cfallin commented Sep 14, 2022

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.

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.
@cfallin cfallin requested a review from fitzgen September 14, 2022 00:42
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language labels Sep 14, 2022
@github-actions
Copy link

Subscribe to Label Action

cc @cfallin, @fitzgen

This issue or pull request has been labeled: "cranelift", "isle"

Thus the following users have been cc'd because of the following labels:

  • cfallin: isle
  • fitzgen: isle

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@cfallin
Copy link
Member Author

cfallin commented Sep 19, 2022

Updated, thanks!

@cfallin cfallin force-pushed the isle-multi-extractors branch from aac03d8 to 84236a6 Compare September 19, 2022 21:28
@jameysharp
Copy link
Contributor

I still need to read this more carefully, but I think it looks good.

One question so far: what's the intended difference between returning Some with an empty iterator, versus returning None? Put another way, what would we lose if we remove the Option wrapper from those return types? I understand the use of Option for fallible non-multi extractors, but I'm not sure how that extends here. I'd prefer to just use an empty iterator to indicate that the extractor failed, if that's not too much trouble, because otherwise the types appear to permit two ways of encoding the same situation.

I don't see any documentation for how someone writing an external multi-extractor should implement the auto-generated traits. I don't think that's strictly necessary before merging this, but if that documentation existed then I would look for the answer to the above question there.

@cfallin
Copy link
Member Author

cfallin commented Sep 20, 2022

One question so far: what's the intended difference between returning Some with an empty iterator, versus returning None?

That's a good question. Functionally there is no difference, and the main reason is just to manage complexity: otherwise we have a special case wherever we have a match failure in that we have to invent an empty iterator rather than return None. If it were one code-generator site then maybe that's fine, but we also use the ? operator everywhere and I didn't want to work out how to get auto-conversions going with that. It's simpler to stick to the invariant that all constructors live in the Option monad and let the Try magic do its thing.

@github-actions github-actions bot added cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:x64 Issues related to x64 codegen labels Sep 21, 2022
@cfallin cfallin enabled auto-merge (squash) September 21, 2022 23:28
@jameysharp
Copy link
Contributor

I asked Chris to show me a diff of the generated code for existing uses of ISLE. We verified that the only difference was additional types and traits related to ContextIter. As a result I'm convinced that this is safe to merge as-is. I haven't fully understood the multi-extractors and multi-constructors, but since we don't use any of those yet, we can fix any issues that come up when we start trying to use them, instead of worrying about them now.

@cfallin cfallin merged commit b652ce2 into bytecodealliance:main Sep 21, 2022
@cfallin cfallin deleted the isle-multi-extractors branch September 21, 2022 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:x64 Issues related to x64 codegen cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language
3 participants