Add length guard to eta reduction (#1)
commitcf270e8bf1a75d75f4aba48c8b194c99f20beb61
authorNathan Faubion <natefaubion@users.noreply.github.com>
dateTue 23 Aug 2022, 12:09 (4 years ago)
parentb2c1d05
backend-es/test/snapshots-out/Snapshot.EtaReduceRegression01.jsnew file+9
@@ -0,0 +1,9 @@
1+import * as $runtime from "../runtime.js";
2+const identity = x => x;
3+const fold = dictFoldable => dictMonoid => dictFoldable.foldMap(dictMonoid)(identity);
4+const test = v1 => {
5+ if (v1.tag === "Nothing") { return ""; }
6+ if (v1.tag === "Just") { return v1._1; }
7+ $runtime.fail();
8+};
9+export {fold, identity, test};
backend-es/test/snapshots/Snapshot.EtaReduceRegression01.pursnew file+12
@@ -0,0 +1,12 @@
1+module Snapshot.EtaReduceRegression01 where
2+
3+import Prelude
4+
5+import Data.Foldable (class Foldable, foldMap)
6+import Data.Maybe (Maybe)
7+
8+fold :: forall f a. Foldable f => Monoid a => f a -> a
9+fold = foldMap identity
10+
11+test :: Maybe String -> String
12+test = fold
backend-es/test/snapshots/spago.dhall−2
@@ -13,11 +13,9 @@
1313 , "integers"
1414 , "lists"
1515 , "maybe"
16− , "newtype"
1716 , "partial"
1817 , "prelude"
1918 , "profunctor-lenses"
20− , "qualified-do"
2119 , "record"
2220 , "refs"
2321 , "safe-coerce"
src/PureScript/Backend/Optimizer/Semantics.purs+1
@@ -1209,6 +1209,7 @@ shouldEtaReduce :: Level -> BackendExpr -> BackendExpr -> Maybe BackendExpr
12091209shouldEtaReduce level1 binding = case _ of
12101210 ExprSyntax _ (Abs args1 (ExprSyntax _ (App (ExprSyntax _ (Local _ level2)) args2)))
12111211 | level1 == level2
1212+ , NonEmptyArray.length args1 == NonEmptyArray.length args2
12121213 , and $ NonEmptyArray.zipWith isSameArg args1 args2 ->
12131214 Just binding
12141215 _ ->