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
brat/Brat/Checker/Helpers.hs
Outdated
| 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.
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.
Not as far as I'm aware 😔
| show Empty = "()" | ||
| show (a :|: b) = bracket PJuxtPull a ++ ", " ++ bracket PJuxtPull b | ||
| show Pass = "pass" | ||
| show Pass = ".." |
There was a problem hiding this comment.
This is a drive-by fix - the surface syntax for the Pass operator is .., not pass
brat/Brat/Syntax/Value.hs
Outdated
| Kerny -> "-o" | ||
|
|
||
| instance MODEY m => Show (CTy m n) where | ||
| show = showWithMetas M.empty |
There was a problem hiding this comment.
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.
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 |
| 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.
Hmmm, how about fmap-ing showWithMetas over the variable to give a NumVal String (or NumVal of something that can be Shown)
There was a problem hiding this comment.
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!
| 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.
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.
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 theRo` data structure
| 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.
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.
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 Names "Names" 😅
There was a problem hiding this comment.
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
acl-cqc
left a comment
There was a problem hiding this comment.
Ok, looking good, let's
- separate out from #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 #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
NumValfmapsuggestion and see if it doesn't work
| 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.
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 <>> [])) |
brat/Brat/Checker/Monad.hs
Outdated
| 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.
The \n in the middle here looks a bit weird, is that what you want?
| [] -> 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.
Looks like this PR has got muddled up with #75
| -- 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.
How about a tracking issue with all the ways to improve error messages ;)
| -} | ||
|
|
||
| newtype CompilingHoles = CompilingHoles [TypedHole] | ||
| data CompilingHoles = CompilingHoles UserNameMap [TypedHole] |
There was a problem hiding this comment.
Worth adding a comment that this is an error. Or just rename to CompilingHolesError
brat/Brat/Eval.hs
Outdated
| 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.
let msg = --> pure $ Left $
| 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.
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.
brat/Brat/Checker/Monad.hs
Outdated
| 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.
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)
| (_, _) -> 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.
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.
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 likemnemonicsas we use for the user-provided names of holesreq AskNames >>= \nm -> showRow nmpattern?I have a hunch this could look nicer after we tackle #23.
New test case
vec_length2.bratreveals an error, which I plan to fix in #38.(This bit of code is driving me up the wall 😅)