summaryrefslogtreecommitdiff
path: root/compiler/typecheck/Inst.hs
diff options
context:
space:
mode:
authorAlan Zimmerman <alan.zimm@gmail.com>2017-05-19 14:56:09 +0200
committerAlan Zimmerman <alan.zimm@gmail.com>2017-06-06 00:16:20 +0200
commit8e6ec0fa7431b0454b09c0011a615f0845df1198 (patch)
treed6b3604e0ceac3d81d0510669f7ccce9a2bf3ae2 /compiler/typecheck/Inst.hs
parentc9eb4385aad248118650725b7b699bb97ee21c0d (diff)
downloadhaskell-8e6ec0fa7431b0454b09c0011a615f0845df1198.tar.gz
Udate hsSyn AST to use Trees that Grow
Summary: See https://ghc.haskell.org/trac/ghc/wiki/ImplementingTreesThatGrow This commit prepares the ground for a full extensible AST, by replacing the type parameter for the hsSyn data types with a set of indices into type families, data GhcPs -- ^ Index for GHC parser output data GhcRn -- ^ Index for GHC renamer output data GhcTc -- ^ Index for GHC typechecker output These are now used instead of `RdrName`, `Name` and `Id`/`TcId`/`Var` Where the original name type is required in a polymorphic context, this is accessible via the IdP type family, defined as type family IdP p type instance IdP GhcPs = RdrName type instance IdP GhcRn = Name type instance IdP GhcTc = Id These types are declared in the new 'hsSyn/HsExtension.hs' module. To gain a better understanding of the extension mechanism, it has been applied to `HsLit` only, also replacing the `SourceText` fields in them with extension types. To preserve extension generality, a type class is introduced to capture the `SourceText` interface, which must be honoured by all of the extension points which originally had a `SourceText`. The class is defined as class HasSourceText a where -- Provide setters to mimic existing constructors noSourceText :: a sourceText :: String -> a setSourceText :: SourceText -> a getSourceText :: a -> SourceText And the constraint is captured in `SourceTextX`, which is a constraint type listing all the extension points that make use of the class. Updating Haddock submodule to match. Test Plan: ./validate Reviewers: simonpj, shayan-najd, goldfire, austin, bgamari Subscribers: rwbarton, thomie, mpickering Differential Revision: https://phabricator.haskell.org/D3609
Diffstat (limited to 'compiler/typecheck/Inst.hs')
-rw-r--r--compiler/typecheck/Inst.hs29
1 files changed, 16 insertions, 13 deletions
diff --git a/compiler/typecheck/Inst.hs b/compiler/typecheck/Inst.hs
index a83bbae36f..cad7793f51 100644
--- a/compiler/typecheck/Inst.hs
+++ b/compiler/typecheck/Inst.hs
@@ -7,6 +7,7 @@ The @Inst@ type: dictionaries or method instances
-}
{-# LANGUAGE CPP, MultiWayIf, TupleSections #-}
+{-# LANGUAGE FlexibleContexts #-}
module Inst (
deeplySkolemise,
@@ -75,7 +76,7 @@ import Control.Monad( unless )
************************************************************************
-}
-newMethodFromName :: CtOrigin -> Name -> TcRhoType -> TcM (HsExpr TcId)
+newMethodFromName :: CtOrigin -> Name -> TcRhoType -> TcM (HsExpr GhcTcId)
-- Used when Name is the wired-in name for a wired-in class method,
-- so the caller knows its type for sure, which should be of form
-- forall a. C a => <blah>
@@ -500,9 +501,9 @@ cases (the rest are caught in lookupInst).
-}
-newOverloadedLit :: HsOverLit Name
+newOverloadedLit :: HsOverLit GhcRn
-> ExpRhoType
- -> TcM (HsOverLit TcId)
+ -> TcM (HsOverLit GhcTcId)
newOverloadedLit
lit@(OverLit { ol_val = val, ol_rebindable = rebindable }) res_ty
| not rebindable
@@ -528,9 +529,9 @@ newOverloadedLit
-- Does not handle things that 'shortCutLit' can handle. See also
-- newOverloadedLit in TcUnify
newNonTrivialOverloadedLit :: CtOrigin
- -> HsOverLit Name
+ -> HsOverLit GhcRn
-> ExpRhoType
- -> TcM (HsOverLit TcId)
+ -> TcM (HsOverLit GhcTcId)
newNonTrivialOverloadedLit orig
lit@(OverLit { ol_val = val, ol_witness = HsVar (L _ meth_name)
, ol_rebindable = rebindable }) res_ty
@@ -548,16 +549,17 @@ newNonTrivialOverloadedLit _ lit _
= pprPanic "newNonTrivialOverloadedLit" (ppr lit)
------------
-mkOverLit :: OverLitVal -> TcM HsLit
+mkOverLit ::(HasDefaultX p, SourceTextX p) => OverLitVal -> TcM (HsLit p)
mkOverLit (HsIntegral i)
= do { integer_ty <- tcMetaTy integerTyConName
- ; return (HsInteger (il_text i) (il_value i) integer_ty) }
+ ; return (HsInteger (setSourceText $ il_text i)
+ (il_value i) integer_ty) }
mkOverLit (HsFractional r)
= do { rat_ty <- tcMetaTy rationalTyConName
- ; return (HsRat r rat_ty) }
+ ; return (HsRat def r rat_ty) }
-mkOverLit (HsIsString src s) = return (HsString src s)
+mkOverLit (HsIsString src s) = return (HsString (setSourceText src) s)
{-
************************************************************************
@@ -592,9 +594,10 @@ just use the expression inline.
-}
tcSyntaxName :: CtOrigin
- -> TcType -- Type to instantiate it at
- -> (Name, HsExpr Name) -- (Standard name, user name)
- -> TcM (Name, HsExpr TcId) -- (Standard name, suitable expression)
+ -> TcType -- ^ Type to instantiate it at
+ -> (Name, HsExpr GhcRn) -- ^ (Standard name, user name)
+ -> TcM (Name, HsExpr GhcTcId)
+ -- ^ (Standard name, suitable expression)
-- USED ONLY FOR CmdTop (sigh) ***
-- See Note [CmdSyntaxTable] in HsExpr
@@ -621,7 +624,7 @@ tcSyntaxName orig ty (std_nm, user_nm_expr) = do
expr <- tcPolyExpr (L span user_nm_expr) sigma1
return (std_nm, unLoc expr)
-syntaxNameCtxt :: HsExpr Name -> CtOrigin -> Type -> TidyEnv
+syntaxNameCtxt :: HsExpr GhcRn -> CtOrigin -> Type -> TidyEnv
-> TcRn (TidyEnv, SDoc)
syntaxNameCtxt name orig ty tidy_env
= do { inst_loc <- getCtLocM orig (Just TypeLevel)