| ... |
... |
@@ -3785,30 +3785,24 @@ simplAlt env _scrut' imposs_deflt_cons case_bndr' bndr_swap' cont' (Alt DEFAULT |
|
3785
|
3785
|
; (floats, rhs') <- simplExprF env' rhs cont'
|
|
3786
|
3786
|
; return (DEFAULT, [], floats, rhs') }
|
|
3787
|
3787
|
|
|
3788
|
|
-simplAlt env _scrut' _ case_bndr' bndr_swap' cont' (Alt (LitAlt lit) bndrs rhs)
|
|
|
3788
|
+simplAlt env _scrut' _ case_bndr' bndr_swap' cont' (Alt lit_alt@(LitAlt {}) bndrs rhs)
|
|
3789
|
3789
|
= assert (null bndrs) $
|
|
3790
|
|
- do { let env' = addAltUnfoldings env case_bndr' bndr_swap' (Lit lit)
|
|
|
3790
|
+ do { let env' = addAltUnfoldings env case_bndr' bndr_swap' lit_alt []
|
|
3791
|
3791
|
; (floats, rhs') <- simplExprF env' rhs cont'
|
|
3792
|
|
- ; return (LitAlt lit, [], floats, rhs') }
|
|
|
3792
|
+ ; return (lit_alt, [], floats, rhs') }
|
|
3793
|
3793
|
|
|
3794
|
|
-simplAlt env scrut' _ case_bndr' bndr_swap' cont' (Alt (DataAlt con) vs rhs)
|
|
|
3794
|
+simplAlt env scrut' _ case_bndr' bndr_swap' cont' (Alt data_alt@(DataAlt con) vs rhs)
|
|
3795
|
3795
|
= do { -- See Note [Adding evaluatedness info to pattern-bound variables]
|
|
3796
|
3796
|
-- and Note [DataAlt occ info]
|
|
3797
|
3797
|
; let vs_with_info = adjustFieldsIdInfo scrut' case_bndr' bndr_swap' con vs
|
|
|
3798
|
+ ; (env', vs') <- simplBinders env vs_with_info
|
|
3798
|
3799
|
-- Adjust evaluated-ness and occ-info flags before `simplBinders`
|
|
3799
|
3800
|
-- because the latter extends the in-scope set, which propagates this
|
|
3800
|
3801
|
-- adjusted info to use sites.
|
|
3801
|
3802
|
|
|
3802
|
|
- ; (env', vs') <- simplBinders env vs_with_info
|
|
3803
|
|
-
|
|
3804
|
|
- -- Bind the case-binder to (con args)
|
|
3805
|
|
- ; let inst_tys' = tyConAppArgs (idType case_bndr')
|
|
3806
|
|
- con_app :: OutExpr
|
|
3807
|
|
- con_app = mkConApp2 con inst_tys' vs'
|
|
3808
|
|
- env'' = addAltUnfoldings env' case_bndr' bndr_swap' con_app
|
|
3809
|
|
-
|
|
|
3803
|
+ ; let env'' = addAltUnfoldings env' case_bndr' bndr_swap' data_alt vs'
|
|
3810
|
3804
|
; (floats, rhs') <- simplExprF env'' rhs cont'
|
|
3811
|
|
- ; return (DataAlt con, vs', floats, rhs') }
|
|
|
3805
|
+ ; return (data_alt, vs', floats, rhs') }
|
|
3812
|
3806
|
|
|
3813
|
3807
|
{- Note [Adding evaluatedness info to pattern-bound variables]
|
|
3814
|
3808
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ... |
... |
@@ -3911,12 +3905,17 @@ addDefaultUnfoldings env case_bndr bndr_swap imposs_deflt_cons |
|
3911
|
3905
|
| otherwise = env1
|
|
3912
|
3906
|
|
|
3913
|
3907
|
|
|
3914
|
|
-addAltUnfoldings :: SimplEnv -> OutId -> BinderSwapDecision -> OutExpr -> SimplEnv
|
|
3915
|
|
-addAltUnfoldings env case_bndr bndr_swap con_app
|
|
|
3908
|
+addAltUnfoldings :: SimplEnv -> OutId -> BinderSwapDecision
|
|
|
3909
|
+ -> AltCon -> [OutVar] -> SimplEnv
|
|
|
3910
|
+addAltUnfoldings env case_bndr bndr_swap con bndrs
|
|
3916
|
3911
|
= env2
|
|
3917
|
3912
|
where
|
|
3918
|
|
- con_app_unf = mk_simple_unf con_app
|
|
3919
|
|
- env1 = addBinderUnfolding env case_bndr con_app_unf
|
|
|
3913
|
+ -- Add unfolding for case_bndr
|
|
|
3914
|
+ -- See #28164
|
|
|
3915
|
+ env1 | seCaseCase env || null bndrs
|
|
|
3916
|
+ = addBinderUnfolding env case_bndr con_app_unf
|
|
|
3917
|
+ | otherwise
|
|
|
3918
|
+ = env
|
|
3920
|
3919
|
|
|
3921
|
3920
|
-- See Note [Add unfolding for scrutinee]
|
|
3922
|
3921
|
-- e.g. case (x |> co) of K a b -> blah
|
| ... |
... |
@@ -3929,6 +3928,18 @@ addAltUnfoldings env case_bndr bndr_swap con_app |
|
3929
|
3928
|
|
|
3930
|
3929
|
| otherwise = env1
|
|
3931
|
3930
|
|
|
|
3931
|
+ -- Bind the case-binder to (con args)
|
|
|
3932
|
+ con_app_unf :: Unfolding
|
|
|
3933
|
+ con_app_unf = mk_simple_unf con_app
|
|
|
3934
|
+
|
|
|
3935
|
+ con_app :: OutExpr
|
|
|
3936
|
+ con_app = case con of
|
|
|
3937
|
+ DEFAULT -> pprPanic "addAltUnfoldings" (ppr case_bndr)
|
|
|
3938
|
+ LitAlt lit -> Lit lit
|
|
|
3939
|
+ DataAlt con -> mkConApp2 con inst_tys bndrs
|
|
|
3940
|
+ where
|
|
|
3941
|
+ inst_tys = tyConAppArgs (idType case_bndr)
|
|
|
3942
|
+
|
|
3932
|
3943
|
-- Force the opts, so that the whole SimplEnv isn't retained
|
|
3933
|
3944
|
!opts = seUnfoldingOpts env
|
|
3934
|
3945
|
mk_simple_unf = mkSimpleUnfolding opts
|