1. 20 Feb, 2003 2 commits
    • 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.
      56b5a8b8
    • simonpj's avatar
      [project @ 2003-02-20 13:00:24 by simonpj] · 5b7c931a
      simonpj authored
      Eliminate bogus string-literal duplication
      5b7c931a
  2. 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
  3. 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
  4. 04 Feb, 2003 4 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.
      17777c53
    • 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 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.
      e8f681e4
    • simonpj's avatar
      [project @ 2003-02-04 12:23:32 by simonpj] · 23a4e1f0
      simonpj authored
      Add type sig
      23a4e1f0
  5. 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?
      9ceeb6e5
  6. 09 Jan, 2003 2 commits
  7. 11 Dec, 2002 1 commit
  8. 21 Nov, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-11-21 14:59:51 by simonpj] · c9c01697
      simonpj authored
      -------------------------------
      	Better notion of what a 'value' is
      	Slightly better eta reduction
      	-------------------------------
      
      1.  At various places we watch out for "values"; the predicate exprIsValue
      detects them. It was stupidly treating nullary constructors as non-values
      which is exceptionally stupid.  This (performance) bug has been there
      for ages.
      
      There's an exactly similar bug in SimplUtils.interestingArg, which looks
      for an interesting argument to trigger an inlining.
      
      
      2.  The eta reduction in SimplUtils.tryEtaReduce would only eta reduce if
      that left us with a variable.  That led to slightly tiresome thing like
      	:DMonad (/\a b -> foo @ s @ a @ b) ...
      where this would be neater
      	:DMonad (foo @ s)
      The fix is easy, and there's a little less code too.
      c9c01697
  9. 19 Nov, 2002 1 commit
    • simonmar's avatar
      [project @ 2002-11-19 14:16:43 by simonmar] · de7a4a03
      simonmar authored
      - Fix a bug in eta-expansion of an application; it probably never bit
        us in practice.
      
      - Change the behaviour of State#-lambdas: previously a State# lambda
        was considered to be one-shot for the purposes of inlining and
        eta-expansion.  Both can lead to unbounded extra work, but inlining
        is more likely to kill us, and eta-expansion is the case we mostly
        care about (getting the State# lambda to the outside of the function
        is often very important).  So now we only consider a State# lambda to be
        one-shot in eta expansion, not for inlining.
      de7a4a03
  10. 31 Oct, 2002 1 commit
  11. 10 Oct, 2002 1 commit
  12. 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
  13. 27 Sep, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-09-27 08:16:24 by simonpj] · b7cc3d01
      simonpj authored
      --------------------------------
           Do type-checking of external-core input
      	--------------------------------
      
      When we read in an External Core file, we should really type-check it.
      We weren't, because we treated it as if it were trusted, interface-file
      material.
      
      This commit fixes the problem, albeit in a bit of a hacky way.  The
      typechecking is done by Lint, which does not give as friendly error
      messages as does the normal typechecker.  But it's much better than nothing.
      
      I also removed the entirely-unused 'warnings' from the Lint monad.
      b7cc3d01
  14. 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
  15. 03 Sep, 2002 1 commit
  16. 29 Aug, 2002 3 commits
    • simonmar's avatar
      [project @ 2002-08-29 15:44:11 by simonmar] · ce9687a5
      simonmar authored
      Housekeeping:
      
        - The main goal is to remove dependencies on hslibs for a
          bootstrapped compiler, leaving only a requirement that the
          packages base, haskell98 and readline are built in stage 1 in
          order to bootstrap.  We're almost there: Posix is still required
          for signal handling, but all other dependencies on hslibs are now
          gone.
      
          Uses of Addr and ByteArray/MutableByteArray array are all gone
          from the compiler.  PrimPacked defines the Ptr type for GHC 4.08
          (which didn't have it), and it defines simple BA and MBA types to
          replace uses of ByteArray and MutableByteArray respectively.
      
        - Clean up import lists.  HsVersions.h now defines macros for some
          modules which have moved between GHC versions.  eg. one now
          imports 'GLAEXTS' to get at unboxed types and primops in the
          compiler.
      
          Many import lists have been sorted as per the recommendations in
          the new style guidelines in the commentary.
      
      I've built the compiler with GHC 4.08.2, 5.00.2, 5.02.3, 5.04 and
      itself, and everything still works here.  Doubtless I've got something
      wrong, though.
      ce9687a5
    • simonpj's avatar
      [project @ 2002-08-29 13:38:45 by simonpj] · 4a851c82
      simonpj authored
      Fix eta-expansion bug, which led to an infinite loop in
      CoreUtils.etaExpand. This showed up when compiling FranTk.
      
      		MERGE TO STABLE
      4a851c82
    • simonmar's avatar
      [project @ 2002-08-29 11:47:46 by simonmar] · a7ae6708
      simonmar authored
      Add a ToDo note.
      a7ae6708
  17. 20 Aug, 2002 1 commit
    • simonmar's avatar
      [project @ 2002-08-20 10:32:48 by simonmar] · a4ac1436
      simonmar authored
      Fix a buglet in CorePrep:  an expression such as
      
      	case __coerce (\x -> e) :: T of { ... }
      
      would be left as is, but the lambda expression should really be
      abstracted as a let (causes a panic later in srtExpr; shown up by
      the dynamic001 test).  There was a missing call to deLam in the case
      for Case expressions in corePrepExprFloat.
      
      In addition, I made a new version of deLam, deLamFloat, which can
      float any bindings generated.  This helps to generate slightly cleaner
      code in the above case (the binding is floated out of the scrutinee).
      
      Also: GC unused imports while I'm here.
      a4ac1436
  18. 29 Jul, 2002 2 commits
  19. 18 Jun, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-06-18 13:58:22 by simonpj] · 80e39963
      simonpj authored
      ---------------------------------------
      	    Rehash the handling of SeqOp
      	---------------------------------------
      
      See the comments in the commentary (Cunning Prelude Code).
      
      * Expunge SeqOp altogether
      
      * Add GHC.Base.lazy :: a -> a
        to GHC.Base
      
      * Add GHC.Base.lazy
        to basicTypes/MkId.  The idea is that this defn will over-ride
        the info from GHC.Base.hi, thereby hiding strictness and
        unfolding
      
      * Make stranal/WorkWrap do a "manual inlining" for GHC.Base.lazy
        This happens nicely after the strictness analyser has run.
      
      * Expunge the SeqOp/ParOp magic in CorePrep
      
      * Expunge the RULE for seq in PrelRules
      
      * Change the defns of pseq/par in GHC.Conc to:
      
      	{-# INLINE pseq  #-}
             	pseq :: a -> b -> b
             	pseq  x y = x `seq` lazy y
      
             	{-# INLINE par  #-}
             	par :: a -> b -> b
             	par  x y = case (par# x) of { _ -> lazy y }
      80e39963
  20. 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
  21. 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
      'ptext'.
      
      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.
      b085ee40
  22. 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
      libraries.
      
      
      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.
      a7b95beb
  23. 08 Apr, 2002 1 commit
  24. 05 Apr, 2002 1 commit
  25. 03 Apr, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-04-03 09:45:14 by simonpj] · f2f40c0f
      simonpj authored
      -----------------------------
      	Put existential tyvars second
      	[fixes ParsecPerm lint error]
      	-----------------------------
      
      In an existential data constr:
      
      	data Eq a => T a = forall b. Ord b => MkT a [b]
      
      the type of MkT is
      
      	MkT :: forall a b . Ord b => a -> [b] -> MkT a
      
      Note that the existential tyvars (b in this case) come *after*
      the "ordinary" tyvars.
      
      I had switched this around earlier in the week, but I'm putting
      it back (and fixing a bug) because I found it really works better second.
      
      Reason: in a case expression we may find:
      	case (e :: T t) of { MkT b (d:Ord b) (x:t) (xs:[b]) -> ... }
      It's convenient to apply the rep-type of MkT to 't', to get
      	forall b. Ord b => ...
      and use that to check the pattern.  Mind you, this is really only
      use in CoreLint.
      f2f40c0f
  26. 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
      	mkReboxingAlt
      
      * Add function DataCon.dataConExistentialTyVars, with the obvious meaning
      9003a18c
  27. 20 Mar, 2002 1 commit
  28. 19 Mar, 2002 1 commit
  29. 18 Mar, 2002 2 commits
  30. 15 Mar, 2002 1 commit
  31. 14 Mar, 2002 1 commit