Skip to content

Add return types to internal methods #6548

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

Closed
wants to merge 4 commits into from

Conversation

kocsismate
Copy link
Member

@kocsismate kocsismate commented Dec 28, 2020

@kocsismate kocsismate added the RFC label Dec 28, 2020
@kocsismate kocsismate force-pushed the internal-method-return-type branch 2 times, most recently from 99cace9 to 78cf458 Compare December 28, 2020 20:46
@nikic
Copy link
Member

nikic commented Jan 6, 2021

This probably also needs some adjustments inside opcache to not make use of "optional" return type information, for cases that are subject to inheritance.

@kocsismate
Copy link
Member Author

This probably also needs some adjustments inside opcache to not make use of "optional" return type information, for cases that are subject to inheritance.

Yeah, this was my assumption as well :) But I wanted to defer additional work until we decide what the preferable direction is to go.

@kocsismate kocsismate force-pushed the internal-method-return-type branch 2 times, most recently from 744b55c to 60af931 Compare March 5, 2021 23:00
@kocsismate
Copy link
Member Author

kocsismate commented Mar 5, 2021

The word "optional" in the code sounds very bad, so I want to change it to something meaningful... Would be "tentative" a more suitable term?

This probably also needs some adjustments inside opcache to not make use of "optional" return type information, for cases that are subject to inheritance.

How is it possible that no opcache/jit tests fail, even though I have not addressed the possible issues with return type information? UPDATE: because only ext/date method return types were updated.

@kocsismate kocsismate force-pushed the internal-method-return-type branch 7 times, most recently from 42989bb to 60ff17c Compare March 15, 2021 12:04
@kocsismate kocsismate force-pushed the internal-method-return-type branch 2 times, most recently from 99ee3a5 to 2f25f9d Compare April 19, 2021 23:19
@kocsismate
Copy link
Member Author

kocsismate commented May 8, 2021

In my recent push, I tried to tidy my commits up, so that hopefully they became easier to review. Besides, I also tried to cater to OPcache and JIT... I'm not really sure if I left out anything..

However, as far as normal behavior is concerned, the PR should be ready for review, since the implementation seems to be done. My only problem is that I'm sure there are some tentative return types which are not really compatible with each other, so they should be found - and possibly fixed or excluded via @no-generate-tentative-return-type - ASAP. I.e. FilesystemIterator::key() and DirectoryIterator::key() is not compatible as currently declared.

@kocsismate kocsismate added this to the PHP 8.1 milestone May 8, 2021
@kocsismate kocsismate force-pushed the internal-method-return-type branch from 70d6645 to 9892c35 Compare May 8, 2021 19:56
@kocsismate kocsismate force-pushed the internal-method-return-type branch from 9892c35 to 8438e51 Compare May 10, 2021 10:17
@nikic
Copy link
Member

nikic commented May 10, 2021

In terms of general approach, I don't like the fact that this is picking up types from phpdoc and using them as tentative return types automatically. This makes it hard to see the actual impact, and may be problematic for extensions (if they regenerate their stubs, they'll probably become PHP-8.1-only.)

I think the way this should work is that tentative return types are added as real return types, and the "tentativeness" is indicated through a @tentative-return-type tag or #[TentativeReturnType] attribute. This will allow us to at least see what is actually changing, and it's worth noting that return types will have to be transferred to the position of "real" return types for PHP 9 anyway, so we might as well do it now. This should also allow this change to be split into two parts: One that implements the actual technical change and adds the tentative types to some sample class that is sufficient for testing. And one that actually adds it on a large scale.

@kocsismate
Copy link
Member Author

kocsismate commented May 10, 2021

I understand your concerns, and I have to agree that your suggestion should be the way forward (even though I'll have quite a bit of extra work) :) That said, I'll separate this PR into two new ones.

@kocsismate
Copy link
Member Author

I'm closing this in favor of the new, separated PRs.

@kocsismate kocsismate closed this May 11, 2021
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.

4 participants