Simon Peyton Jones pushed to branch wip/spj-try-opt-coercion at Glasgow Haskell Compiler / GHC Commits: eb6c0cc3 by Simon Peyton Jones at 2026-01-15T14:17:12+00:00 Comments only - - - - - 8a1aa810 by Simon Peyton Jones at 2026-01-15T16:54:19+00:00 Try dropping all optimisation The Simplifier just calls substCo, instead of optCoRefl - - - - - 6 changed files: - compiler/GHC/Core.hs - compiler/GHC/Core/Lint.hs - compiler/GHC/Core/Opt/Simplify/Iteration.hs - compiler/GHC/Core/SimpleOpt.hs - compiler/GHC/Core/Utils.hs - compiler/GHC/Types/Literal.hs Changes: ===================================== compiler/GHC/Core.hs ===================================== @@ -190,7 +190,7 @@ These data types are the heart of the compiler -- -- See Note [Core binding invariants] -- See Note [Representation polymorphism invariants] --- See Note [Core type and coercion invariant] +-- See Note [Core type and coercion invariants] -- -- * Case expression. Operationally this corresponds to evaluating -- the scrutinee (expression examined) to weak head normal form @@ -449,7 +449,7 @@ OR * Have a RHS that is ok-for-speculation NB: this only applies to /non-recursive/ bindings. For recursive -(or top-level) bindings see Note [Top-level binding invariants]. +(or top-level) bindings see Note [Top/rec binding invariants]. This means that the let can be floated around without difficulty. For example, this is OK: @@ -2122,13 +2122,13 @@ mkLetRec [] body = body mkLetRec bs body = Let (Rec bs) body -- | Create a binding group where a type variable is bound to a type. --- Per Note [Core type and coercion invariant], +-- Per Note [Core type and coercion invariants], -- this can only be used to bind something in a non-recursive @let@ expression mkTyBind :: TyVar -> Type -> CoreBind mkTyBind tv ty = NonRec tv (Type ty) -- | Create a binding group where a type variable is bound to a type. --- Per Note [Core type and coercion invariant], +-- Per Note [Core type and coercion invariants], -- this can only be used to bind something in a non-recursive @let@ expression mkCoBind :: CoVar -> Coercion -> CoreBind mkCoBind cv co = NonRec cv (Coercion co) ===================================== compiler/GHC/Core/Lint.hs ===================================== @@ -183,7 +183,7 @@ Note [Linting type lets] In the desugarer, it's very very convenient to be able to say (in effect) let a = Type Bool in let x::a = True in <body> -That is, use a type let. See Note [Core type and coercion invariant] in "GHC.Core". +That is, use a type let. See Note [Core type and coercion invariants] in "GHC.Core". One place it is used is in mkWwBodies; see Note [Join points and beta-redexes] in GHC.Core.Opt.WorkWrap.Utils. (Maybe there are other "clients" of this feature; I'm not sure). @@ -582,7 +582,7 @@ lintLetBind top_lvl rec_flag binder rhs rhs_ty ; ensureEqTys binder_ty rhs_ty (mkRhsMsg binder (text "RHS") rhs_ty) -- If the binding is for a CoVar, the RHS should be (Coercion co) - -- See Note [Core type and coercion invariant] in GHC.Core + -- See Note [Core type and coercion invariants] in GHC.Core ; checkL (not (isCoVar binder) || isCoArg rhs) (mkLetErr binder rhs) ===================================== compiler/GHC/Core/Opt/Simplify/Iteration.hs ===================================== @@ -26,7 +26,7 @@ import GHC.Core.Opt.OccurAnal ( occurAnalyseExpr, zapLambdaBndrs, scrutOkForBind import GHC.Core.Make ( FloatBind, mkImpossibleExpr, castBottomExpr ) import qualified GHC.Core.Make import GHC.Core.Coercion hiding ( substCo, substCoVar ) -import GHC.Core.Coercion.Opt +-- import GHC.Core.Coercion.Opt import GHC.Core.Reduction import GHC.Core.FamInstEnv ( FamInstEnv, topNormaliseType_maybe ) import GHC.Core.DataCon @@ -1390,7 +1390,8 @@ simplCoercionF env co cont simplCoercion :: SimplEnv -> InCoercion -> SimplM OutCoercion simplCoercion env co - = do { let out_co = optCoRefl (getTCvSubst env) co + = do { let out_co = -- optCoRefl (getTCvSubst env) co + substCo env co ; seqCo out_co `seq` return out_co } ----------------------------------- @@ -3211,7 +3212,7 @@ doCaseToLet :: OutExpr -- Scrutinee -- Can we transform thus? let { b = scrut } in body doCaseToLet scrut case_bndr | isTyCoVar case_bndr -- Respect GHC.Core - = isTyCoArg scrut -- Note [Core type and coercion invariant] + = isTyCoArg scrut -- Note [Core type and coercion invariants] | isUnliftedType (exprType scrut) -- We can call isUnliftedType here: scrutinees always have a fixed RuntimeRep (see FRRCase). ===================================== compiler/GHC/Core/SimpleOpt.hs ===================================== @@ -610,7 +610,7 @@ simple_bind_pair env@(SOE { soe_inl = inl_env, soe_subst = subst, soe_opts = opt | assertPpr (isNonCoVarId in_bndr) (ppr in_bndr) -- The previous two guards got rid of tyvars and coercions - -- See Note [Core type and coercion invariant] in GHC.Core + -- See Note [Core type and coercion invariants] in GHC.Core pre_inline_unconditionally = (env { soe_inl = extendVarEnv inl_env in_bndr clo }, Nothing) @@ -694,7 +694,7 @@ simple_out_bind_pair env@(SOE { soe_subst = subst, soe_opts = opts }) occ_info active stable_unf top_level | assertPpr (isNonCoVarId in_bndr) (ppr in_bndr) -- Type and coercion bindings are caught earlier - -- See Note [Core type and coercion invariant] + -- See Note [Core type and coercion invariants] post_inline_unconditionally = ( env' { soe_subst = extendIdSubst subst in_bndr out_rhs } , Nothing) ===================================== compiler/GHC/Core/Utils.hs ===================================== @@ -577,7 +577,7 @@ can be eliminated by expanding the synonym. Note [Binding coercions] ~~~~~~~~~~~~~~~~~~~~~~~~ Consider binding a CoVar, c = e. Then, we must satisfy -Note [Core type and coercion invariant] in GHC.Core, +Note [Core type and coercion invariants] in GHC.Core, which allows only (Coercion co) on the RHS. ************************************************************************ @@ -1813,10 +1813,11 @@ exprIsUnaryClassFun _ = False -- See also Note [Classifying primop effects] in "GHC.Builtin.PrimOps" -- and Note [Transformations affected by primop effects]. -- --- 'exprOkForSpeculation' is used in the definition of Note [Nested binding --- invariants]in GHC.Core. It is therefore frequently called on arguments of --- unlifted type, especially via 'needsCaseBinding'. But it is sometimes --- called on expressions of lifted type as well. For example, see +-- 'exprOkForSpeculation' is used in the definition of +-- Note [Nested non-rec binding invariants] in GHC.Core. It is therefore +-- frequently called on arguments of unlifted type, especially via +-- 'needsCaseBinding'. But it is sometimes called on expressions of +-- lifted type as well. For example, see -- Note [Speculative evaluation] in "GHC.CoreToStg.Prep". exprOkForSpeculation, exprOkToDiscard :: CoreExpr -> Bool @@ -2049,7 +2050,7 @@ But we restrict it sharply: DEFAULT -> ... (let v::Int# = case x of { ... } in ...) .... - which does /not/ satisfy Note [Nested non-rec bindings invariants], + which does /not/ satisfy Note [Nested non-rec binding invariants], because x is not evaluated. See Note [Binder-swap during float-out] in GHC.Core.Opt.SetLevels. To avoid this awkwardness it seems simpler to stick to unlifted scrutinees where the issue does not ===================================== compiler/GHC/Types/Literal.hs ===================================== @@ -1004,7 +1004,7 @@ data type. Here are the moving parts: levity/runtime-rep polymorphism naturally uphold this invariant. INVARIANT 2: we never make a rubbish literal of type (a ~# b). Reason: - see Note [Core type and coercion invariant] in GHC.Core. We can't substitute + see Note [Core type and coercion invariants] in GHC.Core. We can't substitute a LitRubbish inside a coercion, so it's best not to make one. They are zero width anyway, so passing absent ones around costs nothing. If we wanted an absent filler of type (a ~# b) we should use (Coercion (UnivCo ...)), View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/6e78fe41fd14bcd7b541774bfb5d084... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/6e78fe41fd14bcd7b541774bfb5d084... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Simon Peyton Jones (@simonpj)