From 2125c17620c701a55d6bef48cfd1abc9cf183161 Mon Sep 17 00:00:00 2001 From: Luite Stegeman <stegeman@gmail.com> Date: Wed, 8 Nov 2023 15:20:38 +0100 Subject: [PATCH] JS: Fix missing variable declarations The JStg IR update was missing some local variable declarations that were present earlier, causing global variables to be used implicitly (or an error in JavaScript strict mode). This adds the local variable declarations again. --- compiler/GHC/StgToJS/Expr.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/GHC/StgToJS/Expr.hs b/compiler/GHC/StgToJS/Expr.hs index cf4267bc863c..c379295d93f8 100644 --- a/compiler/GHC/StgToJS/Expr.hs +++ b/compiler/GHC/StgToJS/Expr.hs @@ -232,10 +232,10 @@ genEntryLne ctx i rhs@(StgRhsClosure _ext _cc update args body typ) = (L.find ((==i) . fst . snd) (zip [0..] vars)) mk_bh :: G JStgStat mk_bh | isUpdatable update = - do x <- Var <$> freshIdent + do x <- freshIdent return $ mconcat - [ x |= ApplExpr (var "h$bh_lne") [Sub sp (toJExpr myOffset), toJExpr (payloadSize+1)] - , IfStat x (ReturnStat x) mempty + [ x ||= ApplExpr (var "h$bh_lne") [Sub sp (toJExpr myOffset), toJExpr (payloadSize+1)] + , IfStat (Var x) (ReturnStat (Var x)) mempty ] | otherwise = pure mempty blk_hl <- mk_bh @@ -913,11 +913,11 @@ loadParams from args = do [ loadIfUsed (from .^ closureField1_) x1 u1 , loadIfUsed (from .^ closureField2_) x2 u2 ] - ((x,u):xs) -> do d <- Var <$> freshIdent + ((x,u):xs) -> do d <- freshIdent return $ mconcat [ loadIfUsed (from .^ closureField1_) x u - , mconcat [ d |= from .^ closureField2_ - , loadConVarsIfUsed d xs + , mconcat [ d ||= from .^ closureField2_ + , loadConVarsIfUsed (Var d) xs ] ] where -- GitLab