Where is Twig service defined? In twig_render_template(), I see this drupal_container()-&gt;get('twig')-&gt;loadTemplate($template_file)-&gt;render($variables). But I can not see where the twig service is defined.
The class that registers the Twig service is CoreServiceProvider which, in CoreServiceProvider::register() (the method that every service provider needs to implement), uses the following code.

  // The 'request' scope and service enable services to depend on the Request
  // object and get reconstructed when the request object changes (e.g.,
  // during a subrequest).
  $container-&gt;addScope(new Scope('request'));
  $this-&gt;registerTwig($container);
  $this-&gt;registerModuleHandler($container);


The class used for the Twig service is not the Twig_Environment class that Symfony implements, but a subclass of it (TwigEnvironment) implemented by Drupal.

The other registered service is twig.loader.filesystem, which uses the Symfony's Twig_Loader_Filesystem class.