-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add attributes section to TASTy and use it for Stdlib TASTy #18599
Conversation
1c146f9
to
9481cf9
Compare
Only the fact that we added a |
645d7f5
to
4e12301
Compare
will be useful as well to add a |
val attributesBuilder = List.newBuilder[String] | ||
while (!isAtEnd) { | ||
val length = readNat() | ||
if (length > 0) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
compiler/src/dotty/tools/dotc/core/tasty/AttributePickler.scala
Outdated
Show resolved
Hide resolved
compiler/src/dotty/tools/dotc/core/tasty/AttributeUnpickler.scala
Outdated
Show resolved
Hide resolved
@@ -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* |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
It would be good to have a second reviewer here. Adding a TASTy section is a pretty big deal. |
6785fa8
to
2ccdcc1
Compare
compiler/src/dotty/tools/dotc/core/tasty/AttributeUnpickler.scala
Outdated
Show resolved
Hide resolved
2ccdcc1
to
51095d0
Compare
@@ -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 |
There was a problem hiding this comment.
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
There was a problem hiding this 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]+ |
There was a problem hiding this comment.
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:
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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). |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
compiler/src/dotty/tools/dotc/core/tasty/AttributePickler.scala
Outdated
Show resolved
Hide resolved
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). |
There was a problem hiding this comment.
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.
82d25c2
to
16966fd
Compare
Squashed and rebased |
The
Attributes
section contains a listAttribute
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 withScala2x | Scala2Tasty
.Attributes will also be used to mark files that were compiled with explicit nulls using the
EXPLICITNULLSattr
attribute.