Andreas Klebinger pushed to branch wip/andreask/deep-discounts-2026 at Glasgow Haskell Compiler / GHC Commits: 957eb82e by Andreas Klebinger at 2026-07-18T16:53:53+00:00 Respect unfolding depth when creating unfoldings - - - - - 651770ba by Andreas Klebinger at 2026-07-19T06:47:05+00:00 Clarify comment. - - - - - 58f3327a by Andreas Klebinger at 2026-07-19T07:12:30+00:00 Short circuit for non-conlike vars - - - - - 2 changed files: - compiler/GHC/Core/Opt/Simplify/Inline.hs - compiler/GHC/Core/Unfold.hs Changes: ===================================== compiler/GHC/Core/Opt/Simplify/Inline.hs ===================================== @@ -923,12 +923,11 @@ interestingArg env e = ConArg con fn_args | isClassTyCon (dataConTyCon con) -> ValueArg | otherwise -> - -- fn_args can be non-empty if the head of the application is - -- a variable whose unfolding is a partially applied constructor - -- application (see the first clause of go_var). In that case the - -- args from the unfolding come before the args of this - -- application, e.g. for `v ys` with `v = (:) x` we get - -- ConArg (:) [x_summary, ys_summary]. + -- fn_args are the arguments already applied inside `fn` + -- in case `fn` is a variable representing a partial application. + -- For example if we have `v xs` with `v` unfolding into `(: x)`. + -- In that case we will get: + -- ConArg (:) [x_summary, xs_summary]. ConArg con (fn_args ++ arg_summaries) _ -> fn_summary @@ -947,7 +946,9 @@ interestingArg env e = env' = env `addNewInScopeBndr` b go_var depth n v - | Just rhs <- maybeUnfoldingTemplate (idUnfolding v) + | unf <- (idUnfolding v) + , isConLikeUnfolding unf + , Just rhs <- maybeUnfoldingTemplate unf , Just con_app <- isConApp_maybe rhs = con_app ===================================== compiler/GHC/Core/Unfold.hs ===================================== @@ -693,7 +693,7 @@ sizeExpr opts !bOMB_OUT_SIZE top_args' expr | Just v <- is_top_arg e = let -- Compute size of alternatives - alt_sizes = map (size_up_alt depth (Just v) arg_comps) alts + alt_sizes = map (size_up_alt (depth-1) (Just v) arg_comps) alts -- Apply a discount for a given constructor that brings the size down to just -- the size of the alternative. @@ -747,7 +747,7 @@ sizeExpr opts !bOMB_OUT_SIZE top_args' expr size_up !depth arg_comps (Case e _ _ alts) = size_up depth arg_comps e `addSizeNSD` - foldr (addAltSize . (size_up_alt depth Nothing arg_comps) ) case_size alts + foldr (addAltSize . (size_up_alt (depth-1) Nothing arg_comps) ) case_size alts where case_size | is_inline_scrut e, lengthAtMost alts 1 = sizeN (-10) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/551b9ccadbd91155770a8aa940b5092... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/551b9ccadbd91155770a8aa940b5092... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help