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

update property map #8000

Merged
merged 10 commits into from Jul 6, 2022
Merged

Conversation

discordier
Copy link
Contributor

This is an attempt at fixing #7983 by:

  1. adding a (at least more) correct doc parsing approach than in phan/phan.
  2. updating the property map with said parser.

Currently tests fail on my machine but I submit anyway to have a discussion base if this is the general correct direction.

@discordier
Copy link
Contributor Author

For the code style issue, shall I suppress the phpcs issue or change the function to a variable?

@discordier
Copy link
Contributor Author

discordier commented May 23, 2022

We should also decide how we want to handle "manual" classes which are currently dropped by this PR as there is no documentation.

'actualEncoding' => 'string',
'encoding' => 'string',
'version' => 'string',
'CommonMark\\Node' => [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the offset should be a lowercase string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall I also lowercase the property names?
They were so in the original file but I currently keep them as documented in the XML files.

Copy link
Collaborator

@orklah orklah May 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting:

$cased_key = strtolower($key);

Psalm does a strtolower by itself on every class name. It would be best to do it on generation instead of in execution (we could drop the whole loop then). There is no such requirement on property names (I'm also not sure they're case insensitive)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did both in latest commit.
The removal of the loop I left for a later commit/PR, as we have some more strtolower() calls over the code base where the property map is used.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using strtolower when using propertymap is expected, we'll retrieve all sort of case from user code that we need to normalize

@orklah
Copy link
Collaborator

orklah commented May 23, 2022

We should also decide how we want to handle "manual" classes

Yeah, this will cause issues. I'm fine with keeping an automatically generated file, but if we do, we should create a second one with manual additions.

shall I suppress the phpcs issue or change the function to a variable

I think you can suppress it. Bin files are pretty special in that regard

@AndrolGenhald
Copy link
Collaborator

we should create a second one with manual additions

And removals I think. For stuff overridden by stubs it would probably be less confusing if they were omitted from the PropertyMap instead of being unused.

@discordier
Copy link
Contributor Author

we should create a second one with manual additions

And removals I think. For stuff overridden by stubs it would probably be less confusing if they were omitted from the PropertyMap instead of being unused.

I am unsure how I should approach the removal file.
In the end, it should be a direct map between class with properties and stub, can you elaborate on your idea?

@orklah
Copy link
Collaborator

orklah commented May 24, 2022

removal could be as simple as having a key in the second file that match the first file but without any property. If we merge the two arrays, the second key will simply overwrite the first. Maybe not very self-explanatory...

@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented May 24, 2022

In the end, it should be a direct map between class with properties and stub, can you elaborate on your idea?

Stubs can support much more than the property map, and if a stub exists it seems like it might be confusing to future contributors for the property map to exist as well. See eg this stub for DOMNode that marks most properties as @readonly.

Also, I would like to get Psalm to not load extension classes unless the extension is required by the project. I'm not entirely sure how the property map works with that (I think maybe property map doesn't matter unless it's in callmap as well?), but I think it would be best if fully stubbed classes from PHP extensions didn't exist in the property map.

removal could be as simple as having a key in the second file that match the first file but without any property.

Haven't looked at the implementation, but maybe something like ["domnode" => null, "otherclasstoremove" => null, ...] with array_diff_key? I'm not sure if pointing a class to an empty array in the property map has any significance, but it's probably better if it's removed entirely. (Note that the DOMNode stub example is currently an unmerged PR, so don't actually remove it from the property map just yet...)

@discordier
Copy link
Contributor Author

Implemented the extraction of stub class names and skipping them when generating the propertymap.

Checking the tests, I found that the stubs do not define the properties at all.
Shall I add them in this PR?

I also found a little discrepancy for DOMElement::attributes
Old code is:

'attributes' => 'DOMNamedNodeMap<DOMAttr>',

While PHP Docs state (for parent class DOMNode): DOMNamedNodeMap|null.
Shall I add the attributes to both (DOMNode and DOMElement) in the stub? The first one nullable and the second not?

What do you think?

@AndrolGenhald
Copy link
Collaborator

Checking the tests, I found that the stubs do not define the properties at all.
Shall I add them in this PR?

I wouldn't bother, that should mostly be handled by #7641 whenever I get the time and motivation to finish it (hopefully soon).

I also found a little discrepancy for DOMElement::attributes

I went through most of these by hand pretty extensively for #7641, and my comment here suggests that it's intentional. You can look into it further to confirm if you'd like, iirc I actually checked php-src for those to make sure they couldn't be null.

@discordier
Copy link
Contributor Author

I wouldn't bother, that should mostly be handled by #7641 whenever I get the time and motivation to finish it (hopefully soon).

So how shall I'll fix the tests regarding the property maps?
Most of them get resolved when using the stubs from #7641.

However, one is remaining and seems fishy to me.

echo $a->name . " - " . $a->class;',

Where does the property name come from? The tested class does not declare it and does not extend any parent or use traits.
So the failure seems correct to me and therefore the test seems wrong.

I went through most of these by hand pretty extensively for #7641, and my comment here suggests that it's intentional. You can look into it further to confirm if you'd like, iirc I actually checked php-src for those to make sure they couldn't be null.

Looks good to me.

Can we make a roadmap on this?
IMO this now depends on #7641.
Can I help to speed that one up?
What is missing?

@orklah
Copy link
Collaborator

orklah commented May 30, 2022

The tested class does not declare it and does not extend any parent or use traits.

Documentation do mention it though: https://www.php.net/manual/en/class.reflectionmethod.php
It seems to come from https://www.php.net/manual/en/class.reflectionfunctionabstract.php

@discordier
Copy link
Contributor Author

The tested class does not declare it and does not extend any parent or use traits.

Documentation do mention it though: https://www.php.net/manual/en/class.reflectionmethod.php It seems to come from https://www.php.net/manual/en/class.reflectionfunctionabstract.php

You are right, it is missing in

class ReflectionMethod implements Reflector

In fact, the whole inheritance is also misisng in there, most only implement Reflector.

After updating the stub files locally, all went smooth.

So it seems we definitely need #7641 in here to make the tests pass.

@AndrolGenhald
Copy link
Collaborator

I'll find some time this week to go through that, I might end up splitting it up into separate PRs for each stub so more important ones can be merged sooner.

@discordier
Copy link
Contributor Author

I'll find some time this week to go through that, I might end up splitting it up into separate PRs for each stub so more important ones can be merged sooner.

No need to rush this, I'll be on vacation until June 13th from tomorrow on.
Feel free to adjust/merge/postpone this PR though.

@discordier
Copy link
Contributor Author

So, I am back from vacation.
How may I further assist on this one?
Shall we incorporate #7641 into this one or rather split that one up?

@AndrolGenhald
Copy link
Collaborator

I've been a bit busy lately, give me a day or two and I'll pull that out into separate PRs that we can review and merge quickly (I hope).

@AndrolGenhald
Copy link
Collaborator

I haven't forgotten about this! I wasn't super clean about keeping the commits on that PR fully separate for the different stubs, so pulling it apart isn't as easy as I expected, I should be able to get the DOM one in a separate PR today or tomorrow though.

@AndrolGenhald
Copy link
Collaborator

Opened #8140.

@discordier
Copy link
Contributor Author

Shall I rebase on #8140 or do we want to merge that one?

@AndrolGenhald
Copy link
Collaborator

@orklah I didn't notice this was actually targeting 4.x, do you think I should backport #8140 to 4.x or should this be changed to target master?

@orklah
Copy link
Collaborator

orklah commented Jun 23, 2022

It would probably be easier to target this one on master I think

@discordier discordier changed the base branch from 4.x to master June 29, 2022 07:13
@discordier
Copy link
Contributor Author

I have updated the target branch and rebased onto current master.

We need a defined, reproducible starting point.
This should fix the now failing tests as the properties got removed from
the autogenerated property map.
We now have the extensions in a sub directory and therefore have to skip
that one.
@discordier
Copy link
Contributor Author

Do I have to rebase against current master again?
What else should I cram into this PR?

@orklah is this ready from your POV?

@orklah orklah added the release:internal The PR will be included in 'Internal changes' section of the release notes label Jul 4, 2022
@orklah
Copy link
Collaborator

orklah commented Jul 4, 2022

There is still an error in CI that should be adressed before I can merge this

@discordier
Copy link
Contributor Author

Ok, I fixed the shepherd run, there was an issue in code I did not touch.
I suppose this means the updated property map is used and works correctly. :)

I have no idea how to fix the "label" run - I suppose this needs to re run to spit out any information as you just added the label.

@orklah orklah merged commit 6d45003 into vimeo:master Jul 6, 2022
@orklah
Copy link
Collaborator

orklah commented Jul 6, 2022

Thanks!

@discordier discordier deleted the hotfix/update-property-map branch July 7, 2022 09:59
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

3 participants