Get GlobalHint flag right

'True' means a default hint, which is only used if all else fails (and
is only really intended to get default Integer)
This commit is contained in:
Edwin Brady 2019-06-15 12:42:35 +01:00
parent c121910298
commit a7bf075c94
8 changed files with 43 additions and 28 deletions

View File

@ -412,7 +412,9 @@ searchType {vars} fc rigc defaults depth def top env target
tryGroups nty [] = throw (CantSolveGoal fc [] top) tryGroups nty [] = throw (CantSolveGoal fc [] top)
tryGroups nty (g :: gs) tryGroups nty (g :: gs)
= handleUnify = handleUnify
(searchNames fc rigc defaults depth def top env g nty) (do logC 5 (do gn <- traverse getFullName g
pure ("Search: Trying names " ++ show gn))
searchNames fc rigc defaults depth def top env g nty)
(\err => if ambig err || isNil gs (\err => if ambig err || isNil gs
then throw err then throw err
else tryGroups nty gs) else tryGroups nty gs)
@ -427,7 +429,8 @@ searchType {vars} fc rigc defaults depth def top env target
Core.Unify.search fc rigc defaults depth def top_in env Core.Unify.search fc rigc defaults depth def top_in env
= do defs <- get Ctxt = do defs <- get Ctxt
top <- normaliseScope defs env top_in top <- normaliseScope defs env top_in
logTerm 10 "Initial target: " top logTerm 2 "Initial target: " top
log 2 $ "Running search with defaults " ++ show defaults
tm <- searchType fc rigc defaults depth def tm <- searchType fc rigc defaults depth def
(abstractEnvType fc env top) env (abstractEnvType fc env top) env
top top

View File

@ -945,9 +945,9 @@ getSearchData fc defaults target
Just hs => hs Just hs => hs
Nothing => [] Nothing => []
if defaults if defaults
then let defaults = map fst (filter isDefault then let defns = map fst (filter isDefault
(toList (autoHints defs))) in (toList (autoHints defs))) in
pure (MkSearchData [] [defaults]) pure (MkSearchData [] [defns])
else let opens = map fst (toList (openHints defs)) else let opens = map fst (toList (openHints defs))
autos = map fst (filter (not . isDefault) autos = map fst (filter (not . isDefault)
(toList (autoHints defs))) (toList (autoHints defs)))

View File

@ -1013,7 +1013,12 @@ retryGuess mode smode (hid, (loc, hname))
Just def => Just def =>
case definition def of case definition def of
BySearch rig depth defining => BySearch rig depth defining =>
handleUnify case smode of
LastChance =>
do log 5 $ "Last chance at " ++ show hname
search loc rig False depth defining (type def) []
pure True
_ => handleUnify
(do tm <- search loc rig (smode == Defaults) depth defining (do tm <- search loc rig (smode == Defaults) depth defining
(type def) [] (type def) []
let gdef = record { definition = PMDef [] (STerm tm) (STerm tm) [] } def let gdef = record { definition = PMDef [] (STerm tm) (STerm tm) [] } def

View File

@ -968,9 +968,9 @@ fnDirectOpt
= do exactIdent "hint" = do exactIdent "hint"
pure (Hint True) pure (Hint True)
<|> do exactIdent "globalhint" <|> do exactIdent "globalhint"
pure (GlobalHint True)
<|> do exactIdent "defaulthint"
pure (GlobalHint False) pure (GlobalHint False)
<|> do exactIdent "defaulthint"
pure (GlobalHint True)
<|> do exactIdent "inline" <|> do exactIdent "inline"
pure Inline pure Inline
<|> do exactIdent "extern" <|> do exactIdent "extern"
@ -1381,6 +1381,9 @@ command
<|> do symbol ":"; keyword "total" <|> do symbol ":"; keyword "total"
n <- name n <- name
pure (Total n) pure (Total n)
<|> do symbol ":"; replCmd ["log", "logging"]
i <- intLit
pure (SetLog (fromInteger i))
<|> do symbol ":"; cmd <- editCmd <|> do symbol ":"; cmd <- editCmd
pure (Editing cmd) pure (Editing cmd)
<|> do tm <- expr EqOK "(interactive)" init <|> do tm <- expr EqOK "(interactive)" init

View File

@ -521,6 +521,10 @@ process (DebugInfo n)
process (SetOpt opt) process (SetOpt opt)
= do setOpt opt = do setOpt opt
pure True pure True
process (SetLog lvl)
= do setLogLevel lvl
iputStrLn $ "Log level to set " ++ show lvl
pure True
process (Editing cmd) process (Editing cmd)
= do ppopts <- getPPrint = do ppopts <- getPPrint
-- Since we're working in a local environment, don't do the usual -- Since we're working in a local environment, don't do the usual

View File

@ -271,6 +271,7 @@ data REPLCmd : Type where
CD : String -> REPLCmd CD : String -> REPLCmd
Missing : Name -> REPLCmd Missing : Name -> REPLCmd
Total : Name -> REPLCmd Total : Name -> REPLCmd
SetLog : Nat -> REPLCmd
Editing : EditCmd -> REPLCmd Editing : EditCmd -> REPLCmd
Quit : REPLCmd Quit : REPLCmd

View File

@ -156,8 +156,7 @@ mutual
-- Flag means the hint is a direct hint, not a function which might -- Flag means the hint is a direct hint, not a function which might
-- find the result (e.g. chasing parent interface dictionaries) -- find the result (e.g. chasing parent interface dictionaries)
Hint : Bool -> FnOpt Hint : Bool -> FnOpt
-- flag means always use this in search. If not set, it is only -- Flag means to use as a default if all else fails
-- used as a hint if all else fails (i.e. a default)
GlobalHint : Bool -> FnOpt GlobalHint : Bool -> FnOpt
ExternFn : FnOpt ExternFn : FnOpt
-- assume safe to cancel arguments in unification -- assume safe to cancel arguments in unification