- dest_vertices src_mentions = [ target_vertex
- | ((names_defined, _, _, _), target_vertex) <- flat_info,
- mentioned_name <- src_mentions,
- mentioned_name `elemNameSet` names_defined
- ]
+ dest_vertices uses = [ target_vertex
+ | ((defs, _, _, _), target_vertex) <- tagged_nodes,
+ defs `intersectsNameSet` uses
+ ]
+
+reconstructCycle :: SCC FlatMonoBinds -> (RenamedHsBinds, Uses)
+reconstructCycle (AcyclicSCC (defs, uses, binds, sigs))
+ = (MonoBind binds sigs NonRecursive, uses)
+reconstructCycle (CyclicSCC cycle)
+ = (MonoBind this_gp_binds this_gp_sigs Recursive,
+ unionManyNameSets uses_s `minusNameSet` unionManyNameSets defs_s)
+ -- The uses of the cycle are the things used in any RHS
+ -- minus the binders of the group. Knocking them out
+ -- right here improves the error reporting for usused
+ -- bindings; e.g. f x = f x -- Otherwise unused
+ where
+ (defs_s, uses_s, binds_s, sigs_s) = unzip4 cycle
+ this_gp_binds = foldr1 AndMonoBinds binds_s
+ this_gp_sigs = foldr1 (++) sigs_s