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

Leverage LazyProxyTrait in LazySchemaDiffProvider #1273

Merged
merged 1 commit into from
Dec 9, 2022

Conversation

nicolas-grekas
Copy link
Member

Q A
Type improvement
BC Break no (LazySchemaDiffProvider is internal)
Fixed issues -

This PR proposes to leverage the new LazyProxyTrait that's going to be shipped with Symfony 6.2 to implement lazy schemas as required by LazySchemaDiffProvider. (See https://symfony.com/blog/revisiting-lazy-loading-proxies-in-php for an introduction to this trait.)

This would require bumping the minimum PHP version to 8.1 in the next minor version.
The main benefit is simplicity. As you can read in the patch, using this trait requires no proxy generation infrastructure, and no calls to eval() either. The other benefit is simplifying dependency management.

@nicolas-grekas nicolas-grekas force-pushed the lazy-var-exporter branch 3 times, most recently from 12bc44d to 4d6fe1b Compare September 15, 2022 09:55
@nicolas-grekas
Copy link
Member Author

phpstan report is only about false positives:

Property Doctrine\Migrations\Provider\LazySchema::$lazyObject* is unused

Yes it is: by the trait.
(And no, the trait cannot declare those properties because their type/modifiers can vary in classes using it.)

Result of && is always true.

No it's not: undefined properties are not in objects cast to arrays.

@derrabus
Copy link
Member

Add those errors to the ignoreErrors section in phpstan.neon.dist with a comment explaining why you want to ignore them. If you consider the errors PHPStan bugs and want to go the extra mile, report them to PHPStan and add a link to your issue as a comment to phpstan.neon.dist.

@nicolas-grekas nicolas-grekas force-pushed the lazy-var-exporter branch 3 times, most recently from dbbe0fa to 2b6b124 Compare September 15, 2022 10:13
@stof
Copy link
Member

stof commented Sep 15, 2022

Merging this is blocked on the stable release of Symfony 6.2 though

@nicolas-grekas nicolas-grekas force-pushed the lazy-var-exporter branch 2 times, most recently from e6c96fa to 4041c76 Compare September 15, 2022 10:17
@stof
Copy link
Member

stof commented Sep 15, 2022

Looking at https://packagist.org/packages/doctrine/migrations/php-stats#3, PHP 8.1 only represents 45% of the installations for doctrine/migrations 3.x. The bump might be too early (the wait for the stable release of Symfony 6.2 gives us 2.5 months before re-evaluating that ratio anyway)

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Sep 15, 2022

phpstan green, thanks for the hint @derrabus
The remaining failures were already there so 🤷

@stof indeed, but Symfony 6.2 is pretty close (end of November) so we can start considering this now. v3.5 will still be usable for ppl on php < 8.1. The bump is worth it IMHO.

@derrabus
Copy link
Member

My attempt at getting the CI green: #1274

@nicolas-grekas nicolas-grekas force-pushed the lazy-var-exporter branch 3 times, most recently from a55f734 to eb91ae8 Compare September 15, 2022 15:32
@stof
Copy link
Member

stof commented Sep 15, 2022

Property Doctrine\Migrations\Provider\LazySchema::$lazyObject* is unused

Yes it is: by the trait. (And no, the trait cannot declare those properties because their type/modifiers can vary in classes using it.)

@nicolas-grekas This is true for lazyObjectReal. But AFAICT, lazyObjectId is always an int. So couldn't we declare it in the trait ?

@nicolas-grekas
Copy link
Member Author

lazyObjectId is always an int. So couldn't we declare it in the trait ?

I could not add it because it would make the trait incompatible with readonly classes (there's a test case about that in the component)

@stof
Copy link
Member

stof commented Sep 16, 2022

I could not add it because it would make the trait incompatible with readonly classes (there's a test case about that in the component)

if the trait supports making the property readonly, maybe it should always have it readonly ? Non-readonly classes can have readonly properties.

@nicolas-grekas
Copy link
Member Author

Making lazyObjectId readonly breaks cloning... I opened a discussion on php-internals about this and almost nobody dared to care for now... I hope this could be resolved soon...

@derrabus
Copy link
Member

Can you please rebase? The CI on 3.6.x should be green now.

@nicolas-grekas nicolas-grekas force-pushed the lazy-var-exporter branch 6 times, most recently from 5e64e5e to adba576 Compare September 18, 2022 21:02
@nicolas-grekas
Copy link
Member Author

Rebased. I don't reproduce the deps=low failure locally, I need to understand why it happens. I thought it might be because of composer/composer#11068 but apparently not.

@nicolas-grekas nicolas-grekas force-pushed the lazy-var-exporter branch 2 times, most recently from ee3a2d3 to f42a06a Compare September 19, 2022 06:20
@nicolas-grekas
Copy link
Member Author

I figured out the issue, all green.

composer.json Outdated Show resolved Hide resolved
$this->originalSchemaManipulator = $originalSchemaManipulator;
}

public static function fromDefaultProxyFactoryConfiguration(
Copy link
Member

Choose a reason for hiding this comment

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

this method should probably be deprecated instead of being removed

Copy link
Member Author

Choose a reason for hiding this comment

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

the class is marked @internal so I didn't bother doing that :)

Copy link
Member

Choose a reason for hiding this comment

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

ah indeed. I missed that

@nicolas-grekas
Copy link
Member Author

Ready for merge!
(failures are unrelated IIUC)

🚀

@greg0ire greg0ire closed this Dec 8, 2022
@greg0ire greg0ire reopened this Dec 8, 2022
@greg0ire
Copy link
Member

greg0ire commented Dec 8, 2022

Just did a merge-up, it should fix the SA job (the BC check will still be broken).

Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

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

A lot less code :)

@derrabus derrabus merged commit 7fa9d14 into doctrine:3.6.x Dec 9, 2022
@greg0ire greg0ire added this to the 3.6.0 milestone Dec 9, 2022
@nicolas-grekas nicolas-grekas deleted the lazy-var-exporter branch December 13, 2022 08:04
@bobvandevijver
Copy link
Contributor

@nicolas-grekas I'm just seeing this update, but due to the requirement on symfony/var-exporter on ^6.2 combined with the flex functionality to limit the Symfony packages to 5.4.* (symfony.require in the composer file), the latest release isn't installable. Would that be an oversight or was it intentional to require SF 6.2?

@stof
Copy link
Member

stof commented Feb 23, 2023

older versions of var-exporter don't have that LazyProxyTrait

@nicolas-grekas
Copy link
Member Author

Thanks for the report. This should now be fixed. I did so by reporting that var-exporter didn't existing before 6.2, see
symfony-tools/recipes-checker@a50caac

This should allow installing var-exporter at v6.2 while the rest is at 5.4.
This is also important to help Doctrine ORM adopt lazy-proxies faster.
/cc @derrabus since we talked about this issue recently.

@derrabus
Copy link
Member

Thank you! That should help indeed.

@bobvandevijver
Copy link
Contributor

This fixed it indeed, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants