-
Notifications
You must be signed in to change notification settings - Fork 8k
[PFA 2/n] Support PFA functionality #20848
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
Open
arnaud-lb
wants to merge
47
commits into
php:master
Choose a base branch
from
arnaud-lb:partials-v2-gen
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.
Open
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
07bf2bc
Partial application
arnaud-lb 45fdaac
Remove unnecessary change
arnaud-lb 80172bb
Skip preload test on Windows
arnaud-lb b1b3143
Comments
arnaud-lb 00d8ea7
Improve type coherency
arnaud-lb f2761fb
Clarify
arnaud-lb b4b5913
Useless memset
arnaud-lb 7d555ca
Move include
arnaud-lb bbfafb1
Rename tests
arnaud-lb b75f636
Fix test
arnaud-lb 415b710
Better type
arnaud-lb d14e971
Generated file
arnaud-lb 38cefac
Consistency
arnaud-lb 5833529
Fix test name
arnaud-lb c032ec3
Improve tests
arnaud-lb a9658b8
Improve tests
arnaud-lb 4b2d4d5
Improve tests
arnaud-lb 17ac6b2
Update comment, add tests
arnaud-lb d6ccbba
Improve test
arnaud-lb f12fa36
Avoid void cast
arnaud-lb 261dc75
Fix tests
arnaud-lb 83a54c0
constify
arnaud-lb fb57977
inline
arnaud-lb b4efad5
Useless condition
arnaud-lb 430e3bd
const
arnaud-lb dffbcd4
Simplify
arnaud-lb 985f5b1
fix build
arnaud-lb b75bf82
Fix test on x32
arnaud-lb 39ba9bd
Support PFAs in array_map() optimization
arnaud-lb c8f1654
Reuse zp_argument_error()
arnaud-lb 84214ba
WS
arnaud-lb 1d6f2df
Improve tests
arnaud-lb 2396893
Add tests
arnaud-lb 97c1bf1
Fix tests
arnaud-lb 7c4055e
Fix arg name
arnaud-lb a56a3e5
Add tests
arnaud-lb e155185
Fix tests after rebasing
arnaud-lb cabbfb6
Fix tests
arnaud-lb 8f69b50
Improve tests
arnaud-lb 3a3df20
CS
arnaud-lb 6bc2a0b
Placeholder tmps=
arnaud-lb cc54793
Improve tests
arnaud-lb 523f0fa
ZEND_SEND_PLACEHOLDER metadata
arnaud-lb 04e9b0f
CS
arnaud-lb abb5d54
Fix re-binding of inner closure, fix test
arnaud-lb 5a3de00
Fix staticness inference
arnaud-lb 85ea067
Generated files
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
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
10 changes: 0 additions & 10 deletions
10
Zend/tests/first_class_callable/first_class_callable_non_unary_error.phpt
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
Zend/tests/first_class_callable/first_class_callable_non_variadic_error.phpt
This file was deleted.
Oops, something went wrong.
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,35 @@ | ||
| --TEST-- | ||
| PFA of assert() behaves like a dynamic call to assert() | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| try { | ||
| echo "# Static call:\n"; | ||
| assert(false); | ||
| } catch (Error $e) { | ||
| echo $e::class, ": ", $e->getMessage(), "\n"; | ||
| } | ||
|
|
||
| try { | ||
| echo "# Dynamic call:\n"; | ||
| (function ($f) { $f(false); })('assert'); | ||
| } catch (Error $e) { | ||
| echo $e::class, ": ", $e->getMessage() ?: '(no message)', "\n"; | ||
| } | ||
|
|
||
| try { | ||
| echo "# PFA call:\n"; | ||
| $f = assert(?); | ||
| $f(false); | ||
| } catch (Error $e) { | ||
| echo $e::class, ": ", $e->getMessage() ?: '(no message)', "\n"; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| # Static call: | ||
| AssertionError: assert(false) | ||
| # Dynamic call: | ||
| AssertionError: (no message) | ||
| # PFA call: | ||
| AssertionError: (no message) |
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,88 @@ | ||
| --TEST-- | ||
| PFA inherits NoDiscard and SensitiveParameter attributes | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| #[Attribute] | ||
| class Test {} | ||
|
|
||
| #[NoDiscard] #[Test] | ||
| function f($a, #[SensitiveParameter] $b, #[Test] ...$c) { | ||
| } | ||
|
|
||
| function dump_attributes($function) { | ||
| $r = new ReflectionFunction($function); | ||
| var_dump($r->getAttributes()); | ||
|
|
||
| foreach ($r->getParameters() as $i => $p) { | ||
| echo "Parameter $i:\n"; | ||
| var_dump($p->getAttributes()); | ||
| } | ||
| } | ||
|
|
||
| echo "# Orig attributes:\n"; | ||
|
|
||
| dump_attributes('f'); | ||
|
|
||
| $f = f(1, ?, ?, ...); | ||
|
|
||
| echo "# PFA attributes:\n"; | ||
|
|
||
| dump_attributes($f); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| # Orig attributes: | ||
| array(2) { | ||
| [0]=> | ||
| object(ReflectionAttribute)#%d (1) { | ||
| ["name"]=> | ||
| string(9) "NoDiscard" | ||
| } | ||
| [1]=> | ||
| object(ReflectionAttribute)#%d (1) { | ||
| ["name"]=> | ||
| string(4) "Test" | ||
| } | ||
| } | ||
| Parameter 0: | ||
| array(0) { | ||
| } | ||
| Parameter 1: | ||
| array(1) { | ||
| [0]=> | ||
| object(ReflectionAttribute)#%d (1) { | ||
| ["name"]=> | ||
| string(18) "SensitiveParameter" | ||
| } | ||
| } | ||
| Parameter 2: | ||
| array(1) { | ||
| [0]=> | ||
| object(ReflectionAttribute)#%d (1) { | ||
| ["name"]=> | ||
| string(4) "Test" | ||
| } | ||
| } | ||
| # PFA attributes: | ||
| array(1) { | ||
| [0]=> | ||
| object(ReflectionAttribute)#%d (1) { | ||
| ["name"]=> | ||
| string(9) "NoDiscard" | ||
| } | ||
| } | ||
| Parameter 0: | ||
| array(1) { | ||
| [0]=> | ||
| object(ReflectionAttribute)#%d (1) { | ||
| ["name"]=> | ||
| string(18) "SensitiveParameter" | ||
| } | ||
| } | ||
| Parameter 1: | ||
| array(0) { | ||
| } | ||
| Parameter 2: | ||
| array(0) { | ||
| } | ||
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,19 @@ | ||
| --TEST-- | ||
| PFA preserves #[SensitiveParameter] | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function f($a, #[SensitiveParameter] $b, $c, #[SensitiveParameter] ...$d) { | ||
| throw new Exception(); | ||
| } | ||
|
|
||
| $f = f(1, ?, ?, ?, ...)('normal param', 3, 'reified variadic', 'variadic'); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Uncaught Exception in %s:%d | ||
| Stack trace: | ||
| #0 %s(%d): f(1, Object(SensitiveParameterValue), 3, Object(SensitiveParameterValue), Object(SensitiveParameterValue)) | ||
| #1 %s(%d): {closure:pfa:%s:7}(Object(SensitiveParameterValue), 3, Object(SensitiveParameterValue), Object(SensitiveParameterValue)) | ||
| #2 {main} | ||
| thrown 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,16 @@ | ||
| --TEST-- | ||
| PFA preserves #[NoDiscard] | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| #[NoDiscard] function f($a) { | ||
| } | ||
|
|
||
| $f = f(?); | ||
| $f(1); | ||
|
|
||
| (void) $f(1); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Warning: The return value of function {closure:%s}() should either be used or intentionally ignored by casting it as (void) in %s on line 7 |
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,50 @@ | ||
| --TEST-- | ||
| clone() can be partially applied | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| class C { | ||
| public function __construct( | ||
| public mixed $a, | ||
| public mixed $b, | ||
| ) { } | ||
| } | ||
|
|
||
| $clone = clone(?); | ||
| var_dump($clone(new C(1, 2))); | ||
|
|
||
| $clone = clone(...); | ||
| var_dump($clone(new C(3, 4))); | ||
|
|
||
| $clone = clone(new C(5, 6), ?); | ||
| var_dump($clone(['a' => 7])); | ||
|
|
||
| $clone = clone(?, ['a' => 8]); | ||
| var_dump($clone(new C(9, 10))); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| object(C)#%d (2) { | ||
| ["a"]=> | ||
| int(1) | ||
| ["b"]=> | ||
| int(2) | ||
| } | ||
| object(C)#%d (2) { | ||
| ["a"]=> | ||
| int(3) | ||
| ["b"]=> | ||
| int(4) | ||
| } | ||
| object(C)#%d (2) { | ||
| ["a"]=> | ||
| int(7) | ||
| ["b"]=> | ||
| int(6) | ||
| } | ||
| object(C)#%d (2) { | ||
| ["a"]=> | ||
| int(8) | ||
| ["b"]=> | ||
| int(10) | ||
| } |
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,8 @@ | ||
| --TEST-- | ||
| PFA compile errors: multiple variadic placeholders | ||
| --FILE-- | ||
| <?php | ||
| foo(..., ...); | ||
| ?> | ||
| --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,8 @@ | ||
| --TEST-- | ||
| PFA compile errors: variadic placeholder must be last | ||
| --FILE-- | ||
| <?php | ||
| foo(..., ?); | ||
| ?> | ||
| --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,8 @@ | ||
| --TEST-- | ||
| PFA compile errors: placeholders can not appear after named args | ||
| --FILE-- | ||
| <?php | ||
| foo(n: 5, ?); | ||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Cannot use positional argument after named argument 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,8 @@ | ||
| --TEST-- | ||
| PFA compile errors: variadic placeholder must be last, including after named args | ||
| --FILE-- | ||
| <?php | ||
| foo(..., n: 5); | ||
| ?> | ||
| --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,8 @@ | ||
| --TEST-- | ||
| PFA compile errors: variadic placeholder must be last, including after positional args | ||
| --FILE-- | ||
| <?php | ||
| foo(..., $a); | ||
| ?> | ||
| --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,8 @@ | ||||||
| --TEST-- | ||||||
| PFA compile errors: can not use unpacking in PFA, including with variadic placeholdres | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| --FILE-- | ||||||
| <?php | ||||||
| foo(...["foo" => "bar"], ...); | ||||||
| ?> | ||||||
| --EXPECTF-- | ||||||
| Fatal error: Cannot combine partial application and unpacking in %s on line %d | ||||||
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.
why only these attributes but not the others (looking at
#[Test]specifically here)