Revert "Use dropWhileEndLE p instead of reverse . dropWhile p . reverse"

This reverts commit 2a8856884de7d476e26b4ffa829ccb3a14d6f63e.
Use dropWhileEndLE p instead of reverse . dropWhile p . reverse

Summary: Using `dropWhileEndLE` tends to be faster and easier to read
than the `reverse . dropWhile p . reverse` idiom. This also cleans up
some other, nearby, messes. Fix #9616 (incorrect number formatting
potentially leading to incorrect numbers in output).

Test Plan: Run validate

Reviewers: thomie, rwbarton, nomeata, austin

Reviewed By: nomeata, austin

Subscribers: simonmar, ezyang, carter, thomie

Projects: #ghc

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

GHC Trac Issues: #9623, #9616

Conflicts:
	compiler/basicTypes/OccName.lhs
rts/PrimOps.cmm: follow '_static_closure' update

Caught by UNREG build failure:

      rts_dist_HC rts/dist/build/PrimOps.o
    /tmp/ghc8613_0/ghc8613_2.hc: In function 'cf8_entry':

    /tmp/ghc8613_0/ghc8613_2.hc:1942:13:
         error: 'base_ControlziExceptionziBase_nestedAtomically_static_closure' undeclared (first use in this function)
         R1.w = (W_)&base_ControlziExceptionziBase_nestedAtomically_static_closure;
                     ^

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Really fix dropWhileEndLE commit

which I fixed before, but failed to pass -a to "git commit --amend"
arclint: Don't complain about tabs unless it's inside the diff.

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

Test Plan: none

Reviewers: austin

Subscribers: simonmar, ezyang, carter, thomie

Differential Revision: https://phabricator.haskell.org/D303
Comments only (instances for Proxy are lazy)
Revert "Basic Python 3 support for testsuite driver (Trac #9184)"

This reverts commit 084d241b316bfa12e41fc34cae993ca276bf0730.

This is a possible culprit of Windows breakage reported at ghc-devs.
Restore spaces instead of tabs, caused by revert of Python 3

The git hook does not allow to reinsert tabs.
Check for staticclosures section in Windows linker.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Implement closure indirections.

Summary:
Closure indirections live in the staticclosureinds section
and initially point to their corresponding closure in
the staticclosures.  The intent is that all code goes through
a closure indirection, and at runtime the indirections can
change.

These pieces of code have to go through closure indirections:

    - Code references to a static closure
    - SRTs
    - Heap check (but we want to fix this)
    - References to closures in RTS (see STATIC_CLOSURE) macro
    - Runtime symbol lookup (e.g. GHCi, dynwrapper)
    - The main closure passed to hs_main

Closure indirections should simplify these components (but that
is not implemented yet):

    - Windows DLL handling (which already needed an indirection)

In order to keep the code running, the fields of static closures
are not indirected (although they should be); this will be switched
over in a later commit.

Important invariant: an indirection may only be dereferenced
after the runtime is setup.  In particular, references to
closures in __attribute__(constructor) need to be kept indirections;
this is what the stable pointer deferral is for.

Part of remove HEAP_ALLOCED patch set (#8199)

Depends on D267

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>

Test Plan: validate

Reviewers: simonmar, austin

Subscribers: simonmar, ezyang, carter, thomie

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

GHC Trac Issues: #8199
Implement runtime setup code for static closures.

Summary:
Fields of static closures are now indirected, and we have a simple
runtime initialization code initStaticClosures() which merely rewrites
all of the indirections into untagged pointers and untangles references
between the static closures.  This also copies static closures into
blocks, although this data is unused.

The runtime system finds out about indirections by way of
__attribute__(constructor) methods; thus C-- compilation may now
generate foreign stubs (if it defines closures).

Part of remove HEAP_ALLOCED patch set (#8199)

Depends on D270

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>

Test Plan: validate

Reviewers: simonmar, austin

Subscribers: simonmar, ezyang, carter, thomie

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

GHC Trac Issues: #8199
Indirect SRTs and heap checks.

Summary:
SRT pointers go through the static closure indirection table,
so there's one more indirection you need.

(The XXX is because we are conservatively untagging the
incoming pointer always.  We'll relax this in a later commit.)

Part of remove HEAP_ALLOCED patch set (#8199)

Depends on D271

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>

Test Plan: validate

Reviewers: simonmar, austin

Subscribers: simonmar, ezyang, carter, thomie

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

GHC Trac Issues: #8199
CHARLIKE/INTLIKE must use indirections.

Summary:
While these are "closures", they aren't allocated the usual
way, so we just special case them in closure initialization.

It is very important that these arrays fit in a single block,
since a pointer to a closure across the boundary needs to have
the appropriate BF_STATIC flag set.

Nota bene: C will implicitly dereference the _ind reference,
but C-- will not; thus the extra load in C-- land.

Part of remove HEAP_ALLOCED patch set (#8199)

Depends on D272

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>

Test Plan: validate

Reviewers: simonmar, austin

Subscribers: simonmar, ezyang, carter, thomie

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

GHC Trac Issues: #8199
Port integer-gmp to use static closures.

Part of remove HEAP_ALLOCED patch set (#8199)

Depends on D273

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

Reviewers: simonmar, austin

Subscribers: simonmar, ezyang, carter, thomie

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

GHC Trac Issues: #8199
Closure tables must use indirections.

Summary:
Note: In principle, a closure table could be updated to point to the
true location of the closures in question after initialization.
However, in order to update the closure tables, the RTS needs to know
about them, and tracking that information may be more costly than
we want (it's already a pain for the CAFs proper, where we use
a static initializer.)

Part of remove HEAP_ALLOCED patch set (#8199)

Depends on D274

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>

Reviewers: simonmar, austin

Subscribers: simonmar, ezyang, carter, thomie

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

GHC Trac Issues: #8199
Add some thread-safety.

Summary:
This helps protect if processStaticClosures is called concurrently,
which may occur if you are loading objects.  Under normal circumstances
these locks should be unnecessary.

Part of remove HEAP_ALLOCED patch set (#8199)

Depends on D275

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>

Reviewers: simonmar, austin

Subscribers: simonmar, ezyang, carter, thomie

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

GHC Trac Issues: #8199
Replace HEAP_ALLOCED with block descriptor check.

Summary:
Blocks have a new flag BF_STATIC, which indicates if the data
contained therein is static.  This means we can get rid of
all of the complicated caching logic in MBlock.h.  For now,
we still maintain the memory mapping, so we can deallocate
all our memory at the end and do some sanity checks.

Part of remove HEAP_ALLOCED patch set (#8199)

Depends on D276

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>

Reviewers: simonmar, austin

Subscribers: simonmar, ezyang, carter, thomie

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

GHC Trac Issues: #8199
Move tag from outside to inside indirection.

Summary:
In the old world, code referring to a closure had code like:

    foobar_closure + tag

Previously, when there was no dereference, this was essentially
free; but in the new world, we have:

    *foobar_static_closure_ind + tag

and that means a few extra instructions at runtime.  But
we can store the tag in the indirection itself, to simplify
the code back to:

    *foobar_static_closure_ind

A bit of stuff needs to be rewired. One important thing:
CHARLIKE/INTLIKE do *not* do this scheme, since there isn't
a separate tagged pointer for each closure, and it's free
anyway, since we already need to add an offset to index
into the appropriate little object.

Part of remove HEAP_ALLOCED patch set (#8199)

Depends on D277

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>

Reviewers: simonmar, austin

Subscribers: simonmar, ezyang, carter, thomie

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

GHC Trac Issues: #8199
Improve documentation for debug-only code.

Part of remove HEAP_ALLOCED patch set (#8199)

Depends on D278

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

Reviewers: simonmar, austin

Subscribers: simonmar, ezyang, carter, thomie

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

GHC Trac Issues: #8199
Reduce number of exported symbols (e.g. _static_closure)

Part of remove HEAP_ALLOCED patch set (#8199)

Depends on D279

Summary: Signed-off-by: Edward Z. Yang <ezyang@mit.edu>

Reviewers: simonmar, austin

Subscribers: simonmar, ezyang, carter, thomie

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

GHC Trac Issues: #8199