[Git][ghc/ghc][wip/simplifier-tweaks] 27 commits: Turn -Wtype-equality-out-of-scope on by default

Simon Peyton Jones (@simonpj) gitlab at gitlab.haskell.org
Sat Jan 20 23:45:42 UTC 2024



Simon Peyton Jones pushed to branch wip/simplifier-tweaks at Glasgow Haskell Compiler / GHC


Commits:
eaf8a06d by Krzysztof Gogolewski at 2024-01-11T00:43:17+01:00
Turn -Wtype-equality-out-of-scope on by default

Also remove -Wnoncanonical-{monoid,monad}-instances from -Wcompat,
since they are enabled by default. Refresh wcompat-warnings/ test
with new -Wcompat warnings.

Part of #24267

Co-authored-by: sheaf <sam.derbyshire at gmail.com>

- - - - -
42bee5aa by Sebastian Graf at 2024-01-12T21:16:21-05:00
Arity: Require called *exactly once* for eta exp with -fpedantic-bottoms (#24296)

In #24296, we had a program in which we eta expanded away an error despite the
presence of `-fpedantic-bottoms`.
This was caused by turning called *at least once* lambdas into one-shot lambdas,
while with `-fpedantic-bottoms` it is only sound to eta expand over lambdas that
are called *exactly* once.
An example can be found in `Note [Combining arity type with demand info]`.

Fixes #24296.

- - - - -
7e95f738 by Andreas Klebinger at 2024-01-12T21:16:57-05:00
Aarch64: Enable -mfma by default.

Fixes #24311

- - - - -
e43788d0 by Jason Shipman at 2024-01-14T12:47:38-05:00
Add more instances for Compose: Fractional, RealFrac, Floating, RealFloat

CLC proposal #226 https://github.com/haskell/core-libraries-committee/issues/226

- - - - -
ae6d8cd2 by Sebastian Graf at 2024-01-14T12:48:15-05:00
Pmc: COMPLETE pragmas associated with Family TyCons should apply to representation TyCons as well (#24326)

Fixes #24326.

- - - - -
c5fc7304 by sheaf at 2024-01-15T14:15:29-05:00
Use lookupOccRn_maybe in TH.lookupName

When looking up a value, we want to be able to find both variables
and record fields. So we should not use the lookupSameOccRn_maybe
function, as we can't know ahead of time which record field namespace
a record field with the given textual name will belong to.

Fixes #24293

- - - - -
da908790 by Krzysztof Gogolewski at 2024-01-15T14:16:05-05:00
Make the build more strict on documentation errors

* Detect undefined labels. This can be tested by adding :ref:`nonexistent`
  to a documentation rst file; attempting to build docs will fail.
  Fixed the undefined label in `9.8.1-notes.rst`.
* Detect errors. While we have plenty of warnings, we can at least enforce
  that Sphinx does not report errors.
  Fixed the error in `required_type_arguments.rst`.

Unrelated change: I have documented that the `-dlint` enables
`-fcatch-nonexhaustive-cases`, as can be verified by checking
`enableDLint`.

- - - - -
5077416e by Javier Sagredo at 2024-01-16T15:40:06-05:00
Profiling: Adds an option to not start time profiling at startup

Using the functionality provided by
d89deeba47ce04a5198a71fa4cbc203fe2c90794, this patch creates a new rts
flag `--no-automatic-time-samples` which disables the time profiling
when starting a program. It is then expected that the user starts it
whenever it is needed.

Fixes #24337

- - - - -
5776008c by Matthew Pickering at 2024-01-16T15:40:42-05:00
eventlog: Fix off-by-one error in postIPE

We were missing the extra_comma from the calculation of the size of the
payload of postIPE. This was causing assertion failures when the event
would overflow the buffer by one byte, as ensureRoomForVariable event
would report there was enough space for `n` bytes but then we would
write `n + 1` bytes into the buffer.

Fixes #24287

- - - - -
66dc09b1 by Simon Peyton Jones at 2024-01-16T15:41:18-05:00
Improve SpecConstr (esp nofib/spectral/ansi)

This MR makes three improvements to SpecConstr: see #24282

* It fixes an outright (and recently-introduced) bug in `betterPat`, which
  was wrongly forgetting to compare the lengths of the argument lists.

* It enhances ConVal to inclue a boolean for work-free-ness, so that the
  envt can contain non-work-free constructor applications, so that we
  can do more: see Note [ConVal work-free-ness]

* It rejigs `subsumePats` so that it doesn't reverse the list.  This can
  make a difference because, when patterns overlap, we arbitrarily pick
  the first.  There is no "right" way, but this retains the old
  pre-subsumePats behaviour, thereby "fixing" the regression in #24282.

Nofib results

   +========================================
   |                 spectral/ansi  -21.14%
   | spectral/hartel/comp_lab_zift   -0.12%
   |       spectral/hartel/parstof   +0.09%
   |           spectral/last-piece   -2.32%
   |           spectral/multiplier   +6.03%
   |                 spectral/para   +0.60%
   |               spectral/simple   -0.26%
   +========================================
   |                     geom mean   -0.18%
   +----------------------------------------

The regression in `multiplier` is sad, but it simply replicates GHC's
previous behaviour (e.g. GHC 9.6).

- - - - -
65da79b3 by Matthew Pickering at 2024-01-16T15:41:54-05:00
hadrian: Reduce Cabal verbosity

The comment claims that `simpleUserHooks` decrease verbosity, and it
does, but only for the `postConf` phase. The other phases are too
verbose with `-V`.

At the moment > 5000 lines of the build log are devoted to output from
`cabal copy`.

So I take the simple approach and just decrease the verbosity level
again.

If the output of `postConf` is essential then it would be better to
implement our own `UserHooks` which doesn't decrease the verbosity for
`postConf`.

Fixes #24338

- - - - -
16414d7d by Matthew Pickering at 2024-01-17T10:54:59-05:00
Stop retaining old ModGuts throughout subsequent simplifier phases

Each phase of the simplifier typically rewrites the majority of ModGuts,
so we want to be able to release the old ModGuts as soon as possible.

`name_ppr_ctxt` lives throught the whole optimiser phase and it was
retaining a reference to `ModGuts`, so we were failing to release the
old `ModGuts` until the end of the phase (potentially doubling peak
memory usage for that particular phase).

This was discovered using eras profiling (#24332)

Fixes #24328

- - - - -
7f0879e1 by Matthew Pickering at 2024-01-17T10:55:35-05:00
Update nofib submodule

- - - - -
320454d3 by Cheng Shao at 2024-01-17T23:02:40+00:00
ci: bump ci-images for updated wasm image

- - - - -
2eca52b4 by Cheng Shao at 2024-01-17T23:06:44+00:00
base: treat all FDs as "nonblocking" on wasm

On posix platforms, when performing read/write on FDs, we check the
nonblocking flag first. For FDs without this flag (e.g. stdout), we
call fdReady() first, which in turn calls poll() to wait for I/O to be
available on that FD. This is problematic for wasm32-wasi: although
select()/poll() is supported via the poll_oneoff() wasi syscall, that
syscall is rather heavyweight and runtime behavior differs in
different wasi implementations. The issue is even worse when targeting
browsers, given there's no satisfactory way to implement async I/O as
a synchronous syscall, so existing JS polyfills for wasi often give up
and simply return ENOSYS.

Before we have a proper I/O manager that avoids poll_oneoff() for
async I/O on wasm, this patch improves the status quo a lot by merely
pretending all FDs are "nonblocking". Read/write on FDs will directly
invoke read()/write(), which are much more reliably handled in
existing wasi implementations, especially those in browsers.

Fixes #23275 and the following test cases: T7773 isEOF001 openFile009
T4808 cgrun025

Approved by CLC proposal #234:
https://github.com/haskell/core-libraries-committee/issues/234

- - - - -
83c6c710 by Andrew Lelechenko at 2024-01-18T05:21:49-05:00
base: clarify how to disable warnings about partiality of Data.List.{head,tail}

- - - - -
c4078f2f by Simon Peyton Jones at 2024-01-18T05:22:25-05:00
Fix four bug in handling of (forall cv. body_ty)

These bugs are all described in #24335

It's not easy to provoke the bug, hence no test case.

- - - - -
119586ea by Alexis King at 2024-01-19T00:08:00-05:00
Always refresh profiling CCSes after running pending initializers

Fixes #24171.

- - - - -
9718d970 by Oleg Grenrus at 2024-01-19T00:08:36-05:00
Set default-language: GHC2021 in ghc library

Go through compiler/ sources, and remove
all BangPatterns (and other GHC2021 enabled extensions in these files).

- - - - -
3ef71669 by Matthew Pickering at 2024-01-19T21:55:16-05:00
testsuite: Remove unused have_library function

Also remove the hence unused testsuite option `--test-package-db`.

Fixes #24342

- - - - -
5b7fa20c by Jade at 2024-01-19T21:55:53-05:00
Fix Spelling in the compiler

Tracking: #16591

- - - - -
09875f48 by Matthew Pickering at 2024-01-20T12:20:44-05:00
testsuite: Implement `isInTreeCompiler` in a more robust way

Just a small refactoring to avoid redundantly specifying the same
strings in two different places.

- - - - -
0d12b987 by Jade at 2024-01-20T12:21:20-05:00
Change maintainer email from cvs-ghc at haskell.org to ghc-devs at haskell.org. Fixes #22142

- - - - -
e7fed826 by Simon Peyton Jones at 2024-01-20T22:54:01+00:00
Several improvements to the handling of coercions

* Make `mkSymCo` and `mkInstCo` smarter
  Fixes #23642

* Fix return role of `SelCo` in the coercion optimiser.
  Fixes #23617

* Make the coercion optimiser `opt_trans_rule` work better for newtypes
  Fixes #23619

- - - - -
967c369f by Simon Peyton Jones at 2024-01-20T22:55:36+00:00
Simplifier improvements

This MR started as: allow the simplifer to do more in one pass,
arising from places I could see the simplifier taking two iterations
where one would do.  But it turned into a larger project, because
these changes unexpectedly made inlining blow up, especially join
points in deeply-nested cases.

The net result is good: a 1.5% improvement in compile time.  The table
below shows changes over 1%.

The main changes are:

* The SimplEnv now has a seInlineDepth field, which says how deep
  in unfoldings we are.  See Note [Inline depth] in Simplify.Env

* Avoid repeatedly simplifying coercions.
  see Note [Avoid re-simplifying coercions] in Simplify.Iteration
  As you'll see from the Note, this makes use of the seInlineDepth.

* Allow Simplify.Utils.postInlineUnconditionally to inline variables
  that are used exactly once. See Note [Post-inline for single-use things].

* Allow Simplify.Iteration.simplAuxBind to inline used-once things.
  This is another part of Note [Post-inline for single-use things], and
  is really good for reducing simplifier iterations in situations like
      case K e of { K x -> blah }
  wher x is used once in blah.

* Make GHC.Core.SimpleOpt.exprIsConApp_maybe do some simple case
  elimination.  Note [Case elim in exprIsConApp_maybe]

* Many new or rewritten Notes.  E.g. Note [Avoiding simplifying repeatedly]

Join points
~~~~~~~~~~~
* Be very careful about inlining join points. See
  Note [Duplicating join points] in GHC.Core.Opt.Simplify.Iteration

* When making join points, don't do so if the join point is so small
  it will immediately be inlined; check uncondInlineJoin.

* When considering inlining a join point, never do so unless
  there is a positive gain: see (DJ5) in Note [Duplicating join points].

* Do not float join points at all, except to top level.
  See GHC.Core.Opt.SetLevels.dontFloatNonRec

* Do not add an unfolding to a join point at birth.  This is a tricky one
  and has a long Note [Do not add unfoldings to join points at birth]
  It shows up in two places
  - In `mkDupableAlt` do not add an inlining
  - (trickier) In `simplLetUnfolding` don't add an unfolding for a
    fresh join point
  I am not fully satisifed with this, but it works and is well documented.

* In GHC.Core.Unfold.sizeExpr, make jumps small, so that we don't penalise
  having a non-inlined join point.

* Use plan A for dataToTag and tagToEnum

I discovered that GHC.HsToCore.Pmc.Solver.Types.trvVarInfo was very
delicately balanced.  It's a small, heavily used, overloaded function
and it's important that it inlines. By a fluke it was before, but at
various times in my journey it stopped doing so.  So I added an INLINE
pragma to it.

    Metrics: compile_time/bytes allocated
    ------------------------------------------------
           CoOpt_Singletons(normal)   -8.2% GOOD
                LargeRecord(normal)  -22.7% GOOD
                  PmSeriesS(normal)   -4.1%
                  PmSeriesT(normal)   -3.1%
                  PmSeriesV(normal)   -1.6%
                     T11195(normal)   -1.9%
                     T12227(normal)  -19.9% GOOD
                     T12545(normal)   -5.4%
                     T12707(normal)   -2.1% GOOD
                 T13253-spj(normal)  -13.1% GOOD
                     T13386(normal)   -1.6%
                     T14766(normal)   -2.2% GOOD
                    T15630a(normal)          NEW
                     T15703(normal)  -13.5% GOOD
                     T16577(normal)   -4.3% GOOD
                     T17096(normal)   -4.4%
                     T17516(normal)   -0.2%
                     T18223(normal)  -16.3% GOOD
                     T18282(normal)   -5.3% GOOD
                     T18730(optasm)          NEW
                     T18923(normal)   -3.7% GOOD
                    T21839c(normal)   -2.3% GOOD
                      T3064(normal)   -1.3%
                      T5030(normal)  -16.1% GOOD
                   T5321Fun(normal)   -1.5%
                      T6048(optasm)  -11.8% GOOD
                       T783(normal)   -1.4%
                      T8095(normal)   -5.9% GOOD
                      T9630(normal)   -5.1% GOOD

                      T9020(optasm)   +1.5%
                    T18698a(normal)   +1.5%  BAD
                     T14683(normal)   +1.2%
        DsIncompleteRecSel3(normal)   +1.2%
MultiComponentModulesRecomp(normal)   +1.0%
    MultiLayerModulesRecomp(normal)   +1.9%
   MultiLayerModulesTH_Make(normal)   +1.4%
                     T10421(normal)   +1.9%  BAD
                    T10421a(normal)   +3.0%
                     T13056(optasm)   +1.1%
                     T13253(normal)   +1.0%
                      T1969(normal)   +1.1%  BAD
                     T15304(normal)   +1.7%
                      T9675(optasm)   +1.2%
                      T9961(normal)   +2.4%  BAD

                          geo. mean   -1.5%
                          minimum    -22.7%
                          maximum     +3.0%
Metric Decrease:
    CoOpt_Singletons
    LargeRecord
    T12227
    T12707
    T12990
    T13253-spj
    T13536a
    T14766
    T15703
    T16577
    T18223
    T18282
    T18923
    T21839c
    T5030
    T6048
    T8095
    T9630
Metric Increase:
    T10421
    T18698a
    T1969
    T9961

- - - - -
0d6a128d by Simon Peyton Jones at 2024-01-20T22:55:36+00:00
Improve postInlineUnconditionally

This commit adds two things to postInlineUnconditionally:

1. Do not postInlineUnconditionally join point, ever.
   Doing so does not reduce allocation, which is the main point,
   and with join points that are used a lot it can bloat code.
   See point (1) of Note [Duplicating join points] in
   GHC.Core.Opt.Simplify.Iteration.

2. Do not postInlineUnconditionally a strict (demanded) binding.
   It will not allocate a thunk (it'll turn into a case instead)
   so again the main point of inlining it doesn't hold.  Better
   to check per-call-site.

- - - - -
e4ff310c by Simon Peyton Jones at 2024-01-20T23:45:22+00:00
Wibbles

- - - - -


30 changed files:

- .gitlab-ci.yml
- compiler/GHC/Cmm/CLabel.hs
- compiler/GHC/Cmm/CommonBlockElim.hs
- compiler/GHC/Cmm/ContFlowOpt.hs
- compiler/GHC/Cmm/Dataflow.hs
- compiler/GHC/Cmm/Dataflow/Graph.hs
- compiler/GHC/Cmm/Expr.hs
- compiler/GHC/Cmm/Graph.hs
- compiler/GHC/Cmm/Info/Build.hs
- compiler/GHC/Cmm/LayoutStack.hs
- compiler/GHC/Cmm/Liveness.hs
- compiler/GHC/Cmm/MachOp.hs
- compiler/GHC/Cmm/Node.hs
- compiler/GHC/Cmm/Pipeline.hs
- compiler/GHC/Cmm/ProcPoint.hs
- compiler/GHC/Cmm/Utils.hs
- compiler/GHC/CmmToAsm.hs
- compiler/GHC/CmmToAsm/AArch64/CodeGen.hs
- compiler/GHC/CmmToAsm/CFG/Dominators.hs
- compiler/GHC/CmmToAsm/Reg/Graph/Stats.hs
- compiler/GHC/CmmToAsm/Reg/Linear.hs
- compiler/GHC/CmmToAsm/Reg/Liveness.hs
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- compiler/GHC/Core.hs
- compiler/GHC/Core.hs-boot
- compiler/GHC/Core/Coercion.hs
- compiler/GHC/Core/Coercion/Opt.hs
- compiler/GHC/Core/Lint.hs
- compiler/GHC/Core/Opt/Arity.hs
- compiler/GHC/Core/Opt/CallArity.hs


The diff was not included because it is too large.


View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ef3db00a55ceac61b45aa3bd0fc4b256935020e3...e4ff310c8e4b75049add18c2025f32657bc2e0af

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ef3db00a55ceac61b45aa3bd0fc4b256935020e3...e4ff310c8e4b75049add18c2025f32657bc2e0af
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/20240120/7edef060/attachment-0001.html>


More information about the ghc-commits mailing list