Skip to content

GHC allocates a thunk for a function that captures no free variables.

I came across this STG code:

Rec {
go24_rdAG :: [GHC.Types.Bool] -> Data.Semigroup.Internal.Any
[GblId, Arity=1, Str=<1L>, Unf=OtherCon []] =
    {} \r [ds_sECM]
        case ds_sECM of {
          [] -> GHC.Types.False #45 [];
          : y_sECO [Occ=Once1] ys_sECP [Occ=Once1] ->
              let {
                sat_sECT [Occ=Once1] :: GHC.Types.Bool
                [LclId] =
                    {ys_sECP} \u [] go24_rdAG ys_sECP; } in
              let {
                sat_sECS [Occ=Once1] :: GHC.Types.Bool
                [LclId] =
                    {y_sECO} \u []
                        let {
                          sat_sECR [Occ=Once1!T[1]] :: GHC.Types.Bool -> GHC.Types.Bool
                          [LclId] =
                              {} \u [] Data.Foldable.and2;
                        } in  sat_sECR y_sECO; } in
              let {
                sat_sECQ [Occ=Once1!]
                  :: GHC.Types.Bool -> GHC.Types.Bool -> GHC.Types.Bool
                [LclId] =
                    {} \u [] GHC.Classes.||;
              } in  sat_sECQ sat_sECS sat_sECT;
        };
end Rec }

Which is pretty bad in all manner of ways. However what stood out in particular is the thunk for sat_sECQ which is just ||. It's forced right after too.

The core looks like this:

-- RHS size: {terms: 11, types: 15, coercions: 5, joins: 0/0}
go23_rdAF
  :: [(BlockId, EdgeInfo)] -> base:Data.Semigroup.Internal.Any
[GblId, Arity=1, Str=<1L>, Unf=OtherCon []]
go23_rdAF
  = \ (ds_X2A :: [(BlockId, EdgeInfo)]) ->
      case ds_X2A of {
        [] ->
          ghc-prim:GHC.Types.False
          `cast` (Sym (base:Data.Semigroup.Internal.N:Any[0])
                  :: Bool ~R# base:Data.Semigroup.Internal.Any);
        : y_X2C ys_X2D ->
          ((scc<GHC.CmmToAsm.CFG.mkGlobalWeights>
            scc<GHC.CmmToAsm.CFG.staticBranchPrediction> ||)
             ((scc<GHC.CmmToAsm.CFG.mkGlobalWeights>
               scc<GHC.CmmToAsm.CFG.staticBranchPrediction> lvl63_rdwO)
                y_X2C)
             ((go23_rdAF ys_X2D)
              `cast` (base:Data.Semigroup.Internal.N:Any[0]
                      :: base:Data.Semigroup.Internal.Any ~R# Bool)))
          `cast` (Sym (base:Data.Semigroup.Internal.N:Any[0])
                  :: Bool ~R# base:Data.Semigroup.Internal.Any)
      }
end Rec }

This is when compiling without profiling. I used hadrian/build -j6 --flavour=default+no_profiled_libs+ipe+ticky_ghc -o_ticky --freeze1 so the scc annotations shouldn't affect anything.

I think this is a bug where we assume the scc annotations matter during Core->STG but then discard them after leaving us with questionable code.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information