-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: Human-friendly metavariable printing #54
base: main
Are you sure you want to change the base?
Conversation
Naming. I reckon the current Then, the names here that we show to the user can be UserName...? Failing that, hmmm, VarName? It's not good as many of our names can stand for variables. UserVarName is too long and directs me back down the QualName route. SourceCodeName, also too long - and we can't abbreviate to SrcName because we have Src's everywhere. EDIT: VisName (yes short for visible), SurfaceName? |
e0963ab
to
303025f
Compare
303025f
to
42e299d
Compare
42e299d
to
4e06428
Compare
ensureEmpty str xs = err $ InternalError $ "Expected empty " ++ str ++ ", got:\n " ++ showSig (rowToSig xs) | ||
ensureEmpty str xs = do | ||
nm <- req AskNames | ||
err $ InternalError $ "Expected empty " ++ str ++ ", got:\n " ++ showRow nm xs |
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.
I guess there is no easy equivalent of format!
that we can partially apply to give a function from (string to insert into the middle) -> (another string with that inserted) ?
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.
Not as far as I'm aware 😔
@@ -85,7 +85,7 @@ instance Show (Term d k) where | |||
show (VHole (name, _)) = '?' : name | |||
show Empty = "()" | |||
show (a :|: b) = bracket PJuxtPull a ++ ", " ++ bracket PJuxtPull b | |||
show Pass = "pass" | |||
show Pass = ".." |
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.
??
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.
This is a drive-by fix - the surface syntax for the Pass
operator is ..
, not pass
brat/Brat/Syntax/Value.hs
Outdated
where | ||
arrow = case modey :: Modey m of | ||
Braty -> "->" | ||
Kerny -> "-o" | ||
|
||
instance MODEY m => Show (CTy m n) where | ||
show = showWithMetas M.empty |
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.
This sounds like we'll end up showing CTy's without user-names by accident....do we really need it?
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.
I think you're right. 9c5f374d addresses this and most of the other comments
brat/Brat/Syntax/Value.hs
Outdated
where | ||
helper :: MODEY m => Some (Ro m n) -> String | ||
helper (Some ro) = show ro | ||
instance MODEY m => Show (Ro m bot top) where |
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.
similarly
show (NumValue 0 g) = show g | ||
show (NumValue n Constant0) = show n | ||
show (NumValue n g) = show n ++ " + " ++ show g | ||
instance ShowWithMetas x => ShowWithMetas (NumVal x) where |
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.
Hmmm, how about fmap
-ing showWithMetas
over the variable to give a NumVal String
(or NumVal
of something that can be Show
n)
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.
This does kinda work, in that it saves a bunch of code, but results in error messages containing significantly more quotes - as show
on a string produces that string in quotes. So maybe not. Shame!
@@ -602,3 +660,13 @@ stkLen (zx :<< _) = Sy (stkLen zx) | |||
numValIsConstant :: NumVal (VVar Z) -> Maybe Integer | |||
numValIsConstant (NumValue up Constant0) = pure up | |||
numValIsConstant _ = Nothing | |||
|
|||
showRow :: ShowWithMetas ty => M.Map End String -> [(NamedPort e, ty)] -> String |
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.
Hmmm, this now looks a bit like
instance ShowWithMetas ty => ShowWithMetas [(NamedPort e, ty)]
Although just using showWithMetas
when we used to use showRow
might be quite a jump...
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.
I'm not sure about replacing showRow
like this... showRow definitely needs to
showWithMetasbecause it's makes a user facing string, but I'm not sure that encompasses all uses of the
Ro` data structure
@@ -164,6 +174,8 @@ deriving instance Eq io => Eq (CType' io) | |||
instance Semigroup (CType' (PortName, ty)) where | |||
(ss :-> ts) <> (us :-> vs) = (ss <> us) :-> (ts <> vs) | |||
|
|||
type UserNameMap = M.Map End String |
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.
How about calling this NamesForMetas
or NamesForEnds
? (Is "Metas" a new term in this PR and if so do we want to suddenly introduce it like so, or is it a term we've been using in the code previously?
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.
I don't think "Metas" is a term used in the code base per se, but it certainly comes up when talking about the code base! Otherwise we'd refer to these as global Names
? For this reason, I'm reluctant to call the things we call the Name
s "Names" 😅
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.
Ok, I have come round to calling this UserNameMap
(or UserNamesForEnds
I guess). But I think we should probably rename ShowWithMetas
to Show(With)UserNames
.
4e06428
to
ff0481d
Compare
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.
Ok, looking good, let's
- separate out from fix: False positive in type equality #75 (or base off that if you think that'll resolve first!)
- rename ShowWithMetas. Really it's "show with usernames for metas" so I think that's probably just ShowUserNames or ShowWithUserNames (how about ShowUserNamed ?)
- what's going on with refactor: Use a structure with variable names and port names #23 ? Is that a tidyup of this? would it replace the yet-another-thing-in-the-store?
- I will have a quick go about my
NumVal
fmap
suggestion and see if it doesn't work
@@ -67,8 +69,10 @@ pull1PortRo :: MODEY m | |||
-- TODO: Make an `Error` constructor for this | |||
pull1PortRo _ p _ R0 = fail $ "Port not found: " ++ p | |||
pull1PortRo m p stuff (RPr (p', ty) ro) | |||
| p == p' = if portNameExists m p ro | |||
then err (AmbiguousPortPull p (show (RPr (p', ty) ro))) | |||
| p == p' = do |
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.
Good to keep the scope small, this doesn't cost you anything in line count:
| p == p' = do | |
| p == p' = if portNameExists m p ro | |
then do | |
names <- req AskNames | |
err (AmbiguousPortPull p (showWithMetas names (RPr (p', ty) ro))) | |
else pure ((p', ty), rebuildRo m ro (stuff <>> [])) |
@@ -281,6 +283,12 @@ handler (Req s k) ctx g | |||
if M.member e hset | |||
then handler (k ()) (ctx { hopes = M.delete e hset }) g | |||
else Left (dumbErr (InternalError ("Trying to remove unknown Hope: " ++ show e))) | |||
NameMeta end name -> let names = userNames (store ctx) in | |||
case M.lookup end names of | |||
Just oldName -> error $ "Trying to name end (" ++ show end ++ ")\nas " ++ show name ++ " but it's already called " ++ oldName |
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.
The \n
in the middle here looks a bit weird, is that what you want?
@@ -83,8 +83,11 @@ typeEqEta tm stuff@(ny :* _ks :* _sems) hopes k exp act = do | |||
when (or [M.member ie hopes | InEnd ie <- ends]) $ typeErr "ends were in hopeset" | |||
case ends of | |||
[] -> typeEqRigid tm stuff k exp act -- easyish, both rigid i.e. already defined | |||
[e1, e2] | e1 == e2 -> pure () -- trivially same, even if both still yet-to-be-defined | |||
_es -> error "TODO: must wait for one or the other to become more defined" | |||
-- variables are trivially the same, even if undefined, but the values may |
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.
Looks like this PR has got muddled up with #75
@@ -193,6 +193,9 @@ unify l k r = do | |||
|
|||
-- Solve a metavariable statically - don't do anything dynamic | |||
-- Once a metavariable is solved, we expect to not see it again in a normal form. | |||
-- | |||
-- N.B. We should try harder to preserve order here for more comprehensible |
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.
How about a tracking issue with all the ways to improve error messages ;)
@@ -64,11 +66,11 @@ writeDot libDirs file out = do | |||
isMain _ = False | |||
-} | |||
|
|||
newtype CompilingHoles = CompilingHoles [TypedHole] | |||
data CompilingHoles = CompilingHoles UserNameMap [TypedHole] |
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.
Worth adding a comment that this is an error. Or just rename to CompilingHolesError
then pure (Right ()) | ||
else do | ||
names <- req AskNames | ||
let msg = TypeMismatch tm (showWithMetas names exp) (showWithMetas names act) |
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.
let msg =
--> pure $ Left $
@@ -164,6 +174,8 @@ deriving instance Eq io => Eq (CType' io) | |||
instance Semigroup (CType' (PortName, ty)) where | |||
(ss :-> ts) <> (us :-> vs) = (ss <> us) :-> (ts <> vs) | |||
|
|||
type UserNameMap = M.Map End String |
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.
Ok, I have come round to calling this UserNameMap
(or UserNamesForEnds
I guess). But I think we should probably rename ShowWithMetas
to Show(With)UserNames
.
@@ -281,6 +283,12 @@ handler (Req s k) ctx g | |||
if M.member e hset | |||
then handler (k ()) (ctx { hopes = M.delete e hset }) g | |||
else Left (dumbErr (InternalError ("Trying to remove unknown Hope: " ++ show e))) | |||
NameMeta end name -> let names = userNames (store ctx) in |
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.
How about making the name an extra Maybe parameter to Declare
?
(I say Maybe - we could then even turn Nothings into integer indices, say, to make them more compact than the rather-complex VPar End notation. Using len nameMap
or something)
@@ -125,18 +129,25 @@ pullPorts toPort showFn to_pull types = | |||
([found], remaining) -> pure (found, remaining) | |||
(_, _) -> err $ AmbiguousPortPull p (showFn available) | |||
|
|||
ensureEmpty :: Show ty => String -> [(NamedPort e, ty)] -> Checking () | |||
combineDisjointEnvs :: M.Map QualName v -> M.Map QualName v -> Checking (M.Map QualName v) |
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.
Isn't this still in Checker.hs
as well? Is this one used?
showWithMetas m (StrictMonoFun sm) = showWithMetas m sm | ||
|
||
instance ShowWithMetas x => Show (Fun00 x) where | ||
show = showWithMetas M.empty |
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.
I am a bit worried about all these showWithMetas M.empty
. Removing a few threw (so that use of Show
raised an error) pointed me at many places where I could have been using showWithMetas
with a UserNameMap from the Checking monad, as well as a few where that was not available (but in those cases, presumably it would be better to use the UserNameMap if it had been available, so at the least, good to make it obvious that we'd like to route the map in at some point).
Possibly we need it for tests. I wonder about declaring that in the test module though?
You can see my playing around in branch |
Closes #3.
There are a couple of open questions here:
nameMap
? I kind of likemnemonics
as we use for the user-provided names of holesreq AskNames >>= \nm -> showRow nm
pattern?I have a hunch this could look nicer after we tackle #23.
New test case
vec_length2.brat
reveals an error, which I plan to fix in #38.(This bit of code is driving me up the wall 😅)