-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #4811: Widen private[this]/protected[this] just before Flatten #4814
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
Conversation
#159 is the original PR that introduced the phase |
test performance please |
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.
There's something weird going on: Extension methods does move code to companion objects, which causes strictly speaking illegal code.
First, private[this] methods are moved as private[this] to the companion, which means the forwarder to the method is incorrect. This should be corrected by removing Local
from extension methods.
Second, private[this]
fields in the instance are then accessed from the extension methods in the companion object. So far, this is not a problem because Ycheck is a ReTyper that does not do ensureAccessible except for New nodes. But since value classes cannot contain inner classes it's impossible to have a New
of a private[this] class accessed from an extension method.
All of this is a bit subtle and arbitrary. On the other hand, it only affects testing, not the actual code, which does not care about Local. So I would just do the change for extension methods and document the rest in the ExtensionMethods phase.
I took a different approach: I exclude fields when removing |
* | ||
* This allows subsequent code motions where code is moved from a class to its | ||
* companion object. | ||
* We maintain the Local flag for field since then cannot move to the companion |
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.
typo: then -> they
Would be good to check that this works for this example:
The extension method accesses the private[this] |
This is what I get after final class FooOps(s: String) extends AnyVal() {
private[this] val s: String
def foo: String = FooOps.foo$extension(this)
override def hashCode(): Int = FooOps.hashCode$extension(this)()
override def equals(x$0: Any): Boolean = FooOps.equals$extension(this)(x$0)
}
final lazy module val FooOps: FooOps$ = new FooOps$()
final module class FooOps$() extends Object() {
final def foo$extension($this: FooOps): String = $this.s
final def hashCode$extension($this: FooOps)(): Int = $this.s.hashCode()
final def equals$extension($this: FooOps)(x$0: Any): Boolean =
x$0 match
{
case x$0 @ _: FooOps @unchecked => $this.s.==(x$0.s)
case _ => false
}
} |
I think it would be nice to have ReTyper do ensureAccessible. Maybe in a separate PR? |
Ah yes indeed the extension method makes an illegal access (i.e. |
On Fri, Jul 20, 2018 at 9:56 AM, Allan Renucci ***@***.***> wrote:
I think it would be nice to have ReTyper do ensureAccessible. Maybe in a
separate PR?
That would make it slower. I'd rather restrict this to TreeChecker only.
—
… You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#4814 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAwlVsNUOCl-61yQFhcsj9TeOOgn3NV8ks5uIY0fgaJpZM4VWrEq>
.
{"api_version":"1.0","publisher":{"api_key":"
05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":
{"external_key":"github/lampepfl/dotty","title":"
lampepfl/dotty","subtitle":"GitHub repository","main_image_url":"
https://assets-cdn.github.com/images/email/message_cards/header.png
","avatar_image_url":"https://assets-cdn.github.com/images/email/message_
cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.
***@***.***
in #4814: I think it would be nice to have ReTyper do ensureAccessible.
Maybe in a separate PR?"}],"action":{"name":"View Pull Request","url":"
#4814 (comment)"}}} [
{ ***@***.***": "http://schema.org", ***@***.***": "EmailMessage",
"potentialAction": { ***@***.***": "ViewAction", "target": "
#4814 (comment)",
"url": "#4814 (comment)",
"name": "View Pull Request" }, "description": "View this Pull Request on
GitHub", "publisher": { ***@***.***": "Organization", "name": "GitHub", "url": "
https://github.com" } }, { ***@***.***": "MessageCard", ***@***.***": "
http://schema.org/extensions", "hideOriginalBody": "false", "originator":
"AF6C5A86-E920-430C-9C59-A73278B5EFEB", "title": "Re: [lampepfl/dotty]
Fix #4811: Widen private[this]/protected[this] just before Flatten
(#4814)", "sections": [ { "text": "", "activityTitle": "**Allan Renucci**",
"activityImage": "https://assets-cdn.github.com/images/email/message_
cards/avatar.png", "activitySubtitle": ***@***.***", "facts": [ ] } ],
"potentialAction": [ { "name": "Add a comment", ***@***.***": "ActionCard",
"inputs": [ { "isMultiLine": true, ***@***.***": "TextInput", "id":
"IssueComment", "isRequired": false } ], "actions": [ { "name": "Comment",
***@***.***": "HttpPOST", "target": "https://api.github.com", "body":
"{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\":
\"lampepfl/dotty\",\n\"issueId\": 4814,\n\"IssueComment\":
\"{{IssueComment.value}}\"\n}" } ] }, { "name": "Close pull request",
***@***.***": "HttpPOST", "target": "https://api.github.com", "body":
"{\n\"commandName\": \"PullRequestClose\",\n\"repositoryFullName\":
\"lampepfl/dotty\",\n\"pullRequestId\": 4814\n}" }, { "targets": [ {
"os": "default", "uri": "https://github.com/lampepfl/
dotty/pull/4814#issuecomment-406519498" } ], ***@***.***": "OpenUri", "name":
"View on GitHub" }, { "name": "Unsubscribe", ***@***.***": "HttpPOST", "target":
"https://api.github.com", "body": "{\n\"commandName\":
\"MuteNotification\",\n\"threadId\": 358265130\n}" } ], "themeColor":
"26292E" } ]
--
Prof. Martin Odersky
LAMP/IC, EPFL
|
Edits: In fact, if you look at
So, derived value class parameters do Summary: What I proposed originally here will not work. |
a843f61
to
724c377
Compare
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.
Update the docs of Getters and ExtensionMethods to indicate their new behavior, also would be nice if TreeChecker started checking accessibility everywhere.
This fixes the crash because in Getter we don't look for a setter that was not generated. The original documentation for ElimLocals says: This phase drops the Local flag from all private[this] and protected[this] members. This allows subsequent code motions where code is moved from a class to its companion object. It invalidates variance checking, which is consequently disabled when retyping. We instead let ExtensionMethods remove the flag when needed. And then remove all Local flags in Getters once there are not needed anymore.
This fix the crash because we don't need to generate a getter or setter
for private[this] field anymore.
The original documentation for ElimLocals says:
I believe this is legacy code and not true anymore (when code is moved to the companion object, modifiers are widened as needed). This phase is still required to Ycheck Flatten. Not sure why...