[Git][ghc/ghc][wip/T20749] 49 commits: Fix several mistakes around free variables in iface breakpoints

Sebastian Graf (@sgraf812) gitlab at gitlab.haskell.org
Fri Oct 13 10:39:04 UTC 2023



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


Commits:
d3874407 by Torsten Schmits at 2023-09-30T16:08:10-04:00
Fix several mistakes around free variables in iface breakpoints

Fixes #23612 , #23607, #23998 and #23666.

MR: !11026

The fingerprinting logic in `Iface.Recomp` failed lookups when processing decls containing breakpoints for two reasons:

* IfaceBreakpoint created binders for free variables instead of expressions

* When collecting free names for the dependency analysis for fingerprinting, breakpoint FVs were skipped

- - - - -
ef5342cd by Simon Peyton Jones at 2023-09-30T16:08:48-04:00
Refactor to combine HsLam and HsLamCase

This MR is pure refactoring (#23916):
* Combine `HsLam` and `HsLamCase`
* Combine `HsCmdLam` and `HsCmdLamCase`

This just arranges to treat uniformly
   \x -> e
   \case pi -> ei
   \cases pis -> ie

In the exising code base the first is treated differently
to the latter two.

No change in behaviour.

More specifics:

* Combine `HsLam` and `HsLamCase` (constructors of `Language.Haskell.Syntax.Expr.HsExpr`) into one data construtor covering
  * Lambda
  * `\case`
  * `\cases`

* The new `HsLam` has an argument of type `HsLamVariant` to distinguish the three cases.

* Similarly, combine `HsCmdLam` and `HsCmdLamCase` (constructors of `Language.Haskell.Syntax.Expr.HsCmd` ) into one.

* Similarly, combine `mkHsLamPV` and `mkHsLamCasePV` (methods of class `DisambECP`) into one. (Thank you Alan Zimmerman.)

* Similarly, combine `LambdaExpr` and `LamCaseAlt` (constructors of `Language.Haskell.Syntax.Expr.HsMatchContext`) into one: `LamAlt` with a `HsLamVariant` argument.

* Similarly, combine `KappaExpr` and `ArrowLamCaseAlt` (constructors of `Language.Haskell.Syntax.Expr.HsArrowMatchContext`) into one: `ArrowLamAlt` with a `HsLamVariant` argument.

* Similarly, combine `PsErrLambdaInPat` and `PsErrLambdaCaseInPat` (constructors of `GHC.Parser.Errors.Ppr.PsError`) into one.

* Similarly, combine `PsErrLambdaInPat` and `PsErrLambdaCaseInPat` (constructors of `GHC.Parser.Errors.Ppr.PsError`) into one.

* In the same `PsError` data type, combine `PsErrLambdaCmdInFunAppCmd` and `PsErrLambdaCaseCmdInFunAppCmd` into one.

* In the same `PsError` data tpye, combine `PsErrLambdaInFunAppExpr` and `PsErrLambdaCaseInFunAppExpr` into one.

p* Smilarly combine `ExpectedFunTyLam` and `ExpectedFunTyLamCase` (constructors of `GHC.Tc.Types.Origin.ExpectedFunTyOrigin`) into one.

Phew!

- - - - -
b048bea0 by Andreas Klebinger at 2023-09-30T16:09:24-04:00
Arm: Make ppr methods easier to use by not requiring NCGConfig

- - - - -
2adc0508 by Andreas Klebinger at 2023-09-30T16:09:24-04:00
AArch64: Fix broken conditional jumps for offsets >= 1MB

Rewrite conditional jump instructions with offsets >= 1MB to use unconditional jumps
to avoid overflowing the immediate.

Fixes #23746

- - - - -
1424f790 by Alan Zimmerman at 2023-09-30T16:10:00-04:00
EPA: Replace Monoid with NoAnn

We currently use the Monoid class as a constraint on Exact Print
Annotation functions, so we can use mempty. But this leads to
requiring Semigroup instances too, which do not always make sense.

Instead, introduce a class NoAnn, with a function noAnn analogous to
mempty.

Closes #20372

Updates haddock submodule

- - - - -
c1a3ecde by Ben Gamari at 2023-09-30T16:10:36-04:00
users-guide: Refactor handling of :base-ref: et al.

- - - - -
bc204783 by Richard Eisenberg at 2023-10-02T14:50:52+02:00
Simplify and correct nasty case in coercion opt

This fixes #21062.

No test case, because triggering this code seems challenging.

- - - - -
9c9ca67e by Andrew Lelechenko at 2023-10-04T05:42:28-04:00
Bump bytestring submodule to 0.12.0.2

- - - - -
4e46dc2b by Andrew Lelechenko at 2023-10-04T05:42:28-04:00
Inline bucket_match

- - - - -
f6b2751f by Ben Gamari at 2023-10-04T05:43:05-04:00
configure: Fix #21712 again

This is a bit of a shot in the dark to fix #24033, which appears to be
another instance of #21712. For some reason the ld-override logic
*still* appears to be active on Darwin targets (or at least one).
Consequently, on misconfigured systems we may choose a non-`ld64`
linker.

It's a bit unclear exactly what happened in #24033 but ultimately the
check added for #21712 was not quite right, checking for the
`ghc_host_os` (the value of which depends upon the bootstrap compiler)
instead of the target platform. Fix this.

Fixes #24033.

- - - - -
2f0a101d by Krzysztof Gogolewski at 2023-10-04T05:43:42-04:00
Add a regression test for #24029

- - - - -
8cee3fd7 by sheaf at 2023-10-04T05:44:22-04:00
Fix non-symbolic children lookup of fixity decl

The fix for #23664 did not correctly account for non-symbolic names
when looking up children of a given parent. This one-line fix changes
that.

Fixes #24037

- - - - -
a4785b33 by Cheng Shao at 2023-10-04T05:44:59-04:00
rts: fix incorrect ticket reference

- - - - -
e037f459 by Ben Gamari at 2023-10-04T05:45:35-04:00
users-guide: Fix discussion of -Wpartial-fields

 * fix a few typos
 * add a new example showing when the warning fires
 * clarify the existing example
 * point out -Wincomplete-record-selects

Fixes #24049.

- - - - -
8ff3134e by Matthew Pickering at 2023-10-05T05:34:58-04:00
Revert "Pass preprocessor options to C compiler when building foreign C files (#16737)"

This reverts commit 1c18d3b41f897f34a93669edaebe6069f319f9e2.

`-optP` should pass options to the preprocessor, that might be a very
different program to the C compiler, so passing the options to the C
compiler is likely to result in `-optP` being useless.

Fixes #17185 and #21291

- - - - -
8f6010b9 by Ben Gamari at 2023-10-05T05:35:36-04:00
rts/nonmoving: Fix on LLP64 platforms

Previously `NONMOVING_SEGMENT_MASK` and friends were defined with the `UL`
size suffix. However, this is wrong on LLP64 platforms like Windows,
where `long` is 32-bits.

Fixes #23003.
Fixes #24042.

- - - - -
f20d02f8 by Andreas Klebinger at 2023-10-05T05:36:14-04:00
Fix isAArch64Bitmask for 32bit immediates.

Fixes #23802

- - - - -
63afb701 by Bryan Richter at 2023-10-05T05:36:49-04:00
Work around perf note fetch failure

Addresses #24055.

- - - - -
242102f4 by Krzysztof Gogolewski at 2023-10-05T05:37:26-04:00
Add a test for #21348

- - - - -
7d390bce by Rewbert at 2023-10-05T05:38:08-04:00
Fixes #24046

- - - - -
69abb171 by Finley McIlwaine at 2023-10-06T14:06:28-07:00
Ensure unconstrained instance dictionaries get IPE info

In the `StgRhsCon` case of `GHC.Stg.Debug.collectStgRhs`, we were not coming up
with an initial source span based on the span of the binder, which was causing
instance dictionaries without dynamic superclass constraints to not have source
locations in their IPE info. Now they do.

Resolves #24005

- - - - -
390443b7 by Andreas Klebinger at 2023-10-07T10:00:20-04:00
rts: Split up rts/include/stg/MachRegs.h by arch

- - - - -
3685942f by Bryan Richter at 2023-10-07T10:00:56-04:00
Actually set hackage index state

Or at least, use a version of the cabal command that *claims* to set the
index state.

Time will tell.

- - - - -
46a0e5be by Bryan Richter at 2023-10-07T10:00:56-04:00
Update hackage index state

- - - - -
d4b037de by Bryan Richter at 2023-10-07T10:00:56-04:00
Ensure hadrian uses CI's hackage index state

- - - - -
e206be64 by Andrew Lelechenko at 2023-10-08T15:06:14-04:00
Do not use O_NONBLOCK on regular files or block devices

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

- - - - -
a06197c4 by David Binder at 2023-10-08T15:06:55-04:00
Update hpc-bin submodule to 0.69

- - - - -
ed6785b6 by David Binder at 2023-10-08T15:06:55-04:00
Update Hadrian with correct path to happy file for hpc-bin

- - - - -
ec5314a5 by Simon Peyton Jones at 2023-10-09T17:30:03+01: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

- - - - -
37ea9daf by Simon Peyton Jones at 2023-10-09T17:31:06+01: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 2% 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]

* When making join points, don't do so if the join point is so small
  it will immediately be inlined.  See Note [Duplicating alternatives]

* 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.

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

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)   -4.3% GOOD
                LargeRecord(normal)  -23.3% GOOD
                  PmSeriesS(normal)   -2.4%
                     T11195(normal)   -1.7%
                     T12227(normal)  -20.0% GOOD
                     T12545(normal)   -5.4%
                 T13253-spj(normal)  -50.7% GOOD
                     T13386(normal)   -5.1% GOOD
                     T14766(normal)   -2.4% GOOD
                     T15164(normal)   -1.7%
                     T15304(normal)   +1.0%
                     T15630(normal)   -7.7%
                    T15630a(normal)          NEW
                     T15703(normal)   -7.5% GOOD
                     T16577(normal)   -5.1% GOOD
                     T17516(normal)   -3.6%
                     T18223(normal)  -16.8% GOOD
                     T18282(normal)   -1.5%
                     T18304(normal)   +1.9%
                    T21839c(normal)   -3.5% GOOD
                      T3064(normal)   -1.5%
                      T5030(normal)  -16.2% GOOD
                   T5321Fun(normal)   -1.6%
                      T6048(optasm)   -2.1% GOOD
                      T8095(normal)   -6.1% GOOD
                      T9630(normal)   -5.1% GOOD
                      WWRec(normal)   -1.6%

                          geo. mean   -2.1%
                          minimum    -50.7%
                          maximum     +1.9%

Metric Decrease:
    CoOpt_Singletons
    LargeRecord
    T12227
    T13253-spj
    T13386
    T14766
    T15703
    T16577
    T18223
    T21839c
    T5030
    T6048
    T8095
    T9630

- - - - -
a57fd42c by Simon Peyton Jones at 2023-10-09T17:31:06+01: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.

- - - - -
498d8293 by Simon Peyton Jones at 2023-10-09T17:31:06+01:00
Update testsuite output

- - - - -
4a16ecd9 by Simon Peyton Jones at 2023-10-09T17:31:06+01:00
Try effect of

* making multi-branch cases not work free (fixes #22423)
* use plan A for dataToTag and tagToEnum

- - - - -
6517a2ff by Simon Peyton Jones at 2023-10-09T17:31:06+01:00
More changes

* No floating at all for join points

* Never inline j x = I x
  Example: integerSignum !j = IS (integerSignum# j)
  We want this to inline and then cancel with an enclosing case.
  But it won't if we have changed it to
       integerSignum x = case x of
                            IN a -> IS (...)
                            IS b -> IS (...)
                            IP c -> IS (...)

  This involved changing
  - UnfoldingGuidance to not say always-inline for j x = Ix
  - callSiteInline to inline join points only if there is a real
    benefit
  - ok_to_dup_alt in Simplify.Iteration

* Row back (for now) on changes to GHC.Core.Utils.ExprIsCheap

- - - - -
4c867702 by Simon Peyton Jones at 2023-10-09T17:31:06+01:00
Wibble

- - - - -
f875ef1c by Simon Peyton Jones at 2023-10-09T17:31:06+01:00
Wibble

- - - - -
7514e8de by Simon Peyton Jones at 2023-10-09T17:31:06+01:00
Further wibbles

- - - - -
cb5f2a8e by Simon Peyton Jones at 2023-10-09T17:31:06+01:00
One more wibble

Don't float an unlifted join point

- - - - -
af4f30b1 by Simon Peyton Jones at 2023-10-09T17:31:06+01:00
Small wibbles

The most significant change is to mkSelCo.

- - - - -
9c7acc26 by Simon Peyton Jones at 2023-10-10T09:35:00+01:00
Temporarily add -DDEBUG to Coercion.hs

- - - - -
735951dd by Simon Peyton Jones at 2023-10-10T15:57:04+01:00
Fix a missing zonk in before mkSelCo

- - - - -
12609f12 by Simon Peyton Jones at 2023-10-10T16:26:33+01:00
Wibbles

- - - - -
d5d52467 by Simon Peyton Jones at 2023-10-10T16:26:42+01:00
Tickish comment

- - - - -
07bd48ae by Sebastian Graf at 2023-10-12T15:00:22+02:00
CorePrep: Refactor FloatingBind (#23442)

A drastically improved architecture for local floating in CorePrep
that decouples the decision of whether a float is going to be let- or case-bound
from how far it can float (out of strict contexts, out of lazy contexts, to
top-level).

There are a couple of new Notes describing the effort:

  * `Note [Floating in CorePrep]` for the overview
  * `Note [BindInfo and FloatInfo]` for the new classification of floats
  * `Note [Floats and FloatDecision]` for how FloatInfo is used to inform
    floating decisions

This is necessary ground work for proper treatment of Strict fields and
unlifted values at top-level.

Fixes #23442.

- - - - -
fec58945 by Sebastian Graf at 2023-10-12T15:00:22+02:00
Fix restarts in .ghcid

Using the whole of `hadrian/` restarted in a loop for me.

- - - - -
5b226c89 by Sebastian Graf at 2023-10-13T12:38:55+02:00
Make DataCon workers strict in strict fields (#20749)

This patch tweaks `exprIsConApp_maybe`, `exprIsHNF` and friends, and Demand
Analysis so that they exploit and maintain strictness of DataCon workers. See
`Note [Strict fields in Core]` for details.

Very little needed to change, and it puts field seq insertion done by Tag
Inference into a new perspective: That of *implementing* strict field semantics.
Before Tag Inference, DataCon workers are strict. Afterwards they are
effectively lazy and field seqs happen around use sites. History has shown
that there is no other way to guarantee taggedness and thus the STG Strict Field
Invariant.

Knock-on changes:

  * `exprIsHNF` previously used `exprOkForSpeculation` on unlifted arguments
    instead of recursing into `exprIsHNF`. That regressed the termination
    analysis in CPR analysis (which simply calls out to `exprIsHNF`), so I made
    it call `exprOkForSpeculation`, too.

  * There's a small regression in Demand Analysis, visible in the changed test
    output of T16859: Previously, a field seq on a variable would give that
    variable a "used exactly once" demand, now it's "used at least once",
    because `dmdTransformDataConSig` accounts for future uses of the field
    that actually all go through the case binder (and hence won't re-enter the
    potential thunk). The difference should hardly be observable.

  * The Simplifier's fast path for data constructors only applies to lazy
    data constructors now. I observed regressions involving Data.Binary.Put's
    `Pair` data type.

  * Unfortunately, T21392 does no longer reproduce after this patch, so I marked
    it as "not broken" in order to track whether we regress again in the future.

Fixes #20749, the satisfying conclusion of an annoying saga (cf. the ideas
in #21497 and #22475).

- - - - -
c1aca439 by Jaro Reinders at 2023-10-13T12:38:55+02:00
Try fixing allocation regressions

- - - - -
fafb6d89 by Sebastian Graf at 2023-10-13T12:38:55+02:00
CorePrep: Attach evaldUnfolding to floats to detect more values

- - - - -
7a8b97fb by Sebastian Graf at 2023-10-13T12:38:55+02:00
Arity: Attach eval'd arity type of scrutinee to case binder

Just a sensible thing to do; should be a straight win.

- - - - -


30 changed files:

- .ghcid
- .gitignore
- .gitlab/ci.sh
- .gitlab/test-metrics.sh
- compiler/CodeGen.Platform.h
- compiler/GHC/Builtin/Types.hs
- compiler/GHC/CmmToAsm.hs
- compiler/GHC/CmmToAsm/AArch64.hs
- compiler/GHC/CmmToAsm/AArch64/CodeGen.hs
- compiler/GHC/CmmToAsm/AArch64/Cond.hs
- compiler/GHC/CmmToAsm/AArch64/Instr.hs
- compiler/GHC/CmmToAsm/AArch64/Ppr.hs
- compiler/GHC/CmmToAsm/BlockLayout.hs
- compiler/GHC/CmmToAsm/Monad.hs
- compiler/GHC/CmmToAsm/PPC/Instr.hs
- compiler/GHC/CmmToAsm/X86.hs
- compiler/GHC/Core.hs
- compiler/GHC/Core/Coercion.hs
- compiler/GHC/Core/Coercion/Opt.hs
- compiler/GHC/Core/DataCon.hs
- compiler/GHC/Core/Opt/Arity.hs
- compiler/GHC/Core/Opt/ConstantFold.hs
- compiler/GHC/Core/Opt/CprAnal.hs
- compiler/GHC/Core/Opt/DmdAnal.hs
- compiler/GHC/Core/Opt/OccurAnal.hs
- compiler/GHC/Core/Opt/SetLevels.hs
- compiler/GHC/Core/Opt/Simplify/Env.hs
- compiler/GHC/Core/Opt/Simplify/Inline.hs
- compiler/GHC/Core/Opt/Simplify/Iteration.hs
- compiler/GHC/Core/Opt/Simplify/Monad.hs


The diff was not included because it is too large.


View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2403009c6d12882197ae015a6c72d129236e7606...7a8b97fbf89f37eaba135a623ce9a79250cbc268

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2403009c6d12882197ae015a6c72d129236e7606...7a8b97fbf89f37eaba135a623ce9a79250cbc268
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/20231013/0cbf0680/attachment-0001.html>


More information about the ghc-commits mailing list