ghc.git
4 years agoBuild system: delete the InstallExtraPackages variable
Thomas Miedema [Tue, 25 Aug 2015 15:30:18 +0000 (17:30 +0200)] 
Build system: delete the InstallExtraPackages variable

Just install all packages that are built. Don't make an exception for
the dph and extra packages.

You can control whether the dph and extra packages should be build using
the variables BUILD_DPH and BUILD_EXTRA_PKGS. These variables didn't
exist before. But now that they do, InstallExtraPackages isn't really
needed anymore.

Reviewed by: austin

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

4 years agoBuild system: remove hack for Mac OSX in configure.ac (#10476)
Thomas Miedema [Mon, 7 Sep 2015 13:58:33 +0000 (15:58 +0200)] 
Build system: remove hack for Mac OSX in configure.ac (#10476)

Cross-compilation on Mac OSX currently doesn't work. While building
stage 1, the build system uses the `ar` for the target architecture
instead of the `ar` for build/host architecture.

The cause is a hack added in 24746fe78024a1edab843bc710c79c55998ab134
(2010), to supporting bootstrap compilers built with older versions of
Xcode. Xcode 4.3 started installing command line tools in a different
location. Assuming this all behind us now, and the paths didn't change
again (you never now), we can delete the hack.

Deleting the hack fixes the cross compilation issue. Tested by Trac user
jakzale.

Reviewed by: austin

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

4 years agoBuild system: detect when user cloned from GitHub
Thomas Miedema [Mon, 7 Sep 2015 13:28:30 +0000 (15:28 +0200)] 
Build system: detect when user cloned from GitHub

Cloning the ghc repository from GitHub doesn't work out of the box. It
requires installing some special url rewrites into ~/.gitconfig. The
build fails mysteriously if you forget. This patch tries to detect when
you cloned from GitHub, and warns you if you didn't set those url
rewrites.

This hopefully lowers to barrier to contribute to GHC by a tiny bit. At
least one /r/haskell user ran into this recently.

Test Plan:
cloned from github, ran ./boot, saw the message. Installed url
rewrites, and ran ./boot again, didn't see the message.

Reviewed by: austin

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

4 years agoFurther simplify the story around minimum/maximum
Joachim Breitner [Mon, 7 Sep 2015 11:48:10 +0000 (13:48 +0200)] 
Further simplify the story around minimum/maximum

After I have found out that I should look at -ddump-prep and not
-ddump-core, I noticed that these days, GHC is perfectly capeable of
turning (the equivalent) of foldl to (the equivalent) of foldl' if the
operation in question is strict. So instead of using rewrite rules to
rewrite maximum to a strictMaximum for certain types, we simply use
SPECIALIZE.

This also marks maximum/minimum as INLINEABLE, so that client code can
get similar specializations, hopefully even automatically. And inded,
minimum applied to [Double] produces good code (although due to
inlineing, not due to specialization, it seems).

I checked (by looking at the core) that this still fixes #10788.

Differential revision: https://phabricator.haskell.org/D1229

4 years agoSPECIALIZE strictMinimum for Int and Integer
Joachim Breitner [Mon, 7 Sep 2015 11:19:50 +0000 (13:19 +0200)] 
SPECIALIZE strictMinimum for Int and Integer

This fixes a regression reported in #10788, where due to less inlining
compared to earlier versions, we’d get worse code. With the SPECIALIZE,
we get the good code, and moreover, the good code is in List.hs and
_not_ inlined to the use site, so smaller code size and less compilation
time.

4 years agoBuild system: cleanup utils/ghc-pkg/ghc.mk
Thomas Miedema [Thu, 9 Jul 2015 23:02:31 +0000 (01:02 +0200)] 
Build system: cleanup utils/ghc-pkg/ghc.mk

There used to be a lot of custom make code to build ghc-pkg with the
stage0 compiler. Commit ac5a314504554ddef0e855ef9e2fcf51e961f4a6
thankfully cleaned this up, by using the build settings from the
ghc-pkg.cabal file.

This commit removes some remains of the old way of installing ghc-pkg
when Stage1Only=YES. Notably, we called both `build-prog` as
`shell-wrapper`. This is surely wrong, because `build-prog` already
calls `shell-wrapper`. It isn't needed to set WANT_INSTALLED_WRAPPER
either; build-prog does that for us.

This prevents the following warnings when Stage1Only=YES:
  utils/ghc-pkg/ghc.mk:46: warning:
    overriding commands for target `install_utils/ghc-pkg_dist_wrapper'
  utils/ghc-pkg/ghc.mk:37: warning:
    ignoring old commands for target `install_utils/ghc-pkg_dist_wrapper'

Also add more comments and restructure a bit.

Reviewed by: austin

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

4 years agoBuild system: simplify *-llvm BuildFlavours (#10223)
Thomas Miedema [Tue, 25 Aug 2015 15:49:32 +0000 (17:49 +0200)] 
Build system: simplify *-llvm BuildFlavours (#10223)

Note that SRC_HC_OPTS are added to every Haskell compilation. So
there isn't any need to also add `-fllvm` to GhcStage1HcOpts,
GhcStage2HcOpts and GhcLibHcOpts.

Small bug fix: make sure we test for -fllvm in SRC_HC_OPTS, to check
whether the bootstrap compiler is affected by bug #9439.

Reviewed by: austin

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

4 years agoBuild system: put each BuildFlavour in a separate file (#10223)
Thomas Miedema [Mon, 31 Aug 2015 12:39:47 +0000 (14:39 +0200)] 
Build system: put each BuildFlavour in a separate file (#10223)

This allows easier diffing of different BuildFlavours, including
`mk/flavours/validate.mk`.

Reviewed By: bgamari, austin

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

4 years agotracing: Kill EVENT_STARTUP
Ben Gamari [Mon, 31 Aug 2015 20:39:13 +0000 (22:39 +0200)] 
tracing: Kill EVENT_STARTUP

This has been unnecessary for quite some time due to the create/delete
capability events.

4 years agoEventLog: Factor out ensureRoomFor*Event
Ben Gamari [Mon, 31 Aug 2015 20:00:10 +0000 (22:00 +0200)] 
EventLog: Factor out ensureRoomFor*Event

4 years agouser-guide: Add missing <para> tags around <listitem> body
Ben Gamari [Fri, 4 Sep 2015 16:49:23 +0000 (18:49 +0200)] 
user-guide: Add missing <para> tags around <listitem> body

Otherwise this is ill-formed DocBook

4 years agoghc-pkg: don't print ignored errors when verbosity=0
Thomas Miedema [Fri, 4 Sep 2015 14:59:44 +0000 (16:59 +0200)] 
ghc-pkg: don't print ignored errors when verbosity=0

Lines like the following are filling up the build logs:

  binary-0.7.5.0: cannot find any of
  ["Data/Binary.hi","Data/Binary.p_hi","Data/Binary.dyn_hi"] (ignoring)

4 years agoBuild system: implement `make install-strip` (#1851)
Thomas Miedema [Sat, 15 Aug 2015 15:45:57 +0000 (17:45 +0200)] 
Build system: implement `make install-strip` (#1851)

Reviewed by: bgamari

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

4 years agoFix T6018th test failure
Jan Stolarek [Fri, 4 Sep 2015 03:15:06 +0000 (05:15 +0200)] 
Fix T6018th test failure

4 years agoMake Data.List.foldr1 inline
Joachim Breitner [Wed, 2 Sep 2015 22:58:38 +0000 (15:58 -0700)] 
Make Data.List.foldr1 inline

Previously, foldr1 would be defiend recursively and thus not inline.
This is bad, for example, when maximumBy has a strict comparison
function: Before the BBP, it was implemented via foldl1, which inlined
and yielded good code. With BBP, it goes via foldr1, so we better inline
this as well. Fixes #10830.

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

4 years agoTestsuite: ignore line number differences in call stacks (#10834)
Thomas Miedema [Thu, 3 Sep 2015 12:56:50 +0000 (14:56 +0200)] 
Testsuite: ignore line number differences in call stacks (#10834)

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

4 years agoTestsuite: only print msg when timeout kills process unexpectedly
Thomas Miedema [Thu, 3 Sep 2015 14:13:42 +0000 (16:13 +0200)] 
Testsuite: only print msg when timeout kills process unexpectedly

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

4 years agoTestsuite: fix tcfail220 - Maybe is wired-in now
Thomas Miedema [Thu, 3 Sep 2015 15:01:10 +0000 (17:01 +0200)] 
Testsuite: fix tcfail220 - Maybe is wired-in now

This fixes validate.

374457809de343f409fbeea0a885877947a133a2 (D202) mentions: "This patch
also wires-in Maybe data type".

A conflicting definition of a wired-in type in a .hsig file doesn't seem
to cause compilation to fail. This is probably a bug, but a small one.
Since SPJ in ffc21506894c7887d3620423aaf86bc6113a1071 swept this under
the rug, by removing `data Bool a b c d = False` from tcfail220.hsig,
I'm going to do the same here.

D1098 touches these files, so ezyang can decide whether this problem
warrants fixing when doing a rebase.

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

4 years agoAccept underscores in the module parser. (Thanks spinda for the fix.)
Edward Z. Yang [Thu, 3 Sep 2015 21:16:03 +0000 (14:16 -0700)] 
Accept underscores in the module parser. (Thanks spinda for the fix.)

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
4 years agoAdd test for T10836 (expected broken)
Jan Stolarek [Thu, 3 Sep 2015 17:28:44 +0000 (19:28 +0200)] 
Add test for T10836 (expected broken)

4 years agoInjective type families
Jan Stolarek [Fri, 11 Jul 2014 11:54:45 +0000 (13:54 +0200)] 
Injective type families

For details see #6018, Phab:D202 and the wiki page:

https://ghc.haskell.org/trac/ghc/wiki/InjectiveTypeFamilies

This patch also wires-in Maybe data type and updates haddock submodule.

Test Plan: ./validate

Reviewers: simonpj, goldfire, austin, bgamari

Subscribers: mpickering, bgamari, alanz, thomie, goldfire, simonmar,
             carter

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

GHC Trac Issues: #6018

4 years agoTestsuite: delete dead code
Thomas Miedema [Thu, 27 Aug 2015 23:00:31 +0000 (01:00 +0200)] 
Testsuite: delete dead code

4 years agoTestsuite: by default run all tests for a single way
Thomas Miedema [Thu, 27 Aug 2015 10:44:15 +0000 (12:44 +0200)] 
Testsuite: by default run all tests for a single way

`make test` now runs all tests for a single way only. Use `make slowtest` to
get the previous behaviour (i.e. run all tests for all ways).

The intention is to use this new `make test` setting for Phabricator, as
a reasonable compromise between `make fasttest` (what it previously
used) and a fullblown `make slowtest` (which runs all tests for all
ways).

See Note [validate and testsuite speed] in toplevel Makefile.

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

4 years agoFix some tests that were broken by D861
Eric Seidel [Wed, 2 Sep 2015 18:17:01 +0000 (20:17 +0200)] 
Fix some tests that were broken by D861

I didn't realize that `./validate` does not run every test :(

Test Plan: ./validate --slow

Update submodule hpc.

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

4 years agoTestsuite: mark 4 tests expect_broken_for(#10712, opt_ways)
Thomas Miedema [Wed, 2 Sep 2015 16:49:25 +0000 (18:49 +0200)] 
Testsuite: mark 4 tests expect_broken_for(#10712, opt_ways)

Please revert when #10712 is fixed.

4 years agoTestsuite: update expected output
Thomas Miedema [Wed, 2 Sep 2015 16:30:07 +0000 (18:30 +0200)] 
Testsuite: update expected output

4 years agoTestsuite: don't warn about missing specialisations
Thomas Miedema [Wed, 2 Sep 2015 13:45:57 +0000 (15:45 +0200)] 
Testsuite: don't warn about missing specialisations

They can only occur with `-O`, but we want tests to produce the same
output for all test ways.

This brings us closer to passing the complete testsuite.

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

4 years agostm: Fix test case
Ben Gamari [Wed, 2 Sep 2015 13:34:56 +0000 (09:34 -0400)] 
stm: Fix test case

Updates stm submodule.

4 years agoImprove the error messages for class instance errors
Simon Peyton Jones [Wed, 2 Sep 2015 12:05:36 +0000 (14:05 +0200)] 
Improve the error messages for class instance errors

Summary: See Note [Displaying potential instances].

Reviewers: austin

Subscribers: KaneTW, thomie

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

4 years agoExpand declaration QQs first (#10047)
Michael Smith [Wed, 2 Sep 2015 11:57:44 +0000 (13:57 +0200)] 
Expand declaration QQs first (#10047)

Declaration QuasiQuoters do not cause a group split like $(...)
splices, and are run and expanded before other declarations in
the group.

Resolves the lingering issue with #10047, and fixes broken tests
qq007 and qq008.

Test Plan: validate

Reviewers: goldfire, austin, bgamari

Reviewed By: bgamari

Subscribers: goldfire, simonpj, thomie, spinda

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

GHC Trac Issues: #10047

4 years agoAllow annotations though addTopDecls (#10486)
Michael Smith [Wed, 2 Sep 2015 11:56:27 +0000 (13:56 +0200)] 
Allow annotations though addTopDecls (#10486)

addTopDecls restricts what declarations it can be used to add. Adding
annotations via this method works fine with no special changes apart
from adding AnnD to the declaration whitelist.

Test Plan: validate

Reviewers: austin, goldfire, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

GHC Trac Issues: #10486

4 years agoUse a response file for linker command line arguments #10777
Michael Snoyman [Wed, 2 Sep 2015 11:31:25 +0000 (13:31 +0200)] 
Use a response file for linker command line arguments #10777

On Windows, we're constrained to 32k bytes total for command line
arguments.  When building large projects, this limit can be exceeded.
This patch changes GHC to always use response files for linker
arguments, a feature first used by Microsoft compilers and added to GCC
(over a decade ago).

Alternatives here include:

* Only use this method on Windows systems
* Check the length of the command line arguments and use that to decide
  whether to use this method

I did not pursue either of these, as I believe it would make the patch
more likely to break in less tested situations.

Test Plan:
Confirm that linking still works in general. Ideally: compile a very
large project on Windows with this patch. (I am attempting to do that
myself now, but having trouble getting the Windows build tool chain up
and running.)

Reviewers: goldfire, hvr, rwbarton, austin, thomie, bgamari, Phyx

Reviewed By: thomie, bgamari, Phyx

Subscribers: erikd, awson, #ghc_windows_task_force, thomie

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

GHC Trac Issues: #8596, #10777

4 years agoAdd test for updating a record with existentially quantified fields.
Matthew Pickering [Wed, 2 Sep 2015 11:28:34 +0000 (13:28 +0200)] 
Add test for updating a record with existentially quantified fields.

Test Plan: ./validate

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

4 years agoFix trac #10413
Ben Gamari [Wed, 2 Sep 2015 11:26:22 +0000 (13:26 +0200)] 
Fix trac #10413

Test Plan: Validate.

Reviewers: austin, tibbe, bgamari

Reviewed By: tibbe, bgamari

Subscribers: thomie

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

GHC Trac Issues: #10413

4 years agoUse IP based CallStack in error and undefined
Eric Seidel [Wed, 2 Sep 2015 08:22:01 +0000 (10:22 +0200)] 
Use IP based CallStack in error and undefined

This patch modifies `error`, `undefined`, and `assertError` to use
implicit call-stacks to provide better error messages to users.

There are a few knock-on effects:

- `GHC.Classes.IP` is now wired-in so it can be used in the wired-in
  types for `error` and `undefined`.

- `TysPrim.tyVarList` has been replaced with a new function
  `TysPrim.mkTemplateTyVars`. `tyVarList` made it easy to introduce
  subtle bugs when you need tyvars of different kinds. The naive

  ```
  tv1 = head $ tyVarList kind1
  tv2 = head $ tyVarList kind2
  ```

  would result in `tv1` and `tv2` sharing a `Unique`, thus substitutions
  would be applied incorrectly, treating `tv1` and `tv2` as the same
  tyvar. `mkTemplateTyVars` avoids this pitfall by taking a list of kinds
  and producing a single tyvar of each kind.

- The types `GHC.SrcLoc.SrcLoc` and `GHC.Stack.CallStack` now live in
  ghc-prim.

- The type `GHC.Exception.ErrorCall` has a new constructor
  `ErrorCallWithLocation` that takes two `String`s instead of one, the
  2nd one being arbitrary metadata about the error (but usually the
  call-stack). A bi-directional pattern synonym `ErrorCall` continues to
  provide the old API.

Updates Cabal, array, and haddock submodules.

Reviewers: nh2, goldfire, simonpj, hvr, rwbarton, austin, bgamari

Reviewed By: simonpj

Subscribers: rwbarton, rodlogic, goldfire, maoe, simonmar, carter,
liyang, bgamari, thomie

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

GHC Trac Issues: #5273

4 years agoTestsuite: refactoring only
Thomas Miedema [Fri, 28 Aug 2015 10:03:30 +0000 (12:03 +0200)] 
Testsuite: refactoring only

* Rename `platform_wordsize_qualify` to `find_expected_file`, and make
  it return a filename instead of an (absolute) filepath.

* Replace most usages of `qualify` by `in_testdir`. Others usage sites
  will be deleted in a later commit.

These changes will be useful in a later commit, when we'll distinguish
between files in the source directory and those in a (newly created)
test directory.

Reviewed by: austin, bgamari

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

4 years agoAnchor type family instances deterministically
Bartosz Nitka [Mon, 31 Aug 2015 15:10:34 +0000 (16:10 +0100)] 
Anchor type family instances deterministically

Summary:
This is very similar to D1073. It makes type family instances to be
attached to a binding with a least `OccName`, therefore not depending on `Unique` ordering.

Test Plan:
* this makes `Language.Haskell.Exts.SrcLoc` deterministic
* ./validate

Reviewers: simonmar, austin, bgamari, simonpj

Reviewed By: simonpj

Subscribers: thomie

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

GHC Trac Issues: #4012

4 years agoFix typo in pattern synonym documentation.
Matthew Pickering [Sun, 30 Aug 2015 16:31:01 +0000 (18:31 +0200)] 
Fix typo in pattern synonym documentation.

`MkT` is the name of the constructor whilst `T` is the name of
the type.

Reviewers: bgamari, austin

Subscribers: thomie

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

GHC Trac Issues: #10787

4 years agoFix 7.10 validate
Matthew Pickering [Sun, 30 Aug 2015 16:30:51 +0000 (18:30 +0200)] 
Fix 7.10 validate

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

4 years agoStgCmmHeap: Re-add check for large static allocations
Ben Gamari [Thu, 27 Aug 2015 12:08:01 +0000 (14:08 +0200)] 
StgCmmHeap: Re-add check for large static allocations

This should at least help alleviate the annoyance of #4505. This
reintroduces a compile-time check originally added in
a278f3f02d09bc32b0a75d4a04d710090cde250f but dropped with the new code
generator.

4 years agointeger-gmp: optimise bitBigNat
Herbert Valerio Riedel [Sat, 29 Aug 2015 10:25:45 +0000 (12:25 +0200)] 
integer-gmp: optimise bitBigNat

This is a somewhat minor optimisation exploiting the static knowledge
of the operands involved allowing to save a few allocations.

Reviewers: austin, rwbarton, goldfire, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

4 years agoghc-pkg --enable-multi-instance should not complain about case sensitivity.
Edward Z. Yang [Sat, 29 Aug 2015 10:25:28 +0000 (12:25 +0200)] 
ghc-pkg --enable-multi-instance should not complain about case sensitivity.

Test Plan: validate

Reviewers: simonmar, bgamari, austin

Reviewed By: bgamari, austin

Subscribers: thomie

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

4 years agoFix identifier parsing in hp2ps
Yuras Shumovich [Sat, 29 Aug 2015 10:25:14 +0000 (12:25 +0200)] 
Fix identifier parsing in hp2ps

Now identifiers can start with a package key, which is a hash, so they
may also start with a digit. Identifiers always appear at the beginning
of a line, and numbers never appear here, soit's safe to allow
identifiers to start with a digit.

Test Plan: `concprog002` passes under `threaded2_hT` way

Reviewers: austin, bgamari, thomie

Reviewed By: austin, bgamari, thomie

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

GHC Trac Issues: #10661

4 years agoDwarf: Produce .dwarf_aranges section
Ben Gamari [Sat, 29 Aug 2015 10:25:04 +0000 (12:25 +0200)] 
Dwarf: Produce .dwarf_aranges section

Test Plan: Check with `readelf --debug-dump=ranges`

Reviewers: scpmw, austin

Subscribers: thomie

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

4 years agoDwarf: Produce {low,high}_pc attributes for compilation units
Ben Gamari [Sat, 29 Aug 2015 10:24:54 +0000 (12:24 +0200)] 
Dwarf: Produce {low,high}_pc attributes for compilation units

Some libraries (e.g. elfutils) need these otherwise they ignore our
DWARF annotations.

Test Plan: Test with elfutils' `readelf --debug-dump=cu_index`

Reviewers: scpmw, austin

Subscribers: thomie

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

4 years agoDwarf: Fix DW_AT_use_UTF8 attribute
Ben Gamari [Sat, 29 Aug 2015 10:24:14 +0000 (12:24 +0200)] 
Dwarf: Fix DW_AT_use_UTF8 attribute

Previously this was given in the body but not in the abbreviation table.
Who knows what sort of havoc this was wrecking.

Test Plan: Verify against DWARF4 specification

Reviewers: scpmw, austin

Subscribers: Tarrasch, thomie

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

4 years agoRespect GHC_CHARENC environment variable #10762
Michael Snoyman [Sat, 29 Aug 2015 10:23:48 +0000 (12:23 +0200)] 
Respect GHC_CHARENC environment variable #10762

Only supports UTF-8 as a value right now. I expect some discussion to go
on around the naming of this variable and whether it's valid to backport
it to GHC 7.10 (which would be my preference). The motivation here is
that, when capturing the output of GHC to a file, we often want to
ensure that the output is UTF-8, regardless of the actual character
encoding of the terminal/console.

On the other hand, we don't want to necessary change the
terminal/console encoding. The reason being:

* On Windows, this requires a global-esque change to the console
  codepage, which adversely affects other processes in the same console

* On all OSes, this can break features like smart quote auto-detection.

Test Plan:
Set LANG to C, GHC_CHARENC to UTF-8, and compile a Haskell source
file with a non-ASCII warning produced. The output who include the UTF-8
sequence instead of replacing it with ?.

Reviewers: austin, rwbarton, bgamari

Reviewed By: bgamari

Subscribers: hsyl20, thomie

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

GHC Trac Issues: #10762

4 years agoMake Generic (Proxy t) instance poly-kinded (fixes #10775)
RyanGlScott [Sat, 29 Aug 2015 10:23:31 +0000 (12:23 +0200)] 
Make Generic (Proxy t) instance poly-kinded (fixes #10775)

This amounts to enabling PolyKinds in GHC.Generics. However, explicit
kind signatures must be applied to the datatypes and typeclasses in
GHC.Generics to ensure that the Core which TcGenGenerics generates
is properly kinded.

Several of the typeclasses in GHC.Generics could be poly-kinded, but
this differential does not attempt to address this, since D493 already
addresses this.

Test Plan: ./validate

Reviewers: hvr, austin, dreixel, bgamari

Reviewed By: austin, dreixel, bgamari

Subscribers: goldfire, thomie

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

GHC Trac Issues: #10775

4 years agoAdd testcase for #7411
Ben Gamari [Thu, 27 Aug 2015 13:04:29 +0000 (15:04 +0200)] 
Add testcase for #7411

4 years agoRTS: Reduce MBLOCK_SPACE_SIZE on AArch64
Erik de Castro Lopo [Tue, 25 Aug 2015 02:07:45 +0000 (02:07 +0000)] 
RTS: Reduce MBLOCK_SPACE_SIZE on AArch64

Commit 0d1a8d09f4 added a two step allocator for 64 bit systems. This
allocator mmaps a huge (1 TB) chunk of memory out of which it does
smaller allocations. On AArch64/Arm64 linux, this mmap was failing
due to the Arm64 Linux kernel parameter CONFIG_ARM64_VA_BITS
defaulting to 39 bits.

Therefore reducing the AArch64 value for MBLOCK_SPACE_SIZE to make
this allocation 1/4 TB while remaining 1 TB for other archs.

Reviewers: ezyang, austin, bgamari

Subscribers: thomie

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

GHC Trac Issues: #10682

4 years agobase: Remove a redundant 'return'
Simon Peyton Jones [Thu, 26 Mar 2015 11:06:12 +0000 (11:06 +0000)] 
base: Remove a redundant 'return'

4 years agoTysWiredIn: Shuffle code around
Ben Gamari [Wed, 26 Aug 2015 16:19:31 +0000 (18:19 +0200)] 
TysWiredIn: Shuffle code around

4 years agoMkIface: Introduce PatSynId, ReflectionId, DefMethId
Ben Gamari [Wed, 26 Aug 2015 16:14:31 +0000 (18:14 +0200)] 
MkIface: Introduce PatSynId, ReflectionId, DefMethId

Currently we don't persist these three "advisory" IdInfos through
interface files.  We easily could if needed.

4 years agoIfaceEnv: Clean up updNameCache a bit
Ben Gamari [Wed, 26 Aug 2015 16:10:21 +0000 (18:10 +0200)] 
IfaceEnv: Clean up updNameCache a bit

4 years agoMove newImplicitBinder to from IfaceEnv to BuildTyCl
Ben Gamari [Thu, 27 Aug 2015 06:01:21 +0000 (08:01 +0200)] 
Move newImplicitBinder to from IfaceEnv to BuildTyCl

4 years agoPrelNames: introduce dcQual in place of conName
Ben Gamari [Wed, 26 Aug 2015 16:03:00 +0000 (18:03 +0200)] 
PrelNames: introduce dcQual in place of conName

4 years agoRevert "Clean up handling of knownKeyNames"
Ben Gamari [Wed, 26 Aug 2015 23:00:52 +0000 (01:00 +0200)] 
Revert "Clean up handling of knownKeyNames"

This reverts commit 792446906c718a08f0870b58acbdf2cfdeb77770.

This commit was a failed part of an effort to split up D757. I'll need
to try again and make sure I build-test next time.

4 years agoClean up handling of knownKeyNames
Ben Gamari [Wed, 26 Aug 2015 15:58:25 +0000 (17:58 +0200)] 
Clean up handling of knownKeyNames

4 years agoBinIface: Clean up whitespace
Ben Gamari [Wed, 26 Aug 2015 15:56:06 +0000 (17:56 +0200)] 
BinIface: Clean up whitespace

4 years agoPrelNames: Clean up list a bit
Ben Gamari [Wed, 26 Aug 2015 15:50:33 +0000 (17:50 +0200)] 
PrelNames: Clean up list a bit

4 years agoTcDeriv: Kill dead code
Ben Gamari [Wed, 26 Aug 2015 15:46:22 +0000 (17:46 +0200)] 
TcDeriv: Kill dead code

4 years agotcRnDeclsi can use tcRnSrcDecls
Simon Peyton Jones [Mon, 23 Mar 2015 14:32:31 +0000 (14:32 +0000)] 
tcRnDeclsi can use tcRnSrcDecls

I'm not sure why tcRnDeclsi didn't call tcRnSrcDecls before, but now it
does.  About 20 lines of code vanish. Hooray.

4 years agoImplement lookupGlobal in TcEnv, and use it
Simon Peyton Jones [Fri, 20 Mar 2015 12:38:42 +0000 (12:38 +0000)] 
Implement lookupGlobal in TcEnv, and use it

This localises the (revolting) initTcForLookup function, exposing
instead the more civilised interface for lookupGlobal

4 years agoComments and white space
Simon Peyton Jones [Fri, 20 Mar 2015 12:36:22 +0000 (12:36 +0000)] 
Comments and white space

4 years agoFix algorithm.tex build and update with some new info.
Edward Z. Yang [Wed, 26 Aug 2015 17:16:05 +0000 (10:16 -0700)] 
Fix algorithm.tex build and update with some new info.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
4 years agoconfigure.ac: Allow disabling of large-address-space
Erik de Castro Lopo [Tue, 25 Aug 2015 01:33:32 +0000 (11:33 +1000)] 
configure.ac: Allow disabling of large-address-space

Recent changes (commit 0d1a8d09f4) for 64 bit platforms allowed GHC
to mmap one huge (currently 1 terrabyte) memory region from which to
do its own allocations. This is enabled by default, but it would be
nice (even just from the point of view of testing) to be able to
disable this at configure time.

Test Plan: configure and grep mk/config.h for USE_LARGE_ADDRESS_SPACE

Reviewers: austin, ezyang, bgamari, rwbarton

Subscribers: thomie

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

GHC Trac Issues: #10791

4 years agofix 64bit two-stage allocator on Solaris/AMD64 platform (#10790)
Karel Gardas [Tue, 25 Aug 2015 12:06:29 +0000 (14:06 +0200)] 
fix 64bit two-stage allocator on Solaris/AMD64 platform (#10790)

Test Plan: tested on Solaris 11/AMD64 when previous build failed

Reviewers: bgamari, austin, simonmar, gcampax, ezyang

Subscribers: thomie

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

4 years agoDelete ExtsCompat46 (#8330)
Thomas Miedema [Tue, 21 Jul 2015 12:59:55 +0000 (14:59 +0200)] 
Delete ExtsCompat46 (#8330)

We require ghc-7.8 to build HEAD (ghc-7.11).

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

4 years agoCheck options before warning about source imports.
Alex Rozenshteyn [Fri, 21 Aug 2015 19:42:16 +0000 (21:42 +0200)] 
Check options before warning about source imports.

Summary: Fixes T10637

Reviewers: austin, bgamari, thomie

Subscribers: dfordivam, simonpj, thomie

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

GHC Trac Issues: #10637

4 years agoBuild system: delete unused distrib/Makefile
Thomas Miedema [Sat, 15 Aug 2015 17:07:52 +0000 (19:07 +0200)] 
Build system: delete unused distrib/Makefile

4 years agoBuild system: simplify install.mk.in
Thomas Miedema [Sat, 15 Aug 2015 12:18:07 +0000 (14:18 +0200)] 
Build system: simplify install.mk.in

This will allow fixing #1851 more easily
("make install-strip" should work).

This reverts 57e2a81c589103b50da80a9e378b1a11285bd521:
  "On Cygwin, use a Cygwin-style path for /bin/install's destination"

Update submodule haddock and hsc2hs.

4 years agoRefactor: delete most of the module FastTypes
Thomas Miedema [Fri, 21 Aug 2015 08:44:54 +0000 (10:44 +0200)] 
Refactor: delete most of the module FastTypes

This reverses some of the work done in #1405, and goes back to the
assumption that the bootstrap compiler understands GHC-haskell.

In particular:
  * use MagicHash instead of _ILIT and _CLIT
  * pattern matching on I# if possible, instead of using iUnbox
    unnecessarily
  * use Int#/Char#/Addr# instead of the following type synonyms:
    - type FastInt   = Int#
    - type FastChar  = Char#
    - type FastPtr a = Addr#
  * inline the following functions:
    - iBox           = I#
    - cBox           = C#
    - fastChr        = chr#
    - fastOrd        = ord#
    - eqFastChar     = eqChar#
    - shiftLFastInt  = uncheckedIShiftL#
    - shiftR_FastInt = uncheckedIShiftRL#
    - shiftRLFastInt = uncheckedIShiftRL#
  * delete the following unused functions:
    - minFastInt
    - maxFastInt
    - uncheckedIShiftRA#
    - castFastPtr
    - panicDocFastInt and pprPanicFastInt
  * rename panicFastInt back to panic#

These functions remain, since they actually do something:
  * iUnbox
  * bitAndFastInt
  * bitOrFastInt

Test Plan: validate

Reviewers: austin, bgamari

Subscribers: rwbarton

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

GHC Trac Issues: #1405

4 years agoDelete FastBool
Thomas Miedema [Fri, 21 Aug 2015 08:38:06 +0000 (10:38 +0200)] 
Delete FastBool

This reverses some of the work done in Trac #1405, and assumes GHC is
smart enough to do its own unboxing of booleans now.

I would like to do some more performance measurements, but the code
changes can be reviewed already.

Test Plan:
With a perf build:
./inplace/bin/ghc-stage2 nofib/spectral/simple/Main.hs -fforce-recomp
+RTS -t --machine-readable

before:
```
  [("bytes allocated", "1300744864")
  ,("num_GCs", "302")
  ,("average_bytes_used", "8811118")
  ,("max_bytes_used", "24477464")
  ,("num_byte_usage_samples", "9")
  ,("peak_megabytes_allocated", "64")
  ,("init_cpu_seconds", "0.001")
  ,("init_wall_seconds", "0.001")
  ,("mutator_cpu_seconds", "2.833")
  ,("mutator_wall_seconds", "4.283")
  ,("GC_cpu_seconds", "0.960")
  ,("GC_wall_seconds", "0.961")
  ]
```

after:
```
  [("bytes allocated", "1301088064")
  ,("num_GCs", "310")
  ,("average_bytes_used", "8820253")
  ,("max_bytes_used", "24539904")
  ,("num_byte_usage_samples", "9")
  ,("peak_megabytes_allocated", "64")
  ,("init_cpu_seconds", "0.001")
  ,("init_wall_seconds", "0.001")
  ,("mutator_cpu_seconds", "2.876")
  ,("mutator_wall_seconds", "4.474")
  ,("GC_cpu_seconds", "0.965")
  ,("GC_wall_seconds", "0.979")
  ]
```

CPU time seems to be up a bit, but I'm not sure. Unfortunately CPU time
measurements are rather noisy.

Reviewers: austin, bgamari, rwbarton

Subscribers: nomeata

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

GHC Trac Issues: #1405

4 years agoImplement getSizeofMutableByteArrayOp primop
Ben Gamari [Fri, 21 Aug 2015 08:37:39 +0000 (10:37 +0200)] 
Implement getSizeofMutableByteArrayOp primop

Now since ByteArrays are mutable we need to be more explicit about when
the size is queried.

Test Plan: Add testcase and validate

Reviewers: goldfire, hvr, austin

Subscribers: thomie

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

GHC Trac Issues: #9447

4 years agoBag: Add Foldable instance
Ben Gamari [Tue, 18 Aug 2015 17:17:50 +0000 (19:17 +0200)] 
Bag: Add Foldable instance

4 years agoGhcMake: Fix spelling in comment
Ben Gamari [Tue, 18 Aug 2015 17:17:22 +0000 (19:17 +0200)] 
GhcMake: Fix spelling in comment

4 years agoDelete sync-all
Thomas Miedema [Thu, 20 Aug 2015 22:47:16 +0000 (00:47 +0200)] 
Delete sync-all

4 years agoBuild system: delete half-baked Cygwin support
Thomas Miedema [Sat, 15 Aug 2015 09:36:44 +0000 (11:36 +0200)] 
Build system: delete half-baked Cygwin support

We only support building GHC on mys2 nowadays, see
https://ghc.haskell.org/trac/ghc/wiki/Building/Preparation/Windows.

This (partially) reverts various commits from a few years ago, among which:
  * 5775d5142da227d65fb86994d363eb16841ee642
    "Add OSTYPE build-system variable, and use it"
  * 3fb8c431824aa2f3bd979e35d1a283546fcfbe74
    "Fix building libgmp on cygwin"
  * cdbb4720c424500adb57cbbef69721d0b039fa46
    "Fix cmd invocation by libffi cuild system on Windows 7 cygwin"
  * e8121501ee3549a35e954726ccfd871ac9d51f83
    "Fix dblatex and xml* tool detection on Windows"

Reviewed by: austin, Phyx

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

4 years agoComments reformating/corrections
Divam [Tue, 18 Aug 2015 16:08:26 +0000 (18:08 +0200)] 
Comments reformating/corrections

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

4 years agoAdd selectors for common fields (DataCon/PatSyn) to ConLike
Matthew Pickering [Tue, 18 Aug 2015 16:07:18 +0000 (18:07 +0200)] 
Add selectors for common fields (DataCon/PatSyn) to ConLike

When pattern synonyms were introduced a new sum type was used
in places where DataCon used to be used. PatSyn and DataCon share many
of the same fields, this patch adds selectors to ConLike for these
fields.

Reviewers: austin, goldfire, bgamari

Subscribers: thomie

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

4 years agorts/Printer.c: speed up '-Da' printer for 'LIBBFD' build
Sergei Trofimovich [Tue, 18 Aug 2015 16:06:41 +0000 (18:06 +0200)] 
rts/Printer.c: speed up '-Da' printer for 'LIBBFD' build

Patch switches from linear lookup in unordered array
to a hash table lookup.

When debugging GHC array contains 658_445 elements.

Found performance gap when tried to debug blackholes.

Signed-off-by: Sergei Trofimovich <siarheit@google.com>
Reviewers: simonmar, austin, bgamari

Subscribers: thomie

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

4 years agoFix rdynamic flag and test on Windows
Tamar Christina [Tue, 18 Aug 2015 15:59:04 +0000 (17:59 +0200)] 
Fix rdynamic flag and test on Windows

The rdynamic tests and feature are marked broken on windows.
This is because the flag used doesn't exist and the symbol lookup
in the test did not account for platform differences in name mangling.

This commit fixes the flag and tests for rdynamic on windows.

Test Plan:
make TEST="rdynamic"

on both x86 and x86_64

Reviewers: austin, thomie, bgamari

Reviewed By: thomie, bgamari

Subscribers: #ghc_windows_task_force

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

GHC Trac Issues: #9381

4 years agoDump files always use UTF8 encoding #10762
Michael Snoyman [Tue, 18 Aug 2015 15:58:36 +0000 (17:58 +0200)] 
Dump files always use UTF8 encoding #10762

When the Windows codepage or *nix LANG variable is something besides
UTF-8, dumping to file can cause GHC to exit currently. This changes the
output encoding for files to match the defined input encoding for
Haskell source code (UTF-8), making it easier for users and build tools
to capture this output.

Test Plan:
Create a Haskell source file with non-Latin characters for identifier
names and
compile with:

LANG=C ghc -ddump-to-file -ddump-hi filename.hs -fforce-recomp

Without this patch, it will fail. With this patch, it succeeds

Reviewers: austin, rwbarton, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

GHC Trac Issues: #10762

4 years agoTransliterate unknown characters at output
Michael Snoyman [Tue, 18 Aug 2015 15:58:02 +0000 (17:58 +0200)] 
Transliterate unknown characters at output

This avoids the compiler from crashing when, for example, a warning
contains a non-Latin identifier and the LANG variable is set to C.
Fixes #6037.

Test Plan:
Create a Haskell source file containing an identifier with non-Latin
characters and no type signature. Compile with `LANG=C ghc -Wall
foo.hs`, and it should fail. With this patch, it will succeed.

Reviewers: austin, rwbarton, bgamari

Subscribers: thomie

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

GHC Trac Issues: #6037, #10762

4 years agoMake rts/ThreadLabels.c threadsafe for debug runtime.
Sergei Trofimovich [Mon, 17 Aug 2015 22:14:42 +0000 (23:14 +0100)] 
Make rts/ThreadLabels.c threadsafe for debug runtime.

rts/ThreadLabels.c has a global hashtable for each
running haskell thread. It's not synchronized across
OS threads.

Was discovered when ran -debug build of ghc itself as:

    $ ghc-stage2 -j8 +RTS -A256M -l

and glibc detected double-free corruption:

    #2  in __libc_message (do_abort=do_abort@entry=2,
        fmt=fmt@entry=0x7fe0bcebf368 "*** Error in `%s': %s: 0x%s ***\n")
    #3  in malloc_printerr (action=3, str=0x7fe0bcebf4c0 "double free or corruption (fasttop)",
        ptr=<optimized out>)
    #4  in _int_free (av=<optimized out>, p=<optimized out>, have_lock=0)
    #5  in stgFree (p=0x7fe060001820) at rts/RtsUtils.c:108
    #6  in freeHashTable (table=0x5929320, freeDataFun=0x36374df <stgFree>) at rts/Hash.c:360
    #7  in freeThreadLabelTable () at rts/ThreadLabels.c:37
    #8  in hs_exit_ (wait_foreign=rtsFalse) at rts/RtsStartup.c:403
    #9  in shutdownHaskellAndExit (n=0, fastExit=0) at rts/RtsStartup.c:481
    #10 in hs_main (...) at rts/RtsMain.c:91
    #11 in main (...) at ghc/hschooks.c:63

Exposed itself after commit:

> commit f6866824ce5cdf5359f0cad78c49d65f6d43af12
> Author: Sergei Trofimovich <slyfox@gentoo.org>
> Date:   Mon Aug 4 08:10:33 2014 -0500
>
>     ghc --make: add nicer names to RTS threads (threaded IO manager, make workers)

Signed-off-by: Sergei Trofimovich <siarheit@google.com>
Reviewers: austin, simonmar, ezyang, bgamari

Reviewed By: ezyang, bgamari

Subscribers: thomie

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

4 years agoTravis: prevent 10' no output, by setting VERBOSE=2
Thomas Miedema [Mon, 17 Aug 2015 12:31:07 +0000 (14:31 +0200)] 
Travis: prevent 10' no output, by setting VERBOSE=2

4 years agoTestsuite: speedup running a single test
Thomas Miedema [Sat, 15 Aug 2015 19:10:32 +0000 (21:10 +0200)] 
Testsuite: speedup running a single test

Benchmark: in rootdirectory, run `time make test TEST=dummy VERBOSE=0`
Before this commit: 2.6s
After this commit: 0.7s

4 years agoTestsuite: recenter 2 performance tests on Windows
Thomas Miedema [Fri, 14 Aug 2015 10:05:20 +0000 (12:05 +0200)] 
Testsuite: recenter 2 performance tests on Windows

No major deviations. Also fixup T7861.

4 years agoTestsuite: mark encoding005 expect_broken(#10623) on Windows
Thomas Miedema [Sat, 15 Aug 2015 14:55:26 +0000 (16:55 +0200)] 
Testsuite: mark encoding005 expect_broken(#10623) on Windows

4 years agoTestsuite: mark T8089 expect_broken(#7325) on Windows
Thomas Miedema [Sat, 15 Aug 2015 14:33:33 +0000 (16:33 +0200)] 
Testsuite: mark T8089 expect_broken(#7325) on Windows

4 years agoName: Show NameSort in warning
Ben Gamari [Thu, 13 Aug 2015 18:18:56 +0000 (20:18 +0200)] 
Name: Show NameSort in warning

This is quite useful information to know. Spotted when looking at #10769.

4 years agoDynFlags: Prohibit hpc and byte-code interpreter
Ben Gamari [Thu, 13 Aug 2015 18:17:06 +0000 (20:17 +0200)] 
DynFlags: Prohibit hpc and byte-code interpreter

The user's guide says hpc is incompatible with GHCi and #9903 would
agree. Fixes #9903.

4 years agoSysTools: Fix whitespace in error message
Ben Gamari [Wed, 12 Aug 2015 14:31:46 +0000 (16:31 +0200)] 
SysTools: Fix whitespace in error message

4 years agoUpdate mingw tarball location
Ben Gamari [Wed, 12 Aug 2015 12:06:37 +0000 (14:06 +0200)] 
Update mingw tarball location

4 years agoUpgrade GCC to 5.2.0 for Windows x86 and x86_64
Tamar Christina [Wed, 12 Aug 2015 11:33:13 +0000 (13:33 +0200)] 
Upgrade GCC to 5.2.0 for Windows x86 and x86_64

This patch does a few things

- Moved GHC x86 to MinGW-w64 (Using Awson's patch)
- Moves Both GHCs to MSYS2 toolchains
- Completely removes the dependencies on the git tarball repo
  - Downloads only the required tarball for the architecture for
    which we are building
  - Downloads the perl tarball is missing as well
  - Fixed a few bugs in the linker to fix tests on Windows

The links currently point to repo.msys2.org and GitHub, it might be
more desirable to mirror them on
http://downloads.haskell.org/~ghc/mingw/ as with the previous patch
attempt.

For more details on what the MSYS2 packages I include see #10726
(Awson's comment). but it should contain all we need
and no python or fortran, which makes the uncompressed tar a 1-2
hundreds mb smaller.

The `GCC 5.2.0` in the package supports `libgcc` as a shared library,
this is a problem since
when compiling with -shared the produced dll now has a dependency on
`libgcc_s_sjlj-1.dll`.
To solve this the flag `-static-libgcc` is now being used for all GCC
calls on windows.

Test Plan:
./validate was ran both on x86 and x86_64 windows and compared against
the baseline.

A few test were failing due to Ld no longer being noisy. These were
updated.

The changes to the configure script *should* be validated by the build
bots for the other platforms before landing

Reviewers: simonmar, awson, bgamari, austin, thomie

Reviewed By: thomie

Subscribers: #ghc_windows_task_force, thomie, awson

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

GHC Trac Issues: #10726, #9014, #9218, #10435

4 years agotemplate-haskell: Add changelog entry to infix type operators
Ben Gamari [Wed, 12 Aug 2015 11:32:08 +0000 (13:32 +0200)] 
template-haskell: Add changelog entry to infix type operators

4 years agoPretty: improving the space/time performance of vcat, hsep, hcat (#10735)
Thomas Miedema [Wed, 5 Aug 2015 08:31:46 +0000 (10:31 +0200)] 
Pretty: improving the space/time performance of vcat, hsep, hcat (#10735)

After 5d57087e314bd484dbe14958f9b422be3ac6641a ("Pretty: fix a broken
invariant"), T3294 showed 50% more max_bytes_used (#3294). After this
commit, max_bytes_used is back to what it was before, and the test
passes again.

This is a backport of a bug fix by Benedikt Huber (#2393), from commit
1e50748beaa4bd2281d323b18ea51c786bba04a1 in the pretty library.

From https://mail.haskell.org/pipermail/libraries/2008-June/009991.html:

    vcat (hsep,cat) is implemented in an unneccessarily strict way.
    We only get some output after all of vcat's arguments are evaluated
    and checked against being Empty.
    This can be improved by only checking the right argument of foldr
    against being Empty, and
    then applying an Empty-filter on the resulting Doc. Space improvement
    is obvious.
    The microbenchmark (code.haskell.org/~bhuber/Text/PrettyPrint/
    HughesPJPerfCheck.hs) suggests that
    the improvements in time are remarkable too.

4 years agoPretty: show rational as is (#10735)
Thomas Miedema [Wed, 5 Aug 2015 11:17:56 +0000 (13:17 +0200)] 
Pretty: show rational as is (#10735)

Following libraries/pretty. I'm not sure why it converted to Double
before.

This function isn't used by GHC itself. It is exported from these two
places:
  * compiler/utils/Outputable
  * libraries/template-haskell/Language/Haskell/TH/PprLib.hs

4 years agoPretty: fix a broken invariant (#10735)
Thomas Miedema [Wed, 5 Aug 2015 09:31:21 +0000 (11:31 +0200)] 
Pretty: fix a broken invariant (#10735)

This is a backport of a bug fix from
6cfbd0444981c074bae10a3cf72733bcb8597bef in libraries/pretty:

    Fix a broken invariant
    Patch from #694,  for the problem "empty is an identity for <> and $$" is
    currently broken by eg. isEmpty (empty<>empty)"

4 years agoPretty: fix potential bad formatting of error message (#10735)
Thomas Miedema [Wed, 5 Aug 2015 08:58:54 +0000 (10:58 +0200)] 
Pretty: fix potential bad formatting of error message (#10735)

This is a backport of a bug fix by Benedikt Huber for the same problem
in the pretty library (#1337), from commit
8d8866a8379c2fe8108ef034893c59e06d5e752f. The original explanation for
the fix is attached below.

Ticket #1776 originally reported an infinite loop when printing error
message. This promptly got fixed in:

  commit 2d52ee06786e5caf0c2d65a4b4bb7c45c6493190
  Author: simonpj@microsoft.com <unknown>
  Date:   Thu Mar 1 11:45:13 2007 +0000

      Do not go into an infinite loop when pretty-printer finds a
      negative indent (Trac #1176)

SPJ reports in the ticket: "So infinite loop is fixed, but the bad
formatting remains. I've added a test, tcfail177."

tcfail177 however hasn't triggered the formatting problem for years (as
Ian reported in c9e0e6067a47c574d9ff3721afe58e30ca1be3e4).

This patch updates the test to a version that at least still failed with
ghc-7.0 (from #1776#comment:7).

-------------------

From https://mail.haskell.org/pipermail/libraries/2008-June/010013.html,
by Benedikt Huber:

    Concerning ticket #1337, we have to change the formal specification of
    fill (it doesn't match the implementation):

    -- Current Specification:
    --   fill []  = empty
    --   fill [p] = p
    --   fill (p1:p2:ps) = oneLiner p1 <#> nest (length p1)
    --                                          (fill (oneLiner p2 : ps))
    --                     `union`
    --                      p1 $$ fill ps

    Problem 1: We want to `unnest' the second argument of (p1 $$ fill ps),
    but not the first one

    In the definition above we have e.g.

    > getSecondLayout $
    >   fillDef False [text "a", text "b", text "a"]

    >> text "ab"; nilabove; nest -1; text "a"; empty
    >> |ab|
    >> |.a|

    Problem 2: The overlapping $$ should only be used for those layouts of
    p1 which aren't one liners (otherwise violating the invariant "Left
    union arg has shorter first line").

    I suggest the following specification (i believe it almost matches the
    current implementation, modulo [fillNB: fix bug #1337] (see below):

    -- Revised Specification:
    --   fill g docs = fill' 0 docs
    --   gap g       = if g then 1 else 0
    --   fill' n []  = []
    --   fill' n [p] = [p]
    --   fill' n (p1:p2:ps) =
    --      oneLiner p1 <g> (fill' (n+length p1+gap g) (oneLiner p2 : ps))
    --        `union`
    --     (p1 $*$ nest (-n) (fill' g ps))
    --
    -- $*$ is defined for layouts (One-Layout Documents) as
    --
    -- layout1 $*$ layout2 | isOneLiner layout1 = layout1 $+$ layout2
    --                     | otherwise          = layout1 $$ layout2

    I've also implemented the specification in HughesPJQuickCheck.hs,
    and checked them against the patched pretty printer.

    Concerning Bug #1337:
    ~~~~~~~~~~~~~~~~~~~~~

    If the above formal specification is fine, it is easy to fix:
    elide the nests of (oneLiner p2) [see attached patch, record bug #1337].

    > PrettyPrint(0) $ ./Bug1337
    > ....ab
    > ...c

    The (long) explanation follows below.

    <snip/>

    ===========================================================
    Explanation of Bug #1337:

    Consider

    > fcat [ nest 1 $ text "a", nest 2 $ text "b", text "c"]

    --> expected: (nest 1; text "a"; text "b"; nest -3; "c")
    --> actual  : (nest 1; text "a"; text "b"; nest -5; "c")

    Reduction:
    === (nest 1; text a) <> (fill (-2) (p2:ps))
    ==>                     (nest 2 (text "b") $+$ text "c")
    ==>                     (nest 2 (text "b")) `nilabove`
                            (nest (-3) (text "c"))
    ==> (nest 1; text a; text b; nest -5 c)

    The problem is that if we decide to layout (p1:p2:ps) as

    | p1 p2
    | ps

    (call it layout A), then we want to have

    > (p1 <> p2) $+$ ps.

    But following law <n6> this means that

    > fcat_A [p1:nest k p2:ps]

    is equivalent to

    > fcat_A [p1,p2,ps]

    so the nest of p2 has to be removed.

    This is somewhat similar to bug #667, but easier to fix
    from a semantic point of view:
    p1,p2 and ps are distinct layouts - we only have to preserve the
    individual layouts, and no combinations of them.