- -- We add demand info for let(rec) binders, because
- -- that's what tells CorePrep to generate a case instead of a thunk
- add_dmd_info (env,new_id)
- | isStrictDmd dmd_info = (env, setIdNewDemandInfo new_id dmd_info)
- | otherwise = (env, new_id)
- dmd_info = idNewDemandInfo id
-
-tidyId :: TidyEnv -> Id -> (TidyEnv, Id)
-tidyId env@(tidy_env, var_env) id
+ ((tidy_env,var_env), new_id) = tidyIdBndr env id
+
+ -- We need to keep around any interesting strictness and demand info
+ -- because later on we may need to use it when converting to A-normal form.
+ -- eg.
+ -- f (g x), where f is strict in its argument, will be converted
+ -- into case (g x) of z -> f z by CorePrep, but only if f still
+ -- has its strictness info.
+ --
+ -- Similarly for the demand info - on a let binder, this tells
+ -- CorePrep to turn the let into a case.
+ final_id = new_id `setIdNewDemandInfo` idNewDemandInfo id
+ `setIdNewStrictness` idNewStrictness id
+
+ -- Override the env we get back from tidyId with the new IdInfo
+ -- so it gets propagated to the usage sites.
+ new_var_env = extendVarEnv var_env id final_id
+
+tidyIdBndr :: TidyEnv -> Id -> (TidyEnv, Id)
+tidyIdBndr env@(tidy_env, var_env) id