Ben Gamari pushed to branch wip/backports-9.14 at Glasgow Haskell Compiler / GHC
Commits:
c7bd98fa by Ben Gamari at 2025-08-18T15:17:53-04:00
compiler: Enable polymorphic-specialisation
Fixes #23559, by re-enabling polymorphic specialisation by default as
the remaining hazards to soundness have been addressed by #23109.
Metric Increase:
info_table_map_perf
(cherry picked from commit bbe5bb7682c2dbbfc89ad9031c77bb4a1845451a)
- - - - -
f957d52f by Ben Gamari at 2025-08-18T15:17:53-04:00
users-guide: Release notes formatting wibbles
- - - - -
5 changed files:
- compiler/GHC/Driver/DynFlags.hs
- compiler/GHC/Driver/Flags.hs
- docs/users_guide/9.14.1-notes.rst
- docs/users_guide/using-optimisation.rst
- testsuite/tests/simplCore/should_compile/T8331.stderr
Changes:
=====================================
compiler/GHC/Driver/DynFlags.hs
=====================================
@@ -1250,6 +1250,7 @@ optLevelFlags -- see Note [Documenting optimisation flags]
, ([1,2], Opt_CfgBlocklayout) -- Experimental
, ([1,2], Opt_Specialise)
+ , ([1,2], Opt_PolymorphicSpecialisation)
, ([1,2], Opt_CrossModuleSpecialise)
, ([1,2], Opt_InlineGenerics)
, ([1,2], Opt_Strictness)
=====================================
compiler/GHC/Driver/Flags.hs
=====================================
@@ -907,6 +907,7 @@ optimisationFlags = EnumSet.fromList
, Opt_SpecialiseAggressively
, Opt_CrossModuleSpecialise
, Opt_StaticArgumentTransformation
+ , Opt_PolymorphicSpecialisation
, Opt_CSE
, Opt_StgCSE
, Opt_StgLiftLams
=====================================
docs/users_guide/9.14.1-notes.rst
=====================================
@@ -102,7 +102,9 @@ Language
Compiler
~~~~~~~~
-- An improved error message is introduced to refer users to the heap-controlling flags of the RTS when there is a heap overflow during compilation. (#25198)
+- Polymorphic specialisation has been reenabled by default in optimisation levels 1 and higher (:ghc-ticket:`23559`)
+
+- An improved error message is introduced to refer users to the heap-controlling flags of the RTS when there is a heap overflow during compilation. (:ghc-ticket:`25198`)
- The kind checker now does a better job of finding type family instances for
use in the kinds of other declarations in the same module. This fixes a number
@@ -116,14 +118,14 @@ Compiler
subordinate import lists (:ghc-ticket:`22581`).
- A new flag, :ghc-flag:`-Wuseless-specialisations`, controls warnings emitted when GHC
- determines that a SPECIALISE pragma would have no effect.
+ determines that a ``SPECIALISE`` pragma would have no effect.
-- A new flag, :ghc-flag:`-Wrule-lhs-equalities`, controls warnings emitted for RULES
+- A new flag, :ghc-flag:`-Wrule-lhs-equalities`, controls warnings emitted for ``RULES``
whose left-hand side attempts to quantify over equality constraints that
previous GHC versions accepted quantifying over. GHC will now drop such RULES,
emitting a warning message controlled by this flag.
- This warning is intended to give visibility to the fact that the RULES that
+ This warning is intended to give visibility to the fact that the ``RULES`` that
previous GHC versions generated in such circumstances could never fire.
- A new flag, :ghc-flag:`-Wunusable-unpack-pragmas`, controls warnings emitted
=====================================
docs/users_guide/using-optimisation.rst
=====================================
@@ -1316,10 +1316,7 @@ as such you shouldn't need to set any of them explicitly. A flag
:reverse: -fno-polymorphic-specialisation
:category:
- :default: off
-
- Warning, this feature is highly experimental and may lead to incorrect runtime
- results. Use at your own risk (:ghc-ticket:`23469`, :ghc-ticket:`23109`, :ghc-ticket:`21229`, :ghc-ticket:`23445`).
+ :default: on
Enable specialisation of function calls to known dictionaries with free type variables.
The created specialisation will abstract over the type variables free in the dictionary.
=====================================
testsuite/tests/simplCore/should_compile/T8331.stderr
=====================================
@@ -1,5 +1,148 @@
==================== Tidy Core rules ====================
+"SPEC $c*> @(ST s) @_"
+ forall (@s) (@r) ($dApplicative :: Applicative (ST s)).
+ $fApplicativeReaderT_$c*> @(ST s) @r $dApplicative
+ = ($fApplicativeReaderT2 @s @r)
+ `cast` (forall (a :: <*>_N) (b :: <*>_N).
+ _R
+ %<'Many>_N ->_R _R
+ %<'Many>_N ->_R <r>_R %<'Many>_N ->_R Sym (N:ST <s>_N <b>_R)
+ ; Sym (N:ReaderT <*>_N <r>_R <ST s>_R <b>_N)
+ :: Coercible
+ (forall a b.
+ ReaderT r (ST s) a -> ReaderT r (ST s) b -> r -> STRep s b)
+ (forall a b.
+ ReaderT r (ST s) a -> ReaderT r (ST s) b -> ReaderT r (ST s) b))
+"SPEC $c<$ @(ST s) @_"
+ forall (@s) (@r) ($dFunctor :: Functor (ST s)).
+ $fFunctorReaderT_$c<$ @(ST s) @r $dFunctor
+ = ($fApplicativeReaderT6 @s @r)
+ `cast` (forall (a :: <*>_N) (b :: <*>_N).
+ <a>_R
+ %<'Many>_N ->_R _R
+ %<'Many>_N ->_R <r>_R %<'Many>_N ->_R Sym (N:ST <s>_N <a>_R)
+ ; Sym (N:ReaderT <*>_N <r>_R <ST s>_R <a>_N)
+ :: Coercible
+ (forall a b. a -> ReaderT r (ST s) b -> r -> STRep s a)
+ (forall a b. a -> ReaderT r (ST s) b -> ReaderT r (ST s) a))
+"SPEC $c<* @(ST s) @_"
+ forall (@s) (@r) ($dApplicative :: Applicative (ST s)).
+ $fApplicativeReaderT_$c<* @(ST s) @r $dApplicative
+ = ($fApplicativeReaderT1 @s @r)
+ `cast` (forall (a :: <*>_N) (b :: <*>_N).
+ _R
+ %<'Many>_N ->_R _R
+ %<'Many>_N ->_R <r>_R %<'Many>_N ->_R Sym (N:ST <s>_N <a>_R)
+ ; Sym (N:ReaderT <*>_N <r>_R <ST s>_R <a>_N)
+ :: Coercible
+ (forall a b.
+ ReaderT r (ST s) a -> ReaderT r (ST s) b -> r -> STRep s a)
+ (forall a b.
+ ReaderT r (ST s) a -> ReaderT r (ST s) b -> ReaderT r (ST s) a))
+"SPEC $c<*> @(ST s) @_"
+ forall (@s) (@r) ($dApplicative :: Applicative (ST s)).
+ $fApplicativeReaderT9 @(ST s) @r $dApplicative
+ = ($fApplicativeReaderT4 @s @r)
+ `cast` (forall (a :: <*>_N) (b :: <*>_N).
+ b)>_R
+ %<'Many>_N ->_R _R
+ %<'Many>_N ->_R <r>_R
+ %<'Many>_N ->_R Sym (N:ST <s>_N <b>_R)
+ :: Coercible
+ (forall a b.
+ ReaderT r (ST s) (a -> b) -> ReaderT r (ST s) a -> r -> STRep s b)
+ (forall a b.
+ ReaderT r (ST s) (a -> b) -> ReaderT r (ST s) a -> r -> ST s b))
+"SPEC $c>> @(ST s) @_"
+ forall (@s) (@r) ($dMonad :: Monad (ST s)).
+ $fMonadReaderT1 @(ST s) @r $dMonad
+ = $fMonadAbstractIOSTReaderT_$s$c>> @s @r
+"SPEC $c>>= @(ST s) @_"
+ forall (@s) (@r) ($dMonad :: Monad (ST s)).
+ $fMonadReaderT2 @(ST s) @r $dMonad
+ = ($fMonadAbstractIOSTReaderT2 @s @r)
+ `cast` (forall (a :: <*>_N) (b :: <*>_N).
+ _R
+ %<'Many>_N ->_R ReaderT r (ST s) b>_R
+ %<'Many>_N ->_R <r>_R
+ %<'Many>_N ->_R Sym (N:ST <s>_N <b>_R)
+ :: Coercible
+ (forall a b.
+ ReaderT r (ST s) a -> (a -> ReaderT r (ST s) b) -> r -> STRep s b)
+ (forall a b.
+ ReaderT r (ST s) a -> (a -> ReaderT r (ST s) b) -> r -> ST s b))
+"SPEC $cfmap @(ST s) @_"
+ forall (@s) (@r) ($dFunctor :: Functor (ST s)).
+ $fFunctorReaderT_$cfmap @(ST s) @r $dFunctor
+ = ($fApplicativeReaderT7 @s @r)
+ `cast` (forall (a :: <*>_N) (b :: <*>_N).
+ b>_R
+ %<'Many>_N ->_R _R
+ %<'Many>_N ->_R <r>_R %<'Many>_N ->_R Sym (N:ST <s>_N <b>_R)
+ ; Sym (N:ReaderT <*>_N <r>_R <ST s>_R <b>_N)
+ :: Coercible
+ (forall a b. (a -> b) -> ReaderT r (ST s) a -> r -> STRep s b)
+ (forall a b. (a -> b) -> ReaderT r (ST s) a -> ReaderT r (ST s) b))
+"SPEC $cliftA2 @(ST s) @_"
+ forall (@s) (@r) ($dApplicative :: Applicative (ST s)).
+ $fApplicativeReaderT_$cliftA2 @(ST s) @r $dApplicative
+ = ($fApplicativeReaderT3 @s @r)
+ `cast` (forall (a :: <*>_N) (b :: <*>_N) (c :: <*>_N).
+ b -> c>_R
+ %<'Many>_N ->_R _R
+ %<'Many>_N ->_R _R
+ %<'Many>_N ->_R <r>_R %<'Many>_N ->_R Sym (N:ST <s>_N <c>_R)
+ ; Sym (N:ReaderT <*>_N <r>_R <ST s>_R <c>_N)
+ :: Coercible
+ (forall a b c.
+ (a -> b -> c)
+ -> ReaderT r (ST s) a -> ReaderT r (ST s) b -> r -> STRep s c)
+ (forall a b c.
+ (a -> b -> c)
+ -> ReaderT r (ST s) a -> ReaderT r (ST s) b -> ReaderT r (ST s) c))
+"SPEC $cp1Applicative @(ST s) @_"
+ forall (@s) (@r) ($dApplicative :: Applicative (ST s)).
+ $fApplicativeReaderT_$cp1Applicative @(ST s) @r $dApplicative
+ = $fApplicativeReaderT_$s$fFunctorReaderT @s @r
+"SPEC $cp1Monad @(ST s) @_"
+ forall (@s) (@r) ($dMonad :: Monad (ST s)).
+ $fMonadReaderT_$cp1Monad @(ST s) @r $dMonad
+ = $fApplicativeReaderT_$s$fApplicativeReaderT @s @r
+"SPEC $cpure @(ST s) @_"
+ forall (@s) (@r) ($dApplicative :: Applicative (ST s)).
+ $fApplicativeReaderT_$cpure @(ST s) @r $dApplicative
+ = ($fApplicativeReaderT5 @s @r)
+ `cast` (forall (a :: <*>_N).
+ <a>_R
+ %<'Many>_N ->_R <r>_R %<'Many>_N ->_R Sym (N:ST <s>_N <a>_R)
+ ; Sym (N:ReaderT <*>_N <r>_R <ST s>_R <a>_N)
+ :: Coercible
+ (forall a. a -> r -> STRep s a)
+ (forall a. a -> ReaderT r (ST s) a))
+"SPEC $creturn @(ST s) @_"
+ forall (@s) (@r) ($dMonad :: Monad (ST s)).
+ $fMonadReaderT_$creturn @(ST s) @r $dMonad
+ = ($fApplicativeReaderT5 @s @r)
+ `cast` (forall (a :: <*>_N).
+ <a>_R
+ %<'Many>_N ->_R <r>_R %<'Many>_N ->_R Sym (N:ST <s>_N <a>_R)
+ ; Sym (N:ReaderT <*>_N <r>_R <ST s>_R <a>_N)
+ :: Coercible
+ (forall a. a -> r -> STRep s a)
+ (forall a. a -> ReaderT r (ST s) a))
+"SPEC $fApplicativeReaderT @(ST s) @_"
+ forall (@s) (@r) ($dApplicative :: Applicative (ST s)).
+ $fApplicativeReaderT @(ST s) @r $dApplicative
+ = $fApplicativeReaderT_$s$fApplicativeReaderT @s @r
+"SPEC $fFunctorReaderT @(ST s) @_"
+ forall (@s) (@r) ($dFunctor :: Functor (ST s)).
+ $fFunctorReaderT @(ST s) @r $dFunctor
+ = $fApplicativeReaderT_$s$fFunctorReaderT @s @r
+"SPEC $fMonadReaderT @(ST s) @_"
+ forall (@s) (@r) ($dMonad :: Monad (ST s)).
+ $fMonadReaderT @(ST s) @r $dMonad
+ = $fMonadAbstractIOSTReaderT_$s$fMonadReaderT @s @r
"USPEC useAbstractMonad @(ReaderT Int (ST s))"
forall (@s)
($dMonadAbstractIOST :: MonadAbstractIOST (ReaderT Int (ST s))).
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/4a8df35bf60e46affe13dbef3637a6ce55c7afc5...f957d52f50b16f7ed2246d315a2761f037917df4
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/4a8df35bf60e46affe13dbef3637a6ce55c7afc5...f957d52f50b16f7ed2246d315a2761f037917df4
You're receiving this email because of your account on gitlab.haskell.org.