private function sortDeps(Bag $toSort)
    {
        $sorted = [];
        $toSort = $toSort->mutable();

        while (count($toSort) > 0) {
            foreach ($toSort as $name => $dependencies) {
                if (!array_diff($dependencies->toArray(), $sorted)) {
                    $sorted[] = $name;
                    unset($toSort[$name]);
                }
            }
        }

        return new Bag($sorted);
    }