Conversation
|
This looks fine, but I'm just a little nervous about introducing new name clashes with this. Have you been able to rule that out as a possibility? |
|
PS doesn't allow names starting with |
|
(admittedly this is still "stringly-typed" programming, but I think it will do the trick in lieu of a much tricker solution) |
|
Right, but the compiler already generates plenty of names with dollar signs in them in various situations. |
I think |
there is a function called |
-- | Attempts to find a human-readable name for a symbol, if none has been specified returns the
-- ordinal value.
identCharToText :: Char -> Text
identCharToText c | isAlphaNum c = T.singleton c
identCharToText '_' = "_"
identCharToText '.' = "$dot"
identCharToText '$' = "$dollar"
identCharToText '~' = "$tilde"
identCharToText '=' = "$eq"
identCharToText '<' = "$less"
identCharToText '>' = "$greater"
identCharToText '!' = "$bang"
identCharToText '#' = "$hash"
identCharToText '%' = "$percent"
identCharToText '^' = "$up"
identCharToText '&' = "$amp"
identCharToText '|' = "$bar"
identCharToText '*' = "$times"
identCharToText '/' = "$div"
identCharToText '+' = "$plus"
identCharToText '-' = "$minus"
identCharToText ':' = "$colon"
identCharToText '\\' = "$bslash"
identCharToText '?' = "$qmark"
identCharToText '@' = "$at"
identCharToText '\'' = "$prime"
identCharToText c = '$' `T.cons` T.pack (show (ord c)) |
|
None of these are used anymore since you can only introduce them with operators, which are desugared to the actual identifier it represents. |
|
There is also |
|
For reference, the function that handles the name conversion generally is |
|
So you're saying there's absolutely no use of I'd like to remove the unused code to do with how operators used to work, and actually I think I'd be slightly happier if we did that before doing this. |
Yes
This guarantees no clash in JS output and intermediate representations (they don't use "$" to my knowledge). Other backends, however, would have to avoid the
Might make a PR for this if nobody else has that waiting. |
I've just been bitten too many times by thinking "I can't think of a way that this could go wrong, therefore it will not go wrong." Not using it to anyone's knowledge doesn't really count as any kind of guarantee, in my mind. I'll review this more thoroughly when I get a chance to try to verify that this is safe, but since this is a very small code change and it addresses a rare edge case that nobody has even run in to as far as we are aware, I'm probably not going to prioritise it (just FYI).
I'm not aware of anyone else working on that; please go ahead! |
Yes, this makes sense. Also, on reflection, there is indeed the issue that other backends might potentially exist for languages where something like |
|
I'm going to close this now and try to come up with a better solution :) |
|
purescript/src/Language/PureScript/Names.hs Lines 83 to 86 in 3103dbf |
|
Ok great - I forgot that freshly generated names have a number at the end. In that case I’m happy with this. |
|
I will resurrect this if I can't get something better to work. But I think there is a better way. |
|
To introduce the new name type will take a little work, as currently "CoreImp" (aka, JS) uses |
|
Not that it'd be hard to introduce a type for CoreImp names, just a little tedious 😉 |
|
I haven't done a thorough check, but it seems that so far |
|
(Regarding the mentions of "other backends" - there's always going to be some mangling in some circumstances, and it will be different to the JS mangling, which is fine so long as it's injective - I think any principled approach is likely to be fine) |
|
Another use of $ in variable names is in the tail call optimisation code |
resolves #3187