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
3 changed files:
- compiler/GHC/Core/Opt/OccurAnal.hs
- compiler/GHC/Core/Opt/Simplify/Iteration.hs
- compiler/GHC/Core/Utils.hs
Changes:
| ... | ... | @@ -3454,7 +3454,7 @@ addBndrSwap scrut case_bndr |
| 3454 | 3454 | , scrut_var /= case_bndr
|
| 3455 | 3455 | -- Consider: case x of x { ... }
|
| 3456 | 3456 | -- Do not add [x :-> x] to occ_bs_env, else lookupBndrSwap will loop
|
| 3457 | - = env { occ_bs_env = extendVarEnv swap_env scrut_var (case_bndr', mco)
|
|
| 3457 | + = env { occ_bs_env = extendVarEnv swap_env scrut_var (case_bndr', mkSymMCo mco)
|
|
| 3458 | 3458 | , occ_bs_rng = rng_vars `extendVarSet` case_bndr'
|
| 3459 | 3459 | `unionVarSet` tyCoVarsOfMCo mco }
|
| 3460 | 3460 |
| ... | ... | @@ -3593,11 +3593,13 @@ addAltUnfoldings env case_bndr bndr_swap con_app |
| 3593 | 3593 | env1 = addBinderUnfolding env case_bndr con_app_unf
|
| 3594 | 3594 | |
| 3595 | 3595 | -- See Note [Add unfolding for scrutinee]
|
| 3596 | + -- e.g. case (x |> co) of K a b -> blah
|
|
| 3597 | + -- We add to `x` the unfolding (K a b |> sym co)
|
|
| 3596 | 3598 | env2 | DoBinderSwap v mco <- bndr_swap
|
| 3597 | 3599 | = addBinderUnfolding env1 v $
|
| 3598 | 3600 | if isReflMCo mco -- isReflMCo: avoid calling mk_simple_unf
|
| 3599 | 3601 | then con_app_unf -- twice in the common case
|
| 3600 | - else mk_simple_unf (mkCastMCo con_app mco)
|
|
| 3602 | + else mk_simple_unf (mkCastMCo con_app (mkSymMCo mco))
|
|
| 3601 | 3603 | |
| 3602 | 3604 | | otherwise = env1
|
| 3603 | 3605 |
| ... | ... | @@ -597,7 +597,7 @@ data BinderSwapDecision |
| 597 | 597 | |
| 598 | 598 | scrutOkForBinderSwap :: OutExpr -> BinderSwapDecision
|
| 599 | 599 | -- If (scrutOkForBinderSwap e = DoBinderSwap v mco, then
|
| 600 | --- v = e |> mco
|
|
| 600 | +-- e = v |> mco
|
|
| 601 | 601 | -- See Note [Case of cast]
|
| 602 | 602 | -- See Historical Note [Care with binder-swap on dictionaries]
|
| 603 | 603 | --
|
| ... | ... | @@ -609,7 +609,7 @@ scrutOkForBinderSwap e |
| 609 | 609 | = case e of
|
| 610 | 610 | Tick _ e -> scrutOkForBinderSwap e -- Drop ticks
|
| 611 | 611 | Var v -> DoBinderSwap v MRefl
|
| 612 | - Cast (Var v) co -> DoBinderSwap v (MCo (mkSymCo co))
|
|
| 612 | + Cast (Var v) co -> DoBinderSwap v (MCo co)
|
|
| 613 | 613 | -- Cast: see Note [Case of cast]
|
| 614 | 614 | _ -> NoBinderSwap
|
| 615 | 615 |