18 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:

18 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:

18 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:

19 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:

19 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:

19 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:

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

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

19 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:

19 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:

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

19 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:

19 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:

19 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:

19 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:

19 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:

19 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:

19 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:

19 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:

19 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:

19 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:

19 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:

19 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:

19 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:

19 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:

19 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:

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

19 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:

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

19 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:

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

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

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

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

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

19 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:

19 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:

19 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:

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

19 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

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

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

19 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).

19 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

19 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:

19 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:

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

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

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

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

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

19 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)

19 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

19 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

19 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

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

19 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:

19 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:

19 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:

19 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:

19 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:

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

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

19 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".

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

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

19 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:

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

19 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

19 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:

19 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 <>
19 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

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

19 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

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

19 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)

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

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

19 months agoFix floating of equalities
Simon Peyton Jones [Thu, 21 Dec 2017 14:13:54 +0000 (14:13 +0000)] 
Fix floating of equalities

This rather subtle patch fixes Trac #14584.  The problem was
that we'd allowed a coercion, bound in a nested scope, to escape
into an outer scope.

The main changes are

* TcSimplify.floatEqualities takes more care when floating
  equalities to make sure we don't float one out that mentions
  a locally-bound coercion.
  See Note [What prevents a constraint from floating]

* TcSimplify.emitResidualConstraints (which emits the residual
  constraints in simplifyInfer) now avoids burying the constraints
  for escaping CoVars inside the implication constraint.

* Since I had do to this stuff with CoVars, I moved the
  fancy footwork about not quantifying over CoVars from
  TcMType.quantifyTyVars to its caller
  TcSimplify.decideQuantifiedTyVars.  I think its other
  callers don't need to worry about all this CoVar stuff.

This turned out to be surprisigly tricky, and took me a solid
day to get right.  I think the result is reasonably neat, though,
and well documented with Notes.

19 months agoRefactor coercion holes
Simon Peyton Jones [Thu, 21 Dec 2017 13:31:13 +0000 (13:31 +0000)] 
Refactor coercion holes

In fixing Trac #14584 I found that it would be /much/ more
convenient if a "hole" in a coercion (much like a unification
variable in a type) acutally had a CoVar associated with it
rather than just a Unique.  Then I can ask what the free variables
of a coercion is, and get a set of CoVars including those
as-yet-un-filled in holes.

Once that is done, it makes no sense to stuff coercion holes
inside UnivCo.  They were there before so we could know the
kind and role of a "hole" coercion, but once there is a CoVar
we can get that info from the CoVar.  So I removed HoleProv
from UnivCoProvenance and added HoleCo to Coercion.

In summary:

* Add HoleCo to Coercion and remove HoleProv from UnivCoProvanance

* Similarly in IfaceCoercion

* Make CoercionHole have a CoVar in it, not a Unique

* Make tyCoVarsOfCo return the free coercion-hole variables
  as well as the ordinary free CoVars.  Similarly, remember
  to zonk the CoVar in a CoercionHole

We could go further, and remove CoercionHole as a distinct type
altogther, just collapsing it into HoleCo.  But I have not done
that yet.

19 months agoCheck for bogus quantified tyvars in partial type sigs
Simon Peyton Jones [Wed, 20 Dec 2017 15:41:02 +0000 (15:41 +0000)] 
Check for bogus quantified tyvars in partial type sigs

This fixes Trac #14479.  Not difficult.

See Note [Quantification and partial signatures] Wrinkle 4,
in TcSimplify.

19 months agoSimplify HsPatSynDetails
Simon Peyton Jones [Wed, 20 Dec 2017 15:36:49 +0000 (15:36 +0000)] 
Simplify HsPatSynDetails

This is a pure refactoring.  Use HsConDetails to implement
HsPatSynDetails, instead of defining a whole new data type.
Less code, fewer types, all good.

19 months agoImprove treatment of sectioned holes
Ryan Scott [Thu, 21 Dec 2017 00:25:53 +0000 (19:25 -0500)] 
Improve treatment of sectioned holes

Previously, GHC was pretty-printing left-section holes
incorrectly and not parsing right-sectioned holes at all. This patch
fixes both problems.

Test Plan: make test TEST=T14590

Reviewers: bgamari, simonpj

Reviewed By: simonpj

Subscribers: simonpj, rwbarton, thomie, mpickering, carter

GHC Trac Issues: #14590

Differential Revision:

19 months agoDocument ScopedTypeVariables' interaction with nested foralls
Ryan Scott [Thu, 21 Dec 2017 00:25:44 +0000 (19:25 -0500)] 
Document ScopedTypeVariables' interaction with nested foralls

This documents the status quo with regards to how
`ScopedTypeVariables` brings into scope type variables that are
quantified by nested `forall`s (that is to say, it doesn't). This
takes the prose in
and enshrines it into the users' guide.

Test Plan: Read it

Reviewers: simonpj, bgamari

Reviewed By: simonpj

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14288

Differential Revision:

19 months agoRemove hack put in place for #12512
Ryan Scott [Thu, 21 Dec 2017 00:25:37 +0000 (19:25 -0500)] 
Remove hack put in place for #12512

Previously, I added an ad hoc check for unboxed tuples and
sums in standalone-derived instances to fix #12512, under the
pretense that polymorphism over `UnboxedTupleRep` and
`UnboxedSumRep` was a lie. But that is no longer the case, and so
this ad hoc check can be removed entirely. Less code, and easier to

Test Plan: make test TEST=T12512

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

Differential Revision:

19 months agoFix #14588 by checking for more bang patterns
Ryan Scott [Thu, 21 Dec 2017 00:25:30 +0000 (19:25 -0500)] 
Fix #14588 by checking for more bang patterns

Commit 372995364c52eef15066132d7d1ea8b6760034e6
inadvertently removed a check in the parser which rejected
let-bindings with bang patterns, leading to #14588. This fixes it by
creating a `hintBangPat` function to perform this check, and
sprinkling it in the right places.

Test Plan: make test TEST=T14588

Reviewers: bgamari, alanz, simonpj

Reviewed By: bgamari, simonpj

Subscribers: rwbarton, thomie, mpickering, carter

GHC Trac Issues: #14588

Differential Revision:

19 months agoFix #14578 by checking isCompoundHsType in more places
Ryan Scott [Thu, 21 Dec 2017 00:25:18 +0000 (19:25 -0500)] 
Fix #14578 by checking isCompoundHsType in more places

The `HsType` pretty-printer does not automatically insert
parentheses where necessary for type applications, so a function
`isCompoundHsType` was created in D4056 towards this purpose.
However, it was not used in as many places as it ought to be,
resulting in #14578.

Test Plan: make test TEST=T14578

Reviewers: alanz, bgamari, simonpj

Reviewed By: alanz, simonpj

Subscribers: simonpj, rwbarton, thomie, carter

GHC Trac Issues: #14578

Differential Revision:

19 months agoSync up ghc-prim changelog from GHC 8.2 branch
Herbert Valerio Riedel [Wed, 20 Dec 2017 07:10:59 +0000 (08:10 +0100)] 
Sync up ghc-prim changelog from GHC 8.2 branch

[skip ci]

(cherry picked from commit 005656776be8a447785627d549ee393dad468ff6)

19 months agoRmove a call to mkStatePrimTy
Simon Peyton Jones [Tue, 19 Dec 2017 10:37:13 +0000 (10:37 +0000)] 
Rmove a call to mkStatePrimTy

This is a tiny refactoring that removes one of the calls
to mkStatePrimTy, in service to Trac #14596

19 months agoStop runRW# being magic
Simon Peyton Jones [Tue, 19 Dec 2017 10:35:27 +0000 (10:35 +0000)] 
Stop runRW# being magic

Triggered by thinking about Trac #14596, I found that runRW#
does not need to be a "magic" wired-in Id, now that we have
levity polymorphism.

This patch stops it being wired-in.

19 months agoGet rid of some stuttering in comments and docs
Gabor Greif [Tue, 19 Dec 2017 12:52:06 +0000 (13:52 +0100)] 
Get rid of some stuttering in comments and docs

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

20 months agotestsuite: Semigroup/Monoid compat for T3001-2
Ben Gamari [Thu, 14 Dec 2017 22:26:43 +0000 (17:26 -0500)] 
testsuite: Semigroup/Monoid compat for T3001-2

20 months agotestsuite: Exit with non-zero exit code when tests fail
Ben Gamari [Thu, 14 Dec 2017 22:08:36 +0000 (17:08 -0500)] 
testsuite: Exit with non-zero exit code when tests fail

20 months agoBlackholes can be large objects (#14497)
Simon Marlow [Mon, 18 Dec 2017 16:23:16 +0000 (11:23 -0500)] 
Blackholes can be large objects (#14497)

Test Plan: validate

Reviewers: bgamari, niteria, erikd, dfeuer

Reviewed By: dfeuer

Subscribers: Yuras, dfeuer, rwbarton, thomie, carter

GHC Trac Issues: #14497

Differential Revision:

20 months agoFix scoping of pattern-synonym existentials
Simon Peyton Jones [Mon, 18 Dec 2017 12:03:33 +0000 (12:03 +0000)] 
Fix scoping of pattern-synonym existentials

This patch fixes Trac #14998, where we eventually decided that
the existential type variables of the signature of a pattern
synonym should not scope over the pattern synonym.

See Note [Pattern synonym existentials do not scope] in TcPatSyn.

20 months agoTiny refactor: use mkTyVarNamePairs
Simon Peyton Jones [Mon, 18 Dec 2017 12:01:58 +0000 (12:01 +0000)] 
Tiny refactor: use mkTyVarNamePairs

20 months agoAdd missing case to HsExpr.isMonadFailStmtContext
Simon Peyton Jones [Mon, 18 Dec 2017 11:55:16 +0000 (11:55 +0000)] 
Add missing case to HsExpr.isMonadFailStmtContext

This fixes Trac #14591

I took the opportunity to delete the dead code isMonadCompExpr

20 months agoAdd some commentary re: fix to #11203
Richard Eisenberg [Fri, 15 Dec 2017 19:27:47 +0000 (14:27 -0500)] 
Add some commentary re: fix to #11203

The fix for #11203 prohibits duplicate SigTvs in non-CUSK kind
signatures by checking for duplicates after type inference is
done. This works well. GHC also checks for duplicate SigTvs
after working with partial type signatures (another place where
SigTvs arise). However, neither fix eliminates this whole class
of problems (because doing so would be heavier than we would
like). So, this comment adds a warning to users of newSigTyVar
to be aware of problems with duplicates.

20 months agoFix tcDataKindSig
Simon Peyton Jones [Fri, 15 Dec 2017 09:29:12 +0000 (09:29 +0000)] 
Fix tcDataKindSig

This patch fixes an outright bug in tcDataKindSig, shown up in Trac
of a data type declaration.  See Note [TyConBinders for the result kind
signature of a data type]

I also took the opportunity to elminate the DataKindCheck argument
and data type from tcDataKindSig, instead moving the check to the
call site, which is easier to understand.