@@ -1431,12 +1431,14 @@ findHighlight n = do ctxt <- get_context
1431 Nothing -> lift . tfail . InternalMsg $
1431 Nothing -> lift . tfail . InternalMsg $
1432 "Can't find name" ++ show n
1432 "Can't find name" ++ show n
1434−
1434+-- | Find the names of instances that have been designeated for
1435+-- searching (i.e. non-named instances or instances from Elab scripts)
1435findInstances :: IState -> Term -> [Name]
1436findInstances :: IState -> Term -> [Name]
1436findInstances ist t
1437findInstances ist t
1437 | (P _ n _, _) <- unApply (getRetTy t)
1438 | (P _ n _, _) <- unApply (getRetTy t)
1438 = case lookupCtxt n (idris_classes ist) of
1439 = case lookupCtxt n (idris_classes ist) of
1439− [CI _ _ _ _ _ ins _] -> filter accessible ins
1440+ [CI _ _ _ _ _ ins _] ->
1441+ [n | (n, True) <- ins, accessible n]
1441 | otherwise = []
1443 | otherwise = []
1442 where accessible n = case lookupDefAccExact n False (tt_ctxt ist) of
1444 where accessible n = case lookupDefAccExact n False (tt_ctxt ist) of
@@ -1466,11 +1468,10 @@ proofSearch' ist rec ambigok depth prv top n hints
1466 proofSearch rec prv ambigok (not prv) depth
1468 proofSearch rec prv ambigok (not prv) depth
1467 (elab ist toplevel ERHS [] (sMN 0 "tac")) top n hints ist
1469 (elab ist toplevel ERHS [] (sMN 0 "tac")) top n hints ist
1469−-- Resolve type classes. This will only pick up 'normal' instances, never
1471+-- | Resolve type classes. This will only pick up 'normal' instances, never
1470−-- named instances (hence using 'tcname' to check it's a generated instance
1472+-- named instances (which is enforced by 'findInstances').
1472resolveTC :: Bool -- using default Int
1473resolveTC :: Bool -- using default Int
1473− -> Bool -- allow metavariables in the goal
1474+ -> Bool -- allow metavariables in the goal
1474 -> Int -- depth
1475 -> Int -- depth
1475 -> Term -- top level goal
1476 -> Term -- top level goal
1476 -> Name -- top level function name
1477 -> Name -- top level function name
@@ -1527,9 +1528,6 @@ resTC' tcs defaultOn topholes depth topg fn ist
1527 | Constant _ <- c = not (n `elem` hs)
1528 | Constant _ <- c = not (n `elem` hs)
1528 notHole _ _ = True
1529 notHole _ _ = True
1530− elabTC n | n /= fn && tcname n = (resolve n depth, show n)
1531− | otherwise = (fail "Can't resolve", show n)
1533 -- HACK! Rather than giving a special name, better to have some kind
1531 -- HACK! Rather than giving a special name, better to have some kind
1534 -- of flag in ClassInfo structure
1532 -- of flag in ClassInfo structure
1535 chaser (UN nm)
1533 chaser (UN nm)
@@ -1555,11 +1553,11 @@ resTC' tcs defaultOn topholes depth topg fn ist
1555 -- ps <- get_probs
1553 -- ps <- get_probs
1556 lift $ tfail $ CantResolve False topg
1554 lift $ tfail $ CantResolve False topg
1557 blunderbuss t d stk (n:ns)
1555 blunderbuss t d stk (n:ns)
1558− | n /= fn && (n `elem` stk || tcname n)
1556+ | n /= fn -- && (n `elem` stk)
1559− = tryCatch (resolve n d)
1557+ = tryCatch (resolve n d)
1560 (\e -> case e of
1558 (\e -> case e of
1561 CantResolve True _ -> lift $ tfail e
1559 CantResolve True _ -> lift $ tfail e
1562− _ -> blunderbuss t d stk ns)
1560+ _ -> blunderbuss t d stk ns)
1563 | otherwise = blunderbuss t d stk ns
1561 | otherwise = blunderbuss t d stk ns
1565 introImps = do g <- goal
1563 introImps = do g <- goal
@@ -1888,6 +1886,12 @@ runTactical fc env tm = do tm' <- eval tm
1888 = do defn <- reifyFunDefn decl
1886 = do defn <- reifyFunDefn decl
1889 defineFunction defn
1887 defineFunction defn
1890 returnUnit
1888 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 :
1891 | n == tacN "prim__RecursiveElab", [goal, script] <- args
1895 | n == tacN "prim__RecursiveElab", [goal, script] <- args
1892 = do goal' <- reifyRaw goal
1896 = do goal' <- reifyRaw goal
1893 ctxt <- get_context
1897 ctxt <- get_context
@@ -2266,6 +2270,12 @@ processTacticDecls info steps =
2266 let ds' = map (\(n, (i, top, t)) -> (n, (i, top, t, True))) ds
2270 let ds' = map (\(n, (i, top, t)) -> (n, (i, top, t, True))) ds
2267 in addDeferred ds'
2271 in addDeferred ds'
2268 _ -> return ()
2272 _ -> 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)
2269 RClausesInstrs n cs ->
2279 RClausesInstrs n cs ->
2270 do logLvl 3 $ "Pattern-matching definition from tactics: " ++ show n
2280 do logLvl 3 $ "Pattern-matching definition from tactics: " ++ show n
2271 solveDeferred n
2281 solveDeferred n