Simon Peyton Jones pushed to branch wip/andreask/spec_tyfams at Glasgow Haskell Compiler / GHC
Commits:
-
483a939e
by Simon Peyton Jones at 2025-04-26T22:51:58+01:00
7 changed files:
- compiler/GHC/Core/Opt/Specialise.hs
- compiler/GHC/Core/Predicate.hs
- compiler/GHC/Tc/Solver.hs
- compiler/GHC/Tc/Solver/Dict.hs
- compiler/GHC/Tc/Solver/InertSet.hs
- compiler/GHC/Tc/Solver/Monad.hs
- compiler/GHC/Tc/Utils/TcType.hs
Changes:
... | ... | @@ -26,7 +26,7 @@ import GHC.Core.Make ( mkLitRubbish ) |
26 | 26 | import GHC.Core.Unify ( tcMatchTy )
|
27 | 27 | import GHC.Core.Rules
|
28 | 28 | import GHC.Core.Utils ( exprIsTrivial, exprIsTopLevelBindable
|
29 | - , mkCast, exprType
|
|
29 | + , mkCast, exprType, exprIsHNF
|
|
30 | 30 | , stripTicksTop, mkInScopeSetBndrs )
|
31 | 31 | import GHC.Core.FVs
|
32 | 32 | import GHC.Core.TyCo.FVs ( tyCoVarsOfTypeList )
|
... | ... | @@ -1646,10 +1646,10 @@ specCalls spec_imp env existing_rules calls_for_me fn rhs |
1646 | 1646 | -- See Note [Inline specialisations] for why we do not
|
1647 | 1647 | -- switch off specialisation for inline functions
|
1648 | 1648 | |
1649 | - = -- pprTrace "specCalls: some" (vcat
|
|
1650 | - -- [ text "function" <+> ppr fn
|
|
1651 | - -- , text "calls:" <+> ppr calls_for_me
|
|
1652 | - -- , text "subst" <+> ppr (se_subst env) ]) $
|
|
1649 | + = pprTrace "specCalls: some" (vcat
|
|
1650 | + [ text "function" <+> ppr fn
|
|
1651 | + , text "calls:" <+> ppr calls_for_me
|
|
1652 | + , text "subst" <+> ppr (se_subst env) ]) $
|
|
1653 | 1653 | foldlM spec_call ([], [], emptyUDs) calls_for_me
|
1654 | 1654 | |
1655 | 1655 | | otherwise -- No calls or RHS doesn't fit our preconceptions
|
... | ... | @@ -1705,7 +1705,7 @@ specCalls spec_imp env existing_rules calls_for_me fn rhs |
1705 | 1705 | , rule_bndrs, rule_lhs_args
|
1706 | 1706 | , spec_bndrs1, dx_binds, spec_args) <- specHeader env rhs_bndrs all_call_args
|
1707 | 1707 | |
1708 | - ; when False $ pprTrace "spec_call" (vcat
|
|
1708 | + ; when True $ pprTrace "spec_call" (vcat
|
|
1709 | 1709 | [ text "fun: " <+> ppr fn
|
1710 | 1710 | , text "call info: " <+> ppr _ci
|
1711 | 1711 | , text "useful: " <+> ppr useful
|
... | ... | @@ -3034,7 +3034,7 @@ mkCallUDs' :: SpecEnv -> Id -> [OutExpr] -> UsageDetails |
3034 | 3034 | mkCallUDs' env f args
|
3035 | 3035 | | wantCallsFor env f -- We want it, and...
|
3036 | 3036 | , not (null ci_key) -- this call site has a useful specialisation
|
3037 | - = -- pprTrace "mkCallUDs: keeping" _trace_doc
|
|
3037 | + = pprTrace "mkCallUDs: keeping" _trace_doc
|
|
3038 | 3038 | singleCall env f ci_key
|
3039 | 3039 | |
3040 | 3040 | | otherwise -- See also Note [Specialisations already covered]
|
... | ... | @@ -3042,7 +3042,7 @@ mkCallUDs' env f args |
3042 | 3042 | emptyUDs
|
3043 | 3043 | |
3044 | 3044 | where
|
3045 | - _trace_doc = vcat [ppr f, ppr args, ppr ci_key]
|
|
3045 | + _trace_doc = vcat [ppr f, ppr args, ppr ci_key, ppr (se_subst env)]
|
|
3046 | 3046 | pis = fst $ splitPiTys $ idType f
|
3047 | 3047 | constrained_tyvars = tyCoVarsOfTypes $ getTheta pis
|
3048 | 3048 | |
... | ... | @@ -3116,22 +3116,64 @@ There really is not much point in specialising f wrt the dictionary d, |
3116 | 3116 | because the code for the specialised f is not improved at all, because
|
3117 | 3117 | d is lambda-bound. We simply get junk specialisations.
|
3118 | 3118 | |
3119 | -What is "interesting"? Just that it has *some* structure. But what about
|
|
3120 | -variables? We look in the variable's /unfolding/. And that means
|
|
3121 | -that we must be careful to ensure that dictionaries have unfoldings,
|
|
3122 | - |
|
3123 | -* cloneBndrSM discards non-Stable unfoldings
|
|
3124 | -* specBind updates the unfolding after specialisation
|
|
3125 | - See Note [Update unfolding after specialisation]
|
|
3126 | -* bindAuxiliaryDict adds an unfolding for an aux dict
|
|
3127 | - see Note [Specialisation modulo dictionary selectors]
|
|
3128 | -* specCase adds unfoldings for the new bindings it creates
|
|
3129 | - |
|
3130 | -We accidentally lost accurate tracking of local variables for a long
|
|
3131 | -time, because cloned variables didn't have unfoldings. But makes a
|
|
3132 | -massive difference in a few cases, eg #5113. For nofib as a
|
|
3133 | -whole it's only a small win: 2.2% improvement in allocation for ansi,
|
|
3134 | -1.2% for bspt, but mostly 0.0! Average 0.1% increase in binary size.
|
|
3119 | +What is "interesting"? Our Main Plan is to use `exprIsConApp_maybe` to see
|
|
3120 | +if the argumeng is a dictionary constructor applied to some arguments, in which
|
|
3121 | +case we can clearly specialise. But there are wrinkles:
|
|
3122 | + |
|
3123 | +(ID1) Note that we look at the argument /term/, not its /type/. Suppose the
|
|
3124 | + argument is
|
|
3125 | + (% d1, d2 %) |> co
|
|
3126 | + where co :: (% Eq [a], Show [a] %) ~ F Int a, and `F` is a type family.
|
|
3127 | + Then its type (F Int a) looks very un-informative, but the term is super
|
|
3128 | + helpful. See #19747 (where missing this point caused a 70x slow down)
|
|
3129 | + and #7785.
|
|
3130 | + |
|
3131 | +(ID2) Note that the Main Plan works fine for an argument that is a DFun call,
|
|
3132 | + e.g. $fOrdList $dOrdInt
|
|
3133 | + because `exprIsConApp_maybe` cleverly deals with DFunId applications. Good!
|
|
3134 | + |
|
3135 | +(ID3) For variables, we look in the variable's /unfolding/. And that means
|
|
3136 | + that we must be careful to ensure that dictionaries /have/ unfoldings:
|
|
3137 | + * cloneBndrSM discards non-Stable unfoldings
|
|
3138 | + * specBind updates the unfolding after specialisation
|
|
3139 | + See Note [Update unfolding after specialisation]
|
|
3140 | + * bindAuxiliaryDict adds an unfolding for an aux dict
|
|
3141 | + see Note [Specialisation modulo dictionary selectors]
|
|
3142 | + * specCase adds unfoldings for the new bindings it creates
|
|
3143 | + |
|
3144 | + We accidentally lost accurate tracking of local variables for a long
|
|
3145 | + time, because cloned variables didn't have unfoldings. But makes a
|
|
3146 | + massive difference in a few cases, eg #5113. For nofib as a
|
|
3147 | + whole it's only a small win: 2.2% improvement in allocation for ansi,
|
|
3148 | + 1.2% for bspt, but mostly 0.0! Average 0.1% increase in binary size.
|
|
3149 | + |
|
3150 | +(ID4) We must be very careful not to specialise on a "dictionry" that is, or contains
|
|
3151 | + an implicit parameter, because implicit parameters are emphatically not singleton
|
|
3152 | + types. See #25999:
|
|
3153 | + useImplicit :: (?i :: Int) => Int
|
|
3154 | + useImplicit = ?i + 1
|
|
3155 | + |
|
3156 | + foo = let ?i = 1 in (useImplicit, let ?i = 2 in useImplicit)
|
|
3157 | + Both calls to `useImplicit` are at type `?i::Int`, but they pass different values.
|
|
3158 | + We must not specialise on implicit parameters! Hence the call to `couldBeIPLike`.
|
|
3159 | + |
|
3160 | +(ID5) Suppose the argument is (e |> co). Can we rely on `exprIsConApp_maybe` to deal
|
|
3161 | + with the coercion. No! That only works if (co :: C t1 ~ C t2) with the same type
|
|
3162 | + constructor at the top of both sides. But see the example in (ID1), where that
|
|
3163 | + is not true. For thes same reason, we can't rely on `exprIsConApp_maybe` to look
|
|
3164 | + through unfoldings (because there might be a cast inside), hence dealing with
|
|
3165 | + expandable unfoldings in `interestingDict` directly.
|
|
3166 | + |
|
3167 | +(ID6) The Main Plan says that it's worth specialising if the argument is an application
|
|
3168 | + of a dictionary contructor. But what if the dictionary has no methods? Then we
|
|
3169 | + gain nothing by specialising, unless the /superclasses/ are interesting. A case
|
|
3170 | + in point is constraint tuples (% d1, .., dn %); a constraint N-tuple is a class
|
|
3171 | + with N superclasses and no methods.
|
|
3172 | + |
|
3173 | +(ID7) A unary (single-method) class is currently represented by (meth |> co).
|
|
3174 | + We will unwrap the cast (see (ID5)) and then want to reply "yes" if the method
|
|
3175 | + has any struture. We use `exprIsHNF` for this. (We plan a new story for unary
|
|
3176 | + classes, see #23109, and this special case will become irrelevant.)
|
|
3135 | 3177 | |
3136 | 3178 | Note [Update unfolding after specialisation]
|
3137 | 3179 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
... | ... | @@ -3159,6 +3201,7 @@ Consider (#21848) |
3159 | 3201 | Now `f` turns into:
|
3160 | 3202 | |
3161 | 3203 | f @a @b (dd :: D a) (ds :: Show b) a b
|
3204 | + |
|
3162 | 3205 | = let dc :: D a = %p1 dd -- Superclass selection
|
3163 | 3206 | in meth @a dc ....
|
3164 | 3207 | meth @a dc ....
|
... | ... | @@ -3174,50 +3217,25 @@ in the NonRec case of specBind. (This is too exotic to trouble with |
3174 | 3217 | the Rec case.)
|
3175 | 3218 | -}
|
3176 | 3219 | |
3177 | --- interestingDict :: CoreExpr -> Type -> Bool
|
|
3178 | 3220 | interestingDict :: InScopeEnv -> CoreExpr -> Bool
|
3179 | --- A dictionary argument is interesting if it has *some* structure,
|
|
3180 | --- see Note [Interesting dictionary arguments]
|
|
3181 | --- NB: "dictionary" arguments include constraints of all sorts,
|
|
3182 | --- including equality constraints; hence the Coercion case
|
|
3183 | --- To make this work, we need to ensure that dictionaries have
|
|
3184 | --- unfoldings in them.
|
|
3185 | -interestingDict env (Cast arg _)
|
|
3221 | +-- See Note [Interesting dictionary arguments]
|
|
3222 | +interestingDict env (Var v) -- See (ID3) and (ID5)
|
|
3223 | + | Just rhs <- expandUnfolding_maybe (idUnfolding v)
|
|
3224 | + = interestingDict env rhs
|
|
3225 | +interestingDict env (Cast arg _) -- See (ID5)
|
|
3186 | 3226 | = interestingDict env arg
|
3187 | -interestingDict env arg
|
|
3227 | +interestingDict env arg -- Main Plan: use exprIsConApp_maybe
|
|
3188 | 3228 | | Just (_, _, data_con, _tys, args) <- exprIsConApp_maybe env arg
|
3189 | 3229 | , Just cls <- tyConClass_maybe (dataConTyCon data_con)
|
3190 | - , (not . isIPLikePred) (exprType arg)
|
|
3191 | - = if isCTupleClass cls
|
|
3230 | + , (not . couldBeIPLike) (exprType arg) -- See (ID4)
|
|
3231 | + = if null (classMethods cls) -- See (ID6)
|
|
3192 | 3232 | then any (interestingDict env) args
|
3193 | 3233 | else True
|
3234 | + | exprIsHNF arg -- See (ID7)
|
|
3235 | + = True
|
|
3194 | 3236 | | otherwise
|
3195 | 3237 | = False
|
3196 | 3238 | |
3197 | - |
|
3198 | --- interestingDict arg _arg_ty
|
|
3199 | --- -- No benefit to specalizing for a ~# b I believe
|
|
3200 | --- -- | (isEqPred arg_ty) = False
|
|
3201 | --- -- |
|
|
3202 | --- -- not (typeDeterminesValue arg_ty) = False -- See Note [Type determines value]
|
|
3203 | --- | otherwise = go arg
|
|
3204 | --- where
|
|
3205 | --- go (Var v) = hasSomeUnfolding (idUnfolding v)
|
|
3206 | --- || isDataConWorkId v
|
|
3207 | --- go (Type _) = False
|
|
3208 | --- go (Coercion _) = False
|
|
3209 | --- go (App fn (Type _)) = go fn
|
|
3210 | --- go (App fn (Coercion _)) = go fn
|
|
3211 | --- go (Tick _ a) = go a
|
|
3212 | --- go (Cast e _) = go e
|
|
3213 | --- go (Lit{}) = True
|
|
3214 | --- go (Case{}) = True
|
|
3215 | --- go (Let{}) = True
|
|
3216 | --- go (App{}) = True
|
|
3217 | --- go (Lam{}) = True
|
|
3218 | - |
|
3219 | - -- go _ = True
|
|
3220 | - |
|
3221 | 3239 | thenUDs :: UsageDetails -> UsageDetails -> UsageDetails
|
3222 | 3240 | thenUDs (MkUD {ud_binds = db1, ud_calls = calls1})
|
3223 | 3241 | (MkUD {ud_binds = db2, ud_calls = calls2})
|
... | ... | @@ -24,7 +24,7 @@ module GHC.Core.Predicate ( |
24 | 24 | classMethodTy, classMethodInstTy,
|
25 | 25 | |
26 | 26 | -- Implicit parameters
|
27 | - isIPLikePred, mentionsIP, isIPTyCon, isIPClass,
|
|
27 | + couldBeIPLike, mightMentionIP, isIPTyCon, isIPClass,
|
|
28 | 28 | isCallStackTy, isCallStackPred, isCallStackPredTy,
|
29 | 29 | isExceptionContextPred, isExceptionContextTy,
|
30 | 30 | isIPPred_maybe,
|
... | ... | @@ -127,7 +127,7 @@ isDictTy ty = isClassPred pred |
127 | 127 | |
128 | 128 | typeDeterminesValue :: Type -> Bool
|
129 | 129 | -- See Note [Type determines value]
|
130 | -typeDeterminesValue ty = isDictTy ty && not (isIPLikePred ty)
|
|
130 | +typeDeterminesValue ty = isDictTy ty && not (couldBeIPLike ty)
|
|
131 | 131 | |
132 | 132 | getClassPredTys :: HasDebugCallStack => PredType -> (Class, [Type])
|
133 | 133 | getClassPredTys ty = case getClassPredTys_maybe ty of
|
... | ... | @@ -424,44 +424,44 @@ isCallStackTy ty |
424 | 424 | | otherwise
|
425 | 425 | = False
|
426 | 426 | |
427 | --- --------------------- isIPLike and mentionsIP --------------------------
|
|
427 | +-- --------------------- couldBeIPLike and mightMentionIP --------------------------
|
|
428 | 428 | -- See Note [Local implicit parameters]
|
429 | 429 | |
430 | -isIPLikePred :: Type -> Bool
|
|
430 | +couldBeIPLike :: Type -> Bool
|
|
431 | 431 | -- Is `pred`, or any of its superclasses, an implicit parameter?
|
432 | 432 | -- See Note [Local implicit parameters]
|
433 | -isIPLikePred pred =
|
|
434 | - mentions_ip_pred initIPRecTc (const True) (const True) pred
|
|
435 | - |
|
436 | -mentionsIP :: (Type -> Bool) -- ^ predicate on the string
|
|
437 | - -> (Type -> Bool) -- ^ predicate on the type
|
|
438 | - -> Class
|
|
439 | - -> [Type] -> Bool
|
|
440 | --- ^ @'mentionsIP' str_cond ty_cond cls tys@ returns @True@ if:
|
|
433 | +couldBeIPLike pred
|
|
434 | + = might_mention_ip1 initIPRecTc (const True) (const True) pred
|
|
435 | + |
|
436 | +mightMentionIP :: (Type -> Bool) -- ^ predicate on the string
|
|
437 | + -> (Type -> Bool) -- ^ predicate on the type
|
|
438 | + -> Class
|
|
439 | + -> [Type] -> Bool
|
|
440 | +-- ^ @'mightMentionIP' str_cond ty_cond cls tys@ returns @True@ if:
|
|
441 | 441 | --
|
442 | 442 | -- - @cls tys@ is of the form @IP str ty@, where @str_cond str@ and @ty_cond ty@
|
443 | 443 | -- are both @True@,
|
444 | 444 | -- - or any superclass of @cls tys@ has this property.
|
445 | 445 | --
|
446 | 446 | -- See Note [Local implicit parameters]
|
447 | -mentionsIP = mentions_ip initIPRecTc
|
|
447 | +mightMentionIP = might_mention_ip initIPRecTc
|
|
448 | 448 | |
449 | -mentions_ip :: RecTcChecker -> (Type -> Bool) -> (Type -> Bool) -> Class -> [Type] -> Bool
|
|
450 | -mentions_ip rec_clss str_cond ty_cond cls tys
|
|
449 | +might_mention_ip :: RecTcChecker -> (Type -> Bool) -> (Type -> Bool) -> Class -> [Type] -> Bool
|
|
450 | +might_mention_ip rec_clss str_cond ty_cond cls tys
|
|
451 | 451 | | Just (str_ty, ty) <- isIPPred_maybe cls tys
|
452 | 452 | = str_cond str_ty && ty_cond ty
|
453 | 453 | | otherwise
|
454 | - = or [ mentions_ip_pred rec_clss str_cond ty_cond (classMethodInstTy sc_sel_id tys)
|
|
454 | + = or [ might_mention_ip1 rec_clss str_cond ty_cond (classMethodInstTy sc_sel_id tys)
|
|
455 | 455 | | sc_sel_id <- classSCSelIds cls ]
|
456 | 456 | |
457 | 457 | |
458 | -mentions_ip_pred :: RecTcChecker -> (Type -> Bool) -> (Type -> Bool) -> Type -> Bool
|
|
459 | -mentions_ip_pred rec_clss str_cond ty_cond ty
|
|
458 | +might_mention_ip1 :: RecTcChecker -> (Type -> Bool) -> (Type -> Bool) -> Type -> Bool
|
|
459 | +might_mention_ip1 rec_clss str_cond ty_cond ty
|
|
460 | 460 | | Just (cls, tys) <- getClassPredTys_maybe ty
|
461 | 461 | , let tc = classTyCon cls
|
462 | 462 | , Just rec_clss' <- if isTupleTyCon tc then Just rec_clss
|
463 | 463 | else checkRecTc rec_clss tc
|
464 | - = mentions_ip rec_clss' str_cond ty_cond cls tys
|
|
464 | + = might_mention_ip rec_clss' str_cond ty_cond cls tys
|
|
465 | 465 | | otherwise
|
466 | 466 | = False -- Includes things like (D []) where D is
|
467 | 467 | -- a Constraint-ranged family; #7785
|
... | ... | @@ -474,7 +474,7 @@ initIPRecTc = setRecTcMaxBound 1 initRecTc |
474 | 474 | See also wrinkle (SIP1) in Note [Shadowing of implicit parameters] in
|
475 | 475 | GHC.Tc.Solver.Dict.
|
476 | 476 | |
477 | -The function isIPLikePred tells if this predicate, or any of its
|
|
477 | +The function couldBeIPLike tells if this predicate, or any of its
|
|
478 | 478 | superclasses, is an implicit parameter.
|
479 | 479 | |
480 | 480 | Why are implicit parameters special? Unlike normal classes, we can
|
... | ... | @@ -482,7 +482,7 @@ have local instances for implicit parameters, in the form of |
482 | 482 | let ?x = True in ...
|
483 | 483 | So in various places we must be careful not to assume that any value
|
484 | 484 | of the right type will do; we must carefully look for the innermost binding.
|
485 | -So isIPLikePred checks whether this is an implicit parameter, or has
|
|
485 | +So couldBeIPLike checks whether this is an implicit parameter, or has
|
|
486 | 486 | a superclass that is an implicit parameter.
|
487 | 487 | |
488 | 488 | Several wrinkles
|
... | ... | @@ -523,16 +523,16 @@ Small worries (Sept 20): |
523 | 523 | think nothing does.
|
524 | 524 | * I'm a little concerned about type variables; such a variable might
|
525 | 525 | be instantiated to an implicit parameter. I don't think this
|
526 | - matters in the cases for which isIPLikePred is used, and it's pretty
|
|
526 | + matters in the cases for which couldBeIPLike is used, and it's pretty
|
|
527 | 527 | obscure anyway.
|
528 | 528 | * The superclass hunt stops when it encounters the same class again,
|
529 | 529 | but in principle we could have the same class, differently instantiated,
|
530 | 530 | and the second time it could have an implicit parameter
|
531 | 531 | I'm going to treat these as problems for another day. They are all exotic.
|
532 | 532 | |
533 | -Note [Using typesAreApart when calling mentionsIP]
|
|
534 | -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
535 | -We call 'mentionsIP' in two situations:
|
|
533 | +Note [Using typesAreApart when calling mightMentionIP]
|
|
534 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
535 | +We call 'mightMentionIP' in two situations:
|
|
536 | 536 | |
537 | 537 | (1) to check that a predicate does not contain any implicit parameters
|
538 | 538 | IP str ty, for a fixed literal str and any type ty,
|
... | ... | @@ -1902,7 +1902,7 @@ growThetaTyVars theta tcvs |
1902 | 1902 | | otherwise = transCloVarSet mk_next seed_tcvs
|
1903 | 1903 | where
|
1904 | 1904 | seed_tcvs = tcvs `unionVarSet` tyCoVarsOfTypes ips
|
1905 | - (ips, non_ips) = partition isIPLikePred theta
|
|
1905 | + (ips, non_ips) = partition couldBeIPLike theta
|
|
1906 | 1906 | -- See Note [Inheriting implicit parameters]
|
1907 | 1907 | |
1908 | 1908 | mk_next :: VarSet -> VarSet -- Maps current set to newly-grown ones
|
... | ... | @@ -749,7 +749,7 @@ shortCutSolver dflags ev_w ev_i |
749 | 749 | -- programs should typecheck regardless of whether we take this step or
|
750 | 750 | -- not. See Note [Shortcut solving]
|
751 | 751 | |
752 | - , not (isIPLikePred (ctEvPred ev_w)) -- Not for implicit parameters (#18627)
|
|
752 | + , not (couldBeIPLike (ctEvPred ev_w)) -- Not for implicit parameters (#18627)
|
|
753 | 753 | |
754 | 754 | , not (xopt LangExt.IncoherentInstances dflags)
|
755 | 755 | -- If IncoherentInstances is on then we cannot rely on coherence of proofs
|
... | ... | @@ -2013,10 +2013,10 @@ solveOneFromTheOther ct_i ct_w |
2013 | 2013 | is_wsc_orig_w = isWantedSuperclassOrigin orig_w
|
2014 | 2014 | |
2015 | 2015 | different_level_strategy -- Both Given
|
2016 | - | isIPLikePred pred = if lvl_w `strictlyDeeperThan` lvl_i then KeepWork else KeepInert
|
|
2017 | - | otherwise = if lvl_w `strictlyDeeperThan` lvl_i then KeepInert else KeepWork
|
|
2016 | + | couldBeIPLike pred = if lvl_w `strictlyDeeperThan` lvl_i then KeepWork else KeepInert
|
|
2017 | + | otherwise = if lvl_w `strictlyDeeperThan` lvl_i then KeepInert else KeepWork
|
|
2018 | 2018 | -- See Note [Replacement vs keeping] part (1)
|
2019 | - -- For the isIPLikePred case see Note [Shadowing of implicit parameters]
|
|
2019 | + -- For the couldBeIPLike case see Note [Shadowing of implicit parameters]
|
|
2020 | 2020 | -- in GHC.Tc.Solver.Dict
|
2021 | 2021 | |
2022 | 2022 | same_level_strategy -- Both Given
|
... | ... | @@ -396,8 +396,8 @@ updInertDicts dict_ct@(DictCt { di_cls = cls, di_ev = ev, di_tys = tys }) |
396 | 396 | -- an implicit parameter (?str :: ty) for the given 'str' and any type 'ty'?
|
397 | 397 | does_not_mention_ip_for :: Type -> DictCt -> Bool
|
398 | 398 | does_not_mention_ip_for str_ty (DictCt { di_cls = cls, di_tys = tys })
|
399 | - = not $ mentionsIP (not . typesAreApart str_ty) (const True) cls tys
|
|
400 | - -- See Note [Using typesAreApart when calling mentionsIP]
|
|
399 | + = not $ mightMentionIP (not . typesAreApart str_ty) (const True) cls tys
|
|
400 | + -- See Note [Using typesAreApart when calling mightMmentionIP]
|
|
401 | 401 | -- in GHC.Core.Predicate
|
402 | 402 | |
403 | 403 | updInertIrreds :: IrredCt -> TcS ()
|
... | ... | @@ -533,7 +533,7 @@ updSolvedDicts what dict_ct@(DictCt { di_cls = cls, di_tys = tys, di_ev = ev }) |
533 | 533 | = do { is_callstack <- is_tyConTy isCallStackTy callStackTyConName
|
534 | 534 | ; is_exceptionCtx <- is_tyConTy isExceptionContextTy exceptionContextTyConName
|
535 | 535 | ; let contains_callstack_or_exceptionCtx =
|
536 | - mentionsIP
|
|
536 | + mightMentionIP
|
|
537 | 537 | (const True)
|
538 | 538 | -- NB: the name of the call-stack IP is irrelevant
|
539 | 539 | -- e.g (?foo :: CallStack) counts!
|
... | ... | @@ -551,9 +551,9 @@ updSolvedDicts what dict_ct@(DictCt { di_cls = cls, di_tys = tys, di_ev = ev }) |
551 | 551 | |
552 | 552 | -- Return a predicate that decides whether a type is CallStack
|
553 | 553 | -- or ExceptionContext, accounting for e.g. type family reduction, as
|
554 | - -- per Note [Using typesAreApart when calling mentionsIP].
|
|
554 | + -- per Note [Using typesAreApart when calling mightMentionIP].
|
|
555 | 555 | --
|
556 | - -- See Note [Using isCallStackTy in mentionsIP].
|
|
556 | + -- See Note [Using isCallStackTy in mightMentionIP].
|
|
557 | 557 | is_tyConTy :: (Type -> Bool) -> Name -> TcS (Type -> Bool)
|
558 | 558 | is_tyConTy is_eq tc_name
|
559 | 559 | = do { (mb_tc, _) <- wrapTcS $ TcM.tryTc $ TcM.tcLookupTyCon tc_name
|
... | ... | @@ -581,14 +581,14 @@ in a different context! |
581 | 581 | See also Note [Shadowing of implicit parameters], which deals with a similar
|
582 | 582 | problem with Given implicit parameter constraints.
|
583 | 583 | |
584 | -Note [Using isCallStackTy in mentionsIP]
|
|
585 | -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
584 | +Note [Using isCallStackTy in mightMentionIP]
|
|
585 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
586 | 586 | To implement Note [Don't add HasCallStack constraints to the solved set],
|
587 | 587 | we need to check whether a constraint contains a HasCallStack or HasExceptionContext
|
588 | 588 | constraint. We do this using the 'mentionsIP' function, but as per
|
589 | -Note [Using typesAreApart when calling mentionsIP] we don't want to simply do:
|
|
589 | +Note [Using typesAreApart when calling mightMentions] we don't want to simply do:
|
|
590 | 590 | |
591 | - mentionsIP
|
|
591 | + mightMentionIP
|
|
592 | 592 | (const True) -- (ignore the implicit parameter string)
|
593 | 593 | (isCallStackTy <||> isExceptionContextTy)
|
594 | 594 |
... | ... | @@ -155,7 +155,7 @@ module GHC.Tc.Utils.TcType ( |
155 | 155 | mkTyConTy, mkTyVarTy, mkTyVarTys,
|
156 | 156 | mkTyCoVarTy, mkTyCoVarTys,
|
157 | 157 | |
158 | - isClassPred, isEqPred, isIPLikePred, isEqClassPred,
|
|
158 | + isClassPred, isEqPred, couldBeIPLike, isEqClassPred,
|
|
159 | 159 | isEqualityClass, mkClassPred,
|
160 | 160 | tcSplitQuantPredTy, tcSplitDFunTy, tcSplitDFunHead, tcSplitMethodTy,
|
161 | 161 | isRuntimeRepVar, isFixedRuntimeRepKind,
|
... | ... | @@ -1819,7 +1819,7 @@ pickCapturedPreds |
1819 | 1819 | pickCapturedPreds qtvs theta
|
1820 | 1820 | = filter captured theta
|
1821 | 1821 | where
|
1822 | - captured pred = isIPLikePred pred || (tyCoVarsOfType pred `intersectsVarSet` qtvs)
|
|
1822 | + captured pred = couldBeIPLike pred || (tyCoVarsOfType pred `intersectsVarSet` qtvs)
|
|
1823 | 1823 | |
1824 | 1824 | |
1825 | 1825 | -- Superclasses
|