Fix optimize loop guard (#52)
The loop guard was pattern matching on BackendExpr only, but the
InlineNever case was emitting BackendRewrite RewriteStop.
Fixes #49
commitc11f1e9f411ebbb4045734f7429578972836d60c
authorNathan Faubion <natefaubion@users.noreply.github.com>
dateMon 8 May 2023, 14:12 (3 years ago)
parent756bbb7
backend-es/test/snapshots-out/Snapshot.InlineNever.jsnew file+4
@@ -0,0 +1,4 @@
1+// @inline Snapshot.InlineNever.foo never
2+const foo = "foo";
3+const test = foo;
4+export {foo, test};
backend-es/test/snapshots/Snapshot.InlineNever.pursnew file+8
@@ -0,0 +1,8 @@
1+-- @inline Snapshot.InlineNever.foo never
2+module Snapshot.InlineNever where
3+
4+foo :: String
5+foo = "foo"
6+
7+test :: String
8+test = foo
src/PureScript/Backend/Optimizer/Semantics.purs+5−5
@@ -1509,11 +1509,11 @@ optimize ctx env (Qualified mn (Ident id)) initN = go initN
15091509 unsafeCrashWith $ name <> ": Possible infinite optimization loop."
15101510 | otherwise = do
15111511 let expr2 = quote ctx (eval env expr1)
1512− case expr2 of
1513− ExprSyntax (BackendAnalysis { rewrite }) _ | not rewrite ->
1514− expr2
1515− _ ->
1516− go (n - 1) expr2
1512+ let BackendAnalysis { rewrite } = analysisOf expr2
1513+ if rewrite then
1514+ go (n - 1) expr2
1515+ else
1516+ expr2
15171517
15181518freeze :: BackendExpr -> Tuple BackendAnalysis NeutralExpr
15191519freeze init = Tuple (analysisOf init) (go init)