[Git][ghc/ghc][wip/T23083] 4 commits: Core.Ppr: Omit case binder for empty case alternatives

Sebastian Graf (@sgraf812) gitlab at gitlab.haskell.org
Mon Apr 3 09:23:17 UTC 2023



Sebastian Graf pushed to branch wip/T23083 at Glasgow Haskell Compiler / GHC


Commits:
e04ec8f5 by Sebastian Graf at 2023-04-03T11:16:25+02:00
Core.Ppr: Omit case binder for empty case alternatives

A minor improvement to pretty-printing

- - - - -
18578d31 by Sebastian Graf at 2023-04-03T11:19:33+02:00
exprIsTrivial: Factor out shared implementation and introduce TrivialExpr

The duplication between `exprIsTrivial` and `getIdFromTrivialExpr_maybe` (along
with its lacking check that the returned Var is indeed an Id) has been bugging
me for a long time.

This patch introduces a inlinable worker function `trivial_expr_fold`
acting as the single, shared decision procedure of triviality.
It "returns" a Church-encoded `Maybe TrivialExpr`, so when it is inlined, it
fuses to similar code as before.

This allows us to export a generalisation of `getIdFromTrivialExpr_maybe` that
returns any `TrivialExpr` I dubbed `trivialExpr[_maybe]`. It will be of use in
!10088 during CoreToStg, where we want to look into scrutinees of empty case
alternatives and thus is ultimately part of #23083.

- - - - -
105494e0 by Sebastian Graf at 2023-04-03T11:19:54+02:00
CorePrep: Do not eliminate EmptyCase, do it in StgToCmm instead

We eliminate EmptyCase by way of `cgCase e _ _ [] = cgExpr e` now.
The main reason is that it plays far better in conjunction with eta expansion
(as we aim to do for arguments in CorePrep, #23083), because we can discard
any arguments, `(case e of {}) eta == case e of {}`, whereas in `(e |> co) eta`
it's impossible to discard the argument.

It is also both much simpler to describe than the previous mechanism of emitting
an unsafe coercion and simpler to implement, removing quite a bit of commentary
and the `Bool` field of `CorePrepProv`.

- - - - -
26ff3536 by Sebastian Graf at 2023-04-03T11:21:42+02:00
CorePrep: Eta expand arguments (#23083)

Previously, we'd only eta expand let bindings and lambdas,
now we'll also eta expand arguments such as in T23083:
```hs
g f h = f (h `seq` (h $))
```
Unless `-fpedantic-bottoms` is set, we'll now transform to
```hs
g f h = f (\eta -> h eta)
```
in CorePrep.

See the new `Note [Eta expansion of arguments in CorePrep]` for the details.

Fixes #23083.

- - - - -


30 changed files:

- compiler/GHC/Core.hs
- compiler/GHC/Core/Coercion.hs
- compiler/GHC/Core/Coercion/Opt.hs
- compiler/GHC/Core/FVs.hs
- compiler/GHC/Core/Lint.hs
- compiler/GHC/Core/Ppr.hs
- compiler/GHC/Core/TyCo/FVs.hs
- compiler/GHC/Core/TyCo/Rep.hs
- compiler/GHC/Core/TyCo/Subst.hs
- compiler/GHC/Core/TyCo/Tidy.hs
- compiler/GHC/Core/Type.hs
- compiler/GHC/Core/Utils.hs
- compiler/GHC/CoreToIface.hs
- compiler/GHC/CoreToStg.hs
- compiler/GHC/CoreToStg/Prep.hs
- compiler/GHC/Driver/Config/CoreToStg/Prep.hs
- compiler/GHC/Iface/Syntax.hs
- compiler/GHC/Iface/Type.hs
- compiler/GHC/IfaceToCore.hs
- compiler/GHC/Stg/CSE.hs
- compiler/GHC/Stg/Unarise.hs
- compiler/GHC/StgToCmm/Expr.hs
- compiler/GHC/Tc/TyCl/Utils.hs
- compiler/GHC/Tc/Utils/TcMType.hs
- testsuite/tests/corelint/T21115b.stderr
- testsuite/tests/deSugar/should_compile/T2431.stderr
- testsuite/tests/simplCore/should_compile/T13143.stderr
- + testsuite/tests/simplCore/should_compile/T23083.hs
- + testsuite/tests/simplCore/should_compile/T23083.stderr
- testsuite/tests/simplCore/should_compile/T9400.stderr


The diff was not included because it is too large.


View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d0bcf3702b2c5a701525b3a0e95ca8213e6e1d52...26ff3536bf7de746899a5a5de9cfb0295227bfba

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d0bcf3702b2c5a701525b3a0e95ca8213e6e1d52...26ff3536bf7de746899a5a5de9cfb0295227bfba
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230403/21c25d95/attachment.html>


More information about the ghc-commits mailing list