Skip to content
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

TASTy Reader: support Scala 3.4 [ci: last-only] #10670

Merged
merged 19 commits into from Feb 12, 2024

Conversation

bishabosha
Copy link
Member

@bishabosha bishabosha commented Jan 23, 2024

Additions:

  • support for reading TASTy 28.4 (stable) which will release in Scala 3.4.0
  • a new error message format for reading a TASTy file with an unexpected version. The new message format is meant to be more readable and actionable.
  • support for reading TASTy-only classpaths. Previous 2.13.x versions required both a pair of Foo.class and Foo.tasty to read any top-level Scala 3 class Foo, now there only needs to be the TASTy file.
  • support for reading Java definitions from TASTy files. Java definitions can appear in TASTy files, for example to support pipelined compilation.

fixes scala/bug#12932

@scala-jenkins scala-jenkins added this to the 2.13.14 milestone Jan 23, 2024
@bishabosha bishabosha force-pushed the tasty/support-scala-3.4 branch 2 times, most recently from c3f5fa6 to 7c3a242 Compare January 23, 2024 16:43
@SethTisue SethTisue modified the milestones: 2.13.14, 2.13.13 Jan 23, 2024
@SethTisue SethTisue added prio:blocker release blocker (used only by core team, only near release time) release-notes worth highlighting in next release notes labels Jan 23, 2024
@SethTisue
Copy link
Member

SethTisue commented Jan 23, 2024

I don't have permission to push to this PR, but it looks like you've run afoul of fatal warnings only being enabled by default in CI. You need to:

diff --git src/compiler/scala/tools/tasty/Attributes.scala src/compiler/scala/tools/tasty/Attributes.scala
index 5d886ea998..44ed185777 100644
--- src/compiler/scala/tools/tasty/Attributes.scala
+++ src/compiler/scala/tools/tasty/Attributes.scala
@@ -15,6 +15,6 @@ package scala.tools.tasty
 class Attributes(val isJava: Boolean)
 
 object Attributes {
-  val empty = new Attributes(false)
-  val java = new Attributes(true)
+  val empty = new Attributes(isJava = false)
+  val java = new Attributes(isJava = true)
 }

if you want @som-snytt to let you out of named-arguments jail

@SethTisue
Copy link
Member

@lrytz and/or @som-snytt will probably want to eyeball the pipelining changes. it seems okay to me but I don't think my review is worth too much here.

@SethTisue SethTisue removed their assignment Jan 23, 2024
@som-snytt
Copy link
Contributor

Our goal here with named boolean args is to be more opinionated than dotty.

I'll make an effort to overcome my ignorance about all things tasty. One can only be intrigued by a pr from a branch at scalacenter, that organization cloaked in mystery.

@bishabosha
Copy link
Member Author

let it be noted that I also need to test more java language features before this PR is ready (enums already are causing an issue)

@bishabosha bishabosha requested a review from lrytz January 31, 2024 15:14
Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

The change in AggregateClassPath looks good, but I think it's not enough.

When a directory or jar contains both a/A.class and a/A.tasty, it seems to me the classes method in DirectoryClassPath or ZipArchiveClassPath will have a ClassFileEntry for both.

I haven't checked in detail where the classes method is used, but probably that should be deterministic too.

Usually we have an aggregate classpath of course, but I think in principle it could be a single entry.

Let me know if you prefer for me to take a look or pair on it.

@bishabosha
Copy link
Member Author

When a directory or jar contains both a/A.class and a/A.tasty, it seems to me the classes method in DirectoryClassPath or ZipArchiveClassPath will have a ClassFileEntry for both.

right, I wasn't sure if this method was supposed to only return a single entry per class, so I was relying on the aggregate classpath to merge them.

I think I would prefer some guidance here, I guess each "list" method should do its own merging at the end to reduce quadratic complexity

@lrytz
Copy link
Member

lrytz commented Feb 2, 2024

I'll take a look next week (was sick today)

@lrytz
Copy link
Member

lrytz commented Feb 5, 2024

@bishabosha
Copy link
Member Author

bishabosha commented Feb 5, 2024

@bishabosha what do you think about this approach?

https://github.com/scalacenter/scala/compare/tasty/support-scala-3.4...lrytz:scala:pr10670?expand=1

This was what I thought you might want to avoid because you are doing a directory lookup on every class file, rather than a single extra pass to merge that replaces class by tasty if it is encountered

@lrytz
Copy link
Member

lrytz commented Feb 5, 2024

Yeah, but the alternatives are pretty hairy, need to implement the filtering in a couple of places. I wonder if it's that bad? Directories are probably not performance relevant, the ordinary use case is Jars. There the lookup is a hash map lookup.

@bishabosha
Copy link
Member Author

bishabosha commented Feb 5, 2024

Yeah, but the alternatives are pretty hairy, need to implement the filtering in a couple of places. I wonder if it's that bad? Directories are probably not performance relevant, the ordinary use case is Jars. There the lookup is a hash map lookup.

I'm happy to go with this as dotty does the same, does the CI have benchmarks for if this is a significant problem for standard scala 2 projects with no tasty? (I'd assume its not an issue)

@bishabosha
Copy link
Member Author

@SethTisue and @lrytz addressed your comments and updated the PR description

@SethTisue SethTisue removed the prio:blocker release blocker (used only by core team, only near release time) label Feb 12, 2024
@SethTisue SethTisue merged commit 2d30e4b into scala:2.13.x Feb 12, 2024
3 checks passed
@bishabosha bishabosha deleted the tasty/support-scala-3.4 branch February 12, 2024 17:59
@SethTisue
Copy link
Member

@bishabosha this is failing on Windows, can you have a look? https://github.com/scala/scala/actions/runs/7875223173/job/21486648145

@bishabosha
Copy link
Member Author

bishabosha commented Feb 13, 2024

first look is that only the pipelining tests fail, and then only the java definitions can't be found, so my initial thoughts are that either the path to the java tasty jar isn't correct, the classpath isn't formatted correctly, or perhaps the jar isn't even written on windows? have to check this

@bishabosha
Copy link
Member Author

bishabosha commented Feb 13, 2024

Ok so it turns out we will have to disable these tests (run-pipelined and neg-pipelined on windows) - Dotty was writing a backslash for jar entries in windows (only for the -Yjava-tasty-output jar)

created scala/scala3#19681

@SethTisue
Copy link
Member

SethTisue commented Feb 13, 2024

it turns out we will have to disable these tests (run-pipelined and neg-pipelined on windows

Okay, sounds good. I see the PR (#10688).

In the meantime I can go ahead and announce the 2.13.13 release candidate today, then. (Community build is green.)

@SethTisue
Copy link
Member

@bishabosha do I remember/understand correctly that no additional followup PR will be needed for 3.4.0 final?

@bishabosha
Copy link
Member Author

Nothing is necessary, a good to have is removing the toolOveride to support the RC (which also enables 3.3.x nightlies)

@SethTisue
Copy link
Member

Nothing is necessary, a good to have is removing the toolOveride to support the RC (which also enables 3.3.x nightlies)

Mind pre-submitting that as a draft, so I can just hit "merge" when the time comes?

@SethTisue
Copy link
Member

@bishabosha in the draft release notes I mention 3.4 support but don't mention pipelining. it's too soon to highlight this for users, I assume?

@bishabosha
Copy link
Member Author

it's too soon to highlight this for users, I assume?

Well it's not ready now, however I plan to still release it as a patch version e.g 3.4.1

@SethTisue
Copy link
Member

I see. Well, in the blog post you'll surely write about it 😉 , you can highlight that support already landed in 2.13.13.

@bishabosha
Copy link
Member Author

bishabosha commented Feb 16, 2024

just observed a probable bug (not tested) in the classpath loading: - standalone objects e.g. object foo will have foo$.class and be associated with foo.tasty, i.e. dropping $ as well as .class

here is the dotty implementation of resolving a tasty name from a class file:

private def classNameToTasty(fileName: String): String =
    val classOrModuleName = fileName.stripSuffix(".class")
    val className =
      if classOrModuleName.endsWith("$")
        && classOrModuleName != "Null$" // scala.runtime.Null$
        && classOrModuleName != "Nothing$" // scala.runtime.Nothing$
        // Special case for `object $` in Amonite.
        // This is an ad-hoc workaround for Amonite `object $`. See issue #19702
        // This definition is not valid Scala.
        && classOrModuleName != "$"
      then classOrModuleName.stripSuffix("$")
      else classOrModuleName
    className + SUFFIX_TASTY

@lrytz
Copy link
Member

lrytz commented Feb 16, 2024

👍 we can still include a fix for that

@SethTisue
Copy link
Member

some followup work: #10689, #10694

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
5 participants