-
Notifications
You must be signed in to change notification settings - Fork 8k
PHP RFC: Bound-Erased Generic Types #21969
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
azjezz
wants to merge
1
commit into
php:master
Choose a base branch
from
carthage-software:rfc/bound-erased-generic-types
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
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
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
18 changes: 18 additions & 0 deletions
18
Zend/tests/generics/declaration/default_satisfies_bound.phpt
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,18 @@ | ||
| --TEST-- | ||
| Declaration: type-parameter default that satisfies its bound is accepted | ||
| --FILE-- | ||
| <?php | ||
| class A {} | ||
| class B extends A {} | ||
|
|
||
| class Box<T : A = B> {} | ||
| function f<T : A = B>(): void {} | ||
| trait Tr<T : A = B> {} | ||
| interface I<T : A = B> {} | ||
|
|
||
| new Box; | ||
| f(); | ||
| echo "OK\n"; | ||
| ?> | ||
| --EXPECT-- | ||
| OK |
9 changes: 9 additions & 0 deletions
9
Zend/tests/generics/declaration/default_violates_bound_class.phpt
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,9 @@ | ||
| --TEST-- | ||
| Declaration: class type-parameter default that does not satisfy its bound is rejected | ||
| --FILE-- | ||
| <?php | ||
| class Animal {} | ||
| class Box<T : Animal = int> {} | ||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Default int for type parameter T does not satisfy its bound Animal in %s on line %d |
9 changes: 9 additions & 0 deletions
9
Zend/tests/generics/declaration/default_violates_bound_function.phpt
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,9 @@ | ||
| --TEST-- | ||
| Declaration: function type-parameter default that does not satisfy its bound is rejected | ||
| --FILE-- | ||
| <?php | ||
| class Animal {} | ||
| function id<T : Animal = int>(): void {} | ||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Default int for type parameter T does not satisfy its bound Animal in %s on line %d |
9 changes: 9 additions & 0 deletions
9
Zend/tests/generics/declaration/default_violates_bound_interface.phpt
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,9 @@ | ||
| --TEST-- | ||
| Declaration: interface type-parameter default that does not satisfy its bound is rejected | ||
| --FILE-- | ||
| <?php | ||
| class Animal {} | ||
| interface I<T : Animal = int> {} | ||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Default int for type parameter T does not satisfy its bound Animal in %s on line %d |
9 changes: 9 additions & 0 deletions
9
Zend/tests/generics/declaration/default_violates_bound_trait.phpt
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,9 @@ | ||
| --TEST-- | ||
| Declaration: trait type-parameter default that does not satisfy its bound is rejected | ||
| --FILE-- | ||
| <?php | ||
| class Animal {} | ||
| trait Holder<T : Animal = int> {} | ||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Default int for type parameter T does not satisfy its bound Animal in %s on line %d |
8 changes: 8 additions & 0 deletions
8
Zend/tests/generics/declaration/default_with_intersection_bound.phpt
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-- | ||
| Declaration: default checked against intersection bound when types are concrete | ||
| --FILE-- | ||
| <?php | ||
| class Box<T : Traversable & Countable = int> {} | ||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Default int for type parameter T does not satisfy its bound Traversable&Countable in %s on line %d |
8 changes: 8 additions & 0 deletions
8
Zend/tests/generics/declaration/default_with_union_bound.phpt
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-- | ||
| Declaration: default checked against union bound when types are concrete | ||
| --FILE-- | ||
| <?php | ||
| class Box<T : int | string = float> {} | ||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Default float for type parameter T does not satisfy its bound string|int in %s on line %d |
9 changes: 9 additions & 0 deletions
9
Zend/tests/generics/declaration/error_renders_default_args.phpt
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,9 @@ | ||
| --TEST-- | ||
| Bound error message: declaration-time default-vs-bound error renders NAMED_WITH_ARGS in the bound | ||
| --FILE-- | ||
| <?php | ||
| interface Comparable<T> {} | ||
| class Box<T : Comparable<T> = int> {} | ||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Default int for type parameter T does not satisfy its bound Comparable<T> 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,17 @@ | ||
| --TEST-- | ||
| Generics: declaring a class with a DNF-typed bound does not leak memory | ||
| --FILE-- | ||
| <?php | ||
| interface A {} | ||
| interface B {} | ||
| interface C {} | ||
|
|
||
| class Holder<T: (A&B)|C> { | ||
| public function take(T $x): void {} | ||
| public function get(): T {} | ||
| } | ||
|
|
||
| echo "ok\n"; | ||
| ?> | ||
| --EXPECT-- | ||
| ok |
15 changes: 15 additions & 0 deletions
15
Zend/tests/generics/declaration/no_leak_intersection_bound.phpt
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,15 @@ | ||
| --TEST-- | ||
| Generics: declaring a class with an intersection-typed bound does not leak memory | ||
| --FILE-- | ||
| <?php | ||
| interface A {} | ||
| interface B {} | ||
|
|
||
| class Holder<T: A&B> { | ||
| public function take(T $x): void {} | ||
| } | ||
|
|
||
| echo "ok\n"; | ||
| ?> | ||
| --EXPECT-- | ||
| ok |
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,15 @@ | ||
| --TEST-- | ||
| Generics: declaring a class with a union-typed bound does not leak memory | ||
| --FILE-- | ||
| <?php | ||
| interface A {} | ||
| interface B {} | ||
|
|
||
| class Holder<T: A|B> { | ||
| public function take(T $x): void {} | ||
| } | ||
|
|
||
| echo "ok\n"; | ||
| ?> | ||
| --EXPECT-- | ||
| ok |
11 changes: 11 additions & 0 deletions
11
Zend/tests/generics/declaration/recursive_bounds/chain_forward.phpt
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,11 @@ | ||
| --TEST-- | ||
| Recursive bounds: chain of forward references through three parameters | ||
| --FILE-- | ||
| <?php | ||
| class Box<X> {} | ||
| class Foo {} | ||
| function f<T: Box<U>, U: Box<V>, V: Foo>(T $a, U $b, V $c): void {} | ||
| echo "ok\n"; | ||
| ?> | ||
| --EXPECT-- | ||
| ok |
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.
zend_try_inline_callinlines simple function calls by replacing theirINIT_FCALLandDO_FCALLopcodes withNOP.e.g. before the optimizer:
after inlining without the guard:
The constraint is permanent: any future pass that elides an
INIT_FCALL/DO_FCALLpair has to consider whether intervening opcodes depend on the call frame.