Conversation
1958dc5 to
d6bf7b0
Compare
|
This PR is a successor to #3188. Rather than attempting to address the issue by choosing a smarter magic string, it attempts to avoid optimizing based on matching |
kritzcreek
left a comment
There was a problem hiding this comment.
I've added a couple of comments, thanks!
|
|
||
| -- the __unused parameter used to get optimized away | ||
| abuseUnused :: forall a. a -> a | ||
| abuseUnused __unused = __unused |
There was a problem hiding this comment.
I don't understand why this is inside passing, shouldn't this explode now that UnusedIdent is a special, generated name inside the compiler?
There was a problem hiding this comment.
No, the opposite. It exploded before this PR, because "__unused" was a magic string. This PR makes it so __unused is no longer a magic name, but a name like any other. So this test now passes.
There was a problem hiding this comment.
Oh I see :D I somehow thought this was a self recursive ever looping binding. My bad.
| identToJs (GenIdent _ _) = internalError "GenIdent in identToJs" | ||
| identToJs UnusedIdent = C.__unused | ||
|
|
||
| -- | Convert an 'Ident' into a valid JavaScript identifier, or Nothing. |
There was a problem hiding this comment.
A function returning both a Maybe AND throwing exceptions is a red flag to me, which is almost guaranteed to be used wrong. And why do we still need the old version of this function?
Since this function is only used in a single place, I think it would be better to define it inline where it has more context.
There was a problem hiding this comment.
Agreed. Will fix.
src/Language/PureScript/Names.hs
Outdated
| freshIdent' :: MonadSupply m => m Ident | ||
| freshIdent' = GenIdent Nothing <$> fresh | ||
|
|
||
| unusedIdent :: Ident |
There was a problem hiding this comment.
Why this indirection? You could just use the constructor.
src/Language/PureScript/Names.hs
Outdated
| runIdent (Ident i) = i | ||
| runIdent (GenIdent Nothing n) = "$" <> T.pack (show n) | ||
| runIdent (GenIdent (Just name) n) = "$" <> name <> T.pack (show n) | ||
| runIdent UnusedIdent = "__unused" |
There was a problem hiding this comment.
Now that this is a special identifier, shouldn't this also be prefixed with a $ so it can't be mixed up with Ident "__unused"
There was a problem hiding this comment.
good point. Will fix.
d6bf7b0 to
0c382c6
Compare
|
I've implemented the requested changes. Eager for any further feedback. |
Fixes purescript#3187 Rather than using the magic string "__unused" to represent generated names that are meant to go unused, we create a new Ident constructor for them. Instead of eliminating them as arguments in the optimization phase, they are stripped during the conversion from CoreFn to CoreImp.
0c382c6 to
9a9e623
Compare
|
Looks good to me, but I'd appreciate one more person with a better idea of Codegen to take a look and merge. |
|
Should we ever hit the cases where we return |
|
We will hit that case when the compiler infers a |
|
To clarify:
|
|
Do we need to come to a consensus on #3182 first? |
I don't think so? The only behavioral change this PR introduces is that |
|
Sorry, I guess I really mean #2768; whether or not we do that seems like it would have implications for what we do here, or at least has implications for the approach taken in #3195, right? And the decision we make about #2768 also influences #3182 as well, which is why I mentioned that one in the first place. |
|
Ok so I'm just untangling my own confusion here. AFAICT we're pretty much all agreed that we want to do #2768, right? That's a breaking change at the moment, but only because you're allowed to use constraints in |
|
#2768 is not necessarily breaking. The approach brought up by @paf31 simply converts the parameter to "unused" ( |
|
As for #3182 , you're right of course. But I don't see how any of these impact this PR. |
|
Ok, well ignore me for now then, and if I manage to sort out my confusion before we want to merge this then I'll let you all know, but otherwise please don't let me keep this from being merged. |
|
I wouldn't recommend trying to optimize as far as |
|
@garyb or @natefaubion any thoughts on this? |
Fixes #3187
Rather than using the magic string
"__unused"to represent generated names that are meant to go unused, we create a newIdentconstructor for them. Instead of eliminating unused function arguments in the optimization phase, they are stripped during the conversion from CoreFn to CoreImp.