ghc.git
3 years agoComments (only) in TcFlatten
Richard Eisenberg [Mon, 21 Mar 2016 21:03:38 +0000 (17:03 -0400)] 
Comments (only) in TcFlatten

3 years agostgMallocBytes: Tolerate malloc(0) returning a NULL ptr
Herbert Valerio Riedel [Mon, 21 Mar 2016 20:40:23 +0000 (21:40 +0100)] 
stgMallocBytes: Tolerate malloc(0) returning a NULL ptr

This is valid behaviour for `malloc()` according to ISO C99 and POSIX,
and there's at least one operating system (AIX) which actually does return
NULL for 0-sized allocations.

The `createAdjustor()` routine is currently the only known use-site of
`stgMallocBytes` which may call `stgMallocBytes()` requesting a 0-size
allocation.

Reviewed By: bgamari, austin

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

3 years agoImprove panicking output
Richard Eisenberg [Mon, 21 Mar 2016 03:15:13 +0000 (23:15 -0400)] 
Improve panicking output

3 years agoFix #11723 and #11724.
Richard Eisenberg [Sat, 19 Mar 2016 21:19:04 +0000 (17:19 -0400)] 
Fix #11723 and #11724.

Test cases: typecheck/should_fail/T1172{3,4}

3 years agoZonk before calling splitDepVarsOfType.
Richard Eisenberg [Mon, 21 Mar 2016 15:08:10 +0000 (11:08 -0400)] 
Zonk before calling splitDepVarsOfType.

It was Utterly Wrong before.

Note to self: Never, ever take the free vars of an unzonked type.

3 years agoTrack specified/invisible more carefully.
Richard Eisenberg [Sat, 19 Mar 2016 20:55:50 +0000 (16:55 -0400)] 
Track specified/invisible more carefully.

In particular, this allows correct tracking of specified/invisible
for variables in Haskell98 data constructors and in pattern synonyms.
GADT-syntax constructors are harder, and are left until #11721.

This was all inspired by Simon's comments to my fix for #11512,
which this subsumes.

Test case: ghci/scripts/TypeAppData

[skip ci]  (The test case fails because of an unrelated problem
fixed in the next commit.)

3 years agoComment a suspicious zonk in TcFlatten.
Richard Eisenberg [Sat, 19 Mar 2016 02:37:37 +0000 (22:37 -0400)] 
Comment a suspicious zonk in TcFlatten.

3 years agoPrevent eager unification with type families.
Richard Eisenberg [Sat, 19 Mar 2016 02:36:34 +0000 (22:36 -0400)] 
Prevent eager unification with type families.

See Note [Prevent unification with type families]
in TcUnify for the details.

3 years agoRename test for #11334 to 11334b, fixing conflict
Richard Eisenberg [Sat, 19 Mar 2016 01:40:04 +0000 (21:40 -0400)] 
Rename test for #11334 to 11334b, fixing conflict

3 years agoMake equality print better. (#11712)
Richard Eisenberg [Fri, 18 Mar 2016 15:20:31 +0000 (11:20 -0400)] 
Make equality print better. (#11712)

3 years agoFix #11635 / #11719.
Richard Eisenberg [Fri, 18 Mar 2016 15:02:38 +0000 (11:02 -0400)] 
Fix #11635 / #11719.

Instead of creating a new meta-tyvar and then unifying it with
a known kind in a KindedTyVar in a LHsQTyVars, just use the known kind.

Sadly, this still doesn't make #11719 usable, because while you can
now define a higher-kinded type family, you can't write any equations
for it, which is a larger problem.

test cases: dependent/should_compile/T{11635,11719}

3 years agoAdd two small optimizations. (#11196)
Richard Eisenberg [Fri, 18 Mar 2016 13:40:15 +0000 (09:40 -0400)] 
Add two small optimizations. (#11196)

- Optimize zonking * to avoid allocation.
- Try to avoid looking at the free variables of a type in the
  pure unifier. We need look at the variables only in the case
  of a forall.

The performance results updates included in this also include
a regression, but the regression is not due to this patch. When
validating previous patches, the test case failed, but I was
unable to reproduce outside of validation, so I let it go by, thinking
the failure was spurious. Upon closer inspection, the perf number
was right at the line, and the wibble between a valiation environment
and a regular test run was enough to make the difference.

3 years agoTypeApplications does not imply AllowAmbiguousTypes
Richard Eisenberg [Thu, 17 Mar 2016 21:49:28 +0000 (17:49 -0400)] 
TypeApplications does not imply AllowAmbiguousTypes

3 years agoFix exponential algorithm in pure unifier.
Richard Eisenberg [Thu, 17 Mar 2016 19:40:58 +0000 (15:40 -0400)] 
Fix exponential algorithm in pure unifier.

3 years agoRemove unused substTyWithBinders functions
Bartosz Nitka [Mon, 21 Mar 2016 12:33:44 +0000 (05:33 -0700)] 
Remove unused substTyWithBinders functions

Originally I wanted to only remove substTyWithBindersUnchecked, but
since both of them are unused maybe we don't need them.

Test Plan: ./validate

Reviewers: austin, goldfire, bgamari, simonpj

Reviewed By: simonpj

Subscribers: thomie, simonmar

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

GHC Trac Issues: #11371

3 years agoRemove unnecessary Ord instance for ConLike
Bartosz Nitka [Mon, 21 Mar 2016 10:34:03 +0000 (03:34 -0700)] 
Remove unnecessary Ord instance for ConLike

The Ord instance for ConLike uses Unique order which is bad for
determinism. Fortunately it's not used, so we can just delete it.
The is part of the effort to make Unique comparisons explicit.

Test Plan: ./validate

Reviewers: austin, simonmar, bgamari, simonpj

Reviewed By: simonpj

Subscribers: thomie

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

GHC Trac Issues: #4012

3 years agoDelete a misleading comment in TyCon
Bartosz Nitka [Mon, 21 Mar 2016 10:30:59 +0000 (03:30 -0700)] 
Delete a misleading comment in TyCon

`Ord` for `TyCon` uses `Uniques` and it's not lexicographic.
I did some archeology and in
rGHC6c381e873e222417d9a67aeec77b9555eca7b7a8 the comment was introduced,
where there was something like `Ord3 Tycon` which *was* lexicographic.
In rGHC9dd6e1c216993624a2cd74b62ca0f0569c02c26b `Ord3 TyCon` was already
not lexicographic and `Ord3` got removed.

Test Plan: make someone take a look

Reviewers: hvr, austin, bgamari

Reviewed By: bgamari

Subscribers: thomie, simonmar

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

3 years agobase: Fix CPUTime on Windows
Ben Gamari [Sun, 20 Mar 2016 21:15:46 +0000 (22:15 +0100)] 
base: Fix CPUTime on Windows

Arg, silly CPP.

3 years agoT11145: Fix expected output
Ben Gamari [Sun, 20 Mar 2016 19:44:19 +0000 (20:44 +0100)] 
T11145: Fix expected output

The uniques seem to keep changing here.

3 years agobase: Rework System.CPUTime
Ben Gamari [Sun, 20 Mar 2016 16:56:24 +0000 (17:56 +0100)] 
base: Rework System.CPUTime

This started when I noticed that `getCPUTime` only provides 1
millisecond resolution on Linux. Unfortunately the previous
implementation was quite unmaintainable, so this ended up being a bit
more involved than I expected.

Here we do several things,

 * Split up `System.CPUTime`

 * Add support for `clock_gettime`, allowing for significantly more
   precise timing information when available

 * Fix System.CPUTime resolution for Windows. While it's hard to get
   reliable numbers, the consensus is that Windows only provides 16
   millisecond resolution in GetProcessTimes (see Python PEP 0418 [1])

 * Eliminate terrible hack wherein we would cast between `CTime` and
   `Integer` through `Double`

[1] https://www.python.org/dev/peps/pep-0418/#id59

Test Plan: Validate on various platforms

Reviewers: austin, hvr, erikd

Reviewed By: erikd

Subscribers: thomie

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

3 years agoAdd test for incompatible flags (issue #11580)
Kai Harries [Sun, 20 Mar 2016 16:51:39 +0000 (17:51 +0100)] 
Add test for incompatible flags (issue #11580)

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

GHC Trac Issues: #11580

3 years agoDsExpr: Don't build/foldr huge lists
Ben Gamari [Sun, 20 Mar 2016 16:49:58 +0000 (17:49 +0100)] 
DsExpr: Don't build/foldr huge lists

Desugaring long lists with build trades large static data for large
code, which is likely a poor trade-off. See #11707.

Test Plan: Validate, nofib

Reviewers: simonpj, austin

Reviewed By: austin

Subscribers: thomie

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

GHC Trac Issues: #11707

3 years agoprof: Fix heap census for large ARR_WORDS (#11627)
Jason Eisenberg [Sun, 20 Mar 2016 16:49:24 +0000 (17:49 +0100)] 
prof: Fix heap census for large ARR_WORDS (#11627)

The heap census now handles large ARR_WORDS objects which have
been shrunk by shrinkMutableByteArray# or resizeMutableByteArray#.

Test Plan: ./validate && make test WAY=profasm

Reviewers: hvr, bgamari, austin, thomie

Reviewed By: thomie

Subscribers: thomie

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

GHC Trac Issues: #11627

3 years agoDwarf: Add support for labels in unwind expressions
Ben Gamari [Sun, 20 Mar 2016 16:47:57 +0000 (17:47 +0100)] 
Dwarf: Add support for labels in unwind expressions

Test Plan: Look at DWARF output.

Reviewers: scpmw, austin

Reviewed By: austin

Subscribers: thomie

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

3 years agoFix T9646
Ben Gamari [Sun, 20 Mar 2016 15:47:31 +0000 (16:47 +0100)] 
Fix T9646

For #9646.

3 years agoFix duplicate T11334 test
Ben Gamari [Sun, 20 Mar 2016 15:02:32 +0000 (16:02 +0100)] 
Fix duplicate T11334 test

3 years agoRevert "Add test for #11473"
Ben Gamari [Fri, 18 Mar 2016 15:49:13 +0000 (16:49 +0100)] 
Revert "Add test for #11473"

This reverts commit 89bdac7635e6ed08927d760aa885d3e7ef3edb81 as
this test is duplicated with dependent/should_fail/T11473, added by
aade111248dce0834ed83dc4f18c234967b3202.

3 years agoEnsure T11702 always runs with optasm
Ben Gamari [Wed, 16 Mar 2016 09:00:12 +0000 (10:00 +0100)] 
Ensure T11702 always runs with optasm

3 years agoMark GHC.Real.even and odd as INLINEABLE
Ben Gamari [Mon, 14 Mar 2016 12:27:23 +0000 (13:27 +0100)] 
Mark GHC.Real.even and odd as INLINEABLE

Previously they were merely specialised at Int and Integer. It seems to
me that these are cheap enough to be worth inlining. See #11701 for
motivation.

Test Plan: Validate

Reviewers: austin, hvr, simonpj

Reviewed By: simonpj

Subscribers: thomie

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

GHC Trac Issues: #11701

3 years agoPrelRules: Fix constant folding for WordRemOp
Ben Gamari [Mon, 14 Mar 2016 12:27:00 +0000 (13:27 +0100)] 
PrelRules: Fix constant folding for WordRemOp

Test Plan: Validate with testcase in D2002

Reviewers: austin, simonpj

Reviewed By: simonpj

Subscribers: simonpj, thomie

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

GHC Trac Issues: #11702

3 years agoAdd test for #9646
Erik de Castro Lopo [Wed, 16 Mar 2016 09:19:28 +0000 (20:19 +1100)] 
Add test for #9646

Test Plan: Test that it passes git HEAD and fails with GHC 7.8.

Reviewers: bgamari, hvr, austin, goldfire, thomie

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

GHC Trac Issues: #9646

3 years agoFix #11512 by getting visibility right for methods
Richard Eisenberg [Thu, 17 Mar 2016 03:37:30 +0000 (23:37 -0400)] 
Fix #11512 by getting visibility right for methods

Test case: typecheck/should_compile/T11512

3 years agoFix #11716.
Richard Eisenberg [Wed, 16 Mar 2016 19:20:32 +0000 (15:20 -0400)] 
Fix #11716.

There were several smallish bugs here:
 - We had too small an InScopeSet when rejigging GADT return types.
 - When adding the extra_tvs with a datatype kind signature, we
   were sometimes changing Uniques of an explicitly bound kind var.
 - Using coercionKind in the flattener got the wrong visibility
   for a binder. Now we just zonk to get what we need.

Test case: dependent/should_compile/RaeJobTalk

3 years agotypechecker: fix trac issue #11708
Csongor Kiss [Wed, 16 Mar 2016 19:26:59 +0000 (15:26 -0400)] 
typechecker: fix trac issue #11708

Summary: Fixes T11708

Reviewers: austin, bgamari, goldfire, simonpj

Reviewed By: goldfire, simonpj

Subscribers: simonpj, goldfire, thomie

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

GHC Trac Issues: #11708

3 years agoFix #11711.
Richard Eisenberg [Wed, 16 Mar 2016 18:30:00 +0000 (14:30 -0400)] 
Fix #11711.

There were two bugs here, both simple: we need to filter out
covars before calling isMetaTyVar in the solver, and TcPat had
a tcSubType the wrong way round.

test case: dependent/should_compile/T11711

3 years agoDriverPipeline: Fix 'unused arguments' warnings from Clang
Erik de Castro Lopo [Sun, 13 Mar 2016 04:28:11 +0000 (15:28 +1100)] 
DriverPipeline: Fix 'unused arguments' warnings from Clang

When using Clang as the C compiler, over 100 tests were failing
due to Clang reporting that some command line arguments were not
being used. These warnings only occur when Clang is compiling
assembler files which happens in two places, one of which already
conditionally adding `-Qunused-arguments` to the command line when
the compiler was Clang. This fixes the other.

Test Plan: validate with clang as the C compiler

Reviewers: bgamari, hvr, austin, rwbarton

Subscribers: thomie

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

GHC Trac Issues: #11684

3 years agoClean up some pretty-printing in errors.
Richard Eisenberg [Tue, 15 Mar 2016 20:56:51 +0000 (16:56 -0400)] 
Clean up some pretty-printing in errors.

It turns out that there were some pretty egregious mistakes
in the code that suggested -fprint-explicit-kinds, which are
fixed. This commit also reorders a bunch of error messages,
which I think is an improvement.

This also adds the test case for #11471, which is what
triggered the cleanup in TcErrors. Now that #11473 is done,
there is nothing more outstanding for #11471.

test case: dependent/should_fail/T11471

3 years agoFix printing of "kind" vs. "type"
Richard Eisenberg [Tue, 15 Mar 2016 18:54:48 +0000 (14:54 -0400)] 
Fix printing of "kind" vs. "type"

This is as reported in #11471, though it's not the focus of that
ticket.

test case: polykinds/KindVType

3 years agoFix #11473.
Richard Eisenberg [Tue, 15 Mar 2016 18:27:22 +0000 (14:27 -0400)] 
Fix #11473.

I've added a check in the zonker for representation polymorphism.
I don't like having this be in the zonker, but I don't know where
else to put it. It can't go in TcValidity, because a clever enough
user could convince the solver to do bogus representation polymorphism
even though there's nothing obviously wrong in what they wrote.
Note that TcValidity doesn't run over *expressions*, which is where
this problem arises.

In any case, the check is simple and it works.

test case: dependent/should_fail/T11473

3 years agoFix #11357.
Richard Eisenberg [Tue, 15 Mar 2016 17:49:15 +0000 (13:49 -0400)] 
Fix #11357.

We were looking at a data instance tycon for visibility info,
which is the wrong place to look. Look at the data family tycon
instead.

Also improved the pretty-printing near there to suppress kind
arguments when appropriate.

3 years agoIncorporate bgamari's suggestions for #11614.
Richard Eisenberg [Tue, 15 Mar 2016 17:21:20 +0000 (13:21 -0400)] 
Incorporate bgamari's suggestions for #11614.

3 years agoRemove redundant anonymiseTyBinders (#11648)
Richard Eisenberg [Tue, 15 Mar 2016 15:37:00 +0000 (11:37 -0400)] 
Remove redundant anonymiseTyBinders (#11648)

This was necessary in an earlier version of the patch for #11648,
but not in the final version. I forgot to remove it.

3 years agoTestsuite wibbles from previous commits.
Richard Eisenberg [Sat, 12 Mar 2016 20:52:22 +0000 (15:52 -0500)] 
Testsuite wibbles from previous commits.

3 years agoAllow eager unification with type families.
Richard Eisenberg [Tue, 15 Mar 2016 02:09:36 +0000 (22:09 -0400)] 
Allow eager unification with type families.

Previously, checkTauTvUpdate, used in the eager unifier (TcUnify)
right before writing to a metavar, refused to write a metavar to
a type involving type functions. The reason for this was given
in a Note, but the Note didn't make all that much sense and even
admitted that it was a bit confused. The Note, in turn, referred
to another Note, which it was quite sceptical of, as well.

The type-family check was slowing down performance, so I tried
removing it, running the tests referred to in the Note. The tests
all passed without the check. Looking at more test results, I
saw several error messages improve without the check, and some cases
where GHC looped (T7788, in particular) it now doesn't.

So, all in all, quite a win: Two hairy Notes removed, several lines
of code removed, better performance, and improved output.

[skip ci]

3 years agoFix #11648.
Richard Eisenberg [Sun, 13 Mar 2016 01:59:44 +0000 (20:59 -0500)] 
Fix #11648.

We now check that a CUSK is really a CUSK and issue an error if
it isn't. This also involves more solving and zonking in
kcHsTyVarBndrs, which was the outright bug reported in #11648.

Test cases: polykinds/T11648{,b}

This updates the haddock submodule.

[skip ci]

3 years agoDocument TypeInType (#11614)
Richard Eisenberg [Fri, 11 Mar 2016 16:14:04 +0000 (11:14 -0500)] 
Document TypeInType (#11614)

[skip ci]

3 years agoTest case for #11699 in typecheck/should_compile
Richard Eisenberg [Fri, 11 Mar 2016 15:27:53 +0000 (10:27 -0500)] 
Test case for #11699 in typecheck/should_compile

[skip ci]

3 years agoExpand Note [Non-trivial definitional equality]
Richard Eisenberg [Wed, 24 Feb 2016 19:41:37 +0000 (14:41 -0500)] 
Expand Note [Non-trivial definitional equality]

This adapts the text from D1944.

[skip ci]

3 years agoRefactor visible type application.
Richard Eisenberg [Tue, 23 Feb 2016 14:51:50 +0000 (09:51 -0500)] 
Refactor visible type application.

This replaces the old HsType and HsTypeOut constructors
with HsAppType and HsAppTypeOut, leading to some simplification.
(This refactoring addresses #11329.)

This also fixes #11456, which stumbled over HsType (which is
not an expression).

test case: ghci/scripts/T11456

[skip ci]

3 years agoFix #11401.
Richard Eisenberg [Tue, 23 Feb 2016 03:15:44 +0000 (22:15 -0500)] 
Fix #11401.

This commit teaches shortCutReduction about Derived constraints.

[skip ci]

3 years agoFix #11334.
Richard Eisenberg [Tue, 23 Feb 2016 02:47:32 +0000 (21:47 -0500)] 
Fix #11334.

Now we fail when trying to default non-*-kinded kind variables
with -XNoPolyKinds.

test case: dependent/should_fail/T11334

[skip ci]

3 years agoFix #11407.
Richard Eisenberg [Mon, 22 Feb 2016 17:54:56 +0000 (12:54 -0500)] 
Fix #11407.

This removes the `defer_me` check that was in checkTauTvUpdate
and uses only a type family check instead. The old defer_me check
repeated work done by fast_check in occurCheckExpand.

There is also some error message improvement, necessitated by
the terrible error message that the test case produced, even when
it didn't consume all of memory.

test case: dependent/should_fail/T11407

[skip ci]

3 years agoMove and expand (slightly) TypeApplications docs
Richard Eisenberg [Mon, 22 Feb 2016 01:51:27 +0000 (20:51 -0500)] 
Move and expand (slightly) TypeApplications docs

[skip ci]

3 years agoAdd regression test for #11702
Ben Gamari [Sun, 13 Mar 2016 20:29:19 +0000 (21:29 +0100)] 
Add regression test for #11702

Test Plan: Validate

Reviewers: austin

Subscribers: thomie

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

GHC Trac Issues: #11702

3 years agoFix the name of the Word16ElemRep wired-in datacon
mniip [Sun, 13 Mar 2016 17:12:55 +0000 (18:12 +0100)] 
Fix the name of the Word16ElemRep wired-in datacon

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

3 years agousers_guide: Break up -fprint-* description
Ben Gamari [Sun, 13 Mar 2016 11:56:37 +0000 (12:56 +0100)] 
users_guide: Break up -fprint-* description

This makes it a bit easier to find the description corresponding to
particular flags.

3 years agoLlvmCodeGen: Fix generation of malformed LLVM blocks
Erik de Castro Lopo [Sat, 12 Mar 2016 11:03:56 +0000 (12:03 +0100)] 
LlvmCodeGen: Fix generation of malformed LLVM blocks

Commit 673efccb3b uncovered a bug in LLVM code generation that produced
LLVM code that the LLVM compiler refused to compile:

    {
    clpH:
      br label %clpH
    }

This may well be a bug in LLVM itself. The solution is to keep the
existing entry label and rewrite the function as:

    {
    clpH:
      br label %nPV
    nPV:
      br label %nPV
    }

Thanks to Ben Gamari for pointing me in the right direction on this
one.

Test Plan: Build GHC with BuildFlavour=quick-llvm

Reviewers: hvr, austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

GHC Trac Issues: #11649

3 years agoghci: add message when reusing compiled code #9887
Alexander Lukyanov [Sat, 12 Mar 2016 11:03:47 +0000 (12:03 +0100)] 
ghci: add message when reusing compiled code #9887

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

GHC Trac Issues: #9887

3 years agoSimplify: Make generated names more useful
Ben Gamari [Fri, 11 Mar 2016 14:24:49 +0000 (15:24 +0100)] 
Simplify: Make generated names more useful

makeTrivial is responsible for concocting names during simplification.
Previously, however, it would make no attempt to generate a name that
might be useful to later readers of the resulting Core. Here we add a
bit of state to SimplEnv: a finite depth stack of binders within which
we are currently simplifying. We then derive generated binders from this
context.

See #11676.

Open questions:
  * Is there a better way to accomplish this?
  * Is `maxContextDepth` too large/small?

Test Plan: Validate, look at Core.

Reviewers: austin, simonpj

Reviewed By: simonpj

Subscribers: thomie, simonpj

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

GHC Trac Issues: #11676

3 years agorts: fix threadStackUnderflow type in cmm
Sergei Trofimovich [Fri, 11 Mar 2016 22:31:58 +0000 (22:31 +0000)] 
rts: fix threadStackUnderflow type in cmm

stg_stack_underflow_frame had an incorrect
call of C function 'threadStackUnderflow':
    ("ptr" ret_off) =
      foreign "C" threadStackUnderflow(
        MyCapability(),
        CurrentTSO);

Which means it's prototype is:
    void * (*) (W_, void*);
While real prototype is:
    W_ (*) (Capability *cap, StgTSO *tso);

The fix is simple. Fix type annotations:
    (ret_off) =
      foreign "C" threadStackUnderflow(
        MyCapability() "ptr",
        CurrentTSO "ptr");

Noticed when debugged T9045 test failure
on m68k target which distincts between
pointer and non pointer return types
(uses different registers)

While at it noticed and fixed return types
for 'throwTo' and 'findSpark'.

Trac #11395

Signed-off-by: Sergei Trofimovich <siarheit@google.com>
3 years agoAdd -foptimal-applicative-do
Simon Marlow [Fri, 4 Mar 2016 13:06:42 +0000 (13:06 +0000)] 
Add -foptimal-applicative-do

Summary:
The algorithm for ApplicativeDo rearrangement is based on a heuristic
that runs in O(n^2).  This patch adds the optimal algorithm, which is
O(n^3), selected by a flag (-foptimal-applicative-do).  It finds better
solutions in a small number of cases (about 2% of the cases where
ApplicativeDo makes a difference), but it can be very slow for large do
expressions.  I'm mainly adding it for experimental reasons.

ToDo: user guide docs

Test Plan: validate

Reviewers: simonpj, bgamari, austin, niteria, erikd

Subscribers: thomie

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

3 years agoBump allocations for T6048
Ben Gamari [Fri, 11 Mar 2016 12:23:30 +0000 (13:23 +0100)] 
Bump allocations for T6048

This occassionally fails with allocations a few tenths of a percent
above threshold. Sadly there isn't a clear cause; it's likely just the
result of gradual creep, further underscoring the need for more regular
performance characterization.

3 years agoMove getOccFS to Name
Ben Gamari [Fri, 11 Mar 2016 10:42:01 +0000 (11:42 +0100)] 
Move getOccFS to Name

3 years agoHandle unset HOME environment variable more gracefully
Ben Gamari [Fri, 11 Mar 2016 09:44:03 +0000 (10:44 +0100)] 
Handle unset HOME environment variable more gracefully

Test Plan:
  * Validate
  * try `env -i ghc`
  * try `env -i runghc HelloWorld.hs`

Reviewers: austin

Subscribers: thomie, ezyang

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

GHC Trac Issues: #11678

3 years agoAdd ghc-flag directory for -XPatternGuards
Ben Gamari [Fri, 11 Mar 2016 09:41:30 +0000 (10:41 +0100)] 
Add ghc-flag directory for -XPatternGuards

Reviewers: austin

Subscribers: thomie

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

3 years agoAdd MonadUnique instance for LlvmM
Ben Gamari [Fri, 11 Mar 2016 09:41:05 +0000 (10:41 +0100)] 
Add MonadUnique instance for LlvmM

Reviewers: erikd, austin

Reviewed By: erikd

Subscribers: thomie

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

3 years agortx/posix/Itimer.c: Handle return value of `read`
Erik de Castro Lopo [Fri, 11 Mar 2016 09:40:50 +0000 (10:40 +0100)] 
rtx/posix/Itimer.c: Handle return value of `read`

On Ubuntu libc's `read` function is marked with attribute
`warn_unused_result` which was causing build failures on
Harbourmaster.

Test Plan: validate on Harbourmaster

Reviewers: austin, hvr, bgamari

Reviewed By: hvr, bgamari

Subscribers: thomie

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

GHC Trac Issues: #11697

3 years agoAdd doc to (<$>) explaining its relationship to ($)
Chris Martin [Fri, 11 Mar 2016 09:40:16 +0000 (10:40 +0100)] 
Add doc to (<$>) explaining its relationship to ($)

Reviewers: bgamari, hvr, austin

Reviewed By: bgamari

Subscribers: thomie

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

3 years agoFix readme link to FixingBugs wiki page
Chris Martin [Fri, 11 Mar 2016 09:40:06 +0000 (10:40 +0100)] 
Fix readme link to FixingBugs wiki page

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

3 years agoAdd Note [Running splices in the Renamer]
Owen Stephens [Fri, 11 Mar 2016 09:39:55 +0000 (10:39 +0100)] 
Add Note [Running splices in the Renamer]

Reviewers: austin, goldfire, bgamari

Reviewed By: goldfire, bgamari

Subscribers: thomie

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

3 years agoMake integer-gmp operations more strict
Herbert Valerio Riedel [Fri, 11 Mar 2016 09:39:30 +0000 (10:39 +0100)] 
Make integer-gmp operations more strict

Reviewers: austin, goldfire, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

GHC Trac Issues: #10691

3 years agoInclude version in AC_PACKAGE_TARNAME
Ben Gamari [Fri, 11 Mar 2016 09:39:20 +0000 (10:39 +0100)] 
Include version in AC_PACKAGE_TARNAME

`AC_PACKAGE_TARNAME` is used by autoconf to generate the default value
of docdir, which we now set to include a version number (see #11354).
This fixed #11659.

Test Plan: `./configure --help`, validate

Reviewers: austin, thomie, hvr, erikd

Reviewed By: hvr, erikd

Subscribers: erikd

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

GHC Trac Issues: #11659

3 years agoDocument Quasi-quotes/list comprehension ambiguity
Ben Gamari [Fri, 11 Mar 2016 09:38:42 +0000 (10:38 +0100)] 
Document Quasi-quotes/list comprehension ambiguity

Test Plan: read it

Reviewers: austin, goldfire

Reviewed By: goldfire

Subscribers: hvr, thomie

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

GHC Trac Issues: #11679

3 years agoadd regression test for #11145.
Dominik Bollmann [Fri, 11 Mar 2016 09:38:28 +0000 (10:38 +0100)] 
add regression test for #11145.

The original TH failure observed by the ticket, namely that Template
Haskell quotes of data instance GADTs are broken, is not observable
anymore in HEAD. I therefore just added the corresponding regression
test.

Test Plan: ./validate

Reviewers: goldfire, austin, thomie, jstolarek, bgamari

Reviewed By: bgamari

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

GHC Trac Issues: #11145

3 years agoMake `catch` lazy in the action
Ben Gamari [Fri, 11 Mar 2016 09:38:10 +0000 (10:38 +0100)] 
Make `catch` lazy in the action

Previously
```lang=haskell
catch (error "uh oh") (\(_ :: SomeException) -> print "it failed")
```
would unexpectedly fail with "uh oh" instead of the handler being run
due to the strictness of `catch` in its first argument. See #11555 for
details.

Test Plan: Validate

Reviewers: austin, hvr, simonpj

Reviewed By: simonpj

Subscribers: simonpj, thomie

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

GHC Trac Issues: #11555

3 years agoUse catchException in a few more places
Ben Gamari [Fri, 11 Mar 2016 09:43:52 +0000 (10:43 +0100)] 
Use catchException in a few more places

These are cases in the standard library that may benefit from the
strictness signature of catchException and where we know that the action
won't bottom.

Test Plan: Validate, carefully consider changed callsites

Reviewers: austin, hvr

Subscribers: thomie

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

3 years agoAdd regression test for #11555
Ben Gamari [Fri, 11 Mar 2016 10:20:43 +0000 (11:20 +0100)] 
Add regression test for #11555

3 years agoFix #11624, cannot declare hs-boot if already one in scope.
Edward Z. Yang [Fri, 11 Mar 2016 09:37:26 +0000 (10:37 +0100)] 
Fix #11624, cannot declare hs-boot if already one in scope.

I'm not sure if this fix is the "right way" to do it, but
it solves the proximal problem, which is that lookupBindGroupOcc
was picking out the wrong renaming for hs-boot signatures,
which then lead to an interface file error.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Test Plan: validate

Reviewers: simonpj, hvr, austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

GHC Trac Issues: #11624

3 years agofix Float/Double unreg cross-compilation
Sergei Trofimovich [Thu, 10 Mar 2016 21:53:16 +0000 (21:53 +0000)] 
fix Float/Double unreg cross-compilation

Looking at more failures on m68k (Trac #11395)
I've noticed the arith001 and arith012 test failures.
(--host=x86_64-linux --target=m68k-linux).

The following example was enough to reproduce a problem:

    v :: Float
    v = 43
    main = print v

m68k binaries printed '0.0' instead of '43.0'.

The bug here is how we encode Floats and Double
as Words with the same binary representation.

Floats:
  Before the patch we just coerced Float to Int.
  That breaks when we cross-compile from
  64-bit LE to 32-bit BE.

  The patch fixes conversion by accounting for padding.
  when we extend 32-bit value to 64-bit value (LE and BE
  do it slightly differently).

Doubles:
  Before the patch Doubles were coerced to a pair of Ints
  (not correct as x86_64 can hold Double in one Int) and
  then trucated this pair of Ints to pair of Word32.

  The patch fixes conversion by always decomposing in
  Word32 and accounting for host endianness (newly
  introduced hostBE)  and target endianness (wORDS_BIGENDIAN).

I've tested this patch on Double and Float conversion on
    --host=x86_64-linux --target=m68k-linux
crosscompiler. It fixes 10 tests related to printing Floats
and Doubles.

Thanks to Bertram Felgenhauer who poined out this probem.

Signed-off-by: Sergei Trofimovich <siarheit@google.com>
Test Plan: checked some examples manually, fixed 10 tests in test suite

Reviewers: int-e, austin, bgamari

Subscribers: thomie

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

GHC Trac Issues: #11395

3 years agoUpdate Cabal submodule to latest HEAD snapshot
Herbert Valerio Riedel [Tue, 8 Mar 2016 09:58:49 +0000 (10:58 +0100)] 
Update Cabal submodule to latest HEAD snapshot

3 years agoRefactoring around TcPatSyn.tcPatToExpr
Simon Peyton Jones [Wed, 9 Mar 2016 13:14:09 +0000 (13:14 +0000)] 
Refactoring around TcPatSyn.tcPatToExpr

Just comments, a bit of refactoring, and a better
error-reporting infrastructure

3 years agoFix the implementation of lazyId
Simon Peyton Jones [Tue, 8 Mar 2016 15:27:54 +0000 (15:27 +0000)] 
Fix the implementation of lazyId

'lazy' was doing part of its job, but not all!  In particular,
an application
  f (lazy e)
where f is strict, was still being compiled using call-by-value in
CorePrep.  This defeated the purpose of defining catch as
   catch a b = catch# (lazy a) b
See Trac #11555, and Neil Mitchell's test case in comment:14

This patch makes 'lazy' behave properly. I updated Note [lazyId magic]
in MkId, but all the action is in CorePrep.

I can't say I really like this, but it does the job.

3 years agotemplate-haskell: define `MonadFail Q` instance
Herbert Valerio Riedel [Tue, 8 Mar 2016 16:26:00 +0000 (17:26 +0100)] 
template-haskell: define `MonadFail Q` instance

When `MonadFail`is available, this patch makes `MonadFail` a superclass
of `Quasi`, and `Q` an instance of `MonadFail`.

NB: Since f16ddcee0c64a92ab911a7841a8cf64e3ac671fd, we need to be able
    to compile `template-haskell` with stage0 compilers that don't provide
    a `MonadFail` class yet. Once we reach GHC 8.3 development we can drop
    the CPP conditionals again.

Addresses #11661

Reviewed By: bgamari, goldfire

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

3 years agotemplate-haskell: remove redundant CPP use
Herbert Valerio Riedel [Tue, 8 Mar 2016 11:46:49 +0000 (12:46 +0100)] 
template-haskell: remove redundant CPP use

GHC 8.1's template-haskell package requires base>=4.8 anyway, so
we can assume Numeric.Natural to be available unconditionally.

3 years agotemplate-haskell: Drop use of Rank2Types/PolymorphicComponents
Herbert Valerio Riedel [Tue, 8 Mar 2016 11:42:32 +0000 (12:42 +0100)] 
template-haskell: Drop use of Rank2Types/PolymorphicComponents

As per #6032, `Rank2Types` and `PolymorphicComponents` have been
deprecated in favour of `RankNTypes`.

also update `other-extensions` in template-haskell.cabal flag to
reflect reality.

3 years agoSplit external symbol prototypes (EF_) (Trac #11395)
Sergei Trofimovich [Tue, 8 Mar 2016 08:14:08 +0000 (08:14 +0000)] 
Split external symbol prototypes (EF_) (Trac #11395)

Before the patch both Cmm and C symbols were declared
with 'EF_' macro:

    #define EF_(f)    extern StgFunPtr f()

but for Cmm symbols we know exact prototypes.

The patch splits there prototypes in to:

    #define EFF_(f)   void f() /* See Note [External function prototypes] */
    #define EF_(f)    StgFunPtr f(void)

Cmm functions are 'EF_' (External Functions),
C functions are 'EFF_' (External Foreign Functions).

While at it changed external C function prototype
to return 'void' to workaround ghc bug on m68k.
Described in detail in Trac #11395.

This makes simple tests work on m68k-linux target!

Thanks to Michael Karcher for awesome analysis
happening in Trac #11395.

Signed-off-by: Sergei Trofimovich <siarheit@google.com>
Test Plan: ran "hello world" on m68k successfully

Reviewers: simonmar, austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

GHC Trac Issues: #11395

3 years agoReduce fragmentation from m32_allocator
Bartosz Nitka [Sun, 6 Mar 2016 21:18:12 +0000 (13:18 -0800)] 
Reduce fragmentation from m32_allocator

This patch brings in two improvements:
a) m32_allocator will now reuse the pages that are no longer
used by anyone else.
b) m32_allocator will preallocate the "filling" area,
so that the pages it allocates end up as a big chunk
instead of being allocated on demand in random places,
fragmenting the precious lower 2G address space.

Test Plan: testsuite - 3 tests failing with substTy asserts

Reviewers: ezyang, austin, bgamari, erikd, hsyl20, simonmar

Reviewed By: hsyl20, simonmar

Subscribers: hvr, thomie

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

3 years agoRevert "Mark tests for #11643, #11644, #11645 and #9406 expect_broken"
Ben Gamari [Mon, 7 Mar 2016 13:49:38 +0000 (14:49 +0100)] 
Revert "Mark tests for #11643, #11644, #11645 and #9406 expect_broken"

This reverts commit 90fa8cf2bf1677545c3f4a8bc967b1674822e90a.

As noted in #11643, these should be fixed.

Updates hpc submodule.

3 years agoGhcMake: Clang/ASSERT fix
Erik de Castro Lopo [Mon, 7 Mar 2016 13:32:07 +0000 (14:32 +0100)] 
GhcMake: Clang/ASSERT fix

Test Plan: Build with clang

Reviewers: thomie, rwbarton, austin, bgamari

Reviewed By: bgamari

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

3 years agoFix minimum alignment for StgClosure (Trac #11395)
Sergei Trofimovich [Sun, 6 Mar 2016 09:55:12 +0000 (09:55 +0000)] 
Fix minimum alignment for StgClosure (Trac #11395)

The bug is observed on m68k-linux target as crash
in RTS:

    -- a.hs:
    main = print 43

    $ inplace/bin/ghc-stage1 --make -debug a.hs

    $ ./a
    Program terminated with signal SIGSEGV, Segmentation fault.
    #0  0x80463b0a in LOOKS_LIKE_INFO_PTR_NOT_NULL (p=32858)
        at includes/rts/storage/ClosureMacros.h:248
    (gdb) bt
    #0  0x80463b0a in LOOKS_LIKE_INFO_PTR_NOT_NULL (p=32858)
        at includes/rts/storage/ClosureMacros.h:248
    #1  0x80463b46 in LOOKS_LIKE_INFO_PTR (p=32858)
        at includes/rts/storage/ClosureMacros.h:253
    #2  0x80463b6c in LOOKS_LIKE_CLOSURE_PTR (
            p=0x805aac6e <stg_dummy_ret_closure>)
        at includes/rts/storage/ClosureMacros.h:258
    #3  0x80463e4c in initStorage ()
        at rts/sm/Storage.c:121
    #4  0x8043ffb4 in hs_init_ghc (...)
        at rts/RtsStartup.c:181
    #5  0x80455982 in hs_main (...)
        at rts/RtsMain.c:51
    #6  0x80003c1c in main ()

GHC assumes last 2 pointer bits are tags on 32-bit targets.
But here 'stg_dummy_ret_closure' address violates the assumption:

    LOOKS_LIKE_CLOSURE_PTR (p=0x805aac6e <stg_dummy_ret_closure>)

I've added compiler hint for static StgClosure objects to
align closures at least by their natural alignment (what GHC assumes).
See Note [StgWord alignment].

Signed-off-by: Sergei Trofimovich <siarheit@google.com>
Test Plan: ran basic test on m68k qemu, it got past ASSERTs

Reviewers: simonmar, austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

GHC Trac Issues: #11395

3 years agoDrop module qualifier from punned record fields (#11662)
Adam Gundry [Sat, 5 Mar 2016 19:02:32 +0000 (20:02 +0100)] 
Drop module qualifier from punned record fields (#11662)

A record pattern match, construction or update like
`Rec { Mod.f }` should expand to `Rec { Mod.f = f }` rather
than `Rec { Mod.f = Mod.f }`.

Test Plan: New test rename/should_compile/T11662

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: hesselink, thomie

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

GHC Trac Issues: #11662

3 years agoUsing unsafe foreign import for rtsSupportsBoundThreads (part of #9696)
Marcin Mrotek [Sat, 5 Mar 2016 19:02:18 +0000 (20:02 +0100)] 
Using unsafe foreign import for rtsSupportsBoundThreads (part of #9696)

A safe import is unnecessary considering rtsSupportsBoundThreads simply
returns a constant.

This commit doesn't fix the main issue of ticket #9696 that
"readRawBufferPtr and writeRawBufferPtr allocate memory".

Reviewers: bgamari, austin, hvr

Reviewed By: hvr

Subscribers: thomie

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

GHC Trac Issues: #9696

3 years agoFix printing of an `IfacePatSyn`
Rik Steenkamp [Sat, 5 Mar 2016 19:01:06 +0000 (20:01 +0100)] 
Fix printing of an `IfacePatSyn`

Now the existentially quantified type variables are printed
at the correct location when printing a pattern synonym type
from an `IfacePatSyn`. The function `pprIfaceContextMaybe`
has been removed as it is no longer needed.

Fixes #11524.

Reviewers: austin, goldfire, thomie, bgamari, mpickering

Reviewed By: bgamari

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

GHC Trac Issues: #11524

3 years agoGHCi: Fix load/reload space leaks (#4029)
Jason Eisenberg [Sat, 5 Mar 2016 19:00:38 +0000 (20:00 +0100)] 
GHCi: Fix load/reload space leaks (#4029)

This patch addresses GHCi load/reload space leaks which could be
fixed without adversely affecting performance.

Test Plan: make test "TEST=T4029"

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: mpickering, thomie

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

GHC Trac Issues: #4029

3 years agorts/timer: use timerfd_* on Linux instead of alarm signals
Sylvain HENRY [Sat, 5 Mar 2016 19:00:06 +0000 (20:00 +0100)] 
rts/timer: use timerfd_* on Linux instead of alarm signals

Reviewers: erikd, simonmar, austin, bgamari

Reviewed By: simonmar, bgamari

Subscribers: hvr, thomie

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

GHC Trac Issues: #10840

3 years agousers-guide: Mention #11558 in release notes
Ben Gamari [Sat, 5 Mar 2016 15:26:33 +0000 (16:26 +0100)] 
users-guide: Mention #11558 in release notes

3 years agoSimplEnv: Add Haddock headings to export list
Ben Gamari [Fri, 4 Mar 2016 22:15:34 +0000 (23:15 +0100)] 
SimplEnv: Add Haddock headings to export list

3 years agoAdd Monoid instance for FastString
Ben Gamari [Fri, 4 Mar 2016 21:48:50 +0000 (22:48 +0100)] 
Add Monoid instance for FastString

3 years agoUse tyConArity rather than (length tvs)
Simon Peyton Jones [Wed, 2 Mar 2016 15:22:46 +0000 (15:22 +0000)] 
Use tyConArity rather than (length tvs)

A bit more efficient

3 years agoFix an outright bug in expandTypeSynonyms
Simon Peyton Jones [Wed, 2 Mar 2016 15:12:12 +0000 (15:12 +0000)] 
Fix an outright bug in expandTypeSynonyms

The bug was in this code:

    go subst (TyConApp tc tys)
      | Just (tenv, rhs, tys') <- expandSynTyCon_maybe tc tys
      = let subst' = unionTCvSubst subst (mkTvSubstPrs tenv) in
        go subst' (mkAppTys rhs tys')

This is wrong in two ways.
 * It is wrong to apply the expanded substitution to tys',
 * The unionTCvSubst is utterly wrong; after all, rhs is
   completely separate, and the union makes a non-idempotent
   substitution.

It was the non-idempotency that gave the Lint failure in Trac #11665,
when there was a type synonym whose RHS mentioned another type synonym,
something like

  type T a b = a -> b
  type S x y = T y x

It only affects SpecConstr because that's about the only place where
expandTypeSyonym is called.  I tried to trigger the failure with a
simple test case, but failed, so I have not added a regression test.

Fortunately the solution is very simple and solid.

FWIW, the culprit was 674654, "Add kind equalities to GHC".