-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Dotty's name encoding scheme does not match Scala 2 in some situations #5936
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
Comments
The commit where the current encoding scheme was implemented: debdafa#diff-e19ba84e185a59cba334b987a1cadc6a |
Subsidiary question: why does the new scheme have both class A {
def a_/(): Unit = {} // encoded as: public void a_$div()
def `b_/`(): Unit = {} // encoded as: public void b_$u002F()
} |
@smarter The reason to do it this way is that we cannot simply translate all operator occurrences, since they might be unintentional, i.e. some internal name might end up containing a nested
With blind |
Could we simplify the problem by simply disallowing |
Please don't. (also |
Maybe we should use some other character than $ in our encodings then :). |
This reverts commit 0abd076. Until scala#5936 is fixed, this is the most conservative option to get: > dotty-semanticdb/test:compile to work again.
paulp had a lot to say on this subject... I believe he said that a lot of
bugs in scalac could have been prevented by having a more principled set of
encoding rules.
I think there are a lot of unicode characters available that can be used,
and wouldn't be used by users (can be outlawed). And using more characters
means the encodings can be more robust since you don't need to overload
meaning.
…On Mon, Feb 18, 2019 at 5:27 AM Guillaume Martres ***@***.***> wrote:
Maybe we should use some other character than $ in our encodings then :).
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#5936 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAGAUAWYYpwcES-aPcjhQMvFGvJiaZQ1ks5vOn_9gaJpZM4a_Og4>
.
|
Name encoding in Dotty is already much more principled than in Scala 2. We could replace $ by a Unicode character but that would make Java interop impossible in some cases, e.g. an especially common pattern is writing a Java static class that forwards to a Scala object using the MODULE$ field. |
We could use 🤫 |
I like that actually, since it's not present on non-european keyboards it's harder to misuse, let's abandon the dollar peg and join the Eurozone! |
Name encoding does not kick in automatically for operator symbols which appear in a prefix of a name, so the name `<<<_of_A_given` was kept as is, which is problematic since `<` is not valid in method names on the JVM (in `i6902.scala`, `<<<<` runs fine even before this change, because monomorphic givens are implemented as vals, not defs). Having to remember to call `avoidIllegalChars` isn't great, but fixing that should be part of a bigger refactoring of name mangling we still need to do: scala#5936.
Name encoding does not kick in automatically for operator symbols which appear in a prefix of a name, so the name `<<<_of_A_given` was kept as is, which is problematic since `<` is not valid in method names on the JVM (in `i6902.scala`, `<<<<` runs fine even before this change, because monomorphic givens are implemented as objects, not defs). Having to remember to call `avoidIllegalChars` isn't great, but fixing that should be part of a bigger refactoring of name mangling we still need to do: scala#5936.
This reverts commit 5a74718 which itself reverted 0abd076. Since scala#5936 is not fixed yet, we need to turn off one test in semanticdb which uses parens in a class name.
This reverts commit 5a74718 which itself reverted 0abd076. Since scala#5936 is not fixed yet, so we need to turn off one test in semanticdb which uses parens in a class name. This is problematic, but upgrading to ASM 7.0 still seems worth it since it allows running scalac and dotty in the same classpath which should make it easier to test the scalac tasty reader.
This reverts commit 5a74718 which itself reverted 0abd076. Since scala#5936 is not fixed yet, so we need to turn off one test in semanticdb which uses parens in a class name. This is problematic, but upgrading to ASM 7.0 still seems worth it since it allows running scalac and dotty in the same classpath which should make it easier to test the scalac tasty reader.
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 Fixes scala#3100. Fixes scala#5936. Fixes scala#7492.
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 Fixes scala#3100. Fixes scala#5936. Fixes scala#7492.
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 Fixes scala#3100. Fixes scala#5936. Fixes scala#7492.
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.
Given:
Dotty generates methods:
Whereas Scala 2 generates:
I was about to fix this but the comment above
NameTransformer#encode
written by @odersky suggests that this is intentional: https://github.com/lampepfl/dotty/blob/12eef6d8e51dcd8a9a73387659b0f860d7b9ca80/compiler/src/dotty/tools/dotc/util/NameTransformer.scala#L87-L88@odersky Is being different from Scala 2 actually intended here ? This makes it impossible to call some Scala 2 methods from Dotty (we may want to change the name encoding scheme, but only if we get Scala 2 to change it in lockstep with us).
Marked as a blocker for the release because upgrading to ASM 7 lead to a name-encoding-related issue: #5917 (comment), I know how to fix it but the fix interacts with the current semantics of
encode
and I'd like to get some clarity here.The text was updated successfully, but these errors were encountered: