scalacenter / spores

Scala Spores, safe mobile closures.
http://scalacenter.github.io/spores/
Other
28 stars 6 forks source link

Scala.JS support #23

Open edmundnoble opened 7 years ago

edmundnoble commented 7 years ago

This would probably amount to making it a crossproject.

jvican commented 7 years ago

I'll try to do this tomorrow. Thanks for the suggestion!

jvican commented 7 years ago

This has turned out to be more difficult than expected due to some internal tricks that I'm doing inside spores to improve user experience. These tricks rely on Java Reflection, so I'll think of a good way to only include them in the JVM artifact and ship a JS artifact soon. I cannot predict when this version will be out, though, but I'll be working on it in the next week.

jvican commented 7 years ago

Progress can be tracked in the scalajs-version branch https://github.com/scalacenter/spores/tree/scalajs-version.

andreaTP commented 7 years ago

Would you like to discuss about the open points? If you can elaborate a list of open points to be solved for porting to Scala.Js I think I can help.

jvican commented 7 years ago

@andreaTP The main issue is that the macro implementation depends on the compiler jar (it needs to reflectively access the global context to check some situations at the spore call site, details are complicated). Unfortunately, the compiler jar is not scalajs compatible.

The scalajs-version has some changes to the build to make spores Scalajs compatible, but it's still required to port the isUserCapturingNothing function to an object that is independently implemented in the js and jvm projects. The idea would be that the JS implementation always returns false and the JVM modules has the current implementation of the function, that depends on java reflection. This way, we can just put the compiler library dependency into the JVM settings of the cross project. JS users won't benefit from the extra checks that this functionality entails, but as they are not critical it's fine.

Please, let me know if everything is clear, I'm happy to elaborate more.

andreaTP commented 7 years ago

The macro implementation should be trivial to fix, macro-time is at compile time and you can have access to any jar or reflection based stuff you like, it will just be a matter of properly have them just just in the right scope. Or am I missing anything?

A local different behavior due to different platforms looks totally ok, so a different implementation of isUserCapturingNothing is totally ok.

We can go on here and if you need help on specific points I will be glad to help!

jvican commented 7 years ago

@andreaTP True, that change is not even necessary. I ran into some issues with sbt that lead me to believe it was.

I have succeded creating a cross project for scalajs. I have to find out why spores-coreJS/test does not work though, it's probably related to the Junit plugin sbt uses under the hood...

andreaTP commented 7 years ago

yes to keep sbt build right can take a while .... I know ... you can look at what I did to start crosscompiling scalameta here: https://github.com/andreaTP/minimeta/blob/master/build.sbt they had the very same problem I think...

If you need help in running tests after that ping and I will take a look if possible.

jvican commented 7 years ago

@andreaTP @edmundnoble https://github.com/scalacenter/spores/commit/4bf990df24a71e52f2aa2bf4a5dcd1e421027a2d introduces "experimental" scalajs support. It is still "experimental" because we cannot run our test suite in JS runtimes -- important bits of our test suite depend on the JVM (classpaths, resources) and the Scala compiler to run neg tests. It would take me time to refactor these bits and disable neg tests for the JS version, so this won't happen any time soon. For now, compilations are successful and the playground JS version works. I'm planning to cut a release soon so I'll ping you when the sjs artifacts are out.

I'm leaving this thread open in case folks want to comment on any bug they encounter in the scalajs artifacts.