-
Notifications
You must be signed in to change notification settings - Fork 1
Add error message to Yield #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,8 +82,8 @@ data Context = Ctx { globalVEnv :: VEnv | |
| mkFork :: String -> Free sig () -> Free sig () | ||
| mkFork d par = thTrace ("Forking " ++ d) $ Fork d par $ pure () | ||
|
|
||
| mkYield :: String -> S.Set End -> Free sig () | ||
| mkYield desc es = thTrace ("Yielding in " ++ desc ++ "\n " ++ show es) $ Yield (AwaitingAny es) (\_ -> trackM ("woke up " ++ desc) >> Ret ()) | ||
| mkYield :: ErrorMsg -> String -> S.Set End -> Free sig () | ||
| mkYield err desc es = thTrace ("Yielding in " ++ desc ++ "\n " ++ show es) $ Yield err (AwaitingAny es) (\n -> trackM ("woke up " ++ desc ++ "\n" ++ show n) >> Ret ()) | ||
|
|
||
| -- Commands for synchronous operations | ||
| data CheckingSig ty where | ||
|
|
@@ -127,7 +127,7 @@ wrapper f (Req s k) = f s >>= \case | |
| Just v -> wrapper f (k v) | ||
| Nothing -> Req s (wrapper f . k) | ||
| wrapper f (Define lbl v e k) = Define lbl v e (wrapper f . k) | ||
| wrapper f (Yield st k) = Yield st (wrapper f . k) | ||
| wrapper f (Yield err st k) = Yield err st (wrapper f . k) | ||
| wrapper f (Fork d par c) = Fork d (wrapper f par) (wrapper f c) | ||
|
|
||
| wrapper2 :: (forall a. CheckingSig a -> Maybe a) -> Checking v -> Checking v | ||
|
|
@@ -238,7 +238,7 @@ localKVar env (Req KDone k) = case [ x | (x,(One,_)) <- M.assocs env ] of | |
| ] | ||
| localKVar env (Req r k) = Req r (localKVar env . k) | ||
| localKVar env (Define lbl e v k) = Define lbl e v (localKVar env . k) | ||
| localKVar env (Yield st k) = Yield st (localKVar env . k) | ||
| localKVar env (Yield err st k) = Yield err st (localKVar env . k) | ||
| localKVar env (Fork desc par c) = | ||
| -- can't send end both ways, so until we can join (TODO), restrict Forks to local scope | ||
| thTrace ("Spawning(LKV) " ++ desc) $ localKVar env $ par *> c | ||
|
|
@@ -253,7 +253,7 @@ catchErr (Ret t) = Ret (Right t) | |
| catchErr (Req (Throw e) _) = pure $ Left e | ||
| catchErr (Req r k) = Req r (catchErr . k) | ||
| catchErr (Define lbl e v k) = Define lbl e v (catchErr . k) | ||
| catchErr (Yield st k) = Yield st (catchErr . k) | ||
| catchErr (Yield err st k) = Yield err st (catchErr . k) | ||
| catchErr (Fork desc par c) = thTrace ("Spawning(catch) " ++ desc) $ catchErr $ par *> c | ||
|
|
||
| handler :: Free CheckingSig v | ||
|
|
@@ -347,10 +347,13 @@ handler (Define lbl end v k) ctx g = let st@Store{typeMap=tm, valueMap=vm} = sto | |
| (M.delete inport (dynamicSet ctx)) | ||
| Nothing -> dynamicSet ctx | ||
| }) g | ||
| handler (Yield Unstuck k) ctx g = handler (k mempty) ctx g | ||
| handler (Yield (AwaitingAny ends) _k) ctx _ = Left $ dumbErr $ TypeErr $ unlines $ | ||
| handler (Yield _err Unstuck k) ctx g = handler (k mempty) ctx g | ||
| handler (Yield err (AwaitingAny ends) _k) ctx _ = Left $ dumbErr $ Both | ||
| (TypeErr $ unlines $ | ||
| ("Typechecking blocked on:":(show <$> S.toList ends)) | ||
| ++ "":"Dynamic set is":(show <$> M.keys (dynamicSet ctx)) ++ ["Try writing more types! :-)"] | ||
| ++ "":"Dynamic set is":(show <$> M.keys (dynamicSet ctx)) | ||
| ++ "":["Try writing more types! :-)"]) | ||
| err | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whether you store |
||
| handler (Fork desc par c) ctx g = handler (thTrace ("Spawning " ++ desc) $ par *> c) ctx g | ||
|
|
||
| type Checking = Free CheckingSig | ||
|
|
@@ -404,7 +407,7 @@ localNS ns (Req (SplitNS str) k) = let (subSpace, newRoot) = split str ns in | |
| localNS ns (Req AskNS k) = localNS ns (k (fst ns)) | ||
| localNS ns (Req c k) = Req c (localNS ns . k) | ||
| localNS ns (Define lbl e v k) = Define lbl e v (localNS ns . k) | ||
| localNS ns (Yield st k) = Yield st (localNS ns . k) | ||
| localNS ns (Yield err st k) = Yield err st (localNS ns . k) | ||
| localNS ns (Fork desc par c) = let (subSpace, newRoot) = split desc ns in | ||
| Fork desc (localNS subSpace par) (localNS newRoot c) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |
|
|
||
| import Brat.FC | ||
| import Data.Bracket | ||
| import Brat.Syntax.Port (PortName) | ||
| import Brat.Syntax.Port (End, PortName) | ||
|
|
||
| import Data.List (intercalate) | ||
| import System.Exit | ||
|
|
@@ -109,6 +109,9 @@ | |
| | ThunkLeftUnders String | ||
| | BracketErr BracketErrMsg | ||
| | RemainingNatHopes [String] | ||
| | NeedToKnow End | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not make this take a Set of Ends? |
||
| | Both ErrorMsg ErrorMsg | ||
| | WaitingForConstraint String | ||
|
|
||
| instance Show ErrorMsg where | ||
| show (TypeErr x) = "Type error: " ++ x | ||
|
|
@@ -194,6 +197,10 @@ | |
| show (ThunkLeftUnders unders) = "Expected function to return additional values of type: " ++ unders | ||
| show (BracketErr msg) = show msg | ||
| show (RemainingNatHopes hs) = unlines ("Expected to work out values for these holes:":((" " ++) <$> hs)) | ||
| show (NeedToKnow end) = unlines ["I wanna know what:", ' ':show end,"is."] | ||
| show (Both err1 err2) = unlines [show err1,""," AND WORSE","",show err2] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. funny to read as the AND WORSE is, it's not necessarily true is it? There's no ordering or reason for the second to be worse than the first, is there? Should we just go with "AND ALSO" ? |
||
| show (WaitingForConstraint msg) = "Waiting for constraint:\n " ++ msg | ||
|
|
||
|
|
||
| data Error = Err { fc :: Maybe FC | ||
| , msg :: ErrorMsg | ||
|
|
@@ -240,8 +247,8 @@ | |
| ls = lines contents | ||
| in case endLineN - startLineN of | ||
| 0 -> [ls!!startLineN, highlightSection startCol endCol] | ||
| n | n > 0 -> let (first:rest) = drop (startLineN - 1) $ take (endLineN + 1) ls | ||
|
Check warning on line 250 in brat/Brat/Error.hs
|
||
| (last:rmid) = reverse rest | ||
|
Check warning on line 251 in brat/Brat/Error.hs
|
||
| in [first, highlightSection startCol (length first)] | ||
| ++ (reverse rmid >>= (\l -> [l, highlightSection 0 (length l)])) | ||
| ++ [last, highlightSection 0 endCol] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
NeedToKnowtook a set of ends, you could drop this ErrorMsg param frommkYieldand have it construct aNeedToKnowusing the set it's given.You might then keep the string, this seems useful as a hint as to where in the code we are blocked.