1. 01 Nov, 2006 1 commit
    • SamB's avatar
      Get External Core (-fext-core) working with readline · e513c1cc
      SamB authored
      Had to add support for dynamic C calls and for foreign labels (Addr#
      constants). Actually I only did the printing side -- parsing is not
      done yet. But at least now you can build the libraries with -fext-core.
      I also got the function arrow to print out properly again (it was
      printing fully-qualified and z-coded!)
      I also added a field for calling convention name to the External
      data constructor in ExternalCore.Exp (for static C calls).
      I'm not exactly sure where to document all of this, so I haven't done
      that, though I did comment the code a bit.
  2. 11 Oct, 2006 1 commit
    • Simon Marlow's avatar
      Module header tidyup, phase 1 · 49c98d14
      Simon Marlow authored
      This patch is a start on removing import lists and generally tidying
      up the top of each module.  In addition to removing import lists:
         - Change DATA.IOREF -> Data.IORef etc.
         - Change List -> Data.List etc.
         - Remove $Id$
         - Update copyrights
         - Re-order imports to put non-GHC imports last
         - Remove some unused and duplicate imports
  3. 20 Sep, 2006 3 commits
    • chak@cse.unsw.edu.au.'s avatar
      Indexed newtypes · 27897431
      chak@cse.unsw.edu.au. authored
      Mon Sep 18 19:24:27 EDT 2006  Manuel M T Chakravarty <chak@cse.unsw.edu.au>
        * Indexed newtypes
        Thu Aug 31 22:09:21 EDT 2006  Manuel M T Chakravarty <chak@cse.unsw.edu.au>
          * Indexed newtypes
          - This patch makes indexed newtypes work
          - Only lightly tested
          - We need to distinguish between open and closed newtypes in a number of 
            places, because looking through newtypes doesn't work easily for open ones.
    • chak@cse.unsw.edu.au.'s avatar
      fix bugs, add boolean flag to identify coercion variables · 0b86bc9b
      chak@cse.unsw.edu.au. authored
      Mon Sep 18 16:41:32 EDT 2006  Manuel M T Chakravarty <chak@cse.unsw.edu.au>
        * fix bugs, add boolean flag to identify coercion variables
        Sun Aug  6 17:04:02 EDT 2006  Manuel M T Chakravarty <chak@cse.unsw.edu.au>
          * fix bugs, add boolean flag to identify coercion variables
          Tue Jul 25 06:20:05 EDT 2006  kevind@bu.edu
    • chak@cse.unsw.edu.au.'s avatar
      newtype fixes, coercions for non-recursive newtypes now optional · c94408e5
      chak@cse.unsw.edu.au. authored
      Mon Sep 18 14:24:27 EDT 2006  Manuel M T Chakravarty <chak@cse.unsw.edu.au>
        * newtype fixes, coercions for non-recursive newtypes now optional
        Sat Aug  5 21:19:58 EDT 2006  Manuel M T Chakravarty <chak@cse.unsw.edu.au>
          * newtype fixes, coercions for non-recursive newtypes now optional
          Fri Jul  7 06:11:48 EDT 2006  kevind@bu.edu
  4. 06 Aug, 2006 1 commit
  5. 04 Aug, 2006 1 commit
  6. 25 Jul, 2006 1 commit
    • Simon Marlow's avatar
      Generalise Package Support · 61d2625a
      Simon Marlow authored
      This patch pushes through one fundamental change: a module is now
      identified by the pair of its package and module name, whereas
      previously it was identified by its module name alone.  This means
      that now a program can contain multiple modules with the same name, as
      long as they belong to different packages.
      This is a language change - the Haskell report says nothing about
      packages, but it is now necessary to understand packages in order to
      understand GHC's module system.  For example, a type T from module M
      in package P is different from a type T from module M in package Q.
      Previously this wasn't an issue because there could only be a single
      module M in the program.
      The "module restriction" on combining packages has therefore been
      lifted, and a program can contain multiple versions of the same
      Note that none of the proposed syntax changes have yet been
      implemented, but the architecture is geared towards supporting import
      declarations qualified by package name, and that is probably the next
      It is now necessary to specify the package name when compiling a
      package, using the -package-name flag (which has been un-deprecated).
      Fortunately Cabal still uses -package-name.
      Certain packages are "wired in".  Currently the wired-in packages are:
      base, haskell98, template-haskell and rts, and are always referred to
      by these versionless names.  Other packages are referred to with full
      package IDs (eg. "network-1.0").  This is because the compiler needs
      to refer to entities in the wired-in packages, and we didn't want to
      bake the version of these packages into the comiler.  It's conceivable
      that someone might want to upgrade the base package independently of
      Internal changes:
        - There are two module-related types:
              ModuleName      just a FastString, the name of a module
              Module          a pair of a PackageId and ModuleName
          A mapping from ModuleName can be a UniqFM, but a mapping from Module
          must be a FiniteMap (we provide it as ModuleEnv).
        - The "HomeModules" type that was passed around the compiler is now
          gone, replaced in most cases by the current package name which is
          contained in DynFlags.  We can tell whether a Module comes from the
          current package by comparing its package name against the current
        - While I was here, I changed PrintUnqual to be a little more useful:
          it now returns the ModuleName that the identifier should be qualified
          with according to the current scope, rather than its original
          module.  Also, PrintUnqual tells whether to qualify module names with
          package names (currently unused).
      Docs to follow.
  7. 02 Jul, 2006 1 commit
    • Jan Rochel's avatar
      Add %local-tag to external core output · 99bab7d8
      Jan Rochel authored
      Hello, this is my first patch contributed to GHC. If there are any
      inadequacies about it (maybe like this introductory disclaimer), please
      let me know about it.
      So, the need for this patch arose, while I was involved with processing
      hcr files (external core output) and I noticed, that the output didn't
      fully conform to the specification [1].
      No %local-tags were used, which turned out to be a real nuisance as it
      was not possible to determine which VDEFs can be erased in a further
      optimization process and which ones are exported by the module.
      Since the specification does not define the meaning of the %local-tag, I
      assume, it makes sense, that it tags all functions, that are not
      exported by the module.
      The patch does not fully comply to the specification, as in my
      implementation a local tag may appear before a VDEF but not before a
      [1] An External Representation for the GHC Core Language
          (DRAFT for GHC5.02), page 3, line 1
  8. 23 Jun, 2006 1 commit
  9. 05 Jun, 2006 1 commit
    • simonpj@microsoft.com's avatar
      Remove InlinePlease and add inline function and RULE · f2dcf256
      simonpj@microsoft.com authored
      For a long time GHC has had some internal mechanism designed to support
      a call-site inline directive, thus
      	inline f xs
      makes f be inlined at the call site even if f is big.
      However, the surface syntax seems to have gone, and in any case it
      can be done more neatly using a RULE.
      This commit:
        * Removes the InlineCall constructor for Note
          and InlinePlease for SimplCont
        * Adds a new known-key Id called 'inline', whose definition in
          GHC.Base is just the identity function
        * Adds a built-in RULE in PrelRules that rewrites (inline f) to
          the body of f, if possible
        * Adds documentation
      NOTE: I have not tested this (aeroplane work).  Give it a try!
  10. 20 Apr, 2006 1 commit
  11. 07 Apr, 2006 1 commit
    • Simon Marlow's avatar
      Reorganisation of the source tree · 0065d5ab
      Simon Marlow authored
      Most of the other users of the fptools build system have migrated to
      Cabal, and with the move to darcs we can now flatten the source tree
      without losing history, so here goes.
      The main change is that the ghc/ subdir is gone, and most of what it
      contained is now at the top level.  The build system now makes no
      pretense at being multi-project, it is just the GHC build system.
      No doubt this will break many things, and there will be a period of
      instability while we fix the dependencies.  A straightforward build
      should work, but I haven't yet fixed binary/source distributions.
      Changes to the Building Guide will follow, too.
  12. 28 Apr, 2005 1 commit
    • simonpj's avatar
      [project @ 2005-04-28 16:05:54 by simonpj] · 91944423
      simonpj authored
      Re-plumb the connections between TidyPgm and the various
      code generators.  There's a new type, CgGuts, to mediate this,
      which has the happy effect that ModGuts can die earlier.
      The non-O route still isn't quite right, because default methods
      are being lost.  I'm working on it.
  13. 18 Mar, 2005 1 commit
    • simonmar's avatar
      [project @ 2005-03-18 13:37:27 by simonmar] · d1c1b7d0
      simonmar authored
      Flags cleanup.
      Basically the purpose of this commit is to move more of the compiler's
      global state into DynFlags, which is moving in the direction we need
      to go for the GHC API which can have multiple active sessions
      supported by a single GHC instance.
      $ grep 'global_var' */*hs | wc -l
      $ grep 'global_var' */*hs | wc -l
      Well, it's an improvement.  Most of what's left won't really affect
      our ability to host multiple sessions.
      Lots of static flags have become dynamic flags (yay!).  Notably lots
      of flags that we used to think of as "driver" flags, like -I and -L,
      are now dynamic.  The most notable static flags left behind are the
      "way" flags, eg. -prof.  It would be nice to fix this, but it isn't
      On the way, lots of cleanup has happened.  Everything related to
      static and dynamic flags lives in StaticFlags and DynFlags
      respectively, and they share a common command-line parser library in
      CmdLineParser.  The flags related to modes (--makde, --interactive
      etc.) are now private to the front end: in fact private to Main
      itself, for now.
  14. 26 Nov, 2004 1 commit
    • simonmar's avatar
      [project @ 2004-11-26 16:19:45 by simonmar] · ef5b4b14
      simonmar authored
      Further integration with the new package story.  GHC now supports
      pretty much everything in the package proposal.
        - GHC now works in terms of PackageIds (<pkg>-<version>) rather than
          just package names.  You can still specify package names without
          versions on the command line, as long as the name is unambiguous.
        - GHC understands hidden/exposed modules in a package, and will refuse
          to import a hidden module.  Also, the hidden/eposed status of packages
          is taken into account.
        - I had to remove the old package syntax from ghc-pkg, backwards
          compatibility isn't really practical.
        - All the package.conf.in files have been rewritten in the new syntax,
          and contain a complete list of modules in the package.  I've set all
          the versions to 1.0 for now - please check your package(s) and fix the
          version number & other info appropriately.
        - New options:
      	-hide-package P    sets the expose flag on package P to False
      	-ignore-package P  unregisters P for this compilation
      	For comparison, -package P sets the expose flag on package P
              to True, and also causes P to be linked in eagerly.
              -package-name is no longer officially supported.  Unofficially, it's
      	a synonym for -ignore-package, which has more or less the same effect
      	as -package-name used to.
      	Note that a package may be hidden and yet still be linked into
      	the program, by virtue of being a dependency of some other package.
      	To completely remove a package from the compiler's internal database,
              use -ignore-package.
      	The compiler will complain if any two packages in the
              transitive closure of exposed packages contain the same
      	You *must* use -ignore-package P when compiling modules for
              package P, if package P (or an older version of P) is already
              registered.  The compiler will helpfully complain if you don't.
      	The fptools build system does this.
         - Note: the Cabal library won't work yet.  It still thinks GHC uses
           the old package config syntax.
      Internal changes/cleanups:
         - The ModuleName type has gone away.  Modules are now just (a
           newtype of) FastStrings, and don't contain any package information.
           All the package-related knowledge is in DynFlags, which is passed
           down to where it is needed.
         - DynFlags manipulation has been cleaned up somewhat: there are no
           global variables holding DynFlags any more, instead the DynFlags
           are passed around properly.
         - There are a few less global variables in GHC.  Lots more are
           scheduled for removal.
         - -i is now a dynamic flag, as are all the package-related flags (but
           using them in {-# OPTIONS #-} is Officially Not Recommended).
         - make -j now appears to work under fptools/libraries/.  Probably
           wouldn't take much to get it working for a whole build.
  15. 01 Oct, 2004 1 commit
    • simonpj's avatar
      [project @ 2004-10-01 13:42:04 by simonpj] · 837824d2
      simonpj authored
      	Simplify the treatment of newtypes
      	Complete hi-boot file consistency checking
      In the representation of types, newtypes used to have a special constructor
      all to themselves, very like TyConApp, called NewTcApp.    The trouble is
      that means we have to *know* when a newtype is a newtype, and in an hi-boot
      context we may not -- the data type might be declared as
      	data T
      in the hi-boot file, but as
      	newtype T = ...
      in the source file.  In GHCi, which accumulates stuff from multiple compiles,
      this makes a difference.
      So I've nuked NewTcApp.  Newtypes are represented using TyConApps again. This
      turned out to reduce the total amount of code, and simplify the Type data type,
      which is all to the good.
      This commit also fixes a few things in the hi-boot consistency checking
  16. 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
          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
      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).
  17. 30 Dec, 2003 1 commit
    • simonpj's avatar
      [project @ 2003-12-30 16:29:17 by simonpj] · f714e6b6
      simonpj authored
              Re-do kind inference (again)
         [WARNING: interface file binary representation has
         (as usual) changed slightly; recompile your libraries!]
      Inspired by the lambda-cube, for some time GHC has used
      	type Kind = Type
      That is, kinds were represented by the same data type as types.
      But GHC also supports unboxed types and unboxed tuples, and these
      complicate the kind system by requiring a sub-kind relationship.
      Notably, an unboxed tuple is acceptable as the *result* of a
      function but not as an *argument*.  So we have the following setup:
      		/ \
      	       /   \
      	      ??   (#)
      	     /  \
                  *   #
      where	*    [LiftedTypeKind]   means a lifted type
      	#    [UnliftedTypeKind] means an unlifted type
      	(#)  [UbxTupleKind]     means unboxed tuple
      	??   [ArgTypeKind]      is the lub of *,#
      	?    [OpenTypeKind]	means any type at all
      In particular:
        error :: forall a:?. String -> a
        (->)  :: ?? -> ? -> *
        (\(x::t) -> ...)	Here t::?? (i.e. not unboxed tuple)
      All this has beome rather difficult to accommodate with Kind=Type, so this
      commit splits the two.
        * Kind is a distinct type, defined in types/Kind.lhs
        * IfaceType.IfaceKind disappears: we just re-use Kind.Kind
        * TcUnify.unifyKind is a distinct unifier for kinds
        * TyCon no longer needs KindCon and SuperKindCon variants
        * TcUnify.zapExpectedType takes an expected Kind now, so that
          in TcPat.tcMonoPatBndr we can express that the bound variable
          must have an argTypeKind (??).
      The big change is really that kind inference is much more systematic and
      well behaved.  In particular, a kind variable can unify only with a
      "simple kind", which is built from * and (->).  This deals neatly
      with awkward questions about how we can combine sub-kinding with type
      Lots of small consequential changes, especially to the kind-checking
      plumbing in TcTyClsDecls.  (We played a bit fast and loose before, and
      now we have to be more honest, in particular about how kind inference
      works for type synonyms.  They can have kinds like (* -> #), so
      This cures two long-standing SourceForge bugs
      * 753777 (tcfail115.hs), which used erroneously to pass,
        but crashed in the code generator
            type T a = Int -> (# Int, Int #)
            f :: T a -> T a
            f t = \x -> case t x of r -> r
      * 753780 (tc167.hs), which used erroneously to fail
            f :: (->) Int# Int#
      Still, the result is not entirely satisfactory.  In particular
      * The error message from tcfail115 is pretty obscure
      * SourceForge bug 807249 (Instance match failure on openTypeKind)
        is not fixed.  Alas.
  18. 10 Dec, 2003 1 commit
    • simonmar's avatar
      [project @ 2003-12-10 14:15:16 by simonmar] · 55042138
      simonmar authored
      Add accurate source location annotations to HsSyn
      Every syntactic entity in HsSyn is now annotated with a SrcSpan, which
      details the exact beginning and end points of that entity in the
      original source file.  All honest compilers should do this, and it was
      about time GHC did the right thing.
      The most obvious benefit is that we now have much more accurate error
      messages; when running GHC inside emacs for example, the cursor will
      jump to the exact location of an error, not just a line somewhere
      nearby.  We haven't put a huge amount of effort into making sure all
      the error messages are accurate yet, so there could be some tweaking
      still needed, although the majority of messages I've seen have been
      Error messages now contain a column number in addition to the line
      number, eg.
         read001.hs:25:10: Variable not in scope: `+#'
      To get the full text span info, use the new option -ferror-spans.  eg.
         read001.hs:25:10-11: Variable not in scope: `+#'
      I'm not sure whether we should do this by default.  Emacs won't
      understand the new error format, for one thing.
      In a more elaborate editor setting (eg. Visual Studio), we can arrange
      to actually highlight the subexpression containing an error.  Eventually
      this information will be used so we can find elements in the abstract
      syntax corresponding to text locations, for performing high-level editor
      functions (eg. "tell me the type of this expression I just highlighted").
      Performance of the compiler doesn't seem to be adversely affected.
      Parsing is still quicker than in 6.0.1, for example.
      This was an excrutiatingly painful change to make: both Simon P.J. and
      myself have been working on it for the last three weeks or so.  The
      basic changes are:
       - a new datatype SrcSpan, which represents a beginning and end position
         in a source file.
       - To reduce the pain as much as possible, we also defined:
            data Located e = L SrcSpan e
       - Every datatype in HsSyn has an equivalent Located version.  eg.
            type LHsExpr id = Located (HsExpr id)
         and pretty much everywhere we used to use HsExpr we now use
         LHsExpr.  Believe me, we thought about this long and hard, and
         all the other options were worse :-)
      Additional changes/cleanups we made at the same time:
        - The abstract syntax for bindings is now less arcane.  MonoBinds
          and HsBinds with their built-in list constructors have gone away,
          replaced by HsBindGroup and HsBind (see HsSyn/HsBinds.lhs).
        - The various HsSyn type synonyms have now gone away (eg. RdrNameHsExpr,
          RenamedHsExpr, and TypecheckedHsExpr are now HsExpr RdrName,
          HsExpr Name, and HsExpr Id respectively).
        - Utilities over HsSyn are now collected in a new module HsUtils.
          More stuff still needs to be moved in here.
        - MachChar now has a real Char instead of an Int.  All GHC versions that
          can compile GHC now support 32-bit Chars, so this was a simplification.
  19. 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
      * 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
      * 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
      * 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
  20. 19 Aug, 2003 1 commit
    • krc's avatar
      [project @ 2003-08-19 21:59:40 by krc] · 0f9750be
      krc authored
      Two issues:
      1. According to the spec for External Core, datatype declarations are required
      to have at least one data constructor. Previously, if you tried to generate
      External Core for a program containing a datatype declaration with no
      constructors, generating the Core file would succeed, but compiling it would
      result in a parse error. Changed MkExternalCore to signal an error if such
      a declaration is encountered while compiling to External Core.
      2. Previously, MachLabel literals were translated into Externals when compiling
      to External Core. This is wrong -- such literals are not foreign calls and
      can't be handled in the same way (compiling any External Core code generated
      from code containing literals resulting from "foreign label" declarations would
      result in a strange error message). There doesn't seem to be any way to
      correctly represent these labels in External Core, so MkExternalCore now
      signals an error if one of these is encountered as well.
  21. 11 Jul, 2003 1 commit
  22. 10 Jul, 2003 1 commit
  23. 01 Apr, 2003 1 commit
    • sof's avatar
      [project @ 2003-04-01 15:28:20 by sof] · 1d87bd26
      sof authored
      Have Literal.Literal support the representation of NULL pointers only,
      and not arbitrary pointer values.
      (MachAddr <some-pointer-value-as-an-Integer>) wasn't being used,
      except to handle nullAddr#. It (MachAddr) is a potential source of
      problems should the compiler start doing constant folding or other
      interesting operations over MachAddrs (think: interface files +
      cross-compilation), so we might as well scale back the representation
      of raw pointer values.
  24. 27 Mar, 2003 1 commit
    • sof's avatar
      [project @ 2003-03-27 17:59:09 by sof] · 6da62425
      sof authored
      NCG support for f.e.d. stdcall -- Literal.MachLabels now optionally carry
      the size (in bytes) of the stack frame it expects, if known. That just
      so happens to match what stdcall labels need to be annotated with when
      emitting them in the NCG..
  25. 20 Feb, 2003 1 commit
    • simonpj's avatar
      [project @ 2003-02-20 18:33:50 by simonpj] · 56b5a8b8
      simonpj authored
            Add Core Notes and the {-# CORE #-} pragma
      This is an idea of Hal Daume's. The key point is that Notes in Core
      are augmented thus:
        data Note
          = SCC CostCentre
          | ...
          | CoreNote String     -- NEW
      These notes can be injected via a Haskell-source pragma:
         f x = ({-# CORE "foo" #-} show) ({-# CORE "bar" #-} x)
      This wraps a (Note (CoreNote "foo")) around the 'show' variable,
      and a similar note around the argument to 'show'.
      These notes are basically ignored by GHC, but are emitted into
      External Core, where they may convey useful information.
      Exactly how code involving these notes is munged by the simplifier
      isn't very well defined.  We'll see how it pans out.  Meanwhile
      the impact on the rest of the compiler is minimal.
  26. 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
      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.
  27. 04 Feb, 2003 2 commits
    • simonpj's avatar
      [project @ 2003-02-04 15:31:18 by simonpj] · 17777c53
      simonpj authored
      	Fix a name-capture bug in Ext-Core
      Don't expand newtypes (even non-recursive ones) when going to External Core.
      Reason: the expansion was performed *after* Tidying; the expansion performs
      type substitution, which is only done right if you take account of the Uniques.
      But since it's post-tidying, we got capture of occurence names.
      I hope the lack of newtype expansion doesn't hurt anyone; I doubt it will.
      If so, we can think again.
      Thanks to Tobias Gedell for this one.
    • simonpj's avatar
      [project @ 2003-02-04 13:06:41 by simonpj] · e8f681e4
      simonpj authored
      			External Core fix
      	output implicit bindings in correct dependency order
      In coreSyn/MkExternalCore, output constructor wrappers before the
      other implicit bindings, because the latter may use the former.
      Thanks to Tobias Gedell for this one.
  28. 24 Jan, 2003 1 commit
    • simonpj's avatar
      [project @ 2003-01-24 11:26:39 by simonpj] · 9ceeb6e5
      simonpj authored
      Perform 'tidying' on the implicit bindings before emitting
      	External Core.  We were getting silly bindings like
      		\ tpl -> case tpl of tpl -> (tpl,tpl) -> tpl
      	Maybe we should add these implicit bindings in CoreTidy,
      	rather than in both MkExternalCore and CorePrep?
  29. 11 Dec, 2002 1 commit
  30. 31 Oct, 2002 1 commit
  31. 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
      * 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
        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.
      	HsPat.InPat	--> HsPat.Pat
      	HsPat.OutPat	--> HsPat.Pat
      	No 'pat' type parameter in HsExpr, HsBinds, etc
      	Constructor patterns are nicer now: they use
      	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.
  32. 29 Apr, 2002 1 commit
    • simonmar's avatar
      [project @ 2002-04-29 14:03:38 by simonmar] · b085ee40
      simonmar authored
      FastString cleanup, stage 1.
      The FastString type is no longer a mixture of hashed strings and
      literal strings, it contains hashed strings only with O(1) comparison
      (except for UnicodeStr, but that will also go away in due course).  To
      create a literal instance of FastString, use FSLIT("..").
      By far the most common use of the old literal version of FastString
      was in the pattern
      	  ptext SLIT("...")
      this combination still works, although it doesn't go via FastString
      any more.  The next stage will be to remove the need to use this
      special combination at all, using a RULE.
      To convert a FastString into an SDoc, now use 'ftext' instead of
      I've also removed all the FAST_STRING related macros from HsVersions.h
      except for SLIT and FSLIT, just use the relevant functions from
      FastString instead.
  33. 11 Apr, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-04-11 12:03:29 by simonpj] · a7b95beb
      simonpj authored
      	Mainly derived Read
      This commit is a tangle of several things that somehow got wound up
      together, I'm afraid.
      The main course
      Replace the derived-Read machinery with Koen's cunning new parser
      combinator library.   The result should be
      	* much smaller code sizes from derived Read
      	* faster execution of derived Read
      WARNING: I have not thoroughly tested this stuff; I'd be glad if you did!
      	 All the hard work is done, but there may be a few nits.
      The Read class gets two new methods, not exposed
      in the H98 inteface of course:
        class Read a where
          readsPrec    :: Int -> ReadS a
          readList     :: ReadS [a]
          readPrec     :: ReadPrec a		-- NEW
          readListPrec :: ReadPrec [a]	-- NEW
      There are the following new libraries:
        Text.ParserCombinators.ReadP		Koens combinator parser
        Text.ParserCombinators.ReadPrec	Ditto, but with precedences
        Text.Read.Lex				An emasculated lexical analyser
      					that provides the functionality
      					of H98 'lex'
      TcGenDeriv is changed to generate code that uses the new libraries.
      The built-in instances of Read (List, Maybe, tuples, etc) use the new
      Other stuff
      1. Some fixes the the plumbing of external-core generation. Sigbjorn
      did most of the work earlier, but this commit completes the renaming and
      typechecking plumbing.
      2. Runtime error-generation functions, such as GHC.Err.recSelErr,
      GHC.Err.recUpdErr, etc, now take an Addr#, pointing to a UTF8-encoded
      C string, instead of a Haskell string.  This makes the *calls* to these
      functions easier to generate, and smaller too, which is a good thing.
      In particular, it means that MkId.mkRecordSelectorId doesn't need to
      be passed "unpackCStringId", which was GRUESOME; and that in turn means
      that tcTypeAndClassDecls doesn't need to be passed unf_env, which is
      a very worthwhile cleanup.   Win/win situation.
      3.  GHC now faithfully translates do-notation using ">>" for statements
      with no binding, just as the report says.  While I was there I tidied
      up HsDo to take a list of Ids instead of 3 (but now 4) separate Ids.
      Saves a bit of code here and there.  Also introduced Inst.newMethodFromName
      to package a common idiom.
  34. 01 Apr, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-04-01 08:23:30 by simonpj] · 9003a18c
      simonpj authored
      	Change the treatment of the stupid
      	   context on data constructors
      Data types can have a context:
      	data (Eq a, Ord b) => T a b = T1 a b | T2 a
      and that makes the constructors have a context too
      (notice that T2's context is "thinned"):
      	T1 :: (Eq a, Ord b) => a -> b -> T a b
      	T2 :: (Eq a) => a -> T a b
      Furthermore, this context pops up when pattern matching
      (though GHC hasn't implemented this, but it is in H98, and
      I've fixed GHC so that it now does):
      	f (T2 x) = x
      gets inferred type
      	f :: Eq a => T a b -> a
      I say the context is "stupid" because the dictionaries passed
      are immediately discarded -- they do nothing and have no benefit.
      It's a flaw in the language.
      Up to now I have put this stupid context into the type of
      the "wrapper" constructors functions, T1 and T2, but that turned
      out to be jolly inconvenient for generics, and record update, and
      other functions that build values of type T (because they don't
      have suitable dictionaries available).
      So now I've taken the stupid context out.  I simply deal with
      it separately in the type checker on occurrences of a constructor,
      either in an expression or in a pattern.
      To this end
      * Lots of changes in DataCon, MkId
      * New function Inst.tcInstDataCon to instantiate a data constructor
      I also took the opportunity to
      * Rename
      	dataConId --> dataConWorkId
        for consistency.
      * Tidied up MkId.rebuildConArgs quite a bit, and renamed it
      * Add function DataCon.dataConExistentialTyVars, with the obvious meaning
  35. 06 Feb, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-02-06 15:54:23 by simonpj] · 979947f5
      simonpj authored
      Eliminate all vestiages of UsageTy, in preparation for
      	Keith's new version.  Hurrah!
      	Keith: LBVarInfo and usOnce,usMany are still there,
      	because I know you have eliminated LBVarInfo, and I didn't
      	want to cause unnecessary conflicts.
  36. 27 Aug, 2001 1 commit
  37. 17 Aug, 2001 1 commit
    • apt's avatar
      [project @ 2001-08-17 17:18:51 by apt] · 1dfaee31
      apt authored
      How I spent my summer vacation.
      The format of the primops.txt.pp file has been enhanced to allow
      (latex-style) primop descriptions to be included.  There is a new flag
      to genprimopcode that generates documentation including these
      descriptions. A first cut at descriptions of the more interesting
      primops has been made, and the file has been reordered a bit.
      31-bit words
      The front end now can cope with the possibility of 31-bit (or even 30-bit)
      Int# and Word# types.  The only current use of this is to generate
      external .core files that can be translated into OCAML source files
      (OCAML uses a one-bit tag to distinguish integers from pointers).
      The only way to get this right now is by hand-defining the preprocessor
      symbol WORD_SIZE_IN_BITS, which is normally set automatically from
      the familiar WORD_SIZE_IN_BYTES.
      Just in case 31-bit words are used, we now have Int32# and Word32# primitive types
      and an associated family of operators, paralleling the existing 64-bit
      stuff.  Of course, none of the operators actually need to be implemented
      in the absence of a 31-bit backend.
      There has also been some minor re-jigging of the 32 vs. 64 bit stuff.
      See the description at the top of primops.txt.pp file for more details.
      Note that, for the first time, the *type* of a primop can now depend
      on the target word size.
      Also, the family of primops intToInt8#, intToInt16#, etc.
      have been renamed narrow8Int#, narrow16Int#, etc., to emphasize
      that they work on Int#'s and don't actually convert between types.
      As another part of coping with the possibility of 31-bit ints,
      the addr2Int# and int2Addr# primops are now thoroughly deprecated
      (and not even defined in the 31-bit case) and all uses
      of them have been removed except from the (deprecated) module
      Addr# should now be treated as a proper abstract type, and has these suitable operators:
      nullAddr# : Int# -> Addr# (ignores its argument; nullary primops cause problems at various places)
      plusAddr# :  Addr# -> Int# -> Addr#
      minusAddr : Addr# -> Addr# -> Int#
      remAddr# : Addr# -> Int# -> Int#
      Obviously, these don't allow completely arbitrary offsets if 31-bit ints are
      in use, but they should do for all practical purposes.
      It is also still possible to generate an address constant, and there is a built-in rule
      that makes use of this to remove the nullAddr# calls.
      There is a new compile flag -fno-code that causes GHC to quit after generating .hi files
      and .core files (if requested) but before generating STG.
      Z-encoded names for tuples have been rationalized; e.g.,
      Z3H now means an unboxed 3-tuple, rather than an unboxed
      tuple with 3 commas (i.e., a 4-tuple)!
      Removed misc. litlits in hslibs/lang
      Misc. small changes to external core format.  The external core description
      has also been substantially updated, and incorporates the automatically-generated
      primop documentation; its in the repository at /papers/ext-core/core.tex.
      A little make-system addition to allow passing CPP options to compiler and
      library builds.