11 months agoFix #15572 by checking for promoted names in ConT
Ryan Scott [Tue, 28 Aug 2018 18:54:28 +0000 (20:54 +0200)] 
Fix #15572 by checking for promoted names in ConT

When converting `ConT`s to `HsTyVar`s in `Convert`, we were
failing to account for the possibility of promoted data constructor
names appearing in a `ConT`, which could result in improper
pretty-printing results (as observed in #15572). The fix is
straightforward: use `Promoted` instead of `NotPromoted` when the
name of a `ConT` is a data constructor name.

Test Plan: make test TEST=T15572

Reviewers: goldfire, bgamari, simonpj, monoidal

Reviewed By: goldfire, simonpj

Subscribers: monoidal, rwbarton, carter

GHC Trac Issues: #15572

Differential Revision:

(cherry picked from commit c46a5f2002f6694ea58f79f505d57f3b7bd450e7)

11 months agoFix #15550 by quoting RULE names during TH conversion
Ryan Scott [Mon, 27 Aug 2018 12:02:42 +0000 (14:02 +0200)] 
Fix #15550 by quoting RULE names during TH conversion

When converting a `RuleP` to a GHC source `RuleD` during TH
conversion, we were stupidly not double-quoting the name of the rule.
Easily fixed.

Test Plan: make test TEST=T15550

Reviewers: goldfire, bgamari, simonpj

Reviewed By: simonpj

Subscribers: simonpj, rwbarton, carter

GHC Trac Issues: #15550

Differential Revision:

(cherry picked from commit 5e6cf2a9301a5473ff9c5319b96de941b1ad72dd)

11 months agocanCFunEqCan: use isTcReflexiveCo (not isTcReflCo)
Simon Peyton Jones [Mon, 3 Sep 2018 08:00:49 +0000 (09:00 +0100)] 
canCFunEqCan: use isTcReflexiveCo (not isTcReflCo)

As Trac #15577 showed, it was possible for a /homo-kinded/
constraint to trigger the /hetero-kinded/ branch of canCFunEqCan,
and that triggered an infinite loop.

The fix is easier, but there remains a deeper questions: why is
the flattener producing giant refexive coercions?

(cherry picked from commit 2e226a46c422c12f78dc3d3f62fe5a15e22bd986)

11 months agoFix #15502 by not casting to Int during TH conversion
Ryan Scott [Mon, 27 Aug 2018 12:02:49 +0000 (14:02 +0200)] 
Fix #15502 by not casting to Int during TH conversion

When turning an `IntegerL` to an `IntegralLit` during TH
conversion, we were stupidly casting an `Integer` to an `Int` in
order to determine how it should be pretty-printed. Unsurprisingly,
this causes problems when the `Integer` doesn't lie within the bounds
of an `Int`, as demonstrated in #15502.

The fix is simple: don't cast to an `Int`.

Test Plan: make test TEST=T15502

Reviewers: bgamari, simonpj

Reviewed By: simonpj

Subscribers: simonpj, rwbarton, carter

GHC Trac Issues: #15502

Differential Revision:

(cherry picked from commit 7a3cda534d1447c813aa37cdd86e20b8d782cb02)

11 months agoRevert "An overhaul of the SRT representation"
Ben Gamari [Wed, 12 Sep 2018 19:17:15 +0000 (15:17 -0400)] 
Revert "An overhaul of the SRT representation"

This reverts commit eb8e692cab7970c495681e14721d05ecadd21581.

11 months agoRevert "Save a word in the info table on x86_64"
Ben Gamari [Wed, 12 Sep 2018 19:14:08 +0000 (15:14 -0400)] 
Revert "Save a word in the info table on x86_64"

This reverts commit 2b0918c9834be1873728176e4944bec26271234a.

11 months agoRevert "Merge FUN_STATIC closure with its SRT"
Ben Gamari [Wed, 12 Sep 2018 19:09:20 +0000 (15:09 -0400)] 
Revert "Merge FUN_STATIC closure with its SRT"

This reverts commit 838b69032566ce6ab3918d70e8d5e098d0bcee02.

11 months agoRevert "Comments and refactoring only"
Ben Gamari [Wed, 12 Sep 2018 19:07:44 +0000 (15:07 -0400)] 
Revert "Comments and refactoring only"

This reverts commit f2d27c1ad69321872a87a37144fe41e815301f5b.

11 months agoRevert "Fix retainer profiling after SRT overhaul"
Ben Gamari [Wed, 12 Sep 2018 19:06:29 +0000 (15:06 -0400)] 
Revert "Fix retainer profiling after SRT overhaul"

This reverts commit d78dde9ff685830bc9d6bb24a158eb31bb8a7028.

11 months agoRevert "Fix a bug in SRT generation"
Ben Gamari [Wed, 12 Sep 2018 19:06:18 +0000 (15:06 -0400)] 
Revert "Fix a bug in SRT generation"

This reverts commit d424d4a46a729f8530e9273282d22b6b8f34daaa.

11 months agoRevert "Disable the SRT offset optimisation on MachO platforms"
Simon Marlow [Thu, 26 Jul 2018 21:19:54 +0000 (17:19 -0400)] 
Revert "Disable the SRT offset optimisation on MachO platforms"

This reverts commit bf10456edaa03dc010821cd4c3d9f49cb11d89da.

11 months agoRevert incorrect STM wakeup optimisation
Ömer Sinan Ağacan [Tue, 11 Sep 2018 18:43:50 +0000 (20:43 +0200)] 
Revert incorrect STM wakeup optimisation

Summary: (see the comments)

Reviewers: simonmar, bgamari, erikd

Reviewed By: simonmar

Subscribers: rwbarton, carter

Differential Revision:

(cherry picked from commit 36740b4c346c619e31d24d6672caa6f4f7fea123)

11 months agoFix gcCAFs()
Simon Marlow [Thu, 26 Jul 2018 21:19:54 +0000 (17:19 -0400)] 
Fix gcCAFs()

The test here should have been changed after D1106.  It was harmless
but we caught fewer GC'd CAFs than we should have.

Test Plan:
Using `nofib/imaginary/primes` compiled with `-debug`.

> ./primes 100 +RTS -G1 -A32k -DG
CAF gc'd at 0x0x7b0960
CAF gc'd at 0x0x788728
CAF gc'd at 0x0x790db0
CAF gc'd at 0x0x790de0
12 CAFs live
CAF gc'd at 0x0x788880
12 CAFs live
12 CAFs live
12 CAFs live
12 CAFs live
12 CAFs live
12 CAFs live
12 CAFs live
12 CAFs live
12 CAFs live
12 CAFs live
12 CAFs live
CAF gc'd at 0x0x7995c8
13 CAFs live


> ./primes 100 +RTS -G1 -A32k -DG
CAF gc'd at 0x0x7b0960
CAF gc'd at 0x0x788728
CAF gc'd at 0x0x790db0
CAF gc'd at 0x0x790de0
12 CAFs live
CAF gc'd at 0x0x788880
12 CAFs live
12 CAFs live
12 CAFs live
12 CAFs live
12 CAFs live
12 CAFs live
12 CAFs live
12 CAFs live
12 CAFs live
12 CAFs live
12 CAFs live
CAF gc'd at 0x0x7995c8
CAF gc'd at 0x0x790ea0
12 CAFs live

Reviewers: bgamari, osa1, erikd, noamz

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

Differential Revision:

(cherry picked from commit e431d75f8350f25159f9aaa49fe9a504e94bc0a4)

11 months agotemplate-haskell: Fix typo in changelog
Ben Gamari [Mon, 10 Sep 2018 02:23:16 +0000 (22:23 -0400)] 
template-haskell: Fix typo in changelog

11 months agorts: Handle SMALL_MUT_ARR_PTRS in retainer profilter
Ben Gamari [Mon, 27 Aug 2018 22:59:17 +0000 (00:59 +0200)] 
rts: Handle SMALL_MUT_ARR_PTRS in retainer profilter

Summary: These can be treated similarly to MUT_ARRY_PTRS. Fixes #15529.

Reviewers: erikd, simonmar

Reviewed By: simonmar

Subscribers: RyanGlScott, rwbarton, carter

GHC Trac Issues: #15529

Differential Revision:

(cherry picked from commit 2cf98e2207421200fc73c25a08f6435859cdff92)

11 months agoFixed typo in exponent example
chris-bacon [Mon, 27 Aug 2018 12:45:47 +0000 (13:45 +0100)] 
Fixed typo in exponent example

(cherry picked from commit 36c1431d9d2d06049190cc0888dbfaee8e2179d6)

11 months agoFix a constant folding rule
Andrey Mokhov [Wed, 29 Aug 2018 13:16:51 +0000 (15:16 +0200)] 
Fix a constant folding rule

One of the constant folding rules introduced in D2858 is:

(L y :-:   v) :-: (L x :-: w) -> return $ mkL (y-x)   `add` (w `add` v)

Or, after removing syntactic noise: `(y - v) - (x - w) ==> (y - x) + (w + v)`.
This is incorrect, since the sign of `v` is changed from negative to positive.
As a consequence, the following program prints `3` when compiled with `-O`:

-- This is just subtraction in disguise
minus :: Int -> Int -> Int
minus x y = (8 - y) - (8 - x)
{-# NOINLINE minus #-}

main :: IO ()
main = print (2 `minus` 1)

The correct rule is: `(y - v) - (x - w) ==> (y - x) + (w - v)`.

This commit does the fix. I haven't found any other issues with the constant
folding code, but it's difficult to be certain without some automated checking.

Reviewers: bgamari, tdammers

Subscribers: hsyl20, tdammers, rwbarton, carter

GHC Trac Issues: #15569

Differential Revision:

(cherry picked from commit 65eec9cfd4410c0e30b0ed06116c15f8ce3de49d)

11 months agoFix typo in 8.6.1 notes
Krzysztof Gogolewski [Tue, 28 Aug 2018 20:31:22 +0000 (22:31 +0200)] 
Fix typo in 8.6.1 notes

(cherry picked from commit 34b8e613606653187f1ffae36a83e33f0c673720)

11 months agoSkip eventlog tests in GHCi way
Ömer Sinan Ağacan [Wed, 5 Sep 2018 11:11:30 +0000 (13:11 +0200)] 
Skip eventlog tests in GHCi way

Summary: (GHCi doesn't generate event logs)

Test Plan:
These tests were failing in GHCi way, they're now skipped in GHCi way as GHCi
doesn't generate eventlogs

Reviewers: bgamari, simonmar, maoe, alpmestan

Reviewed By: alpmestan

Subscribers: rwbarton, carter

GHC Trac Issues: #15587

Differential Revision:

(cherry picked from commit c0e5087d01e2912f00feede6c259a2ee87685c90)

11 months agoFix a race between GC threads in concurrent scavenging
Ömer Sinan Ağacan [Thu, 6 Sep 2018 12:52:53 +0000 (15:52 +0300)] 
Fix a race between GC threads in concurrent scavenging

While debugging #15285 I realized that free block lists (free_list in
BlockAlloc.c) get corrupted when multiple scavenge threads allocate and
release blocks concurrently. Here's a picture of one such race:

    Thread 2 (Thread 32573.32601):
    #0  check_tail
        (bd=0x940d40 <stg_TSO_info>) at rts/sm/BlockAlloc.c:860
    #1  0x0000000000928ef7 in checkFreeListSanity
        () at rts/sm/BlockAlloc.c:896
    #2  0x0000000000928979 in freeGroup
        (p=0x7e998ce02880) at rts/sm/BlockAlloc.c:721
    #3  0x0000000000928a17 in freeChain
        (bd=0x7e998ce02880) at rts/sm/BlockAlloc.c:738
    #4  0x0000000000926911 in freeChain_sync
        (bd=0x7e998ce02880) at rts/sm/GCUtils.c:80
    #5  0x0000000000934720 in scavenge_capability_mut_lists
        (cap=0x1acae80) at rts/sm/Scav.c:1665
    #6  0x000000000092b411 in gcWorkerThread
        (cap=0x1acae80) at rts/sm/GC.c:1157
    #7  0x000000000090be9a in yieldCapability
        (pCap=0x7f9994e69e20, task=0x7e9984000b70, gcAllowed=true) at rts/Capability.c:861
    #8  0x0000000000906120 in scheduleYield
        (pcap=0x7f9994e69e50, task=0x7e9984000b70) at rts/Schedule.c:673
    #9  0x0000000000905500 in schedule
        (initialCapability=0x1acae80, task=0x7e9984000b70) at rts/Schedule.c:293
    #10 0x0000000000908d4f in scheduleWorker
        (cap=0x1acae80, task=0x7e9984000b70) at rts/Schedule.c:2554
    #11 0x000000000091a30a in workerStart
        (task=0x7e9984000b70) at rts/Task.c:444
    #12 0x00007f99937fa6db in start_thread
        (arg=0x7f9994e6a700) at pthread_create.c:463
    #13 0x000061654d59f88f in clone
        () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

    Thread 1 (Thread 32573.32573):
    #0  checkFreeListSanity
        () at rts/sm/BlockAlloc.c:887
    #1  0x0000000000928979 in freeGroup
        (p=0x7e998d303540) at rts/sm/BlockAlloc.c:721
    #2  0x0000000000926f23 in todo_block_full
        (size=513, ws=0x1aa8ce0) at rts/sm/GCUtils.c:264
    #3  0x00000000009583b9 in alloc_for_copy
        (size=513, gen_no=0) at rts/sm/Evac.c:80
    #4  0x000000000095850d in copy_tag_nolock
        (p=0x7e998c675f28, info=0x421d98 <Main_Large_con_info>, src=0x7e998d075d80, size=513,
        gen_no=0, tag=1) at rts/sm/Evac.c:153
    #5  0x0000000000959177 in evacuate
        (p=0x7e998c675f28) at rts/sm/Evac.c:715
    #6  0x0000000000932388 in scavenge_small_bitmap
        (p=0x7e998c675f28, size=1, bitmap=0) at rts/sm/Scav.c:271
    #7  0x0000000000934aaf in scavenge_stack
        (p=0x7e998c675f28, stack_end=0x7e998c676000) at rts/sm/Scav.c:1908
    #8  0x0000000000934295 in scavenge_one
        (p=0x7e998c66e000) at rts/sm/Scav.c:1466
    #9  0x0000000000934662 in scavenge_mutable_list
        (bd=0x7e998d300440, gen=0x1b1d880) at rts/sm/Scav.c:1643
    #10 0x0000000000934700 in scavenge_capability_mut_lists
        (cap=0x1aaa340) at rts/sm/Scav.c:1664
    #11 0x00000000009299b6 in GarbageCollect
        (collect_gen=0, do_heap_census=false, gc_type=2, cap=0x1aaa340, idle_cap=0x1b38aa0)
        at rts/sm/GC.c:378
    #12 0x0000000000907a4a in scheduleDoGC
        (pcap=0x7ffdec5b5310, task=0x1b36650, force_major=false) at rts/Schedule.c:1798
    #13 0x0000000000905de7 in schedule
        (initialCapability=0x1aaa340, task=0x1b36650) at rts/Schedule.c:546
    #14 0x0000000000908bc4 in scheduleWaitThread
        (tso=0x7e998c0067c8, ret=0x0, pcap=0x7ffdec5b5430) at rts/Schedule.c:2537
    #15 0x000000000091b5a0 in rts_evalLazyIO
        (cap=0x7ffdec5b5430, p=0x9c11f0, ret=0x0) at rts/RtsAPI.c:530
    #16 0x000000000091ca56 in hs_main
        (argc=1, argv=0x7ffdec5b5628, main_closure=0x9c11f0, rts_config=...) at rts/RtsMain.c:72
    #17 0x0000000000421ea0 in main

In particular, dbl_link_onto() which is used to add a freed block to a
doubly-linked free list is not thread safe and corrupts the list when
called concurrently.

Note that thread 1 is to blame here as thread 2 is properly taking the
spinlock. With this patch we now take the spinlock when freeing a todo
block in GC, avoiding this race.

Test Plan:
- Tried slow validate locally: this patch does not introduce new failures.
- circleci: The test got killed
  because it took 5 hours but T7919 (which was previously failing on circleci)

Reviewers: simonmar, bgamari, erikd

Reviewed By: simonmar

Subscribers: rwbarton, carter

GHC Trac Issues: #15285

Differential Revision:

(cherry picked from commit c6fbac6a6a69a2f4be89701b2c386ae53214f9a3)

11 months agoBump Cabal submodule to
Ben Gamari [Fri, 7 Sep 2018 11:14:43 +0000 (07:14 -0400)] 
Bump Cabal submodule to

11 months agoDo a final pass over the changelogs
Ben Gamari [Tue, 28 Aug 2018 13:42:39 +0000 (09:42 -0400)] 
Do a final pass over the changelogs

11 months agoExpose the StableName constructor
David Feuer [Tue, 21 Aug 2018 00:08:14 +0000 (20:08 -0400)] 
Expose the StableName constructor

* Move the definition of `StableName` from `System.Mem.StableName`
  to a new `GHC.StableName` module.

* Expose the `StableName` data constructor from `GHC.StableName`.
  Once we have `UnliftedArray#`, this will enable `StableName`s to
  be stored in `UnliftedArray`s (from `primitive`) without unsafe

Reviewers: hvr, bgamari, andrewthad, osa1

Reviewed By: osa1

Subscribers: osa1, rwbarton, carter

GHC Trac Issues: #15535

Differential Revision:

(cherry picked from commit 9c4e6c6b1affd410604f8f76ecf56abfcc5cccb6)

11 months agoProperly designate LambdaCase alts as CaseAlt in TH
Ryan Scott [Tue, 14 Aug 2018 20:35:23 +0000 (22:35 +0200)] 
Properly designate LambdaCase alts as CaseAlt in TH

When `\case` expressions are parsed normally, their
alternatives are marked as `CaseAlt` (which means that they are
pretty-printed without a `\` character in front of them, unlike for
lambda expressions). However, `\case` expressions created by way of
Template Haskell (in `Convert`) inconsistently designated the case
alternatives as `LambdaExpr`, causing them to be pretty-printed
poorly (as shown in #15518). The fix is simple: use `CaseAlt`

Test Plan: make test TEST=T15518

Reviewers: goldfire, bgamari

Subscribers: rwbarton, carter

GHC Trac Issues: #15518

Differential Revision:

(cherry picked from commit 32008a9d0e09f0cc8899aa871d9a6b63fcc28a1a)

11 months agoSuppress redundant givens during error reporting
Ryan Scott [Sun, 12 Aug 2018 15:27:27 +0000 (17:27 +0200)] 
Suppress redundant givens during error reporting

When GHC reports that it cannot solve a constraint in error
messages, it often reports what given constraints it has in scope.
Unfortunately, sometimes redundant constraints (like `* ~ *`,
from  #15361) can sneak in. The fix is simple: blast away these
redundant constraints using `mkMinimalBySCs`.

Test Plan: make test TEST=T15361

Reviewers: simonpj, bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15361

Differential Revision:

(cherry picked from commit c552feea127d8ed8cbf4994a157c4bbe254b96c3)

11 months ago--show-iface: Qualify all non-local names
Simon Jakobi [Sun, 12 Aug 2018 09:10:39 +0000 (11:10 +0200)] 
--show-iface: Qualify all non-local names

In order to disambiguate names from different modules, qualify all names
that don't originate in the current module.

Also update docs for QueryQualifyName

Test Plan: validate

Reviewers: simonpj, bgamari

Reviewed By: simonpj

Subscribers: rwbarton, thomie, carter, tdammers

GHC Trac Issues: #15269

Differential Revision:

(cherry picked from commit d42eef344a71990d12f27e88cdf10ba0b2a2f34b)

11 months agoAccommodate API change in transSuperClasses
Simon Peyton Jones [Thu, 23 Aug 2018 08:22:42 +0000 (09:22 +0100)] 
Accommodate API change in transSuperClasses

In this patch

    commit 6eabb6ddb7c53784792ee26b1e0657bde7eee7fb
    Author: Simon Peyton Jones <>
    Date:   Tue Dec 15 14:26:13 2015 +0000

    Allow recursive (undecidable) superclasses

I changed (transSuperClasses p) to return only the
superclasses of p, but not p itself. (Previously it always
returned p as well.)

The use of transSuperClasses in TcErrors.warnRedundantConstraints
really needs 'p' in the result -- but I faild to fix this
call site, and instead crippled the test for Trac #10100.

This patch sets things right

* Accomodates the API change
* Re-enables T10100
* And thereby fixes Trac #11474

(cherry picked from commit 4293a80a3ea835412737911bcb2a6703e9af378b)

11 months agoFix a typo in TcValidity.checkFamInstRhs
Simon Peyton Jones [Wed, 22 Aug 2018 09:00:20 +0000 (10:00 +0100)] 
Fix a typo in TcValidity.checkFamInstRhs

In error message generation we were using the wrong
type constructor in inst_head.  Result: the type became
ill-kinded, and that sent the compiler into a loop.

A separate patch fixes the loop. This patch fixes the
actual bug -- Trac #15473.

I also improved the "occurs more often" error message
a bit.  But it's still pretty terrible:

    * Variable ‘a’ occurs more often
      in the type family application ‘Undefined’
      than in the instance head ‘LetInterleave xs t ts is y z’

It looks like nonsense, but all becomes clear if you use
-fprint-explicit-kinds.  Really we should fix this by spotting
when invisible arguments are involved and at least suggesting

(cherry picked from commit 8c7f90abcc1e8f9f29b751f23174e8db89ba6983)

11 months agoTurn infinite loop into a panic
Simon Peyton Jones [Wed, 22 Aug 2018 08:51:26 +0000 (09:51 +0100)] 
Turn infinite loop into a panic

In these two functions
  * TcIface.toIfaceAppTyArgsX
  * Type.piResultTys
we take a type application (f t1 .. tn) and try to find
its kind. It turned out that, if (f t1 .. tn) was ill-kinded
the function would go into an infinite loop.

That's not good: it caused the loop in Trac #15473.

This patch doesn't fix the bug in #15473, but it does turn the
loop into a decent panic, which is a step forward.

(cherry picked from commit db6f1d9cfc74690798645a7cc5b25040c36bb35d)

11 months agotestsuite: Add (broken) test for #15473
Ben Gamari [Tue, 7 Aug 2018 17:59:31 +0000 (13:59 -0400)] 
testsuite: Add (broken) test for #15473

(cherry picked from commit 5487f305d9dea298f0822082389d8a0225956c55)

11 months agoExplicitly tell 'getNameToInstances' mods to load
Alec Theriault [Tue, 21 Aug 2018 20:03:40 +0000 (16:03 -0400)] 
Explicitly tell 'getNameToInstances' mods to load

Calculating which modules to load based on the InteractiveContext means
maintaining a potentially very large GblRdrEnv.

In Haddock's case, it is much cheaper (from a memory perspective) to
just keep track of which modules interfaces we want loaded then hand
these off explicitly to 'getNameToInstancesIndex'.

Bumps haddock submodule.

Reviewers: alexbiehl, bgamari

Reviewed By: alexbiehl

Subscribers: rwbarton, thomie, carter

Differential Revision:

(cherry picked from commit c971e1193fa44bb507d1806d5bb61768670dc912)

11 months agoCorrect limb length and assertion for gcdExtInteger
DavidEichamnn [Tue, 21 Aug 2018 20:06:45 +0000 (16:06 -0400)] 
Correct limb length and assertion for gcdExtInteger

Reviewers: hvr, bgamari, monoidal

Reviewed By: monoidal

Subscribers: monoidal, rwbarton, thomie, carter

GHC Trac Issues: #15350

Differential Revision:

(cherry picked from commit c331592130ef592b92084e7417581a4039bfa7d2)

11 months agoFix gcdExtInteger (trac#15350)
Bodigrim [Fri, 6 Jul 2018 23:20:10 +0000 (00:20 +0100)] 
Fix gcdExtInteger (trac#15350)

(cherry picked from commit 7c207c86ab0de955ebec70eeeb366ba0d94acc4a)

12 months agorts: Align the_gc_thread to 64 bytes
Ben Gamari [Tue, 21 Aug 2018 20:06:12 +0000 (16:06 -0400)] 
rts: Align the_gc_thread to 64 bytes

In a previous attempt (c6cc93bca69abc258513af8cf2370b14e70fd8fb) I had
tried aligning to 8 bytes under the assumption that the problem was that
the_gc_thread, a StgWord8[], wasn't being aligned to 8-bytes as the
gc_thread struct would expect. However, we actually need even stronger
alignment due to the alignment attribute attached to gen_workspace,
which claims it should be aligned to a 64-byte boundary.

This fixes #15482.

Reviewers: erikd, simonmar

Reviewed By: simonmar

Subscribers: rwbarton, carter

GHC Trac Issues: #15482

Differential Revision:

(cherry picked from commit 68a1fc29b4bb3eae54e4d96c9aec20e700040f34)

12 months agoSet strictness correctly for JoinIds
Simon Peyton Jones [Tue, 21 Aug 2018 08:56:39 +0000 (09:56 +0100)] 
Set strictness correctly for JoinIds

We were failing to keep correct strictness info when eta-expanding
join points; Trac #15517.   The situation was something like

  \q v eta ->
     let j x = error "blah
         -- STR Lx   bottoming!
     in case y of
           A -> j x eta
           B -> blah
           C -> j x eta

So we spot j as a join point and eta-expand it.  But we must
also adjust the stricness info, else it vlaimes to bottom after
one arg is applied but now it has become two.

I fixed this in two places:

 - In CoreOpt.joinPointBinding_maybe, adjust strictness info

 - In SimplUtils.tryEtaExpandRhs, return consistent values
   for arity and bottom-ness

(cherry picked from commit ce6ce788251b6102f5c1b878ffec53ba7ad678b5)

12 months agoBe mindful of GADT tyvar order when desugaring record updates
Ryan Scott [Fri, 17 Aug 2018 14:31:27 +0000 (16:31 +0200)] 
Be mindful of GADT tyvar order when desugaring record updates

After commit ef26182e2014b0a2a029ae466a4b121bf235e4e4,
the type variable binders in GADT constructor type signatures
are now quantified in toposorted order, instead of always having
all the universals before all the existentials. Unfortunately, that
commit forgot to update some code (which was assuming the latter
scenario) in `DsExpr` which desugars record updates. This wound
up being the cause of #15499.

This patch makes up for lost time by desugaring record updates in
a way such that the desugared expression applies type arguments to
the right-hand side constructor in the correct order—that is, the
order in which they were quantified by the user.

Test Plan: make test TEST=T15499

Reviewers: simonpj, bgamari

Reviewed By: simonpj

Subscribers: rwbarton, carter

GHC Trac Issues: #15499

Differential Revision:

(cherry picked from commit 63b6a1d44849c479d2a7cb59211f5c64d133bc62)

12 months agoBump stm submodule
Ben Gamari [Mon, 20 Aug 2018 19:04:31 +0000 (15:04 -0400)] 
Bump stm submodule

12 months agoCheck if files are same in combineSrcSpans
Zubin Duggal [Sun, 12 Aug 2018 13:51:29 +0000 (15:51 +0200)] 
Check if files are same in combineSrcSpans

Summary: If this is not checked, SrcSpans are sometimes mangled by CPP.

Test Plan: ./validate

Reviewers: bgamari, dfeuer

Reviewed By: bgamari

Subscribers: dfeuer, rwbarton, thomie, carter

GHC Trac Issues: #15279

Differential Revision:

(cherry picked from commit f7f9820e8f5601e9a072e504f3d772fd78df6700)

12 months agoFix #15527 by pretty-printing an RdrName prefixly
Ryan Scott [Thu, 16 Aug 2018 09:53:33 +0000 (11:53 +0200)] 
Fix #15527 by pretty-printing an RdrName prefixly

When `(.) @Int` is used without enabling `TypeApplications`,
the resulting error message will pretty-print the (symbolic)
`RdrName` `(.)`. However, it does so without parenthesizing it, which
causes the pretty-printed expression to appear as `.@Int`. Yuck.

Since the expression in a type application will always be prefix,
we can fix this issue by using `pprPrefixOcc` instead of plain ol'

Test Plan: make test TEST=T15527

Reviewers: bgamari, monoidal, simonpj

Reviewed By: monoidal, simonpj

Subscribers: rwbarton, carter

GHC Trac Issues: #15527

Differential Revision:

(cherry picked from commit 5238f204482ac7f05f4e2d2e92576288cc00d42d)

12 months agoFilter plugin dylib locations
Christiaan Baaij [Sat, 11 Aug 2018 16:56:34 +0000 (18:56 +0200)] 
Filter plugin dylib locations

Previously we just created a cartesian product of the library
paths of the plugin package and the libraries of the package.
Of course, some of these combinations result in a filepath of
a file doesn't exists, leading to #15475.

Instead of making `haskFile` return Nothing in case a file
doesn't exist (which would hide errors), we look at all the
possible dylib locations and ensure that at least one of those
locations is an existing file. If the list turns out to be
empty however, we panic.

Reviewers: mpickering, bgamari

Reviewed By: mpickering

Subscribers: monoidal, rwbarton, carter

GHC Trac Issues: #15475

Differential Revision:

(cherry picked from commit b324c5624432f2c3d5b0a689fdff75a1ccc563f5)

12 months agoBump parsec submodule
Ben Gamari [Sat, 11 Aug 2018 16:00:44 +0000 (12:00 -0400)] 
Bump parsec submodule

12 months agoRevert "rts: Ensure that the_gc_thread is aligned" ghc-8.6.1-beta1
Ben Gamari [Fri, 10 Aug 2018 13:21:05 +0000 (09:21 -0400)] 
Revert "rts: Ensure that the_gc_thread is aligned"

This reverts commit 87a79e394013e5f722496900227b126015d0d780.

12 months agotestsuite: Bump for unix 2.7
Ben Gamari [Thu, 9 Aug 2018 16:30:43 +0000 (12:30 -0400)] 
testsuite: Bump for unix 2.7

12 months agoBump unix submodule
Ben Gamari [Thu, 9 Aug 2018 15:28:04 +0000 (11:28 -0400)] 
Bump unix submodule

12 months agoAdd FreeBSD amd64 LLVM target
Viktor Dukhovni [Thu, 9 Aug 2018 05:47:02 +0000 (01:47 -0400)] 
Add FreeBSD amd64 LLVM target

(cherry picked from commit 396aac4c65a47b6252e0a73d2a3066e924d53f11)

12 months agocircleci: Reduce compression effort to 3
Ben Gamari [Wed, 8 Aug 2018 22:45:53 +0000 (18:45 -0400)] 
circleci: Reduce compression effort to 3

(cherry picked from commit 60e12f26a28ce4ed0ecb905baef207a0388947f1)

12 months agocircleci: Reduce build verbosity
Ben Gamari [Wed, 8 Aug 2018 19:53:42 +0000 (15:53 -0400)] 
circleci: Reduce build verbosity

(cherry picked from commit 5be646f251b25c22ba24ad2a4eb5af66b3f95d74)

12 months agocircleci: Fix documentation building
Ben Gamari [Fri, 3 Aug 2018 20:48:18 +0000 (16:48 -0400)] 
circleci: Fix documentation building

(cherry picked from commit 9f937142f67ccf1c8bff9bb809539deca39a7a6f)

12 months agoAllow arbitrary options to be passed to tar compression
Ben Gamari [Wed, 8 Aug 2018 20:08:02 +0000 (16:08 -0400)] 
Allow arbitrary options to be passed to tar compression

(cherry picked from commit 4d6dfc35c06abb747de318ada2f27985c9369a6d)

12 months agoBump Cabal submodule
Ben Gamari [Wed, 8 Aug 2018 00:10:01 +0000 (20:10 -0400)] 
Bump Cabal submodule

12 months agoBump binary submodule to
Ben Gamari [Mon, 6 Aug 2018 22:39:35 +0000 (18:39 -0400)] 
Bump binary submodule to

This is actually a decrease in the version number since a bump to 0.10
wasn't actually necessary.

(cherry picked from commit 960a7d17a79417300ee81e884e867bf3de4e535b)

12 months agoBump hadrian submodule
Ben Gamari [Sun, 5 Aug 2018 14:24:30 +0000 (10:24 -0400)] 
Bump hadrian submodule

12 months agoTestsuite driver: fix encoding issue when calling ghc-pkg
Krzysztof Gogolewski [Mon, 6 Aug 2018 19:38:52 +0000 (21:38 +0200)] 
Testsuite driver: fix encoding issue when calling ghc-pkg

In Python 3, subprocess.communicate() returns a pair of bytes, which
need to be decoded. In, we were just calling str() instead,
which converts b'x' to "b'x'". As a result, the loop that was checking
pkginfo for lines starting with 'library-dirs' couldn't work.

Reviewers: bgamari, thomie, Phyx

Reviewed By: thomie

Subscribers: Phyx, rwbarton, carter

Differential Revision:

(cherry picked from commit 36a4c19494e2cb7e968f1d0e0c09926a660e1a56)

12 months ago[docs] Add missed specialisations warnings to list of those not enabled by -Wall
Maximilian Tagher [Sat, 28 Jul 2018 21:04:16 +0000 (14:04 -0700)] 
[docs] Add missed specialisations warnings to list of those not enabled by -Wall

Enabling `-Weverything` does enable those warnings.

(cherry picked from commit b062bd10a88ea407ae91610f822f0c352909bcce)
(cherry picked from commit 24b76d1bef7e61791907fbd063f85643eeb1211a)

12 months agoUnhide GHC.List for haddock
Simon Jakobi [Thu, 19 Jul 2018 12:35:15 +0000 (14:35 +0200)] 
Unhide GHC.List for haddock

The unhidden module GHC.OldList recommends using GHC.List instead.
In consequence we should also have haddocks for GHC.List.

(cherry picked from commit e3df129c8bf4c35693d01ea66238882f3e3b6fe1)
(cherry picked from commit 672f177300b2df1b8a4cd49d560a6fd6da2415d2)

12 months agodocs: Fix wrong module name in hsig example
Mathieu Boespflug [Sat, 21 Jul 2018 11:48:33 +0000 (13:48 +0200)] 
docs: Fix wrong module name in hsig example

In the module signatures section, two modules were defined, `Str` and
`A`, but `A` was importing `Text`, not `Str`.

(cherry picked from commit 26ab3635ca342c88310321d7f310f1c12c23ec4c)
(cherry picked from commit ce9b459de30e15f2d65518ca12974a692256d477)

12 months agoAdd since annotation to GHC.ByteOrder
Alexander Biehl [Sun, 5 Aug 2018 10:29:51 +0000 (12:29 +0200)] 
Add since annotation to GHC.ByteOrder

(cherry picked from commit 6fb2620dbc420c976dc9da90b0efc6eae533ebff)
(cherry picked from commit 8b357c6ad17bfe802c4a818b0cd7440bced024a3)

12 months agorts: Ensure that the_gc_thread is aligned
Ben Gamari [Mon, 6 Aug 2018 18:52:59 +0000 (14:52 -0400)] 
rts: Ensure that the_gc_thread is aligned

Since we cast this to a gc_thread the compiler may assume that it's aligned.
Make sure that this is so. Fixes #15482.

(cherry picked from commit c6cc93bca69abc258513af8cf2370b14e70fd8fb)

12 months agocircleci: Don't build validate-x86_64-linux-debug unregisterised
Ben Gamari [Sun, 5 Aug 2018 20:27:21 +0000 (22:27 +0200)] 
circleci: Don't build validate-x86_64-linux-debug unregisterised

Summary: This was a cut-and-paste error.

Reviewers: alpmestan

Reviewed By: alpmestan

Subscribers: alpmestan, rwbarton, thomie, carter

GHC Trac Issues: #15466

Differential Revision:

(cherry picked from commit f355b72113e646cb3785937f5506ee4c084c127f)

12 months agoRefactor printMinimalImports (#15439)
vrom911 [Sun, 5 Aug 2018 13:28:25 +0000 (15:28 +0200)] 
Refactor printMinimalImports (#15439)

Split into getMinimalImports and printMinimalImports.
Export both functions from RnNames module.

Reviewers: bgamari, mpickering

Reviewed By: mpickering

Subscribers: mpickering, rwbarton, carter

GHC Trac Issues: #15439

Differential Revision:

(cherry picked from commit 73683f143d352343b00b1ab4f3abeb38b81794be)

12 months agoFix the TcLevel not being set correctly when finding valid hole fits
Matthías Páll Gissurarson [Sat, 21 Jul 2018 13:48:53 +0000 (15:48 +0200)] 
Fix the TcLevel not being set correctly when finding valid hole fits

This fixes the problem revealed by a new assert as it relates to valid
hole fits. However, tests `T10384`, `T14040a` and `TcStaticPointersFail02`
still fail the assert, but they are unrelated to valid hole fits.

Reviewers: bgamari, simonpj

Reviewed By: simonpj

Subscribers: simonpj, rwbarton, thomie, carter

GHC Trac Issues: #15384

Differential Revision:

(cherry picked from commit b202e7a48401bd8e805a92dcfe5ea059cbd8e41c)

12 months agoTurn on MonadFail desugaring by default
Herbert Valerio Riedel [Mon, 6 Aug 2018 16:59:40 +0000 (12:59 -0400)] 
Turn on MonadFail desugaring by default

This contains two commits:


Make GHC's code-base compatible w/ `MonadFail`

There were a couple of use-sites which implicitly used pattern-matches
in `do`-notation even though the underlying `Monad` didn't explicitly
support `fail`

This refactoring turns those use-sites into explicit case
discrimations and adds an `MonadFail` instance for `UniqSM`
(`UniqSM` was the worst offender so this has been postponed for a
follow-up refactoring)


Turn on MonadFail desugaring by default

This finally implements the phase scheduled for GHC 8.6 according to

This also preserves some tests that assumed MonadFail desugaring to be
active; all ghc boot libs were already made compatible with this
`MonadFail` long ago, so no changes were needed there.

Test Plan: Locally performed ./validate --fast

Reviewers: bgamari, simonmar, jrtc27, RyanGlScott

Reviewed By: bgamari

Subscribers: bgamari, RyanGlScott, rwbarton, thomie, carter

Differential Revision:

12 months agoBump filepath submodule
Ben Gamari [Thu, 2 Aug 2018 21:56:30 +0000 (17:56 -0400)] 
Bump filepath submodule

(cherry picked from commit 9472db132d2e455c106778c7daa30af71fbf6fee)

12 months agoBump binary submodule
Ben Gamari [Thu, 2 Aug 2018 12:29:52 +0000 (08:29 -0400)] 
Bump binary submodule

(cherry picked from commit 3110428dd63a2014fe131cb2abff192570cc89e9)

12 months agoBump Cabal submodule
Ben Gamari [Fri, 3 Aug 2018 20:33:13 +0000 (16:33 -0400)] 
Bump Cabal submodule

12 months agofixup! Disable T10962 on llvm for now
Krzysztof Gogolewski [Sun, 22 Jul 2018 20:50:06 +0000 (22:50 +0200)] 
fixup! Disable T10962 on llvm for now

(cherry picked from commit a606750b36862367d038813f9fe7170f93c36222)

12 months agoClone relevant constraints to avoid side-effects on HoleDests. Fixes #15370.
Matthías Páll Gissurarson [Tue, 24 Jul 2018 21:57:48 +0000 (23:57 +0200)] 
Clone relevant constraints to avoid side-effects on HoleDests. Fixes #15370.

Summary: When looking for valid hole fits, the constraints relevant
to the hole may sometimes contain a HoleDest. Previously,
these were not cloned, which could cause the filling of filled
coercion hole being, which would cause an assert to fail. This is now fixed.

Test Plan: Regression test included.

Reviewers: simonpj, bgamari, goldfire

Reviewed By: simonpj

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15370

Differential Revision:

(cherry picked from commit 0dc86f6bc454253969dedc31bed477eded4cf82d)

12 months agoPlugin dependency information is stored separately
Christiaan Baaij [Wed, 1 Aug 2018 18:21:22 +0000 (14:21 -0400)] 
Plugin dependency information is stored separately

We need to store the used plugins so that we recompile
a module when a plugin that it uses is recompiled.

However, storing the `ModuleName`s of the plugins used by a
module in the `dep_mods` field made the rest of GHC think
that they belong in the HPT, causing at least the issues
reported in #15234

We therefor store the `ModuleName`s of the plugins in a
new field, `dep_plgins`, which is only used the the
recompilation logic.

Reviewers: mpickering, bgamari

Reviewed By: mpickering, bgamari

Subscribers: alpmestan, rwbarton, thomie, carter

GHC Trac Issues: #15234

Differential Revision:

(cherry picked from commit 52065e95c6df89d0048c6e3f35d6cc26ce8246f9)

12 months agoTreat isConstraintKind more consistently
Simon Peyton Jones [Wed, 25 Jul 2018 10:35:43 +0000 (11:35 +0100)] 
Treat isConstraintKind more consistently

It turned out that we were not being consistent
about our use of isConstraintKind.

It's delicate, because the typechecker treats Constraint and Type as
/distinct/, whereas they are the /same/ in the rest of the compiler
(Trac #11715).

And had it wrong, which led to Trac #15412.  This patch does the

* Rename isConstraintKind      to tcIsConstraintKind
         returnsConstraintKind to tcReturnsConstraintKind
  to emphasise that they use the 'tcView' view of types.

* Move these functions, and some related ones (tcIsLiftedTypeKind),
  from Kind.hs, to group together in Type.hs, alongside isPredTy.

It feels very unsatisfactory that these 'tcX' functions live in Type,
but it happens because isPredTy is called later in the compiler
too.  But it's a consequence of the 'Constraint vs Type' dilemma.

(cherry picked from commit c5d31df70b16dc346b5860077c8bbe585ddb7a78)

12 months agoFix #15385 by using addDictsDs in matchGuards
Ryan Scott [Mon, 30 Jul 2018 12:47:39 +0000 (08:47 -0400)] 
Fix #15385 by using addDictsDs in matchGuards

When coverage checking pattern-matches, we rely on the call
sites in the desugarer to populate the local dictionaries and term
evidence in scope using `addDictsDs` and `addTmCsDs`. But it turns
out that only the call site for desugaring `case` expressions was
actually doing this properly. In another part of the desugarer,
`matchGuards` (which handles pattern guards), it did not update the
local dictionaries in scope at all, leading to #15385.

Fixing this is relatively straightforward: just augment the
`BindStmt` case of `matchGuards` to use `addDictsDs` and `addTmCsDs`.
Accomplishing this took a little bit of import/export tweaking:

* We now need to export `collectEvVarsPat` from `HsPat.hs`.
* To avoid an import cycle with `Check.hs`, I moved `isTrueLHsExpr`
  from `DsGRHSs.hs` to `DsUtils.hs`, which resides lower on the
  import chain.

Test Plan: make test TEST=T15385

Reviewers: simonpj, bgamari

Reviewed By: simonpj

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15385

Differential Revision:

(cherry picked from commit 9d388eb83e797fd28e14868009c4786f3f1a8aa6)

12 months agoSmall refactor in desugar of pattern matching
Simon Peyton Jones [Fri, 27 Jul 2018 08:17:20 +0000 (09:17 +0100)] 
Small refactor in desugar of pattern matching

In reviewing Phab:D4968 for Trac #15385 I saw a small
but simple refactor to avoid unnecessary work in the

This patch just arranges to call
   matchSinglePatVar v ...
rather than
   matchSinglePat (Var v) ...

The more specialised function already existed, as

I also added more comments about decideBangHood

(cherry picked from commit 45cfe6514afb47c26883687e25ff7eb1e40c5a52)

12 months agoRemove the type-checking knot.
Richard Eisenberg [Tue, 17 Jul 2018 04:12:34 +0000 (00:12 -0400)] 
Remove the type-checking knot.

Bug #15380 hangs because a knot-tied TyCon ended up in a kind.
Looking at the code in tcInferApps, I'm amazed this hasn't happened
before! I couldn't think of a good way to fix it (with dependent
types, we can't really keep types out of kinds, after all), so
I just went ahead and removed the knot.

This was remarkably easy to do. In tcTyVar, when we find a TcTyCon,
just use it. (Previously, we looked up the knot-tied TyCon and used
that.) Then, during the final zonk, replace TcTyCons with the real,
full-blooded TyCons in the global environment. It's all very easy.

The new bit is explained in the existing
Note [Type checking recursive type and class declarations]
in TcTyClsDecls.

Naturally, I removed various references to the knot and the
zonkTcTypeInKnot (and related) functions. Now, we can print types
during type checking with abandon!

NB: There is a teensy error message regression with this patch,
around the ordering of quantified type variables. This ordering
problem is fixed (I believe) with the patch for #14880. The ordering
affects only internal variables that cannot be instantiated with
any kind of visible type application.

There is also a teensy regression around the printing of types
in TH splices. I think this is really a TH bug and will file

Test case: dependent/should_fail/T15380

(cherry picked from commit f8618a9b15177ee8c84771b927cb3583c9cd8408)

12 months agoBump Cabal submodule to 2.4
Ben Gamari [Wed, 1 Aug 2018 23:42:53 +0000 (19:42 -0400)] 
Bump Cabal submodule to 2.4

12 months agoFix #15450 by refactoring checkEmptyCase'
Ryan Scott [Wed, 1 Aug 2018 18:26:44 +0000 (14:26 -0400)] 
Fix #15450 by refactoring checkEmptyCase'

`checkEmptyCase'` (the code path for coverage-checking
`EmptyCase` expressions) had a fair bit of code duplication from the
code path for coverage-checking non-`EmptyCase` expressions, and to
make things worse, it behaved subtly different in some respects (for
instance, emitting different warnings under unsatisfiable
constraints, as shown in #15450). This patch attempts to clean up
both this discrepancy and the code duplication by doing the

* Factor out a `pmInitialTmTyCs` function, which returns the initial
  set of term and type constraints to use when beginning coverage
  checking. If either set of constraints is unsatisfiable, we use an
  empty set in its place so that we can continue to emit as many
  warnings as possible. (The code path for non-`EmptyCase`
  expressions was doing this already, but not the code path for
  `EmptyCase` expressions, which is the root cause of #15450.)

  Along the way, I added a `Note` to explain why we do this.
* Factor out a `pmIsSatisfiable` constraint which checks if a set of
  term and type constraints are satisfiable. This does not change any
  existing behavior; this is just for the sake of deduplicating code.

Test Plan: make test TEST=T15450

Reviewers: simonpj, bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15450

Differential Revision:

(cherry picked from commit 7f3cb50dd311caefb536d582f1e3d1b33d6650f6)

12 months agoFix #15415 and simplify tcWildCardBinders
Vladislav Zavialov [Wed, 1 Aug 2018 18:28:16 +0000 (14:28 -0400)] 
Fix #15415 and simplify tcWildCardBinders

Test Plan: Validate

Reviewers: goldfire, simonpj, bgamari

Reviewed By: simonpj

Subscribers: RyanGlScott, rwbarton, thomie, carter

GHC Trac Issues: #15415

Differential Revision:

(cherry picked from commit 120cc9f85ee1120072eb44c5bf37ac3055883605)

12 months agolinker: Nub rpaths
Moritz Angermann [Wed, 1 Aug 2018 18:25:03 +0000 (14:25 -0400)] 
linker: Nub rpaths

When compiling and linking files in `ghci`, we keep adding rpath
arguments to the linker command invoation.  If those are identical we
should `nub` them out.  Otherwise we not only risk overflowing the
argument limit, but also embed huge amounts of identical rpath values
into the dynamic library, eventually leading to the overflow of the load
command size limit, due to the number of rpath entries alone.

A further improvement could be to pass `-Xlinker -dead_strip_dylibs`;
that however might be stipping too aggressively, and potentially lead to
missing symbols?

For the time being I suggest to only do the nubbing and if need be to
provide -Wl,-dead_strip_dylibs when invoking ghci.

Test Plan: ./validate

Reviewers: bgamari, hvr

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15446

Differential Revision:

(cherry picked from commit b803c40608119469bdda330cb88860be2cbed25b)

12 months agoFix #15453: bug in ForAllCo case in opt_trans_rule
Ningning Xie [Sun, 29 Jul 2018 11:15:33 +0000 (13:15 +0200)] 
Fix #15453: bug in ForAllCo case in opt_trans_rule


co1 = \/ tv1 : eta1. r1
co2 = \/ tv2 : eta2. r2

We would like to optimize `co1; co2` so we push transitivity inside forall.
It should be

\/tv1 : (eta1;eta2).  (r1; r2[tv2 |-> tv1 |> eta1])

It is implemented in the ForAllCo case in opt_trans_rule in OptCoercion.
However current implementation is not right:

r2' = substCoWithUnchecked [tv2] [TyVarTy tv1] r2 -- ill-kinded!

This patch corrects it to be

r2' = substCoWithUnchecked [tv2] [mkCastTy (TyVarTy tv1) eta1] r2

Test Plan: validate

Reviewers: bgamari, goldfire, RyanGlScott

Reviewed By: RyanGlScott

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15453

Differential Revision:

(cherry picked from commit 11de4380c2f16f374c6e8fbacf8dce00376e7efb)

12 months agoEnable two-step allocator on FreeBSD
Ben Gamari [Mon, 30 Jul 2018 22:01:40 +0000 (18:01 -0400)] 
Enable two-step allocator on FreeBSD

Simplify #ifdef nesting and use MAP_GUARD on FreeBSD and similar
systems. This allows the two-step allocator to be used on FreeBSD,
fixing #15348.

(cherry picked from commit 123aeb916cba93018039e583d42408dae80a6dc9)

12 months agotestsuite: Add test for #15346
Richard Eisenberg [Thu, 19 Jul 2018 04:16:13 +0000 (00:16 -0400)] 
testsuite: Add test for #15346

Test case: dependent/should_compile/T{15346,15419}.

12 months agoFix some casts.
Ben Gamari [Tue, 31 Jul 2018 20:44:12 +0000 (16:44 -0400)] 
Fix some casts.

This fixes #15346, and is a team effort between Ryan Scott and
myself (mostly Ryan). We discovered two errors related to FC's
"push" rules, one in the TPush rule (as implemented in pushCoTyArg)
and one in KPush rule (it shows up in liftCoSubstVarBndr).

The solution: do what the paper says, instead of whatever random
thoughts popped into my head as I was actually implementing.

Note that this is a backport of the fix merged to master,

Also fixes #15419, which is actually the same underlying problem.

Test case: dependent/should_compile/T{15346,15419}.

12 months agoFix Git commit ID detection in Git worktrees
Sylvain Henry [Sat, 28 Jul 2018 15:48:04 +0000 (17:48 +0200)] 
Fix Git commit ID detection in Git worktrees

Summary: When using a Git worktree, ".git" is a file, not a directory

Reviewers: bgamari, monoidal

Reviewed By: monoidal

Subscribers: rwbarton, thomie, erikd, carter

Differential Revision:

(cherry picked from commit 3539561b24b78aee2b37280ddf6bb64e2db3a67d)

12 months agoFix PrelRules.caseRules to account for out-of-range tags
Simon Peyton Jones [Wed, 25 Jul 2018 15:41:16 +0000 (16:41 +0100)] 
Fix PrelRules.caseRules to account for out-of-range tags

As Trac #15436 points out, it is possible to get
   case dataToTag# (x :: T) of
      DEFAULT -> blah1
      -1#     -> blah2
      0       -> blah3

The (-1#) alterantive is unreachable, because dataToTag# returns
tags in the range [0..n-1] where n is the number of data constructors
in type T.

This actually made GHC crash; now we simply discard the unreachable
alterantive.  See Note [Unreachable caseRules alternatives]
in PrelRules

(cherry picked from commit 9897f6783a58265d5eaef5fb06f04320c7737e87)

12 months agoStop marking soluble ~R# constraints as insoluble
Simon Peyton Jones [Mon, 23 Jul 2018 14:33:13 +0000 (15:33 +0100)] 
Stop marking soluble ~R# constraints as insoluble

We had a constraint (a b ~R# Int), and were marking it as 'insoluble'.
That's bad; it isn't.  And it caused Trac #15431. Soultion is simple.

I did a tiny refactor on can_eq_app, so that it is used only for
nominal equalities.

(cherry picked from commit f0d27f515ffbc476144d1d1dd1a71bf9fa93c94b)

12 months agoFix #15423 by using pprAStmtContext
Ryan Scott [Fri, 20 Jul 2018 10:50:50 +0000 (12:50 +0200)] 
Fix #15423 by using pprAStmtContext

Previously, we were using `pprStmtContext` instead, which
led to error messages missing indefinite articles where they were

Test Plan: make test TEST="T13242a T7786 Typeable1"

Reviewers: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15423

Differential Revision:

(cherry picked from commit 99f45e2a751dda4fdf00256d397a2932d430f3a7)

12 months agoFix the GHCi debugger with ApplicativeDo
Simon Marlow [Sun, 22 Jul 2018 15:03:33 +0000 (17:03 +0200)] 
Fix the GHCi debugger with ApplicativeDo

`collectLStmtsBinders` was returning nothing for `ApplicativeStmts`, which
caused the debugger to not track free variables in many cases when using

Test Plan:
* new test case
* validate

Reviewers: bgamari, erikd

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15422

Differential Revision:

(cherry picked from commit 4ea9311cc5c3b99ea6915bee23f0a6776731f20e)

12 months agoSuppress -Winaccessible-code in derived code
Ryan Scott [Tue, 24 Jul 2018 12:40:42 +0000 (14:40 +0200)] 
Suppress -Winaccessible-code in derived code

It's rather unfortunate that derived code can produce inaccessible
code warnings (as demonstrated in #8128, #8740, and #15398), since
the programmer has no control over the generated code. This patch
aims to suppress `-Winaccessible-code` in all derived code. It
accomplishes this by doing the following:

* Generalize the `ic_env :: TcLclEnv` field of `Implication` to
  be of type `Env TcGblEnc TcLclEnv` instead. This way, it also
  captures `DynFlags`, which record the flag state at the time
  the `Implication` was created.
* When typechecking derived code, turn off `-Winaccessible-code`.
  This way, any insoluble given `Implication`s that are created when
  typechecking this derived code will remember that
  `-Winaccessible-code` was disabled.
* During error reporting, consult the `DynFlags` of an
  `Implication` before making the decision to report an inaccessible
  code warning.

Test Plan: make test TEST="T8128 T8740 T15398"

Reviewers: simonpj, bgamari

Reviewed By: simonpj

Subscribers: monoidal, rwbarton, thomie, carter

GHC Trac Issues: #8128, #8740, #15398

Differential Revision:

(cherry picked from commit 44a7b9baa45c4ab939c7d996519b5e3de3e13c5a)

12 months agoFix Ar crashing on odd-sized object files (Trac #15396)
Krzysztof Gogolewski [Fri, 27 Jul 2018 20:10:52 +0000 (22:10 +0200)] 
Fix Ar crashing on odd-sized object files (Trac #15396)

Summary: All the work was done by Moritz Angermann.

Test Plan: validate

Reviewers: angerman, RyanGlScott, bgamari

Reviewed By: angerman

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15396

Differential Revision:

(cherry picked from commit 754c3a55a603b155fa5d9a282de73d41a4694ffc)

12 months agoFix pretty-printing of data declarations in splices
Krzysztof Gogolewski [Sun, 22 Jul 2018 16:58:33 +0000 (18:58 +0200)] 
Fix pretty-printing of data declarations in splices

Test Plan: validate

Reviewers: RyanGlScott, bgamari

Reviewed By: RyanGlScott

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15365

Differential Revision:

(cherry picked from commit 3aa09cc5af9cacba91915c095f9652ee5ed31ec7)

12 months agoHarden fixST
David Feuer [Sat, 21 Jul 2018 19:45:35 +0000 (15:45 -0400)] 
Harden fixST

Trac #15349 reveals that lazy blackholing can cause trouble for
`fixST` much like it can for `fixIO`. Make `fixST` work just
like `fixIO`.

Reviewers: simonmar, hvr, bgamari

Reviewed By: simonmar

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15349

Differential Revision:

(cherry picked from commit 5a49651f3161473b383ec497af38e9daa022b9ac)

12 months agoFix a major copy'n'paste error in LLVM CodeGen
Krzysztof Gogolewski [Sun, 22 Jul 2018 15:33:32 +0000 (17:33 +0200)] 
Fix a major copy'n'paste error in LLVM CodeGen

In D4592, `AddWordC` is lowered as an unsigned subtraction instead
of an unsigned addition when compiling with LLVM.

This patch rectifies that.

Reviewers: angerman, bgamari, monoidal

Reviewed By: angerman, bgamari, monoidal

Subscribers: osa1, rwbarton, thomie, carter

Differential Revision:

(cherry picked from commit f629442be93f4608e6bb53bfe2264a406230c546)

12 months agostack: fix stack allocations on Windows
Tamar Christina [Wed, 18 Jul 2018 20:03:58 +0000 (21:03 +0100)] 
stack: fix stack allocations on Windows

On Windows one is not allowed to drop the stack by more than a page size.
The reason for this is that the OS only allocates enough stack till what
the TEB specifies. After that a guard page is placed and the rest of the
virtual address space is unmapped.

The intention is that doing stack allocations will cause you to hit the
guard which will then map the next page in and move the guard.  This is
done to prevent what in the Linux world is known as stack clash

There are modules in GHC for which the liveliness analysis thinks the
reserved 8KB of spill slots isn't enough.  One being DynFlags and the
other being Cabal.

Though I think the Cabal one is likely a bug:

  4d6544:       81 ec 00 46 00 00       sub    $0x4600,%esp
  4d654a:       8d 85 94 fe ff ff       lea    -0x16c(%ebp),%eax
  4d6550:       3b 83 1c 03 00 00       cmp    0x31c(%ebx),%eax
  4d6556:       0f 82 de 8d 02 00       jb     4ff33a <_cLpg_info+0x7a>
  4d655c:       c7 45 fc 14 3d 50 00    movl   $0x503d14,-0x4(%ebp)
  4d6563:       8b 75 0c                mov    0xc(%ebp),%esi
  4d6566:       83 c5 fc                add    $0xfffffffc,%ebp
  4d6569:       66 f7 c6 03 00          test   $0x3,%si
  4d656e:       0f 85 a6 d7 02 00       jne    503d1a <_cLpb_info+0x6>
  4d6574:       81 c4 00 46 00 00       add    $0x4600,%esp

It allocates nearly 18KB of spill slots for a simple 4 line function
and doesn't even use it.  Note that this doesn't happen on x64 or
when making a validate build.  Only when making a build without a
validate and

This and the allocation in DynFlags means the stack allocation will jump
over the guard page into unmapped memory areas and GHC or an end program

The pagesize on x86 Windows is 4KB which means we hit it very easily for
these two modules, which explains the total DOA of GHC 32bit for the past
3 releases and the "random" segfaults on Windows.

0:000> bp 00503d29
0:000> gn
Breakpoint 0 hit
WARNING: Stack overflow detected. The unwound frames are extracted from outside
         normal stack bounds.
eax=03b6b9c9 ebx=00dc90f0 ecx=03cac48c edx=03cac43d esi=03b6b9c9 edi=03abef40
eip=00503d29 esp=013e96fc ebp=03cf8f70 iopl=0         nv up ei pl nz na po nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000202
00503d29 89442440        mov     dword ptr [esp+40h],eax ss:002b:013e973c=????????
WARNING: Stack overflow detected. The unwound frames are extracted from outside
         normal stack bounds.
WARNING: Stack overflow detected. The unwound frames are extracted from outside
         normal stack bounds.
0:000> !teb
TEB at 00384000
    ExceptionList:        013effcc
    StackBase:            013f0000
    StackLimit:           013eb000

This doesn't fix the liveliness analysis but does fix the allocations, by
emitting a function call to `__chkstk_ms` when doing allocations of larger
than a page, this will make sure the stack is probed every page so the kernel
maps in the next page.

`__chkstk_ms` is provided by `libGCC`, which is under the
`GNU runtime exclusion license`, so it's safe to link against it, even for
proprietary code. (Technically we already do since we link compiled C code in.)

For allocations smaller than a page we drop the stack and probe the new address.
This avoids the function call and still makes sure we hit the guard if needed.

PS: In case anyone is Wondering why we didn't notice this before, it's because we
only test x86_64 and on Windows 10.  On x86_64 the page size is 8KB and also the
kernel is a bit more lenient on Windows 10 in that it seems to catch the segfault
and resize the stack if it was unmapped:

0:000> t
eax=03b6b9c9 ebx=00dc90f0 ecx=03cac48c edx=03cac43d esi=03b6b9c9 edi=03abef40
eip=00503d2d esp=013e96fc ebp=03cf8f70 iopl=0         nv up ei pl nz na po nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000202
00503d2d 8b461b          mov     eax,dword ptr [esi+1Bh] ds:002b:03b6b9e4=03cac431
0:000> !teb
TEB at 00384000
    ExceptionList:        013effcc
    StackBase:            013f0000
    StackLimit:           013e9000

Likely Windows 10 has a guard page larger than previous versions.

This fixes the stack allocations, and as soon as I get the time I will look at
the liveliness analysis. I find it highly unlikely that simple Cabal function
requires ~2200 spill slots.

Test Plan: ./validate

Reviewers: simonmar, bgamari

Reviewed By: bgamari

Subscribers: AndreasK, rwbarton, thomie, carter

GHC Trac Issues: #15154

Differential Revision:

(cherry picked from commit d0bbe1bf351c8b85c310afb0dd1fb1f12f9474bf)

12 months agoFix a nasty bug in piResultTys
Simon Peyton Jones [Tue, 24 Jul 2018 07:57:34 +0000 (08:57 +0100)] 
Fix a nasty bug in piResultTys

I was failing to instantiate vigorously enough in Type.piResultTys
and in the very similar function ToIface.toIfaceAppArgsX

This caused Trac #15428.  The fix is easy.

See Note [Care with kind instantiation] in Type.hs

(cherry picked from commit e1b5a1174e42e390855b153015ce5227b3251d89)

12 months agotestsuite: Add test for #14346
Sylvain Henry [Tue, 31 Jul 2018 15:02:20 +0000 (11:02 -0400)] 
testsuite: Add test for #14346

(cherry picked from commit f8e5da92c0160a675e1666a5d6ed6a8ffcae193c)

12 months agotestsuite: Fix up testsuite
Ben Gamari [Mon, 30 Jul 2018 21:42:49 +0000 (17:42 -0400)] 
testsuite: Fix up testsuite

12 months agobase: Fix documentation of System.Environment.Blank
Ben Gamari [Mon, 30 Jul 2018 21:27:13 +0000 (17:27 -0400)] 
base: Fix documentation of System.Environment.Blank

12 months agobase: Make Foreign.Marshal.Alloc.allocBytes[Aligned] NOINLINE
Ben Gamari [Tue, 24 Oct 2017 16:19:08 +0000 (12:19 -0400)] 
base: Make Foreign.Marshal.Alloc.allocBytes[Aligned] NOINLINE

As noted in #14346, touch# may be optimized away when the simplifier can see
that the continuation passed to allocaBytes will not return. Marking CPS-style
functions with NOINLINE ensures that the simplier can't draw any unsound

Ultimately the right solution here will be to do away with touch# and instead
introduce a scoped primitive as is suggested in #14375.

(cherry picked from commit 404bf05ed3193e918875cd2f6c95ae0da5989be2)

12 months agoFix minor formatting issue in users_guide/bugs.rst
Josh Price [Fri, 27 Jul 2018 04:00:31 +0000 (00:00 -0400)] 
Fix minor formatting issue in users_guide/bugs.rst

(cherry picked from commit fb11a104018dfb4065fd91c549fec6d46fa77945)

12 months agoFix endian issues in ghc-heap
Peter Trommler [Thu, 26 Jul 2018 21:23:22 +0000 (17:23 -0400)] 
Fix endian issues in ghc-heap

In test heap_all arity and n_args were swapped on big endian

Take care of endianness when reading parts of a machine word
from a `Word`.

This fixes one out of 36 failing tests reported in #15399.

Test Plan: validate

Reviewers: simonmar, bgamari, hvr, erikd

Reviewed By: simonmar

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15399

Differential Revision:

(cherry picked from commit d7cb1bbc26719cf6082abe0d91d80be466e25bfc)

12 months agoBump terminfo submodule to
Ben Gamari [Fri, 27 Jul 2018 13:57:52 +0000 (09:57 -0400)] 
Bump terminfo submodule to

(cherry picked from commit b2852a440cac3310bbe443a9010949dbea94e7db)

12 months agorts: Flush eventlog in hs_init_ghc (fixes #15440)
Mitsutoshi Aoe [Thu, 26 Jul 2018 05:50:51 +0000 (14:50 +0900)] 
rts: Flush eventlog in hs_init_ghc (fixes #15440)

Without this change RTS typically doesn't flush some important
events until the process terminates or it doesn't write them at
all in case it terminates abnormally.

Here is a list of such events:


(cherry picked from commit 7a3e1b25ff9a570851a59c4cf3600daa49867b9b)