ghc.git
2 years agoPretty-printer missing parens for infix class declaration
Alan Zimmerman [Mon, 2 Oct 2017 16:09:37 +0000 (18:09 +0200)] 
Pretty-printer missing parens for infix class declaration

    class (a `C` b) c

Is pretty printed as

    class a `C` b c

Fixes #14306

2 years agoCircleCI: Install texinfo
Joachim Breitner [Mon, 2 Oct 2017 17:08:12 +0000 (13:08 -0400)] 
CircleCI: Install texinfo

2 years agoTravis: Install texinfo
Joachim Breitner [Mon, 2 Oct 2017 14:55:45 +0000 (10:55 -0400)] 
Travis: Install texinfo

2 years agoBump submodule nofib again (Semigroup now required)
Joachim Breitner [Thu, 14 Sep 2017 20:42:53 +0000 (16:42 -0400)] 
Bump submodule nofib again (Semigroup now required)

Commit 063e0b4e5ea53a02713eb48555bbd99d934a3de5 accidentially undid
7b8827ab24a3af8555f1adf250b7b541e41d8f5d where I bumped nofib
previously.

2 years agoAllow libffi snapshots
Moritz Angermann [Sat, 30 Sep 2017 13:31:12 +0000 (09:31 -0400)] 
Allow libffi snapshots

This is rather annoying. I'd prefer to have a stable release to
use. However libffi-3.2.1 has been released November 12, 2014, and
libffi-4 is TBD. See also https://github.com/libffi/libffi/issues/296

The core reason for this change is that llvm changed the supported
assembly to unified syntax, which libffi-3.2.1 does not use, and hence
fails to compile for arm with llvm. For refence, see the following
issue: https://github.com/libffi/libffi/issues/191.

This diff contains a script to generate a tarball for the
`libffi-tarballs` repository from the libffi GitHub repository; as well
as the necessary changes to the build system.

Updates libffi-tarballs submodule.

Reviewers: austin, bgamari, hvr

Subscribers: hvr, erikd, rwbarton, thomie

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

2 years agoiserv: Don't build vanilla iserv unless vanilla libraries are built
Ben Gamari [Sat, 30 Sep 2017 03:33:29 +0000 (23:33 -0400)] 
iserv: Don't build vanilla iserv unless vanilla libraries are built

Test Plan: Validate

Reviewers: austin, snowleopard

Subscribers: angerman, rwbarton, thomie, int-e

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

2 years agoDon't use "character" in haddocks of Char
Ben Gamari [Sat, 30 Sep 2017 03:33:03 +0000 (23:33 -0400)] 
Don't use "character" in haddocks of Char

Character is a terribly overloaded term and may refer to graphemes or
code points. Specifically say that Char represents Unicode code points.

[skip ci]

Test Plan: Read it.

Reviewers: hvr, austin

Subscribers: rwbarton, thomie

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

2 years agoDocument a law for TH's Lift class
Ryan Scott [Sat, 30 Sep 2017 03:32:41 +0000 (23:32 -0400)] 
Document a law for TH's Lift class

Inspired by the discussion in #14296, I've decided to
document a law which is usually in the back of my mind when I'm using
Template Haskell's `Lift` class, but isn't formally stated anywhere.
That is, every `Lift` instance should satisfy (for all `x`):

```lang=haskell
$(lift x) == x
```

Test Plan: Read it

Reviewers: austin, goldfire, bgamari

Subscribers: rwbarton, thomie

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

2 years agouser-guide: Document -Weverything
Ben Gamari [Sat, 30 Sep 2017 03:29:47 +0000 (23:29 -0400)] 
user-guide: Document -Weverything

[skip ci]

Reviewers: hvr, austin, dfeuer

Reviewed By: dfeuer

Subscribers: rwbarton, thomie

GHC Trac Issues: #14284

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

2 years agoFix Raspberry Pi target name
Moritz Angermann [Thu, 28 Sep 2017 03:04:32 +0000 (11:04 +0800)] 
Fix Raspberry Pi target name

Summary:
For some reson, the `*`, that was supposed to be in D4031
got lost in the diff.

Reviewers: bgamari, austin, hvr, dfeuer

Reviewed By: dfeuer

Subscribers: rwbarton, thomie, erikd

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

2 years agoFix #13391 by checking for kind-GADTs
Richard Eisenberg [Tue, 15 Aug 2017 21:22:50 +0000 (17:22 -0400)] 
Fix #13391 by checking for kind-GADTs

The check is a bit gnarly, but I couldn't think of a better way.
See the new code in TcTyClsDecls.

test case: polykinds/T13391

2 years agomkDataConRep: fix bug in strictness signature (#14290)
Simon Marlow [Thu, 28 Sep 2017 17:08:45 +0000 (13:08 -0400)] 
mkDataConRep: fix bug in strictness signature (#14290)

The strictness signature for a data con wrapper wasn't including any
dictionary arguments, which meant that bangs on the fields of a
constructor with an existential context would be moved to the wrong
fields.  See T14290 for an example.

Test Plan:
* New test T14290
* validate

Reviewers: simonpj, niteria, austin, bgamari, erikd

Reviewed By: simonpj, bgamari

Subscribers: rwbarton, thomie

GHC Trac Issues: #14290

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

2 years agoconfigure: Make sure we try all possible linkers
Ben Gamari [Wed, 27 Sep 2017 19:30:18 +0000 (15:30 -0400)] 
configure: Make sure we try all possible linkers

Previously if we had both ld.lld and ld.gold installed but a gcc which
didn't support -fuse-ld=lld we would fail when trying ld.lld and fall
immediately back to plain ld. Now we will try ld.gold as well. This was
brought to light by #14280, where using ld.bfd resulted in a broken
stage2 compiler.

Test Plan: Configure

Reviewers: angerman, hvr, austin

Reviewed By: angerman

Subscribers: rwbarton, thomie, erikd

GHC Trac Issues: #14280

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

2 years agobase: fdReady(): Ensure and doc that return values are always -1/0/1
Niklas Hambüchen [Wed, 27 Sep 2017 19:29:06 +0000 (15:29 -0400)] 
base: fdReady(): Ensure and doc that return values are always -1/0/1

Reviewers: bgamari, austin, hvr, Phyx

Reviewed By: Phyx

Subscribers: Phyx, rwbarton, thomie

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

2 years agofdReady(): Fix some C -Wconversion warnings.
Niklas Hambüchen [Wed, 27 Sep 2017 19:26:37 +0000 (15:26 -0400)] 
fdReady(): Fix some C -Wconversion warnings.

Btw, -Wconversion is off by default and not included in -Wall, -Wextra
or -pedantic, so I used it temporarily with -optc-Wconversion.

Reviewers: bgamari, austin, hvr

Reviewed By: bgamari

Subscribers: rwbarton, thomie

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

2 years agoAdd TODO about getMonotonicNSec() wrapping that can no longer happen.
Niklas Hambüchen [Wed, 27 Sep 2017 19:24:11 +0000 (15:24 -0400)] 
Add TODO about getMonotonicNSec() wrapping that can no longer happen.

Knowing this is important for followup commits, where we will subtract
getProcessElapsedTime() values from each other, in a way that assumes
that there is no wrapping every 49 days.

Reviewers: bgamari, austin, erikd, simonmar, NicolasT

Reviewed By: bgamari

Subscribers: rwbarton, thomie

GHC Trac Issues: #14233

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

2 years agoMove check-ppr and check-api-annotations to testsuite/utils
Ben Gamari [Wed, 27 Sep 2017 19:22:37 +0000 (15:22 -0400)] 
Move check-ppr and check-api-annotations to testsuite/utils

These are needed by the testsuite and consequently must be shipped in
the testsuite tarball to ensure that we can test binary distributions.

See #13897.

Test Plan: Validate

Reviewers: austin

Subscribers: snowleopard, rwbarton, thomie

GHC Trac Issues: #13897

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

2 years agoTypofixes
Gabor Greif [Wed, 27 Sep 2017 10:21:33 +0000 (12:21 +0200)] 
Typofixes

2 years agollvm-targets: drop soft-float
Moritz Angermann [Mon, 25 Sep 2017 06:17:11 +0000 (14:17 +0800)] 
llvm-targets: drop soft-float

Summary:
The llvm-targets file records `mattr` values, and
while interrogating `clang` for the target, we might
stumble upon `+soft-float-abi`, however ghc does not support
full soft-float, and as such passing `+soft-float` to `llc`
will result in segfaults for any function passing float
registers F1, ... in the ARM Instruction Selection Pass.

Reviewers: bgamari, austin

Reviewed By: bgamari

Subscribers: rwbarton, thomie

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

2 years agoGHC_LLVM_TARGET: Keep android OS
Moritz Angermann [Wed, 27 Sep 2017 01:20:31 +0000 (09:20 +0800)] 
GHC_LLVM_TARGET: Keep android OS

Summary:
Our usual GHC_CONVERT_OS macro, will turn any andoird* into android.
This however drops the essential androideabi part. As such for the
GHC_LLVM_TARGET we only convert the VENDOR, not the OS.

Reviewers: bgamari, austin, hvr

Reviewed By: bgamari

Subscribers: rwbarton, thomie, erikd

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

2 years agoSwitch VEH to VCH and allow disabling of SEH completely.
Tamar Christina [Tue, 26 Sep 2017 18:34:58 +0000 (14:34 -0400)] 
Switch VEH to VCH and allow disabling of SEH completely.

Exception handling on Windows is unfortunately a bit complicated.
But essentially the VEH Handlers we currently have are running too
early.

This was a problem as it ran so early it also swallowed C++ exceptions
and other software exceptions which the system could have very well
recovered from.

So instead we use a sequence of chains to for the exception handlers to
run as late as possible. You really can't get any later than this.

Please read the comment in the patch for more details.

I'm also providing a switch to allow people to turn off the exception
handling entirely. In case it does present a problem with their code.

(Reverted and recommitted to fix authorship information)

Test Plan: ./validate

Reviewers: austin, hvr, bgamari, erikd, simonmar

Reviewed By: bgamari

Subscribers: rwbarton, thomie

GHC Trac Issues: #13911, #12110

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

2 years agoRevert "Switch VEH to VCH and allow disabling of SEH completely."
Ben Gamari [Tue, 26 Sep 2017 19:43:47 +0000 (15:43 -0400)] 
Revert "Switch VEH to VCH and allow disabling of SEH completely."

Reverting to fix authorship of commit.

This reverts commit 1825cbdbdf08ed4bd6fd6794852596078953298a.

2 years agorts: Throw proper HeapOverflow exception on allocating large array
Ben Gamari [Tue, 26 Sep 2017 19:09:13 +0000 (15:09 -0400)] 
rts: Throw proper HeapOverflow exception on allocating large array

Test Plan: Validate, add tests

Reviewers: simonmar, austin, erikd

Reviewed By: simonmar

Subscribers: rwbarton, thomie

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

2 years agodesugar: Catch levity polymorphism in unboxed sum expressions
Ben Gamari [Tue, 26 Sep 2017 18:52:26 +0000 (14:52 -0400)] 
desugar: Catch levity polymorphism in unboxed sum expressions

Fixes #13929.

2 years agobase: fdReady(): Add note about O_NONBLOCK requirement
Niklas Hambüchen [Tue, 26 Sep 2017 18:41:50 +0000 (14:41 -0400)] 
base: fdReady(): Add note about O_NONBLOCK requirement

Reviewers: bgamari, austin, hvr

Reviewed By: bgamari

Subscribers: rwbarton, thomie

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

2 years agoSwitch VEH to VCH and allow disabling of SEH completely.
Ben Gamari [Tue, 26 Sep 2017 18:34:58 +0000 (14:34 -0400)] 
Switch VEH to VCH and allow disabling of SEH completely.

Exception handling on Windows is unfortunately a bit complicated.
But essentially the VEH Handlers we currently have are running too
early.

This was a problem as it ran so early it also swallowed C++ exceptions
and other software exceptions which the system could have very well
recovered from.

So instead we use a sequence of chains to for the exception handlers to
run as late as possible. You really can't get any later than this.

Please read the comment in the patch for more details.

I'm also providing a switch to allow people to turn off the exception
handling entirely. In case it does present a problem with their code.

Test Plan: ./validate

Reviewers: austin, hvr, bgamari, erikd, simonmar

Reviewed By: bgamari

Subscribers: rwbarton, thomie

GHC Trac Issues: #13911, #12110

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

2 years agorts: Silence missing __noreturn__ warning
Ben Gamari [Tue, 26 Sep 2017 18:34:58 +0000 (14:34 -0400)] 
rts: Silence missing __noreturn__ warning

Reviewers: angerman, austin, erikd, simonmar

Subscribers: rwbarton, thomie

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

2 years agoRules: Show the binder type in the unbound template binder error
Ben Gamari [Tue, 26 Sep 2017 18:32:02 +0000 (14:32 -0400)] 
Rules: Show the binder type in the unbound template binder error

Reviewers: austin

Subscribers: rwbarton, thomie

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

2 years agoRelease console for ghci wrapper
Tamar Christina [Tue, 26 Sep 2017 18:43:15 +0000 (19:43 +0100)] 
Release console for ghci wrapper

Summary:
It seems the call that caused issues with the gcc wrapper before
was needed for the ghci wrapper in order for the child process
to be the one handling console events.

This code slightly refactors the wrappers to make sure only ghci
calls FreeConsole and nothing else.

Test Plan: ./validate , open ghci.exe press ctrl+c

Reviewers: RyanGlScott, austin, hvr, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, erikd

GHC Trac Issues: #14150

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

2 years agoTcInteract: Remove redundant import of Typeable
Ben Gamari [Tue, 26 Sep 2017 17:35:46 +0000 (13:35 -0400)] 
TcInteract: Remove redundant import of Typeable

2 years agotestsuite: Add test for #14272
Ben Gamari [Tue, 26 Sep 2017 16:02:27 +0000 (12:02 -0400)] 
testsuite: Add test for #14272

Reviewers: austin

Subscribers: rwbarton, thomie

GHC Trac Issues: #14272

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

2 years agoPrelRules: Handle Int left shifts of more than word-size bits
Ben Gamari [Tue, 26 Sep 2017 12:01:44 +0000 (08:01 -0400)] 
PrelRules: Handle Int left shifts of more than word-size bits

This should result in zero. Failing to realize this caused us to try
to constant-fold via the normal path, resulting in #14272.

Test Plan: Validate with coming tests

Reviewers: austin, simonpj

Subscribers: simonpj, rwbarton, thomie, hvr

GHC Trac Issues: #14272

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

2 years agorts: Inform kernel that we won't need reserved address space
Ben Gamari [Tue, 26 Sep 2017 14:09:06 +0000 (10:09 -0400)] 
rts: Inform kernel that we won't need reserved address space

Trac #14192 points out that currently GHC's two-step allocator results
in extremely large coredumps. It seems like WebKit may have encountered
similar issues and their apparent solution uses madvise(MADV_DONTNEED)
while reserving address space to inform the kernel that the address
space we just requested needs no backing. Perhaps this is used by the
core dump logic to trim out uncommitted pages.

Test Plan: Validate, try core-dumping a compiled executable

Reviewers: austin, erikd, simonmar

Reviewed By: simonmar

Subscribers: rwbarton, thomie

GHC Trac Issues: #14192, #14193

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

2 years agoprimops: Add some notes regarding the meaning of the "type" field
Ben Gamari [Tue, 26 Sep 2017 13:33:53 +0000 (09:33 -0400)] 
primops: Add some notes regarding the meaning of the "type" field

The overloading of "monadic" definitely deserved some explanation.

[skip ci]

2 years agoStgCmmMonad: Remove unnecessary use of unboxed tuples
Ben Gamari [Tue, 26 Sep 2017 12:33:34 +0000 (08:33 -0400)] 
StgCmmMonad: Remove unnecessary use of unboxed tuples

The simplifier can simplify this without any trouble. Moreover, the
unboxed tuples cause bootstrapping issues due #14123.

I also went ahead and inlined a few definitions into the Monad instance.

Test Plan: Validate

Reviewers: austin, simonmar

Subscribers: rwbarton, thomie

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

2 years agoOmit Typeable from the "naturally coherent" list
Simon Peyton Jones [Tue, 26 Sep 2017 14:02:09 +0000 (15:02 +0100)] 
Omit Typeable from the "naturally coherent" list

In doing something else (Trac #14218) I tripped over the
definition of "naturally coherent" classes.  This patch

- Cocuments properly what that means

- Removes Typeable from the list, because now we know what
  it meams, Typeable clearly doesn't belong.

No regressions.

(Actually the term "naturally coherent" seems a bit off.
More like "invertible" or something.  But I left it.)

2 years agoA bunch of typofixes
Gabor Greif [Mon, 25 Sep 2017 10:31:12 +0000 (12:31 +0200)] 
A bunch of typofixes

2 years agotestsuite: Expect T13168 to be broken on Windows
Ben Gamari [Tue, 26 Sep 2017 00:40:41 +0000 (20:40 -0400)] 
testsuite: Expect T13168 to be broken on Windows

Spurious output pertaining to dynamic linking causes it to fail. See #14276.

2 years agoconfigure: Don't hard-code strip tool
Ben Gamari [Mon, 25 Sep 2017 22:41:23 +0000 (18:41 -0400)] 
configure: Don't hard-code strip tool

For reasons that I don't entirely understand we didn't previously detect
`strip` using autoconf. This naturally broke during cross-compilation.
How did this ever work? I have no idea.

Test Plan: Try cross-compiling

Reviewers: austin, hvr, angerman

Subscribers: rwbarton, thomie, erikd

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

2 years agoconfigure: Catch case where LLVM tools can't be found
Ben Gamari [Mon, 25 Sep 2017 22:39:11 +0000 (18:39 -0400)] 
configure: Catch case where LLVM tools can't be found

Previously we didn't specify the prog-not-found value passed to
AC_CHECK_TOOLS.  Reported by @snowleopard in
https://github.com/snowleopard/hadrian/issues/415.

Test Plan: validate

Reviewers: austin, hvr

Subscribers: rwbarton, thomie, snowleopard, erikd

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

2 years agoUse SIGQUIT for DWARF backtraces instead of SIGUSR2
Ben Gamari [Mon, 25 Sep 2017 22:34:54 +0000 (18:34 -0400)] 
Use SIGQUIT for DWARF backtraces instead of SIGUSR2

Reviewers: austin, erikd, simonmar

Subscribers: NicolasT, rwbarton, thomie

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

2 years agoAdd NOINLINE pragma to builtinRules
Ben Gamari [Mon, 25 Sep 2017 22:34:21 +0000 (18:34 -0400)] 
Add NOINLINE pragma to builtinRules

As mentioned in #14275, GHC will otherwise decide to produce unfoldings
for this rather large binding, making recompilation more expensive than
necessary. Since inlining is almost certainly not fruitful mark it as
NOINLINE.

[skip ci]

Test Plan: Validate

Reviewers: austin

Subscribers: rwbarton, thomie

GHC Trac Issues: #14275

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

2 years agointeger-gmp: Fix style
Ben Gamari [Mon, 25 Sep 2017 22:34:13 +0000 (18:34 -0400)] 
integer-gmp: Fix style

Just fix a few inconsistencies that I encountered.

[skip ci]

Reviewers: austin, hvr, goldfire

Subscribers: rwbarton, thomie

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

2 years agoInclude original process name in worker thread name (#14153)
Echo Nolan [Mon, 25 Sep 2017 22:33:30 +0000 (18:33 -0400)] 
Include original process name in worker thread name (#14153)

Prior to this commit, worker OS thread were renamed to "ghc_worker" when
spawned. This was annoying when reading debugging messages that print
the process name because it doesn't tell you *which* Haskell program is
generating the message.

This commit changes it to "original_process_name:w", truncating the
original name to fit in the kernel buffer if neccesary.

Test Plan: ./validate

Reviewers: austin, bgamari, erikd, simonmar

Reviewed By: bgamari

Subscribers: Phyx, rwbarton, thomie

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

2 years agoDocument Typeable's treatment of kind polymorphic tycons
Ben Gamari [Mon, 25 Sep 2017 22:33:06 +0000 (18:33 -0400)] 
Document Typeable's treatment of kind polymorphic tycons

Test Plan: Read it

Reviewers: dfeuer, goldfire, austin, hvr

Reviewed By: dfeuer

Subscribers: rwbarton, thomie

GHC Trac Issues: #14199

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

2 years agoAdds mingw64 to the valid GHC OSs.
Moritz Angermann [Mon, 25 Sep 2017 23:19:06 +0000 (00:19 +0100)] 
Adds mingw64 to the valid GHC OSs.

Summary:
This fixes hadrian#420 (https://github.com/snowleopard/hadrian/issues/420)

specifically the "Unknown OS mingw64".

Reviewers: austin, hvr, bgamari, Phyx

Reviewed By: Phyx

Subscribers: rwbarton, thomie, erikd

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

2 years agoFix the searching of target AR tool
Tamar Christina [Mon, 25 Sep 2017 18:12:35 +0000 (19:12 +0100)] 
Fix the searching of target AR tool

Summary:
Ar was being checked twice prior to D3883 where I removed one of the checks
because the converted path was being overridden after the check because of
the second check for Ar. However the one in configure.ac was a target check
so I'm changing the path check to a target check now.

Test Plan: ./configure

Reviewers: angerman, austin, hvr, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, erikd

GHC Trac Issues: #14274

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

2 years agoEnsure text mode when calling debug functions
Tamar Christina [Mon, 25 Sep 2017 19:21:39 +0000 (20:21 +0100)] 
Ensure text mode when calling debug functions

Summary:
Something seems to be changing stderr into binary mode,
so when the `traceIO` is called, the C code that ultimately
calls `vfprintf` is using a binary mode handle.

This causes newlines not to be encoded properly.

The patch ensures we're in text mode when writing the debug
messages (% interleaving as it's not thread safe at all) and restores
the previous mode when done.

I'm slightly concerned about the performance implications of writing
large dumps out in text mode, but I think the current behavior is not
intended as I cannot see any of the printing code setting the mode of
the std handles.

Test Plan: ./validate

Reviewers: austin, bgamari, erikd, simonmar

Reviewed By: bgamari

Subscribers: rwbarton, thomie

GHC Trac Issues: #14188

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

2 years agoBump template-haskell to 2.13.0.0
Ryan Scott [Mon, 25 Sep 2017 18:22:27 +0000 (14:22 -0400)] 
Bump template-haskell to 2.13.0.0

Summary:
Now that `MonadIO` is a superclass of `Quasi`, it's a good
time to bump the `template-haskell` version so that libraries can
accommodate the change using CPP.

Test Plan: ./validate

Reviewers: bgamari, austin

Subscribers: rwbarton, thomie

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

2 years agoDocument how GHC disambiguates between multiple COMPLETE sets
Ryan Scott [Mon, 25 Sep 2017 18:21:54 +0000 (14:21 -0400)] 
Document how GHC disambiguates between multiple COMPLETE sets

Summary:
Up until now, the knowledge of how GHC chooses which
`COMPLETE` set to use in the presence of multiple applicable
`COMPLETE` sets for a single data type constructor was only
documented in the GHC wiki. But this really should be advertised to
anyone who uses `COMPLETE` pragmas heavily, so per SPJ's advice in
https://ghc.haskell.org/trac/ghc/ticket/14253#comment:10, this adds
this wisdom to the GHC users' guide.

Test Plan: Read it

Reviewers: austin, bgamari

Subscribers: mpickering, rwbarton, thomie

GHC Trac Issues: #14253

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

2 years agoFix solving of implicit parameter constraints
Simon Peyton Jones [Mon, 25 Sep 2017 10:06:34 +0000 (11:06 +0100)] 
Fix solving of implicit parameter constraints

Trac #14218 showed that we were not solving implicit-parameter
constraints correctly.  In particular,

- A tuple constraint could "hide" an implicit-parameter wanted
  constraint, and that in turn could that we solved it from the
  wrong implicit-parameter binding.

- As a special case the HasCallStack constraint (which is just
  short for (IP "callStack" CallStack), was getting mis-solved.

The big change is to arrange that, in TcSMonad.findDict when looking
for a dictionary, either when looking for a matching inert or solved
dictionary, we fail for

  - Tuples that are hiding implicit parameters
    See Note [Tuples hiding implicit parameters]

  - HasCallStack constraints where we have not yet pushed
    on the call-site info
    See Note [Solving CallStack constraints]

I also did a little refactoring

* Move naturallyCoherentClass from Class to TcInteract, its sole
  use site.  Class.hs seems like the wrong place.  (And I also
  do not understand the reason that we need the eq/Coercible/
  Typable stuff in this predicate, but I'll tackle that separately.)

* Move the code that pushes call-site info onto a call stack
  from the "interact" part to the "canonicalise" part of the solver.

2 years agoImprove type-error reporting
Simon Peyton Jones [Thu, 21 Sep 2017 16:39:18 +0000 (17:39 +0100)] 
Improve type-error reporting

This patch does two things:

* When reporting a hole, we now include its kind if the
  kind is not just '*'.  This addresses Trac #14265

* When reporting things like "'a' is a rigid type varaible
  bound by ...", this patch arranges to group the type variables
  together, so we don't repeat the "bound by..." stuff endlessly

2 years agoComments only
Simon Peyton Jones [Thu, 21 Sep 2017 16:38:54 +0000 (17:38 +0100)] 
Comments only

2 years agoMake pprQuotedList use fsep not hsep
Simon Peyton Jones [Thu, 21 Sep 2017 16:38:08 +0000 (17:38 +0100)] 
Make pprQuotedList use fsep not hsep

This just does wrapping on very long lists

2 years agoDeal with large extra-contraints wildcards
Simon Peyton Jones [Thu, 21 Sep 2017 16:35:11 +0000 (17:35 +0100)] 
Deal with large extra-contraints wildcards

For reasons explained in TcHsType
Note [Extra-constraint holes in partial type signatures],
if we had
  f :: (_) => blahs
and the '_' was filled in by more than a 62-tuple of contraints,
GHC crashed.

The same Note explains the hacky solution I have adopted to
evade this.  Maybe there is some better way, but I couldn't
see one that didn't involve a great deal of work. And the problem
is a very narrow one!  If the hack bites us we'll need to think
again.

2 years agodon't allow AsmTempLabel in UNREG mode (Trac #14264)
Sergei Trofimovich [Sun, 24 Sep 2017 11:14:03 +0000 (12:14 +0100)] 
don't allow AsmTempLabel in UNREG mode (Trac #14264)

AsmTempLabel is really a label that describes
label in assembly output (or equivalent like LLVM IR).

Unregisterised build does not handle it correctly.

This change does not fix UNREG build failure in
Ticket #14264 but reverts back to panic:
    pprCLbl AsmTempLabel

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
2 years agoRevert "Typeable: Allow App to match arrow types"
Herbert Valerio Riedel [Sun, 24 Sep 2017 06:54:28 +0000 (08:54 +0200)] 
Revert "Typeable: Allow App to match arrow types"

This reverts commit cc6be3a2f23c9b2e04f9f491099149e1e1d4d20b.
because it caused the regression #14270 which according to
Richard probably doesn't have an easy fix. So this one goes
back to the drawning board.

This reopens #14236

2 years ago[Semigroup] fix genapply
Moritz Angermann [Sat, 23 Sep 2017 13:21:45 +0000 (21:21 +0800)] 
[Semigroup] fix genapply

Summary:
The SMP causes <> to be exported from Prelude by
default.  When building HEAD with HEAD, genapply suffers from
<> being imported from Prelude.

Reviewers: hvr, bgamari, austin

Reviewed By: hvr

Subscribers: rwbarton, thomie

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

2 years agoFix AsmTempLabel
Moritz Angermann [Fri, 22 Sep 2017 08:17:30 +0000 (16:17 +0800)] 
Fix AsmTempLabel

Summary:
This is another fallout from 8b007abb
should fix Trac #14264. I am not sure if this is
complete. It does however allow me to build an iOS
LLVM cross compiler.

Reviewers: bgamari, trofi, austin, simonmar

Reviewed By: trofi

Subscribers: rwbarton, thomie

GHC Trac Issues: #14264

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

2 years agoAdditional LLVM_TARGET logic.
Moritz Angermann [Thu, 21 Sep 2017 13:28:29 +0000 (21:28 +0800)] 
Additional LLVM_TARGET logic.

Summary:
This should help resolve the
compilcation that came up in Trac #14261

Test Plan: validate on various platforms

Reviewers: trofi, bgamari, austin, hvr

Reviewed By: trofi

Subscribers: rwbarton, thomie, erikd

GHC Trac Issues: #14261

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

2 years agoBump haskeline submodule
Ben Gamari [Fri, 22 Sep 2017 20:55:54 +0000 (16:55 -0400)] 
Bump haskeline submodule

Should fix the win32 build.

2 years agoFix build with GhcWithInterpreter=NO
Herbert Valerio Riedel [Fri, 22 Sep 2017 11:03:49 +0000 (13:03 +0200)] 
Fix build with GhcWithInterpreter=NO

This is a consequence of NoImplicitPrelude which was introduced
in f63bc730c7ea42ca6882f8078eb86be8bf1cc6ad.

2 years agoRemove 'stm' from EXTRA_PACKAGES set
Herbert Valerio Riedel [Fri, 22 Sep 2017 08:35:02 +0000 (10:35 +0200)] 
Remove 'stm' from EXTRA_PACKAGES set

This effectively broke `make sdist`; the surprising thing is that
./validate didn't catch this (and thus the buildbots didn't either).

Also, I would have expected `EXTRA_PACKAGES` to be populated by the
data in `./packages` which already encodes that information...

This is a follow-up to 02ff70563e490d2a7f3141eab7229803c523da57

2 years agoFix broken LLVM code gen
Moritz Angermann [Thu, 21 Sep 2017 22:05:46 +0000 (18:05 -0400)] 
Fix broken LLVM code gen

In 8b007abbeb30 (nativeGen: Consistently use blockLbl to generate
CLabels from BlockIds) all blockLbls were changed. This interfered with
the `toInfoLbl` call in CmmProcPoint, and caused the LLVM backend to
fall over.

Reviewers: bgamari, austin, simonmar

Reviewed By: bgamari

Subscribers: rwbarton, thomie

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

2 years agoImplement TH addCorePlugin.
Facundo Domínguez [Thu, 21 Sep 2017 22:04:56 +0000 (18:04 -0400)] 
Implement TH addCorePlugin.

This allows template-haskell code to add plugins to the compilation
pipeline. Otherwise, the user would have to pass -fplugin=... to ghc.

For now, plugin modules in the current package can't be used. This is
because when TH runs, it is too late to let GHC know that the plugin
modules needed to be compiled first.

Test Plan: ./validate

Reviewers: simonpj, bgamari, austin, goldfire

Reviewed By: bgamari

Subscribers: angerman, rwbarton, mboes, thomie

GHC Trac Issues: #13608

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

2 years agorts: Set unwind information for catch_frame
Ben Gamari [Thu, 21 Sep 2017 22:04:24 +0000 (18:04 -0400)] 
rts: Set unwind information for catch_frame

Reviewers: austin, erikd, simonmar

Reviewed By: simonmar

Subscribers: rwbarton, thomie

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

2 years agorts: Set unwind information for remaining stack frames
Ben Gamari [Thu, 21 Sep 2017 22:04:03 +0000 (18:04 -0400)] 
rts: Set unwind information for remaining stack frames

Reviewers: austin, erikd, simonmar

Reviewed By: simonmar

Subscribers: rwbarton, thomie

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

2 years agoReexport Semigroup's <> operator from Prelude (#14191)
Herbert Valerio Riedel [Thu, 21 Sep 2017 21:30:05 +0000 (23:30 +0200)] 
Reexport Semigroup's <> operator from Prelude (#14191)

This completes the 2nd phase of the Semigroup=>Monoid Proposal (SMP)
initiated in 8ae263ceb3566a7c82336400b09cb8f381217405.

This updates a couple submodules to address <> naming clashes.

2 years agocmm/CBE: Use foldLocalRegsDefd
Ben Gamari [Thu, 21 Sep 2017 22:02:36 +0000 (18:02 -0400)] 
cmm/CBE: Use foldLocalRegsDefd

Simonpj suggested this as a follow-on to #14226 to avoid code
duplication. This also gives us the ability to CBE cases involving
foreign calls for free.

Test Plan: Validate

Reviewers: austin, simonmar, simonpj

Reviewed By: simonpj

Subscribers: michalt, simonpj, rwbarton, thomie

GHC Trac Issues: #14226

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

2 years agotestsuite: Bump allocations of T12150
Ben Gamari [Thu, 21 Sep 2017 21:23:34 +0000 (17:23 -0400)] 
testsuite: Bump allocations of T12150

It looks like this is probably just drift.

2 years agoAlso show types that subsume a hole as valid substitutions for that hole.
Matthías Páll Gissurarson [Thu, 21 Sep 2017 18:14:53 +0000 (14:14 -0400)] 
Also show types that subsume a hole as valid substitutions for that hole.

This builds on the previous "Valid substitutions include..." functionality,
but add subsumption checking as well, so that the suggested valid substitutions
show not only exact matches, but also identifiers that fit the hole by virtue of
subsuming the type of the hole (i.e. being more general than the type of the
hole).

Building on the previous example, in the given program

```
ps :: String -> IO ()
ps = putStrLn

ps2 :: a -> IO ()
ps2 _ = putStrLn "hello, world"

main :: IO ()
main = _ "hello, world"
```

The results would be something like

```
    • Found hole: _ :: [Char] -> IO ()
    • In the expression: _
      In the expression: _ "hello, world"
      In an equation for ‘main’: main = _ "hello, world"
    • Relevant bindings include main :: IO () (bound at t1.hs:8:1)
      Valid substitutions include
        ps :: String -> IO () (defined at t1.hs:2:1)
        ps2 :: forall a. a -> IO () (defined at t1.hs:5:1)
        putStrLn :: String -> IO ()
          (imported from ‘Prelude’ at t1.hs:1:1
           (and originally defined in ‘System.IO’))
        fail :: forall (m :: * -> *). Monad m => forall a. String -> m a
          (imported from ‘Prelude’ at t1.hs:1:1
           (and originally defined in ‘GHC.Base’))
        mempty :: forall a. Monoid a => a
          (imported from ‘Prelude’ at t1.hs:1:1
           (and originally defined in ‘GHC.Base’))
        print :: forall a. Show a => a -> IO ()
          (imported from ‘Prelude’ at t1.hs:1:1
           (and originally defined in ‘System.IO’))
        (Some substitutions suppressed;
         use -fmax-valid-substitutions=N or -fno-max-valid-substitutions)
```

Signed-off-by: Matthías Páll Gissurarson <mpg@mpg.is>
Modified according to suggestions from Simon PJ

Accept tests that match the expectations, still a few to look better at

Swithced to using tcLookup, after sit down with SPJ at ICFP. Implications are WIP.

Now works with polymorphism and constraints!

We still need to merge the latest master, before we can make a patch.

Wrap the type of the hole, instead of implication shenanigans,

As per SPJs suggestion, this is simpler and feels closer to
what we actually want to do.

Updated tests with the new implementation

Remove debugging trace and update documentation

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: RyanGlScott, rwbarton, thomie

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

2 years agoBump base to 4.11.0.0
Ben Gamari [Thu, 21 Sep 2017 16:50:47 +0000 (12:50 -0400)] 
Bump base to 4.11.0.0

Bumps numerous submodules.

Reviewers: austin, hvr

Subscribers: rwbarton, thomie

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

2 years agobase: Add changelog entry for withTypeable generalization
Ben Gamari [Thu, 21 Sep 2017 16:11:33 +0000 (12:11 -0400)] 
base: Add changelog entry for withTypeable generalization

2 years agotestsuite: Add unboxed sum to T13929
Ben Gamari [Tue, 19 Sep 2017 23:09:58 +0000 (19:09 -0400)] 
testsuite: Add unboxed sum to T13929

Test Plan: Validate

Reviewers: austin

Subscribers: rwbarton, thomie

GHC Trac Issues: #13929

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

2 years agotestsuite: Add testcase for #14253
Ben Gamari [Tue, 19 Sep 2017 23:03:33 +0000 (19:03 -0400)] 
testsuite: Add testcase for #14253

Reviewers: austin

Subscribers: rwbarton, thomie

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

2 years agoIdentify fields by selector when type-checking (fixes #13644)
Adam Gundry [Tue, 19 Sep 2017 23:03:16 +0000 (19:03 -0400)] 
Identify fields by selector when type-checking (fixes #13644)

Test Plan: new test for #13847, and the test for #13644 now passes

Reviewers: mpickering, austin, bgamari, simonpj

Reviewed By: mpickering, simonpj

Subscribers: simonpj, rwbarton, thomie

GHC Trac Issues: #13644, #13847

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

2 years agoTypeable: Generalize kind of represented type
Ben Gamari [Tue, 19 Sep 2017 22:59:18 +0000 (18:59 -0400)] 
Typeable: Generalize kind of represented type

This allows withTypeable to be used with things that are of kind other
than Type.

Test Plan: Validate

Reviewers: austin, hvr, dfeuer

Reviewed By: dfeuer

Subscribers: rwbarton, thomie, dfeuer

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

2 years agoTypeable: Allow App to match arrow types
Ben Gamari [Tue, 19 Sep 2017 22:57:38 +0000 (18:57 -0400)] 
Typeable: Allow App to match arrow types

Test Plan: T14236

Reviewers: austin, hvr, goldfire

Reviewed By: goldfire

Subscribers: RyanGlScott, simonpj, rwbarton, goldfire, thomie, dfeuer

GHC Trac Issues: #14236

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

2 years agoInitial CircleCI support.
Mathieu Boespflug [Sun, 3 Sep 2017 14:13:06 +0000 (16:13 +0200)] 
Initial CircleCI support.

2 years agoTypofixes (visiblity -> visibility)
Ryan Scott [Thu, 21 Sep 2017 13:08:15 +0000 (09:08 -0400)] 
Typofixes (visiblity -> visibility)

2 years agoaclocal.m4: call cygpath on mingw32 only
Sergei Trofimovich [Wed, 20 Sep 2017 22:18:22 +0000 (23:18 +0100)] 
aclocal.m4: call cygpath on mingw32 only

The only reason I noticed is warning these lines on linux:

```
$ ./configure --target=sparc-unknown-linux-gnu
...
./configure: line 9708: cygpath: command not found
./configure: line 9708: ArCmd: command not found
```

POSIX shell syntax requires no spaces in assignments.
Fixed guarding condition while at it.

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
2 years agoAdd 'stm' package to the global package database
Herbert Valerio Riedel [Wed, 20 Sep 2017 13:16:24 +0000 (15:16 +0200)] 
Add 'stm' package to the global package database

This is a preparation for `haskeline` picking up a dependency on `stm`
real soon now. See https://github.com/judah/haskeline/pull/61 for details.

If we figure out a way to not bundle the libraries depended upon by the
GHCi executable in the global package database (see #8919 for the original
reason why we had to start bundling terminfo/haskeline in the first place)
we can get rid of `stm` again...

On the bright side, we were able to avoid uploading new `stm` releases for
over two years already, so it shouldn't cause too much trouble if GHC imposes
a strong preference on the `stm` package's version (this most likely will
mostly affect Linux distributions & similiar).

While at it, this also update the stm submodule to include relaxed
bounds to allow the upcoming base-4.11 version.

2 years agoMake zipWith and zipWith3 inlinable.
HE, Tao [Tue, 19 Sep 2017 20:58:19 +0000 (16:58 -0400)] 
Make zipWith and zipWith3 inlinable.

Reviewers: austin, hvr, bgamari, dfeuer

Reviewed By: dfeuer

Subscribers: rwbarton, thomie

GHC Trac Issues: #14224

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

2 years agoRestore function powModSecInteger
Olivier Chéron [Tue, 19 Sep 2017 20:58:01 +0000 (16:58 -0400)] 
Restore function powModSecInteger

The function existed in integer-gmp-0.5.1.0 but was removed as
part of integer-gmp2 rewrite in #9281.  This is to bring it back.

Test Plan: Case integerGmpInternals, with GMP 4.3.2 and GMP 6.1.2

Reviewers: austin, hvr, goldfire, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie

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

2 years agocmm/CBE: Collapse blocks equivalent up to alpha renaming of local registers
Ben Gamari [Tue, 19 Sep 2017 20:57:41 +0000 (16:57 -0400)] 
cmm/CBE: Collapse blocks equivalent up to alpha renaming of local registers

As noted in #14226, the common block elimination pass currently
implements an extremely strict equivalence relation, demanding that two
blocks are equivalent including the names of their local registers. This
is quite restrictive and severely hampers the effectiveness of the pass.

Here we allow the CBE pass to collapse blocks which are equivalent up to
alpha renaming of locally-bound local registers. This is completely safe
and catches many more duplicate blocks.

Test Plan: Validate

Reviewers: austin, simonmar, michalt

Reviewed By: michalt

Subscribers: rwbarton, thomie

GHC Trac Issues: #14226

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

2 years agoFactor mkCoreApp and mkCoreApps
Arnaud Spiwack [Tue, 19 Sep 2017 20:57:25 +0000 (16:57 -0400)] 
Factor mkCoreApp and mkCoreApps

`mkCoreApps` re-implemented `mkCoreApp` in a recursive function,
rather than using a simple `foldl'` in order to avoid repeatingly
computing the type of the function argument. I've factored the two
logic into a new (internal) function `mkCoreType` which assumes that
the type is known. `mkCoreApp` and `mkCoreApps` are thin wrappers
around it.

Differences
- The assertion failure message of `mkCoreApps` has more
  information in it.
- `mkCoreApps` now special-cases coercion argument like
  `mkCoreApp` (previously they were given to `mk_val_app` instead)

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie

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

2 years agousers-guide: Mention changes necessary due to #13391
Ben Gamari [Tue, 19 Sep 2017 20:57:08 +0000 (16:57 -0400)] 
users-guide: Mention changes necessary due to #13391

Some variant of this should also be added to the migration guide.

[skip ci]

Test Plan: Read it

Reviewers: goldfire, austin

Reviewed By: goldfire

Subscribers: rwbarton, thomie

GHC Trac Issues: #13391

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

2 years agobase: Add more detail to FD_SETSIZE related error message
Niklas Hambüchen [Tue, 19 Sep 2017 19:14:27 +0000 (15:14 -0400)] 
base: Add more detail to FD_SETSIZE related error message

Reviewers: bgamari, austin, hvr

Reviewed By: bgamari

Subscribers: rwbarton, thomie

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

2 years agobase: Make it less likely for fdReady() to fail on Windows sockets.
Niklas Hambüchen [Tue, 19 Sep 2017 19:12:56 +0000 (15:12 -0400)] 
base: Make it less likely for fdReady() to fail on Windows sockets.

See the added comment for details.

It's "less likely" because it can still fail if the socket happens to
have an FD larger than 1023, which can happen if many files are opened.

Until now, basic socket programs that use `hWaitForInput` were broken on
Windows.

That is because on Windows `FD_SETSIZE` defaults to 64, but pretty much
all GHC programs seem to have > 64 FDs open, so you can't actually
create a socket on which you can `select()`.

It errors with `fdReady: fd is too big` even with an example as simple
as the following (in this case, on my machine the `fd` is `284`):

  {-# LANGUAGE OverloadedStrings #-}

  import Control.Monad (forever)
  import Network.Socket
  import System.IO

  -- Simple echo server: Reads up to 10 chars from network, echoes them back.
  -- Uses the Handle API so that `hWaitForInput` can be used.
  main :: IO ()
  main = do
    sock <- socket AF_INET Stream 0
    setSocketOption sock ReuseAddr 1
    bind sock (SockAddrInet 1234 0x0100007f)
      -- 0x0100007f == 127.0.0.1 localhost
    listen sock 2
    forever $ do
      (connSock, _connAddr) <- accept sock
      putStrLn "Got connection"

      h <- socketToHandle connSock ReadWriteMode
      hSetBuffering h NoBuffering

      ready <- hWaitForInput h (5 * 1000) -- 5 seconds
      putStrLn $ "Ready: " ++ show ready

      line <- hGetLine h
      putStrLn "Got line"
      hPutStrLn h ("Got: " ++ line)
      hClose h

I'm not sure how this was not discovered earlier; for #13525 (where
`fdReady()` breaking completely was also discovered late) at least it
failed only when the timeout was non-zero, which is not used in ghc
beyond in `hWaitForInput`, but in this Windows socket case it breaks
even on the 0-timeout.

Maybe there is not actually anybody who uses sockets as handles on
Windows?

The workaround for now is to increase `FD_SETSIZE` on Windows;
increasing it is possible on Windows and BSD, see

https://stackoverflow.com/questions/7976388/increasing-limit-of-fd-setsi
ze-and-select

A real fix would be to move to IO Completion Ports on Windows, and thus
get rid of the last uses of `select()` (the other platforms already use
`poll()` but Windows doesn't have that).

Reviewers: bgamari, austin, hvr, erikd, simonmar

Reviewed By: bgamari

Subscribers: rwbarton, thomie

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

2 years agorts: Fix typo in comment
Niklas Hambüchen [Tue, 19 Sep 2017 19:12:11 +0000 (15:12 -0400)] 
rts: Fix typo in comment

Reviewers: bgamari, austin, erikd, simonmar

Reviewed By: bgamari

Subscribers: rwbarton, thomie

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

2 years agorts: Update comment about FreeBSD's unsigned FD_SETSIZE
Niklas Hambüchen [Tue, 19 Sep 2017 19:11:38 +0000 (15:11 -0400)] 
rts: Update comment about FreeBSD's unsigned FD_SETSIZE

Reviewers: bgamari, austin, erikd, simonmar

Reviewed By: bgamari

Subscribers: rwbarton, thomie

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

2 years agobase: Fix fdReady() returning immediately for pipes on Windows.
Niklas Hambüchen [Tue, 19 Sep 2017 19:11:05 +0000 (15:11 -0400)] 
base: Fix fdReady() returning immediately for pipes on Windows.

See https://ghc.haskell.org/trac/ghc/ticket/13497#comment:17

Until now, the program

  import System.IO
  main = hWaitForInput stdin (5 * 1000)

didn't wait 5 seconds for input on Winodws, it terminated immediately.

This was because the `PeekNamedPipe()` function introduced in commit
94fee9e7 really only peeks, it doesn't block.  So if there's no data,
`fdReady(fd, msec)` would return immediately even when the given `msec`
timeout is not zero.

This commit fixes it by looping around `PeekNamedPipe()` with a `sleep(1
ms)`.

Apparently there's no better way to do this on Windows without switching
to IOCP.

In any case, this change should be strictly better than what was there
before.

Reviewers: bgamari, austin, hvr

Reviewed By: bgamari

Subscribers: Phyx, rwbarton, thomie

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

2 years agobase: Fix fdReady() potentially running forever for Windows Char devices.
Niklas Hambüchen [Tue, 19 Sep 2017 19:10:31 +0000 (15:10 -0400)] 
base: Fix fdReady() potentially running forever for Windows Char devices.

Reviewers: bgamari, austin, hvr

Reviewed By: bgamari

Subscribers: rwbarton, thomie

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

2 years agobase: Fix fdReady() potentially running forever on Windows.
Niklas Hambüchen [Tue, 19 Sep 2017 19:10:00 +0000 (15:10 -0400)] 
base: Fix fdReady() potentially running forever on Windows.

This fixes #13497 for Windows -- at least for the `if (isSock)` part; I
haven't investigated the case where it's not a socket yet.

Solved by copying the new current-time based waiting logic from the
non-Windows implementation above.

Reviewers: bgamari, austin, hvr

Reviewed By: bgamari

Subscribers: rwbarton, thomie

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

2 years agobase: fdReady(): Improve accuracy and simplify code.
Niklas Hambüchen [Tue, 19 Sep 2017 19:09:29 +0000 (15:09 -0400)] 
base: fdReady(): Improve accuracy and simplify code.

This is done by reusing the existing cross-platform
`getProcessElapsedTime()` function, which already provides nanosecond
monotonic clocks, and fallback for platforms that don't have those.

To do this, `getProcessElapsedTime()` had to be moved from a private RTS
symbol into the public interface.

Accuracy is improved in 2 ways:

* Use of the monotonic clock where available
* Measuring the total time spent waiting instead of a sum
  of intervals (between which there are small gaps)

Reviewers: bgamari, austin, hvr, erikd, simonmar

Reviewed By: bgamari

Subscribers: rwbarton, thomie

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

2 years agoFix Windows build regression due to GhcPrelude change
Ben Gamari [Tue, 19 Sep 2017 19:58:20 +0000 (15:58 -0400)] 
Fix Windows build regression due to GhcPrelude change

2 years agocompiler: introduce custom "GhcPrelude" Prelude
Herbert Valerio Riedel [Tue, 19 Sep 2017 18:35:36 +0000 (14:35 -0400)] 
compiler: introduce custom "GhcPrelude" Prelude

This switches the compiler/ component to get compiled with
-XNoImplicitPrelude and a `import GhcPrelude` is inserted in all
modules.

This is motivated by the upcoming "Prelude" re-export of
`Semigroup((<>))` which would cause lots of name clashes in every
modulewhich imports also `Outputable`

Reviewers: austin, goldfire, bgamari, alanz, simonmar

Reviewed By: bgamari

Subscribers: goldfire, rwbarton, thomie, mpickering, bgamari

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

2 years agoOccurAnal: Ensure SourceNotes don't interfere with join-point analysis
Ben Gamari [Tue, 19 Sep 2017 15:16:55 +0000 (11:16 -0400)] 
OccurAnal: Ensure SourceNotes don't interfere with join-point analysis

In general ticks are problematic for join point analysis as described
in #14242.  However, source notes are intended to be a best-effort
annotation which shouldn't interfere with optimization. Special-case
these to ensure that tail-call information is still correct, even in the
presence of source note
ticks.

Test Plan: Validate

Reviewers: simonpj, austin

Reviewed By: simonpj

Subscribers: rwbarton, thomie

GHC Trac Issues: #14242

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

2 years agonativeGen: Consistently use blockLbl to generate CLabels from BlockIds
Ben Gamari [Tue, 19 Sep 2017 14:58:36 +0000 (10:58 -0400)] 
nativeGen: Consistently use blockLbl to generate CLabels from BlockIds

This fixes #14221, where the NCG and the DWARF code were apparently
giving two different names to the same block.

Test Plan: Validate with DWARF support enabled.

Reviewers: simonmar, austin

Subscribers: rwbarton, thomie

GHC Trac Issues: #14221

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

2 years agorts/RetainerProfile: Adding missing closure types to isRetainer
Ben Gamari [Tue, 19 Sep 2017 13:51:01 +0000 (09:51 -0400)] 
rts/RetainerProfile: Adding missing closure types to isRetainer

orzo in `#ghc` reported seeing a crash due to the retainer profiler encountering
a BLOCKING_QUEUE closure, which isRetainer didn't know about. I performed an
audit to make sure that all of the valid closure types were listed; they
weren't. This is my guess of how they should appear.

Test Plan: Validate

Reviewers: simonmar, austin, erikd

Reviewed By: simonmar

Subscribers: rwbarton, thomie

GHC Trac Issues: #14235

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