I don't know if it's possible or better. But I think adding a tag in the compiler pass is strange.
Would it not be better to remove the definition of the service when the service cannot be used? Like
`$container->removeDefinition('twig.extension.routing')`?