Skip to content
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

tests: add test that validates the callmap in the current runtime #8104

Merged
merged 22 commits into from Jun 15, 2022
Merged

tests: add test that validates the callmap in the current runtime #8104

merged 22 commits into from Jun 15, 2022

Conversation

SamMousa
Copy link
Contributor

@SamMousa SamMousa commented Jun 13, 2022

Test for #8101

Reflection doesn't always work correctly for built-in functions, especially those defined by extensions. It's also going to be less specific than any psalm specific type like numeric-string, int<0, max>, class-string, etc. I can already see that many of those are false positives, so using a generated callmap is definitely not possible.

If you want to add that snippet to the bin directory and do a manual comparison to see which are actual problems though that would be great!

I'm aware that more specific return types are won't be validated by this tester; this is still a WIP.
The idea is that we can at least fail on things that are guaranteed to be wrong.

@SamMousa

This comment was marked as duplicate.

@SamMousa SamMousa mentioned this pull request Jun 13, 2022
3 tasks
@AndrolGenhald
Copy link
Collaborator

Might be worth trying to scrape the documentation like #8000 as well. If reflection and documentation disagree we can see whether we need to open a documentation issue or ignore reflection for that case.

@AndrolGenhald
Copy link
Collaborator

Looking good so far! A lot of these we'll have to look at the documentation or test to see if we need to add a change to one of the version diffs or if the callmap was always incorrect and the historical one needs changed.

@SamMousa
Copy link
Contributor Author

Yeah I'm liking it as well. Just an FYI regarding your comments on the change maps.
My time is limited and I prefer not to spend it on old PHP versions. Since the fixes fix what is currently broken in PHP8.1, to me this is already an improvement from what we have today (where it works on some older versions but definitely not on 8.1).

So I hope someone else is willing to do the manual fixes for the other version diffs. Note that this test code can also be run on PHP8 to identify issues with the callmap (which can then be fixed in the diff).

@orklah
Copy link
Collaborator

orklah commented Jun 14, 2022

Since the fixes fix what is currently broken in PHP8.1, to me this is already an improvement

It is. Unfortunately, the way callmap works is that changing callmap is not enough. Callmap.php should always match with another Callmap file in which the signature was introduced. So you're forced to either pick the correct version, or to change Callmap_historical (which will break signatures for old versions that didn't change)

@SamMousa
Copy link
Contributor Author

Unfortunately, the way callmap works is that changing callmap is not enough. Callmap.php should always match with another Callmap file in which the signature was introduced.

When running on the current version though, the historical file and diffs are not used. They are only used in downgrading the callmap (if i understand correctly). So this will work just fine on php 8.1 and fixing it to work on old version is something someone else will hopefully have motivation for.

Note that many (100+ of the fixes in the callmap) changes were already broken to begin with for older PHP versions, we just didn't know.

@SamMousa
Copy link
Contributor Author

Is there some internal psalm function that will tell me if 2 types are compatible? Currently I'm using my own poor man's parser, but im thinking it probably already exists somewhere else.

@orklah
Copy link
Collaborator

orklah commented Jun 14, 2022

You can use UnionTypeComparator::isContainedBy to check if an union is contained completely in another. Type;;parseString should give you an union from a string

@SamMousa
Copy link
Contributor Author

@orklah to get this ready for merged I've chosen the following approach:

  1. Revert most fixes to the callmap.
  2. Add lots if exclusions to the new test.

If you'd be so kind to add a release label then all tests will pass.

Currently this the test file has ~2355 tests (in my docker container that has all possible php extensions enabled), of which 1167 are skipped.
This means that we have verified that ~1180 functions in the callmap are correct.

Next steps are to incrementally remove functions and prefixes from the ignore list and fix their definitions in the callmap & diff files. This can be done by anyone looking for simple improvements.
Also we should add the procedure that anyone making a PR that changes the callmap removes the corresponding functions from the ignore list.

@SamMousa SamMousa marked this pull request as ready for review June 15, 2022 14:06
@orklah orklah added the release:internal The PR will be included in 'Internal changes' section of the release notes label Jun 15, 2022
@orklah
Copy link
Collaborator

orklah commented Jun 15, 2022

Cool! Could you open an issue explaining how to tackle a function so we can redirect contributors to it when needed?

@orklah orklah merged commit 9a64143 into vimeo:4.x Jun 15, 2022
@SamMousa SamMousa deleted the automated-callmap-validation branch June 16, 2022 10:53
@AndrolGenhald
Copy link
Collaborator

We should probably update the callmap guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:internal The PR will be included in 'Internal changes' section of the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants