diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-02-13 14:54:36 +0100 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-02-13 14:54:50 +0100 |
commit | 0acea3e60e03418dcc0fe6346d8115769a2b4c17 (patch) | |
tree | 556e9e10667bac81560d6e392a4aba55f600b614 /src/LambdaCube | |
parent | a8ece97efac68c03b3eb9c9e962b8a9b1d994519 (diff) |
use different kinf of infos
Diffstat (limited to 'src/LambdaCube')
-rw-r--r-- | src/LambdaCube/Compiler.hs | 6 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Infer.hs | 46 |
2 files changed, 35 insertions, 17 deletions
diff --git a/src/LambdaCube/Compiler.hs b/src/LambdaCube/Compiler.hs index cb93928a..916c57f5 100644 --- a/src/LambdaCube/Compiler.hs +++ b/src/LambdaCube/Compiler.hs | |||
@@ -9,8 +9,7 @@ | |||
9 | module LambdaCube.Compiler | 9 | module LambdaCube.Compiler |
10 | ( Backend(..) | 10 | ( Backend(..) |
11 | , Pipeline | 11 | , Pipeline |
12 | , Infos, listInfos, Range(..) | 12 | , module Infer |
13 | , Exp, outputType, boolType, trueExp | ||
14 | 13 | ||
15 | , MMT, runMMT, mapMMT | 14 | , MMT, runMMT, mapMMT |
16 | , MM, runMM | 15 | , MM, runMM |
@@ -45,7 +44,8 @@ import qualified Data.Text.IO as TIO | |||
45 | 44 | ||
46 | import LambdaCube.IR as IR | 45 | import LambdaCube.IR as IR |
47 | import LambdaCube.Compiler.Pretty hiding ((</>)) | 46 | import LambdaCube.Compiler.Pretty hiding ((</>)) |
48 | import LambdaCube.Compiler.Infer (Infos, listInfos, PolyEnv(..), Export(..), Module(..), showError, parseLC, joinPolyEnvs, filterPolyEnv, inference_, ImportItems (..), Range(..), Exp, outputType, boolType, trueExp) | 47 | import LambdaCube.Compiler.Infer (PolyEnv(..), Export(..), Module(..), showError, parseLC, joinPolyEnvs, filterPolyEnv, inference_, ImportItems (..)) |
48 | import LambdaCube.Compiler.Infer as Infer (Infos, listAllInfos, listTypeInfos, Range(..), Exp, outputType, boolType, trueExp) | ||
49 | import LambdaCube.Compiler.CoreToIR | 49 | import LambdaCube.Compiler.CoreToIR |
50 | 50 | ||
51 | -- inlcude path for: Builtins, Internals and Prelude | 51 | -- inlcude path for: Builtins, Internals and Prelude |
diff --git a/src/LambdaCube/Compiler/Infer.hs b/src/LambdaCube/Compiler/Infer.hs index 3a2bbe77..72a41786 100644 --- a/src/LambdaCube/Compiler/Infer.hs +++ b/src/LambdaCube/Compiler/Infer.hs | |||
@@ -23,15 +23,17 @@ module LambdaCube.Compiler.Infer | |||
23 | , down, Subst (..), free | 23 | , down, Subst (..), free |
24 | , litType | 24 | , litType |
25 | , initEnv, Env(..), pattern EBind2 | 25 | , initEnv, Env(..), pattern EBind2 |
26 | , Infos(..), listInfos, PolyEnv(..), parseLC, joinPolyEnvs, filterPolyEnv, inference_ | 26 | , Info(..), Infos, listAllInfos, listTypeInfos, PolyEnv(..), parseLC, joinPolyEnvs, filterPolyEnv, inference_ |
27 | , ImportItems (..) | 27 | , ImportItems (..) |
28 | , SI(..), Range(..) | 28 | , SI(..), Range(..) |
29 | , nType, conType, neutType, neutType', appTy, mkConPars, makeCaseFunPars, makeCaseFunPars' | 29 | , nType, conType, neutType, neutType', appTy, mkConPars, makeCaseFunPars, makeCaseFunPars' |
30 | , MaxDB(..), unfixlabel | 30 | , MaxDB(..), unfixlabel |
31 | , ErrorMsg, showError | 31 | , ErrorMsg, showError |
32 | ) where | 32 | ) where |
33 | |||
33 | import Data.Monoid | 34 | import Data.Monoid |
34 | import Data.Maybe | 35 | import Data.Maybe |
36 | import Data.List | ||
35 | import qualified Data.Set as Set | 37 | import qualified Data.Set as Set |
36 | import qualified Data.Map as Map | 38 | import qualified Data.Map as Map |
37 | 39 | ||
@@ -1108,17 +1110,34 @@ extractDesugarInfo ge = | |||
1108 | 1110 | ||
1109 | -------------------------------------------------------------------------------- infos | 1111 | -------------------------------------------------------------------------------- infos |
1110 | 1112 | ||
1111 | newtype Infos = Infos (Map.Map Range (Set.Set String)) | 1113 | data Info |
1112 | deriving (NFData) | 1114 | = Info Range String |
1115 | | IType String String | ||
1116 | deriving (Eq, Ord) | ||
1117 | |||
1118 | instance NFData Info | ||
1119 | where | ||
1120 | rnf = \case | ||
1121 | Info r s -> rnf (r, s) | ||
1122 | IType a b -> rnf (a, b) | ||
1123 | |||
1124 | instance Show Info where | ||
1125 | show = \case | ||
1126 | Info r s -> ppShow r ++ " " ++ s | ||
1127 | IType a b -> a ++ " :: " ++ b | ||
1113 | 1128 | ||
1114 | instance Monoid Infos where | 1129 | type Infos = [Info] |
1115 | mempty = Infos mempty | ||
1116 | Infos x `mappend` Infos y = Infos $ Map.unionWith mappend x y | ||
1117 | 1130 | ||
1118 | mkInfoItem (RangeSI r) i = Infos $ Map.singleton r $ Set.singleton i | 1131 | mkInfoItem (RangeSI r) i = [Info r i] |
1119 | mkInfoItem _ _ = mempty | 1132 | mkInfoItem _ _ = mempty |
1120 | 1133 | ||
1121 | listInfos (Infos m) = [(r, Set.toList i) | (r, i) <- Map.toList m] | 1134 | listAllInfos m = h "items" [show i | i@IType{} <- m] |
1135 | ++ h "tooltips" [ ppShow r ++ " " ++ intercalate " | " is | (r, is) <- listTypeInfos m ] | ||
1136 | where | ||
1137 | h x [] = [] | ||
1138 | h x xs = ("------------ " ++ x) : xs | ||
1139 | |||
1140 | listTypeInfos m = map (second Set.toList) $ Map.toList $ Map.unionsWith (<>) [Map.singleton r $ Set.singleton i | Info r i <- m] | ||
1122 | 1141 | ||
1123 | -------------------------------------------------------------------------------- inference for statements | 1142 | -------------------------------------------------------------------------------- inference for statements |
1124 | 1143 | ||
@@ -1126,13 +1145,13 @@ handleStmt :: MonadFix m => [Stmt] -> Stmt -> IM m GlobalEnv | |||
1126 | handleStmt defs = \case | 1145 | handleStmt defs = \case |
1127 | Primitive n mf (trSExp' -> t_) -> do | 1146 | Primitive n mf (trSExp' -> t_) -> do |
1128 | t <- inferType tr =<< ($ t_) <$> addF | 1147 | t <- inferType tr =<< ($ t_) <$> addF |
1129 | tellStmtType (fst n) t | 1148 | tellType (fst n) t |
1130 | addToEnv n mf $ flip (,) t $ lamify t $ DFun (FunName (snd n) t) | 1149 | addToEnv n mf $ flip (,) t $ lamify t $ DFun (FunName (snd n) t) |
1131 | Let n mf mt t_ -> do | 1150 | Let n mf mt t_ -> do |
1132 | af <- addF | 1151 | af <- addF |
1133 | let t__ = maybe id (flip SAnn . af) mt t_ | 1152 | let t__ = maybe id (flip SAnn . af) mt t_ |
1134 | (x, t) <- inferTerm (snd n) tr $ trSExp' $ if usedS n t__ then SBuiltin "primFix" `SAppV` SLamV (substSG0 n t__) else t__ | 1153 | (x, t) <- inferTerm (snd n) tr $ trSExp' $ if usedS n t__ then SBuiltin "primFix" `SAppV` SLamV (substSG0 n t__) else t__ |
1135 | tellStmtType (fst n) t | 1154 | tellType (fst n) t |
1136 | addToEnv n mf (mkELet (True, n) x t, t) | 1155 | addToEnv n mf (mkELet (True, n) x t, t) |
1137 | {- -- hack | 1156 | {- -- hack |
1138 | when (snd (getParams t) == TType) $ do | 1157 | when (snd (getParams t) == TType) $ do |
@@ -1148,7 +1167,7 @@ handleStmt defs = \case | |||
1148 | Data s (map (second trSExp') -> ps) (trSExp' -> t_) addfa (map (second trSExp') -> cs) -> do | 1167 | Data s (map (second trSExp') -> ps) (trSExp' -> t_) addfa (map (second trSExp') -> cs) -> do |
1149 | af <- if addfa then asks $ \(exs, ge) -> addForalls exs . (snd s:) . defined' $ ge else return id | 1168 | af <- if addfa then asks $ \(exs, ge) -> addForalls exs . (snd s:) . defined' $ ge else return id |
1150 | vty <- inferType tr $ addParamsS ps t_ | 1169 | vty <- inferType tr $ addParamsS ps t_ |
1151 | tellStmtType (fst s) vty | 1170 | tellType (fst s) vty |
1152 | let | 1171 | let |
1153 | pnum' = length $ filter ((== Visible) . fst) ps | 1172 | pnum' = length $ filter ((== Visible) . fst) ps |
1154 | inum = arity vty - length ps | 1173 | inum = arity vty - length ps |
@@ -1157,7 +1176,7 @@ handleStmt defs = \case | |||
1157 | | c == SGlobal s && take pnum' xs == downToS "a3" (length . fst . getParamsS $ ct) pnum' | 1176 | | c == SGlobal s && take pnum' xs == downToS "a3" (length . fst . getParamsS $ ct) pnum' |
1158 | = do | 1177 | = do |
1159 | cty <- removeHiddenUnit <$> inferType tr (addParamsS [(Hidden, x) | (Visible, x) <- ps] ct) | 1178 | cty <- removeHiddenUnit <$> inferType tr (addParamsS [(Hidden, x) | (Visible, x) <- ps] ct) |
1160 | tellStmtType (fst cn) cty | 1179 | tellType (fst cn) cty |
1161 | let pars = zipWith (\x -> second $ STyped (debugSI "mkConstr1") . flip (,) TType . up_ (1+j) x) [0..] $ drop (length ps) $ fst $ getParams cty | 1180 | let pars = zipWith (\x -> second $ STyped (debugSI "mkConstr1") . flip (,) TType . up_ (1+j) x) [0..] $ drop (length ps) $ fst $ getParams cty |
1162 | act = length . fst . getParams $ cty | 1181 | act = length . fst . getParams $ cty |
1163 | acts = map fst . fst . getParams $ cty | 1182 | acts = map fst . fst . getParams $ cty |
@@ -1252,7 +1271,7 @@ addToEnv :: Monad m => SIName -> MFixity -> ExpType -> IM m GlobalEnv | |||
1252 | addToEnv (si, s) mf (x, t) = do | 1271 | addToEnv (si, s) mf (x, t) = do |
1253 | -- maybe (pure ()) throwError_ $ ambiguityCheck s t -- TODO | 1272 | -- maybe (pure ()) throwError_ $ ambiguityCheck s t -- TODO |
1254 | exs <- asks fst | 1273 | exs <- asks fst |
1255 | when (trLight exs) $ mtrace (s ++ " :: " ++ ppShow t) | 1274 | when (trLight exs) $ tell [IType s $ ppShow t] |
1256 | v <- asks $ Map.lookup s . snd | 1275 | v <- asks $ Map.lookup s . snd |
1257 | case v of | 1276 | case v of |
1258 | Nothing -> return $ Map.singleton s (closedExp x, closedExp t, (si, mf)) | 1277 | Nothing -> return $ Map.singleton s (closedExp x, closedExp t, (si, mf)) |
@@ -1269,7 +1288,6 @@ defined' = Map.keys | |||
1269 | addF = asks $ \(exs, ge) -> addForalls exs $ defined' ge | 1288 | addF = asks $ \(exs, ge) -> addForalls exs $ defined' ge |
1270 | 1289 | ||
1271 | tellType si t = tell $ mkInfoItem (sourceInfo si) $ removeEscs $ showDoc $ mkDoc True (t, TType) | 1290 | tellType si t = tell $ mkInfoItem (sourceInfo si) $ removeEscs $ showDoc $ mkDoc True (t, TType) |
1272 | tellStmtType si t = tellType si t | ||
1273 | 1291 | ||
1274 | 1292 | ||
1275 | -------------------------------------------------------------------------------- inference output | 1293 | -------------------------------------------------------------------------------- inference output |