+argToPat in_scope con_env arg arg_occ
+ | is_value_lam arg
+ = return (True, arg)
+ where
+ is_value_lam (Lam v e) -- Spot a value lambda, even if
+ | isId v = True -- it is inside a type lambda
+ | otherwise = is_value_lam e
+ is_value_lam other = False
+
+argToPat in_scope con_env arg arg_occ
+ | Just (CV dc args) <- is_con_app_maybe con_env arg
+ , case arg_occ of
+ ScrutOcc _ -> True -- Used only by case scrutinee
+ BothOcc -> case arg of -- Used by case scrut
+ App {} -> True -- ...and elsewhere...
+ other -> False
+ other -> False -- No point; the arg is not decomposed
+ = do { args' <- argsToPats in_scope con_env (args `zip` subOccs arg_occ dc)
+ ; return (True, mk_con_app dc (map snd args')) }
+
+argToPat in_scope con_env arg arg_occ
+ = do { uniq <- getUniqueUs
+ ; let id = mkSysLocal FSLIT("sc") uniq (exprType arg)
+ ; return (False, Var id) }
+
+argsToPats :: InScopeEnv -> ConstrEnv
+ -> [(CoreArg, ArgOcc)]
+ -> UniqSM [(Bool, CoreArg)]
+argsToPats in_scope con_env args
+ = mapUs do_one args
+ where
+ do_one (arg,occ) = argToPat in_scope con_env arg occ