-
Couldn't load subscription status.
- Fork 1.4k
Use an inline given for CanFail evidence in Scala 3
#9568
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
Conversation
74602fe
| Exit.succeed(exec.getEmit) | ||
| case ChannelState.Effect(zio) => | ||
| zio.mapError(Left(_)) *> interpret(exec.run().asInstanceOf[ChannelState[Env, OutErr]]) | ||
| zio.asInstanceOf[ZIO[Any, OutErr, Any]].mapError(Left(_)) *> |
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 bit bizarre. Out of the entire codebase this seems to be the only place where we lost source compatibility and I'm really not sure why. I think it probably has to do with the typer phases pre/post inlining and this is the only place that we need the explicit cast for some reason.
What do we think, is it significant enough of a risk for source compatibility? If yes I'll close this PR
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.
Could we keep the standard implicit in a low priority trait?
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.
Yeah this works, although I couldn't simply move the previous implicit as it wasn't binary compatible (the new implicit method would be static whereas previously it wasn't for some reason)
When looking at some decompiled code for Scala 3, I realised that the
CanFailevidence implicit required 2 method invocations; one forCanFail.canFailand one forNotGiven.value. By inlining the evidence and the implicit parameter, we avoid these 2 method invocations andCanFailis inlined at the callsite during compile time (if theNotGivenpredicate is satisfied that's it).Note that we keep the old method as a normal
defwith atargetNameannotation and as package-private in order to maintain binary compatibility for code compiled with older ZIO versions.