@@ -94,7 +94,7 @@ build ist info emode opts fn tm
94 when tydecl (do update_term orderPats
94 when tydecl (do update_term orderPats
96-- update_term liftPats)
96-- update_term liftPats)
97− is <- getAux
97+ EState is _ <- getAux
98 tt <- get_term
98 tt <- get_term
99 let (tm, ds) = runState (collectDeferred (Just fn) tt) []
99 let (tm, ds) = runState (collectDeferred (Just fn) tt) []
100 log <- getLog
100 log <- getLog
@@ -130,7 +130,12 @@ buildTC ist info emode opts fn tm
130 [] -> return ()
130 [] -> return ()
131 ((_,_,_,_,e,_,_):es) -> if inf then return ()
131 ((_,_,_,_,e,_,_):es) -> if inf then return ()
132 else lift (Error e)
132 else lift (Error e)
134+ -- 'dots' are the PHidden things which have not been solved by
136+ when (not (null dots)) $
137+ lift (Error (CantMatch (getInferTerm tm)))
133− is <- getAux
138+ EState is _ <- getAux
134 tt <- get_term
139 tt <- get_term
135 let (tm, ds) = runState (collectDeferred (Just fn) tt) []
140 let (tm, ds) = runState (collectDeferred (Just fn) tt) []
136 log <- getLog
141 log <- getLog
@@ -181,6 +186,8 @@ elab ist info emode opts fn tm
181 compute -- expand type synonyms, etc
186 compute -- expand type synonyms, etc
182 let fc = maybe "(unknown)"
187 let fc = maybe "(unknown)"
183 elabE initElabCtxt (elabFC info) tm -- (in argument, guarded, in type, in qquote)
188 elabE initElabCtxt (elabFC info) tm -- (in argument, guarded, in type, in qquote)
190+ sequence_ (delayed_elab est)
184 end_unify
191 end_unify
185 ptm <- get_term
192 ptm <- get_term
186 when pattern -- convert remaining holes to pattern vars
193 when pattern -- convert remaining holes to pattern vars
@@ -388,7 +395,7 @@ elab ist info emode opts fn tm
388 trySeq' deferr (x : xs)
395 trySeq' deferr (x : xs)
389 = try' (do elab' ina fc x
396 = try' (do elab' ina fc x
390 solveAutos ist fn False) (trySeq' deferr xs) True
397 solveAutos ist fn False) (trySeq' deferr xs) True
391− elab' ina _ (PPatvar fc n) | bindfree = do patvar n; -- update_term liftPats
398+ elab' ina _ (PPatvar fc n) | bindfree = do patvar n; update_term liftPats
392-- elab' (_, _, inty) (PRef fc f)
399-- elab' (_, _, inty) (PRef fc f)
393-- | isTConName f (tt_ctxt ist) && pattern && not reflection && not inty
400-- | isTConName f (tt_ctxt ist) && pattern && not reflection && not inty
394-- = lift $ tfail (Msg "Typecase is not allowed")
401-- = lift $ tfail (Msg "Typecase is not allowed")
@@ -587,9 +594,13 @@ elab ist info emode opts fn tm
587 | otherwise
594 | otherwise
588 = do env <- get_env
595 = do env <- get_env
589 ty <- goal
596 ty <- goal
590 let unmatchableArgs = if pattern
598 let unmatchableArgs = if pattern
591 then getUnmatchable (tt_ctxt ist) f
599 then getUnmatchable (tt_ctxt ist) f
601+ -- Dot it if we're in a pattern and it isn't a constructor
602+-- when (pattern && not (isDConName f ctxt) && f /= fn) $ dotterm
593 when (pattern && not reflection && not (e_qq ina) && not (e_intype ina)
604 when (pattern && not reflection && not (e_qq ina) && not (e_intype ina)
594 && isTConName f (tt_ctxt ist)) $
605 && isTConName f (tt_ctxt ist)) $
595 lift $ tfail $ Msg ("No explicit types on left hand side: " ++ show tm)
606 lift $ tfail $ Msg ("No explicit types on left hand side: " ++ show tm)
@@ -612,7 +623,6 @@ elab ist info emode opts fn tm
612 _ -> do mapM_ setInjective (map getTm args)
623 _ -> do mapM_ setInjective (map getTm args)
613 -- maybe more things are solvable now
624 -- maybe more things are solvable now
614 unifyProblems
625 unifyProblems
616 let guarded = isConName f ctxt
626 let guarded = isConName f ctxt
617-- trace ("args is " ++ show args) $ return ()
627-- trace ("args is " ++ show args) $ return ()
618 ns <- apply (Var f) (map isph args)
628 ns <- apply (Var f) (map isph args)
@@ -666,13 +676,15 @@ elab ist info emode opts fn tm
666 PLam _ _ _ -> 3
676 PLam _ _ _ -> 3
667 PRewrite _ _ _ _ -> 4
677 PRewrite _ _ _ _ -> 4
668 PResolveTC _ -> 0
678 PResolveTC _ -> 0
671 constraint (PConstraint _ _ _ _) = True
682 constraint (PConstraint _ _ _ _) = True
672 constraint _ = False
683 constraint _ = False
674 -- Score a point for every level where there is a non-constructor
685 -- Score a point for every level where there is a non-constructor
675− -- function (so higher score --> done later)
686+ -- function (so higher score --> done later), and lots of points
687+ -- if there is a PHidden since this should be unifiable.
676 -- Only relevant when on lhs
688 -- Only relevant when on lhs
677 conDepth d t | not pattern = 0
689 conDepth d t | not pattern = 0
678 conDepth d (PRef _ f) | isConName f (tt_ctxt ist) = 0
690 conDepth d (PRef _ f) | isConName f (tt_ctxt ist) = 0
@@ -681,6 +693,7 @@ elab ist info emode opts fn tm
681 = conDepth d f + sum (map (conDepth (d+1)) (map getTm as))
693 = conDepth d f + sum (map (conDepth (d+1)) (map getTm as))
682 conDepth d (PPatvar _ _) = 0
694 conDepth d (PPatvar _ _) = 0
683 conDepth d (PAlternative _ as) = maximum (map (conDepth d) as)
695 conDepth d (PAlternative _ as) = maximum (map (conDepth d) as)
696+ conDepth d (PHidden _) = 150
684 conDepth d Placeholder = 0
697 conDepth d Placeholder = 0
685 conDepth d (PResolveTC _) = 0
698 conDepth d (PResolveTC _) = 0
686 conDepth d t = max (100 - d) 1
699 conDepth d t = max (100 - d) 1
@@ -810,7 +823,7 @@ elab ist info emode opts fn tm
810 (caseBlock fc cname'
823 (caseBlock fc cname'
811 (map (isScr scr) (reverse args')) opts)
824 (map (isScr scr) (reverse args')) opts)
812 -- elaborate case
825 -- elaborate case
813− updateAux (newdef : )
826+ updateAux (\e -> e { case_decls = newdef : case_decls e } )
814 -- if we haven't got the type yet, hopefully we'll get it later!
827 -- if we haven't got the type yet, hopefully we'll get it later!
815 movelast tyn
828 movelast tyn
@@ -930,8 +943,24 @@ elab ist info emode opts fn tm
931 elab' ina fc (PUnquote t) = fail "Found unquote outside of quasiquote"
944 elab' ina fc (PUnquote t) = fail "Found unquote outside of quasiquote"
932 elab' ina fc (PAs _ n t) = lift . tfail . Msg $ "@-pattern not allowed here"
945 elab' ina fc (PAs _ n t) = lift . tfail . Msg $ "@-pattern not allowed here"
946+ elab' ina fc (PHidden t)
947+ | reflection = elab' ina fc t
949+ = do (h : hs) <- get_holes
950+ -- Dotting a hole means that either the hole or any outer
951+ -- hole (a hole outside any occurrence of it)
952+ -- must be solvable by unification as well as being filled
954+ -- Delay dotted things to the end, then when we elaborate them
955+ -- we can check the result against what was inferred
957+ delayElab $ do focus h
933 elab' ina fc x = fail $ "Unelaboratable syntactic form " ++ showTmImpls x
960 elab' ina fc x = fail $ "Unelaboratable syntactic form " ++ showTmImpls x
962+ delayElab t = updateAux (\e -> e { delayed_elab = delayed_elab e ++ [t] })
935 isScr :: PTerm -> (Name, Binder Term) -> (Name, (Bool, Binder Term))
964 isScr :: PTerm -> (Name, Binder Term) -> (Name, (Bool, Binder Term))
936 isScr (PRef _ n) (n', b) = (n', (n == n', b))
965 isScr (PRef _ n) (n', b) = (n', (n == n', b))
937 isScr _ (n', b) = (n', (False, b))
966 isScr _ (n', b) = (n', (False, b))
@@ -1126,6 +1155,7 @@ pruneByType env t c as
1126 | otherwise = locallyBound ts
1155 | otherwise = locallyBound ts
1127 getName (PRef _ n) = Just n
1156 getName (PRef _ n) = Just n
1128 getName (PApp _ f _) = getName f
1157 getName (PApp _ f _) = getName f
1158+ getName (PHidden t) = getName t
1129 getName _ = Nothing
1159 getName _ = Nothing
1131pruneByType env (P _ n _) ctxt as
1161pruneByType env (P _ n _) ctxt as
@@ -1143,6 +1173,7 @@ pruneByType env (P _ n _) ctxt as
1143 headIs var f (PApp _ (PRef _ f') _) = typeHead var f f'
1173 headIs var f (PApp _ (PRef _ f') _) = typeHead var f f'
1144 headIs var f (PApp _ f' _) = headIs var f f'
1174 headIs var f (PApp _ f' _) = headIs var f f'
1145 headIs var f (PPi _ _ _ sc) = headIs var f sc
1175 headIs var f (PPi _ _ _ sc) = headIs var f sc
1176+ headIs var f (PHidden t) = headIs var f t
1146 headIs _ _ _ = True -- keep if it's not an application
1177 headIs _ _ _ = True -- keep if it's not an application
1148 typeHead var f f'
1179 typeHead var f f'
@@ -2195,6 +2226,7 @@ reflectErr (TooManyArguments n) = raw_apply (Var $ reflErrName "TooManyArguments
2195reflectErr (CantIntroduce t) = raw_apply (Var $ reflErrName "CantIntroduce") [reflect t]
2226reflectErr (CantIntroduce t) = raw_apply (Var $ reflErrName "CantIntroduce") [reflect t]
2196reflectErr (NoSuchVariable n) = raw_apply (Var $ reflErrName "NoSuchVariable") [reflectName n]
2227reflectErr (NoSuchVariable n) = raw_apply (Var $ reflErrName "NoSuchVariable") [reflectName n]
2197reflectErr (WithFnType t) = raw_apply (Var $ reflErrName "WithFnType") [reflect t]
2228reflectErr (WithFnType t) = raw_apply (Var $ reflErrName "WithFnType") [reflect t]
2229+reflectErr (CantMatch t) = raw_apply (Var $ reflErrName "CantMatch") [reflect t]
2198reflectErr (NoTypeDecl n) = raw_apply (Var $ reflErrName "NoTypeDecl") [reflectName n]
2230reflectErr (NoTypeDecl n) = raw_apply (Var $ reflErrName "NoTypeDecl") [reflectName n]
2199reflectErr (NotInjective t1 t2 t3) =
2231reflectErr (NotInjective t1 t2 t3) =
2200 raw_apply (Var $ reflErrName "NotInjective")
2232 raw_apply (Var $ reflErrName "NotInjective")
@@ -2306,7 +2338,7 @@ reifyReportPart (App (P (DCon _ _ _) n _) (Constant (Str msg))) | n == reflm "Te
2306 Right (TextPart msg)
2338 Right (TextPart msg)
2307reifyReportPart (App (P (DCon _ _ _) n _) ttn)
2339reifyReportPart (App (P (DCon _ _ _) n _) ttn)
2308 | n == reflm "NamePart" =
2340 | n == reflm "NamePart" =
2309− case runElab [] (reifyTTName ttn) (initElaborator NErased initContext Erased) of
2341+ case runElab initEState (reifyTTName ttn) (initElaborator NErased initContext Erased) of
2310 Error e -> Left . InternalMsg $
2342 Error e -> Left . InternalMsg $
2311 "could not reify name term " ++
2343 "could not reify name term " ++
2312 show ttn ++
2344 show ttn ++
@@ -2314,7 +2346,7 @@ reifyReportPart (App (P (DCon _ _ _) n _) ttn)
2314 OK (n', _)-> Right $ NamePart n'
2346 OK (n', _)-> Right $ NamePart n'
2315reifyReportPart (App (P (DCon _ _ _) n _) tm)
2347reifyReportPart (App (P (DCon _ _ _) n _) tm)
2316 | n == reflm "TermPart" =
2348 | n == reflm "TermPart" =
2317− case runElab [] (reifyTT tm) (initElaborator NErased initContext Erased) of
2349+ case runElab initEState (reifyTT tm) (initElaborator NErased initContext Erased) of
2318 Error e -> Left . InternalMsg $
2350 Error e -> Left . InternalMsg $
2319 "could not reify reflected term " ++
2351 "could not reify reflected term " ++
2320 show tm ++
2352 show tm ++