17 months agoTighten cached role in NthCo wip/tdammers/T11735
Richard Eisenberg [Mon, 12 Feb 2018 18:02:23 +0000 (13:02 -0500)] 
Tighten cached role in NthCo

17 months agoPerformance improvements based on Trac #11735 and #14683.
Tobias Dammers [Tue, 30 Jan 2018 16:04:47 +0000 (17:04 +0100)] 
Performance improvements based on Trac #11735 and #14683.

This includes:

- Refactoring coercionKind / coercionKindRole
- Caching role in NthCo constructor and mkNthCo
- Discard reflexive casts during Simplify
- Additional SCC's to hunt down performance bottlenecks in Coercion,
  CoreTidy, and Simplify

Reviewers: goldfire, bgamari

Subscribers: rwbarton, thomie, carter

Differential Revision:

17 months agoFix testsuite failures
Richard Eisenberg [Sat, 27 Jan 2018 21:46:36 +0000 (16:46 -0500)] 
Fix testsuite failures

17 months agoThis should really have been in the previous commit.
Richard Eisenberg [Sat, 27 Jan 2018 14:55:21 +0000 (09:55 -0500)] 
This should really have been in the previous commit.

17 months agoDiscard reflexive casts during Simplify
Richard Eisenberg [Sat, 27 Jan 2018 03:42:46 +0000 (22:42 -0500)] 
Discard reflexive casts during Simplify

Previously, we went to great lengths to build just the right
reflexive casts, only to discard them shortly later. Now, just
skip creating reflexive casts altogether.

17 months agoUpdate core-spec with new NthCo
Richard Eisenberg [Sat, 27 Jan 2018 03:28:42 +0000 (22:28 -0500)] 
Update core-spec with new NthCo

17 months agoMake mkNthCo take a Role parameter.
Richard Eisenberg [Sat, 27 Jan 2018 03:09:33 +0000 (22:09 -0500)] 
Make mkNthCo take a Role parameter.

Most callers of mkNthCo know the role of the coercion they
are trying to make. So instead of calculating this role, just
pass it in.

17 months agoCaching coercion roles in NthCo (#11735)
Tobias Dammers [Thu, 25 Jan 2018 19:33:58 +0000 (20:33 +0100)] 
Caching coercion roles in NthCo (#11735)

17 months agoSimplification as per #11735
Tobias Dammers [Thu, 25 Jan 2018 10:16:30 +0000 (11:16 +0100)] 
Simplification as per #11735


17 months agoRefactored coercionKindsRole (as per #11735)
Tobias Dammers [Wed, 24 Jan 2018 16:20:20 +0000 (17:20 +0100)] 
Refactored coercionKindsRole (as per #11735)

17 months agoAdded SCCs to hunt down #14683
Tobias Dammers [Wed, 24 Jan 2018 15:07:00 +0000 (16:07 +0100)] 
Added SCCs to hunt down #14683

17 months agoApplying patch suggested in #11735 to improve coercionKind perf
Tobias Dammers [Wed, 24 Jan 2018 15:05:55 +0000 (16:05 +0100)] 
Applying patch suggested in #11735 to improve coercionKind perf

17 months agoPass -dsuppress-uniques when running T14507
Ryan Scott [Mon, 22 Jan 2018 19:16:12 +0000 (14:16 -0500)] 
Pass -dsuppress-uniques when running T14507

Not doing so resulted in different uniques being printed on different
environments, as shown in #14703.

17 months agoImprove comments about TcLevel invariants
Simon Peyton Jones [Mon, 22 Jan 2018 14:49:46 +0000 (14:49 +0000)] 
Improve comments about TcLevel invariants

17 months agoBump transformers submodule to
Ben Gamari [Mon, 22 Jan 2018 01:09:20 +0000 (20:09 -0500)] 
Bump transformers submodule to

17 months agoUpdate Cabal submodule
Oleg Grenrus [Sun, 21 Jan 2018 18:37:17 +0000 (20:37 +0200)] 
Update Cabal submodule

- Cabal-2.2 uses SPDX license identifiers, so I had to update
  `cabal-version: 2.1` packages `license: BSD3` to `license: BSD-3-Clause`
- `ghc-cabal` used old ReadP parsec, now it uses `parsec` too
- InstalledPackageInfo pretty-printing have changed a little,
  fields with default values aren't printed. This can be changed in
  `Cabal` still, but I haven't found problems with omitting them.

Note: `BSD-3-Clause` is parsed as "name = BSD, version = 3" by old
parser (because 3-Clause looks like version 3 with tag Clause).
If you see *"BSD-3" is not a valid license*, then something is using
old parser still.

Fixes #9885.

17 months agoSysTools: Add detection support for LLD linker
Ben Gamari [Sun, 21 Jan 2018 18:31:29 +0000 (13:31 -0500)] 
SysTools: Add detection support for LLD linker

I noticed while trying to test against LLVM 5.0 that GHC would throw "Couldn't
figure out linker information" warnings due to LLD being chosen by configure.
Adding detection support to silence these is simple enough, let's just do it.

17 months agoUse IntSet in Dataflow
Bartosz Nitka [Sun, 21 Jan 2018 17:11:28 +0000 (12:11 -0500)] 
Use IntSet in Dataflow

Before this change, a list was used as a substitute for a heap.
This led to quadratic behavior on a simple program (see new
test case).

This change replaces it with IntSet in effect reverting
5a1a2633553. @simonmar said it's fine to revert as long as nofib
results are good.

Test Plan:
new test case:

20% improvement
3x improvement when N=10000


I run it twice for before and after because the compile time
results are noisy.

- Compile Allocations:

          before    before re-run    after     after re-run
-1 s.d.   -----     -0.0%            -0.1%     -0.1%
+1 s.d.   -----     +0.0%            +0.1%     +0.1%
Average   -----     +0.0%            -0.0%     -0.0%
- Compile Time:

          before    before re-run    after     after re-run
-1 s.d.   -----     -0.1%            -2.3%     -2.6%
+1 s.d.   -----     +5.2%            +3.7%     +4.4%
Average   -----     +2.5%            +0.7%     +0.8%

I checked each case and couldn't find consistent slow-down/speed-up on
compile time. Full results here: P173

Reviewers: simonpj, simonmar, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter, simonmar

GHC Trac Issues: #14667

Differential Revision:

17 months agoImplement underscores in numeric literals (NumericUnderscores extension)
Takenobu Tani [Sun, 21 Jan 2018 17:08:59 +0000 (12:08 -0500)] 
Implement underscores in numeric literals (NumericUnderscores extension)

Implement the proposal of underscores in numeric literals.
Underscores in numeric literals are simply ignored.

The specification of the feature is available here:

For a discussion of the various choices:

Implementation detail:

* Added dynamic flag
  * `NumericUnderscores` extension flag is added for this feature.

* Alex "Regular expression macros" in Lexer.x
  * Add `@numspc` (numeric spacer) macro to represent multiple
  * Modify `@decimal`, `@decimal`, `@binary`, `@octal`, `@hexadecimal`,
    `@exponent`, and `@bin_exponent` macros to include `@numspc`.

* Alex "Rules" in Lexer.x
  * To be simpler, we have only the definitions with underscores.
    And then we have a separate function (`tok_integral` and `tok_frac`)
    that validates the literals.

* Validation functions in Lexer.x
  * `tok_integral` and `tok_frac` functions validate
    whether contain underscores or not.
    If `NumericUnderscores` extensions are not enabled,
    check that there are no underscores.
  * `tok_frac` function is created by merging `strtoken` and
  * `init_strtoken` is deleted. Because it is no longer used.

* Remove underscores from target literal string
  * `parseUnsignedInteger`, `readRational__`, and `readHexRational} use
    the customized `span'` function to remove underscores.

* Added Testcase
  * testcase for NumericUnderscores enabled.
      NumericUnderscores0.hs and NumericUnderscores1.hs
  * testcase for NumericUnderscores disabled.
      NoNumericUnderscores0.hs and NoNumericUnderscores1.hs
  * testcase to invalid pattern for NumericUnderscores enabled.
      NumericUnderscoresFail0.hs and NumericUnderscoresFail1.hs

Test Plan: `validate` including the above testcase

Reviewers: goldfire, bgamari

Reviewed By: bgamari

Subscribers: carter, rwbarton, thomie

GHC Trac Issues: #14473

Differential Revision:

17 months ago[rts] Adjust whitehole_spin
Douglas Wilson [Sun, 21 Jan 2018 17:08:19 +0000 (12:08 -0500)] 
[rts] Adjust whitehole_spin

Rename to whitehole_gc_spin, in preparation for adding stats for the
whitehole busy-loop in SMPClosureOps.

Make whitehole_gc_spin volatile, and move it to be defined and
statically initialised in GC.c. This saves some #ifs, and I'm pretty
sure it should be volatile.

Test Plan: ./validate

Reviewers: bgamari, erikd, simonmar

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

Differential Revision:

17 months agotentative improvement to callstack docs
Alp Mestanogullari [Sun, 21 Jan 2018 17:07:58 +0000 (12:07 -0500)] 
tentative improvement to callstack docs

This is an attempt at clarifying the docs for HasCallStack in both the
user guide and libraries/base/GHC/Stack/Types.hs. The example used right
now is built around an hypothetical 'error' function that doesn't itself
print call stacks, and the fact that this doesn't hold makes it all
confusing, see #14635.

Reviewers: hvr, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14635

Differential Revision:

17 months agoFix #14692 by correcting an off-by-one error in TcGenDeriv
Ryan Scott [Sun, 21 Jan 2018 17:06:06 +0000 (12:06 -0500)] 
Fix #14692 by correcting an off-by-one error in TcGenDeriv

A silly mistake in `gen_Show_binds` was causing derived
`Show` instances for empty data types to case on the precedence
argument instead of the actual value being showed.

Test Plan: make test TEST=drv-empty-data

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14692

Differential Revision:

17 months agotestsuite: Add testcase for #14670
Ben Gamari [Sun, 21 Jan 2018 16:57:34 +0000 (11:57 -0500)] 
testsuite: Add testcase for #14670

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14670

Differential Revision:

17 months agoAdd new mbmi and mbmi2 compiler flags
John Ky [Sun, 21 Jan 2018 16:55:45 +0000 (11:55 -0500)] 
Add new mbmi and mbmi2 compiler flags

This adds support for the bit deposit and extraction operations provided
by the BMI and BMI2 instruction set extensions on modern amd64 machines.

Implement x86 code generator for pdep and pext.  Properly initialise
bmiVersion field.

pdep and pext test cases

Fix pattern match for pdep and pext instructions

Fix build of pdep and pext code for 32-bit architectures

Test Plan: Validate

Reviewers: austin, simonmar, bgamari, angerman

Reviewed By: bgamari

Subscribers: trommler, carter, angerman, thomie, rwbarton, newhoggy

GHC Trac Issues: #14206

Differential Revision:

17 months agotestsuite: Add test for #14335
Ben Gamari [Thu, 18 Jan 2018 23:23:06 +0000 (18:23 -0500)] 
testsuite: Add test for #14335

Subscribers: rwbarton, thomie

GHC Trac Issues: #14335

Differential Revision:

17 months agoFix #14681 and #14682 with precision-aimed parentheses
Ryan Scott [Thu, 18 Jan 2018 16:06:42 +0000 (11:06 -0500)] 
Fix #14681 and #14682 with precision-aimed parentheses

It turns out that `Convert` was recklessly leaving off
parentheses in two places:

* Negative numeric literals
* Patterns in lambda position

This patch fixes it by adding three new functions, `isCompoundHsLit`,
`isCompoundHsOverLit`, and `isCompoundPat`, and using them in the
right places in `Convert`. While I was in town, I also sprinkled
`isCompoundPat` among some `Pat`-constructing functions in `HsUtils`
to help avoid the likelihood of this problem happening in other
places. One of these places is in `TcGenDeriv`, and sprinkling
`isCompountPat` there fixes #14682

Test Plan: make test TEST="T14681 T14682"

Reviewers: alanz, goldfire, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14681, #14682

Differential Revision:

17 months agoRemove unused extern cost centre collection
Ömer Sinan Ağacan [Thu, 18 Jan 2018 16:06:30 +0000 (11:06 -0500)] 
Remove unused extern cost centre collection

Reviewers: bgamari, simonmar

Reviewed By: simonmar

Subscribers: alexbiehl, rwbarton, thomie, carter

Differential Revision:

17 months agocmm: Include braces on default branch as required by the parser [Thu, 18 Jan 2018 16:05:40 +0000 (11:05 -0500)] 
cmm: Include braces on default branch as required by the parser

Test Plan: Looking at cmm-dump

Reviewers: bgamari, simonmar

Reviewed By: simonmar

Subscribers: rwbarton, thomie, carter

Differential Revision:

17 months agoRevert "Improve accuracy of get/setAllocationCounter"
Ben Gamari [Thu, 18 Jan 2018 05:50:31 +0000 (00:50 -0500)] 
Revert "Improve accuracy of get/setAllocationCounter"

This reverts commit a1a689dda48113f3735834350fb562bb1927a633.

17 months agoRevert "Fix regression on i386 due to get/setAllocationCounter change"
Ben Gamari [Thu, 18 Jan 2018 05:50:05 +0000 (00:50 -0500)] 
Revert "Fix regression on i386 due to get/setAllocationCounter change"

This reverts commit a770226e03f09b767fdb4ce826162a5c0f29ec29.

17 months agoInform hole substitutions of typeclass constraints (fixes #14273).
Matthías Páll Gissurarson [Thu, 18 Jan 2018 05:49:38 +0000 (00:49 -0500)] 
Inform hole substitutions of typeclass constraints (fixes  #14273).

This implements SPJ's suggestion on the ticket (#14273). We find the
relevant constraints (ones that whose free unification variables are all
mentioned in the type of the hole), and then clone the free unification
variables of the hole and the relevant constraints. We then add a
subsumption constraints and run the simplifier, and then check whether
all the constraints were solved.

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: RyanGlScott, rwbarton, thomie, carter

GHC Trac Issues: #14273

Differential Revision:

17 months agoFix references to
Ben Gamari [Thu, 18 Jan 2018 00:58:41 +0000 (19:58 -0500)] 
Fix references to

Reviewers: simonmar

Reviewed By: simonmar

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14665

Differential Revision:

17 months agoTypos in comments
Gabor Greif [Wed, 17 Jan 2018 13:05:48 +0000 (14:05 +0100)] 
Typos in comments

17 months agoFix quadratic behavior of prepareAlts
Bartosz Nitka [Sat, 13 Jan 2018 02:02:22 +0000 (02:02 +0000)] 
Fix quadratic behavior of prepareAlts

This code is quadratic and a simple test case I used
managed to tickle it.

The example (same one as #14667) looks like this:
module A10000 where

 data A = A
   | A00001
   | A00002
   | A10000

 f :: A -> Int
 f A00001 = 19900001
 f A00002 = 19900002
 f A10000 = 19910000

Applied on top of a fix for #14667, it gives a 30% compile time

Test Plan: ./validate

Reviewers: simonpj, bgamari

Subscribers: rwbarton, thomie, simonmar, carter

Differential Revision:

17 months agoconfigure: Various cleanups
John Ericson [Mon, 15 Jan 2018 18:53:08 +0000 (13:53 -0500)] 
configure: Various cleanups

Substitute RanlibCmd for consistency, and other configure cleanups that
should have no effect

The other commands are so substituted. Maybe we don't need ranlib at
all, and the configure snippet can be removed all together, but that
can always be done later.

Reviewers: bgamari, hvr, angerman

Reviewed By: bgamari, angerman

Subscribers: rwbarton, thomie, erikd, carter

Differential Revision:

17 months agoSimplify guard in createSwitchPlan. [Mon, 15 Jan 2018 18:52:33 +0000 (13:52 -0500)] 
Simplify guard in createSwitchPlan.

Given that we have two unique keys (guaranteed by Map) checking that
`|range| == 1` is faster.

The fact that `x1 == lo` and `x2 == hi` is guaranteed by mkSwitchTargets
which removes values outside of the range.

Test Plan: ci

Reviewers: bgamari, simonmar

Reviewed By: simonmar

Subscribers: rwbarton, thomie, carter

Differential Revision:

17 months agoRemove executable filename check on windows [Mon, 15 Jan 2018 18:52:15 +0000 (13:52 -0500)] 
Remove executable filename check on windows

On Windows GHC enforces currently that the real executable is named

I don't see a good reason why this is neccessary.
This patch removes this restriction and fixes #14652

Test Plan: ci

Reviewers: bgamari, Phyx

Reviewed By: Phyx

Subscribers: Phyx, rwbarton, thomie, carter

GHC Trac Issues: #14652

Differential Revision:

17 months agoParenthesize forall-type args in cvtTypeKind
Ryan Scott [Mon, 15 Jan 2018 18:51:55 +0000 (13:51 -0500)] 
Parenthesize forall-type args in cvtTypeKind

Trac #14646 happened because we forgot to parenthesize `forall` types to
the left of an arrow. This simple patch fixes that.

Test Plan: make test TEST=T14646

Reviewers: alanz, goldfire, bgamari

Reviewed By: alanz

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14646

Differential Revision:

17 months agoAdd flag -fno-it
Matthew Pickering [Mon, 15 Jan 2018 18:51:38 +0000 (13:51 -0500)] 
Add flag -fno-it

This flag stops ghci creating the special variable `it`
after evaluating an expression. This stops ghci leaking
as much memory when evaluating expressions. See #14336

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14336

Differential Revision:

17 months agoFix hash in haddock of ghc-prim.
HE, Tao [Mon, 15 Jan 2018 18:51:15 +0000 (13:51 -0500)] 
Fix hash in haddock of ghc-prim.

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14653

Differential Revision:

17 months agoCoreLint: typo in a comment
Ömer Sinan Ağacan [Mon, 15 Jan 2018 18:51:02 +0000 (13:51 -0500)] 
CoreLint: typo in a comment

Reviewers: bgamari, goldfire

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

Differential Revision:

17 months agoFix hashbang of gen-data-layout
Ben Gamari [Mon, 15 Jan 2018 18:50:35 +0000 (13:50 -0500)] 
Fix hashbang of gen-data-layout

Subscribers: rwbarton, thomie, carter

Differential Revision:

17 months agoSupport LIBRARY_PATH and LD_LIBRARY_PATH in rts
Ben Gamari [Mon, 15 Jan 2018 17:40:22 +0000 (12:40 -0500)] 

`LIBRARY_PATH` is used to find libraries and other link artifacts while
`LD_LIBRARY_PATH` is used to find shared libraries by the loader.

Due to an implementation detail on Windows, using `LIBRARY_PATH` will
automatically add the path of any library found to the loader's path.

So in that case `LD_LIBRARY_PATH` won't be needed.

Test Plan:
./validate along with T14611 which has been made Windows only
due to linux using the system linker/loader by default. So I feel a
testcase there is unwarranted as the support is indirect via glibc.

Reviewers: hvr, bgamari, erikd, simonmar, RyanGlScott

Reviewed By: RyanGlScott

Subscribers: RyanGlScott, rwbarton, thomie, carter

GHC Trac Issues: #14611

Differential Revision:

17 months agoTweak link order slightly to prefer user shared libs before system ones.
Tamar Christina [Mon, 15 Jan 2018 17:38:45 +0000 (12:38 -0500)] 
Tweak link order slightly to prefer user shared libs before system ones.

We currently always prefer shared libraries before import libraries and
static libraries. This is because they're faster to load. The problem is
when shared library are installed in the Windows directory. These would
supersede any user specified ones.

This is bad because e.g. Windows now ships icuuc, but an old version.
If you try to use -licuuc then it would pick the Windows one instead of
your user specified one.

This patch slighly tweaks the ordering so user paths get prefered.

Test Plan: ./validate

Reviewers: RyanGlScott, hvr, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14456

Differential Revision:

17 months agoKill off irrefutable pattern errors
David Feuer [Mon, 15 Jan 2018 17:38:29 +0000 (12:38 -0500)] 
Kill off irrefutable pattern errors

Distinguishing between "refutable" and "irrefutable" patterns
(as described by the Haskell Report) in incomplete pattern errors
was more confusing than helpful. Remove references to irrefutable

Reviewers: hvr, bgamari, simonpj

Reviewed By: simonpj

Subscribers: simonpj, rwbarton, thomie, carter

GHC Trac Issues: #14569

Differential Revision:

17 months agoRename -frule-check to -drule-check and document
Matthew Pickering [Mon, 15 Jan 2018 17:37:51 +0000 (12:37 -0500)] 
Rename -frule-check to -drule-check and document

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

Differential Revision:

17 months agoFix regression on i386 due to get/setAllocationCounter change
Ben Gamari [Mon, 15 Jan 2018 18:01:59 +0000 (13:01 -0500)] 
Fix regression on i386 due to get/setAllocationCounter change

Reviewers: simonmar, erikd

Subscribers: rwbarton, thomie, carter

Differential Revision:

18 months agoSupport constructor Haddocks in more places
Alec Theriault [Fri, 12 Jan 2018 21:45:48 +0000 (16:45 -0500)] 
Support constructor Haddocks in more places

This adds support for adding Haddocks on individual non-record fields
of regular (and GADT) constructors. The following now parses just fine
with `-haddock` enabled:

data Foo
  = Baz             -- ^ doc on the `Baz` constructor
      Int           -- ^ doc on the `Int` field of `Baz`
      String        -- ^ doc on the `String` field of `Baz`

  | Int             -- ^ doc on the `Int` field of the `:*` constructor
      :*            -- ^ doc on the `:*` constructor
    String          -- ^ doc on the `String` field of the `:*`

  | Boa             -- ^ doc on the `Boa` record constructor
      { y :: () }

The change is backwards compatible: if there is only one doc and it
on the last field, it is lifted to apply to the whole constructor (as

Reviewers: bgamari, alanz

Subscribers: rwbarton, thomie, mpickering, carter

Differential Revision:

18 months agoFix mistaken merge
Ben Gamari [Fri, 12 Jan 2018 20:03:11 +0000 (15:03 -0500)] 
Fix mistaken merge

When merging D4259 I had to resort to manual merge due to some conflicts that
arc couldn't sort out. Unfortunately in the process I merged the wrong version
of the patch. Fix this. Thanks to @ntc2 for the great documentation and noticing
my mistake.

18 months agoKQueue: Fix write notification requests being ignored...
Matthias Treydte [Mon, 8 Jan 2018 15:33:37 +0000 (10:33 -0500)] 
KQueue: Fix write notification requests being ignored...

when read notifications are requested, too (#13903)

Signed-off-by: Matthias Treydte <>
KQueue: Drop Bits/FiniteBits instances for Filter as they are really
constants whose bits should not be fiddled with

Signed-off-by: Matthias Treydte <>
Reviewers: austin, hvr, bgamari

Reviewed By: bgamari

Subscribers: gridaphobe, kazu_yamamoto, rwbarton, thomie

GHC Trac Issues: #13903

Differential Revision:

18 months agoFix previous patch
Simon Peyton Jones [Wed, 10 Jan 2018 16:46:55 +0000 (16:46 +0000)] 
Fix previous patch

This recent patch
    commit 1577908f2a9db0fcf6f749d40dd75481015f5497
    Author: Simon Peyton Jones <>
    Date:   Tue Jan 9 16:20:46 2018 +0000

        Fix two more bugs in partial signatures

        These were shown up by Trac #14643

failed validation for typecheck/should_run/T10846
(Reported in Trac #14658.)

The fix is simple.

18 months agoLift constructor tag allocation out of a loop
Bartosz Nitka [Fri, 5 Jan 2018 15:20:05 +0000 (15:20 +0000)] 
Lift constructor tag allocation out of a loop

Before this change, for each constructor that we want
to allocate a tag for we would traverse a list of all
the constructors in a datatype to determine which tag
a constructor should get.

This is obviously quadratic and for datatypes with 10k
constructors it actually makes a big difference.

This change implements the plan outlined by @simonpj in
which is basically about using a map and constructing it outside the

One place where things got a bit awkward was TysWiredIn.hs,
it would have been possible to just assign the tags by hand, but
that seemed error-prone to me, so I decided to go through a map
there as well.

Test Plan:
On a file with 10k constructors
   8,130,522,344 bytes allocated in the heap
  Total   time    3.682s  (  3.920s elapsed)
   4,133,478,744 bytes allocated in the heap
  Total   time    2.509s  (  2.750s elapsed)

Reviewers: simonpj, bgamari

Reviewed By: simonpj

Subscribers: goldfire, rwbarton, thomie, simonmar, carter, simonpj

GHC Trac Issues: #14657

Differential Revision:

18 months agoFix two more bugs in partial signatures
Simon Peyton Jones [Tue, 9 Jan 2018 16:20:46 +0000 (16:20 +0000)] 
Fix two more bugs in partial signatures

These were shown up by Trac #14643

Bug 1: if we had a single partial signature for
two functions
   f, g :: forall a. _ -> a
then we made two different SigTvs but with the sane Name.
This was jolly confusing and ultimately led to deeply bogus
results with Any's appearing in the resulting program. Yikes.
Fix: clone the quantified variables in TcSigs.tcInstSig (as
indeed its name suggests).

Bug 2: we were not eliminating duplicate/superclass constraints
in the partial signatures of a mutually recursive group.

Easy to fix: we are already doing dup/superclass elim in
TcSimplify.decideQuantification.  So we move the partial-sig
constraints there too.

18 months agoSmall local refactoring
Simon Peyton Jones [Tue, 9 Jan 2018 16:18:37 +0000 (16:18 +0000)] 
Small local refactoring

18 months agopreInlineUnconditionally is ok for INLINEABLE
Simon Peyton Jones [Tue, 9 Jan 2018 16:11:44 +0000 (16:11 +0000)] 
preInlineUnconditionally is ok for INLINEABLE

When debugging Trac #14650, I found a place where we had

    let {-# INLINEABLE f #-}
        f = BIG
    in f 7

but 'f' wasn't getting inlined at its unique call site.
There's a good reason for that with INLINE things, which
should only inline when saturated, but not  for INILNEABLE

This patch narrows the case where preInlineUnconditionally
gives up.  It significantly shortens (and improves) the code
for #14650.

18 months agoFix join-point decision
Simon Peyton Jones [Tue, 9 Jan 2018 13:53:09 +0000 (13:53 +0000)] 
Fix join-point decision

This patch moves the "ok_unfolding" test
   from  CoreOpt.joinPointBinding_maybe
   to    OccurAnal.decideJoinPointHood

Previously the occurrence analyser was deciding to make
something a join point, but the simplifier was reversing
that decision, which made the decision about /other/ bindings

Fixes Trac #14650.

18 months agoRemove a bogus warning
Simon Peyton Jones [Tue, 9 Jan 2018 13:51:40 +0000 (13:51 +0000)] 
Remove a bogus warning

The new comment explains why this warning can
legitimately fire, so I've removed it entirely.
Lint will cath any bad cases.

18 months agoExport typeNat{Div;Mod;Log}TyCon from TcTypeNats
Christiaan Baaij [Mon, 8 Jan 2018 17:26:54 +0000 (12:26 -0500)] 
Export typeNat{Div;Mod;Log}TyCon from TcTypeNats

Summary: To be in line with the other typeNatTyCons

Reviewers: bgamari, RyanGlScott

Reviewed By: RyanGlScott

Subscribers: RyanGlScott, rwbarton, thomie, carter

GHC Trac Issues: #14632

Differential Revision:

18 months agoImprove accuracy of get/setAllocationCounter
Simon Marlow [Fri, 5 Jan 2018 16:12:49 +0000 (16:12 +0000)] 
Improve accuracy of get/setAllocationCounter

get/setAllocationCounter didn't take into account allocations in the
current block. This was known at the time, but it turns out to be
important to have more accuracy when using these in a fine-grained

Test Plan:
New unit test to test incrementally larger allocaitons.  Before I got
results like this:


Notice how the results aren't always monotonically increasing.  After
this patch:


Reviewers: niteria, bgamari, hvr, erikd

Subscribers: rwbarton, thomie, carter

Differential Revision:

18 months agoMake the Div and Mod type families `infixl 7`
Ryan Scott [Sun, 7 Jan 2018 18:05:13 +0000 (13:05 -0500)] 
Make the Div and Mod type families `infixl 7`

Commit fa8035e3ee83aff5a20fc5e7e2697bac1686d6a6 added `Div`
and `Mod` type families to `GHC.TypeNats`. However, they did not add
the corresponding fixities! Currently, we have that both `div` and
`mod` (at the value level) are `infixl 7`, so we should adopt the
same fixities for the type-level `Div` and `Mod` as well.

Test Plan: It compiles

Reviewers: hvr, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14640

Differential Revision:

18 months agoFix another obscure pattern-synonym crash
Simon Peyton Jones [Fri, 5 Jan 2018 09:12:49 +0000 (09:12 +0000)] 
Fix another obscure pattern-synonym crash

This one, discovered by Iceland Jack (Trac #14507), shows
that a pattern-bound coercion can show up in the argument
type(s) of the matcher of a pattern synonym.

The error message isn't great, but at least we now rightly
reject the program.

18 months agoImprove pretty-printing for pattern synonyms
Simon Peyton Jones [Fri, 5 Jan 2018 09:11:32 +0000 (09:11 +0000)] 
Improve pretty-printing for pattern synonyms

Just better layout in output for the user

18 months agoFix deep, dark corner of pattern synonyms
Simon Peyton Jones [Thu, 4 Jan 2018 17:18:15 +0000 (17:18 +0000)] 
Fix deep, dark corner of pattern synonyms

Trac #14552 showed a very obscure case where we can't infer a
good pattern-synonym type.

The error message is horrible, but at least we no longer crash
and burn.

18 months agocomments only
Simon Peyton Jones [Thu, 4 Jan 2018 16:14:56 +0000 (16:14 +0000)] 
comments only

18 months agoStop double-stacktrace in ASSERT failures
Simon Peyton Jones [Thu, 4 Jan 2018 16:12:39 +0000 (16:12 +0000)] 
Stop double-stacktrace in ASSERT failures

We were getting the stack trace printed twice in assertion
failures (e.g. see the Description of Trac #14552).

This fixes it, by deleting code.

(c.f. Trac #14635 which reports the same bug in documentation).

18 months agoDrop dead Given bindings in setImplicationStatus
Simon Peyton Jones [Thu, 4 Jan 2018 12:32:13 +0000 (12:32 +0000)] 
Drop dead Given bindings in setImplicationStatus

Trac #13032 pointed out that we sometimes generate unused
bindings for Givens, and (worse still) we can't always discard
them later (we don't drop a case binding unless we can prove
that the scrutinee is non-bottom.

It looks as if this may be a major reason for the performace
problems in #14338 (see comment:29).

This patch fixes the problem at source, by pruning away all the
dead Givens.  See Note [Delete dead Given evidence bindings]

Remarkably, compiler allocation falls by 23% in

I have not confirmed whether this change actualy helps with

18 months agoCache the number of data cons in DataTyCon and SumTyCon
Bartosz Nitka [Tue, 26 Dec 2017 12:54:27 +0000 (12:54 +0000)] 
Cache the number of data cons in DataTyCon and SumTyCon

This is a follow-up after faf60e85 - Make tagForCon non-linear.
On the mailing list @simonpj suggested to solve the
linear behavior by caching the sizes.

Test Plan: ./validate

Reviewers: simonpj, simonmar, bgamari, austin

Reviewed By: simonpj

Subscribers: carter, goldfire, rwbarton, thomie, simonpj

Differential Revision:

18 months agoMake typeToLHsType produce kind signatures for tycon applications
Ryan Scott [Thu, 4 Jan 2018 01:11:31 +0000 (20:11 -0500)] 
Make typeToLHsType produce kind signatures for tycon applications

`GeneralizedNewtypeDeriving` generates calls to `coerce`
which take visible type arguments. These types must be produced by
way of `typeToLHsType`, which converts a `Type` to an `LHsType`.
However, `typeToLHsType` was leaving off important kind information
when a `Type` contained a poly-kinded tycon application, leading to
incorrectly generated code in #14579.

This fixes the issue by tweaking `typeToLHsType` to generate
explicit kind signatures for tycon applications. This makes the
generated code noisier, but at least the program from #14579 now
works correctly.

Test Plan: make test TEST=T14579

Reviewers: simonpj, bgamari

Reviewed By: simonpj

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14579

Differential Revision:

18 months agoTypos in comments
Gabor Greif [Wed, 3 Jan 2018 15:58:36 +0000 (16:58 +0100)] 
Typos in comments

18 months agoNo deferred type errors under a forall
Simon Peyton Jones [Wed, 3 Jan 2018 10:51:18 +0000 (10:51 +0000)] 
No deferred type errors under a forall

As Trac #14605 showed, we can't defer a type error under a
'forall' (when unifying two forall types).

The fix is simple.

18 months agoGet evaluated-ness right in the back end
Simon Peyton Jones [Wed, 3 Jan 2018 10:48:26 +0000 (10:48 +0000)] 
Get evaluated-ness right in the back end

See Trac #14626, comment:4.  We want to maintain evaluted-ness
info on Ids into the code generateor for two reasons
(see Note [Preserve evaluated-ness in CorePrep] in CorePrep)

- DataToTag magic
- Potentially using it in the codegen (this is Gabor's
  current work)

But it was all being done very inconsistently, and actually
outright wrong -- the DataToTag magic hasn't been working for

This patch tidies it all up, with Notes to match.

18 months agoFix OptCoercion
Simon Peyton Jones [Tue, 2 Jan 2018 17:25:58 +0000 (17:25 +0000)] 
Fix OptCoercion

In the presence of -fdefer-type-errors, OptCoercion can
encounter a mal-formed coerercion with type
    T a ~ T a b
and that was causing a subsequent Lint error.

This caused Trac #14607.  Easily fixed by turning an ASSERT
into a guard.

18 months agoWhite space only
Simon Peyton Jones [Tue, 2 Jan 2018 17:13:31 +0000 (17:13 +0000)] 
White space only

18 months agoSmall refactoring in Coercion
Simon Peyton Jones [Tue, 2 Jan 2018 17:11:55 +0000 (17:11 +0000)] 
Small refactoring in Coercion

* Kill unused mkHomoPhantomCo
* Refactor downgradeRole_maybe to be more perspicuous
* Don't export toPhantomCo (not used externally)

18 months agoTiny refactor around fillInferResult
Simon Peyton Jones [Tue, 2 Jan 2018 17:10:40 +0000 (17:10 +0000)] 
Tiny refactor around fillInferResult

...arising from Richard's fix to Trac #14618

18 months agoComments about join point types
Simon Peyton Jones [Tue, 2 Jan 2018 17:08:16 +0000 (17:08 +0000)] 
Comments about join point types

...provked by #14620

18 months agoMore informative pretty-printing for phantom coercions
Simon Peyton Jones [Tue, 2 Jan 2018 17:07:33 +0000 (17:07 +0000)] 
More informative pretty-printing for phantom coercions

18 months agoComments only
Simon Peyton Jones [Fri, 22 Dec 2017 17:49:41 +0000 (17:49 +0000)] 
Comments only

18 months agoRename HEq_sc and Coercible_sc to heq_sel and coercible_sel
Matthew Pickering [Tue, 2 Jan 2018 21:29:00 +0000 (16:29 -0500)] 
Rename HEq_sc and Coercible_sc to heq_sel and coercible_sel

These functions are record selectors.

To the unfamiliar, when inspecting core, they looked like data
constructors as they started with an upper case letter. We rename them
so that it is more clear that firstly they are functions and secondly
that they are selectors.

Reviewers: bgamari, simonpj

Reviewed By: simonpj

Subscribers: simonpj, rwbarton, thomie, carter

Differential Revision:

18 months agoFix #14608 by restoring an unboxed tuple check
Ryan Scott [Tue, 2 Jan 2018 21:03:08 +0000 (16:03 -0500)] 
Fix #14608 by restoring an unboxed tuple check

Commit 714bebff44076061d0a719c4eda2cfd213b7ac3d removed
a check in the bytecode compiler that caught illegal uses of unboxed
tuples (and now sums) in case alternatives, which causes the program
in #14608 to panic. This restores the check (using modern,
levity-polymorphic vocabulary).

Test Plan: make test TEST=T14608

Reviewers: hvr, bgamari, dfeuer, simonpj

Reviewed By: dfeuer, simonpj

Subscribers: simonpj, rwbarton, thomie, carter

GHC Trac Issues: #14608

Differential Revision:

18 months agoMake System.IO.openTempFile thread-safe on Windows
Tamar Christina [Tue, 2 Jan 2018 21:02:49 +0000 (16:02 -0500)] 
Make System.IO.openTempFile thread-safe on Windows

This calls out to the Win32 API `GetTempFileName` to generate
a temporary file. Using `uUnique = 0` guarantees that the file
we get back is unique and the file is "reserved" by creating it.

Test Plan:

I can't think of any sensible tests that shouldn't run for a while
to verify. So the example in #10731 was ran for a while and no
collisions in new code

Reviewers: hvr, bgamari, erikd

Reviewed By: bgamari

Subscribers: RyanGlScott, rwbarton, thomie, carter

GHC Trac Issues: #10731

Differential Revision:

18 months agoWindows: fix all failing tests.
Tamar Christina [Tue, 2 Jan 2018 21:00:57 +0000 (16:00 -0500)] 
Windows: fix all failing tests.

This makes the testsuite pass clean on Windows again.
It also fixes the `libstdc++-6.dll` error harbormaster
was showing.

I'm marking some tests as isolated tests to reduce their
flakiness (mostly concurrency tests) when the test system
is under heavy load.

Updates process submodule.

Test Plan: ./validate

Reviewers: hvr, bgamari, erikd, simonmar

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

Differential Revision:

18 months agoImprove Control.Monad docs
Nathan Collins [Sun, 10 Dec 2017 02:59:05 +0000 (18:59 -0800)] 
Improve Control.Monad docs

* Reformat Control.Monad.mfilter docs

The formatting was bad, with everything running together, and a
paranthesis was missing. Now the examples and relation between
`filter` and `mfilter` are typeset as code blocks instead of inline.

* Add example to Control.Monad.join docs

The example is using `join . atomically` to run IO actions computed by
STM transactions.

I couldn't figure out how to link to the STM docs in
`Control.Monad.STM`, because that module comes from the `stm` package,
not from `base`, even though `stm` is also part of the GHC source
tree. So, instead I linked to the STM docs in `GHC.Conc`, which seems
inferior to linking to `Control.Monad.STM`, but better than having no
links at all.

* Add example to Control.Monad.forever docs

The example is a simple TCP echo server. To make the uses of `forever`
stand out in the example code, I only link to the non-`forever`
functions (e.g. `forkFinally`) in the import lists.

Reviewers: bgamari, hvr

Subscribers: rwbarton, thomie, carter

Differential Revision:

18 months agoAdd example to Control.Monad.join docs
Nathan Collins [Sun, 10 Dec 2017 02:58:03 +0000 (18:58 -0800)] 
Add example to Control.Monad.join docs

The example is using `join . atomically` to run IO actions computed by
STM transactions.

I couldn't figure out how to link to the STM docs in
`Control.Monad.STM`, because that module comes from the `stm` package,
not from `base`, even though `stm` is also part of the GHC source
tree. So, instead I linked to the STM docs in `GHC.Conc`, which seems
inferior to linking to `Control.Monad.STM`, but better than having no
links at all.

18 months agoReformat Control.Monad.mfilter docs
Nathan Collins [Tue, 5 Dec 2017 08:09:23 +0000 (00:09 -0800)] 
Reformat Control.Monad.mfilter docs

The formatting was bad, with everything running together, and a
paranthesis was missing. Now the examples and relation between
`filter` and `mfilter` are typeset as code blocks instead of inline.

18 months agoPrevent "C--" translating to "C–" in the User's Guide.
Steven Shaw [Mon, 18 Dec 2017 21:35:44 +0000 (07:35 +1000)] 
Prevent "C--" translating to "C–" in the User's Guide.

i.e. escape "--" so that it doesn't translate to an "en dash".

18 months agoFix sign error in kelvinToC.
Galen Huntington [Mon, 1 Jan 2018 07:43:15 +0000 (23:43 -0800)] 
Fix sign error in kelvinToC.

18 months agousers-guide: Fix markup
Ben Gamari [Sat, 23 Dec 2017 16:23:40 +0000 (11:23 -0500)] 
users-guide: Fix markup

18 months agoRewrite Note [The polymorphism rule of join points]
Joachim Breitner [Tue, 2 Jan 2018 16:33:47 +0000 (17:33 +0100)] 
Rewrite Note [The polymorphism rule of join points]

I found the reference to CPS unhelpful, but Simon gave me a good
explanation in #14610 that I believe is going to be more enlightening
for future readers.

Differential Revision:

18 months agoTypos in comments [ci skip]
Gabor Greif [Wed, 27 Dec 2017 22:31:21 +0000 (23:31 +0100)] 
Typos in comments [ci skip]

18 months agoFix #14618 by applying a subst in deeplyInstantiate
Richard Eisenberg [Tue, 26 Dec 2017 19:23:40 +0000 (14:23 -0500)] 
Fix #14618 by applying a subst in deeplyInstantiate

Previously, we were inexplicably not applying an instantiating
substitution to arguments in non-prenex types. It's amazing this
has been around for so long! I guess there aren't a lot of non-prenex
types around.

test case: typecheck/should_fail/T14618

18 months agoCompute InScopeSet in substInteractiveContext
Bartosz Nitka [Tue, 26 Dec 2017 12:28:39 +0000 (12:28 +0000)] 
Compute InScopeSet in substInteractiveContext

It doesn't look like we keep any sets of free variables
of the types of Ids handy, so we just have to build them
when doing a substitution.

Test Plan: buildbot + run testsuite with debug

Reviewers: simonmar, simonpj, austin, bgamari

Reviewed By: simonpj

Subscribers: carter, rwbarton, thomie

GHC Trac Issues: #11371

Differential Revision:

18 months agoaclocal.m4: add minimal support for nios2 architecture
Sergei Trofimovich [Mon, 25 Dec 2017 15:46:06 +0000 (15:46 +0000)] 
aclocal.m4: add minimal support for nios2 architecture

With this change unregisterised port can already produce minimal
    ELF 32-bit LSB executable, Altera Nios II, version 1 (SYSV),
    dynamically linked, interpreter /lib/

Signed-off-by: Sergei Trofimovich <>
18 months agoAdd GHC 8.6.1 release notes
Tamar Christina [Sat, 23 Dec 2017 09:06:30 +0000 (09:06 +0000)] 
Add GHC 8.6.1 release notes

18 months agoBump Cabal submodule
Ben Gamari [Thu, 21 Dec 2017 20:04:05 +0000 (15:04 -0500)] 
Bump Cabal submodule

18 months agorelnotes: Fix typo in pattern synonym example
Ben Gamari [Thu, 21 Dec 2017 03:59:28 +0000 (22:59 -0500)] 
relnotes: Fix typo in pattern synonym example

18 months agoMkIface: Ensure syntactic compatibility with ghc 8.0.1
Ben Gamari [Mon, 18 Dec 2017 22:16:22 +0000 (17:16 -0500)] 
MkIface: Ensure syntactic compatibility with ghc 8.0.1

Prior to 8.0.2 MultiWayIf syntax required that the -> token be indented relative
to the guard.

18 months agoSync `ghc-prim` changelog from GHC 8.2
Herbert Valerio Riedel [Thu, 21 Dec 2017 23:04:19 +0000 (00:04 +0100)] 
Sync `ghc-prim` changelog from GHC 8.2

(cherry picked from commit 4d99a665986f66f403ad49f7d91a1fc069870274)

18 months agoComments only [skip ci]
Richard Eisenberg [Thu, 21 Dec 2017 18:38:35 +0000 (13:38 -0500)] 
Comments only [skip ci]

This fixes a typo and elaborates the Note [TyVarBndrs ...]
in TyCoRep, which was previously subtly wrong about
Required ForAllTys.

18 months agoTypos in comments
Gabor Greif [Thu, 21 Dec 2017 17:36:21 +0000 (18:36 +0100)] 
Typos in comments