[Git][ghc/ghc][wip/T18078] 36 commits: rts: Teach getNumProcessors to return available processors

Simon Peyton Jones gitlab at gitlab.haskell.org
Mon Jun 1 20:35:29 UTC 2020



Simon Peyton Jones pushed to branch wip/T18078 at Glasgow Haskell Compiler / GHC


Commits:
4413828b by Ben Gamari at 2020-05-30T06:07:31-04:00
rts: Teach getNumProcessors to return available processors

Previously we would report the number of physical processors, which
can be quite wrong in a containerized setting. Now we rather return how
many processors are in our affinity mask when possible.

I also refactored the code to prefer platform-specific since this will
report logical CPUs instead of physical (using
`machdep.cpu.thread_count` on Darwin and `cpuset_getaffinity` on FreeBSD).

Fixes #14781.

- - - - -
1449435c by Ben Gamari at 2020-05-30T06:07:31-04:00
users-guide: Note change in getNumProcessors in users guide

- - - - -
3d960169 by Ben Gamari at 2020-05-30T06:07:31-04:00
rts: Drop compatibility shims for Windows Vista

We can now assume that the thread and processor group interfaces are
available.

- - - - -
7f8f948c by Peter Trommler at 2020-05-30T06:08:07-04:00
PPC NCG: Fix .size directive on powerpc64 ELF v1

Thanks to Sergei Trofimovich for pointing out the issue.

Fixes #18237

- - - - -
7c555b05 by Andreas Klebinger at 2020-05-30T06:08:43-04:00
Optimize GHC.Utils.Monad.

Many functions in this module are recursive and as such are marked
loop breakers. Which means they are unlikely to get an unfolding.

This is *bad*. We always want to specialize them to specific Monads.
Which requires a visible unfolding at the use site.

I rewrote the recursive ones from:

    foo f x = ... foo x' ...

to

    foo f x = go x
      where
        go x = ...

As well as giving some pragmas to make all of them available
for specialization.

The end result is a reduction of allocations of about -1.4% for
nofib/spectral/simple/Main.hs when compiled with `-O`.

-------------------------
Metric Decrease:
    T12425
    T14683
    T5631
    T9233
    T9675
    T9961
    WWRec
-------------------------

- - - - -
8b1cb5df by Ben Gamari at 2020-05-30T06:09:20-04:00
Windows: Bump Windows toolchain to 0.2

- - - - -
6947231a by Zubin Duggal at 2020-05-30T06:10:02-04:00
Simplify contexts in GHC.Iface.Ext.Ast

- - - - -
2ee4f36c by Daniel Gröber at 2020-06-01T06:32:56-04:00
Cleanup OVERWRITING_CLOSURE logic

The code is just more confusing than it needs to be. We don't need to mix
the threaded check with the ldv profiling check since ldv's init already
checks for this. Hence they can be two separate checks. Taking the sanity
checking into account is also cleaner via DebugFlags.sanity. No need for
checking the DEBUG define.

The ZERO_SLOP_FOR_LDV_PROF and ZERO_SLOP_FOR_SANITY_CHECK definitions the
old code had also make things a lot more opaque IMO so I removed those.

- - - - -
6159559b by Daniel Gröber at 2020-06-01T06:32:56-04:00
Fix OVERWRITING_CLOSURE assuming closures are not inherently used

The new ASSERT in LDV_recordDead() was being tripped up by MVars when
removeFromMVarBlockedQueue() calls OVERWRITING_CLOSURE() via
OVERWRITE_INFO().

- - - - -
38992085 by Daniel Gröber at 2020-06-01T06:32:56-04:00
Always zero shrunk mutable array slop when profiling

When shrinking arrays in the profiling way we currently don't always zero
the leftover slop. This means we can't traverse such closures in the heap
profiler. The old Note [zeroing slop] and #8402 have some rationale for why
this is so but I belive the reasoning doesn't apply to mutable
closures. There users already have to ensure multiple threads don't step on
each other's toes so zeroing should be safe.

- - - - -
b0c1f2a6 by Ben Gamari at 2020-06-01T06:33:37-04:00
testsuite: Add test for #18151

- - - - -
9a99a178 by Ben Gamari at 2020-06-01T06:33:37-04:00
testsuite: Add test for desugaring of PostfixOperators

- - - - -
2b89ca5b by Ben Gamari at 2020-06-01T06:33:37-04:00
HsToCore: Eta expand left sections

Strangely, the comment next to this code already alluded to the fact
that even simply eta-expanding will sacrifice laziness. It's quite
unclear how we regressed so far.

See #18151.

- - - - -
d412d7a3 by Kirill Elagin at 2020-06-01T06:34:21-04:00
Winferred-safe-imports: Do not exit with error

Currently, when -Winferred-safe-imports is enabled, even when it is not
turned into an error, the compiler will still exit with exit code 1 if
this warning was emitted.

Make sure it is really treated as a warning.

- - - - -
f945eea5 by Ben Gamari at 2020-06-01T06:34:58-04:00
nonmoving: Optimise log2_ceil

- - - - -
aab606e4 by Bodigrim at 2020-06-01T06:35:36-04:00
Clarify description of fromListN
- - - - -
7e5220e2 by Bodigrim at 2020-06-01T06:35:36-04:00
Apply suggestion to libraries/base/GHC/Exts.hs
- - - - -
f3fb1ce9 by fendor at 2020-06-01T06:36:18-04:00
Add `isInScope` check to `lintCoercion`

Mirrors the behaviour of `lintType`.

- - - - -
5ac4d946 by fendor at 2020-06-01T06:36:18-04:00
Lint rhs of IfaceRule

- - - - -
1cef6126 by Jeremy Schlatter at 2020-06-01T06:37:00-04:00
Fix wording in documentation

The duplicate "orphan instance" phrase here doesn't make sense, and was
probably an accident.

- - - - -
5aaf08f2 by Takenobu Tani at 2020-06-01T06:37:43-04:00
configure: Modify aclocal.m4 according to new module hierarchy

This patch updates file paths according to new module hierarchy [1]:

* Rename:
  * compiler/GHC/Parser.hs       <= compiler/parser/Parser.hs
  * compiler/GHC/Parser/Lexer.hs <= compiler/Parser/Lexer.hs

* Add:
  * compiler/GHC/Cmm/Lexer.hs

[1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular

- - - - -
15857ad8 by Ben Gamari at 2020-06-01T06:38:26-04:00
testsuite: Don't fail if we can't unlink __symlink_test

Afterall, it's possible we were unable to create it due to lack of
symlink permission.

- - - - -
4a7229ef by Ben Gamari at 2020-06-01T06:38:26-04:00
testsuite: Refactor ghostscript detection

Tamar reported that he saw crashes due to unhandled exceptions.

- - - - -
2ab37eaf by Ben Gamari at 2020-06-01T06:38:26-04:00
testsuite/perf_notes: Fix ill-typed assignments

- - - - -
e45d5b66 by Ben Gamari at 2020-06-01T06:38:26-04:00
testsuite/testutil: Fix bytes/str mismatch

- - - - -
7002d0cb by Ben Gamari at 2020-06-01T06:38:26-04:00
testsuite: Work around spurious mypy failure

- - - - -
11390e3a by Takenobu Tani at 2020-06-01T06:39:05-04:00
Clean up file paths for new module hierarchy

This updates comments only.
This patch replaces file references according to new module hierarchy.

See also:
* https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular
* https://gitlab.haskell.org/ghc/ghc/issues/13009

- - - - -
8f2e5732 by Takenobu Tani at 2020-06-01T06:39:05-04:00
Modify file paths to module paths for new module hierarchy

This updates comments only.

This patch replaces module references according to new module
hierarchy [1][2].

For files under the `compiler/` directory, I replace them as
module paths instead of file paths. For instance,
`GHC.Unit.State` instead of `compiler/GHC/Unit/State.hs` [3].

For current and future haddock's markup, this patch encloses
the module name with "" [4].

[1]: https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular
[2]: https://gitlab.haskell.org/ghc/ghc/issues/13009
[3]: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3375#note_276613
[4]: https://haskell-haddock.readthedocs.io/en/latest/markup.html#linking-to-modules

- - - - -
68b71c4a by Tom Ellis at 2020-06-01T06:39:55-04:00
Rename the singleton tuple GHC.Tuple.Unit to GHC.Tuple.Solo

- - - - -
95da76c2 by Sylvain Henry at 2020-06-01T06:40:41-04:00
Hadrian: fix binary-dist target for cross-compilation

- - - - -
730fcd54 by Vladislav Zavialov at 2020-06-01T06:41:18-04:00
Improve parser error messages for the @-operator

Since GHC diverges from the Haskell Report by allowing the user
to define (@) as an infix operator, we better give a good
error message when the user does so unintentionally.

In general, this is rather hard to do, as some failures will be
discovered only in the renamer or the type checker:

	x :: (Integer, Integer)
	x @ (a, b) = (1, 2)

This patch does *not* address this general case.

However, it gives much better error messages when the binding
is not syntactically valid:

	pairs xs @ (_:xs') = zip xs xs'

Before this patch, the error message was rather puzzling:

	<interactive>:1:1: error: Parse error in pattern: pairs

After this patch, the error message includes a hint:

	<interactive>:1:1: error:
	    Parse error in pattern: pairs
	    In a function binding for the ‘@’ operator.
	    Perhaps you meant an as-pattern, which must not be surrounded by whitespace

- - - - -
0fde5377 by Vladislav Zavialov at 2020-06-01T06:41:18-04:00
Improve parser error messages for TypeApplications

With this patch, we always parse  f @t  as a type application,
thereby producing better error messages.

This steals two syntactic forms:

* Prefix form of the @-operator in expressions. Since the @-operator is
  a divergence from the Haskell Report anyway, this is not a major loss.

* Prefix form of @-patterns. Since we are stealing loose infix form
  anyway, might as well sacrifice the prefix form for the sake of much
  better error messages.

- - - - -
c68e7e1e by Vladislav Zavialov at 2020-06-01T06:41:18-04:00
Improve parser error messages for TemplateHaskellQuotes

While [e| |], [t| |], [d| |], and so on, steal syntax from list
comprehensions, [| |] and [|| ||] do not steal any syntax.

Thus we can improve error messages by always accepting them in the
lexer. Turns out the renamer already performs necessary validation.

- - - - -
120aedbd by Ben Gamari at 2020-06-01T16:07:02-04:00
gitlab-ci: Disable use of ld.lld on ARMv7

It turns out that lld non-deterministically fails on ARMv7. I suspect
this may be due to the a kernel regression as this only started
happening when we upgraded to 5.4. Nevertheless, easily avoided by
simply sticking with gold.

Works around #18280.

- - - - -
b3624e02 by Simon Peyton Jones at 2020-06-01T21:35:07+01:00
Optimisation in Unique.Supply

This patch switches on -fno-state-hack in GHC.Types.Unique.Supply.

It turned out that my fixes for #18078 (coercion floating) changed the
optimisation pathway for mkSplitUniqSupply in such a way that we had
an extra allocation inside the inner loop.  Adding -fno-state-hack
fixed that -- and indeed the loop in mkSplitUniqSupply is a classic
example of the way in which -fno-state-hack can be bad; see #18238.

Moreover, the new code is better than the old.  They allocate
the same, but the old code ends up with a partial application.
The net effect is that the test
    perf/should_run/UniqLoop
runs 20% faster!   From 2.5s down to 2.0s.  The allocation numbers
are the same -- but elapsed time falls. Good!

The bad thing about this is that it's terribly delicate.  But
at least it's a good example of such delicacy in action.

There is a long Note [Optimising the unique supply] which now
explains all this.

- - - - -
320ec1f3 by Simon Peyton Jones at 2020-06-01T21:35:07+01:00
Implement cast worker/wrapper properly

The cast worker/wrapper transformation transforms
   x = e |> co
into
   y = e
   x = y |> co

This is done by the simplifier, but we were being
careless about transferring IdInfo from x to y,
and about what to do if x is a NOINLNE function.
This resulted in a series of bugs:
     #17673, #18093, #18078.

This patch fixes all that:

* Main change is in GHC.Core.Opt.Simplify, and
  the new prepareBinding function, which does this
  cast worker/wrapper transform.
  See Note [Cast worker/wrappers].

* There is quite a bit of refactoring around
  prepareRhs, makeTrivial etc.  It's nicer now.

* Some wrappers from strictness and cast w/w, notably those for
  a function with a NOINLINE, should inline very late. There
  wasn't really a mechanism for that, which was an existing bug
  really; so I invented a new finalPhase = Phase (-1).  It's used
  for all simplifier runs after the user-visible phase 2,1,0 have
  run.  (No new runs of the simplifier are introduced thereby.)

  See new Note [Compiler phases] in GHC.Types.Basic;
  the main changes are in GHC.Core.Opt.Driver

* Doing this made me trip over two places where the AnonArgFlag on a
  FunTy was being lost so we could end up with (Num a -> ty)
  rather than (Num a => ty)
    - In coercionLKind/coercionRKind
    - In contHoleType in the Simplifier

  I fixed the former by defining mkFunctionType and using it in
  coercionLKind/RKind.

  I could have done the same for the latter, but the information
  is almost to hand.  So I fixed the latter by
    - adding sc_hole_ty to ApplyToVal (like ApplyToTy),
    - adding as_hole_ty to ValArg (like TyArg)
    - adding sc_fun_ty to StrictArg
  Turned out I could then remove ai_type from ArgInfo.  This is
  just moving the deck chairs around, but it worked out nicely.

  See the new Note [AnonArgFlag] in GHC.Types.Var

* When looking at the 'arity decrease' thing (#18093) I discovered
  that stable unfoldings had a much lower arity than the actual
  optimised function.  That's what led to the arity-decrease
  message.  Simple solution: eta-expand.

  It's described in Note [Eta-expand stable unfoldings]
  in GHC.Core.Opt.Simplify

* I also discovered that unsafeCoerce wasn't being inlined if
  the context was boring.  So (\x. f (unsafeCoerce x)) would
  create a thunk -- yikes!  I fixed that by making inlineBoringOK
  a bit cleverer: see Note [Inline unsafeCoerce] in GHC.Core.Unfold.

  I also found that unsafeCoerceName was unused, so I removed it.

I made a test case for #18078, and a very similar one for #17673.

The net effect of all this on nofib is very modest, but positive:

--------------------------------------------------------------------------------
        Program           Size    Allocs   Runtime   Elapsed  TotalMem
--------------------------------------------------------------------------------
           anna          -0.4%     -0.1%     -3.1%     -3.1%      0.0%
 fannkuch-redux          -0.4%     -0.3%     -0.1%     -0.1%      0.0%
       maillist          -0.4%     -0.1%     -7.8%     -1.0%    -14.3%
      primetest          -0.4%    -15.6%     -7.1%     -6.6%      0.0%
--------------------------------------------------------------------------------
            Min          -0.9%    -15.6%    -13.3%    -14.2%    -14.3%
            Max          -0.3%      0.0%    +12.1%    +12.4%      0.0%
 Geometric Mean          -0.4%     -0.2%     -2.3%     -2.2%     -0.1%

Metric Decrease:
  T15164
  T13701
Metric Increase:
  T12150
  T12234
  T12425

- - - - -


30 changed files:

- .gitlab-ci.yml
- aclocal.m4
- compiler/GHC.hs
- compiler/GHC/Builtin/Names.hs
- compiler/GHC/Builtin/Types.hs
- compiler/GHC/Builtin/Utils.hs
- compiler/GHC/Cmm/Utils.hs
- compiler/GHC/CmmToAsm/PPC/Ppr.hs
- compiler/GHC/CmmToAsm/SPARC/Base.hs
- compiler/GHC/Core/Coercion.hs
- compiler/GHC/Core/Coercion/Opt.hs
- compiler/GHC/Core/InstEnv.hs
- compiler/GHC/Core/Lint.hs
- compiler/GHC/Core/Make.hs
- compiler/GHC/Core/Opt/CSE.hs
- compiler/GHC/Core/Opt/ConstantFold.hs
- compiler/GHC/Core/Opt/CprAnal.hs
- compiler/GHC/Core/Opt/Driver.hs
- compiler/GHC/Core/Opt/Simplify.hs
- compiler/GHC/Core/Opt/Simplify/Utils.hs
- compiler/GHC/Core/Opt/SpecConstr.hs
- compiler/GHC/Core/Opt/WorkWrap.hs
- compiler/GHC/Core/SimpleOpt.hs
- compiler/GHC/Core/TyCo/Tidy.hs
- compiler/GHC/Core/TyCon.hs
- compiler/GHC/Core/Type.hs
- compiler/GHC/Core/Unfold.hs
- compiler/GHC/Core/Utils.hs
- compiler/GHC/CoreToStg/Prep.hs
- compiler/GHC/Driver/Main.hs


The diff was not included because it is too large.


View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/12f458eb7e63b6ca8a2d5a3c94ab355582763ecc...320ec1f370b7929d91df527ddc10c8c2e977bb7c

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/12f458eb7e63b6ca8a2d5a3c94ab355582763ecc...320ec1f370b7929d91df527ddc10c8c2e977bb7c
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/20200601/33b2d0f0/attachment-0001.html>


More information about the ghc-commits mailing list