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

[DI] Fix support for multiple tags for locators and iterators #35342

Merged
merged 1 commit into from Feb 4, 2020
Merged

[DI] Fix support for multiple tags for locators and iterators #35342

merged 1 commit into from Feb 4, 2020

Conversation

alex-dev
Copy link
Contributor

Q A
Branch? 4.3
Bug fix? no
New feature? no
Deprecations? no
Tickets Fix #34462, Fix #35326
License MIT
Doc PR none

Fix PriorityTaggedServiceTrait::findAndSortTaggedServices to work with multiple explicitely tagged services as would be expected by !tagged_locator. Also reorganize PriorityTaggedServiceTrait::findAndSortTaggedServices to be simpler and easier to understand.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Hello, thank you for working on this!
I didn't review the logic in details but I think there are some flaws in the current patch that need to be addressed:

  • the diff in the PR contains unneeded changes - eg variable declaration reordering. As any unneeded diff is a potential merge conflict when we'll merge changes from 3.4/4.3, we try to avoid them as much as possible.
  • because the patch is so big, reviewing is extremely difficult. A PR should do one and only one change. Here, there are two of them: refacto + bug fix. This increases the risk of introducing bugs and the risk of missing the regressions during the review. I'd kindly ask you to rewrite your patch to stick to fixing the logic only.
  • Technically, I found a regression and stopped there my review: $container->getReflectionClass() is now always called inside the foreach loop. The previous logic avoided doing so on purpose when not needed. This behavior should be kept.

Thanks again, I'm looking forward to the next iteration :)

Copy link
Contributor Author

@alex-dev alex-dev left a comment

Choose a reason for hiding this comment

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

  • Technically, I found a regression and stopped there my review: $container->getReflectionClass() is now always called inside the foreach loop. The previous logic avoided doing so on purpose when not needed. This behavior should be kept.

Why should it? It is during container compilation, not a critical path. And the code end up being much easier to follow. Rather than being a mess, everything related to default happens before tag processing, which then becomes repeatable easily.

I'm gonna work a slimmer changeset, but the logic is so tied around the declarations I fear it would complicate the flow even more. Would it be better to split the refacto in a PR to merge and review before this one?

@nicolas-grekas
Copy link
Member

It is during container compilation, not a critical path

Actually, it is: the developer experience is directly affected by the compilation time, and making it faster improves the DX. That's why we strive to have the most performant code here also.

@nicolas-grekas nicolas-grekas added this to the 4.4 milestone Jan 20, 2020
@alex-dev
Copy link
Contributor Author

Actually, it is: the developer experience is directly affected by the compilation time, and making it faster improves the DX. That's why we strive to have the most performant code here also.

The only applicable ways I know to delay computation are:

  1. Proxy the computation in a callable or an object;
  2. Too many if statements to handle the branching;

Simplest way is likely to be an anonymous class.
It is likely to become a bigger merge nightmare than the previous refactorisation.

@alex-dev
Copy link
Contributor Author

Restarting from nothing; Only the tests are left.

@alex-dev
Copy link
Contributor Author

array_key_last... Should I force symfony/dependency-injection to depend of symfony/polyfill-php73 or implement an internal polyfill?

@nicolas-grekas
Copy link
Member

use end($array); return key($array);

@nicolas-grekas nicolas-grekas changed the title [DependencyInjection] Support multiple keys [DI] Fix support for multiple tags for locators and iterators Feb 4, 2020
@nicolas-grekas
Copy link
Member

Thank you @alex-dev.

nicolas-grekas added a commit that referenced this pull request Feb 4, 2020
…ors (Alexandre Parent)

This PR was merged into the 4.4 branch.

Discussion
----------

[DI] Fix support for multiple tags for locators and iterators

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34462, Fix #35326
| License       | MIT
| Doc PR        | none

Fix PriorityTaggedServiceTrait::findAndSortTaggedServices to work with multiple explicitely tagged services as would be expected by !tagged_locator. Also reorganize PriorityTaggedServiceTrait::findAndSortTaggedServices to be simpler and easier to understand.

Commits
-------

6fc91eb [DI] Fix support for multiple tags for locators and iterators
@nicolas-grekas nicolas-grekas merged commit 6fc91eb into symfony:4.4 Feb 4, 2020
This was referenced Feb 29, 2020
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.

None yet

3 participants