@@ -86,7 +86,7 @@ check ctxt env tm
86 = evalStateT (check' True [] ctxt env tm) (0, [])
86 = evalStateT (check' True [] ctxt env tm) (0, [])
88check' :: Bool -> String -> Context -> Env -> Raw -> StateT UCs TC (Term, Type)
88check' :: Bool -> String -> Context -> Env -> Raw -> StateT UCs TC (Term, Type)
89−check' holes tcns ctxt env top = chk (TType (UVar tcns (-5))) env top where
89+check' holes tcns ctxt env top = chk (TType (UVar tcns (-5))) Nothing env top where
91 smaller (UType NullType) _ = UType NullType
91 smaller (UType NullType) _ = UType NullType
92 smaller _ (UType NullType) = UType NullType
92 smaller _ (UType NullType) = UType NullType
@@ -98,8 +98,9 @@ check' holes tcns ctxt env top = chk (TType (UVar tcns (-5))) env top where
98 | otherwise = Complete
98 | otherwise = Complete
100 chk :: Type -> -- uniqueness level
100 chk :: Type -> -- uniqueness level
101+ Maybe UExp -> -- universe for kind
101 Env -> Raw -> StateT UCs TC (Term, Type)
102 Env -> Raw -> StateT UCs TC (Term, Type)
102− chk u env (Var n)
103+ chk u lvl env (Var n)
103 | Just (i, ty) <- lookupTyEnv n env = return (P Bound n ty, ty)
104 | Just (i, ty) <- lookupTyEnv n env = return (P Bound n ty, ty)
104 -- If we're elaborating, we don't want the private names; if we're
105 -- If we're elaborating, we don't want the private names; if we're
105 -- checking an already elaborated term, we do
106 -- checking an already elaborated term, we do
@@ -109,9 +110,9 @@ check' holes tcns ctxt env top = chk (TType (UVar tcns (-5))) env top where
109 | [P nt n' ty] <- lookupP_all (not holes) True n ctxt
110 | [P nt n' ty] <- lookupP_all (not holes) True n ctxt
110 = return (P nt n' ty, ty)
111 = return (P nt n' ty, ty)
111 | otherwise = do lift $ tfail $ NoSuchVariable n
112 | otherwise = do lift $ tfail $ NoSuchVariable n
112− chk u env ap@(RApp f RType) | not holes
113+ chk u lvl env ap@(RApp f RType) | not holes
113 -- special case to reduce constraintss
114 -- special case to reduce constraintss
114− = do (fv, fty) <- chk u env f
115+ = do (fv, fty) <- chk u Nothing env f
115 let fty' = case uniqueBinders (map fst env) (finalise fty) of
116 let fty' = case uniqueBinders (map fst env) (finalise fty) of
116 ty@(Bind x (Pi i s k) t) -> ty
117 ty@(Bind x (Pi i s k) t) -> ty
117 _ -> uniqueBinders (map fst env)
118 _ -> uniqueBinders (map fst env)
@@ -126,21 +127,21 @@ check' holes tcns ctxt env top = chk (TType (UVar tcns (-5))) env top where
126 (Bind x (Let (TType v') (TType (UVar tcns v))) t)
127 (Bind x (Let (TType v') (TType (UVar tcns v))) t)
127 return (App Complete fv (TType (UVar tcns v)), apty)
128 return (App Complete fv (TType (UVar tcns v)), apty)
128 Bind x (Pi i s k) t ->
129 Bind x (Pi i s k) t ->
129− do (av, aty) <- chk u env RType
130+ do (av, aty) <- chk u Nothing env RType
130 convertsC ctxt env aty s
131 convertsC ctxt env aty s
131 let apty = simplify initContext env
132 let apty = simplify initContext env
132 (Bind x (Let aty av) t)
133 (Bind x (Let aty av) t)
133 return (App astate fv av, apty)
134 return (App astate fv av, apty)
134 t -> lift $ tfail $ NonFunctionType fv fty
135 t -> lift $ tfail $ NonFunctionType fv fty
135− chk u env ap@(RApp f a)
136+ chk u lvl env ap@(RApp f a)
136− = do (fv, fty) <- chk u env f
137+ = do (fv, fty) <- chk u Nothing env f
137 let fty' = case uniqueBinders (map fst env) (finalise fty) of
138 let fty' = case uniqueBinders (map fst env) (finalise fty) of
138 ty@(Bind x (Pi i s k) t) -> ty
139 ty@(Bind x (Pi i s k) t) -> ty
139 _ -> uniqueBinders (map fst env)
140 _ -> uniqueBinders (map fst env)
140 $ case hnf ctxt env fty of
141 $ case hnf ctxt env fty of
141 ty@(Bind x (Pi i s k) t) -> ty
142 ty@(Bind x (Pi i s k) t) -> ty
142 _ -> normalise ctxt env fty
143 _ -> normalise ctxt env fty
143− (av, aty) <- chk u env a
144+ (av, aty) <- chk u Nothing env a
144 case fty' of
145 case fty' of
145 Bind x (Pi i s k) t ->
146 Bind x (Pi i s k) t ->
146 do convertsC ctxt env aty s
147 do convertsC ctxt env aty s
@@ -148,13 +149,13 @@ check' holes tcns ctxt env top = chk (TType (UVar tcns (-5))) env top where
148 (Bind x (Let aty av) t)
149 (Bind x (Let aty av) t)
149 return (App astate fv av, apty)
150 return (App astate fv av, apty)
150 t -> lift $ tfail $ NonFunctionType fv fty
151 t -> lift $ tfail $ NonFunctionType fv fty
151− chk u env RType
152+ chk u lvl env RType
152 | holes = return (TType (UVal 0), TType (UVal 0))
153 | holes = return (TType (UVal 0), TType (UVal 0))
153 | otherwise = do (v, cs) <- get
154 | otherwise = do (v, cs) <- get
154 let c = ULT (UVar tcns v) (UVar tcns (v+1))
155 let c = ULT (UVar tcns v) (UVar tcns (v+1))
155 put (v+2, (c:cs))
156 put (v+2, (c:cs))
156 return (TType (UVar tcns v), TType (UVar tcns (v+1)))
157 return (TType (UVar tcns v), TType (UVar tcns (v+1)))
157− chk u env (RUType un)
158+ chk u lvl env (RUType un)
158 | holes = return (UType un, TType (UVal 0))
159 | holes = return (UType un, TType (UVal 0))
159 | otherwise = do -- TODO! Issue #1715 on the issue tracker.
160 | otherwise = do -- TODO! Issue #1715 on the issue tracker.
160 -- https://github.com/idris-lang/Idris-dev/issues/1715
161 -- https://github.com/idris-lang/Idris-dev/issues/1715
@@ -163,8 +164,8 @@ check' holes tcns ctxt env top = chk (TType (UVar tcns (-5))) env top where
163 -- put (v+2, (c:cs))
164 -- put (v+2, (c:cs))
164 -- return (TType (UVar v), TType (UVar (v+1)))
165 -- return (TType (UVar v), TType (UVar (v+1)))
165 return (UType un, TType (UVal 0))
166 return (UType un, TType (UVal 0))
166− chk u env (RConstant Forgot) = return (Erased, Erased)
167+ chk u lvl env (RConstant Forgot) = return (Erased, Erased)
167− chk u env (RConstant c) = return (Constant c, constType c)
168+ chk u lvl env (RConstant c) = return (Constant c, constType c)
168 where constType (I _) = Constant (AType (ATInt ITNative))
169 where constType (I _) = Constant (AType (ATInt ITNative))
169 constType (BI _) = Constant (AType (ATInt ITBig))
170 constType (BI _) = Constant (AType (ATInt ITBig))
170 constType (Fl _) = Constant (AType ATFloat)
171 constType (Fl _) = Constant (AType ATFloat)
@@ -177,13 +178,15 @@ check' holes tcns ctxt env top = chk (TType (UVar tcns (-5))) env top where
177 constType TheWorld = Constant WorldType
178 constType TheWorld = Constant WorldType
178 constType Forgot = Erased
179 constType Forgot = Erased
179 constType _ = TType (UVal 0)
180 constType _ = TType (UVal 0)
180− chk u env (RBind n (Pi i s k) t)
181+ chk u lvl env (RBind n (Pi i s k) t)
181− = do (sv, st) <- chk u env s
182+ = do (sv, st) <- chk u Nothing env s
182 (v, cs) <- get
183 (v, cs) <- get
183− (kv, kt) <- chk u env k -- no need to validate these constraints, they are independent
184+ (kv, kt) <- chk u Nothing env k -- no need to validate these constraints, they are independent
184 put (v+1, cs)
185 put (v+1, cs)
186+ let maxu = case lvl of
185− let maxu = UVar tcns v
187+ Nothing -> UVar tcns v
186− (tv, tt) <- chk st ((n, Pi i sv kv) : env) t
189+ (tv, tt) <- chk st (Just maxu) ((n, Pi i sv kv) : env) t
188-- convertsC ctxt env st (TType maxu)
191-- convertsC ctxt env st (TType maxu)
189-- convertsC ctxt env tt (TType maxu)
192-- convertsC ctxt env tt (TType maxu)
@@ -219,25 +222,25 @@ check' holes tcns ctxt env top = chk (TType (UVar tcns (-5))) env top where
219 mostUnique (Pi _ _ pk : es) k = mostUnique es (smaller pk k)
222 mostUnique (Pi _ _ pk : es) k = mostUnique es (smaller pk k)
220 mostUnique (_ : es) k = mostUnique es k
223 mostUnique (_ : es) k = mostUnique es k
222− chk u env (RBind n b sc)
225+ chk u lvl env (RBind n b sc)
223 = do (b', bt') <- checkBinder b
226 = do (b', bt') <- checkBinder b
224− (scv, sct) <- chk (smaller bt' u) ((n, b'):env) sc
227+ (scv, sct) <- chk (smaller bt' u) Nothing ((n, b'):env) sc
225 discharge n b' bt' (pToV n scv) (pToV n sct)
228 discharge n b' bt' (pToV n scv) (pToV n sct)
226 where checkBinder (Lam t)
229 where checkBinder (Lam t)
227− = do (tv, tt) <- chk u env t
230+ = do (tv, tt) <- chk u Nothing env t
228 let tv' = normalise ctxt env tv
231 let tv' = normalise ctxt env tv
229 convType tcns ctxt env tt
232 convType tcns ctxt env tt
230 return (Lam tv, tt)
233 return (Lam tv, tt)
231 checkBinder (Let t v)
234 checkBinder (Let t v)
232− = do (tv, tt) <- chk u env t
235+ = do (tv, tt) <- chk u Nothing env t
233− (vv, vt) <- chk u env v
236+ (vv, vt) <- chk u Nothing env v
234 let tv' = normalise ctxt env tv
237 let tv' = normalise ctxt env tv
235 convertsC ctxt env vt tv
238 convertsC ctxt env vt tv
236 convType tcns ctxt env tt
239 convType tcns ctxt env tt
237 return (Let tv vv, tt)
240 return (Let tv vv, tt)
238 checkBinder (NLet t v)
241 checkBinder (NLet t v)
239− = do (tv, tt) <- chk u env t
242+ = do (tv, tt) <- chk u Nothing env t
240− (vv, vt) <- chk u env v
243+ (vv, vt) <- chk u Nothing env v
241 let tv' = normalise ctxt env tv
244 let tv' = normalise ctxt env tv
242 convertsC ctxt env vt tv
245 convertsC ctxt env vt tv
243 convType tcns ctxt env tt
246 convType tcns ctxt env tt
@@ -245,33 +248,33 @@ check' holes tcns ctxt env top = chk (TType (UVar tcns (-5))) env top where
245 checkBinder (Hole t)
248 checkBinder (Hole t)
246 | not holes = lift $ tfail (IncompleteTerm undefined)
249 | not holes = lift $ tfail (IncompleteTerm undefined)
247 | otherwise
250 | otherwise
248− = do (tv, tt) <- chk u env t
251+ = do (tv, tt) <- chk u Nothing env t
249 let tv' = normalise ctxt env tv
252 let tv' = normalise ctxt env tv
250 convType tcns ctxt env tt
253 convType tcns ctxt env tt
251 return (Hole tv, tt)
254 return (Hole tv, tt)
252 checkBinder (GHole i ns t)
255 checkBinder (GHole i ns t)
253− = do (tv, tt) <- chk u env t
256+ = do (tv, tt) <- chk u Nothing env t
254 let tv' = normalise ctxt env tv
257 let tv' = normalise ctxt env tv
255 convType tcns ctxt env tt
258 convType tcns ctxt env tt
256 return (GHole i ns tv, tt)
259 return (GHole i ns tv, tt)
257 checkBinder (Guess t v)
260 checkBinder (Guess t v)
258 | not holes = lift $ tfail (IncompleteTerm undefined)
261 | not holes = lift $ tfail (IncompleteTerm undefined)
259 | otherwise
262 | otherwise
260− = do (tv, tt) <- chk u env t
263+ = do (tv, tt) <- chk u Nothing env t
261− (vv, vt) <- chk u env v
264+ (vv, vt) <- chk u Nothing env v
262 let tv' = normalise ctxt env tv
265 let tv' = normalise ctxt env tv
263 convertsC ctxt env vt tv
266 convertsC ctxt env vt tv
264 convType tcns ctxt env tt
267 convType tcns ctxt env tt
265 return (Guess tv vv, tt)
268 return (Guess tv vv, tt)
266 checkBinder (PVar t)
269 checkBinder (PVar t)
267− = do (tv, tt) <- chk u env t
270+ = do (tv, tt) <- chk u Nothing env t
268 let tv' = normalise ctxt env tv
271 let tv' = normalise ctxt env tv
269 convType tcns ctxt env tt
272 convType tcns ctxt env tt
270 -- Normalised version, for erasure purposes (it's easier
273 -- Normalised version, for erasure purposes (it's easier
271 -- to tell if it's a collapsible variable)
274 -- to tell if it's a collapsible variable)
272 return (PVar tv, tt)
275 return (PVar tv, tt)
273 checkBinder (PVTy t)
276 checkBinder (PVTy t)
274− = do (tv, tt) <- chk u env t
277+ = do (tv, tt) <- chk u Nothing env t
275 let tv' = normalise ctxt env tv
278 let tv' = normalise ctxt env tv
276 convType tcns ctxt env tt
279 convType tcns ctxt env tt
277 return (PVTy tv, tt)
280 return (PVTy tv, tt)