Skip to content

Initial infrastructure and hello world for the Scala.js back-end. #1126

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

Merged
merged 5 commits into from
Mar 4, 2016

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Feb 26, 2016

The Scala.js back-end can be enabled with the -scalajs command-line option. Currently, it adds one phase to the pipeline, which emits .sjsir files from trees.

A sandbox project sjsSandbox, in sandbox/scalajs/, can be used to easily test Scala.js compilation. One can run the main() method of the hello.world object with

> sjsSandbox/run

The back-end only contains the bare mimimum to compile the hello world application in the sandbox. Anything else will blow up (for example, primitive method calls). It is a work-in-progress.

@sjrd
Copy link
Member Author

sjrd commented Feb 26, 2016

I am not sure whether you would consider this for inclusion in the repo, at this point. But I figured it was in a good enough state to suggest it.

In any case, I would very much like comments on the general aspect. Please tell me if I'm doing anything stupid at this point.

It might be interesting to compare this with the scalac implementation at https://github.com/scala-js/scala-js/tree/master/compiler/src/main/scala/org/scalajs/core/compiler
In particular, the "giant" JSCodeGen is mostly parts of GenJSCode.

I guess all of @odersky @DarkDimius @smarter might be interested in having a look at this, if not all the details.
Also /cc @nicolasstucki and @gzm0.

@DarkDimius
Copy link
Contributor

In any case, I would very much like comments on the general aspect. Please tell me if I'm doing anything stupid at this point.

I followed most of the code. Ideologically it looks good to me. I'd be curious to see how much different would be handling of Try and code generated by patmat compared to scalac. Please tell me if you'll need help understanding some details(especially in LabelDefs).

@sjrd sjrd force-pushed the scalajs branch 2 times, most recently from f08f000 to 70e6665 Compare February 28, 2016 11:52
@sjrd
Copy link
Member Author

sjrd commented Feb 28, 2016

Rebased. I saved the earlier comments at sjrd@57c1b1c
Note that, if you comment on the Files tab of the PR (instead of in the commits), the comments survive rebases on GitHub.

@sjrd
Copy link
Member Author

sjrd commented Feb 29, 2016

@DarkDimius I added a commit moving JSDefinitions to a custom SJSPlatform as you suggested. This required to have a valid ctx with properly initialized settings when creating the ContextBase.platform, which required to defer its initialization.

I am not sure if the new situation is desirable. But in any case the required changes highlight that, in master, platform is a useless concept, since it is not configurable.

@sjrd
Copy link
Member Author

sjrd commented Feb 29, 2016

/rebuild

@sjrd
Copy link
Member Author

sjrd commented Feb 29, 2016

Are OOMs in partest CI common? Or are the failures in fact not spurious?

@smarter
Copy link
Member

smarter commented Feb 29, 2016

I'm getting them too so it's probably not your fault, we're just steadily using more and more memory, you can try increasing https://github.com/lampepfl/dotty/blob/master/project/Build.scala#L11 and see if it helps.

@sjrd
Copy link
Member Author

sjrd commented Feb 29, 2016

It appears to have helped, indeed.

So, from my side, I'm happy with this PR the way it is. I guess it deserves a real review, now.

odersky and others added 5 commits March 1, 2016 15:47
…ctor.

Dotty treats trait and class constructors as returning the class.
But scalac uses Unit for the return type of trait init methods.
When a concrete val is mixed in from a Scala2 trait, a setter is
generated, which is called by the `$init$` method. Since the
assignment in this setter is not done in the constructor, it is
nonsensical for the field to be immutable.

This commit sets the Mutable flag on such fields. It only applies
for vals coming from Scala2 traits. vals coming from Dotty traits
are kept immutable.
The Scala.js back-end can be enabled with the `-scalajs`
command-line option. Currently, it adds one phase to the pipeline,
which emits .sjsir files from trees.

A sandbox project `sjsSandbox`, in `sandbox/scalajs/`, can be used
to easily test Scala.js compilation. One can run the `main()`
method of the `hello.world` object with

  > sjsSandbox/run

The back-end only contains the bare mimimum to compile the hello
world application in the sandbox. Anything else will blow up
(for example, primitive method calls). It is a work-in-progress.
This required the ability to instantiate a different `Platform`
depending on settings, which, in turn, required to defer the
initialization of `ContextBase.platform`.
This guarantees that we can bootstrap dotty without depending on
the binaries of scalajs-ir compiled by another Scala compiler.
@sjrd
Copy link
Member Author

sjrd commented Mar 4, 2016

@DarkDimius Following our conversation from this afternoon, I have added a commit addressing your concern about the bootstrap'ability of scalajs-ir. Instead of depending on the compiled artifacts, the build now depends on the sources and compiles them as part of dotty. In bootstrap tests, they are therefore part of the compilation of dotty by itself.

@sjrd
Copy link
Member Author

sjrd commented Mar 4, 2016

As for testability, something we could do would be to simply add a CI command sbt sjsSandbox/run. This triggers the Dotty+Scala.js compilation, the linking (including verying the IR--similar to how the JVM verifies bytecode), and the execution with Rhino of the generated .js code.

@DarkDimius
Copy link
Contributor

@sjrd, for testability, I leave this for you to decide. Please tell me if you wish to add it to CI.
LGTM

DarkDimius added a commit that referenced this pull request Mar 4, 2016
Initial infrastructure and hello world for the Scala.js back-end.
@DarkDimius DarkDimius merged commit a509267 into scala:master Mar 4, 2016
@sjrd sjrd deleted the scalajs branch March 4, 2016 23:09
@sjrd
Copy link
Member Author

sjrd commented Mar 4, 2016

Thanks!

Please tell me if you wish to add it to CI.

I think it would be worth it, yes.

@smarter
Copy link
Member

smarter commented Mar 4, 2016

How long do the tests take?

@sjrd
Copy link
Member Author

sjrd commented Mar 4, 2016

How long do the tests take?

sjsSandbox/run? Less than 3 seconds on my machine.

@smarter
Copy link
Member

smarter commented Mar 4, 2016

OK then, add it :).

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.

4 participants