- 23 Oct, 2002 1 commit
-
-
simonpj authored
------------------------------------------------ Allow implicit-parameter bindings anywhere that a normal binding group is allowed. ------------------------------------------------ That is, you can have implicit parameters * in a let binding * in a where clause (but then you can't have non-implicit ones as well) * in a let group in a list comprehension or monad do-notation The implementation is simple: just add IPBinds to the allowable forms of HsBinds, and remove the HsWith expression form altogether. (It now comes in via the HsLet form.) It'a a nice generalisation really. Needs a bit of documentation, which I'll do next.
-
- 11 Oct, 2002 2 commits
-
-
simonpj authored
More reification wibbling; and -ddump-splices
-
simonpj authored
------------------------------------------ Implement reification for Template Haskell ------------------------------------------ This is entirely un-tested, but I don't think it'll break non-TH stuff. Implements reifyDecl T :: Dec -- Data type T reifyDecl C :: Dec -- Class C reifyType f :: Typ -- Function f I hope.
-
- 09 Oct, 2002 2 commits
-
-
simonpj authored
Fix to mdo, plus SrcLocs on splices and brackets
-
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.
-
- 27 Sep, 2002 2 commits
-
-
simonpj authored
Wibbles to improve error reporting
-
simonpj authored
-------------------------------- Implement recursive do-notation -------------------------------- This commit adds recursive do-notation, which Hugs has had for some time. mdo { x <- foo y ; y <- baz x ; return (y,x) } turns into do { (x,y) <- mfix (\~(x,y) -> do { x <- foo y; y <- baz x }) ; return (y,x) } This is all based on work by Levent Erkok and John Lanuchbury. The really tricky bit is in the renamer (RnExpr.rnMDoStmts) where we break things up into minimal segments. The rest is easy, including the type checker. Levent laid the groundwork, and Simon finished it off. Needless to say, I couldn't resist tidying up other stuff, so there's no guaranteed I have not broken something.
-
- 13 Sep, 2002 1 commit
-
-
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.
-
- 06 Jun, 2002 1 commit
-
-
simonpj authored
Fix bogon in rebindable syntax implementation
-
- 05 Jun, 2002 1 commit
-
-
simonpj authored
--------------------------------------- Add rebindable syntax for do-notation (this time, on the HEAD) --------------------------------------- Make do-notation use rebindable syntax, so that -fno-implicit-prelude makes do-notation use whatever (>>=), (>>), return, fail are in scope, rather than the Prelude versions. On the way, combine HsDo and HsDoOut into one constructor in HsSyn, and tidy up type checking of HsDo.
-
- 29 Apr, 2002 1 commit
-
-
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.
-
- 11 Apr, 2002 1 commit
-
-
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.
-
- 02 Apr, 2002 1 commit
-
-
simonmar authored
Allow the use of 'let' for implcit bindings. Support for 'with' is left in place for the time being, but on seeing a 'with' we emit a non-suppressible warning about 'with' being deprecated in favour of 'let'.
-
- 01 Apr, 2002 1 commit
-
-
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
-
- 11 Feb, 2002 1 commit
-
-
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 `-fflatten'. - 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.
-
- 29 Nov, 2001 1 commit
-
-
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 split!) 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) where 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) where (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. Warnings ~~~~~~~~ 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) where 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) where 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.
-
- 26 Nov, 2001 1 commit
-
-
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 like 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 example: 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 TcUnify.tcSub 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 file). All of this doesn't come entirely for free. Here's the typechecker line count (INCLUDING comments) Before 16,551 After 17,116
-
- 31 Oct, 2001 1 commit
-
-
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.
-
- 20 Aug, 2001 1 commit
-
-
simonpj authored
Print implicit-parameter bindings properly
-
- 13 Jul, 2001 1 commit
-
-
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 RnEnv.lookupSyntaxName
-
- 12 Jul, 2001 1 commit
-
-
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 value.
-
- 25 Jun, 2001 1 commit
-
-
simonpj authored
Import wibbles
-
- 11 Jun, 2001 1 commit
-
-
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!
-
- 22 May, 2001 1 commit
-
-
simonpj authored
------------------------------------------- Towards generalising 'foreign' declarations ------------------------------------------- This is a first step towards generalising 'foreign' declarations to handle langauges other than C. Quite a lot of files are touched, but nothing has really changed. Everything should work exactly as before. But please be on your guard for ccall-related bugs. Main things Basic data types: ForeignCall.lhs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Remove absCSyn/CallConv.lhs * Add prelude/ForeignCall.lhs. This defines the ForeignCall type and its variants * Define ForeignCall.Safety to say whether a call is unsafe or not (was just a boolean). Lots of consequential chuffing. * Remove all CCall stuff from PrimOp, and put it in ForeignCall Take CCallOp out of the PrimOp type (where it was always a glitch) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Add IdInfo.FCallId variant to the type IdInfo.GlobalIdDetails, along with predicates Id.isFCallId, Id.isFCallId_maybe * Add StgSyn.StgOp, to sum PrimOp with FCallOp, because it *is* useful to sum them together in Stg and AbsC land. If nothing else, it minimises changes. Also generally rename "CCall" stuff to "FCall" where it's generic to all foreign calls.
-
- 10 May, 2001 1 commit
-
-
simonmar authored
typo in error msg, pointed out by Alastair Reid.
-
- 08 May, 2001 1 commit
-
-
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.
-
- 03 May, 2001 1 commit
-
-
simonpj authored
Correct pretty print of HsIPVar
-
- 30 Apr, 2001 1 commit
-
-
simonpj authored
Improve error message
-
- 27 Mar, 2001 1 commit
-
-
simonpj authored
Print minimal import operators correctly
-
- 26 Feb, 2001 1 commit
-
-
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.
-
- 20 Feb, 2001 1 commit
-
-
simonpj authored
Decoupling the Prelude [HsExpr, HsLit, HsPat, ParseUtil, Parser.y, PrelNames, ~~~~~~~~~~~~~~~~~~~~~~ Rename, RnEnv, RnExpr, RnHsSyn, Inst, TcEnv, TcMonad, TcPat, TcExpr] The -fno-implicit-prelude flag is meant to arrange that when you write 3 you get fromInt 3 where 'fromInt' is whatever fromInt is in scope at the top level of the module being compiled. Similarly for * numeric patterns * n+k patterns * negation This used to work, but broke when we made the static/dynamic flag distinction. It's now tidied up a lot. Here's the plan: - PrelNames contains sugarList :: SugarList, which maps built-in names to the RdrName that should replace them. - The renamer makes a finite map :: SugarMap, which maps the built-in names to the Name of the re-mapped thing - The typechecker consults this map via tcLookupSyntaxId when it is doing numeric things At present I've only decoupled numeric syntax, since that is the main demand, but the scheme is much more robustly extensible than the previous method. As a result some HsSyn constructors don't need to carry names in them (notably HsOverLit, NegApp, NPlusKPatIn)
-
- 10 Nov, 2000 1 commit
-
-
simonpj authored
1. Outputable.PprStyle now carries a bit more information In particular, the printing style tells whether to print a name in unqualified form. This used to be embedded in a Name, but since Names now outlive a single compilation unit, that's no longer appropriate. So now the print-unqualified predicate is passed in the printing style, not embedded in the Name. 2. I tidied up HscMain a little. Many of the showPass messages have migraged into the repective pass drivers
-
- 07 Nov, 2000 1 commit
-
-
simonmar authored
This commit completes the merge of compiler part of the HEAD with the before-ghci-branch to before-ghci-branch-merged.
-
- 03 Oct, 2000 1 commit
-
-
simonpj authored
-------------------------------------- Adding generics SLPJ Oct 2000 -------------------------------------- This big commit adds Hinze/PJ-style generic class definitions, based on work by Andrei Serjantov. For example: class Bin a where toBin :: a -> [Int] fromBin :: [Int] -> (a, [Int]) toBin {| Unit |} Unit = [] toBin {| a :+: b |} (Inl x) = 0 : toBin x toBin {| a :+: b |} (Inr y) = 1 : toBin y toBin {| a :*: b |} (x :*: y) = toBin x ++ toBin y fromBin {| Unit |} bs = (Unit, bs) fromBin {| a :+: b |} (0:bs) = (Inl x, bs') where (x,bs') = fromBin bs fromBin {| a :+: b |} (1:bs) = (Inr y, bs') where (y,bs') = fromBin bs fromBin {| a :*: b |} bs = (x :*: y, bs'') where (x,bs' ) = fromBin bs (y,bs'') = fromBin bs' Now we can say simply instance Bin a => Bin [a] and the compiler will derive the appropriate code automatically. (About 9k lines of diffs. Ha!) Generic related things ~~~~~~~~~~~~~~~~~~~~~~ * basicTypes/BasicTypes: The EP type (embedding-projection pairs) * types/TyCon: An extra field in an algebraic tycon (genInfo) * types/Class, and hsSyn/HsBinds: Each class op (or ClassOpSig) carries information about whether it a) has no default method b) has a polymorphic default method c) has a generic default method There's a new data type for this: Class.DefMeth * types/Generics: A new module containing good chunk of the generic-related code It has a .hi-boot file (alas). * typecheck/TcInstDcls, typecheck/TcClassDcl: Most of the rest of the generics-related code * hsSyn/HsTypes: New infix type form to allow types of the form data a :+: b = Inl a | Inr b * parser/Parser.y, Lex.lhs, rename/ParseIface.y: Deal with the new syntax * prelude/TysPrim, TysWiredIn: Need to generate generic stuff for the wired-in TyCons * rename/RnSource RnBinds: A rather gruesome hack to deal with scoping of type variables from a generic patterns. Details commented in the ClassDecl case of RnSource.rnDecl. Of course, there are many minor renamer consequences of the other changes above. * lib/std/PrelBase.lhs Data type declarations for Unit, :+:, :*: Slightly unrelated housekeeping ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * hsSyn/HsDecls: ClassDecls now carry the Names for their implied declarations (superclass selectors, tycon, etc) in a list, rather than laid out one by one. This simplifies code between the parser and the type checker. * prelude/PrelNames, TysWiredIn: All the RdrNames are now together in PrelNames. * utils/ListSetOps: Add finite mappings based on equality and association lists (Assoc a b) Move stuff from List.lhs that is related
-
- 22 Sep, 2000 1 commit
-
-
simonpj authored
-------------------------------------------------- Tidying up HsLit, and making it possible to define your own numeric library Simon PJ 22 Sept 00 -------------------------------------------------- ** NOTE: I did these changes on the aeroplane. They should compile, and the Prelude still compiles OK, but it's entirely possible that I've broken something The original reason for this many-file but rather shallow commit is that it's impossible in Haskell to write your own numeric library. Why? Because when you say '1' you get (Prelude.fromInteger 1), regardless of what you hide from the Prelude, or import from other libraries you have written. So the idea is to extend the -fno-implicit-prelude flag so that in addition to no importing the Prelude, you can rebind fromInteger -- Applied to literal constants fromRational -- Ditto negate -- Invoked by the syntax (-x) the (-) used when desugaring n+k patterns After toying with other designs, I eventually settled on a simple, crude one: rather than adding a new flag, I just extended the semantics of -fno-implicit-prelude so that uses of fromInteger, fromRational and negate are all bound to "whatever is in scope" rather than "the fixed Prelude functions". So if you say {-# OPTIONS -fno-implicit-prelude #-} module M where import MyPrelude( fromInteger ) x = 3 the literal 3 will use whatever (unqualified) "fromInteger" is in scope, in this case the one gotten from MyPrelude. On the way, though, I studied how HsLit worked, and did a substantial tidy up, deleting quite a lot of code along the way. In particular. * HsBasic.lhs is renamed HsLit.lhs. It defines the HsLit type. * There are now two HsLit types, both defined in HsLit. HsLit for non-overloaded literals (like 'x') HsOverLit for overloaded literals (like 1 and 2.3) * HsOverLit completely replaces Inst.OverloadedLit, which disappears. An HsExpr can now be an HsOverLit as well as an HsLit. * HsOverLit carries the Name of the fromInteger/fromRational operation, so that the renamer can help with looking up the unqualified name when -fno-implicit-prelude is on. Ditto the HsExpr for negation. It's all very tidy now. * RdrHsSyn contains the stuff that handles -fno-implicit-prelude (see esp RdrHsSyn.prelQual). RdrHsSyn also contains all the "smart constructors" used by the parser when building HsSyn. See for example RdrHsSyn.mkNegApp (previously the renamer (!) did the business of turning (- 3#) into -3#). * I tidied up the handling of "special ids" in the parser. There's much less duplication now. * Move Sven's Horner stuff to the desugarer, where it belongs. There's now a nice function DsUtils.mkIntegerLit which brings together related code from no fewer than three separate places into one single place. Nice! * A nice tidy-up in MatchLit.partitionEqnsByLit became possible. * Desugaring of HsLits is now much tidier (DsExpr.dsLit) * Some stuff to do with RdrNames is moved from ParseUtil.lhs to RdrHsSyn.lhs, which is where it really belongs. * I also removed many unnecessary imports from modules quite a bit of dead code in divers places
-
- 17 Jul, 2000 1 commit
-
-
simonpj authored
Print operator names in HsExpr better
-
- 25 May, 2000 1 commit
-
-
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 altogether. 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. Miscellaneous ~~~~~~~~~~~~~ * 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[!]
-
- 13 Apr, 2000 1 commit
-
-
simonpj authored
Add support for 'packages'. * A package is a group of modules. * A package has a name (e.g. std) * A package is built into a single library (Unix; e.g. libHSstd.a) or a single DLL (Windows; e.g. HSstd.dll) * The '-package-name foo' flag tells GHC that the module being compiled is destined for package foo. * The '-package foo' flag tells GHC to make available modules from package 'foo'. It replaces '-syslib foo' which is now deprecated. * Cross-package references cost an extra indirection in Windows, but not Unix * GHC does not maintain detailed cross-package dependency information. It does remember which modules in other packages the current module depends on, but not which things within those imported things. All of this tidies up the Prelude enormously. The Prelude and Standard Libraries are built into a singl package called 'std'. (This is a change; the library is now called libHSstd.a instead of libHS.a)
-
- 03 Apr, 2000 1 commit
-
-
simonpj authored
* Make it so that recursive newtype declarations don't send GHC into an infinite loop. newtype T = MkT T This happened because Type.repType looked throught newtypes, and that never stopped! Now TcTyDecls.mkNewTyConRep does the job more carefully, and the result is cached in the TyCon itself. * Improve the handling of type signatures & pragmas. Previously a mis-placed (say) SPECIALISE instance pragmas could be silently ignored. Both these changes involved moving quite a lot of stuff between modules.
-
- 23 Mar, 2000 1 commit
-
-
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. Parsing ~~~~~~~ * 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. Miscellaneous ~~~~~~~~~~~~~ * 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* Types ~~~~~ * 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. Simplification ~~~~~~~~~~~~~~~ * 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 in 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 like 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.
-