3 years agoTag pointers in interpreted constructors
mniip [Tue, 30 Aug 2016 20:57:47 +0000 (16:57 -0400)] 
Tag pointers in interpreted constructors

Instead of stg_interp_constr_entry there are now 7 functions (one for
each value of the tag bits) that tag the constructor pointer before
returning. This is consistent with compiled constructors' entry code,
and expectations that compiled code places on compiled constructors. The
iserv protocol is extended with an extra field that explains what
pointer tag the constructor should use.

Test Plan: Added tests for #12523

Reviewers: erikd, bgamari, hvr, austin, simonmar

Reviewed By: simonmar

Subscribers: osa1, thomie, rwbarton

Differential Revision:

GHC Trac Issues: #12523

(cherry picked from commit a25bf2673d0f6db5f454619ddf91f974cace4e8b)

3 years agousers_guide: Move -fdefer-out-of-scope-variables note to 8.0.2 relnotes
Ben Gamari [Wed, 31 Aug 2016 21:14:42 +0000 (17:14 -0400)] 
users_guide: Move -fdefer-out-of-scope-variables note to 8.0.2 relnotes

It will be included in 8.0.2

(cherry picked from commit 3cbb60b59e2bb0e2f8985a672b96bac74ca47c5d)

3 years agousers_guide: A few miscellaneous notes in relnotes
Ben Gamari [Wed, 31 Aug 2016 21:15:37 +0000 (17:15 -0400)] 
users_guide: A few miscellaneous notes in relnotes

3 years agousers_guide: Document removal of -Wredundant-constraints from -Wall
Ben Gamari [Wed, 31 Aug 2016 20:42:53 +0000 (16:42 -0400)] 
users_guide: Document removal of -Wredundant-constraints from -Wall

(cherry picked from commit 9661f59be99dcb0767739d6734e66babdc2bfe16)

3 years agoRemove redundant-constraints from -Wall (#10635)
Adam C. Foltzer [Wed, 31 Aug 2016 20:02:53 +0000 (16:02 -0400)] 
Remove redundant-constraints from -Wall (#10635)

Removes -Wredundant-constraints from -Wall, as per the
discussion in #10635.

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #10635

(cherry picked from commit e9b0bf4ed52114852dbaf6af556514610a895f88)

3 years agoAdd -fdefer-out-of-scope-variables flag (#12170).
Eugene Akentyev [Wed, 31 Aug 2016 20:02:10 +0000 (16:02 -0400)] 
Add -fdefer-out-of-scope-variables flag (#12170).

Reviewers: simonpj, thomie, austin, bgamari

Reviewed By: simonpj, thomie, bgamari

Subscribers: simonpj, thomie

Differential Revision:

GHC Trac Issues: #12170

(cherry picked from commit 75321ffa25ad377fa200485a7d58ad32a87e7d65)

3 years agoDocs: fix links to ghc-flags
Thomas Miedema [Thu, 9 Jun 2016 11:26:35 +0000 (13:26 +0200)] 
Docs: fix links to ghc-flags

(cherry picked from commit e703a232174fd6e6cc42f2b27a2d9a2a17957aa7)

3 years agoPPC NCG: Implement minimal stack frame header.
Peter Trommler [Wed, 31 Aug 2016 19:18:06 +0000 (15:18 -0400)] 
PPC NCG: Implement minimal stack frame header.

According to the ABI specifications a minimal stack frame consists
of a header and a minimum size parameter save area. We reserve the
minimal size for each ABI.

On PowerPC 64-bil Linux and AIX the parameter save area can accomodate
up to eight parameters. So calls with eight parameters and fewer
can be done without allocating a new stack frame and deallocating
that stack frame after the call. On AIX one additional spill slot
is available on the stack.

Code size for all nofib benchmarks is 0.3 % smaller on powerpc64.

Test Plan: validate on AIX

Reviewers: hvr!, erikd, austin, simonmar, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision:

(cherry picked from commit 010b07aae082cb6b1f2a5db3deecc5997f6d9a6d)

3 years agouser_guide: Move addModFinalizer mention to 8.0.2 release notes
Ben Gamari [Wed, 31 Aug 2016 21:03:46 +0000 (17:03 -0400)] 
user_guide: Move addModFinalizer mention to 8.0.2 release notes

(cherry picked from commit 4e1e7f2b2b3e352bd772339480b67f7c02ba9061)

3 years agoHsExpr: Ensure Type is derived on ThModFinalizers
Ben Gamari [Wed, 31 Aug 2016 19:26:16 +0000 (15:26 -0400)] 
HsExpr: Ensure Type is derived on ThModFinalizers

This is necessary to bootstrap with GHC 7.8.

3 years agoFixes #12504: Double-escape paths used to build call to hsc_line
Richard Cook [Tue, 30 Aug 2016 21:00:36 +0000 (17:00 -0400)] 
Fixes #12504: Double-escape paths used to build call to hsc_line

In outHsLine, paths passed to construct invocations of hsc_line must be
escaped twice in order to generate a properly escaped string literal
that will end up in the eventual LINE pragma emitted by this code. This
is especially important on Windows paths, where backslashes would
otherwise be treated as C escape sequences and result in the incorrect
Windows paths.

Adds test case to verify that hsc2hs properly escapes file paths in LINE

Updates the hsc2hs submodule.


Reviewers: erikd, hvr, austin, bgamari, Phyx

Reviewed By: erikd, Phyx

Subscribers: thomie, Phyx, mpickering

Differential Revision:

GHC Trac Issues: #12504

(cherry picked from commit 2ee1db60ab29258fa9f8ab820f778bd0bb7f87a4)

3 years agoFix aggressive cleanup of T1407
Tamar Christina [Sun, 1 May 2016 15:25:48 +0000 (17:25 +0200)] 
Fix aggressive cleanup of T1407

The aggressive cleanup routine of T1407 is removing files that don't belong to it.
Constrain the test to only removing files it should by putting all it's generated
binaries in it's own output folder.

Test Plan: make test -C testsuite/tests/ghci/linking/dyn

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie, #ghc_windows_task_force

Differential Revision:

GHC Trac Issues: #1407

(cherry picked from commit e6627d1f8964807f19f8773f09cfaacae7ca8ab8)

3 years agoFix Windows build after Ticky changes
Tamar Christina [Sat, 21 May 2016 09:31:58 +0000 (11:31 +0200)] 
Fix Windows build after Ticky changes

Replace hardcoded ld with FMT_Int for
StgInt types.

Test Plan: ./validate

Reviewers: austin, bgamari, simonmar, erikd

Reviewed By: erikd

Subscribers: thomie, #ghc_windows_task_force

Differential Revision:

(cherry picked from commit ae7e9cb574801954c7769c210829b06193fa72ea)

3 years agoErrUtils: Expose accessors of ErrDoc and ErrMsg
Ben Gamari [Wed, 31 Aug 2016 17:50:30 +0000 (13:50 -0400)] 
ErrUtils: Expose accessors of ErrDoc and ErrMsg

Test Plan: Validate

Reviewers: austin

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #12206

(cherry picked from commit 2d220263f6e5f49139f5571b7a5bc1649cb9ac8c)

3 years agoDisable T12031 on linux
Tamar Christina [Sun, 12 Jun 2016 12:41:18 +0000 (14:41 +0200)] 
Disable T12031 on linux

(cherry picked from commit 29e1464319f40fe30fd63d8648f0d0a05541abe0)

3 years agoFix failures of T12031
Ben Gamari [Wed, 31 Aug 2016 18:12:06 +0000 (14:12 -0400)] 
Fix failures of T12031

TEST_HC_OPTS_INTERACTIVE was not defined due to an inconsistent
cherry-pick. In master this was done in
bdc555885b8898684549eca70053c9ce0ec7fa39 but I opted to simply extract
the relevant definition from this commit in the interest of simplicity.

3 years agoClarify scope of `getQ`/`putQ` state.
Francesco Mazzoli [Tue, 30 Aug 2016 21:09:16 +0000 (17:09 -0400)] 
Clarify scope of `getQ`/`putQ` state.

The current haddocks do not specify the scope of the state manipulated
by `getQ`/`putQ`.

Reviewers: austin, goldfire, bgamari, ezyang

Reviewed By: ezyang

Subscribers: ezyang, thomie

Differential Revision:

(cherry picked from commit d1f22396eec4be0a2101de6b7f7b780792acc0a9)

3 years agoStgCmmPrim: Add missing MO_WriteBarrier
Ben Gamari [Tue, 30 Aug 2016 21:08:05 +0000 (17:08 -0400)] 
StgCmmPrim: Add missing MO_WriteBarrier

Test Plan: Good question

Reviewers: austin, trommler, simonmar, rrnewton

Reviewed By: simonmar

Subscribers: RyanGlScott, thomie

Differential Revision:

GHC Trac Issues: #12469

(cherry picked from commit d40d6df74a9fca382a84709ac9bc862897fbec18)

3 years agoiserv: Show usage message on argument parse failure
Ben Gamari [Tue, 30 Aug 2016 21:06:08 +0000 (17:06 -0400)] 
iserv: Show usage message on argument parse failure

Test Plan: validate

Reviewers: simonmar, erikd, austin

Reviewed By: simonmar, erikd

Subscribers: thomie, erikd

Differential Revision:

GHC Trac Issues: #12491

(cherry picked from commit 3005fa5313b6d5fd9d4f47192c84e96e94ee7f17)

3 years agousers_guide: More capabilities than processors considered harmful
Ben Gamari [Tue, 30 Aug 2016 21:05:25 +0000 (17:05 -0400)] 
users_guide: More capabilities than processors considered harmful

Test Plan: None.

Reviewers: austin, simonmar

Reviewed By: simonmar

Subscribers: thomie

Differential Revision:

(cherry picked from commit 28b71c55d057b780d92b351498ec611287dedbd4)

3 years agoFix handling of package-db entries in .ghc.environment files, etc.
Duncan Coutts [Tue, 30 Aug 2016 20:59:17 +0000 (16:59 -0400)] 
Fix handling of package-db entries in .ghc.environment files, etc.

Previously interpreting the content of the .ghc.env files was done
after the step that loaded the available package dbs. This meant that
setting the package db flags was ineffective. This patch moves
interpreting the env files before loading of the package dbs.

Also, the package-db entries refer to files. Allow spaces in these file
names. Also treat as comments lines beginning with "--".

These are pretty minor fixes in a feature that up 'til now has been
essentially unused (witness no bug report about it), so there's very
low risk here. If we can get this into 8.0.2 then cabal can start
generating the .ghc.environment files, otherwise it cannot as it needs
the working package-db entries, to be able to refer to local package
dbs in the build tree (or cabal nix store).

Test Plan:
Manually create example .ghc.env files
run ghci; :show packages
Done this. It works.

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision:

(cherry picked from commit ef784c551ef9b64c3c0b32c73f54bbdb747a8188)

3 years agousers_guide: Add 8.0.2 release notes
Ben Gamari [Wed, 31 Aug 2016 20:42:53 +0000 (16:42 -0400)] 
users_guide: Add 8.0.2 release notes

3 years agoMissing stderr for T12531.
Edward Z. Yang [Tue, 30 Aug 2016 09:43:38 +0000 (02:43 -0700)] 
Missing stderr for T12531.

Signed-off-by: Edward Z. Yang <>
(cherry picked from commit 21c2ebf2504125611eec0d24ab3ed60cd9e475be)

3 years agoFix T12177
Ben Gamari [Tue, 30 Aug 2016 18:48:49 +0000 (14:48 -0400)] 
Fix T12177

3 years agoHave addModFinalizer expose the local type environment.
Facundo Domínguez [Wed, 6 Jul 2016 09:48:27 +0000 (06:48 -0300)] 
Have addModFinalizer expose the local type environment.

This annotates the splice point with 'HsSpliced ref e' where 'e' is the
result of the splice. 'ref' is a reference that the typechecker will fill with
the local type environment.

The finalizer then reads the ref and uses the local type environment, which
causes 'reify' to find local variables when run in the finalizer.

Test Plan: ./validate

Reviewers: simonpj, simonmar, bgamari, austin, goldfire

Reviewed By: goldfire

Subscribers: simonmar, thomie, mboes

Differential Revision:

GHC Trac Issues: #11832

(cherry picked from commit 567dbd9bcb602accf3184b83050f2982cbb7758b)

3 years agoTestsuite: for tests that use TH, omit *all* prof_ways
Thomas Miedema [Mon, 22 Feb 2016 17:55:30 +0000 (18:55 +0100)] 
Testsuite: for tests that use TH, omit *all* prof_ways

Instead of just profasm and profthreaded. And at least until
-fexternal-interpreter is the default.

  * WAY=profc doesn't exist anymore.
  * Omit all threaded_ways for conc039, not just a few.

(cherry picked from commit e02b8c8dadcc77c0c40d5346246f6a3b548258c2)

3 years agopass -z wxneeded or -Wl,-zwxneeded for linking on OpenBSD
Karel Gardas [Sat, 13 Aug 2016 16:49:53 +0000 (18:49 +0200)] 
pass -z wxneeded or -Wl,-zwxneeded for linking on OpenBSD

This patch fixes issue with abort in GHCi on OpenBSD current
as of Aug 12 2016. The OpenBSD is more and more strict about usage
of writable and executable memory. Programs/applications which
requires such functionality need to be linked with -z wxneeded linker
flag and need to be run from the file-system mounted with wxallowed
mount option. If either of those options in not met, then problematic
program/application usually fail on some mmap/mprotect call which fail.

Reviewers: bgamari, austin, hvr

Subscribers: thomie, erikd

Differential Revision:

(cherry picked from commit f9aa996f0af59f32dc7b1528ff78be41413a9c27)

3 years agoAllow typed holes to be levity-polymorphic
Simon Peyton Jones [Fri, 26 Aug 2016 16:24:10 +0000 (17:24 +0100)] 
Allow typed holes to be levity-polymorphic

This one-line change fixes Trac #12531.  Hooray.

Simple, non-invasive; can merge to 8.0.2

(cherry picked from commit ae66f356fb0dbf79dab1074d71275904c448b329)

3 years agoRtClosureInspect: Fix off-by-one error in cvReconstructType
mniip [Tue, 23 Aug 2016 17:19:02 +0000 (13:19 -0400)] 
RtClosureInspect: Fix off-by-one error in cvReconstructType

Replaced error-prone index manipulation on a pointer array with
a simple fold on the array elements.

Test Plan: Added a test case that triggers the bug

Reviewers: hvr, austin, bgamari

Reviewed By: bgamari

Subscribers: simonpj, thomie

Differential Revision:

GHC Trac Issues: #12458

(cherry picked from commit 1766bb3cfd1460796c78bd5651f89d53603586f9)

3 years agoRelevant Bindings no longer reports shadowed bindings (fixes #12176)
Annie Cherkaev [Mon, 1 Aug 2016 06:30:42 +0000 (23:30 -0700)] 
Relevant Bindings no longer reports shadowed bindings (fixes #12176)

Summary: Modified the RelevantBindings method in TcErrors.hs to only search over
non-shadowed bindings.

Test Plan: Wrote 2 simple test cases, verified that it worked with multiple
shadowed bindings, and also non-shadowed bindings.

Reviewers: austin, bgamari, ezyang

Reviewed By: ezyang

Subscribers: ezyang, thomie

Differential Revision:

GHC Trac Issues: #12177

(cherry picked from commit 89ae1e858f6eed42cebd9af01b30e239d4543faf)

3 years agoFix a performance issue with -fprint-expanded-synonyms
Ömer Sinan Ağacan [Sun, 15 May 2016 11:04:39 +0000 (07:04 -0400)] 
Fix a performance issue with -fprint-expanded-synonyms

The type synonym expander was doing redundant work by looking at same
types again and again. This patch fixes the loop code when both of the
types can be expanded, to do `O(min(n, m))` comparisons and `O(n + m)`
expansions, where `n` is expansions of the first type and `m` is
expansions of the second type.

Reported by sjcjoosten in T10547.

Test Plan:
Added a regression test that was taking several minutes to type check
before this patch.

Reviewers: bgamari, simonpj, austin, ezyang

Reviewed By: bgamari, simonpj, austin, ezyang

Subscribers: simonpj, thomie

Differential Revision:

GHC Trac Issues: #10547

(cherry picked from commit e4834edf4418ace657361649365979e29ebd9daa)

3 years agorts/LdvProfile.c: Fix NULL dereference on shutdown
Erik de Castro Lopo [Thu, 28 Apr 2016 21:15:53 +0000 (07:15 +1000)] 
rts/LdvProfile.c: Fix NULL dereference on shutdown

Test Plan: validate

Reviewers: carter, austin, simonmar, bgamari

Reviewed By: simonmar, bgamari

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #11978

(cherry picked from commit bcfee2181e7b7edfea3473ec408a3a2a1815ecff)

3 years agoMake okConIdOcc recognize unboxed tuples
Ryan Scott [Mon, 18 Jul 2016 17:51:53 +0000 (13:51 -0400)] 
Make okConIdOcc recognize unboxed tuples

`okConIdOcc`, which validates that a type or constructor name is valid
for splicing using Template Haskell, has a special case for tuples, but
neglects to look for unboxed tuples, causing some sensible Template Haskell
code involving unboxed tuples to be rejected.

Fixes #12407.

Test Plan: make test TEST=T12407

Reviewers: austin, bgamari, hvr, goldfire

Reviewed By: goldfire

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #12407

(cherry picked from commit 1fc41d3274b5bf62f027aa6c7df57998db494938)

3 years agoFix incorrect calculated relocations on Windows x86_64
Tamar Christina [Sat, 11 Jun 2016 08:18:19 +0000 (10:18 +0200)] 
Fix incorrect calculated relocations on Windows x86_64

See #12031 for analysis, but essentially what happens is:

To sum up the issue, the reason this seems to go wrong is because
of how we initialize the `.bss` section for Windows in the runtime linker.

The first issue is where we calculate the zero space for the section:

zspace = stgCallocBytes(1, bss_sz, "ocGetNames_PEi386(anonymous bss)");
sectab_i->PointerToRawData = ((UChar*)zspace) - ((UChar*)(oc->image));

UInt32 PointerToRawData;

This means we're stuffing a `64-bit` value into a `32-bit` one. Also `zspace`
can be larger than `oc->image`. In which case it'll overflow and
then get truncated in the cast.

The address of a value in the `.bss` section is then calculated as:

addr = ((UChar*)(oc->image))
     + (sectabent->PointerToRawData
     + symtab_i->Value);

If it does truncate then this calculation won't be correct (which is what is happening).

We then later use the value of `addr` as the `S` (Symbol) value for the relocations

S = (size_t) lookupSymbol_( (char*)symbol );

Now the majority of the relocations are `R_X86_64_PC32` etc.
e.g. They are guaranteed to fit in a `32-bit` value.

The `R_X86_64_64` introduced for these pseudo-relocations so they can use
the full `48-bit` addressing space isn't as lucky.
As for why it sometimes work has to do on whether the value is truncated or not.

`PointerToRawData` can't be changed because it's size is fixed by the PE specification.

Instead just like with the other platforms, we now use `section` on Windows as well.
This gives us a `start` parameter of type `void*` which solves the issue.

This refactors the code to use `section.start` and to fix the issues.

Test Plan: ./validate and new test added T12031

Reviewers: RyanGlScott, erikd, bgamari, austin, simonmar

Reviewed By: simonmar

Subscribers: thomie, #ghc_windows_task_force

Differential Revision:

GHC Trac Issues: #12031, #11317

(cherry picked from commit b40e1b4c6746bdc34e6a53548a3925d309201c4d)

3 years agoDo not init record accessors as exported
Ömer Sinan Ağacan [Fri, 27 May 2016 15:02:47 +0000 (11:02 -0400)] 
Do not init record accessors as exported

This was causing redundant code generation when accessors are not
actually exported, as they were being marked as "exported" at

Test Plan: validate

Reviewers: simonpj, austin, bgamari

Reviewed By: simonpj

Subscribers: mpickering, thomie

Differential Revision:

(cherry picked from commit 3a00ff92a3ee66c096b85b180d247d1a471a6b6e)

3 years agoExpand given superclasses more eagerly
Simon Peyton Jones [Wed, 22 Jun 2016 13:17:58 +0000 (14:17 +0100)] 
Expand given superclasses more eagerly

This patch fixes Trac #12175, another delicate corner case of
Note [Instance and Given overlap] in TcInteract.

In #12175 we were not expanding given superclasses eagerly
enough. It was easy to fix, and is actually rather neater than

See Note [Eagerly expand given superclasses] in TcCanonical.
The main change is to move the eager expansion of given superclasses
to canClassNC.

(cherry picked from commit ce97b7298d54bdfccd9dcf366a69c5617b4eb43f)

3 years agoKeep the bindings local during defaultCallStacks
Simon Peyton Jones [Wed, 17 Aug 2016 13:35:19 +0000 (14:35 +0100)] 
Keep the bindings local during defaultCallStacks

defaultCallStacks generates evidence bindings for call stacks,
but wasn't setting the binding site correctly.  As a result
they were simply discarded in the case of pattern synonyms,
giving rise to Trac #12489.

The fix is easy; and I added an ASSERT to catch the error earlier.

(cherry picked from commit f352e5cd7bb629fe0ca3b913bfbe7bee43d62f3a)

3 years agoNot-in-scope variables are always errors
Simon Peyton Jones [Wed, 17 Aug 2016 11:04:30 +0000 (12:04 +0100)] 
Not-in-scope variables are always errors

This fixes Trac #12406.  A not-in-scope error shoudl be an error
even if you have -fdefer-typed-holes.

(cherry picked from commit efc0372a157eadeee58bbada77c64d53590e04af)

3 years agoImprove missing-sig warning
Simon Peyton Jones [Fri, 12 Aug 2016 14:52:07 +0000 (15:52 +0100)] 
Improve missing-sig warning

Fixes Trac #12484

(cherry picked from commit ac0e11252af149f085e2262200b7a1638b4a1553)

3 years agocheck that the number of parallel build is greater than 0
Ruey-Lin Hsu [Thu, 4 Aug 2016 11:41:57 +0000 (13:41 +0200)] 
check that the number of parallel build is greater than 0

Fixes #12062.

Reviewers: bgamari, thomie, austin, simonmar

Reviewed By: bgamari, thomie, simonmar

Subscribers: simonmar, thomie

Differential Revision:

GHC Trac Issues: #12062

(cherry picked from commit f09d65474ed042360999cb88221d65b07bfb4b5f)

3 years agoAnother try to get thread migration right
Simon Marlow [Thu, 4 Aug 2016 14:59:43 +0000 (15:59 +0100)] 
Another try to get thread migration right

This is surprisingly tricky.  There were linked list bugs in the
previous version (D2430) that showed up as a test failure in
setnumcapabilities001 (that's a great stress test!).

This new version uses a different strategy that doesn't suffer from
the problem that @ezyang pointed out in D2430.  We now pre-calculate
how many threads to keep for this capability, and then migrate any
surplus threads off the front of the queue, taking care to account for
threads that can't be migrated.

Test Plan:
1. setnumcapabilities001 stress test with sanity checking (+RTS -DS) turned on:

cd testsuite/tests/concurrent/should_run
make TEST=setnumcapabilities001 WAY=threaded1 EXTRA_HC_OPTS=-with-rtsopts=-DS CLEANUP=0
while true; do ./ 4 9 2000 || break; done

2. The test case from #12419

Reviewers: niteria, ezyang, rwbarton, austin, bgamari, erikd

Subscribers: thomie, ezyang

Differential Revision:

GHC Trac Issues: #12419

(cherry picked from commit 89fa4e968f47cfb42d0dc33fc3bfffdce31d850e)

3 years agoFix to thread migration
Simon Marlow [Wed, 27 Jul 2016 15:00:08 +0000 (16:00 +0100)] 
Fix to thread migration

If we had 2 threads on the run queue, say [A,B], and B is bound to the
current Task, then we would fail to migrate any threads.  This fixes it
so that we would migrate A in that case.

This will help parallelism a bit in programs that have lots of bound

Test Plan:
Test program in #12419, which is actually not a great program but it
does behave a bit better after this change.

Reviewers: ezyang, niteria, bgamari, austin, erikd

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #12419

(cherry picked from commit 988ad8ba8e709eff3cea59728e481bb269fa6185)

3 years agoTrack the lengths of the thread queues
Simon Marlow [Tue, 2 Aug 2016 08:55:31 +0000 (09:55 +0100)] 
Track the lengths of the thread queues

Knowing the length of the run queue in O(1) time is useful: for example
we don't have to traverse the run queue to know how many threads we have
to migrate in schedulePushWork().

Test Plan: validate

Reviewers: ezyang, erikd, bgamari, austin

Subscribers: thomie

Differential Revision:

(cherry picked from commit 55f5aed756cd5d464942dddcb33e0bd19b05f2a4)

3 years agoMove stat_startGCSync
Bartosz Nitka [Wed, 27 Jul 2016 15:25:59 +0000 (08:25 -0700)] 
Move stat_startGCSync

@simonmar told me that it makes more sense this way.

Test Plan: it still builds

Reviewers: bgamari, austin, simonmar, erikd

Reviewed By: simonmar, erikd

Subscribers: thomie, simonmar

Differential Revision:

(cherry picked from commit e98edbd1b8947dcb4a47d20fc854c0a9a6954bea)

3 years agoFix double-free in T5644 (#12208)
Simon Marlow [Mon, 20 Jun 2016 12:33:13 +0000 (13:33 +0100)] 
Fix double-free in T5644 (#12208)

(cherry picked from commit e7e42c838e32ef1e05daf04b0b6afb62ffc4ec97)

3 years agoFix ASSERT failure and re-enable setnumcapabilities001
Simon Marlow [Wed, 11 May 2016 14:38:25 +0000 (15:38 +0100)] 
Fix ASSERT failure and re-enable setnumcapabilities001

The assertion failure was fairly benign, I think, but this fixes it.
I've been running the test repeatedly for the last 30 mins and it hasn't

There are other problems exposed by this test (see #12038), but I've
worked around those in the test itself for now.

I also copied the relevant bits of the parallel library here so that we
don't need parallel for the test to run.

(cherry picked from commit cfc5df43a7789832a2789e517d8270650cc31b7f)

3 years agoFix a crash in requestSync()
Simon Marlow [Tue, 10 May 2016 10:22:57 +0000 (03:22 -0700)] 
Fix a crash in requestSync()

It was possible for a thread to read invalid memory after a conflict
when multiple threads were synchronising.

I haven't been successful in constructing a test case that triggers
this, but we have some internal code that ran into it.

(cherry picked from commit ea3d1efb863ca83b28af9056576d47f1abf98fa9)

3 years agoschedulePushWork: avoid unnecessary wakeups
Simon Marlow [Sun, 24 Apr 2016 20:31:55 +0000 (21:31 +0100)] 
schedulePushWork: avoid unnecessary wakeups

This function had some pathalogically bad behaviour: if we had 2 threads
on the current capability and 23 other idle capabilities, we would

* grab all 23 capabilities
* migrate one Haskell thread to one of them
* wake up a worker on *all* 23 other capabilities.

This lead to a lot of unnecessary wakeups when using large -N values.

Now, we

* Count how many capabilities we need to wake up
* Start from cap->no+1, so that we don't overload low-numbered capabilities
* Only wake up capabilities that we migrated a thread to (unless we have
  sparks to steal)

This results in a pretty dramatic improvement in our production system.

(cherry picked from commit 1fa92ca9b1ed4cf44e2745830c9e9ccc2bee12d5)

3 years agoAllow limiting the number of GC threads (+RTS -qn<n>)
Simon Marlow [Sat, 9 Apr 2016 19:45:50 +0000 (20:45 +0100)] 
Allow limiting the number of GC threads (+RTS -qn<n>)

This allows the GC to use fewer threads than the number of capabilities.
At each GC, we choose some of the capabilities to be "idle", which means
that the thread running on that capability (if any) will sleep for the
duration of the GC, and the other threads will do its work.  We choose
capabilities that are already idle (if any) to be the idle capabilities.

The idea is that this helps in the following situation:

* We want to use a large -N value so as to make use of hyperthreaded
* We use a large heap size, so GC is infrequent
* But we don't want to use all -N threads in the GC, because that
  thrashes the memory too much.

See docs for usage.

(cherry picked from commit 76ee260778991367b8dbf07ecf7afd31f826c824)

3 years agoRevert "Fix Template Haskell reification of unboxed tuple types"
Ben Gamari [Thu, 25 Aug 2016 15:09:31 +0000 (11:09 -0400)] 
Revert "Fix Template Haskell reification of unboxed tuple types"

This reverts commit 3470f82fbd7039f9957761c5a12988fd558d6cb8 which we
decided not to merge afterall. See #12403.

3 years agotestsuite: Remove spurious change from last commit
Ben Gamari [Thu, 25 Aug 2016 15:08:12 +0000 (11:08 -0400)] 
testsuite: Remove spurious change from last commit

3 years agotestsuite: Update performance numbers
Ben Gamari [Thu, 25 Aug 2016 15:02:58 +0000 (11:02 -0400)] 
testsuite: Update performance numbers

3 years agoFix productivity calculation (#12424)
Simon Marlow [Tue, 26 Jul 2016 14:55:37 +0000 (07:55 -0700)] 
Fix productivity calculation (#12424)

(cherry picked from commit 1783011726a355ac7647246699d43bc7d8b6d9f1)

3 years agoUpdate docs for partial type signatures (#12365)
Thomas Winant [Wed, 20 Jul 2016 07:57:04 +0000 (09:57 +0200)] 
Update docs for partial type signatures (#12365)

* Update the sample error messages. The messages have been reworded and
  reformatted since GHC 7.10.

* Mention `TypeApplications` in "Where can they occur?"

* The name of a named wild card is no longer used in the name of a
  resulting type variable. Before: `_foo` => `w_foo`, now: `_foo` => `t`
  or `a`.

Test Plan: generate the users guide

Reviewers: goldfire, austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #12365

(cherry picked from commit 627c767b8e5587de52086d8891d7f7aabf6fa49f)

3 years agoImprove documentation for type wildcards
Simon Peyton Jones [Wed, 18 May 2016 16:13:29 +0000 (17:13 +0100)] 
Improve documentation for type wildcards

This docmentation improvement was triggered by Trac #12072

(cherry picked from commit f9e90bcb202b164189d71535eafbb39577682ff2)

3 years agoFix bytecode generator panic
Seraphime Kirkovski [Wed, 20 Jul 2016 07:47:23 +0000 (09:47 +0200)] 
Fix bytecode generator panic

This fixes #12128.

The bug was introduced in 1c9fd3f1c5522372fcaf250c805b959e8090a62c.

Test Plan: ./validate

Reviewers: simonmar, austin, hvr, simonpj, bgamari

Reviewed By: bgamari

Subscribers: simonpj, thomie

Differential Revision:

GHC Trac Issues: #12128

(cherry picked from commit 8de6e13f9ef784750e502955fcb38d4a7e179727)

3 years agoFix Template Haskell reification of unboxed tuple types
Ryan Scott [Mon, 18 Jul 2016 13:29:05 +0000 (09:29 -0400)] 
Fix Template Haskell reification of unboxed tuple types

Previously, Template Haskell reified unboxed tuple types as boxed
tuples with twice the appropriate arity.

Fixes #12403.

Test Plan: make test TEST=T12403

Reviewers: hvr, goldfire, austin, bgamari

Reviewed By: goldfire

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #12403

(cherry picked from commit 514c4a4741f3881672f1ccc1fe6d08a5d596bb87)

3 years agoMake DeriveFunctor work with unboxed tuples
Ryan Scott [Mon, 18 Jul 2016 13:28:42 +0000 (09:28 -0400)] 
Make DeriveFunctor work with unboxed tuples

Unboxed tuples have `RuntimeRep` arguments which `-XDeriveFunctor` was
mistaking for actual data constructor arguments. As a result, a derived
`Functor` instance for a datatype that contained an unboxed tuple would
generate twice as many arguments as it needed for an unboxed tuple pattern
match or expression. The solution is to simply put `dropRuntimeRepArgs` in the
right place.

Fixes #12399.

Test Plan: ./validate

Reviewers: austin, hvr, bgamari

Reviewed By: bgamari

Subscribers: thomie, osa1

Differential Revision:

GHC Trac Issues: #12399

(cherry picked from commit 3fa3fe8a9a8afa67829e12efa5d25b76e58a185a)

3 years agoPretty: remove a harmful $! (#12227)
Thomas Miedema [Sat, 16 Jul 2016 22:13:45 +0000 (00:13 +0200)] 
Pretty: remove a harmful $! (#12227)

This is backport of [1] for GHC's copy of Pretty. See Note [Differences
between libraries/pretty and compiler/utils/Pretty.hs].


Reviewers: bgamari, austin

Reviewed By: austin

Differential Revision:

GHC Trac Issues: #12227

(cherry picked from commit 89a8be71a3715c948cebcb19ac81f84da0e6270e)

3 years agoBugfix for bug 11632: `readLitChar` should consume null characters
Ben Gamari [Sat, 16 Jul 2016 22:12:52 +0000 (00:12 +0200)] 
Bugfix for bug 11632: `readLitChar` should consume null characters

Test Plan: The tests have been included. This change deals with a
relatively minor edge case and should not break unrelated functionality.

Reviewers: thomie, #core_libraries_committee, ekmett, bgamari

Reviewed By: #core_libraries_committee, ekmett, bgamari

Subscribers: bgamari, ekmett

Differential Revision:

GHC Trac Issues: #11632

(cherry picked from commit 0f0cdb6827803015a9a3924fdafaef8dbcde048f)

3 years agoPretty: delete really old changelog
Thomas Miedema [Mon, 11 Jul 2016 15:59:59 +0000 (17:59 +0200)] 
Pretty: delete really old changelog

This changelog is very incomplete, and basically useless. I'm removing
it, because it made it harder to compare this copy of `Pretty.hs` with
the copy in `libraries/pretty` (from which a similar changelog was
deleted some time ago).

(cherry picked from commit 372dbc4e78abfb6b5d72c0fea27a1c858c5cd797)

3 years agoEnum: Ensure that operations on Word fuse
Ben Gamari [Mon, 4 Jul 2016 12:36:44 +0000 (14:36 +0200)] 
Enum: Ensure that operations on Word fuse

Test Plan: Validate, verify fusion

Reviewers: austin, hvr

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #12354

(cherry picked from commit 0bd7c4b4240a27d4e26290741394b31b48db7671)

3 years agoFix pretty-printer for IfaceCo
Simon Peyton Jones [Wed, 29 Jun 2016 22:21:49 +0000 (23:21 +0100)] 
Fix pretty-printer for IfaceCo

As Trac #12242 showed, there was a missing case in
the pretty printer for IfaceCo. I've refactored it
so that the pattern-match ovelap checker will spot
it next time.

(cherry picked from commit 24194a6aed950ed4c3733e3c582abf8a15d98ffd)

3 years agoDeal correctly with unused imports for 'coerce'
Simon Peyton Jones [Tue, 28 Jun 2016 11:13:13 +0000 (12:13 +0100)] 
Deal correctly with unused imports for 'coerce'

We only do newtype unwrapping for Coercible constraints if
the newtype's data constructor is in scope.  We were trying to
record the fact that the data constructor was thereby 'used', so
that an import statement would not be flagged as unnecsssary
(by -Wunused-imports).

But the code was simply wrong. It was wrong because it assumed
that only one level of unwrapping happened, whereas
tcTopNormaliseNewTypeTF_maybe actually unwraps multiple layers.
So we need to return a /list/ of data constructors that are used.

This entailed a bit of refactoring, as usual.

Fixes Trac #12067

(cherry picked from commit 23b80ac41cc945cea0fc6ff9ade6b4be8aa81b7f)

3 years agoFix #11974 by adding a more smarts to TcDefaults.
Richard Eisenberg [Sat, 23 Apr 2016 02:28:35 +0000 (22:28 -0400)] 
Fix #11974 by adding a more smarts to TcDefaults.

Test cases:

(cherry picked from commit 9a34bf1985035858ece043bf38b47b6ff4b88efb)

3 years agoSecond attempt to fix sizeExpr
Simon Marlow [Fri, 17 Jun 2016 10:21:52 +0000 (11:21 +0100)] 
Second attempt to fix sizeExpr

* sizeExpr was calculating expressions like ((e `cast` T) x) wrongly
* Fixing it caused regressions in compile performance, and one nofib
  program (k-nucleotide)

I managed to fix the source of the compiler regressions.  I think it was
due to traceTc not being inlined, which I fixed in a more robust way by
putting an export list on TcRnMonad.

The k-nucleotide regression is more difficult.  I don't think anything
is actually going wrong, but this program has been highly tuned and is
quite sensitive to changing in inlining behaviour.  I managed to recover
most of the performance by manual lambda-lifting which makes it a bit
less fragile, but the end result was a bit slower.  I don't think this
is disastrous, the program is pretty horrible to begin with and we could
probably make a faster one by starting from scratch.

Test Plan: validate, nofib

Reviewers: simonpj, bgamari, niteria, austin, erikd

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #11564

(cherry picked from commit a47b62cb36853d03c77ef63b3208b3d869fb687e)

3 years agoPPC NCG: Fix and refactor TOC handling.
Peter Trommler [Sat, 18 Jun 2016 10:29:12 +0000 (12:29 +0200)] 
PPC NCG: Fix and refactor TOC handling.

In a call to a fixed function the TOC does not need to be saved.
The linker handles TOC saving.

Refactor TOC handling by folding the two functions toc_before and
toc_after into the code generating the call sequence. This saves
repeating the case distinction in those two functions.

Test Plan: validate on PowerPC 32-bit Linux and AIX

Reviewers: hvr, simonmar, austin, erikd, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision:

(cherry picked from commit f4b0488dba4c97630ed1e4417eef546abd5c3df5)

3 years agoPPC NCG: Fix float parameter passing on 64-bit.
Peter Trommler [Sat, 18 Jun 2016 10:28:41 +0000 (12:28 +0200)] 
PPC NCG: Fix float parameter passing on 64-bit.

On Linux 64-bit PowerPC the first 13 floating point parameters are
passed in registers. We only passed the first 8 floating point params.

The alignment of a floating point single precision value in ELF v1.9 is
the second word of a doubleword. For ELF v2 we support only little
endian and the least significant word of a doubleword is the first word,
so no special handling is required.

Add a regression test.

Test Plan: validate on powerpc Linux and AIX

Reviewers: erikd, hvr, austin, simonmar, bgamari

Reviewed By: simonmar

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #12134

(cherry picked from commit 2897be77123bf31cad1c60dd5560eba7f2f021ce)

3 years agoRefactor derived Generic instances to reduce allocations
Ryan Scott [Sat, 18 Jun 2016 10:23:12 +0000 (12:23 +0200)] 
Refactor derived Generic instances to reduce allocations

Previously, derived implementations of `to`/`from` in `Generic`
instances were wastefully putting extra `M1`s in every case, which led
to an O(n) increase in the number of coercions, resulting in a slowdown
during the typechecker phase.

This factors out the common `M1` in every case of a `to`/`from`
definition so that the typechecker has far fewer coercions to deal with.
For a datatype with 300 constructors, this change has been observed to
save almost 3 seconds of compilation time.

This is one step towards coming up with a solution for #5642.

Test Plan: ./validate

Reviewers: hvr, austin, simonpj, bgamari

Reviewed By: bgamari

Subscribers: basvandijk, carter, thomie, osa1

Differential Revision:

GHC Trac Issues: #5642

(cherry picked from commit 9649fc0ae45e006c2ed54cc5ea2414158949fadb)

3 years agoDon't GC sparks for CAFs
Simon Marlow [Fri, 10 Jun 2016 16:07:13 +0000 (17:07 +0100)] 
Don't GC sparks for CAFs

We can't tell whether the CAF is actually garbage or not.

(cherry picked from commit 23b73c97312e4d812812ed25a6396fff44d1da28)

3 years agoFix #12064 by making IfaceClass typechecking more lazy.
Edward Z. Yang [Sun, 15 May 2016 23:13:51 +0000 (16:13 -0700)] 
Fix #12064 by making IfaceClass typechecking more lazy.

Comes with a test based off of prog006.

Signed-off-by: Edward Z. Yang <>
Test Plan: validate

Reviewers: simonpj, austin, bgamari

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #12064

(cherry picked from commit 8f6d292746217f1fa9f645ff8d191943af1c5771)

3 years agoKill varEnvElts in tcPragExpr
Bartosz Nitka [Wed, 18 May 2016 23:47:29 +0000 (16:47 -0700)] 
Kill varEnvElts in tcPragExpr

I had to refactor some things to take VarSet instead of [Var],
but I think it's more precise this way.

Test Plan: ./validate

Reviewers: simonmar, simonpj, austin, bgamari, goldfire

Reviewed By: simonpj

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #4012

(cherry picked from commit 13e40f998e15a626a4212bde0987ddbc98b3f56f)

3 years agoImprove failed knot-tying error message.
Edward Z. Yang [Mon, 30 May 2016 12:21:36 +0000 (14:21 +0200)] 
Improve failed knot-tying error message.

Test Plan: validate

Reviewers: simonpj, austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision:

(cherry picked from commit f2b3be031075156cf128aba127bdddb84f8b2eb8)

3 years agoAdd relocation type R_X86_64_REX_GOTPCRELX
Tamar Christina [Sun, 5 Jun 2016 07:59:05 +0000 (09:59 +0200)] 
Add relocation type R_X86_64_REX_GOTPCRELX

Adding support for the `R_X86_64_REX_GOTPCRELX` relocation type.
This relocation is treated by the linker the same as the `R_X86_64_GOTPCRELX` type
`G + GOT + A - P` to generate relative offsets to the GOT.
The `REX` prefix has no influence in this stage.

This is based on

Test Plan: ./validate

Reviewers: erikd, austin, bgamari, simonmar

Reviewed By: erikd

Subscribers: thomie, #ghc_windows_task_force

Differential Revision:

GHC Trac Issues: #12147

(cherry picked from commit 0d963caf40da4391028a3beb95b5082c87985e7d)

3 years agoMore fixes for unboxed tuples
Simon Peyton Jones [Fri, 27 May 2016 13:34:45 +0000 (14:34 +0100)] 
More fixes for unboxed tuples

This is a continuation of
   commit e9e61f18a548b70693f4ccd245bc56335c94b498
   Date:   Thu May 26 15:24:53 2016 +0100
   Reduce special-casing for nullary unboxed tuple

which related to Trac #12115.  But typecheck/should_run/tcrun051
revealed that my patch was incomplete.

This fixes it, by removing another special case in Type.repType.
I had also missed a case in UnariseStg.unariseIdBinder.

I took the opportunity to add explanatory notes
  Note [Unarisation]
  Note [Unarisation and nullary tuples]
in UnariseStg

(cherry picked from commit b43a7936ebf77bce744d50a131d686c83f63e60b)

3 years agoReduce special-casing for nullary unboxed tuple
Simon Peyton Jones [Thu, 26 May 2016 14:24:53 +0000 (15:24 +0100)] 
Reduce special-casing for nullary unboxed tuple

When we built the kind of a nullary unboxed tuple, we said, in

    res_rep | arity == 0 = voidRepDataConTy
                  -- See Note [Nullary unboxed tuple] in Type
            | otherwise  = unboxedTupleRepDataConTy

But this is bogus.  The Note deals with what the 'unarise' transformation
does, and up to that point it's simpler and more uniform to treat
nullary unboxed tuples the same as all the others.

Nicer now.  And it fixes the Lint error in Trac #12115

(cherry picked from commit e9e61f18a548b70693f4ccd245bc56335c94b498)

3 years agoTestsuite: also normalise platform-dependent .stdout/stderr
Thomas Miedema [Wed, 25 May 2016 14:03:19 +0000 (16:03 +0200)] 
Testsuite: also normalise platform-dependent .stdout/stderr

This effectively reverses commit
429f0099ab9adfadc779ca76f3aae1c9c160fb8c (2006).

I don't see why platform-dependent .stdout/stderr files should //not//
get normalised.

It fixes T11223_link_order_a_b_2_fail on Windows, by normalising
`ghc-stage2.exe` to `ghc` when comparing stderr with .stderr-mingw32.

Reviewed by: Phyx

Differential Revision:

GHC Trac Issues: #12118

(cherry picked from commit 6a5bce14ffb8b10def150b185fc95d7b2ebab263)

3 years agoTestsuite: check actual_prof_file only when needed
Thomas Miedema [Fri, 26 Feb 2016 10:23:28 +0000 (11:23 +0100)] 
Testsuite: check actual_prof_file only when needed

Might be a little faster. Avoids testing for #6113 (.prof file not
written when process is killed with any signal but SIGINT) for tests
that don't have a .prof.sample file (which is almost all of them) when
running the profiling ways.
Tests that were failing because of #6113: T8089, overflow1, overflow2 and

(cherry picked from commit e3b9dbf48c7b7b1ac4a5d6ecf1411469b5f7666c)

3 years agoBuild system: temp solution for parallelisation bug (#11960)
Thomas Miedema [Sun, 22 May 2016 08:14:44 +0000 (10:14 +0200)] 
Build system: temp solution for parallelisation bug (#11960)

(cherry picked from commit c81e7b2014e284774eecf5e48e42aab31892cec1)

3 years agoFunDep printer: Fix unicode arrow
Ömer Sinan Ağacan [Fri, 20 May 2016 08:39:57 +0000 (04:39 -0400)] 
FunDep printer: Fix unicode arrow

The arrow should be printed in unicode arrow syntax when
-fprint-unicode-syntax is used.

Reviewers: austin, bgamari, thomie

Reviewed By: thomie

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #11825

(cherry picked from commit 08e47ca9849ab986d0367746a003754fcf0d4176)

3 years agoImprove pretty-printing of equalities
Simon Peyton Jones [Mon, 16 May 2016 12:42:22 +0000 (13:42 +0100)] 
Improve pretty-printing of equalities

The previous pretty-printer didn't account for partially
applied equalities, causing Trac #12041

(cherry picked from commit ad7f12260e227e849b815f4959df0f886ecbe807)

3 years agoFix deriveTyData's kind unification when two kind variables are unified
RyanGlScott [Wed, 11 May 2016 13:57:24 +0000 (15:57 +0200)] 
Fix deriveTyData's kind unification when two kind variables are unified

When `deriveTyData` attempts to unify two kind variables (which can
happen if both the typeclass and the datatype are poly-kinded), it
mistakenly adds an extra mapping to its substitution which causes the
unification to fail when applying the substitution. This can be
prevented by checking both the domain and the range of the original
substitution to see which kind variables shouldn't be put into the
domain of the substitution. A more in-depth explanation is included in
`Note [Unification of two kind variables in deriving]`.

Fixes #11837.

Test Plan: ./validate

Reviewers: simonpj, hvr, goldfire, niteria, austin, bgamari

Reviewed By: bgamari

Subscribers: niteria, thomie

Differential Revision:

GHC Trac Issues: #11837

(cherry picked from commit e53f2180e89652c72e51ffa614c56294ba67cf37)

3 years agoFix pretty printing of IEThingWith
Matthew Pickering [Fri, 6 May 2016 16:15:54 +0000 (17:15 +0100)] 
Fix pretty printing of IEThingWith

[skip ci]

(cherry picked from commit 018487e686793e22efd595491be5b5305ed2b9c0)

3 years agoMake validDerivPred ignore non-visible arguments to a class type constructor
RyanGlScott [Mon, 2 May 2016 16:38:04 +0000 (12:38 -0400)] 
Make validDerivPred ignore non-visible arguments to a class type constructor

GHC choked when trying to derive the following:

{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE PolyKinds #-}
module Example where

class Category (cat :: k -> k -> *) where
  catId   :: cat a a
  catComp :: cat b c -> cat a b -> cat a c

newtype T (c :: * -> * -> *) a b = MkT (c a b) deriving Category

Unlike in #8865, where we were deriving `Category` for a concrete type like
`Either`, in the above example we are attempting to derive an instance of the

instance Category * c => Category (T * c) where ...

(using `-fprint-explicit-kinds` syntax). But `validDerivPred` is checking if
`sizePred (Category * c)` equals the number of free type variables in
`Category * c`. But note that `sizePred` counts both type variables //and//
type constructors, and `*` is a type constructor! So `validDerivPred`
erroneously rejects the above instance.

The fix is to make `validDerivPred` ignore non-visible arguments to the class
type constructor (e.g., ignore `*` is `Category * c`) by using

Fixes #11833.

Test Plan: ./validate

Reviewers: goldfire, hvr, simonpj, austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #11833

(cherry picked from commit fa86ac7c14b67f27017d795811265c3a9750024b)

3 years agoTest #11484 in th/T11484
Richard Eisenberg [Tue, 26 Apr 2016 18:07:08 +0000 (14:07 -0400)] 
Test #11484 in th/T11484

(cherry picked from commit 7242582b2fad6e0a734c012da25e66fe6f2ef11a)

3 years agoRemove the incredibly hairy splitTelescopeTvs.
Richard Eisenberg [Tue, 26 Apr 2016 14:50:33 +0000 (10:50 -0400)] 
Remove the incredibly hairy splitTelescopeTvs.

This patch removes splitTelescopeTvs by adding information about
scoped type variables to TcTyCon. Vast simplification!

This also fixes #11821 by bringing only unzonked vars into scope.

Test case: polykinds/T11821

(cherry picked from commit c5919f75afab9dd6f0a4a2670402024cece5da57)

3 years agoAdd Edward Kmett's example as a test case
Simon Peyton Jones [Mon, 1 Feb 2016 13:59:11 +0000 (13:59 +0000)] 
Add Edward Kmett's example as a test case

This is a more stressful example of T11480.

(cherry picked from commit 4e6530122ab458211add07a7167d077eba3eea21)

3 years agoAdd missing solveEqualities
Simon Peyton Jones [Mon, 25 Apr 2016 15:17:34 +0000 (16:17 +0100)] 
Add missing solveEqualities

I'd missed a call to solveEqualities in the partial-type-sig case
of TcBinds.tcUserTypeSig.

Also the checkValidType test done there best done after inference,
in checkInferredPolyId (and is already done there).

Fixes Trac #11976

(cherry picked from commit 4c746cb2886b06ca53a2edb62188827c3dbccce0)

3 years agoDo not use defaulting in ambiguity check
Simon Peyton Jones [Thu, 21 Apr 2016 12:03:29 +0000 (13:03 +0100)] 
Do not use defaulting in ambiguity check

This fixes Trac #11947.  See TcSimplify
Note [No defaulting in the ambiguity check]

(cherry picked from commit edf54d72b5b8a6dd0deafa036dc16dcfc3fcb29f)

3 years agoAdd Windows import library support to the Runtime Linker
Tamar Christina [Sun, 17 Apr 2016 11:03:17 +0000 (13:03 +0200)] 
Add Windows import library support to the Runtime Linker

Import libraries are files ending in `.dll.a` and `.lib` depending on which
compiler creates them (GCC, vs MSVC).

Import Libraries are standard `archive` files that contain object files.
These object files can have two different formats:

1) The normal COFF Object format for object files
    (contains all ascii data and very little program code, so do not
     try to execute.)
2) "short import" format which just contains a symbol name and
   the dll in which the symbol can be found.

Import Libraries are useful for two things:

1) Allowing applications that don't support dynamic linking to
   link against the import lib (non-short format) which then
   makes calls into the DLL by loading it at runtime.

2) Allow linking of mutually recursive dlls. if `A.DLL` requires
   `B.DLL` and vice versa, import libs can be used to break the cycle
   as they can be created from the expected exports of the DLLs.

A side effect of having these two capabilities is that Import libs are often
used to hide specific versions of DLLs behind a non-versioned import lib.

e.g. GCC_S.a (non-conventional import lib) will point to the correct
`libGCC` DLL. With this support Windows Haskell files can now just link
to `-lGCC_S` and not have to worry about what the actual name of libGCC is.

Also third party libraries such as `icuuc` use import libs to forward to
versioned DLLs. e.g. `icuuc.lib` points to `icuuc51.dll` etc.

Test Plan:

Two new tests added T11072gcc T11072msvc

Two binary files have been added to the test folder because the "short"
import library format doesn't seem to be creatable via `dlltool`
and requires Microsoft's `lib.exe`.

Reviewers: bgamari, RyanGlScott, erikd, goldfire, austin, hvr

Reviewed By: RyanGlScott, erikd

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #11072

(cherry picked from commit 97f2b16483aae28dc8fd60b6d2e1e283618f2390)

3 years agoImprove accuracy of suggestion to use TypeApplications
Matthew Pickering [Thu, 25 Feb 2016 14:51:46 +0000 (15:51 +0100)] 
Improve accuracy of suggestion to use TypeApplications

The suggestion only makes sense when we try
to use an as pattern in an expression context.

It is misleading in the case of a lazy pattern and
view pattern.

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision:

(cherry picked from commit e38c07bf5ceb8f50fa5110b70b3b83f0ce1358ba)

3 years agorts/Profiling: Fix C99-ism
Ben Gamari [Sun, 21 Aug 2016 13:30:42 +0000 (09:30 -0400)] 
rts/Profiling: Fix C99-ism

GHC 8.0 isn't C99.

3 years agoWiden deepseq lower bound
Ben Gamari [Tue, 9 Aug 2016 09:46:38 +0000 (11:46 +0200)] 
Widen deepseq lower bound

3 years agoCheck generic-default method for ambiguity
Simon Peyton Jones [Fri, 1 Jul 2016 21:33:33 +0000 (22:33 +0100)] 
Check generic-default method for ambiguity

Fixes Trac #7497 and #12151.   In some earlier upheaval I introduced
a bug in the ambiguity check for genreric-default method.

This patch fixes it.  But in fixing it I realised that the
sourc-location of any such error message was bogus, so I fixed
that too, which involved a slightly wider change; see the
comments with TcMethInfo.

(cherry picked from commit 85aa6ef09346e841abf4e089b24c7f783286cd74)

3 years agoFix #12076 by inlining trivial expressions in CorePrep.
Edward Z. Yang [Tue, 17 May 2016 04:05:24 +0000 (21:05 -0700)] 
Fix #12076 by inlining trivial expressions in CorePrep.

This mostly follows the plan detailed by the discussion
Simon and I had, with one difference: instead of grabbing
the free variables of the trivial expressions to get the
embedded Ids, we just use getIdFromTrivialExpr_maybe to extract
out the Id.  If there is no Id, the expression cannot
refer to a function (as there are no literal functions)
and thus we do not need to saturate.

Signed-off-by: Edward Z. Yang <>
Test Plan: validate

Reviewers: simonpj, austin, bgamari

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #12076

(cherry picked from commit 11ff1df8a7c25485c9c7508d65bcb380e592010d)

3 years agoFailing test case for #12076.
Edward Z. Yang [Tue, 17 May 2016 04:05:24 +0000 (21:05 -0700)] 
Failing test case for #12076.

Signed-off-by: Edward Z. Yang <>
Test Plan: validate

Reviewers: austin, bgamari

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #12076

(cherry picked from commit 5f1557eea2c1a5cf09321d9dc01070b6c068e2fa)

3 years agohp2ps: fix invalid PostScript for names with parentheses
Ben Gamari [Sat, 16 Jul 2016 22:14:04 +0000 (00:14 +0200)] 
hp2ps: fix invalid PostScript for names with parentheses

The names in the .hp files may contain un-matched opening parentheses,
so escape them.

GHC Trac: #9517

Reviewers: bgamari, austin

Reviewed By: bgamari, austin

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #9517

(cherry picked from commit 5df92f6776b31b375a80865e7db1f330d929c18f)

3 years agoUNPACK the size field of SizedSeq
Simon Marlow [Thu, 21 Jul 2016 12:47:47 +0000 (05:47 -0700)] 
UNPACK the size field of SizedSeq

(cherry picked from commit 1fe5c8916a2bdf90ed2d9c70f900642b56650592)

3 years agoSquash space leaks in the result of byteCodeGen
Simon Marlow [Thu, 21 Jul 2016 11:51:05 +0000 (04:51 -0700)] 
Squash space leaks in the result of byteCodeGen

When loading a large number of modules into GHCi, we collect
CompiledByteCode for every module and then link it all at the end.
Space leaks in the CompiledByteCode linger until we traverse it all for
linking, and possibly longer, if there are bits we don't look at.

This is the nuke-it-from-orbit approach: we deepseq the whole thing
after code generation. It's the only way to be sure.

Test Plan:
Heap profile of GHCi while loading nofib/real/anna into GHCi, this patch
reduces the peak heap usage from ~100M to ~50M.

Reviewers: hvr, austin, bgamari, erikd

Subscribers: thomie

Differential Revision:

(cherry picked from commit 648fd73a7b8fbb7955edc83330e2910428e76147)

3 years agoAdd deepseq dependency and a few NFData instances
Simon Marlow [Thu, 21 Jul 2016 11:32:55 +0000 (04:32 -0700)] 
Add deepseq dependency and a few NFData instances

I needed to rnf a data structure (CompiledByteCode) but we don't have
any good deepseq infrastructure in the compiler yet.  There are bits and
pieces, but nothing consistent, so this is a start.

We already had a dependency on deepseq indirectly via other packages
(e.g. containers).

Includes an update to the haddock submodule, to remove orphan NFData
instances in there.

Test Plan: validate

Reviewers: austin, bgamari, erikd, hvr

Subscribers: thomie

Differential Revision:

(cherry picked from commit c4f3d91b6b32a27c2e00506de532e90c595de2d1)