Skip to content

Compile Scala library with Dotty and test its TASTy #9925

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

Conversation

nicolasstucki
Copy link
Contributor

No description provided.

@nicolasstucki nicolasstucki force-pushed the scala-library-from-tasty-tests branch from 24852e8 to 6c0f4de Compare October 1, 2020 10:14
@nicolasstucki nicolasstucki force-pushed the scala-library-from-tasty-tests branch 17 times, most recently from 0ee5051 to 59e7a4f Compare October 5, 2020 12:08
@nicolasstucki nicolasstucki marked this pull request as ready for review October 5, 2020 12:48
@nicolasstucki nicolasstucki requested a review from smarter October 5, 2020 12:48
@nicolasstucki nicolasstucki force-pushed the scala-library-from-tasty-tests branch from 006eb1f to 69dda1c Compare October 5, 2020 14:01
@@ -817,6 +817,74 @@ object Build {
javaOptions := (javaOptions in `dotty-compiler-bootstrapped`).value
)

lazy val `dotty-scala-library-from-tasty-tests` = project.in(file("dotty-scala-library-from-tasty-tests")).
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand what this project is for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is there to test that we can recompile the jar from dotty-scala-library from a bootstrapped compiler with the normal bootstrapped library. We needed an extra project to get the dependencies on the bootstrapped compiler right.

)


// Scala library compiled by dotty using the latest published sources of the library
Copy link
Member

Choose a reason for hiding this comment

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

I suggest using the stdlib sources from our community-build instead, that way if we need to change something we can change it in the community build submodule.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those sources are not aligned with the library that we are using to run dotty apps. Their documentation may also slightly defer.

Copy link
Member

Choose a reason for hiding this comment

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

We should keep them aligned if possible.

Copy link
Member

Choose a reason for hiding this comment

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

If you change things because you need to change something, by definition they're not aligned anymore.

Copy link
Member

Choose a reason for hiding this comment

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

Sure but we can make PRs to keep them aligned if needed. I think it's just confusing to operate on multiple versions of scala-library at the same time, I don't see the advantages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Under that logic, if we don't want to operate on multiple versions of the scala-library, we should remove the stdlib213 from the community-build as it is not aligned with the one we use to run dotty. But the one in the community build allows us to future proof the compilation of the library, therefore it is good to have this second variant of the scala-library.

)

// Tests that we can compile and run an app using the scala-library compiled by dotty
lazy val `dotty-scala-library-sandbox` = project.in(file("sandbox/dotty-scala-library")).
Copy link
Member

Choose a reason for hiding this comment

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

can we use dotty-scala-library/test instead of adding an extra project?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The library dependency setup is different on those two projects. That would not be testing what we want to test.

Copy link
Member

Choose a reason for hiding this comment

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

Different how?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't remember why we did not set up the tests of that project to this. @sjrd was there a specific reason? Or just for simplicity?

dependsOn(`dotty-scala-library`).
settings(
managedClasspath in Compile ~= {
_.filterNot(file => file.data.getName == "scala-library-2.13.3.jar")
Copy link
Member

Choose a reason for hiding this comment

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

If you want to remove the stdlib from the dependencies of a scala project, you can use autoScalaLibrary := false (this will also remove dotty-library)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't want to remove the dotty-library.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, but then don't hardcore 2.13.3, use stdlibVersion

@@ -0,0 +1,488 @@
/*
Copy link
Member

Choose a reason for hiding this comment

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

Why is this file needed? I tthought we already handled macro ??? to allow compiling the scala 2 stdlb as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can compile them, but we assume that if they are going to be consumed from Scala 3 we need a scala 3 macro implementation as well. Here that second implementation is missing and when we load the class we ignore the Scala 2 macros. This implies that when loaded, StringContext does not have s, f and raw methods.

The usual solution is to add the second macro, but because those are intrinsic macros we can get away by just making them non-macros and let the compiler do its usual transformation of these methods.

Copy link
Member

Choose a reason for hiding this comment

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

Can't we interpret macro ??? like ??? when it doesn't come from scala 2 so that we can keep using the same source?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not under the normal dual macros rules. We would have to add an extra compilation flag for this special case which seems to be overkill in this single case.

Copy link
Member

@smarter smarter Oct 5, 2020

Choose a reason for hiding this comment

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

which seems to be overkill in this single case.

I disagree, I think that a special case is better than having a copy of a file we need to worry about keeping up to date. Furthermore, it would be nice if in scala/scala we didn't just compile the stdlib with dotty but we also ran the stdlib tests, that is only possible if the compiler can handle the normal StringContext correctly if I understand this correctly.

Copy link
Contributor Author

@nicolasstucki nicolasstucki Oct 6, 2020

Choose a reason for hiding this comment

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

I removed the file and special-cased these macros in TreeUnpickler.

@nicolasstucki nicolasstucki force-pushed the scala-library-from-tasty-tests branch 2 times, most recently from 8ec5eb2 to dccd60b Compare October 16, 2020 07:48
@nicolasstucki
Copy link
Contributor Author

@smarter I merged the sandbox into scala3-scala2-library (former dotty-scala-library). I kept scala3-scala2-library-tasty-tasty-tests (former dotty-scala-library-tasty-tests).
I tried to put the tests in BootstrappedOnlyCompilationTests but they were timing out all the time on the CI, these tests are a bit too heavy to run in parallel with other tests.

@smarter
Copy link
Member

smarter commented Oct 16, 2020

scala3-scala2-library isn't a great name, maybe stdlib-bootstrapped?

},
)

lazy val `scala3-scala2-library-tasty-tests` = project.in(file("scala3-scala2-library-tasty-tests")).
Copy link
Member

Choose a reason for hiding this comment

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

This should have some documentation explaining what it tests and why that needs to be done in a separate project.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

@nicolasstucki nicolasstucki force-pushed the scala-library-from-tasty-tests branch 2 times, most recently from 69a5e1b to 3647e95 Compare October 19, 2020 07:37
@nicolasstucki nicolasstucki requested a review from smarter October 19, 2020 11:38
@nicolasstucki
Copy link
Contributor Author

@smarter now it is ready for re-review. All tests pass again.

@@ -805,6 +805,74 @@ object Build {
javaOptions := (javaOptions in `scala3-compiler-bootstrapped`).value
)

/** Scala library compiled by dotty using the latest published sources of the library */
lazy val `scala3-scala2-library` = project.in(file("scala3-scala2-library")).
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a fan of that name, I suggest stdlib-booststrapped or stdlib-recompiled maybe.

compileFromTasty(loadBlacklisted.union(compileBlacklisted))

@Ignore
@Test def testWhiteListFromTasty: Unit =
Copy link
Member

Choose a reason for hiding this comment

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

What do we need a whitelist for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was a simple way to test a subset of files. Now that I have minimized everything I can remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On second thought, I prefer to keep in case a change breaks the compilation of the library. This would help to minimize the failing combination of files faster.

Copy link
Member

Choose a reason for hiding this comment

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

That's fine but then please add a comment on top of the test explaining that

/** List of classes that cannot be recompilied from TASTy */
def compileBlacklist = List[String](
// OK?
// failed: java.lang.AssertionError: assertion failed: class Boolean
Copy link
Member

Choose a reason for hiding this comment

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

We should have an issue for thos and the comment should point to that issue

@nicolasstucki
Copy link
Contributor Author

scala3 prefix is not needed but it makes naming consistent

@smarter
Copy link
Member

smarter commented Oct 20, 2020

I think ideally we would only use the scala3 prefix for the artifacts we distribute (library, compiler, ...), for internal things it doesn't seem useful.

@nicolasstucki
Copy link
Contributor Author

We already have a few projects with scala3 that we don’t distribute: scala3-tastydoc-input, scala3-bench-run, scala3-sbt-bridge-tests, scala3-tastydoc, scala3-library, scala3-compiler, scala3-bench
Should we rename those?

@nicolasstucki nicolasstucki force-pushed the scala-library-from-tasty-tests branch from 2a422ae to 8567ffc Compare October 20, 2020 14:56
@smarter
Copy link
Member

smarter commented Oct 20, 2020

Should we rename those?

We could yes (in fact, we could also rename scala3-compiler to compiler, etc, we just need the artifact name to start with scala3-, but the name of the sbt project can be whatever we want, so we could make them easier to type)

@nicolasstucki
Copy link
Contributor Author

Let's make a single PR afterward to renames them. It will be simpler to track.

@nicolasstucki nicolasstucki force-pushed the scala-library-from-tasty-tests branch from ed2e882 to aee734d Compare October 20, 2020 15:20
@nicolasstucki nicolasstucki force-pushed the scala-library-from-tasty-tests branch from aee734d to b4dec3c Compare October 20, 2020 15:24
@nicolasstucki
Copy link
Contributor Author

I renamed this one to stdlib-bootstrapped.

@@ -805,6 +805,74 @@ object Build {
javaOptions := (javaOptions in `scala3-compiler-bootstrapped`).value
)

/** Scala library compiled by dotty using the latest published sources of the library */
lazy val `stdlib-bootstrappedject.in(file("stdlib-stdlib-bootstrapped
Copy link
Member

Choose a reason for hiding this comment

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

typo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

* - inspector: test that we can load the contents of the jar using the tasty inspector
* - from-tasty: test that we can recompile the contents of the jar using `dotc -from-tasty`
*/
lazy val `stdlib-bootstrappedtests` = project.in(file("stdlib-stdlib-bootstrapped).
Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't call that project just stdlib-bootstrappedtests, because it's not clear how it's different from stdlib-bootstrapped/test, -tasty-test or -sanity-test would be better I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test").
dependsOn(`scala3-tasty-inspector` % "test->test").
settings(commonBootstrappedSettings).
settings(
Copy link
Member

Choose a reason for hiding this comment

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

You could add a setting:

Suggested change
settings(
settings(
moduleName := "scala-library"

this way the jar will be called scala-library_3.0.0-M1.jar which makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

@nicolasstucki nicolasstucki force-pushed the scala-library-from-tasty-tests branch from b4dec3c to 3a6f1f7 Compare October 20, 2020 15:51
@nicolasstucki nicolasstucki force-pushed the scala-library-from-tasty-tests branch from 3a6f1f7 to b02abfc Compare October 20, 2020 15:53
@nicolasstucki nicolasstucki merged commit 57dd672 into scala:master Oct 21, 2020
@nicolasstucki nicolasstucki deleted the scala-library-from-tasty-tests branch October 21, 2020 15:02
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