@@ -480,7 +480,6 @@ scope :: PathElement v loc -> M v loc a -> M v loc a
480
480
scope p (MT m) = MT \ ppe pmcSwitch datas effects env -> mapErrors (scope' p) (m ppe pmcSwitch datas effects env)
481
481
482
482
newtype Context v loc = Context [(Element v loc , Info v loc )]
483
- deriving stock (Show )
484
483
485
484
data Info v loc = Info
486
485
{ existentialVars :: Set v , -- set of existentials seen so far
@@ -489,7 +488,6 @@ data Info v loc = Info
489
488
termVarAnnotations :: Map v (Type v loc ),
490
489
allVars :: Set v -- all variables seen so far
491
490
}
492
- deriving stock (Show )
493
491
494
492
-- | The empty context
495
493
context0 :: Context v loc
@@ -1083,43 +1081,35 @@ generalizeExistentials' t =
1083
1081
isExistential TypeVar. Existential {} = True
1084
1082
isExistential _ = False
1085
1083
1086
- noteBindingType ::
1087
- forall v loc .
1084
+ noteTopLevelType ::
1088
1085
(Ord loc , Var v ) =>
1089
- Term. IsTop ->
1090
- loc ->
1091
- v ->
1086
+ ABT. Subst f v a ->
1092
1087
Term v loc ->
1093
1088
Type v loc ->
1094
1089
M v loc ()
1095
- noteBindingType top _span v binding typ = case binding of
1090
+ noteTopLevelType e binding typ = case binding of
1096
1091
Term. Ann' strippedBinding _ -> do
1097
1092
inferred <- (Just <$> synthesizeTop strippedBinding) `orElse` pure Nothing
1098
1093
case inferred of
1099
1094
Nothing -> do
1100
- let v = Var. reset v
1101
- let t = generalizeAndUnTypeVar typ
1102
- let redundant = False
1103
- note [(v, t, redundant)]
1095
+ btw $
1096
+ topLevelComponent
1097
+ [(Var. reset (ABT. variable e), generalizeAndUnTypeVar typ, False )]
1104
1098
Just inferred -> do
1105
1099
redundant <- isRedundant typ inferred
1106
- note [(Var. reset v, generalizeAndUnTypeVar typ, redundant)]
1100
+ btw $
1101
+ topLevelComponent
1102
+ [(Var. reset (ABT. variable e), generalizeAndUnTypeVar typ, redundant)]
1107
1103
-- The signature didn't exist, so was definitely redundant
1108
- _ ->
1109
- note
1110
- [(Var. reset v, generalizeAndUnTypeVar typ, True )]
1111
- where
1112
- note :: (Var v ) => [(v , Type. Type v loc , RedundantTypeAnnotation )] -> M v loc ()
1113
- note comps = do
1114
- -- Also note top-level components as standard let bindings for the LSP
1115
- -- for_ comps \(v, t, _r) -> noteVarBinding v span t
1116
- when top (btw $ topLevelComponent comps)
1117
-
1104
+ _ -> do
1105
+ btw $
1106
+ topLevelComponent
1107
+ [(Var. reset (ABT. variable e), generalizeAndUnTypeVar typ, True )]
1118
1108
-- | Take note of the types and locations of all bindings, including let bindings, letrec
1119
1109
-- bindings, lambda argument bindings and top-level bindings.
1120
1110
-- This information is used to provide information to the LSP after typechecking.
1121
- _noteVarBinding :: (Var v ) => v -> loc -> Type. Type v loc -> M v loc ()
1122
- _noteVarBinding _v _span _t = pure () -- btw $ VarBinding v span t
1111
+ noteVarBinding :: (Var v ) => v -> loc -> Type. Type v loc -> M v loc ()
1112
+ noteVarBinding v span t = btw $ VarBinding v span t
1123
1113
1124
1114
synthesizeTop ::
1125
1115
(Var v ) =>
@@ -1237,7 +1227,8 @@ synthesizeWanted abt@(Term.Let1Top' top binding e) = do
1237
1227
appendContext [Ann v' tbinding]
1238
1228
(t, w) <- synthesize (ABT. bindInheritAnnotation e (Term. var () v'))
1239
1229
t <- applyM t
1240
- noteBindingType top (ABT. annotation abt) (ABT. variable e) binding tbinding
1230
+ when top $ noteTopLevelType e binding tbinding
1231
+ noteVarBinding (ABT. variable e) (ABT. annotation abt) (TypeVar. lowerType tbinding)
1241
1232
want <- coalesceWanted w wb
1242
1233
-- doRetract $ Ann v' tbinding
1243
1234
pure (t, want)
@@ -1334,7 +1325,6 @@ synthesizeWanted e
1334
1325
let it = existential' l B. Blank i
1335
1326
ot = existential' l B. Blank o
1336
1327
et = existential' l B. Blank e
1337
-
1338
1328
appendContext $
1339
1329
[existential i, existential e, existential o, Ann arg it]
1340
1330
when (Var. typeOf i == Var. Delay ) $ do
@@ -1348,9 +1338,8 @@ synthesizeWanted e
1348
1338
ctx <- getContext
1349
1339
let t = apply ctx $ Type. arrow l it (Type. effect l [et] ot)
1350
1340
1351
- -- TODO revive
1352
- -- let solvedInputType = fromMaybe it . fmap Type.getPolytype $ Map.lookup i . solvedExistentials . info $ ctx
1353
- -- noteVarBinding i l (TypeVar.lowerType $ solvedInputType)
1341
+ let solvedInputType = fromMaybe it . fmap Type. getPolytype $ Map. lookup i . solvedExistentials . info $ ctx
1342
+ noteVarBinding i l (TypeVar. lowerType $ solvedInputType)
1354
1343
pure (t, [] )
1355
1344
| Term. If' cond t f <- e = do
1356
1345
cwant <- scope InIfCond $ check cond (Type. boolean l)
@@ -1853,7 +1842,7 @@ annotateLetRecBindings ::
1853
1842
Term. IsTop ->
1854
1843
((v -> M v loc v ) -> M v loc ([(v , Term v loc )], Term v loc )) ->
1855
1844
M v loc (Term v loc )
1856
- annotateLetRecBindings _span isTop letrec =
1845
+ annotateLetRecBindings span isTop letrec =
1857
1846
-- If this is a top-level letrec, then emit a TopLevelComponent note,
1858
1847
-- which asks if the user-provided type annotations were needed.
1859
1848
if isTop
@@ -1878,9 +1867,8 @@ annotateLetRecBindings _span isTop letrec =
1878
1867
topLevelComponent ((\ (v, b) -> (Var. reset v, b, False )) . unTypeVar <$> vts)
1879
1868
pure body
1880
1869
else do -- If this isn't a top-level letrec, then we don't have to do anything special
1881
- (body, _vts) <- annotateLetRecBindings' True
1882
- -- TODO revive
1883
- -- for_ vts \(v, t) -> noteVarBinding v span (TypeVar.lowerType t)
1870
+ (body, vts) <- annotateLetRecBindings' True
1871
+ for_ vts \ (v, t) -> noteVarBinding v span (TypeVar. lowerType t)
1884
1872
pure body
1885
1873
where
1886
1874
annotateLetRecBindings' useUserAnnotations = do
@@ -1906,8 +1894,7 @@ annotateLetRecBindings _span isTop letrec =
1906
1894
-- Anything else, just make up a fresh existential
1907
1895
-- which will be refined during typechecking of the binding
1908
1896
vt <- extendExistential v
1909
- let typ = existential' (loc binding) B. Blank vt
1910
- pure $ (e, typ)
1897
+ pure $ (e, existential' (loc binding) B. Blank vt)
1911
1898
(bindings, bindingTypes) <- unzip <$> traverse f bindings
1912
1899
appendContext (zipWith Ann vs bindingTypes)
1913
1900
-- check each `bi` against its type
@@ -1925,8 +1912,9 @@ annotateLetRecBindings _span isTop letrec =
1925
1912
gen bindingType _arity = generalizeExistentials ctx2 bindingType
1926
1913
bindingTypesGeneralized = zipWith gen bindingTypes bindingArities
1927
1914
annotations = zipWith Ann vs bindingTypesGeneralized
1928
- -- for_ (zip3 vs bindings bindingTypesGeneralized) \(v, b, t) -> do
1929
- -- noteVarBinding v (loc b) (TypeVar.lowerType t)
1915
+ -- TODO: is this right?
1916
+ for_ (zip3 vs bindings bindingTypesGeneralized) \ (v, b, t) -> do
1917
+ noteVarBinding v (loc b) (TypeVar. lowerType t)
1930
1918
appendContext annotations
1931
1919
pure (body, vs `zip` bindingTypesGeneralized)
1932
1920
@@ -2230,7 +2218,7 @@ coalesceWanted' keep ((loc, n) : new) old
2230
2218
if keep u
2231
2219
then pure (new, (loc, n) : old)
2232
2220
else do
2233
- defaultAbility n
2221
+ _ <- defaultAbility n
2234
2222
pure (new, old)
2235
2223
coalesceWanted new old
2236
2224
| otherwise = coalesceWanted' keep new ((loc, n) : old)
@@ -2465,7 +2453,7 @@ checkWanted want (Term.Lam' body) (Type.Arrow'' i es o) = do
2465
2453
body <- pure $ ABT. bindInheritAnnotation body (Term. var () x)
2466
2454
checkWithAbilities es body o
2467
2455
pure want
2468
- checkWanted want _abt @ (Term. Let1Top' top binding m) t = do
2456
+ checkWanted want abt @ (Term. Let1Top' top binding m) t = do
2469
2457
(tbinding, wbinding) <- synthesizeBinding top binding
2470
2458
want <- coalesceWanted wbinding want
2471
2459
v <- ABT. freshen m freshenVar
@@ -2474,8 +2462,7 @@ checkWanted want _abt@(Term.Let1Top' top binding m) t = do
2474
2462
-- enforce that actions in a block have type ()
2475
2463
subtype tbinding (DDB. unitType (ABT. annotation binding))
2476
2464
extendContext (Ann v tbinding)
2477
- -- TODO revive
2478
- -- noteVarBinding v (ABT.annotation abt) (TypeVar.lowerType tbinding)
2465
+ noteVarBinding v (ABT. annotation abt) (TypeVar. lowerType tbinding)
2479
2466
checkWanted want (ABT. bindInheritAnnotation m (Term. var () v)) t
2480
2467
checkWanted want (Term. LetRecNamed' [] m) t =
2481
2468
checkWanted want m t
@@ -3414,15 +3401,15 @@ instance (Var v) => Show (Element v loc) where
3414
3401
++ TP. prettyStr Nothing PPE. empty t
3415
3402
show (Marker v) = " |" ++ Text. unpack (Var. name v) ++ " |"
3416
3403
3417
- -- instance (Ord loc, Var v) => Show (Context v loc) where
3418
- -- show ctx@(Context es) = "Γ\n " ++ (intercalate "\n " . map (showElem ctx . fst)) (reverse es)
3419
- -- where
3420
- -- showElem _ctx (Var v) = case v of
3421
- -- TypeVar.Universal x -> "@" <> show x
3422
- -- e -> show e
3423
- -- showElem ctx (Solved _ v (Type.Monotype t)) = "'" ++ Text.unpack (Var.name v) ++ " = " ++ TP.prettyStr Nothing PPE.empty (apply ctx t)
3424
- -- showElem ctx (Ann v t) = Text.unpack (Var.name v) ++ " : " ++ TP.prettyStr Nothing PPE.empty (apply ctx t)
3425
- -- showElem _ (Marker v) = "|" ++ Text.unpack (Var.name v) ++ "|"
3404
+ instance (Ord loc , Var v ) => Show (Context v loc ) where
3405
+ show ctx@ (Context es) = " Γ\n " ++ (intercalate " \n " . map (showElem ctx . fst )) (reverse es)
3406
+ where
3407
+ showElem _ctx (Var v) = case v of
3408
+ TypeVar. Universal x -> " @" <> show x
3409
+ e -> show e
3410
+ showElem ctx (Solved _ v (Type. Monotype t)) = " '" ++ Text. unpack (Var. name v) ++ " = " ++ TP. prettyStr Nothing PPE. empty (apply ctx t)
3411
+ showElem ctx (Ann v t) = Text. unpack (Var. name v) ++ " : " ++ TP. prettyStr Nothing PPE. empty (apply ctx t)
3412
+ showElem _ (Marker v) = " |" ++ Text. unpack (Var. name v) ++ " |"
3426
3413
3427
3414
instance (Monad f ) => Monad (MT v loc f ) where
3428
3415
return = pure
0 commit comments