How does Magento\Setup\Module\Di\Compiler\Config\ModificationChain::modify() work?

Context: How are the generated/medatata files generated in Magento 2.2?

Details: