Merge pull request #1251 from jvoigtlaender/patch-1
Add name normalization in tail optimization code
commit29ab83c99f0956efbb82ee2e78350a71d30c5dbf
authorEvan Czaplicki <info@elm-lang.org>
dateWed 6 Jan 2016, 10:58 (11 years ago)
parent353930a293b34d
src/Generate/JavaScript/Expression.hs+1−1
@@ -157,7 +157,7 @@ generateCode expr =
157157 TailCall name argNames args ->
158158 let
159159 reassign name tempName =
160− ExprStmt () (AssignExpr () OpAssign (LVar () name) (ref tempName))
160+ ExprStmt () (AssignExpr () OpAssign (LVar () (Var.safe name)) (ref tempName))
161161 in
162162 do args' <- mapM generateJsExpr args
163163 tempNames <- mapM (\_ -> Var.fresh) args
tests/test-files/good-expected-js/CodeGenBugs/TailRecursion_NameNormalization.elm.jsnew file+10
@@ -0,0 +1,10 @@
1+Elm.Main = Elm.Main || {};
2+Elm.Main.make = function (_elm) {
3+ "use strict";
4+ _elm.Main = _elm.Main || {};
5+ if (_elm.Main.values) return _elm.Main.values;
6+ var _U = Elm.Native.Utils.make(_elm);
7+ var _op = {};
8+ var go = function (n$) { go: while (true) if (n$) { var _v0 = n$;n$ = _v0;continue go;} else return false;};
9+ return _elm.Main.values = {_op: _op,go: go};
10+};
tests/test-files/good/CodeGenBugs/TailRecursion_NameNormalization.elmnew file+8
@@ -0,0 +1,8 @@
1+-- From https://github.com/elm-lang/elm-compiler/issues/1226
2+--
3+-- When code can be tail call optimized, one of the arguments turns into
4+-- the loop variable. Its name must be properly normalized, for example,
5+-- to avoid primes.
6+
7+go n' = if n' then go n' else False
8+