ghc.git
13 months agoRegressions caused by workaround to #14963 wip/tdammers/disable-defer-type-errors-ghci
Tobias Dammers [Tue, 12 Jun 2018 10:39:22 +0000 (12:39 +0200)] 
Regressions caused by workaround to #14963

13 months agoTest for #14963 workaround
Tobias Dammers [Tue, 12 Jun 2018 10:38:04 +0000 (12:38 +0200)] 
Test for #14963 workaround

13 months agoDocumentation
Tobias Dammers [Tue, 12 Jun 2018 08:40:22 +0000 (10:40 +0200)] 
Documentation

13 months agoDisable error deferring in interactive statements
Tobias Dammers [Tue, 12 Jun 2018 08:01:26 +0000 (10:01 +0200)] 
Disable error deferring in interactive statements

The `-fdefer-type-errors` flag, as well as `-fdefer-typed-holes` and
`-fdefer-out-of-scope-variables` (which are implied by
`-fdefer-type-errors`) currently cause GHCi to crash on perfectly
well-typed programs (see Trac:#14963).

Rather than fixing the underlying problem, we provide a workaround by
simply disabling the three offending extensions while running
interactive statements.

13 months agotestsuite: allow passing extra_hc_options to ghci
Tobias Dammers [Tue, 12 Jun 2018 10:38:26 +0000 (12:38 +0200)] 
testsuite: allow passing extra_hc_options to ghci

We need this in order to test passing flags to ghci externally vs. via a
:set command.

13 months agoRevert "ghc-pkg: recompute `abi-depends` for updated packages"
Ben Gamari [Mon, 21 May 2018 20:37:31 +0000 (16:37 -0400)] 
Revert "ghc-pkg: recompute `abi-depends` for updated packages"

This reverts commit 1cdc14f9c014f1a520638f7c0a01799ac6d104e6.

This is causing non-deterministic testsuite output.

13 months agoCheck for type families in an instance context
Simon Peyton Jones [Mon, 21 May 2018 12:38:12 +0000 (13:38 +0100)] 
Check for type families in an instance context

This patch adds a check for type families to the instance-decl
termination check.  See Note [Type families in instance contexts]
and Trac #15172.

13 months agoMake dischargeFmv handle Deriveds
Simon Peyton Jones [Mon, 21 May 2018 09:38:03 +0000 (10:38 +0100)] 
Make dischargeFmv handle Deriveds

A Derived CFunEqCan does not "own" its FlatMetaTv (fmv), and should not
update it.  But one caller (canCFunEqCan) was failing to satisfy the
precondition to dischargeFmv, which led to a crash (Trac #15170).

I fixed this by making dischargeFmv handle Deriveds (to avoid forcing
each caller to do so separately).

NB: this does not completely fix the original #15170 bug, but I'll
explain that on the ticket.  The test case for this patch is actually
the program in comment:1.

13 months agoRemove TcType.toTcType
Simon Peyton Jones [Mon, 21 May 2018 08:00:32 +0000 (09:00 +0100)] 
Remove TcType.toTcType

In the olden days we insisted that only TcTyVars could appear
in a TcType.  But now we are more accommodating; see TcType
  Note [TcTyVars and TyVars in the typechecker]

This patch removes a function that converted a Type to a TcType.
It didn't do anything useful except statisfy an invariant that
we no longer have.  Now it's gone.

13 months agoFix perf numbers for #15164
Simon Peyton Jones [Mon, 21 May 2018 10:02:57 +0000 (11:02 +0100)] 
Fix perf numbers for #15164

13 months agoDo better sharing in the short-cut solver
Simon Peyton Jones [Sun, 20 May 2018 20:43:45 +0000 (21:43 +0100)] 
Do better sharing in the short-cut solver

Trac #15164 showed that it sometimes really matters to share
sub-proofs when solving constraints.  Without it, we can get
exponentialy bad behaviour.

Fortunately, it's easily solved.
Note [Shortcut try_solve_from_instance] explains.

I did some minor assocaited refactoring.

13 months agoghc-pkg: recompute `abi-depends` for updated packages
Austin Seipp [Sun, 20 May 2018 17:25:09 +0000 (13:25 -0400)] 
ghc-pkg: recompute `abi-depends` for updated packages

See `Note [Recompute abi-depends]` for more information.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
Test Plan: `./validate`

Reviewers: bgamari, ezyang

Reviewed By: bgamari

Subscribers: tdammers, juhp, carter, alexbiehl, shlevy, cocreature,
rwbarton, thomie

GHC Trac Issues: #14381

Differential Revision: https://phabricator.haskell.org/D4159

13 months agoghc-prim: Bump version
Ben Gamari [Sun, 20 May 2018 23:47:43 +0000 (19:47 -0400)] 
ghc-prim: Bump version

unpackClosure#'s behavior and type has changed. This caused a CPP guard
in the new ghc-heap package to fail when bootstrapping with GHC 8.4.

Test Plan: Validate bootstrapping with GHC 8.4

Reviewers: RyanGlScott

Subscribers: rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4716

14 months agoAdd HeapView functionality
Patrick Dougherty [Wed, 16 May 2018 20:50:13 +0000 (16:50 -0400)] 
Add HeapView functionality

This pulls parts of Joachim Breitner's ghc-heap-view library inside GHC.
The bits added are the C hooks into the RTS and a basic Haskell wrapper
to these C hooks. The main reason for these to be added to GHC proper
is that the code needs to be kept in sync with the closure types
defined by the RTS. It is expected that the version of HeapView shipped
with GHC will always work with that version of GHC and that extra
functionality can be layered on top with a library like ghc-heap-view
distributed via Hackage.

Test Plan: validate

Reviewers: simonmar, hvr, nomeata, austin, Phyx, bgamari, erikd

Reviewed By: bgamari

Subscribers: carter, patrickdoc, tmcgilchrist, rwbarton, thomie

Differential Revision: https://phabricator.haskell.org/D3055

14 months agorts: Fix compaction of SmallMutArrPtrs
Ben Gamari [Sat, 19 May 2018 18:00:59 +0000 (14:00 -0400)] 
rts: Fix compaction of SmallMutArrPtrs

This was blatantly wrong due to copy-paste blindness:

 * labels were shadowed, which GHC doesn't warn about(!), resulting in
   plainly wrong behavior
 * the sharing check was omitted
 * the wrong closure layout was being used

Moreover, the test wasn't being run due to its primitive dependency, so
I didn't even notice. Sillyness.

Test Plan: install `primitive`, `make test TEST=compact_small_array`

Reviewers: simonmar, erikd

Reviewed By: simonmar

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #13857.

Differential Revision: https://phabricator.haskell.org/D4702

14 months agoAnother batch of './validation --slow' tweaks
Alp Mestanogullari [Sat, 19 May 2018 18:00:21 +0000 (14:00 -0400)] 
Another batch of './validation --slow' tweaks

This finally gets us to a green ./validate --slow on linux for a ghc
checkout from the beginning of this week, see

  https://circleci.com/gh/ghc/ghc/4739

This is hopefully the final (or second to final) patch to
address #14890.

Test Plan: ./validate --slow

Reviewers: bgamari, hvr, simonmar

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14890

Differential Revision: https://phabricator.haskell.org/D4712

14 months agobase: Fix typo
Ben Gamari [Thu, 17 May 2018 03:44:34 +0000 (23:44 -0400)] 
base: Fix typo

14 months agobase: Add Foldable and Traversable instances for Alt
Jack Henahan [Wed, 16 May 2018 20:39:15 +0000 (16:39 -0400)] 
base: Add Foldable and Traversable instances for Alt

Add Foldable and Traversable instances for Data.Monoid.Alt

Signed-off-by: Jack Henahan <jhenahan@me.com>
Reviewers: hvr, bgamari

Reviewed By: bgamari

Subscribers: mpickering, rwbarton, thomie, carter

GHC Trac Issues: #15099

Differential Revision: https://phabricator.haskell.org/D4698

14 months agoFix retainer profiling after SRT overhaul
Simon Marlow [Sat, 19 May 2018 05:43:52 +0000 (08:43 +0300)] 
Fix retainer profiling after SRT overhaul

Recent changes to SRTs (D4632, D4637) also required changes to
RetainerProfile.c. This should hopefully get things working again.

Test Plan: validate with profiling turned on

Reviewers: bgamari, osa1, tdammers, erikd

Subscribers: rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4707

14 months agoDo not unify representational equalities
Simon Peyton Jones [Fri, 18 May 2018 12:58:25 +0000 (13:58 +0100)] 
Do not unify representational equalities

This patch is an easy fix to Trac #15144, which was caused
by accidentally unifying a representational equality in the
unflattener.  (The main code in TcInteract was always careful
not to do so, but I'd missed the test in the unflattener.)

See Note [Do not unify representational equalities]
in TcInteract

14 months agoDebug tracing only
Simon Peyton Jones [Fri, 18 May 2018 07:47:26 +0000 (08:47 +0100)] 
Debug tracing only

14 months agoOrient TyVar/TyVar equalities with deepest on the left
Simon Peyton Jones [Fri, 18 May 2018 07:43:11 +0000 (08:43 +0100)] 
Orient TyVar/TyVar equalities with deepest on the left

Trac #15009 showed that, for Given TyVar/TyVar equalities, we really
want to orient them with the deepest-bound skolem on the left. As it
happens, we also want to do the same for Wanteds, but for a different
reason (more likely to be touchable).  Either way, deepest wins:
see TcUnify Note [Deeper level on the left].

This observation led me to some significant changes:

* A SkolemTv already had a TcLevel, but the level wasn't really being
  used.   Now it is!

* I updated added invariant (SkolInf) to TcType
  Note [TcLevel and untouchable type variables], documenting that
  the level number of all the ic_skols should be the same as the
  ic_tclvl of the implication

* FlatSkolTvs and FlatMetaTvs previously had a dummy level-number of
  zero, which messed the scheme up.   Now they get a level number the
  same way as all other TcTyVars, instead of being a special case.

* To make sure that FlatSkolTvs and FlatMetaTvs are untouchable (which
  was previously done via their magic zero level) isTouchableMetaTyVar
  just tests for those two cases.

* TcUnify.swapOverTyVars is the crucial orientation function; see the
  new Note [TyVar/TyVar orientation].  I completely rewrote this function,
  and it's now much much easier to understand.

I ended up doing some related refactoring, of course

* I noticed that tcImplicitTKBndrsX and tcExplicitTKBndrsX were doing
  a lot of useless work in the case where there are no skolems; I
  added a fast-patch

* Elminate the un-used tcExplicitTKBndrsSig; and thereby get rid of
  the higher-order parameter to tcExpliciTKBndrsX.

* Replace TcHsType.emitTvImplication with TcUnify.checkTvConstraints,
  by analogy with TcUnify.checkConstraints.

* Inline TcUnify.buildImplication into its only call-site in
  TcUnify.checkConstraints

* TcS.buildImplication becomes TcS.CheckConstraintsTcS, with a
  simpler API

* Now that we have NoEvBindsVar we have no need of termEvidenceAllowed;
  nuke the latter, adding Note [No evidence bindings] to TcEvidence.

14 months agoTiny refactor
Simon Peyton Jones [Thu, 10 May 2018 16:30:43 +0000 (17:30 +0100)] 
Tiny refactor

14 months agoComments only
Simon Peyton Jones [Thu, 10 May 2018 16:30:09 +0000 (17:30 +0100)] 
Comments only

14 months agoAdd regression tests for #11515 and #12563
Ryan Scott [Fri, 18 May 2018 15:50:07 +0000 (11:50 -0400)] 
Add regression tests for #11515 and #12563

Happily, both of these issues appear to have been fixed in GHC 8.2.
Let's add regression tests for them to ensure that they stay fixed.

14 months agoFix unwinding of C -> Haskell FFI calls with -threaded (2nd try)
Bartosz Nitka [Thu, 17 May 2018 15:06:33 +0000 (08:06 -0700)] 
Fix unwinding of C -> Haskell FFI calls with -threaded (2nd try)

Summary:
See the new note.
This should fix cb5c2fe875965b7aedbc189012803fc62e48fb3f enough
to unbreak Windows and OS X builds.

Test Plan: manual testing with patched gdb

Reviewers: bgamari, simonmar, erikd

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4694

14 months agoFix GHCi space leaks (#15111)
Simon Marlow [Tue, 1 May 2018 15:52:05 +0000 (16:52 +0100)] 
Fix GHCi space leaks (#15111)

Summary:
There were a number of leaks causing previously loaded modules to be
retained after a new `:load`.  This fixes enough leaks to get the
tests to pass from D4658.

Test Plan: See new tests in D4658

Reviewers: niteria, bgamari, simonpj, erikd

Subscribers: thomie, carter

GHC Trac Issues: #15111

Differential Revision: https://phabricator.haskell.org/D4659

14 months agoAdd /* fallthrough */ to fix -Wimplicit-fallthrough warning
Simon Marlow [Thu, 17 May 2018 08:04:05 +0000 (09:04 +0100)] 
Add /* fallthrough */ to fix -Wimplicit-fallthrough warning

14 months agoUpdate Cabal submodule
Simon Marlow [Thu, 17 May 2018 07:48:40 +0000 (08:48 +0100)] 
Update Cabal submodule

14 months agoComments and refactoring only
Simon Marlow [Wed, 16 May 2018 13:03:55 +0000 (14:03 +0100)] 
Comments and refactoring only

Addressing review comments on D4637

14 months agoFix #15073 by suggesting UnboxedTuples in an error message
Ryan Scott [Wed, 16 May 2018 16:59:45 +0000 (12:59 -0400)] 
Fix #15073 by suggesting UnboxedTuples in an error message

Under certain circumstances, `GeneralizedNewtypeDeriving`
can emit code which uses unboxed tuple types, but if `UnboxedTuples`
wasn't enabled, the error message that GHC gave didn't make it very
clear that it could be worked around by explicitly enabling the
extension. Easily fixed.

Test Plan: make test TEST=T15073

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: simonpj, thomie, carter

GHC Trac Issues: #15073

Differential Revision: https://phabricator.haskell.org/D4620

14 months agoImprove numeric stability of numericEnumFrom for floating numbers
HE, Tao [Wed, 16 May 2018 16:13:16 +0000 (12:13 -0400)] 
Improve numeric stability of numericEnumFrom for floating numbers

Fixes #15081.

Test Plan: cd libraries/base && make test TEST="enumNumeric"

Reviewers: hvr, bgamari

Reviewed By: bgamari

Subscribers: dfeuer, simonpj, thomie, carter

GHC Trac Issues: #15081

Differential Revision: https://phabricator.haskell.org/D4650

14 months agoFix #15039 by pretty-printing equalities more systematically
Ryan Scott [Wed, 16 May 2018 16:11:37 +0000 (12:11 -0400)] 
Fix #15039 by pretty-printing equalities more systematically

GHC previously had a handful of special cases for
pretty-printing equalities in a more user-friendly manner, but they
were far from comprehensive (see #15039 for an example of where this
fell apart).

This patch makes the pretty-printing of equalities much more
systematic. I've adopted the approach laid out in
https://ghc.haskell.org/trac/ghc/ticket/15039#comment:4, and updated
`Note [Equality predicates in IfaceType]` accordingly. We are now
more careful to respect the properties of the
`-fprint-explicit-kinds` and `-fprint-equality-relations` flags,
which led to some improvements in error message outputs.

Along the way, I also tweaked the error-reporting machinery not to
print out the type of a typed hole when the type is an unlifted
equality, since it's kind (`TYPE ('TupleRep '[])`) was more
confusing than anything.

Test Plan: make test TEST="T15039a T15039b T15039c T15039d"

Reviewers: simonpj, goldfire, bgamari

Reviewed By: simonpj

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15039

Differential Revision: https://phabricator.haskell.org/D4696

14 months agoAdd pprTraceM to Outputable as analog to traceM.
klebinger.andreas@gmx.at [Wed, 16 May 2018 16:11:27 +0000 (12:11 -0400)] 
Add pprTraceM to Outputable as analog to traceM.

Test Plan: ci, using it in monadic code.

Reviewers: bgamari, mpickering

Reviewed By: mpickering

Subscribers: rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4697

14 months agoInfoTables: Fix #if uses introduced by D4634
Ben Gamari [Wed, 16 May 2018 16:15:32 +0000 (12:15 -0400)] 
InfoTables: Fix #if uses introduced by D4634

14 months agoMake finalizers more reliable.
Tamar Christina [Wed, 16 May 2018 01:20:45 +0000 (21:20 -0400)] 
Make finalizers more reliable.

Ignore any errors thrown by finalizers when running them.

This prevents a faulty finalizer from stopping the rest being called.

Test Plan: ./validate, new test T13167

Reviewers: hvr, bgamari, simonmar

Reviewed By: bgamari, simonmar

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #13167

Differential Revision: https://phabricator.haskell.org/D4693

14 months agoMerge FUN_STATIC closure with its SRT
Simon Marlow [Sun, 22 Apr 2018 18:34:32 +0000 (19:34 +0100)] 
Merge FUN_STATIC closure with its SRT

Summary:
The idea here is to save a little code size and some work in the GC,
by collapsing FUN_STATIC closures and their SRTs.

This is (4) in a series; see D4632 for more details.

There's a tradeoff here: more complexity in the compiler in exchange
for a modest code size reduction (probably around 0.5%).

Results:
* GHC binary itself (statically linked) is 1% smaller
* -0.2% binary sizes in nofib (-0.5% module sizes)

Full nofib results comparing D4634 with this: P177 (ignore runtimes,
these aren't stable on my laptop)

Test Plan: validate, nofib

Reviewers: bgamari, niteria, simonpj, erikd

Subscribers: thomie, carter

Differential Revision: https://phabricator.haskell.org/D4637

14 months agoSave a word in the info table on x86_64
Simon Marlow [Sun, 22 Apr 2018 13:28:47 +0000 (14:28 +0100)] 
Save a word in the info table on x86_64

Summary:
An info table with an SRT normally looks like this:

    StgWord64 srt_offset
    StgClosureInfo layout
    StgWord32 layout
    StgWord32 has_srt

But we only need 32 bits for srt_offset on x86_64, because the small
memory model requires that code segments are at most 2GB. So we can
optimise this to

    StgClosureInfo layout
    StgWord32 layout
    StgWord32 srt_offset

saving a word.  We can tell whether the info table has an SRT or not,
because zero is not a valid srt_offset, so zero still indicates that
there's no SRT.

Test Plan:
* validate
* For results, see D4632.

Reviewers: bgamari, niteria, osa1, erikd

Subscribers: thomie, carter

Differential Revision: https://phabricator.haskell.org/D4634

14 months agoAllow CmmLabelDiffOff with different widths
Simon Marlow [Sun, 22 Apr 2018 11:48:11 +0000 (12:48 +0100)] 
Allow CmmLabelDiffOff with different widths

Summary:
This change makes it possible to generate a static 32-bit relative label
offset on x86_64. Currently we can only generate word-sized label
offsets.

This will be used in D4634 to shrink info tables.  See D4632 for more
details.

Test Plan: See D4632

Reviewers: bgamari, niteria, michalt, erikd, jrtc27, osa1

Subscribers: thomie, carter

Differential Revision: https://phabricator.haskell.org/D4633

14 months agoAn overhaul of the SRT representation
Simon Marlow [Mon, 26 Sep 2016 11:07:05 +0000 (12:07 +0100)] 
An overhaul of the SRT representation

Summary:
- Previously we would hvae a single big table of pointers per module,
  with a set of bitmaps to reference entries within it. The new
  representation is identical to a static constructor, which is much
  simpler for the GC to traverse, and we get to remove the complicated
  bitmap-traversal code from the GC.

- Rewrite all the code to generate SRTs in CmmBuildInfoTables, and
  document it much better (see Note [SRTs]). This has been something
  I've wanted to do since we moved to the new code generator, I
  finally had the opportunity to finish it while on a transatlantic
  flight recently :)

There are a series of 4 diffs:

1. D4632 (this one), which does the bulk of the changes

2. D4633 which adds support for smaller `CmmLabelDiffOff` constants

3. D4634 which takes advantage of D4632 and D4633 to save a word in
   info tables that have an SRT on x86_64. This is where most of the
   binary size improvement comes from.

4. D4637 which makes a further optimisation to merge some SRTs with
   static FUN closures.  This adds some complexity and the benefits
   are fairly modest, so it's not clear yet whether we should do this.

Results (after (3), on x86_64)

- GHC itself (staticaly linked) is 5.2% smaller

- -1.7% binary sizes in nofib, -2.9% module sizes. Full nofib results: P176

- I measured the overhead of traversing all the static objects in a
  major GC in GHC itself by doing `replicateM_ 1000 performGC` as the
  first thing in `Main.main`.  The new version was 5-10% faster, but
  the results did vary quite a bit.

- I'm not sure if there's a compile-time difference, the results are
  too unreliable.

Test Plan: validate

Reviewers: bgamari, michalt, niteria, simonpj, erikd, osa1

Subscribers: thomie, carter

Differential Revision: https://phabricator.haskell.org/D4632

14 months agoForce findPtr to be included in the binary
Simon Marlow [Wed, 9 May 2018 12:37:30 +0000 (13:37 +0100)] 
Force findPtr to be included in the binary

Summary: A better alternative to D4657.

Test Plan:
```
cd testsuite/tests/codeGen/should_run
../../../../inplace/bin/ghc-stage2 -debug cgrun001
nm cgrun001 | grep findPtr
```

Reviewers: bgamari, Phyx, erikd

Subscribers: rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4683

14 months agoLess Tc inside simplCore (Phase 1 for #14391)
Artem Pelenitsyn [Tue, 15 May 2018 22:07:23 +0000 (18:07 -0400)] 
Less Tc inside simplCore (Phase 1 for #14391)

Simplifier depends on typechecker in two points: `thNameToGhcName`
(`lookupThName_maybe`, in particular)  and `lookupGlobal`. We want to
cut the ties in two steps.

1. (Presented in this commit), reimplement both functions in a way that
doesn't use typechecker.

2. (Should follow), do code moving: a) `lookupGlobal` should go in some
typechecker-free place; b) `thNameToGhcName` should leave simplifier,
because it is not used there at all (probably, it should be placed
somewhere where `GhcPlugins` can see it -- this is suggested by Joachim
on Trac).

Details
=======

We redesigned lookup interface a bit so that it exposes some
`IO`-equivalents of `Tc`-features in use.

First, `CoreMonad.hs` still calls `lookupGlobal` which is no longer
bound to the typechecker monad, but still resides in `TcEnv.hs` — it
should be moved out of Tc-land at some point (“Phase 2”) in the
future in order to achieve its part of the #14391's goal.

Second, `lookupThName_maybe` is eliminated from `CoreMonad.hs`
completely; this already achieves its part of the goal of #14391. Its
client, though, `thNameToGhcName`, is better to be moved in the future
also, for it is not used in the `CoreMonad.hs` (or anywhere else)
anyway. Joachim suggested “any module reexported by GhcPlugins (or
maybe even that module itself)”.

As a side goal, we removed `initTcForLookup` which was instrumental for
the past version of `lookupGlobal`. This, in turn, called for pushing
some more parts of the lookup interface from the `Tc`-monad to `IO`,
most notably, adding `IO`-version of `lookupOrig` and pushing
`dataConInfoPtrToName` to `IO`. The `lookupOrig` part, in turn,
triggered a slight redesign of name cache updating interface: we now
have both, `updNameCacheIO` and `updNameCacheTc`, both accepting `mod`
and `occ` to force them inside, instead of more error-prone outside
before. But all these hardly have to do anything with #14391, mere
refactoring.

Reviewers: simonpj, nomeata, bgamari, hvr

Reviewed By: simonpj, bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14391

Differential Revision: https://phabricator.haskell.org/D4503

14 months agoAlgebraically simplify add/sub with carry/overflow
Sebastian Graf [Tue, 15 May 2018 17:12:56 +0000 (13:12 -0400)] 
Algebraically simplify add/sub with carry/overflow

Previously, the `{add,sub}{Int,Word}C#` PrimOps weren't handled
in PrelRules (constant folding and algebraic simplification) at all.
This implements the necessary logic, so that using these primitives
isn't too punishing compared to their well-optimised, overflow-unaware
counterparts.

This is so that using these primitives in `enumFromThenTo @Int` can
be optimized by constant folding, reducing closure sizes.

Reviewers: bgamari, simonpj, hsyl20

Reviewed By: bgamari, simonpj

Subscribers: AndreasK, thomie, carter

GHC Trac Issues: #8763

Differential Revision: https://phabricator.haskell.org/D4605

14 months agoCalling GetLastError() on Windows for socket IO (trac issue #12012)
ARJANEN Loïc Jean David [Mon, 14 May 2018 20:38:21 +0000 (16:38 -0400)] 
Calling GetLastError() on Windows for socket IO (trac issue #12012)

For the threaded RTS, putting a private copy of the throwErrno
series in GHC.IO.FD which gets if the operation was on a socket,
so that we can call c_maperrno if need be.
For the non-threaded RTS, if memory serves we call GetLastError()
in case of an error on socket IO. However, we don't do the translation
ErrCode ↔ Errno currently (and besides, it's a primop) so we do it if
needed through c_maperrno_func in the asynchronous read/write
functions.

Signed-off-by: ARJANEN Loïc Jean David <arjanen.loic@gmail.com>
Reviewers: ekmett, hvr, bgamari

Reviewed By: bgamari

Subscribers: thomie, carter

GHC Trac Issues: #12012

Differential Revision: https://phabricator.haskell.org/D4639

14 months agotestsuite: Disable T14697 on Windows
Ben Gamari [Mon, 14 May 2018 20:36:52 +0000 (16:36 -0400)] 
testsuite: Disable T14697 on Windows

Test Plan: Validate on Windows

Subscribers: thomie, carter

GHC Trac Issues: #14697, #15072

Differential Revision: https://phabricator.haskell.org/D4619

14 months agoMore explicit comment on switch in registerDelay
Kirill Zaborsky [Thu, 10 May 2018 14:57:59 +0000 (17:57 +0300)] 
More explicit comment on switch in registerDelay

14 months agoEnsure that RTS cabal file reflects dependency on libnuma
Ben Gamari [Mon, 14 May 2018 14:17:51 +0000 (10:17 -0400)] 
Ensure that RTS cabal file reflects dependency on libnuma

Test Plan: Validate with Hadrian and `libnuma` support

Reviewers: snowleopard, hvr, erikd, simonmar

Subscribers: izgzhen, alpmestan, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4616

14 months agoRevert "Simplify callSiteInline a little"
Ben Gamari [Mon, 14 May 2018 13:25:32 +0000 (09:25 -0400)] 
Revert "Simplify callSiteInline a little"

This lead to some rather significant performance regressions.
Specifically,

    bytes allocated value is too high:
        Expected    T5631(normal) bytes allocated: 1106015512 +/-5%
        Lower bound T5631(normal) bytes allocated: 1050714736
        Upper bound T5631(normal) bytes allocated: 1161316288
        Actual      T5631(normal) bytes allocated: 1164953208
        Deviation   T5631(normal) bytes allocated:        5.3 %
    *** unexpected stat test failure for T5631(normal)
    max_bytes_used value is too high:
        Expected    T9630(normal) max_bytes_used: 35324712 +/-15%
        Lower bound T9630(normal) max_bytes_used: 30026005
        Upper bound T9630(normal) max_bytes_used: 40623419
        Actual      T9630(normal) max_bytes_used: 43490984
        Deviation   T9630(normal) max_bytes_used:     23.1 %
    *** unexpected stat test failure for T9630(normal)

This reverts commit 7271db46c332f15c302b9a55f4ed005cdd0fb898.
This reverts commit b750dcc5d9e1df8505788a41d0cf0d92acd17f0d.
This reverts commit 33de71fa06d03e6da396a7c0a314fea3b492ab91.

14 months agotestsuite: Fix expected allocations of T9020 and T12425
Ben Gamari [Mon, 14 May 2018 21:19:07 +0000 (17:19 -0400)] 
testsuite: Fix expected allocations of T9020 and T12425

These were both improved by d92c7556501a4cdeb7d269c4624992c94d9b3b8b but the
changes were lost due to merge silliness.

14 months agoTidy up error suppression
Simon Peyton Jones [Tue, 15 May 2018 10:36:28 +0000 (11:36 +0100)] 
Tidy up error suppression

Trac #15152 showed that when a flag turned an error into a warning, we
were still (alas) suppressing subequent errors; includign their
essential addTcEvBind.  That led (rightly) to a Lint error.

This patch fixes it, and incidentally tidies up an ad-hoc special
case of out-of-scope variables (see the old binding for
'out_of_scope_killer' in 'tryReporters').

No test, because the problem was only shown up when turning
inaccessible code into a warning.

14 months agorts: export new absentSumFieldError from base
Sergei Trofimovich [Mon, 14 May 2018 20:51:48 +0000 (21:51 +0100)] 
rts: export new absentSumFieldError from base

commit b2ff5dde399cd012218578945ada1d9ff68daa35 "Fix #15038"
added new stable closure 'absentSumFieldError_closure' to
base package. This closure is used in rts package.

Unfortunately the symbol was not explicitly exported and build
failed on windows as:

```
"inplace/bin/ghc-stage1" -o ...hsc2hs.exe ...
rts/dist/build/libHSrts.a(RtsStartup.o): In function `hs_init_ghc':

rts/RtsStartup.c:272:0: error:
     undefined reference to `base_ControlziExceptionziBase_absentSumFieldError_closure'
    |
272 |     getStablePtr((StgPtr)absentSumFieldError_closure);
    | ^

```

This change adds 'absentSumFieldError_closure' to explicit export
into libHSbase.def.

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
14 months agoFix performance regressions from #14737
Tobias Dammers [Mon, 14 May 2018 12:50:29 +0000 (08:50 -0400)] 
Fix performance regressions from #14737

See #15019. When removing an unnecessary type equality check in #14737,
several regression tests failed. The cause was that some coercions that
are actually Refl coercions weren't passed in as such, which made the
equality check needlessly complex (Refl coercions can be discarded in
this particular check immediately, without inspecting the types at all).

We fix that, and get additional performance improvements for free.

Reviewers: goldfire, bgamari, simonpj

Reviewed By: bgamari, simonpj

Subscribers: simonpj, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4635

14 months agoRevert "rts: Compile with gcc -Og"
Ben Gamari [Mon, 14 May 2018 12:48:42 +0000 (08:48 -0400)] 
Revert "rts: Compile with gcc -Og"

This reverts commit d4abd031f6e8c2fa01f8949f60d8a02cca513804.

14 months agoFix #14973
Denis M [Mon, 14 May 2018 04:08:36 +0000 (00:08 -0400)] 
Fix #14973

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: thomie, carter

Differential Revision: https://phabricator.haskell.org/D4661

14 months agoutils/fs: use <sys/stat.h>, not <sys\stat.h>
Sergei Trofimovich [Mon, 14 May 2018 08:09:58 +0000 (09:09 +0100)] 
utils/fs: use <sys/stat.h>, not <sys\stat.h>

Fix cross-compilation failure from linux to windows:
```
  CC utils/unlit/dist-install/build/fs.o
utils/unlit/fs.c:24:10: fatal error: sys\stat.h: No such file or directory
 #include <sys\stat.h>
          ^~~~~~~~~~~~
```

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
14 months agoImprove some Foldable methods for NonEmpty
David Feuer [Mon, 14 May 2018 03:26:08 +0000 (23:26 -0400)] 
Improve some Foldable methods for NonEmpty

* `length` is improved by using the default definition,
  while `foldr1` is improved by using a custom one.

* Several methods had useless lazy pattern matches
  (i.e., the functions were actually strict in those arguments).
  Remove `~`s to clarify.

Reviewers: hvr, bgamari, mpickering, nomeata

Reviewed By: bgamari

Subscribers: ygale, rwbarton, thomie, carter

GHC Trac Issues: #15131

Differential Revision: https://phabricator.haskell.org/D4677

14 months agoFix another batch of `./validate --slow` failures
Alp Mestanogullari [Sun, 13 May 2018 22:38:18 +0000 (18:38 -0400)] 
Fix another batch of `./validate --slow` failures

A rather detailed summary can be found at:

    https://gist.github.com/alpmestan/be82b47bb88b7dc9ff84105af9b1bb82

This doesn't fix all expectation mismatches yet, but we're down to about
20 mismatches with my previous patch and this one, as opposed to ~150
when I got started.

Test Plan: ./validate --slow

Reviewers: bgamari, erikd, simonmar

Reviewed By: simonmar

Subscribers: thomie, carter

GHC Trac Issues: #14890

Differential Revision: https://phabricator.haskell.org/D4636

14 months agoAdd support for opting out of package environments
Herbert Valerio Riedel [Sun, 13 May 2018 22:37:18 +0000 (18:37 -0400)] 
Add support for opting out of package environments

This implements the first part proposed in #13753:

Define a special magic "null" environment, which instructs GHC to ignore
any package environment files. To this end, I propose to use the name
`-` (i.e. a single dash), as that is more portable than using the empty
string for environment variables. In other words, a

- `-package-env -` CLI flag, or a
- `GHC_ENVIRONMENT=-` env var (unless a `-package-env` flag is present)

would inhibit GHC from looking up and interpreting any package
environment files from the filesystem; this is the equivalent of
`-ignore-dot-ghci` for package environment files.

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #13753

Differential Revision: https://phabricator.haskell.org/D4690

14 months agoghc-pkg: Configure handle encodings
Ben Gamari [Sun, 13 May 2018 22:36:59 +0000 (18:36 -0400)] 
ghc-pkg: Configure handle encodings

This fixes #15021 using a the same approach as was used to fix the issue
in ghc (#10762).

Test Plan: Validate on Windows as user whose username contains
non-ASCII characters

Reviewers: simonmar

Reviewed By: simonmar

Subscribers: lehins, thomie, carter

GHC Trac Issues: #15021

Differential Revision: https://phabricator.haskell.org/D4642

14 months agoFix #14875 by introducing PprPrec, and using it
Ryan Scott [Sun, 13 May 2018 22:36:23 +0000 (18:36 -0400)] 
Fix #14875 by introducing PprPrec, and using it

Trying to determine when to insert parentheses during TH
conversion is a bit of a mess. There is an assortment of functions
that try to detect this, such as:

* `hsExprNeedsParens`
* `isCompoundHsType`
* `hsPatNeedsParens`
* `isCompoundPat`
* etc.

To make things worse, each of them have slightly different semantics.
Plus, they don't work well in the presence of explicit type
signatures, as #14875 demonstrates.

All of these problems can be alleviated with the use of an explicit
precedence argument (much like what `showsPrec` currently does). To
accomplish this, I introduce a new `PprPrec` data type, and define
standard predences for things like function application, infix
operators, function arrows, and explicit type signatures (that last
one is new). I then added `PprPrec` arguments to the various
`-NeedsParens` functions, and use them to make smarter decisions
about when things need to be parenthesized.

A nice side effect is that functions like `isCompoundHsType` are
now completely unneeded, since they're simply aliases for
`hsTypeNeedsParens appPrec`. As a result, I did a bit of refactoring
to remove these sorts of functions. I also did a pass over various
utility functions in GHC for constructing AST forms and used more
appropriate precedences where convenient.

Along the way, I also ripped out the existing `TyPrec`
data type (which was tailor-made for pretty-printing `Type`s) and
replaced it with `PprPrec` for consistency.

Test Plan: make test TEST=T14875

Reviewers: alanz, goldfire, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14875

Differential Revision: https://phabricator.haskell.org/D4688

14 months agoAdd note documenting refineDefaultAlt
Matthew Pickering [Sun, 13 May 2018 22:36:10 +0000 (18:36 -0400)] 
Add note documenting refineDefaultAlt

Reviewers: sjakobi, bgamari

Reviewed By: sjakobi

Subscribers: rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4687

14 months agoClarify what the FFI spec says
David Feuer [Sun, 13 May 2018 22:35:34 +0000 (18:35 -0400)] 
Clarify what the FFI spec says

Section 10.1.1 claimed that

> The FFI addendum stipulates that an implementation is free to
implement an unsafe call by performing a safe call ...

Reading through the FFI addendum (and the Haskell 2010 Report, which
integrates it), I see no such stipulation. I think this explains the
situation a bit better.

[ci skip]

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: thomie, carter

Differential Revision: https://phabricator.haskell.org/D4656

14 months agoGHCi: Include a note in the hint to expose a hidden package
Chaitanya Koparkar [Sun, 13 May 2018 22:35:18 +0000 (18:35 -0400)] 
GHCi: Include a note in the hint to expose a hidden package

Test Plan: validate

Reviewers: bgamari, RyanGlScott, osa1

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15055

Differential Revision: https://phabricator.haskell.org/D4669

14 months agorts: Compile with gcc -Og
Ben Gamari [Sun, 13 May 2018 22:34:48 +0000 (18:34 -0400)] 
rts: Compile with gcc -Og

This optimisation level is specifically designed to provide the benefits
of optimisation without the obfuscation that sometimes results.

Test Plan: Validate

Reviewers: simonmar

Reviewed By: simonmar

Subscribers: rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4675

14 months agoRemove unused things from utils/Digraph
David Feuer [Sun, 13 May 2018 22:34:38 +0000 (18:34 -0400)] 
Remove unused things from utils/Digraph

`utils/Digraph` had a bunch of code that wasn't actually being used,
much of which wasn't documented at all, some of which was clearly
ill-considered, and some of which was documented as being inefficient.

Remove all unused code from that module except for the obvious and
innocuous `emptyG`.

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4676

14 months agoFix changelog message for asinh
David Feuer [Sun, 13 May 2018 22:34:26 +0000 (18:34 -0400)] 
Fix changelog message for asinh

Reviewers: bgamari, hvr

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4678

14 months agoFix a few GCC warnings
Michal Terepeta [Sun, 13 May 2018 22:34:03 +0000 (18:34 -0400)] 
Fix a few GCC warnings

GCC 8 now generates warnings for incompatible function pointer casts
[-Werror=cast-function-type]. Apparently there are a few of those in rts
code, which makes `./validate` unhappy (since we compile with `-Werror`)

This commit tries to fix these issues by changing the functions to have
the correct type (and, if necessary, moving the casts into those
functions).

For instance, hash/comparison function are declared (`Hash.h`) to take
`StgWord` but we want to use `StgWord64[2]` in `StaticPtrTable.c`.
Instead of casting the function pointers, we can cast the `StgWord`
parameter to `StgWord*`. I think this should be ok since `StgWord`
should be the same size as a pointer.

Signed-off-by: Michal Terepeta <michal.terepeta@gmail.com>
Test Plan: ./validate

Reviewers: bgamari, erikd, simonmar

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4673

14 months agoRefactor LitString
Sylvain Henry [Sun, 13 May 2018 15:36:28 +0000 (11:36 -0400)] 
Refactor LitString

Refactor LitString so that the string length is computed at most once
and then stored.

Also remove strlen and memcmp wrappers (it seems like they were a
workaround for a very old GCC when using -fvia-C).

Bumps haddock submodule.

Reviewers: bgamari, dfeuer, nickkuk

Reviewed By: bgamari, nickkuk

Subscribers: nickkuk, dfeuer, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4630

14 months agoBump array submodule
Ben Gamari [Sun, 13 May 2018 15:52:56 +0000 (11:52 -0400)] 
Bump array submodule

14 months agoTcInteract: Ensure that tycons have representations before solving for Typeable
Ben Gamari [Sun, 13 May 2018 15:41:16 +0000 (11:41 -0400)] 
TcInteract: Ensure that tycons have representations before solving for Typeable

Summary: This fixes #15067.

Test Plan: Validate

Subscribers: thomie, carter, RyanGlScott

GHC Trac Issues: #15067

Differential Revision: https://phabricator.haskell.org/D4623

14 months agobase: Fix handling of showEFloat (Just 0)
Ben Gamari [Sun, 13 May 2018 15:40:18 +0000 (11:40 -0400)] 
base: Fix handling of showEFloat (Just 0)

Previously `showEFloat (Just 0) pi ""` would produce `3.0e0`. Of
course, this
blatantly disrespects the user's request to print with zero digits of
precision.
Fix this.

This is tested by base's `num008` testcase.

Test Plan: Validate

Reviewers: hvr

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15115

Differential Revision: https://phabricator.haskell.org/D4665

14 months agoSimplify -ddump-json implementation
Matthew Pickering [Sun, 13 May 2018 15:39:34 +0000 (11:39 -0400)] 
Simplify -ddump-json implementation

This patch takes the much simpler route of whenever the compiler tries
to output something. We just dump a JSON document there and then.

I think this should be sufficient to work with and anything more refined
quickly got complicated as it was necessary to demarcate message scopes
and so on.

Reviewers: bgamari, dfeuer

Reviewed By: bgamari

Subscribers: Phyx, dfeuer, rwbarton, thomie, carter

GHC Trac Issues: #14078

Differential Revision: https://phabricator.haskell.org/D4532

14 months agoEmit info-level log message when package envs are loaded
Herbert Valerio Riedel [Sun, 13 May 2018 17:32:29 +0000 (19:32 +0200)] 
Emit info-level log message when package envs are loaded

A common complaint with the new package environment files feature is
that it's not obvious when package environments have been picked up.
This patch applies the same strategy that was already used for `.ghci` files
(which exhibit similar potential for confusion, c.f. #11389) to package
environment files.

For instance, this new notification looks like below for a GHCi invocation which
loads both, a GHCi configuration as well as a package environment:

  GHCi, version 8.5.20180512: http://www.haskell.org/ghc/  :? for help
  Loaded package environment from /tmp/parsec-3.1.13.0/.ghc.environment.x86_64-linux-8.5.20180512
  Loaded GHCi configuration from /home/hvr/.ghci
  Prelude>

Addresses #15145

Reviewed By: bgamari, angerman

GHC Trac Issues: #15145

Differential Revision: https://phabricator.haskell.org/D4689

14 months agoUse correct source spans for EmptyCase
Ryan Scott [Sat, 12 May 2018 16:56:30 +0000 (12:56 -0400)] 
Use correct source spans for EmptyCase

Summary:
The parser's calculation of source spans for `EmptyCase`
expressions was a bit off, leading to some wonky-looking error
messages. Easily fixed with some uses of `comb3` and `sLL`.

Test Plan: make test TEST=T15139

Reviewers: bgamari, simonpj

Reviewed By: simonpj

Subscribers: simonpj, rwbarton, thomie, mpickering, carter

GHC Trac Issues: #15139

Differential Revision: https://phabricator.haskell.org/D4685

14 months agoRevert "Fix unwinding of C -> Haskell FFI calls with -threaded"
Bartosz Nitka [Sat, 12 May 2018 14:31:20 +0000 (07:31 -0700)] 
Revert "Fix unwinding of C -> Haskell FFI calls with -threaded"

This reverts commit cb5c2fe875965b7aedbc189012803fc62e48fb3f.

It appears to have broken OSX and Windows builds.

14 months agoAdds CTRL-C handler in Windows's timeout (trac issue #12721)
ARJANEN Loïc Jean David [Sat, 12 May 2018 07:35:27 +0000 (08:35 +0100)] 
Adds CTRL-C handler in Windows's timeout (trac issue #12721)

Summary:
Uses Win32's System.Win32.Console.CtrlHandler.withConsoleCtrlHandler to add
to Windows's version of the timeout executable a CTRL-C/CTRL-BREAK
handler which does the close IO port/kill job cleanup, just in case.

Signed-off-by: ARJANEN Loïc Jean David <arjanen.loic@gmail.com>
Reviewers: Phyx, bgamari

Reviewed By: Phyx

Subscribers: dfeuer, thomie, carter

GHC Trac Issues: #12721

Differential Revision: https://phabricator.haskell.org/D4631

14 months agoExpand $tooldir in ghc --info output
Alp Mestanogullari [Sat, 12 May 2018 07:36:19 +0000 (08:36 +0100)] 
Expand $tooldir in ghc --info output

Summary:
This requires adding an `sToolDir :: Maybe FilePath` field to Settings, since
compilerInfo is pure and therefore needs to have all the information
available in the DynFlags.

This should fix #15101 and #15107.

Test Plan: ./validate --fast

Reviewers: Phyx, bgamari

Reviewed By: Phyx

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15101, #15107

Differential Revision: https://phabricator.haskell.org/D4686

14 months agoFix unwinding of C -> Haskell FFI calls with -threaded
Bartosz Nitka [Thu, 3 May 2018 17:43:38 +0000 (10:43 -0700)] 
Fix unwinding of C -> Haskell FFI calls with -threaded

See the new note.

Test Plan:
manual testing with patched gdb

Reviewers: bgamari, simonmar, erikd

Subscribers: rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4666

14 months agoBlockAlloc.c: reuse tail_of function
Ömer Sinan Ağacan [Fri, 11 May 2018 07:24:00 +0000 (10:24 +0300)] 
BlockAlloc.c: reuse tail_of function

14 months agoRevert "Add -fghci-leak-check to check for space leaks"
Simon Marlow [Thu, 10 May 2018 16:39:53 +0000 (17:39 +0100)] 
Revert "Add -fghci-leak-check to check for space leaks"

This reverts commit 5fe6aaa3756cda654374ebfd883fa8f064ff64a4.

14 months agorts: remove unused round_up_to_mblocks function
Ömer Sinan Ağacan [Thu, 10 May 2018 15:05:51 +0000 (18:05 +0300)] 
rts: remove unused round_up_to_mblocks function

14 months agoFix #15038
Ömer Sinan Ağacan [Thu, 10 May 2018 08:13:37 +0000 (11:13 +0300)] 
Fix #15038

We introduce a new Id for unused pointer values in unboxed sums that is
not CAFFY. Because the Id is not CAFFY it doesn't make non-CAFFY
definitions CAFFY, fixing #15038.

To make sure anything referenced by the new id will be retained we get a
stable pointer to in on RTS startup.

Test Plan: Passes validate

Reviewers: simonmar, simonpj, hvr, bgamari, erikd

Reviewed By: simonmar

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15038

Differential Revision: https://phabricator.haskell.org/D4680

14 months agoAdd -fghci-leak-check to check for space leaks
Simon Marlow [Wed, 2 May 2018 10:01:13 +0000 (11:01 +0100)] 
Add -fghci-leak-check to check for space leaks

Summary:
Space leaks in GHCi emerge from time to time and tend to come back again
after they get fixed. This is an attempt to limit regressions by

* adding a reliable detection for some classes of space leaks in GHCi
* turning on leak checking for all GHCi tests in the test suite, so that
  we'll notice if the leak appears again.

The idea for detecting space leaks is quite simple:

* find some data that we expect to be GC'd later, make a weak pointer to it
* when we expect the data to be dead, do a `performGC` and then check
  the status of the weak pointer.

It would be nice to apply this trick to lots of things in GHC,
e.g. ensuring that HsSyn is not retained after the desugarer, or
ensuring that CoreSyn from the previous simplifier pass is not retained.

Test Plan: validate

Reviewers: bgamari, simonpj, erikd, niteria

Subscribers: thomie, carter

GHC Trac Issues: #15111

Differential Revision: https://phabricator.haskell.org/D4658

14 months agoNormalize the element type of ListPat, fix #14547
HE, Tao [Tue, 8 May 2018 14:53:41 +0000 (10:53 -0400)] 
Normalize the element type of ListPat, fix #14547

Summary:
The element type of `List` maybe a type family instacen, rather than a trivial type.
For example in Trac #14547,

```
{-# LANGUAGE TypeFamilies, OverloadedLists #-}

class Foo f where
        type It f
        foo :: [It f] -> f

data List a = Empty | a :! List a deriving Show

instance Foo (List a) where
        type It (List a) = a
        foo [] = Empty
        foo (x : xs) = x :! foo xs
```

Here the element type of `[]` is `It (List a)`, we should also normalize
it as `a`.

Test Plan: make test TEST="T14547"

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: thomie, carter

GHC Trac Issues: #14547

Differential Revision: https://phabricator.haskell.org/D4624

14 months agoRevert "Normalize the element type of ListPat, fix #14547"
Ben Gamari [Tue, 8 May 2018 14:52:28 +0000 (10:52 -0400)] 
Revert "Normalize the element type of ListPat, fix #14547"

This reverts commit 981bf4718de7daef7817a363ccc14030c2688632.

14 months agoNormalize the element type of ListPat, fix #14547
Ben Gamari [Tue, 8 May 2018 14:08:04 +0000 (10:08 -0400)] 
Normalize the element type of ListPat, fix #14547

The element type of `List` maybe a type family instacen, rather than a
trivial type.
For example in Trac #14547,

```
{-# LANGUAGE TypeFamilies, OverloadedLists #-}

class Foo f where
        type It f
        foo :: [It f] -> f

data List a = Empty | a :! List a deriving Show

instance Foo (List a) where
        type It (List a) = a
        foo [] = Empty
        foo (x : xs) = x :! foo xs
```

Here the element type of `[]` is `It (List a)`, we should also normalize
it as `a`.

Test Plan: make test TEST="T14547"

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: thomie, carter

GHC Trac Issues: #14547

Differential Revision: https://phabricator.haskell.org/D4624

14 months agoRevert "Normalize the element type of ListPat, fix #14547"
Ben Gamari [Tue, 8 May 2018 14:07:53 +0000 (10:07 -0400)] 
Revert "Normalize the element type of ListPat, fix #14547"

This reverts commit 361d23a8ebb44f5df5167306d7b98d8bd1724e06.

14 months agousers-guide: Move discussion MAX_PATH out of release notes
Ben Gamari [Mon, 7 May 2018 18:43:45 +0000 (14:43 -0400)] 
users-guide: Move discussion MAX_PATH out of release notes

This discussion will be useful for users; move it into the users-guide proper.
Also fixes a few typos noted by @Phyx.

Test Plan: Read it

Reviewers: Phyx

Reviewed By: Phyx

Subscribers: dfeuer, Phyx, rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4420

14 months agoSimplify the kind checking for type/class decls
Simon Peyton Jones [Fri, 4 May 2018 15:31:55 +0000 (16:31 +0100)] 
Simplify the kind checking for type/class decls

This patch deletes quite a bit of code,
AND fixes Trac #15116.

14 months agoUsed named fields for DataDeclRn
Simon Peyton Jones [Fri, 4 May 2018 15:25:46 +0000 (16:25 +0100)] 
Used named fields for DataDeclRn

14 months agoSmall refactoring in Exitify
Simon Peyton Jones [Fri, 4 May 2018 15:24:26 +0000 (16:24 +0100)] 
Small refactoring in Exitify

This refactoring was provoked by our conversation on
Trac #14152.  No change in behaviour.

14 months agoprintStackChunk: recognise a few more ret frames
Ömer Sinan Ağacan [Sun, 6 May 2018 07:31:22 +0000 (10:31 +0300)] 
printStackChunk: recognise a few more ret frames

14 months agotestsuite: Bump T5631 expected allocations
Ben Gamari [Sun, 6 May 2018 01:50:37 +0000 (21:50 -0400)] 
testsuite: Bump T5631 expected allocations

This was failing on Darwin; I believe this is due to 33de71fa06d0.

14 months agobase/changelog: Note stabilization of asinh (#14927)
Ben Gamari [Sun, 6 May 2018 01:48:17 +0000 (21:48 -0400)] 
base/changelog: Note stabilization of asinh (#14927)

14 months agoStable area hyperbolic sine for `Double` and `Float`.
Justus Sagemüller [Wed, 28 Mar 2018 13:51:16 +0000 (15:51 +0200)] 
Stable area hyperbolic sine for `Double` and `Float`.

This function was unstable, in particular for negative arguments.

https://ghc.haskell.org/trac/ghc/ticket/14927

The reason is that the formula `log (x + sqrt (1 + x*x))` is dominated
by the numerical error of the `sqrt` function when x is strongly negative
(and thus the summands in the `log` mostly cancel). However, the area
hyperbolic sine is an odd function, thus the negative side can as well
be calculated by flipping over the positive side, which avoids this instability.

Furthermore, for _very_ big arguments, the `x*x` subexpression overflows. However,
long before that happens, the square root is anyways completely dominated
by that term, so we can neglect the `1 +` and get

    sqrt (1 + x*x) ≈ sqrt (x*x) = x

and therefore

    asinh x ≈ log (x + x) = log (2*x) = log 2 + log x

which does not overflow for any normal-finite positive argument, but
perfectly matches the exact formula within the floating-point accuracy.

14 months agoAdd hyperbolic functions to test of Float-inverses
Justus Sagemüller [Wed, 28 Mar 2018 12:44:51 +0000 (14:44 +0200)] 
Add hyperbolic functions to test of Float-inverses

The area hyperbolic sine is currently broken,
see https://ghc.haskell.org/trac/ghc/ticket/14927.

14 months agoAdd test for invertability of `Floating` methods.
Justus Sagemüller [Wed, 28 Mar 2018 10:52:30 +0000 (12:52 +0200)] 
Add test for invertability of `Floating` methods.

These functions have inverses only on part of the real line, but
there they should be reliably inverted – that's basically the whole
point of the functions like `asin`, `atan` etc..

14 months agoAdd 'addWordC#' PrimOp
Sebastian Graf [Sat, 5 May 2018 17:30:32 +0000 (13:30 -0400)] 
Add 'addWordC#' PrimOp

This is mostly for congruence with 'subWordC#' and '{add,sub}IntC#'.
I found 'plusWord2#' while implementing this, which both lacks
documentation and has a slightly different specification than
'addWordC#', which means the generic implementation is unnecessarily
complex.

While I was at it, I also added lacking meta-information on PrimOps
and refactored 'subWordC#'s generic implementation to be branchless.

Reviewers: bgamari, simonmar, jrtc27, dfeuer

Reviewed By: bgamari, dfeuer

Subscribers: dfeuer, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4592

14 months agoUse unsafeInsertNew to create timers in TimerManager
Mitchell Rosen [Mon, 30 Apr 2018 22:05:07 +0000 (18:05 -0400)] 
Use unsafeInsertNew to create timers in TimerManager

14 months agoDo not supply `-mcpu` if `-optlc` provides `-mcpu` already.
Moritz Angermann [Fri, 4 May 2018 18:39:16 +0000 (14:39 -0400)] 
Do not supply `-mcpu` if `-optlc` provides `-mcpu` already.

Reviewers: bgamari

Subscribers: thomie, carter

GHC Trac Issues: #14982

Differential Revision: https://phabricator.haskell.org/D4548