CPR optimisation for sum types if only one constructor is used
|Reported by:||batterseapower||Owned by:||simonpj|
|Keywords:||Cc:||tkn.akio@…, danielv@…, nfrisby@…, mail@…|
|Type of failure:||None/Unknown||Difficulty:||Unknown|
|Test Case:||Blocked By:|
loop x = case x < 10 of True -> Left x; False -> loop (x*2)
We can usefully transform to:
$wloop x = case (case x < 10 of True -> Left x; False -> loop (x*2)) of Left y -> (# y #) loop x = case loop x of (# y #) -> Left y
Attached patch implements this behaviour. Most of the complication in the new code occurs because adding a DataCon? field to the Demand data type means that we have to define a separate IfaceDemand? type for storage in interface files.
The patch validates but I haven't done any tests on nofib. I have confirmed that the new optimisation hits on some examples, though.