[Git][ghc/ghc][wip/unloading] 27 commits: hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468.

Ben Gamari gitlab at gitlab.haskell.org
Sun Aug 9 20:05:28 UTC 2020



Ben Gamari pushed to branch wip/unloading at Glasgow Haskell Compiler / GHC


Commits:
947206f4 by Niklas Hambüchen at 2020-08-03T07:52:33+02:00
hadrian: Fix running stage0/bin/ghc with wrong package DB. Fixes #17468.

In the invocation of `cabal configure`, `--ghc-pkg-option=--global-package-db`
was already given correctly to tell `stage0/bin/ghc-pkg` that it should use
the package DB in `stage1/`.

However, `ghc` needs to be given this information as well, not only `ghc-pkg`!
Until now that was not the case; the package DB in `stage0` was given to
`ghc` instead.
This was wrong, because there is no binary compatibility guarantee that says
that the `stage0` DB's `package.cache` (which is written by the
stage0 == system-provided ghc-pkg) can be deserialised by the `ghc-pkg`
from the source code tree.

As a result, when trying to add fields to `InstalledPackageInfo` that get
serialised into / deserialised from the `package.cache`, errors like

    _build/stage0/lib/package.conf.d/package.cache: GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!)

would appear. This was because the `stage0/bin/ghc would try to
deserialise the newly added fields from
`_build/stage0/lib/package.conf.d/package.cache`, but they were not in there
because the system `ghc-pkg` doesn't know about them and thus didn't write them
there.
It would try to do that because any GHC by default tries to read the global
package db in `../lib/package.conf.d/package.cache`.
For `stage0/bin/ghc` that *can never work* as explained above, so we
must disable this default via `-no-global-package-db` and give it the
correct package DB explicitly.

This is the same problem as #16534, and the same fix as in MR !780
(but in another context; that one was for developers trying out the
`stage0/bin/ghc` == `_build/ghc-stage1` interactively, while this fix
is for a `cabal configure` invocation).

I also noticed that the fix for #16534 forgot to pass `-no-global-package-db`,
and have fixed that in this commit as well.
It only worked until now because nobody tried to add a new ghc-pkg `.conf`
field since the introduction of Hadrian.

- - - - -
ef2ae81a by Alex Biehl at 2020-08-03T07:52:33+02:00
Hardcode RTS includes to cope with unregistered builds

- - - - -
d613ed76 by Sylvain Henry at 2020-08-05T03:59:27-04:00
Bignum: add backward compat integer-gmp functions

Also enhance bigNatCheck# and isValidNatural test

- - - - -
3f2f7718 by Sylvain Henry at 2020-08-05T03:59:27-04:00
Bignum: add more BigNat compat functions in integer-gmp

- - - - -
5e12cd17 by Krzysztof Gogolewski at 2020-08-05T04:00:04-04:00
Rename Core.Opt.Driver -> Core.Opt.Pipeline

Closes #18504.

- - - - -
2bff2f87 by Ben Gamari at 2020-08-05T04:00:39-04:00
Revert "iserv: Don't pass --export-dynamic on FreeBSD"

This reverts commit 2290eb02cf95e9cfffcb15fc9c593d5ef79c75d9.

- - - - -
53ce0db5 by Ben Gamari at 2020-08-05T04:00:39-04:00
Refactor handling of object merging

Previously to merge a set of object files we would invoke the linker as
usual, adding -r to the command-line. However, this can result in
non-sensical command-lines which causes lld to balk (#17962).

To avoid this we introduce a new tool setting into GHC, -pgmlm, which is
the linker which we use to merge object files.

- - - - -
eb7013c3 by Hécate at 2020-08-05T04:01:15-04:00
Remove all the unnecessary LANGUAGE pragmas

- - - - -
fbcb886d by Ryan Scott at 2020-08-05T04:01:51-04:00
Make CodeQ and TExpQ levity polymorphic

The patch is quite straightforward. The only tricky part is that
`Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead
of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`).

Since `CodeQ` has yet to appear in any released version of
`template-haskell`, I didn't bother mentioning the change to `CodeQ`
in the `template-haskell` release notes.

Fixes #18521.

- - - - -
686e06c5 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00
Grammar for types and data/newtype constructors

Before this patch, we parsed types into a reversed sequence
of operators and operands. For example, (F x y + G a b * X)
would be parsed as [X, *, b, a, G, +, y, x, F],
using a simple grammar:

	tyapps
	  : tyapp
	  | tyapps tyapp

	tyapp
	  : atype
	  | PREFIX_AT atype
	  | tyop
	  | unpackedness

Then we used a hand-written state machine to assemble this
 either into a type,        using 'mergeOps',
     or into a constructor, using 'mergeDataCon'.

This is due to a syntactic ambiguity:

	data T1 a =          MkT1 a
	data T2 a = Ord a => MkT2 a

In T1, what follows after the = sign is a data/newtype constructor
declaration. However, in T2, what follows is a type (of kind
Constraint). We don't know which of the two we are parsing until we
encounter =>, and we cannot check for => without unlimited lookahead.

This poses a few issues when it comes to e.g. infix operators:

	data I1 = Int :+ Bool :+ Char          -- bad
	data I2 = Int :+ Bool :+ Char => MkI2  -- fine

By this issue alone we are forced into parsing into an intermediate
representation and doing a separate validation pass.

However, should that intermediate representation be as low-level as a
flat sequence of operators and operands?

Before GHC Proposal #229, the answer was Yes, due to some particularly
nasty corner cases:

	data T = ! A :+ ! B          -- used to be fine, hard to parse
	data T = ! A :+ ! B => MkT   -- bad

However, now the answer is No, as this corner case is gone:

	data T = ! A :+ ! B          -- bad
	data T = ! A :+ ! B => MkT   -- bad

This means we can write a proper grammar for types, overloading it in
the DisambECP style, see Note [Ambiguous syntactic categories].

With this patch, we introduce a new class, DisambTD. Just like
DisambECP is used to disambiguate between expressions, commands, and patterns,
DisambTD  is used to disambiguate between types and data/newtype constructors.

This way, we get a proper, declarative grammar for constructors and
types:

	infixtype
	  : ftype
	  | ftype tyop infixtype
	  | unpackedness infixtype

	ftype
	  : atype
	  | tyop
	  | ftype tyarg
	  | ftype PREFIX_AT tyarg

	tyarg
	  : atype
	  | unpackedness atype

And having a grammar for types means we are a step closer to using a
single grammar for types and expressions.

- - - - -
6770e199 by Vladislav Zavialov at 2020-08-06T13:34:05-04:00
Clean up the story around runPV/runECP_P/runECP_PV

This patch started as a small documentation change, an attempt to make
Note [Parser-Validator] and Note [Ambiguous syntactic categories]
more clear and up-to-date.

But it turned out that runECP_P/runECP_PV are weakly motivated,
and it's easier to remove them than to find a good rationale/explanation
for their existence.

As the result, there's a bit of refactoring in addition to
a documentation update.

- - - - -
826d07db by Vladislav Zavialov at 2020-08-06T13:34:06-04:00
Fix debug_ppr_ty ForAllTy (#18522)

Before this change, GHC would
pretty-print   forall k. forall a -> ()
          as   forall @k a. ()
which isn't even valid Haskell.

- - - - -
0ddb4384 by Vladislav Zavialov at 2020-08-06T13:34:06-04:00
Fix visible forall in ppr_ty (#18522)

Before this patch, this type:
  T :: forall k -> (k ~ k) => forall j -> k -> j -> Type
was printed incorrectly as:
  T :: forall k j -> (k ~ k) => k -> j -> Type

- - - - -
d2a43225 by Richard Eisenberg at 2020-08-06T13:34:06-04:00
Fail eagerly on a lev-poly datacon arg

Close #18534.

See commentary in the patch.

- - - - -
63348155 by Sylvain Henry at 2020-08-06T13:34:08-04:00
Use a type alias for Ways

- - - - -
9570c212 by Takenobu Tani at 2020-08-06T19:46:46-04:00
users-guide: Rename 8.12 to 9.0

GHC 8.12.1 has been renamed to GHC 9.0.1.

See also:
  https://mail.haskell.org/pipermail/ghc-devs/2020-July/019083.html

[skip ci]

- - - - -
3907ee01 by Cale Gibbard at 2020-08-07T08:34:46-04:00
A fix to an error message in monad comprehensions, and a move of dsHandleMonadicFailure
as suggested by comments on !2330.

- - - - -
fa9bb70a by Cale Gibbard at 2020-08-07T08:34:46-04:00
Add some tests for fail messages in do-expressions and monad-comprehensions.

- - - - -
5f036063 by Ben Gamari at 2020-08-07T08:35:21-04:00
cmm: Clean up Notes a bit

- - - - -
6402c124 by Ben Gamari at 2020-08-07T08:35:21-04:00
CmmLint: Check foreign call argument register invariant

As mentioned in Note [Register parameter passing] the arguments of
foreign calls cannot refer to caller-saved registers.

- - - - -
15b36de0 by Ben Gamari at 2020-08-07T08:35:21-04:00
nativeGen: One approach to fix #18527

Previously the code generator could produce corrupt C call sequences due
to register overlap between MachOp lowerings and the platform's calling
convention. We fix this using a hack described in Note [Evaluate C-call
arguments before placing in destination registers].

- - - - -
3847ae0c by Ben Gamari at 2020-08-07T08:35:21-04:00
testsuite: Add test for #18527

- - - - -
dd51d53b by Ben Gamari at 2020-08-07T08:35:21-04:00
testsuite: Fix prog001

Previously it failed as the `ghc` package was not visible.

- - - - -
e4f1b73a by Alan Zimmerman at 2020-08-07T23:58:10-04:00
ApiAnnotations; tweaks for ghc-exactprint update

Remove unused ApiAnns, add one for linear arrow.

Include API Annotations for trailing comma in export list.

- - - - -
8a665db6 by Ben Gamari at 2020-08-07T23:58:45-04:00
configure: Fix double-negation in ld merge-objects check

We want to only run the check if ld is gold.

Fixes the fix to #17962.
- - - - -
46234542 by Ömer Sinan Ağacan at 2020-08-09T16:05:22-04:00
Fix and enable object unloading in GHCi

Fixes #16525

See Note [Object unloading] in CheckUnload.c for details.

NoFib results:

--------------------------------------------------------------------------------
        Program           Size    Allocs    Instrs     Reads    Writes
--------------------------------------------------------------------------------
             CS          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
            CSD          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
             FS          -0.2%      0.0%     +0.0%     +0.0%     -0.0%
              S          -0.2%      0.0%     +1.0%     +1.1%     +0.0%
             VS          -0.2%      0.0%     +0.0%     +0.0%     -0.0%
            VSD          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
            VSM          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
           anna          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
           ansi          -0.1%      0.0%     +0.0%     +0.0%      0.0%
           atom          -0.1%      0.0%     +0.0%     +0.0%      0.0%
         awards          -0.1%      0.0%     +0.0%     +0.0%      0.0%
         banner          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
     bernouilli          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
   binary-trees          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
          boyer          -0.1%      0.0%     +0.1%     +0.1%      0.0%
         boyer2          -0.1%      0.0%     +0.0%     +0.1%      0.0%
           bspt          -0.1%      0.0%     +0.0%     +0.0%      0.0%
      cacheprof          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
       calendar          -0.1%      0.0%     +0.0%     +0.0%      0.0%
       cichelli          -0.1%      0.0%     +0.1%     +0.2%     +0.0%
        circsim          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
       clausify          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
  comp_lab_zift          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
       compress          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
      compress2          -0.1%      0.0%     +0.0%     +0.0%      0.0%
    constraints          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
   cryptarithm1          -0.1%      0.0%     +0.0%     +0.0%      0.0%
   cryptarithm2          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
            cse          -0.1%      0.0%     +0.0%     +0.0%      0.0%
   digits-of-e1          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
   digits-of-e2          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
         dom-lt          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
          eliza          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
          event          -0.1%      0.0%     +0.0%     +0.1%      0.0%
    exact-reals          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
         exp3_8          -0.1%      0.0%     +0.0%     +0.0%      0.0%
         expert          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
 fannkuch-redux          -0.1%      0.0%     +0.0%     +0.0%      0.0%
          fasta          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
            fem          -0.1%      0.0%     +0.0%     +0.0%      0.0%
            fft          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
           fft2          -0.1%      0.0%     +0.0%     +0.0%      0.0%
       fibheaps          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
           fish          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
          fluid          -0.1%      0.0%     +0.1%     +0.1%     -0.0%
         fulsom          -0.1%      0.0%     +0.0%     +0.0%      0.0%
         gamteb          -0.1%      0.0%     +0.0%     +0.0%      0.0%
            gcd          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
    gen_regexps          -0.2%      0.0%     +0.0%     +0.0%     -0.0%
         genfft          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
             gg          -0.1%      0.0%     +0.1%     +0.1%      0.0%
           grep          -0.1%      0.0%     +0.0%     +0.0%      0.0%
         hidden          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
            hpg          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
            ida          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
          infer          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
        integer          -0.1%      0.0%     +0.0%     +0.0%      0.0%
      integrate          -0.1%      0.0%     +0.0%     +0.0%      0.0%
   k-nucleotide          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
          kahan          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
        knights          -0.1%      0.0%     +0.0%     +0.0%      0.0%
         lambda          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
     last-piece          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
           lcss          -0.1%      0.0%     +0.0%     +0.0%      0.0%
           life          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
           lift          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
         linear          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
      listcompr          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
       listcopy          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
       maillist          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
         mandel          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
        mandel2          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
           mate          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
        minimax          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
        mkhprog          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
     multiplier          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
         n-body          -0.1%      0.0%     +0.0%     +0.0%      0.0%
       nucleic2          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
           para          -0.1%      0.0%     +0.0%     +0.0%      0.0%
      paraffins          -0.1%      0.0%     +0.0%     +0.0%      0.0%
         parser          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
        parstof          -0.1%      0.0%     +0.2%     +0.2%     -0.0%
            pic          -0.1%      0.0%     +0.1%     +0.1%     +0.0%
       pidigits          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
          power          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
         pretty          -0.1%      0.0%     +0.5%     +0.6%     -0.0%
         primes          -0.1%      0.0%     +0.0%     +0.0%      0.0%
      primetest          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
         prolog          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
         puzzle          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
         queens          -0.1%      0.0%     +0.0%     +0.0%      0.0%
        reptile          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
reverse-complem          -0.2%      0.0%     +0.0%     +0.0%      0.0%
        rewrite          -0.1%      0.0%     +0.0%     +0.0%      0.0%
           rfib          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
            rsa          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
            scc          -0.2%      0.0%     +0.5%     +0.7%     +0.0%
          sched          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
            scs          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
         simple          -0.1%      0.0%     +0.3%     +0.4%      0.0%
          solid          -0.1%      0.0%     +0.0%     +0.0%      0.0%
        sorting          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
  spectral-norm          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
         sphere          -0.1%      0.0%     +0.0%     +0.0%      0.0%
         symalg          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
            tak          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
      transform          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
       treejoin          -0.1%      0.0%     +0.1%     +0.1%      0.0%
      typecheck          -0.1%      0.0%     +0.0%     +0.0%      0.0%
        veritas          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
           wang          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
      wave4main          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
   wheel-sieve1          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
   wheel-sieve2          -0.1%      0.0%     +0.0%     +0.0%     -0.0%
           x2n1          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
--------------------------------------------------------------------------------
            Min          -0.2%      0.0%     +0.0%     +0.0%     -0.0%
            Max          -0.1%      0.0%     +1.0%     +1.1%     +0.0%
 Geometric Mean          -0.1%     -0.0%     +0.0%     +0.0%     -0.0%

- - - - -
b2658359 by Ray Shih at 2020-08-09T16:05:22-04:00
Add loadNativeObj and unloadNativeObj

Summary:

(This change is originally written by niteria)

This adds two functions:
* `loadNativeObj`
* `unloadNativeObj`
and implements them for Linux.

They are useful if you want to load a shared object with Haskell code
using the system linker and have GHC call dlclose() after the
code is no longer referenced from the heap.

Using the system linker allows you to load the shared object
above outside the lowmem region. It also loads the DWARF sections
in a way that `perf` understands.

`dl_iterate_phdr` is what makes this implementation Linux specific.

NOTE: this should be replaceable by whatever D4263 becomes

Test Plan: manual testing

Reviewers: simonmar, Phyx, bgamari, erikd

Reviewed By: niteria

Subscribers: rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4263

- - - - -


30 changed files:

- aclocal.m4
- compiler/GHC.hs
- compiler/GHC/Cmm/Lint.hs
- compiler/GHC/Cmm/MachOp.hs
- compiler/GHC/Cmm/Node.hs
- compiler/GHC/Cmm/Sink.hs
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- compiler/GHC/Core/Opt/Driver.hs → compiler/GHC/Core/Opt/Pipeline.hs
- compiler/GHC/Core/Opt/Simplify.hs
- compiler/GHC/Core/TyCo/Ppr.hs
- compiler/GHC/Driver/CodeOutput.hs
- compiler/GHC/Driver/Main.hs
- compiler/GHC/Driver/Pipeline.hs
- compiler/GHC/Driver/Session.hs
- compiler/GHC/HsToCore/Expr.hs
- compiler/GHC/HsToCore/Expr.hs-boot
- compiler/GHC/HsToCore/ListComp.hs
- compiler/GHC/HsToCore/Utils.hs
- compiler/GHC/Iface/Type.hs
- compiler/GHC/Parser.y
- compiler/GHC/Parser/Annotation.hs
- compiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Platform/Profile.hs
- compiler/GHC/Platform/Ways.hs
- compiler/GHC/Runtime/Linker.hs
- compiler/GHC/Settings.hs
- compiler/GHC/Settings/IO.hs
- compiler/GHC/StgToCmm/Foreign.hs
- compiler/GHC/StgToCmm/Utils.hs
- compiler/GHC/SysTools/Tasks.hs


The diff was not included because it is too large.


View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2cfcbcfa90dd5cda84c7bdd3b4ef36786ea508c8...b2658359ca2493e4f5eccaffabd367d7bd550189

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2cfcbcfa90dd5cda84c7bdd3b4ef36786ea508c8...b2658359ca2493e4f5eccaffabd367d7bd550189
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/20200809/6349d5bf/attachment-0001.html>


More information about the ghc-commits mailing list