-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Implement return types #997
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
Conversation
ef8e348
to
c322955
Compare
So I guess, the function keyword is still going to be required for declaring methods even when return type hinting is implemented? If so, it just kills the purpose of this feature. Much more typing and ugly syntax, I wont use it then. I hope, this one will be optional though. |
@HallofFamer No, it won't replace the function keyword. At some point in some future RFC someone could theoretically make |
c322955
to
f047cf7
Compare
f047cf7
to
a0ce77a
Compare
@@ -193,7 +193,7 @@ ZEND_API zend_ast *zend_ast_create(zend_ast_kind kind, ...); | |||
|
|||
ZEND_API zend_ast *zend_ast_create_decl( | |||
zend_ast_kind kind, uint32_t flags, uint32_t start_lineno, zend_string *doc_comment, | |||
zend_string *name, zend_ast *child0, zend_ast *child1, zend_ast *child2 | |||
zend_string *name, zend_ast *child0, zend_ast *child1, zend_ast *child2, zend_ast *child3 |
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.
Instead of changing the API/ABI here, wouldn't it make more sense to use a ** for the children? Right now, this ABI can be changed for PHP 7, but not generally in any other case than a major release.
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.
@derickr I thought we broke the ABI on minors?
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.
x.y.z to x.y+1.z
- Bugfixes
- New features
- Extensions support can be ended (moved to pecl)
- Backward compatibility must be kept
- API compatibility must be kept (userland)
- ABI and API can be broken (internals), src compatibility should be kept if possible, while breakages are allowed
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 for PHP7
On Wed, Jan 28, 2015 at 5:23 AM, Andrea Faulds [email protected]
wrote:
In Zend/zend_ast.h
#997 (comment):@@ -193,7 +193,7 @@ ZEND_API zend_ast *zend_ast_create(zend_ast_kind kind, ...);
ZEND_API zend_ast *zend_ast_create_decl(
zend_ast_kind kind, uint32_t flags, uint32_t start_lineno, zend_string *doc_comment,
- zend_string *name, zend_ast *child0, zend_ast *child1, zend_ast *child2
- zend_string *name, zend_ast *child0, zend_ast *child1, zend_ast *child2, zend_ast *child3
x.y.z to x.y+1.z
Bugfixes
New features
Extensions support can be ended (moved to pecl)
Backward compatibility must be kept
API compatibility must be kept (userland)
ABI and API can be broken (internals), src compatibility should be
kept if possible, while breakages are allowed—
Reply to this email directly or view it on GitHub
https://github.com/php/php-src/pull/997/files#r23661647.
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 also a largely internal API anyway
Okay for god's sake I hope by the time PHP 7 comes out, the function keyword will be optional, especially with class methods(not necessary with orphan functions, since these really by definition are 'functions'). The function keyword does not mesh well with the return type syntax, the two combined makes syntax ugly and hard to read. |
@@ -0,0 +1,28 @@ | |||
--TEST-- | |||
Method returned callable, expected callable |
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.
wrong test name, copied from 011.phpt
IMO it would be a good idea to run the phpng benchmark before and after merging this into master //cc @dstogov |
the patch was carefully designed to not make any performance degradation. On Sat, Jan 24, 2015 at 11:47 AM, Markus Staab [email protected]
|
I am just started playing with docker and try to get a vm up and runiing, so i can do those benchmarks myself in the future. Thanks |
@dstogov i just ran the benchmark on a freshly configured ubuntu 14 lts. It yielded 7,339,515,001 instructions for the Zend/bench.php. Does the number of instructions depend on the architecture or where might this big diff come frame - comparing to your measures within the phpng rfc? |
I suppose you run PHP master branch. may be you run DEBUG build? On Sun, Jan 25, 2015 at 1:47 AM, Markus Staab [email protected]
|
cfd7dcf
to
0009013
Compare
RFC is documented here: https://wiki.php.net/rfc/return_types
0009013
to
c8576c5
Compare
For anyone who's concerned about the failing Travis CI build that shows lots of return type test case failures ... I just compiled release and debug builds in linux, windows and mac environments and didn't receive any unexpected test failures. Not sure why Travis borked, but everything seems fine so far as I can tell. |
@rdlowrey Travis is segfaulting, that is incredibly serious and must be looked into. |
Serious is serious, I'm just saying I've tried to reproduce and have been unable to do so with this patch applied to current master. |
Could not reproduce too. Linux and OSx here. |
I also can't reproduce, but I'm curious now. May look over the source. |
some problems are reproducible running: make test TESTS="-m Dmitry. On Wed, Jan 28, 2015 at 5:21 AM, Andrea Faulds [email protected]
|
|
||
if (op_array->fn_flags & ZEND_ACC_VARIADIC) { | ||
num_args++; | ||
} | ||
for (i = 0; i < num_args; i++) { | ||
for ( ; i < num_args; i++) { |
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.
That for loop looks like an error to me - I know it's not, but the lack of an initialisation expression is weird. while (i++ < num_args) {
would seem better to me. But what do I know.
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.
right :)
I'm in the process of fixing.
Dmitry.
On Wed, Jan 28, 2015 at 5:31 AM, Andrea Faulds [email protected]
wrote:
In Zend/zend_opcode.c
#997 (comment):if (op_array->fn_flags & ZEND_ACC_VARIADIC) { num_args++; }
for (i = 0; i < num_args; i++) {
for ( ; i < num_args; i++) {
This looks to my eyes like an error... while (i++ < num_args) { would
seem better to me. But what do I know.—
Reply to this email directly or view it on GitHub
https://github.com/php/php-src/pull/997/files#r23661891.
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.
It may just be the space that throws me off, for (; i < num_args; i++) {
would be fine and probably better than using a while
loop
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.
Ooh, this may be causing a segfault actually:
http://chat.stackoverflow.com/transcript/message/21204876#21204876
RFC is documented here: https://wiki.php.net/rfc/return_types
This differs from Dmitry's pull request #986 in a few ways: