on master help sign in
javascript: collapse some more tailcalls
1a3acberaichoo
src/IRTS/CodegenJavaScript.hs+13−1
@@ -1062,7 +1062,7 @@ extractLocalConstructors js =
1062
1062
1063evalCons :: [JS] -> [JS]
1063evalCons :: [JS] -> [JS]
1064evalCons js =
1064evalCons js =
1065− map (expandProj . evalCons') js
1065+ map (collapseTC . expandProj . evalCons') js
1066 where
1066 where
1067 cons :: [(String, JS)]
1067 cons :: [(String, JS)]
1068 cons = concatMap getGlobalCons js
1068 cons = concatMap getGlobalCons js
@@ -1095,6 +1095,18 @@ evalCons js =
1095 match js = transformJS match js
1095 match js = transformJS match js
1096
1096
1097
1097
1098+ collapseTC :: JS -> JS
1099+ collapseTC js = transformJS match js
1100+ where
1101+ match :: JS -> JS
1102+ match (JSApp (JSIdent "__IDRRT__tailcall") [JSFunction [] (
1103+ JSReturn (JSIdent name)
1104+ )])
1105+ | Just _ <- lookup name cons = (JSIdent name)
1106+
1107+ match js = transformJS match js
1108+
1109+
1098getGlobalCons :: JS -> [(String, JS)]
1110getGlobalCons :: JS -> [(String, JS)]
1099getGlobalCons js = foldJS match (++) [] js
1111getGlobalCons js = foldJS match (++) [] js
1100 where
1112 where