[Git][ghc/ghc][wip/T26615] Flip the sense of BinderSwapDecision
Simon Peyton Jones pushed to branch wip/T26615 at Glasgow Haskell Compiler / GHC Commits: fbca59fd by Simon Peyton Jones at 2025-12-01T17:40:10+00:00 Flip the sense of BinderSwapDecision It was weird before, which led to a bug in my new patch - - - - - 3 changed files: - compiler/GHC/Core/Opt/OccurAnal.hs - compiler/GHC/Core/Opt/Simplify/Iteration.hs - compiler/GHC/Core/Utils.hs Changes: ===================================== compiler/GHC/Core/Opt/OccurAnal.hs ===================================== @@ -3454,7 +3454,7 @@ addBndrSwap scrut case_bndr , scrut_var /= case_bndr -- Consider: case x of x { ... } -- Do not add [x :-> x] to occ_bs_env, else lookupBndrSwap will loop - = env { occ_bs_env = extendVarEnv swap_env scrut_var (case_bndr', mco) + = env { occ_bs_env = extendVarEnv swap_env scrut_var (case_bndr', mkSymMCo mco) , occ_bs_rng = rng_vars `extendVarSet` case_bndr' `unionVarSet` tyCoVarsOfMCo mco } ===================================== compiler/GHC/Core/Opt/Simplify/Iteration.hs ===================================== @@ -3593,11 +3593,13 @@ addAltUnfoldings env case_bndr bndr_swap con_app env1 = addBinderUnfolding env case_bndr con_app_unf -- See Note [Add unfolding for scrutinee] + -- e.g. case (x |> co) of K a b -> blah + -- We add to `x` the unfolding (K a b |> sym co) env2 | DoBinderSwap v mco <- bndr_swap = addBinderUnfolding env1 v $ if isReflMCo mco -- isReflMCo: avoid calling mk_simple_unf then con_app_unf -- twice in the common case - else mk_simple_unf (mkCastMCo con_app mco) + else mk_simple_unf (mkCastMCo con_app (mkSymMCo mco)) | otherwise = env1 ===================================== compiler/GHC/Core/Utils.hs ===================================== @@ -597,7 +597,7 @@ data BinderSwapDecision scrutOkForBinderSwap :: OutExpr -> BinderSwapDecision -- If (scrutOkForBinderSwap e = DoBinderSwap v mco, then --- v = e |> mco +-- e = v |> mco -- See Note [Case of cast] -- See Historical Note [Care with binder-swap on dictionaries] -- @@ -609,7 +609,7 @@ scrutOkForBinderSwap e = case e of Tick _ e -> scrutOkForBinderSwap e -- Drop ticks Var v -> DoBinderSwap v MRefl - Cast (Var v) co -> DoBinderSwap v (MCo (mkSymCo co)) + Cast (Var v) co -> DoBinderSwap v (MCo co) -- Cast: see Note [Case of cast] _ -> NoBinderSwap View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fbca59fd30abaf4ce2412b3f8806184e... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fbca59fd30abaf4ce2412b3f8806184e... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Simon Peyton Jones (@simonpj)