| ... |
... |
@@ -2056,16 +2056,19 @@ is a join point, and what 'cont' is, in a value of type MaybeJoinCont |
|
2056
|
2056
|
of a SpecConstr-generated RULE for a join point.
|
|
2057
|
2057
|
-}
|
|
2058
|
2058
|
|
|
2059
|
|
--- SLD TODO horrible logic that must be removed
|
|
2060
|
|
-peelJoinResTy :: Int -> Type -> Type
|
|
2061
|
|
-peelJoinResTy 0 ty = ty
|
|
2062
|
|
-peelJoinResTy n ty
|
|
2063
|
|
- | Just (_bndr, inner_ty) <- splitForAllTyCoVar_maybe ty
|
|
2064
|
|
- = peelJoinResTy n inner_ty
|
|
2065
|
|
- | Just (_, _mult, _arg, res_ty) <- splitFunTy_maybe ty
|
|
2066
|
|
- = peelJoinResTy (n-1) res_ty
|
|
2067
|
|
- | otherwise
|
|
2068
|
|
- = ty
|
|
|
2059
|
+joinResTy :: HasDebugCallStack => JoinArity -> Type -> Type
|
|
|
2060
|
+joinResTy n0 ty0 = go n0 ty0
|
|
|
2061
|
+ where
|
|
|
2062
|
+ go !n ty
|
|
|
2063
|
+ | Just (_bndr, res_ty) <- splitPiTy_maybe ty
|
|
|
2064
|
+ = go (n-1) res_ty
|
|
|
2065
|
+ | otherwise
|
|
|
2066
|
+ = pprPanic "joinResTy" $
|
|
|
2067
|
+ vcat [ text "join arity:" <+> ppr n0
|
|
|
2068
|
+ , text "join ty:" <+> ppr ty0
|
|
|
2069
|
+ , text "n:" <+> ppr n
|
|
|
2070
|
+ , text "ty:" <+> ppr ty
|
|
|
2071
|
+ ]
|
|
2069
|
2072
|
|
|
2070
|
2073
|
simplNonRecJoinPoint :: SimplEnv -> InId -> InExpr
|
|
2071
|
2074
|
-> InExpr -> SimplCont
|
| ... |
... |
@@ -2078,12 +2081,18 @@ simplNonRecJoinPoint env bndr rhs body cont |
|
2078
|
2081
|
; let (mult, res_ty)
|
|
2079
|
2082
|
-- SLD TODO
|
|
2080
|
2083
|
| Just QuasiJoinPoint <- joinId_maybe bndr
|
|
2081
|
|
- = (idMult bndr, peelJoinResTy (idJoinArity bndr) $ substTy env (idType bndr))
|
|
|
2084
|
+ = (idMult bndr, joinResTy (idJoinArity bndr) $ substTy env (idType bndr))
|
|
2082
|
2085
|
| otherwise
|
|
2083
|
2086
|
= (contHoleScaling cont, contResultType cont)
|
|
|
2087
|
+
|
|
|
2088
|
+ -- SLD TODO explain, refactor
|
|
|
2089
|
+ ; let bind_cont
|
|
|
2090
|
+ | do_case_case = cont
|
|
|
2091
|
+ | otherwise = mkBoringStop res_ty
|
|
|
2092
|
+
|
|
2084
|
2093
|
; (env1, bndr1) <- simplNonRecJoinBndr env bndr mult res_ty
|
|
2085
|
|
- ; (env2, bndr2) <- addBndrRules env1 bndr bndr1 (BC_Join NonRecursive cont)
|
|
2086
|
|
- ; (floats1, env3) <- simplJoinBind NonRecursive cont (bndr,env) (bndr2,env2) (rhs,env)
|
|
|
2094
|
+ ; (env2, bndr2) <- addBndrRules env1 bndr bndr1 (BC_Join NonRecursive bind_cont)
|
|
|
2095
|
+ ; (floats1, env3) <- simplJoinBind NonRecursive bind_cont (bndr,env) (bndr2,env2) (rhs,env)
|
|
2087
|
2096
|
; (floats2, body') <- simplExprF env3 body cont
|
|
2088
|
2097
|
; return (floats1 `addFloats` floats2, body') }
|
|
2089
|
2098
|
where
|
| ... |
... |
@@ -2096,23 +2105,30 @@ simplNonRecJoinPoint env bndr rhs body cont |
|
2096
|
2105
|
simplRecJoinPoint :: SimplEnv -> [(InId, InExpr)]
|
|
2097
|
2106
|
-> InExpr -> SimplCont
|
|
2098
|
2107
|
-> SimplM (SimplFloats, OutExpr)
|
|
2099
|
|
-simplRecJoinPoint env pairs body cont
|
|
2100
|
|
- = wrapJoinCont do_case_case env cont $ \ env cont ->
|
|
|
2108
|
+simplRecJoinPoint env pairs body cont0
|
|
|
2109
|
+ = wrapJoinCont do_case_case env cont0 $ \ env cont ->
|
|
2101
|
2110
|
do { let bndrs = map fst pairs
|
|
2102
|
2111
|
(mult, res_ty)
|
|
2103
|
2112
|
-- SLD TODO
|
|
2104
|
|
- | [b] <- bndrs
|
|
|
2113
|
+ | b:_ <- bndrs
|
|
2105
|
2114
|
, Just QuasiJoinPoint <- joinId_maybe b
|
|
2106
|
|
- = (idMult b, peelJoinResTy (idJoinArity b) $ substTy env (idType b))
|
|
|
2115
|
+ = (idMult b, joinResTy (idJoinArity b) $ substTy env (idType b))
|
|
2107
|
2116
|
| otherwise
|
|
2108
|
2117
|
= (contHoleScaling cont, contResultType cont)
|
|
2109
|
2118
|
; env1 <- simplRecJoinBndrs env bndrs mult res_ty
|
|
2110
|
2119
|
-- NB: bndrs' don't have unfoldings or rules
|
|
2111
|
2120
|
-- We add them as we go down
|
|
2112
|
|
- ; (floats1, env2) <- simplRecBind env1 (BC_Join Recursive cont) pairs
|
|
|
2121
|
+
|
|
|
2122
|
+ -- SLD TODO explain, refactor
|
|
|
2123
|
+ ; let bind_cont
|
|
|
2124
|
+ | do_case_case = cont
|
|
|
2125
|
+ | otherwise = mkBoringStop res_ty
|
|
|
2126
|
+
|
|
|
2127
|
+ ; (floats1, env2) <- simplRecBind env1 (BC_Join Recursive bind_cont) pairs
|
|
2113
|
2128
|
; (floats2, body') <- simplExprF env2 body cont
|
|
2114
|
2129
|
; return (floats1 `addFloats` floats2, body') }
|
|
2115
|
2130
|
where
|
|
|
2131
|
+
|
|
2116
|
2132
|
do_case_case =
|
|
2117
|
2133
|
if all ((== Just TrueJoinPoint) . joinId_maybe . fst) pairs
|
|
2118
|
2134
|
then seCaseCase env
|