Skip to content

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

Merged
merged 1 commit into from
Jan 28, 2015
Merged

Implement return types #997

merged 1 commit into from
Jan 28, 2015

Conversation

morrisonlevi
Copy link
Contributor

RFC is documented here: https://wiki.php.net/rfc/return_types

This differs from Dmitry's pull request #986 in a few ways:

  • Minor naming differences
  • Updated to latest master (were some merge conflicts)
  • Return type mismatches are now fatals instead of E_STRICTs.

@HallofFamer
Copy link

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.

@morrisonlevi
Copy link
Contributor Author

@HallofFamer No, it won't replace the function keyword. At some point in some future RFC someone could theoretically make function optional. It's not happening with this RFC as it would certainly kill it dead in the water. Return types and removing the function keyword are orthogonal if return types are placed after the parameter list.

@morrisonlevi morrisonlevi changed the title Implement return type hinting Implement return types Jan 14, 2015
@@ -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
Copy link
Member

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.

Copy link
Contributor

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?

Copy link
Contributor

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

https://wiki.php.net/rfc/releaseprocess#releases_cycle

Copy link
Member

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.

Copy link
Contributor

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

@HallofFamer
Copy link

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
Copy link
Contributor

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

@staabm
Copy link
Contributor

staabm commented Jan 24, 2015

IMO it would be a good idea to run the phpng benchmark before and after merging this into master

//cc @dstogov

@dstogov
Copy link
Member

dstogov commented Jan 24, 2015

the patch was carefully designed to not make any performance degradation.
It was tested about month ago. Nothing serious was changed after that.
Anyway, if you have time and experience - please, test it and report your
results.

On Sat, Jan 24, 2015 at 11:47 AM, Markus Staab [email protected]
wrote:

IMO it would be a good idea to run the phpng benchmark before and after
merging this into master

//cc @dstogov https://github.com/dstogov


Reply to this email directly or view it on GitHub
#997 (comment).

@staabm
Copy link
Contributor

staabm commented Jan 24, 2015

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

@staabm
Copy link
Contributor

staabm commented Jan 24, 2015

@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?

@dstogov
Copy link
Member

dstogov commented Jan 26, 2015

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]
wrote:

@dstogov https://github.com/dstogov i just ran the benchmark on a
freshly configured ubuntu 14 lts. It yielded ~9,267,xxx,yyy 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?


Reply to this email directly or view it on GitHub
#997 (comment).

@morrisonlevi morrisonlevi force-pushed the typed_returns branch 2 times, most recently from cfd7dcf to 0009013 Compare January 27, 2015 18:49
@rdlowrey
Copy link
Contributor

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.

@hikari-no-yume
Copy link
Contributor

@rdlowrey Travis is segfaulting, that is incredibly serious and must be looked into.

@rdlowrey
Copy link
Contributor

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.

@marcioAlmada
Copy link
Contributor

Could not reproduce too. Linux and OSx here.

@hikari-no-yume
Copy link
Contributor

I also can't reproduce, but I'm curious now. May look over the source.

@dstogov
Copy link
Member

dstogov commented Jan 28, 2015

some problems are reproducible running: make test TESTS="-m
Zend/tests/return_types"
I'm working on them

Dmitry.

On Wed, Jan 28, 2015 at 5:21 AM, Andrea Faulds [email protected]
wrote:

I also can't reproduce, but I'm curious now. May look over the source.


Reply to this email directly or view it on GitHub
#997 (comment).


if (op_array->fn_flags & ZEND_ACC_VARIADIC) {
num_args++;
}
for (i = 0; i < num_args; i++) {
for ( ; i < num_args; i++) {
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor

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

Copy link
Contributor

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

@php-pulls php-pulls merged commit c8576c5 into php:master Jan 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.