@@ -49,9 +49,18 @@ recheckC fc env t
49 addConstraints fc cs
49 addConstraints fc cs
50 return (tm, ty)
50 return (tm, ty)
53+checkDef fc ns = checkAddDef False True fc ns
55+checkAddDef add toplvl fc [] = return []
56+checkAddDef add toplvl fc ((n, (i, top, t)) : ns)
52−checkDef fc ns = do ctxt <- getContext
57+ = do ctxt <- getContext
58+ (t', _) <- recheckC fc [] t
59+ when add $ addDeferred [(n, (i, top, t, toplvl))]
60+ ns' <- checkAddDef add toplvl fc ns
61+ return ((n, (i, top, t')) : ns')
53− mapM (\(n, (i, top, t)) -> do (t', _) <- recheckC fc [] t
62+-- mapM (\(n, (i, top, t)) -> do (t', _) <- recheckC fc [] t
54− return (n, (i, top, t'))) ns
63+-- return (n, (i, top, t'))) ns
56-- | Elaborate a top-level type declaration - for example, "foo : Int -> Int".
65-- | Elaborate a top-level type declaration - for example, "foo : Int -> Int".
57elabType :: ElabInfo -> SyntaxInfo -> String ->
66elabType :: ElabInfo -> SyntaxInfo -> String ->
@@ -76,9 +85,12 @@ elabType' norm info syn doc fc opts n ty' = {- let ty' = piBind (params info) ty
76 ((tyT, defer, is), log) <-
85 ((tyT, defer, is), log) <-
77 tclift $ elaborate ctxt n (TType (UVal 0)) []
86 tclift $ elaborate ctxt n (TType (UVal 0)) []
78 (errAt "type of " n (erun fc (build i info False [] n ty)))
87 (errAt "type of " n (erun fc (build i info False [] n ty)))
79− ds <- checkDef fc defer
88+ ds <- checkAddDef True False fc defer
89+ -- if the type is not complete, note that we'll need to infer
90+ -- things later (for solving metavariables)
91+ when (not (null ds)) $ addTyInferred n
80− let ds' = map (\(n, (i, top, t)) -> (n, (i, top, t, True))) ds
92+-- let ds' = map (\(n, (i, top, t)) -> (n, (i, top, t, True))) ds
81− addDeferred ds'
93+-- addDeferred ds'
82 mapM_ (elabCaseBlock info opts) is
94 mapM_ (elabCaseBlock info opts) is
83 ctxt <- getContext
95 ctxt <- getContext
84 logLvl 5 $ "Rechecking"
96 logLvl 5 $ "Rechecking"
@@ -1262,6 +1274,7 @@ elabClause info opts (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
1262 -- Build the LHS as an "Infer", and pull out its type and
1274 -- Build the LHS as an "Infer", and pull out its type and
1263 -- pattern bindings
1275 -- pattern bindings
1264 i <- getIState
1276 i <- getIState
1277+ inf <- isTyInferred fname
1265 -- get the parameters first, to pass through to any where block
1278 -- get the parameters first, to pass through to any where block
1266 let fn_ty = case lookupTy fname (tt_ctxt i) of
1279 let fn_ty = case lookupTy fname (tt_ctxt i) of
1267 [t] -> t
1280 [t] -> t
@@ -1275,16 +1288,25 @@ elabClause info opts (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
1275 logLvl 5 ("LHS: " ++ show fc ++ " " ++ showTmImpls lhs)
1288 logLvl 5 ("LHS: " ++ show fc ++ " " ++ showTmImpls lhs)
1276 logLvl 4 ("Fixed parameters: " ++ show params ++ " from " ++ show (fn_ty, fn_is))
1289 logLvl 4 ("Fixed parameters: " ++ show params ++ " from " ++ show (fn_ty, fn_is))
1278− ((lhs', dlhs, []), _) <-
1291+ (((lhs', dlhs, []), probs), _) <-
1279 tclift $ elaborate ctxt (sMN 0 "patLHS") infP []
1292 tclift $ elaborate ctxt (sMN 0 "patLHS") infP []
1280− (errAt "left hand side of " fname
1293+ (do res <- errAt "left hand side of " fname
1281− (erun fc (buildTC i info True opts fname (infTerm lhs))))
1294+ (erun fc (buildTC i info True opts fname (infTerm lhs)))
1296+ return (res, probs))
1298+ when inf $ addTyInfConstraints fc (map (\(x,y,_,_) -> (x,y)) probs)
1282 let lhs_tm = orderPats (getInferTerm lhs')
1300 let lhs_tm = orderPats (getInferTerm lhs')
1283 let lhs_ty = getInferType lhs'
1301 let lhs_ty = getInferType lhs'
1284 logLvl 3 ("Elaborated: " ++ show lhs_tm)
1302 logLvl 3 ("Elaborated: " ++ show lhs_tm)
1285 logLvl 3 ("Elaborated type: " ++ show lhs_ty)
1303 logLvl 3 ("Elaborated type: " ++ show lhs_ty)
1305+ -- If we're inferring metavariables in the type, don't recheck,
1306+ -- because we're only doing this to try to work out those metavariables
1307+ (clhs_c, clhsty) <- if not inf
1287− (clhs_c, clhsty) <- recheckC fc [] lhs_tm
1308+ then recheckC fc [] lhs_tm
1309+ else return (lhs_tm, lhs_ty)
1288 let clhs = normalise ctxt [] clhs_c
1310 let clhs = normalise ctxt [] clhs_c
1290 logLvl 3 ("Normalised LHS: " ++ showTmImpls (delabMV i clhs))
1312 logLvl 3 ("Normalised LHS: " ++ showTmImpls (delabMV i clhs))
@@ -1319,7 +1341,7 @@ elabClause info opts (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
1319 logLvl 2 $ "RHS: " ++ showTmImpls rhs
1341 logLvl 2 $ "RHS: " ++ showTmImpls rhs
1320 ctxt <- getContext -- new context with where block added
1342 ctxt <- getContext -- new context with where block added
1321 logLvl 5 "STARTING CHECK"
1343 logLvl 5 "STARTING CHECK"
1322− ((rhs', defer, is), _) <-
1344+ ((rhs', defer, is, probs), _) <-
1323 tclift $ elaborate ctxt (sMN 0 "patRHS") clhsty []
1345 tclift $ elaborate ctxt (sMN 0 "patRHS") clhsty []
1324 (do pbinds lhs_tm
1346 (do pbinds lhs_tm
1325 setNextName
1347 setNextName
@@ -1332,7 +1354,11 @@ elabClause info opts (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
1332 mapM_ (elabCaseHole aux) hs
1354 mapM_ (elabCaseHole aux) hs
1333 tt <- get_term
1355 tt <- get_term
1334 let (tm, ds) = runState (collectDeferred (Just fname) tt) []
1356 let (tm, ds) = runState (collectDeferred (Just fname) tt) []
1335− return (tm, ds, is))
1358+ return (tm, ds, is, probs))
1360+ when inf $ addTyInfConstraints fc (map (\(x,y,_,_) -> (x,y)) probs)
1336 logLvl 5 "DONE CHECK"
1362 logLvl 5 "DONE CHECK"
1337 logLvl 2 $ "---> " ++ show rhs'
1363 logLvl 2 $ "---> " ++ show rhs'
1338 when (not (null defer)) $ iLOG $ "DEFERRED " ++ show (map fst defer)
1364 when (not (null defer)) $ iLOG $ "DEFERRED " ++ show (map fst defer)
@@ -1352,7 +1378,9 @@ elabClause info opts (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
1352 ctxt <- getContext
1378 ctxt <- getContext
1353 logLvl 5 $ "Rechecking"
1379 logLvl 5 $ "Rechecking"
1354 logLvl 6 $ " ==> " ++ show (forget rhs')
1380 logLvl 6 $ " ==> " ++ show (forget rhs')
1381+ (crhs, crhsty) <- if not inf
1355− (crhs, crhsty) <- recheckC fc [] rhs'
1382+ then recheckC fc [] rhs'
1383+ else return (rhs', clhsty)
1356 logLvl 6 $ " ==> " ++ show crhsty ++ " against " ++ show clhsty
1384 logLvl 6 $ " ==> " ++ show crhsty ++ " against " ++ show clhsty
1357 case converts ctxt [] clhsty crhsty of
1385 case converts ctxt [] clhsty crhsty of
1358 OK _ -> return ()
1386 OK _ -> return ()