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

Align unpickled Scala 2 accessors encoding with Scala 3 #18874

Merged
merged 2 commits into from
Nov 16, 2023

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Nov 7, 2023

Adapt the flags of getters so they become like vals/vars instead. The
getters flags and info are modified. The private fields for case
accessors are not unpickled anymore.

We need these getters to be aligned with Scala 3 if we want to be able
to use the Scala 2 library TASTy. Otherwise library classfiles would not
behave in the same way as their TASTy counterpart.

This change may cause some macros to fail if they relied on the old
style accessors. This should be adapted to work with the old and new
representation. We observed that such a change is needed in verify,
other might be detected with the open community build.

@nicolasstucki nicolasstucki changed the title Move Scala 2 library tests from Windows into Linux Fix Scala 2 TASTy accessors in inline patterns reduction Nov 7, 2023
@nicolasstucki nicolasstucki self-assigned this Nov 7, 2023
@nicolasstucki nicolasstucki removed their assignment Nov 8, 2023
@nicolasstucki nicolasstucki requested review from sjrd and removed request for sjrd November 8, 2023 10:18
@sjrd

This comment was marked as outdated.

@nicolasstucki nicolasstucki force-pushed the fix-ci-for-scala2-library branch 2 times, most recently from a2a3f39 to 831c3c7 Compare November 8, 2023 12:42
@nicolasstucki nicolasstucki assigned nicolasstucki and unassigned sjrd Nov 8, 2023
sjrd
sjrd previously approved these changes Nov 8, 2023
@nicolasstucki nicolasstucki force-pushed the fix-ci-for-scala2-library branch 2 times, most recently from 2dfe63c to 6da4d4a Compare November 10, 2023 09:42
@nicolasstucki nicolasstucki changed the title Fix Scala 2 TASTy accessors in inline patterns reduction Align unpickled Scala 2 accessors encoding with Scala 3 Nov 10, 2023
@nicolasstucki
Copy link
Contributor Author

This PR has completely shifted from the original draft.

@@ -329,7 +329,7 @@ class InlineReducer(inliner: Inliner)(using Context):
val paramCls = paramType.classSymbol
if (paramCls.is(Case) && unapp.symbol.is(Synthetic) && scrut <:< paramType) {
val caseAccessors =
if (paramCls.is(Scala2x)) paramCls.caseAccessors.filter(_.is(Method))
if (paramCls.is(Scala2x, butNot = Scala2Tasty)) paramCls.caseAccessors.filter(_.is(Method))
Copy link
Contributor Author

@nicolasstucki nicolasstucki Nov 8, 2023

Choose a reason for hiding this comment

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

When we load the Scala 2 library TASTy we get the accessor as a val but if we load the library from classfiles we get both a val and a def. This guard is to avoid the filtering.

// Scala 2
   case class Foo extends AnyRef with Product with Serializable {
      <caseaccessor> <paramaccessor> private[this] val x: Int = _;
      <stable> <caseaccessor> <accessor> <paramaccessor> def x: Int = Foo.this.x;
      ...
// Scala 3
 case <noinits> <touched> class Foo <method> <stable> <touched>(
    <param> <touched> x: Int) extends Object(), _root_.scala.Product, _root_.
    scala.Serializable {
    <paramaccessor> <caseaccessor> <touched> val x: Int
   ...
  }

This comment was marked as outdated.

Copy link
Contributor Author

@nicolasstucki nicolasstucki Nov 8, 2023

Choose a reason for hiding this comment

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

Now I fixed the Scala2Unpickler to avoid loading the private val of case accessor and interpret all accessors as val/vars.

@@ -25,7 +25,7 @@ class CompletionSuite extends BaseCompletionSuite:
| Lis@@
|}""".stripMargin,
"""
|List scala.collection.immutable
|List: scala.collection.immutable
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rochala the List accessor changed from a getter into a proper value. I see that this has changed. Is this the correct output? Or is this a symptom of some logic not identifying the accessor correctly and not dealiasing it? I remember that there are some special cases for these aliases.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this is the correct completion label.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this PR going to be backported to LTS or is it targeted for 3.4 ?

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 sure if we can. It would break some macros. We should at least see what happens in the open community build before we consider it as an option.

Copy link
Contributor

@rochala rochala Nov 10, 2023

Choose a reason for hiding this comment

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

OK, this will make backporting a bit harder as tests will diverge between LTS and Next. This is not a big deal, but will be a small pain. I'll investigate whether the labels can print in the same fashion.

Adapt the flags of getters so they become like vals/vars instead. The
getters flags and info are modified. The private fields for case
accessors are not unpickled anymore.

We need these getters to be aligned with Scala 3 if we want to be able
to use the Scala 2 library TASTy. Otherwise library classfiles would not
behave in the same way as their TASTy counterpart.

This change may cause some macros to fail if they relied on the old
style accessors. This should be adapted to work with the old and new
representation. We observed that such a change is needed in `verify`,
other might be detected with the open community build.
@nicolasstucki
Copy link
Contributor Author

nicolasstucki commented Nov 10, 2023

false
0
false
List
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 sure if these changes in the coverage are fine. This seems to relate with the List accessor in Predef. Coverage might not be tracking it anymore because now it is a val instead of a def and there fore it does not consider it as a method call.

@sjrd sjrd merged commit fdf8de3 into scala:main Nov 16, 2023
18 checks passed
@sjrd sjrd deleted the fix-ci-for-scala2-library branch November 16, 2023 14:09
nicolasstucki added a commit that referenced this pull request Nov 17, 2023
tgodzik added a commit that referenced this pull request Dec 6, 2023
@Kordyjan Kordyjan added this to the 3.4.0 milestone Dec 20, 2023
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.

None yet

4 participants