Admin message

Due to a large amount of spam we do not allow new users to create repositories, they are "external" users. If you are a new user and want to create a repository, for example for forking GHC, open a new issue on ghc/ghc using the "get-verified" issue template

GHC can put a profiling tick around the RHS of a coercion binding
See also * #26878 Consider the following 2-module program with no dependencies (extracted out from #26693): ```hs -- Ox1.hs {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE TypeOperators #-} module Ox1 where import GHC.TypeLits import Ox2 ( SMayNat(SKnown), ListH, shxHead ) shsHead :: ListH (Just n : sh) Int -> SNat n shsHead shx = case shxHead shx of SKnown SNat -> SNat -- Ox2.hs {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE StandaloneKindSignatures #-} {-# LANGUAGE TypeOperators #-} module Ox2 where import Data.Kind import GHC.TypeLits shxHead :: ListH (n : sh) i -> SMayNat i n shxHead list = {-# SCC "bad_scc" #-} ( case list of (i `ConsKnown` _) -> SKnown i ) type ListH :: [Maybe Nat] -> Type -> Type data ListH sh i where ConsKnown :: SNat n -> ListH sh i -> ListH (Just n : sh) i data SMayNat i n where SKnown :: SNat n -> SMayNat i (Just n) ``` When compiled with `ghc -O1 -prof`, GHC HEAD (version tested: 016f79d54d4) triggers the following Core Lint error: ``` [1 of 2] Compiling Ox2 ( Ox2.hs, Ox2.o ) [2 of 2] Compiling Ox1 ( Ox1.hs, Ox1.o ) *** Core Lint errors : in result of Simplifier *** Ox1.hs:12:9: warning: Bad `let' binding: Variable: co_aJI :: 'Just n_aJv ~# 'Just n1_iKr Rhs: scc<bad_scc> CO: Sym (SelCo:Tc(1,N) (Sym co_iKt)) In the RHS of shsHead :: forall (n :: Nat) (sh :: [Maybe Nat]). ListH ('Just n : sh) Int -> SNat n In the body of lambda with binder n_aJv :: Nat In the body of lambda with binder sh_aJw :: [Maybe Nat] In the body of lambda with binder shx_aIP :: ListH ('Just n_aJv : sh_aJw) Int In a case alternative: (ConsKnown n1_iKr :: Nat, sh1_iKs :: [Maybe Nat], co_iKt :: ('Just n_aJv : sh_aJw) ~# ('Just n1_iKr : sh1_iKs), i1_iKu :: SNat n1_iKr, ds_iKv :: ListH sh1_iKs Int) Substitution: <InScope = {n_aJv sh_aJw co_aJI n1_iKr sh1_iKs co_iKt} IdSubst = [] TvSubst = [] CvSubst = []> *** Offending Program *** shsHead :: forall (n :: Nat) (sh :: [Maybe Nat]). ListH ('Just n : sh) Int -> SNat n [LclIdX, Arity=1, Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=IF_ARGS [20] 50 0}] shsHead = \ (@(n_aJv :: Nat)) (@(sh_aJw :: [Maybe Nat])) (shx_aIP :: ListH ('Just n_aJv : sh_aJw) Int) -> tick<bad_scc> case shx_aIP of { ConsKnown @n1_iKr @sh1_iKs co_iKt i1_iKu ds_iKv -> let { co_aJI :: 'Just n_aJv ~# 'Just n1_iKr [LclId[CoVarId]] co_aJI = scc<bad_scc> CO: Sym (SelCo:Tc(1,N) (Sym co_iKt)) } in case withKnownNat @n1_iKr @LiftedRep @(KnownNatInstance n1_iKr) i1_iKu (KnownNatInstance @n1_iKr) of { KnownNatInstance $dKnownNat_aKL -> natSing @n_aJv ($dKnownNat_aKL `cast` ((KnownNat (SelCo:Tc(1,N) (Sym co_aJI)))_R :: KnownNat n1_iKr ~R# KnownNat n_aJv)) } } *** End of Offense *** ``` The problem is that we have: ``` let { [LclId[CoVarId]] co_aJI = scc<bad_scc> CO: Sym (SelCo:Tc(1,N) (Sym co_iKt)) } in ... ``` namely, the binding of a coercion variable whose RHS is not a (bare) coercion: it is a ticked coercion.
issue