summaryrefslogtreecommitdiff
path: root/compiler/parser
Commit message (Collapse)AuthorAgeFilesLines
* Support code generation for unboxed-tuple function argumentsunboxed-tuple-arguments2Max Bolingbroke2012-05-151-1/+1
| | | | | | | | | | | This is done by a 'unarisation' pre-pass at the STG level which translates away all (live) binders binding something of unboxed tuple type. This has the following knock-on effects: * The subkind hierarchy is vastly simplified (no UbxTupleKind or ArgKind) * Various relaxed type checks in typechecker, 'foreign import prim' etc * All case binders may be live at the Core level
* Tweak the lexer: In particular, improve notFollowedBy and friendsIan Lynagh2012-05-151-7/+14
| | | | | | | | | | | | | We were hitting a problem when reading the LANGUAGE/OPTIONS pragmas from GHC.TypeLits, where the buffer ended "{-". The rules for the start-comment lexeme check that "{-" is not followed by "#", but the test returned False when there was no next character. Therefore we were lexing this as as an open-curly lexeme (only consuming the "{", and not reaching the end of the buffer), which meant the options parser think that it had reached the end of the options. Now we correctly lex as "{-".
* Refactor LHsTyVarBndrs to fix Trac #6081Simon Peyton Jones2012-05-113-21/+22
| | | | | | | | | | | | | | | This is really a small change, but it touches a lot of files quite significantly. The real goal is to put the implicitly-bound kind variables of a data/class decl in the right place, namely on the LHsTyVarBndrs type, which now looks like data LHsTyVarBndrs name = HsQTvs { hsq_kvs :: [Name] , hsq_tvs :: [LHsTyVarBndr name] } This little change made the type checker neater in a number of ways, but it was fiddly to push through the changes.
* Tidy up a remaining glitch in unificationSimon Peyton Jones2012-05-011-1/+2
| | | | | | | | | | | | | | | | | | There was one place, in type checking parallel list comprehensions where we were unifying types, but had no convenient way to use the resulting coercion; instead we just checked that it was Refl. This was Wrong Wrong; it might fail unpredicably in a GADT-like situation, and it led to extra error-generation code used only in this one place. This patch tidies it all up, by moving the 'return' method from the *comprehension* to the ParStmtBlock. The latter is a new data type, now used for each sub-chunk of a parallel list comprehension. Because of the data type change, quite a few modules are touched, but only in a fairly trivial way. The real changes are in TcMatches (and corresponding desugaring); plus deleting code from TcUnify. This patch also fixes the pretty-printing bug in Trac #6060
* Move free-var info from InstDecl to FamInstDeclSimon Peyton Jones2012-04-202-9/+9
|
* Do SCC on instance declarations (fixes Trac #5715)Simon Peyton Jones2012-04-202-11/+16
| | | | | | | | | | | | | | | | | | The trouble here is that given {-# LANGUAGE DataKinds, TypeFamilies #-} data instance Foo a = Bar (Bar a) we want to get a sensible message that we can't use the promoted 'Bar' constructor until after its definition; it's a staging error. Bud the staging mechanism that we use for vanilla data declarations don't work here. Solution is to perform strongly-connected component analysis on the instance declarations. But that in turn means that we need to track free-variable information on more HsSyn declarations, which is why so many files are touched. All the changes are boiler-platey except the ones in TcInstDcls.
* Merge branch 'master' of http://darcs.haskell.org//ghcSimon Peyton Jones2012-04-131-0/+3
|\
| * Allow promoted constructors in the typedoc production (#5948)Paolo Capriotti2012-04-061-0/+3
| |
* | Allow kind-variable binders in type signaturesSimon Peyton Jones2012-04-133-68/+4
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is the last major addition to the kind-polymorphism story, by allowing (Trac #5938) type family F a -- F :: forall k. k -> * data T a -- T :: forall k. k -> * type instance F (T (a :: Maybe k)) = Char The new thing is the explicit 'k' in the type signature on 'a', which itself is inside a type pattern for F. Main changes are: * HsTypes.HsBSig now has a *pair* (kvs, tvs) of binders, the kind variables and the type variables * extractHsTyRdrTyVars returns a pair (kvs, tvs) and the function itself has moved from RdrHsSyn to RnTypes * Quite a bit of fiddling with TcHsType.tcHsPatSigType and tcPatSig which have become a bit simpler. I'm still not satisfied though. There's some consequential fiddling in TcRules too. * Removed the unused HsUtils.collectSigTysFromPats There's a consequential wibble to Haddock too
* Support qualified identifiers in quasi-quotes (#5555).Paolo Capriotti2012-04-022-1/+29
|
* Merge with HEADSimon Peyton Jones2012-03-271-14/+2
|\
| * Remove dead codeJose Pedro Magalhaes2012-03-271-12/+1
| | | | | | | | | | RdrHsSyn.extractGenericPatTyVars was a leftover from the old generic classes.
* | Merge branch 'master' of http://darcs.haskell.org//ghcSimon Peyton Jones2012-03-263-19/+84
|\ \ | |/ | | | | | | | | Conflicts: compiler/hsSyn/Convert.lhs compiler/hsSyn/HsDecls.lhs
| * Add -XExplicitNamespaces to enable using 'type' in import/exports.Iavor S. Diatchki2012-03-243-4/+19
| | | | | | | | | | | | | | | | This extension is implied by: * TypeOperators: so that we can import/export things like (+) * TypeFamilies: because associated type synonyms use "type T" to name the associated type in a subordinate list.
| * Merge remote-tracking branch 'origin/master' into type-natsIavor S. Diatchki2012-03-193-10/+11
| |\
| | * Deal with kind variables brought into scope by a kind signatureSimon Peyton Jones2012-03-143-10/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes Trac #5937, where a kind variable is mentioned only in the kind signature of a GADT data SMaybe :: (k -> *) -> Maybe k -> * where ... The main change is that the tcdKindSig field of TyData and TyFamily now has type Maybe (HsBndrSig (LHsKind name)), where the HsBndrSig part deals with the kind variables that the signature may bind. I also removed the now-unused PostTcKind field of UserTyVar and KindedTyVar.
| * | Only parse type literals when using `DataKinds`.Iavor S. Diatchki2012-03-183-2/+22
| | |
| * | Merge remote-tracking branch 'origin/master' into type-natsIavor S. Diatchki2012-03-134-38/+69
| |\ \ | | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: compiler/coreSyn/CoreLint.lhs compiler/deSugar/DsBinds.lhs compiler/hsSyn/HsTypes.lhs compiler/iface/IfaceType.lhs compiler/rename/RnHsSyn.lhs compiler/rename/RnTypes.lhs compiler/stgSyn/StgLint.lhs compiler/typecheck/TcHsType.lhs compiler/utils/ListSetOps.lhs
| * | Merge remote-tracking branch 'origin/master' into type-natsIavor S. Diatchki2012-02-121-17/+22
| |\ \ | | | | | | | | | | | | | | | | Conflicts: compiler/coreSyn/CoreLint.lhs
| * | | Add support for type-level "strings".Iavor S. Diatchki2012-01-242-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These are types that look like "this" and "that". They are of kind `Symbol`, defined in module `GHC.TypeLits`. For each type-level symbol `X`, we have a singleton type, `TSymbol X`. The value of the singleton type can be named with the overloaded constant `tSymbol`. Here is an example: tSymbol :: TSymbol "Hello"
| * | | Merge remote-tracking branch 'origin/master' into type-natsIavor S. Diatchki2012-01-243-66/+47
| |\ \ \ | | | | | | | | | | | | | | | | | | | | Conflicts: compiler/typecheck/TcEvidence.lhs
| * \ \ \ Merge in more HEAD, fix stuff upSimon Peyton Jones2012-01-233-11/+11
| |\ \ \ \
| * | | | | Change -XTypeOperators to treat all type-operators as type-constructors.Iavor S. Diatchki2012-01-082-16/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, only type operators starting with ":" were type constructors, and writing "+" in a type resulted in a type variable. Now, type variables are always ordinary identifiers, and all operators are treated as constructors. One can still write type variables in infix form though, for example, "a `fun` b" is a type expression with 3 type variables: "a", "fun", and "b". Writing (+) in an import/export list always refers to the value (+) and not the type. To refer to the type one can write either "type (+)", or provide an explicit suobrdinate list (e.g., "(+)()"). For clarity, one can also combine the two, for example "type (+)(A,B,C)" is also accepted and means the same thing as "(+)(A,B,C)" (i.e., export the type (+), with the constructors A,B,and C).
| * | | | | Merge branch 'master' into type-natsIavor S. Diatchki2011-12-293-35/+44
| |\ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: compiler/typecheck/TcCanonical.lhs compiler/typecheck/TcSMonad.lhs
| * | | | | | Add numeric types to the parsing part of the front end.Iavor S. Diatchki2011-12-182-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For the moment, the kind of the numerical literals is the type "Word" lifted to the kind level. This should probably be changed in the future.
* | | | | | | Make the 'extract' functions to find free type variablesSimon Peyton Jones2012-03-261-16/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | of an HsType return RdrNames rather than (Located RdrNames). This means less clutter, and the individual locations are a bit arbitrary if a name occurs more than once.
* | | | | | | Refactor HsDecls.TyClDecl to extract the type HsTyDefn, which is theSimon Peyton Jones2012-03-223-122/+113
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | RHS of a data type or type synonym declaration. This can be shared between type declarations and type *instance* declarations.
* | | | | | | Deal with kind variables brought into scope by a kind signatureSimon Peyton Jones2012-03-143-10/+11
| |_|_|_|_|/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes Trac #5937, where a kind variable is mentioned only in the kind signature of a GADT data SMaybe :: (k -> *) -> Maybe k -> * where ... The main change is that the tcdKindSig field of TyData and TyFamily now has type Maybe (HsBndrSig (LHsKind name)), where the HsBndrSig part deals with the kind variables that the signature may bind. I also removed the now-unused PostTcKind field of UserTyVar and KindedTyVar.
* | | | | | Hurrah! This major commit adds support for scoped kind variables,Simon Peyton Jones2012-03-023-6/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | which (finally) fills out the functionality of polymorphic kinds. It also fixes numerous bugs. Main changes are: Renaming stuff ~~~~~~~~~~~~~~ * New type in HsTypes: data HsBndrSig sig = HsBSig sig [Name] which is used for type signatures in patterns, and kind signatures in types. So when you say f (x :: [a]) = x ++ x or data T (f :: k -> *) (x :: *) = MkT (f x) the signatures in both cases are a HsBndrSig. * The [Name] in HsBndrSig records the variables bound by the pattern, that is 'a' in the first example, 'k' in the second, and nothing in the third. The renamer initialises the field. * As a result I was able to get rid of RnHsSyn.extractHsTyNames :: LHsType Name -> NameSet and its friends altogether. Deleted the entire module! This led to some knock-on refactoring; in particular the type renamer now returns the free variables just like the term renamer. Kind-checking types: mainly TcHsType ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A major change is that instead of kind-checking types in two passes, we now do one. Under the old scheme, the first pass did kind-checking and (hackily) annotated the HsType with the inferred kinds; and the second pass desugared the HsType to a Type. But now that we have kind variables inside types, the first pass (TcHsType.tc_hs_type) can go straight to Type, and zonking will squeeze out any kind unification variables later. This is much nicer, but it was much more fiddly than I had expected. The nastiest corner is this: it's very important that tc_hs_type uses lazy constructors to build the returned type. See Note [Zonking inside the knot] in TcHsType. Type-checking type and class declarations: mainly TcTyClsDecls ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I did tons of refactoring in TcTyClsDecls. Simpler and nicer now. Typechecking bindings: mainly TcBinds ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I rejigged (yet again) the handling of type signatures in TcBinds. It's a bit simpler now. The main change is that tcTySigs goes right through to a TcSigInfo in one step; previously it was split into two, part here and part later. Unsafe coercions ~~~~~~~~~~~~~~~~ Usually equality coercions have exactly the same kind on both sides. But we do allow an *unsafe* coercion between Int# and Bool, say, used in case error Bool "flah" of { True -> 3#; False -> 0# } --> (error Bool "flah") |> unsafeCoerce Bool Int# So what is the instantiation of (~#) here? unsafeCoerce Bool Int# :: (~#) ??? Bool Int# I'm using OpenKind here for now, but it's un-satisfying that the lhs and rhs of the ~ don't have precisely the same kind. More minor ~~~~~~~~~~ * HsDecl.TySynonym has its free variables attached, which makes the cycle computation in TcTyDecls.mkSynEdges easier. * Fixed a nasty reversed-comparison bug in FamInstEnv: @@ -490,7 +490,7 @@ lookup_fam_inst_env' match_fun one_sided ie fam tys n_tys = length tys extra_tys = drop arity tys (match_tys, add_extra_tys) - | arity > n_tys = (take arity tys, \res_tys -> res_tys ++ extra_tys) + | arity < n_tys = (take arity tys, \res_tys -> res_tys ++ extra_tys) | otherwise = (tys, \res_tys -> res_tys)
* | | | | | Implement "value" imports with the CAPIIan Lynagh2012-02-262-6/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This allows us to import values (i.e. non-functions) with the CAPI. This means we can access values even if (on some or all platforms) they are simple #defines.
* | | | | | Fix parsing of FFI import declsIan Lynagh2012-02-251-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | We no longer parse "staticfoo" as "static foo".
* | | | | | Remove support for CTYPE pragmas on type synonymsIan Lynagh2012-02-222-16/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's not clear whether it's desirable or not, and it turns out that the way we use coercions in GHC means we tend to lose information about type synonyms.
* | | | | | Small refactoring: Use (Maybe Header) rather than FastStringIan Lynagh2012-02-172-7/+7
| | | | | |
* | | | | | Allow a header to be specified in a CTYPE pragmaIan Lynagh2012-02-171-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | You can now say data {-# CTYPE "some_header.h" "the C type" #-} Foo = ... I think it's rare that this will actually be needed. If the header for a CAPI FFI import includes a void f(ctype x); prototype then ctype must already be defined. However, if the header only has #define f(p) p->j then the type need not be defined. But either way, it seems good practice for us to specify the header that we need.
* | | | | | Fix parsing regression in CTYPE patchIan Lynagh2012-02-161-3/+6
| | | | | |
* | | | | | Implement the CTYPE pragma; part of the CApiFFI extensionIan Lynagh2012-02-163-30/+38
| |_|_|_|/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | For now, the syntax is type {-# CTYPE "some C type" #-} Foo = ... newtype {-# CTYPE "some C type" #-} Foo = ... data {-# CTYPE "some C type" #-} Foo = ...
* | | | | Refactor HsDecls again, to put family instances in InstDeclSimon Peyton Jones2012-02-061-15/+20
| |_|_|/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This continues the clean up of the front end. Since they were first invented, type and data family *instance* decls have been in the TyClDecl data type, even though they always treated separately. This patch takes a step in the right direction * The InstDecl type now includes both class instances and type/data family instances * The hs_tyclds field of HsGroup now never has any family instance declarations in it However a family instance is still a TyClDecl. It should really be a separate type, but that's the next step. All this was provoked by fixing Trac #5792 in the HEAD. (I did a less invasive fix on the branch.)
* | | | Eliminate {| and |} vestiges in lexer/parserSimon Peyton Jones2012-01-172-19/+8
| | | | | | | | | | | | | | | | They weren't being lexed any more, but we still had productions!
* | | | Remove trailing whitespace in compiler/parser/LexCore.hsIan Lynagh2012-01-151-8/+8
| | | |
* | | | remove tabs (+ ignore tabs option) from LexCore.hsNils Schweinsberg2012-01-151-40/+32
| |_|/ |/| |
* | | Implememt -fdefer-type-errors (Trac #5624)Simon Peyton Jones2012-01-121-3/+3
| |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch implements the idea of deferring (most) type errors to runtime, instead emitting only a warning at compile time. The basic idea is very simple: * The on-the-fly unifier in TcUnify never fails; instead if it gets stuck it emits a constraint. * The constraint solver tries to solve the constraints (and is entirely unchanged, hooray). * The remaining, unsolved constraints (if any) are passed to TcErrors.reportUnsolved. With -fdefer-type-errors, instead of emitting an error message, TcErrors emits a warning, AND emits a binding for the constraint witness, binding it to (error "the error message"), via the new form of evidence TcEvidence.EvDelayedError. So, when the program is run, when (and only when) that witness is needed, the program will crash with the exact same error message that would have been given at compile time. Simple really. But, needless to say, the exercise forced me into some major refactoring. * TcErrors is almost entirely rewritten * EvVarX and WantedEvVar have gone away entirely * ErrUtils is changed a bit: * New Severity field in ErrMsg * Renamed the type Message to MsgDoc (this change touches a lot of files trivially) * One minor change is that in the constraint solver we try NOT to combine insoluble constraints, like Int~Bool, else all such type errors get combined together and result in only one error message! * I moved some definitions from TcSMonad to TcRnTypes, where they seem to belong more
* | Use HsTupleTy [] for unit tuples, uniformlySimon Peyton Jones2011-12-232-25/+27
| | | | | | | | | | | | This is just a tidy-up triggered by #5719. We were parsing () as a type constructor, rather than as a HsTupleTy, but it's better dealt with uniformly as the former, I think. Somewhat a matter of taste.
* | Fix the behaviour of the unit unboxed tuple (# #)Simon Peyton Jones2011-12-231-8/+15
| | | | | | | | | | | | | | | | | | See Trac #5720: make the unit unboxed tuple (# #) behave uniformly with the unit boxed tuple () This is actually a change in behaviour, but in a very dark corner, so I don't think this is going to hurt anyone, and the current behaviour is deeply strange.
* | Add a class HasDynFlags(getDynFlags)Ian Lynagh2011-12-191-2/+2
|/ | | | | | | | We no longer have many separate, clashing getDynFlags functions I've given each GhcMonad its own HasDynFlags instance, rather than using UndecidableInstances to make a GhcMonad m => HasDynFlags m instance.
* Allow full constraint solving under a for-all (Trac #5595)Simon Peyton Jones2011-12-052-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The main idea is that when we unify forall a. t1 ~ forall a. t2 we get constraints from unifying t1~t2 that mention a. We are producing a coercion witnessing the equivalence of the for-alls, and inside *that* coercion we need bindings for the solved constraints arising from t1~t2. We didn't have way to do this before. The big change is that here's a new type TcEvidence.TcCoercion, which is much like Coercion.Coercion except that there's a slot for TcEvBinds in it. This has a wave of follow-on changes. Not deep but broad. * New module TcEvidence, which now contains the HsWrapper TcEvBinds, EvTerm etc types that used to be in HsBinds * The typechecker works exclusively in terms of TcCoercion. * The desugarer converts TcCoercion to Coercion * The main payload is in TcUnify.unifySigmaTy. This is the function that had a gross hack before, but is now beautiful. * LCoercion is gone! Hooray. Many many fiddly changes in conssequence. But it's nice.
* Merge branch 'master' of http://darcs.haskell.org/ghcDavid Waern2011-11-292-0/+9
|\
| * Implement a capi calling convention; fixes #2979Ian Lynagh2011-11-282-0/+8
| | | | | | | | | | | | | | | | | | In GHC, this provides an easy way to call a C function via a C wrapper. This is important when the function is really defined by CPP. Requires the new CApiFFI extension. Not documented yet, as it's still an experimental feature at this stage.
| * Allow the quotes to be omitted in {-# SCC "<varid>" #-}Simon Marlow2011-11-281-0/+1
| |
* | Merge branch 'master' of http://darcs.haskell.org/ghcDavid Waern2011-11-263-10/+25
|\ \ | |/
| * Fix newtype wrapper for 'PData[s] (Wrap a)' and fix VECTORISE type and ↵Manuel M T Chakravarty2011-11-251-3/+4
| | | | | | | | | | | | | | | | instance pragmas * Correct usage of new type wrappers from MkId * 'VECTORISE [SCALAR] type T = S' didn't work correctly across module boundaries * Clean up 'VECTORISE SCALAR instance'