forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 1
Partials v2 gen #22
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
17
commits into
master
Choose a base branch
from
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.
Draft
Partials v2 gen #22
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f65bf45
Partial application
arnaud-lb a65faa6
Generate static closure when possible. Use static:: for static methods.
arnaud-lb a8701b1
Fix tests
arnaud-lb 24d16a3
Use only function as cache key. Fix inline cache.
arnaud-lb eb6e304
Fix jit
arnaud-lb 23dce32
Restore bindTo() rules (TODO: rebind internal closure)
arnaud-lb ca7d05b
Reorganize zend_partial_create / zp_compile
arnaud-lb 2b0a697
Fix arg
arnaud-lb 99886b7
Use arena
arnaud-lb 4998b9d
Fix pass-by-ref variadic
arnaud-lb 6cd5d6a
Simplify
arnaud-lb 4707bbb
Remove trailing new line in tests
arnaud-lb 50278cc
Print exception class
arnaud-lb 6fb8e36
Update Zend/tests/partial_application/clone.phpt
arnaud-lb 73b218d
Fix tests when opcache is not enabled
arnaud-lb 3bc2239
Fix mem leak when opcache is not enabled
arnaud-lb c5bdca0
Fix UAF when opcache is not enabled
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
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,92 @@ | ||
--TEST-- | ||
Closure application copies attributes | ||
--XFAIL-- | ||
Only NoDiscard and SensitiveParameter are copied | ||
--FILE-- | ||
<?php | ||
|
||
#[Attribute] | ||
class Test {} | ||
|
||
#[NoDiscard] | ||
function f($a, #[SensitiveParameter] $b, #[Test] ...$c) { | ||
} | ||
|
||
function dump_attributes($function) { | ||
echo "Function attributes:\n"; | ||
$r = new ReflectionFunction($function); | ||
var_dump($r->getAttributes()); | ||
|
||
foreach ($r->getParameters() as $i => $p) { | ||
echo "Parameter $i:\n"; | ||
var_dump($p->getAttributes()); | ||
} | ||
} | ||
|
||
dump_attributes('f'); | ||
|
||
$f = f(1, ?, ?, ...); | ||
|
||
dump_attributes($f); | ||
|
||
?> | ||
--EXPECTF-- | ||
Function attributes: | ||
array(1) { | ||
[0]=> | ||
object(ReflectionAttribute)#%d (1) { | ||
["name"]=> | ||
string(9) "NoDiscard" | ||
} | ||
} | ||
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" | ||
} | ||
} | ||
Function 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(1) { | ||
[0]=> | ||
object(ReflectionAttribute)#%d (1) { | ||
["name"]=> | ||
string(4) "Test" | ||
} | ||
} | ||
Parameter 2: | ||
array(1) { | ||
[0]=> | ||
object(ReflectionAttribute)#%d (1) { | ||
["name"]=> | ||
string(4) "Test" | ||
} | ||
} |
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,53 @@ | ||
--TEST-- | ||
Closure application preserves #[SensitiveParameter] | ||
--FILE-- | ||
<?php | ||
|
||
function f($a, #[SensitiveParameter] $b, $c) { | ||
throw new Exception(); | ||
} | ||
|
||
echo "# During partial application:\n"; | ||
|
||
try { | ||
$f = f(1, 'sensitive'); | ||
} catch (Error $e) { | ||
echo $e, "\n\n"; | ||
} | ||
|
||
echo "# In trampoline:\n"; | ||
|
||
try { | ||
$f = f(1, ?, ?)('sensitive'); | ||
} catch (Error $e) { | ||
echo $e, "\n\n"; | ||
} | ||
|
||
echo "# In execution:\n"; | ||
|
||
try { | ||
$f = f(1, ?, ?)('sensitive', 3); | ||
} catch (Exception $e) { | ||
echo $e, "\n"; | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
# During partial application: | ||
ArgumentCountError: Too few arguments to function f(), 2 passed in %s on line %d and exactly 3 expected in %s:%d | ||
Stack trace: | ||
#0 %s(%d): f(1, Object(SensitiveParameterValue)) | ||
#1 {main} | ||
|
||
# In trampoline: | ||
ArgumentCountError: Too few arguments to function {closure:%s:%d}(), 1 passed in %s on line %d and exactly 2 expected in %s:%d | ||
Stack trace: | ||
#0 %s(%d): {closure:%s}(Object(SensitiveParameterValue)) | ||
#1 {main} | ||
|
||
# In execution: | ||
Exception in %s:%d | ||
Stack trace: | ||
#0 %s(%d): f(1, Object(SensitiveParameterValue), 3) | ||
#1 %s(%d): {closure:%s}(Object(SensitiveParameterValue), 3) | ||
#2 {main} |
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-- | ||
Closure application 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-- | ||
Closure application clone | ||
--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"]=> | ||
NULL | ||
["b"]=> | ||
NULL | ||
} | ||
object(C)#%d (2) { | ||
["a"]=> | ||
NULL | ||
["b"]=> | ||
NULL | ||
} | ||
object(C)#%d (2) { | ||
["a"]=> | ||
int(1) | ||
["b"]=> | ||
NULL | ||
} | ||
object(C)#%d (2) { | ||
["a"]=> | ||
int(1) | ||
["b"]=> | ||
NULL | ||
} |
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-- | ||
Closure application compile errors: multiple ... | ||
--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-- | ||
Closure application compile errors: only named arguments after ... | ||
--FILE-- | ||
<?php | ||
foo(..., ?); | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Only named arguments may follow variadic placeholder 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-- | ||
Closure application compile errors: named arguments must come after placeholder | ||
--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-- | ||
Closure application compile errors: named arguments must come after variadic placeholder | ||
--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-- | ||
Closure application compile errors: follow variadic with un-named arg | ||
--FILE-- | ||
<?php | ||
foo(..., $a); | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Only named arguments may follow variadic placeholder 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-- | ||
Closure application compile errors: mix application with unpack (placeholder after) | ||
--FILE-- | ||
<?php | ||
foo(...["foo" => "bar"], ...); | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Cannot combine partial application and unpacking 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-- | ||
Closure application compile errors: mix application with unpack (placeholder before) | ||
--FILE-- | ||
<?php | ||
foo(..., ...["foo" => "bar"]); | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Cannot combine partial application and unpacking %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,37 @@ | ||
--TEST-- | ||
Closure application errors: placeholder count errors | ||
--FILE-- | ||
<?php | ||
function foo($a, $b, $c) { | ||
|
||
} | ||
|
||
try { | ||
foo(?); | ||
} catch (Error $ex) { | ||
printf("%s\n", $ex->getMessage()); | ||
} | ||
|
||
try { | ||
foo(?, ?, ?, ?); | ||
} catch (Error $ex) { | ||
printf("%s\n", $ex->getMessage()); | ||
} | ||
|
||
try { | ||
property_exists(?); | ||
} catch (Error $ex) { | ||
printf("%s\n", $ex->getMessage()); | ||
} | ||
|
||
try { | ||
usleep(?, ?); | ||
} catch (Error $ex) { | ||
printf("%s\n", $ex->getMessage()); | ||
} | ||
?> | ||
--EXPECT-- | ||
not enough arguments or placeholders for application of foo, 1 given and exactly 3 expected | ||
too many arguments or placeholders for application of foo, 4 given and a maximum of 3 expected | ||
not enough arguments or placeholders for application of property_exists, 1 given and exactly 2 expected | ||
too many arguments or placeholders for application of usleep, 2 given and a maximum of 1 expected |
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-- | ||
Closure application errors: named parameter overwrites placeholder | ||
--FILE-- | ||
<?php | ||
function foo($a) { | ||
|
||
} | ||
|
||
try { | ||
foo(?, a: 1); | ||
} catch (Error $ex) { | ||
printf("%s: %s\n", $ex::class, $ex->getMessage()); | ||
} | ||
?> | ||
--EXPECT-- | ||
Error: Named parameter $a overwrites previous placeholder |
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.
Uh oh!
There was an error while loading. Please reload this page.