sheaf pushed to branch wip/andreask/ticked_joins at Glasgow Haskell Compiler / GHC

Commits:

4 changed files:

Changes:

  • compiler/GHC/Core/Lint.hs
    ... ... @@ -1151,7 +1151,11 @@ lintJoinBndrType :: OutType -- Type of the body
    1151 1151
     -- E.g. join j x = rhs in body
    
    1152 1152
     --      The type of 'rhs' must be the same as the type of 'body'
    
    1153 1153
     lintJoinBndrType body_ty bndr
    
    1154
    -  | JoinPoint { joinPointArity = arity } <- idJoinPointHood bndr
    
    1154
    +  | JoinPoint
    
    1155
    +    { joinPointArity = arity
    
    1156
    +    , joinPointType = TrueJoinPoint
    
    1157
    +      -- SLD TODO: quasi join points can have intervening casts
    
    1158
    +    } <- idJoinPointHood bndr
    
    1155 1159
       , let bndr_ty = idType bndr
    
    1156 1160
       , (bndrs, res) <- splitPiTys bndr_ty
    
    1157 1161
       = do let msg =
    

  • compiler/GHC/Core/Opt/OccurAnal.hs
    ... ... @@ -1127,7 +1127,7 @@ occAnalNonRecRhs !env lvl imp_rule_edges mb_join bndr rhs
    1127 1127
         -- returned by of occAnalLamTail. It's totally OK for them to mismatch;
    
    1128 1128
         -- hence adjust the UDs from the RHS
    
    1129 1129
     
    
    1130
    -    WUD adj_rhs_uds final_rhs = adjustNonRecRhs (joinPointHoodArity mb_join) $
    
    1130
    +    WUD adj_rhs_uds final_rhs = adjustNonRecRhs mb_join $
    
    1131 1131
                                     occAnalLamTail rhs_env rhs
    
    1132 1132
         final_bndr_with_rules
    
    1133 1133
           | noBinderSwaps env = bndr -- See Note [Unfoldings and rules]
    
    ... ... @@ -1217,7 +1217,7 @@ occAnalRec !_ lvl
    1217 1217
       = WUD body_uds binds
    
    1218 1218
       | otherwise
    
    1219 1219
       = let (bndr', mb_join) = tagNonRecBinder lvl occ bndr
    
    1220
    -        !(WUD rhs_uds' rhs') = adjustNonRecRhs (joinPointHoodArity mb_join) wtuds
    
    1220
    +        !(WUD rhs_uds' rhs') = adjustNonRecRhs mb_join wtuds
    
    1221 1221
         in WUD (body_uds `andUDs` rhs_uds')
    
    1222 1222
                (NonRec bndr' rhs' : binds)
    
    1223 1223
       where
    
    ... ... @@ -2621,7 +2621,7 @@ occAnal env app@(App _ _)
    2621 2621
       = occAnalApp env (collectArgsTicks tickishFloatable app)
    
    2622 2622
     
    
    2623 2623
     occAnal env expr@(Lam {})
    
    2624
    -  = adjustNonRecRhs Nothing $ -- Nothing <=> markAllManyNonTail
    
    2624
    +  = adjustNonRecRhs NotJoinPoint $ -- NotJoinPoint <=> markAllManyNonTail
    
    2625 2625
         occAnalLamTail env expr
    
    2626 2626
     
    
    2627 2627
     occAnal env (Case scrut bndr ty alts)
    
    ... ... @@ -2749,7 +2749,7 @@ occAnalApp env (Var fun, args, ticks)
    2749 2749
       --     This caused #18296
    
    2750 2750
       | fun `hasKey` runRWKey
    
    2751 2751
       , [t1, t2, arg]  <- args
    
    2752
    -  , WUD usage arg' <- adjustNonRecRhs (Just 1) $ occAnalLamTail env arg
    
    2752
    +  , WUD usage arg' <- adjustNonRecRhs (JoinPoint TrueJoinPoint 1) $ occAnalLamTail env arg
    
    2753 2753
       = let app_out = mkTicks ticks $ mkApps (Var fun) [t1, t2, arg']
    
    2754 2754
         in WUD usage app_out
    
    2755 2755
     
    
    ... ... @@ -3975,21 +3975,21 @@ lookupOccInfoByUnique (UD { ud_env = env
    3975 3975
     -------------------
    
    3976 3976
     -- See Note [Adjusting right-hand sides]
    
    3977 3977
     
    
    3978
    -adjustNonRecRhs :: Maybe JoinArity
    
    3978
    +adjustNonRecRhs :: JoinPointHood
    
    3979 3979
                     -> WithTailUsageDetails CoreExpr
    
    3980 3980
                     -> WithUsageDetails CoreExpr
    
    3981 3981
     -- ^ This function concentrates shared logic between occAnalNonRecBind and the
    
    3982 3982
     -- AcyclicSCC case of occAnalRec.
    
    3983 3983
     -- It returns the adjusted rhs UsageDetails combined with the body usage
    
    3984
    -adjustNonRecRhs mb_join_arity (WTUD (TUD rhs_ja uds) rhs)
    
    3984
    +adjustNonRecRhs mb_join (WTUD (TUD rhs_ja uds) rhs)
    
    3985 3985
       = WUD (adjustTailUsage exact_join rhs uds) rhs
    
    3986 3986
       where
    
    3987 3987
         exact_join =
    
    3988
    -      case mb_join_arity of
    
    3989
    -        Nothing -> Nothing
    
    3990
    -        Just ja' ->
    
    3988
    +      case mb_join of
    
    3989
    +        NotJoinPoint -> Nothing
    
    3990
    +        JoinPoint { joinPointArity = ja', joinPointType = ty } ->
    
    3991 3991
               if ja' == rhs_ja
    
    3992
    -          then Just TrueJoinPoint
    
    3992
    +          then Just ty
    
    3993 3993
               else Nothing
    
    3994 3994
     
    
    3995 3995
     adjustTailUsage :: HasDebugCallStack
    
    ... ... @@ -4120,11 +4120,8 @@ decideRecJoinPointHood :: TopLevelFlag -> UsageDetails
    4120 4120
                            -> [CoreBndr] -> Maybe JoinPointType
    
    4121 4121
     decideRecJoinPointHood lvl usage bndrs = do
    
    4122 4122
       bndrsNE <- NE.nonEmpty bndrs
    
    4123
    -  res <- Semi.sconcat <$> traverse ok bndrsNE  -- Invariant 3: Either all are join points or none are
    
    4124
    -  pprTraceM "decideRecJoinPointHood" $
    
    4125
    -    vcat [ text "bndrs:" <+> ppr bndrs
    
    4126
    -         , text "res:" <+> ppr res ]
    
    4127
    -  return res
    
    4123
    +  -- Invariant 3: Either all are join points or none are
    
    4124
    +  Semi.sconcat <$> traverse ok bndrsNE
    
    4128 4125
       where
    
    4129 4126
         ok bndr = okForJoinPoint lvl bndr (lookupTailCallInfo usage bndr)
    
    4130 4127
     
    
    ... ... @@ -4132,10 +4129,11 @@ okForJoinPoint :: TopLevelFlag -> Id -> TailCallInfo -> Maybe JoinPointType
    4132 4129
         -- See Note [Invariants on join points]; invariants cited by number below.
    
    4133 4130
         -- Invariant 2 is always satisfiable by the simplifier by eta expansion.
    
    4134 4131
     okForJoinPoint lvl bndr tail_call_info
    
    4135
    -  | Just join_ty <- joinId_maybe bndr
    
    4132
    +  | isJoinId bndr
    
    4136 4133
       -- A current join point should still be one!
    
    4137 4134
       = warnPprTrace lost_join "Lost join point" lost_join_doc $
    
    4138
    -    Just join_ty
    
    4135
    +      mb_valid_join
    
    4136
    +    -- NB: we might downgrade 'TrueJoinPoint' to 'QuasiJoinPoint'.
    
    4139 4137
       | otherwise
    
    4140 4138
       = mb_valid_join
    
    4141 4139
       where
    

  • compiler/GHC/Core/Opt/SetLevels.hs
    ... ... @@ -1895,7 +1895,7 @@ newPolyBndrs dest_lvl
    1895 1895
           , not dest_is_top
    
    1896 1896
           = asJoinId new_bndr
    
    1897 1897
               join_ty
    
    1898
    -          ( join_arity + length abs_vars )
    
    1898
    +          (join_arity + length abs_vars)
    
    1899 1899
           | otherwise
    
    1900 1900
           = new_bndr
    
    1901 1901
     
    

  • compiler/GHC/Core/Opt/Simplify/Iteration.hs
    ... ... @@ -2088,7 +2088,7 @@ simplNonRecJoinPoint env bndr rhs body cont
    2088 2088
             ; return (floats1 `addFloats` floats2, body') }
    
    2089 2089
       where
    
    2090 2090
         do_case_case
    
    2091
    -      | Just TrueJoinPoint <- occInfoJoinPointType_maybe (idOccInfo bndr)
    
    2091
    +      | Just TrueJoinPoint <- joinId_maybe bndr
    
    2092 2092
           = seCaseCase env
    
    2093 2093
           | otherwise
    
    2094 2094
           = False
    
    ... ... @@ -2114,7 +2114,7 @@ simplRecJoinPoint env pairs body cont
    2114 2114
            ; return (floats1 `addFloats` floats2, body') }
    
    2115 2115
       where
    
    2116 2116
         do_case_case =
    
    2117
    -      if all ((== Just TrueJoinPoint) . occInfoJoinPointType_maybe . idOccInfo . fst) pairs
    
    2117
    +      if all ((== Just TrueJoinPoint) . joinId_maybe . fst) pairs
    
    2118 2118
           then seCaseCase env
    
    2119 2119
           else False
    
    2120 2120
     
    
    ... ... @@ -2154,15 +2154,15 @@ trimJoinCont :: Id -- Used only in error message
    2154 2154
     trimJoinCont _ NotJoinPoint cont
    
    2155 2155
       = cont -- Not a jump
    
    2156 2156
     trimJoinCont var (JoinPoint { joinPointType = join_ty, joinPointArity = arity }) cont
    
    2157
    -  | QuasiJoinPoint <- join_ty
    
    2158
    -  -- SLD TODO
    
    2159
    -  = cont
    
    2160
    -  | otherwise
    
    2161 2157
       = trim arity cont
    
    2162 2158
       where
    
    2163 2159
         trim 0 cont@(Stop {})
    
    2164 2160
           = cont
    
    2165 2161
         trim 0 cont
    
    2162
    +      | QuasiJoinPoint <- join_ty
    
    2163
    +      -- SLD TODO explain
    
    2164
    +      = cont
    
    2165
    +      | otherwise
    
    2166 2166
           = mkBoringStop (contResultType cont)
    
    2167 2167
         trim n cont@(ApplyToVal { sc_cont = k })
    
    2168 2168
           = cont { sc_cont = trim (n-1) k }