sheaf pushed to branch wip/debug-join-point at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • compiler/GHC/Core/Opt/Simplify/Iteration.hs
    ... ... @@ -316,8 +316,8 @@ simplLazyBind :: TopLevelFlag -> RecFlag
    316 316
     -- Precondition: Ids only, no TyVars; not a JoinId
    
    317 317
     -- Precondition: rhs obeys the let-can-float invariant
    
    318 318
     simplLazyBind top_lvl is_rec (bndr,unf_se) (bndr1,env) (rhs,rhs_se)
    
    319
    -  = assert (isId bndr )
    
    320
    -    assertPpr (not (isJoinId bndr)) (ppr bndr) $
    
    319
    +  = assert (isId bndr)
    
    320
    +    assertPpr (isNothing (joinPointBinding_maybe bndr rhs)) (ppr bndr) $
    
    321 321
         -- pprTrace "simplLazyBind" ((ppr bndr <+> ppr bndr1) $$ ppr rhs $$ ppr (seIdSubst rhs_se)) $
    
    322 322
         do  { let   !rhs_env     = rhs_se `setInScopeFromE` env -- See Note [Bangs in the Simplifier]
    
    323 323
                     (tvs, body) = case collectTyAndValBinders rhs of
    
    ... ... @@ -399,7 +399,7 @@ simplAuxBind :: String
    399 399
     -- Precondition: rhs satisfies the let-can-float invariant
    
    400 400
     
    
    401 401
     simplAuxBind _str env bndr new_rhs
    
    402
    -  | assertPpr (isId bndr && not (isJoinId bndr)) (ppr bndr) $
    
    402
    +  | assertPpr (isId bndr && isNothing (joinPointBinding_maybe bndr new_rhs)) (ppr bndr) $
    
    403 403
         isDeadBinder bndr   -- Not uncommon; e.g. case (a,b) of c { (p,q) -> p }
    
    404 404
       = return (emptyFloats env, env)    --  Here c is dead, and we avoid
    
    405 405
                                          --  creating the binding c = (a,b)
    
    ... ... @@ -1905,7 +1905,7 @@ simplNonRecE :: HasDebugCallStack
    1905 1905
     -- Otherwise it may or may not satisfy it.
    
    1906 1906
     
    
    1907 1907
     simplNonRecE env from_what bndr (rhs, rhs_se) body cont
    
    1908
    -  | assert (isId bndr && not (isJoinId bndr) ) $
    
    1908
    +  | assert (isId bndr && isNothing (joinPointBinding_maybe bndr rhs)) $
    
    1909 1909
         is_strict_bind
    
    1910 1910
       = -- Evaluate RHS strictly
    
    1911 1911
         simplExprF (rhs_se `setInScopeFromE` env) rhs
    
    ... ... @@ -1943,7 +1943,7 @@ simplRecE :: SimplEnv
    1943 1943
     -- Precondition: not a join-point binding
    
    1944 1944
     simplRecE env pairs body cont
    
    1945 1945
       = do  { let bndrs = map fst pairs
    
    1946
    -        ; massert (all (not . isJoinId) bndrs)
    
    1946
    +        ; massert (isNothing $ joinPointBindings_maybe pairs)
    
    1947 1947
             ; env1 <- simplRecBndrs env bndrs
    
    1948 1948
                     -- NB: bndrs' don't have unfoldings or rules
    
    1949 1949
                     -- We add them as we go down
    
    ... ... @@ -2051,7 +2051,7 @@ simplNonRecJoinPoint :: SimplEnv -> InId -> InExpr
    2051 2051
                          -> InExpr -> SimplCont
    
    2052 2052
                          -> SimplM (SimplFloats, OutExpr)
    
    2053 2053
     simplNonRecJoinPoint env bndr rhs body cont
    
    2054
    -   = assert (isJoinId bndr ) $
    
    2054
    +   = assert (isJust $ joinPointBinding_maybe bndr rhs) $
    
    2055 2055
          wrapJoinCont env cont $ \ env cont ->
    
    2056 2056
          do { -- We push join_cont into the join RHS and the body;
    
    2057 2057
               -- and wrap wrap_cont around the whole thing
    
    ... ... @@ -4574,22 +4574,24 @@ simplLetUnfolding env bind_cxt id new_rhs rhs_ty arity unf
    4574 4574
       | isStableUnfolding unf
    
    4575 4575
       = simplStableUnfolding env bind_cxt id rhs_ty arity unf
    
    4576 4576
     
    
    4577
    -  | freshly_born_join_point id
    
    4578
    -  = -- This is a tricky one!
    
    4579
    -    -- See wrinkle (JU1) in Note [Do not add unfoldings to join points at birth]
    
    4580
    -    return noUnfolding
    
    4581
    -
    
    4582 4577
       | isExitJoinId id
    
    4583 4578
       = -- See Note [Do not inline exit join points] in GHC.Core.Opt.Exitify
    
    4584 4579
         return noUnfolding
    
    4585 4580
     
    
    4586
    -  | otherwise
    
    4587
    -  = mkLetUnfolding env (bindContextLevel bind_cxt) VanillaSrc id is_join_point new_rhs
    
    4581
    +  | freshly_born_join_point
    
    4582
    +  = -- This is a tricky one!
    
    4583
    +    -- See wrinkle (JU1) in Note [Do not add unfoldings to join points at birth]
    
    4584
    +    return noUnfolding
    
    4588 4585
     
    
    4586
    +  | otherwise
    
    4587
    +  = mkLetUnfolding env (bindContextLevel bind_cxt) VanillaSrc id' is_join new_rhs'
    
    4589 4588
       where
    
    4590
    -    is_join_point = isJoinId id
    
    4591
    -    freshly_born_join_point id = is_join_point && isManyOccs (idOccInfo id)
    
    4592
    -      -- OLD: too_many_occs (OneOcc { occ_n_br = n }) = n > 10 -- See #23627
    
    4589
    +    (id', new_rhs', is_join) =
    
    4590
    +      case joinPointBinding_maybe id new_rhs of
    
    4591
    +        Nothing -> (id, new_rhs, False)
    
    4592
    +        Just (id', new_rhs') -> (id', new_rhs', True)
    
    4593
    +    freshly_born_join_point =
    
    4594
    +      is_join && (not (isJoinId id) || isManyOccs (idOccInfo id))
    
    4593 4595
     
    
    4594 4596
     -------------------
    
    4595 4597
     mkLetUnfolding :: SimplEnv -> TopLevelFlag -> UnfoldingSource
    

  • compiler/GHC/Core/SimpleOpt.hs
    ... ... @@ -1059,28 +1059,27 @@ and again its arity increases (#15517)
    1059 1059
     -}
    
    1060 1060
     
    
    1061 1061
     
    
    1062
    --- | Returns Just (bndr,rhs) if the binding is a join point:
    
    1063
    --- If it's a JoinId, just return it
    
    1064
    --- If it's not yet a JoinId but is always tail-called,
    
    1065
    ---    make it into a JoinId and return it.
    
    1066
    --- In the latter case, eta-expand the RHS if necessary, to make the
    
    1067
    --- lambdas explicit, as is required for join points
    
    1068
    ---
    
    1069
    --- Precondition: the InBndr has been occurrence-analysed,
    
    1070
    ---               so its OccInfo is valid
    
    1062
    +-- | Returns @Just (bndr,rhs)@ if the binding is a join point or can be made
    
    1063
    +-- into a join point (it is always tail called). In the latter case, eta-expand
    
    1064
    +-- the RHS if necessary, to make the lambdas explicit, as is required for join points.
    
    1071 1065
     joinPointBinding_maybe :: InBndr -> InExpr -> Maybe (InBndr, InExpr)
    
    1072 1066
     joinPointBinding_maybe bndr rhs
    
    1073 1067
       | not (isId bndr)
    
    1074 1068
       = Nothing
    
    1075 1069
     
    
    1070
    +  -- NB: the 'OccInfo' of the 'InBndr' may have been zapped, e.g. if we
    
    1071
    +  -- have inlined it. In this case, we may lose the join-point-hood of the
    
    1072
    +  -- original binder. A later occurrence analysis pass may recover it.
    
    1076 1073
       | isJoinId bndr
    
    1077
    -  = Just (bndr, rhs)
    
    1074
    +  = case tailCallInfo (idOccInfo bndr) of
    
    1075
    +      NoTailCallInfo -> Nothing
    
    1076
    +      AlwaysTailCalled {} -> Just (bndr, rhs)
    
    1078 1077
     
    
    1079 1078
       | AlwaysTailCalled join_arity <- tailCallInfo (idOccInfo bndr)
    
    1080 1079
       , (bndrs, body) <- etaExpandToJoinPoint join_arity rhs
    
    1081 1080
       , let str_sig   = idDmdSig bndr
    
    1082 1081
             str_arity = count isId bndrs  -- Strictness demands are for Ids only
    
    1083
    -        join_bndr = bndr `asJoinId`        join_arity
    
    1082
    +        join_bndr = bndr `asJoinId`    join_arity
    
    1084 1083
                              `setIdDmdSig` etaConvertDmdSig str_arity str_sig
    
    1085 1084
       = Just (join_bndr, mkLams bndrs body)
    
    1086 1085