-
Notifications
You must be signed in to change notification settings - Fork 183
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
DSLX is different from Rust for match patterns (currently does equality comparison for any bound identifier) #1909
Comments
Shouldn't the parser reject this though? Per https://google.github.io/xls/dslx_reference/#match-expression:
But here there is no "pattern" to match the data against, so it shouldn't probably not be a valid match expression? /cc @richmckeever |
Note: it does seem useful to have a language construct to encapsulate selection of subexpression given a collection of exclusive |
Okay discovered this is in a fun space: this is WAI... but it /shouldn't/ be intended to work this way given we'd like to mimic Rust semantics where reasonably possible. I think this was probably my oversight from a long time back, mea culpa. Currently, in DSLX, if the match pattern identifier is bound in the outer scope, it does an equality comparison (instead of binding the name in the match arm scope) -- the intent of that was to enable things like:
However, that's not the syntax for Rust equality comparison for a match arm -- it's:
So ideally we'd:
The good news is this issue caused me to at least write some more unit level tests for warning on unused bindings in studying the behavior from the original example, that PR is incoming. :-) |
As an intermediary step we could write a warning-as-error for any non-const binding that was used for equality comparison in a match, if people think that'd be valuable as a stepping stone it's easy to whip up. |
This sounds like a good enhancement request! A |
@ericastor @proppy If I'm understanding right, what I've been recommending to people is that if they want this they can do:
Though the DSLX IR converter will emit a prio selector the one hot guaranteed postcondition will ensure the optimizer turns it into a one hot selector. A match is inherently a priority selector on equality conditions right now as I mentioned in #1909 (comment) |
@cdleary Per this issue's original motivating example, DSLX's current match may be a priority selector on equality conditions - but it's not a priority selector on boolean values, and can in fact end up replacing them with unused bindings. I was suggesting a specialized syntax for ordered boolean conditions, so the author doesn't need to manually concat the conditions all into a single selector (remembering which way around the priority goes), feed that through a one_hot, and then pass that to a match against one-hot binary values. |
@ericastor I think I'm getting confused because the unused binding thing is orthogonal and was the crux of the OP -- now we're talking about expressive power/convenience and what ops things lower to. We do have this ability:
Are you saying "we could have a more first class syntax for that pattern and/or its similar one-hot matching scenario"? |
@cdleary Yes. 😀 Or rather, I'm saying that @proppy's comment that "Note: it does seem useful to have a language construct to encapsulate selection of subexpression given a collection of exclusive bool value" is saying that (EDIT: and endorsing the idea). |
@ericastor Thanks for confirming! I'll break out a separate issue: #1913 |
After doing more testing, I don't think that's the case. Your example does pass the following test:
and produces the following un-optimized IR:
which seems to be the correct encoding of the original intent (apart from the |
re-reading @cdleary comment:
Did you mean that the "invalid use" pointed my meheff #1909 (comment) is in fact valid and working as intended (a), or that it is intended to be an "invalid use" (b) ? :) |
The motivation is the following (incorrect) use of match:
Superficially this looks like it tests whether arguments x, y, or z are true and return a respective value. However, this construct creates a new temporary named
x
and binds true to it and returns 42.This should raise a warning that the match temporaries
x
,y
, andz
are unused.The text was updated successfully, but these errors were encountered: