-
Notifications
You must be signed in to change notification settings - Fork 8.1k
[PFA 3/n] Support PFA in const exprs #22785
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
Draft
arnaud-lb
wants to merge
8
commits into
php:master
Choose a base branch
from
arnaud-lb:partials-const-expr-simple
base: master
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.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fe6432b
run-tests: Clean the file cache directory in --file-cache-prime
arnaud-lb f5efdc6
Fix preloading FCC const exprs
arnaud-lb ba99bcb
Use a pointer to the declaring opline->lineno as unique addr, instead…
arnaud-lb 58c2e55
zend_partial_create(): Remove the dependency on the declaring op_array
arnaud-lb f5a4f79
Support for PFA in constant expressions
arnaud-lb 3c9faab
Fix test
arnaud-lb b398da2
Fix memory leaks
arnaud-lb 0a6d9cd
Simplify
arnaud-lb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| --TEST-- | ||
| PFA in constexpr 001 | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function f($a = g("foo", ?)) { | ||
| return $a(1); | ||
| } | ||
|
|
||
| function g(string $a, int $b) { | ||
| return [$a, $b]; | ||
| } | ||
|
|
||
| var_dump(f()); | ||
| var_dump(f()); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| array(2) { | ||
| [0]=> | ||
| string(3) "foo" | ||
| [1]=> | ||
| int(1) | ||
| } | ||
| array(2) { | ||
| [0]=> | ||
| string(3) "foo" | ||
| [1]=> | ||
| int(1) | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --TEST-- | ||
| PFA in constexpr: non-constexpr arg | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function f($a = g(new stdClass, $x, ?)) { | ||
| return $a(1); | ||
| } | ||
|
|
||
| function g(string $a, int $b) { | ||
| return [$a, $b]; | ||
| } | ||
|
|
||
| try { | ||
| var_dump(f()); | ||
| } catch (Error $e) { | ||
| echo $e::class, ": ", $e->getMessage(), " on line ", $e->getLine(); | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Constant expression contains invalid operations in %s on line %d |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| --TEST-- | ||
| PFA in constexpr: named args | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function f($a = g(c: ?, ...)) { | ||
| return $a(1.5, b: 3); | ||
| } | ||
|
|
||
| function g(string $a = 'hello', int $b = 2, float $c = 0) { | ||
| return [$a, $b, $c]; | ||
| } | ||
|
|
||
| var_dump(f()); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| array(3) { | ||
| [0]=> | ||
| string(5) "hello" | ||
| [1]=> | ||
| int(3) | ||
| [2]=> | ||
| float(1.5) | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| --TEST-- | ||
| PFA in constexpr: extra named args | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function f($a = g(?, foo: 'bar', ...)) { | ||
| return $a(1, bar: 'baz'); | ||
| } | ||
|
|
||
| function g(...$args) { | ||
| return [$args]; | ||
| } | ||
|
|
||
| var_dump(f()); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| array(1) { | ||
| [0]=> | ||
| array(3) { | ||
| [0]=> | ||
| int(1) | ||
| ["foo"]=> | ||
| string(3) "bar" | ||
| ["bar"]=> | ||
| string(3) "baz" | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --TEST-- | ||
| PFA in constexpr: variadic placeholder must be after positional params | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function f($a = g(..., 1)) { | ||
| } | ||
|
|
||
| f(); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Variadic placeholder must be last in %s on line %d |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --TEST-- | ||
| PFA in constexpr: variadic placeholder must be after named params | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function f($a = g(..., foo: 1)) { | ||
| } | ||
|
|
||
| f(); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Variadic placeholder must be last in %s on line %d |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --TEST-- | ||
| PFA in constexpr: variadic placeholder may only appear once | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function f($a = g(..., ...)) { | ||
| } | ||
|
|
||
| f(); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Variadic placeholder may only appear once in %s on line %d |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --TEST-- | ||
| PFA in constexpr: variadic placeholder not allowed to be named | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function f($a = g(foo: ...)) { | ||
| } | ||
|
|
||
| f(); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Parse error: syntax error, unexpected token "..." in %s on line %d |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --TEST-- | ||
| PFA in constexpr: variadic placeholder not allowed to be named | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function f($a = g(foo: ...)) { | ||
| } | ||
|
|
||
| f(); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Parse error: syntax error, unexpected token "..." in %s on line %d |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| --TEST-- | ||
| PFA in constexpr: error during partial creation | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function f($a = g(?)) { | ||
| } | ||
|
|
||
| function g($a, $b) { | ||
| } | ||
|
|
||
| try { | ||
| f(); | ||
| } catch (Error $e) { | ||
| echo $e::class, ": ", $e->getMessage(), "\n"; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| ArgumentCountError: Partial application of g() expects exactly 2 arguments, 1 given |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| --TEST-- | ||
| PFA in constexpr: error during arg list evaluation | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function f($a = g(strlen(?), e: strlen(?), a: strlen(?), ...)) { | ||
| } | ||
|
|
||
| function g($a, $b, $c, $d, $e) { | ||
| } | ||
|
|
||
| function h($a = i(strlen(?), a: strlen(?), b: invalid(?), ...)) { | ||
| } | ||
|
|
||
| function i(...$args) { | ||
| } | ||
|
|
||
| try { | ||
| f(); | ||
| } catch (Error $e) { | ||
| echo $e::class, ": ", $e->getMessage(), "\n"; | ||
| } | ||
|
|
||
| try { | ||
| h(); | ||
| } catch (Error $e) { | ||
| echo $e::class, ": ", $e->getMessage(), "\n"; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| Error: Named parameter $a overwrites previous argument | ||
| Error: Call to undefined function invalid() |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| --TEST-- | ||
| PFA in constexpr: nested const expr | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function f($a = g(new stdClass, g(...), ...)) { | ||
| return $a(1); | ||
| } | ||
|
|
||
| function g($a, $b, $c) { | ||
| return [$a, $b, $c]; | ||
| } | ||
|
|
||
| var_dump(f()); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| array(3) { | ||
| [0]=> | ||
| object(stdClass)#%d (0) { | ||
| } | ||
| [1]=> | ||
| object(Closure)#%d (2) { | ||
| ["function"]=> | ||
| string(1) "g" | ||
| ["parameter"]=> | ||
| array(3) { | ||
| ["$a"]=> | ||
| string(10) "<required>" | ||
| ["$b"]=> | ||
| string(10) "<required>" | ||
| ["$c"]=> | ||
| string(10) "<required>" | ||
| } | ||
| } | ||
| [2]=> | ||
| int(1) | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| --TEST-- | ||
| PFA in constexpr: sites | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| #[Attribute] | ||
| class A { | ||
| function __construct(public mixed $fn) {} | ||
| } | ||
|
|
||
| #[A(strlen(?))] | ||
| class C { | ||
| const CC = strlen(?); | ||
|
|
||
| #[A(strlen(?))] | ||
| function f($arg = strlen(?)) { | ||
| return $arg; | ||
| } | ||
| } | ||
|
|
||
| const CC = strlen(?); | ||
|
|
||
| echo "# Class const\n"; | ||
| var_dump((C::CC)('hello')); | ||
| echo "# Const\n"; | ||
| var_dump((CC)('hello')); | ||
| echo "# Class attr\n"; | ||
| var_dump((new ReflectionClass(C::class)->getAttributes(A::class)[0]->newInstance()->fn)('hello')); | ||
| echo "# Method attr\n"; | ||
| var_dump((new ReflectionMethod(C::class, 'f')->getAttributes(A::class)[0]->newInstance()->fn)('hello')); | ||
| echo "# Method default value\n"; | ||
| var_dump((new C()->f())('hello')); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| # Class const | ||
| int(5) | ||
| # Const | ||
| int(5) | ||
| # Class attr | ||
| int(5) | ||
| # Method attr | ||
| int(5) | ||
| # Method default value | ||
| int(5) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?php | ||
|
|
||
| #[Attribute] | ||
| class A { | ||
| function __construct(public mixed $fn) {} | ||
| } | ||
|
|
||
| #[A(strlen(?))] | ||
| class C { | ||
| const CC = strlen(?); | ||
|
|
||
| #[A(strlen(?))] | ||
| function f($arg = strlen(?)) { | ||
| return $arg; | ||
| } | ||
| } | ||
|
|
||
| const CC = strlen(?); | ||
|
|
||
| ?> |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| --TEST-- | ||
| PFA in constexpr: preloading | ||
| --INI-- | ||
| opcache.enable=1 | ||
| opcache.enable_cli=1 | ||
| opcache.optimization_level=-1 | ||
| opcache.preload={PWD}/constexpr_015.inc | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| echo "# Class const\n"; | ||
| var_dump((C::CC)('hello')); | ||
| echo "# Class attr\n"; | ||
| var_dump((new ReflectionClass(C::class)->getAttributes(A::class)[0]->newInstance()->fn)('hello')); | ||
| echo "# Method attr\n"; | ||
| var_dump((new ReflectionMethod(C::class, 'f')->getAttributes(A::class)[0]->newInstance()->fn)('hello')); | ||
| echo "# Method default value\n"; | ||
| var_dump((new C()->f())('hello')); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| # Class const | ||
| int(5) | ||
| # Class attr | ||
| int(5) | ||
| # Method attr | ||
| int(5) | ||
| # Method default value | ||
| int(5) |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same as Zend/tests/partial_application/constexpr_008.phpt