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] Shared services should not be inlined in non-shared ones #27265

Merged
merged 1 commit into from May 15, 2018

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented May 14, 2018

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

Already good on 2.7/2.8.

@nicolas-grekas nicolas-grekas merged commit 6f8b862 into symfony:3.4 May 15, 2018
nicolas-grekas added a commit that referenced this pull request May 15, 2018
…nes (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Shared services should not be inlined in non-shared ones

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

[Already good on 2.7/2.8.](https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php#L152)

Commits
-------

6f8b862 [DI] Shared services should not be inlined in non-shared ones
@nicolas-grekas nicolas-grekas deleted the di-no-inline branch May 15, 2018 08:57
This was referenced May 21, 2018
@@ -138,6 +138,6 @@ private function isInlineableDefinition($id, Definition $definition, ServiceRefe
return false;
}

return true;
return $this->container->getDefinition($ids[0])->isShared();
Copy link
Member

Choose a reason for hiding this comment

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

Look like this change break the compilation with Undefined offset: 0 when the node doesn't have any InEdges

Copy link
Member Author

Choose a reason for hiding this comment

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

hotfixed in 5eb17e5
but I don't understand how this can happen logically (we're here because we did find a reference to the service, to it must have at least one in-edge.)
could you share a reproduder?

Copy link
Member

Choose a reason for hiding this comment

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

The use case is: I use a custom TestKernel which inject mocks in the container and set the service as Synthetic with a compiler pass

NB: Changing the type of the compiler pass to PassConfig::TYPE_AFTER_REMOVING (to run after InlineServiceDefinitionsPass) fix the issue

This minimal reproduct case is:

class Kernel extends BaseKernel implements CompilerPassInterface
{
    // ...
    public function process(ContainerBuilder $container)
    {
        // routing.resolver is just an example for the minimal reproduct case here
        $container->getDefinition('routing.resolver')->setPublic(true)->setSynthetic(true);
    }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, so this means we are missing a check for synthetic service!
added in #27366

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

5 participants