2 months agoAdd some lock contention checking
Ben Gamari [Sun, 14 Apr 2019 14:46:40 +0000 (10:46 -0400)] 
Add some lock contention checking

2 months agoImplement -xns for -xn with selector opt
Ömer Sinan Ağacan [Thu, 16 May 2019 13:28:32 +0000 (16:28 +0300)] 
Implement -xns for -xn with selector opt

2 months agoMerge branches 'wip/gc/segment-header-to-bdescr' and 'wip/gc/docs' into tmp
Ben Gamari [Tue, 21 May 2019 13:39:11 +0000 (09:39 -0400)] 
Merge branches 'wip/gc/segment-header-to-bdescr' and 'wip/gc/docs' into tmp

2 months agoNonMoving: Implement selector optimisation
Ömer Sinan Ağacan [Mon, 16 Jul 2018 12:22:29 +0000 (15:22 +0300)] 
NonMoving: Implement selector optimisation

2 months agoNonMoving: Implement indirection shortcutting
Ömer Sinan Ağacan [Thu, 25 Apr 2019 13:08:13 +0000 (16:08 +0300)] 
NonMoving: Implement indirection shortcutting

This allows indirection chains residing in the non-moving heap to be

3 months agoNonMoving: Move next_free_snap to block descriptor
Ben Gamari [Fri, 17 May 2019 17:38:36 +0000 (13:38 -0400)] 
NonMoving: Move next_free_snap to block descriptor

3 months agoNonMoving: Move block size to block descriptor
Ben Gamari [Fri, 17 May 2019 17:28:53 +0000 (13:28 -0400)] 
NonMoving: Move block size to block descriptor

3 months agoNonMoving: Introduce nonmovingSegmentLogBlockSize acccessor
Ben Gamari [Fri, 17 May 2019 17:18:48 +0000 (13:18 -0400)] 
NonMoving: Introduce nonmovingSegmentLogBlockSize acccessor

This will allow us to easily move the block size elsewhere.

3 months agoNonMoving: More comments
Ben Gamari [Sun, 19 May 2019 18:09:16 +0000 (14:09 -0400)] 
NonMoving: More comments

3 months agoNonMoving: Add summarizing Note
Ben Gamari [Fri, 17 May 2019 15:42:11 +0000 (11:42 -0400)] 
NonMoving: Add summarizing Note

3 months agoMerge branches 'wip/gc/optimize' and 'wip/gc/test' into wip/gc/everything
Ben Gamari [Sun, 19 May 2019 18:50:29 +0000 (14:50 -0400)] 
Merge branches 'wip/gc/optimize' and 'wip/gc/test' into wip/gc/everything

3 months agoNonmoving: Ensure write barrier vanishes in non-threaded RTS
Ben Gamari [Sun, 19 May 2019 17:29:42 +0000 (13:29 -0400)] 
Nonmoving: Ensure write barrier vanishes in non-threaded RTS

3 months agoNonMoving: Don't do major GC if one is already running
Ben Gamari [Fri, 17 May 2019 23:18:42 +0000 (19:18 -0400)] 
NonMoving: Don't do major GC if one is already running

Previously we would perform a preparatory moving collection, resulting
in many things being added to the mark queue. When we finished with this
we would realize in nonmovingCollect that there was already a collection
running, in which case we would simply not run the nonmoving collector.

However, it was very easy to end up in a "treadmilling" situation: all
subsequent GC following the first failed major GC would be scheduled as
major GCs. Consequently we would continuously feed the concurrent
collector with more mark queue entries and it would never finish.

This patch aborts the major collection far earlier, meaning that we
avoid adding nonmoving objects to the mark queue and allowing the
concurrent collector to finish.

3 months agoNonMovingMark: Eliminate redundant check_in_nonmoving_heaps
Ben Gamari [Sat, 4 May 2019 00:06:47 +0000 (20:06 -0400)] 
NonMovingMark: Eliminate redundant check_in_nonmoving_heaps

3 months agoNonMoving: Optimise allocator cache behavior
Ben Gamari [Sun, 12 May 2019 03:04:54 +0000 (23:04 -0400)] 
NonMoving: Optimise allocator cache behavior

Previously we would look at the segment header to determine the block
size despite the fact that we already had the block size at hand.

3 months agoNonMoving: Prefetch segment header
Ben Gamari [Thu, 16 May 2019 21:14:38 +0000 (17:14 -0400)] 
NonMoving: Prefetch segment header

3 months agoNonMoving: Pre-fetch during mark
Ben Gamari [Wed, 15 May 2019 20:49:40 +0000 (16:49 -0400)] 
NonMoving: Pre-fetch during mark

This improved overall runtime on nofib's constraints test by nearly 10%.

3 months agoNonMoving: Fuse sweep preparation into mark prep
Ben Gamari [Sat, 11 May 2019 23:53:46 +0000 (19:53 -0400)] 
NonMoving: Fuse sweep preparation into mark prep

3 months agoNonMoving: Inline nonmovingClearAllBitmaps
Ben Gamari [Sat, 11 May 2019 23:32:17 +0000 (19:32 -0400)] 
NonMoving: Inline nonmovingClearAllBitmaps

3 months agoNonMoving: Prefetch when clearing bitmaps
Ben Gamari [Sat, 11 May 2019 23:14:43 +0000 (19:14 -0400)] 
NonMoving: Prefetch when clearing bitmaps

Ensure that the bitmap of the segmentt that we will clear next is in
cache by the time we reach it.

3 months agorts: Add prefetch macros
Ben Gamari [Sat, 18 May 2019 15:02:03 +0000 (11:02 -0400)] 
rts: Add prefetch macros

3 months agorts/Stats: Track time usage of nonmoving collector
Ben Gamari [Fri, 3 May 2019 19:15:45 +0000 (15:15 -0400)] 
rts/Stats: Track time usage of nonmoving collector

3 months agorts: Add GetMyThreadCPUTime helper
Ben Gamari [Fri, 17 May 2019 19:40:26 +0000 (15:40 -0400)] 
rts: Add GetMyThreadCPUTime helper

3 months agoNonMoving: Optimize bitmap search during allocation
Ben Gamari [Sat, 11 May 2019 15:55:42 +0000 (11:55 -0400)] 
NonMoving: Optimize bitmap search during allocation

Use memchr instead of a open-coded loop. This is nearly twice as fast in
a synthetic benchmark.

3 months agoNonMovingMark: Optimize representation of mark queue
Ben Gamari [Fri, 3 May 2019 23:44:54 +0000 (19:44 -0400)] 
NonMovingMark: Optimize representation of mark queue

This shortens MarkQueueEntry by 30% (one word)

3 months agoAllocate mark queues in larger block groups
Ben Gamari [Sun, 14 Apr 2019 16:26:57 +0000 (12:26 -0400)] 
Allocate mark queues in larger block groups

3 months agoNonMoving: Eliminate integer division in nonmovingBlockCount
Ben Gamari [Tue, 16 Apr 2019 18:32:40 +0000 (14:32 -0400)] 
NonMoving: Eliminate integer division in nonmovingBlockCount

Perf showed that the this single div was capturing up to 10% of samples
in nonmovingMark. However, the overwhelming majority of cases is looking
at small block sizes. These cases we can easily compute explicitly,
allowing the compiler to turn the division into a significantly more
efficient division-by-constant.

While the increase in source code looks scary, this all optimises down
to very nice looking assembler. At this point the only remaining
hotspots in nonmovingBlockCount are due to memory access.

3 months agoNonmoving: Allow aging and refactor static objects logic
Ben Gamari [Thu, 18 Apr 2019 18:08:32 +0000 (14:08 -0400)] 
Nonmoving: Allow aging and refactor static objects logic

This commit does two things:

 * Allow aging of objects during the preparatory minor GC
 * Refactor handling of static objects to avoid the use of a hashtable

3 months agotests
Ben Gamari [Thu, 16 May 2019 12:53:35 +0000 (08:53 -0400)] 

3 months agotestsuite: Add nonmoving_thr_ghc way
Ben Gamari [Tue, 12 Feb 2019 03:03:33 +0000 (22:03 -0500)] 
testsuite: Add nonmoving_thr_ghc way

This uses the nonmoving collector when compiling the testcases.

3 months agotestsuite fixes
Ben Gamari [Sun, 14 Apr 2019 16:38:04 +0000 (12:38 -0400)] 
testsuite fixes

3 months agoSkip ghc_heap_all test in nonmoving ways
Ben Gamari [Wed, 3 Apr 2019 00:50:56 +0000 (20:50 -0400)] 
Skip ghc_heap_all test in nonmoving ways

3 months agoghc-heap: Skip heap_all test with debugged RTS
Ben Gamari [Tue, 5 Mar 2019 00:45:36 +0000 (19:45 -0500)] 
ghc-heap: Skip heap_all test with debugged RTS

The debugged RTS initializes the heap with 0xaa, which breaks the
(admittedly rather fragile) assumption that uninitialized fields are set
to 0x00:
Wrong exit code for heap_all(nonmoving)(expected 0 , actual 1 )
Stderr ( heap_all ):
heap_all: user error (assertClosuresEq: Closures do not match
Expected: FunClosure {info = StgInfoTable {entry = Nothing, ptrs = 0, nptrs = 1, tipe = FUN_0_1, srtlen = 0, code = Nothing}, ptrArgs = [], dataArgs = [0]}
Actual:   FunClosure {info = StgInfoTable {entry = Nothing, ptrs = 0, nptrs = 1, tipe = FUN_0_1, srtlen = 1032832, code = Nothing}, ptrArgs = [], dataArgs = [12297829382473034410]}

CallStack (from HasCallStack):
  assertClosuresEq, called at heap_all.hs:230:9 in main:Main

3 months agotestsuite: Don't run conc071 in nonmoving_thr_ghc
Ben Gamari [Mon, 4 Mar 2019 22:49:53 +0000 (17:49 -0500)] 
testsuite: Don't run conc071 in nonmoving_thr_ghc

3 months agotestsuite: Disable conc016 and conc068 in nonmoving ways
Ben Gamari [Fri, 15 Feb 2019 13:36:48 +0000 (08:36 -0500)] 
testsuite: Disable conc016 and conc068 in nonmoving ways

3 months agotestsuite: Skip T15892 in nonmoving_thr_ghc
Ben Gamari [Wed, 13 Feb 2019 20:33:31 +0000 (15:33 -0500)] 
testsuite: Skip T15892 in nonmoving_thr_ghc

3 months agoOmit broken tests
Ben Gamari [Wed, 13 Feb 2019 20:31:27 +0000 (15:31 -0500)] 
Omit broken tests

3 months agotestsuite: bug1010 requires -c, which isn't supported by nonmoving
Ben Gamari [Wed, 13 Feb 2019 19:05:37 +0000 (14:05 -0500)] 
testsuite: bug1010 requires -c, which isn't supported by nonmoving

3 months agotestsuite: Ensure that threaded tests are run in nonmoving_thr
Ben Gamari [Wed, 13 Feb 2019 18:49:04 +0000 (13:49 -0500)] 
testsuite: Ensure that threaded tests are run in nonmoving_thr

3 months agotestsuite: Add nonmoving_thr_ghc way
Ben Gamari [Tue, 12 Feb 2019 03:03:33 +0000 (22:03 -0500)] 
testsuite: Add nonmoving_thr_ghc way

This uses the nonmoving collector when compiling the testcases.

3 months agotestsuite: Nonmoving collector doesn't support -G1
Ben Gamari [Tue, 5 Feb 2019 22:15:57 +0000 (17:15 -0500)] 
testsuite: Nonmoving collector doesn't support -G1

3 months agotestsuite: Don't run T15892 in nonmoving ways
Ben Gamari [Tue, 5 Feb 2019 22:06:25 +0000 (17:06 -0500)] 
testsuite: Don't run T15892 in nonmoving ways

The nonmoving GC doesn't support `+RTS -G1`, which this test insists on.

3 months agoNonmovingCensus: Emit samples to eventlog
Ben Gamari [Mon, 15 Apr 2019 20:42:56 +0000 (16:42 -0400)] 
NonmovingCensus: Emit samples to eventlog

3 months agoAllow census without live word count
Ben Gamari [Sat, 16 Mar 2019 14:24:24 +0000 (10:24 -0400)] 
Allow census without live word count

Otherwise the census is unsafe when mutators are running due to
concurrent mutation.

3 months agorts/Eventlog: More descriptive error message
Ben Gamari [Mon, 15 Apr 2019 21:07:24 +0000 (17:07 -0400)] 
rts/Eventlog: More descriptive error message

3 months agorts: Introduce non-moving heap census
Ben Gamari [Tue, 5 Feb 2019 16:52:13 +0000 (11:52 -0500)] 
rts: Introduce non-moving heap census

This introduces a simple census of the non-moving heap (not to be
confused with the heap census used by the heap profiler). This
collects basic heap usage information (number of allocated and free
blocks) which is useful when characterising fragmentation of the
nonmoving heap.

3 months agorts: Tracing support for nonmoving collection events
Ben Gamari [Tue, 5 Feb 2019 16:51:52 +0000 (11:51 -0500)] 
rts: Tracing support for nonmoving collection events

This introduces a few events to mark key points in the nonmoving
garbage collection cycle. These include:

 * `EVENT_CONC_MARK_BEGIN`, denoting the beginning of a round of
   marking. This may happen more than once in a single major collection
   since we the major collector iterates until it hits a fixed point.

 * `EVENT_CONC_MARK_END`, denoting the end of a round of marking.

 * `EVENT_CONC_SYNC_BEGIN`, denoting the beginning of the post-mark
   synchronization phase

 * `EVENT_CONC_UPD_REM_SET_FLUSH`, indicating that a capability has
   flushed its update remembered set.

 * `EVENT_CONC_SYNC_END`, denoting that all mutators have flushed their
   update remembered sets.

 * `EVENT_CONC_SWEEP_BEGIN`, denoting the beginning of the sweep portion
   of the major collection.

 * `EVENT_CONC_SWEEP_END`, denoting the end of the sweep portion of the
   major collection.

3 months agoNonmoving: Disable memory inventory with concurrent collection
Ben Gamari [Fri, 17 May 2019 02:13:02 +0000 (22:13 -0400)] 
Nonmoving: Disable memory inventory with concurrent collection

3 months agoDrop redundant write barrier
Ben Gamari [Thu, 16 May 2019 21:18:19 +0000 (17:18 -0400)] 
Drop redundant write barrier

3 months agorts: Implement concurrent collection in the nonmoving collector
Ben Gamari [Tue, 5 Feb 2019 16:51:14 +0000 (11:51 -0500)] 
rts: Implement concurrent collection in the nonmoving collector

This extends the non-moving collector to allow concurrent collection.

The full design of the collector implemented here is described in detail
in a technical note

    B. Gamari. "A Concurrent Garbage Collector For the Glasgow Haskell
    Compiler" (2018)

This extension involves the introduction of a capability-local
remembered set, known as the /update remembered set/, which tracks
objects which may no longer be visible to the collector due to mutation.
To maintain this remembered set we introduce a write barrier on
mutations which is enabled while a concurrent mark is underway.

The update remembered set representation is similar to that of the
nonmoving mark queue, being a chunked array of `MarkEntry`s. Each
`Capability` maintains a single accumulator chunk, which it flushed
when it (a) is filled, or (b) when the nonmoving collector enters its
post-mark synchronization phase.

While the write barrier touches a significant amount of code it is
conceptually straightforward: the mutator must ensure that the referee
of any pointer it overwrites is added to the update remembered set.
However, there are a few details:

 * In the case of objects with a dirty flag (e.g. `MVar`s) we can
   exploit the fact that only the *first* mutation requires a write

 * Weak references, as usual, complicate things. In particular, we must
   ensure that the referee of a weak object is marked if dereferenced by
   the mutator. For this we (unfortunately) must introduce a read
   barrier, as described in Note [Concurrent read barrier on deRefWeak#]
   (in `NonMovingMark.c`).

 * Stable names are also a bit tricky as described in Note [Sweeping
   stable names in the concurrent collector] (`NonMovingSweep.c`).

We take quite some pains to ensure that the high thread count often seen
in parallel Haskell applications doesn't affect pause times. To this end
we allow thread stacks to be marked either by the thread itself (when it
is executed or stack-underflows) or the concurrent mark thread (if the
thread owning the stack is never scheduled). There is a non-trivial
handshake to ensure that this happens without racing which is described
in Note [StgStack dirtiness flags and concurrent marking].

Co-Authored-by: Ömer Sinan Ağacan <>
3 months agotestsuite: Add nonmoving WAY
Ben Gamari [Tue, 5 Feb 2019 19:39:52 +0000 (14:39 -0500)] 
testsuite: Add nonmoving WAY

This simply runs the compile_and_run tests with `-xn`, enabling the
nonmoving oldest generation.

3 months agorts: Non-concurrent mark and sweep
Ömer Sinan Ağacan [Tue, 5 Feb 2019 05:18:44 +0000 (00:18 -0500)] 
rts: Non-concurrent mark and sweep

This implements the core heap structure and a serial mark/sweep
collector which can be used to manage the oldest-generation heap.
This is the first step towards a concurrent mark-and-sweep collector
aimed at low-latency applications.

The full design of the collector implemented here is described in detail
in a technical note

    B. Gamari. "A Concurrent Garbage Collector For the Glasgow Haskell
    Compiler" (2018)

The basic heap structure used in this design is heavily inspired by

    K. Ueno & A. Ohori. "A fully concurrent garbage collector for
    functional programs on multicore processors." /ACM SIGPLAN Notices/
    Vol. 51. No. 9 (presented by ICFP 2016)

This design is intended to allow both marking and sweeping
concurrent to execution of a multi-core mutator. Unlike the Ueno design,
which requires no global synchronization pauses, the collector
introduced here requires a stop-the-world pause at the beginning and end
of the mark phase.

To avoid heap fragmentation, the allocator consists of a number of
fixed-size /sub-allocators/. Each of these sub-allocators allocators into
its own set of /segments/, themselves allocated from the block
allocator. Each segment is broken into a set of fixed-size allocation
blocks (which back allocations) in addition to a bitmap (used to track
the liveness of blocks) and some additional metadata (used also used
to track liveness).

This heap structure enables collection via mark-and-sweep, which can be
performed concurrently via a snapshot-at-the-beginning scheme (although
concurrent collection is not implemented in this patch).

The mark queue is a fairly straightforward chunked-array structure.
The representation is a bit more verbose than a typical mark queue to
accomodate a combination of two features:

 * a mark FIFO, which improves the locality of marking, reducing one of
   the major overheads seen in mark/sweep allocators (see [1] for

 * the selector optimization and indirection shortcutting, which
   requires that we track where we found each reference to an object
   in case we need to update the reference at a later point (e.g. when
   we find that it is an indirection). See Note [Origin references in
   the nonmoving collector] (in `NonMovingMark.h`) for details.

Beyond this the mark/sweep is fairly run-of-the-mill.

[1] R. Garner, S.M. Blackburn, D. Frampton. "Effective Prefetch for
    Mark-Sweep Garbage Collection." ISMM 2007.

Co-Authored-By: Ben Gamari <>
3 months agorts: Introduce debug flag for non-moving GC
Ben Gamari [Sat, 7 Jul 2018 01:02:22 +0000 (21:02 -0400)] 
rts: Introduce debug flag for non-moving GC

3 months agorts: Introduce flag to enable the nonmoving old generation
Ben Gamari [Tue, 5 Feb 2019 05:10:43 +0000 (00:10 -0500)] 
rts: Introduce flag to enable the nonmoving old generation

This flag will enable the use of a non-moving oldest generation.

3 months agorts/Scav: Expose scavenging functions
Ömer Sinan Ağacan [Tue, 5 Feb 2019 16:46:25 +0000 (11:46 -0500)] 
rts/Scav: Expose scavenging functions

To keep the non-moving collector nicely separated from the moving
collector its scavenging phase will live in another file,
`NonMovingScav.c`. However, it will need to use these functions so
let's expose them.

3 months agorts: Disable aggregate-return warnings from gcc
Ben Gamari [Tue, 5 Feb 2019 17:48:29 +0000 (12:48 -0500)] 
rts: Disable aggregate-return warnings from gcc

This warning is a bit of a relic; there is little reason to avoid
aggregate return values in 2019.

3 months agorts/StableName: Expose FOR_EACH_STABLE_NAME, freeSnEntry, SNT_size
Ömer Sinan Ağacan [Tue, 5 Feb 2019 05:40:27 +0000 (00:40 -0500)] 
rts/StableName: Expose FOR_EACH_STABLE_NAME, freeSnEntry, SNT_size

These will be needed when we implement sweeping in the nonmoving

3 months agoMerge branch 'wip/gc/misc-rts' into wip/gc/preparation
Ben Gamari [Thu, 16 May 2019 16:31:34 +0000 (12:31 -0400)] 
Merge branch 'wip/gc/misc-rts' into wip/gc/preparation

3 months agorts: Fix macro parenthesisation
Ben Gamari [Wed, 8 May 2019 22:35:26 +0000 (18:35 -0400)] 
rts: Fix macro parenthesisation

5 months agoMerge branches 'wip/gc/sync-without-capability', 'wip/gc/factor-out-bitmap-walking...
Ben Gamari [Fri, 22 Feb 2019 01:00:02 +0000 (20:00 -0500)] 
Merge branches 'wip/gc/sync-without-capability', 'wip/gc/factor-out-bitmap-walking', 'wip/gc/aligned-block-allocation', 'wip/gc/misc-rts', 'wip/gc/printer-improvements' and 'wip/gc/unglobalize-gc-state' into wip/gc/preparation

5 months agorts/GC: Refactor gcCAFs
Ben Gamari [Wed, 6 Feb 2019 02:17:36 +0000 (21:17 -0500)] 
rts/GC: Refactor gcCAFs

5 months agorts/Printer: Print forwarding pointers
Ömer Sinan Ağacan [Tue, 5 Feb 2019 05:39:03 +0000 (00:39 -0500)] 
rts/Printer: Print forwarding pointers

5 months agorts: Unglobalize dead_weak_ptr_list and resurrected_threads
Ömer Sinan Ağacan [Tue, 5 Feb 2019 17:45:17 +0000 (12:45 -0500)] 
rts: Unglobalize dead_weak_ptr_list and resurrected_threads

In the concurrent nonmoving collector we will need the ability to call
`traverseWeakPtrList` concurrently with minor generation collections.
This global state stands in the way of this. However, refactoring it
away is straightforward since this list only persists the length of a
single GC.

5 months agorts: Give stack flags proper macros
Ben Gamari [Tue, 5 Feb 2019 16:01:10 +0000 (11:01 -0500)] 
rts: Give stack flags proper macros

This were previously quite unclear and will change a bit under the
non-moving collector so let's clear this up now.

5 months agorts/Printer: Introduce a few more printing utilities
Ömer Sinan Ağacan [Tue, 5 Feb 2019 05:37:57 +0000 (00:37 -0500)] 
rts/Printer: Introduce a few more printing utilities

These include printLargeAndPinnedObjects, printWeakLists, and
printStaticObjects. These are generally useful things to have.

5 months agorts/Capability: A few documentation comments
Ben Gamari [Tue, 5 Feb 2019 15:43:56 +0000 (10:43 -0500)] 
rts/Capability: A few documentation comments

5 months agorts: Add Note explaining applicability of selector optimisation depth limit
Ben Gamari [Tue, 3 Jul 2018 23:58:37 +0000 (19:58 -0400)] 
rts: Add Note explaining applicability of selector optimisation depth limit

This was slightly non-obvious so a note seems deserved.

5 months agorts/GC: Add an obvious assertion during block initialization
Ömer Sinan Ağacan [Tue, 5 Feb 2019 15:40:29 +0000 (10:40 -0500)] 
rts/GC: Add an obvious assertion during block initialization

Namely ensure that block descriptors are initialized with valid
generation numbers.

5 months agorts/BlockAlloc: Allow aligned allocation requests
Ömer Sinan Ağacan [Mon, 5 Mar 2018 12:57:47 +0000 (15:57 +0300)] 
rts/BlockAlloc: Allow aligned allocation requests

This implements support for block group allocations which are aligned to
an integral number of blocks.

This will be used by the nonmoving garbage collector, which uses the
block allocator to allocate the segments which back its heap. These
segments are a fixed number of blocks in size, with each segment being
aligned to the segment size boundary. This allows us to easily find the
segment metadata stored at the beginning of the segment.

5 months agorts: Factor out large bitmap walking
Ben Gamari [Tue, 5 Feb 2019 15:59:32 +0000 (10:59 -0500)] 
rts: Factor out large bitmap walking

This will be needed by the mark phase of the non-moving collector
so let's factor it out.

5 months agorts/Schedule: Allow synchronization without holding a capability
Ben Gamari [Fri, 20 Jul 2018 01:57:14 +0000 (21:57 -0400)] 
rts/Schedule: Allow synchronization without holding a capability

The concurrent mark-and-sweep will be performed by a GHC task which will
not hold a capability. This is necessary to avoid a concurrent mark from
interfering with minor generation collections.

However, the major collector must synchronize with the mutators at the
end of marking to flush their update remembered sets. This patch extends
the `requestSync` mechanism used to synchronize garbage collectors to
allow synchronization without holding a capability.

This change is fairly straightforward as the capability was previously
only required for two reasons:

 1. to ensure that we don't try to re-acquire a capability that we
    the sync requestor already holds.

 2. to provide a way to suspend and later resume the sync request if
    there is already a sync pending.

When synchronizing without holding a capability we needn't worry about
consideration (1) at all.

(2) is slightly trickier and may happen, for instance, when a capability
requests a minor collection and shortly thereafter the non-moving mark
thread requests a post-mark synchronization. In this case we need to
ensure that the non-moving mark thread suspends his request until after
the minor GC has concluded to avoid dead-locking. For this we introduce
a condition variable, `sync_finished_cond`, which a
non-capability-bearing requestor will wait on and which is signalled
after a synchronization or GC has finished.

6 months agoFix bogus worker for newtypes
Simon Peyton Jones [Wed, 16 Jan 2019 16:34:24 +0000 (16:34 +0000)] 
Fix bogus worker for newtypes

The "worker" for a newtype is actually a function
with a small (compulsory) unfolding, namely a cast.

But the construction of this function was plain wrong
for newtype /instances/; it cast the arguemnt to the
family type rather than the representation type.

This never actually bit us because, in the case of a
family instance, we immediately cast the result to
the family type.  So we get
   \x. (x |> co1) |> co2

where the compositio of co1 and co2 is ill-kinded.
However the optimiser (even the simple optimiser)
just collapsed those casts, ignoring the mis-match
in the middle, so we never saw the problem.

Trac #16191 is indeed a dup of #16141; but the resaon
these tickets produce Lint errors is not the unnecessary
forcing; it's because of the ill-typed casts.

This patch fixes the ill-typed casts, properly.  I can't
see a way to trigger an actual failure prior to this
patch, but it's still wrong wrong wrong to have ill-typed
casts, so better to get rid of them.

6 months agoExtend linker-script workaround to work with musl libc
Samuel Holland [Mon, 21 Jan 2019 02:20:16 +0000 (20:20 -0600)] 
Extend linker-script workaround to work with musl libc

GHC has code to handle unsuffixed .so files that are linker scripts
pointing to the real shared library. The detection is done by parsing
the result of `dlerror()` after calling `dlopen()` and looking for
certain error strings. On musl libc, the error message is "Exec format
error", which happens to be `strerror(ENOEXEC)`:

$ cat tmp.c
#include <dlfcn.h>
#include <stdio.h>

int main(void) {
        dlopen("", RTLD_NOW | RTLD_GLOBAL);
        return 0;
$ gcc -o tmp tmp.c
$ ./tmp
Error loading shared library Exec format error

This change fixes the workaround to also work on musl libc.

6 months agoAdd CODEOWNERS
Ben Gamari [Mon, 21 Jan 2019 19:42:13 +0000 (14:42 -0500)] 

GitLab uses this file to suggest reviewers based upon the files that a Merge
Request touches.


6 months agogitlab: Add merge request template
Ben Gamari [Sat, 19 Jan 2019 20:47:33 +0000 (15:47 -0500)] 
gitlab: Add merge request template

This begins to define our expectations of contributions.


6 months agoFix typo in TcRnTypes.hs [skip ci]
Matthew Pickering [Mon, 21 Jan 2019 17:17:20 +0000 (12:17 -0500)] 
Fix typo in TcRnTypes.hs [skip ci]

6 months agoAdd support for ASM foreign files (.s) in TH (#16180)
Sylvain Henry [Tue, 15 Jan 2019 12:14:45 +0000 (13:14 +0100)] 
Add support for ASM foreign files (.s) in TH (#16180)

6 months agoRemove TODO in HsExpr
Matthew Pickering [Fri, 18 Jan 2019 16:36:12 +0000 (11:36 -0500)] 
Remove TODO in HsExpr

It is correct to be `GhcTc` as the data type is for expressions which are inside splices
so they can be delayed until desugaring.

6 months agoMention DerivingStrategies in the warning when DAC and GND are both enabled
Chaitanya Koparkar [Mon, 14 Jan 2019 19:36:29 +0000 (14:36 -0500)] 
Mention DerivingStrategies in the warning when DAC and GND are both enabled


When DeriveAnyClass and GeneralizedNewtypeDeriving are both enabled,
GHC prints out a warning that specifies the strategy it used to
derive a class. This patch updates the warning to mention that users
may pick a particular strategy by using DerivingStrategies.

Test plan: make test TEST=T16179

6 months ago[T16199] Adds a verify-packages script
Moritz Angermann [Sun, 20 Jan 2019 10:24:21 +0000 (05:24 -0500)] 
[T16199] Adds a verify-packages script

7 months agoPrepare source-tree for base-4.13 MFP bump
Herbert Valerio Riedel [Tue, 18 Dec 2018 22:36:29 +0000 (23:36 +0100)] 
Prepare source-tree for base-4.13 MFP bump

7 months agoFix typo in DsExpr
Matthew Pickering [Fri, 18 Jan 2019 13:35:08 +0000 (08:35 -0500)] 
Fix typo in DsExpr

7 months agoComments in stranal test declarations
Ömer Sinan Ağacan [Fri, 18 Jan 2019 08:51:59 +0000 (11:51 +0300)] 
Comments in stranal test declarations

7 months agoSmall refactor
Simon Peyton Jones [Thu, 10 Jan 2019 12:08:47 +0000 (12:08 +0000)] 
Small refactor use the same error message rather than duplicating it

7 months agoRemove export of checkValidFamPats, never used
Simon Peyton Jones [Thu, 10 Jan 2019 12:08:15 +0000 (12:08 +0000)] 
Remove export of checkValidFamPats, never used

7 months agoComments about data constructor wrappers
Simon Peyton Jones [Thu, 10 Jan 2019 12:07:57 +0000 (12:07 +0000)] 
Comments about data constructor wrappers

7 months ago'DynFlag'-free version of 'mkParserFlags'
Alec Theriault [Tue, 8 Jan 2019 20:07:07 +0000 (12:07 -0800)] 
'DynFlag'-free version of 'mkParserFlags'

This is a fixed version of the reverted d2fbc33c4ff3074126ab71654af8bbf8a46e4e11
and  5aa29231ab7603537284eff5e4caff3a73dba6d2.

Obtaining a `DynFlags` is difficult, making using the lexer/parser
for pure parsing/lexing unreasonably difficult, even with `mkPStatePure`.
This is despite the fact that we only really need

    * language extension flags
    * warning flags
    * a handful of boolean options

The new `mkParserFlags'` function makes is easier to directly construct a
`ParserFlags`. Furthermore, since `pExtsBitmap` is just a footgun, I've gone
ahead and made `ParserFlags` an abstract type.

Also, we now export `ExtBits` and `getBit` instead of defining/exporting a
bunch of boilerplate functions that test for a particular 'ExtBits'.
In the process, I also

  * cleaned up an unneeded special case for `ITstatic`
  * made `UsePosPrags` another variant of `ExtBits`
  * made the logic in `reservedSymsFM` match that of `reservedWordsFM`

Test Plan: make test

Reviewers: bgamari, alanz, tdammers

Subscribers: sjakobi, tdammers, rwbarton, mpickering, carter

GHC Trac Issues: #11301

Differential Revision:

7 months agoPPC NCG: Rename constructors
Peter Trommler [Thu, 3 Jan 2019 13:04:37 +0000 (14:04 +0100)] 
PPC NCG: Rename constructors

Rename constructors in calling convention data type to reflect the
fact that they represent an ELF ABI not only a Linux ABI.

7 months agoFix tab and improve whitespace
Peter Trommler [Sat, 29 Dec 2018 10:29:02 +0000 (11:29 +0100)] 
Fix tab and improve whitespace

7 months agoPPC NCG: Register definitions for all 64-bit systems
Peter Trommler [Sat, 29 Dec 2018 09:14:12 +0000 (10:14 +0100)] 
PPC NCG: Register definitions for all 64-bit systems

7 months agoPPC NCG: GOT declaration for all 64-bit ELF systems
Peter Trommler [Sat, 29 Dec 2018 09:12:48 +0000 (10:12 +0100)] 
PPC NCG: GOT declaration for all 64-bit ELF systems

7 months agoPPC NCG: Make `stackHeaderSize` more general
Peter Trommler [Fri, 28 Dec 2018 22:55:35 +0000 (23:55 +0100)] 
PPC NCG: Make `stackHeaderSize` more general

7 months agoPPC NCG: Make calling convention more general
Peter Trommler [Fri, 28 Dec 2018 22:52:31 +0000 (23:52 +0100)] 
PPC NCG: Make calling convention more general

All operating systems except AIX and Darwin follow the ELF

7 months agoRTS: Use ELF v1 convention on all powerpc64 systems
Peter Trommler [Fri, 28 Dec 2018 21:30:34 +0000 (22:30 +0100)] 
RTS: Use ELF v1 convention on all powerpc64 systems

7 months agoAdd test for #16197
Ömer Sinan Ağacan [Thu, 17 Jan 2019 13:57:20 +0000 (16:57 +0300)] 
Add test for #16197

7 months agoDocumentation for StgRetFun
Ömer Sinan Ağacan [Wed, 16 Jan 2019 06:47:35 +0000 (09:47 +0300)] 
Documentation for StgRetFun

7 months agoMake sure 'haddock' package also copies resources
Alec Theriault [Thu, 10 Jan 2019 12:37:36 +0000 (04:37 -0800)] 
Make sure 'haddock' package also copies resources

...and does so in the lib folder of the right stage

7 months agoHadrian: handle Haddock's resource directory
Alec Theriault [Thu, 10 Jan 2019 11:45:06 +0000 (03:45 -0800)] 
Hadrian: handle Haddock's resource directory

Fixes #16105

  * Require Haddock's resource as runtime dependencies of the Haddock
    builder. This means we no longer have to `need` particular resources
    in every other documentation rule.

  * Do a _tracked_ copy of both the 'html' and 'latex' folder resource

  * Move resources into `stage1/lib` (NB: the `haddock` binary goes in
    `stage1/bin`). Besides now actually matching the Haddock script
    wrapper generated by BinaryDist, this also prepares for Haddock
    in relocatable build folder detecting its own resources.

7 months agoImprove clarity of documentation for maybeToList
Steve Hart [Thu, 10 Jan 2019 13:30:47 +0000 (08:30 -0500)] 
Improve clarity of documentation for maybeToList

7 months agoRevert "Fix typo in maybeToList documentation"
Steve Hart [Thu, 10 Jan 2019 13:29:29 +0000 (08:29 -0500)] 
Revert "Fix typo in maybeToList documentation"

This reverts commit af210f40ce7ad7b3351abc988b0351446e8b639e