@@ -86,7 +86,7 @@ check ctxt env tm
8686 = evalStateT (check' True [] ctxt env tm) (0, [])
8787
8888check' :: 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
9090
9191 smaller (UType NullType) _ = UType NullType
9292 smaller _ (UType NullType) = UType NullType
@@ -98,8 +98,9 @@ check' holes tcns ctxt env top = chk (TType (UVar tcns (-5))) env top where
9898 | otherwise = Complete
9999
100100 chk :: Type -> -- uniqueness level
101+ Maybe UExp -> -- universe for kind
101102 Env -> Raw -> StateT UCs TC (Term, Type)
102− chk u env (Var n)
103+ chk u lvl env (Var n)
103104 | Just (i, ty) <- lookupTyEnv n env = return (P Bound n ty, ty)
104105 -- If we're elaborating, we don't want the private names; if we're
105106 -- 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
109110 | [P nt n' ty] <- lookupP_all (not holes) True n ctxt
110111 = return (P nt n' ty, ty)
111112 | 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
113114 -- special case to reduce constraintss
114− = do (fv, fty) <- chk u env f
115+ = do (fv, fty) <- chk u Nothing env f
115116 let fty' = case uniqueBinders (map fst env) (finalise fty) of
116117 ty@(Bind x (Pi i s k) t) -> ty
117118 _ -> uniqueBinders (map fst env)
@@ -126,21 +127,21 @@ check' holes tcns ctxt env top = chk (TType (UVar tcns (-5))) env top where
126127 (Bind x (Let (TType v') (TType (UVar tcns v))) t)
127128 return (App Complete fv (TType (UVar tcns v)), apty)
128129 Bind x (Pi i s k) t ->
129− do (av, aty) <- chk u env RType
130+ do (av, aty) <- chk u Nothing env RType
130131 convertsC ctxt env aty s
131132 let apty = simplify initContext env
132133 (Bind x (Let aty av) t)
133134 return (App astate fv av, apty)
134135 t -> lift $ tfail $ NonFunctionType fv fty
135− chk u env ap@(RApp f a)
136− = do (fv, fty) <- chk u env f
136+ chk u lvl env ap@(RApp f a)
137+ = do (fv, fty) <- chk u Nothing env f
137138 let fty' = case uniqueBinders (map fst env) (finalise fty) of
138139 ty@(Bind x (Pi i s k) t) -> ty
139140 _ -> uniqueBinders (map fst env)
140141 $ case hnf ctxt env fty of
141142 ty@(Bind x (Pi i s k) t) -> ty
142143 _ -> normalise ctxt env fty
143− (av, aty) <- chk u env a
144+ (av, aty) <- chk u Nothing env a
144145 case fty' of
145146 Bind x (Pi i s k) t ->
146147 do convertsC ctxt env aty s
@@ -148,13 +149,13 @@ check' holes tcns ctxt env top = chk (TType (UVar tcns (-5))) env top where
148149 (Bind x (Let aty av) t)
149150 return (App astate fv av, apty)
150151 t -> lift $ tfail $ NonFunctionType fv fty
151− chk u env RType
152+ chk u lvl env RType
152153 | holes = return (TType (UVal 0), TType (UVal 0))
153154 | otherwise = do (v, cs) <- get
154155 let c = ULT (UVar tcns v) (UVar tcns (v+1))
155156 put (v+2, (c:cs))
156157 return (TType (UVar tcns v), TType (UVar tcns (v+1)))
157− chk u env (RUType un)
158+ chk u lvl env (RUType un)
158159 | holes = return (UType un, TType (UVal 0))
159160 | otherwise = do -- TODO! Issue #1715 on the issue tracker.
160161 -- 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
163164 -- put (v+2, (c:cs))
164165 -- return (TType (UVar v), TType (UVar (v+1)))
165166 return (UType un, TType (UVal 0))
166− chk u env (RConstant Forgot) = return (Erased, Erased)
167− chk u env (RConstant c) = return (Constant c, constType c)
167+ chk u lvl env (RConstant Forgot) = return (Erased, Erased)
168+ chk u lvl env (RConstant c) = return (Constant c, constType c)
168169 where constType (I _) = Constant (AType (ATInt ITNative))
169170 constType (BI _) = Constant (AType (ATInt ITBig))
170171 constType (Fl _) = Constant (AType ATFloat)
@@ -177,13 +178,15 @@ check' holes tcns ctxt env top = chk (TType (UVar tcns (-5))) env top where
177178 constType TheWorld = Constant WorldType
178179 constType Forgot = Erased
179180 constType _ = TType (UVal 0)
180− chk u env (RBind n (Pi i s k) t)
181− = do (sv, st) <- chk u env s
181+ chk u lvl env (RBind n (Pi i s k) t)
182+ = do (sv, st) <- chk u Nothing env s
182183 (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
184185 put (v+1, cs)
185− let maxu = UVar tcns v
186− (tv, tt) <- chk st ((n, Pi i sv kv) : env) t
186+ let maxu = case lvl of
187+ Nothing -> UVar tcns v
188+ Just v' -> v'
189+ (tv, tt) <- chk st (Just maxu) ((n, Pi i sv kv) : env) t
187190
188191-- convertsC ctxt env st (TType maxu)
189192-- convertsC ctxt env tt (TType maxu)
@@ -219,25 +222,25 @@ check' holes tcns ctxt env top = chk (TType (UVar tcns (-5))) env top where
219222 mostUnique (Pi _ _ pk : es) k = mostUnique es (smaller pk k)
220223 mostUnique (_ : es) k = mostUnique es k
221224
222− chk u env (RBind n b sc)
225+ chk u lvl env (RBind n b sc)
223226 = 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
225228 discharge n b' bt' (pToV n scv) (pToV n sct)
226229 where checkBinder (Lam t)
227− = do (tv, tt) <- chk u env t
230+ = do (tv, tt) <- chk u Nothing env t
228231 let tv' = normalise ctxt env tv
229232 convType tcns ctxt env tt
230233 return (Lam tv, tt)
231234 checkBinder (Let t v)
232− = do (tv, tt) <- chk u env t
233− (vv, vt) <- chk u env v
235+ = do (tv, tt) <- chk u Nothing env t
236+ (vv, vt) <- chk u Nothing env v
234237 let tv' = normalise ctxt env tv
235238 convertsC ctxt env vt tv
236239 convType tcns ctxt env tt
237240 return (Let tv vv, tt)
238241 checkBinder (NLet t v)
239− = do (tv, tt) <- chk u env t
240− (vv, vt) <- chk u env v
242+ = do (tv, tt) <- chk u Nothing env t
243+ (vv, vt) <- chk u Nothing env v
241244 let tv' = normalise ctxt env tv
242245 convertsC ctxt env vt tv
243246 convType tcns ctxt env tt
@@ -245,33 +248,33 @@ check' holes tcns ctxt env top = chk (TType (UVar tcns (-5))) env top where
245248 checkBinder (Hole t)
246249 | not holes = lift $ tfail (IncompleteTerm undefined)
247250 | otherwise
248− = do (tv, tt) <- chk u env t
251+ = do (tv, tt) <- chk u Nothing env t
249252 let tv' = normalise ctxt env tv
250253 convType tcns ctxt env tt
251254 return (Hole tv, tt)
252255 checkBinder (GHole i ns t)
253− = do (tv, tt) <- chk u env t
256+ = do (tv, tt) <- chk u Nothing env t
254257 let tv' = normalise ctxt env tv
255258 convType tcns ctxt env tt
256259 return (GHole i ns tv, tt)
257260 checkBinder (Guess t v)
258261 | not holes = lift $ tfail (IncompleteTerm undefined)
259262 | otherwise
260− = do (tv, tt) <- chk u env t
261− (vv, vt) <- chk u env v
263+ = do (tv, tt) <- chk u Nothing env t
264+ (vv, vt) <- chk u Nothing env v
262265 let tv' = normalise ctxt env tv
263266 convertsC ctxt env vt tv
264267 convType tcns ctxt env tt
265268 return (Guess tv vv, tt)
266269 checkBinder (PVar t)
267− = do (tv, tt) <- chk u env t
270+ = do (tv, tt) <- chk u Nothing env t
268271 let tv' = normalise ctxt env tv
269272 convType tcns ctxt env tt
270273 -- Normalised version, for erasure purposes (it's easier
271274 -- to tell if it's a collapsible variable)
272275 return (PVar tv, tt)
273276 checkBinder (PVTy t)
274− = do (tv, tt) <- chk u env t
277+ = do (tv, tt) <- chk u Nothing env t
275278 let tv' = normalise ctxt env tv
276279 convType tcns ctxt env tt
277280 return (PVTy tv, tt)