1. 19 Jul, 2005 1 commit
    • simonpj's avatar
      [project @ 2005-07-19 16:44:50 by simonpj] · a7ecdf96
      simonpj authored
      WARNING: this is a big commit.  You might want 
      	to wait a few days before updating, in case I've 
      	broken something.
      
      	However, if any of the changes are what you wanted,
      	please check it out and test!
      
      This commit does three main things:
      
      1. A re-organisation of the way that GHC handles bindings in HsSyn.
         This has been a bit of a mess for quite a while.  The key new
         types are
      
      	-- Bindings for a let or where clause
      	data HsLocalBinds id
      	  = HsValBinds (HsValBinds id)
      	  | HsIPBinds  (HsIPBinds id)
      	  | EmptyLocalBinds
      
      	-- Value bindings (not implicit parameters)
      	data HsValBinds id
      	  = ValBindsIn  -- Before typechecking
      		(LHsBinds id) [LSig id]	-- Not dependency analysed
      					-- Recursive by default
      
      	  | ValBindsOut	-- After typechecking
      		[(RecFlag, LHsBinds id)]-- Dependency analysed
      
      2. Implement Mark Jones's idea of increasing polymoprhism
         by using type signatures to cut the strongly-connected components
         of a recursive group.  As a consequence, GHC no longer insists
         on the contexts of the type signatures of a recursive group
         being identical.
      
         This drove a significant change: the renamer no longer does dependency
         analysis.  Instead, it attaches a free-variable set to each binding,
         so that the type checker can do the dep anal.  Reason: the typechecker
         needs to do *two* analyses:
      	one to find the true mutually-recursive groups
      		(which we need so we can build the right CoreSyn)
      	one to find the groups in which to typecheck, taking
      		account of type signatures
      
      3. Implement non-ground SPECIALISE pragmas, as promised, and as
         requested by Remi and Ross.  Certainly, this should fix the 
         current problem with GHC, namely that if you have
      	g :: Eq a => a -> b -> b
         then you can now specialise thus
      	SPECIALISE g :: Int -> b -> b
          (This didn't use to work.)
      
         However, it goes further than that.  For example:
      	f :: (Eq a, Ix b) => a -> b -> b
         then you can make a partial specialisation
      	SPECIALISE f :: (Eq a) => a -> Int -> Int
      
          In principle, you can specialise f to *any* type that is
          "less polymorphic" (in the sense of subsumption) than f's 
          actual type.  Such as
      	SPECIALISE f :: Eq a => [a] -> Int -> Int
          But I haven't tested that.
      
          I implemented this by doing the specialisation in the typechecker
          and desugarer, rather than leaving around the strange SpecPragmaIds,
          for the specialiser to find.  Indeed, SpecPragmaIds have vanished 
          altogether (hooray).
      
          Pragmas in general are handled more tidily.  There's a new
          data type HsBinds.Prag, which lives in an AbsBinds, and carries
          pragma info from the typechecker to the desugarer.
      
      
      Smaller things
      
      - The loop in the renamer goes via RnExpr, instead of RnSource.
        (That makes it more like the type checker.)
      
      - I fixed the thing that was causing 'check_tc' warnings to be 
        emitted.
      a7ecdf96
  2. 28 Apr, 2005 1 commit
    • simonpj's avatar
      [project @ 2005-04-28 10:09:41 by simonpj] · dd313897
      simonpj authored
      This big commit does several things at once (aeroplane hacking)
      which change the format of interface files.  
      
      	So you'll need to recompile your libraries!
      
      1. The "stupid theta" of a newtype declaration
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Retain the "stupid theta" in a newtype declaration.
      For some reason this was being discarded, and putting it
      back in meant changing TyCon and IfaceSyn slightly.
         
      
      2. Overlap flags travel with the instance
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Arrange that the ability to support overlap and incoherence
      is a property of the *instance declaration* rather than the
      module that imports the instance decl.  This allows a library
      writer to define overlapping instance decls without the
      library client having to know.  
      
      The implementation is that in an Instance we store the
      overlap flag, and preseve that across interface files
      
      
      3. Nuke the "instnce pool" and "rule pool"
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      A major tidy-up and simplification of the way that instances
      and rules are sucked in from interface files.  Up till now
      an instance decl has been held in a "pool" until its "gates" 
      (a set of Names) are in play, when the instance is typechecked
      and added to the InstEnv in the ExternalPackageState.  
      This is complicated and error-prone; it's easy to suck in 
      too few (and miss an instance) or too many (and thereby be
      forced to suck in its type constructors, etc).
      
      Now, as we load an instance from an interface files, we 
      put it straight in the InstEnv... but the Instance we put in
      the InstEnv has some Names (the "rough-match" names) that 
      can be used on lookup to say "this Instance can't match".
      The detailed dfun is only read lazily, and the rough-match
      thing meansn it is'nt poked on until it has a chance of
      being needed.
      
      This simply continues the successful idea for Ids, whereby
      they are loaded straightaway into the TypeEnv, but their
      TyThing is a lazy thunk, not poked on until the thing is looked
      up.
      
      Just the same idea applies to Rules.
      
      On the way, I made CoreRule and Instance into full-blown records
      with lots of info, with the same kind of key status as TyCon or 
      DataCon or Class.  And got rid of IdCoreRule altogether.   
      It's all much more solid and uniform, but it meant touching
      a *lot* of modules.
      
      
      4. Allow instance decls in hs-boot files
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Allowing instance decls in hs-boot files is jolly useful, becuase
      in a big mutually-recursive bunch of data types, you want to give
      the instances with the data type declarations.  To achieve this
      
      * The hs-boot file makes a provisional name for the dict-fun, something
        like $fx9.
      
      * When checking the "mother module", we check that the instance
        declarations line up (by type) and generate bindings for the 
        boot dfuns, such as
      	$fx9 = $f2
        where $f2 is the dfun generated by the mother module
      
      * In doing this I decided that it's cleaner to have DFunIds get their
        final External Name at birth.  To do that they need a stable OccName,
        so I have an integer-valued dfun-name-supply in the TcM monad.
        That keeps it simple.
      
      This feature is hardly tested yet.
      
      
      5. Tidy up tidying, and Iface file generation
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      main/TidyPgm now has two entry points:
      
        simpleTidyPgm is for hi-boot files, when typechecking only
        (not yet implemented), and potentially when compiling without -O.
        It ignores the bindings, and generates a nice small TypeEnv.
      
        optTidyPgm is the normal case: compiling with -O.  It generates a
        TypeEnv rich in IdInfo
      
      MkIface.mkIface now only generates a ModIface.  A separate
      procedure, MkIface.writeIfaceFile, writes the file out to disk.
      dd313897
  3. 04 Apr, 2005 1 commit
    • simonpj's avatar
      [project @ 2005-04-04 11:55:11 by simonpj] · d551dbfe
      simonpj authored
      This commit combines three overlapping things:
      
      1.  Make rebindable syntax work for do-notation. The idea
          here is that, in particular, (>>=) can have a type that
          has class constraints on its argument types, e.g.
             (>>=) :: (Foo m, Baz a) => m a -> (a -> m b) -> m b
          The consequence is that a BindStmt and ExprStmt must have
          individual evidence attached -- previously it was one
          batch of evidence for the entire Do
          
          Sadly, we can't do this for MDo, because we use bind at
          a polymorphic type (to tie the knot), so we still use one
          blob of evidence (now in the HsStmtContext) for MDo.
          
          For arrow syntax, the evidence is in the HsCmd.
          
          For list comprehensions, it's all built-in anyway.
          
          So the evidence on a BindStmt is only used for ordinary
          do-notation.
      
      2.  Tidy up HsSyn.  In particular:
      
      	- Eliminate a few "Out" forms, which we can manage
      	without (e.g. 
      
      	- It ought to be the case that the type checker only
      	decorates the syntax tree, but doesn't change one
      	construct into another.  That wasn't true for NPat,
      	LitPat, NPlusKPat, so I've fixed that.
      
      	- Eliminate ResultStmts from Stmt.  They always had
      	to be the last Stmt, which led to awkward pattern
      	matching in some places; and the benefits didn't seem
      	to outweigh the costs.  Now each construct that uses
      	[Stmt] has a result expression too (e.g. GRHS).
      
      
      3.  Make 'deriving( Ix )' generate a binding for unsafeIndex,
          rather than for index.  This is loads more efficient.
      
          (This item only affects TcGenDeriv, but some of point (2)
          also affects TcGenDeriv, so it has to be in one commit.)
      d551dbfe
  4. 07 Mar, 2005 1 commit
    • simonpj's avatar
      [project @ 2005-03-07 16:46:08 by simonpj] · 36d22a1c
      simonpj authored
      -----------------------------------------
             Fix a long-standing indirection-zapping bug
      	-----------------------------------------
      
      	Merge to STABLE
      
      Up to now we zap indirections as part of the occurence analyser.
      But this is bogus.  The indirection zapper does the following:
      
      	x_local = <expression>
      	...bindings...
      	x_exported = x_local
      
      where x_exported is exported, and x_local is not, then we
      replace it with this:
      
      	x_exported = <expression>
      	x_local = x_exported
      	...bindings...
      
      But this is plain wrong if x_exported has a RULE that mentions
      something (f, say) in ...bindings.., because 'f' will then die.
      
      After hacking a few solutions, I've eventually simply made the indirection
      zapping into a separate pass (which is cleaner anyway), which wraps the
      entire program back into a single Rec if the bad thing can happen.
      
      On the way I've made indirection-zapping work in Recs too, which wasn't the
      case before.
      
      * Move the zapper from OccurAnal into SimplCore
      * Tidy up the printing of pragmas (PprCore and friends)
      * Add a new function Rules.addRules
      * Merge rules in the indirection zapper (previously one set was discarded)
      36d22a1c
  5. 30 Sep, 2004 1 commit
    • simonpj's avatar
      [project @ 2004-09-30 10:35:15 by simonpj] · 23f40f0e
      simonpj authored
      ------------------------------------
      	Add Generalised Algebraic Data Types
      	------------------------------------
      
      This rather big commit adds support for GADTs.  For example,
      
          data Term a where
       	  Lit :: Int -> Term Int
      	  App :: Term (a->b) -> Term a -> Term b
      	  If  :: Term Bool -> Term a -> Term a
      	  ..etc..
      
          eval :: Term a -> a
          eval (Lit i) = i
          eval (App a b) = eval a (eval b)
          eval (If p q r) | eval p    = eval q
          		    | otherwise = eval r
      
      
      Lots and lots of of related changes throughout the compiler to make
      this fit nicely.
      
      One important change, only loosely related to GADTs, is that skolem
      constants in the typechecker are genuinely immutable and constant, so
      we often get better error messages from the type checker.  See
      TcType.TcTyVarDetails.
      
      There's a new module types/Unify.lhs, which has purely-functional
      unification and matching for Type. This is used both in the typechecker
      (for type refinement of GADTs) and in Core Lint (also for type refinement).
      23f40f0e
  6. 21 Apr, 2004 1 commit
  7. 09 Oct, 2003 1 commit
    • simonpj's avatar
      [project @ 2003-10-09 11:58:39 by simonpj] · 98688c6e
      simonpj authored
      -------------------------
      		GHC heart/lung transplant
      		-------------------------
      
      This major commit changes the way that GHC deals with importing
      types and functions defined in other modules, during renaming and
      typechecking.  On the way I've changed or cleaned up numerous other
      things, including many that I probably fail to mention here.
      
      Major benefit: GHC should suck in many fewer interface files when
      compiling (esp with -O).  (You can see this with -ddump-rn-stats.)
      
      It's also some 1500 lines of code shorter than before.
      
      **	So expect bugs!  I can do a 3-stage bootstrap, and run
      **	the test suite, but you may be doing stuff I havn't tested.
      ** 	Don't update if you are relying on a working HEAD.
      
      
      In particular, (a) External Core and (b) GHCi are very little tested.
      
      	But please, please DO test this version!
      
      
      	------------------------
      		Big things
      	------------------------
      
      Interface files, version control, and importing declarations
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      * There is a totally new data type for stuff that lives in interface files:
      	Original names			IfaceType.IfaceExtName
      	Types				IfaceType.IfaceType
      	Declarations (type,class,id)	IfaceSyn.IfaceDecl
      	Unfoldings			IfaceSyn.IfaceExpr
        (Previously we used HsSyn for type/class decls, and UfExpr for unfoldings.)
        The new data types are in iface/IfaceType and iface/IfaceSyn.  They are
        all instances of Binary, so they can be written into interface files.
        Previous engronkulation concering the binary instance of RdrName has
        gone away -- RdrName is not an instance of Binary any more.  Nor does
        Binary.lhs need to know about the ``current module'' which it used to,
        which made it specialised to GHC.
      
        A good feature of this is that the type checker for source code doesn't
        need to worry about the possibility that we might be typechecking interface
        file stuff.  Nor does it need to do renaming; we can typecheck direct from
        IfaceSyn, saving a whole pass (module TcIface)
      
      * Stuff from interface files is sucked in *lazily*, rather than being eagerly
        sucked in by the renamer. Instead, we use unsafeInterleaveIO to capture
        a thunk for the unfolding of an imported function (say).  If that unfolding
        is every pulled on, TcIface will scramble over the unfolding, which may
        in turn pull in the interface files of things mentioned in the unfolding.
      
        The External Package State is held in a mutable variable so that it
        can be side-effected by this lazy-sucking-in process (which may happen
        way later, e.g. when the simplifier runs).   In effect, the EPS is a kind
        of lazy memo table, filled in as we suck things in.  Or you could think
        of it as a global symbol table, populated on demand.
      
      * This lazy sucking is very cool, but it can lead to truly awful bugs. The
        intent is that updates to the symbol table happen atomically, but very bad
        things happen if you read the variable for the table, and then force a
        thunk which updates the table.  Updates can get lost that way. I regret
        this subtlety.
      
        One example of the way it showed up is that the top level of TidyPgm
        (which updates the global name cache) to be much more disciplined about
        those updates, since TidyPgm may itself force thunks which allocate new
        names.
      
      * Version numbering in interface files has changed completely, fixing
        one major bug with ghc --make.  Previously, the version of A.f changed
        only if A.f's type and unfolding was textually different.  That missed
        changes to things that A.f's unfolding mentions; which was fixed by
        eagerly sucking in all of those things, and listing them in the module's
        usage list.  But that didn't work with --make, because they might have
        been already sucked in.
      
        Now, A.f's version changes if anything reachable from A.f (via interface
        files) changes.  A module with unchanged source code needs recompiling
        only if the versions of any of its free variables changes. [This isn't
        quite right for dictionary functions and rules, which aren't mentioned
        explicitly in the source.  There are extensive comments in module MkIface,
        where all version-handling stuff is done.]
      
      * We don't need equality on HsDecls any more (because they aren't used in
        interface files).  Instead we have a specialised equality for IfaceSyn
        (eqIfDecl etc), which uses IfaceEq instead of Bool as its result type.
        See notes in IfaceSyn.
      
      * The horrid bit of the renamer that tried to predict what instance decls
        would be needed has gone entirely.  Instead, the type checker simply
        sucks in whatever instance decls it needs, when it needs them.  Easy!
      
        Similarly, no need for 'implicitModuleFVs' and 'implicitTemplateHaskellFVs'
        etc.  Hooray!
      
      
      Types and type checking
      ~~~~~~~~~~~~~~~~~~~~~~~
      * Kind-checking of types is far far tidier (new module TcHsTypes replaces
        the badly-named TcMonoType).  Strangely, this was one of my
        original goals, because the kind check for types is the Right Place to
        do type splicing, but it just didn't fit there before.
      
      * There's a new representation for newtypes in TypeRep.lhs.  Previously
        they were represented using "SourceTypes" which was a funny compromise.
        Now they have their own constructor in the Type datatype.  SourceType
        has turned back into PredType, which is what it used to be.
      
      * Instance decl overlap checking done lazily.  Consider
      	instance C Int b
      	instance C a Int
        These were rejected before as overlapping, because when seeking
        (C Int Int) one couldn't tell which to use.  But there's no problem when
        seeking (C Bool Int); it can only be the second.
      
        So instead of checking for overlap when adding a new instance declaration,
        we check for overlap when looking up an Inst.  If we find more than one
        matching instance, we see if any of the candidates dominates the others
        (in the sense of being a substitution instance of all the others);
        and only if not do we report an error.
      
      
      
      	------------------------
      	     Medium things
      	------------------------
      
      * The TcRn monad is generalised a bit further.  It's now based on utils/IOEnv.lhs,
        the IO monad with an environment.  The desugarer uses the monad too,
        so that anything it needs can get faulted in nicely.
      
      * Reduce the number of wired-in things; in particular Word and Integer
        are no longer wired in.  The latter required HsLit.HsInteger to get a
        Type argument.  The 'derivable type classes' data types (:+:, :*: etc)
        are not wired in any more either (see stuff about derivable type classes
        below).
      
      * The PersistentComilerState is now held in a mutable variable
        in the HscEnv.  Previously (a) it was passed to and then returned by
        many top-level functions, which was painful; (b) it was invariably
        accompanied by the HscEnv.  This change tidies up top-level plumbing
        without changing anything important.
      
      * Derivable type classes are treated much more like 'deriving' clauses.
        Previously, the Ids for the to/from functions lived inside the TyCon,
        but now the TyCon simply records their existence (with a simple boolean).
        Anyone who wants to use them must look them up in the environment.
      
        This in turn makes it easy to generate the to/from functions (done
        in types/Generics) using HsSyn (like TcGenDeriv for ordinary derivings)
        instead of CoreSyn, which in turn means that (a) we don't have to figure
        out all the type arguments etc; and (b) it'll be type-checked for us.
        Generally, the task of generating the code has become easier, which is
        good for Manuel, who wants to make it more sophisticated.
      
      * A Name now says what its "parent" is. For example, the parent of a data
        constructor is its type constructor; the parent of a class op is its
        class.  This relationship corresponds exactly to the Avail data type;
        there may be other places we can exploit it.  (I made the change so that
        version comparison in interface files would be a bit easier; but in
        fact it tided up other things here and there (see calls to
        Name.nameParent).  For example, the declaration pool, of declararations
        read from interface files, but not yet used, is now keyed only by the 'main'
        name of the declaration, not the subordinate names.
      
      * New types OccEnv and OccSet, with the usual operations.
        OccNames can be efficiently compared, because they have uniques, thanks
        to the hashing implementation of FastStrings.
      
      * The GlobalRdrEnv is now keyed by OccName rather than RdrName.  Not only
        does this halve the size of the env (because we don't need both qualified
        and unqualified versions in the env), but it's also more efficient because
        we can use a UniqFM instead of a FiniteMap.
      
        Consequential changes to Provenance, which has moved to RdrName.
      
      * External Core remains a bit of a hack, as it was before, done with a mixture
        of HsDecls (so that recursiveness and argument variance is still inferred),
        and IfaceExprs (for value declarations).  It's not thoroughly tested.
      
      
      	------------------------
      	     Minor things
      	------------------------
      
      * DataCon fields dcWorkId, dcWrapId combined into a single field
        dcIds, that is explicit about whether the data con is a newtype or not.
        MkId.mkDataConWorkId and mkDataConWrapId are similarly combined into
        MkId.mkDataConIds
      
      * Choosing the boxing strategy is done for *source* type decls only, and
        hence is now in TcTyDecls, not DataCon.
      
      * WiredIn names are distinguished by their n_sort field, not by their location,
        which was rather strange
      
      * Define Maybes.mapCatMaybes :: (a -> Maybe b) -> [a] -> [b]
        and use it here and there
      
      * Much better pretty-printing of interface files (--show-iface)
      
      Many, many other small things.
      
      
      	------------------------
      	     File changes
      	------------------------
      * New iface/ subdirectory
      * Much of RnEnv has moved to iface/IfaceEnv
      * MkIface and BinIface have moved from main/ to iface/
      * types/Variance has been absorbed into typecheck/TcTyDecls
      * RnHiFiles and RnIfaces have vanished entirely.  Their
        work is done by iface/LoadIface
      * hsSyn/HsCore has gone, replaced by iface/IfaceSyn
      * typecheck/TcIfaceSig has gone, replaced by iface/TcIface
      * typecheck/TcMonoType has been renamed to typecheck/TcHsType
      * basicTypes/Var.hi-boot and basicTypes/Generics.hi-boot have gone altogether
      98688c6e
  8. 23 Sep, 2003 1 commit
    • simonpj's avatar
      [project @ 2003-09-23 15:15:02 by simonpj] · 6c4a98d3
      simonpj authored
      --------------------------
           Move demand-zapping code to where it belongs
      	   --------------------------
      
      A rather subtle point in the simplifier concerns the zapping of demand-info
      when the RHS of a binding is a value.  This used to be tucked away inside
      IdInfo where it was hard to find.  This commit moves the code to Simplify,
      so it occurs where you'd look for it.  Along with copious comments.
      
      See the zapDemandInfo in Simplify.completeLazyBind
      6c4a98d3
  9. 24 Mar, 2003 1 commit
    • simonmar's avatar
      [project @ 2003-03-24 11:23:20 by simonmar] · 82387309
      simonmar authored
      #ifdef some more code that belongs to the old strictness analyser.
      
      It turns out we were still compiling the Demand and SaLib modules,
      which aren't required unless OLD_STRICTNESS is on (do we still need
      OLD_STRICTNESS?).
      82387309
  10. 03 Mar, 2003 1 commit
    • simonmar's avatar
      [project @ 2003-03-03 12:43:31 by simonmar] · 19108ede
      simonmar authored
      A round of space-leak fixing.
      
        - re-instate zapping of the PersistentCompilerState at various
          points during the compilation cycle in HscMain.  This affects
          one-shot compilation only, since in this mode the information
          collected in the PCS is not required after creating the final
          interface file.
      
        - Unravel the recursive dependency between MkIface and
          CoreTidy/CoreToStg.  Previously the CafInfo for each binding was
          calculated by CoreToStg, and fed back into the IdInfo of the Ids
          generated by CoreTidy (an earlier pass).  MkIface then took this
          IdInfo and the bindings from CoreTidy to generate the interface;
          but it couldn't do this until *after* CoreToStg, because the CafInfo
          hadn't been calculated yet.  The result was that the CoreTidy
          output lived until after CoreToStg, and at the same time as the
          CorePrep and STG syntax, which is wasted space, not to mention
          the complexity and general ugliness in HscMain.
      
          So now we calculate CafInfo directly in CoreTidy.  The downside is
          that we have to predict what CorePrep is going to do to the
          bindings so we can tell what will turn into a CAF later, but it's
          no worse than before (it turned out that we were doing this
          prediction before in CoreToStg anyhow).
      
        - The typechecker lazilly typechecks unfoldings.  It turns out that
          this is a good idea from a performance perspective, but it also
          means that it must hang on to all the information it needs to
          do the typechecking.  Previously this meant holding on to the
          whole of the typechecker's environment, which includes all sorts
          of stuff which isn't necessary to typecheck unfoldings.  By paring
          down the environment captured by the lazy unfoldings, we can
          save quite a bit of space in the phases after typechecking.
      19108ede
  11. 19 Feb, 2003 1 commit
    • simonpj's avatar
      [project @ 2003-02-19 15:54:05 by simonpj] · 3355c9d5
      simonpj authored
      -------------------------------------
      	 	Two minor wibbles
      	-------------------------------------
      
      
      1.  Make the generic toT/fromT Ids for "generic derived classes" into
          proper ImplicitIds, with their own GlobalIdDetails. This makes it
          easier to identify them.  (The lack of this showed up as a bug
          when I made an apparently-innocuous other change.)
      
      2.  Distinguish ClassOpIds from RecordSelIds in their GlobalIdDetails.
          They are treated differently here and there, so I made this change
          as part of (1)
      
      3.  Ensure that a declaration quotation [d| ... |] does not have a
          permanent effect on the instance environment. (A TH fix.)
      3355c9d5
  12. 12 Feb, 2003 1 commit
    • simonpj's avatar
      [project @ 2003-02-12 15:01:31 by simonpj] · 42b63073
      simonpj authored
      -------------------------------------
        Big upheaval to the way that constructors are named
      	-------------------------------------
      
      This commit enshrines the new story for constructor names.  We could never
      really get External Core to work nicely before, but now it does.
      
      The story is laid out in detail in the Commentary
      	ghc/docs/comm/the-beast/data-types.html
      so I will not repeat it here.
      
      	[Manuel: the commentary isn't being updated, apparently.]
      
      However, the net effect is that in Core and in External Core, contructors look
      like constructors, and the way things are printed is all consistent.
      
      It is a fairly pervasive change (which is why it has been so long postponed),
      but I hope the question is now finally closed.
      
      All the libraries compile etc, and I've run many tests, but doubtless there will
      be some dark corners.
      42b63073
  13. 04 Feb, 2003 2 commits
    • simonpj's avatar
      [project @ 2003-02-04 15:09:38 by simonpj] · 957bf375
      simonpj authored
      -------------------------------------
      	Remove all vestiges of usage analysis
      	-------------------------------------
      
      This commit removes a large blob of usage-analysis-related code, almost
      all of which was commented out.
      
      Sadly, it doesn't look as if Keith is going to have enough time to polish it
      up, and in any case the actual performance benefits (so far as we can measure
      them) turned out to be pretty modest (a few percent).
      
      So, with regret, I'm chopping it all out.  It's still there in the repository
      if anyone wants go hack on it.  And Tobias Gedell at Chalmers is implementing
      a different analysis, via External Core.
      957bf375
    • simonpj's avatar
      [project @ 2003-02-04 12:33:05 by simonpj] · e6d00492
      simonpj authored
      ---------------------------------------------------
      	Template-Haskell fix to make the global environment
      		      more side-effect-ful
      	---------------------------------------------------
      
      Consider
      
      	f = $(...foldl...) $(...foldl...)
      
      The first splice sucks in the type sig for foldl, which the second
      splice needs.  That means that the second splice is going to have to
      consult the persistent compiler state to see the effect of imports
      by the first one.
      
      We used to cache the global type environment in the TcGblEnv, but
      this commit switches to the obvious thing: consult the persistent
      state on every global lookup.  After all, reading a MutVar is no
      big deal; and it's a benign, ever-growing cache of type signatures,
      so the side effect is fine.
      
      On the way I tidied up the knot-tying in TcIfaceSig a bit more.
      Previously, I think the setUnfoldingInfo was being strict in the
      unfolding, which forced it to be type-checked.  Now it's lazy.
      That could mean a lot less typechecking overall, for things whose
      unfolding isn't looked at.  I hope I havn't broken it, though.
      e6d00492
  14. 09 Oct, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-10-09 15:03:48 by simonpj] · 8c1b6bd7
      simonpj authored
      -----------------------------------
      	Lots more Template Haskell stuff
      	-----------------------------------
      
      At last!  Top-level declaration splices work!
      Syntax is
      
      	$(f x)
      
      not "splice (f x)" as in the paper.
      
      Lots jiggling around, particularly with the top-level plumbining.
      Note the new data type HsDecls.HsGroup.
      8c1b6bd7
  15. 13 Sep, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-09-13 15:02:25 by simonpj] · 9af77fa4
      simonpj authored
      --------------------------------------
      	Make Template Haskell into the HEAD
      	--------------------------------------
      
      This massive commit transfers to the HEAD all the stuff that
      Simon and Tim have been doing on Template Haskell.  The
      meta-haskell-branch is no more!
      
      WARNING: make sure that you
      
        * Update your links if you are using link trees.
          Some modules have been added, some have gone away.
      
        * Do 'make clean' in all library trees.
          The interface file format has changed, and you can
          get strange panics (sadly) if GHC tries to read old interface files:
          e.g.  ghc-5.05: panic! (the `impossible' happened, GHC version 5.05):
      	  Binary.get(TyClDecl): ForeignType
      
        * You need to recompile the rts too; Linker.c has changed
      
      
      However the libraries are almost unaltered; just a tiny change in
      Base, and to the exports in Prelude.
      
      
      NOTE: so far as TH itself is concerned, expression splices work
      fine, but declaration splices are not complete.
      
      
      		---------------
      		The main change
      		---------------
      
      The main structural change: renaming and typechecking have to be
      interleaved, because we can't rename stuff after a declaration splice
      until after we've typechecked the stuff before (and the splice
      itself).
      
      * Combine the renamer and typecheker monads into one
      	(TcRnMonad, TcRnTypes)
        These two replace TcMonad and RnMonad
      
      * Give them a single 'driver' (TcRnDriver).  This driver
        replaces TcModule.lhs and Rename.lhs
      
      * The haskell-src library package has a module
      	Language/Haskell/THSyntax
        which defines the Haskell data type seen by the TH programmer.
      
      * New modules:
      	hsSyn/Convert.hs 	converts THSyntax -> HsSyn
      	deSugar/DsMeta.hs 	converts HsSyn -> THSyntax
      
      * New module typecheck/TcSplice type-checks Template Haskell splices.
      
      		-------------
      		Linking stuff
      		-------------
      
      * ByteCodeLink has been split into
      	ByteCodeLink	(which links)
      	ByteCodeAsm	(which assembles)
      
      * New module ghci/ObjLink is the object-code linker.
      
      * compMan/CmLink is removed entirely (was out of place)
        Ditto CmTypes (which was tiny)
      
      * Linker.c initialises the linker when it is first used (no need to call
        initLinker any more).  Template Haskell makes it harder to know when
        and whether to initialise the linker.
      
      
      	-------------------------------------
      	Gathering the LIE in the type checker
      	-------------------------------------
      
      * Instead of explicitly gathering constraints in the LIE
      	tcExpr :: RenamedExpr -> TcM (TypecheckedExpr, LIE)
        we now dump the constraints into a mutable varabiable carried
        by the monad, so we get
      	tcExpr :: RenamedExpr -> TcM TypecheckedExpr
      
        Much less clutter in the code, and more efficient too.
        (Originally suggested by Mark Shields.)
      
      
      		-----------------
      		Remove "SysNames"
      		-----------------
      
      Because the renamer and the type checker were entirely separate,
      we had to carry some rather tiresome implicit binders (or "SysNames")
      along inside some of the HsDecl data structures.  They were both
      tiresome and fragile.
      
      Now that the typechecker and renamer are more intimately coupled,
      we can eliminate SysNames (well, mostly... default methods still
      carry something similar).
      
      		-------------
      		Clean up HsPat
      		-------------
      
      One big clean up is this: instead of having two HsPat types (InPat and
      OutPat), they are now combined into one.  This is more consistent with
      the way that HsExpr etc is handled; there are some 'Out' constructors
      for the type checker output.
      
      So:
      	HsPat.InPat	--> HsPat.Pat
      	HsPat.OutPat	--> HsPat.Pat
      	No 'pat' type parameter in HsExpr, HsBinds, etc
      
      	Constructor patterns are nicer now: they use
      		HsPat.HsConDetails
      	for the three cases of constructor patterns:
      		prefix, infix, and record-bindings
      
      	The *same* data type HsConDetails is used in the type
      	declaration of the data type (HsDecls.TyData)
      
      Lots of associated clean-up operations here and there.  Less code.
      Everything is wonderful.
      9af77fa4
  16. 28 Jun, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-06-28 14:06:52 by simonpj] · 33ce2a14
      simonpj authored
      -----------------------------------
      	Fix the CAF info field of error Ids
      	-----------------------------------
      
      A bizarre bug.   In MkId, we build the Id for various error-y
      Ids (like pAT_ERROR_ID) that we grab out of thin air in various
      places (like the desugarer).  They were marked as not referring
      to any CAFs, but this was a lie!  In fact, they refer to 'untangle'
      (see GHC.Err) and thence to a CAF.
      
      Result: GC crash under very obscure circumstances.  (Rob's optimistic
      evaluator tickled it.)
      
      Solution: give them more conservative IdInfo.
      
      Two other better solutions to think about:
      
      * Don't grab them out of thin air; instead get them from
        an interface file.
      
      * Treat them as always-live (requires mod to garbage collector)
        so they don't need to be mentioned in SRTs at all
      33ce2a14
  17. 14 Jun, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-06-14 14:03:25 by simonpj] · 990dd09b
      simonpj authored
      ---------------------------------------
      	Utterly expunge the tyGenInfo field of
      			an IdInfo
      	---------------------------------------
      
      tyGenInfo was a relic of a previous version of Keith's usage
      analyser.  It's just dead code, so I've nuked it.
      990dd09b
  18. 22 Apr, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-04-22 16:06:35 by simonpj] · dbfe93e6
      simonpj authored
      CPR control
      
      1.  Remove -fno-cpr, add -fcpr-off which is a simple static flag
          for switching the new CPR analysis off altogether.
          (The "-fno" machinery is rather complicated.)
      
      2.  Rejig SimplCore a little so that the "old strictness analyser"
          runs both the old strictness analyser and the old CPR analyser,
          which makes it more like the new strictness/CPR analyser.
      
          (How much longer we keep the old strictness/CPR analyser in the
          compiler at all I don't know.  It's just for comparision purposes
          when we write the paper.)
      dbfe93e6
  19. 04 Apr, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-04-04 13:15:18 by simonpj] · c44e1c41
      simonpj authored
      ---------------------------------------
      	A glorious improvement to CPR analysis
      	---------------------------------------
      
      Working on the CPR paper, I finally figured out how to
      do a decent job of taking account of strictness analyis when doing
      CPR analysis.
      
      There are two places we do that:
      
      1.  Usually, on a letrec for a *thunk* we discard any CPR info from
      the RHS.  We can't worker/wrapper a thunk.  BUT, if the let is
      	non-recursive
      	non-top-level
      	used strictly
      we don't need to discard the CPR info, because the thunk-splitting
      transform (WorkWrap.splitThunk) works.  This idea isn't new in this
      commit.
      
      
      2. Arguments to strict functions.  Consider
      
        fac n m = if n==0 then m
      		    else fac (n-1) (m*n)
      
      Does it have the CPR property?  Apparently not, because it returns the
      accumulating parameter, m.  But the strictness analyser will
      discover that fac is strict in m, so it will be passed unboxed to
      the worker for fac.  More concretely, here is the worker/wrapper
      split that will result from strictness analysis alone:
      
        fac n m = case n of MkInt n' ->
      	    case m of MkInt m' ->
      	    facw n' m'
      
        facw n' m' = if n' ==# 0#
      	       then I# m'
      	       else facw (n' -# 1#) (m' *# n')
      
      Now facw clearly does have the CPR property!  We can take advantage
      of this by giving a demanded lambda the CPR property.
      
      
      To make this work nicely, I've made NewDemandInfo into Maybe Demand
      rather than simply Demand, so that we can tell when we are on the
      first iteration.  Lots of comments about this in Note [CPR-AND-STRICTNESS].
      
      I don't know how much all this buys us, but it is simple and elegant.
      c44e1c41
  20. 15 Mar, 2002 1 commit
  21. 14 Mar, 2002 1 commit
  22. 11 Dec, 2001 3 commits
  23. 10 Dec, 2001 1 commit
    • simonmar's avatar
      [project @ 2001-12-10 14:07:30 by simonmar] · 973539a8
      simonmar authored
      Make the inclusion of the old strictness analyser, CPR analyser, and
      the relevant IdInfo components, conditional on DEBUG.  This makes
      IdInfo smaller by three fields in a non-DEBUG compiler, and reduces
      the risk that the unused fields could harbour space leaks.
      
      Eventually these passes will go away altogether.
      973539a8
  24. 19 Nov, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-11-19 14:23:52 by simonpj] · d8af6b8c
      simonpj authored
      --------------------------------------
      	Yet another cut at the DmdAnal domains
      	--------------------------------------
      
      This version of the domain for demand analysis was developed
      in discussion with Peter Sestoft, so I think it might at last
      be more or less right!
      
      Our idea is mentally to separate
      	strictness analysis
      from
      	absence and boxity analysis
      
      Then we combine them back into a single domain.  The latter
      is all you see in the compiler (the Demand type, as before)
      but we understand it better now.
      d8af6b8c
  25. 25 Oct, 2001 1 commit
    • sof's avatar
      [project @ 2001-10-25 02:13:10 by sof] · 9e933350
      sof authored
      - Pet peeve removal / code tidyup, replaced various sub-optimal
        uses of 'length' with something a bit better, i.e., replaced
        the following patterns
      
         *  length as `cmpOp` length bs
         *  length as `cmpOp` val   -- incl. uses where val == 1 and val == 0
         *  {take,drop,splitAt} (length as) bs
         *  length [ () | pat <- as ]
      
        with uses of misc Util functions.
      
        I'd be surprised if there's a noticeable reduction in running
        times as a result of these changes, but every little bit helps.
      
        [ The changes have been tested wrt testsuite/ - I'm seeing a couple
          of unexpected breakages coming from CorePrep, but I'm currently
          assuming that these are due to other recent changes. ]
      
      - compMan/CompManager.lhs: restored 4.08 compilability + some code
        cleanup.
      
      None of these changes are HEADworthy.
      9e933350
  26. 23 Oct, 2001 1 commit
    • sof's avatar
      [project @ 2001-10-23 22:25:46 by sof] · 1181f398
      sof authored
      Deleted HsVersions.h #defines that were now past their use-by-dates; in
      particular, make the assumption that a post-Haskell 1.4 compiler is now
      used to compile ghc/compiler/
      
      Hanging on to those FastString #defines is probably not worth it any longer,
      either, but I punted on making that (much bigger) change.
      1181f398
  27. 18 Oct, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-10-18 16:29:12 by simonpj] · 685e04e4
      simonpj authored
      ----------------------------------------------
      	The CoreTidy/CorePrep/CoreToStg saga continues
      	[actually, this commit mostly completes the job]
      	----------------------------------------------
      
      			DO NOT MERGE!
      
      * CorePrep injects implicit bindings, not the type checker,
        nor CgConTbls.   (This way, all the code generators see
        them, so no need to fiddle with the byte code generator.)
      
        As a result, all bindings in the module are for LocalIds,
        at least until CoreTidy.   This is a Big Win.
      
        Hence remove nasty isImplicitId test in update_bndr in
        SimplCore and DmdAnal
      
      * hasNoBinding is no longer true of a dataConId (worker).
        There's an implicit curried binding for it.
      
      * Remove yukky test in exprIsTrivial that did not regard
        a hasNoBinding Id as trivial; similarly in SimplUtils.tryEtaReduce
      
      * In CoreTidy, get the names to avoid from the type env.
        That way it includes implicit bindings too.
      
      * CoreTidy set the Arity of a top-level Id permanently;
        it's up to the rest of the compiler to respect it.
        Notably, CorePrep uses etaExpand to make the manifest arity
        match the claimed arity.
      
      * As a result, nuke CgArity, so that CgInfo now contains only
        CafInfo.  The CafInfo is knot-tied as before.
      
      
      Other things
      
      * In Simplify.simplLazyBind, be a bit keener to float bindings
        out if it's a top-level binding.
      685e04e4
  28. 15 Oct, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-10-15 15:06:01 by simonpj] · 713b32a5
      simonpj authored
      --------------------------
      	Tidy up arity propagation
      	--------------------------
      
      Due to excessive complexity, correct arity information was getting
      lost on the way to interface files.  As a result, a function that had
      CPR info __S SLm (say), was getting arity 0, and this confused the (old)
      CPR analyser ("lub of function and HasCPR").
      
      I hope this fixes the above error (which showed up somewhere in
      compiling Edison), but I'm going to commit it right now anyway.
      Meanwhile I'll recompile Edison too.
      
      
      Details
      ~~~~~~~
      Digging out the rather obscure cause made me tidy up the CgInfo stuff.
      The story is now
      
      * The CgInfo field of an Id gets attached to the Id *only* in
        the TypeEnv of the ModuleDetails, during CoreTidy.
      
        This ModuleDetails stuff is used
      	a) to generate the interface file
      	b) to import into other modules in GHCi
      
      * No CgInfo field is in the CoreBindings which are passed
        downsteam to CorePrep and thence CodeGen.  Quite right too...
        it's the downstream stuff that *generates* the CgInfo.
      
      * But the Arity field *is* now passed on through CoreTidy
        (like strictness info) since it is usefully used by CorePrep.
      
      * On the way I simplified the ArityInfo field of an IdInfo
        to simply
      		Arity
        instead of
      		Maybe Arity
      713b32a5
  29. 03 Oct, 2001 1 commit
  30. 26 Sep, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-09-26 15:12:33 by simonpj] · e0d750be
      simonpj authored
      ------------------
      		Simon's big commit
      		------------------
      
      This commit, which I don't think I can sensibly do piecemeal, consists
      of the things I've been doing recently, mainly directed at making
      Manuel, George, and Marcin happier with RULES.
      
      
      Reogranise the simplifier
      ~~~~~~~~~~~~~~~~~~~~~~~~~
      1. The simplifier's environment is now an explicit parameter.  This
      makes it a bit easier to figure out where it is going.
      
      2. Constructor arguments can now be arbitrary expressions, except
      when the application is the RHS of a let(rec).  This makes it much
      easier to match rules like
      
      	RULES
      	    "foo"  f (h x, g y) = f' x y
      
      In the simplifier, it's Simplify.mkAtomicArgs that ANF-ises a
      constructor application where necessary.  In the occurrence analyser,
      there's a new piece of context info (OccEncl) to say whether a
      constructor app is in a place where it should be in ANF.  (Unless
      it knows this it'll give occurrence info which will inline the
      argument back into the constructor app.)
      
      3. I'm experimenting with doing the "float-past big lambda" transformation
      in the full laziness pass, rather than mixed in with the simplifier (was
      tryRhsTyLam).
      
      4.  Arrange that
      	case (coerce (S,T) (x,y)) of ...
      will simplify.  Previous it didn't.
      A local change to CoreUtils.exprIsConApp_maybe.
      
      5. Do a better job in CoreUtils.exprEtaExpandArity when there's an
      error function in one branch.
      
      
      Phase numbers, RULES, and INLINE pragmas
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      1.  Phase numbers decrease from N towards zero (instead of increasing).
      This makes it easier to add new earlier phases, which is what users want
      to do.
      
      2.  RULES get their own phase number, N, and are disabled in phases before N.
      
      e.g. 	{-# RULES "foo" [2] forall x y.  f (x,y) = f' x y #-}
      
      Note the [2], which says "only active in phase 2 and later".
      
      3.  INLINE and NOINLINE pragmas have a phase number to.  This is now treated
      in just the same way as the phase number on RULE; that is, the Id is not inlined
      in phases earlier than N.  In phase N and later the Id *may* be inlined, and
      here is where INLINE and NOINLINE differ: INLNE makes the RHS look small, so
      as soon as it *may* be inlined it probably *will* be inlined.
      
      The syntax of the phase number on an INLINE/NOINLINE pragma has changed to be
      like the RULES case (i.e. in square brackets).  This should also make sure
      you examine all such phase numbers; many will need to change now the numbering
      is reversed.
      
      Inlining Ids is no longer affected at all by whether the Id appears on the
      LHS of a rule.  Now it's up to the programmer to put a suitable INLINE/NOINLINE
      pragma to stop it being inlined too early.
      
      
      Implementation notes:
      
      *  A new data type, BasicTypes.Activation says when a rule or inline pragma
      is active.   Functions isAlwaysActive, isNeverActive, isActive, do the
      obvious thing (all in BasicTypes).
      
      * Slight change in the SimplifierSwitch data type, which led to a lot of
      simplifier-specific code moving from CmdLineOpts to SimplMonad; a Good Thing.
      
      * The InlinePragma in the IdInfo of an Id is now simply an Activation saying
      when the Id can be inlined.  (It used to be a rather bizarre pair of a
      Bool and a (Maybe Phase), so this is much much easier to understand.)
      
      * The simplifier has a "mode" environment switch, replacing the old
      black list.  Unfortunately the data type decl has to be in
      CmdLineOpts, because it's an argument to the CoreDoSimplify switch
      
          data SimplifierMode = SimplGently | SimplPhase Int
      
      Here "gently" means "no rules, no inlining".   All the crucial
      inlining decisions are now collected together in SimplMonad
      (preInlineUnconditionally, postInlineUnconditionally, activeInline,
      activeRule).
      
      
      Specialisation
      ~~~~~~~~~~~~~~
      1.  Only dictionary *functions* are made INLINE, not dictionaries that
      have no parameters.  (This inline-dictionary-function thing is Marcin's
      idea and I'm still not sure whether it's a good idea.  But it's definitely
      a Bad Idea when there are no arguments.)
      
      2.  Be prepared to specialise an INLINE function: an easy fix in
      Specialise.lhs
      
      But there is still a problem, which is that the INLINE wins
      at the call site, so we don't use the specialised version anyway.
      I'm still unsure whether it makes sense to SPECIALISE something
      you want to INLINE.
      
      
      
      
      
      Random smaller things
      ~~~~~~~~~~~~~~~~~~~~~~
      
      * builtinRules (there was only one, but may be more) in PrelRules are now
        incorporated.   They were being ignored before...
      
      * OrdList.foldOL -->  OrdList.foldrOL, OrdList.foldlOL
      
      * Some tidying up of the tidyOpenTyVar, tidyTyVar functions.  I've
        forgotten exactly what!
      e0d750be
  31. 20 Sep, 2001 1 commit
  32. 11 Sep, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-09-11 08:18:16 by simonpj] · 3ea73c48
      simonpj authored
      -----------------------
      	More demand-info fixes
      	-----------------------
      
      	MERGE WITH STABLE BRANCH
      
      There are a handful of functions in IdInfo that zap the
      demand-info stored in an Id.  Alas, they were zapping the
      *old* demand-info not the new one.  (The old one is still
      there for comparison purposes.)  So we were getting some
      spurious warnings and (more seriously) potentially some
      incorrect strictness.  Easily fixed though.
      3ea73c48
  33. 07 Sep, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-09-07 12:42:46 by simonpj] · d3f61314
      simonpj authored
      ------------------------
      	Fix the demand analyser
      	------------------------
      
      A spiffy new domain for demands, and definitions for lub/both
      which are actually monotonic.   Quite a bit of related jiggling
      around.
      
      One of the original motivations was to do with functions like:
      
      	sum n []     = n
      	sum n (x:xs) = sum (n+x) xs
      
      Even though n is returned boxed from the first case, we don't want
      to get strictness
      	S(L)V -> T
      because that means we pass the box for n, and that is TERRIBLE.
      So the new version errs on the side of unboxing, more like the forwards
      analyser, and only passes the box if it is *definitely* needed, rather
      than if it *may* be needed.
      d3f61314
  34. 24 Aug, 2001 2 commits
    • simonpj's avatar
      [project @ 2001-08-24 13:22:25 by simonpj] · 2daf21bb
      simonpj authored
      Make when comparing old and new strictness information,
      we were being a bit too generous with the old case.
      When a function has (say) arity 2, we can't use strictness
      info like SSS, because that only applies if the fn is
      applied to 3 args.  So it's an unfair comparison.
      
      This commit makes the old->new conversion function more
      truthful in this regard, which should eliminate the
      erroneously-claimed "worse" strictness results.
      2daf21bb
    • rrt's avatar
      [project @ 2001-08-24 09:41:27 by rrt] · 10f01216
      rrt authored
      Remove unused import of DmdType
      10f01216
  35. 24 Jul, 2001 1 commit
  36. 23 Jul, 2001 1 commit