- ; rewrite_blocks comp txlim (extendBlockEnv rewritten id b) bs }
- Rewrite fg ->
- do { g <- lgraphOfGraph fg
- ; (txlim, a, g') <- solve_and_rewrite_b comp (txlim-1) g out
- ; markGraphRewritten
- ; let (t, g'') = G.splice_tail g' tail
- ; let rewritten' = plusUFM (G.gr_blocks g'') rewritten
- ; my_trace "Rewrote label " (f4sep [ppr id, text "to", ppr g]) $
- propagate txlim h a t rewritten' }
- in rewrite_next_block txlim
+ ; rewrite_blocks comp fuel (extendBlockEnv rewritten id b) bs }
+ Rewrite g ->
+ do { markGraphRewritten
+ ; (fuel, a, g') <- solve_and_rewrite_b_graph comp (fuel-1) g out
+ ; let G.Graph t newblocks = G.splice_tail g' tail
+ ; my_trace "Rewrote label " (f4sep [ppr id,text "to",pprGraph g])$
+ propagate fuel h a t (newblocks `plusUFM` rewritten) }
+ in rewrite_next_block fuel
+
+{- Note [Rewriting labelled LGraphs]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+It's hugely annoying that we get in an LGraph and in order to solve it
+we have to slap on a new label which we then immediately strip off.
+But the alternative is to have all the iterative solvers work on
+Graphs, and then suddenly instead of a single case (ZBlock) every
+solver has to deal with two cases (ZBlock and ZTail). So until
+somebody comes along who is smart enough to do this and still leave
+the code understandable for mortals, it stays as it is.
+
+(One part of the solution will be postorder_dfs_from_except.)
+-}
+
+solve_and_rewrite_b_graph comp fuel graph exit_fact =
+ do g <- lgraphOfGraph graph
+ (fuel, a, g') <- solve_and_rewrite_b comp fuel g exit_fact
+ return (fuel, a, remove_entry_label g')