Andreas Klebinger pushed to branch wip/apk/expose-overloaded-unfoldings at Glasgow Haskell Compiler / GHC
Commits:
-
1077867a
by Andreas Klebinger at 2026-09-30T16:05:13+00:00
6 changed files:
- + changelog.d/T13090-expose-overloaded-unfoldings
- compiler/GHC/Driver/DynFlags.hs
- compiler/GHC/Driver/Flags.hs
- compiler/GHC/Iface/Tidy.hs
- docs/users_guide/using-optimisation.rst
- testsuite/tests/dmdanal/should_compile/T23398.stderr
Changes:
| 1 | +section: compiler
|
|
| 2 | +issues: #13090
|
|
| 3 | +mrs: !16684
|
|
| 4 | +synopsis:
|
|
| 5 | + Enable :ghc-flag:`-fexpose-overloaded-unfoldings` by default with :ghc-flag:`-O` or higher.
|
|
| 6 | + |
| ... | ... | @@ -1337,6 +1337,7 @@ optLevelFlags -- see Note [Documenting optimisation flags] |
| 1337 | 1337 | , ([1,2], Opt_Specialise)
|
| 1338 | 1338 | , ([1,2], Opt_PolymorphicSpecialisation) -- Now on by default (#23559)
|
| 1339 | 1339 | , ([1,2], Opt_CrossModuleSpecialise)
|
| 1340 | + , ([1,2], Opt_ExposeOverloadedUnfoldings) -- See Note [Exposing overloaded functions] in GHC.Iface.Tidy
|
|
| 1340 | 1341 | , ([1,2], Opt_InlineGenerics)
|
| 1341 | 1342 | , ([1,2], Opt_Strictness)
|
| 1342 | 1343 | , ([1,2], Opt_UnboxSmallStrictFields)
|
| ... | ... | @@ -971,6 +971,8 @@ optimisationFlags = EnumSet.fromList |
| 971 | 971 | , Opt_SolveConstantDicts
|
| 972 | 972 | , Opt_SpecEval
|
| 973 | 973 | , Opt_SpecEvalDictFun
|
| 974 | + , Opt_ExposeAllUnfoldings
|
|
| 975 | + , Opt_ExposeOverloadedUnfoldings
|
|
| 974 | 976 | ]
|
| 975 | 977 | |
| 976 | 978 | -- | The set of flags which affect code generation and can change a program's
|
| ... | ... | @@ -1001,8 +1003,6 @@ codeGenFlags = EnumSet.fromList |
| 1001 | 1003 | , Opt_OmitYields
|
| 1002 | 1004 | |
| 1003 | 1005 | -- Flags that affect generated code
|
| 1004 | - , Opt_ExposeAllUnfoldings
|
|
| 1005 | - , Opt_ExposeOverloadedUnfoldings
|
|
| 1006 | 1006 | , Opt_NoTypeableBinds
|
| 1007 | 1007 | , Opt_NoBuiltinRules
|
| 1008 | 1008 | , Opt_NoBignumRules
|
| ... | ... | @@ -806,8 +806,19 @@ anyway we allow for some false positives and simply expose all functions which |
| 806 | 806 | have a constraint. This means we might expose more unhelpful unfoldings. But
|
| 807 | 807 | it seems like the better choice.
|
| 808 | 808 | |
| 809 | -Currently this option is off by default and has to be enabled manually. But
|
|
| 810 | -we might change this in the future.
|
|
| 809 | +We enable the flag by default with -O/O2 to allow users to opt into specialization
|
|
| 810 | +at call sites. We do not enable -fspecialize-aggressively. See also #13090.
|
|
| 811 | + |
|
| 812 | +In terms of performance impact the cost is very modest:
|
|
| 813 | +On GHC and it's boot libraries overall enabling this flag increases overall disk
|
|
| 814 | +space used by ~1%. With a highly variant distribution across various .hi files.
|
|
| 815 | +In terms of compile times the overhead is low enough to be hard to measure, but
|
|
| 816 | +seemed to be less than 0.2% if anything at all.
|
|
| 817 | + |
|
| 818 | +It seems tempting to do the same for -fspecialize-aggressively, but that comes in
|
|
| 819 | +at a hefty 20% compile time overhead. So we only provide the unfoldings and leave
|
|
| 820 | +the choice of how much specialization to enable up to the user.
|
|
| 821 | + |
|
| 811 | 822 | -}
|
| 812 | 823 | |
| 813 | 824 | {-
|
| ... | ... | @@ -624,10 +624,10 @@ as such you shouldn't need to set any of them explicitly. A flag |
| 624 | 624 | :reverse: -fno-expose-overloaded-unfoldings
|
| 625 | 625 | :category:
|
| 626 | 626 | |
| 627 | - :default: off
|
|
| 627 | + :default: -O and above
|
|
| 628 | 628 | :since: 9.12.1
|
| 629 | 629 | |
| 630 | - This experimental flag is a slightly less heavy weight alternative
|
|
| 630 | + This flag is a slightly less heavy weight alternative
|
|
| 631 | 631 | to :ghc-flag:`-fexpose-all-unfoldings`.
|
| 632 | 632 | |
| 633 | 633 | Instead of exposing all functions it exposes only those functions which
|
| ... | ... | @@ -40,7 +40,9 @@ T23398.$wbar [InlPrag=[2], Occ=LoopBreaker] |
| 40 | 40 | [GblId[StrictWorker([~, !])],
|
| 41 | 41 | Arity=4,
|
| 42 | 42 | Str=<L><SP(A,SC(S,L),A)><1L><L>,
|
| 43 | - Unf=OtherCon []]
|
|
| 43 | + Unf=Unf{Src=<vanilla>, TopLvl=True,
|
|
| 44 | + Value=True, ConLike=True, WorkFree=True, Expandable=True,
|
|
| 45 | + Guidance=IF_ARGS [0 90 60 0] 91 70}]
|
|
| 44 | 46 | T23398.$wbar
|
| 45 | 47 | = \ (@a)
|
| 46 | 48 | (@b)
|