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

Prioritize TASTy files over classfiles on classpath aggregation #19431

Merged
merged 2 commits into from
Jan 31, 2024

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Jan 12, 2024

In most cases the TASTy file is chosen over the classfile in a classpath
because they are packaged together. However, for the scala-library
(Scala 2 compiled library) and scala2-library-tasty (Scala 3 compiled Scala 2 library)
we have the classfiles in one jar and the TASTy files in another jar.
Given that the classpaths order in guaranteed to be deterministic we might
end up with the classfile being loaded first and the TASTy file second.
The aggregator must be capable of choosing the TASTy file over the classfile
in this case as well. The aggregator will only choose the new TASTy over
the old classfile if the TASTy file has no classfile in its classpath. In
other words, we only use this new behaviour for TASTy only classpaths.

This also implies that we can just add the scala2-library-tasty as a
dependency in any project to use it. Note that this jar is not published
yet.

This change required a refactoring of ClassRepresentation implementations. Here is the change in structure and naming.

- ClassRepresentation
-   +- ClassFileEntry
-   |    +- ClassFileEntryImpl(AbstractFile)
-   +- SourceFileEntry
-   |    +- SourceFileEntryImpl(AbstractFile)
-   +- ClassAndSourceFilesEntry(AbstractFile, AbstractFile)
+ ClassRepresentation
+   +- BinaryFileEntry
+   |    +- ClassFileEntry(AbstractFile)
+   |    +- TastyWithClassFileEntry(AbstractFile)
+   |    +- StandaloneTastyFileEntry(AbstractFile)
+   +- SourceFileEntry(AbstractFile)
+   +- BinaryAndSourceFilesEntry(BinaryFileEntry, SourceFileEntry)

@nicolasstucki nicolasstucki self-assigned this Jan 12, 2024
@nicolasstucki nicolasstucki force-pushed the prioritze-tasty-over-classfiles branch 2 times, most recently from a0fd162 to 759a71c Compare January 12, 2024 12:40
@nicolasstucki nicolasstucki marked this pull request as ready for review January 19, 2024 08:44
@nicolasstucki nicolasstucki added the needs-minor-release This PR cannot be merged until the next minor release label Jan 19, 2024
@nicolasstucki nicolasstucki force-pushed the prioritze-tasty-over-classfiles branch 8 times, most recently from e33062c to 78dcb5f Compare January 29, 2024 09:09
@nicolasstucki nicolasstucki force-pushed the prioritze-tasty-over-classfiles branch 2 times, most recently from d0d5fbe to 7d23518 Compare January 30, 2024 08:09
@nicolasstucki nicolasstucki removed their assignment Jan 30, 2024
@nicolasstucki nicolasstucki requested a review from sjrd January 30, 2024 12:28
* creates an entry containing both of them. If there would be more than one class or source
* entries for the same class it always would use the first entry of each type found on a classpath.
*
* A class entry with a TASTy file will be chosen over one with a class file. Usually the class entries
Copy link
Member

Choose a reason for hiding this comment

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

A binary entry [...]
?

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 did not update this documentation correctly after some refactoring. I will update 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.

Updated

Comment on lines 135 to 134
// Here we do not create a TastyFileEntry(entry.file) because the TASTy and the classfile
// come from different classpaths. These may not have the same TASTy UUID.
Copy link
Member

Choose a reason for hiding this comment

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

This comment is confusing. It seems to directly contradict what the commit is trying to do. On the other hand, if I ignore the comment and only read the code, it makes sense. What is that comment really trying to say? Nothing else in this method creates a TastyFileEntry; why should I expect that we would do that here?

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 did not update this documentation correctly after some refactoring. I will update 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.

Updated

Copy link
Member

Choose a reason for hiding this comment

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

The same comment seems to still be here. Perhaps it's meant to say TastyWithClassFileEntry instead of TastyFileEntry? That would make more sense IIUC.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it should be TastyWithClassFileEntry. I updated it.

@@ -52,7 +52,8 @@ sealed trait BinaryFileEntry extends ClassRepresentation {
object BinaryFileEntry {
def apply(file: AbstractFile): BinaryFileEntry =
if file.isTasty then
TastyFileEntry(file)
if file.resolveSiblingWithExtension("class") != null then TastyFileEntry(file)
Copy link
Member

Choose a reason for hiding this comment

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

Should we rename TastyFileEntry into TastyAndClassFileEntry 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.

TastyWithClassFileEntry might be more appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

```
- ClassRepresentation
-   +- ClassFileEntry
-   |    +- ClassFileEntryImpl(AbstractFile)
-   +- SourceFileEntry
-   |    +- SourceFileEntryImpl(AbstractFile)
-   +- ClassAndSourceFilesEntry(AbstractFile, AbstractFile)
+ ClassRepresentation
+   +- BinaryFileEntry
+   |    +- ClassFileEntry(AbstractFile)
+   |    +- TastyWithClassFileEntry(AbstractFile)
+   +- SourceFileEntry(AbstractFile)
+   +- BinaryAndSourceFilesEntry(BinaryFileEntry, SourceFileEntry)
```
@nicolasstucki nicolasstucki force-pushed the prioritze-tasty-over-classfiles branch from acede1e to c48406c Compare January 31, 2024 07:39
In most cases the TASTy file is chosen over the classfile in a classpath
because they are packaged together. However, for the `scala-library`
(Scala 2 compiled library) and `scala2-library-tasty` (Scala 3 compiled Scala 2 library)
we have the classfiles in one jar and the TASTy files in another jar.
Given that the classpaths order in guaranteed to be deterministic we might
end up with the classfile being loaded first and the TASTy file second.
The aggregator must be capable of choosing the TASTy file over the classfile
in this case as well. The aggregator will only choose the new TASTy over
the old classfile if the TASTy file has no classfile in its classpath. In
other words, we only use this new behaviour for TASTy only classpaths.

This also implies that we can just add the `scala2-library-tasty` as a
dependency in any project to use it. Note that this jar is not published
yet.
@nicolasstucki nicolasstucki force-pushed the prioritze-tasty-over-classfiles branch from c48406c to ebe09ac Compare January 31, 2024 09:18
@bishabosha bishabosha merged commit 459fe60 into scala:main Jan 31, 2024
19 checks passed
@bishabosha bishabosha deleted the prioritze-tasty-over-classfiles branch January 31, 2024 12:34
@bishabosha
Copy link
Member

oh right I just saw the needs minor release, so does this have to wait until 3.5?

@Kordyjan Kordyjan added this to the 3.4.1 milestone Feb 14, 2024
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants