diff options
author | Tom Smeding <tom@tomsmeding.com> | 2024-09-13 23:07:04 +0200 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2024-09-13 23:07:04 +0200 |
commit | 94938d648e021d2ace0f3b7bf383d256449d619f (patch) | |
tree | ef077de27b08027c7117761c3efc7d29b7ad3d56 /src/Simplify.hs | |
parent | 3d8a6cca424fc5279c43a266900160feb28aa715 (diff) |
WIP better zero/plus, fixing Accum (...)
The accumulator implementation was wrong because it forgot (in accumAdd)
to take into account that values may be variably-sized. Furthermore, it
was also complexity-inefficient because it did not build up a sparse
value. Thus let's go for the Haskell-interpreter-equivalent of what a
real, fast, compiled implementation would do: just a tree with mutable
variables. In practice one can decide to indeed flatten parts of that
tree, i.e. using a tree representation for nested pairs is bad, but that
should have been done _before_ execution and for _all_ occurrences of
that type fragment, not live at runtime by the accumulator
implementation.
Diffstat (limited to 'src/Simplify.hs')
-rw-r--r-- | src/Simplify.hs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/Simplify.hs b/src/Simplify.hs index 1640729..3ac68ed 100644 --- a/src/Simplify.hs +++ b/src/Simplify.hs @@ -68,6 +68,8 @@ simplify' = \case -- TODO: constant folding for operations + -- TODO: accum of zero, plus of zero + EVar _ t i -> EVar ext t i ELet _ a b -> ELet ext (simplify' a) (simplify' b) EPair _ a b -> EPair ext (simplify' a) (simplify' b) @@ -92,6 +94,8 @@ simplify' = \case EOp _ op e -> EOp ext op (simplify' e) EWith e1 e2 -> EWith (simplify' e1) (let ?accumInScope = True in simplify' e2) EAccum i e1 e2 e3 -> EAccum i (simplify' e1) (simplify' e2) (simplify' e3) + EZero t -> EZero t + EPlus t a b -> EPlus t (simplify' a) (simplify' b) EError t s -> EError t s cheapExpr :: Expr x env t -> Bool @@ -129,6 +133,8 @@ hasAdds = \case EOp _ _ e -> hasAdds e EWith a b -> hasAdds a || hasAdds b EAccum _ _ _ _ -> True + EZero _ -> False + EPlus _ a b -> hasAdds a || hasAdds b EError _ _ -> False checkAccumInScope :: SList STy env -> Bool |