on master help sign in
Disambiguation tweak

At the final step, if any elaboration adds new class constraints, reject it in favour of any which do work. This is particularly helpful in the case that there are holes which would otherwise help determine which name is intended.

commit6eaf9332325893bf7295ff29390f64e21f42ef33 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateSun 17 Jan 2016, 21:23 (11 years ago) parent75e34a7
4 files changed+40−27
src/Idris/Core/Elaborate.hs+29−17 src/Idris/Elab/Term.hs+2−2 src/Idris/Interactive.hs+5−1 test/interactive010/expected+4−7
src/Idris/Core/Elaborate.hs+29−17
@@ -863,7 +863,7 @@ try' t1 t2 proofSearch
863863 ps <- get_probs
864864 ulog <- getUnifyLog
865865 ivs <- get_instances
866− case prunStateT 999999 False ps t1 s of
866+ case prunStateT 999999 False ps Nothing t1 s of
867867 OK ((v, _, _), s') -> do put s'
868868 return $! v
869869 Error e1 -> traceWhen ulog ("try failed " ++ show e1) $
@@ -906,8 +906,11 @@ tryWhen False a b = a
906906-- Bool says whether it's okay to create new unification problems. If set
907907-- to False, then the whole tactic fails if there are any new problems
908908tryAll :: [(Elab' aux a, Name)] -> Elab' aux a
909−tryAll [(x, _)] = x
910−tryAll xs = tryAll' [] 999999 xs
909+tryAll = tryAll' True
910+
911+tryAll' :: Bool -> [(Elab' aux a, Name)] -> Elab' aux a
912+tryAll' _ [(x, _)] = x
913+tryAll' constrok xs = doAll [] 999999 xs
911914 where
912915 cantResolve :: Elab' aux a
913916 cantResolve = lift $ tfail $ CantResolveAlts (map snd xs)
@@ -915,44 +918,53 @@ tryAll xs = tryAll' [] 999999 xs
915918 noneValid :: Elab' aux a
916919 noneValid = lift $ tfail $ NoValidAlts (map snd xs)
917920
918− tryAll' :: [Elab' aux a] -> -- successes
919− Int -> -- most problems
920− [(Elab' aux a, Name)] -> -- still to try
921− Elab' aux a
922− tryAll' [res] pmax [] = res
923− tryAll' (_:_) pmax [] = cantResolve
924− tryAll' [] pmax [] = noneValid
925− tryAll' cs pmax ((x, msg):xs)
921+ doAll :: [Elab' aux a] -> -- successes
922+ Int -> -- most problems
923+ [(Elab' aux a, Name)] -> -- still to try
924+ Elab' aux a
925+ doAll [res] pmax [] = res
926+ doAll (_:_) pmax [] = cantResolve
927+ doAll [] pmax [] = noneValid
928+ doAll cs pmax ((x, msg):xs)
926929 = do s <- get
927930 ps <- get_probs
928− case prunStateT pmax True ps x s of
931+ ivs <- get_instances
932+ case prunStateT pmax True ps (if constrok then Nothing
933+ else Just ivs) x s of
929934 OK ((v, newps, probs), s') ->
930935 do let cs' = if (newps < pmax)
931936 then [do put s'; return $! v]
932937 else (do put s'; return $! v) : cs
933− tryAll' cs' newps xs
938+ doAll cs' newps xs
934939 Error err -> do put s
935− tryAll' cs pmax xs
940+ doAll cs pmax xs
936941
937−-- Run an elaborator, and fail if any problems are introduced
942+-- Run an elaborator, and fail if any problems or constraints are introduced
938943prunStateT
939944 :: Int
940945 -> Bool
941946 -> [a]
947+ -> Maybe [b] -- constraints left, if we're interested
942948 -> Control.Monad.State.Strict.StateT
943949 (ElabState t) TC t1
944950 -> ElabState t
945951 -> TC ((t1, Int, Idris.Core.Unify.Fails), ElabState t)
946−prunStateT pmax zok ps x s
952+prunStateT pmax zok ps ivs x s
947953 = case runStateT x s of
948954 OK (v, s'@(ES (p, _) _ _)) ->
949955 let newps = length (problems p) - length ps
956+ ibad = badInstances (instances p) ivs
950957 newpmax = if newps < 0 then 0 else newps in
951958 if (newpmax > pmax || (not zok && newps > 0)) -- length ps == 0 && newpmax > 0))
952959 then case reverse (problems p) of
953960 ((_,_,_,_,e,_,_):_) -> Error e
954− else OK ((v, newpmax, problems p), s')
961+ else if ibad
962+ then Error (InternalMsg "Constraint introduced in disambiguation")
963+ else OK ((v, newpmax, problems p), s')
955964 Error e -> Error e
965+ where
966+ badInstances _ Nothing = False
967+ badInstances inow (Just ithen) = length inow > length ithen
956968
957969debugElaborator :: [ErrorReportPart] -> Elab' aux a
958970debugElaborator msg = do ps <- fmap proof get
src/Idris/Elab/Term.hs+2−2
@@ -464,8 +464,8 @@ elab ist info emode opts fn tm
464464 case as'' of
465465 [x] -> elab' ina fc x
466466 _ -> do hds <- mapM showHd as''
467− tryAll (zip (map (elab' ina fc) as'')
468− hds))
467+ tryAll' False (zip (map (elab' ina fc) as'')
468+ hds))
469469 where showHd (PApp _ (PRef _ _ (UN l)) [_, _, arg])
470470 | l == txt "Delay" = showHd (getTm arg)
471471 showHd (PApp _ (PRef _ _ n) _) = return n
src/Idris/Interactive.hs+5−1
@@ -400,10 +400,14 @@ makeLemma fn updatefile l n
400400 = n : guessImps ist ctxt sc
401401 | isClass ist ty
402402 = n : guessImps ist ctxt sc
403− | TType _ <- ty = n : guessImps ist ctxt sc
403+ | paramty ty = n : guessImps ist ctxt sc
404404 | ignoreName n = n : guessImps ist ctxt sc
405405 | otherwise = guessImps ist ctxt sc
406406 guessImps ist ctxt _ = []
407+
408+ paramty (TType _) = True
409+ paramty (Bind _ (Pi _ (TType _) _) sc) = paramty sc
410+ paramty _ = False
407411
408412 -- TMP HACK unusable name so don't lift
409413 ignoreName n = case show n of
test/interactive010/expected+4−7
@@ -1,15 +1,12 @@
11Prelude.List.(++) : List a -> List a -> List a
22Prelude.Strings.(++) : String -> String -> String
3−Prelude.Classes./ Double
4− Prelude.Classes.Double implementation of Prelude.Classes.Fractional : (__pi_arg : Double) →
5− (__pi_arg3 : Double) →
6− Double
3+a is not an implicit argument of Prelude.Classes./
74Usage is :doc <functionname>
85Usage is :wc <functionname>
96Usage is :printdef <functionname>
10−pat {a504} : Type u. pat {__class505} : Prelude.Classes.Fractional {a504}. Prelude.Classes./ {a504} {__class505}
7+pat {ty504} : Type u. pat {__class505} : Prelude.Classes.Fractional {ty504}. Prelude.Classes./ {ty504} {__class505}
118
12− : pty {a504} : Type u. pty {__class505} : Prelude.Classes.Fractional {a504}. {a504} -> {a504} -> {a504}
9+ : pty {ty504} : Type u. pty {__class505} : Prelude.Classes.Fractional {ty504}. {ty504} -> {ty504} -> {ty504}
1310(input):1:1: error: expected: ":",
1411 dependent type signature,
1512 end of input
@@ -20,4 +17,4 @@ pat {a504} : Type u. pat {__class505} : Prelude.Classes.Fractional {a504}. Prelu
2017 end of input
2118++<EOF>
2219^
23−Can't resolve type class Fractional a
20+Can't resolve type class Fractional ty