ghc.git
3 years agocleanup: drop 11 years old performance hack
Sergei Trofimovich [Sun, 4 Sep 2016 21:08:27 +0000 (22:08 +0100)] 
cleanup: drop 11 years old performance hack

The 'return () >>' hack was added in commit
    commit ac88f113abdec1edbffb6d2f97323e81f82908e7
    Date:   Tue Jul 26 12:14:03 2005 +0000

Nowadays it has no effect on generated Core on -O1/-O2
and slightly bloats Core on -O0.

Signed-off-by: Sergei Trofimovich <siarheit@google.com>
3 years agoaccept current (problematic) output
Gabor Greif [Sun, 4 Sep 2016 10:38:40 +0000 (12:38 +0200)] 
accept current (problematic) output

3 years agotest #12567: add new testcase with expected plugin behaviour
Gabor Greif [Sun, 4 Sep 2016 10:13:54 +0000 (12:13 +0200)] 
test #12567: add new testcase with expected plugin behaviour

3 years agoFix comment about result
Gabor Greif [Sat, 3 Sep 2016 15:10:49 +0000 (17:10 +0200)] 
Fix comment about result

3 years agoTypo in comment
Gabor Greif [Sat, 3 Sep 2016 12:44:48 +0000 (14:44 +0200)] 
Typo in comment

3 years agoextend '-fmax-worker-args' limit to specialiser (Trac #11565)
Sergei Trofimovich [Fri, 2 Sep 2016 17:47:56 +0000 (18:47 +0100)] 
extend '-fmax-worker-args' limit to specialiser (Trac #11565)

It's a complementary change to
    a48de37dcca98e7d477040b0ed298bcd1b3ab303
    restore -fmax-worker-args handling (Trac #11565)

I don't have a small example but I've noticed another
discrepancy when was profiling GHC for performance

    cmmExprNative :: ReferenceKind -> CmmExpr -> CmmOptM CmmExpr

was specialised by 'spec_one' down to a function with arity 159.
As a result 'perf record' pointed at it as at slowest
function in whole ghc library.

I've extended -fmax-worker-args effect to 'spec_one'
as it does the same worker/wrapper split to push
arguments to the heap.

The change decreases heap usage on a synth.bash benchmark
(Trac #9221) from 67G down to 64G (-4%). Benchmark runtime
decreased from 14.5 s down to 14.s (-7%).

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

Subscribers: thomie

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

GHC Trac Issues: #11565

3 years agoghc-cabal: accept EXTRA_HC_OPTS make variable
Sergei Trofimovich [Fri, 2 Sep 2016 17:04:03 +0000 (18:04 +0100)] 
ghc-cabal: accept EXTRA_HC_OPTS make variable

Signed-off-by: Sergei Trofimovich <siarheit@google.com>
3 years agoProtect StablPtr dereference with the StaticPtr table lock.
Facundo Domínguez [Thu, 1 Sep 2016 19:31:26 +0000 (16:31 -0300)] 
Protect StablPtr dereference with the StaticPtr table lock.

Summary: Also comment on the need to use stgMallocBytes in StaticPtrTable.c.

Test Plan: ./validate

Reviewers: erikd, austin, bgamari, simonmar

Reviewed By: simonmar

Subscribers: thomie

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

3 years agoTypos in notes
ggreif [Mon, 15 Jun 2015 16:10:24 +0000 (18:10 +0200)] 
Typos in notes

3 years agoFix #10923 by fingerprinting optimization level.
Edward Z. Yang [Thu, 1 Sep 2016 22:28:07 +0000 (15:28 -0700)] 
Fix #10923 by fingerprinting optimization level.

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

Reviewers: simonmar, austin, bgamari, thomie, rwbarton

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

GHC Trac Issues: #10923

3 years agoconfigure.ac: fix --host= handling
Sergei Trofimovich [Fri, 2 Sep 2016 07:35:25 +0000 (08:35 +0100)] 
configure.ac: fix --host= handling

The following command fails as:
    $ ./configure --prefix=/usr \
        --build=x86_64-pc-linux-gnu \
        --host=x86_64-pc-linux-gnu \
        --target=x86_64-pc-linux-gnu
    configure: error:
    You've selected:

      BUILD:  x86_64-unknown-linux
      HOST:   x86_64-unknown-linux
      TARGET: x86_64-unknown-linux

    BUILD must equal HOST;

18f06878ed5d8cb0cf366a876f2bfea29647e5f0 changed native
configure $build/$host/$target checks to ghc-mangled ones,
but not completely.

Signed-off-by: Sergei Trofimovich <siarheit@google.com>
Reviewers: rwbarton, erikd, austin, hvr, bgamari, Phyx

Reviewed By: Phyx

Subscribers: thomie

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

GHC Trac Issues: #12487

3 years agoAdded support for deprecated POSIX functions on Windows.
Tamar Christina [Thu, 1 Sep 2016 20:30:07 +0000 (21:30 +0100)] 
Added support for deprecated POSIX functions on Windows.

Summary:
With the introduction of 8.0.1 We've stopped supporting in GHCi
the use of POSIX functions under their deprecated names on Windows.

This to be compatible with object and libraries from the most
popular compilers on the platform (Microsoft and Intel compilers).

However this brings a confusing disparity between the compiled and
interpreted behavior since MingW-W64 does support the deprecated names.

Also It seems clear that package writers won't update their packages to
properly support Windows. As such I have added redirects in the RTS
for the deprecated functions as listed on

https://msdn.microsoft.com/en-us/library/ms235384.aspx.

This won't export the functions (as in, they won't be in the symbol table
of compiled code for the RTS.) but we inject them into the symbol table
of the dynamic linker at startup.

Test Plan:
./validate
and

make test TEST="ffi017 ffi021"

Reviewers: thomie, simonmar, RyanGlScott, bgamari, austin, hvr, erikd

Reviewed By: simonmar, bgamari

Subscribers: RyanGlScott, #ghc_windows_task_force

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

GHC Trac Issues: #12209, #12497, #12496

3 years agoFix startsVarSym and refactor operator predicates (fixes #4239)
Malo Jaffré [Thu, 1 Sep 2016 18:13:47 +0000 (14:13 -0400)] 
Fix startsVarSym and refactor operator predicates (fixes #4239)

startsVarSym used isSymbol which does not recognize valid operators
beginning with OtherPunctuation generalCategory (e. g. (·)).
Move it to ghc-boot-th for reducing duplication.

This patch fixes template-haskell pretty printer, which is used by
-ddump-minimal-imports.

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

GHC Trac Issues: #4239

3 years agoRevert "Fix startsVarSym and refactor operator predicates (fixes #4239)"
Ben Gamari [Thu, 1 Sep 2016 19:03:46 +0000 (15:03 -0400)] 
Revert "Fix startsVarSym and refactor operator predicates (fixes #4239)"

This reverts commit 8d35e18d885e60f998a9dddb6db19762fe4c6d92.
arc butchered the authorship on this.

3 years agoFix startsVarSym and refactor operator predicates (fixes #4239)
Ben Gamari [Thu, 1 Sep 2016 18:13:47 +0000 (14:13 -0400)] 
Fix startsVarSym and refactor operator predicates (fixes #4239)

startsVarSym used isSymbol which does not recognize valid operators
beginning with OtherPunctuation generalCategory (e. g. (·)).
Move it to ghc-boot-th for reducing duplication.

This patch fixes template-haskell pretty printer, which is used by
-ddump-minimal-imports.

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

GHC Trac Issues: #4239

3 years agoKill vestiages of DEFAULT_TMPDIR
Ben Gamari [Thu, 1 Sep 2016 16:13:18 +0000 (12:13 -0400)] 
Kill vestiages of DEFAULT_TMPDIR

It was removed long ago in cf403b50900648063d99afa160d2091a7d6f58c1.
Thanks for @rwbarton for catching this.

Updates nofib submodule.

Test Plan: Validate

Reviewers: austin, rwbarton

Subscribers: thomie, rwbarton

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

GHC Trac Issues: #12443

3 years agorestore -fmax-worker-args handling (Trac #11565)
Sergei Trofimovich [Thu, 1 Sep 2016 16:34:58 +0000 (17:34 +0100)] 
restore -fmax-worker-args handling (Trac #11565)

maxWorkerArgs handling was accidentally lost 3 years ago
in a major update of demand analysis
    commit 0831a12ea2fc73c33652eeec1adc79fa19700578

Old regression is noticeable as:
- code bloat (requires stack reshuffling)
- compilation slowdown (more code to optimise/generate)
- and increased heap usage (DynFlags unboxing/reboxing?)

On a simple compile benchmark this change causes heap
allocation drop from 70G don to 67G (ghc perf build).

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

Reviewed By: simonpj, ezyang

Subscribers: thomie

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

GHC Trac Issues: #11565

3 years agousers_guide: Move initGhcMonad note to 8.0.2 relnotes
Ben Gamari [Thu, 1 Sep 2016 05:06:25 +0000 (01:06 -0400)] 
users_guide: Move initGhcMonad note to 8.0.2 relnotes

3 years agousers_guide: Move -fdefer-out-of-scope-variables note to 8.0.2 relnotes
Ben Gamari [Wed, 31 Aug 2016 21:14:42 +0000 (17:14 -0400)] 
users_guide: Move -fdefer-out-of-scope-variables note to 8.0.2 relnotes

It will be included in 8.0.2

3 years agousers_guide: Move addModFinalizer mention to 8.0.2 release notes
Ben Gamari [Wed, 31 Aug 2016 21:03:46 +0000 (17:03 -0400)] 
users_guide: Move addModFinalizer mention to 8.0.2 release notes

3 years agousers_guide: Document removal of -Wredundant-constraints from -Wall
Ben Gamari [Wed, 31 Aug 2016 20:42:53 +0000 (16:42 -0400)] 
users_guide: Document removal of -Wredundant-constraints from -Wall

3 years agoRevert "testsuite: Update bytes allocated of parsing001"
Ben Gamari [Thu, 1 Sep 2016 14:23:20 +0000 (10:23 -0400)] 
Revert "testsuite: Update bytes allocated of parsing001"

This reverts commit ca6d0eb0f7d28b0245abc2b0783141101e51945f.

I'm really not sure what happened with the test build that lead me to
believe that this was necessary. Mysterious.

3 years agoLoadIFace: Show known names on inconsistent interface file
Ben Gamari [Wed, 31 Aug 2016 20:04:11 +0000 (16:04 -0400)] 
LoadIFace: Show known names on inconsistent interface file

Reviewers: austin

Subscribers: simonpj, ezyang, thomie

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

3 years agoRnExpr: Fix ApplicativeDo desugaring with RebindableSyntax
Ben Gamari [Wed, 31 Aug 2016 20:03:33 +0000 (16:03 -0400)] 
RnExpr: Fix ApplicativeDo desugaring with RebindableSyntax

We need to compare against the local return and pure, not returnMName
and pureAName.

Fixes #12490.

Test Plan: Validate, add testcase

Reviewers: austin, simonmar

Reviewed By: simonmar

Subscribers: thomie

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

GHC Trac Issues: #12490

3 years agoRemove redundant-constraints from -Wall (#10635)
Adam C. Foltzer [Wed, 31 Aug 2016 20:02:53 +0000 (16:02 -0400)] 
Remove redundant-constraints from -Wall (#10635)

Removes -Wredundant-constraints from -Wall, as per the
discussion in #10635.

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

GHC Trac Issues: #10635

3 years agoAdd -fdefer-out-of-scope-variables flag (#12170).
Eugene Akentyev [Wed, 31 Aug 2016 20:02:10 +0000 (16:02 -0400)] 
Add -fdefer-out-of-scope-variables flag (#12170).

Reviewers: simonpj, thomie, austin, bgamari

Reviewed By: simonpj, thomie, bgamari

Subscribers: simonpj, thomie

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

GHC Trac Issues: #12170

3 years agotestsuite: Update bytes allocated of parsing001
Ben Gamari [Wed, 31 Aug 2016 20:16:25 +0000 (16:16 -0400)] 
testsuite: Update bytes allocated of parsing001

Sadly I don't know precisely which commit regressed this, but it was
quite recent. I'm not sure how this wasn't caught by my test builds.

3 years agoPPC NCG: Implement minimal stack frame header.
Peter Trommler [Wed, 31 Aug 2016 19:18:06 +0000 (15:18 -0400)] 
PPC NCG: Implement minimal stack frame header.

According to the ABI specifications a minimal stack frame consists
of a header and a minimum size parameter save area. We reserve the
minimal size for each ABI.

On PowerPC 64-bil Linux and AIX the parameter save area can accomodate
up to eight parameters. So calls with eight parameters and fewer
can be done without allocating a new stack frame and deallocating
that stack frame after the call. On AIX one additional spill slot
is available on the stack.

Code size for all nofib benchmarks is 0.3 % smaller on powerpc64.

Test Plan: validate on AIX

Reviewers: hvr!, erikd, austin, simonmar, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

3 years agoAdd -flocal-ghci-history flag (#9089).
Eugene Akentyev [Wed, 31 Aug 2016 18:31:39 +0000 (14:31 -0400)] 
Add -flocal-ghci-history flag (#9089).

Reviewers: thomie, bgamari, austin

Reviewed By: thomie, bgamari

Subscribers: thomie

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

GHC Trac Issues: #9089

3 years agoAdd Read1/Read2 methods defined in terms of ReadPrec
Ryan Scott [Wed, 31 Aug 2016 18:30:57 +0000 (14:30 -0400)] 
Add Read1/Read2 methods defined in terms of ReadPrec

This adds new methods `liftReadList(2)` and `liftReadListPrec(2)` to the
`Read1`/`Read2` classes which are defined in terms of `ReadPrec` instead
of `ReadS`. This also adds related combinators and changes existing
`Read1` and `Read2` instances to be defined in terms of the new methods.

Reviewers: hvr, austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

GHC Trac Issues: #12358

3 years agoTysWiredIn: Use dataConWorkerUnique instead of incrUnique
Ben Gamari [Wed, 31 Aug 2016 17:53:04 +0000 (13:53 -0400)] 
TysWiredIn: Use dataConWorkerUnique instead of incrUnique

Test Plan: Validate

Reviewers: austin

Subscribers: thomie

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

3 years agoA failing testcase for T12485
Bartosz Nitka [Wed, 31 Aug 2016 17:52:35 +0000 (13:52 -0400)] 
A failing testcase for T12485

Test Plan: it's just a testcase

Reviewers: ezyang, simonmar, bgamari, austin

Subscribers: thomie

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

GHC Trac Issues: #12485

3 years agoErrUtils: Expose accessors of ErrDoc and ErrMsg
Ben Gamari [Wed, 31 Aug 2016 17:50:30 +0000 (13:50 -0400)] 
ErrUtils: Expose accessors of ErrDoc and ErrMsg

Test Plan: Validate

Reviewers: austin

Subscribers: thomie

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

GHC Trac Issues: #12206

3 years agotestsuite: Failing testcase for #12091
Ben Gamari [Wed, 31 Aug 2016 17:49:24 +0000 (13:49 -0400)] 
testsuite: Failing testcase for #12091

Just as it says on the can

Test Plan: validate

Reviewers: austin

Subscribers: thomie

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

GHC Trac Issues: #12091

3 years agoClarify scope of `getQ`/`putQ` state.
Francesco Mazzoli [Tue, 30 Aug 2016 21:09:16 +0000 (17:09 -0400)] 
Clarify scope of `getQ`/`putQ` state.

The current haddocks do not specify the scope of the state manipulated
by `getQ`/`putQ`.

Reviewers: austin, goldfire, bgamari, ezyang

Reviewed By: ezyang

Subscribers: ezyang, thomie

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

3 years agoStgCmmPrim: Add missing MO_WriteBarrier
Ben Gamari [Tue, 30 Aug 2016 21:08:05 +0000 (17:08 -0400)] 
StgCmmPrim: Add missing MO_WriteBarrier

Test Plan: Good question

Reviewers: austin, trommler, simonmar, rrnewton

Reviewed By: simonmar

Subscribers: RyanGlScott, thomie

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

GHC Trac Issues: #12469

3 years agoBump the default allocation area size to 1MB
Simon Marlow [Tue, 30 Aug 2016 21:07:36 +0000 (17:07 -0400)] 
Bump the default allocation area size to 1MB

This is long overdue.

Perhaps 1MB is a little on the skinny size, but this is based on
* A lot of commodity dual-core desktop processors have 3MB L3 cache
* We're traditionally quite frugal with memory by default

Test Plan: validate

Reviewers: erikd, bgamari, hvr, austin, rwbarton, ezyang

Reviewed By: ezyang

Subscribers: thomie

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

3 years agoiserv: Show usage message on argument parse failure
Ben Gamari [Tue, 30 Aug 2016 21:06:08 +0000 (17:06 -0400)] 
iserv: Show usage message on argument parse failure

Test Plan: validate

Reviewers: simonmar, erikd, austin

Reviewed By: simonmar, erikd

Subscribers: thomie, erikd

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

GHC Trac Issues: #12491

3 years agoGHC: Expose installSignalHandlers, withCleanupSession
Ben Gamari [Tue, 30 Aug 2016 21:05:43 +0000 (17:05 -0400)] 
GHC: Expose installSignalHandlers, withCleanupSession

Test Plan: Validate

Reviewers: austin, simonmar

Reviewed By: simonmar

Subscribers: thomie

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

GHC Trac Issues: #12398

3 years agousers_guide: More capabilities than processors considered harmful
Ben Gamari [Tue, 30 Aug 2016 21:05:25 +0000 (17:05 -0400)] 
users_guide: More capabilities than processors considered harmful

Test Plan: None.

Reviewers: austin, simonmar

Reviewed By: simonmar

Subscribers: thomie

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

3 years agoFixes #12504: Double-escape paths used to build call to hsc_line
Richard Cook [Tue, 30 Aug 2016 21:00:36 +0000 (17:00 -0400)] 
Fixes #12504: Double-escape paths used to build call to hsc_line

In outHsLine, paths passed to construct invocations of hsc_line must be
escaped twice in order to generate a properly escaped string literal
that will end up in the eventual LINE pragma emitted by this code. This
is especially important on Windows paths, where backslashes would
otherwise be treated as C escape sequences and result in the incorrect
Windows paths.

Adds test case to verify that hsc2hs properly escapes file paths in LINE
pragmas

Updates the hsc2hs submodule.

See https://ghc.haskell.org/trac/ghc/ticket/12504

Reviewers: erikd, hvr, austin, bgamari, Phyx

Reviewed By: erikd, Phyx

Subscribers: thomie, Phyx, mpickering

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

GHC Trac Issues: #12504

3 years agoFix handling of package-db entries in .ghc.environment files, etc.
Duncan Coutts [Tue, 30 Aug 2016 20:59:17 +0000 (16:59 -0400)] 
Fix handling of package-db entries in .ghc.environment files, etc.

Previously interpreting the content of the .ghc.env files was done
after the step that loaded the available package dbs. This meant that
setting the package db flags was ineffective. This patch moves
interpreting the env files before loading of the package dbs.

Also, the package-db entries refer to files. Allow spaces in these file
names. Also treat as comments lines beginning with "--".

These are pretty minor fixes in a feature that up 'til now has been
essentially unused (witness no bug report about it), so there's very
low risk here. If we can get this into 8.0.2 then cabal can start
generating the .ghc.environment files, otherwise it cannot as it needs
the working package-db entries, to be able to refer to local package
dbs in the build tree (or cabal nix store).

Test Plan:
Manually create example .ghc.env files
run ghci; :show packages
Done this. It works.

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

3 years agoTag pointers in interpreted constructors
mniip [Tue, 30 Aug 2016 20:57:47 +0000 (16:57 -0400)] 
Tag pointers in interpreted constructors

Instead of stg_interp_constr_entry there are now 7 functions (one for
each value of the tag bits) that tag the constructor pointer before
returning. This is consistent with compiled constructors' entry code,
and expectations that compiled code places on compiled constructors. The
iserv protocol is extended with an extra field that explains what
pointer tag the constructor should use.

Test Plan: Added tests for #12523

Reviewers: erikd, bgamari, hvr, austin, simonmar

Reviewed By: simonmar

Subscribers: osa1, thomie, rwbarton

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

GHC Trac Issues: #12523

3 years agoFix binary-trees regression from unnecessary floating in CorePrep.
Edward Z. Yang [Tue, 30 Aug 2016 20:55:58 +0000 (16:55 -0400)] 
Fix binary-trees regression from unnecessary floating in CorePrep.

In the previous patch, I handled lazy @(Int -> Int) f x
correctly, but failed to handle lazy @Int (f x) (we need
to collect arguments in f x).

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

Reviewers: simonpj, austin, bgamari, nomeata

Reviewed By: nomeata

Subscribers: simonmar, thomie

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

3 years agoClarify pkg selection when multiple versions are available
Harendra Kumar [Tue, 30 Aug 2016 20:55:08 +0000 (16:55 -0400)] 
Clarify pkg selection when multiple versions are available

Reviewers: austin, bgamari, ezyang

Reviewed By: ezyang

Subscribers: thomie

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

3 years agoFix and complete runghc documentation
Harendra Kumar [Tue, 30 Aug 2016 20:54:30 +0000 (16:54 -0400)] 
Fix and complete runghc documentation

Reviewers: austin, thomie, bgamari

Reviewed By: bgamari

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

GHC Trac Issues: #12517

3 years agoTcGenDeriv: Typofix
Ryan Scott [Tue, 30 Aug 2016 15:05:14 +0000 (11:05 -0400)] 
TcGenDeriv: Typofix

I think someone accidentally a word in a Note in TcGenDeriv.

3 years agoOccName: Remove unused DrIFT directive
Ryan Scott [Tue, 30 Aug 2016 15:02:01 +0000 (11:02 -0400)] 
OccName: Remove unused DrIFT directive

3 years agorts: enable parallel GC scan of large (32M+) allocation area
Sergei Trofimovich [Tue, 30 Aug 2016 11:10:54 +0000 (12:10 +0100)] 
rts: enable parallel GC scan of large (32M+) allocation area

Parallel GC does not scan large allocation area (-A)
effectively as it does not do work stealing from nursery
by default.

That leads to large imbalance when only one of threads
overflows allocation area: most of GC threads finish
quickly (as there is not much to collect) and sit idle
waiting while single GC thread finishes scan of single
allocation area for that thread.

The patch enables work stealing for (equivalent of -qb0)
allocation area of -A32M or higher.

Tested on a highlighting-kate package from Trac #9221

On 8-core machine the difference is around 5% faster
of wall-clock time. On 24-core VM the speedup is 20%.

Signed-off-by: Sergei Trofimovich <siarheit@google.com>
Test Plan: measured wall time and GC parallelism on highlighting-kate build

Reviewers: austin, bgamari, erikd, simonmar

Reviewed By: bgamari, simonmar

Subscribers: thomie

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

GHC Trac Issues: #9221

3 years agoGhcMake: limit Capability count to CPU count in parallel mode
Sergei Trofimovich [Tue, 30 Aug 2016 11:10:47 +0000 (12:10 +0100)] 
GhcMake: limit Capability count to CPU count in parallel mode

In Trac #9221 one of problems using high --jobs=<N>
is amount of mutator (or GC) threads we crate.

We use userspace spinning-and-yielding (see ACQUIRE_SPIN_LOCK)
to acess work stealing queues. In case of
N-worker-threads > N-CPUs fraction of time when
thread holding spin lock gets descheduled by kernel
increases. That causes other threads to waste CPU time
before giving up CPU.

Signed-off-by: Sergei Trofimovich <siarheit@google.com>
Test Plan:
ghc --make -j8 and -j80 have comparable sys time
on a 8-core system.

Reviewers: austin, gintas, bgamari, simonmar

Reviewed By: bgamari, simonmar

Subscribers: thomie

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

GHC Trac Issues: #9221

3 years agoMissing stderr for T12531.
Edward Z. Yang [Tue, 30 Aug 2016 09:43:38 +0000 (02:43 -0700)] 
Missing stderr for T12531.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
3 years agoRemove unused DerivInst constructor for DerivStuff
Ryan Scott [Mon, 29 Aug 2016 19:26:53 +0000 (15:26 -0400)] 
Remove unused DerivInst constructor for DerivStuff

Summary:
Back when derived `Generic` instances used to generate auxiliary datatypes,
they would also generate instances for those datatypes. Nowadays, GHC generics
uses a `DataKinds`-based encoding that requires neither auxiliary datatypes
(corresponding to the `DerivTyCon` constructor of `DerivStuff`) nor instances
for them (the `DerivInst` constructor of `DerivStuff`). It appears that
`DerivTyCon` constructor was removed at some point, but `DerivInst` never was.

No `DerivInst` values are ever constructed, so we can safely remove it.

Test Plan: It builds

Reviewers: austin, hvr, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

3 years agoFix broken Haddock comment
Ryan Scott [Mon, 29 Aug 2016 14:35:37 +0000 (10:35 -0400)] 
Fix broken Haddock comment

3 years agoTemplate Haskell support for TypeApplications
Ryan Scott [Mon, 29 Aug 2016 13:47:56 +0000 (09:47 -0400)] 
Template Haskell support for TypeApplications

Summary: Fixes #12530.

Test Plan: make test TEST=12530

Reviewers: austin, bgamari, hvr, goldfire

Reviewed By: goldfire

Subscribers: thomie

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

GHC Trac Issues: #12530

3 years agoTypofix in docs.
Edward Z. Yang [Sun, 28 Aug 2016 07:18:21 +0000 (00:18 -0700)] 
Typofix in docs.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
3 years agoFix scoping of type variables in instances
Simon Peyton Jones [Fri, 26 Aug 2016 16:32:42 +0000 (17:32 +0100)] 
Fix scoping of type variables in instances

This fixes Trac #12531:

   class Foo x where
     foo :: forall a . x a -> x a
     default foo :: forall b . x b -> x b
     foo x = go
       where go :: x b
             go = undefined

We want 'b' to scope over the code for 'foo', but we were
using 'a' instead.

3 years agoMove import to avoid warning
Simon Peyton Jones [Fri, 26 Aug 2016 16:25:52 +0000 (17:25 +0100)] 
Move import to avoid warning

The import of UniqFM in HscTypes was only needed in stage2

3 years agoAllow typed holes to be levity-polymorphic
Simon Peyton Jones [Fri, 26 Aug 2016 16:24:10 +0000 (17:24 +0100)] 
Allow typed holes to be levity-polymorphic

This one-line change fixes Trac #12531.  Hooray.

Simple, non-invasive; can merge to 8.0.2

3 years agoFix doc build inconsistency
Harendra Kumar [Fri, 26 Aug 2016 00:28:29 +0000 (20:28 -0400)] 
Fix doc build inconsistency

Remove the doc targets completely not partially when disabled.
Otherwise even though we are able to build the targets but we will see
some strange errors.

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

3 years agoWwLib: Add strictness signature to "let x = absentError …"
Joachim Breitner [Tue, 26 Jul 2016 10:08:59 +0000 (12:08 +0200)] 
WwLib: Add strictness signature to "let x = absentError …"

indicating that it is bottom. This should help making the "empty cases"
lint error give less false alarms.

3 years agoDegrade "case scrutinee not known to diverge for sure" Lint error to warning
Joachim Breitner [Tue, 26 Jul 2016 09:44:53 +0000 (11:44 +0200)] 
Degrade "case scrutinee not known to diverge for sure" Lint error to warning

as proposed in #12435, as it easily gets in the way of development when
it reports false positives.

3 years agoDmdAnal: Testcase about splitFVs and dmdFix abortion
Joachim Breitner [Thu, 21 Jul 2016 15:44:25 +0000 (17:44 +0200)] 
DmdAnal: Testcase about splitFVs and dmdFix abortion

Any variable with useful information (strict or used-once) will not be
included in lazy_fv (according to splitFVs). If we now also remove them
from the strictness signatures, their uses are not recorded anywhere –
and then probably considered absent.

3 years agoDmdAnal: Add a final, safe iteration
Joachim Breitner [Thu, 7 Jul 2016 09:23:48 +0000 (11:23 +0200)] 
DmdAnal: Add a final, safe iteration

this fixes #12368.

It also refactors dmdFix a bit, removes some redundancies (such as
passing around an strictness signature right next to an id, when that id
is guaranteed to have been annotated with that strictness signature).

Note that when fixed-point iteration does not terminate, we
conservatively delete their strictness signatures (set them to nopSig).
But this loses the information on how its strict free variables are
used!

Lazily used variables already escape via lazy_fvs. We ensure that in the
case of an aborted fixed-point iteration, also the strict variables are
put there (with a conservative demand of topDmd).

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

3 years agoComments only: Refer to actually existing Notes
Joachim Breitner [Mon, 1 Aug 2016 00:59:54 +0000 (20:59 -0400)] 
Comments only: Refer to actually existing Notes

3 years agoTemplate Haskell support for unboxed sums
Ryan Scott [Tue, 23 Aug 2016 18:20:36 +0000 (14:20 -0400)] 
Template Haskell support for unboxed sums

This adds new constructors `UnboxedSumE`, `UnboxedSumT`, and
`UnboxedSumP` to represent unboxed sums in Template Haskell.

One thing you can't currently do is, e.g., `reify ''(#||#)`, since I
don't believe unboxed sum type/data constructors can be written in
prefix form.  I will look at fixing that as part of #12514.

Fixes #12478.

Test Plan: make test TEST=T12478_{1,2,3}

Reviewers: osa1, goldfire, austin, bgamari

Reviewed By: goldfire, bgamari

Subscribers: thomie

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

GHC Trac Issues: #12478

3 years agoRtClosureInspect: Fix off-by-one error in cvReconstructType
mniip [Tue, 23 Aug 2016 17:19:02 +0000 (13:19 -0400)] 
RtClosureInspect: Fix off-by-one error in cvReconstructType

Replaced error-prone index manipulation on a pointer array with
a simple fold on the array elements.

Test Plan: Added a test case that triggers the bug

Reviewers: hvr, austin, bgamari

Reviewed By: bgamari

Subscribers: simonpj, thomie

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

GHC Trac Issues: #12458

3 years agoAdd T12520 as a test
Ömer Sinan Ağacan [Tue, 23 Aug 2016 06:53:11 +0000 (06:53 +0000)] 
Add T12520 as a test

  #12520 was already fixed in HEAD. Adding a test to make sure it stays fixed.

3 years agoMove #12403, #12513 users guide notes to 8.2.1 release notes
Ryan Scott [Mon, 22 Aug 2016 23:01:01 +0000 (19:01 -0400)] 
Move #12403, #12513 users guide notes to 8.2.1 release notes

The changes in #12403 and #12513 subtly changed the behavior of Template
Haskell reification and splicing. While the old behavior was certainly buggy,
it's possible that there's code in the wild that depended on the old behavior
to work. To err on the side of caution, I'll postpone these changes to GHC
8.2.1 instead of having them merged into GHC 8.0.2.

3 years agoExtra comments, as per SPJ in #12035.
Edward Z. Yang [Mon, 22 Aug 2016 20:34:43 +0000 (13:34 -0700)] 
Extra comments, as per SPJ in #12035.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
3 years agoSplice singleton unboxed tuples correctly with Template Haskell
Ryan Scott [Mon, 22 Aug 2016 14:39:12 +0000 (10:39 -0400)] 
Splice singleton unboxed tuples correctly with Template Haskell

Summary:
Previously, TH would implicitly remove the parentheses when splicing in
singleton unboxed tuple types (e.g., turning `(# Int #)` into `Int`). Luckily,
the fix is simply to delete some code.

Fixes #12513.

Test Plan: make test TEST=T12513

Reviewers: hvr, bgamari, austin, goldfire

Reviewed By: goldfire

Subscribers: thomie

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

GHC Trac Issues: #12513

3 years agopass -z wxneeded or -Wl,-zwxneeded for linking on OpenBSD
Karel Gardas [Sat, 13 Aug 2016 16:49:53 +0000 (18:49 +0200)] 
pass -z wxneeded or -Wl,-zwxneeded for linking on OpenBSD

Summary:
This patch fixes issue with abort in GHCi on OpenBSD current
as of Aug 12 2016. The OpenBSD is more and more strict about usage
of writable and executable memory. Programs/applications which
requires such functionality need to be linked with -z wxneeded linker
flag and need to be run from the file-system mounted with wxallowed
mount option. If either of those options in not met, then problematic
program/application usually fail on some mmap/mprotect call which fail.

Reviewers: bgamari, austin, hvr

Subscribers: thomie, erikd

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

3 years agoFix #12472 by looking for noinline/lazy inside oversaturated applications.
Edward Z. Yang [Sat, 6 Aug 2016 20:47:05 +0000 (13:47 -0700)] 
Fix #12472 by looking for noinline/lazy inside oversaturated applications.

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

Reviewers: simonpj, austin, bgamari

Subscribers: thomie

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

GHC Trac Issues: #12472

3 years agoWe also need to retypecheck before when we do parallel make.
Edward Z. Yang [Sat, 14 May 2016 02:32:37 +0000 (19:32 -0700)] 
We also need to retypecheck before when we do parallel make.

Summary:
Kept this seperate from the previous patch for clarity.
Comes with a test.

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

Reviewers: simonpj, austin, bgamari

Subscribers: thomie

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

GHC Trac Issues: #12035

3 years agoRetypecheck both before and after finishing hs-boot loops in --make.
Edward Z. Yang [Fri, 13 May 2016 07:10:47 +0000 (00:10 -0700)] 
Retypecheck both before and after finishing hs-boot loops in --make.

Summary:
This makes ghc --make's retypecheck behavior more in line
with ghc -c, which is able to tie the knot as we are typechecking.

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

Reviewers: simonpj, austin, bgamari

Subscribers: thomie

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

GHC Trac Issues: #12035

3 years agoWhen a value Id comes from hi-boot, insert noinline. Fixes #10083.
Edward Z. Yang [Fri, 13 May 2016 03:33:43 +0000 (20:33 -0700)] 
When a value Id comes from hi-boot, insert noinline. Fixes #10083.

Summary:
This also drops the parked fix from
efa7b3a474bc373201ab145c129262a73c86f959
(though I didn't revert the refactoring).

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

Reviewers: simonpj, austin, bgamari

Subscribers: thomie

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

GHC Trac Issues: #10083

3 years agoIntroduce BootUnfolding, set when unfolding is absent due to hs-boot file.
Edward Z. Yang [Thu, 12 May 2016 19:47:16 +0000 (12:47 -0700)] 
Introduce BootUnfolding, set when unfolding is absent due to hs-boot file.

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

Reviewers: simonpj, austin, bgamari

Subscribers: thomie

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

3 years agoSupport for noinline magic function.
Edward Z. Yang [Fri, 13 May 2016 02:38:57 +0000 (19:38 -0700)] 
Support for noinline magic function.

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

Reviewers: simonpj, austin, bgamari

Subscribers: thomie

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

3 years agoAxe initIfaceTc, tie the knot through HPT (or if_rec_types).
Edward Z. Yang [Sun, 19 Jun 2016 21:28:55 +0000 (14:28 -0700)] 
Axe initIfaceTc, tie the knot through HPT (or if_rec_types).

Summary:
initIfaceTc was originally used to make sure when we typecheck
an interface, it can find the TyThings for things it itself
defined.  However, in the case of retypecheckLoop, this wasn't
necessary because we ALREADY tied the knot through the HPT.

This commit removes initIfaceTc, instead relying on the HPT
to tie the knot.  genModDetails' caller needed to be modified
to tie the knot, but there are not that many call-sites of
typecheckIface so the change is quite reasonable.

We also introduce a new 'initIfaceLoad', which does
NOT set up 'if_rec_types'.  It's used when we're
typechecking old, up-to-date interfaces in, since we're
never going to update the type environment.

The full details are in Note [Knot-tying typecheckIface].
Displeasingly, we need a special case to handle DFuns in
the case of tcHiBootIface, see
Note [DFun knot-tying special case] for the gory details.

I also added another test which tickles a bug in a buggy
version of this patch (see "Why the seq?")

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

Reviewers: simonpj, austin, bgamari

Subscribers: thomie

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

3 years agoAnnotate initIfaceCheck with usage information.
Edward Z. Yang [Mon, 20 Jun 2016 05:31:06 +0000 (22:31 -0700)] 
Annotate initIfaceCheck with usage information.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
3 years agoRevert "codeGen: Remove binutils<2.17 hack, fixes T11758"
Simon Peyton Jones [Thu, 18 Aug 2016 17:16:01 +0000 (18:16 +0100)] 
Revert "codeGen: Remove binutils<2.17 hack, fixes T11758"

This reverts commit e3e2e49a8f6952e1c8a19321c729c17b294d8c92.

I'm reverting because it makes ghc-stage2 seg-fault on
64-bit Windows machines.  Even ghc-stage2 --version seg-faults.

3 years agoAdd gcoerceWith to Data.Type.Coercion
Ryan Scott [Thu, 18 Aug 2016 13:11:03 +0000 (09:11 -0400)] 
Add gcoerceWith to Data.Type.Coercion

Summary:
For symmetry with `gcastWith` in `Data.Type.Equality`.

Fixes #12493.

Test Plan: It compiles

Reviewers: bgamari, goldfire, hvr, austin

Subscribers: thomie

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

GHC Trac Issues: #12493

3 years agoRevert "T1969: Enable it again but bump the max residency temporarily"
Matthew Pickering [Wed, 17 Aug 2016 20:48:57 +0000 (21:48 +0100)] 
Revert "T1969: Enable it again but bump the max residency temporarily"

This reverts commit 773e3aadac4bbee9a0173ebc90ffdc9458a2a3a9.

3 years agoRefactor nestImplicTcS
Simon Peyton Jones [Wed, 17 Aug 2016 13:38:02 +0000 (14:38 +0100)] 
Refactor nestImplicTcS

Simpler code, and simpler to understand.
No change in behaviour.

3 years agoKeep the bindings local during defaultCallStacks
Simon Peyton Jones [Wed, 17 Aug 2016 13:35:19 +0000 (14:35 +0100)] 
Keep the bindings local during defaultCallStacks

defaultCallStacks generates evidence bindings for call stacks,
but wasn't setting the binding site correctly.  As a result
they were simply discarded in the case of pattern synonyms,
giving rise to Trac #12489.

The fix is easy; and I added an ASSERT to catch the error earlier.

3 years agoNot-in-scope variables are always errors
Simon Peyton Jones [Wed, 17 Aug 2016 11:04:30 +0000 (12:04 +0100)] 
Not-in-scope variables are always errors

This fixes Trac #12406.  A not-in-scope error shoudl be an error
even if you have -fdefer-typed-holes.

3 years agoTypo in comment
Gabor Greif [Thu, 11 Aug 2016 08:14:25 +0000 (10:14 +0200)] 
Typo in comment

3 years agoTypofix in System.Environment docs.
Edward Z. Yang [Tue, 16 Aug 2016 09:38:02 +0000 (02:38 -0700)] 
Typofix in System.Environment docs.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
3 years agoMinor typofix.
Edward Z. Yang [Sat, 2 Jul 2016 00:00:01 +0000 (20:00 -0400)] 
Minor typofix.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
3 years agoWhen in sanity mode, un-zero malloc'd memory; fix uninitialized memory bugs.
Edward Z. Yang [Mon, 15 Aug 2016 09:22:28 +0000 (02:22 -0700)] 
When in sanity mode, un-zero malloc'd memory; fix uninitialized memory bugs.

malloc'd memory is not guaranteed to be zeroed.  On Linux, however,
it is often zeroed, leading to latent bugs.  In fact, with this
patch I fix two uninitialized memory bugs stemming from this.

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

Reviewers: simonmar, austin, Phyx, bgamari, erikd

Subscribers: thomie

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

3 years agoDarwin: Detect broken NM program at configure time
Erik de Castro Lopo [Mon, 15 Aug 2016 20:41:19 +0000 (06:41 +1000)] 
Darwin: Detect broken NM program at configure time

Some recent versions of XCode ship a broken version of `nm`. Detect this
at configure time, and error out with a suggestion to rerun configure
with a `--with-nm=...` argument.

Test Plan: Test of Linux and OS X

Reviewers: carter, hvr, austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

3 years agorefactor test for __builtin_unreachable into Rts.h macro RTS_UNREACHABLE
Karel Gardas [Mon, 15 Aug 2016 20:26:04 +0000 (22:26 +0200)] 
refactor test for __builtin_unreachable into Rts.h macro RTS_UNREACHABLE

Summary:
This patch refactors GNU C version test (for 4.5 and more modern)
due to usage of __builtin_unreachable done in the CNF.c code directly
into the new RTS_UNREACHABLE macro placed into Rts.h

Reviewers: bgamari, austin, simonmar, erikd

Subscribers: thomie

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

3 years agoUpdate hoopl submodule (extra .gitignore entry)
Edward Z. Yang [Mon, 15 Aug 2016 10:13:43 +0000 (03:13 -0700)] 
Update hoopl submodule (extra .gitignore entry)

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
3 years agofix compilation failure on OpenBSD with system supplied GNU C 4.2.1
Karel Gardas [Sat, 13 Aug 2016 16:46:43 +0000 (18:46 +0200)] 
fix compilation failure on OpenBSD with system supplied GNU C 4.2.1

Summary:
This patch fixes compilation failure on OpenBSD. The OpenBSD's
GNU C compiler is of 4.2.1 version and problematic __builtin_unreachable
was added in GNU C 4.5 release. Let's use pure abort() call
on OpenBSD instead of __builtin_unreachable

Reviewers: bgamari, austin, erikd, simonmar

Subscribers: thomie

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

3 years agoFix configure detection.
Tamar Christina [Sat, 13 Aug 2016 15:27:30 +0000 (16:27 +0100)] 
Fix configure detection.

Summary:
GHC's configure script seems to normalize the values returned from config.guess.
So for Windows it turns x86_64-pc-mingw64 into x86_64-unknown-mingw32.
These mangled names are stored in the values $BuildPlatform, $HostPlatform
and $TargetPlatform.

However further down the file when the comparison is done between the stage0
compiler and the host the normalized versions are not used.
So when normalization actually changes the triple this check will fail.

Not sure why it's worked for all this time.. Nor if this is the right fix?
Does it still work for cross compiling correctly?

Test Plan: ./configure

Reviewers: hvr, austin, thomie, bgamari, erikd

Reviewed By: erikd

Subscribers: erikd, #ghc_windows_task_force

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

GHC Trac Issues: #12487

3 years agoMisspellings in comments [skip ci]
Gabor Greif [Sun, 14 Aug 2016 11:03:23 +0000 (13:03 +0200)] 
Misspellings in comments [skip ci]

3 years agoUpdate `nofib` submodule to newest commit
Gabor Greif [Sun, 14 Aug 2016 07:50:49 +0000 (09:50 +0200)] 
Update `nofib` submodule to newest commit

3 years agoFix GHCi perf-llvm build on x86_64
Erik de Castro Lopo [Sat, 13 Aug 2016 21:23:35 +0000 (07:23 +1000)] 
Fix GHCi perf-llvm build on x86_64

With BuildFlavour set to `perf-llvm`, GHCi would fail as soon as it
was run with:

  ghc-stage2: .../ghc-prim/dist-install/build/HSghc-prim-0.5.0.0.o:
  unknown symbol `__udivti3'
  ghc-stage2: unable to load package `ghc-prim-0.5.0.0'

Fix this by adding `__udivti3` and `__umodti3` to RtsSymbols.c.

Test Plan: Validate

Reviewers: simonmar, austin, bgamari, Phyx, trofi

Reviewed By: Phyx, trofi

Subscribers: thomie

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

GHC Trac Issues: #11981

3 years agoImprove missing-sig warning
Simon Peyton Jones [Fri, 12 Aug 2016 14:52:07 +0000 (15:52 +0100)] 
Improve missing-sig warning

Fixes Trac #12484

3 years agoRemove StgRubbishArg and CmmArg
Ömer Sinan Ağacan [Wed, 10 Aug 2016 16:47:47 +0000 (16:47 +0000)] 
Remove StgRubbishArg and CmmArg

The idea behind adding special "rubbish" arguments was in unboxed sum types
depending on the tag some arguments are not used and we don't want to move some
special values (like 0 for literals and some special pointer for boxed slots)
for those arguments (to stack locations or registers). "StgRubbishArg" was an
indicator to the code generator that the value won't be used. During Stg-to-Cmm
we were then not generating any move or store instructions at all.

This caused problems in the register allocator because some variables were only
initialized in some code paths. As an example, suppose we have this STG: (after
unarise)

    Lib.$WT =
        \r [dt_sit]
            case
                case dt_sit of {
                  Lib.F dt_siv [Occ=Once] ->
                      (#,,#) [1# dt_siv StgRubbishArg::GHC.Prim.Int#];
                  Lib.I dt_siw [Occ=Once] ->
                      (#,,#) [2# StgRubbishArg::GHC.Types.Any dt_siw];
                }
            of
            dt_six
            { (#,,#) us_giC us_giD us_giE -> Lib.T [us_giC us_giD us_giE];
            };

This basically unpacks a sum type to an unboxed sum with 3 fields, and then
moves the unboxed sum to a constructor (`Lib.T`).

This is the Cmm for the inner case expression (case expression in the scrutinee
position of the outer case):

    ciN:
        ...
        -- look at dt_sit's tag
        if (_ciT::P64 != 1) goto ciS; else goto ciR;
    ciS: -- Tag is 2, i.e. Lib.F
        _siw::I64 = I64[_siu::P64 + 6];
        _giE::I64 = _siw::I64;
        _giD::P64 = stg_RUBBISH_ENTRY_info;
        _giC::I64 = 2;
        goto ciU;
    ciR: -- Tag is 1, i.e. Lib.I
        _siv::P64 = P64[_siu::P64 + 7];
        _giD::P64 = _siv::P64;
        _giC::I64 = 1;
        goto ciU;

Here one of the blocks `ciS` and `ciR` is executed and then the execution
continues to `ciR`, but only `ciS` initializes `_giE`, in the other branch
`_giE` is not initialized, because it's "rubbish" in the STG and so we don't
generate an assignment during code generator. The code generator then panics
during the register allocations:

    ghc-stage1: panic! (the 'impossible' happened)
      (GHC version 8.1.20160722 for x86_64-unknown-linux):
            LocalReg's live-in to graph ciY {_giE::I64}

(`_giD` is also "rubbish" in `ciS`, but it's still initialized because it's a
pointer slot, we have to initialize it otherwise garbage collector follows the
pointer to some random place. So we only remove assignment if the "rubbish" arg
has unboxed type.)

This patch removes `StgRubbishArg` and `CmmArg`. We now always initialize
rubbish slots. If the slot is for boxed types we use the existing `absentError`,
otherwise we initialize the slot with literal 0.

Reviewers: simonpj, erikd, austin, simonmar, bgamari

Reviewed By: erikd

Subscribers: thomie

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

3 years agoFix a bug in unboxed sum layout generation
Ömer Sinan Ağacan [Tue, 9 Aug 2016 22:30:56 +0000 (22:30 +0000)] 
Fix a bug in unboxed sum layout generation

We need to maintain the invariant that the layout fields are always sorted.

Two tests that were previously broken are added.