ghc.git
15 months agoBump perf test targets wip/tdammers/D4568
Tobias Dammers [Mon, 9 Apr 2018 16:08:15 +0000 (18:08 +0200)] 
Bump perf test targets

Collateral to #14737: a handful of tests perform somewhat worse with
this patch.

15 months agoFix unintended Haddock
Tobias Dammers [Thu, 5 Apr 2018 12:25:03 +0000 (14:25 +0200)] 
Fix unintended Haddock

15 months agoRemove unnecessary check in simplCast
Tobias Dammers [Tue, 3 Apr 2018 11:49:40 +0000 (13:49 +0200)] 
Remove unnecessary check in simplCast

The coercion optimizer will take care of it anyway, and the check is
prohibitively expensive.

See Trac #14737.

15 months agoClean up & document isReflexiveCo.
Tobias Dammers [Sat, 31 Mar 2018 16:25:15 +0000 (18:25 +0200)] 
Clean up & document isReflexiveCo.

15 months agoImprove isReflexiveCo performance
Tobias Dammers [Thu, 29 Mar 2018 08:45:54 +0000 (10:45 +0200)] 
Improve isReflexiveCo performance

15 months agoFix huge performance regression
Tobias Dammers [Mon, 26 Mar 2018 11:44:56 +0000 (13:44 +0200)] 
Fix huge performance regression

Previous version caused a 10x increase in execution time for the
infamous Grammar.hs test case from #14683; this patch gets us back on
par.

15 months agoDiscard reflexive casts during Simplify
Richard Eisenberg [Sat, 27 Jan 2018 03:42:46 +0000 (22:42 -0500)] 
Discard reflexive casts during Simplify

Previously, we went to great lengths to build just the right
reflexive casts, only to discard them shortly later. Now, just
skip creating reflexive casts altogether.

15 months agorts: Fix profiled build after D4529
Ben Gamari [Mon, 26 Mar 2018 20:34:06 +0000 (16:34 -0400)] 
rts: Fix profiled build after D4529

15 months agotestsuite: Add test for #14965
Ben Gamari [Mon, 26 Mar 2018 19:41:39 +0000 (15:41 -0400)] 
testsuite: Add test for #14965

15 months agoCmmPipeline: add a second pass of CmmCommonBlockElim
Michal Terepeta [Mon, 26 Mar 2018 19:18:44 +0000 (15:18 -0400)] 
CmmPipeline: add a second pass of CmmCommonBlockElim

The sinking pass often gets rid of unnecessary registers
registers/assignements exposing more opportunities for CBE, so this
commit adds a second round of CBE after the sinking pass and should
fix #12915 (and some examples in #14226).

Nofib results:
* Binary size:         0.9% reduction on average
* Compile allocations: 0.7% increase on average
* Runtime:             noisy, two separate runs of nofib showed a tiny
                       reduction on average, (~0.2-0.3%), but I think
                       this is mostly noise
* Compile time:        very noisy, but generally within +/- 0.5% (one
                       run faster, one slower)

One interesting part of this change is that running CBE invalidates
results of proc-point analysis. But instead of re-doing the whole
analysis, we can use the map that CBE creates for replacing/comparing
block labels (maps a redundant label to a useful one) to update the
results of proc-point analysis. This lowers the overhead compared to the
previous experiment in #12915.

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

Reviewers: bgamari, simonmar

Reviewed By: simonmar

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #12915, #14226

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

15 months agoconfigure: Throw error if OS is found to be msys
Ben Gamari [Mon, 26 Mar 2018 19:18:00 +0000 (15:18 -0400)] 
configure: Throw error if OS is found to be msys

Test Plan: Try running configure on Windows with msys and mingw
toolchains

Reviewers: Phyx, hvr

Reviewed By: Phyx

Subscribers: rwbarton, thomie, erikd, carter

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

15 months agoFix the test for #13938
Ryan Scott [Tue, 27 Mar 2018 12:52:15 +0000 (08:52 -0400)] 
Fix the test for #13938

Only half of the test files were checked in for T13938.
This commit adds the missing half.

15 months agoDeal with join points with RULES
Simon Peyton Jones [Mon, 26 Mar 2018 16:16:14 +0000 (17:16 +0100)] 
Deal with join points with RULES

Trac #13900 showed that when we have a join point that
has a RULE, we must push the continuation into the RHS
of the RULE.

See Note [Rules and unfolding for join points]

It's hard to tickle this bug, so I have not added a regression test.

15 months agoWhite space only
Simon Peyton Jones [Mon, 26 Mar 2018 15:09:45 +0000 (16:09 +0100)] 
White space only

15 months agoMinor refactor and commments
Simon Peyton Jones [Mon, 26 Mar 2018 15:07:06 +0000 (16:07 +0100)] 
Minor refactor and commments

Minor refactor and comments, following Ryan's excellent DeriveAnyClass
bug (Trac #14932)

15 months agoAvoid quadratic complexity in typeKind
Simon Peyton Jones [Mon, 26 Mar 2018 14:54:53 +0000 (15:54 +0100)] 
Avoid quadratic complexity in typeKind

I took 10 minute to fix this potential performance hole
(Trac #14263)

There are no actual bug reports against it, so no regression
test.

15 months agoComments only
Simon Peyton Jones [Mon, 26 Mar 2018 10:26:42 +0000 (11:26 +0100)] 
Comments only

15 months agoFix performance of flattener patch (#12919)
Alexander Vieth [Mon, 26 Mar 2018 15:19:27 +0000 (11:19 -0400)] 
Fix performance of flattener patch (#12919)

This patch, authored by alexvieth and reviewed at D4451,
makes performance improvements by critically optimizing parts
of the flattener.

Summary:
T3064, T5321FD, T5321Fun, T9872a, T9872b, T9872c all pass.
T9872a and T9872c show improvements beyond the -5% threshold.
T9872d fails at 10.9% increased allocations.

15 months agoFix #12919 by making the flattener homegeneous.
Richard Eisenberg [Thu, 3 Aug 2017 19:18:39 +0000 (15:18 -0400)] 
Fix #12919 by making the flattener homegeneous.

This changes a key invariant of the flattener. Previously,
flattening a type meant flattening its kind as well. But now,
flattening is always homogeneous -- that is, the kind of the
flattened type is the same as the kind of the input type.
This is achieved by various wizardry in the TcFlatten.flatten_many
function, as described in Note [flatten_many].

There are several knock-on effects, including some refactoring
in the canonicalizer to take proper advantage of the flattener's
changed behavior. In particular, the tyvar case of can_eq_nc' no
longer needs to take casts into account.

Another effect is that flattening a tyconapp might change it
into a casted tyconapp. This might happen if the result kind
of the tycon contains a variable, and that variable changes
during flattening. Because the flattener is homogeneous, it tacks
on a cast to keep the tyconapp kind the same. However, this
is problematic when flattening CFunEqCans, which need to have
an uncasted tyconapp on the LHS and must remain homogeneous.
The solution is a more involved canCFunEqCan, described in
Note [canCFunEqCan].

This patch fixes #13643 (as tested in typecheck/should_compile/T13643)
and the panic in typecheck/should_compile/T13822 (as reported in #14024).
Actually, there were two bugs in T13822: the first was just some
incorrect logic in tryFill (part of the unflattener) -- also fixed
in this patch -- and the other was the main bug fixed in this ticket.

The changes in this patch exposed a long-standing flaw in OptCoercion,
in that breaking apart an AppCo sometimes has unexpected effects on
kinds. See new Note [EtaAppCo] in OptCoercion, which explains the
problem and fix.

Also here is a reversion of the major change in
09bf135ace55ce2572bf4168124d631e386c64bb, affecting ctEvCoercion.
It turns out that making the flattener homogeneous changes the
invariants on the algorithm, making the change in that patch
no longer necessary.

This patch also fixes:
  #14038 (dependent/should_compile/T14038)
  #13910 (dependent/should_compile/T13910)
  #13938 (dependent/should_compile/T13938)
  #14441 (typecheck/should_compile/T14441)
  #14556 (dependent/should_compile/T14556)
  #14720 (dependent/should_compile/T14720)
  #14749 (typecheck/should_compile/T14749)

Sadly, this patch negatively affects performance of type-family-
heavy code. The following patch fixes these performance degradations.
However, the performance fixes are somewhat invasive and so I've
kept them as a separate patch, labeling this one as [skip ci] so
that validation doesn't fail on the performance cases.

15 months agoFix compilation stopper on macOS with -Werror
Richard Eisenberg [Mon, 26 Mar 2018 16:45:59 +0000 (12:45 -0400)] 
Fix compilation stopper on macOS with -Werror

Commit 94f02547083cf6df686ea0b95fed050184c533de
added some pragmas that allow GCC to compile GHC, but stop
macOS's clang. This adds another counter-pragma to halp
clang lumber along, too.

Fixes #14977.

15 months agoMake it evident in types that StgLam can't have empty args
Ömer Sinan Ağacan [Mon, 26 Mar 2018 20:15:32 +0000 (23:15 +0300)] 
Make it evident in types that StgLam can't have empty args

StgLam can't have empty arguments. Reflect this in types. An assertion
can now be deleted.

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

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

15 months agorts, base: Refactor stats.c to improve --machine-readable report
Douglas Wilson [Mon, 26 Mar 2018 19:16:11 +0000 (15:16 -0400)] 
rts, base: Refactor stats.c to improve --machine-readable report

There should be no change in the output of the '+RTS -s' (summary)
report, or
the 'RTS -t' (one-line) report.

All data shown in the summary report is now shown in the machine
readable
report.

All data in RTSStats is now shown in the machine readable report.

init times are added to RTSStats and added to GHC.Stats.

Example of the new output:
```
 [("bytes allocated", "375016384")
 ,("num_GCs", "113")
 ,("average_bytes_used", "148348")
 ,("max_bytes_used", "206552")
 ,("num_byte_usage_samples", "2")
 ,("peak_megabytes_allocated", "6")
 ,("init_cpu_seconds", "0.001642")
 ,("init_wall_seconds", "0.001027")
 ,("mut_cpu_seconds", "3.020166")
 ,("mut_wall_seconds", "0.757244")
 ,("GC_cpu_seconds", "0.037750")
 ,("GC_wall_seconds", "0.009569")
 ,("exit_cpu_seconds", "0.000890")
 ,("exit_wall_seconds", "0.002551")
 ,("total_cpu_seconds", "3.060452")
 ,("total_wall_seconds", "0.770395")
 ,("major_gcs", "2")
 ,("allocated_bytes", "375016384")
 ,("max_live_bytes", "206552")
 ,("max_large_objects_bytes", "159344")
 ,("max_compact_bytes", "0")
 ,("max_slop_bytes", "59688")
 ,("max_mem_in_use_bytes", "6291456")
 ,("cumulative_live_bytes", "296696")
 ,("copied_bytes", "541024")
 ,("par_copied_bytes", "493976")
 ,("cumulative_par_max_copied_bytes", "104104")
 ,("cumulative_par_balanced_copied_bytes", "274456")
 ,("fragmentation_bytes", "2112")
 ,("alloc_rate", "124170795")
 ,("productivity_cpu_percent", "0.986838")
 ,("productivity_wall_percent", "0.982935")
 ,("bound_task_count", "1")
 ,("sparks_count", "5836258")
 ,("sparks_converted", "237")
 ,("sparks_overflowed", "1990408")
 ,("sparks_dud ", "0")
 ,("sparks_gcd", "3455553")
 ,("sparks_fizzled", "390060")
 ,("work_balance", "0.555606")
 ,("n_capabilities", "4")
 ,("task_count", "10")
 ,("peak_worker_count", "9")
 ,("worker_count", "9")
 ,("gc_alloc_block_sync_spin", "162")
 ,("gc_alloc_block_sync_yield", "0")
 ,("gc_alloc_block_sync_spin", "162")
 ,("gc_spin_spin", "18840855")
 ,("gc_spin_yield", "10355")
 ,("mut_spin_spin", "70331392")
 ,("mut_spin_yield", "61700")
 ,("waitForGcThreads_spin", "241")
 ,("waitForGcThreads_yield", "2797")
 ,("whitehole_gc_spin", "0")
 ,("whitehole_lockClosure_spin", "0")
 ,("whitehole_lockClosure_yield", "0")
 ,("whitehole_executeMessage_spin", "0")
 ,("whitehole_threadPaused_spin", "0")
 ,("any_work", "1667")
 ,("no_work", "1662")
 ,("scav_find_work", "1026")
 ,("gen_0_collections", "111")
 ,("gen_0_par_collections", "111")
 ,("gen_0_cpu_seconds", "0.036126")
 ,("gen_0_wall_seconds", "0.036126")
 ,("gen_0_max_pause_seconds", "0.036126")
 ,("gen_0_avg_pause_seconds", "0.000081")
 ,("gen_0_sync_spin", "21")
 ,("gen_0_sync_yield", "0")
 ,("gen_1_collections", "2")
 ,("gen_1_par_collections", "1")
 ,("gen_1_cpu_seconds", "0.001624")
 ,("gen_1_wall_seconds", "0.001624")
 ,("gen_1_max_pause_seconds", "0.001624")
 ,("gen_1_avg_pause_seconds", "0.000272")
 ,("gen_1_sync_spin", "3")
 ,("gen_1_sync_yield", "0")
 ]
```

Test Plan: Ensure that one-line and summary reports are unchanged.

Reviewers: erikd, simonmar, hvr

Subscribers: duog, carter, thomie, rwbarton

GHC Trac Issues: #14660

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

15 months agocircleci: Bump Hackage index state
Ben Gamari [Mon, 26 Mar 2018 06:45:53 +0000 (02:45 -0400)] 
circleci: Bump Hackage index state

15 months agoAdd a job running on Fedora
mrkkrp [Wed, 21 Mar 2018 15:11:04 +0000 (22:11 +0700)] 
Add a job running on Fedora

15 months agoAdd unaligned bytearray access primops. Fixes #4442.
Reiner Pope [Mon, 26 Mar 2018 03:16:03 +0000 (23:16 -0400)] 
Add unaligned bytearray access primops. Fixes #4442.

Reviewers: bgamari, simonmar

Reviewed By: bgamari

Subscribers: dfeuer, rwbarton, thomie, carter

GHC Trac Issues: #4442

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

15 months agoAdd new debugging flag -dinline-check
Ben Gamari [Mon, 26 Mar 2018 02:17:24 +0000 (22:17 -0400)] 
Add new debugging flag -dinline-check

This flag reports a summary of the inlining decision for identifiers
prefixed by the flag's argument.

For example, `-dinline-check foo` will report why definitions whose
prefix is `foo` are inlined or not.

Previously the only way to get this information was to pass a
combination of `-dverbose-core2core` and `-ddump-inlinings`.

This combination led to a log of 12 million lines in a module of about
200 lines I recently had to apply it to. This flag provides a much more
direct way to find the occurence you care about.

Reviewers: osa1, dfeuer, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

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

15 months agobase: Fix Unicode handling of TyCon's Show instance
Ben Gamari [Mon, 26 Mar 2018 02:12:49 +0000 (22:12 -0400)] 
base: Fix Unicode handling of TyCon's Show instance

Test Plan: `make test TEST=T14925`

Reviewers: hvr, dfeuer

Reviewed By: dfeuer

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14925

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

15 months agollvmGen: Pass -optlo flags last to opt
Oleg Grenrus [Mon, 26 Mar 2018 00:13:18 +0000 (20:13 -0400)] 
llvmGen: Pass -optlo flags last to opt

LLVM, like GHC, processes flags in the order that they appear.
Consequently, we need to ensure the user-provided flags appear last so
they can override flags produced by GHC. See #14821.

Test Plan: `ghc -O2 -optlo-O2 -v3 $FILE` and ensure that `opt` and `llc`
are invoked with `-O2`.

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14821

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

15 months agoFix scoped type variables in TH for several constructs
HE, Tao [Sun, 25 Mar 2018 19:34:45 +0000 (15:34 -0400)] 
Fix scoped type variables in TH for several constructs

Namely class methods, default signatures and pattern synonyms.

When scoped type variables occur inside class default methods,
default signatures and pattern synonyms, avoid re-create explicit
type variables when represent the type signatures.

This patch should fix Trac#14885.

Signed-off-by: HE, Tao <sighingnow@gmail.com>
Test Plan: make test TEST="T14885a T14885b T14885c"

Reviewers: goldfire, bgamari, simonpj, RyanGlScott

Reviewed By: simonpj, RyanGlScott

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14885

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

15 months agoDon't refer to blocks in debug info when -g1
Bartosz Nitka [Sun, 25 Mar 2018 19:34:27 +0000 (15:34 -0400)] 
Don't refer to blocks in debug info when -g1

-g1 removes block information, but it turns out that procs can
refer to block information through parents.
Note [Splitting DebugBlocks] explains the parentage relationship.

Test Plan:
* ./validate
* added a new test

Reviewers: bgamari, simonmar

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14894

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

15 months agoFix #14916 with an additional validity check in deriveTyData
Ryan Scott [Sun, 25 Mar 2018 19:34:05 +0000 (15:34 -0400)] 
Fix #14916 with an additional validity check in deriveTyData

Manually-written instances and standalone-derived instances
have the benefit of having the `checkValidInstHead` function run over
them, which catches manual instances of built-in types like `(~)` and
`Coercible`. However, instances generated from `deriving` clauses
weren't being passed through `checkValidInstHead`, leading to
confusing results as in #14916.

`checkValidInstHead` also has additional validity checks for language
extensions like `FlexibleInstances` and `MultiParamTypeClasses`. Up
until now, GHC has never required these language extensions for
`deriving` clause, so to avoid unnecessary breakage, I opted to
suppress these language extension checks for `deriving` clauses, just
like we currently suppress them for `SPECIALIZE instance` pragmas.

Test Plan: make test TEST=T14916

Reviewers: goldfire, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14916

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

15 months agotestsuite: Add test for #14925
Ben Gamari [Sun, 25 Mar 2018 19:33:48 +0000 (15:33 -0400)] 
testsuite: Add test for #14925

Test Plan: Validate

Reviewers: alpmestan

Reviewed By: alpmestan

Subscribers: alpmestan, leftaroundabout, rwbarton, thomie, carter

GHC Trac Issues: #14925

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

15 months agorts/RetainerProfile: Dump closure type if push() fails
Ryan Scott [Sun, 25 Mar 2018 19:33:37 +0000 (15:33 -0400)] 
rts/RetainerProfile: Dump closure type if push() fails

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

Reviewers: bgamari, erikd, simonmar

Reviewed By: bgamari

Subscribers: alexbiehl, rwbarton, thomie, carter

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

15 months agodocument: fix trac issue #14229
Võ Anh Duy [Sun, 25 Mar 2018 18:06:11 +0000 (14:06 -0400)] 
document: fix trac issue #14229

Accroding to
https://git.haskell.org/ghc.git/commitdiff/49672659113371c3bee691e6d913d
f8e6f60a1d8,
`-Wredundant-constraints` is no longer turn on by default.

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

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

15 months agoFix panic on module re-exports of DuplicateRcordFields
Adam Gundry [Sun, 25 Mar 2018 18:05:55 +0000 (14:05 -0400)] 
Fix panic on module re-exports of DuplicateRcordFields

Test Plan: new test overloadedrecflds/should_fail/T14953

Reviewers: mpickering, simonpj, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14953

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

15 months agoRun C finalizers incrementally during mutation
Simon Marlow [Sun, 25 Mar 2018 18:04:02 +0000 (14:04 -0400)] 
Run C finalizers incrementally during mutation

With a large heap it's possible to build up a lot of finalizers
between GCs.  We've observed GC spending up to 50% of its time running
finalizers.  But there's no reason we have to run finalizers during
GC, and especially no reason we have to block *all* the mutator
threads while *one* GC thread runs finalizers one by one.

I thought about a bunch of alternative ways to handle this, which are
documented along with runSomeFinalizers() in Weak.c.  The approach I
settled on is to have a capability run finalizers if it is idle.  So
running finalizers is like a low-priority background thread. This
requires some minor scheduler changes, but not much.  In the future we
might be able to move more GC work into here (I have my eye on freeing
large blocks, for example).

Test Plan:
* validate
* tested on our system and saw reductions in GC pauses of 40-50%.

Reviewers: bgamari, niteria, osa1, erikd

Reviewed By: bgamari, osa1

Subscribers: rwbarton, thomie, carter

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

15 months agoAdd Note [BLACKHOLE points to IND]
Simon Marlow [Sun, 25 Mar 2018 18:02:16 +0000 (14:02 -0400)] 
Add Note [BLACKHOLE points to IND]

Test Plan: ci

Reviewers: osa1, bgamari, erikd

Reviewed By: osa1

Subscribers: rwbarton, thomie, carter

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

15 months agoFix two pernicious bugs in DeriveAnyClass
Ryan Scott [Sun, 25 Mar 2018 18:00:39 +0000 (14:00 -0400)] 
Fix two pernicious bugs in DeriveAnyClass

The way GHC was handling `DeriveAnyClass` was subtly wrong
in two notable ways:

* In `inferConstraintsDAC`, we were //always// bumping the `TcLevel`
  of newly created unification variables, under the assumption that
  we would always place those unification variables inside an
  implication constraint. But #14932 showed precisely the scenario
  where we had `DeriveAnyClass` //without// any of the generated
  constraints being used inside an implication, which made GHC
  incorrectly believe the unification variables were untouchable.
* Even worse, we were using the generated unification variables from
  `inferConstraintsDAC` in every single iteration of `simplifyDeriv`.
  In #14933, however, we have a scenario where we fill in a
  unification variable with a skolem in one iteration, discard it,
  proceed on to another iteration, use the same unification variable
  (still filled in with the old skolem), and try to unify it with
  a //new// skolem! This results in an utter disaster.

The root of both these problems is `inferConstraintsDAC`. This patch
fixes the issue by no longer generating unification variables
directly in `inferConstraintsDAC`. Instead, we store the original
variables from a generic default type signature in `to_metas`, a new
field of `ThetaOrigin`, and in each iteration of `simplifyDeriv`, we
generate fresh meta tyvars (avoiding the second issue). Moreover,
this allows us to more carefully fine-tune the `TcLevel` under which
we create these meta tyvars, fixing the first issue.

Test Plan: make test TEST="T14932 T14933"

Reviewers: simonpj, bgamari

Reviewed By: simonpj

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14932, #14933

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

15 months agoSupport iOS variants elsewhere when configuring
John Ericson [Sun, 25 Mar 2018 18:00:26 +0000 (14:00 -0400)] 
Support iOS variants elsewhere when configuring

Reviewers: hvr, bgamari, angerman

Reviewed By: angerman

Subscribers: rwbarton, thomie, erikd, carter, angerman

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

15 months agotestsuite: Add test for #14931
Ben Gamari [Sun, 25 Mar 2018 18:00:12 +0000 (14:00 -0400)] 
testsuite: Add test for #14931

Reviewers: alpmestan

Reviewed By: alpmestan

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14931

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

15 months agoSupport adding objects from TH
Alec Theriault [Sun, 25 Mar 2018 17:59:27 +0000 (13:59 -0400)] 
Support adding objects from TH

The user facing TH interface changes are:

  * 'addForeignFile' is renamed to 'addForeignSource'
  * 'qAddForeignFile'/'addForeignFile' now expect 'FilePath's
  * 'RawObject' is now a constructor for 'ForeignSrcLang'
  * 'qAddTempFile'/'addTempFile' let you request a temporary file
    from the compiler.

Test Plan: unsure about this, added a TH test

Reviewers: goldfire, bgamari, angerman

Reviewed By: bgamari, angerman

Subscribers: hsyl20, mboes, carter, simonmar, bitonic, ljli, rwbarton, thomie

GHC Trac Issues: #14298

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

15 months agoAllow PartialTypeSignatures in standalone deriving contexts
Ryan Scott [Fri, 23 Mar 2018 16:06:04 +0000 (12:06 -0400)] 
Allow PartialTypeSignatures in standalone deriving contexts

Summary:
At its core, this patch is a simple tweak that allows a user
to write:

```lang=haskell
deriving instance _ => Eq (Foo a)
```

Which is functionally equivalent to:

```lang=haskell
data Foo a = ...
  deriving Eq
```

But with the added flexibility that `StandaloneDeriving` gives you
(namely, the ability to use it anywhere, not just in the same module
that `Foo` was declared in). This fixes #13324, and should hopefully
address a use case brought up in #10607.

Currently, only the use of a single, extra-constraints wildcard is
permitted in a standalone deriving declaration. Any other wildcard
is rejected, so things like
`deriving instance (Eq a, _) => Eq (Foo a)` are currently forbidden.

There are quite a few knock-on changes brought on by this change:

* The `HsSyn` type used to represent standalone-derived instances
  was previously `LHsSigType`, which isn't sufficient to hold
  wildcard types. This needed to be changed to `LHsSigWcType` as a
  result.

* Previously, `DerivContext` was a simple type synonym for
  `Maybe ThetaType`, under the assumption that you'd only ever be in
  the `Nothing` case if you were in a `deriving` clause. After this
  patch, that assumption no longer holds true, as you can also be
  in this situation with standalone deriving when an
  extra-constraints wildcard is used.

  As a result, I changed `DerivContext` to be a proper datatype that
  reflects the new wrinkle that this patch adds, and plumbed this
  through the relevant parts of `TcDeriv` and friends.

* Relatedly, the error-reporting machinery in `TcErrors` also assumed
  that if you have any unsolved constraints in a derived instance,
  then you should be able to fix it by switching over to standalone
  deriving. This was always sound advice before, but with this new
  feature, it's possible to have unsolved constraints even when
  you're standalone-deriving something!

  To rectify this, I tweaked some constructors of `CtOrigin` a bit
  to reflect this new subtlety.

This requires updating the Haddock submodule. See my fork at
https://github.com/RyanGlScott/haddock/commit/067d52fd4be15a1842cbb05f42d9d482de0ad3a7

Test Plan: ./validate

Reviewers: simonpj, goldfire, bgamari

Reviewed By: simonpj

Subscribers: goldfire, rwbarton, thomie, mpickering, carter

GHC Trac Issues: #13324

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

15 months agoSpecial-case record fields ending with hash when deriving Read
Ryan Scott [Fri, 23 Mar 2018 15:40:02 +0000 (11:40 -0400)] 
Special-case record fields ending with hash when deriving Read

Summary:
In commit dbd81f7e86514498218572b9d978373b1699cc5b, a
regression was inadvertently introduced which caused derived `Read`
instances for record data types with fields ending in a `#` symbol
(using `MagicHash`) would no longer parse on valid output. This
is ultimately due to the same reasons as #5041, as we cannot parse
a field name like `foo#` as a single identifier. We fix this issue
by employing the same workaround as in #5041: first parse the
identifier name `foo`, then then symbol `#`.

This is accomplished by the new `readFieldHash` function in
`GHC.Read`. This will likely warrant a `base-4.11.1.0` release.

Test Plan: make test TEST=T14918

Reviewers: tdammers, hvr, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14918

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

15 months agoImprove shortOutIndirections slightly
Simon Peyton Jones [Thu, 22 Mar 2018 14:31:45 +0000 (14:31 +0000)] 
Improve shortOutIndirections slightly

I found (when investigating Trac #14955) a binding looking like

   Rec { exported_id = ....big...lcl_id...
       ; lcl_id = exported_id }

but bizarrely 'lcl_id' was chosen as the loop breaker, and never
inlined.  It turned out to be an unintended consequence of the
shortOutIndirections code in SimplCore.  Easily fixed.

15 months agoFix over-eager constant folding in bitInteger
Simon Peyton Jones [Thu, 22 Mar 2018 09:51:24 +0000 (09:51 +0000)] 
Fix over-eager constant folding in bitInteger

The RULE for bitInteger was trying to constant-fold

    bitInteger 9223372036854775807#

which meant constructing a gigantic Integer at compile
time.  Very bad idea!  Easily fixed.

Fixes Trac #14959, #14962.

15 months agoFix two obscure bugs in rule matching
Simon Peyton Jones [Wed, 21 Mar 2018 17:25:23 +0000 (17:25 +0000)] 
Fix two obscure bugs in rule matching

This patch fixes Trac #14777, a compiler crash.

There were actually two bugs.

1. In Rules.matchN, I was (consciously) not rename the template binders
   of the rule. Sadly, in rare cases an accidental coincidence of
   uniques could mean that a term variable was mapped to a type
   variable, utterly bogusly.  See "Historical note" in
   Note [Cloning the template binders] in Rules.

   This was hard to find, but easy to fix.

2. The fix to (1) showed up a bug in Unify.hs.  The test in
   Unify.tvBindFlag was previously using the domain of the RnEnv2
   to detect locally-bound variables (e.g. when unifying under
   a forall).  That's fine when teh RnEnv2 starts empty, as it
   does in most entry points.  But the tcMatchTyKisX entry point,
   used from the rule matcher, passes in a non-empty RnEnv2 (by
   design).  Now the domain of the RnEnv doesn't idenfity those
   locally-bound variables any more :-(.

   Solution: extend UmEnv with a new field um_skols, to capture
   the skolems directly.  Simple, easy, works.

15 months agoAllow as-patterns in unidirectional patttern synonyms
Simon Peyton Jones [Wed, 21 Mar 2018 17:21:15 +0000 (17:21 +0000)] 
Allow as-patterns in unidirectional patttern synonyms

This patch implements GHC Proposal #94, described here
   https://github.com/ghc-proposals/ghc-proposals/pull/94

The effect is simply to lift a totally-undocumented restriction to
unidirecional pattern synonyms, namely that they can't have as-patterns
or n+k patterns.

The fix is easy: just remove the checks.

I also took the opportunity to improve the manual entry for
the semantics of pattern matching for pattern synonyms.

15 months agoFix #14869 by being more mindful of Type vs. Constraint
Ryan Scott [Wed, 21 Mar 2018 12:59:28 +0000 (08:59 -0400)] 
Fix #14869 by being more mindful of Type vs. Constraint

Summary:
Before, we were using `isLiftedTypeKind` in `reifyType`
before checking if a type was `Constraint`. But as it turns out,
`isLiftedTypeKind` treats `Constraint` the same as `Type`, so every
occurrence of `Constraint` would be reified as `Type`! To make things
worse, the documentation for `isLiftedTypeKind` stated that it
treats `Constraint` //differently// from `Type`, which simply isn't
true.

This revises the documentation for `isLiftedTypeKind` to reflect
reality, and defers the `isLiftedTypeKind` check in `reifyType` so
that it does not accidentally swallow `Constraint`.

Test Plan: make test TEST=T14869

Reviewers: goldfire, bgamari

Reviewed By: goldfire

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14869

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

15 months agoFix seq# case of exprOkForSpeculation
Simon Peyton Jones [Tue, 20 Mar 2018 16:30:01 +0000 (16:30 +0000)] 
Fix seq# case of exprOkForSpeculation

This subtle patch fixes Trac #5129 (again; comment:20
and following).

I took the opportunity to document seq# properly; see
Note [seq# magic] in PrelRules, and Note [seq# and expr_ok]
in CoreUtils.

15 months agoRevert "rts, base: Refactor stats.c to improve --machine-readable report"
Ben Gamari [Tue, 20 Mar 2018 16:17:43 +0000 (12:17 -0400)] 
Revert "rts, base: Refactor stats.c to improve --machine-readable report"

This reverts commit 2d4bda2e4ac68816baba0afab00da6f769ea75a7.

15 months agoUpdate T5129 test:
Ömer Sinan Ağacan [Tue, 20 Mar 2018 07:48:14 +0000 (10:48 +0300)] 
Update T5129 test:

- Add some comments
- Remove $s as they complicate desugarer output for no reason
- Remove an indirection, case_negative is now main

16 months agoconfigure: Accept version suffix in solaris name
Ben Gamari [Mon, 19 Mar 2018 17:32:14 +0000 (13:32 -0400)] 
configure: Accept version suffix in solaris name

Summary: OpenIndiana apparently reports a triple of i386-pc-solaris2.11.

Reviewers: hvr

Subscribers: rwbarton, thomie, erikd, carter

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

16 months agorelnotes: Fix parsing of Version: field from Cabal file
Ben Gamari [Mon, 19 Mar 2018 17:31:46 +0000 (13:31 -0400)] 
relnotes: Fix parsing of Version: field from Cabal file

Subscribers: rwbarton, thomie, carter

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

16 months agoBump autoconf version bound to >= 2.69
Ben Gamari [Mon, 19 Mar 2018 17:31:31 +0000 (13:31 -0400)] 
Bump autoconf version bound to >= 2.69

Reviewers: hvr

Subscribers: rwbarton, thomie, erikd, carter

GHC Trac Issues: #14910

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

16 months agoAdd -flate-specialise which runs a later specialisation pass
Matthew Pickering [Mon, 19 Mar 2018 17:29:14 +0000 (13:29 -0400)] 
Add -flate-specialise which runs a later specialisation pass

Runs another specialisation pass towards the end of the optimisation
pipeline. This can catch specialisation opportunities which arose from
the previous specialisation pass or other inlining.

You might want to use this if you are you have a type class method
which returns a constrained type. For example, a type class where one
of the methods implements a traversal.

It is not enabled by default or any optimisation level. Only by
manually enabling the flag `-flate-specialise`.

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

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

16 months agorts, base: Refactor stats.c to improve --machine-readable report
Douglas Wilson [Mon, 19 Mar 2018 17:26:41 +0000 (13:26 -0400)] 
rts, base: Refactor stats.c to improve --machine-readable report

There should be no change in the output of the '+RTS -s' (summary)
report, or the 'RTS -t' (one-line) report.

All data shown in the summary report is now shown in the machine
readable report.

All data in RTSStats is now shown in the machine readable report.

init times are added to RTSStats and added to GHC.Stats.

Example of the new output:
```
 [("bytes allocated", "375016384")
 ,("num_GCs", "113")
 ,("average_bytes_used", "148348")
 ,("max_bytes_used", "206552")
 ,("num_byte_usage_samples", "2")
 ,("peak_megabytes_allocated", "6")
 ,("init_cpu_seconds", "0.001642")
 ,("init_wall_seconds", "0.001027")
 ,("mut_cpu_seconds", "3.020166")
 ,("mut_wall_seconds", "0.757244")
 ,("GC_cpu_seconds", "0.037750")
 ,("GC_wall_seconds", "0.009569")
 ,("exit_cpu_seconds", "0.000890")
 ,("exit_wall_seconds", "0.002551")
 ,("total_cpu_seconds", "3.060452")
 ,("total_wall_seconds", "0.770395")
 ,("major_gcs", "2")
 ,("allocated_bytes", "375016384")
 ,("max_live_bytes", "206552")
 ,("max_large_objects_bytes", "159344")
 ,("max_compact_bytes", "0")
 ,("max_slop_bytes", "59688")
 ,("max_mem_in_use_bytes", "6291456")
 ,("cumulative_live_bytes", "296696")
 ,("copied_bytes", "541024")
 ,("par_copied_bytes", "493976")
 ,("cumulative_par_max_copied_bytes", "104104")
 ,("cumulative_par_balanced_copied_bytes", "274456")
 ,("fragmentation_bytes", "2112")
 ,("alloc_rate", "124170795")
 ,("productivity_cpu_percent", "0.986838")
 ,("productivity_wall_percent", "0.982935")
 ,("bound_task_count", "1")
 ,("sparks_count", "5836258")
 ,("sparks_converted", "237")
 ,("sparks_overflowed", "1990408")
 ,("sparks_dud ", "0")
 ,("sparks_gcd", "3455553")
 ,("sparks_fizzled", "390060")
 ,("work_balance", "0.555606")
 ,("n_capabilities", "4")
 ,("task_count", "10")
 ,("peak_worker_count", "9")
 ,("worker_count", "9")
 ,("gc_alloc_block_sync_spin", "162")
 ,("gc_alloc_block_sync_yield", "0")
 ,("gc_alloc_block_sync_spin", "162")
 ,("gc_spin_spin", "18840855")
 ,("gc_spin_yield", "10355")
 ,("mut_spin_spin", "70331392")
 ,("mut_spin_yield", "61700")
 ,("waitForGcThreads_spin", "241")
 ,("waitForGcThreads_yield", "2797")
 ,("whitehole_gc_spin", "0")
 ,("whitehole_lockClosure_spin", "0")
 ,("whitehole_lockClosure_yield", "0")
 ,("whitehole_executeMessage_spin", "0")
 ,("whitehole_threadPaused_spin", "0")
 ,("any_work", "1667")
 ,("no_work", "1662")
 ,("scav_find_work", "1026")
 ,("gen_0_collections", "111")
 ,("gen_0_par_collections", "111")
 ,("gen_0_cpu_seconds", "0.036126")
 ,("gen_0_wall_seconds", "0.036126")
 ,("gen_0_max_pause_seconds", "0.036126")
 ,("gen_0_avg_pause_seconds", "0.000081")
 ,("gen_0_sync_spin", "21")
 ,("gen_0_sync_yield", "0")
 ,("gen_1_collections", "2")
 ,("gen_1_par_collections", "1")
 ,("gen_1_cpu_seconds", "0.001624")
 ,("gen_1_wall_seconds", "0.001624")
 ,("gen_1_max_pause_seconds", "0.001624")
 ,("gen_1_avg_pause_seconds", "0.000272")
 ,("gen_1_sync_spin", "3")
 ,("gen_1_sync_yield", "0")
 ]
```

Test Plan: Ensure that one-line and summary reports are unchanged.

Reviewers: bgamari, erikd, simonmar, hvr

Reviewed By: simonmar

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14660

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

16 months agogen-data-layout.sh: Use bash array for readability
John Ericson [Mon, 19 Mar 2018 17:24:46 +0000 (13:24 -0400)] 
gen-data-layout.sh: Use bash array for readability

Reviewers: angerman, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

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

16 months agoFix typo
Gabor Greif [Thu, 8 Mar 2018 11:13:08 +0000 (12:13 +0100)] 
Fix typo

16 months agoFix typo in user guide about ConstraintKinds
Frank Steffahn [Tue, 13 Mar 2018 22:29:04 +0000 (23:29 +0100)] 
Fix typo in user guide about ConstraintKinds

The backslash currently in this type signature makes no sense. Without it, the example is fine.

16 months agoBump array submodule
Ben Gamari [Mon, 19 Mar 2018 16:46:44 +0000 (12:46 -0400)] 
Bump array submodule

16 months agoUpdate tests for #12870 to pass with a slow run of the testsuite.
Andreas Klebinger [Mon, 19 Mar 2018 16:06:54 +0000 (12:06 -0400)] 
Update tests for #12870 to pass with a slow run of the testsuite.

Test Plan: make slow

Reviewers: bgamari, erikd, simonmar

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #12870

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

16 months agoDon't permit data types with return kind Constraint
Ryan Scott [Mon, 19 Mar 2018 16:06:41 +0000 (12:06 -0400)] 
Don't permit data types with return kind Constraint

Previously, GHC allowed all of the following:

```lang=haskell
data Foo1 :: Constraint
data family Foo2 :: Constraint
data family Foo3 :: k
data instance Foo3 :: Constraint
```

Yikes! This is because GHC was confusing `Type` with `Constraint`
due to careless use of the `isLiftedTypeKind` function. To respect
this distinction, I swapped `isLiftedTypeKind` out for
`tcIsStarKind`—which does respect this distinction—in the right
places.

Test Plan: make test TEST="T14048a T14048b T14048c"

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: goldfire, rwbarton, thomie, carter

GHC Trac Issues: #14048

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

16 months agoFix #14934 by including axSub0R in typeNatCoAxiomRules
Ryan Scott [Mon, 19 Mar 2018 16:05:36 +0000 (12:05 -0400)] 
Fix #14934 by including axSub0R in typeNatCoAxiomRules

For some reason, `axSub0R` was left out of `typeNatCoAxiomRules` in
`TcTypeNats`, which led to disaster when trying to look up `Sub0R` from
an interface file, as demonstrated in #14934.

The fix is simple—just add `axSub0R` to that list. To help prevent
an issue like this happening in the future, I added a
`Note [Adding built-in type families]` to `TcTypeNats`, which
contains a walkthrough of all the definitions in `TcTypeNats` you
need to update when adding a new built-in type family.

Test Plan: make test TEST=T14934

Reviewers: bgamari, simonpj

Reviewed By: simonpj

Subscribers: simonpj, rwbarton, thomie, carter

GHC Trac Issues: #14934

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

16 months agoRequire GHC 8.2 to bootstrap GHC
Joachim Breitner [Mon, 19 Mar 2018 16:05:22 +0000 (12:05 -0400)] 
Require GHC 8.2 to bootstrap GHC

Reviewers: bgamari, hvr, RyanGlScott

Reviewed By: RyanGlScott

Subscribers: RyanGlScott, rwbarton, thomie, erikd, carter

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

16 months agoTurn a TH Name for built-in syntax into an unqualified RdrName
Chaitanya Koparkar [Mon, 19 Mar 2018 16:04:03 +0000 (12:04 -0400)] 
Turn a TH Name for built-in syntax into an unqualified RdrName

Previously, the Renamer would turn any fully qualified Template Haskell
name into a corresponding fully qualified `RdrName`. But this is not
what we want for built-in syntax, as it produces unnecessarily qualified
names (eg. GHC.Types.[], GHC.Tuple.(,) etc.).

Test Plan: ./validate

Reviewers: RyanGlScott, bgamari, goldfire

Reviewed By: RyanGlScott, bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #13776

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

16 months agoImplement equalKeysUFM the right way
David Feuer [Mon, 19 Mar 2018 16:03:36 +0000 (12:03 -0400)] 
Implement equalKeysUFM the right way

Originally, we compared the key lists, which was kind of silly.
Then I changed it to something fancier ... and also silly.
This is much more reasonable, should be faster, and is nice and
clear.

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

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

16 months agoCmmUtils: get rid of insertBlock
Michal Terepeta [Mon, 19 Mar 2018 16:03:20 +0000 (12:03 -0400)] 
CmmUtils: get rid of insertBlock

`Hoopl.Graph` has almost exactly the same function, so let's use that.
Also, use `IntMap.alter` to make it more efficient.

Also switch `Hoopl` to use strict maps.

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

Reviewers: bgamari, simonmar

Reviewed By: bgamari

Subscribers: dfeuer, rwbarton, thomie, carter

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

16 months agoImprove accuracy of get/setAllocationCounter
Ben Gamari [Mon, 19 Mar 2018 16:02:43 +0000 (12:02 -0400)] 
Improve accuracy of get/setAllocationCounter

Summary:
get/setAllocationCounter didn't take into account allocations in the
current block. This was known at the time, but it turns out to be
important to have more accuracy when using these in a fine-grained
way.

Test Plan:
New unit test to test incrementally larger allocaitons.  Before I got
results like this:

```
+0
+0
+0
+0
+0
+4096
+0
+0
+0
+0
+0
+4064
+0
+0
+4088
+4056
+0
+0
+0
+4088
+4096
+4056
+4096
```

Notice how the results aren't always monotonically increasing.  After
this patch:

```
+344
+416
+488
+560
+632
+704
+776
+848
+920
+992
+1064
+1136
+1208
+1280
+1352
+1424
+1496
+1568
+1640
+1712
+1784
+1856
+1928
+2000
+2072
+2144
```

Reviewers: hvr, erikd, simonmar, jrtc27, trommler

Reviewed By: simonmar

Subscribers: trommler, jrtc27, rwbarton, thomie, carter

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

16 months ago[RFC] nativeGen: Add support for MO_SS_Conv_W32_W64 on i386
Ben Gamari [Mon, 19 Mar 2018 16:02:29 +0000 (12:02 -0400)] 
[RFC] nativeGen: Add support for MO_SS_Conv_W32_W64 on i386

This is required by D4288. However, this only handles i386; we will
likely also need to do the same for PPC and SPARC, lest they break when
D4288 is re-merged.

Test Plan: Validate

Reviewers: simonmar

Reviewed By: simonmar

Subscribers: rwbarton, thomie, carter

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

16 months agoSPARC nativeGen: Support for MO_SS_Conv_W32_W64
Peter Trommler [Mon, 19 Mar 2018 16:02:03 +0000 (12:02 -0400)] 
SPARC nativeGen: Support for MO_SS_Conv_W32_W64

Support for signed conversion from 32 bit to 64 bit
integers is required by D4363.

Test Plan: validate (perhaps also on SPARC)

Reviewers: simonmar, bgamari, kgardas, jrtc27

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

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

16 months agoPPC nativeGen: Add support for MO_SS_Conv_W32_W64
Peter Trommler [Mon, 19 Mar 2018 16:01:37 +0000 (12:01 -0400)] 
PPC nativeGen: Add support for MO_SS_Conv_W32_W64

This is required by D4363. D4362 has the implementation for i386
this commit adds PowerPC.

Test Plan: validate

Reviewers: erikd, hvr, simonmar, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

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

16 months agoImplement -dword-hex-literals
Andrew Martin [Mon, 19 Mar 2018 16:01:17 +0000 (12:01 -0400)] 
Implement -dword-hex-literals

Provide flag for showing showing Word# and Word64# as hexadecimal when
dumping GHC core.  The only affects Word, not Int, and it prefixes the
hexadecimal with enough zeroes to make the total character count a power
of two. For example:

- 0x0C0C instead of 0xC0C
- 0x00BA00BA instead of 0xBA00BA

This also affects the presentation of Word# and Word64# in GHC's error
messages. It is not expected that the flag will be used for this, but
it is a side-effect worth noting.

Test Plan: none

Reviewers: bgamari, simonpj

Reviewed By: simonpj

Subscribers: simonpj, mpickering, rwbarton, thomie, carter, andrewthad

GHC Trac Issues: #14872

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

16 months agoHoopl: improve postorder calculation
Michal Terepeta [Mon, 19 Mar 2018 15:58:54 +0000 (11:58 -0400)] 
Hoopl: improve postorder calculation

- Fix the naming and comments to indicate that we are calculating
  *reverse* postorder (and not the standard postorder).

- Rewrite the calculation to avoid CPS code. I found it fairly
  difficult to understand and the new one seems faster (according to
  nofib, decreases compiler allocations by 0.2%)

- Remove `LabelsPtr`, which seems unnecessary and could be *really*
  confusing. For instance, previously:
  `postorder_dfs_from <block with label X>`
  and
  `postorder_dfs_from <label X>`
  would actually mean quite different things (and give different
  results).

- Change the `Dataflow` module to always use entry of the graph for
  reverse postorder calculation. This should be the only change in
  behavior of this commit.

  Previously, if the caller provided initial facts for some of the
  labels, we would use those labels for our postorder calculation.
  However, I don't think that's correct in general - if the initial
  facts did not contain the entry of the graph, we would never analyze
  the blocks reachable from the entry but unreachable from the labels
  provided with the initial facts. It seems that the only analysis that
  used this was proc-point analysis, which I think would always include
  the entry block (so I don't think there's any bug due to this).

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

Reviewers: bgamari, simonmar

Reviewed By: simonmar

Subscribers: rwbarton, thomie, carter

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

16 months agoGet rid of more CPP in cmm/ and codeGen/
Michal Terepeta [Mon, 19 Mar 2018 15:58:39 +0000 (11:58 -0400)] 
Get rid of more CPP in cmm/ and codeGen/

This removes a bunch of unnecessary includes of `HsVersions.h` along
with unnecessary CPP (e.g., due to checking for DEBUG which can be
achieved by looking at `debugIsOn`)

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

Reviewers: bgamari, simonmar

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

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

16 months agoImprove the warning message of qualified unused imports.
HE, Tao [Mon, 19 Mar 2018 15:58:26 +0000 (11:58 -0400)] 
Improve the warning message of qualified unused imports.

Pretty-print unused imported names unqualified unconditionally to
make the warning message consistent for ambiguous/unambiguous
identifiers.

Signed-off-by: HE, Tao <sighingnow@gmail.com>
Test Plan: make test TEST="T14881"

Reviewers: bgamari, simonpj

Reviewed By: simonpj

Subscribers: simonpj, rwbarton, thomie, carter

GHC Trac Issues: #14881

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

16 months agoBe more selective in which conditionals we invert
Simon Marlow [Mon, 19 Mar 2018 15:57:27 +0000 (11:57 -0400)] 
Be more selective in which conditionals we invert

Test Plan: validate

Reviewers: bgamari, AndreasK, erikd

Reviewed By: AndreasK

Subscribers: rwbarton, thomie, carter

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

16 months agoAlso check local rules with -frules-check
Matthew Pickering [Mon, 19 Mar 2018 15:57:06 +0000 (11:57 -0400)] 
Also check local rules with -frules-check

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

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

16 months agorts: Add --internal-counters RTS flag and several counters
Douglas Wilson [Mon, 19 Mar 2018 15:55:37 +0000 (11:55 -0400)] 
rts: Add --internal-counters RTS flag and several counters

The existing internal counters:
* gc_alloc_block_sync
* whitehole_spin
* gen[g].sync
* gen[1].sync

are now not shown in the -s report unless --internal-counters is also passed.

If --internal-counters is passed we now show the counters above, reformatted, as
well as several other counters. In particular, we now count the yieldThread()
calls that SpinLocks do as well as their spins.

The added counters are:
* gc_spin (spin and yield)
* mut_spin (spin and yield)
* whitehole_threadPaused (spin only)
* whitehole_executeMessage (spin only)
* whitehole_lockClosure (spin only)
* waitForGcThreadsd (spin and yield)

As well as the following, which are not SpinLock-like things:
* any_work
* do_work
* scav_find_work

See the Note for descriptions of what these counters are.

We add busy_wait_nops in these loops along with the counter increment where it
was absent.

Old internal counters output:
```
gc_alloc_block_sync: 0
whitehole_gc_spin: 0
gen[0].sync: 0
gen[1].sync: 0
```

New internal counters output:
```
Internal Counters:
                                           Spins        Yields
    gc_alloc_block_sync                      323             0
    gc_spin                              9016713           752
    mut_spin                            57360944         47716
    whitehole_gc                               0           n/a
    whitehole_threadPaused                     0           n/a
    whitehole_executeMessage                   0           n/a
    whitehole_lockClosure                      0             0
    waitForGcThreads                           2           415
    gen[0].sync                                6             0
    gen[1].sync                                1             0

    any_work                                2017
    no_work                                 2014
    scav_find_work                          1004
```

Test Plan:
./validate

Check it builds with #define PROF_SPIN removed from includes/rts/Config.h

Reviewers: bgamari, erikd, simonmar, hvr

Reviewed By: simonmar

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #3553, #9221

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

16 months agoAdd a build with 32bit Ubuntu container
mrkkrp [Wed, 28 Feb 2018 11:18:58 +0000 (18:18 +0700)] 
Add a build with 32bit Ubuntu container

16 months agoUpdate test for #5129:
Ömer Sinan Ağacan [Mon, 19 Mar 2018 12:46:44 +0000 (15:46 +0300)] 
Update test for #5129:

Make sure it runs with --fast validate with correct optimisation
settings (-O1 or above) so that it actually tests the bug.

Because the bug is in the simplifier running it with -O0 doesn't
test it.

16 months agoComments and tiny refactor
Simon Peyton Jones [Mon, 19 Mar 2018 09:39:58 +0000 (09:39 +0000)] 
Comments and tiny refactor

Related to Ryan's upcoming patch for Trac #14933

16 months agoaclocal.m4: add OSHurd (debian patch)
Sergei Trofimovich [Sat, 17 Mar 2018 17:12:04 +0000 (17:12 +0000)] 
aclocal.m4: add OSHurd (debian patch)

ghc treats OSUnknown (and GNU/Hurd) as non-ELF target.
This causes panic in native codegenerator when trying
to build PIC code:

```
  ...
  -- all other platforms
  howToAccessLabel dflags _ _ _ _ _
        | not (positionIndependent dflags)
        = AccessDirectly
        | otherwise
        = panic "howToAccessLabel: PIC not defined for this platform"
```

This change declares new 'OSHurd' and marks it as an
ELF target. Fixes building ghc-stage2 on i686-unknown-gnu0.9.

Patch provided by "Pino" via Samuel Thibault and taken from
debian.

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
16 months agoaclocal.m4: allow more GNU/Hurd tuples
Sergei Trofimovich [Sat, 17 Mar 2018 12:12:43 +0000 (12:12 +0000)] 
aclocal.m4: allow more GNU/Hurd tuples

Running plain ./configure fails on hurd because
./config.guess reports unrecognised tuple:
    $ ./config.guess
    i686-unknown-gnu0.9

The change makes the following target configure:
$ ./configure --target=i686-unknown-gnu0.9

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
16 months agoSlighly improve infix con app pattern errors
Ömer Sinan Ağacan [Wed, 14 Mar 2018 06:16:51 +0000 (09:16 +0300)] 
Slighly improve infix con app pattern errors

Given this program:

    main = do
      f $ do
        a <- return 3
          c <- do
          return 5

GHC previously gave this error message:

    Main.hs:2:7: error:
        Parse error in pattern: do a <- return 3 c
        Possibly caused by a missing 'do'?
      |
    2 |   f $ do
      |       ^^...

What happened is GHC considered the whole `f $ do a <- return 3 c` as a
pattern. When parsed as an expression it becomes an infix application of
`($)`, and GHC checks left and right hand sides before checking if `($)`
is a valid infix constructor name, and shows the first error it got.

If instead we first check if the infix op is valid in pattern context,
the error message becomes much clearer:

    Main.hs:2:3: error:
        Parse error in pattern: f $ do a <- return 3 c
        Possibly caused by a missing 'do'?
      |
    2 |   f $ do
      |   ^^^^^^...

This may not entirely fix #11188 but I think it's an improvement.

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #11188

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

16 months agoDrop GHC 8.0 compatibility
Ryan Scott [Tue, 13 Mar 2018 17:36:38 +0000 (13:36 -0400)] 
Drop GHC 8.0 compatibility

GHC 8.4.1 is out, so now GHC's support window only extends
back to GHC 8.2. This means we can delete gobs of code that were
only used for GHC 8.0 support. Hooray!

Test Plan: ./validate

Reviewers: bgamari, erikd, dfeuer

Reviewed By: bgamari, dfeuer

Subscribers: alexbiehl, dfeuer, rwbarton, thomie, carter

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

16 months agoUpdate a comment in Exception.cmm
Ömer Sinan Ağacan [Tue, 13 Mar 2018 12:34:21 +0000 (15:34 +0300)] 
Update a comment in Exception.cmm

[skip ci]

16 months agoComment improvements on interpreter breakpoint IO action
Ömer Sinan Ağacan [Tue, 13 Mar 2018 12:25:53 +0000 (15:25 +0300)] 
Comment improvements on interpreter breakpoint IO action

[skip ci]

16 months agoBump Cabal submodule
Ben Gamari [Sat, 10 Mar 2018 18:47:51 +0000 (13:47 -0500)] 
Bump Cabal submodule

16 months agoRemove splitEithers, use partitionEithers from base
Ömer Sinan Ağacan [Mon, 12 Mar 2018 07:54:17 +0000 (10:54 +0300)] 
Remove splitEithers, use partitionEithers from base

16 months agotestsuite: disable T13615 on non-smp targets
Sergei Trofimovich [Sat, 10 Mar 2018 12:33:59 +0000 (12:33 +0000)] 
testsuite: disable T13615 on non-smp targets

T13615 needs multicore support from RTS:
    T13615: unknown RTS option: -N15

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
16 months agoFix a debug print in disassembler (#14905)
Ömer Sinan Ağacan [Fri, 9 Mar 2018 12:38:58 +0000 (15:38 +0300)] 
Fix a debug print in disassembler (#14905)

When interpreter is not profiled (see `interpreterProfiled` in
`DynFlags`) bytecode generator generates a NULL pointer as the cost
centre of a `BRK_FUN` instruction:

    let cc | interpreterProfiled dflags = cc_arr ! tick_no
           | otherwise = toRemotePtr nullPtr
    let breakInstr = BRK_FUN (fromIntegral tick_no) (getUnique this_mod) cc
    return $ breakInstr `consOL` code

We now take this into account when disassembling `BRK_FUN`.

Reviewers: bgamari, simonmar, erikd

Subscribers: rwbarton, thomie, carter

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

16 months agoUNREG: fix implicit declarations from pdep and pext
Sergei Trofimovich [Fri, 9 Mar 2018 17:43:01 +0000 (17:43 +0000)] 
UNREG: fix implicit declarations from pdep and pext

Unreg build failed as:

  $ ./configure --enable-unregisterised
  $ make

  HC [stage 1] libraries/ghc-prim/dist-install/build/GHC/PrimopWrappers.o
    ghc_1.hc: In function 'ghczmprim_GHCziPrimopWrappers_pdep8zh_entry':

    ghc_1.hc:1810:9: error:
     error: implicit declaration of function 'hs_pdep8'; did you mean 'hs_ctz8'?
       [-Werror=implicit-function-declaration]
     _c3jz = hs_pdep8(*Sp, Sp[1]);
             ^~~~~~~~
             hs_ctz8
       |
  1810 | _c3jz = hs_pdep8(*Sp, Sp[1]);
       |         ^

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
16 months agoCompacted arrays are pinned for isByteArrayPinned#
Simon Marlow [Thu, 8 Mar 2018 08:54:01 +0000 (08:54 +0000)] 
Compacted arrays are pinned for isByteArrayPinned#

Test Plan: New unit test

Reviewers: andrewthad, niteria, bgamari, erikd

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14900

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

16 months agoconfigure: Accept suffix in OpenBSD triple's OS name
Ben Gamari [Thu, 8 Mar 2018 18:29:01 +0000 (13:29 -0500)] 
configure: Accept suffix in OpenBSD triple's OS name

Reviewers: hvr

Subscribers: rwbarton, thomie, erikd, carter

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

16 months agoRemove outdated documentation bits concerning -Wmissing-methods
Ryan Scott [Thu, 8 Mar 2018 18:23:27 +0000 (13:23 -0500)] 
Remove outdated documentation bits concerning -Wmissing-methods

In commit 503219e3e1667ac39607021b2d9586260fbab32b, we
stopped suppressing `-Wmissing-methods` warnings on class methods
whose names begin with an underscore. However, it seems the users'
guide documentation concerning this was never updated. Let's do so.

Test Plan: Read it

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #12959

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

16 months agoghc-prim: Silence -Wsync-nand warning in atomic.c
Ben Gamari [Thu, 8 Mar 2018 18:22:37 +0000 (13:22 -0500)] 
ghc-prim: Silence -Wsync-nand warning in atomic.c

GCC throws this warning to inform us that __sync_fetch_and_nand's
behavior changed in GCC 4.4. However, this causes the build to fail when
-Werror is used.

Test Plan: Validate with -Werror

Subscribers: rwbarton, thomie, carter

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

16 months agoghc-prim: Reduce scope of Clang sync_fetch_and_nand workaround
Ben Gamari [Thu, 8 Mar 2018 18:22:22 +0000 (13:22 -0500)] 
ghc-prim: Reduce scope of Clang sync_fetch_and_nand workaround

As described in https://bugs.llvm.org/show_bug.cgi?id=8842, Clang
removed the __sync_fetch_and_nand builtins due to inconsistency in GCC's
behavior in 2010.  However, GCC has since clarified the behavior of
their builtins and consequently Clang re-added them in 2014.
Consequently this workaround should no longer be necessary.

Test Plan: Validate building with Clang

Subscribers: rwbarton, thomie, carter

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

16 months agoError message and doc improvements for #14335
Ömer Sinan Ağacan [Thu, 8 Mar 2018 18:19:33 +0000 (13:19 -0500)] 
Error message and doc improvements for #14335

- Show a more friendly error message when -fplugin is used with
  -fexternal-interpreter

- Add a few words to users guide about the interaction with -fplugin and
  -fexternal-interpreter

- Update test for #14335

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14335

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

16 months agoRevert "GHCi: Don't remove shadowed bindings from typechecker scope."
Ömer Sinan Ağacan [Thu, 8 Mar 2018 18:42:22 +0000 (21:42 +0300)] 
Revert "GHCi: Don't remove shadowed bindings from typechecker scope."

This reverts commit 59d7ee53906b9cee7f279c1f9567af7b930f8636 and enables
the test for #14052.

(See #14052 for the discussion)

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14052

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

16 months agoAdd -fexternal-dynamic-refs
Simon Marlow [Wed, 28 Feb 2018 19:03:37 +0000 (11:03 -0800)] 
Add -fexternal-dynamic-refs

Summary:
The `-dynamic` flag does two things:

* In the code generator, it generates code designed to link against
  external shared libraries.  References outside of the current module
  go through platform-specific indirection tables (e.g. the GOT on ELF).

* It enables a "way", which changes which hi files we look
  for (`Foo.dyn_hi`) and which libraries we link against.

Some specialised applications want the first of these without the
second. (I could go into detail here but it's probably not all that
important).

This diff splits out the code-generation effects of `-dynamic` from the
"way" parts of its behaviour, via a new flag `-fexternal-dynamic-refs`.

Test Plan: validate

Reviewers: niteria, bgamari, erikd

Subscribers: rwbarton, thomie, carter

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