@@ -1431,12 +1431,14 @@ findHighlight n = do ctxt <- get_context
14311431 Nothing -> lift . tfail . InternalMsg $
14321432 "Can't find name" ++ show n
14331433
1434−
1434+-- | Find the names of instances that have been designeated for
1435+-- searching (i.e. non-named instances or instances from Elab scripts)
14351436findInstances :: IState -> Term -> [Name]
14361437findInstances ist t
14371438 | (P _ n _, _) <- unApply (getRetTy t)
14381439 = case lookupCtxt n (idris_classes ist) of
1439− [CI _ _ _ _ _ ins _] -> filter accessible ins
1440+ [CI _ _ _ _ _ ins _] ->
1441+ [n | (n, True) <- ins, accessible n]
14401442 _ -> []
14411443 | otherwise = []
14421444 where accessible n = case lookupDefAccExact n False (tt_ctxt ist) of
@@ -1466,11 +1468,10 @@ proofSearch' ist rec ambigok depth prv top n hints
14661468 proofSearch rec prv ambigok (not prv) depth
14671469 (elab ist toplevel ERHS [] (sMN 0 "tac")) top n hints ist
14681470
1469−-- Resolve type classes. This will only pick up 'normal' instances, never
1470−-- named instances (hence using 'tcname' to check it's a generated instance
1471−-- name).
1471+-- | Resolve type classes. This will only pick up 'normal' instances, never
1472+-- named instances (which is enforced by 'findInstances').
14721473resolveTC :: Bool -- using default Int
1473− -> Bool -- allow metavariables in the goal
1474+ -> Bool -- allow metavariables in the goal
14741475 -> Int -- depth
14751476 -> Term -- top level goal
14761477 -> Name -- top level function name
@@ -1527,9 +1528,6 @@ resTC' tcs defaultOn topholes depth topg fn ist
15271528 | Constant _ <- c = not (n `elem` hs)
15281529 notHole _ _ = True
15291530
1530− elabTC n | n /= fn && tcname n = (resolve n depth, show n)
1531− | otherwise = (fail "Can't resolve", show n)
1532−
15331531 -- HACK! Rather than giving a special name, better to have some kind
15341532 -- of flag in ClassInfo structure
15351533 chaser (UN nm)
@@ -1555,11 +1553,11 @@ resTC' tcs defaultOn topholes depth topg fn ist
15551553 -- ps <- get_probs
15561554 lift $ tfail $ CantResolve False topg
15571555 blunderbuss t d stk (n:ns)
1558− | n /= fn && (n `elem` stk || tcname n)
1559− = tryCatch (resolve n d)
1556+ | n /= fn -- && (n `elem` stk)
1557+ = tryCatch (resolve n d)
15601558 (\e -> case e of
15611559 CantResolve True _ -> lift $ tfail e
1562− _ -> blunderbuss t d stk ns)
1560+ _ -> blunderbuss t d stk ns)
15631561 | otherwise = blunderbuss t d stk ns
15641562
15651563 introImps = do g <- goal
@@ -1888,6 +1886,12 @@ runTactical fc env tm = do tm' <- eval tm
18881886 = do defn <- reifyFunDefn decl
18891887 defineFunction defn
18901888 returnUnit
1889+ | n == tacN "prim__AddInstance", [cls, inst] <- args
1890+ = do className <- reifyTTName cls
1891+ instName <- reifyTTName inst
1892+ updateAux $ \e -> e { new_tyDecls = RAddInstance className instName :
1893+ new_tyDecls e}
1894+ returnUnit
18911895 | n == tacN "prim__RecursiveElab", [goal, script] <- args
18921896 = do goal' <- reifyRaw goal
18931897 ctxt <- get_context
@@ -2266,6 +2270,12 @@ processTacticDecls info steps =
22662270 let ds' = map (\(n, (i, top, t)) -> (n, (i, top, t, True))) ds
22672271 in addDeferred ds'
22682272 _ -> return ()
2273+ RAddInstance className instName ->
2274+ do -- The type class resolution machinery relies on a special
2275+ logLvl 2 $ "Adding elab script instance " ++ show instName ++
2276+ " for " ++ show className
2277+ addInstance False True className instName
2278+ addIBC (IBCInstance False True className instName)
22692279 RClausesInstrs n cs ->
22702280 do logLvl 3 $ "Pattern-matching definition from tactics: " ++ show n
22712281 solveDeferred n