Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kyri-petrou
Copy link
Contributor

When looking at some decompiled code for Scala 3, I realised that the CanFail evidence implicit required 2 method invocations; one for CanFail.canFail and one for NotGiven.value. By inlining the evidence and the implicit parameter, we avoid these 2 method invocations and CanFail is inlined at the callsite during compile time (if the NotGiven predicate is satisfied that's it).

Note that we keep the old method as a normal def with a targetName annotation and as package-private in order to maintain binary compatibility for code compiled with older ZIO versions.

hearnadam
hearnadam previously approved these changes Feb 10, 2025
ghostdogpr
ghostdogpr previously approved these changes Feb 10, 2025
@kyri-petrou kyri-petrou dismissed stale reviews from ghostdogpr and hearnadam via 74602fe February 10, 2025 02:06
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(_)) *>
Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

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?

Copy link
Contributor Author

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)

@kyri-petrou kyri-petrou merged commit 1117a61 into zio:series/2.x Feb 10, 2025
18 checks passed
@kyri-petrou kyri-petrou deleted the inline-canfail-given branch February 10, 2025 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants