A higher-level topological sort.