-
Notifications
You must be signed in to change notification settings - Fork 521
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
Experiment with scala native #1302
Comments
To note, the only async-anything support within scala-native comes via libuv and https://github.com/scala-native/scala-native-loop. We could technically do something like this, but it's an open question as to whether or not it would be worthwhile. |
🙌 If you come up with any experiments, I'd love to test them out |
This is definitely one of those things that will be a little interest-driven. 😃 Also if anyone wants to dive in and start playing with getting it working, the Cats Effect side of it would actually be very straightforward (for the most part, you just need to implement an ExecutionContext that works), and I would love to help out anyone interested in trying their hand at it. |
So I did some investigating and concluded that integrating with Scala Native & libuv may be currently possible, but it's bleeding edge and exceeds my personal bravery level. I think it might be prudent to wait for stabilization of:
|
Would it probably make sense to just publish the kernel for scala native for now? While it migh make sense to wait before porting cats IO, having the typeclasses available would allow:
WDYT? |
That makes sense to me. It opens the way for someone to have a go of
implementing an IO on SN.
Maintaining an IO for SN within CE is what I'd be wary of, as the
underlying libuv bindings might keep changing for a while yet ..
…On Sun., 14 Feb. 2021, 8:26 pm João Costa, ***@***.***> wrote:
Would it probably make sense to just publish the kernel for scala native
for now?
While it migh make sense to wait before porting cats IO, having the
typeclasses available would allow:
- Library authors to still cross-publish code with CE3 to scala-native
- Application authors to plug in a simpler IO monad and use only a
subset of operations (e.g. it should be simple to write an IO monad that
only implements Sync and the required typeclasses).
WDYT?
—
You are receiving this because you commented.
Reply to this email directly, view it on G itHub
<#1302 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAXJZDG2YF6JH466US2G33S66JKTANCNFSM4SMIE5ZQ>
.
|
Would be very welcome 👍 |
I like the proposal. |
I like the proposal as well. Could also conceivably do std as well as kernel. My main concern is that Scala Native currently doesn't support Scala 3, so the build matrix gets to be… very annoying. But, regardless, PRs welcome. |
I got that cross-build fever 😅 #2168 |
Scala native is now meant to work on Windows |
That has now been remedied also. |
@arashi01 Yes, this has been on my mind :) we still need the Typelevel ecosystem to be built for Native/3 which is currently blocked at typelevel/scalacheck#868. The problem is supporting Native requires jumping to Scala 3.1, see discussion about that in typelevel/cats#4016. But, hopefully once scala/scala3#14156 arrives in 3.1.2 this will no longer be a problem.
Update: specs2 now runs on Native :) |
@armanbilge 3.1.2 fixes the referenced problem. It seems like scalacheck has been updated as well. Can you summarize the current ecosystem blockers? |
Ah yes, update time :)
So there's no longer any major blockers :) However, I don't think that Cats Effect on Native 0.4 will be very interesting or useful. Since Scala Native 0.4 does not support multi-threading, we can't even implement an async Furthermore, to build interesting applications, we will need asynchronous I/O (TCP, TLS, UDP, file systems). So we need to think ahead to how fs2-io will cross-build. The JS cross-build of fs2-io shows that anything is possible after that (http4s ember, skunk, etc.). As suggested in #1302 (comment), one option could be to implement a libuv-based runtime via scala-native-loop. I'm 👎 on this happening in Cats Effect for various reasons.
So my current proposal is that Cats Effect Native 0.4 ships with a "dummy" runtime. By this I mean The point of this would be to allow downstreams to also start exploratory cross-building for Native. That way we can figure out what problems lie ahead and be more prepared for when Native 0.5 ships with multi-threading support and things get more interesting. Meanwhile, nothing stops a Highly-Motivated Developer™ from building a libuv runtime for Cats Effect in an external project. As pointed out in #1302 (comment), all that's needed is an
So basically the goal is to unblock downstream explorative work. It's better to do this outside of Cats Effect to take advantage of:
|
Just to bump my previous point that (if it doesn't make te build matrix too weird), it might also make sense to just not publish any native runtime for now (publishing just std and kernel). That would allow for libraries to start being ported and some applications could still be written, but with custom runtimes. Maybe there could be a dummy runtime like the one proposed, but without being "the official cats effect runtime" (as in, living in a seperate project clearly marked as experimental). Mostly because I'm not sure what's preferable:
|
FWIW, I agree with @JD557 and hope that CE publishes all the modules that can be published without having to add any dummy implementations. CE's typeclasses sit at the top of the hierarchy for a lot of libraries that don't exercise runtime in the library code, so it would be best to have all the auxillary modules published and ready to go, so that when (not if, there's a lot of Highly Motivated Individuals around) the runtime is ready, it can sweep through the ecosystem, either as a separate project or as one built into CE itself. The upgrades train took a long time to get even to this current point, so if something can be done to shorten it next time round - I'd support that and will be happy to help on either SN or CE side. |
Thanks for raising this! It's important we cross-publish Cats Effect core, because fs2 depends on it, particularly It sucks to delegate You are right though, that the
I also desire this "sweeping" phenomenon :) and the best way to achieve that IMHO is to start pro-actively cross-building and testing downstream libraries, and we cannot do this without |
Amazing status update. :) Note fs2-core relies on |
Just to clarify, I'm skeptical that we will ever have an official Cats Effect runtime for Native 0.4.
The story changes dramatically when Native 0.5 arrives with multi-threaded support.
For the record, I am very supportive of a libuv runtime, as an external project :) Also for the record, I'm not the BDFL or even a maintainer of many projects in the stack, so these are all my personal opinions, I certainly don't have any final say on the matter. My bias is towards minimizing build-complexity and maintenance burden over the long-term, but I admittedly have limited experience with this.
Actually, I might take this back. There are still interesting things you could do with the dummy runtime. For example, it would be sufficient to cross the fs2 hexdump4s application. It would essentially have the performance of a sync, blocking I/O app. But at least you get to use fs2! :) |
Out of curiosity, does anyone know what would be a blocker to implementing |
That's exactly what's been done in WojciechMazur/scala-native#23 :) there's a lot of good stuff in that branch, worth checking out! The real blocker for multi-threading is Garbage Collection. IIUC the Native 0.4 runtime will crash if managed memory is accessed/modified by an external thread, but I haven't tried this at all. |
I had a very informative chat with @lolgab on the Scala Native Discord (thank you so much 🙏 ) who was supportive of my proposal here.
https://discord.com/channels/632150470000902164/635668881951686686/985223897706266745 We agree that ideally an event loop runtime would eventually live in Scala Native core itself. |
@keynmol thank you so much for volunteering! To support the Cats Effect effort please port the following Java lib to Scala Native. Scala.js has them, so there's no reason Scala Native can't have them either.
|
I put up a PR against my own repo. Locally, the entire test suite is passing on Native :) I experimented with two runtimes: First I tried a sort of event-loopy Unfortunately, this runtime could not be used for tests, because specs2 has a hard-assumption that the Scala Native global So I also implemented the original "dummy" runtime I proposed, which implements a busy-wait I'll try to put up a snapshot later. PRs against my branch are welcome btw. |
Also published for 2.12 and 2.13 Native. |
Remaining blockers: |
PR is up: |
Based on my PR, a very small demo of async I/O: https://github.com/armanbilge/epollcat |
Cross-linking to the FS2 ticket. I did some preliminary investigations to see what Scala Native is missing to support FS2 and wrote a summary. |
After extensive bootlegging, I've published a fully async, non-blocking http4s-curl client. |
Probably the final update on this issue in #3138 (comment). tl;dr we have a viable ecosystem on Cats Effect Native, including http4s ember and skunk, and plenty more to follow. So I am ready to begin publishing this stuff :) |
It would be really interesting to see what we can do on this front, now that Scala Native is on 2.12. We would need Cats to publish for it, though. This is a rather large and sprawling project, tbh, and I'm not sure if there's even a definitive payoff at the end, but it will be cool to try anyway!
The text was updated successfully, but these errors were encountered: