def all_descendants_of(root_node, ancestor):
  """Return a set of all descendants of `ancestor` in the graph `root_node`."""
  visited = set([ancestor])
  descendants = set([ancestor])
  def collect_descendants(node):
    if node not in visited:
      visited.add(node)
      if node is ancestor or any([collect_descendants(p) or p in descendants
                                  for p in node.parents]):
        descendants.add(node)
  collect_descendants(root_node)
  return frozenset(descendants)