ghc-hetmet.git
15 years agoMake some profiling flags dynamic
Ian Lynagh [Tue, 9 Dec 2008 23:01:57 +0000 (23:01 +0000)]
Make some profiling flags dynamic
In particular:
    -fauto-sccs-on-all-toplevs          -auto-all   -no-auto-all
    -fauto-sccs-on-exported-toplevs     -auto       -no-auto
    -fauto-sccs-on-individual-cafs      -caf-all    -no-caf-all

15 years agoFix warnings in StgCmmGran
Ian Lynagh [Tue, 9 Dec 2008 22:24:13 +0000 (22:24 +0000)]
Fix warnings in StgCmmGran

15 years agoAdd OPTIONS_CATCH,DERIVE,YHC to those that GHC knows about; trac #2847
Ian Lynagh [Tue, 9 Dec 2008 19:17:24 +0000 (19:17 +0000)]
Add OPTIONS_CATCH,DERIVE,YHC to those that GHC knows about; trac #2847

15 years agoFix warnings in CgHpc
Ian Lynagh [Tue, 9 Dec 2008 19:17:13 +0000 (19:17 +0000)]
Fix warnings in CgHpc

15 years agoParse pragma names better; trac #2847
Ian Lynagh [Tue, 9 Dec 2008 19:03:18 +0000 (19:03 +0000)]
Parse pragma names better; trac #2847
We require that pragma names are not followed by pragma character,
defined as
    isAlphaNum c || c == '_'

15 years agoFix warnings in CgParallel
Ian Lynagh [Tue, 9 Dec 2008 18:44:02 +0000 (18:44 +0000)]
Fix warnings in CgParallel

15 years agoFix warnings in StgCmmHpc
Ian Lynagh [Tue, 9 Dec 2008 18:40:04 +0000 (18:40 +0000)]
Fix warnings in StgCmmHpc

15 years agoRemove an unnecessary -w flag
Ian Lynagh [Tue, 9 Dec 2008 18:38:12 +0000 (18:38 +0000)]
Remove an unnecessary -w flag

15 years agoFix Trac #2861: bogus eta expansion
simonpj@microsoft.com [Tue, 9 Dec 2008 17:03:02 +0000 (17:03 +0000)]
Fix Trac #2861: bogus eta expansion

Urghlhl!  I "tided up" the treatment of the "state hack" in CoreUtils, but
missed an unexpected interaction with the way that a bottoming function
simply swallows excess arguments.  There's a long
     Note [State hack and bottoming functions]
to explain (which accounts for most of the new lines of code).

15 years agoFix #2592: do an orderly shutdown when the heap is exhausted
Simon Marlow [Tue, 9 Dec 2008 10:59:19 +0000 (10:59 +0000)]
Fix #2592: do an orderly shutdown when the heap is exhausted
Really we should be raising an exception in this case, but that's
tricky (see comments).  At least now we shut down the runtime
correctly rather than just exiting.

15 years agoFix #2848: avoid overflow during time calculation
Simon Marlow [Tue, 9 Dec 2008 10:56:00 +0000 (10:56 +0000)]
Fix #2848: avoid overflow during time calculation

15 years agoFix #2838: we should narrow a CmmInt before converting to ImmInteger
Simon Marlow [Tue, 9 Dec 2008 10:55:15 +0000 (10:55 +0000)]
Fix #2838: we should narrow a CmmInt before converting to ImmInteger

15 years agofix an assertion failure in prof/threaded/debug mode
Simon Marlow [Thu, 4 Dec 2008 10:12:01 +0000 (10:12 +0000)]
fix an assertion failure in prof/threaded/debug mode

15 years agoInject implicit bindings after CoreTidy, not before Simplify
simonpj@microsoft.com [Mon, 8 Dec 2008 17:35:25 +0000 (17:35 +0000)]
Inject implicit bindings after CoreTidy, not before Simplify

Originally I inject the "implicit bindings" (record selectors, class
method selectors, data con wrappers...) after CoreTidy.  However, in a
misguided attempt to fix Trac #2070, I moved the injection point to
before the Simplifier, so that record selectors would be optimised by
the simplifier.

This was misguided because record selectors (indeed all implicit bindings)
are GlobalIds, whose IdInfo is meant to be frozen.  But the Simplifier,
and other Core-to-Core optimisations, merrily change the IdInfo.  That
ultimately made Trac #2844 happen, where a record selector got arity 2,
but the GlobalId (which importing scopes re-construct from the class decl
rather than reading from the interface file) has arity 1.

So this patch moves the injection back to CoreTidy. Happily #2070 should
still be OK because we now use CoreSubst.simpleOptExpr on the unfoldings
for implict things, which gets rid of the most gratuitous infelicities.

Still, there's a strong case for stoppping record selectors from being
GlobalIds, and treating them much more like dict-funs.  I'm thinking
about that.  Meanwhile, #2844 is ok now.

15 years agoAdd assertion for arity match (checks Trac #2844)
simonpj@microsoft.com [Mon, 8 Dec 2008 17:32:41 +0000 (17:32 +0000)]
Add assertion for arity match (checks Trac #2844)

The exported arity of a function must match the arity for the
STG function.  Trac #2844 was a pretty obscure manifestation of
the failure of this invariant. This patch doesn't cure the bug;
rather it adds an assertion to CoreToStg to check the invariant
so we should get an earlier and less obscure warning if this
fails in future.

15 years agoUse CoreSubst.simpleOptExpr in place of the ad-hoc simpleSubst (reduces code too)
simonpj@microsoft.com [Mon, 8 Dec 2008 17:30:18 +0000 (17:30 +0000)]
Use CoreSubst.simpleOptExpr in place of the ad-hoc simpleSubst (reduces code too)

15 years agoMove simpleOptExpr from CoreUnfold to CoreSubst
simonpj@microsoft.com [Mon, 8 Dec 2008 12:48:40 +0000 (12:48 +0000)]
Move simpleOptExpr from CoreUnfold to CoreSubst

15 years agoWhite space only
simonpj@microsoft.com [Mon, 8 Dec 2008 12:43:10 +0000 (12:43 +0000)]
White space only

15 years agoComments only
simonpj@microsoft.com [Mon, 8 Dec 2008 12:41:55 +0000 (12:41 +0000)]
Comments only

15 years agoCompletely new treatment of INLINE pragmas (big patch)
simonpj@microsoft.com [Fri, 5 Dec 2008 16:54:00 +0000 (16:54 +0000)]
Completely new treatment of INLINE pragmas (big patch)

This is a major patch, which changes the way INLINE pragmas work.
Although lots of files are touched, the net is only +21 lines of
code -- and I bet that most of those are comments!

HEADS UP: interface file format has changed, so you'll need to
recompile everything.

There is not much effect on overall performance for nofib,
probably because those programs don't make heavy use of INLINE pragmas.

        Program           Size    Allocs   Runtime   Elapsed
            Min         -11.3%     -6.9%     -9.2%     -8.2%
            Max          -0.1%     +4.6%     +7.5%     +8.9%
 Geometric Mean          -2.2%     -0.2%     -1.0%     -0.8%

(The +4.6% for on allocs is cichelli; see other patch relating to
-fpass-case-bndr-to-join-points.)

The old INLINE system
~~~~~~~~~~~~~~~~~~~~~
The old system worked like this. A function with an INLINE pragam
got a right-hand side which looked like
     f = __inline_me__ (\xy. e)
The __inline_me__ part was an InlineNote, and was treated specially
in various ways.  Notably, the simplifier didn't inline inside an
__inline_me__ note.

As a result, the code for f itself was pretty crappy. That matters
if you say (map f xs), because then you execute the code for f,
rather than inlining a copy at the call site.

The new story: InlineRules
~~~~~~~~~~~~~~~~~~~~~~~~~~
The new system removes the InlineMe Note altogether.  Instead there
is a new constructor InlineRule in CoreSyn.Unfolding.  This is a
bit like a RULE, in that it remembers the template to be inlined inside
the InlineRule.  No simplification or inlining is done on an InlineRule,
just like RULEs.

An Id can have an InlineRule *or* a CoreUnfolding (since these are two
constructors from Unfolding). The simplifier treats them differently:

  - An InlineRule is has the substitution applied (like RULES) but
    is otherwise left undisturbed.

  - A CoreUnfolding is updated with the new RHS of the definition,
    on each iteration of the simplifier.

An InlineRule fires regardless of size, but *only* when the function
is applied to enough arguments.  The "arity" of the rule is specified
(by the programmer) as the number of args on the LHS of the "=".  So
it makes a difference whether you say
   {-# INLINE f #-}
f x = \y -> e     or     f x y = e
This is one of the big new features that InlineRule gives us, and it
is one that Roman really wanted.

In contrast, a CoreUnfolding can fire when it is applied to fewer
args than than the function has lambdas, provided the result is small
enough.

Consequential stuff
~~~~~~~~~~~~~~~~~~~
* A 'wrapper' no longer has a WrapperInfo in the IdInfo.  Instead,
  the InlineRule has a field identifying wrappers.

* Of course, IfaceSyn and interface serialisation changes appropriately.

* Making implication constraints inline nicely was a bit fiddly. In
  the end I added a var_inline field to HsBInd.VarBind, which is why
  this patch affects the type checker slightly

* I made some changes to the way in which eta expansion happens in
  CorePrep, mainly to ensure that *arguments* that become let-bound
  are also eta-expanded.  I'm still not too happy with the clarity
  and robustness fo the result.

* We now complain if the programmer gives an INLINE pragma for
  a recursive function (prevsiously we just ignored it).  Reason for
  change: we don't want an InlineRule on a LoopBreaker, because then
  we'd have to check for loop-breaker-hood at occurrence sites (which
  isn't currenlty done).  Some tests need changing as a result.

This patch has been in my tree for quite a while, so there are
probably some other minor changes.

15 years agoAdd -fpass-case-bndr-to-join-points
simonpj@microsoft.com [Fri, 5 Dec 2008 10:51:59 +0000 (10:51 +0000)]
Add -fpass-case-bndr-to-join-points

See Note [Passing the case binder to join points] in Simplify.lhs
The default now is *not* to pass the case binder.  There are some
nofib results with the above note; the effect is almost always
negligible.

I don't expect this flag to be used by users (hence no docs). It's just
there to let me try the performance effects of switching on and off.

15 years agoAdd static flag -fsimple-list-literals
simonpj@microsoft.com [Fri, 5 Dec 2008 10:50:02 +0000 (10:50 +0000)]
Add static flag -fsimple-list-literals

The new static flag -fsimple-list-literals makes ExplicitList literals
be desugared in the straightforward way, rather than using 'build' as
now.  See SLPJ comments with Note [Desugaring explicit lists].

I don't expect this flag to be used by users (hence no docs). It's just
there to let me try the performance effects of switching on and off.

15 years agoComments only in OccurAnal
simonpj@microsoft.com [Fri, 5 Dec 2008 10:32:52 +0000 (10:32 +0000)]
Comments only in OccurAnal

15 years agoComments only
simonpj@microsoft.com [Fri, 5 Dec 2008 10:24:37 +0000 (10:24 +0000)]
Comments only

15 years agoLayout only
simonpj@microsoft.com [Fri, 5 Dec 2008 10:22:52 +0000 (10:22 +0000)]
Layout only

15 years agoComments only (Note [Entering error thunks])
simonpj@microsoft.com [Fri, 5 Dec 2008 10:21:49 +0000 (10:21 +0000)]
Comments only (Note [Entering error thunks])

15 years agoMake CoreToStg a little more robust to eta expansion
simonpj@microsoft.com [Fri, 5 Dec 2008 10:19:32 +0000 (10:19 +0000)]
Make CoreToStg a little more robust to eta expansion

15 years agoAdd no-op case for addIdSpecialisations (very minor optimisation)
simonpj@microsoft.com [Fri, 5 Dec 2008 10:10:22 +0000 (10:10 +0000)]
Add no-op case for addIdSpecialisations (very minor optimisation)

15 years agoTrim redundant import
simonpj@microsoft.com [Fri, 5 Dec 2008 10:10:06 +0000 (10:10 +0000)]
Trim redundant import

15 years agoMake CoreTidy retain deadness info (better -ddump-simpl)
simonpj@microsoft.com [Fri, 5 Dec 2008 10:05:18 +0000 (10:05 +0000)]
Make CoreTidy retain deadness info (better -ddump-simpl)

GHC now retains more robust information about dead variables; but
CoreTidy was throwing it away.  This patch makes CoreTidy retain it,
which gives better output for -ddump-simpl.

New opportunity: shrink interface files by using wildcards for dead variables.

15 years agoRemove INLINE pragmas on recursive functions
simonpj@microsoft.com [Fri, 5 Dec 2008 10:03:53 +0000 (10:03 +0000)]
Remove INLINE pragmas on recursive functions

INLINE pragmas on recursive functions are ignored; and this
is checked in my upcoming patch for inlinings.

15 years agoComments only (on Activation)
simonpj@microsoft.com [Fri, 5 Dec 2008 10:01:39 +0000 (10:01 +0000)]
Comments only (on Activation)

15 years agoWe need to tell cabal-bin which version of Cabal to use
Ian Lynagh [Wed, 3 Dec 2008 12:32:08 +0000 (12:32 +0000)]
We need to tell cabal-bin which version of Cabal to use
Otherwise, if the bootstrapping compiler has a newer version, we get
a mismatch between the version used to compile ghc-prim's Setup.hs and
the version that installPackage uses.

15 years agoDocument 'loadModule'.
Thomas Schilling [Tue, 2 Dec 2008 15:48:00 +0000 (15:48 +0000)]
Document 'loadModule'.

15 years agoAdd 'needsTemplateHaskell' utility function and document why one might
Thomas Schilling [Tue, 2 Dec 2008 15:23:58 +0000 (15:23 +0000)]
Add 'needsTemplateHaskell' utility function and document why one might
want to use it.

15 years agoDocumentation only.
Thomas Schilling [Tue, 2 Dec 2008 15:01:58 +0000 (15:01 +0000)]
Documentation only.

15 years agoExport 'succeeded' and 'failed' helper functions.
Thomas Schilling [Tue, 2 Dec 2008 14:44:51 +0000 (14:44 +0000)]
Export 'succeeded' and 'failed' helper functions.

15 years agoPut full ImportDecls in ModSummary instead of just ModuleNames
Simon Marlow [Tue, 2 Dec 2008 13:37:36 +0000 (13:37 +0000)]
Put full ImportDecls in ModSummary instead of just ModuleNames
... and use it to make ghc -M generate correct cross-package
dependencies when using package-qualified imports (needed for the new
build system).  Since we're already parsing the ImportDecl from the
source file, there seems no good reason not to keep it in the
ModSummary, it might be useful for other things too.

15 years agoghc -M: need to add a dep on Prelude unless -fno-implicit-prelude is on
Simon Marlow [Fri, 28 Nov 2008 16:57:07 +0000 (16:57 +0000)]
ghc -M: need to add a dep on Prelude unless -fno-implicit-prelude is on

15 years agomake -include-pkg-deps work (not sure when this got lost)
Simon Marlow [Fri, 28 Nov 2008 13:57:46 +0000 (13:57 +0000)]
make -include-pkg-deps work (not sure when this got lost)

15 years agoFix more problems caused by padding in the Capability structure
Simon Marlow [Tue, 2 Dec 2008 12:07:35 +0000 (12:07 +0000)]
Fix more problems caused by padding in the Capability structure
Fixes crashes on Windows and Sparc

15 years agoadd missing case to Ord GlobalReg (EagerBlackhole == EagerBlackhole)
Simon Marlow [Fri, 28 Nov 2008 13:01:06 +0000 (13:01 +0000)]
add missing case to Ord GlobalReg (EagerBlackhole == EagerBlackhole)

15 years agoBetter error message for fundep conflict
simonpj@microsoft.com [Mon, 1 Dec 2008 16:28:45 +0000 (16:28 +0000)]
Better error message for fundep conflict

15 years agoFix typo in quasi-quote documentation's sample.
shelarcy [Sat, 29 Nov 2008 02:43:44 +0000 (02:43 +0000)]
Fix typo in quasi-quote documentation's sample.

15 years agoRemove the v_Split_info global variable and use a field of dflags instead
Ian Lynagh [Sun, 30 Nov 2008 15:24:03 +0000 (15:24 +0000)]
Remove the v_Split_info global variable and use a field of dflags instead

15 years agoDocument the --machine-readable RTS flag
Ian Lynagh [Sun, 30 Nov 2008 15:23:11 +0000 (15:23 +0000)]
Document the --machine-readable RTS flag

15 years agoLet 'loadModule' generate proper code depending on the 'hscTarget'.
Thomas Schilling [Fri, 28 Nov 2008 16:44:12 +0000 (16:44 +0000)]
Let 'loadModule' generate proper code depending on the 'hscTarget'.

With this change it should be possible to perform something similar to
'load' by traversing the module graph in dependency order and calling
'{parse,typecheck,load}Module' on each.  Of course, if you want smart
recompilation checking you should still use 'load'.

15 years agoExpose a separate 'hscBackend' phase for 'HsCompiler' and change
Thomas Schilling [Fri, 28 Nov 2008 16:37:46 +0000 (16:37 +0000)]
Expose a separate 'hscBackend' phase for 'HsCompiler' and change
parameter to 'InteractiveStatus' to a 'Maybe'.

15 years agoWhoops, *don't* reset the complete session in 'withLocalCallbacks'.
Thomas Schilling [Fri, 28 Nov 2008 15:07:27 +0000 (15:07 +0000)]
Whoops, *don't* reset the complete session in 'withLocalCallbacks'.

15 years agoUse a record instead of a typeclass for 'HsCompiler'. This is mostly
Thomas Schilling [Fri, 28 Nov 2008 12:19:47 +0000 (12:19 +0000)]
Use a record instead of a typeclass for 'HsCompiler'.  This is mostly
equivalent to a typeclass implementation that uses a functional
dependency from the target mode to the result type.

15 years agoRemove dead code
Ian Lynagh [Fri, 28 Nov 2008 19:38:31 +0000 (19:38 +0000)]
Remove dead code

15 years agoUpdate docs not to talk about deprecated -optdep-* flags; fixes trac #2773
Ian Lynagh [Fri, 28 Nov 2008 19:36:33 +0000 (19:36 +0000)]
Update docs not to talk about deprecated -optdep-* flags; fixes trac #2773

15 years agoUse relative URLs in the GHC API haddock docs; fixes #2755
Ian Lynagh [Fri, 28 Nov 2008 18:45:11 +0000 (18:45 +0000)]
Use relative URLs in the GHC API haddock docs; fixes #2755

15 years agoTeach runghc about --help; fixes trac #2757
Ian Lynagh [Fri, 28 Nov 2008 19:17:06 +0000 (19:17 +0000)]
Teach runghc about --help; fixes trac #2757

15 years agoUse a per-session data structure for callbacks. Make 'WarnErrLogger'
Thomas Schilling [Fri, 28 Nov 2008 10:36:28 +0000 (10:36 +0000)]
Use a per-session data structure for callbacks.  Make 'WarnErrLogger'
part of it.

Part of the GHC API essentially represents a compilation framework.
The difference of a *framework* as opposed to a *library* is that the
overall structure of the functionality is pre-defined but certain
details can be customised via callbacks.  (Also known as the Hollywood
Principle: "Don't call us, we'll call you.")

This patch introduces a per-session data structure that contains all
the callbacks instead of adding lots of small function arguments
whenever we want to give the user more control over certain parts of
the API.  This should also help with future changes: Adding a new
callback doesn't break old code since code that doesn't know about the
new callback will use the (hopefully sane) default implementation.

Overall, however, we should try and keep the number of callbacks small
and well-defined (and provide useful defaults) and use simple library
routines for the rest.

15 years agoImprove error message for #2739 (but no fix).
Thomas Schilling [Thu, 27 Nov 2008 13:57:25 +0000 (13:57 +0000)]
Improve error message for #2739 (but no fix).

This patch changes 'loadModule' to define a fake linkable.  The
previous implementation of providing no linkable at all violated a
pre-condition in the ByteCode linker.  This doesn't fix #2739, but it
improves the error message a bit.

15 years agoRemove the packing I added recently to the Capability structure
Simon Marlow [Fri, 28 Nov 2008 10:50:46 +0000 (10:50 +0000)]
Remove the packing I added recently to the Capability structure
The problem is that the packing caused some unaligned loads, which
lead to bus errors on Sparc (and reduced performance elsewhere,
presumably).

15 years agodon't emit CmmComments for now
Simon Marlow [Thu, 27 Nov 2008 09:01:45 +0000 (09:01 +0000)]
don't emit CmmComments for now
  - if the string contains */, we need to fix it (demonstrated by
    building Cabal with -fvia-C)
  - the strings can get quite large, so we probably only want to
    inject comments when some debugging option is on.

15 years agoCollect instead of print warnings in 'warnUnnecessarySourceImports'.
Thomas Schilling [Thu, 27 Nov 2008 10:25:34 +0000 (10:25 +0000)]
Collect instead of print warnings in 'warnUnnecessarySourceImports'.

15 years agoForce recompilation of BCOs when they were compiled in HscNothing mode.
Thomas Schilling [Wed, 26 Nov 2008 18:34:02 +0000 (18:34 +0000)]
Force recompilation of BCOs when they were compiled in HscNothing mode.

Previously, loading a set of modules in HscNothing mode and then
switching to HscInterpreted could lead to crashes since modules
compiled with HscNothing were thought to be valid bytecode objects.

This patch forces recompilation in these cases, hence switching between
HscNothing and HscInterpreted should be safe now.

15 years agoDocumentation only: Add module description for HscMain.
Thomas Schilling [Wed, 26 Nov 2008 13:43:44 +0000 (13:43 +0000)]
Documentation only: Add module description for HscMain.

15 years agoInclude GHCi files in ctags/etags.
Thomas Schilling [Wed, 26 Nov 2008 12:28:01 +0000 (12:28 +0000)]
Include GHCi files in ctags/etags.

15 years agodrop some debugging traces and use only one flag for new codegen
dias@eecs.harvard.edu [Wed, 26 Nov 2008 18:08:08 +0000 (18:08 +0000)]
drop some debugging traces and use only one flag for new codegen

15 years agoone more missing patch from new codegen path
dias@eecs.harvard.edu [Wed, 26 Nov 2008 16:57:42 +0000 (16:57 +0000)]
one more missing patch from new codegen path

15 years agoFix Trac #2817 (TH syntax -> HsSyn conversion)
simonpj@microsoft.com [Wed, 26 Nov 2008 15:40:22 +0000 (15:40 +0000)]
Fix Trac #2817 (TH syntax -> HsSyn conversion)

15 years agoFix Trac #2756: CorePrep strictness bug
simonpj@microsoft.com [Wed, 26 Nov 2008 14:34:48 +0000 (14:34 +0000)]
Fix Trac #2756: CorePrep strictness bug

15 years agoFormat output for :t more nicely
simonpj@microsoft.com [Wed, 26 Nov 2008 13:48:14 +0000 (13:48 +0000)]
Format output for :t more nicely

15 years agoFix Trac #2766: printing operator type variables
simonpj@microsoft.com [Wed, 26 Nov 2008 13:22:02 +0000 (13:22 +0000)]
Fix Trac #2766: printing operator type variables

15 years agoFix build following codegen patch
simonpj@microsoft.com [Wed, 26 Nov 2008 12:55:26 +0000 (12:55 +0000)]
Fix build following codegen patch

15 years agoRemoved warnings, made Haddock happy, added examples in documentation
dias@eecs.harvard.edu [Fri, 17 Oct 2008 17:07:07 +0000 (17:07 +0000)]
Removed warnings, made Haddock happy, added examples in documentation
The interesting examples talk about our story with heap checks in
case alternatives and our story with the case scrutinee as a Boolean.

15 years agoFixed linear regalloc bug, dropped some tracing code
dias@eecs.harvard.edu [Thu, 16 Oct 2008 10:42:18 +0000 (10:42 +0000)]
Fixed linear regalloc bug, dropped some tracing code
o The linear-scan register allocator sometimes allocated a block
  before allocating one of its predecessors, which could lead
  to inconsistent allocations. Now, we allocate a block only
  if a predecessor has set the "incoming" assignments for the block
  (or if it's the procedure's entry block).
o Also commented out some tracing code on the new codegen path.

15 years agoKeep update frames live even in functions that never return
dias@eecs.harvard.edu [Tue, 14 Oct 2008 16:54:37 +0000 (16:54 +0000)]
Keep update frames live even in functions that never return
An unusual case, but without it:
(a) we had an assertion failure
(b) we can overwrite the caller's infotable, which might cause
    the garbage collector to collect live data.
Better to keep the update frame live at all call sites,
not just at returns.

15 years agoRemoved space and time inefficiency in procpoint splitting
dias@eecs.harvard.edu [Tue, 14 Oct 2008 16:03:54 +0000 (16:03 +0000)]
Removed space and time inefficiency in procpoint splitting
I was adding extra jumps to every procpoint, even when the split-off graph
referred to only some of the procpoints. No effect on correctness,
but a big effect on space/time efficiency when there are lots of procpoints...

15 years agoClarify the SRT building process
dias@eecs.harvard.edu [Tue, 14 Oct 2008 14:02:02 +0000 (14:02 +0000)]
Clarify the SRT building process
Before: building a closure that would build an SRT given the top-level
SRT. It was somewhat difficult to understand the control flow, and it
may have had held onto some data structures long after they should be dead.
Now, I just bundle the info we need about CAFs along with the procedure
and directly call a new top-level function to build the SRTs later.

15 years agoDon't adjust hp up when the case scrutinee won't allocate
dias@eecs.harvard.edu [Tue, 14 Oct 2008 11:26:18 +0000 (11:26 +0000)]
Don't adjust hp up when the case scrutinee won't allocate

If the case scrutinee can't allocate, we don't need to do a heap
check in the case alternatives. (A previous patch got that right.)
In that case, we had better not adjust the heap pointer to recover
unused stack space before evaluating the scrutinee -- because we
aren't going to reallocate for the case alternative.

15 years agoFloating infotables were reversed in C back end
dias@eecs.harvard.edu [Mon, 13 Oct 2008 15:27:18 +0000 (15:27 +0000)]
Floating infotables were reversed in C back end

15 years agoforgot a few files
dias@eecs.harvard.edu [Mon, 13 Oct 2008 13:42:51 +0000 (13:42 +0000)]
forgot a few files

15 years agoBig collection of patches for the new codegen branch.
dias@eecs.harvard.edu [Mon, 13 Oct 2008 13:25:56 +0000 (13:25 +0000)]
Big collection of patches for the new codegen branch.
o Fixed bug that emitted the copy-in code for closure entry
  in the wrong place -- at the initialization of the closure.
o Refactored some of the closure entry code.
o Added code to check that no LocalRegs are live-in to a procedure
   -- trip up some buggy programs earlier
o Fixed environment bindings for thunks
   -- we weren't (re)binding the free variables in a thunk
o Fixed a bug in proc-point splitting that dropped some updates
  to the entry block in a procedure.
o Fixed improper calls to code that generates CmmLit's for strings
o New invariant on cg_loc in CgIdInfo: the expression is always tagged
o Code to load free vars on entry to a thunk was (wrongly) placed before
  the heap check.
o Some of the StgCmm code was redundantly passing around Id's
  along with CgIdInfo's; no more.
o Initialize the LocalReg's that point to a closure before allocating and
  initializing the closure itself -- otherwise, we have problems with
  recursive closure bindings
o BlockEnv and BlockSet types are now abstract.
o Update frames:
  - push arguments in Old call area
  - keep track of the return sp in the FCode monad
  - keep the return sp in every call, tail call, and return
      (because it might be different at different call sites,
       e.g. tail calls to the gc after a heap check are performed
            before pushing the update frame)
  - set the sp appropriately on returns and tail calls
o Reduce call, tail call, and return to a single LastCall node
o Added slow entry code, using different calling conventions on entry and tail call
o More fixes to the calling convention code.
  The tricky stuff is all about the closure environment: it must be passed in R1,
  but in non-closures, there is no such argument, so we can't treat all arguments
  the same way: the closure environment is special. Maybe the right step forward
  would be to define a different calling convention for closure arguments.
o Let-no-escapes need to be emitted out-of-line -- otherwise, we drop code.
o Respect RTS requirement of word alignment for pointers
  My stack allocation can pack sub-word values into a single word on the stack,
  but it wasn't requiring word-alignment for pointers. It does now,
  by word-aligning both pointer registers and call areas.
o CmmLint was over-aggresively ruling out non-word-aligned memory references,
  which may be kosher now that we can spill small values into a single word.
o Wrong label order on a conditional branch when compiling switches.
o void args weren't dropped in many cases.
  To help prevent this kind of mistake, I defined a NonVoid wrapper,
  which I'm applying only to Id's for now, although there are probably
  other good candidates.
o A little code refactoring: separate modules for procpoint analysis splitting,
  stack layout, and building infotables.
o Stack limit check: insert along with the heap limit check, using a symbolic
  constant (a special CmmLit), then replace it when the stack layout is known.
o Removed last node: MidAddToContext
o Adding block id as a literal: means that the lowering of the calling conventions
  no longer has to produce labels early, which was inhibiting common-block elimination.
  Will also make it easier for the non-procpoint-splitting path.
o Info tables: don't try to describe the update frame!
o Over aggressive use of NonVoid!!!!
  Don't drop the non-void args before setting the type of the closure!!!
o Sanity checking:
  Added a pass to stub dead dead slots on the stack
  (only ~10 lines with the dataflow framework)
o More sanity checking:
  Check that incoming pointer arguments are non-stubbed.
  Note: these checks are still subject to dead-code removal, but they should
  still be quite helpful.
o Better sanity checking: why stop at function arguments?
  Instead, in mkAssign, check that _any_ assignment to a pointer type is non-null
  -- the sooner the crash, the easier it is to debug.
  Still need to add the debugging flag to turn these checks on explicitly.
o Fixed yet another calling convention bug.
  This time, the calls to the GC were wrong. I've added a new convention
  for GC calls and invoked it where appropriate.
  We should really straighten out the calling convention stuff:
    some of the code (and documentation) is spread across the compiler,
    and there's some magical use of the node register that should really
    be handled (not avoided) by calling conventions.
o Switch bug: the arms in mkCmmLitSwitch weren't returning to a single join point.
o Environment shadowing problem in Stg->Cmm:
  When a closure f is bound at the top-level, we should not bind f to the
  node register on entry to the closure.
  Why? Because if the body of f contains a let-bound closure g that refers
  to f, we want to make sure that it refers to the static closure for f.
  Normally, this would all be fine, because when we compile a closure,
  we rebind free variables in the environment. But f doesn't look like
  a free variable because it's a static value. So, the binding for f
  remains in the environment when we compile g, inconveniently referring
  to the wrong thing.
  Now, I bind the variable in the local environment only if the closure is not
  bound at the top level. It's still okay to make assumptions about the
  node holding the closure environment; we just won't find the binding
  in the environment, so code that names the closure will now directly
  get the label of the static closure, not the node register holding a
  pointer to the static closure.
o Don't generate bogus Cmm code containing SRTs during the STG -> Cmm pass!
  The tables made reference to some labels that don't exist when we compute and
  generate the tables in the back end.
o Safe foreign calls need some special treatment (at least until we have the integrated
  codegen). In particular:
  o they need info tables
  o they are not procpoints -- the successor had better be in the same procedure
  o we cannot (yet) implement the calling conventions early, which means we have
    to carry the calling-conv info all the way to the end
o We weren't following the old convention when registering a module.
  Now, we use update frames to push any new modules that have to be registered
  and enter the youngest one on the stack.
  We also use the update frame machinery to specify that the return should pop
  the return address off the stack.
o At each safe foreign call, an infotable must be at the bottom of the stack,
  and the TSO->sp must point to it.
o More problems with void args in a direct call to a function:
  We were checking the args (minus voids) to check whether the call was saturated,
  which caused problems when the function really wasn't saturated because it
  took an extra void argument.
o Forgot to distinguish integer != from floating != during Stg->Cmm
o Updating slotEnv and areaMap to include safe foreign calls
  The dataflow analyses that produce the slotEnv and areaMap give
  results for each basic block, but we also need the results for
  a safe foreign call, which is a middle node.
  After running the dataflow analysis, we have another pass that
  updates the results to includ any safe foreign calls.
o Added a static flag for the debugging technique that inserts
  instructions to stub dead slots on the stack and crashes when
  a stubbed value is loaded into a pointer-typed LocalReg.
o C back end expects to see return continuations before their call sites.
  Sorted the flowgraphs appropriately after splitting.
o PrimOp calling conventions are special -- unlimited registers, no stack
  Yet another calling convention...
o More void value problems: if the RHS of a case arm is a void-typed variable,
  don't try to return it.
o When calling some primOp, they may allocate memory; if so, we need to
  do a heap check when we return from the call.

15 years agoMerging in the new codegen branch
dias@eecs.harvard.edu [Thu, 14 Aug 2008 12:40:27 +0000 (12:40 +0000)]
Merging in the new codegen branch
This merge does not turn on the new codegen (which only compiles
a select few programs at this point),
but it does introduce some changes to the old code generator.

The high bits:
1. The Rep Swamp patch is finally here.
   The highlight is that the representation of types at the
   machine level has changed.
   Consequently, this patch contains updates across several back ends.
2. The new Stg -> Cmm path is here, although it appears to have a
   fair number of bugs lurking.
3. Many improvements along the CmmCPSZ path, including:
   o stack layout
   o some code for infotables, half of which is right and half wrong
   o proc-point splitting

15 years agoMajor clean-up of HscMain.
Thomas Schilling [Tue, 25 Nov 2008 15:32:01 +0000 (15:32 +0000)]
Major clean-up of HscMain.

This patch entails a major restructuring of HscMain and a small bugfix
to MkIface (which required the restructuring in HscMain).

In MkIface:

  - mkIface* no longer outputs orphan warnings directly and also no
    longer quits GHC when -Werror is set.  Instead, errors are
    reported using the common IO (Messages, Maybe result) scheme.

In HscMain:

  - Get rid of the 'Comp' monad.  This monad was mostly GhcMonad + two
    reader arguments, a ModSummary for the currently compiled module
    and a possible old interface.  The latter actually lead to a small
    space-leak since only its hash was needed (to check whether the
    newly-generated interface file was the same as the original one).

    Functions originally of type 'Comp' now only take the arguments
    that they actually need.  This leads to slighly longer argument
    lists in some places, however, it is now much easier to see what
    is actually going on.

  - Get rid of 'myParseModule'.  Rename 'parseFile' to 'hscParse'.

  - Join 'deSugarModule' and 'hscDesugar' (keeping the latter).

  - Rename 'typecheck{Rename}Module{'}' to 'hscTypecheck{Rename}'.
    One variant keeps the renamed syntax, the other doesn't.

  - Parameterise 'HscStatus', so that 'InteractiveStatus' is just a
    different parameterisation of 'HscStatus'.

  - 'hscCompile{OneShot,Batch,Nothing,Interactive}' are now
    implemented using a (local) typeclass called 'HsCompiler'.  The
    idea is to make the common structure more obvious.  Using this
    typeclass we now have two functions 'genericHscCompile' (original
    'hscCompiler') and 'genericHscRecompile' (original 'genComp')
    describing the default pipeline.  The methods of the typeclass
    describe a sort of "hook" interface (in OO-terms this would be
    called the "template method" pattern).

    One problem with this approach is that we parameterise over the
    /result/ type which, in fact, is not actually different for
    "nothing" and "batch" mode.  To avoid functional dependencies or
    associated types, we use type tags to make them artificially
    different and parameterise the type class over the result type.
    A perhaps better approach might be to use records instead.

  - Drop some redundant 'HscEnv' arguments.  These were likely
    different from what 'getSession' would return because during
    compilation we temporarily set the module's DynFlags as well as a
    few other fields.  We now use the 'withTempSession' combinator to
    temporarily change the 'HscEnv' and automatically restore the
    original session after the enclosed action has returned (even in
    case of exceptions).

  - Rename 'hscCompile' to 'hscGenHardCode' (since that is what it
    does).

Calls in 'GHC' and 'DriverPipeline' accordingly needed small
adaptions.

15 years agoFix Trac #2799: TcType.isOverloadedTy
simonpj@microsoft.com [Tue, 25 Nov 2008 11:05:40 +0000 (11:05 +0000)]
Fix Trac #2799: TcType.isOverloadedTy

A missing case (for equality predicates) in isOverloadedTy make
bindInstsOfLocalFuns/Pats do the wrong thing.  Core Lint nailed it.

Merge to 6.10 branch.

15 years agoFix #2740: we were missing the free variables on some expressions
Simon Marlow [Tue, 25 Nov 2008 10:31:13 +0000 (10:31 +0000)]
Fix #2740: we were missing the free variables on some expressions
Particularly boolean expresions: the conditional of an 'if', and
guards, were missing their free variables.

15 years agoFix symbol macro names in Linker.c
Thorkil Naur [Fri, 21 Nov 2008 16:01:49 +0000 (16:01 +0000)]
Fix symbol macro names in Linker.c

15 years agoAdd a --machine-readable RTS flag
Ian Lynagh [Sun, 23 Nov 2008 15:21:27 +0000 (15:21 +0000)]
Add a --machine-readable RTS flag
Currently it only affects the -t flag output

15 years agoReturn errors instead of dying in myParseModule.
Thomas Schilling [Sat, 22 Nov 2008 15:41:51 +0000 (15:41 +0000)]
Return errors instead of dying in myParseModule.

15 years agoComments/Haddockification only.
Thomas Schilling [Sat, 22 Nov 2008 14:30:18 +0000 (14:30 +0000)]
Comments/Haddockification only.

15 years agoReport source span instead of just source location for unused names.
Thomas Schilling [Sat, 22 Nov 2008 14:26:41 +0000 (14:26 +0000)]
Report source span instead of just source location for unused names.

15 years agoChange 'handleFlagWarnings' to throw exceptions instead of dying.
Thomas Schilling [Sat, 22 Nov 2008 13:06:58 +0000 (13:06 +0000)]
Change 'handleFlagWarnings' to throw exceptions instead of dying.

It now uses the standard warning log and error reporting mechanism.

15 years agoDocument exported functions in main/HeaderInfo.
Thomas Schilling [Fri, 21 Nov 2008 14:53:07 +0000 (14:53 +0000)]
Document exported functions in main/HeaderInfo.

15 years agoRemove warning supression klugde in main/HeaderInfo
Thomas Schilling [Fri, 21 Nov 2008 14:41:55 +0000 (14:41 +0000)]
Remove warning supression klugde in main/HeaderInfo

15 years agoUse mutator threads to do GC, instead of having a separate pool of GC threads
Simon Marlow [Fri, 21 Nov 2008 15:12:33 +0000 (15:12 +0000)]
Use mutator threads to do GC, instead of having a separate pool of GC threads

Previously, the GC had its own pool of threads to use as workers when
doing parallel GC.  There was a "leader", which was the mutator thread
that initiated the GC, and the other threads were taken from the pool.

This was simple and worked fine for sequential programs, where we did
most of the benchmarking for the parallel GC, but falls down for
parallel programs.  When we have N mutator threads and N cores, at GC
time we would have to stop N-1 mutator threads and start up N-1 GC
threads, and hope that the OS schedules them all onto separate cores.
It practice it doesn't, as you might expect.

Now we use the mutator threads to do GC.  This works quite nicely,
particularly for parallel programs, where each mutator thread scans
its own spark pool, which is probably in its cache anyway.

There are some flag changes:

  -g<n> is removed (-g1 is still accepted for backwards compat).
  There's no way to have a different number of GC threads than mutator
  threads now.

  -q1       Use one OS thread for GC (turns off parallel GC)
  -qg<n>    Use parallel GC for generations >= <n> (default: 1)

Using parallel GC only for generations >=1 works well for sequential
programs.  Compiling an ordinary sequential program with -threaded and
running it with -N2 or more should help if you do a lot of GC.  I've
found that adding -qg0 (do parallel GC for generation 0 too) speeds up
some parallel programs, but slows down some sequential programs.
Being conservative, I left the threshold at 1.

ToDo: document the new options.

15 years agowe shouldn't update topBound in discardSparks()
Simon Marlow [Fri, 21 Nov 2008 11:35:39 +0000 (11:35 +0000)]
we shouldn't update topBound in discardSparks()

15 years agoThrow SourceErrors instead of ProgramErrors in main/HeaderInfo.
Thomas Schilling [Fri, 21 Nov 2008 14:13:39 +0000 (14:13 +0000)]
Throw SourceErrors instead of ProgramErrors in main/HeaderInfo.

Parse errors during dependency analysis or options parsing really
shouldn't kill GHC; this is particularly annoying for GHC API clients.

15 years agofix the build when !USE_MMAP
Simon Marlow [Fri, 21 Nov 2008 08:54:18 +0000 (08:54 +0000)]
fix the build when !USE_MMAP

15 years agoround the size up to a page in mmapForLinker() instead of in the caller
Simon Marlow [Thu, 20 Nov 2008 15:40:14 +0000 (15:40 +0000)]
round the size up to a page in mmapForLinker() instead of in the caller

15 years agoFix a race in the deadlock-detection code
Simon Marlow [Thu, 20 Nov 2008 11:24:38 +0000 (11:24 +0000)]
Fix a race in the deadlock-detection code
After a deadlock it was possible for the timer signal to remain off,
which meant that the next deadlock would not be detected, and the
system would hang.  Spotted by conc047(threaded2).

15 years agoerror message wibble
Simon Marlow [Thu, 20 Nov 2008 08:49:01 +0000 (08:49 +0000)]
error message wibble

15 years agoFix flag name -XDisambiguateRecordFields
simonpj@microsoft.com [Thu, 20 Nov 2008 12:32:05 +0000 (12:32 +0000)]
Fix flag name -XDisambiguateRecordFields

15 years agoFix regTableToCapability() if gcc introduces padding
Simon Marlow [Wed, 19 Nov 2008 16:29:10 +0000 (16:29 +0000)]
Fix regTableToCapability() if gcc introduces padding
Also avoid padding if possible using __attribute__((packed))
Fixes the Windows build

15 years agoFix 32-bit breakage
Simon Marlow [Wed, 19 Nov 2008 14:54:29 +0000 (14:54 +0000)]
Fix 32-bit breakage