on master help sign in
Remove dodgy unification hack

Also need to recheck unification problems immediately after setting injective arguments, or we get strange results for disambiguation. Fixes #1372

commit8ed343ba6adcb3dbf01ce2b6313206774401f4db authorEdwin Brady <ecb10@st-andrews.ac.uk> dateFri 11 Jul 2014, 14:26 (12 years ago) parentb7756f2
10 files changed+72−37
idris.cabal+3 libs/neweffects/Effect/State.idr+2−2 src/Idris/Core/Elaborate.hs+4−2 src/Idris/Core/ProofState.hs+1−1 src/Idris/Core/Unify.hs+2−8 src/Idris/ElabTerm.hs+37−23 test/error003/ErrorReflection.idr+1−1 test/reg046/expected test/reg046/reg046.idr+19 test/reg046/run+3
idris.cabal+3
@@ -240,6 +240,9 @@ Extra-source-files:
240240 test/reg045/run
241241 test/reg045/*.idr
242242 test/reg045/expected
243+ test/reg046/run
244+ test/reg046/*.idr
245+ test/reg046/expected
243246
244247 test/basic001/run
245248 test/basic001/*.idr
libs/neweffects/Effect/State.idr+2−2
@@ -8,8 +8,8 @@ data State : Effect where
88 Get : { a } State a
99 Put : b -> { a ==> b } State ()
1010
11−using (m : Type -> Type)
12− instance Handler State m where
11+-- using (m : Type -> Type)
12+instance Handler State m where
1313 handle st Get k = k st st
1414 handle st (Put n) k = k () n
1515
src/Idris/Core/Elaborate.hs+4−2
@@ -514,8 +514,10 @@ apply' fillt fn imps =
514514 put (ES (p { dontunify = dont, unified = (n, unify),
515515 notunified = notunify ++ notunified p }, a) s prev)
516516 fillt (raw_apply fn (map (Var . snd) args))
517−-- trace ("Goal " ++ show g ++ "\n" ++ show (fn, imps, unify) ++ "\n" ++ show ptm) $
518− end_unify
517+ ulog <- getUnifyLog
518+ g <- goal
519+ traceWhen ulog ("Goal " ++ show g ++ " -- when elaborating " ++ show fn) $
520+ end_unify
519521 return $! (map (\(argName, argHole) -> (argName, updateUnify unify argHole)) args)
520522 where updateUnify us n = case lookup n us of
521523 Just (P _ t _) -> t
src/Idris/Core/ProofState.hs+1−1
@@ -871,7 +871,7 @@ updateNotunified ns nu = up nu where
871871
872872updateProblems :: Context -> [(Name, TT Name)] -> Fails -> [Name] -> [Name]
873873 -> ([(Name, TT Name)], Fails)
874−updateProblems ctxt [] ps inj holes = ([], ps)
874+-- updateProblems ctxt [] ps inj holes = ([], ps)
875875updateProblems ctxt ns ps inj holes = up ns ps where
876876 up ns [] = (ns, [])
877877 up ns ((x, y, env, err, while, um) : ps) =
src/Idris/Core/Unify.hs+2−8
@@ -428,18 +428,12 @@ unify ctxt env topx topy inj holes from =
428428
429429 unApp fn bnames appx@(App fx ax) appy@(App fy ay)
430430 | (injectiveApp fx && injectiveApp fy)
431− || (injectiveApp fx && rigid appx && metavarApp appy && numArgs appx == numArgs appy)
432− || (injectiveApp fy && rigid appy && metavarApp appx && numArgs appx == numArgs appy)
433431 || (injectiveApp fx && metavarApp fy && ax == ay)
434432 || (injectiveApp fy && metavarApp fx && ax == ay)
435433 = do let (headx, _) = unApply fx
436434 let (heady, _) = unApply fy
437435 -- fail quickly if the heads are disjoint
438436 checkHeads headx heady
439−-- if True then -- (injective fx || injective fy || fx == fy) then
440−-- if (injective fx && metavarApp appy) ||
441−-- (injective fy && metavarApp appx) ||
442−-- (injective fx && injective fy) || fx == fy
443437 uplus
444438 (do hf <- un' True bnames fx fy
445439 let ax' = hnormalise hf ctxt env (substNames hf ax)
@@ -624,9 +618,9 @@ envPos x i ((y, _) : ys) | x == y = i
624618-- ASSUMPTION: inputs are in normal form
625619
626620recoverable t@(App _ _) _
627− | (P _ (UN l) _, _) <- unApply t, l == txt "Lazy" = False
621+ | (P _ (UN l) _, _) <- unApply t, l == txt "Lazy'" = False
628622recoverable _ t@(App _ _)
629− | (P _ (UN l) _, _) <- unApply t, l == txt "Lazy" = False
623+ | (P _ (UN l) _, _) <- unApply t, l == txt "Lazy'" = False
630624recoverable (P (DCon _ _) x _) (P (DCon _ _) y _) = x == y
631625recoverable (P (TCon _ _) x _) (P (TCon _ _) y _) = x == y
632626recoverable (Constant _) (P (DCon _ _) y _) = False
src/Idris/ElabTerm.hs+37−23
@@ -245,12 +245,8 @@ elab ist info emode opts fn tm
245245 elab' ina (PResolveTC (FC "HACK" _ _)) -- for chasing parent classes
246246 = do g <- goal; resolveTC 5 g fn ist
247247 elab' ina (PResolveTC fc)
248− | True = do c <- getNameFrom (sMN 0 "class")
249− instanceArg c
250− | otherwise = do g <- goal
251− try (resolveTC 2 g fn ist)
252− (do c <- getNameFrom (sMN 0 "class")
253− instanceArg c)
248+ = do c <- getNameFrom (sMN 0 "class")
249+ instanceArg c
254250 elab' ina (PRefl fc t)
255251 = elab' ina (PApp fc (PRef fc eqCon) [pimp (sMN 0 "A") Placeholder True,
256252 pimp (sMN 0 "x") t False])
@@ -485,7 +481,9 @@ elab ist info emode opts fn tm
485481 -- we can unify with them
486482 case lookupCtxt f (idris_classes ist) of
487483 [] -> return ()
488− _ -> mapM_ setInjective (map getTm args)
484+ _ -> do mapM_ setInjective (map getTm args)
485+ -- maybe more things are solvable now
486+ unifyProblems
489487 ctxt <- get_context
490488 let guarded = isConName f ctxt
491489-- trace ("args is " ++ show args) $ return ()
@@ -498,10 +496,11 @@ elab ist info emode opts fn tm
498496 -- Sort so that the implicit tactics and alternatives go last
499497 let (ns', eargs) = unzip $
500498 sortBy cmpArg (zip ns args)
499+ ulog <- getUnifyLog
501500 elabArgs ist (ina || not isinf, guarded, inty, qq)
502501 [] fc False f ns'
503502 (f == sUN "Force")
504− (map (\x -> (False, getTm x)) eargs) -- TODO: remove this False arg
503+ (map (\x -> getTm x) eargs) -- TODO: remove this False arg
505504 solve
506505 ivs' <- get_instances
507506 -- Attempt to resolve any type classes which have 'complete' types,
@@ -525,16 +524,23 @@ elab ist info emode opts fn tm
525524 -- FIXME: Better would be to allow alternative resolution to be
526525 -- retried after more information is in.
527526 cmpArg (_, x) (_, y)
527+ | constraint x && not (constraint y) = LT
528+ | constraint y && not (constraint x) = GT
529+ | otherwise
528530 = compare (conDepth 0 (getTm x) + priority x + alt x)
529531 (conDepth 0 (getTm y) + priority y + alt y)
530532 where alt t = case getTm t of
531533 PAlternative False _ -> 5
532− PAlternative True _ -> 1
534+ PAlternative True _ -> 2
533535 PTactics _ -> 150
534− PLam _ _ _ -> 2
535− PRewrite _ _ _ _ -> 3
536− _ -> 0
537−
536+ PLam _ _ _ -> 3
537+ PRewrite _ _ _ _ -> 4
538+ PResolveTC _ -> 0
539+ _ -> 1
540+
541+ constraint (PConstraint _ _ _ _) = True
542+ constraint _ = False
543+
538544 -- Score a point for every level where there is a non-constructor
539545 -- function (so higher score --> done later)
540546 -- Only relevant when on lhs
@@ -546,6 +552,7 @@ elab ist info emode opts fn tm
546552 conDepth d (PPatvar _ _) = 0
547553 conDepth d (PAlternative _ as) = maximum (map (conDepth d) as)
548554 conDepth d Placeholder = 0
555+ conDepth d (PResolveTC _) = 0
549556 conDepth d t = max (100 - d) 1
550557
551558 checkIfInjective n = do
@@ -558,7 +565,14 @@ elab ist info emode opts fn tm
558565 case lookupCtxt c (idris_classes ist) of
559566 [] -> return ()
560567 _ -> -- type class, set as injective
561− mapM_ setinjArg args
568+ do mapM_ setinjArg args
569+ -- maybe we can solve more things now...
570+ ulog <- getUnifyLog
571+ probs <- get_probs
572+ traceWhen ulog ("Injective now " ++ show args ++ "\n" ++ qshow probs) $
573+ unifyProblems
574+ probs <- get_probs
575+ traceWhen ulog (qshow probs) $ return ()
562576 _ -> return ()
563577
564578 setinjArg (P _ n _) = setinj n
@@ -832,17 +846,13 @@ elab ist info emode opts fn tm
832846 -> Name -- ^ Name of the function being applied
833847 -> [(Name, Name)] -- ^ (Argument Name, Hole Name)
834848 -> Bool -- ^ under a 'force'
835− -> [(Bool, PTerm)] -- ^ (Laziness, argument)
849+ -> [PTerm] -- ^ (Laziness, argument)
836850 -> ElabD ()
837851 elabArgs ist ina failed fc retry f [] force _ = return ()
838− elabArgs ist ina failed fc r f (n:ns) force ((_, Placeholder) : args)
852+ elabArgs ist ina failed fc r f (n:ns) force (Placeholder : args)
839853 = elabArgs ist ina failed fc r f ns force args
840− elabArgs ist ina failed fc r f ((argName, holeName):ns) force ((lazy, t) : args)
841− | lazy && not pattern
842− = elabArg argName holeName (PApp bi (PRef bi (sUN "Delay"))
843− [pimp (sUN "a") Placeholder True,
844− pexp t])
845− | otherwise = elabArg argName holeName t
854+ elabArgs ist ina failed fc r f ((argName, holeName):ns) force (t : args)
855+ = do elabArg argName holeName t
846856 where elabArg argName holeName t =
847857 do now_elaborating fc f argName
848858 wrapErr f argName $ do
@@ -854,7 +864,11 @@ elab ist info emode opts fn tm
854864 failed' <- -- trace (show (n, t, hs, tm)) $
855865 -- traceWhen (not (null cs)) (show ty ++ "\n" ++ showImp True t) $
856866 case holeName `elem` hs of
857− True -> do focus holeName; elab ina t; return failed
867+ True -> do focus holeName;
868+ g <- goal
869+ ulog <- getUnifyLog
870+ traceWhen ulog ("Elaborating argument " ++ show (argName, holeName, g)) $
871+ elab ina t; return failed
858872 False -> return failed
859873 done_elaborating_arg f argName
860874 elabArgs ist ina failed fc r f ns force args
test/error003/ErrorReflection.idr+1−1
@@ -58,7 +58,7 @@ dslerr (CantUnify _ tm1 tm2 _ _ _) = do tm1' <- getTmTy tm1
5858 tm2' <- getTmTy tm2
5959 ty1 <- reifyTy tm1'
6060 ty2 <- reifyTy tm2'
61− return [TextPart $ "DSL type error: " ++ (show ty1) ++ " doesn't match " ++(show ty2)]
61+ Just [TextPart $ "DSL type error: " ++ (show ty1) ++ " doesn't match " ++(show ty2)]
6262dslerr _ = Nothing
6363
6464
test/reg046/expectednew file

No changes to the content.

test/reg046/reg046.idrnew file+19
@@ -0,0 +1,19 @@
1+module test
2+
3+data MyList : (A : Type) -> Type where
4+ nil : (A : Type) -> MyList A
5+ cons : (A : Type) -> A -> MyList A -> MyList A
6+
7+elimList : (A : Type) ->
8+ (m : MyList A -> Type) ->
9+ (f1 : m (nil A)) ->
10+ (f2 : (a : A) -> (as : MyList A) -> m as -> m (cons A a as)) ->
11+ (e : MyList A) ->
12+ m e
13+elimList A m f1 f2 (nil A) = f1
14+elimList A m f1 f2 (cons A a as) = f2 a as (elimList A m f1 f2 as)
15+
16+append : (A : Type) -> (b : MyList A) -> (c : MyList A) -> MyList A
17+append A b c = (elimList A (\ d => MyList A) c
18+ (\ d => \ e => \ f => cons A d f)
19+ b)
test/reg046/runnew file+3
@@ -0,0 +1,3 @@
1+#!/usr/bin/env bash
2+idris $@ reg046.idr --check
3+rm -f reg046 *.ibc