8000 Fixed CachePoolClearerPass fails if "cache.annotations" service is created by antanas-arvasevicius · Pull Request #21362 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fixed CachePoolClearerPass fails if "cache.annotations" service is created #21362

8000 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

Conversation

antanas-arvasevicius
Copy link
Contributor
@antanas-arvasevicius antanas-arvasevicius commented Jan 20, 2017
Q A
Branch? master / 3.2
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #21339
License MIT

Moved "cache.annotations" injenction logic from CachePoolClearerPass which was called after RemovePrivateAliasesPass into CacheAnnotationsMonologInjectorPass which is now called just before RemovePrivateAliasesPass so that we can track "cache.annotations" service definition propery.
Also using findDefinition() instead of getDefinition() as it can be an alias too.
And do not using has() as it searches not only definition, definition aliases but also in instantiated services too.

@xabbuh
Copy link
Member
xabbuh commented Jan 21, 2017

Can you also add a test that would fail without your changes?

@javiereguiluz javiereguiluz changed the title bug #21339 CachePoolClearerPass fails if "cache.annotations" service is created Fixed CachePoolClearerPass fails if "cache.annotations" service is created Jan 21, 2017
@antanas-arvasevicius antanas-arvasevicius force-pushed the cache-annotations-compiler-pass-fix branch 2 times, most recently from 2708b19 to fcd76ea Compare January 21, 2017 12:28
@antanas-arvasevicius
Copy link
Contributor Author
antanas-arvasevicius commented Jan 21, 2017

Hi, added functional test which fails in 3.2 branch and works with this PR.
Test simulates behavior written in #21339 ticket.
Short scenario:

  • compilation starts
  • AnnotationConfigurationPass, it uses "cache.annotations" service
  • CacheCollectorPass, it aliases "cache.annotations" and other tagged services (in debug mode it wraps around pools to collect debug info)
  • RemovePrivateAliasesPass , it removes all private aliases so after this step we cannot find "cache.annotations"
  • CachePoolClearerPass, throw error as it cannot find any info about "cache.annotations"
  • end of story

*/
public function process(ContainerBuilder $container)
{
if (!($container->hasDefinition('cache.annotations') || $container->hasAlias('cache.annotations'))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally I would write this inversed, saving some parenthesis and reads a lot easier:

if (!$container->hasDefinition('cache.annotations') && !$container->hasAlias('cache.annotations'))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it a preferred way in this project? From practice I can say that thinking in NOT (x OR y) is less confused than NOT x AND NOT y as first you could reason by simple positive predicate and then just negate it:
hasDefinitions := X OR Y; and negation would be: hasNotDefinition := NOT hasDefinition;

In second case it would be confusion as we immediately start thinking from negation hasNotDefinition := NOT x AND NOT y; and then positive would be: hasDefinition := NOT hasNotDefinition -> NOT (NOT x AND NOT y) (pretty complicated?) we need more transformations: (NOT NOT x) OR (NOT NOT y) -> x OR y;
Generally we use more positive logic in daily life than negative and it's easier to reason about.

Copy link
Member

Choose a reason for hiding this comment

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

Personally, I find it less confusing when an inversed condition is not a composed one. So I find @iltar's suggestion more readable.

Copy link
Contributor

Choose a reason for hiding this comment

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

The less parenthesis and OR present in a condition, the easier it is to understand. Especially in guard clauses you want it to be as specific as possible with AND:
if x AND y AND z; then return

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, changed to AND if it's better. But if it would be if x AND y then yes it's better, but now there is if NOT x AND NOT y and is more difficult to reason than if NOT (x OR y); In natural language the more negations is in the sentence the harder to know a real meaning. ( see http://www.grammar-monster.com/glossary/double_negative.htm )

@antanas-arvasevicius antanas-arvasevicius force-pushed the cache-annotations-compiler-pass-fix branch 3 times, most recently from 62c601e to 94acf45 Compare January 22, 2017 09:38
@antanas-arvasevicius antanas-arvasevicius force-pushed the cache-annotations-compiler-pass-fix branch from 94acf45 to cbae126 Compare January 22, 2017 10:28
@antanas-arvasevicius
Copy link
Contributor Author

Tests failed in not related bundle to this PR in TwigBundle.

@nicolas-grekas
Copy link
Member

Closed in favor of #21381, thanks @antanas-arvasevicius!

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.

5 participants
0