13 months agoghc: Remove warning of StaticPointers not being supported by GHCi
Ben Gamari [Thu, 6 Sep 2018 22:51:31 +0000 (18:51 -0400)] 
ghc: Remove warning of StaticPointers not being supported by GHCi

Support for StaticPointers was added in #12356 but I apparently
neglected to remove the warning.

13 months agoDocumentation tweaks
Krzysztof Gogolewski [Fri, 7 Sep 2018 11:53:11 +0000 (13:53 +0200)] 
Documentation tweaks

- Mention static pointers in "stolen syntax"
- Suggest importing Constraint and IsString from Data.* instead of GHC.*
- Remove obsolete SPECIALISE syntax; it was removed in or before 1999
- Fix link in pattern signatures

Test Plan: build

Reviewers: bgamari, takenobu

Reviewed By: takenobu

Subscribers: rwbarton, carter

Differential Revision:

13 months agoVarious RTS bug fixes:
Ömer Sinan Ağacan [Fri, 7 Sep 2018 06:28:36 +0000 (09:28 +0300)] 
Various RTS bug fixes:

- Retainer profiler: init_srt_thunk() should mark the stack entry as SRT
- Retainer profiler: Remove an incorrect assertion about FUN_STATIC.
  FUN_STATIC does not have to have an SRT.
- Fix nptrs of BCO

Test Plan: validate

Reviewers: simonmar, bgamari, erikd

Reviewed By: simonmar

Subscribers: rwbarton, carter

Differential Revision:

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

13 months agoRemove an incorrect assertion in threadPaused:
Ömer Sinan Ağacan [Thu, 6 Sep 2018 08:39:46 +0000 (11:39 +0300)] 
Remove an incorrect assertion in threadPaused:

The assertion is triggered when we have a loop in the program (in which case we
see the same update frame multiple times in the stack). See #14915 for more

Reviewers: simonmar, bgamari, erikd

Reviewed By: simonmar

Subscribers: rwbarton, carter

GHC Trac Issues: #14915

Differential Revision:

13 months agoPreserve specialisations despite CSE
Simon Peyton Jones [Wed, 5 Sep 2018 14:54:48 +0000 (15:54 +0100)] 
Preserve specialisations despite CSE

Trac #15445 showed that, as a result of CSE, a function with an
automatically generated specialisation RULE could be inlined
before the RULE had a chance to fire.

This patch attaches a NOINLINE[2] activation to the Id, during
CSE, to stop this happening.

See Note [Delay inlining after CSE]

---- Historical note ---

This patch is simpler and more direct than an earlier

  commit 2110738b280543698407924a16ac92b6d804dc36
  Author: Simon Peyton Jones <>
  Date:   Mon Jul 30 13:43:56 2018 +0100

  Don't inline functions with RULES too early

We had to revert this patch because it made GHC itself slower.

Why? It delayed inlining of /all/ functions with RULES, and that was
very bad in TcFlatten.flatten_ty_con_app

* It delayed inlining of liftM
* That delayed the unravelling of the recursion in some dictionary
* That delayed some eta expansion, leaving
     flatten_ty_con_app = \x y. let <stuff> in \z. blah
* That allowed the float-out pass to put sguff between
  the \y and \z.
* And that permanently stopped eta expasion of the function,
  even once <stuff> was simplified.

-- End of historical note ---

13 months agoDefine activeAfterInitial, activeDuringFinal
Simon Peyton Jones [Wed, 5 Sep 2018 14:53:15 +0000 (15:53 +0100)] 
Define activeAfterInitial, activeDuringFinal

This is pure refactoring, just adding a couple of
definitions to BasicTypes, and using them.

Plus some whitespace stuff.

13 months agoExpose 'moduleToPkgConfAll' from 'PackageState'
Alec Theriault [Wed, 5 Sep 2018 12:27:40 +0000 (14:27 +0200)] 
Expose 'moduleToPkgConfAll' from 'PackageState'

Having direct access to this field is going to enable Haddock to
compute in batch which modules to load before looking up instances
of external packages.

Reviewers: bgamari, monoidal

Reviewed By: monoidal

Subscribers: rwbarton, carter

Differential Revision:

13 months agotestsuite: Use bools for booleans, not ints
Ben Gamari [Wed, 5 Sep 2018 11:45:50 +0000 (13:45 +0200)] 
testsuite: Use bools for booleans, not ints

Summary: Just as it says on the tin.

Test Plan: Validate

Reviewers: bgamari, osa1

Reviewed By: osa1

Subscribers: osa1, monoidal, rwbarton, thomie, carter

Differential Revision:

13 months agobase: Add references to Notes for certain special imports
Chaitanya Koparkar [Wed, 5 Sep 2018 11:41:24 +0000 (13:41 +0200)] 
base: Add references to Notes for certain special imports

Modules like GHC.Integer, GHC.Natural etc. are special and sometimes
have to be imported just to resolve build ordering issues. It's useful
to refer to the appropriate Notes at such import sites.

Test Plan: Read it.

Reviewers: RyanGlScott, bgamari, hvr, simonpj

Reviewed By: RyanGlScott, simonpj

Subscribers: simonpj, rwbarton, carter

GHC Trac Issues: #15526

Differential Revision:

13 months agotestsuite: Add test for #15368
Ben Gamari [Wed, 5 Sep 2018 11:22:24 +0000 (13:22 +0200)] 
testsuite: Add test for #15368

Reviewers: bgamari, osa1

Reviewed By: osa1

Subscribers: osa1, monoidal, rwbarton, thomie, carter

GHC Trac Issues: #15368

Differential Revision:

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

13 months agoFix tests ghci057 and T9293. (#15071)
roland [Tue, 4 Sep 2018 20:23:55 +0000 (22:23 +0200)] 
Fix tests ghci057 and T9293. (#15071)

Summary: As both tests specify -fno-ghci-leak-check, the GHCi :set
command is not expected to list the -fghci-leak check flag.

Test Plan: WINDOWS: make test TESTS="ghci057 T9293"

Reviewers: bgamari, monoidal

Reviewed By: monoidal

Subscribers: rwbarton, carter

GHC Trac Issues: #15071

Differential Revision:

13 months agotestsuite: make CHECK_API_ANNOTATIONS and CHECK_PPR overridable
Alp Mestanogullari [Tue, 4 Sep 2018 17:09:06 +0000 (19:09 +0200)] 
testsuite: make CHECK_API_ANNOTATIONS and CHECK_PPR overridable

Without this patch, (which is included by a lot of Makefiles from
our testsuite) just assumes they reside in the usual inplace directory, which is
not friendly to hadrian and this makes a lot of tests (e.g T10255) fail when
building GHC and running the testsuite with hadrian.

With this patch, the said tests pass.

Test Plan: api annotation tests (with hadrian)

Reviewers: bgamari, monoidal

Reviewed By: monoidal

Subscribers: rwbarton, carter

Differential Revision:

13 months agoAdd a test for Trac #15586
Krzysztof Gogolewski [Tue, 4 Sep 2018 13:42:52 +0000 (15:42 +0200)] 
Add a test for Trac #15586

Summary: The bug is already fixed in master.

Test Plan: make test TEST=T15586

Reviewers: bgamari, simonpj

Reviewed By: simonpj

Subscribers: rwbarton, carter

GHC Trac Issues: #15586

Differential Revision:

13 months agoCompiler panic on invalid syntax (unterminated pragma)
roland [Tue, 4 Sep 2018 12:09:20 +0000 (14:09 +0200)] 
Compiler panic on invalid syntax (unterminated pragma)

Summary: After a parse error in OPTIONS_GHC issue an error message instead of a compiler panic.

Test Plan: make test TEST=T15053

Reviewers: Phyx, thomie, bgamari, monoidal, osa1

Reviewed By: Phyx, monoidal, osa1

Subscribers: tdammers, osa1, rwbarton, carter

GHC Trac Issues: #15053

Differential Revision:

13 months agoFix typos in -Wsimplifiable-class-constraints flag docs
Sergey Vinokurov [Mon, 3 Sep 2018 23:09:45 +0000 (00:09 +0100)] 
Fix typos in -Wsimplifiable-class-constraints flag docs

13 months agoRemove duplicate "since" field in glasgow_exts.rst
Josh Price [Sun, 2 Sep 2018 23:20:28 +0000 (19:20 -0400)] 
Remove duplicate "since" field in glasgow_exts.rst

13 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?

13 months agomake iToBase62's inner loop stricter in one of its arguments
Alp Mestanogullari [Sun, 2 Sep 2018 20:06:55 +0000 (22:06 +0200)] 
make iToBase62's inner loop stricter in one of its arguments

hadrian's support for dynamic ways is currently broken (see hadrian#641 [1]).
The stage 1 GHCs that hadrian produces end up producing bad code for
the `iToBase62` function after a few optimisation passes.

In the case where `quotRem` returns (overflowError, 0),
GHC isn't careful enough to realise q is _|_ and happily inlines,
distributes and floats code around until we end up trying to access
index `minBound :: Int` of an array of 62 chars, as a result of inlining
the definition of `quotRem` for Ints, in particular the minBound branch [2].

I will separately look into reproducing the bad transformation on a small
self-contained example and filling a ticket.


Test Plan: fixes hadrian#641

Reviewers: bgamari, tdammers

Reviewed By: tdammers

Subscribers: tdammers, rwbarton, carter

Differential Revision:

13 months agoReject class instances with type families in kinds
Ryan Scott [Sun, 2 Sep 2018 20:03:53 +0000 (22:03 +0200)] 
Reject class instances with type families in kinds

GHC doesn't know how to handle type families that appear in
class instances. Unfortunately, GHC didn't reject instances where
type families appear in //kinds//, leading to #15515. This is easily
rectified by calling `checkValidTypePat` on all arguments to a class
in an instance (and not just the type arguments).

Test Plan: make test TEST=T15515

Reviewers: bgamari, goldfire, simonpj

Reviewed By: simonpj

Subscribers: simonpj, rwbarton, carter

GHC Trac Issues: #15515

Differential Revision:

13 months agoRemove knot-tying bug in TcHsSyn.zonkTyVarOcc
Simon Peyton Jones [Fri, 31 Aug 2018 10:33:08 +0000 (11:33 +0100)] 
Remove knot-tying bug in TcHsSyn.zonkTyVarOcc

There was a subtle knot-tying bug in TcHsSyn.zonkTyVarOcc, revealed
in Trac #15552.

I fixed it by

* Eliminating the short-circuiting optimisation in zonkTyVarOcc,
  instead adding a finite map to get sharing of zonked unification

  See Note [Sharing when zonking to Type] in TcHsSyn

* On the way I /added/ the short-circuiting optimisation to
  TcMType.zonkTcTyVar, which has no such problem.  This turned
  out (based on non-systematic measurements) to be a modest win.

  See Note [Sharing in zonking] in TcMType

On the way I renamed some of the functions in TcHsSyn:

* Ones ending in "X" (like zonkTcTypeToTypeX) take a ZonkEnv

* Ones that do not end in "x" (like zonkTcTypeToType), don't.
  Instead they whiz up an empty ZonkEnv.

13 months agoCommets on flatten_args_tc
Simon Peyton Jones [Thu, 30 Aug 2018 10:55:31 +0000 (11:55 +0100)] 
Commets on flatten_args_tc

13 months agoComments only
Simon Peyton Jones [Thu, 30 Aug 2018 10:54:49 +0000 (11:54 +0100)] 
Comments only

13 months agoMinor improvements to comments [skip ci]
Richard Eisenberg [Fri, 31 Aug 2018 02:33:40 +0000 (22:33 -0400)] 
Minor improvements to comments [skip ci]

13 months agofix -ddump-asm description
Alp Mestanogullari [Thu, 30 Aug 2018 18:57:17 +0000 (20:57 +0200)] 
fix -ddump-asm description

Summary: It was missing some words.

Test Plan: None (docs only)

Reviewers: bgamari, monoidal

Reviewed By: monoidal

Subscribers: rwbarton, carter

Differential Revision:

13 months agoA few typos [ci skip]
Gabor Greif [Thu, 30 Aug 2018 16:38:38 +0000 (18:38 +0200)] 
A few typos [ci skip]

13 months agoFix the __GLASGOW_HASKELL__ comparison
Krzysztof Gogolewski [Thu, 30 Aug 2018 13:34:39 +0000 (15:34 +0200)] 
Fix the __GLASGOW_HASKELL__ comparison

GHC 8.4 corresponds to 804, not 840.

Found by Gabor Greif.

Test Plan: Harbormaster

Reviewers: ggreif, bgamari, mpickering

Reviewed By: ggreif

Subscribers: rwbarton, carter

Differential Revision:

13 months agoFinish stable split
David Feuer [Wed, 29 Aug 2018 20:34:21 +0000 (16:34 -0400)] 
Finish stable split

Long ago, the stable name table and stable pointer tables were one.
Now, they are separate, and have significantly different
implementations. I believe the time has come to finish the split
that began in #7674.

* Divide `rts/Stable` into `rts/StableName` and `rts/StablePtr`.

* Give each table its own mutex.

* Add FFI functions `hs_lock_stable_ptr_table` and
`hs_unlock_stable_ptr_table` and document them.
  These are intended to replace the previously undocumented
`hs_lock_stable_tables` and `hs_lock_stable_tables`,
  which are now documented as deprecated synonyms.

* Make `eqStableName#` use pointer equality instead of unnecessarily
comparing stable name table indices.

Reviewers: simonmar, bgamari, erikd

Reviewed By: bgamari

Subscribers: rwbarton, carter

GHC Trac Issues: #15555

Differential Revision:

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

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

13 months agoRename kind vars in left-to-right order in bindHsQTyVars
Ryan Scott [Tue, 28 Aug 2018 20:58:52 +0000 (22:58 +0200)] 
Rename kind vars in left-to-right order in bindHsQTyVars

When renaming kind variables in an `LHsQTyVars`, we were
erroneously putting all of the kind variables in the binders
//after// the kind variables in the body, resulting in #15568. The
fix is simple: just swap the order of these two around.

Test Plan: make test TEST=T15568

Reviewers: simonpj, bgamari, goldfire

Reviewed By: goldfire

Subscribers: goldfire, rwbarton, carter

GHC Trac Issues: #15568

Differential Revision:

13 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

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

13 months agoRemove dead code for commandline parsing
Krzysztof Gogolewski [Tue, 28 Aug 2018 10:52:47 +0000 (12:52 +0200)] 
Remove dead code for commandline parsing

PrefixPred and AnySuffixPred are not used
since static flags were removed in bbd3c399939.

Test Plan: validate

Reviewers: bgamari, tdammers

Reviewed By: tdammers

Subscribers: rwbarton, carter

Differential Revision:

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

13 months agoRemove dph, vector, primitive and random from .gitmodules
Chaitanya Koparkar [Mon, 27 Aug 2018 15:19:57 +0000 (17:19 +0200)] 
Remove dph, vector, primitive and random from .gitmodules

These packages were removed from the GHC source tree in
Phab:D4761 and 0905fec089b3270f540c7ee33959cbf8ecfcb4d7.

Reviewers: RyanGlScott, bgamari

Reviewed By: RyanGlScott

Subscribers: rwbarton, carter

Differential Revision:

13 months agoBump nofib submodule
Krzysztof Gogolewski [Mon, 27 Aug 2018 14:39:13 +0000 (16:39 +0200)] 
Bump nofib submodule

13 months agoFix #10859 by using foldr1 while deriving Eq instances
Chaitanya Koparkar [Mon, 27 Aug 2018 12:07:08 +0000 (14:07 +0200)] 
Fix #10859 by using foldr1 while deriving Eq instances

Previously, we were using foldl1 instead, which led to the derived
code to be wrongly associated.

Test Plan: ./validate

Reviewers: RyanGlScott, nomeata, simonpj, bgamari

Reviewed By: RyanGlScott, nomeata

Subscribers: rwbarton, carter

GHC Trac Issues: #10859

Differential Revision:

13 months agoDon't reify redundant class method tyvars/contexts
Ryan Scott [Mon, 27 Aug 2018 12:06:17 +0000 (14:06 +0200)] 
Don't reify redundant class method tyvars/contexts

Currently, reifying classes produces class methods with
redundant tyvars and class contexts in their type signatures, such
as in the following:

class C a where
  method :: forall a. C a => a

Fixing this is very straightforward: just apply `tcSplitMethodTy` to
the type of each class method to lop off the redundant parts.

It's possible that this could break some TH code in the wild that
assumes the existence of these tyvars and class contexts, so I'll
advertise this change in the release notes just to be safe.

Test Plan: make test TEST="TH_reifyDecl1 T9064 T10891 T14888"

Reviewers: goldfire, bgamari, simonpj

Reviewed By: simonpj

Subscribers: simonpj, rwbarton, carter

GHC Trac Issues: #15551

Differential Revision:

13 months agoTake strict fields into account in coverage checking
Ryan Scott [Mon, 27 Aug 2018 12:05:45 +0000 (14:05 +0200)] 
Take strict fields into account in coverage checking

The current pattern-match coverage checker implements the
formalism presented in the //GADTs Meet Their Match// paper in a
fairly faithful matter. However, it was discovered recently that
there is a class of unreachable patterns that
//GADTs Meet Their Match// does not handle: unreachable code due to
strict argument types, as demonstrated in #15305. This patch
therefore goes off-script a little and implements an extension to
the formalism presented in the paper to handle this case.

Essentially, when determining if each constructor can be matched on,
GHC checks if its associated term and type constraints are
satisfiable. This patch introduces a new form of constraint,
`NonVoid(ty)`, and checks if each constructor's strict argument types
satisfy `NonVoid`. If any of them do not, then that constructor is
deemed uninhabitable, and thus cannot be matched on. For the full
story of how this works, see
`Note [Extensions to GADTs Meet Their Match]`.

Along the way, I did a little bit of much-needed refactoring. In
particular, several functions in `Check` were passing a triple of
`(ValAbs, ComplexEq, Bag EvVar)` around to represent a constructor
and its constraints. Now that we're adding yet another form of
constraint to the mix, I thought it appropriate to turn this into
a proper data type, which I call `InhabitationCandidate`.

Test Plan: make test TEST=T15305

Reviewers: simonpj, bgamari

Reviewed By: simonpj

Subscribers: rwbarton, carter

GHC Trac Issues: #15305

Differential Revision:

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

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

13 months agoghc, ghc-pkg: use getExecutablePath on Windows when base >= 4.11.0
Tamar Christina [Sat, 11 Aug 2018 18:25:09 +0000 (19:25 +0100)] 
ghc, ghc-pkg: use getExecutablePath on Windows when base >= 4.11.0

This completes the work started in D4227 by using just 'getExecutablePath'
in ghc and ghc-pkg when building with base >= 4.11.0.

On the long term, we will be able to simply kill the existing code that
follows (or not) symlinks and just get this behaviour for free from
getExecutable. For now we however have to require base >= 4.11.0 to be able
to just use getExecutablePath under Windows, and use the current code when
building with an older base.

Original code by @alpmestan commandeering since patch has been stale
and bug remains open.

Test Plan: Validate

Reviewers: angerman, bgamari, erikd, alpmestan

Reviewed By: bgamari

Subscribers: carter, rwbarton, thomie

GHC Trac Issues: #14483

Differential Revision:

13 months agoBetter error reporting for inaccessible code
Simon Peyton Jones [Fri, 24 Aug 2018 15:40:28 +0000 (16:40 +0100)] 
Better error reporting for inaccessible code

This patch fixes Trac #15558.  There turned out to be
two distinct problems

* In TcExpr.tc_poly_expr_nc we had

    tc_poly_expr_nc (L loc expr) res_ty
      = do { traceTc "tcPolyExprNC" (ppr res_ty)
           ; (wrap, expr')
               <- tcSkolemiseET GenSigCtxt res_ty $ \ res_ty ->
                  setSrcSpan loc $
                    -- NB: setSrcSpan *after* skolemising,
                    -- so we get better skolem locations
                  tcExpr expr res_ty

  Putting the setSrcSpan inside the tcSkolemise means that
  the location on the Implication constraint is the /call/
  to the function rather than the /argument/ to the call,
  and that is really quite wrong.

  I don't know what Richard's comment NB means -- I moved the
  setSrcSpan outside, and the "binding site" info in error
  messages actually improved.

  The reason I found this is that it affects the span reported
  for Trac #15558.

* In TcErrors.mkGivenErrorReporter we carefully munge the location
  for an insoluble Given constraint (Note [Inaccessible code]).
  But the 'implic' passed in wasn't necesarily the immediately-
  enclosing implication -- but for location-munging purposes
  it jolly well should be.

  Solution: use the innermost implication. This actually
  simplifies the code -- no need to pass an implication in to

13 months agoAdd comments about pretty-printing via IfaceSyn
Simon Peyton Jones [Fri, 24 Aug 2018 09:29:58 +0000 (10:29 +0100)] 
Add comments about pretty-printing via IfaceSyn

Provoked by discussion on Phab:D5097 (Trac #15546), I'm adding
a big Note explaing the strategy of pretty-printing via IfaceSyn

13 months agoComments only
Simon Peyton Jones [Fri, 24 Aug 2018 09:29:40 +0000 (10:29 +0100)] 
Comments only

13 months agoClean up TcHsSyn.zonkEnv
Simon Peyton Jones [Fri, 24 Aug 2018 07:14:15 +0000 (08:14 +0100)] 
Clean up TcHsSyn.zonkEnv

Triggered by Trac #15552, I'd been looking at ZonkEnv in TcHsSyn.

This patch does some minor refactoring

* Make ZonkEnv into a record with named fields, and use them.
  (I'm planning to add a new field, for TyCons, so this prepares
  the way.)

* Replace UnboundTyVarZonker (a higer order function) with the
  simpler and more self-descriptive ZonkFlexi data type, below.
 It's just much more perspicuous and direct, and (I suspect)
 a tiny bit faster too -- no unknown function calls.

data ZonkFlexi   -- See Note [Un-unified unification variables]
  = DefaultFlexi    -- Default unbound unificaiton variables to Any
  | SkolemiseFlexi  -- Skolemise unbound unification variables
                    -- See Note [Zonking the LHS of a RULE]
  | RuntimeUnkFlexi -- Used in the GHCi debugger

There was one knock-on effect in the GHCi debugger -- the
RuntimeUnkFlexi case.  Somehow previously, these RuntimeUnk
variables were sometimes getting SystemNames (and hence
printed as 'a0', 'a1', etc) and sometimes not (and hence
printed as 'a', 'b' etc).  I'm not sure precisely why, but
the new behaviour seems more uniform, so I just accepted the
(small) renaming wibbles in some ghci.debugger tests.

I had a quick look at perf: any changes are tiny.

13 months agoUpdate unicode tables to v. 12 of the standard
Artem Pelenitsyn [Tue, 21 Aug 2018 23:33:35 +0000 (19:33 -0400)] 
Update unicode tables to v. 12 of the standard

Reviewers: hvr, bgamari, Azel

Reviewed By: bgamari

Subscribers: thomie, Azel, rwbarton, carter

GHC Trac Issues: #5518, #15525

Differential Revision:

13 months agodocs: Add changelog and release notes entry for traceBinaryEvent#
Ben Gamari [Tue, 21 Aug 2018 23:08:12 +0000 (19:08 -0400)] 
docs: Add changelog and release notes entry for traceBinaryEvent#

13 months agoTcSimplify: Condense MASSERT2() usage onto a single line
Ben Gamari [Fri, 24 Aug 2018 02:39:06 +0000 (22:39 -0400)] 
TcSimplify: Condense MASSERT2() usage onto a single line

Sadly macOS's C preprocessor gets angry at the sight of multi-line macro

13 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

13 months agoComments only
Simon Peyton Jones [Wed, 22 Aug 2018 09:04:08 +0000 (10:04 +0100)] 
Comments only

13 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

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

13 months agoRevert "driver: unconditionally disable relaxation when linking partially"
Ryan Scott [Wed, 22 Aug 2018 13:19:42 +0000 (09:19 -0400)] 
Revert "driver: unconditionally disable relaxation when linking partially"

This reverts commit 1cc9061fce4270739677d475190fd6e890e8b1f9.

This appears to break a clean build with certain versions of
``. See

13 months agoRevert "Properly tag fun field of PAPs generated by ap_0_fast"
Ömer Sinan Ağacan [Wed, 22 Aug 2018 05:52:50 +0000 (08:52 +0300)] 
Revert "Properly tag fun field of PAPs generated by ap_0_fast"

This reverts commit 2693eb11f55f2001701c90c24183e21c794a8be1.

This patch isn't ready yet, see D5051.

13 months agoAdd traceBinaryEvent# primop
Mitsutoshi Aoe [Tue, 21 Aug 2018 20:08:17 +0000 (16:08 -0400)] 
Add traceBinaryEvent# primop

This adds a new primop called traceBinaryEvent# that takes the length
of binary data and a pointer to the data, then emits it to the eventlog.

There is some example code that uses this primop and the new event:

* [traceBinaryEventIO][1] that calls `traceBinaryEvent#`

* [A patch to ghc-events][2] that parses the new `EVENT_USER_BINARY_MSG`

There's no corresponding issue on Trac but it was discussed at
ghc-devs [3].


Reviewers: bgamari, erikd, simonmar

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

Differential Revision:

13 months agodocs: "state transformer" -> "state monad" / "ST" (whichever is meant)
Artem Pelenitsyn [Tue, 21 Aug 2018 20:07:39 +0000 (16:07 -0400)] 
docs: "state transformer" -> "state monad" / "ST" (whichever is meant)

FIxes #15189.

Reviewers: hvr, bgamari, simonmar, simonpj

Reviewed By: simonpj

Subscribers: simonpj, rwbarton, thomie, carter

GHC Trac Issues: #15189

Differential Revision:

13 months agoFix precision of asinh/acosh/atanh by making them primops
Artem Pelenitsyn [Tue, 21 Aug 2018 20:07:24 +0000 (16:07 -0400)] 
Fix precision of asinh/acosh/atanh by making them primops

Reviewers: hvr, bgamari, simonmar, jrtc27

Reviewed By: bgamari

Subscribers: alpmestan, rwbarton, thomie, carter

Differential Revision:

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

13 months agoProperly tag fun field of PAPs generated by ap_0_fast
Ömer Sinan Ağacan [Tue, 21 Aug 2018 20:06:29 +0000 (16:06 -0400)] 
Properly tag fun field of PAPs generated by ap_0_fast

Currently ap_0_fast doesn't maintain the invariant for PAP fun fields
which says if the closure can be tagged, it should be. This is checked
by `Sanity.c:checkPAP` and correctly implemented by `genautoapply`.

This causes sanity check failures when we have a profiling code like

    f = {-# SCC scc #-} g

where g is a PAP or a FUN, and `scc` is different than the current cost

Test Plan: Slow validate (not done yet)

Reviewers: simonmar, bgamari, erikd

Reviewed By: simonmar

Subscribers: rwbarton, carter

GHC Trac Issues: #15508

Differential Revision:

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

13 months agoShow -with-rtsopts options in runtime's --info (#15261)
roland [Tue, 21 Aug 2018 20:05:45 +0000 (16:05 -0400)] 
Show -with-rtsopts options in runtime's --info (#15261)

Add an additional line to the output of +RTS --info.  It shows the value
of the flag -with-rtsopts provided at compile/link time.

Test Plan: make test TESTS="T15261a T15261b"

Reviewers: hvr, erikd, dfeuer, thomie, austin, bgamari, simonmar, osa1,

Reviewed By: osa1, monoidal

Subscribers: osa1, rwbarton, carter

GHC Trac Issues: #15261

Differential Revision:

13 months agoFix ambiguous/out-of-scope Haddock identifiers
Alec Theriault [Tue, 21 Aug 2018 20:05:16 +0000 (16:05 -0400)] 
Fix ambiguous/out-of-scope Haddock identifiers

This drastically cuts down on the number of Haddock warnings when making
docs for `base`.  Plus this means more actual links end up in the docs!
Also fixed other small mostly markup issues in the documentation along
the way.

This is a docs-only change.

Reviewers: hvr, bgamari, thomie

Reviewed By: thomie

Subscribers: thomie, rwbarton, carter

Differential Revision:

13 months agobase: Mark `findIndices` as INLINABLE instead of INLINE (fixes #15426)
Kevin Buhr [Tue, 21 Aug 2018 20:04:59 +0000 (16:04 -0400)] 
base: Mark `findIndices` as INLINABLE instead of INLINE (fixes #15426)

If `findIndices` is marked INLINE in `Data.OldList`, then the unfolded
versions of `elemIndex` and `findIndex` included in the interface file
are unfusible (even though `findIndices` itself remains fusible).  By
marking it INLINABLE instead, elemIndex` and `findIndex` will fuse

Test Plan: make TEST=T15426

Reviewers: hvr, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, carter

GHC Trac Issues: #15426

Differential Revision:

13 months agorts/RetainerProfile: Dump closure type if pop() fails
Ryan Scott [Tue, 21 Aug 2018 20:04:45 +0000 (16:04 -0400)] 
rts/RetainerProfile: Dump closure type if pop() fails

While investigating #15529, I noticed that the `barf`ed
error message in `pop()` doesn't print out the closure type that
causes it to crash. Let's do so.

Reviewers: bgamari, erikd, simonmar

Reviewed By: bgamari

Subscribers: rwbarton, carter

GHC Trac Issues: #15529

Differential Revision:

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

13 months agotestsuite: Deduplicate source in wcompat-warnings test
Ben Gamari [Tue, 21 Aug 2018 16:48:34 +0000 (12:48 -0400)] 
testsuite: Deduplicate source in wcompat-warnings test

13 months agoSimplify callSiteInline a little
Simon Peyton Jones [Fri, 4 May 2018 14:47:31 +0000 (15:47 +0100)] 
Simplify callSiteInline a little

This patch has virtually no effect on anything (according to a
nofib run).  But it simplifies the definition of interesting_call
by being a bit less gung-ho about inlining nested function
bindings.  See Note [Nested functions]

        Program           Size    Allocs   Runtime   Elapsed  TotalMem
           anna          +0.2%     -0.0%     0.163     0.163      0.0%
   binary-trees          +0.1%     +0.0%     -4.5%     -4.5%      0.0%
      cacheprof          -0.1%     +0.1%     -4.7%     -4.8%     +2.7%
          fasta          +0.2%      0.0%     +2.6%     +3.0%      0.0%
          fluid          -0.0%     -0.6%     0.011     0.011      0.0%
         gamteb          -0.1%     -0.0%     0.069     0.070      0.0%
            hpg          +0.1%     +0.0%     +0.7%     +0.7%      0.0%
          infer          +0.3%     +0.2%     0.097     0.098      0.0%
         lambda          -0.1%     -0.0%     +2.0%     +2.0%      0.0%
         n-body          +0.1%     -0.1%     -0.1%     -0.1%      0.0%
         simple          -0.2%     -0.2%     +0.6%     +0.6%      0.0%
  spectral-norm          +0.1%     -0.0%     -0.1%     -0.1%      0.0%
            tak          -0.0%     -0.1%     0.024     0.024      0.0%
            Min          -0.4%     -0.6%     -5.3%     -5.3%      0.0%
            Max          +0.3%     +0.2%     +3.3%     +3.3%    +15.0%
 Geometric Mean          -0.0%     -0.0%     -0.3%     -0.3%     +0.2%

(cherry picked from commit 33de71fa06d03e6da396a7c0a314fea3b492ab91)

(This reverts the previous reversion in commit

13 months agoIntroduce flag -keep-hscpp-files
roland [Tue, 21 Aug 2018 16:18:26 +0000 (12:18 -0400)] 
Introduce flag -keep-hscpp-files

Test Plan: `make test=T10869`

Reviewers: mpickering, thomie, ezyang, bgamari

Reviewed By: thomie, bgamari

Subscribers: rwbarton, carter

GHC Trac Issues: #10869

Differential Revision:

13 months agofunction-section: enable on windows
Tamar Christina [Tue, 21 Aug 2018 16:13:06 +0000 (12:13 -0400)] 
function-section: enable on windows

gc-sections was onced observed to be slow on Windows, which is the only
reason it's not enabled yet.  However, it seems to be better now.

Test Plan: ./validate

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15051

Differential Revision:

13 months agoReplace most occurences of foldl with foldl'. [Tue, 21 Aug 2018 16:10:38 +0000 (12:10 -0400)] 
Replace most occurences of foldl with foldl'.

This patch adds foldl' to GhcPrelude and changes must occurences
of foldl to foldl'. This leads to better performance especially
for quick builds where GHC does not perform strictness analysis.

It does change strictness behaviour when we use foldl' to turn
a argument list into function applications. But this is only a
drawback if code looks ONLY at the last argument but not at the first.
And as the benchmarks show leads to fewer allocations in practice
at O2.

Compiler performance for Nofib:

O2 Allocations:
        -1 s.d.                -----            -0.0%
        +1 s.d.                -----            -0.0%
        Average                -----            -0.0%

O2 Compile Time:
        -1 s.d.                -----            -2.8%
        +1 s.d.                -----            +1.3%
        Average                -----            -0.8%

O0 Allocations:
        -1 s.d.                -----            -0.2%
        +1 s.d.                -----            -0.1%
        Average                -----            -0.2%

Test Plan: ci

Reviewers: goldfire, bgamari, simonmar, tdammers, monoidal

Reviewed By: bgamari, monoidal

Subscribers: tdammers, rwbarton, thomie, carter

Differential Revision:

13 months agoFix #line pragmas in nested comments
Ben Sklaroff [Tue, 21 Aug 2018 16:03:24 +0000 (12:03 -0400)] 
Fix #line pragmas in nested comments

When parsing a nested comment or nested doc comment in the lexer, if we
see a line starting with '#' we attempt to parse a #line pragma. This
fixes how ghc handles output of the C preproccesor (-cpp flag) when the
original source has C comments or pragmas inside haskell comments.

Updates haddock submodule.

Test Plan: ./validate

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #314

Differential Revision:

13 months agoFix redundant imports of Class
Ben Gamari [Tue, 21 Aug 2018 21:18:14 +0000 (17:18 -0400)] 
Fix redundant imports of Class

13 months agodriver: unconditionally disable relaxation when linking partially
Sergei Trofimovich [Tue, 21 Aug 2018 19:08:42 +0000 (20:08 +0100)] 
driver: unconditionally disable relaxation when linking partially

user explicitly uses -Wl,--relax for most built binaries.

Most of the time this works fine except for capi haskell code
similar to the following:

module Z where

import Foreign.C

foreign import capi "unistd.h close" c_close :: CInt -> IO CInt

In this case compilation fails as:

$ inplace/bin/ghc-stage2 -c Z.hs -optl-Wl,--relax -fforce-recomp
ld: --relax and -r may not be used together

GHC's driver already disables relaxation on sparc as there relaxation
is already a default mode.

This change disables relaxation on partial linking for all platforms
where linker is binutils linker.

Reported-by: wmyrda
Signed-off-by: Sergei Trofimovich <>
Test Plan: pass -optl-Wl,--relax in test above

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

Differential Revision:

14 months agoAdd a solveEqualities to tcClassDecl1
Simon Peyton Jones [Tue, 21 Aug 2018 14:57:56 +0000 (15:57 +0100)] 
Add a solveEqualities to tcClassDecl1

Trac #15505 showed that, when we have a type error, we
could have an unfilled-in coercion hole.  We don't want an
assertion error in that case.

The underlying cause is that tcClassDecl1 should call
solveEqualities to fully solve all top-level equalities
(or fail in the attempt).

I also refactored the ClassDecl case for tcTyClDecl1 into
a new function tcClassDecl1.  That makes it symmetrical
with the others.

14 months agoComments only
Simon Peyton Jones [Mon, 20 Aug 2018 08:50:31 +0000 (09:50 +0100)] 
Comments only

14 months agoImprove ambiguous-occurrence error message
Simon Peyton Jones [Mon, 20 Aug 2018 09:01:16 +0000 (10:01 +0100)] 
Improve ambiguous-occurrence error message

Trac #15487 correctly reported that the qualification
of a Name in an ambiguous-occurrence error message was
wrong.  This patch fixes it.

It's easily done, in RnUtils.addNameClashErrRn

The problem was that in complaining about M.x we must
enusre that 'M' part is the same as that used in

14 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

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

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

14 months agoUpdate .mailmap [skip ci]
Thomas Miedema [Fri, 17 Aug 2018 20:25:05 +0000 (22:25 +0200)] 
Update .mailmap [skip ci]

14 months agoInitialise cec_suppress properly
Simon Peyton Jones [Mon, 20 Aug 2018 14:54:14 +0000 (15:54 +0100)] 
Initialise cec_suppress properly

In TcErrors, cec_suppress is used to suppress low-priority
errors in favour of truly insoluble ones.

But I was failing to initialise it correcly at top level, which
resulted in Trac #15539.  Easy to fix.

A few regression tests have fewer errors reported, but that seems to
be an improvement.

14 months agoCSE should deal with letrec (#9441)
roland [Sat, 18 Aug 2018 21:45:31 +0000 (23:45 +0200)] 
CSE should deal with letrec (#9441)

Summary: Write tests with fewer lines. See comments of nomeata in

Test Plan: make test TESTS='T9441a T9441b T9441c'

Reviewers: nomeata, dfeuer, bgamari

Reviewed By: nomeata

Subscribers: rwbarton, carter

GHC Trac Issues: #9441

Differential Revision:

14 months agoAdd test cases for Ticket #12146.
Aditya [Sat, 9 Jul 2016 06:11:25 +0000 (11:41 +0530)] 
Add test cases for Ticket #12146.

Two tests - a ghci script and a compile fail test have been added.

14 months agoAdd comment explaining change in syntax error suggestion for #12146.
Aditya [Sat, 9 Jul 2016 06:08:38 +0000 (11:38 +0530)] 
Add comment explaining change in syntax error suggestion for #12146.

14 months agoMake ghci work for stage1 and Hadrian
Neil Mitchell [Thu, 9 Aug 2018 12:47:20 +0000 (13:47 +0100)] 
Make ghci work for stage1 and Hadrian

This allows you to use the ghc-in-ghci script in Make even if you
haven't built stage2, and also with Hadrian.  Because of the way -I
works, it will prefer Make/stage2.

14 months agobase: Rewrite semigroup documentation
Tobias Pflug [Fri, 3 Aug 2018 20:52:37 +0000 (22:52 +0200)] 
base: Rewrite semigroup documentation

14 months agobase: rewrite Monoid module docs
Tobias Pflug [Wed, 8 Aug 2018 21:21:02 +0000 (23:21 +0200)] 
base: rewrite Monoid module docs

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

14 months agoDocument default value of +RTS -N in user's guide
Ömer Sinan Ağacan [Fri, 17 Aug 2018 07:56:28 +0000 (10:56 +0300)] 
Document default value of +RTS -N in user's guide

Summary: (This is documented in `+RTS -?` but wasn't documented in the user's guide)

Reviewers: simonmar, bgamari, monoidal

Reviewed By: monoidal

Subscribers: rwbarton, carter

Differential Revision:

14 months agoRename SigTv to TyVarTv (#15480)
Joachim Breitner [Fri, 17 Aug 2018 00:16:44 +0000 (17:16 -0700)] 
Rename SigTv to TyVarTv (#15480)

because since #15050, these are no longer used in pattern SIGnatures,
but still in other places where meta-variables should only be unified
with TYpe VARiables.

I also found mentions of `SigTv` in parts of the renamer and desugarer
that do not seem to directly relate to `SigTv` as used in the type
checker, but rather to uses of `forall a.` in type signatures. I renamed
these to `ScopedTv`.

Differential Revision:

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

14 months agoprimops: Drop documentation for WORD_SIZE_IN_BITS < 32
Chai T. Rex [Wed, 15 Aug 2018 20:37:55 +0000 (16:37 -0400)] 
primops: Drop documentation for WORD_SIZE_IN_BITS < 32

Removes documentation suggesting that 30 and 31-bit code generation is supported
(in support of

14 months agoCosmetics in GraphColor
Krzysztof Gogolewski [Wed, 15 Aug 2018 16:20:36 +0000 (18:20 +0200)] 
Cosmetics in GraphColor

This allows to run ghc-in-ghci when :set -XTypeApplications is in

14 months agoAdd a test for Trac #15523
Krzysztof Gogolewski [Wed, 15 Aug 2018 14:49:32 +0000 (16:49 +0200)] 
Add a test for Trac #15523

Summary: Fortunately the bug is not present in master.

Test Plan: make test TEST=T15523

Reviewers: bgamari, RyanGlScott

Reviewed By: RyanGlScott

Subscribers: RyanGlScott, rwbarton, carter

GHC Trac Issues: #15523

Differential Revision:

14 months agoprimops: Drop support for WORD_SIZE_IN_BITS < 32
Ben Gamari [Wed, 15 Aug 2018 14:49:26 +0000 (16:49 +0200)] 
primops: Drop support for WORD_SIZE_IN_BITS < 32

Summary: Fixes #15486.

Test Plan: Validate

Reviewers: monoidal

Reviewed By: monoidal

Subscribers: rwbarton, carter

GHC Trac Issues: #15486

Differential Revision:

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

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