Mikolaj Konarski pushed to branch wip/T28016-inline-boring-work-free at Glasgow Haskell Compiler / GHC Commits: 06d164e6 by Mikolaj Konarski at 2026-10-26T22:11:40+01:00 Experiment: inline 0-ary bindings in boring contexts only if work-free Not for merging. tryUnfolding inlines an INLINE binding with no arguments in a boring context only if its template is work-free, so that no work is duplicated. The test is in tryUnfolding and not in mkInlineUnfoldingWithArity, because simplStableUnfolding only ever turns ug_boring_ok on, while a template can become work-free when it is simplified. This is for #28016, where an INLINE [1] constant inlined after the first float-out is computed at every call. Assisted-by: Claude Opus 5.5 - - - - - 1 changed file: - compiler/GHC/Core/Opt/Simplify/Inline.hs Changes: ===================================== compiler/GHC/Core/Opt/Simplify/Inline.hs ===================================== @@ -308,8 +308,11 @@ tryUnfolding env logger id lone_variable arg_infos UnfNever -> traceInline logger opts id str (text "UnfNever") Nothing UnfWhen { ug_arity = uf_arity, ug_unsat_ok = unsat_ok, ug_boring_ok = boring_ok } - | enough_args && (boring_ok || some_benefit || unfoldingVeryAggressive opts) + | enough_args && ((boring_ok && (uf_arity > 0 || is_wf)) + || some_benefit || unfoldingVeryAggressive opts) -- See Note [INLINE for small functions] (3) + -- EXPERIMENT (#28016): a binding with no arguments is + -- inlined in a boring context only if that duplicates no work. -> traceInline logger opts id str (mk_doc some_benefit empty True) (Just unf_template) | otherwise -> traceInline logger opts id str (mk_doc some_benefit empty False) Nothing View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/06d164e6ca54cb3079ea72f942b0b3fb... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/06d164e6ca54cb3079ea72f942b0b3fb... 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