3 years agoTemporarily mark T1969 perf test as broken (#12437)
Ömer Sinan Ağacan [Fri, 5 Aug 2016 15:28:26 +0000 (15:28 +0000)] 
Temporarily mark T1969 perf test as broken (#12437)

3 years agoBump `hoopl` submodule, mostly cosmetics
Gabor Greif [Fri, 5 Aug 2016 10:39:21 +0000 (12:39 +0200)] 
Bump `hoopl` submodule, mostly cosmetics

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

3 years agoFix an assertion that could randomly fail
Simon Marlow [Thu, 4 Aug 2016 14:57:37 +0000 (15:57 +0100)] 
Fix an assertion that could randomly fail

returning_tasks queue, but that requires cap->lock to access safely.
This assertion would randomly fail if stressed enough.

Instead I've removed it from the catch-all
ASSERT_PARTIAL_CAPABILITIY_INVARIANTS and made it a separate assertion
only called under cap->lock.

Test Plan:
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

Reviewers: niteria, bgamari, ezyang, austin, erikd

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #10860

3 years agoExpanded abbreviations in Haddock documentation
Ben Gamari [Thu, 4 Aug 2016 12:36:09 +0000 (14:36 +0200)] 
Expanded abbreviations in Haddock documentation

This adds notes to the Haddock documentation for various core datatypes
expanding abbreviations.

Reviewers: bgamari, thomie

Differential Revision:

GHC Trac Issues: #12405

3 years agocodeGen: Remove binutils<2.17 hack, fixes T11758
Alex Dzyoba [Thu, 4 Aug 2016 11:42:21 +0000 (13:42 +0200)] 
codeGen: Remove binutils<2.17 hack, fixes T11758

There was a complication on the x86_64 platform, where pointers were 64
bits, but the tools didn't support 64-bit relative relocations.  This
was true before binutils 2.17, which nowadays is quite standart (even
CentOs 5 is shipped with 2.17).

Hacks were removed from x86 genSwitch and asm pretty printer. Also
[x86-64-relative] note was dropped from
includes/rts/storage/InfoTables.h as it's not referenced anywhere now.

Reviewers: austin, simonmar, rwbarton, erikd, bgamari

Reviewed By: simonmar, erikd, bgamari

Subscribers: thomie

Differential Revision:

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

3 years agoRemove identity update of field componentsConfigs
Gabor Greif [Fri, 5 Aug 2016 07:52:26 +0000 (09:52 +0200)] 
Remove identity update of field componentsConfigs

... in LocalBuildInfo, getting rid of a TODO in the
process. Turns out that componentsConfigs won't be
a field in Cabal 2.0 any more, so this can be seen
as a preparation for it.

3 years agoTrim all spaces after 'version:'
Gabor Greif [Fri, 5 Aug 2016 07:42:09 +0000 (09:42 +0200)] 
Trim all spaces after 'version:'

... that we grep out of libraries/Cabal/Cabal/Cabal.cabal

This is necessary because the file got reformatted
in the 'master' branch.

3 years agoFix omission in haddock instance head
Gabor Greif [Fri, 5 Aug 2016 07:00:51 +0000 (09:00 +0200)] 
Fix omission in haddock instance head

3 years agoReplace an unsafeCoerce with coerce
Ryan Scott [Thu, 4 Aug 2016 14:25:10 +0000 (10:25 -0400)] 
Replace an unsafeCoerce with coerce

This matches the implementations of `castPtr` and `castFunPtr`.

3 years agoCmmLayoutStack: Minor simplification
Ömer Sinan Ağacan [Thu, 4 Aug 2016 10:10:41 +0000 (10:10 +0000)] 
CmmLayoutStack: Minor simplification

3 years agoCmmLive: Remove some redundant exports
Ömer Sinan Ağacan [Thu, 4 Aug 2016 10:09:56 +0000 (10:09 +0000)] 
CmmLive: Remove some redundant exports

3 years agoClarify comment on makeCorePair
Matthew Pickering [Wed, 3 Aug 2016 16:06:42 +0000 (17:06 +0100)] 
Clarify comment on makeCorePair

3 years agoRemove `setUnfoldingInfoLazily`
Matthew Pickering [Wed, 3 Aug 2016 13:22:21 +0000 (14:22 +0100)] 
Remove `setUnfoldingInfoLazily`

The definition of `setUnfoldingInfoLazily` is exactly the same as
`setUnfoldingInfo` and is only used in one place, `TcIface`.

They were made equivalent in 2010 in
2ff2497dc374175b8ed81446258baf208d1f3e6e with the commit message.

commit 2ff2497dc374175b8ed81446258baf208d1f3e6e
Author: Ian Lynagh <>  Wed Oct 20 15:37:10 2010
Committer:      Ian Lynagh <>  Wed Oct 20 15:37:10 2010
Original File:  compiler/basicTypes/IdInfo.lhs

Don't seq unfoldings
We generate intermediate unfoldings which are just thrown away, so
evaluating them is a waste of time.

Closes #12453

3 years agoTypo in comment [skip ci]
Matthew Pickering [Wed, 3 Aug 2016 13:06:57 +0000 (14:06 +0100)] 
Typo in comment [skip ci]

3 years agoMore comments about InlinePragmas
Matthew Pickering [Wed, 3 Aug 2016 13:04:53 +0000 (14:04 +0100)] 
More comments about InlinePragmas

Just pointers about where to look in the source code.

3 years agoUpdate old comment InlinePragma
Matthew Pickering [Wed, 3 Aug 2016 10:37:05 +0000 (11:37 +0100)] 
Update old comment InlinePragma

3 years agoAdd comment about lexing of INLINE and INLINABLE pragma
Matthew Pickering [Wed, 3 Aug 2016 10:29:26 +0000 (11:29 +0100)] 
Add comment about lexing of INLINE and INLINABLE pragma

3 years agoStgSyn: Remove unused StgLiveVars types
Ömer Sinan Ağacan [Wed, 3 Aug 2016 08:50:31 +0000 (08:50 +0000)] 
StgSyn: Remove unused StgLiveVars types

3 years agoRemove the DEBUG_<blah> variables, use RtsFlags directly
Simon Marlow [Tue, 2 Aug 2016 12:09:32 +0000 (13:09 +0100)] 
Remove the DEBUG_<blah> variables, use RtsFlags directly

3 years agoOnly trace cap/capset events if we're tracing anything else
Simon Marlow [Tue, 2 Aug 2016 08:57:19 +0000 (09:57 +0100)] 
Only trace cap/capset events if we're tracing anything else

I was getting annoyed by cap/capset messages when using +RTS -DS, which
doesn't cause any other trace messages to be emitted.  This makes it
possible to add --with-rtsopts=-DS when running tests, and not have all
the tests fail due to spurious trace messages.

Test Plan: validate

Reviewers: duncan, bgamari, ezyang, austin, erikd

Subscribers: thomie

Differential Revision:

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

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:

3 years agoForeignCall.hs: Remove DrIFT directives
Ömer Sinan Ağacan [Tue, 2 Aug 2016 13:03:32 +0000 (13:03 +0000)] 
ForeignCall.hs: Remove DrIFT directives

3 years agoTypo in comment
Gabor Greif [Mon, 1 Aug 2016 13:25:10 +0000 (15:25 +0200)] 
Typo in comment

3 years agoUse MO_Cmpxchg in Primops.cmm instead of ccall cas(..)
alexbiehl [Mon, 1 Aug 2016 08:46:29 +0000 (18:46 +1000)] 
Use MO_Cmpxchg in Primops.cmm instead of ccall cas(..)

Adjust `CmmParse.y` to parse the `cmpxchg{8, 16, 32, 64}` instructions
and use the 32 respectively the 64 bit variant in `Primops.cmm`. This
effectively eliminates the compare-and-swap ccall to the rts.

Based off the mailing list question from @osa1

Reviewers: simonmar, austin, erikd, bgamari, trommler

Reviewed By: erikd, bgamari, trommler

Subscribers: carter, trommler, osa1, thomie

Differential Revision:

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

3 years agoAdd atomic operations to
alexbiehl [Sat, 30 Jul 2016 07:22:54 +0000 (17:22 +1000)] 
Add atomic operations to

This patch resulted from the discussion in D2431 and should be merged

@erikd and @trommler reported errors like

): In function `c14_info':
(.text+0x2b8): undefined reference to `hs_cmpxchg32'
): In function `c5e_info':
(.text+0xac4): undefined reference to `hs_cmpxchg32'
): In function `c8b_info':
(.text+0x1198): undefined reference to `hs_cmpxchg32'
): In function `c8b_info':
(.text+0x122c): undefined reference to `hs_cmpxchg32'
): In function `c8b_info':
(.text+0x12ec): undefined reference to `hs_cmpxchg32'

on PowerPC. @simonmar suggests to add the specific exports to
`rts/`. This patch does exactly that, including all
other atomic ops as they probably (maybe someone can verify?) suffer
from the same problem on PPC.

Test Plan: Please make sure to build on PPC.

Reviewers: erikd, austin, bgamari, simonmar, trommler

Reviewed By: erikd, trommler

Subscribers: thomie

Differential Revision:

3 years agoMake Unique a newtype
Ömer Sinan Ağacan [Thu, 28 Jul 2016 15:13:54 +0000 (15:13 +0000)] 
Make Unique a newtype

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision:

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:

3 years agoAdd mblocks_allocated to GC stats API
Bartosz Nitka [Wed, 27 Jul 2016 15:24:40 +0000 (08:24 -0700)] 
Add mblocks_allocated to GC stats API

This exposes mblocks_allocated in the GCStats struct.

Test Plan: it builds

Reviewers: bgamari, simonmar, austin, hvr, erikd

Reviewed By: erikd

Subscribers: thomie

Differential Revision:

3 years agoCompute boot-defined TyCon names from ModIface.
Edward Z. Yang [Sun, 3 Jul 2016 01:08:55 +0000 (18:08 -0700)] 
Compute boot-defined TyCon names from ModIface.

Three things in this commit:

    1. Get rid of sb_ids; we are not going to use them
    to avoid infinite unfoldings in hs-boot files.

    2. Compute sb_tcs from ModIface rather than ModDetails.
    This means that the typechecker can look at this field
    without forcing the boot ModDetails, which would be
    bad if the ModDetails is not available yet (due to
    knot tying.)

    3. A big honking comment explaining what is going on

Signed-off-by: Edward Z. Yang <>
Reviewers: simonpj, austin, bgamari

Subscribers: thomie

Differential Revision:

3 years agoAccept better stats for T9675
Simon Marlow [Tue, 26 Jul 2016 15:01:58 +0000 (08:01 -0700)] 
Accept better stats for T9675

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

3 years agoMonadUtils: Typos in comments
Ömer Sinan Ağacan [Tue, 26 Jul 2016 14:47:43 +0000 (14:47 +0000)] 
MonadUtils: Typos in comments

3 years agoSome typos in comments
Gabor Greif [Mon, 25 Jul 2016 22:34:48 +0000 (00:34 +0200)] 
Some typos in comments

3 years agoTestsuite: fix T10482a
Thomas Miedema [Sun, 24 Jul 2016 23:36:20 +0000 (01:36 +0200)] 
Testsuite: fix T10482a

3 years agoFix the non-Linux build
Erik de Castro Lopo [Fri, 22 Jul 2016 12:59:44 +0000 (14:59 +0200)] 
Fix the non-Linux build

The recent Compact Regions commit (cf989ffe49) builds fine on Linux
but doesn't build on OS X r Windows.

* rts/sm/CNF.c: Drop un-needed #includes.
* Fix parenthesis usage with CPP ASSERT macro.
* Fix format string in debugBelch messages.
* Use stg_max() instead hand rolled inline max() function.

Test Plan: Build on Linux, OS X and Windows

Reviewers: gcampax, simonmar, austin, bgamari

Subscribers: thomie

Differential Revision:

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

3 years ago-fprof-auto-top
Simon Marlow [Thu, 21 Jul 2016 11:33:44 +0000 (04:33 -0700)] 

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:

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:

3 years agoStgCmmBind: Some minor simplifications
Ömer Sinan Ağacan [Fri, 22 Jul 2016 09:48:42 +0000 (09:48 +0000)] 
StgCmmBind: Some minor simplifications

3 years agoUnboxed sums: More unit tests
Ömer Sinan Ağacan [Fri, 22 Jul 2016 08:37:56 +0000 (08:37 +0000)] 
Unboxed sums: More unit tests

3 years agoRevert "Cleanup PosixSource.h"
Ben Gamari [Fri, 22 Jul 2016 07:45:36 +0000 (09:45 +0200)] 
Revert "Cleanup PosixSource.h"

This reverts commit cac3fb06f4b282eee21159c364c4d08e8fdedce9.

This breaks OS X and Windows.

3 years agoMore typos in comments
Gabor Greif [Thu, 21 Jul 2016 22:32:28 +0000 (00:32 +0200)] 
More typos in comments

3 years agoCorrect a few mistyped words in prose/comments
Gabor Greif [Thu, 21 Jul 2016 22:10:32 +0000 (00:10 +0200)] 
Correct a few mistyped words in prose/comments

3 years agoFix and document Unique generation for sum TyCon and DataCons
Ömer Sinan Ağacan [Thu, 21 Jul 2016 19:59:05 +0000 (19:59 +0000)] 
Fix and document Unique generation for sum TyCon and DataCons

Test Plan: validate

Reviewers: bgamari, austin

Reviewed By: bgamari

Subscribers: thomie

Differential Revision:

3 years agoBump Haddock submodule
Ömer Sinan Ağacan [Thu, 21 Jul 2016 12:26:44 +0000 (12:26 +0000)] 
Bump Haddock submodule

3 years agoComments re ApThunks + small refactor in mkRhsClosure
Simon Peyton Jones [Wed, 20 Jul 2016 14:29:44 +0000 (15:29 +0100)] 
Comments re ApThunks + small refactor in mkRhsClosure

3 years agoComments + tiny refactor of isNullarySrcDataCon
Simon Peyton Jones [Wed, 20 Jul 2016 14:28:37 +0000 (15:28 +0100)] 
Comments + tiny refactor of isNullarySrcDataCon

3 years agoComments only
Simon Peyton Jones [Wed, 20 Jul 2016 14:28:10 +0000 (15:28 +0100)] 
Comments only

3 years agoImplement unboxed sum primitive type
Ömer Sinan Ağacan [Thu, 21 Jul 2016 08:07:41 +0000 (08:07 +0000)] 
Implement unboxed sum primitive type

This patch implements primitive unboxed sum types, as described in

Main changes are:

- Add new syntax for unboxed sums types, terms and patterns. Hidden
  behind `-XUnboxedSums`.

- Add unlifted unboxed sum type constructors and data constructors,
  extend type and pattern checkers and desugarer.

- Add new RuntimeRep for unboxed sums.

- Extend unarise pass to translate unboxed sums to unboxed tuples right
  before code generation.

- Add `StgRubbishArg` to `StgArg`, and a new type `CmmArg` for better
  code generation when sum values are involved.

- Add user manual section for unboxed sums.

Some other changes:

- Generalize `UbxTupleRep` to `MultiRep` and `UbxTupAlt` to
  `MultiValAlt` to be able to use those with both sums and tuples.

- Don't use `tyConPrimRep` in `isVoidTy`: `tyConPrimRep` is really
  wrong, given an `Any` `TyCon`, there's no way to tell what its kind
  is, but `kindPrimRep` and in turn `tyConPrimRep` returns `PtrRep`.

- Fix some bugs on the way: #12375.

Not included in this patch:

- Update Haddock for new the new unboxed sum syntax.

- `TemplateHaskell` support is left as future work.

For reviewers:

- Front-end code is mostly trivial and adapted from unboxed tuple code
  for type checking, pattern checking, renaming, desugaring etc.

- Main translation routines are in `RepType` and `UnariseStg`.
  Documentation in `UnariseStg` should be enough for understanding
  what's going on.


- Johan Tibell wrote the initial front-end and interface file

- Simon Peyton Jones reviewed this patch many times, wrote some code,
  and helped with debugging.

Reviewers: bgamari, alanz, goldfire, RyanGlScott, simonpj, austin,
           simonmar, hvr, erikd

Reviewed By: simonpj

Subscribers: Iceland_jack, ggreif, ezyang, RyanGlScott, goldfire,
             thomie, mpickering

Differential Revision:

3 years agoRevert "Clean up interaction between name cache and built-in syntax"
Ben Gamari [Wed, 20 Jul 2016 17:04:10 +0000 (19:04 +0200)] 
Revert "Clean up interaction between name cache and built-in syntax"

This reverts commit 9513fe6bdeafd35ca1a04e17b5f94732516766aa.

Sadly this broke with -DDEBUG.

3 years agoCompact Regions
Giovanni Campagna [Fri, 15 Jul 2016 18:47:26 +0000 (19:47 +0100)] 
Compact Regions

This brings in initial support for compact regions, as described in the
ICFP 2015 paper "Efficient Communication and Collection with Compact
Normal Forms" (Edward Z. Yang and implemented by Giovanni

Some things may change before the 8.2 release, but I (Simon M.) wanted
to get the main patch committed so that we can iterate.

What documentation there is is in the Data.Compact module in the new
compact package.  We'll need to extend and polish the documentation
before the release.

Test Plan:
(new test cases included)

Reviewers: ezyang, simonmar, hvr, bgamari, austin

Subscribers: vikraman, Yuras, RyanGlScott, qnikst, mboes, facundominguez, rrnewton, thomie, erikd

Differential Revision:

GHC Trac Issues: #11493

3 years agoAdd another testcase for #12082
Ben Gamari [Wed, 20 Jul 2016 15:25:37 +0000 (17:25 +0200)] 
Add another testcase for #12082

Test Plan: Validate, should pass.

Reviewers: austin

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #12082

3 years agotestsuite: Add regression test for #12381
Ben Gamari [Wed, 20 Jul 2016 15:21:35 +0000 (17:21 +0200)] 
testsuite: Add regression test for #12381

Test Plan: Validate

Reviewers: austin

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #12381, #11348

3 years agoClean up interaction between name cache and built-in syntax
Ben Gamari [Wed, 20 Jul 2016 10:34:54 +0000 (12:34 +0200)] 
Clean up interaction between name cache and built-in syntax

This cleans up various aspects of the handling of built-in syntax in the
original name cache (hopefully resulting in a nice reduction in compiler

  * Remove tuple types from original name cache: There is really no
    reason for these to be in the name cache since we already handle
    them specially in interface files to ensure that we can resolve them
    directly to Names, avoiding extraneous name cache lookups.

  * Sadly it's not possible to remove all traces of tuples from the
    name cache, however. Namely we need to keep the tuple type
    representations in since otherwise they would need to be wired-in

  * Remove the special cases for (:), [], and (##) in isBuiltInOcc_maybe
    and rename it to isTupleOcc_maybe

  * Split lookupOrigNameCache into two variants,

     * lookupOrigNameCache': Merely looks up an OccName in the original
       name cache, making no attempt to resolve tuples

     * lookupOrigNameCache: Like the above but handles tuples as well.
       This is given the un-primed name since it does the "obvious"
       thing from the perspective of an API user, who knows nothing of
       our special treatment of tuples.

Arriving at this design took a significant amount of iteration. The
trail of debris leading here can be found in #11357.

Thanks to ezyang and Simon for all of their help in coming to this

Test Plan: Validate

Reviewers: goldfire, simonpj, austin

Reviewed By: simonpj

Subscribers: thomie, ezyang

Differential Revision:

GHC Trac Issues: #11357

3 years agoInstEnv: Ensure that instance visibility check is lazy
Ben Gamari [Wed, 20 Jul 2016 07:56:03 +0000 (09:56 +0200)] 
InstEnv: Ensure that instance visibility check is lazy

Previously instIsVisible had completely broken the laziness of
lookupInstEnv' since it would examine is_dfun_name to check the name of
the defining module (to know whether it is an interactive module). This
resulted in the visibility check drawing in an interface file
unnecessarily. This contributed to the unnecessary regression in
compiler allocations reported in #12367.

Test Plan: Validate, check nofib changes

Reviewers: simonpj, ezyang, austin

Reviewed By: ezyang

Subscribers: thomie, ezyang

Differential Revision:

GHC Trac Issues: #12367

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

3 years agoData.Either: Add fromLeft and fromRight (#12402)
Dylan Meysmans [Wed, 20 Jul 2016 07:54:55 +0000 (09:54 +0200)] 
Data.Either: Add fromLeft and fromRight (#12402)

Reviewers: austin, hvr, RyanGlScott, bgamari

Reviewed By: RyanGlScott, bgamari

Subscribers: RyanGlScott, thomie

Differential Revision:

GHC Trac Issues: #12402

3 years agoCleanup PosixSource.h
Moritz Angermann [Wed, 20 Jul 2016 07:53:45 +0000 (09:53 +0200)] 
Cleanup PosixSource.h

When trying to build arm64-apple-iso, the build fell over
`strdup`, as the arm64-apple-ios build did not fall into `darwin_HOST_OS`,
and would need `ios_HOST_OS`.

This diff tries to clean up PosixSource.h, instead of layering another
define on top.

As we use `strnlen` in sources that include PosixSource.h, and `strnlen`
is defined in POSIX.1-2008, the `_POSIX_C_SOURCE` and `_XOPEN_SOURCE`
are increased accordingly.

Furthermore the `_DARWIN_C_SOURCE` (required for `u_char`, etc. used in
sysctl.h) define is moved into `OSThreads.h` alongside a similar ifdef
for freebsd.

Test Plan: Build on all supported platforms.

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

Reviewed By: simonmar, bgamari

Subscribers: thomie

Differential Revision:

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

3 years agoTcInteract: Add braces to matchClassInst trace output
Ben Gamari [Mon, 18 Jul 2016 18:17:24 +0000 (20:17 +0200)] 
TcInteract: Add braces to matchClassInst trace output

This allows you to easily move to the result in a well-equipped editor.

3 years agoMake Data.{Bifoldable,Bitraversable} -XSafe
Ryan Scott [Wed, 20 Jul 2016 13:15:56 +0000 (09:15 -0400)] 
Make Data.{Bifoldable,Bitraversable} -XSafe

Test Plan:
Previously, `Data.{Bifoldable,Bitraversable}` were being inferred as
`Unsafe` due to a transitive `Data.Coerce` import from `Data.Functor.Utils`.
This rectifies this unfortunate mistake.

Reviewers: austin, hvr, bgamari

Reviewed By: bgamari

Subscribers: thomie, phadej

Differential Revision:

3 years agoSupport SCC pragmas in declaration context
Ömer Sinan Ağacan [Wed, 20 Jul 2016 09:33:43 +0000 (09:33 +0000)] 
Support SCC pragmas in declaration context

Not having SCCs at the top level is becoming annoying real quick. For
simplest cases, it's possible to do this transformation:

    f x y = ...
    f = {-# SCC f #-} \x y -> ...

However, it doesn't work when there's a `where` clause:

    f x y = <t is in scope>
      where t = ...
    f = {-# SCC f #-} \x y -> <t is out of scope>
      where t = ...

Or when we have a "equation style" definition:

    f (C1 ...) = ...
    f (C2 ...) = ...
    f (C3 ...) = ...

(usual solution is to rename `f` to `f'` and define a new `f` with a

This patch implements support for SCC annotations in declaration
contexts. This is now a valid program:

    f x y = ...
        g z = ...
        {-# SCC g #-}
    {-# SCC f #-}

Test Plan: This passes slow validate (no new failures added).

Reviewers: goldfire, mpickering, austin, bgamari, simonmar

Reviewed By: bgamari, simonmar

Subscribers: simonmar, thomie, mpickering

Differential Revision:

3 years agoFix PDF build for the User's Guide.
Gabor Pali [Tue, 19 Jul 2016 16:05:53 +0000 (18:05 +0200)] 
Fix PDF build for the User's Guide.

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

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

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

3 years agoFix misspellings of the word "instance" in comments
Ryan Scott [Mon, 18 Jul 2016 13:14:36 +0000 (09:14 -0400)] 
Fix misspellings of the word "instance" in comments

[ci skip]

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

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

3 years agoCodeGen: Way to dump cmm only once (#11717)
Vladimir Trubilov [Sat, 16 Jul 2016 22:13:22 +0000 (00:13 +0200)] 
CodeGen: Way to dump cmm only once (#11717)

The `-ddump-cmm` put all stages of Cmm processing into one output.
This patch changes its behavior and adds two more options to make
Cmm dumping flexible.

- `-ddump-cmm-from-stg` dumps only initial version of  Cmm right after
   STG->Cmm codegen
- `-ddump-cmm` dumps the final result of the Cmm pipeline processing
- `-ddump-cmm-verbose` dumps intermediate output of each Cmm pipeline
- `-ddump-cmm-proc` and `-ddump-cmm-caf` seems were lost. Now enabled

Test Plan: ./validate

Reviewers: thomie, simonmar, austin, bgamari

Reviewed By: thomie, simonmar

Subscribers: simonpj, thomie

Differential Revision:

GHC Trac Issues: #11717

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

3 years agoBinary: Use ByteString's copy in getBS
Ben Gamari [Sat, 16 Jul 2016 21:41:46 +0000 (23:41 +0200)] 
Binary: Use ByteString's copy in getBS

It's unclear how much of an effect on runtime this will have, but if
nothing else the code generation may be a tad better since the system's
`memcpy` will be used.

Test Plan: Validate

Reviewers: simonmar, austin

Subscribers: thomie

Differential Revision:

3 years agoIfaceEnv: Only check for built-in OccNames if mod is GHC.Types
Ben Gamari [Sat, 16 Jul 2016 21:38:51 +0000 (23:38 +0200)] 
IfaceEnv: Only check for built-in OccNames if mod is GHC.Types

This check is not entirely cheap and will not succeed unless we are
looking for something in the module where built-in syntax lives,

Reviewers: simonpj, austin

Subscribers: simonpj, thomie, osa1

Differential Revision:

3 years agoLog heap profiler samples to event log
Ben Gamari [Thu, 16 Jun 2016 13:03:01 +0000 (15:03 +0200)] 
Log heap profiler samples to event log

Test Plan: Try it

Reviewers: hvr, simonmar, austin, erikd

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #11094

3 years agoBring comments in TcGenGenerics up to date
Ryan Scott [Fri, 15 Jul 2016 18:17:24 +0000 (14:17 -0400)] 
Bring comments in TcGenGenerics up to date

[ci skip]

3 years agoAdded type family dependency to Data.Type.Bool.Not
Baldur Blöndal [Thu, 14 Jul 2016 22:09:03 +0000 (18:09 -0400)] 
Added type family dependency to Data.Type.Bool.Not


Signed-off-by: Baldur Blöndal <>
Reviewers: goldfire, RyanGlScott, austin, bgamari, hvr

Reviewed By: RyanGlScott, austin

Subscribers: RyanGlScott, thomie

Differential Revision:

GHC Trac Issues: #12057

3 years agotidyOccNames: Rename variables fairly
Joachim Breitner [Tue, 12 Jul 2016 15:21:07 +0000 (17:21 +0200)] 
tidyOccNames: Rename variables fairly

So that
> :t (id,id,id)
(id,id,id) :: (a3 -> a3, a2 -> a2, a1 -> a1)
instead of
(id,id,id) :: (a2 -> a2, a1 -> a1, a -> a)

Differential Revision:

3 years agotidyType: Rename variables of nested forall at once
Joachim Breitner [Tue, 12 Jul 2016 14:52:42 +0000 (16:52 +0200)] 
tidyType: Rename variables of nested forall at once

this refactoring commit prepares for fixing #12382, which can now be
implemented soley in tidyTyCoVarBndrs.

3 years agoDemand analyser: Implement LetUp rule (#12370)
Joachim Breitner [Wed, 6 Jul 2016 13:44:18 +0000 (15:44 +0200)] 
Demand analyser: Implement LetUp rule (#12370)

This makes the implementation match the description in the paper more
closely: There, a let binding that is not a function has first its body
analised, and then the binding’s RHS. This way, the demand on the bound
variable by the body can be fed into the RHS, yielding more precise

Performance measurements do unfortunately not show significant
improvements or regessions.

Differential Revision:

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

3 years agoAdd -package-env to the flags reference
Simon Marlow [Sun, 10 Jul 2016 10:00:06 +0000 (11:00 +0100)] 
Add -package-env to the flags reference

3 years agocheck-api-annotations utility loads by filename
Alan Zimmerman [Sun, 10 Jul 2016 19:38:01 +0000 (21:38 +0200)] 
check-api-annotations utility loads by filename

Previously it loaded by modulename, which prevented loading files with a
Main module.

3 years agoTysWiredIn: Use UniqFM lookup for built-in OccNames
Ben Gamari [Sat, 9 Jul 2016 19:03:46 +0000 (21:03 +0200)] 
TysWiredIn: Use UniqFM lookup for built-in OccNames

Previously we would unpack the OccName into a String, then pattern match
against this string. Due to the implementation of `unpackFS`, this
actually unpacks the entire contents, even though we often only need to
look at the first few characters.

Here we take another approach: build a UniqFM with the known built-in
OccNames, allowing us to use `FastString`'s hash-based comparison

Reviewers: simonpj, austin, simonmar

Reviewed By: simonmar

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #12357

3 years agoTestsuite: expose TEST_CC (path to gcc)
Thomas Miedema [Sat, 9 Jul 2016 12:03:51 +0000 (14:03 +0200)] 
Testsuite: expose TEST_CC (path to gcc)

Reviewed by: Phyx

Differential Revision:

3 years agoDsExpr: Remove usage of concatFS in fingerprintName
Ben Gamari [Fri, 8 Jul 2016 20:41:55 +0000 (22:41 +0200)] 
DsExpr: Remove usage of concatFS in fingerprintName

This was the only user of concatFS and really just wants the `String`

Stumbled upon while looking at #12357.

Test Plan: Validate

Reviewers: austin

Reviewed By: austin

Subscribers: thomie

Differential Revision:

3 years agoKill eltsUFM in classifyTyCons
Bartosz Nitka [Fri, 8 Jul 2016 14:40:48 +0000 (07:40 -0700)] 
Kill eltsUFM in classifyTyCons

GHC Trac: #4012

3 years agoOccName: Avoid re-encoding derived OccNames
Ben Gamari [Fri, 8 Jul 2016 13:38:23 +0000 (15:38 +0200)] 
OccName: Avoid re-encoding derived OccNames

Previously we would form derived OccNames by first decoding the name
being derived from, manipulating it in [Char] form, and then
re-encoding. This is all very wasteful as we essentially always just
want to concatenate. Instead we now take care to form the final name
with only one concatFS.

Test Plan: Validate, examing compiler allocations

Reviewers: simonpj, austin

Reviewed By: simonpj

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #12357

3 years agoOccName: Implement startsWithUnderscore in terms of headFS
Ben Gamari [Fri, 8 Jul 2016 12:09:36 +0000 (14:09 +0200)] 
OccName: Implement startsWithUnderscore in terms of headFS

This avoids decoding the entire string just to look at the first

Test Plan: Validate

Reviewers: austin

Subscribers: thomie

Differential Revision:

3 years agoFastString: Supply mconcat implementation
Ben Gamari [Fri, 8 Jul 2016 12:09:09 +0000 (14:09 +0200)] 
FastString: Supply mconcat implementation

Test Plan: Validate

Reviewers: austin

Subscribers: thomie

Differential Revision:

3 years agoFastString: Add IsString instance
Ben Gamari [Tue, 5 Jul 2016 10:06:29 +0000 (06:06 -0400)] 
FastString: Add IsString instance

3 years agoFastString: Reduce allocations of concatFS
Ben Gamari [Tue, 5 Jul 2016 00:33:57 +0000 (20:33 -0400)] 
FastString: Reduce allocations of concatFS

Instead of unpacking and then repacking we simply concatenate all of the
individual ByteStrings.

3 years agoGHC.Stack.CCS: Fix typo in Haddocks
Ben Gamari [Thu, 7 Jul 2016 17:42:46 +0000 (19:42 +0200)] 
GHC.Stack.CCS: Fix typo in Haddocks

3 years agoUse UniqDFM for InstEnv
Bartosz Nitka [Thu, 7 Jul 2016 14:56:49 +0000 (07:56 -0700)] 
Use UniqDFM for InstEnv

Rationale in the comment.
Also updates submodule array with test output changes.

GHC Trac: #4012

3 years agoUtils: Fix `lengthIs` and `lengthExceeds` for negative args
Ömer Sinan Ağacan [Thu, 7 Jul 2016 20:01:47 +0000 (20:01 +0000)] 
Utils: Fix `lengthIs` and `lengthExceeds` for negative args

Credits goes to SPJ for finding this.

3 years agoAdd Note [FamInstEnv determinism]
Bartosz Nitka [Thu, 7 Jul 2016 15:12:05 +0000 (08:12 -0700)] 
Add Note [FamInstEnv determinism]

I'm just turning previous commit message into a Note

GHC Trac: #4012