1. 14 Feb, 2002 1 commit
  2. 11 Feb, 2002 1 commit
    • chak's avatar
      [project @ 2002-02-11 08:20:38 by chak] · 10fcd78c
      chak authored
      		       * Merging from ghc-ndp-branch *
      This commit merges the current state of the "parallel array extension" and
      includes the following:
      * (Almost) completed Milestone 1:
        - The option `-fparr' activates the H98 extension for parallel arrays.
        - These changes have a high likelihood of conflicting (in the CVS sense)
          with other changes to GHC and are the reason for merging now.
        - ToDo: There are still some (less often used) functions not implemented in
      	  `PrelPArr' and a mechanism is needed to automatically import
      	  `PrelPArr' iff `-fparr' is given.  Documentation that should go into
      	  the Commentary is currently in `ghc/compiler/ndpFlatten/TODO'.
      * Partial Milestone 2:
        - The option `-fflatten' activates the flattening transformation and `-ndp'
          selects the "ndp" way (where all libraries have to be compiled with
          flattening).  The way option `-ndp' automagically turns on `-fparr' and
        - Almost all changes are in the new directory `ndpFlatten' and shouldn't
          affect the rest of the compiler.  The only exception are the options and
          the points in `HscMain' where the flattening phase is called when
          `-fflatten' is given.
        - This isn't usable yet, but already implements function lifting,
          vectorisation, and a new analysis that determines which parts of a module
          have to undergo the flattening transformation.  Missing are data structure
          and function specialisation, the unboxed array library (including fusion
          rules), and lots of testing.
      I have just run the regression tests on the thing without any problems.  So,
      it seems, as if we haven't broken anything crucial.
  3. 04 Feb, 2002 1 commit
    • chak's avatar
      [project @ 2002-02-04 03:40:31 by chak] · 0299e1a1
      chak authored
      Foreign import/export declarations now conform to FFI Addendum Version 1.0
      * The old form of foreign declarations is still supported, but generates
        deprecation warnings.
      * There are some rather exotic old-style declarations which have become
        invalid as they are interpreted differently under the new scheme and there
        is no (easy) way to determine which style the programmer had in mind (eg,
        importing a C function with the name `wrapper' where the external name is
        explicitly given will not work in some situations - depends on whether an
        `unsafe' was specified and similar things).
      * Some "new" old-style forms have been introduced to make parsing a little bit
        easier (ie, avoid shift/reduce conflicts between new-style and old-style
        grammar rules), but they are few, arcane, and don't really hurt (and I won't
        tell what they are, you need to find that out by yourself ;-)
      * The FFI Addendum doesn't specify whether a header file that is requested for
        inclusion by multiple foreign declarations should be included only once or
        multiple times.  GHC at the moment includes an header as often as it appears
        in a foreign declaration.  For properly written headers, it doesn't make a
        difference anyway...
      * Library object specifications are currently silently ignored.  The feature
        was mainly requested for external calls in .NET (ie, calls which invoke C
        routines when Haskell is compiled to ILX), but those don't seem to be
        supported yet.
      * Foreign label declarations are currently broken, but they were already
        broken before I started messing with the stuff.
      The code is moderately tested.  All modules in lib/std/ and hslibs/lang/
      (using old-style declarations) still compile fine and I have run a couple of
      tests on the different forms of new-style declarations.
  4. 29 Nov, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-11-29 13:47:09 by simonpj] · 32a89583
      simonpj authored
      	Add linear implicit parameters
      Linear implicit parameters are an idea developed by Koen Claessen,
      Mark Shields, and Simon PJ, last week.  They address the long-standing
      problem that monads seem over-kill for certain sorts of problem, notably:
      	* distributing a supply of unique names
      	* distributing a suppply of random numbers
      	* distributing an oracle (as in QuickCheck)
      Linear implicit parameters are just like ordinary implicit parameters,
      except that they are "linear" -- that is, they cannot be copied, and
      must be explicitly "split" instead.  Linear implicit parameters are
      written '%x' instead of '?x'.  (The '/' in the '%' suggests the
      For example:
          data NameSupply = ...
          splitNS :: NameSupply -> (NameSupply, NameSupply)
          newName :: NameSupply -> Name
          instance PrelSplit.Splittable NameSupply where
      	split = splitNS
          f :: (%ns :: NameSupply) => Env -> Expr -> Expr
          f env (Lam x e) = Lam x' (f env e)
      		      x'   = newName %ns
      		      env' = extend env x x'
          ...more equations for f...
      Notice that the implicit parameter %ns is consumed
      	once by the call to newName
      	once by the recursive call to f
      So the translation done by the type checker makes
      the parameter explicit:
          f :: NameSupply -> Env -> Expr -> Expr
          f ns env (Lam x e) = Lam x' (f ns1 env e)
      	 		 (ns1,ns2) = splitNS ns
      			 x' = newName ns2
      			 env = extend env x x'
      Notice the call to 'split' introduced by the type checker.
      How did it know to use 'splitNS'?  Because what it really did
      was to introduce a call to the overloaded function 'split',
      ndefined by
      	class Splittable a where
      	  split :: a -> (a,a)
      The instance for Splittable NameSupply tells GHC how to implement
      split for name supplies.  But we can simply write
      	g x = (x, %ns, %ns)
      and GHC will infer
      	g :: (Splittable a, %ns :: a) => b -> (b,a,a)
      The Splittable class is built into GHC.  It's defined in PrelSplit,
      and exported by GlaExts.
      Other points:
      * '?x' and '%x' are entirely distinct implicit parameters: you
        can use them together and they won't intefere with each other.
      * You can bind linear implicit parameters in 'with' clauses.
      * You cannot have implicit parameters (whether linear or not)
        in the context of a class or instance declaration.
      The monomorphism restriction is even more important than usual.
      Consider the example above:
          f :: (%ns :: NameSupply) => Env -> Expr -> Expr
          f env (Lam x e) = Lam x' (f env e)
      		      x'   = newName %ns
      		      env' = extend env x x'
      If we replaced the two occurrences of x' by (newName %ns), which is
      usually a harmless thing to do, we get:
          f :: (%ns :: NameSupply) => Env -> Expr -> Expr
          f env (Lam x e) = Lam (newName %ns) (f env e)
      		      env' = extend env x (newName %ns)
      But now the name supply is consumed in *three* places
      (the two calls to newName,and the recursive call to f), so
      the result is utterly different.  Urk!  We don't even have
      the beta rule.
      Well, this is an experimental change.  With implicit
      parameters we have already lost beta reduction anyway, and
      (as John Launchbury puts it) we can't sensibly reason about
      Haskell programs without knowing their typing.
      Of course, none of this is throughly tested, either.
  5. 26 Nov, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-11-26 09:20:25 by simonpj] · 5e3f005d
      simonpj authored
      	Implement Rank-N types
      This commit implements the full glory of Rank-N types, using
      the Odersky/Laufer approach described in their paper
      	"Putting type annotations to work"
      In fact, I've had to adapt their approach to deal with the
      full glory of Haskell (including pattern matching, and the
      scoped-type-variable extension).  However, the result is:
      * There is no restriction to rank-2 types.  You can nest forall's
        as deep as you like in a type.  For example, you can write a type
      	p :: ((forall a. Eq a => a->a) -> Int) -> Int
        This is a rank-3 type, illegal in GHC 5.02
      * When matching types, GHC uses the cunning Odersky/Laufer coercion
        rules.  For example, suppose we have
      	q :: (forall c. Ord c => c->c) -> Int
        Then, is this well typed?
      	x :: Int
      	x = p q
        Yes, it is, but GHC has to generate the right coercion.  Here's
        what it looks like with all the big lambdas and dictionaries put in:
      	x = p (\ f :: (forall a. Eq a => a->a) ->
      		 q (/\c \d::Ord c -> f c (eqFromOrd d)))
        where eqFromOrd selects the Eq superclass dictionary from the Ord
        dicationary:		eqFromOrd :: Ord a -> Eq a
      * You can use polymorphic types in pattern type signatures.  For
      	f (g :: forall a. a->a) = (g 'c', g True)
        (Previously, pattern type signatures had to be monotypes.)
      * The basic rule for using rank-N types is that you must specify
        a type signature for every binder that you want to have a type
        scheme (as opposed to a plain monotype) as its type.
        However, you don't need to give the type signature on the
        binder (as I did above in the defn for f).  You can give it
        in a separate type signature, thus:
      	f :: (forall a. a->a) -> (Char,Bool)
      	f g = (g 'c', g True)
        GHC will push the external type signature inwards, and use
        that information to decorate the binders as it comes across them.
        I don't have a *precise* specification of this process, but I
        think it is obvious enough in practice.
      * In a type synonym you can use rank-N types too.  For example,
        you can write
      	type IdFun = forall a. a->a
      	f :: IdFun -> (Char,Bool)
      	f g = (g 'c', g True)
        As always, type synonyms must always occur saturated; GHC
        expands them before it does anything else.  (Still, GHC goes
        to some trouble to keep them unexpanded in error message.)
      The main plan is as before.  The main typechecker for expressions,
      tcExpr, takes an "expected type" as its argument.  This greatly
      improves error messages.  The new feature is that when this
      "expected type" (going down) meets an "actual type" (coming up)
      we use the new subsumption function
      which checks that the actual type can be coerced into the
      expected type (and produces a coercion function to demonstrate).
      The main new chunk of code is TcUnify.tcSub.  The unifier itself
      is unchanged, but it has moved from TcMType into TcUnify.  Also
      checkSigTyVars has moved from TcMonoType into TcUnify.
      Result: the new module, TcUnify, contains all stuff relevant
      to subsumption and unification.
      Unfortunately, there is now an inevitable loop between TcUnify
      and TcSimplify, but that's just too bad (a simple TcUnify.hi-boot
      All of this doesn't come entirely for free.  Here's the typechecker
      line count (INCLUDING comments)
      	Before	16,551
      	After	17,116
  6. 07 Nov, 2001 1 commit
  7. 31 Oct, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-10-31 15:22:53 by simonpj] · 61bfd5dd
      simonpj authored
      	Improved handling of scoped type variables
      The main effect of this commit is to allow scoped type variables
      in pattern bindings, thus
      	(x::a, y::b) = e
      This was illegal, but now it's ok.  a and b have the same scope
      as x and y.
      On the way I beefed up the info inside a type variable
      (TcType.TyVarDetails; c.f. IdInfo.GlobalIdDetails) which
      helps to improve error messages. Hence the wide ranging changes.
      Pity about the extra loop from Var to TcType, but can't be helped.
  8. 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
      	    "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
      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,
      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
      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!
  9. 13 Jul, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-07-13 13:29:56 by simonpj] · d4e38936
      simonpj authored
      	Tidy up the "syntax rebinding" story
      I found a bug in the code that dealt with re-binding implicit
      numerical syntax:
      	literals 	(fromInteger/fromRational)
      	negation	(negate)
      	n+k patterns	(minus)
      This is triggered by the -fno-implicit-prelude flag, and it
      used to be handled via the PrelNames.SyntaxMap.
      But I found a nicer way to do it that involves much less code,
      and doesn't have the bug.  The explanation is with
  10. 12 Jul, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-07-12 16:21:22 by simonpj] · ab46fd8e
      simonpj authored
      	Fix another bug in the squash-newtypes story.
      [This one was spotted by Marcin, and is now enshrined in test tc130.]
      The desugarer straddles the boundary between the type checker and
      Core, so it sometimes needs to look through newtypes/implicit parameters
      and sometimes not.  This is really a bit painful, but I can't think of
      a better way to do it.
      The only simple way to fix things was to pass a bit more type
      information in the HsExpr type, from the type checker to the desugarer.
      That led to the non-local changes you can see.
      On the way I fixed one other thing.  In various HsSyn constructors
      there is a Type that is bogus (bottom) before the type checker, and
      filled in with a real type by the type checker.  In one place it was
      a (Maybe Type) which was Nothing before, and (Just ty) afterwards.
      I've defined a type synonym HsTypes.PostTcType for this, and a named
      bottom value HsTypes.placeHolderType to use when you want the bottom
  11. 25 Jun, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-06-25 08:09:57 by simonpj] · d069cec2
      simonpj authored
      	Squash newtypes
      This commit squashes newtypes and their coerces, from the typechecker
      onwards.  The original idea was that the coerces would not get in the
      way of optimising transformations, but despite much effort they continue
      to do so.   There's no very good reason to retain newtype information
      beyond the typechecker, so now we don't.
      Main points:
      * The post-typechecker suite of Type-manipulating functions is in
      types/Type.lhs, as before.   But now there's a new suite in types/TcType.lhs.
      The difference is that in the former, newtype are transparent, while in
      the latter they are opaque.  The typechecker should only import TcType,
      not Type.
      * The operations in TcType are all non-monadic, and most of them start with
      "tc" (e.g. tcSplitTyConApp).  All the monadic operations (used exclusively
      by the typechecker) are in a new module, typecheck/TcMType.lhs
      * I've grouped newtypes with predicate types, thus:
      	data Type = TyVarTy Tyvar | ....
      		  | SourceTy SourceType
      	data SourceType = NType TyCon [Type]
      			| ClassP Class [Type]
      			| IParam Type
      [SourceType was called PredType.]  This is a little wierd in some ways,
      because NTypes can't occur in qualified types.   However, the idea is that
      a SourceType is a type that is opaque to the type checker, but transparent
      to the rest of the compiler, and newtypes fit that as do implicit parameters
      and dictionaries.
      * Recursive newtypes still retain their coreces, exactly as before. If
      they were transparent we'd get a recursive type, and that would make
      various bits of the compiler diverge (e.g. things which do type comparison).
      * I've removed types/Unify.lhs (non-monadic type unifier and matcher),
      merging it into TcType.
      Ditto typecheck/TcUnify.lhs (monadic unifier), merging it into TcMType.
  12. 11 Jun, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-06-11 12:24:51 by simonpj] · 2c6d73e2
      simonpj authored
      	Tidy up and improve "pattern contexts"
      In various places (renamer, typechecker, desugarer) we need to know
      what the context of a pattern match is (case expression, function defn,
      let binding, etc).  This commit tidies up the story quite a bit.  I
      think it represents a net decrease in code, and certainly it improves the
      error messages from:
      	f x x = 3
      Prevsiously we got a message like "Conflicting bindings for x in a pattern match",
      but not it says "..in a defn of function f".
      WARNING: the tidy up had a more global effect than I originally expected,
      so it's possible that some other error messages look a bit peculiar.  They
      should be easy to fix, but tell us!
  13. 24 May, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-05-24 13:59:09 by simonpj] · cbdeae8f
      simonpj authored
      	More stuff towards generalising 'foreign' declarations
      This is the second step towards generalising 'foreign' declarations to
      handle langauges other than C.  Now I can handle
        foreign import dotnet type T
        foreign import dotnet "void Foo.Baz.f( T )" f :: T -> IO ()
      			** WARNING **
      	I believe that all the foreign stuff for C should
      	work exactly as before, but I have not tested it
      	thoroughly.  Sven, Manuel, Marcin: please give it a
      	whirl and compare old with new output.
      Lots of fiddling around with data types.  The main changes are
      * HsDecls.lhs
      	The ForeignDecl type and its friends
      	Note also the ForeignType constructor to TyClDecl
      * ForeignCall.lhs
      	Here's where the stuff that survives right through
      	compilation lives
      * TcForeign.lhs DsForeign.lhs
      	Substantial changes driven by the new data types
      * Parser.y ParseIface.y RnSource
      	Just what you'd expect
  14. 08 May, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-05-08 14:44:37 by simonpj] · 7c72bad5
      simonpj authored
      ****	MERGE WITH 5.00 BRANCH     ********
      	Make parallel list comprehensions work
      There were two bugs
      1.  The desugaring in DsListComp was generating code that failed Lint.
          I've restructured it quite a lot.
      2.  More seriously, in a ParStmt, the last 'stmt' may be a guard;
          but previously both guards and the result of a list comprehension
          were encoded as an ExprStmt (see HsExpr.Stmt), using the fact that
          the stmt was last in the list to make the difference between a guard
          and a result.  But in parallel list comp this isn't right:
      	[ e | x <- xs, guard | y <- ys ]
          Here 'guard' is last in its list, but isn't an overall result.
          The sensible fix is to properly distinguish
      	"here's the answer" 			 (ResultStmt)
      	"here's a guard or an imperative action" (ExprStmt)
          The fix is rather easy, but touched quite a lot of files.  On the
          way I tidied up the parser a little.
  15. 08 Mar, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-03-08 12:07:38 by simonpj] · 51a571c0
      simonpj authored
      	A major hygiene pass
      1. The main change here is to
      	Move what was the "IdFlavour" out of IdInfo,
      	and into the varDetails field of a Var
         It was a mess before, because the flavour was a permanent attribute
         of an Id, whereas the rest of the IdInfo was ephemeral.  It's
         all much tidier now.
         Main places to look:
      	   Var.lhs	Defn of VarDetails
      	   IdInfo.lhs	Defn of GlobalIdDetails
         The main remaining infelicity is that SpecPragmaIds are right down
         in Var.lhs, which seems unduly built-in for such an ephemeral thing.
         But that is no worse than before.
      2. Tidy up the HscMain story a little.  Move mkModDetails from MkIface
         into CoreTidy (where it belongs more nicely)
         This was partly forced by (1) above, because I didn't want to make
         DictFun Ids into a separate kind of Id (which is how it was before).
         Not having them separate means we have to keep a list of them right
         through, rather than pull them out of the bindings at the end.
      3. Add NameEnv as a separate module (to join NameSet).
      4. Remove unnecessary {-# SOURCE #-} imports from FieldLabel.
  16. 27 Feb, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-02-27 11:50:05 by simonpj] · 82f63df9
      simonpj authored
      Temporary fix for a nasty black hole
      The problem is that the type checker has a big knot for "unf_env".
      This means that we can't look at unfoldings inside the loop, which
      is fair enough.  But setting an unfolding in the IdInfo is strict
      in the unfolding, so we can't look at the IdInfo either.
      But isLocalId looks at the IdInfo, and it was being used in an
      assert in TcHsSyn, and in setting the in_scope_vars in TcIfaceSig.
      I think the right solution is to take the "flavour" out of IdInfo,
      and put it into VarDetails, but I've done a quick fix for now.
      (Remove the assert, and use a different way in TcIfaceSig.)
  17. 26 Feb, 2001 1 commit
    • simonmar's avatar
      [project @ 2001-02-26 15:06:57 by simonmar] · 1c62b517
      simonmar authored
      Implement do-style bindings on the GHCi command line.
      The syntax for a command-line is exactly that of a do statement, with
      the following meanings:
        - `pat <- expr'
          performs expr, and binds each of the variables in pat.
        - `let pat = expr; ...'
          binds each of the variables in pat, doesn't do any evaluation
        - `expr'
          behaves as `it <- expr' if expr is IO-typed, or `let it = expr'
          followed by `print it' otherwise.
  18. 20 Feb, 2001 2 commits
    • simonpj's avatar
      [project @ 2001-02-20 15:38:45 by simonpj] · 48d9dabf
      simonpj authored
      Import wibble
    • simonpj's avatar
      [project @ 2001-02-20 09:42:50 by simonpj] · 22ffc06a
      simonpj authored
      Typechecking [TcModule, TcBinds, TcHsSyn, TcInstDcls, TcSimplify]
      * Fix a bug in TcSimplify that broke functional dependencies.
        Interleaving unification and context reduction is trickier 
        than I thought.  Comments in the code amplify.  
      * Fix a functional-dependency bug, that meant that this pgm:
      	class C a b | a -> b where f :: a -> b
      	g :: (C a b, Eq b) => a -> Bool
      	g x = f x == f x
        gave an ambiguity error report.  I'm afraid I've forgotten
        what the problem was.
      * Correct the implementation of the monomorphism restriction,
        in TcBinds.generalise.  This fixes Marcin's bug report:
      	test1 :: Eq a => a -> b -> b
      	test1 x y = y
      	test2 = test1 (3::Int)
        Previously we were erroneously inferring test2 :: () -> ()
      * Make the "unf_env" that is looped round in TcModule go round
        in a big loop, not just round tcImports.  This matters when
        we have mutually recursive modules, so that the Ids bound in
        the source code may appear in the imports.  Sigh.  But no big
        It does mean that you have to be careful not to call isLocalId,
        isDataConId etc, because they consult the IdInfo of an Id, which 
        in turn may be determined by the loop-tied unf_env.
  19. 25 Jan, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-01-25 17:54:24 by simonpj] · 4e342297
      simonpj authored
      	   Mainly FunDeps (23 Jan 01)
      This commit re-engineers the handling of functional dependencies.
      A functional dependency is no longer an Inst; instead, the necessary
      dependencies are snaffled out of their Class when necessary.
      As part of this exercise I found that I had to re-work how to do generalisation
      in a binding group.  There is rather exhaustive documentation on the new Plan
      at the top of TcSimplify.
      	WARNING: I have compiled all the libraries with this new compiler
      		 and all looks well, but I have not run many programs.
      		 Things may break.  Let me know if so.
      The main changes are these:
      1.  typecheck/TcBinds and TcSimplify have a lot of changes due to the
          new generalisation and context reduction story.  There are extensive
          comments at the start of TcSimplify
      2.  typecheck/TcImprove is removed altogether.  Instead, improvement is
          interleaved with context reduction (until a fixpoint is reached).
          All this is done in TcSimplify.
      3.  types/FunDeps has new exports
      	* 'improve' does improvement, returning a list of equations
      	* 'grow' and 'oclose' close a list of type variables wrt a set of
      	  PredTypes, but in slightly different ways.  Comments in file.
      4.  I improved the way in which we check that main::IO t.  It's tidier now.
      In addition
      *   typecheck/TcMatches:
      	a) Tidy up, introducing a common function tcCheckExistentialPat
      	b) Improve the typechecking of parallel list comprehensions,
      	   which wasn't quite right before.  (see comments with tcStmts)
      	WARNING: (b) is untested!  Jeff, you might want to check.
      *   Numerous other incidental changes in the typechecker
      *   Manuel found that rules don't fire well when you have partial applications
          from overloading.  For example, we may get
      	f a (d::Ord a) = let m_g = g a d
      			 \y :: a -> ...(m_g (h y))...
          The 'method' m_g doesn't get inlined because (g a d) might be a redex.
          Yet a rule that looks like
      		g a d (h y) = ...
          won't fire because that doesn't show up.  One way out would be to make
          the rule matcher a bit less paranoid about duplicating work, but instead
          I've added a flag
          which controls whether we generate things like m_g in the first place.
          It's not clear that they are a win in the first place.
          The flag is actually consulted in Inst.tcInstId
  20. 21 Nov, 2000 1 commit
  21. 20 Nov, 2000 1 commit
    • simonpj's avatar
      [project @ 2000-11-20 14:48:52 by simonpj] · c271b647
      simonpj authored
      When renaming, typechecking an expression from the user
      interface, we may suck in declarations from interface
      files (e.g. the Prelude).  This commit takes account of that.
      To do so, I did some significant restructuring in TcModule,
      with consequential changes and tidy ups elsewhere in the type
      checker.  I think there should be fewer lines in total than before.
  22. 14 Nov, 2000 2 commits
  23. 07 Nov, 2000 1 commit
  24. 13 Oct, 2000 1 commit
  25. 12 Oct, 2000 2 commits
  26. 22 Sep, 2000 1 commit
  27. 14 Jul, 2000 1 commit
    • simonpj's avatar
      [project @ 2000-07-14 08:17:36 by simonpj] · 77a8c0db
      simonpj authored
      This commit completely re-does the kind-inference mechanism.
      Previously it was inter-wound with type inference, but that was
      always hard to understand, and it finally broke when we started
      checking for ambiguity when type-checking a type signature (details
      So now kind inference is more clearly separated, so that it never
      takes place at the same time as type inference.  The biggest change
      is in TcTyClsDecls, which does the kind inference for a group of
      type and class declarations.  It now contains comments to explain
      how it all works.
      There are also comments in TypeRep which describes the slightly
      tricky way in which we deal with the fact that kind 'type' (written
      '*') actually has 'boxed type' and 'unboxed type' as sub-kinds.
      The whole thing is a bit of a hack, because we don't really have 
      sub-kinding, but it's less of a hack than before.
      A lot of general tidying up happened at the same time.
      In particular, I removed some dead code here and there
  28. 11 Jul, 2000 1 commit
  29. 25 May, 2000 1 commit
    • simonpj's avatar
      [project @ 2000-05-25 12:41:14 by simonpj] · 495ef8bd
      simonpj authored
      		Apr/May 2000
      This is a pretty big commit!  It adds stuff I've been working on
      over the last month or so.  DO NOT MERGE IT WITH 4.07!
      Interface file formats have changed a little; you'll need
      to make clean before remaking.
      						Simon PJ
      Recompilation checking
      Substantial improvement in recompilation checking.  The version management
      is now entirely internal to GHC.  ghc-iface.lprl is dead!
      The trick is to generate the new interface file in two steps:
        - first convert Types etc to HsTypes etc, and thereby
      	build a new ParsedIface
        - then compare against the parsed (but not renamed) version of the old
      	interface file
      Doing this meant adding code to convert *to* HsSyn things, and to
      compare HsSyn things for equality.  That is the main tedious bit.
      Another improvement is that we now track version info for
      fixities and rules, which was missing before.
      Interface file reading
      Make interface files reading more robust.
        * If the old interface file is unreadable, don't fail. [bug fix]
        * If the old interface file mentions interfaces
          that are unreadable, don't fail. [bug fix]
        * When we can't find the interface file,
          print the directories we are looking in.  [feature]
      Type signatures
        * New flag -ddump-types to print type signatures
      Type pruning
      When importing
      	data T = T1 A | T2 B | T3 C
      it seems excessive to import the types A, B, C as well, unless
      the constructors T1, T2 etc are used.  A,B,C might be more types,
      and importing them may mean reading more interfaces, and so on.
       So the idea is that the renamer will just import the decl
      	data T
      unless one of the constructors is used.  This turns out to be quite
      easy to implement.  The downside is that we must make sure the
      constructors are always available if they are really needed, so
      I regard this as an experimental feature.
      Elimininate ThinAir names
      Eliminate ThinAir.lhs and all its works.  It was always a hack, and now
      the desugarer carries around an environment I think we can nuke ThinAir
      As part of this, I had to move all the Prelude RdrName defns from PrelInfo
      to PrelMods --- so I renamed PrelMods as PrelNames.
      I also had to move the builtinRules so that they are injected by the renamer
      (rather than appearing out of the blue in SimplCore).  This is if anything simpler.
      * Tidy up the data types involved in Rules
      * Eliminate RnEnv.better_provenance; use Name.hasBetterProv instead
      * Add Unique.hasKey :: Uniquable a => a -> Unique -> Bool
        It's useful in a lot of places
      * Fix a bug in interface file parsing for __U[!]
  30. 05 Apr, 2000 1 commit
    • simonpj's avatar
      [project @ 2000-04-05 16:25:51 by simonpj] · d4e0a55c
      simonpj authored
      * Add new flag -fddump-minimal-imports, which dumps a file
        M.imports that contains the (allegedly) minimal bunch of
        imports that make the system work.
        It's done by Rename.printMinimalImports
      * Extend foreign import/export to handle
      	* Booleans
      	* newtypes
        as requested by the FFI team
      * Tidy up DsCCall quite a bit
        Remove maybeBoxedPrimTy from TcHsSyn
  31. 24 Mar, 2000 1 commit
    • simonpj's avatar
      [project @ 2000-03-24 17:49:29 by simonpj] · 6c872fff
      simonpj authored
      a) Small wibbles to do with inlining and floating
      b) Implement Ralf's request, so that one can write
      	type F = forall a. a -> a
      	f :: Int -> F
      	f = ...
         The for-alls inside F are hoisted out to the top of
         the type signature for f.  This applies uniformly to
         all user-written types
  32. 23 Mar, 2000 1 commit
    • simonpj's avatar
      [project @ 2000-03-23 17:45:17 by simonpj] · 111cee3f
      simonpj authored
      This utterly gigantic commit is what I've been up to in background
      mode in the last couple of months.  Originally the main goal
      was to get rid of Con (staturated constant applications)
      in the CoreExpr type, but one thing led to another, and I kept
      postponing actually committing.   Sorry.
      	Simon, 23 March 2000
      I've tested it pretty thoroughly, but doubtless things will break.
      Here are the highlights
      * Con is gone; the CoreExpr type is simpler
      * NoRepLits have gone
      * Better usage info in interface files => less recompilation
      * Result type signatures work
      * CCall primop is tidied up
      * Constant folding now done by Rules
      * Lots of hackery in the simplifier
      * Improvements in CPR and strictness analysis
      Many bug fixes including
      * Sergey's DoCon compiles OK; no loop in the strictness analyser
      * Volker Wysk's programs don't crash the CPR analyser
      I have not done much on measuring compilation times and binary sizes;
      they could have got worse.  I think performance has got significantly
      better, though, in most cases.
      Removing the Con form of Core expressions
      The big thing is that
        For every constructor C there are now *two* Ids:
      	C is the constructor's *wrapper*. It evaluates and unboxes arguments
      	before calling $wC.  It has a perfectly ordinary top-level defn
      	in the module defining the data type.
      	$wC is the constructor's *worker*.  It is like a primop that simply
      	allocates and builds the constructor value.  Its arguments are the
      	actual representation arguments of the constructor.
      	Its type may be different to C, because:
      		- useless dict args are dropped
      		- strict args may be flattened
        For every primop P there is *one* Id, its (curried) Id
        Neither contructor worker Id nor the primop Id have a defminition anywhere.
        Instead they are saturated during the core-to-STG pass, and the code generator
        generates code for them directly. The STG language still has saturated
        primops and constructor applications.
      * The Const type disappears, along with Const.lhs.  The literal part
        of Const.lhs reappears as Literal.lhs.  Much tidying up in here,
        to bring all the range checking into this one module.
      * I got rid of NoRep literals entirely.  They just seem to be too much trouble.
      * Because Con's don't exist any more, the funny C { args } syntax
        disappears from inteface files.
      * Result type signatures now work
      	f :: Int -> Int = \x -> x
      	-- The Int->Int is the type of f
      	g x y :: Int = x+y
      	-- The Int is the type of the result of (g x y)
      Recompilation checking and make
      * The .hi file for a modules is not touched if it doesn't change.  (It used to
        be touched regardless, forcing a chain of recompilations.)  The penalty for this
        is that we record exported things just as if they were mentioned in the body of
        the module.  And the penalty for that is that we may recompile a module when
        the only things that have changed are the things it is passing on without using.
        But it seems like a good trade.
      * -recomp is on by default
      Foreign declarations
      * If you say
      	foreign export zoo :: Int -> IO Int
        then you get a C produre called 'zoo', not 'zzoo' as before.
        I've also added a check that complains if you export (or import) a C
        procedure whose name isn't legal C.
      Code generation and labels
      * Now that constructor workers and wrappers have distinct names, there's
        no need to have a Foo_static_closure and a Foo_closure for constructor Foo.
        I nuked the entire StaticClosure story.  This has effects in some of
        the RTS headers (i.e. s/static_closure/closure/g)
      Rules, constant folding
      * Constant folding becomes just another rewrite rule, attached to the Id for the
        PrimOp.   To achieve this, there's a new form of Rule, a BuiltinRule (see CoreSyn.lhs).
        The prelude rules are in prelude/PrelRules.lhs, while simplCore/ConFold.lhs has gone.
      * Appending of constant strings now works, using fold/build fusion, plus
        the rewrite rule
      	unpack "foo" c (unpack "baz" c n)  =  unpack "foobaz" c n
        Implemented in PrelRules.lhs
      * The CCall primop is tidied up quite a bit.  There is now a data type CCall,
        defined in PrimOp, that packages up the info needed for a particular CCall.
        There is a new Id for each new ccall, with an big "occurrence name"
      	{__ccall "foo" gc Int# -> Int#}
        In interface files, this is parsed as a single Id, which is what it is, really.
      * There were numerous places where the host compiler's
        minInt/maxInt was being used as the target machine's minInt/maxInt.
        I nuked all of these; everything is localised to inIntRange and inWordRange,
        in Literal.lhs
      * Desugaring record updates was broken: it didn't generate correct matches when
        used withe records with fancy unboxing etc.  It now uses matchWrapper.
      * Significant tidying up in codeGen/SMRep.lhs
      * Add __word, __word64, __int64 terminals to signal the obvious types
        in interface files.  Add the ability to print word values in hex into
        C code.
      * PrimOp.lhs is no longer part of a loop.  Remove PrimOp.hi-boot*
      * isProductTyCon no longer returns False for recursive products, nor
        for unboxed products; you have to test for these separately.
        There's no reason not to do CPR for recursive product types, for example.
        Ditto splitProductType_maybe.
      * New -fno-case-of-case flag for the simplifier.  We use this in the first run
        of the simplifier, where it helps to stop messing up expressions that
        the (subsequent) full laziness pass would otherwise find float out.
        It's much more effective than previous half-baked hacks in inlining.
        Actually, it turned out that there were three places in Simplify.lhs that
        needed to know use this flag.
      * Make the float-in pass push duplicatable bindings into the branches of
        a case expression, in the hope that we never have to allocate them.
        (see FloatIn.sepBindsByDropPoint)
      * Arrange that top-level bottoming Ids get a NOINLINE pragma
        This reduced gratuitous inlining of error messages.
        But arrange that such things still get w/w'd.
      * Arrange that a strict argument position is regarded as an 'interesting'
        context, so that if we see
      	foldr k z (g x)
        then we'll be inclined to inline g; this can expose a build.
      * There was a missing case in CoreUtils.exprEtaExpandArity that meant
        we were missing some obvious cases for eta expansion
        Also improve the code when handling applications.
      * Make record selectors (identifiable by their IdFlavour) into "cheap" operations.
      	  [The change is a 2-liner in CoreUtils.exprIsCheap]
        This means that record selection may be inlined into function bodies, which
        greatly improves the arities of overloaded functions.
      * Make a cleaner job of inlining "lone variables".  There was some distributed
        cunning, but I've centralised it all now in SimplUtils.analyseCont, which
        analyses the context of a call to decide whether it is "interesting".
      * Don't specialise very small functions in Specialise.specDefn
        It's better to inline it.  Rather like the worker/wrapper case.
      * Be just a little more aggressive when floating out of let rhss.
        See comments with Simplify.wantToExpose
        A small change with an occasional big effect.
      * Make the inline-size computation think that
      	case x of I# x -> ...
        is *free*.
      CPR analysis
      * Fix what was essentially a bug in CPR analysis.  Consider
      	letrec f x = let g y = let ... in f e1
      		     if ... then (a,b) else g x
        g has the CPR property if f does; so when generating the final annotated
        RHS for f, we must use an envt in which f is bound to its final abstract
        value.  This wasn't happening.  Instead, f was given the CPR tag but g
        wasn't; but of course the w/w pass gives rotten results in that case!!
        (Because f's CPR-ness relied on g's.)
        On they way I tidied up the code in CprAnalyse.  It's quite a bit shorter.
        The fact that some data constructors return a constructed product shows
        up in their CPR info (MkId.mkDataConId) not in CprAnalyse.lhs
      Strictness analysis and worker/wrapper
      * BIG THING: pass in the demand to StrictAnal.saExpr.  This affects situations
      	f (let x = e1 in (x,x))
        where f turns out to have strictness u(SS), say.  In this case we can
        mark x as demanded, and use a case expression for it.
        The situation before is that we didn't "know" that there is the u(SS)
        demand on the argument, so we simply computed that the body of the let
        expression is lazy in x, and marked x as lazily-demanded.  Then even after
        f was w/w'd we got
      	let x = e1 in case (x,x) of (a,b) -> $wf a b
        and hence
      	let x = e1 in $wf a b
        I found a much more complicated situation in spectral/sphere/Main.shade,
        which improved quite a bit with this change.
      * Moved the StrictnessInfo type from IdInfo to Demand.  It's the logical
        place for it, and helps avoid module loops
      * Do worker/wrapper for coerces even if the arity is zero.  Thus:
      	stdout = coerce Handle (..blurg..)
      	wibble = (...blurg...)
      	stdout = coerce Handle wibble
        This is good because I found places where we were saying
      	case coerce t stdout of { MVar a ->
      	case coerce t stdout of { MVar b ->
        and the redundant case wasn't getting eliminated because of the coerce.
  33. 23 Feb, 2000 1 commit
    • lewie's avatar
      [project @ 2000-02-23 19:41:50 by lewie] · e87d56ce
      lewie authored
      Handle `with' more cleverly.  I was generating partially applied methods
      for the case where the `with' expression was also overloaded, but this
      was buggy, and completely unnecessary.  Instead, simply force the method
      binding at the point of the `with' expression (we reap no benefits from
      pushing the sharing further out anyway), and release the remainder of
      the method's context into the LIE.
  34. 28 Jan, 2000 1 commit
    • lewie's avatar
      [project @ 2000-01-28 20:52:37 by lewie] · 266fadd9
      lewie authored
      First pass at implicit parameters.  Honest, I didn't really go in *intending*
      to modify every file in the typechecker... ;-)  The breadth of the change
      is partly due to generalizing contexts so that they are not hardwired to
      be (Class, [Type]) pairs.  See types/Type.lhs for details (look for PredType).
  35. 06 Dec, 1999 1 commit
  36. 14 Jul, 1999 1 commit
    • simonpj's avatar
      [project @ 1999-07-14 14:40:20 by simonpj] · 4e7d56fd
      simonpj authored
      Main things:
      * Add splitProductType_maybe to DataCon.lhs, with type
      	:: Type 			-- A product type, perhaps
      	-> Maybe (TyCon, 		-- The type constructor
      		  [Type],		-- Type args of the tycon
      		  DataCon,		-- The data constructor
      		  [Type])		-- Its *representation* arg types
        Then use it in many places (e.g. worker-wrapper places) instead
        of a pile of junk
      * Clean up various uses of dataConArgTys, which were plain wrong because
        they weren't passed the existential type arguments.  Most of these calls
        are eliminated by using splitProductType_maybe above.  I hope I correctly
        squashed the others. This fixes a bug that Meurig's programs showed up.
          module FailGHC (killSustainer) where
          import Weak
          import IOExts
          data Sustainer = forall a . Sustainer (IORef (Maybe a)) (IO ())
          killSustainer :: Sustainer -> IO ()
          killSustainer (Sustainer _ act) = act
        The above program used to kill the compiler.
      * A fairly concerted attack on the Dreaded Space Leak.
      	- Add Type.seqType, CoreSyn.seqExpr, CoreSyn.seqRules
      	- Add some seq'ing when building Ids and IdInfos
      		These reduce the space usage a lot
      	- Add CoreSyn.coreBindsSize, which is pretty strict in the program,
      		and call it when we have -dshow-passes.
      	- Do not put the inlining in an Id that is being plugged into
      		the result-expression of the simplifier.  This cures
      		a the 'wedge' in the space profile for reasons I don't understand fully
        Together, these things reduce the max space usage when compiling PrelNum from
        17M to about 7Mbytes.
        I think there are now *too many* seqs, and they waste work, but I don't have
        time to find which ones.
        Furthermore, we aren't done. For some reason, some of the stuff allocated by
        the simplifier makes it through all during code generation and I don't see why.
        There's a should-be-unnecessary call to coreBindsSize in Main.main which
        zaps some, but not all of this space.
        -dshow-passes reduces space usage a bit, but I don't think it should really.
        All the measurements were made on a compiler compiled with profiling by
        GHC 3.03.    I hope they carry over to other builds!
      * One trivial thing: changed all variables 'label' to 'lbl', becuase the
        former is a keyword with -fglagow-exts in GHC 3.03 (which I was compiling with).
        Something similar in StringBuffer.
  37. 18 May, 1999 1 commit