25 Nov '26
Simon Peyton Jones pushed to branch wip/T28169 at Glasgow Haskell Compiler / GHC
Commits:
1daa8f40 by Simon Peyton Jones at 2026-11-25T12:39:53+00:00
I think this is done
Fixes #28183 too
Needs a commit message
- - - - -
21 changed files:
- compiler/GHC/Builtin/WiredIn/Types.hs
- compiler/GHC/Core/DataCon.hs
- compiler/GHC/Core/FamInstEnv.hs
- compiler/GHC/Core/Opt/DmdAnal.hs
- compiler/GHC/Core/Opt/Simplify/Iteration.hs
- compiler/GHC/Core/Opt/SpecConstr.hs
- compiler/GHC/Core/Opt/WorkWrap/Utils.hs
- compiler/GHC/Core/SimpleOpt.hs
- compiler/GHC/Core/TyCon.hs
- compiler/GHC/Core/Type.hs
- compiler/GHC/Core/Utils.hs
- compiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/Gen/Pat.hs
- compiler/GHC/Tc/TyCl.hs
- compiler/GHC/Tc/TyCl/Build.hs
- compiler/GHC/Tc/TyCl/Instance.hs
- compiler/GHC/Tc/TyCl/Utils.hs
- compiler/GHC/Types/Id/Make.hs
- compiler/GHC/Utils/Misc.hs
- + testsuite/tests/simplCore/should_compile/T28169.hs
- testsuite/tests/simplCore/should_compile/all.T
Changes:
=====================================
compiler/GHC/Builtin/WiredIn/Types.hs
=====================================
@@ -626,7 +626,7 @@ typeSymbolKindConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Symbol")
pcTyCon :: Name -> Maybe (CType GhcTc) -> [TyVar] -> [DataCon] -> TyCon
pcTyCon name cType tyvars cons
= mkAlgTyCon name (mkTyConKind bndrs res_kind) bndrs 0 res_kind
- (map (const Representational) tyvars)
+ (mapConst Representational tyvars)
cType
[] -- No stupid theta
(mkDataTyConRhs cons)
@@ -717,9 +717,10 @@ pcDataConWithFixity' declared_infix dc_name wrk_key rri
-- we call pcDataConWithFixity' with static TyCons in the same module.
-- See Note [Constructor tag allocation] and #14657
data_con = mkDataCon dc_name declared_infix prom_info
- (map (const no_bang) arg_tys)
- (map (const HsLazy) arg_tys)
- (map (const NotMarkedStrict) arg_tys)
+ (mapConst no_bang arg_tys)
+ (mapConst HsLazy arg_tys)
+ (mapConst NotMarkedStrict theta ++
+ mapConst NotMarkedStrict arg_tys)
[] -- No labelled fields
tyvars ex_tyvars
conc_tyvars
=====================================
compiler/GHC/Core/DataCon.hs
=====================================
@@ -44,7 +44,7 @@ module GHC.Core.DataCon (
dataConIsInfix,
dataConWorkId, dataConWrapId, dataConWrapId_maybe,
dataConImplicitTyThings,
- dataConRepStrictness,
+ dataConRepStrictness, dataConRepFullStrictness,
dataConImplBangs, dataConBoxer,
dataConRepIsLazy,
@@ -524,9 +524,9 @@ data DataCon
dcStricts :: [StrictnessMark],
-- One mark for every field of the DataCon /worker/
- -- Lines up 1-1 with dataConRepArgTys
+ -- INVARIANT: length dcStricts = length dataConRepArgTys
-- Relates only to user-specified strictness annotations,
- -- not to liftedness or othewrise
+ -- not to liftedness or otherwise
-- E.g. data T a = MkT {-# UNPACK #-} !(S a) Int# !a
-- data S a = MkS a !a
-- Then the worker for MkT has four fields, the first two arising from
@@ -535,6 +535,12 @@ data DataCon
-- See also Note [Strict fields in Core] in GHC.Core
-- for the effect on the strictness signature
+ dcFullStricts :: [StrictnessMark],
+ -- Just like dcStricts, but preceded by one NotMarkedStrict
+ -- for each CoVar in dcExTyCoVars
+ -- INVARIANT: length dcFullStricts = dataConRepArity
+ -- See (EXCO1) Note [Existential coercion variables]
+
dcFields :: [FieldLabel],
-- Field labels for this constructor, in the
-- same order as the dcOrigArgTys;
@@ -543,7 +549,7 @@ data DataCon
dcIsLazy :: Bool,
-- True if (a) all fields of the data con /worker/ are definitely lifted
-- (b) no field has a `StrictnessMark` that forces evaluation
- -- So if `dcIsLazy` is True then all fields of the worker are lazy thunks
+ -- So if `dcIsLazy` is True then all fields of the worker are lazy thunks
-- The curried worker function that corresponds to the constructor:
-- It doesn't have an unfolding; the code generator saturates these Ids
@@ -593,18 +599,29 @@ we can in Core. Consider having:
data T :: forall k. k -> k -> Constraint where
MkT :: forall k (a::k) (b::k).
- forall k' (c::k') (co::k'~k).
- (b ~# (c|>co)) => T k a b
+ forall k' (c::k') (co::k'~#k).
+ (b ~# (c|>co)) => !a -> T k a b
dcUnivTyVars = [k,a,b]
dcExTyCoVars = [k',c,co]
dcUserTyVarBinders = [k,a,k',c]
dcEqSpec = [b ~# (c|>co)]
dcOtherTheta = []
- dcOrigArgTys = []
+ dcOrigArgTys = [a]
dcRepTyCon = T
+ dcStricts = [MarkedStrict]
+ dcFullStricts = [NotMarkedStrict, MarkedStrict] -- (EXCO1)
+
+* `dataConKindEqSpec` returns [k'~k].
+* `dataConRepArgTys` returns [ b~#(c|>co), a ]
+
+(EXCO1) In a call of the data constructor worker we will see
+ MkT tk ta tb tk' tc (co1::tk'~#tk) (co2::tb~#(tc |> co1))
+ dcFullStricts returns a [StrictnessMark] that lines up with all the
+ value arguments, /including/ co1
-Function call 'dataConKindEqSpec' returns [k'~k]
+ dcFullStricts = dcStricts almost always; they differ only in the
+ rare case that we have existential coercion variables
Note [DataCon arities]
~~~~~~~~~~~~~~~~~~~~~~
@@ -864,7 +881,8 @@ type DataConEnv a = UniqFM DataCon a -- Keyed by DataCon
-- In the AST, the @SourceText@ is hidden inside the extension point
-- 'Language.Haskell.Syntax.Extension.XConDeclField'.
data HsSrcBang
- = HsSrcBang SourceText SrcUnpackedness SrcStrictness -- See Note [Pragma source text] in "GHC.Types.SourceText"
+ = HsSrcBang SourceText SrcUnpackedness SrcStrictness
+ -- See Note [Pragma source text] in "GHC.Types.SourceText"
deriving Data.Data
-- | Haskell Implementation Bang
@@ -872,14 +890,14 @@ data HsSrcBang
-- Bangs of data constructor arguments as generated by the compiler
-- after consulting HsSrcBang, flags, etc.
data HsImplBang
- = HsLazy -- ^ Lazy field, or one with an unlifted type
+ = HsLazy -- ^ Lazy field, or one with an unlifted type
+
| HsStrict Bool -- ^ Strict but not unpacked field
- -- True <=> we could have unpacked, but opted not to
- -- because of -O0.
- -- See Note [Detecting useless UNPACK pragmas]
- | HsUnpack (Maybe Coercion)
- -- ^ Strict and unpacked field
- -- co :: arg-ty ~ product-ty HsBang
+ -- True <=> we could have unpacked, but opted not to because of -O0
+ -- See Note [Detecting useless UNPACK pragmas]
+
+ | HsUnpack (Maybe Coercion) -- ^ Strict and unpacked field
+ -- co :: arg-ty ~ product-ty HsBang
deriving Data.Data
@@ -961,9 +979,8 @@ Terminology:
you the demand signature of the wrapper, if it exists.
These demand signatures are set in GHC.Types.Id.Make.mkDataConWorkId,
- computed from the single source of truth `dataConRepStrictness`, which is
- generated from `dcStricts`.
- Note that `dataConRepStrictness` lines up 1-1 with `idDmdSig (dataConWorkId dc)`.
+ computed from the single source of truth `dataConRepFullStrictness`.
+ So `dataConRepFullStrictness` lines up 1-1 with `idDmdSig (dataConWorkId dc)`.
Note [Detecting useless UNPACK pragmas]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1129,7 +1146,7 @@ mkDataCon name declared_infix prom_info
impl_bangs -- Must match orig_arg_tys 1-1
str_marks -- Must be empty or match dataConRepArgTys 1-1
fields
- univ_tvs ex_tvs conc_tvs user_tvbs
+ univ_tvs ex_tcvs conc_tvs user_tvbs
eq_spec theta
orig_arg_tys orig_res_ty rep_info rep_tycon tag
stupid_theta work_id rep
@@ -1143,7 +1160,7 @@ mkDataCon name declared_infix prom_info
= con
where
- is_vanilla = null ex_tvs && null eq_spec && null theta
+ is_vanilla = null ex_tcvs && null eq_spec && null theta
is_lazy = not (any isMarkedStrict str_marks)
&& all (definitelyLiftedType . scaledThing) rep_arg_tys
@@ -1154,7 +1171,7 @@ mkDataCon name declared_infix prom_info
, dcVanilla = is_vanilla
, dcUnivTyVars = univ_tvs
- , dcExTyCoVars = ex_tvs
+ , dcExTyCoVars = ex_tcvs
, dcConcreteTyVars = conc_tvs
, dcUserTyVarBinders = user_tvbs
, dcEqSpec = eq_spec
@@ -1171,18 +1188,20 @@ mkDataCon name declared_infix prom_info
, dcStricts = assertPpr (equalLength str_marks rep_arg_tys)
(ppr name <+> ppr str_marks)
str_marks
+ , dcFullStricts = replicate n_ex_co_vars NotMarkedStrict ++ str_marks
, dcIsLazy = is_lazy
, dcFields = fields
, dcWorkId = work_id
, dcSourceArity = length orig_arg_tys
- , dcRepArity = length rep_arg_tys + count isCoVar ex_tvs
+ , dcRepArity = n_ex_co_vars + length rep_arg_tys
, dcPromoted = promoted }
-- The 'arg_stricts' passed to mkDataCon are simply those for the
-- source-language arguments. We add extra ones for the
-- dictionary arguments right here.
- rep_arg_tys = dataConRepArgTys con
+ n_ex_co_vars = count isCoVar ex_tcvs
+ rep_arg_tys = dataConRepArgTys con
rep_ty = case rep of
-- If the DataCon has no wrapper, then the worker's type *is* the
@@ -1190,7 +1209,7 @@ mkDataCon name declared_infix prom_info
NoDataConRep -> dataConWrapperType con
-- If the DataCon has a wrapper, then the worker's type is never seen
-- by the user. The visibilities we pick do not matter here.
- DCR{} -> mkInfForAllTys univ_tvs $ mkTyCoInvForAllTys ex_tvs $
+ DCR{} -> mkInfForAllTys univ_tvs $ mkTyCoInvForAllTys ex_tcvs $
mkScaledFunctionTys rep_arg_tys $
mkTyConApp rep_tycon (mkTyVarTys univ_tvs)
-- res_arg_tys is a mixture of TypeLike and ConstraintLike,
@@ -1213,8 +1232,8 @@ mkDataCon name declared_infix prom_info
prom_res_kind roles rep_info
roles = map (\tv -> if isTyVar tv then Nominal else Phantom)
- (univ_tvs ++ ex_tvs)
- ++ map (const Representational) (theta ++ map scaledThing orig_arg_tys)
+ (univ_tvs ++ ex_tcvs)
+ ++ mapConst Representational (theta ++ map scaledThing orig_arg_tys)
freshNames :: [Name] -> [Name]
-- Make an infinite list of Names whose Uniques and OccNames
@@ -1422,9 +1441,15 @@ isNullaryRepDataCon dc = dataConRepArity dc == 0
dataConRepStrictness :: DataCon -> [StrictnessMark]
-- ^ Give the demands on the runtime arguments of a Core DataCon worker
--- application. Maches 1-1 with `dataConRepArgTys`
+-- application. Matches 1-1 with `dataConRepArgTys`
dataConRepStrictness = dcStricts
+dataConRepFullStrictness :: DataCon -> [StrictnessMark]
+-- ^ Give the demands on the runtime arguments of a Core DataCon worker
+-- application, /including/ any existential CoVar args
+-- See (EXCO1) in Note [Existential coercion variables]
+dataConRepFullStrictness = dcFullStricts
+
dataConRepIsLazy :: DataCon -> Bool
dataConRepIsLazy = dcIsLazy
@@ -1537,10 +1562,11 @@ dataConWrapperType (MkData { dcUserTyVarBinders = user_tvbs,
res_ty
-- | Finds the instantiated types of the arguments required to construct a
--- 'DataCon' representation
+-- data constructor worker application
-- NB: these INCLUDE any dictionary args
--- but EXCLUDE the data-declaration context, which is discarded
--- It's all post-flattening etc; this is a representation type
+-- but EXCLUDE the "stupid theta" data-declaration context, which is discarded
+--
+-- Result list is 1-1 with dataConRepArgTys, and dataConRepStrictness
dataConInstArgTys :: DataCon -- ^ A datacon with no existentials or equality constraints
-- However, it can have a dcTheta (notably it can be a
-- class dictionary, with superclasses)
@@ -1635,9 +1661,10 @@ dataConOrigArgTys dc = dcOrigArgTys dc
dataConOtherTheta :: DataCon -> ThetaType
dataConOtherTheta dc = dcOtherTheta dc
--- | Returns the arg types of the worker, including *all* non-dependent
--- evidence, after any flattening has been done and without substituting for
--- any type variables
+-- | Returns the arg types of the worker, after any flattening has been done and
+-- without substituting for any type variables
+--
+-- Includes evidence, namely `dcEqSpec` and `dcOtherTheta`
dataConRepArgTys :: DataCon -> [Scaled Type]
dataConRepArgTys (MkData { dcRep = rep
, dcEqSpec = eq_spec
@@ -1656,8 +1683,10 @@ dataConRepArgTys (MkData { dcRep = rep
-- I think it's because of the call in mkDataCon, which in turn feeds
-- into dcRepArity, which in turn is used in mkDataConWorkId.
-- c.f. #23022
- | otherwise -> assert (null eq_spec) $
- map unrestricted theta ++ orig_arg_tys
+ | otherwise -> assert (null eq_spec) $
+ -- null eq_spec: all GADTs go via DCR
+ -- See `dataConUserTyVarsNeedWrapper`
+ map unrestricted theta ++ orig_arg_tys
-- | The string @package:module.name@ identifying a constructor, which is attached
-- to its info table and used by the GHCi debugger and the heap profiler
=====================================
compiler/GHC/Core/FamInstEnv.hs
=====================================
@@ -828,7 +828,7 @@ mkSingleCoAxiom role ax_name tvs eta_tvs cvs fam_tc lhs_tys rhs_ty
-- Note [Storing compatibility]
where
branch = mkCoAxBranch tvs eta_tvs cvs lhs_tys rhs_ty
- (map (const Nominal) tvs)
+ (mapConst Nominal tvs)
(getSrcSpan ax_name)
-- | Create a coercion constructor (axiom) suitable for the given
=====================================
compiler/GHC/Core/Opt/DmdAnal.hs
=====================================
@@ -1020,15 +1020,16 @@ dmdTransform :: AnalEnv -- ^ The analysis environment
-- this function plus demand on its free variables
-- See Note [DmdSig: demand signatures, and demand-sig arity] in "GHC.Types.Demand"
dmdTransform env var sd
- -- Data constructors
+ -- Data constructor workers
| Just con <- isDataConWorkId_maybe var
= -- pprTraceWith "dmdTransform:DataCon" (\ty -> ppr con $$ ppr sd $$ ppr ty) $
- dmdTransformDataConSig (dataConRepStrictness con) sd
- -- See Note [DmdAnal for DataCon wrappers]
+ dmdTransformDataConSig (dataConRepFullStrictness con) sd
+ -- See Note [DmdAnal for DataCon wrappers]
| Just rhs <- dataConWrapUnfolding_maybe var
, WithDmdType dmd_ty _rhs' <- dmdAnal env sd rhs
= dmd_ty
+
-- Dictionary component selectors
-- Used to be controlled by a flag.
-- See #18429 for some perf measurements.
@@ -1036,10 +1037,12 @@ dmdTransform env var sd
= -- pprTrace "dmdTransform:DictSel" (ppr var $$ ppr (idDmdSig var) $$ ppr sd) $
dmdTransformDictSelSig (idDmdSig var) sd
-- Imported functions
+
| isGlobalId var
, let res = dmdTransformSig (idDmdSig var) sd
= -- pprTrace "dmdTransform:import" (vcat [ppr var, ppr (idDmdSig var), ppr sd, ppr res])
res
+
-- Top-level or local let-bound thing for which we use LetDown ('useLetUp').
-- In that case, we have a strictness signature to unleash in our AnalEnv.
| Just (sig, top_lvl) <- lookupSigEnv env var
=====================================
compiler/GHC/Core/Opt/Simplify/Iteration.hs
=====================================
@@ -2257,18 +2257,21 @@ inline y, we must *not* replace x by x' in the inlined copy!!
Note [Fast path for lazy data constructors]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-For applications of a /lazy/ data constructor worker, the full glory of
-rebuildCall is a waste of effort;
+For applications of a completely /lazy/ data constructor worker, the full
+glory of rebuildCall is a waste of effort;
* They never inline, obviously
* They have no rewrite rules
* Lazy constructors don't need the `StrictArg` treatment.
So it's fine to zoom straight to `rebuild` which just rebuilds the
-call in a very straightforward way.
+call in a very straightforward way. But:
-For a data constructor worker that is strict (see Note [Strict fields in Core])
-we take the slow path, so that we'll transform
- K (case x of (a,b) -> a) --> case x of (a,b) -> K a
-via the StrictArg case of rebuildCall
+* For a data constructor worker that is strict (see Note [Strict fields in Core])
+ we take the slow path, so that we'll transform
+ K (case x of (a,b) -> a) --> case x of (a,b) -> K a
+ via the StrictArg case of rebuildCall
+
+* If the data constructor has unlifted arguments, we must also take the
+ slow path (#28169). Same example as `K` above if its arg is Int#
Some programs have a /lot/ of data constructors in the source program
(compiler/perf/T9961 is an example), so this fast path can be very
@@ -2278,8 +2281,9 @@ valuable.
simplInId :: SimplEnv -> InId -> SimplCont -> SimplM (SimplFloats, OutExpr)
simplInId env var cont
| Just dc <- isDataConWorkId_maybe var
- , dataConRepLazy dc -- See Note [Fast path for lazy data constructors]
+ , dataConRepIsLazy dc -- See Note [Fast path for lazy data constructors]
= rebuild env (Var var) cont
+
| otherwise
= assertPpr (not (isCoVar var)) (ppr var) $
case substId env var of
@@ -3649,7 +3653,7 @@ adjustFieldsIdInfo _scrut case_bndr bndr_swap con vs
| otherwise
= go vs the_strs
where
- the_strs = dataConRepStrictness con
+ the_strs = dataConRepFullStrictness con
go [] [] = []
go (v:vs') strs | isTyVar v = v : go vs' strs
@@ -3659,7 +3663,7 @@ adjustFieldsIdInfo _scrut case_bndr bndr_swap con vs
ppr vs $$
ppr_with_length (map strdisp the_strs) $$
ppr_with_length (dataConRepArgTys con) $$
- ppr_with_length (dataConRepStrictness con))
+ ppr_with_length (dataConRepFullStrictness con))
where
ppr_with_length list
= ppr list <+> parens (text "length =" <+> ppr (length list))
@@ -4306,10 +4310,9 @@ mkDupableAlt _env case_bndr jfloats (Alt con alt_bndrs alt_rhs_in)
| otherwise
= do { let rhs_ty' = exprType alt_rhs_in
- bangs
- | DataAlt c <- con
- = dataConRepStrictness c
- | otherwise = []
+ bangs = case con of
+ DataAlt dc -> dataConRepFullStrictness dc
+ _ -> []
abstracted_binders = abstract_binders alt_bndrs bangs
=====================================
compiler/GHC/Core/Opt/SpecConstr.hs
=====================================
@@ -2769,7 +2769,7 @@ argToPat1 env in_scope val_env _pat_ty arg arg_occ _arg_str
= do { let (ty_args, rest_args) = splitAtList (dataConUnivTyVars dc) args
con_str :: [StrictnessMark]
-- con_str corresponds 1-1 with the /value/ arguments
- con_str = dataConRepStrictness dc
+ con_str = dataConRepFullStrictness dc
con_ty = applyTypeToArgs (dataConRepType dc) ty_args
-- ; pprTraceM "bangs" (ppr (length rest_args == length con_str) $$
-- ppr dc $$
=====================================
compiler/GHC/Core/Opt/WorkWrap/Utils.hs
=====================================
@@ -221,7 +221,7 @@ mkWwBodies opts fun_id ww_arity arg_vars res_ty demands res_cpr
zapped_arg_vars = map zap_var arg_vars
; (subst, cloned_arg_vars) <- cloneBndrsM empty_subst zapped_arg_vars
; let res_ty' = substTyUnchecked subst res_ty
- init_str_marks = map (const NotMarkedStrict) cloned_arg_vars
+ init_str_marks = mapConst NotMarkedStrict cloned_arg_vars
; (useful1, work_args_str, wrap_fn_str, fn_args)
<- -- pprTrace "mkWWbodies" (ppr fun_id $$ ppr (arg_vars `zip` cloned_arg_vars) $$ ppr demands) $
@@ -1050,7 +1050,7 @@ unbox_one_arg opts arg_var
-- Mark arguments coming out of strict fields so we can seq them in the worker
-- See Note [Call-by-value for worker args]
- all_str_marks = (map (const NotMarkedStrict) ex_tvs') ++ con_str_marks
+ all_str_marks = mapConst NotMarkedStrict ex_tvs' ++ con_str_marks
; (nested_useful, worker_args, wrap_fn, wrap_args)
<- mkWWstr opts (ex_tvs' ++ arg_ids') all_str_marks
=====================================
compiler/GHC/Core/SimpleOpt.hs
=====================================
@@ -1727,9 +1727,9 @@ exprIsConApp_maybe ise@(ISE in_scope id_unf) expr
-- why we insert them
mkFieldSeqFloats in_scope dc args
| dataConRepIsLazy dc = (in_scope, nilOL, args) -- Short cut in common case
- | otherwise = (in_scope', floats', ty_args ++ val_args')
+ | otherwise = (in_scope', floats', tyco_args ++ val_args')
where
- (ty_args, val_args) = splitAtList (dataConUnivAndExTyCoVars dc) args
+ (tyco_args, val_args) = splitAtList (dataConUnivAndExTyCoVars dc) args
(in_scope', floats', val_args') = foldr do_one (in_scope, nilOL, []) $
zipEqual str_marks val_args
str_marks = dataConRepStrictness dc
=====================================
compiler/GHC/Core/TyCon.hs
=====================================
@@ -1513,9 +1513,10 @@ There are a number of wrinkles
data C a = MkC !(a->a)
so that in exprOkForSpeculation/exprOkToDiscard/exprOkForSpecEval, and
in exprIsHNF/exprIsConLike, we evaluate the argument. This strictness flag
- is set in `GHC.Tc.TyCl.buildClass
+ is set in `GHC.Tc.TyCl.Build.buildClass`; see `bangs` and `bang_opts`.
+ (#28183 shows why this matters.)
-(UMC4) To avoid regressions, in Core we want to remember that
+(UCM4) To avoid regressions, in Core we want to remember that
(MkUC x) is really just x
(op d) is really just d
We account for this in several places:
@@ -3067,8 +3068,8 @@ isUnaryClassTyCon tc@(TyCon { tyConDetails = details })
isTerminatingTyCon :: TyCon -> Bool
-- ^ True <=> a value of type (T t1..tn), where `T` is this TyCon, cannot be bottom.
--- The only TyCons that satisfy `isTerminatingTyCon` are non-unary class TyCons.
--- See (UCM3) in Note [Unary class magic], and
+-- The only TyCons that satisfy `isTerminatingTyCon` are /non-unary/ class TyCons.
+-- See (UCM3a) in Note [Unary class magic], and
-- Note [NON-BOTTOM-DICTS invariant] in GHC.Core.
-- An AbstractTyCon returns False: it comes from an hs-boot file, and the real
-- declaration may turn out to be a unary class. See (NBD2) in that Note.
=====================================
compiler/GHC/Core/Type.hs
=====================================
@@ -1781,7 +1781,7 @@ fun_kind_arg_flags = go emptySubst
where
argf | isVisibleFunArg af = Required
| otherwise = Inferred
- go _ _ arg_tys = map (const Required) arg_tys
+ go _ _ arg_tys = mapConst Required arg_tys
-- something is ill-kinded. But this can happen
-- when printing errors. Assume everything is Required.
=====================================
compiler/GHC/Core/Utils.hs
=====================================
@@ -2271,13 +2271,12 @@ app_ok fun_ok primop_ok fun val_args
| otherwise
= case idDetails fun of
DFunId terminating -> terminating
- -- DFuns terminate, unless the dict is implemented
- -- by a no-op in which case they may not
- -- See (UCM3) in Note [Unary class magic] in GHC.Core.TyCon
+ -- DFuns terminate, except for unary classes
+ -- See (UCM3a) in Note [Unary class magic] in GHC.Core.TyCon
DataConWorkId dc
- | dataConRepLazy dc -> True -- Args are all thunks
- | otherwise -> fields_ok (dataConRepStrictness dc)
+ | dataConRepIsLazy dc -> True -- Args are all thunks
+ | otherwise -> fields_ok (dataConRepFullStrictness dc)
ClassOpId _ is_terminating_result
| is_terminating_result -- See Note [exprOkForSpeculation and type classes]
@@ -2696,45 +2695,54 @@ exprIsHNFlike is_con is_con_unf rubbish_lit_result e
-- check_app: See Note [exprIsHNF for function applications]
-- for the specification and examples
+ -- We check arity (and CONLIKEness) first because it's cheaper
+ -- and we reject quickly on saturated apps.
+ check_app :: Id -> [CoreArg] -> Bool
check_app id val_args
= case compare (idArity id) (length val_args) of
EQ -> check_saturated id val_args -- Saturated application
GT -> check_args id val_args -- Partial application
LT -> False -- Over-saturated
+ check_saturated :: Id -> [CoreArg] -> Bool
check_saturated id val_args
| Just dc <- isDataConWorkId_maybe id
- = -- Saturated data constructors; must account for the strictness flags
- all3Prefix check_field val_args (val_arg_tys id) (dataConStrictness dc)
+ , let strs = dataConRepFullStrictness dc
+ arg_tys = get_val_arg_tys id
+ = -- Saturated data constructors; use `check_field`
+ -- to ensure we account for the strictness flags
+ assertPpr (equalLength val_args arg_tys && equalLength val_args strs)
+ (ppr dc $$ ppr val_args $$ ppr arg_tys $$ ppr strs) $
+ all3Prefix check_field val_args arg_tys strs
+
| is_con id -- Saturated CONLIKE: check the arguments
= check_args id val_args
+
| otherwise -- Saturated function, not a constructor => not HNF
= False
-- check_args: check that any unlifted args are hnf-like
- check_args id val_args = assert (sameLength val_args arg_tys) $
- all2Prefix check_arg val_args arg_tys
+ -- NB: there may be fewer val_args than arg_tys (e.g. (map f))
+ check_args :: Id -> [CoreArg] -> Bool
+ check_args id val_args = all2Prefix check_arg val_args arg_tys
where
- arg_tys = val_arg_tys id
+ arg_tys = get_val_arg_tys id
- check_arg a_ty a
- | mightBeUnliftedType a_ty = is_hnf_like a
- | otherwise = True
- -- Check unliftedness; for example f (x /# 12#) where f has arity two,
- -- and the first argument is unboxed. This is not a value!
- -- But f 34# is a value, so check args for HNFs.
- -- NB: We check arity (and CONLIKEness) first because it's cheaper
- -- and we reject quickly on saturated apps.
+ -- check_arg: check unliftedness; for example f (x /# 12#) where f
+ -- has arity two, and the first argument is unboxed. This is not a value!
+ -- But f 34# is a value, so check unlifted args for HNFs.
+ check_arg arg arg_ty
+ | mightBeUnliftedType arg_ty = is_hnf_like arg
+ | otherwise = True
-- check_field: used for a data constructor worker:
- -- check unlifted val_args and strict fields
+ -- check unlifted val_args /and/ strict fields
-- See (SFC1) of Note [Strict fields in Core]
- check_field a a_ty str
- | mightBeUnliftedType a_ty = is_hnf_like a
- | isMarkedStrict str = is_hnf_like a
- | otherwise = True
+ check_field arg arg_ty str
+ | isMarkedStrict str = is_hnf_like arg
+ | otherwise = check_arg arg arg_ty
- val_arg_tys id = splitUninstantiatedValArgTys (idType id)
+ get_val_arg_tys id = splitUninstantiatedValArgTys (idType id)
-- val_arg_tys = map exprType val_args, but much less costly.
-- The obvious definition regresses T16577 by 30% so we don't do it.
@@ -2893,7 +2901,7 @@ dataConInstPat fss uniqs mult con inst_tys
ex_tvs = dataConExTyCoVars con
arg_tys = dataConRepArgTys con
arg_strs = dataConRepStrictness con -- 1-1 with arg_tys
- n_ex = length ex_tvs
+ n_ex = length ex_tvs
-- split the Uniques and FastStrings
(ex_uniqs, id_uniqs) = splitAt n_ex uniqs
=====================================
compiler/GHC/Tc/Gen/HsType.hs
=====================================
@@ -1369,7 +1369,7 @@ tc_hs_tuple_ty rn_ty mode HsBoxedOrConstraintTuple hs_tys exp_kind
checkExpectedKind hs_ty ty kind arg_kind
| ((L loc hs_ty),ty,kind) <- zip3 hs_tys tys kinds ]
- ; finish_tuple rn_ty tup_sort tys' (map (const arg_kind) tys') exp_kind }
+ ; finish_tuple rn_ty tup_sort tys' (mapConst arg_kind tys') exp_kind }
tc_hs_tuple_ty rn_ty mode HsUnboxedTuple tys exp_kind =
tc_tuple rn_ty mode UnboxedTuple tys exp_kind
=====================================
compiler/GHC/Tc/Gen/Pat.hs
=====================================
@@ -655,7 +655,7 @@ tc_pat scaled_exp_pat_ty@(Scaled w_pat exp_pat_ty) penv ps_pat thing_inside =
OrPat _ pats -> do -- See Note [Implementation of OrPatterns], Typechecker (1)
{ let pats_list = NE.toList pats
- pat_exp_tys = map (const scaled_exp_pat_ty) pats_list
+ pat_exp_tys = mapConst scaled_exp_pat_ty pats_list
; (pats_list', (res, pat_ct)) <- tc_lpats pat_exp_tys penv pats_list (captureConstraints thing_inside)
; let pats' = NE.fromList pats_list' -- tc_lpats preserves non-emptiness
; emitConstraints pat_ct
=====================================
compiler/GHC/Tc/TyCl.hs
=====================================
@@ -3713,7 +3713,7 @@ tcTyFamInstEqn fam_tc mb_clsinfo
-- (tcFamInstEqnGuts zonks to Type)
; let ax = mkCoAxBranch qtvs [] [] pats rhs_ty
- (map (const Nominal) qtvs)
+ (mapConst Nominal qtvs)
(locA loc)
vi = VI { vi_loc = locA loc
, vi_qtvs = qtvs
=====================================
compiler/GHC/Tc/TyCl/Build.hs
=====================================
@@ -291,9 +291,9 @@ type MethInfo -- A temporary intermediate, to communicate
buildClass :: Name -- Name of the class/tycon (they have the same Name)
-> Kind
- -> [TyConBinder] -- Of the tycon
+ -> [TyConBinder] -- Of the tycon
-> [Role]
- -> [FunDep TyVar] -- Functional dependencies
+ -> [FunDep TyVar] -- Functional dependencies
-> KnotTied ThetaType -- Superclasess
-> [ClassATItem] -- Associated types
-> [KnotTied MethInfo] -- Methods
@@ -330,10 +330,15 @@ buildClass tycon_name kind binders roles fds sc_theta at_items sig_stuff mindef
rec_tycon = classTyCon rec_clas
univ_bndrs = tyVarSpecToBinders $ tyConInvisTVBinders binders
univ_tvs = binderVars univ_bndrs
- bang_opts = FixedBangOpts (map (const HsLazy) args)
+
+ -- Unary classes behave as if we added a bang
+ -- See (UCM3b) in Note [Unary class magic]
+ bang_opts :: DataConBangOpts
+ bang_opts | unary_class = FixedBangOpts [HsStrict False]
+ | otherwise = FixedBangOpts (mapConst HsLazy args)
bangs :: [HsSrcBang]
- bangs | unary_class = [yes_bang] -- See (UCM3b) in Note [Unary class magic]
- | otherwise = map (const no_bang) args
+ bangs | unary_class = [yes_bang]
+ | otherwise = mapConst no_bang args
; rep_nm <- newTyConRepName datacon_name
; dict_con <- buildDataCon (panic "buildClass: FamInstEnvs")
@@ -356,8 +361,7 @@ buildClass tycon_name kind binders roles fds sc_theta at_items sig_stuff mindef
; let rhs | unary_class
= UnaryClassTyCon dict_con
| isCTupleTyConName tycon_name
- = TupleTyCon { data_con = dict_con
- , tup_sort = ConstraintTuple }
+ = TupleTyCon { data_con = dict_con, tup_sort = ConstraintTuple }
| otherwise
= mkDataTyConRhs [dict_con]
=====================================
compiler/GHC/Tc/TyCl/Instance.hs
=====================================
@@ -837,7 +837,7 @@ tcDataFamInstDecl mb_clsinfo tv_skol_env
rep_tc = mkAlgTyCon rep_tc_name user_kind
ty_binders (length extra_tcbs)
res_kind
- (map (const Nominal) ty_binders)
+ (mapConst Nominal ty_binders)
(fmap (typeCheckCType . unLoc) cType) stupid_theta
tc_rhs parent
gadt_syntax
=====================================
compiler/GHC/Tc/TyCl/Utils.hs
=====================================
@@ -471,7 +471,7 @@ initialRoleEnv hsc_src annots = extendNameEnvList emptyNameEnv .
initialRoleEnv1 :: HscSource -> RoleAnnotEnv -> TyCon -> (Name, [Role])
initialRoleEnv1 hsc_src annots_env tc
- | isFamilyTyCon tc = (name, map (const Nominal) bndrs)
+ | isFamilyTyCon tc = (name, mapConst Nominal bndrs)
| isAlgTyCon tc = (name, default_roles)
| isTypeSynonymTyCon tc = (name, default_roles)
| otherwise = pprPanic "initialRoleEnv1" (ppr tc)
=====================================
compiler/GHC/Types/Id/Make.hs
=====================================
@@ -541,7 +541,6 @@ mkDataConWorkId wkr_name data_con
univ_tvs = dataConUnivTyVars data_con
ex_tcvs = dataConExTyCoVars data_con
arg_tys = dataConRepArgTys data_con -- Should be same as dataConOrigArgTys
- str_marks = dataConRepStrictness data_con
----------- Workers for data types --------------
alg_wkr_info = noCafIdInfo
@@ -555,10 +554,17 @@ mkDataConWorkId wkr_name data_con
`setLFInfo` wkr_lf_info
wkr_inline_prag = alwaysConLikePragma
- wkr_arity = dataConRepArity data_con
- wkr_sig = mkClosedDmdSig wkr_dmds topDiv
- wkr_dmds = map mk_dmd str_marks
+ -- Strictness signature has arity = wkr_arity
+ -- i.e. including any existential CoVars
+ -- See (EXCO1) in Note [Existential coercion variables]
+ wkr_arity = dataConRepArity data_con
+ str_marks = dataConRepFullStrictness data_con
+ wkr_dmds = map mk_dmd str_marks
+ wkr_sig = assertPpr (str_marks `lengthIs` wkr_arity &&
+ splitUninstantiatedValArgTys wkr_ty `lengthIs` wkr_arity)
+ (ppr data_con $$ ppr str_marks $$ ppr wkr_ty) $
+ mkClosedDmdSig wkr_dmds topDiv
mk_dmd MarkedStrict = evalDmd
mk_dmd NotMarkedStrict = topDmd
@@ -824,7 +830,7 @@ mkDataConRep platform dc_bang_opts fam_envs wrap_name data_con
wrap_ty = dataConWrapperType data_con
ev_tys = eqSpecPreds eq_spec ++ theta
all_arg_tys = map unrestricted ev_tys ++ orig_arg_tys
- ev_ibangs = map (const HsLazy) ev_tys
+ ev_ibangs = mapConst HsLazy ev_tys
orig_bangs = dataConSrcBangs data_con
wrap_arg_tys
@@ -852,14 +858,14 @@ mkDataConRep platform dc_bang_opts fam_envs wrap_name data_con
arg_ibangs
| new_tycon
- = map (const HsLazy) orig_arg_tys -- See Note [HsImplBangs for newtypes]
- -- orig_arg_tys should be a singleton, but
- -- if a user declared a wrong newtype we
- -- detect this later (see test T2334A)
+ = mapConst HsLazy orig_arg_tys -- See Note [HsImplBangs for newtypes]
+ -- orig_arg_tys should be a singleton, but
+ -- if a user declared a wrong newtype we
+ -- detect this later (see test T2334A)
| otherwise
= case dc_bang_opts of
SrcBangOpts bang_opts -> zipWith (dataConSrcToImplBang platform bang_opts fam_envs)
- orig_arg_tys orig_bangs
+ orig_arg_tys orig_bangs
FixedBangOpts bangs -> bangs
(rep_tys_w_strs, wrappers)
@@ -999,11 +1005,11 @@ For further reading, see:
Note [Bangs on imported data constructors]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-We pass Maybe [HsImplBang] to mkDataConRep to make use of HsImplBangs
+We pass `DataConBangOpts` to `mkDataConRep` to make use of `HsImplBangs`
from imported modules.
-- Nothing <=> use HsSrcBangs
-- Just bangs <=> use HsImplBangs
+- SrcBangOpts opts <=> use HsSrcBangs
+- FixedBangOpts impl_bangs <=> use impl_bangs
For imported types we can't work it all out from the HsSrcBangs,
because we want to be very sure to follow what the original module
@@ -1011,8 +1017,8 @@ because we want to be very sure to follow what the original module
flags were enabled when it was compiled. So we record the decisions in
the interface file.
-The HsImplBangs passed are in 1-1 correspondence with the
-dataConOrigArgTys of the DataCon.
+The `HsImplBangs` passed are in 1-1 correspondence with the
+`dataConOrigArgTys` of the DataCon.
Note [Data con wrappers and unlifted types]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
=====================================
compiler/GHC/Utils/Misc.hs
=====================================
@@ -18,7 +18,7 @@ module GHC.Utils.Misc (
unzipWith,
- mapFst, mapSnd, chkAppend,
+ mapFst, mapSnd, mapConst, chkAppend,
mapAndUnzip, mapAndUnzip3, mapAndUnzip4,
filterOut, partitionWith, partitionWithM,
@@ -329,6 +329,10 @@ mapSnd :: Functor f => (b->c) -> f(a,b) -> f(a,c)
mapFst = fmap . first
mapSnd = fmap . second
+mapConst :: a -> [b] -> [a]
+-- (mapConst k [a,b,c]) returns [k,k,k]
+mapConst k xs = [ k | _ <- xs ]
+
zipWithAndUnzip :: (a -> b -> (c,d)) -> [a] -> [b] -> ([c],[d])
zipWithAndUnzip f (a:as) (b:bs)
= let (r1, r2) = f a b
=====================================
testsuite/tests/simplCore/should_compile/T28169.hs
=====================================
@@ -0,0 +1,8 @@
+{-# LANGUAGE MagicHash #-}
+
+module T28169 where
+import GHC.Exts
+
+f :: Int# -> (Int,Int)
+f x = let y = I# (let z = x +# 1# in z *# z)
+ in (y + y, y * y)
=====================================
testsuite/tests/simplCore/should_compile/all.T
=====================================
@@ -631,3 +631,6 @@ test('T27936', normal, compile, [''])
test('T27910', grep_errmsg(r'KnownBranch'), compile, ['-O -dno-typeable-binds -ddump-simpl-stats -dsuppress-uniques'])
test('T27892', grep_errmsg(r'^f = g$'), compile, ['-O -ddump-cse -dsuppress-all -dsuppress-uniques'])
test('T28095a', grep_errmsg(r'^f = g$'), compile, ['-O -ddump-cse -dsuppress-all -dsuppress-uniques'])
+
+# T28169: test that there are no calls to boxed arithmetic,e.g. GHC.Internal.Num.$fNumInt_$c+
+test('T28169', grep_errmsg(r'\$c'), compile, ['-O -ddump-simpl -dsuppress-uniques'])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1daa8f406690ca7747424c88053185c…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1daa8f406690ca7747424c88053185c…
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
1
0
[Git][ghc/ghc][wip/romes/async-rpc] test: Perf overhead of external interpreter communication
by Rodrigo Mesquita (@alt-romes) 25 Nov '26
by Rodrigo Mesquita (@alt-romes) 25 Nov '26
25 Nov '26
Rodrigo Mesquita pushed to branch wip/romes/async-rpc at Glasgow Haskell Compiler / GHC
Commits:
f22a9782 by Rodrigo Mesquita at 2026-11-25T11:38:46+00:00
test: Perf overhead of external interpreter communication
Observed a regression in the async-rpc branch in the cost of
communication with the external interpreter of about 10%.
It compiles many trivial splices with -fno-code, to try and isolate the
cost of the overhead of communication.
- - - - -
2 changed files:
- testsuite/tests/perf/compiler/all.T
- + testsuite/tests/perf/compiler/genExtInterpManySplices
Changes:
=====================================
testsuite/tests/perf/compiler/all.T
=====================================
@@ -890,3 +890,15 @@ test ('T26989',
multimod_compile,
['T26989', '-v0 -O'])
+# Compile many trivial splices with -fno-code, to try and isolate the cost of communication with ext-interp.
+# Introduced as a test against a regression that had been introduced in the async-rpc branch work.
+test('ExtInterpManySplices',
+ [ collect_compiler_stats('bytes allocated', 2),
+ req_th,
+ unless(config.have_ext_interp, skip),
+ pre_cmd('./genExtInterpManySplices'),
+ extra_files(['genExtInterpManySplices']),
+ only_ways(['normal']),
+ ],
+ compile,
+ ['-fno-code -fexternal-interpreter'])
=====================================
testsuite/tests/perf/compiler/genExtInterpManySplices
=====================================
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+# One module with many trivial splices
+NSPLICES=1000
+{
+ echo "{-# LANGUAGE TemplateHaskell #-}"
+ echo "module ExtInterpManySplices where"
+ echo "import Language.Haskell.TH.Syntax"
+ for i in $(seq $NSPLICES); do
+ echo "x$i :: Int"
+ echo "x$i = \$(lift ($i :: Int))"
+ done
+} > ExtInterpManySplices.hs
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f22a97822cb17dd3bd91cffb7a239ef…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f22a97822cb17dd3bd91cffb7a239ef…
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
1
0
[Git][ghc/ghc][wip/teo/T27547] Skip tests that excercise forkProcess when using non-moving GC
by Teo Camarasu (@teo) 25 Nov '26
by Teo Camarasu (@teo) 25 Nov '26
25 Nov '26
Teo Camarasu pushed to branch wip/teo/T27547 at Glasgow Haskell Compiler / GHC
Commits:
726352f1 by Teo Camarasu at 2026-11-25T11:10:06+00:00
Skip tests that excercise forkProcess when using non-moving GC
The non-moving GC creates a persistent marker thread. This causes issues
when users use forkProcess, since the child process ends up in a strange
state.
forkProcess is documented to not work well with the threaded Haskell
runtime. So, it's not surprising that it doesn't work with the
non-moving GC which is inherently threaded.
We should one day add support for forkProcess, but, for now, we just
disable these tests when using the non-moving GC.
The underlying issue is tracked by #27547.
- - - - -
3 changed files:
- testsuite/tests/hpc/fork/test.T
- testsuite/tests/lib/base/all.T
- testsuite/tests/rts/all.T
Changes:
=====================================
testsuite/tests/hpc/fork/test.T
=====================================
@@ -9,5 +9,7 @@ test('hpc_fork',
# and #8862.
req_process,
omit_ways(prof_ways),
- cmd_prefix(hpc_prefix)],
+ cmd_prefix(hpc_prefix),
+ # The threaded nonmoving-gc doesn't support forkProcess. See #27547
+ omit_ways(['nonmoving_thr', 'nonmoving_thr_ghc', 'nonmoving_thr_sanity'])],
compile_and_run, ['-fhpc'])
=====================================
testsuite/tests/lib/base/all.T
=====================================
@@ -2,7 +2,13 @@ test('DataTypeOrd', normal, compile_and_run, [''])
test('T16586', normal, compile_and_run, ['-O2'])
# Event-manager not supported on Windows
test('T16916', [when(opsys('mingw32'), skip), js_broken(22261), fragile(16966), req_ghc_with_threaded_rts], compile_and_run, ['-O2 -threaded -with-rtsopts="-I0" -rtsopts'])
-test('T24672', [when(opsys('mingw32'), skip), js_broken(22261),req_process], compile_and_run, [''])
+test('T24672',
+ [ when(opsys('mingw32'), skip)
+ , js_broken(22261)
+ , req_process
+ # The threaded nonmoving-gc doesn't support forkProcess. See #27547
+ , omit_ways(['nonmoving_thr', 'nonmoving_thr_ghc', 'nonmoving_thr_sanity'])]
+ , compile_and_run, [''])
test('T17310', normal, compile, [''])
test('T19691', normal, compile, [''])
test('executablePath', [extra_run_opts(config.os), js_broken(22261), when(arch('wasm32'), fragile(23248)), omit_ghci], compile_and_run, [''])
=====================================
testsuite/tests/rts/all.T
=====================================
@@ -451,6 +451,8 @@ test('T13617', [ unless(opsys('mingw32'), skip)],
# its history.
test('T12903', [ fragile(21184)
, js_broken(22374)
+ # The threaded nonmoving-gc doesn't support forkProcess. See #27547
+ , omit_ways(['nonmoving_thr', 'nonmoving_thr_ghc', 'nonmoving_thr_sanity'])
, req_process]
, compile_and_run, [''])
@@ -687,7 +689,12 @@ test('IOManager', [js_skip, when(arch('wasm32'), skip), when(opsys('mingw32'), s
test('T24142', [req_target_smp], compile_and_run, ['-threaded -with-rtsopts "-N2"'])
test('T25232', [unless(have_profiling(), skip), only_ways(['normal','nonmoving','nonmoving_prof','nonmoving_thr_prof']), extra_ways(['nonmoving', 'nonmoving_prof'] + (['nonmoving_thr_prof'] if have_threaded() else []))], compile_and_run, [''])
-test('T25280', [unless(opsys('linux'),skip),req_process,js_skip], compile_and_run, [''])
+test('T25280',
+ [unless(opsys('linux'),skip)
+ ,req_process,js_skip
+ # The threaded nonmoving-gc doesn't support forkProcess. See #27547
+ , omit_ways(['nonmoving_thr', 'nonmoving_thr_ghc', 'nonmoving_thr_sanity'])]
+ , compile_and_run , [''])
# N.B. This will likely issue a warning on stderr but we merely care that the
# program doesn't crash.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/726352f193f5b332800fed2f5c78523…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/726352f193f5b332800fed2f5c78523…
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
1
0
[Git][ghc/ghc][wip/T28171] rts/nonmoving: fix wakeBlockingQueue missing update remembered set push
by Teo Camarasu (@teo) 25 Nov '26
by Teo Camarasu (@teo) 25 Nov '26
25 Nov '26
Teo Camarasu pushed to branch wip/T28171 at Glasgow Haskell Compiler / GHC
Commits:
628d79da by Teo Camarasu at 2026-11-25T10:43:03+00:00
rts/nonmoving: fix wakeBlockingQueue missing update remembered set push
When we wake up a blocking queue, we replace the blocking queue with an
indirection.
An indirection has fewer fields than a blocking queue, so we are, in
essence, overwriting some fields with NULL. Thus they need to be pushed
to the update remembered set.
The test shows that this is observable. We can have a situation where a
thread is ONLY being kept alive by being on a blocking queue. If the
nonmoving mark can't see it there then it will be GC'd overly eagerly
and we will get a NonTermination exception when it gets cleaned up.
We also push the other fields to the update remembered set to enforce
the invariant, but I'm not sure if those will ever cause issues in the
same way.
Resolves #28171
- - - - -
5 changed files:
- + changelog.d/T28171
- rts/Threads.c
- + testsuite/tests/rts/T28171.hs
- + testsuite/tests/rts/T28171.stdout
- testsuite/tests/rts/all.T
Changes:
=====================================
changelog.d/T28171
=====================================
@@ -0,0 +1,8 @@
+section: rts
+synopsis: Fix the nonmoving GC sending spurious NonTermination exceptions
+description:
+ We fix the nonmoving GC's logic for waking up threads blocked on a thunk, which had
+ a bug leading to threads being falsely being GC'd too soon.
+ This could lead to spurious NonTermination exceptions.
+mrs: !17050
+issues: #28171
=====================================
rts/Threads.c
=====================================
@@ -440,9 +440,18 @@ wakeBlockingQueue(Capability *cap, StgBlockingQueue *bq)
if (i != &stg_IND_info) {
ASSERT(i == &stg_MSG_BLACKHOLE_info);
tryWakeupThread(cap,msg->tso);
+
}
}
+ // Changing the closure type to IND makes these fields inaccessible,
+ // so we need to push them to the update remembered set.
+ IF_NONMOVING_WRITE_BARRIER_ENABLED {
+ updateRemembSetPushClosure(cap, (StgClosure *) bq->bh);
+ updateRemembSetPushClosure(cap, (StgClosure *) bq->owner);
+ updateRemembSetPushClosure(cap, (StgClosure *) bq->queue);
+ }
+
// overwrite the BQ with an indirection so it will be
// collected at the next GC.
OVERWRITE_INFO(bq, &stg_IND_info);
=====================================
testsuite/tests/rts/T28171.hs
=====================================
@@ -0,0 +1,32 @@
+import Control.Concurrent
+import Control.Concurrent.MVar
+import Control.Exception
+import Control.Monad
+import System.Mem
+import System.IO.Unsafe
+
+main :: IO ()
+main = do
+ forM_ [1 .. 1000] $ \r -> do
+ -- Create a thunk that will never finish evaluating
+ let t = unsafePerformIO (threadDelay (100000000000 + r))
+ -- Begin nonmoving GC
+ performMajorGC
+ performMajorGC
+ x <- newEmptyMVar
+ y <- newEmptyMVar
+ -- we start evaluating it on two threads in parallel
+ k <- forkIO (putMVar x () >> void (evaluate t))
+ performMajorGC
+ -- The second thread gets added to the waking queue
+ _ <- forkIO (putMVar y () >> void (evaluate t))
+ takeMVar x
+ takeMVar y
+ -- We kill the original thread.
+ -- And now wake up the other threads.
+ -- We need to ensure that the nonmoving GC can see that thread.
+ -- Otherwise we will get a NonTermination exception
+ killThread k
+ performMajorGC
+ performMajorGC
+ putStrLn "done"
=====================================
testsuite/tests/rts/T28171.stdout
=====================================
@@ -0,0 +1 @@
+done
=====================================
testsuite/tests/rts/all.T
=====================================
@@ -807,3 +807,9 @@ test('T27376',
only_ways(['nonmoving_thr', 'nonmoving_thr_sanity']),
extra_run_opts('+RTS -A2m -RTS') ],
compile_and_run, ['-O2'])
+
+test('T28171',
+ [ req_target_smp,
+ extra_ways(['nonmoving_thr', 'nonmoving_thr_sanity']),
+ only_ways(['nonmoving_thr', 'nonmoving_thr_sanity'])],
+ compile_and_run, [''])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/628d79daf7f49b1be4c176c5c8b558b…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/628d79daf7f49b1be4c176c5c8b558b…
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
1
0
Teo Camarasu pushed new branch wip/T28171 at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T28171
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
1
0
[Git][ghc/ghc][wip/romes/async-rpc] fixup! ghc-boot-th: avoid orphan NFData instances
by Andrea Vezzosi (@trac-Saizan) 25 Nov '26
by Andrea Vezzosi (@trac-Saizan) 25 Nov '26
25 Nov '26
Andrea Vezzosi pushed to branch wip/romes/async-rpc at Glasgow Haskell Compiler / GHC
Commits:
75c2e58c by Andrea Vezzosi at 2026-11-25T10:09:40+01:00
fixup! ghc-boot-th: avoid orphan NFData instances
- - - - -
1 changed file:
- compiler/GHC/Tc/Gen/Splice.hs
Changes:
=====================================
compiler/GHC/Tc/Gen/Splice.hs
=====================================
@@ -1146,12 +1146,14 @@ convertAnnotationWrapper fhv = do
runQinTcM :: TH.Q a -> TcM a
runQinTcM (TH.Q act) = withRunInIO $ \runInIO -> act (metaHandlersTcM runInIO)
+#if defined(HAVE_INTERNAL_INTERPRETER)
-- | Like 'runQinTcM' but forcing methods' arguments, to trigger exceptions
-- originating from the splice.
--
-- See Note [Exceptions in TH]
runQinTcM' :: TH.Q a -> TcM a
runQinTcM' (TH.Q act) = withRunInIO $ \runInIO -> act (TH.forceMetaHandlersArgs $ metaHandlersTcM runInIO)
+#endif
runRemoteModFinalizers :: ThModFinalizers -> TcM ()
runRemoteModFinalizers (ThModFinalizers finRefs) = do
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/75c2e58cfd1e73f81fe479e4e1670ed…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/75c2e58cfd1e73f81fe479e4e1670ed…
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
1
0
25 Nov '26
Simon Peyton Jones pushed to branch wip/case-bndr-unf at Glasgow Haskell Compiler / GHC
Commits:
1045f6c7 by Simon Peyton Jones at 2026-11-25T09:12:37+00:00
Add splitThunkCpr
This commit adds GHC.Core.Opt.WorkWrap.splitThunkCpr, which adds a form
of "thunk splitting" for strict bindings that have CPR information.
See Note [Thunk splitting] in WorkWrap.hs for the details.
It catches a previously-unrecognised optimisation opportunity
(see #28158) but it only helps in fairly obscure cases, so
I don't expect a big impact in practice.
As usually I did lots of refactoring along the way.
LLM disclosure: lots of interaction with Claude, but I wrote all the
code and comments.
- - - - -
9 changed files:
- compiler/GHC/Core/Opt/CprAnal.hs
- compiler/GHC/Core/Opt/Simplify/Iteration.hs
- compiler/GHC/Core/Opt/WorkWrap.hs
- compiler/GHC/Core/Opt/WorkWrap/Utils.hs
- compiler/GHC/Types/Cpr.hs
- compiler/GHC/Utils/Monad.hs
- + testsuite/tests/simplCore/should_compile/T28158.hs
- + testsuite/tests/simplCore/should_compile/T28158.stderr
- testsuite/tests/simplCore/should_compile/all.T
Changes:
=====================================
compiler/GHC/Core/Opt/CprAnal.hs
=====================================
@@ -173,6 +173,25 @@ So currently we have
1. Strictness
2. CPR
3. worker/wrapper (for strictness and CPR)
+
+Wrinkles
+
+(CPR1) We have a flag `-fcpr-anal`, which sets `Opt_CprAnal`, enabled in -O1 and
+ -O1. Strangely, it does /not/ switch off CPR analysis! Rather, it just
+ switches off the worker/wrapper exploitation of CPR analysis, in `mkWWcpr_entry`.
+ The analysis itself runes whenever `-fstrictness` is on.
+
+ This is peculiar and, I suspect accidental. It would make more sense to switch
+ off the analysis itself with `-fno-cpr-anal`.
+
+ It goes back to at least
+ commit ecb1752ffa12dfa71053f640e6cce64d15e47e8f
+ Author: Christiaan Baaij <christiaan.baaij(a)gmail.com>
+ Date: Wed Aug 5 14:22:14 2015 +0200
+
+ Make -fcpr-off a dynamic flag
+
+ This note is just a breadcrumb to inform the next person who trips over this.
-}
--
@@ -343,7 +362,7 @@ cprTransform env id args
-- Any local binding, except for data structure bindings
-- See Note [Efficient Top sigs in SigEnv]
| Just sig <- lookupSigEnv env id
- = applyCprTy (getCprSig sig) (length args)
+ = applyCprTy (cprSigType sig) (length args)
-- See Note [CPR for data structures]
| Just rhs <- cprDataStructureUnfolding_maybe id
= fst $ cprAnal env rhs
@@ -362,7 +381,7 @@ cprTransform env id args
= cprTransformDataConWork env con args
-- Imported function
| otherwise
- = applyCprTy (getCprSig (idCprSig id)) (length args)
+ = applyCprTy (cprSigType (idCprSig id)) (length args)
-- | Precise, hand-written CPR transformers for select Ids
cprTransformBespoke :: Id -> [(CprType, CoreArg)] -> Maybe CprType
@@ -870,27 +889,42 @@ Does f have the CPR property? Well, no.
However, if the strictness analyser has figured out (in a previous
iteration) that it's strict, then we DON'T need to forget the CPR info.
Instead we can retain the CPR info and do the thunk-splitting transform
-(see WorkWrap.splitThunk).
+(see Note [Thunk splitting] esp (B) CPR-led thunk splitting).
This made a big difference to PrelBase.modInt, which had something like
modInt = \ x -> let r = ... -> I# v in
...body strict in r...
-r's RHS isn't a value yet; but modInt returns r in various branches, so
-if r doesn't have the CPR property then neither does modInt
+r's RHS isn't a value yet; but `modInt` returns `r` in various branches, so
+if `r` doesn't have the CPR property then neither does `modInt`
+
Another case I found in practice (in Complex.magnitude), looks like this:
- let k = if ... then I# a else I# b
- in ... body strict in k ....
+ let k* = if ... then I# a else I# b
+ in ... body strict in k ....
(For this example, it doesn't matter whether k is returned as part of
the overall result; but it does matter that k's RHS has the CPR property.)
+
Left to itself, the simplifier will make a join point thus:
- let $j k = ...body strict in k...
- if ... then $j (I# a) else $j (I# b)
+ let $j k = ...body strict in k...
+ if ... then $j (I# a) else $j (I# b)
+
With thunk-splitting, we get instead
- let $j x = let k = I#x in ...body strict in k...
- in if ... then $j a else $j b
+ let k* = case (if ... then I# a else I# b) of I# z -> I# z
+ in ... body strict in k ....
+Now the simplifier should pull out the `case` to give
+ case (if ... then I# a else I# b) of I# z ->
+ let k = I# z in ... body strict in k ...
+Now case-of-if will give
+ let $j z = let k = I# z in ...body strict in k... in
+ if ... then $j a else $j b
This is much better; there's a good chance the I# won't get allocated.
+TL'DR: During CPR analysis we want to give `k` the CPR property in `body`.
+
+What if the type involved has more than one constructor? E.g.
+ let k* = if ... then Just a else Just b
+ in ... body strict in k ....
+That is good too: see (TS5) in Note [Thunk splitting]
-But what about botCpr? Consider
+Finally, what about botCpr? Consider
lvl = error "boom"
fac -1 = lvl
fac 0 = 1
=====================================
compiler/GHC/Core/Opt/Simplify/Iteration.hs
=====================================
@@ -51,7 +51,6 @@ import GHC.Types.Literal ( litIsLifted ) --, mkLitInt ) -- temporarily comment
import GHC.Types.SourceText
import GHC.Types.Id
import GHC.Types.Id.Info
-import GHC.Types.Cpr( isTopCprSig )
import GHC.Types.InlinePragma
import GHC.Types.Name ( mkSystemVarName, isExternalName, getOccFS )
import GHC.Types.Demand
@@ -1830,7 +1829,7 @@ simplNonRecE :: HasDebugCallStack
simplNonRecE env from_what bndr (rhs, rhs_se) body cont
| assertPpr (isId bndr && not (isJoinId bndr)) (ppr bndr) True
- , useStrictBind env from_what bndr
+ , useStrictBind env from_what bndr rhs
= -- Evaluate RHS strictly
simplExprF (rhs_se `setInScopeFromE` env) rhs
(StrictBind { sc_bndr = bndr, sc_body = body, sc_from = from_what
@@ -1865,11 +1864,10 @@ simplRecE env pairs body cont
; return (floats1 `addFloats` floats2, expr') }
-useStrictBind :: SimplEnv -> FromWhat -> InId -> Bool
+useStrictBind :: SimplEnv -> FromWhat -> InId -> InExpr -> Bool
-- Can we use a StrictBind continuation for this let-binding?
--- If so, return a binder that is suitable to become a lambda binder,
--- i.e. one satisfying `lamBndrInfoOK`; see (SB3) in Note [StrictBind]
-useStrictBind env from_what bndr
+-- See (SB3) in Note [StrictBind]
+useStrictBind env from_what bndr rhs
-- If we are coming from a beta-reduction (FromBeta) we must
-- establish the let-can-float invariant, so we must go via StrictBind
-- If not, the invariant holds already, and it's optional.
@@ -1880,6 +1878,10 @@ useStrictBind env from_what bndr
| not (isStrUsedDmd dmd_info)
= False
+ -- Not if the RHS is ok-for-spec; no benefit
+ | exprOkForSpeculation rhs
+ = False
+
-- Not if case-of-case is off
-- See (SB1) in Note [StrictBind]
| not (seCaseCase env)
@@ -1894,8 +1896,6 @@ useStrictBind env from_what bndr
| isStableUnfolding (unfoldingInfo info)
|| not (isEmptyRuleInfo (ruleInfo info))
|| not (isAlwaysActive (inlinePragmaActivation (inlinePragInfo info)))
- || not (isNopSig (dmdSigInfo info))
- || not (isTopCprSig (cprSigInfo info))
= False
| otherwise
@@ -4243,9 +4243,8 @@ mkDupableAlt _env case_bndr jfloats (Alt con alt_bndrs alt_rhs_in)
, alt') }
-- See Note [Duplicated env]
-{-
-Note [Do not add unfoldings to join points at birth]
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+{- Note [Do not add unfoldings to join points at birth]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider this (#15360)
case (case (case (case ...))) of
@@ -4316,7 +4315,7 @@ The simplifier will find
(Var v) with continuation
Select (pn -> rn) (
Select [I# a -> I# a] (
- StrictBind body Stop
+ StrictBind body Stop))
So we'll call mkDupableCont on
Select [I# a -> I# a] (StrictBind body Stop)
@@ -4455,7 +4454,7 @@ hack and bit us in multiple small and not-so-small ways
Consider this
case (case .. ) of c {
- I# c# -> ....c....
+ I# c# -> ....c.... }
If we make a join point with c but not c# we get
$j = \c -> ....c....
@@ -4655,30 +4654,43 @@ We simplify `rhs` with a StrictBind continuation that continues with
invariants] in GHC.Core. But a let-binder `x` usually has IdInfo that a
lambda binder may not have (an unfolding, arity, a demand signature...).
- So `useStrictBind_maybe` zaps that info, keeping only the occurrence info
- and the demand info. If it happens to stay as a let-binding arity info will
- be re-derived, so nothing is lost.
+ So when we duplicate StrictBind, in `mkDupableContWithDmds`, we use
+ `mkLamBndrFromLetBndr` to zap that info, keeping only the occurrence
+ info and the demand info.
- The exceptions are RULES, a stable unfolding, and a non-default inlining
- activation: these cannot be re-derived, and we have nowhere convenient to
- put them if `x` becomes a lambda binder. For example:
+ However, if the let-binder has
+ * RULES
+ * a stable unfolding
+ * a non-default inlining activation
+ we'd permanently lose these things if we lambda-bind it. For example:
let {-# NOINLINE x #-}
x! = case y of { ... }
in blah
- If we make a join point j x = blah, we have nowhere convenient
- to put that NOINLINE. Ditto INLINE or RULES. So in these cases we
- simply don't use StrictBind. It's very unusual, so no harm done.
- But it does happen; one example is this, in the Applicative (ST s)
- instance in GHC.Internal.Control.Monad.St.Lazy.Imp
+ If we make a join point j x = blah, we have nowhere convenient to put that
+ NOINLINE. Ditto INLINE or RULES. It's unusual. But it happens; one example
+ is the Applicative (ST s) instance in GHC.Internal.Control.Monad.St.Lazy.Imp
{-# NOINLINE res1 #-}
!res1 = unST fm s
- TL;DR: the sc_bndr::Id field in StrictBind always satisfies `lamBndrInfoOK`.
- This means that in the above example { x! = case y of ... } we won't
- float the `case y` out. And perhaps that's fine because of the NOINLNE.
- We could imagine instead imposing these conditions only when we /duplicate/
- the StrictBind, rather than when we /create/ it, but that would require a
- bigger refactor.
+ So in these cases we simply don't use StrictBind -- see `useStrictBind`. We
+ could imagine instead imposing these conditions only when we /duplicate/ the
+ StrictBind, rather than when we /create/ it, but that would require a bigger
+ refactor.
+
+ What if a thunk has a strictness signature, or CPR information? We
+ could make `useStrictBind` say False in these cases too, but that turns
+ out to be a net loss: keeping a thunk is worse than losing the strictness
+ information. Example, where f1,f2 are both strict:
+ let f* {- Str=<S> -} = case x of { True -> f1; False -> f2 }
+ in body
+ Keeping it as-is would use CBV for calls of `f` in `body`. But
+ allowing StrictBind would give us
+ join j f* = body
+ in case x of { True -> j f1; False -> j f2 }
+ which avoids the thunk. It's a trade-off.
+
+ For CPR info, see Note [Thunk splitting] in GHC.Core.Opt.WorkWrap,
+ especially (B) CPR-led thunk splitting.
Note [Join point abstraction] Historical note
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
=====================================
compiler/GHC/Core/Opt/WorkWrap.hs
=====================================
@@ -598,13 +598,19 @@ tryWW ww_opts is_rec fn_id rhs
= splitFun ww_opts new_fn_id rhs
-- See Note [Thunk splitting]
- | isNonRec is_rec, is_thunk
- = splitThunk ww_opts is_rec new_fn_id rhs
+ | isNonRec is_rec -- See (TS4)
+ , is_thunk -- All join points go via splitFun
+ = do { -- Try strictness then CPR; see (TS5)
+ rhs' <- splitThunkStr ww_opts new_fn_id rhs `orElseM`
+ splitThunkCpr ww_opts new_fn_id rhs `orElseM`
+ return rhs
+ ; return [ (new_fn_id, rhs') ] }
| otherwise
= return [ (new_fn_id, rhs) ]
where
+ is_join = isJoinId fn_id
fn_info = idInfo fn_id
(wrap_dmds, _) = splitDmdSig (dmdSigInfo fn_info)
new_fn_id = zap_join_cpr $ zap_usage fn_id
@@ -613,14 +619,13 @@ tryWW ww_opts is_rec fn_id rhs
-- See Note [Zapping DmdEnv after Demand Analyzer] and
-- See Note [Zapping Used Once info in WorkWrap]
- zap_join_cpr id
- | isJoinId id = id `setIdCprSig` topCprSig
- | otherwise = id
+ zap_join_cpr id | is_join = id `setIdCprSig` topCprSig
+ | otherwise = id
-- See Note [Don't w/w join points for CPR]
- is_fun = notNull wrap_dmds || isJoinId fn_id
- is_thunk = not is_fun && not (exprIsHNF rhs) && not (isJoinId fn_id)
- && not (isUnliftedType (idType fn_id))
+ is_fun = notNull wrap_dmds || is_join
+ is_thunk = not (exprIsHNF rhs)
+ && not (isUnliftedType (idType fn_id))
{-
Note [Zapping DmdEnv after Demand Analyzer]
@@ -806,7 +811,7 @@ splitFun ww_opts fn_id rhs
(wrap_dmds, div) = splitDmdSig (dmdSigInfo fn_info)
- cpr_ty = getCprSig (cprSigInfo fn_info)
+ cpr_ty = cprSigType (cprSigInfo fn_info)
-- Arity of the CPR sig should match idArity when it's not a join point.
-- See Note [Arity trimming for CPR signatures] in GHC.Core.Opt.CprAnal
cpr = assertPpr (isJoinId fn_id || cpr_ty == topCprType || ct_arty cpr_ty == arityInfo fn_info)
@@ -957,114 +962,177 @@ the form [Demand=<L,1*(C(1,...(C(1,U))))>]
Note [Thunk splitting]
~~~~~~~~~~~~~~~~~~~~~~
-Suppose x is used strictly; never mind whether it has the CPR
-property. I'll use a '*' to mean "x* is demanded strictly".
-
- let
- x* = x-rhs
+The worker/wrapper split mainly affects let-bound /functions/. But we can also use
+demand and CPR information to improve let-bound /thunks/. Specifically:
+
+* (A) Demand-led thunk splitting:
+ If a thunk is demanded strictly, perhaps nestedly, we can turn it into a
+ case, perhaps nestedly. For example
+ let x :: (Int, Int)
+ {- Dmd = SP(S,L) -}
+ x = rhs
+ in body
+ We would ultimately like to get
+ case rhs of x { (a,b) ->
+ case a of { I# a# ->
+ body
+
+ This is much better: no thunk for `rhs`; and known-data-con unfoldings for `x`
+ and `a` inside `body`.
+
+* (B) CPR-led thunk splitting:
+ If a thunk has the (possibly-nested) CPR property /and/ is demanded strictly
+ at top level, we can again generate a case
+ let x :: (Int, Int)
+ {- Dmd = S, Cpr = (_, I# _) -}
+ x = rhs
+ in body
+ The CPR info says that if `x` is evaluated (which it is), it'll return a pair,
+ whose second component can very cheaply be evaluated to a (I# b#). We would
+ like to end up with
+ case rhs of x { (a,b) ->
+ case b of { I# b# ->
+ body
+ which is good for the same reasons as before. See (TS3) for an example.
+
+Implementation
+~~~~~~~~~~~~~~
+The worker/wrapper pass does not generate these nested case expressions directly.
+Instead it generates a regular let-binding but, since the binder is marked as
+strict, any `case` expressions in the RHS will float out. Specifically:
+
+(TS1) For (A), `splitThunkStr` generates the binding
+ let x! = case rhs of { (a,b) ->
+ case a of { I# a# ->
+ (I# a, b)
+ Now when the Simplifier floats the `case` expressions out, we get
+ case rhs of { (a,b) ->
+ case a of { I# a# ->
+ let x = (I# a, b)
in body
+ which is equivalent to the expression in (A) above.
-splitThunk transforms like this:
- let
- x* = let x = x-rhs in
- case x of { I# a -> I# a }
- in body
+ `splitThunkStr` also works on /absent/ thunks: see (TS6).
-This is a little strange: we are re-using the same `x` in the RHS; and
-the RHS takes `x` apart and reboxes it. But because the outer 'let' is
-strict, and the inner let mentions `x` only once, the simplifier
-transform it to
- case x-rhs of
- I# a -> let x* = I# a
- in body
-
-That is good: in `body` we know the form of `x`, which
- * gives the CPR property, and
- * allows case-of-case to happen on x
-
-Notes
-* I tried transforming like this:
- let
- x* = let x = x-rhs in
- case x of { I# a -> x }
- in body
- where I return `x` itself, rather than reboxing it. But this
- turned out to cause some regressions, which I never fully
- investigated.
-
-* Suppose x-rhs is itself a case:
- x-rhs = case e of { T -> I# e1; F -> I# e2 }
- Then we'll get
- join j a = let x* = I# a in body
- in case e of { T -> j e1; F -> j e2 }
- which is good (no boxing). But in the original, unsplit program
- we would transform
- let x* = case e of ... in body
- ==> join j2 x = body
- in case e of { T -> j2 (I# e1); F -> j (I# e2) }
- which is not good (boxing).
+ Rather cleverly, `splitThunkStr` uses `mkWWstr_one`, the /existing/ function
+ argument w/w splitting function, to do the unpacking. This automatically
+ deals with nested strictness.
-* In fact, splitThunk uses the function argument w/w splitting
- function, mkWWstr_one, so that if x's demand is deeper (say U(U(L,L),L))
- then the splitting will go deeper too.
+(TS2) For (B), `splitThunkCpr` behaves exactly analogously, again
+ using `mkWWcpr_one` to do the unpacking. It works only for /demanded/ thunks.
-* For recursive thunks, the Simplifier is unable to float `x-rhs` out of
- `x*`'s RHS, because `x*` occurs freely in `x-rhs`, and will just change it
- back to the original definition, so we just split non-recursive thunks.
+Wrinkles:
-Note [Thunk splitting for top-level binders]
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Top-level bindings are never strict. Yet they can be absent, as T14270 shows:
-
- module T14270 (mkTrApp) where
- mkTrApp x y
- | Just ... <- ... typeRepKind x ...
- = undefined
- | otherwise
- = undefined
- typeRepKind = Tick scc undefined
-
-(T19180 is a profiling-free test case for this)
-Note that `typeRepKind` is not exported and its only use site in
-`mkTrApp` guards a bottoming expression. Thus, demand analysis
-figures out that `typeRepKind` is absent and splits the thunk to
-
- typeRepKind =
- let typeRepKind = Tick scc undefined in
- let typeRepKind = absentError in
- typeRepKind
-
-But now we have a local binding with an External Name
-(See Note [About the NameSorts]). That will trigger a CoreLint error, which we
-get around by localising the Id for the auxiliary bindings in 'splitThunk'.
+(TS3) Here's an example of (B), thunk-splitting based on CPR information.
+ Suppose we have
+ let x! = case e of { T -> Just e1; F -> Just e2 }
+ in body
+ If the Simplifier floats the `case` out, we get
+ join j2 x = body
+ in case e of { T -> j2 (Just e1); F -> j2 (Just e2) }
+ which is not good (boxing).
+
+ If we first do the thunk-splitting transformation, we get
+ let x! = case (case e of { T -> Just e1; F -> Just e2 }) of
+ Just a -> Just a
+ in body
+
+ Now when the Simplifier floats we will get:
+ join j a = let x = Just a in body
+ in case e of { T -> j e1; F -> j e2 }
+ which is much better (no boxing).
+
+(TS4) We only do thunk-splitting for thunks that are non-recursive
+ For recursive thunks, the Simplifier is unable to float `rhs` out of
+ x's RHS, because `x` occurs freely in `rhs`, and will just change it
+ back to the original definition.
+
+(TS5) Notice that (B) CPR-led thunk splitting can be useful:
+ * when multi-constructor data types are involved, so that the argument-unboxing
+ mechanism (A) is impotent. See the example in (TS3), which uses `Maybe`.
+ * when the binder is only demanded head-strictly, but CPR has nested information.
+
+ So (A) and (B) have complementary benefits. We might do even better by
+ /combining/ (A) and (B), but at the moment we try (A) first, and then try (B)
+ if (A) is impotent. Combining them would be more work.
+
+(TS6) We can also exploit /absence/. Consider
+ let x {-# Dmd = A #-} = rhs
+ in body
+ Generally speaking `x` will be absent becuase it is passed to functions that
+ don't use it, in which case worker/wrapper on those calls will make `x` unused.
+ But suppose `x` is absent inside a /lazy/ argument:
+ let f p = (fst p, 99) in
+ let x = rhs in
+ f (True, x)
+ Here f's argument is lazy, but `x` is definitely absent, and we could replace
+ `x` with an absent filler. Using (TS1) would give us
+ let x = absentError "urk" in ...
+ which is great.
+
+ So `splitThunkStr` works /regardless/ of the demand on `x`; whether it fires is
+ determined only by the `useful` flag returned by `mkWWstr_one`.
+
+(TS7) Adopting (TS6) leads to one other complication: a top-level binder with
+ an External Name (see Note [About the NameSorts]) can be Absent. If so,
+ it must not be used as a local binder in the `Let` created by `splitThunkStr`.
+ T19180 is a test case for this rather obscure situation.
+
+ Solution: use `localiseId` to localise the binder for the `Let`.
+
+(TS8) Consider out poster child test case for `splitThunkCpr`, in (TS3).
+ x! = case e of { True -> Just 1; False -> Just 2 }
+ But suppose we have `-fworker-wrapper-cbv` enabled (reminder: see
+ Note [Worker/wrapper for strict arguments]). Then alas `splitThunkStr`
+ will fire, but it'll be a no-op in this case. But since it fires, `splitThunkCpr`
+ never gets a chance.
+
+ Hacky but effective solution: switch off `wo_unlift_strict` locally in `splitThunkStr`.
-}
--- | See Note [Thunk splitting].
---
--- splitThunk converts the *non-recursive* binding
+-- | splitThunkStr converts the *non-recursive* binding
-- x = e
-- into
--- x = let x' = e in
--- case x' of I# y -> let x' = I# y in x'
--- See comments above. Is it not beautifully short?
--- Moreover, it works just as well when there are
--- several binders, and if the binders are lifted
--- E.g. x = e
--- --> x = let x' = e in
--- case x' of (a,b) -> let x' = (a,b) in x'
--- Here, x' is a localised version of x, in case x is a
--- top-level Id with an External Name, because Lint rejects local binders with
--- External Names; see Note [About the NameSorts] in GHC.Types.Name.
---
--- How can we do thunk-splitting on a top-level binder? See
--- Note [Thunk splitting for top-level binders].
-splitThunk :: WwOpts -> RecFlag -> Var -> Expr Var -> UniqSM [(Var, Expr Var)]
-splitThunk ww_opts is_rec x rhs
- = assert (not (isJoinId x)) $
- do { let x' = localiseId x -- See comment above
- ; (useful,_args, wrap_fn, fn_arg)
- <- mkWWstr_one ww_opts x' NotMarkedStrict
- ; let res = [ (x, Let (NonRec x' rhs) (wrap_fn fn_arg)) ]
- ; if useful then assertPpr (isNonRec is_rec) (ppr x) -- The thunk must be non-recursive
- return res
- else return [(x, rhs)] }
+-- x = let x = e in
+-- case x of I# y -> I# y
+-- See Note [Thunk splitting].
+splitThunkStr :: WwOpts -> Var -> CoreExpr -> UniqSM (Maybe CoreExpr)
+splitThunkStr ww_opts x rhs
+ = -- NB: does not depend on x's demand being strict; it might be absent, see (TS6)
+ do { let x' = localiseId x -- See (TS7)
+ ww_opts' = ww_opts { wo_unlift_strict = False } -- See (TS8)
+ ; (useful, _transit_vars, wrap_fn, fn_arg) <- mkWWstr_one ww_opts' x' NotMarkedStrict
+ -- Use mkWWstr_one: see (TS1) in Note [Thunk splitting]
+
+ ; if useful
+ then return (Just (Let (NonRec x' rhs) $
+ wrap_fn fn_arg))
+ else return Nothing }
+
+splitThunkCpr :: WwOpts -> Var -> CoreExpr -> UniqSM (Maybe CoreExpr)
+-- See Note [Thunk splitting]
+-- Given x* = rhs, where x* is used outermost-strictly, and x* has a (nested) CPR
+-- property, say Just (Just _), return this new RHS:
+-- let x' = rhs in
+-- case x' of { Just p -> case p of { Just q -> -- Unpacking code
+-- Just (Just q) }} -- Repacking code
+-- Works for multi-constructor data types, where splitThunkStr will fail
+splitThunkCpr ww_opts x rhs
+ | wo_cpr_anal ww_opts -- See (CPR1) in Note [Phase ordering] on GHC.Opt.CprAnal
+ , isStrUsedDmd (idDemandInfo x) -- See (TS2)
+ = assertPpr (cprTypeArity cpr_type == 0) (ppr x) $ -- It's a thunk
+ do { (useful, _transit_vars, rebuild_result, unpacker) <- mkWWcpr_one ww_opts x cpr
+ -- Use mkWWcpr_one: see (TS2) in Note [Thunk splitting]
+ ; if useful
+ then return (Just (Let (NonRec x rhs) $
+ unpacker rebuild_result))
+ else return Nothing }
+
+ | otherwise
+ = return Nothing
+ where
+ cpr_type :: CprType
+ cpr_type = cprSigType (idCprSig x)
+ cpr :: Cpr
+ cpr = cprTypeCpr cpr_type
+
=====================================
compiler/GHC/Core/Opt/WorkWrap/Utils.hs
=====================================
@@ -8,7 +8,7 @@ A library for the ``worker\/wrapper'' back-end to the strictness analyser
{-# LANGUAGE ViewPatterns #-}
module GHC.Core.Opt.WorkWrap.Utils
- ( WwOpts(..), mkWwBodies, mkWWstr, mkWWstr_one
+ ( WwOpts(..), mkWwBodies, mkWWstr, mkWWstr_one, mkWWcpr_one
, needsVoidWorkerArg
, DataConPatContext(..)
, UnboxingDecision(..), canUnboxArg
@@ -139,13 +139,18 @@ data WwOpts
= MkWwOpts
{ -- | Environment of type/data family instances
wo_fam_envs :: !FamInstEnvs
+
, -- | Options for the "Simple optimiser"
wo_simple_opts :: !SimpleOpts
+
, -- | Whether to enable "Constructed Product Result" analysis.
-- (Originally from DOI: 10.1017/S0956796803004751)
+ -- See (CPR1) in Note [Phase ordering] on GHC.Opt.CprAnal
wo_cpr_anal :: !Bool
+
, -- | Used for absent argument error message
wo_module :: !Module
+
, -- | Generate workers even if the only effect is some args get passed
-- unlifted. See Note [WW for calling convention]
wo_unlift_strict :: !Bool }
@@ -230,8 +235,7 @@ mkWwBodies opts fun_id ww_arity arg_vars res_ty demands res_cpr
; let (work_args, work_marks) = unzip work_args_str
-- Do CPR w/w. See Note [Always do CPR w/w]
- ; (useful2, wrap_fn_cpr, work_fn_cpr)
- <- mkWWcpr_entry opts res_ty' res_cpr
+ ; (useful2, wrap_fn_cpr, work_fn_cpr) <- mkWWcpr_entry opts res_ty' res_cpr
; let (work_lam_args, work_call_args, work_call_str)
| needsVoidWorkerArg fun_id arg_vars work_args
@@ -662,8 +666,10 @@ canUnboxResult fam_envs ty cpr
= DontUnbox
where
- -- See Note [non-algebraic or open body type warning]
- open_body_ty_warning = warnPprTrace True "canUnboxResult: non-algebraic or open body type" (ppr ty) Nothing
+ -- See Note [Non-algebraic or open body type warning]
+ open_body_ty_warning
+ = warnPprTrace True "canUnboxResult: non-algebraic or open body type"
+ (ppr ty) Nothing
@@ -808,7 +814,7 @@ match the number of constructor arguments; this happened in #8037.
If so, the worker/wrapper split doesn't work right and we get a Core Lint
bug. The fix here is simply to decline to do w/w if that happens.
-Note [non-algebraic or open body type warning]
+Note [Non-algebraic or open body type warning]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There are a few cases where the W/W transformation is told that something
returns a constructor, but the type at hand doesn't really match this. One
@@ -829,8 +835,60 @@ This warning also triggers for the stream fusion library within `text`.
We can't easily W/W constructed results like `Stream` because we have no simple
way to express existential types in the worker's type signature.
+Note [Worker/wrapper for strict arguments]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Consider
+ f x = case x of
+ [] -> blah
+ (y:ys) -> f ys
+
+Clearly `f` is strict, but its argument is not a product type, so by default
+we don't worker/wrapper it. But it is arguably valuable to do so. We could
+do this:
+
+ f x = case x of xx { DEFAULT -> $wf xx }
+ $wf xx = case xx of
+ [] -> blah
+ (y:ys) -> f ys
+
+Now the worker `$wf` knows that its argument `xx` will be evaluated
+and properly tagged, so the code for the `case xx` does not need to do
+an "eval" (see `GHC.StgToCmm.Expr.cgCase`). A call (f (a:as)) will
+have the wrapper inlined, and will drop the `case x`, so no eval
+happens at all.
+
+The worker `$wf` is a CBV function (see `Note [CBV Function Ids: overview]`
+in GHC.Types.Id.Info) and the code generator guarantees that every
+call to `$wf` has a properly tagged argument (see `GHC.Stg.EnforceEpt.Rewrite`).
+
+Is this a win? Not always:
+* It can cause slight code size increases. This is since we push evals to every
+ call sites which there might be many. And the evals will only disappear at
+ call sites where we already known that the argument is evaluated.
+
+* It will also cause many more functions to get a worker/wrapper split
+ which can play badly with rules (see Ticket #20364). In particular
+ if you depend on rules firing on functions marked as NOINLINE
+ without marking use sites of these functions as INLINE or INLINEABLE
+ then things will break.
+
+ But if you want a function to match in a RULE, it is /in any case/ good
+ practice to have a `INLINE[1]` or `NOINLNE[1]` pragma, to ensure that it
+ doesn't inline until the rule has had a chance to fire.
+
+So there is a flag, `-fworker-wrapper-cbv`, to control whether we do
+w/w on strict arguments (internally `Opt_WorkerWrapperUnlift`). The
+flag is off by default. The choice is made in
+GHC.Core.Opt.WorkWrap.Utils.wwUseForUnlifting
+
+See also `Note [WW for calling convention]`
+
Note [WW for calling convention]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ NB: This Note is more of a discussion.
+ Read Note [Worker/wrapper for strict arguments] first,
+ which covers the same ground with more precision
+
If we know a function f will always evaluate a particular argument
we might decide that it should rather get evaluated by the caller.
We call this "unlifting" the argument.
@@ -856,10 +914,9 @@ Hence we have the following strategies with different trade-offs:
A) Never do W/W *just* for unlifting of arguments.
+ Very conservative - doesn't break any rules
- - Lot's of performance left on the table
+ - Lots of performance left on the table
-B) Do W/W on just about anything where it might be
- beneficial.
+B) Do W/W on just about anything where it might be beneficial.
+ Exploits pretty much every opportunity for unlifting.
- A bit of compile time/code size cost for all the wrappers.
- Can break rules which would otherwise fire. See #20364.
@@ -883,10 +940,10 @@ C) Unlift *any* (non-boot exported) functions arguments if they are strict.
functionality. I haven't tried this approach because it's not trivial to
implement and doing W/W splits seems to work well enough.
-Currently we use the first approach A) by default, with a flag that allows users
-to fall back to the more aggressive approach B).
+Currently we use the first approach (A) by default, with a flag `-fworker-wrapper-cbv`
+that allows users to fall back to the more aggressive approach (B).
-I also tried the third approach C) using eta-expansion at call sites to avoid
+I also tried the third approach (C) using eta-expansion at call sites to avoid
modifying the PAP-handling code which wasn't fruitful. See
https://gitlab.haskell.org/ghc/ghc/-/merge_requests/5614#note_389903. We could
still try to do C) in the future by having PAP calls which will evaluate the
@@ -895,53 +952,6 @@ be neither a small nor simple change so we stick with A) and a flag for B) for
now.
See also Note [EPT enforcement] and Note [CBV Function Ids: overview]
-
-Note [Worker/wrapper for strict arguments]
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Consider
- f x = case x of
- [] -> blah
- (y:ys) -> f ys
-
-Clearly `f` is strict, but its argument is not a product type, so by default
-we don't worker/wrapper it. But it is arguably valuable to do so. We could
-do this:
-
- f x = case x of xx { DEFAULT -> $wf xx }
- $wf xx = case xx of
- [] -> blah
- (y:ys) -> f ys
-
-Now the worker `$wf` knows that its argument `xx` will be evaluated
-and properly tagged, so the code for the `case xx` does not need to do
-an "eval" (see `GHC.StgToCmm.Expr.cgCase`). A call (f (a:as)) will
-have the wrapper inlined, and will drop the `case x`, so no eval
-happens at all.
-
-The worker `$wf` is a CBV function (see `Note [CBV Function Ids: overview]`
-in GHC.Types.Id.Info) and the code generator guarantees that every
-call to `$wf` has a properly tagged argument (see `GHC.Stg.EnforceEpt.Rewrite`).
-
-Is this a win? Not always:
-* It can cause slight codesize increases. This is since we push evals to every
- call sites which there might be many. And the evals will only disappear at
- call sites where we already known that the argument is evaluated.
-
-* It will also cause many more functions to get a worker/wrapper split
- which can play badly with rules (see Ticket #20364). In particular
- if you depend on rules firing on functions marked as NOINLINE
- without marking use sites of these functions as INLINE or INLINEABLE
- then things will break.
- But if you want a function to match in a RULE, it is /in any case/ good practice to
- have a `INLINE[1]` or `NOINLNE[1]` pragma, to ensure that it doesn't inline until
- the rule has had a chance to fire.
-
-So there is a flag, `-fworker-wrapper-cbv`, to control whether we do
-w/w on strict arguments (internally `Opt_WorkerWrapperUnlift`). The
-flag is off by default. The choice is made in
-GHC.Core.Opt.WorkWrape.Utils.wwUseForUnlifting
-
-See also `Note [WW for calling convention]` in GHC.Core.Opt.WorkWrap.Utils
-}
{-
@@ -985,6 +995,12 @@ mkWWstr opts args str_marks
-- * wrap_arg assumes work_args are in scope, and builds a ConApp that
-- reconstructs the RHS of wrap_var that we pass to the original RHS
-- See Note [Worker/wrapper for Strictness and Absence]
+--
+-- E.g. mkWWstr_one (x :: (Int,Int) with strictess saying to unbox the pair and second Int
+-- = ( True -- useful
+-- , [p,q#], -- work_args
+-- , \e -> case x of (p,q) -> case q of I# q# -> e -- wrap_fn
+-- , (p, I# q) ) -- wrap_arg
mkWWstr_one :: WwOpts
-> Var
-> StrictnessMark
@@ -1008,7 +1024,7 @@ mkWWstr_one opts arg str_mark =
DontUnbox
| isStrictDmd arg_dmd || isMarkedStrict str_mark
- , wwUseForUnlifting opts -- See Note [WW for calling convention]
+ , wwUseForUnlifting opts -- See Note [Worker/wrapper for strict arguments]
, not (isFunTy arg_ty)
, not (isUnliftedType arg_ty) -- Already unlifted!
-- NB: function arguments have a fixed RuntimeRep,
@@ -1163,7 +1179,7 @@ function is worthy for splitting:
2b But if e.g. a large tuple or product type is always demanded we might
decide to "unlift" it. That is tighten the calling convention for that
argument to require it to be passed as a pointer to the value itself.
- See Note [WW for calling convention].
+ See Note [Worker/wrapper for strict arguments]
3. In all other cases (e.g., lazy, used demand and not eval'd),
'finaliseArgBoxities' will have cleared the Boxity flag to 'Boxed'
@@ -1604,7 +1620,9 @@ mkWWcpr_entry
CoreExpr -> CoreExpr) -- New worker. 'nop_fn' if not useful
-- ^ Entrypoint to CPR W/W. See Note [Worker/wrapper for CPR] for an overview.
mkWWcpr_entry opts body_ty body_cpr
- | not (wo_cpr_anal opts) = return (boringSplit, nop_fn, nop_fn)
+ | not (wo_cpr_anal opts) -- See (CPR1) in Note [Phase ordering] on GHC.Opt.CprAnal
+ = return (boringSplit, nop_fn, nop_fn)
+
| otherwise = do
-- Part (1)
res_bndr <- mk_res_bndr body_ty
@@ -1637,7 +1655,9 @@ mk_res_bndr body_ty = do
-- 1. A 'WwUse' capturing whether the split does anything useful.
-- 2. The list of transit variables (see the Note).
-- 3. The result builder expression for the wrapper. The original case binder if not useful.
--- 4. The result unpacking expression for the worker. 'nop_fn' if not useful.
+-- Assumes that the transit vars are in scope
+-- 4. The result unpacking expression for the worker. 'nop_fn' if not useful
+-- Brings the transit vars into scope
type CprWwResultOne = (WwUse, OrdList Var, CoreExpr , CoreExpr -> CoreExpr)
type CprWwResultMany = (WwUse, OrdList Var, [CoreExpr], CoreExpr -> CoreExpr)
@@ -1768,7 +1788,7 @@ To achieve said transformation, 'mkWWcpr_entry'
what belongs in the case scrutinee of the unpacker through the communicated
Id `r`: The unpacking expression will be free in that variable.
(This is a similar contract as that of 'mkWWstr_one' for strict args.)
- 3. 'mkWWstr_one' produces a bunch of *transit vars*: Those result variables
+ 3. 'mkWWcpr_one' produces a bunch of *transit vars*: Those result variables
that have to be transferred from the worker to the wrapper, where the
constructed result can be rebuilt, `a` and `b` above. Part (3) is
responsible for tupling them up in the worker and taking the tuple apart
=====================================
compiler/GHC/Types/Cpr.hs
=====================================
@@ -8,6 +8,7 @@
module GHC.Types.Cpr (
Cpr (ConCpr), topCpr, botCpr, flatConCpr, asConCpr,
CprType (..), topCprType, botCprType, flatConCprType,
+ cprTypeArity, cprTypeCpr,
lubCprType, applyCprTy, abstractCprTy, trimCprTy,
UnpackConFieldsResult (..), unpackConFieldsCpr,
CprSig (..), topCprSig, isTopCprSig, mkCprSigForArity, mkCprSig,
@@ -106,6 +107,12 @@ data CprType
-- 'ct_arty' arguments
}
+cprTypeArity :: CprType -> Arity
+cprTypeArity = ct_arty
+
+cprTypeCpr :: CprType -> Cpr
+cprTypeCpr = ct_cpr
+
instance Eq CprType where
a == b = ct_cpr a == ct_cpr b
&& (ct_arty a == ct_arty b || ct_cpr a == topCpr)
@@ -167,7 +174,7 @@ seqCprTy (CprType _ cpr) = seqCpr cpr
-- | The arity of the wrapped 'CprType' is the arity at which it is safe
-- to unleash. See Note [Understanding DmdType and DmdSig] in "GHC.Types.Demand"
-newtype CprSig = CprSig { getCprSig :: CprType }
+newtype CprSig = CprSig { cprSigType :: CprType }
deriving (Eq, Binary)
-- | Turns a 'CprType' computed for the particular 'Arity' into a 'CprSig'
=====================================
compiler/GHC/Utils/Monad.hs
=====================================
@@ -16,7 +16,7 @@ module GHC.Utils.Monad
, mapAccumLM
, mapSndM
, concatMapM
- , mapMaybeM
+ , mapMaybeM, orElseM
, anyM, allM, orM
, foldlM, foldlM_, foldrM, foldMapM
, whenM, unlessM
@@ -250,6 +250,14 @@ unlessM :: Monad m => m Bool -> m () -> m ()
unlessM condM acc = do { cond <- condM
; unless cond acc }
+-- | Monadic version of @orElse@
+infixr 4 `orElseM`
+orElseM :: Monad m => m (Maybe a) -> m a -> m a
+orElseM ma def = do { mb_r <- ma
+ ; case mb_r of
+ Just x -> return x
+ Nothing -> def }
+
-- | Like 'filterM', only it reverses the sense of the test.
filterOutM :: (Applicative m) => (a -> m Bool) -> [a] -> m [a]
filterOutM p =
=====================================
testsuite/tests/simplCore/should_compile/T28158.hs
=====================================
@@ -0,0 +1,22 @@
+{-# OPTIONS_GHC -fworker-wrapper-cbv #-}
+-- Adding this option makes things harder for splitThunkCpr, which
+-- this test is testing. See (TS8) in Note [Thunk splitting]
+
+module T28158 where
+
+-- Here we miss CPR on y
+-- It's a bit of an obscure example, but still; see #28158
+f :: a -> a -> a -> [Int] -> [Int]
+f a b c xs = let y = case xs of
+ [0] -> Just a
+ [1] -> Just b
+ _ -> Just c
+ in h y (case y of
+ Just z -> reverse (reverse (reverse (
+ reverse (reverse (reverse (
+ reverse (reverse xs)))))))
+ Nothing -> xs++xs)
+
+h :: Maybe a -> b -> b
+h (Just y) e = h Nothing e
+h Nothing e = e
=====================================
testsuite/tests/simplCore/should_compile/T28158.stderr
=====================================
@@ -0,0 +1,58 @@
+
+==================== Tidy Core ====================
+Result size of Tidy Core
+ = {terms: 98, types: 108, coercions: 0, joins: 1/1}
+
+Rec {
+$wh
+ = \ @a @b ds e ->
+ case ds of ds1 { __DEFAULT ->
+ case e of e1 { __DEFAULT ->
+ case ds1 of {
+ Nothing -> e1;
+ Just y -> $wh Nothing e1
+ }
+ }
+ }
+end Rec }
+
+h = \ @a @b ds e -> $wh ds e
+
+$wf
+ = \ @a a1 b c xs ->
+ join {
+ $j ww
+ = $wh
+ (Just ww)
+ (reverse1
+ (reverse1
+ (reverse1
+ (reverse1
+ (reverse1 (reverse1 (reverse1 (reverse1 xs []) []) []) []) [])
+ [])
+ [])
+ []) } in
+ case xs of {
+ [] -> jump $j c;
+ : ds ds1 ->
+ case ds of { I# ds2 ->
+ case ds2 of {
+ __DEFAULT -> jump $j c;
+ 0# ->
+ case ds1 of {
+ [] -> jump $j a1;
+ : ipv ipv1 -> jump $j c
+ };
+ 1# ->
+ case ds1 of {
+ [] -> jump $j b;
+ : ipv ipv1 -> jump $j c
+ }
+ }
+ }
+ }
+
+f = \ @a a1 b c xs -> $wf a1 b c xs
+
+
+
=====================================
testsuite/tests/simplCore/should_compile/all.T
=====================================
@@ -637,5 +637,5 @@ test('T27963', [grep_errmsg(r'f/42')], compile, ['-O -ddump-rule-firings'])
test('T27965', normal, compile, ['-O'])
test('T27965a', normal, compile, ['-O'])
test('T27965b', normal, compile, ['-O'])
-
+test('T28158', normal, compile, ['-O -dno-typeable-binds -dsuppress-all -dsuppress-uniques -ddump-simpl'])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1045f6c7f26ecab6e993a63aa567a91…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1045f6c7f26ecab6e993a63aa567a91…
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
1
0
25 Nov '26
Simon Peyton Jones pushed to branch wip/T28169 at Glasgow Haskell Compiler / GHC
Commits:
e832b4d2 by Simon Peyton Jones at 2026-11-25T00:48:55+00:00
Progress [skip ci]
- - - - -
5 changed files:
- compiler/GHC/Core/DataCon.hs
- compiler/GHC/Core/SimpleOpt.hs
- compiler/GHC/Core/TyCon.hs
- compiler/GHC/Core/Utils.hs
- compiler/GHC/Tc/TyCl/Build.hs
Changes:
=====================================
compiler/GHC/Core/DataCon.hs
=====================================
@@ -52,7 +52,6 @@ module GHC.Core.DataCon (
-- ** Predicates on DataCons
isNullarySrcDataCon, isNullaryRepDataCon,
- isLazyDataConRep,
isTupleDataCon, isBoxedTupleDataCon, isUnboxedTupleDataCon,
isUnboxedSumDataCon, isCovertGadtDataCon, isUnaryClassDataCon,
isVanillaDataCon, isNewDataCon, isTypeDataCon, isBoxingDataCon,
@@ -524,21 +523,27 @@ data DataCon
-- See Note [Bangs on data constructor arguments]
dcStricts :: [StrictnessMark],
- -- One mark for every field of the DataCon worker;
- -- if it's empty, then all fields are lazy,
- -- otherwise 1-1 with dataConRepArgTys.
+ -- One mark for every field of the DataCon /worker/
+ -- Lines up 1-1 with dataConRepArgTys
+ -- Relates only to user-specified strictness annotations,
+ -- not to liftedness or othewrise
+ -- E.g. data T a = MkT {-# UNPACK #-} !(S a) Int# !a
+ -- data S a = MkS a !a
+ -- Then the worker for MkT has four fields, the first two arising from
+ -- unpacking S. The corresponding strictness marks are [-,!,-,!]; again
+ -- the first two come from MkS
-- See also Note [Strict fields in Core] in GHC.Core
- -- for the effect on the strictness signature
+ -- for the effect on the strictness signature
dcFields :: [FieldLabel],
-- Field labels for this constructor, in the
-- same order as the dcOrigArgTys;
-- length = 0 (if not a record) or dataConSourceArity.
- dcIsLazy :: Bool
+ dcIsLazy :: Bool,
-- True if (a) all fields of the data con /worker/ are definitely lifted
-- (b) no field has a `StrictnessMark` that forces evaluation
- -- So if `dcIsLazy` is True then all fields are lazy thunks
+ -- So if `dcIsLazy` is True then all fields of the worker are lazy thunks
-- The curried worker function that corresponds to the constructor:
-- It doesn't have an unfolding; the code generator saturates these Ids
@@ -836,7 +841,7 @@ data DataConRep
, dcr_boxer :: DataConBoxer
- , dcr_arg_tys :: [Scaled Type] -- Final, representation argument types,
+ , dcr_arg_tys :: [Scaled Type] -- Final, representation /value/ argument types,
-- after unboxing and flattening,
-- and *including* all evidence args
@@ -1139,30 +1144,39 @@ mkDataCon name declared_infix prom_info
= con
where
is_vanilla = null ex_tvs && null eq_spec && null theta
- str_marks' | no_strict_marks = []
- | otherwise = str_marks
- no_strict_marks = not $ any isMarkedStrict str_marks
- is_lazy = no_str_marks && all definitelyLiftedType rep_arg_tys
-
- con = MkData {dcName = name, dcUnique = nameUnique name,
- dcVanilla = is_vanilla, dcInfix = declared_infix,
- dcUnivTyVars = univ_tvs,
- dcExTyCoVars = ex_tvs,
- dcConcreteTyVars = conc_tvs,
- dcUserTyVarBinders = user_tvbs,
- dcEqSpec = eq_spec,
- dcOtherTheta = theta,
- dcStupidTheta = stupid_theta,
- dcOrigArgTys = orig_arg_tys, dcOrigResTy = orig_res_ty,
- dcRepTyCon = rep_tycon,
- dcSrcBangs = arg_stricts, dcImplBangs = impl_bangs,
- dcStricts = str_marks', dcIsLazy = is_lazy,
- dcFields = fields, dcTag = tag, dcRepType = rep_ty,
- dcWorkId = work_id,
- dcRep = rep,
- dcSourceArity = length orig_arg_tys,
- dcRepArity = length rep_arg_tys + count isCoVar ex_tvs,
- dcPromoted = promoted }
+ is_lazy = not (any isMarkedStrict str_marks)
+ && all (definitelyLiftedType . scaledThing) rep_arg_tys
+
+ con = MkData { dcName = name
+ , dcUnique = nameUnique name
+ , dcInfix = declared_infix
+ , dcTag = tag
+ , dcVanilla = is_vanilla
+
+ , dcUnivTyVars = univ_tvs
+ , dcExTyCoVars = ex_tvs
+ , dcConcreteTyVars = conc_tvs
+ , dcUserTyVarBinders = user_tvbs
+ , dcEqSpec = eq_spec
+ , dcOtherTheta = theta
+ , dcStupidTheta = stupid_theta
+ , dcOrigArgTys = orig_arg_tys
+ , dcOrigResTy = orig_res_ty
+
+ , dcRep = rep
+ , dcRepType = rep_ty
+ , dcRepTyCon = rep_tycon
+ , dcSrcBangs = arg_stricts
+ , dcImplBangs = impl_bangs
+ , dcStricts = assertPpr (equalLength str_marks rep_arg_tys)
+ (ppr name <+> ppr str_marks)
+ str_marks
+ , dcIsLazy = is_lazy
+ , dcFields = fields
+ , dcWorkId = work_id
+ , dcSourceArity = length orig_arg_tys
+ , dcRepArity = length rep_arg_tys + count isCoVar ex_tvs
+ , dcPromoted = promoted }
-- The 'arg_stricts' passed to mkDataCon are simply those for the
-- source-language arguments. We add extra ones for the
@@ -1170,8 +1184,7 @@ mkDataCon name declared_infix prom_info
rep_arg_tys = dataConRepArgTys con
- rep_ty =
- case rep of
+ rep_ty = case rep of
-- If the DataCon has no wrapper, then the worker's type *is* the
-- user-facing type, so we can simply use dataConWrapperType.
NoDataConRep -> dataConWrapperType con
@@ -1407,23 +1420,13 @@ isNullarySrcDataCon dc = dataConSourceArity dc == 0
isNullaryRepDataCon :: DataCon -> Bool
isNullaryRepDataCon dc = dataConRepArity dc == 0
-isLazyDataConRep :: DataCon -> Bool
--- ^ True <==> All fields are lazy
-isLazyDataConRep dc = null (dcStricts dc)
-
dataConRepStrictness :: DataCon -> [StrictnessMark]
-- ^ Give the demands on the runtime arguments of a Core DataCon worker
--- application.
--- The length of the list matches `dataConRepArgTys` (e.g., the number
--- of runtime arguments).
-dataConRepStrictness dc
- | isLazyDataConRep dc
- = replicate (dataConRepArity dc) NotMarkedStrict
- | otherwise
- = dcStricts dc
+-- application. Maches 1-1 with `dataConRepArgTys`
+dataConRepStrictness = dcStricts
-dataConRepLazy :: DataCon -> Bool
-dataConRepLazy = dcIsLazy
+dataConRepIsLazy :: DataCon -> Bool
+dataConRepIsLazy = dcIsLazy
dataConImplBangs :: DataCon -> [HsImplBang]
-- The implementation decisions about the strictness/unpack of each
=====================================
compiler/GHC/Core/SimpleOpt.hs
=====================================
@@ -1726,10 +1726,8 @@ exprIsConApp_maybe ise@(ISE in_scope id_unf) expr
-- See Note [Strict fields in Core] for what a field seq is and (SFC2) for
-- why we insert them
mkFieldSeqFloats in_scope dc args
- | isLazyDataConRep dc
- = (in_scope, nilOL, args)
- | otherwise
- = (in_scope', floats', ty_args ++ val_args')
+ | dataConRepIsLazy dc = (in_scope, nilOL, args) -- Short cut in common case
+ | otherwise = (in_scope', floats', ty_args ++ val_args')
where
(ty_args, val_args) = splitAtList (dataConUnivAndExTyCoVars dc) args
(in_scope', floats', val_args') = foldr do_one (in_scope, nilOL, []) $
=====================================
compiler/GHC/Core/TyCon.hs
=====================================
@@ -1504,14 +1504,16 @@ There are a number of wrinkles
(UCM2) The TyCon for a unary class is /not/ identified as a newtype.
Rather, it has its own AlgTyConRhs, namely `UnaryClassTyCon`
-(UCM3) Unlike non-unary classes, a value of type (C ty), where `C` is a unary
+(UCM3a) Unlike non-unary classes, a value of type (C ty), where `C` is a unary
class, might be bottom, because it is represented by the method type alone.
See GHC.Core.Type.isTerminatingType, and Note [NON-BOTTOM-DICTS invariant]
in GHC.Core
- Similarly in exprOkForSpeculation/exprOkToDiscard/exprOkForSpecEval,
- in GHC.Core.Utils. In the utility funcion `app_ok` we need a special
- case for the DFunIds; they generally terminate, but not for unary classes.
+(UCM3b) We treat the data constructor as if it had a strictness annotation
+ data C a = MkC !(a->a)
+ so that in exprOkForSpeculation/exprOkToDiscard/exprOkForSpecEval, and
+ in exprIsHNF/exprIsConLike, we evaluate the argument. This strictness flag
+ is set in `GHC.Tc.TyCl.buildClass
(UMC4) To avoid regressions, in Core we want to remember that
(MkUC x) is really just x
=====================================
compiler/GHC/Core/Utils.hs
=====================================
@@ -2648,9 +2648,9 @@ exprIsHNFlike is_con is_con_unf rubbish_lit_result e
is_hnf_like e
where
is_hnf_like (Var v) -- NB: There are no value args at this point
- = id_app_is_value v [] -- Catches nullary constructors,
- -- so that [] and () are values, for example
- -- and (e.g.) primops that don't have unfoldings
+ = check_app v [] -- Catches nullary constructors,
+ -- so that [] and () are values, for example
+ -- and (e.g.) primops that don't have unfoldings
|| is_con_unf (idUnfolding v)
-- Check the thing's unfolding; it might be bound to a value
-- or to a guaranteed-evaluated variable (isEvaldUnfolding)
@@ -2685,46 +2685,37 @@ exprIsHNFlike is_con is_con_unf rubbish_lit_result e
= is_hnf_like rhs
is_hnf_like _ = False
- -- Collect arguments through Casts and Ticks and call id_app_is_value
+ -- Collect arguments through Casts and Ticks and call check_app
app_is_value :: CoreExpr -> [CoreArg] -> Bool
- app_is_value (Var f) as = id_app_is_value f as
+ app_is_value (Var f) as = check_app f as
app_is_value (Tick _ f) as = app_is_value f as
app_is_value (Cast f _) as = app_is_value f as
app_is_value (App f a) as | isValArg a = app_is_value f (a:as)
| otherwise = app_is_value f as
app_is_value _ _ = False
- id_app_is_value id val_args
- | Just dc <- isDataConWorkId_maybe id
- , isUnaryClassDataCon dc
- = all is_hnf_like val_args -- Look through unary class data cons
- | otherwise
- -- See Note [exprIsHNF for function applications]
- -- for the specification and examples
+ -- check_app: See Note [exprIsHNF for function applications]
+ -- for the specification and examples
+ check_app id val_args
= case compare (idArity id) (length val_args) of
- EQ | is_con id -> -- Saturated app of a DataCon/CONLIKE Id
- case mb_str_marks id of
- Just str_marks -> -- with strict fields; see (SFC1) of Note [Strict fields in Core]
- assert (val_args `equalLength` str_marks) $
- fields_hnf str_marks
- Nothing -> -- without strict fields: like PAP
- args_hnf -- NB: CONLIKEs are lazy!
-
- GT -> -- PAP: Check unlifted val_args
- args_hnf
-
- _ -> False
+ EQ -> check_saturated id val_args -- Saturated application
+ GT -> check_args id val_args -- Partial application
+ LT -> False -- Over-saturated
+ check_saturated id val_args
+ | Just dc <- isDataConWorkId_maybe id
+ = -- Saturated data constructors; must account for the strictness flags
+ all3Prefix check_field val_args (val_arg_tys id) (dataConStrictness dc)
+ | is_con id -- Saturated CONLIKE: check the arguments
+ = check_args id val_args
+ | otherwise -- Saturated function, not a constructor => not HNF
+ = False
+
+ -- check_args: check that any unlifted args are hnf-like
+ check_args id val_args = assert (sameLength val_args arg_tys) $
+ all2Prefix check_arg val_args arg_tys
where
- -- Saturated, Strict DataCon: Check unlifted val_args and strict fields
- fields_hnf str_marks = all3Prefix check_field val_arg_tys str_marks val_args
-
- -- PAP: Check unlifted val_args
- args_hnf = all2Prefix check_arg val_arg_tys val_args
-
- val_arg_tys = splitUninstantiatedValArgTys (idType id)
- -- val_arg_tys = map exprType val_args, but much less costly.
- -- The obvious definition regresses T16577 by 30% so we don't do it.
+ arg_tys = val_arg_tys id
check_arg a_ty a
| mightBeUnliftedType a_ty = is_hnf_like a
@@ -2735,18 +2726,18 @@ exprIsHNFlike is_con is_con_unf rubbish_lit_result e
-- NB: We check arity (and CONLIKEness) first because it's cheaper
-- and we reject quickly on saturated apps.
- check_field a_ty str a
- | mightBeUnliftedType a_ty = is_hnf_like a
- | isMarkedStrict str = is_hnf_like a
- | otherwise = True
- -- isMarkedStrict: Respect Note [Strict fields in Core]
-
- mb_str_marks id
- | Just dc <- isDataConWorkId_maybe id
- , not (isLazyDataConRep dc)
- = Just (dataConRepStrictness dc)
- | otherwise
- = Nothing
+ -- check_field: used for a data constructor worker:
+ -- check unlifted val_args and strict fields
+ -- See (SFC1) of Note [Strict fields in Core]
+ check_field a a_ty str
+ | mightBeUnliftedType a_ty = is_hnf_like a
+ | isMarkedStrict str = is_hnf_like a
+ | otherwise = True
+
+ val_arg_tys id = splitUninstantiatedValArgTys (idType id)
+ -- val_arg_tys = map exprType val_args, but much less costly.
+ -- The obvious definition regresses T16577 by 30% so we don't do it.
+
{-
Note [exprIsHNF Tick]
=====================================
compiler/GHC/Tc/TyCl/Build.hs
=====================================
@@ -331,6 +331,9 @@ buildClass tycon_name kind binders roles fds sc_theta at_items sig_stuff mindef
univ_bndrs = tyVarSpecToBinders $ tyConInvisTVBinders binders
univ_tvs = binderVars univ_bndrs
bang_opts = FixedBangOpts (map (const HsLazy) args)
+ bangs :: [HsSrcBang]
+ bangs | unary_class = [yes_bang] -- See (UCM3b) in Note [Unary class magic]
+ | otherwise = map (const no_bang) args
; rep_nm <- newTyConRepName datacon_name
; dict_con <- buildDataCon (panic "buildClass: FamInstEnvs")
@@ -338,7 +341,7 @@ buildClass tycon_name kind binders roles fds sc_theta at_items sig_stuff mindef
datacon_name
False -- Not declared infix
rep_nm
- (map (const no_bang) args)
+ bangs
[{- No fields -}]
univ_tvs
[{- no existentials -}]
@@ -376,7 +379,8 @@ buildClass tycon_name kind binders roles fds sc_theta at_items sig_stuff mindef
; traceIf (text "buildClass" <+> ppr tycon)
; return result }
where
- no_bang = HsSrcBang NoSourceText NoSrcUnpack NoSrcStrict
+ no_bang = HsSrcBang NoSourceText NoSrcUnpack NoSrcStrict
+ yes_bang = HsSrcBang NoSourceText NoSrcUnpack SrcStrict
mk_op_item :: Class -> TcMethInfo -> TcRnIf n m ClassOpItem
mk_op_item rec_clas (op_name, _, dm_spec)
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e832b4d2113aabe5ba69efabfbb82ec…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e832b4d2113aabe5ba69efabfbb82ec…
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
1
0
[Git][ghc/ghc][wip/case-bndr-unf] 4 commits: Lambda and case binders have vanilla IdInfo (#27965)
by Simon Peyton Jones (@simonpj) 25 Nov '26
by Simon Peyton Jones (@simonpj) 25 Nov '26
25 Nov '26
Simon Peyton Jones pushed to branch wip/case-bndr-unf at Glasgow Haskell Compiler / GHC
Commits:
95079140 by Simon Peyton Jones at 2026-11-25T00:38:11+00:00
Lambda and case binders have vanilla IdInfo (#27965)
Lambda binders, case binders, and case-alternative binders should never
have RULES, a (non-default) inline pragma, or a stable unfolding.
See new Note [Core binder IdInfo invariants] in GHC.Core, which
lays out the invariants.
This patch
* Makes Core Lint check the invariant, using the new predicate
GHC.Types.Id.lamBndrInfoOK.
* Fixes the desugarer, which violated it. For a strict binding
let !x = rhs in body
we generate
let x = rhs in case x of x { DEFAULT -> body }
re-using x (shadowed) as the case binder; see Note [Desugar Strict binds].
But the case binder inherited x's IdInfo, including, say, a NOINLINE
pragma (e.g. `res1` in GHC.Internal.Control.Monad.ST.Lazy.Imp). Now
GHC.HsToCore.Utils.seqVar gives the case binder vanilla IdInfo.
This was not just a matter of taste. For example
h fm s = let {-# NOINLINE res1 #-}
!res1 = fm s
!(f, s') = res1
in (f+1, s')
The NOINLINE case binder becomes a NOINLINE alias `let res3 = res2`,
which is never inlined, and survives (as a silly join point) into the
final code.
* Fixes the Simplifier, which could violate it when duplicating a
StrictBind continuation, which makes a join point
let x = <> in b ==> join j x = b in j <>
If x has any IdInfo that isn't allowed in a lambda-binder, we now zap the
IdInfo in the join point:
let x = <> in b ==> join j x' = b in j <>
where x' is like x (definitely the same unique) but with zapped IdInfo.
See (SB3) in Note [StrictBind].
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
77d3a390 by Simon Peyton Jones at 2026-11-25T00:38:11+00:00
Add varIsHNF, and use it in move_transit_vars
`varIsHNF v` is the same as `exprIsHNF (Var v)`, but avoids building the
Var only to take it apart. The (Var v) case of exprIsHNFlike now uses
the shared varIsHNFlike, so the two cannot drift apart.
In GHC.Core.Opt.WorkWrap.Utils.move_transit_vars we had the guard
isUnliftedType var_ty || exprIsHNF (Var var)
but exprIsHNF is already True of variables of (definitely) unlifted type,
so the isUnliftedType test was redundant. Now it is just (varIsHNF var).
Also make `exprIsHNFlike` treat an application with no value arguments, such as
`f @Int`, exactly like the bare variable `f`, by going through varIsHNFlike.
Otherwise no change in behaviour.
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
b603f32f by Simon Peyton Jones at 2026-11-25T00:38:11+00:00
Use SimplClo for the argument of ApplyToVal
This patch renames SimplSR to SimplClo (a "closure"), and uses it not
only as the range of the Simplifier's substitution, but also as the
argument of an ApplyToVal continuation. ApplyToVal used to have three
fields
sc_env :: StaticEnv
sc_arg :: CoreExpr
sc_cast :: MOutCoercion
but now has just
sc_dup :: DupFlag
sc_arg :: SimplClo
An un-simplified argument is (ContEx env arg mco), and an already-simplified
one is (DoneEx arg _). See Note [The argument of ApplyToVal] in
GHC.Core.Opt.Simplify.Utils.
The main payoff is that, since the substitution maps an Id to a SimplClo,
beta-reduction can substitute the argument for the lambda binder without
further ado. Accordingly, preInlineUnconditionally is split into
* preInlineLetUnconditionally, for let-bindings
* preInlineBetaUnconditionally, for beta-redexes, which takes a SimplClo
The latter omits some checks that cannot fire for lambda binders.
Other notes
* The new (ContEx env arg mco) form makes it easy to push a cast into an
argument (mkCloCastMCo), whether or not it has been simplified.
See Note [The MOutCoercion field of ContEx].
* `preInlineUnconditionally` gets split into two variants, one for
let-bindings and one for beta-reduction (which takes a `SimplClo`).
There is a little bit of duplication here, but not much.
* Fixes #27962. The simplifier was previously dropping a cast when dealing
with runRW#. The new `SimplClo` makes that bug much harder to allow.
* Fixes #27963. contOutArgs, which supplies the arguments for Plan (BEFORE)
rule matching, ignored the sc_cast field of ApplyToVal. So in
(f |> co) n ==> f (n |> co1) -- co1 in sc_cast
a rule for `f` saw `f n` rather than `f (n |> co1)`, and failed to match
(the rule matcher checks the types of template variables). If f's
unfolding is active, f may then be inlined, and the rule is lost for
good. Now contOutArgs uses simplCloExpr, which includes the pending cast.
Almost no change in behaviour, except for the #27963 bug-fix.
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
1d59be95 by Simon Peyton Jones at 2026-11-25T00:38:11+00:00
Add splitThunkCpr
This commit adds GHC.Core.Opt.WorkWrap.splitThunkCpr, which adds a form
of "thunk splitting" for strict bindings that have CPR information.
See Note [Thunk splitting] in WorkWrap.hs for the details.
It catches a previously-unrecognised optimisation opportunity
(see #28258) but it only helps in fairly obscure cases, so
I don't expect a big impact in practice.
As usually I did lots of refactoring along the way.
LLM disclosure: lots of interaction with Claude, but I wrote all the
code and comments.
- - - - -
32 changed files:
- + changelog.d/T27962
- + changelog.d/T27963
- compiler/GHC/Builtin/WiredIn/Ids.hs
- compiler/GHC/Core.hs
- compiler/GHC/Core/Lint.hs
- compiler/GHC/Core/Make/Box.hs
- compiler/GHC/Core/Opt/CprAnal.hs
- compiler/GHC/Core/Opt/Simplify/Env.hs
- compiler/GHC/Core/Opt/Simplify/Iteration.hs
- compiler/GHC/Core/Opt/Simplify/Utils.hs
- compiler/GHC/Core/Opt/SpecConstr.hs
- compiler/GHC/Core/Opt/WorkWrap.hs
- compiler/GHC/Core/Opt/WorkWrap/Utils.hs
- compiler/GHC/Core/Ppr.hs
- compiler/GHC/Core/Utils.hs
- compiler/GHC/CoreToStg/Prep.hs
- compiler/GHC/HsToCore/Expr.hs
- compiler/GHC/HsToCore/Match.hs
- compiler/GHC/HsToCore/Utils.hs
- compiler/GHC/Types/Cpr.hs
- compiler/GHC/Types/Id.hs
- compiler/GHC/Utils/Monad.hs
- testsuite/tests/simplCore/should_compile/T15445.stderr
- + testsuite/tests/simplCore/should_compile/T27962.hs
- + testsuite/tests/simplCore/should_compile/T27963.hs
- + testsuite/tests/simplCore/should_compile/T27963.stderr
- + testsuite/tests/simplCore/should_compile/T27965.hs
- + testsuite/tests/simplCore/should_compile/T27965a.hs
- + testsuite/tests/simplCore/should_compile/T27965b.hs
- + testsuite/tests/simplCore/should_compile/T28158.hs
- + testsuite/tests/simplCore/should_compile/T28158.stderr
- testsuite/tests/simplCore/should_compile/all.T
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/27a190029467e53b9b1e4ad9acde3d…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/27a190029467e53b9b1e4ad9acde3d…
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
1
0
[Git][ghc/ghc][wip/marge_bot_batch_merge_job] 6 commits: Use a different herald for -ddump-simpl-trace
by Marge Bot (@marge-bot) 24 Nov '26
by Marge Bot (@marge-bot) 24 Nov '26
24 Nov '26
Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC
Commits:
1a69c793 by Simon Peyton Jones at 2026-11-24T18:03:57-05:00
Use a different herald for -ddump-simpl-trace
... so that we can more easily skip the high-volume ones
- - - - -
012d9cf1 by Simon Peyton Jones at 2026-11-24T18:03:57-05:00
Update comments and user manual
This commit addresses the comment-related suggestions in #27973
- - - - -
ad578f71 by Simon Peyton Jones at 2026-11-24T18:03:57-05:00
Document and refactor eta-reduction documentation
Triggered by #27212, this patch does several related things.
* #27212 suggested that `findRhsArity` should ask for eta-expansion
whenever the RHS's `manifestArity` is less than the arity it finds.
That is a misconception: it deliberately compares with `exprArity`,
which counts PAPs, so that we do not eta-expand PAPs (#9020).
Switching to `manifestArity` makes compile time worse in T13960
and T13056.
So this patch changes no code here; we continue to expand only to
increase `exprArity` not `manifestArity`. Instead it documents the
design in `findRhsArity`, `tryEtaExpandRhs`, `wantEtaExpansion` and
Note [Do not eta-expand PAPs] (which now records the #27212
experiment).
* Refactor GHC.Core.Opt.Arity.tryEtaReduce, which was hard to
understand:
- Accumulate an MCoercion rather than a Coercion, so the common
no-cast case builds no coercions at all.
- Separate equations of `go` for type and value arguments. For
value arguments, the new `getTrivialHead_maybe` looks through any
nesting of casts and floatable ticks, and `mkEtaReduceFunCo` builds
the coercion.
- Make the FunCo with `mkFunCo2` and compute its right-hand
FunTyFlag from the coercion kinds. The cast can turn a Type-kinded
argument into a Constraint-kinded one. New test T27212 covers this.
- `mkEtaReduceForAllMCo` builds the ForAllCo for type arguments. It
is tiresomely similar to `mkEtaForAllMCo`, but with the visibilities
the other way round (#24014). It will go away again once !17006
lands.
- New helper `mCoToCo` in GHC.Core.TyCo.Make.
* Drop the checks on multiplicity in `tryEtaReduce`, which sometimes
disabled eta-reduction. For example, (\x. K x) has type Int -> T,
but the data constructor has type K :: Int %1 -> T, so we used to
refuse to eta-reduce it to K.
But Note [Linting linearity] in GHC.Core.Lint (EXAMPLE 4) already
says that we do not preserve linearity under eta-reduction, so this
change just puts that claim into practice. See (EtaMult) in
Note [Eta reduction soundness].
Consequences in the testsuite:
- T18052a: the pattern-synonym builder (\x y. (x,y)) is now just (,).
- T21888a: the NOINLINE function (f x = Just x) becomes (f = Just),
so f loses its CPR signature. The test is about demands, not CPR.
* Tidy up the documentation of eta-reduction:
- Relabel the criteria in Note [Eta reduction soundness] as (EtaA),
(EtaS), (EtaR), (EtaE), (EtaT), (EtaJ), (EtaB) and (EtaW), and
update all references to them. Also fix references to point (2) of
Note [Eta reduction makes sense], which no longer exists.
- Replace the confused "never reduce arity" bullet with an example in
(EtaA), cross-referenced from Note [Arity robustness].
- Add historical notes (EtaMult) and (EtaBot).
- Label the equations in Note [Eta reduction with casted arguments]
(ECA1-4), and point to the code that implements them.
LLM disclosure: I interacted with Claude a lot for this MR, but I
wrote all the code and docs myself.
- - - - -
46bd3331 by Simon Jakobi at 2026-11-24T18:03:58-05:00
ci: Anchor the release branch pattern
Branches with `ghc-X.Y` anywhere in their name, such as
wip/ghc-9.16-backports, were treated as release branches. Each push
started a full-ci branch pipeline next to the merge request pipeline,
and its jobs pushed perf notes.
Fixes #28172.
Assisted-by: Claude Fable 5.2
- - - - -
66cd89d8 by Simon Jakobi at 2026-11-24T18:03:58-05:00
ci: Fix the release branch pattern of lint-submods-branch
The pattern had `[0.9]` for `[0-9]`, so the job didn't run on ghc-10.0.
Also anchor the pattern (#28172).
Assisted-by: Claude Fable 5.2
- - - - -
8da4e77a by Simon Jakobi at 2026-11-24T18:03:59-05:00
ci: Retry some failed jobs automatically
Let GitLab retry a job up to twice when it fails with one of these
reasons:
- runner_system_failure: the runner could not run the job. This is
nearly always an image pull that fails before the job starts.
- stuck_or_timeout_failure: GitLab dropped the job, either because
its runner stopped reporting for an hour or because no runner
picked it up within a day.
Assisted-by: Claude Fable 5.2
- - - - -
28 changed files:
- .gitlab-ci.yml
- .gitlab/ci.sh
- .gitlab/generate-ci/gen_ci.hs
- .gitlab/jobs.yaml
- + changelog.d/T27212
- compiler/GHC/Core/Coercion.hs
- compiler/GHC/Core/Opt/Arity.hs
- compiler/GHC/Core/Opt/OccurAnal.hs
- compiler/GHC/Core/Opt/Pipeline.hs
- compiler/GHC/Core/Opt/Simplify/Env.hs
- compiler/GHC/Core/Opt/Simplify/Inline.hs
- compiler/GHC/Core/Opt/Simplify/Iteration.hs
- compiler/GHC/Core/Opt/Simplify/Utils.hs
- compiler/GHC/Core/Opt/SpecConstr.hs
- compiler/GHC/Core/Opt/Specialise.hs
- compiler/GHC/Core/TyCo/Make.hs
- compiler/GHC/Core/Type.hs
- compiler/GHC/Core/Utils.hs
- compiler/GHC/Driver/Config/Core/Opt/Simplify.hs
- compiler/GHC/Utils/Logger.hs
- compiler/Language/Haskell/Syntax/Binds/InlinePragma.hs
- docs/users_guide/debug-info.rst
- docs/users_guide/using-optimisation.rst
- testsuite/tests/dmdanal/sigs/T21888a.stderr
- testsuite/tests/printer/T18052a.stderr
- testsuite/tests/simplCore/should_compile/T24726.stderr
- + testsuite/tests/simplCore/should_compile/T27212.hs
- testsuite/tests/simplCore/should_compile/all.T
Changes:
=====================================
.gitlab-ci.yml
=====================================
@@ -62,6 +62,11 @@ variables:
XZ_OPT: "-1"
default:
interruptible: true
+ retry:
+ max: 2
+ when:
+ - runner_system_failure
+ - stuck_or_timeout_failure
stages:
- not-interruptible
@@ -113,7 +118,7 @@ workflow:
# cause a duplicate pipeline for merge requests coming from the master
# branch of a fork.
- if: $CI_PROJECT_ID == "1" && $CI_COMMIT_BRANCH == "master"
- - if: $CI_PROJECT_ID == "1" && $CI_COMMIT_BRANCH =~ /ghc-[0-9]+\.[0-9]+/
+ - if: $CI_PROJECT_ID == "1" && $CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\.[0-9]+$/
- if: '$CI_PIPELINE_SOURCE == "web"'
# which versions of GHC to allow bootstrap with
@@ -193,7 +198,7 @@ workflow:
- if: '$CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/'
- if: '$CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/'
- if: '$CI_COMMIT_BRANCH == "master"'
- - if: '$CI_COMMIT_BRANCH =~ /ghc-[0-9]+\.[0-9]+/'
+ - if: '$CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\.[0-9]+$/'
############################################################
# Runner Tags
@@ -415,7 +420,7 @@ lint-submods-branch:
- _build/stageBoot/bin/lint-submodule-refs . $(git rev-list $CI_COMMIT_BEFORE_SHA..$CI_COMMIT_SHA)
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
- - if: '$CI_COMMIT_BRANCH =~ /ghc-[0.9]+\.[0-9]+/'
+ - if: '$CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\.[0-9]+$/'
- *drafts-can-fail-lint
############################################################
=====================================
.gitlab/ci.sh
=====================================
@@ -496,7 +496,7 @@ function fetch_perf_notes() {
}
function push_perf_notes() {
- if [[ "${CI_COMMIT_BRANCH:-}" != "master" ]] && [[ ! "${CI_COMMIT_BRANCH:-}" =~ ghc-[0-9]+\.[0-9]+ ]]; then
+ if [[ "${CI_COMMIT_BRANCH:-}" != "master" ]] && [[ ! "${CI_COMMIT_BRANCH:-}" =~ ^ghc-[0-9]+\.[0-9]+$ ]]; then
info "Perf notes are only pushed on master/release branches"
return
fi
=====================================
.gitlab/generate-ci/gen_ci.hs
=====================================
@@ -870,7 +870,7 @@ validateRuleString :: ValidateRule -> Cond
validateRuleString FullCI = or_all [ labelString "full-ci"
, labelString "marge_bot_batch_merge_job"
, branchStringExact "master"
- , branchStringLike "ghc-[0-9]+\\.[0-9]+"
+ , branchStringLike "^ghc-[0-9]+\\.[0-9]+$"
]
validateRuleString FastCI = true
=====================================
.gitlab/jobs.yaml
=====================================
@@ -538,7 +538,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\baarch64-linux-deb12-wine-int_native-cross_aarch64-unknown-mingw32-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || (($CI_MERGE_REQUEST_LABELS =~ /.*aarch64.*/) && ($CI_MERGE_REQUEST_LABELS =~ /.*Windows.*/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\baarch64-linux-deb12-wine-int_native-cross_aarch64-unknown-mingw32-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || (($CI_MERGE_REQUEST_LABELS =~ /.*aarch64.*/) && ($CI_MERGE_REQUEST_LABELS =~ /.*Windows.*/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -622,7 +622,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\baarch64-linux-deb12-wine-int_native-cross_aarch64-unknown-mingw32-validate\\+llvm(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || (($CI_MERGE_REQUEST_LABELS =~ /.*aarch64.*/) && ($CI_MERGE_REQUEST_LABELS =~ /.*Windows.*/) && ($CI_MERGE_REQUEST_LABELS =~ /.*LLVM backend.*/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\baarch64-linux-deb12-wine-int_native-cross_aarch64-unknown-mingw32-validate\\+llvm(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || (($CI_MERGE_REQUEST_LABELS =~ /.*aarch64.*/) && ($CI_MERGE_REQUEST_LABELS =~ /.*Windows.*/) && ($CI_MERGE_REQUEST_LABELS =~ /.*LLVM backend.*/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -952,7 +952,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bi386-linux-alpine3_23-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bi386-linux-alpine3_23-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -1014,7 +1014,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bi386-linux-alpine3_23-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bi386-linux-alpine3_23-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -1323,7 +1323,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bi386-linux-deb13-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*i386.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bi386-linux-deb13-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*i386.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -1384,7 +1384,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bi386-linux-deb13-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*i386.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bi386-linux-deb13-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*i386.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -10542,7 +10542,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-darwin-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*test-primops.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-darwin-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*test-primops.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -10610,7 +10610,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-darwin-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*test-primops.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-darwin-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*test-primops.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -10678,7 +10678,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-freebsd14-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*FreeBSD.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-freebsd14-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*FreeBSD.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -10742,7 +10742,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-freebsd14-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*FreeBSD.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-freebsd14-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*FreeBSD.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -10932,7 +10932,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-alpine3_12-validate\\+fully_static(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-alpine3_12-validate\\+fully_static(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -10994,7 +10994,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-alpine3_12-validate\\+fully_static(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-alpine3_12-validate\\+fully_static(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -11182,7 +11182,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-alpine3_23-wasm-cross_wasm32-wasi-release\\+host_fully_static\\+text_simdutf(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*wasm.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-alpine3_23-wasm-cross_wasm32-wasi-release\\+host_fully_static\\+text_simdutf(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*wasm.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -11246,7 +11246,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-alpine3_23-wasm-cross_wasm32-wasi-release\\+host_fully_static\\+text_simdutf(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*wasm.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-alpine3_23-wasm-cross_wasm32-wasi-release\\+host_fully_static\\+text_simdutf(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*wasm.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -11312,7 +11312,7 @@
"rules": [
{
"allow_failure": true,
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-alpine3_23-wasm-int_native-cross_wasm32-wasi-release\\+host_fully_static\\+text_simdutf(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*wasm.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-alpine3_23-wasm-int_native-cross_wasm32-wasi-release\\+host_fully_static\\+text_simdutf(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*wasm.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "manual"
}
],
@@ -11377,7 +11377,7 @@
"rules": [
{
"allow_failure": true,
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-alpine3_23-wasm-int_native-cross_wasm32-wasi-release\\+host_fully_static\\+text_simdutf(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*wasm.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-alpine3_23-wasm-int_native-cross_wasm32-wasi-release\\+host_fully_static\\+text_simdutf(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*wasm.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "manual"
}
],
@@ -11443,7 +11443,7 @@
"rules": [
{
"allow_failure": true,
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-alpine3_23-wasm-unreg-cross_wasm32-wasi-release\\+host_fully_static\\+text_simdutf(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*wasm.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-alpine3_23-wasm-unreg-cross_wasm32-wasi-release\\+host_fully_static\\+text_simdutf(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*wasm.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "manual"
}
],
@@ -11508,7 +11508,7 @@
"rules": [
{
"allow_failure": true,
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-alpine3_23-wasm-unreg-cross_wasm32-wasi-release\\+host_fully_static\\+text_simdutf(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*wasm.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-alpine3_23-wasm-unreg-cross_wasm32-wasi-release\\+host_fully_static\\+text_simdutf(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*wasm.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "manual"
}
],
@@ -11573,7 +11573,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb11-emsdk-closure-int_native-cross_javascript-unknown-ghcjs-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*javascript.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb11-emsdk-closure-int_native-cross_javascript-unknown-ghcjs-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*javascript.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -11637,7 +11637,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb11-emsdk-closure-int_native-cross_javascript-unknown-ghcjs-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*javascript.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb11-emsdk-closure-int_native-cross_javascript-unknown-ghcjs-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*javascript.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -12071,7 +12071,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-cross_aarch64-linux-gnu-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-cross_aarch64-linux-gnu-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -12137,7 +12137,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-int_native-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-int_native-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -12198,7 +12198,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-int_native-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-int_native-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -12261,7 +12261,7 @@
"rules": [
{
"allow_failure": true,
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-no_tntc-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-no_tntc-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "manual"
}
],
@@ -12323,7 +12323,7 @@
"rules": [
{
"allow_failure": true,
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-no_tntc-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-no_tntc-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "manual"
}
],
@@ -12694,7 +12694,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-riscv-cross_riscv64-linux-gnu-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*RISC-V.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-riscv-cross_riscv64-linux-gnu-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*RISC-V.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -12761,7 +12761,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-unreg-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-unreg-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -12822,7 +12822,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-unreg-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-unreg-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -12884,7 +12884,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*test-primops.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*test-primops.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -13194,7 +13194,7 @@
"rules": [
{
"allow_failure": true,
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-validate\\+thread_sanitizer_cmm(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-validate\\+thread_sanitizer_cmm(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "manual"
}
],
@@ -13258,7 +13258,7 @@
"rules": [
{
"allow_failure": true,
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-validate\\+thread_sanitizer_cmm(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-validate\\+thread_sanitizer_cmm(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "manual"
}
],
@@ -13320,7 +13320,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*test-primops.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-deb13-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*test-primops.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -13879,7 +13879,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-fedora43-validate\\+debug_info\\+ubsan(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-fedora43-validate\\+debug_info\\+ubsan(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -13942,7 +13942,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-fedora43-validate\\+debug_info\\+ubsan(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-fedora43-validate\\+debug_info\\+ubsan(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/))))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
@@ -14372,7 +14372,7 @@
],
"rules": [
{
- "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-ubuntu24_04-loongarch-cross_loongarch64-linux-gnu-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /ghc-[0-9]+\\.[0-9]+/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*loongarch.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
+ "if": "((($ONLY_JOBS) && ($ONLY_JOBS =~ /.*\\bx86_64-linux-ubuntu24_04-loongarch-cross_loongarch64-linux-gnu-validate(\\s|$).*/)) || (($ONLY_JOBS == null) && ((($CI_MERGE_REQUEST_LABELS =~ /.*full-ci.*/) || ($CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/) || ($CI_COMMIT_BRANCH == \"master\") || ($CI_COMMIT_BRANCH =~ /^ghc-[0-9]+\\.[0-9]+$/)) || ($CI_MERGE_REQUEST_LABELS =~ /.*loongarch.*/)))) && ($RELEASE_JOB != \"yes\") && ($NIGHTLY == null)",
"when": "on_success"
}
],
=====================================
changelog.d/T27212
=====================================
@@ -0,0 +1,8 @@
+section: compiler
+synopsis: Tiny change in -drule-check output
+issues: #27212
+mrs: !15954
+description: {
+ The formatting of the heading for the output of ``-drule-check``
+ has changed slightly.
+}
=====================================
compiler/GHC/Core/Coercion.hs
=====================================
@@ -74,7 +74,7 @@ module GHC.Core.Coercion (
isReflCoVar_maybe, assertGoodForAllCo,
- coToMCo, kindCoToMKindCo,
+ coToMCo, kindCoToMKindCo, mCoToCo,
mkTransMCo, mkTransMCoL, mkTransMCoR, mkCastTyMCo, mkSymMCo,
mkFunResMCo, mkPiMCos,
isReflMCo, checkReflexiveMCo,
=====================================
compiler/GHC/Core/Opt/Arity.hs
=====================================
@@ -886,8 +886,14 @@ findRhsArity :: ArityOpts -> RecFlag -> Id -> CoreExpr
-- This implements the fixpoint loop for arity analysis
-- See Note [Arity analysis]
--
--- The Bool is True if the returned arity is greater than (exprArity rhs)
--- so the caller should do eta-expansion
+-- The Bool is True if
+-- the returned arity is greater than (exprArity rhs)
+-- so the caller should do eta-expansion
+-- NB: `exprArity`, not `manifestArity`:
+-- a PAP such as (\x. f x), where f has arity 3, has exprArity 3,
+-- so we do not eta-expand it to (\x y z. f x y z)
+-- See Note [Do not eta-expand PAPs] in GHC.Core.Opt.Simplify.Utils
+--
-- That Bool is never True for join points, which are never eta-expanded
--
-- Returns an SafeArityType that is guaranteed trimmed to typeArity of 'bndr'
@@ -903,10 +909,11 @@ findRhsArity opts is_rec bndr rhs
| otherwise
= (arity_increased, non_join_arity_type)
- -- arity_increased: eta-expand if we'll get more lambdas
- -- to the top of the RHS
+ -- arity_increased: eta-expand if the analysis finds a greater arity
+ -- than exprArity, which already takes account of PAPs
where
- old_arity = exprArity rhs
+ old_arity = exprArity rhs -- See Note [Do not eta-expand PAPs]
+ -- in GHC.Core.Opt.Simplify.Utils
init_env :: ArityEnv
init_env = findRhsArityEnv opts (isJoinId bndr)
@@ -2388,6 +2395,7 @@ mkEtaForAllMCo (Bndr tcv vis) ty mco
-- and is SymCo'd in `etaInfoAbs`. Hence the orientation of the visibility
-- flags. A bit of a brain-strain (#27557).
+
{-
************************************************************************
* *
@@ -2452,16 +2460,20 @@ perform eta reduction on an expression with n leading lambdas `\xs. e xs`
(checked in 'is_eta_reduction_sound' in 'tryEtaReduce', which focuses on the
case where `e` is trivial):
-(A) It is sound to eta-reduce n arguments as long as n does not exceed the
- `exprArity` of `e`. (Needs Arity analysis.)
- This criterion exploits information about how `e` is *defined*.
+(EtaA) It is sound to eta-reduce n arguments as long as n does not exceed the
+ `exprArity` of `e`. (Needs Arity analysis.) This criterion exploits information
+ about how `e` is *defined*. For example:
+ f = \xy. g x y ===> f = g
+ This eta-reduction is good only if `g` has arity at least 2, otherwise
+ f's arity will decrease from 2 to 1.
+ c.f. Note [Arity robustness] in GHC.Core.Opt.Simplify.Env.
- Example: If `e = \x. bot` then we know it won't diverge until it is called
- with one argument. Hence it is safe to eta-reduce `\x. e x` to `e`.
+ Another example: If `e = \x. bot` then we know it won't diverge until it
+ is called with one argument. Hence it is safe to eta-reduce `\x. e x` to `e`.
By contrast, it would be *unsound* to eta-reduce 2 args, `\x y. e x y` to `e`:
`e 42` diverges when `(\x y. e x y) 42` does not.
-(S) It is sound to eta-reduce n arguments in an evaluation context in which all
+(EtaS) It is sound to eta-reduce n arguments in an evaluation context in which all
calls happen with at least n arguments. (Needs Strictness analysis.)
NB: This treats evaluations like a call with 0 args.
NB: This criterion exploits information about how `e` is *used*.
@@ -2483,35 +2495,31 @@ case where `e` is trivial):
But it is unsound to eta-reduce the arg in `g2 (\x y. e x y)` to `g2 e`
when `e = \x. if x then bot else id`, because the latter will diverge when
the former would not. Fortunately, the strictness analyser will report
- "Not always called with two arguments" for `g2` and we won't eta-expand.
+ "Not always called with two arguments" for `g2` and we won't eta-reduce.
See Note [Eta reduction based on evaluation context] for the implementation
details. This criterion is tested extensively in T21261.
-(R) Note [Eta reduction in recursive RHSs] tells us that we should not
+(EtaR) Note [Eta reduction in recursive RHSs] tells us that we should not
eta-reduce `f` in its own RHS and describes our fix.
There we have `f = \x. f x` and we should not eta-reduce to `f=f`. Which
might change a terminating program (think @f `seq` e@) to a non-terminating
one.
-(E) (See fun_arity in tryEtaReduce.) As a perhaps special case on the
- boundary of (A) and (S), when we know that a fun binder `f` is in
- WHNF, we simply assume it has arity 1 and apply (A). Example:
+(EtaE) (See fun_arity in tryEtaReduce.) As a perhaps special case on the
+ boundary of (EtaA) and (EtaS), when we know that a fun binder `f` is in
+ WHNF, we simply assume it has arity 1 and apply (EtaA). Example:
g f = f `seq` \x. f x
Here it's sound eta-reduce `\x. f x` to `f`, because `f` can't be bottom
after the `seq`. This turned up in #7542.
- T. If the binders are all type arguments, it's always safe to eta-reduce,
- regardless of the arity of f.
- /\a b. f @a @b --> f
-
-2. Type and dictionary abstraction. Regardless of whether 'f' is a value, it
+(EtaT) Type and dictionary abstraction. Regardless of whether 'f' is a value, it
is always sound to reduce /type lambdas/, thus:
- (/\a -> f a) --> f
+ (/\a -> f @a) --> f
Moreover, we always want to, because it makes RULEs apply more often:
- This RULE: `forall g. foldr (build (/\a -> g a))`
+ This RULE: `forall g. foldr (build (/\a -> g @a))`
should match `foldr (build (/\b -> ...something complex...))`
- and the simplest way to do so is eta-reduce `/\a -> g a` in the RULE to `g`.
+ and the simplest way to do so is eta-reduce `/\a -> g @a` in the RULE to `g`.
More debatably, we extend this to dictionary arguments too, because the type
checker can insert these eta-expanded versions, with both type and dictionary
@@ -2523,18 +2531,25 @@ case where `e` is trivial):
And here are a few more technical criteria for when it is *not* sound to
eta-reduce that are specific to Core and GHC:
-(J) We may not undersaturate join points.
+(EtaJ) We may not undersaturate join points.
See Note [Invariants on join points] in GHC.Core, and #20599.
-(B) We may not undersaturate functions with no binding.
+(EtaB) We may not undersaturate functions with no binding.
See Note [Eta expanding primops].
-(W) We may not undersaturate StrictWorkerIds.
+(EtaW) We may not undersaturate StrictWorkerIds.
See Note [CBV Function Ids: overview] in GHC.Types.Id.Info.
-Here is a list of historic accidents surrounding unsound eta-reduction:
-* Consider
+Here is a list of historic notes surrounding unsound eta-reduction:
+
+(EtaMult) We used to disable eta-reduction if performing it would change multiplicity.
+ For example:
+ (\x. K x) :: Int -> T but K :: Int %1 -> T
+ But that (a) inhibits beneficial eta-reduction (b) costs extra work to check, and
+ now we don't even try. See Note [Linting linearity] in GHC.Core.Lint, esp EXAMPLE 4
+
+(EtaBot) Consider
f = \x.f x
h y = case (case y of { True -> f `seq` True; False -> False }) of
True -> ...; False -> ...
@@ -2548,16 +2563,6 @@ Here is a list of historic accidents surrounding unsound eta-reduction:
Result: seg-fault because the boolean case actually gets a function value.
See #1947.
-* Never *reduce* arity. For example
- f = \xy. g x y
- Then if h has arity 1 we don't want to eta-reduce because then
- f's arity would decrease, and that is bad
- [SG in 2022: I don't understand this point. There is no `h`, perhaps that
- should have been `g`. Even then, this proposed eta-reduction is invalid by
- criterion (A), which might actually be the point this anecdote is trying to
- make. Perhaps the "no arity decrease" idea is also related to
- Note [Arity robustness]?]
-
Note [Do not eta reduce PAPs]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I considered eta-reducing if the result is a PAP:
@@ -2598,11 +2603,14 @@ This should be eta-reduced to
So we need to accumulate a coercion, pushing it inward (past
variable arguments only) thus:
- f (x |> co_arg) |> co --> (f |> (sym co_arg -> co)) x
- f (x:t) |> co --> (f |> (t -> co)) x
- f @ a |> co --> (f |> (forall a.co)) @ a
- f @ (g:t1~t2) |> co --> (f |> (t1~t2 => co)) @ (g:t1~t2)
-These are the equations for ok_arg.
+(ECA1) \x. f (x |> co_arg) |> co --> (f |> (sym co_arg -> co))
+(ECA2) \x. f (x:t) |> co --> (f |> (t -> co))
+(ECA3) \x. f (x:t1~#t2) |> co --> (f |> (t1~#t2 => co))
+(ECA4) \x. f @ a |> co --> (f |> (forall a.co))
+
+(ECA1,2,4) are implemented by the `go` equations in `tryEtaReduce`.
+However (ECA3) is not implemented -- it could be, perhaps by spotting
+an argument that is (Coercion (CoVar x)), but it seems like a rare case.
Note [Eta reduction with casted function]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -2620,7 +2628,7 @@ eta-expansion may be turned off (by sm_eta_expand).
Note [Eta reduction based on evaluation context]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Note [Eta reduction soundness], criterion (S) allows us to eta-reduce
+Note [Eta reduction soundness], criterion (EtaS) allows us to eta-reduce
`g (\x y. e x y)` to `g e` when we know that `g` always calls its parameter with
at least 2 arguments. So how do we read that off `g`'s demand signature?
@@ -2713,13 +2721,13 @@ tryEtaReduce :: UnVarSet -> [Var] -> CoreExpr -> SubDemand -> Maybe CoreExpr
-- and Note [Eta reduction makes sense] when that is the case.
-- and Note [Eta reduction based on evaluation context] for the `eval_sd` arg
tryEtaReduce rec_ids bndrs body eval_sd
- = go (reverse bndrs) body (mkRepReflCo (exprType body))
+ = go (reverse bndrs) body MRefl
where
- incoming_arity = count isId bndrs -- See Note [Eta reduction makes sense], point (2)
+ incoming_arity = count isId bndrs -- See (EtaA) in Note [Eta reduction soundness]
go :: [Var] -- Binders, innermost first, types [a3,a2,a1]
-> CoreExpr -- Of type tr
- -> Coercion -- Of type tr ~ ts
+ -> MCoercion -- Of type tr ~ ts
-> Maybe CoreExpr -- Of type a1 -> a2 -> a3 -> ts
-- See Note [Eta reduction with casted arguments]
-- for why we have an accumulating coercion
@@ -2729,19 +2737,37 @@ tryEtaReduce rec_ids bndrs body eval_sd
-- See Note [Eta reduction with casted function]
go bs (Cast e co1) co2
- = go bs e (co1 `mkTransCo` co2)
+ = go bs e (co1 `mkTransMCoR` co2)
go bs (Tick t e) co
| tickishFloatable t
= fmap (Tick t) $ go bs e co
-- Float app ticks: \x -> Tick t (e x) ==> Tick t e
- go (b : bs) (App fun arg) co
- | Just (co', ticks) <- ok_arg b arg co (exprType fun)
- = fmap (flip (foldr mkTick) ticks) $ go bs fun co'
- -- Float arg ticks: \x -> e (Tick t x) ==> Tick t e
+ -- Implements (ECA4)
+ go all_bs@(b : bs) all_e@(App fun (Type arg_ty)) mco
+ | Just tv <- getTyVar_maybe arg_ty
+ , b == tv
+ , Just (bndr, body_ty) <- splitForAllForAllTyBinder_maybe (exprType fun)
+ = go bs fun (mkEtaReduceForAllMCo bndr body_ty tv mco)
- go remaining_bndrs fun co
+ | otherwise
+ = go_finish all_bs all_e mco
+ -- Want to go to the finish case; see the call
+ -- to (all isTyVar remaining_bndrs) there
+
+ -- Implements (ECA1,2)
+ go (b : bs) (App fun val_arg) mco
+ | Just (v, arg_mco, arg_ticks) <- getTrivialHead_maybe val_arg
+ , b == v
+ , Just co' <- mkEtaReduceFunCo (exprType fun) arg_mco mco
+ = fmap (flip (foldr mkTick) arg_ticks) $
+ go bs fun co'
+ -- Float arg ticks: \x -> e (Tick t x) ==> Tick t e
+
+ go bs fun co = go_finish bs fun co
+
+ go_finish remaining_bndrs fun co
| all isTyVar remaining_bndrs
-- If all the remaining_bnrs are tyvars, then the etad_exp
-- will be trivial, which is what we want.
@@ -2752,7 +2778,7 @@ tryEtaReduce rec_ids bndrs body eval_sd
, remaining_bndrs `ltLength` bndrs
-- Only reply Just if /something/ has happened
, ok_fun fun
- , let used_vars = exprFreeVars fun `unionVarSet` tyCoVarsOfCo co
+ , let used_vars = exprFreeVars fun `unionVarSet` tyCoVarsOfMCo co
reduced_bndrs = mkVarSet (dropList remaining_bndrs bndrs)
-- reduced_bndrs are the ones we are eta-reducing away
, used_vars `disjointVarSet` reduced_bndrs
@@ -2761,10 +2787,10 @@ tryEtaReduce rec_ids bndrs body eval_sd
-- See Note [Eta reduction makes sense], intro and point (1)
-- NB: don't compute used_vars from exprFreeVars (mkCast fun co)
-- because the latter may be ill formed if the guard fails (#21801)
- = Just (mkLams (reverse remaining_bndrs) (mkCast fun co))
+ = Just (mkLams (reverse remaining_bndrs) (mkCastMCo fun co))
- go _remaining_bndrs _fun _ = -- pprTrace "tER fail" (ppr _fun $$ ppr _remaining_bndrs) $
- Nothing
+ | otherwise
+ = Nothing
---------------
-- See Note [Eta reduction makes sense], point (1)
@@ -2777,18 +2803,18 @@ tryEtaReduce rec_ids bndrs body eval_sd
---------------
-- See Note [Eta reduction soundness], this is THE place to check soundness!
is_eta_reduction_sound fun
- | fun `elemUnVarSet` rec_ids -- Criterion (R)
+ | fun `elemUnVarSet` rec_ids -- Criterion (EtaR)
= False -- Don't eta-reduce in fun in its own recursive RHSs
- | cantEtaReduceFun fun -- Criteria (J), (W), (B)
+ | cantEtaReduceFun fun -- Criteria (EtaJ), (EtaW), (EtaB)
= False -- Function can't be eta reduced to arity 0
-- without violating invariants of Core and GHC
| otherwise
= -- Check that eta-reduction won't make the program stricter...
- fun_arity fun >= incoming_arity -- Criterion (A) and (E)
- || all_calls_with_arity incoming_arity -- Criterion (S)
- || all ok_lam bndrs -- Criterion (T)
+ fun_arity fun >= incoming_arity -- Criterion (EtaA) and (EtaE)
+ || all_calls_with_arity incoming_arity -- Criterion (EtaS)
+ || all ok_lam bndrs -- Criterion (EtaT)
all_calls_with_arity n = isStrict (fst $ peelManyCalls n eval_sd)
-- See Note [Eta reduction based on evaluation context]
@@ -2797,57 +2823,76 @@ tryEtaReduce rec_ids bndrs body eval_sd
fun_arity fun
| arity > 0 = arity
| isEvaldUnfolding (idUnfolding fun) = 1
- -- See Note [Eta reduction soundness], criterion (E)
+ -- See Note [Eta reduction soundness], criterion (EtaE)
| otherwise = 0
where
arity = idArity fun
---------------
ok_lam v = isTyVar v || isEvId v
- -- See Note [Eta reduction makes sense], point (2)
-
- ---------------
- ok_arg :: Var -- Of type bndr_t
- -> CoreExpr -- Of type arg_t
- -> Coercion -- Of kind (t1~t2)
- -> Type -- Type (arg_t -> t1) of the function
- -- to which the argument is supplied
- -> Maybe (Coercion -- Of type (arg_t -> t1 ~ bndr_t -> t2)
- -- (and similarly for tyvars, coercion args)
- , [CoreTickish])
- -- See Note [Eta reduction with casted arguments]
- ok_arg bndr (Type arg_ty) co fun_ty
- | Just tv <- getTyVar_maybe arg_ty
- , bndr == tv = case splitForAllForAllTyBinder_maybe fun_ty of
- Just (Bndr _ vis, _) -> Just (fco, [])
- where !fco = mkForAllCo tv vis coreTyLamForAllTyFlag MRefl co
- -- The lambda we are eta-reducing always has visibility
- -- 'coreTyLamForAllTyFlag' which may or may not match
- -- the visibility on the inner function (#24014)
- Nothing -> pprPanic "tryEtaReduce: type arg to non-forall type"
- (text "fun:" <+> ppr bndr
- $$ text "arg:" <+> ppr arg_ty
- $$ text "fun_ty:" <+> ppr fun_ty)
- ok_arg bndr (Var v) co fun_ty
- | bndr == v
- , let mult = idMult bndr
- , Just (_af, fun_mult, _, _) <- splitFunTy_maybe fun_ty
- , mult `eqType` fun_mult -- There is no change in multiplicity, otherwise we must abort
- = Just (mkFunResCo Representational bndr co, [])
- ok_arg bndr (Cast e co_arg) co fun_ty
- | (ticks, Var v) <- stripTicksTop tickishFloatable e
- , Just (_, fun_mult, _, _) <- splitFunTy_maybe fun_ty
- , bndr == v
- , fun_mult `eqType` idMult bndr
- = Just (mkFunCoNoFTF Representational (multToCo fun_mult) (mkSymCo co_arg) co, ticks)
- -- The simplifier combines multiple casts into one,
- -- so we can have a simple-minded pattern match here
- ok_arg bndr (Tick t arg) co fun_ty
- | tickishFloatable t, Just (co', ticks) <- ok_arg bndr arg co fun_ty
- = Just (co', t:ticks)
-
- ok_arg _ _ _ _ = Nothing
+ -- See Note [Eta reduction soundness], point (EtaT)
+
+
+-----------------
+getTrivialHead_maybe :: CoreExpr -> Maybe (Id, MCoercion, [CoreTickish])
+-- (getTrivialHead_maybe e) returns (Just (fn, co,ts))
+-- if `e` looks like (Tick ts (fn |> co)) and ts are floatable
+-- So co :: fn_ty ~ arg_ty
+
+getTrivialHead_maybe (Var v)
+ = Just (v, MRefl, [])
+
+getTrivialHead_maybe (Cast e co_outer)
+ = do { (v, mco_inner, ticks) <- getTrivialHead_maybe e
+ ; return (v, mco_inner `mkTransMCoL` co_outer, ticks) }
+
+getTrivialHead_maybe (Tick t arg)
+ | tickishFloatable t
+ = do { (v, co, ticks) <- getTrivialHead_maybe arg
+ ; return (v, co, t:ticks) }
+
+getTrivialHead_maybe _ = Nothing
+
+-----------------
+mkEtaReduceFunCo :: Type -> MCoercion -> MCoercion -> Maybe MCoercion
+mkEtaReduceFunCo _ MRefl MRefl
+ = Just MRefl -- Very common case
+mkEtaReduceFunCo fun_ty arg_mco res_mco
+ | Just (ftf, mult, arg_ty, res_ty) <- splitFunTy_maybe fun_ty
+ -- fun_ty = arg_ty -> res_ty
+ -- sym arg_mco : arg_ty ~ inner_arg_ty
+ -- res_mco : res_ty ~ outer_res_ty
+ , let arg_co = mCoToCo Representational arg_ty arg_mco
+ res_co = mCoToCo Representational res_ty res_mco
+ mult_co = multToCo mult
+ ftf' = chooseFunTyFlag (coercionLKind arg_co) (coercionRKind res_co)
+ = Just (MCo (mkFunCo2 Representational ftf ftf' mult_co (mkSymCo arg_co) res_co))
+ -- (arg_ty -> res_ty) ~ (inner_arg_ty -> outer_res_ty)
+ | otherwise
+ = Nothing
+-----------------
+mkEtaReduceForAllMCo :: ForAllTyBinder -> Type -> TyVar -> MCoercion -> MCoercion
+-- Very similar to mkEtaForAllMCo, but with
+-- the visibilities the other way around. Tiresome.
+-- mkEtaReduceForAllMCo (forall a[vis]. body_ty) b (co :: ty1 ~ ty2)
+-- (where `b` may be free in `ty1` and `ty2`)
+-- = ForAllCo b[vis]~[spec]. (co :: ty1 ~ ty2)
+-- where `coreTyLamForAllTyFlag` is [spec]
+mkEtaReduceForAllMCo (Bndr fun_tv vis) body_ty tv mco
+ = case mco of
+ MRefl | isCoreTyLamForAllTyFlag vis
+ -- The lambda we are eta-reducing always has visibility
+ -- 'coreTyLamForAllTyFlag' which may or may not match the
+ -- visibility on the inner function (#24014)
+ -> MRefl
+ | otherwise
+ -> MCo $ mkForAllCo fun_tv vis coreTyLamForAllTyFlag MRefl refl_co
+ MCo co -> MCo $ mkForAllCo tv vis coreTyLamForAllTyFlag MRefl co
+ -- Tricky: `fun_tv` scopes over `body_ty` and hence over `refl_co`
+ -- but: `tv` scopes over `mco` and hence over `co`
+ where
+ refl_co = mkRepReflCo body_ty
{- *********************************************************************
* *
=====================================
compiler/GHC/Core/Opt/OccurAnal.hs
=====================================
@@ -42,7 +42,6 @@ import GHC.Core.Utils ( exprIsTrivial, isDefaultAlt, isExpandableApp,
import GHC.Core.Opt.Arity ( joinRhsArity, isOneShotBndr )
import GHC.Core.Coercion
import GHC.Core.Type
-import GHC.Core.TyCo.FVs ( tyCoVarsOfMCo )
import GHC.Data.Maybe( orElse )
import GHC.Data.Graph.Directed ( SCC(..), Node(..)
@@ -2227,7 +2226,7 @@ lambda and casts, e.g.
* Why do we take care to account for intervening casts? Answer:
currently we don't do eta-expansion and cast-swizzling in a stable
- unfolding (see Historical-note [Eta-expansion in stable unfoldings]).
+ unfolding (see Note [Eta expansion in stable unfoldings and rules])
So we can get
f = \x. ((\y. ...x...y...) |> co)
Now, since the lambdas aren't together, the occurrence analyser will
=====================================
compiler/GHC/Core/Opt/Pipeline.hs
=====================================
@@ -352,8 +352,25 @@ runMaybe :: Maybe a -> (a -> CoreToDo) -> CoreToDo
runMaybe (Just x) f = f x
runMaybe Nothing _ = CoreDoNothing
-{- Note [Inline in InitialPhase]
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+{- Note [The InitialPhase of the Simplifier]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The first run of the simplifier, historically called "gentle" simplification,
+has phase=InitialPhase, which does a number of things:
+
+* Usually sm_case_case is switched off in this phase; see
+ Note [Case-of-case and full laziness] and `initGentleSimplMode`
+
+* Inlining, however, is not switched off in InitialPhase.
+ See Note [Inline in InitialPhase]
+
+* Rules can run in InitialPhase
+ Note [RULEs enabled in InitialPhase]
+
+* Lint is a little aggressive about loop-breaker warnings in InitialPhase.
+ See `check_lbs` in `GHC.Core.Lint.perPassFlags`.
+
+Note [Inline in InitialPhase]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In GHC 8 and earlier we did not inline anything in the InitialPhase. But that is
confusing for users because when they say INLINE they expect the function to inline
right away.
=====================================
compiler/GHC/Core/Opt/Simplify/Env.hs
=====================================
@@ -355,12 +355,18 @@ This simplifier phase is stored in the sm_phase field of SimplMode, usin
the 'SimplPhase' constructor. This allows us to determine which rules/inlinings
are active.
-When we invoke the simplifier on the RHS of a rule, such as 'rhs' above, instead
-of setting the simplifier mode to a single phase, we use a phase range
-corresponding to the range of phases in which the rule is active, with the
-'SimplPhaseRange' constructor. This allows us to check whether other rules or
-inlinings are active throughout the whole activation of the rule.
-See Note [What is active in the RHS of a RULE or unfolding?] in GHC.Core.Opt.Simplify.Utils.
+Wrinkles
+
+(SP1) InitialPhase: see Note [The InitialPhase of the Simplifier]
+ in GHC.Core.Opt.Pipeline.
+
+(SP2) Phase ranges. When we invoke the simplifier on the RHS of a rule, such as
+ `rhs` above, instead of setting the simplifier mode to a single phase, we use a
+ phase /range/ corresponding to the range of phases in which the rule is active,
+ with the 'SimplPhaseRange' constructor. This allows us to check whether other
+ rules or inlinings are active throughout the whole activation of the rule. See
+ Note [What is active in the RHS of a RULE or unfolding?] in
+ GHC.Core.Opt.Simplify.Utils.
-}
instance Outputable SimplMode where
@@ -1234,6 +1240,8 @@ out_id so that its arity is visible in its RHS. Examples:
Example: `f = \x. f x`. See Note [Eta reduction in recursive RHSs] for how
we prevent that.
+c.f. (EtaA) in Note [Eta reduction soundness] in GHC.Core.Opt.Arity.
+
Note [Robust OccInfo]
~~~~~~~~~~~~~~~~~~~~~
It's important that we *do* retain the loop-breaker OccInfo, because
=====================================
compiler/GHC/Core/Opt/Simplify/Inline.hs
=====================================
@@ -126,11 +126,6 @@ activeUnfolding mode id
| otherwise
= isActive (sm_phase mode) (idInlineActivation id)
&& sm_inline mode
- -- `or` isStableUnfolding (realIdUnfolding id)
- -- Inline things when
- -- (a) they are active
- -- (b) sm_inline says so, except that for stable unfoldings
- -- (ie pragmas) we inline anyway
-- | Report the inlining of an identifier's RHS to the user, if requested.
traceInline :: Logger -> UnfoldingOpts -> Id -> String -> SDoc -> a -> a
=====================================
compiler/GHC/Core/Opt/Simplify/Iteration.hs
=====================================
@@ -3143,7 +3143,7 @@ There have been various earlier versions of this patch:
case_bndr_evald_next _ = False
This patch was part of fixing #7542. See also
- Note [Eta reduction soundness], criterion (E) in GHC.Core.Utils.)
+ Note [Eta reduction soundness], criterion (EtaE) in GHC.Core.Opt.Arity.)
Further notes about case elimination
@@ -4959,7 +4959,7 @@ eta-expand the stable unfolding to arity N too. Simple and consistent.
Wrinkles
-* See Historical-note [Eta-expansion in stable unfoldings] in
+* See Note [Eta expansion in stable unfoldings and rules]
GHC.Core.Opt.Simplify.Utils
* Don't eta-expand a trivial expr, else each pass will eta-reduce it,
=====================================
compiler/GHC/Core/Opt/Simplify/Utils.hs
=====================================
@@ -1319,43 +1319,6 @@ But this old note is no longer relevant because the specialiser has
improved: see Note [Account for casts in binding] in
GHC.Core.Opt.Specialise. So we seem to have a free choice.
-Note [Inlining in gentle mode]
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Something is inlined if
- (i) the sm_inline flag is on, AND
- (ii) the thing has an INLINE pragma, AND
- (iii) the thing is inlinable in the earliest phase.
-
-Example of why (iii) is important:
- {-# INLINE [~1] g #-}
- g = ...
-
- {-# INLINE f #-}
- f x = g (g x)
-
-If we were to inline g into f's inlining, then an importing module would
-never be able to do
- f e --> g (g e) ---> RULE fires
-because the stable unfolding for f has had g inlined into it.
-
-On the other hand, it is bad not to do ANY inlining into an
-stable unfolding, because then recursive knots in instance declarations
-don't get unravelled.
-
-However, *sometimes* SimplGently must do no call-site inlining at all
-(hence sm_inline = False). Before full laziness we must be careful
-not to inline wrappers, because doing so inhibits floating
- e.g. ...(case f x of ...)...
- ==> ...(case (case x of I# x# -> fw x#) of ...)...
- ==> ...(case x of I# x# -> case fw x# of ...)...
-and now the redex (f x) isn't floatable any more.
-
-The no-inlining thing is also important for Template Haskell. You might be
-compiling in one-shot mode with -O2; but when TH compiles a splice before
-running it, we don't want to use -O2. Indeed, we don't want to inline
-anything, because the byte-code interpreter might get confused about
-unboxed tuples and suchlike.
-
Note [What is active in the RHS of a RULE or unfolding?]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Suppose we have either a RULE or a stable unfolding with an explicit activation:
@@ -1448,7 +1411,7 @@ First, consider the following example
Now, if that's the ONLY occurrence of f, it might be inlined inside g,
and thence copied multiple times when g is inlined. HENCE we treat
any occurrence in a stable unfolding as a multiple occurrence, not a single
-one; see OccurAnal.addRuleUsage.
+one; see Note [Occurrences in stable unfoldings and RULES] in GHC.Core.Opt.OccurAnal.
Second, we must be careful when simplifying the RHS that we do not apply RULES
which are not active over the whole active range of the stable unfolding.
@@ -1477,17 +1440,6 @@ strictness wrapper get activation (ActiveAfter 0). So the strictness
wrepper fails the test and won't be inlined into f's stable unfolding. That
means f can inline, expose the specialised call to g, so the specialisation
rules can fire.
-
-A note about wrappers
-~~~~~~~~~~~~~~~~~~~~~
-It's also important not to inline a worker back into a wrapper.
-A wrapper looks like
- wraper = inline_me (\x -> ...worker... )
-Normally, the inline_me prevents the worker getting inlined into
-the wrapper (initially, the worker's only call site!). But,
-if the wrapper is sure to be called, the strictness analyser will
-mark it 'demanded', so when the RHS is simplified, it'll get an ArgOf
-continuation.
-}
getUnfoldingInRuleMatch :: SimplEnv -> InScopeEnv
@@ -2158,8 +2110,9 @@ tryEtaExpandRhs :: SimplEnv -> BindContext -> OutId -> OutExpr
tryEtaExpandRhs env bind_cxt bndr rhs
| seEtaExpand env -- If Eta-expansion is on
, wantEtaExpansion rhs -- and we'd like to eta-expand e
- , do_eta_expand -- and e's manifest arity is lower than
- -- what it could be
+ , do_eta_expand -- and arity analysis finds a greater arity
+ -- than (exprArity e); NB: not manifestArity
+ -- See Note [Do not eta-expand PAPs]
-- (never true for join points)
= -- Do eta-expansion.
assertPpr( not (isJoinBC bind_cxt) ) (ppr bndr) $
@@ -2178,7 +2131,8 @@ tryEtaExpandRhs env bind_cxt bndr rhs
(do_eta_expand, arity_type) = findRhsArity arity_opts is_rec bndr rhs
wantEtaExpansion :: CoreExpr -> Bool
--- Mostly True; but False of PAPs which will immediately eta-reduce again
+-- Mostly True; but False of trivial RHSs, and of PAPs at the top of the RHS
+-- (PAPs under value lambdas are dealt with by findRhsArity)
-- See Note [Which RHSs do we eta-expand?]
wantEtaExpansion (Cast e _) = wantEtaExpansion e
wantEtaExpansion (Tick _ e) = wantEtaExpansion e
@@ -2195,24 +2149,6 @@ We now eta expand at let-bindings, which is where the payoff comes.
The most significant thing is that we can do a simple arity analysis
(in GHC.Core.Opt.Arity.findRhsArity), which we can't do for free-floating lambdas
-One useful consequence of not eta-expanding lambdas is this example:
- genMap :: C a => ...
- {-# INLINE genMap #-}
- genMap f xs = ...
-
- myMap :: D a => ...
- {-# INLINE myMap #-}
- myMap = genMap
-
-Notice that 'genMap' should only inline if applied to two arguments.
-In the stable unfolding for myMap we'll have the unfolding
- (\d -> genMap Int (..d..))
-We do not want to eta-expand to
- (\d f xs -> genMap Int (..d..) f xs)
-because then 'genMap' will inline, and it really shouldn't: at least
-as far as the programmer is concerned, it's not applied to two
-arguments!
-
Note [Which RHSs do we eta-expand?]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We don't eta-expand:
@@ -2234,7 +2170,22 @@ seems like a Good idea.
Note [Do not eta-expand PAPs]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-We used to have old_arity = manifestArity rhs, which meant that we
+We do not eta-expand a RHS that is a partial application (PAP). This
+is achieved in two places:
+
+(DEP1) A PAP at the top of the RHS, such as
+ f = g d -- g has arity 2
+ is rejected by `wantEtaExpansion`.
+
+(DEP2) A PAP under value lambdas, such as
+ f = \x. g x -- g has arity 3
+ is not eta-expanded because `findRhsArity` asks for eta-expansion
+ only if the arity it finds is greater than (exprArity rhs), and
+ `exprArity` takes account of PAPs: here (exprArity rhs) = 3.
+ Using `manifestArity` (which is 1 here) instead would eta-expand
+ to f = \x y z. g x y z.
+
+Up to 2014 we used old_arity = manifestArity rhs, which meant that we
would eta-expand even PAPs. But this gives no particular advantage,
and can lead to a massive blow-up in code size, exhibited by #9020.
Suppose we have a PAP
@@ -2250,6 +2201,17 @@ coercions and whatnot that eventually disappear again. For T9020, GHC
allocated 6.6G before, and 0.8G afterwards; and residency dropped from
1.8G to 45M.
+#27212 tried switching (DEP2) back to manifestArity, with these results:
+
+* T13960: bytestring's
+ cstring1 = \(a::Addr#) @r. cstring2 @r a -- cstring2 has arity 4
+ was eta-expanded to (\a @r k br s. cstring2 @r a k br s). That bigger
+ unfolding is inlined at every string literal, adding 6 terms per
+ literal; compile-time allocation went up by 9%.
+
+* T13056: a derived-instance method (\ @a d. lvl @a), where `lvl` is
+ bottoming, was eta-expanded, and then needlessly worker/wrappered.
+
Moreover, if we eta expand
f = g d ==> f = \x. g d x
that might in turn make g inline (if it has an inline pragma), which
@@ -2261,6 +2223,24 @@ But note that this won't eta-expand, say
Does it matter not eta-expanding such functions? I'm not sure. Perhaps
strictness analysis will have less to bite on?
+One useful consequence of not eta-expanding PAPs is this example:
+ genMap :: C a => ...
+ {-# INLINE genMap #-}
+ genMap f xs = ...
+
+ myMap :: D a => ...
+ {-# INLINE myMap #-}
+ myMap = genMap
+
+Notice that 'genMap' should only inline if applied to two arguments.
+In the stable unfolding for myMap we'll have the unfolding
+ (\d -> genMap Int (..d..))
+We do not want to eta-expand to
+ (\d f xs -> genMap Int (..d..) f xs)
+because then 'genMap' will inline, and it really shouldn't: at least
+as far as the programmer is concerned, it's not applied to two
+arguments!
+
************************************************************************
* *
=====================================
compiler/GHC/Core/Opt/SpecConstr.hs
=====================================
@@ -684,7 +684,7 @@ But regardless, SpecConstr can and should! It's easy:
Wrinkles:
* This should all work perfectly fine for newtype classes. Mind you,
- currently newtype classes are inlined fairly agressively, but we
+ currently newtype classes are inlined fairly aggressively, but we
may change that. And it would take extra code to exclude them, as
well as being unnecessary.
=====================================
compiler/GHC/Core/Opt/Specialise.hs
=====================================
@@ -3345,7 +3345,7 @@ pair_fvs :: (Id, CoreExpr) -> VarSet
pair_fvs (bndr, rhs) = exprSomeFreeVars interesting rhs
`unionVarSet` bndrFreeVars bndr
-- bndrFreeVars: don't forget variables mentioned in
- -- the rules of the bndr. C.f. OccAnal.addRuleUsage
+ -- the rules or unfolding of the bndr.
-- Also tyvars mentioned in its type; they may not appear
-- in the RHS
-- type T a = Int
=====================================
compiler/GHC/Core/TyCo/Make.hs
=====================================
@@ -58,7 +58,7 @@ module GHC.Core.TyCo.Make (
, mkAxInstCo
, mkTransCo, mkTransMCo, mkTransMCoL, mkTransMCoR
, mkProofIrrelCo
- , coToMCo, kindCoToMKindCo
+ , coToMCo, kindCoToMKindCo, mCoToCo
, mkCoherenceLeftCo, mkCoherenceRightCo, mkCoherenceRightMCo
, toPhantomCo, mkPhantomCo
, isReflCo, isReflMCo, isReflKindCo, isReflKindMCo, isReflCo_maybe
@@ -860,7 +860,7 @@ mkHomoForAllCos vs orig_co
= foldr go orig_co vs
where
go :: ForAllTyBinder -> Coercion -> Coercion
- go (Bndr var vis) co = mk_forall_co var vis vis MRefl co
+ go (Bndr var vis) co = mkForAllCoNonRefl var vis vis MRefl co
mkHomoForAllCo :: TyVar -> Coercion -> Coercion
-- Specialised for a single TyVar,
@@ -869,7 +869,7 @@ mkHomoForAllCo tv orig_co
| Just (ty, r) <- isReflCo_maybe orig_co
= mkReflCo r (mkForAllTy (Bndr tv vis) ty)
| otherwise
- = mk_forall_co tv vis vis MRefl orig_co
+ = mkForAllCoNonRefl tv vis vis MRefl orig_co
where
vis = coreTyLamForAllTyFlag
@@ -892,15 +892,15 @@ mkForAllCo v visL visR kind_co co
| Just refl_co <- isReflForAllCo v visL visR kind_co co
= refl_co
| otherwise
- = mk_forall_co v visL visR kind_co co
+ = mkForAllCoNonRefl v visL visR kind_co co
--- | `mk_forall_co` just builds a ForAllCo.
+-- | `mkForAllCoNonRefl` just builds a ForAllCo.
-- With debug on, it checks invariants (e.g. he kind of the tycovar should
-- be the left-hand kind of the kind coercion).
-- Callers should have done any isReflCo short-cutting.
-mk_forall_co :: TyCoVar -> ForAllTyFlag -> ForAllTyFlag
- -> KindMCoercion -> Coercion -> Coercion
-mk_forall_co tcv visL visR kind_co co
+mkForAllCoNonRefl :: TyCoVar -> ForAllTyFlag -> ForAllTyFlag
+ -> KindMCoercion -> Coercion -> Coercion
+mkForAllCoNonRefl tcv visL visR kind_co co
= assertGoodForAllCo tcv visL visR kind_co co $
assertPpr (not (isReflCo co && isReflMCo kind_co && visL `eqForAllVis` visR)) (ppr co) $
ForAllCo { fco_tcv = tcv, fco_visL = visL, fco_visR = visR
@@ -1289,6 +1289,10 @@ coToMCo :: Coercion -> MCoercion
coToMCo co | isReflCo co = MRefl
| otherwise = MCo co
+mCoToCo :: Role -> Type -> MCoercion -> Coercion
+mCoToCo role ty MRefl = mkReflCo role ty
+mCoToCo _ _ (MCo co) = co
+
kindCoToMKindCo :: KindCoercion -> KindMCoercion
-- Convert a KindCoercion to a KindMCoercion,
-- coToMCo doesn't eliminate GRefl, but kindCoToMCo can
=====================================
compiler/GHC/Core/Type.hs
=====================================
@@ -160,7 +160,7 @@ module GHC.Core.Type (
-- * Type free variables
tyCoVarsOfType, tyCoVarsOfTypes, tyCoVarsOfTypeDSet,
- coVarsOfType, coVarsOfTypes,
+ tyCoVarsOfMCo, coVarsOfType, coVarsOfTypes,
anyFreeVarsOfType, anyFreeVarsOfTypes,
noFreeVarsOfType,
=====================================
compiler/GHC/Core/Utils.hs
=====================================
@@ -2392,7 +2392,7 @@ canCollectArgsThroughTick id t
= tickishFloatable t || cantEtaReduceFun id
-- | Can we eta-reduce the given function?
--- See Note [Eta reduction soundness], criteria (B), (J), and (W).
+-- See Note [Eta reduction soundness], criteria (EtaB), (EtaJ), and (EtaW).
cantEtaReduceFun :: Id -> Bool
cantEtaReduceFun fun
= hasNoBinding fun -- (B)
@@ -3295,17 +3295,16 @@ Now
the caller guarantees to pass an EPT argument (see Note [EPT enforcement] in
GHC.Core.Stg.EnforceEpt)
- * The code generator will discard that "extra eval" case, because $wfoo is
- CBV.
+ * The code generator will discard that "extra eval" case, because $wfoo is CBV.
See also Note [CBV Function Ids: overview].
-In tihs case the argument is known to be properly tagged at the call site so there is
+In this case the argument is known to be properly tagged at the call site so there is
no additional work for the caller and the worker can be more efficient since it can
assume the presence of a tag.
This is especially true for recursive functions like this:
- -- myPred expect it's argument properly tagged
+ -- myPred expects its argument properly tagged
-- The EnforceEPT pass has made it a CBV function
myPred !x = ...
@@ -3414,16 +3413,17 @@ This note deals with the second part.
There are multiple reasons why we might not want to insert a seq in the rhs to
strictify a functions argument:
-1) The argument doesn't exist at runtime.
- For zero width types (like Types) there is no benefit as we don't operate on them
- at runtime at all. This includes things like void#, coercions and state tokens.
+(WIS1) The argument doesn't exist at runtime: types are erased.
-2) The argument is a unlifted type.
- If the argument is a unlifted type the calling convention already is explicitly
+(WIS2) For zero width types there is no benefit as we don't operate on them at
+ runtime at all. This includes things like void#, coercions and state tokens.
+
+(WIS3) The argument is a unlifted type.
+ If the argument is an unlifted type the calling convention already is explicitly
cbv. This means inserting a seq on this argument wouldn't do anything as the seq
would be a no-op *and* it wouldn't affect the calling convention.
-3) The argument is absent.
+(WIS4) The argument is absent.
If the argument is absent in the body there is no advantage to it being passed as
cbv to the function. The function won't ever look at it so we don't save any work.
@@ -3445,7 +3445,7 @@ strictify a functions argument:
Note [Absent fillers] has an example of this. However this is so rare it's not worth
caring about here.
-5) Functions
+(WIS5) Functions
Functions are tricky (see Note [TagInfo of functions] in EnforceEpt).
But the gist of it even if we make a higher order function argument strict
we can't avoid the tag check when it's used later in the body.
@@ -3453,7 +3453,7 @@ strictify a functions argument:
Wrinkles:
-(WIS1) You might have thought that we can omit the eval if the argument is used
+(WIS6) You might have thought that we can omit the eval if the argument is used
strictly demanded in the body. But you'd be wrong. Consider this code:
data T = MkT ![Int]
f t = case t of MkT xs{Dmd=STR} -> reverse xs
@@ -3509,25 +3509,30 @@ Wrinkles:
wantCbvForId :: Var -> Bool
wantCbvForId v
-- Must be a runtime var.
- -- See Note [Which Ids should be strictified] point 1)
- | isId v
- , not $ isZeroBitTy ty
+ -- See (WIS1) in Note [Which Ids should be strictified]
+ | not (isRuntimeVar v) = False
+
+ -- Not zero-width value
+ -- See (WIS2) in Note [Which Ids should be strictified]
+ | isZeroBitTy ty = False
+
-- Unlifted things don't need special measures to be treated as cbv
- -- See Note [Which Ids should be strictified] point 2)
- , mightBeLiftedType ty
+ -- See (WIS3) in Note [Which Ids should be strictified]
+ | definitelyUnliftedType ty = False
+
+ -- If the var is absent, don't add a seq
+ -- See (WIS4) in Note [Which Ids should be strictified]
+ | isAbsDmd (idDemandInfo v) = False
+
-- Functions sometimes get a zero tag so we can't eliminate the tag check.
-- See Note [TagInfo of functions] in EnforceEpt.
- -- See Note [Which Ids should be strictified] point 5)
- , not $ isFunTy ty
- -- If the var is strict already a seq is redundant.
- -- See Note [Which Ids should be strictified] point 4)
- , not (isAbsDmd dmd)
- = True
- | otherwise
- = False
+ -- See (WIS5) in Note [Which Ids should be strictified]
+ | isFunTy ty = False
+
+ -- Finally! We should add a `seq`
+ | otherwise = True
where
ty = idType v
- dmd = idDemandInfo v
{- *********************************************************************
* *
=====================================
compiler/GHC/Driver/Config/Core/Opt/Simplify.hs
=====================================
@@ -77,6 +77,7 @@ initSimplMode dflags phase name = SimplMode
}
initGentleSimplMode :: DynFlags -> SimplMode
+-- See Note [The InitialPhase of the Simplifier] in GHC.Core.Opt.Pipeline
initGentleSimplMode dflags = (initSimplMode dflags InitialPhase "Gentle")
{ -- Don't do case-of-case transformations.
-- This makes full laziness work better
=====================================
compiler/GHC/Utils/Logger.hs
=====================================
@@ -485,7 +485,7 @@ dumpSDocWithStyle dumps log_action sty logflags flag hdr doc =
let d = timeStamp
$$ blankLine
$$ doc
- return $ mkDumpDoc hdr d
+ return $ mkDumpDoc herald d
-- When we dump to files we use UTF8. Which allows ascii spaces.
defaultLogActionHPrintDoc logflags True handle (withPprStyle sty doc')
@@ -493,9 +493,15 @@ dumpSDocWithStyle dumps log_action sty logflags flag hdr doc =
writeDump Nothing = do
let (doc', msg_class)
| null hdr = (doc, MCOutput)
- | otherwise = (mkDumpDoc hdr doc, MCDump)
+ | otherwise = (mkDumpDoc herald doc, MCDump)
log_action logflags msg_class noSrcSpan (withPprStyle sty doc')
+ -- We use a different herald for some dumps, so that we
+ -- can more easily skip the high-volume ones
+ herald = line <+> text hdr <+> line
+ line = case flag of
+ Opt_D_dump_simpl_trace -> text "-------"
+ _ -> text "===================="
-- | Run an action with the handle of a 'DumpFlag' if we are outputting to a
-- file, otherwise 'Nothing'.
@@ -600,18 +606,17 @@ logTraceMsg logger hdr doc a = putTraceMsg logger (logFlags logger) hdr doc a
-- | Log a dump message (not a dump file)
logDumpMsg :: Logger -> String -> SDoc -> IO ()
-logDumpMsg logger hdr doc = logMsg logger MCDump noSrcSpan
- (withPprStyle defaultDumpStyle
- (mkDumpDoc hdr doc))
-
-mkDumpDoc :: String -> SDoc -> SDoc
-mkDumpDoc hdr doc
- = vcat [blankLine,
- line <+> text hdr <+> line,
- doc,
- blankLine]
- where
- line = text "===================="
+logDumpMsg logger hdr doc
+ = logMsg logger MCDump noSrcSpan
+ (withPprStyle defaultDumpStyle
+ (mkDumpDoc herald doc))
+ where
+ herald = text "------" <+> text hdr <+> text "------"
+
+mkDumpDoc :: SDoc -- Herald
+ -> SDoc -- Payload
+ -> SDoc
+mkDumpDoc herald doc = vcat [blankLine, herald, doc, blankLine]
-- | Dump if the given DumpFlag is set
=====================================
compiler/Language/Haskell/Syntax/Binds/InlinePragma.hs
=====================================
@@ -124,11 +124,15 @@ Note [inl_inline and inl_act]
INLINABLE, OPAQUE, or nothing at all
* inl_act says in what phases the unfolding is active or inactive
- E.g If you write INLINE[1] then inl_act will be set to ActiveAfter 1
- If you write NOINLINE[1] then inl_act will be set to ActiveBefore 1
- If you write NOINLINE[~1] then inl_act will be set to ActiveAfter 1
- So note that inl_act does not say what pragma you wrote: it just
- expresses its consequences
+ E.g If you write then inl_act will be set to
+ INLINE AlwaysActive
+ INLINE[1] ActiveAfter 1
+ INLINE[~1] ActiveBefore 1
+ NOINLINE[1] ActiveAfter 1
+ NOINLINE[~1] ActiveBefore 1
+ NOINLINE NeverActive
+ So note that inl_act does not say what pragma you wrote:
+ it just expresses its consequences
* inl_act just says when the unfolding is active; it doesn't say what
to inline. If you say INLINE f, then f's inl_act will be AlwaysActive,
=====================================
docs/users_guide/debug-info.rst
=====================================
@@ -69,8 +69,9 @@ Here we used the ``-g`` option to inform GHC that it should add debugging
information in the produced binary. There are three levels of debugging
output: ``-g0`` (no debugging information, the default), ``-g1`` (sufficient for
basic backtraces), ``-g2`` (or just ``-g`` for short; emitting everything GHC knows).
-Note that this debugging information does not affect the optimizations performed
-by GHC.
+Note that this debugging information does not affect the optimizations
+that GHC attempts to perform; but it can affect how successful it is in
+performing them (see #21471, #27687).
.. tip::
Under Mac OS X debug information is kept apart from the executable. After
=====================================
docs/users_guide/using-optimisation.rst
=====================================
@@ -1817,7 +1817,7 @@ as such you shouldn't need to set any of them explicitly. A flag
:type: dynamic
:category:
- :default: 80
+ :default: 90
.. index::
single: inlining, controlling
=====================================
testsuite/tests/dmdanal/sigs/T21888a.stderr
=====================================
@@ -7,7 +7,7 @@ T21888a.wombat: <S!P(S)>b
==================== Cpr signatures ====================
-T21888a.f: 2
+T21888a.f:
T21888a.g: 1
T21888a.wombat: b
=====================================
testsuite/tests/printer/T18052a.stderr
=====================================
@@ -10,11 +10,11 @@ Dependent packages: [(normal, base-4.23.0.0)]
==================== Tidy Core ====================
Result size of Tidy Core
- = {terms: 24, types: 52, coercions: 0, joins: 0/0}
+ = {terms: 18, types: 46, coercions: 0, joins: 0/0}
--- RHS size: {terms: 7, types: 6, coercions: 0, joins: 0/0}
+-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0}
T18052a.$b:||: :: forall {a} {b}. a -> b -> (a, b)
-T18052a.$b:||: = \ (@a) (@b) (x :: a) (y :: b) -> (x, y)
+T18052a.$b:||: = GHC.Internal.Tuple.(,)
-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0}
(+++) :: forall {a}. [a] -> [a] -> [a]
=====================================
testsuite/tests/simplCore/should_compile/T24726.stderr
=====================================
@@ -1,5 +1,5 @@
-==================== Rule check ====================
+------ Rule check ------
Rule check results:
--------------------
Expression: concatMapS @(*) @Int @Int foo1
@@ -8,7 +8,7 @@ Rule "concatMap": all arguments match (considered individually), but rule as a w
-==================== Rule check ====================
+------ Rule check ------
Rule check results:
--------------------
Expression: concatMapS @(*) @Int @Int foo1
@@ -17,7 +17,7 @@ Rule "concatMap": all arguments match (considered individually), but rule as a w
-==================== Rule check ====================
+------ Rule check ------
Rule check results:
--------------------
Expression: concatMapS @(*) @Int @Int foo1
@@ -26,7 +26,7 @@ Rule "concatMap": all arguments match (considered individually), but rule as a w
-==================== Rule check ====================
+------ Rule check ------
Rule check results:
--------------------
Expression: concatMapS @(*) @Int @Int foo1
=====================================
testsuite/tests/simplCore/should_compile/T27212.hs
=====================================
@@ -0,0 +1,18 @@
+{-# OPTIONS_GHC -Wno-inaccessible-code -Wno-overlapping-patterns #-}
+module T27212 where
+
+import Unsafe.Coerce
+
+class Given a where given :: a
+newtype Gift a r = Gift (Given a => r)
+
+useIt :: Given Int => Int
+useIt = given + 1
+{-# NOINLINE useIt #-}
+
+foo :: [Int] -> [Int]
+foo xs = case unsafeEqualityProof @(Gift Int Int) @(Int -> Int) of
+ UnsafeRefl -> map (\y -> (Gift useIt :: Gift Int Int) y) xs
+ -- That (\y. glah y) can eta-reduce to `glah`
+ -- but doing so makes a FunCo coercion that crosses from
+ -- Type to constraint. Tricky.
=====================================
testsuite/tests/simplCore/should_compile/all.T
=====================================
@@ -631,3 +631,4 @@ test('T27936', normal, compile, [''])
test('T27910', grep_errmsg(r'KnownBranch'), compile, ['-O -dno-typeable-binds -ddump-simpl-stats -dsuppress-uniques'])
test('T27892', grep_errmsg(r'^f = g$'), compile, ['-O -ddump-cse -dsuppress-all -dsuppress-uniques'])
test('T28095a', grep_errmsg(r'^f = g$'), compile, ['-O -ddump-cse -dsuppress-all -dsuppress-uniques'])
+test('T27212', normal, compile, ['-O'])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/46235ab57884e30dfd46d79544a0b6…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/46235ab57884e30dfd46d79544a0b6…
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
1
0