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

Add attributes section to TASTy and use it for Stdlib TASTy #18599

Merged

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Sep 26, 2023

The Attributes section contains a list Attribute tags.

At this point, the only Scala 2 TASTy is the one from the standard library. To know that a TASTy contains the definitions of the standard library, we add the SCALA2STANDARDLIBRARYattr attribute to the TASTy file. We mark all unpickled classes from those TASTy files with Scala2x | Scala2Tasty.

Attributes will also be used to mark files that were compiled with explicit nulls using the EXPLICITNULLSattr attribute.

@dwijnand dwijnand added the needs-minor-release This PR cannot be merged until the next minor release label Sep 26, 2023
@nicolasstucki nicolasstucki force-pushed the add-attributes-section-to-tasty branch 2 times, most recently from 1c146f9 to 9481cf9 Compare September 27, 2023 13:21
@nicolasstucki nicolasstucki changed the title Add attributes section to TASTy Add attributes section to TASTy and use it for Stdlib TASTy Sep 27, 2023
@nicolasstucki nicolasstucki self-assigned this Sep 27, 2023
@nicolasstucki nicolasstucki marked this pull request as ready for review September 27, 2023 15:11
@nicolasstucki nicolasstucki removed their assignment Sep 27, 2023
@nicolasstucki nicolasstucki added this to the 3.4.0 milestone Sep 27, 2023
@nicolasstucki nicolasstucki added the release-notes Should be mentioned in the release notes label Sep 29, 2023
@nicolasstucki
Copy link
Contributor Author

Only the fact that we added a Attributes section to TASTy is important for the release notes.

@bishabosha
Copy link
Member

will be useful as well to add a JavaSourcefile attribute or equivalent for pipelining purposes

val attributesBuilder = List.newBuilder[String]
while (!isAtEnd) {
val length = readNat()
if (length > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

This test probably should not be there. It would most likely be invalid to have a zero length, but if it is not, it means there is actually an empty string attribute.

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 will specify and validate that attributes are non-empty strings.

@@ -267,6 +267,9 @@ Standard Section: "Comments" Comment*
```none
Comment = Length Bytes LongInt // Raw comment's bytes encoded as UTF-8, followed by the comment's coordinates.
```

Standard Section: "Attributes" UTF8*
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 specify here what are the possible attributes. They have semantic meaning, not just a collection of strings, so they should be specified.

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 extended the definition of Attributes

@sjrd
Copy link
Member

sjrd commented Oct 25, 2023

It would be good to have a second reviewer here. Adding a TASTy section is a pretty big deal.

@nicolasstucki nicolasstucki force-pushed the add-attributes-section-to-tasty branch 5 times, most recently from 6785fa8 to 2ccdcc1 Compare October 25, 2023 15:51
@@ -77,7 +77,7 @@ class ExtensionMethods extends MiniPhase with DenotTransformer with FullParamete

// Create extension methods, except if the class comes from Scala 2
// because it adds extension methods before pickling.
if (!(valueClass.is(Scala2x)))
if !valueClass.is(Scala2x, butNot = Scala2Tasty) then
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 fixed this issue in this commit to be able to test the attribute in scala2-library-tasty-tests/src/Main.scala

Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

One last comment, otherwise LGTM


Standard Section: "Attributes" Attribute*
```none
Attribute = FLAGattr UTF8 // attributes match the regex [a-zA-Z0-9]+
Copy link
Member

Choose a reason for hiding this comment

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

I might not have been clear enough here about what I meant by specifying what attributes we can have. I suggest we keep an actual list of the possible UTF-8 strings we can find here, and is their meaning. So something like:

Suggested change
Attribute = FLAGattr UTF8 // attributes match the regex [a-zA-Z0-9]+
Attribute = FLAGattr UTF8 // attributes match the regex [a-zA-Z0-9]+
Possible values of FLAGattr attributes are:
* Scala2StandardLibrary This TASTy contains code from the Scala 2 standard library

Then later on we can also add:

  * ExplicitNulls      This TASTy uses the explicit-nulls variant of the type system

Copy link
Member

Choose a reason for hiding this comment

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

if we do this then why store utf-8 at all, and go fully to tags

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps there's no real difference, indeed.

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 will use the tags only as we currently only need them for core Scala features. If we need we can add a tag that can store arbitrary UTF-8 later.

@@ -10,18 +10,15 @@ import java.nio.charset.StandardCharsets
object AttributePickler:

def pickleAttributes(
attributes: List[String],
scala2StandardLibrary: Boolean,
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 you create a separate immutable class Attributes in this package that bundles all the possible attributes as fields. pickleAttributes would take an Attributes as argument and AttributeUnpickler would read and probably directly expose an instance of Attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

attributeUnpicklerOpt.exists(_.attributes.scala2StandardLibrary)

/** This dependency was compiled with explicit nulls enabled */
// TODO Use this to tag the symbols of this dependency as compiled with explicit nulls (see use of unpicklingScala2Library).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we tag the top-level class with an annotation?

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 will need help from someone familiar with explicit nulls to finish this side of the implementation. We can do that in another PR. I could also remove this attribute temporarily until we have the full implementation.

Copy link
Member

Choose a reason for hiding this comment

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

What matters for now is that the information gets stored. If it's not used by dotc at the moment, then we don't care.

Standard Section: "Attributes" Attribute*
```none
Attribute = SCALA2STANDARDLIBRARYattr
EXPLICITNULLSattr
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 was wondering if this is the correct way to define experimental language attributes. We might end up at some point with attributes that are never used in stable code. On the other hand, we make sure that all attributes that we ever use are unambiguous.

Copy link
Member

Choose a reason for hiding this comment

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

Explicit-nulls is not experimental, at least not in the meaning of @experimental. For historical reasons, it benefits from a favored treatment and is allowed in stable, non-experimental builds (it only needs the flag).

attributeUnpicklerOpt.exists(_.attributes.scala2StandardLibrary)

/** This dependency was compiled with explicit nulls enabled */
// TODO Use this to tag the symbols of this dependency as compiled with explicit nulls (see use of unpicklingScala2Library).
Copy link
Member

Choose a reason for hiding this comment

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

What matters for now is that the information gets stored. If it's not used by dotc at the moment, then we don't care.

@nicolasstucki
Copy link
Contributor Author

Squashed and rebased

@nicolasstucki nicolasstucki merged commit 319e865 into scala:main Nov 6, 2023
16 checks passed
@nicolasstucki nicolasstucki deleted the add-attributes-section-to-tasty branch November 6, 2023 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-minor-release This PR cannot be merged until the next minor release release-notes Should be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants