Skip to content

Revert to the Scala 2 name encoding scheme #7601

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

Merged
merged 2 commits into from
Nov 25, 2019

Conversation

smarter
Copy link
Member

@smarter smarter commented Nov 21, 2019

There were several issues with the scheme we used so far:

  • It's different from Scala 2, meaning that some Scala 2 methods could
    not be called from Dotty and vice-versa (see the added
    sbt-dotty/sbt-test/scala2-compat/akka/i3100.scala test for an example)
  • It can lead to invalid filenames on Windows (Invalid file name for class files on Windows #7492)
  • The handling of backticks is broken: adding or removing backticks
    around a name changes how it's encoded.

To maintain Scala 2 compat we don't have a lot of choices here, we must
use the same scheme, so this commit aligns NameTransformer.scala with
https://github.com/scala/scala/blob/2.13.x/src/library/scala/reflect/NameTransformer.scala

Fixes #3100. Fixes #5936. Fixes #7492.

@sjrd
Copy link
Member

sjrd commented Nov 21, 2019

You should probably get rid of https://github.com/lampepfl/dotty/blob/a356535118bdbf4dfbaa48b06a8c77380b3c3e9f/compiler/src/dotty/tools/backend/sjs/JSEncoding.scala#L232 in the Scala.js backend.

Just preserve the handling of _ which is Scala.js-specific.

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

It's good that al aspects of encoding / decoding are now combined.

We should have a comment somewhere (maybe in NameTransformer) what the
precise name mangling scheme is now. The commit should also have a short message
indicating how this changed.

Otherwise LGTM

@odersky odersky assigned smarter and unassigned odersky Nov 25, 2019
There were several issues with the scheme we used so far:
- It's different from Scala 2, meaning that some Scala 2 methods could
not be called from Dotty and vice-versa (see the added
sbt-dotty/sbt-test/scala2-compat/akka/i3100.scala test for an example)
- It can lead to invalid filenames on Windows (scala#7492)
- The handling of backticks is broken: adding or removing backticks
around a name changes how it's encoded.

To maintain Scala 2 compat we don't have a lot of choices here, we must
use the same scheme, so this commit aligns NameTransformer.scala with
https://github.com/scala/scala/blob/2.13.x/src/library/scala/reflect/NameTransformer.scala

Some examples:

Method name | Old encoding | New encoding
-----------------------------------------
a_+         |      a_$plus |      a_$plus
`a_+`       |          a_+ |      a_$plus
`+_a`       |          +_a |      $plus_a
a_/         |       a_$div |       a_$div
`a_/`       |     a_$u002F |       a_$div

If a Dotty method is called `def a_$plus` we won't misinterpret it as
`a_+` because the method name comes from the tasty tree which stores
unencoded names. On the other hand, names coming from Java / Scala 2 as
well as top-level classnames might be misinterpreted as encoded names if
they contain a user-written $, this is left unspecified.

Fixes scala#3100. Fixes scala#5936. Fixes scala#7492.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants