on master help sign in
Fix universe errors, update tests
c55895dEdwin Brady
idris.cabal+3
@@ -513,6 +513,9 @@ Extra-source-files:
513 test/unique002/run
513 test/unique002/run
514 test/unique002/*.idr
514 test/unique002/*.idr
515 test/unique002/expected
515 test/unique002/expected
516+ test/unique003/run
517+ test/unique003/*.idr
518+ test/unique003/expected
516
519
517source-repository head
520source-repository head
518 type: git
521 type: git
src/Idris/Core/Typecheck.hs+4−4
@@ -69,7 +69,7 @@ check ctxt env tm
69 = evalStateT (check' True ctxt env tm) (0, []) -- Holes allowed
69 = evalStateT (check' True ctxt env tm) (0, []) -- Holes allowed
70
70
71check' :: Bool -> Context -> Env -> Raw -> StateT UCs TC (Term, Type)
71check' :: Bool -> Context -> Env -> Raw -> StateT UCs TC (Term, Type)
72−check' holes ctxt env top = chk (TType (UVar 0)) env top where
72+check' holes ctxt env top = chk (TType (UVar (-5))) env top where
73
73
74 smaller (UType NullType) _ = UType NullType
74 smaller (UType NullType) _ = UType NullType
75 smaller _ (UType NullType) = UType NullType
75 smaller _ (UType NullType) = UType NullType
@@ -140,11 +140,11 @@ check' holes ctxt env top = chk (TType (UVar 0)) env top where
140 case (normalise ctxt env st, normalise ctxt env tt) of
140 case (normalise ctxt env st, normalise ctxt env tt) of
141 (TType su, TType tu) -> do
141 (TType su, TType tu) -> do
142 when (not holes) $ put (v+1, ULE su (UVar v):ULE tu (UVar v):cs)
142 when (not holes) $ put (v+1, ULE su (UVar v):ULE tu (UVar v):cs)
143− let k' = u `smaller` st `smaller` kv `smaller` TType (UVar v)
143+ let k' = st `smaller` kv `smaller` TType (UVar v) `smaller` u
144 return (Bind n (Pi (uniqueBinders (map fst env) sv) k')
144 return (Bind n (Pi (uniqueBinders (map fst env) sv) k')
145 (pToV n tv), k')
145 (pToV n tv), k')
146 (un, un') ->
146 (un, un') ->
147− let k' = u `smaller` st `smaller` kv `smaller` un `smaller` un' in
147+ let k' = st `smaller` kv `smaller` un `smaller` un' `smaller` u in
148 return (Bind n (Pi (uniqueBinders (map fst env) sv) k')
148 return (Bind n (Pi (uniqueBinders (map fst env) sv) k')
149 (pToV n tv), k')
149 (pToV n tv), k')
150
150
@@ -284,11 +284,11 @@ checkUnique borrowed ctxt env tm
284 -- Must be safe whether we evaluate the scope or binder first
284 -- Must be safe whether we evaluate the scope or binder first
285 -- (Surely there is a tidier rule than this...?)
285 -- (Surely there is a tidier rule than this...?)
286 st <- get
286 st <- get
287− chkBinders ((n, b) : env) t
288 chkBinders env (binderTy b)
287 chkBinders env (binderTy b)
289 case b of
288 case b of
290 Let t v -> chkBinders env v
289 Let t v -> chkBinders env v
291 _ -> return ()
290 _ -> return ()
291+ chkBinders ((n, b) : env) t
292-- put st
292-- put st
293-- chkBinders env (binderTy b)
293-- chkBinders env (binderTy b)
294-- case b of
294-- case b of
src/Idris/ElabDecls.hs+7−7
@@ -103,9 +103,9 @@ elabPrims = do mapM_ (elabDecl' EAll recinfo)
103
103
104 p_believeMe [_,_,x] = Just x
104 p_believeMe [_,_,x] = Just x
105 p_believeMe _ = Nothing
105 p_believeMe _ = Nothing
106− believeTy = Bind (sUN "a") (Pi (TType (UVar (-2))) (TType (UVar 0)))
106+ believeTy = Bind (sUN "a") (Pi (TType (UVar (-2))) (TType (UVar (-1))))
107− (Bind (sUN "b") (Pi (TType (UVar (-2))) (TType (UVar 0)))
107+ (Bind (sUN "b") (Pi (TType (UVar (-2))) (TType (UVar (-1))))
108− (Bind (sUN "x") (Pi (V 1) (TType (UVar 0))) (V 1)))
108+ (Bind (sUN "x") (Pi (V 1) (TType (UVar (-1)))) (V 1)))
109 elabBelieveMe
109 elabBelieveMe
110 = do let prim__believe_me = sUN "prim__believe_me"
110 = do let prim__believe_me = sUN "prim__believe_me"
111 updateContext (addOperator prim__believe_me believeTy 3 p_believeMe)
111 updateContext (addOperator prim__believe_me believeTy 3 p_believeMe)
@@ -126,10 +126,10 @@ elabPrims = do mapM_ (elabDecl' EAll recinfo)
126 vnNothing = VP (DCon 0 1 False) (sNS (sUN "Nothing") ["Maybe", "Prelude"]) VErased
126 vnNothing = VP (DCon 0 1 False) (sNS (sUN "Nothing") ["Maybe", "Prelude"]) VErased
127 vnRefl = VP (DCon 0 2 False) eqCon VErased
127 vnRefl = VP (DCon 0 2 False) eqCon VErased
128
128
129− synEqTy = Bind (sUN "a") (Pi (TType (UVar (-3))) (TType (UVar 0)))
129+ synEqTy = Bind (sUN "a") (Pi (TType (UVar (-3))) (TType (UVar (-2))))
130− (Bind (sUN "b") (Pi (TType (UVar (-3))) (TType (UVar 0)))
130+ (Bind (sUN "b") (Pi (TType (UVar (-3))) (TType (UVar (-2))))
131− (Bind (sUN "x") (Pi (V 1) (TType (UVar 0)))
131+ (Bind (sUN "x") (Pi (V 1) (TType (UVar (-2))))
132− (Bind (sUN "y") (Pi (V 1) (TType (UVar 0)))
132+ (Bind (sUN "y") (Pi (V 1) (TType (UVar (-2))))
133 (mkApp nMaybe [mkApp (P (TCon 0 4) eqTy Erased)
133 (mkApp nMaybe [mkApp (P (TCon 0 4) eqTy Erased)
134 [V 3, V 2, V 1, V 0]]))))
134 [V 3, V 2, V 1, V 0]]))))
135 elabSynEq
135 elabSynEq
src/Idris/Primitives.hs+1−1
@@ -26,7 +26,7 @@ data Prim = Prim { p_name :: Name,
26
26
27ty :: [Const] -> Const -> Type
27ty :: [Const] -> Const -> Type
28ty [] x = Constant x
28ty [] x = Constant x
29−ty (t:ts) x = Bind (sMN 0 "T") (Pi (Constant t) (TType (UVar 0))) (ty ts x)
29+ty (t:ts) x = Bind (sMN 0 "T") (Pi (Constant t) (TType (UVar (-3)))) (ty ts x)
30
30
31total, partial, iopartial :: Totality
31total, partial, iopartial :: Totality
32total = Total []
32total = Total []
test/quasiquote001/expected+3−3
@@ -1,5 +1,5 @@
1−(App (App (App (P (DCon 1 3) (NS (UN ::) ["List", "Prelude"]) (Bind (UN a) (Pi (TType (UVar -1))) (Bind (MN 0 "_t") (Pi (V 0)) (Bind (MN 2 "_t") (Pi (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 1))) (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 2)))))) (P (TCon 7 0) (MN 0 "__Unit") (TType (UVar 6)))) (P (DCon 0 0) (MN 0 "__II") (P (TCon 0 0) (MN 0 "__Unit") (TType (UVar 6))))) (App (App (App (P (DCon 1 3) (NS (UN ::) ["List", "Prelude"]) (Bind (UN a) (Pi (TType (UVar -1))) (Bind (MN 0 "_t") (Pi (V 0)) (Bind (MN 2 "_t") (Pi (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 1))) (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 2)))))) (P (TCon 7 0) (MN 0 "__Unit") (TType (UVar 6)))) (P (DCon 0 0) (MN 0 "__II") (P (TCon 0 0) (MN 0 "__Unit") (TType (UVar 6))))) (App (P (DCon 0 1) (NS (UN Nil) ["List", "Prelude"]) (Bind (UN a) (Pi (TType (UVar -1))) (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 0)))) (P (TCon 7 0) (MN 0 "__Unit") (TType (UVar 6))))))
1+(App (App (App (P (DCon 1 3) (NS (UN ::) ["List", "Prelude"]) (Bind (UN a) (Pi (TType (UVar -1))) (Bind (MN 0 "_t") (Pi (V 0)) (Bind (MN 2 "_t") (Pi (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 1))) (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 2)))))) (P (TCon 7 0) (MN 0 "__Unit") (TType (UVar 10)))) (P (DCon 0 0) (MN 0 "__II") (P (TCon 0 0) (MN 0 "__Unit") (TType (UVar 10))))) (App (App (App (P (DCon 1 3) (NS (UN ::) ["List", "Prelude"]) (Bind (UN a) (Pi (TType (UVar -1))) (Bind (MN 0 "_t") (Pi (V 0)) (Bind (MN 2 "_t") (Pi (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 1))) (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 2)))))) (P (TCon 7 0) (MN 0 "__Unit") (TType (UVar 10)))) (P (DCon 0 0) (MN 0 "__II") (P (TCon 0 0) (MN 0 "__Unit") (TType (UVar 10))))) (App (P (DCon 0 1) (NS (UN Nil) ["List", "Prelude"]) (Bind (UN a) (Pi (TType (UVar -1))) (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 0)))) (P (TCon 7 0) (MN 0 "__Unit") (TType (UVar 10))))))
2--------------
2--------------
3−(App (App (App (P (DCon 1 3) (NS (UN ::) ["List", "Prelude"]) (Bind (UN a) (Pi (TType (UVar -1))) (Bind (MN 0 "_t") (Pi (V 0)) (Bind (MN 2 "_t") (Pi (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 1))) (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 2)))))) (TType (UVar 110))) (TType (UVar 112))) (App (App (App (P (DCon 1 3) (NS (UN ::) ["List", "Prelude"]) (Bind (UN a) (Pi (TType (UVar -1))) (Bind (MN 0 "_t") (Pi (V 0)) (Bind (MN 2 "_t") (Pi (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 1))) (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 2)))))) (TType (UVar 114))) (App (App (App (App (P (DCon 0 4) (MN 0 "__MkPair") (Bind (MN 0 "A") (Pi (TType (UVar 36))) (Bind (MN 0 "B") (Pi (TType (UVar 38))) (Bind (MN 0 "a") (Pi (V 1)) (Bind (MN 0 "b") (Pi (V 1)) (App (App (P (TCon 0 0) (MN 0 "__Pair") (Bind (MN 1 "A") (Pi (TType (UVar 28))) (Bind (MN 1 "B") (Pi (TType (UVar 30))) (TType (UVar 32))))) (V 3)) (V 2))))))) (TType (UVar 108))) (TType (UVar 110))) (P (TCon 15 0) (NS (UN Nat) ["Nat", "Prelude"]) (TType (UVar -1)))) (P (TCon 15 0) (NS (UN Nat) ["Nat", "Prelude"]) (TType (UVar -1))))) (App (P (DCon 0 1) (NS (UN Nil) ["List", "Prelude"]) (Bind (UN a) (Pi (TType (UVar -1))) (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 0)))) (TType (UVar 116)))))
3+(App (App (App (P (DCon 1 3) (NS (UN ::) ["List", "Prelude"]) (Bind (UN a) (Pi (TType (UVar -1))) (Bind (MN 0 "_t") (Pi (V 0)) (Bind (MN 2 "_t") (Pi (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 1))) (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 2)))))) (TType (UVar 190))) (TType (UVar 192))) (App (App (App (P (DCon 1 3) (NS (UN ::) ["List", "Prelude"]) (Bind (UN a) (Pi (TType (UVar -1))) (Bind (MN 0 "_t") (Pi (V 0)) (Bind (MN 2 "_t") (Pi (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 1))) (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 2)))))) (TType (UVar 194))) (App (App (App (App (P (DCon 0 4) (MN 0 "__MkPair") (Bind (MN 0 "A") (Pi (TType (UVar 64))) (Bind (MN 0 "B") (Pi (TType (UVar 68))) (Bind (MN 0 "a") (Pi (V 1)) (Bind (MN 0 "b") (Pi (V 1)) (App (App (P (TCon 0 0) (MN 0 "__Pair") (Bind (MN 1 "A") (Pi (TType (UVar 52))) (Bind (MN 1 "B") (Pi (TType (UVar 56))) (TType (UVar 60))))) (V 3)) (V 2))))))) (TType (UVar 184))) (TType (UVar 186))) (P (TCon 15 0) (NS (UN Nat) ["Nat", "Prelude"]) (TType (UVar -1)))) (P (TCon 15 0) (NS (UN Nat) ["Nat", "Prelude"]) (TType (UVar -1))))) (App (P (DCon 0 1) (NS (UN Nil) ["List", "Prelude"]) (Bind (UN a) (Pi (TType (UVar -1))) (App (P (TCon 0 0) (NS (UN List) ["List", "Prelude"]) Erased) (V 0)))) (TType (UVar 196)))))
4--------------
4--------------
5−(App (App (App (App (P (DCon 0 4) (MN 0 "__MkPair") (Bind (MN 0 "A") (Pi (TType (UVar 36))) (Bind (MN 0 "B") (Pi (TType (UVar 38))) (Bind (MN 0 "a") (Pi (V 1)) (Bind (MN 0 "b") (Pi (V 1)) (App (App (P (TCon 0 0) (MN 0 "__Pair") (Bind (MN 1 "A") (Pi (TType (UVar 28))) (Bind (MN 1 "B") (Pi (TType (UVar 30))) (TType (UVar 32))))) (V 3)) (V 2))))))) (TType (UVar 108))) (TType (UVar 110))) (App (App (App (App (P (DCon 0 4) (MN 0 "__MkPair") (Bind (MN 0 "A") (Pi (TType (UVar 36))) (Bind (MN 0 "B") (Pi (TType (UVar 38))) (Bind (MN 0 "a") (Pi (V 1)) (Bind (MN 0 "b") (Pi (V 1)) (App (App (P (TCon 0 0) (MN 0 "__Pair") (Bind (MN 1 "A") (Pi (TType (UVar 28))) (Bind (MN 1 "B") (Pi (TType (UVar 30))) (TType (UVar 32))))) (V 3)) (V 2))))))) (TType (UVar 108))) (TType (UVar 110))) (TType (UVar 110))) (TType (UVar 110)))) (App (App (App (App (P (DCon 0 4) (MN 0 "__MkPair") (Bind (MN 0 "A") (Pi (TType (UVar 36))) (Bind (MN 0 "B") (Pi (TType (UVar 38))) (Bind (MN 0 "a") (Pi (V 1)) (Bind (MN 0 "b") (Pi (V 1)) (App (App (P (TCon 0 0) (MN 0 "__Pair") (Bind (MN 1 "A") (Pi (TType (UVar 28))) (Bind (MN 1 "B") (Pi (TType (UVar 30))) (TType (UVar 32))))) (V 3)) (V 2))))))) (TType (UVar 108))) (TType (UVar 110))) (TType (UVar 110))) (TType (UVar 110))))
5+(App (App (App (App (P (DCon 0 4) (MN 0 "__MkPair") (Bind (MN 0 "A") (Pi (TType (UVar 64))) (Bind (MN 0 "B") (Pi (TType (UVar 68))) (Bind (MN 0 "a") (Pi (V 1)) (Bind (MN 0 "b") (Pi (V 1)) (App (App (P (TCon 0 0) (MN 0 "__Pair") (Bind (MN 1 "A") (Pi (TType (UVar 52))) (Bind (MN 1 "B") (Pi (TType (UVar 56))) (TType (UVar 60))))) (V 3)) (V 2))))))) (TType (UVar 184))) (TType (UVar 186))) (App (App (App (App (P (DCon 0 4) (MN 0 "__MkPair") (Bind (MN 0 "A") (Pi (TType (UVar 64))) (Bind (MN 0 "B") (Pi (TType (UVar 68))) (Bind (MN 0 "a") (Pi (V 1)) (Bind (MN 0 "b") (Pi (V 1)) (App (App (P (TCon 0 0) (MN 0 "__Pair") (Bind (MN 1 "A") (Pi (TType (UVar 52))) (Bind (MN 1 "B") (Pi (TType (UVar 56))) (TType (UVar 60))))) (V 3)) (V 2))))))) (TType (UVar 184))) (TType (UVar 186))) (TType (UVar 190))) (TType (UVar 190)))) (App (App (App (App (P (DCon 0 4) (MN 0 "__MkPair") (Bind (MN 0 "A") (Pi (TType (UVar 64))) (Bind (MN 0 "B") (Pi (TType (UVar 68))) (Bind (MN 0 "a") (Pi (V 1)) (Bind (MN 0 "b") (Pi (V 1)) (App (App (P (TCon 0 0) (MN 0 "__Pair") (Bind (MN 1 "A") (Pi (TType (UVar 52))) (Bind (MN 1 "B") (Pi (TType (UVar 56))) (TType (UVar 60))))) (V 3)) (V 2))))))) (TType (UVar 184))) (TType (UVar 186))) (TType (UVar 190))) (TType (UVar 190))))
test/unique001/expected+13−1
@@ -1,7 +1,19 @@
119,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,END
119,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,END
219,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,END
219,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,END
338,36,34,32,30,28,26,24,22,20,18,16,14,12,10,8,6,4,2,0,END
338,36,34,32,30,28,26,24,22,20,18,16,14,12,10,8,6,4,2,0,END
4+38,36,34,32,30,28,26,24,22,20,18,16,14,12,10,8,6,4,2,0,END
4−unique001a.idr:23:11:Unique name xs is used more than once
5+unique001a.idr:38:11:Can't convert
6+ Int -> String
7+with
8+ UniqueType (Int -> String)
9+unique001a.idr:49:12:Can't convert
10+ Int -> String
11+with
12+ UniqueType (Int -> String)
13+unique001a.idr:60:12:Can't convert
14+ UniqueType (Int -> String)
15+with
16+ Int -> String
5unique001b.idr:16:7:Borrowed name xs must not be used on RHS
17unique001b.idr:16:7:Borrowed name xs must not be used on RHS
6unique001c.idr:49:6:Unique name f is used more than once
18unique001c.idr:49:6:Unique name f is used more than once
7unique001d.idr:3:7:Borrowed name x must not be used on RHS
19unique001d.idr:3:7:Borrowed name x must not be used on RHS
test/unique002/expected+4−1
@@ -1,2 +1,5 @@
1unique002.idr:15:5:Unique name xs is used more than once
1unique002.idr:15:5:Unique name xs is used more than once
2−unique002a.idr:15:5:Unique name xs is used more than once
2+unique002a.idr:15:5:Can't convert
3+ Int -> String
4+with
5+ UniqueType (Int -> String)
test/unique003/expectednew file+4
@@ -0,0 +1,4 @@
1+unique003.idr:18:5:Can't convert
2+ Int -> String
3+with
4+ UniqueType (Int -> String)
test/unique003/runnew file+3
@@ -0,0 +1,3 @@
1+#!/usr/bin/env bash
2+idris $@ unique003.idr --check
3+rm -f *.ibc
test/unique003/unique003.idrnew file+22
@@ -0,0 +1,22 @@
1+module Main
2+
3+data UList : Type -> UniqueType where
4+ Nil : UList a
5+ (::) : a -> UList a -> UList a
6+
7+showU : Show a => Borrowed (UList a) -> String
8+showU xs = "[" ++ showU' xs ++ "]" where
9+ showU' : Borrowed (UList a) -> String
10+ showU' [] = ""
11+ showU' [x] = show x
12+ showU' (x :: xs) = show x ++ ", " ++ showU' xs
13+
14+free : {a : UniqueType} -> a -> String
15+free xs = ""
16+
17+foo : UList Int -> IO ()
18+foo xs = do let f = \x : Int => showU xs -- can't build this in unique context
19+ putStrLn (f 10)
20+ putStrLn $ free xs
21+ putStrLn (f 10)
22+ return ()