GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — [RFC] Pattern matching by iluuu1994 · Pull Request #20574 · php/php-src Conversation
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| zend_stack_push(&context->bindings, &binding); | ||
|
|
||
| // FIXME: This can be elided most of the time. It may not for: | ||
| // - $a is $b |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
As I think I noted in the discussion, I believe $a is $b with a bare variable on the right should just be a compile-time error.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I understand your reservation here is the confusion of $a is $b as $a === $b, but this seems like an arbitrary restriction. For match specifically, it seems somewhat reasonable. For example:
match ($userOrError) { is User & $user => login($user), is $error => showError($error), };
The rename serves a purpose in the readability sense. Only preventing standalone bindings in is but not match is possible, but seems even more arbitrary.
I don't have too strong feelings on this, so if you can convince @Crell I'm happy to make the change.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I understand your reservation here is the confusion of $a is $b as $a === $b,
Yes. Especially since Python's is for example is a comparison operator.
but this seems like an arbitrary restriction
I feel like this is something that would be pointed out by static analysis tools / IDEs anyways as a possible source of bug, because there is rarely (if ever) a reason to write this. To me it would therefore be helpful to take this footgun away from folks within the language itself so that they don't need to rely on third party tools. I'd be okay with allowing it as $a is ($b) which is similar to how the extra parentheses in:
if (($user = $repository->find($id))) {
}
generally suppress the warnings from IDEs that ask about possible = and == confusion.
Only preventing standalone bindings in
isbut notmatchis possible, but seems even more arbitrary.
Even in match it is misleading, because it effectively is a default that doesn't look like one. is mixed&$error or possibly is default&$error would both be clearer to me.
But I'm happy to figure this out as part of the proper ML discussion rather than inside this PR where no one will find it in the future.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
It's unclear as of yet whether eliding mixed is useful, especially given the optimizer already supports it. For objects, mixed is useless. For arrays, we need some comparison to check whether the offset is IS_UNDEF, so it can't be fully elided anyway. Hence, forget about this for now.
There was an error while loading. Please reload this page.
| bool(true) | ||
| bool(false) | ||
| bool(false) | ||
| bool(false) | ||
| bool(false) | ||
| bool(true) | ||
| bool(true) | ||
| bool(true) | ||
| bool(false) | ||
| bool(false) | ||
| bool(false) | ||
| bool(false) | ||
| bool(false) | ||
| bool(false) | ||
| bool(false) | ||
| bool(true) | ||
| bool(true) | ||
| bool(false) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It would help the readability of the test if this would be structured into “these should match” and “these shouldn't”, possibly with a clear marker in-between. The one doesn't need to cross-reference every single line from the expectation and the test code. Or alternatively clearly separated for each of the variables “$foo up next”, “$bar up next”, “null up next”.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Test-wise I believe a test for $foo is "$foo" and $foo is "\x00" is missing (i.e. for interpolation and escape characters).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -0,0 +1,19 @@ | |||
| --TEST-- | |||
| Refcoutned expression | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Typo in description. It's also awfully generic. I generally try to prefix to prefix the description with the “component name”, this makes it easier to distinguish tests in the output without looking at the file name.
Perhaps something like Pattern Matching: Refcounted match expression or something like this?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| uint32_t rhs_count = rhs->kind == kind ? zend_ast_get_list(rhs)->children : 1; | ||
| uint32_t count = lhs_count + rhs_count; | ||
| uint32_t size = stdc_bit_ceil_ui(count); | ||
| if (size < 4) size = 4; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| if (size < 4) size = 4; | |
| if (size < 4) { | |
| size = 4; | |
| } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This is basically free.
We'll go with either ranges or this, yet to decide.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.