-
Notifications
You must be signed in to change notification settings - Fork 1.1k
use methods to find companion class #436
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
This branch includes change only to |
Otherwise we'll trigger early creation of companions that could shadow something.
034cce7
to
93399e7
Compare
93399e7
to
0a94d6e
Compare
@odersky please review. |
else if (defaultGetters.nonEmpty) | ||
companionDefs(anyRef, defaultGetters) | ||
else Nil | ||
else { |
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.
Why the change in formatting? I liked the old one better.
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.
This code was rewritten, it used to have more complicated logic between the commits. I have no problem changing it back.
I did not see a place where companion methods are turned into trees. Did I miss something? The concern here is that TreeTypeMap (and with it, subst, changeOwner) work on trees, not scopes. So they will not create new companion links unless the methods are part of the tree, |
Actually due to way how
we'll have companion object which is same for all specialized classes. I wanted to discuss if this is what we want. Actually the more i think of this, the more I believe that this actually makes sense. |
if (companionClassMethod.exists) | ||
companionClassMethod.entered | ||
} | ||
|
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.
It's a pity that we still need scalacLinkedClass here, because it means we cannot get rid of the associated complexity of isCoDefinedWith. I would much prefer if we got the linked class directly from the unpickling info, instead of looking at
the scope.
Overall, I am a bit ambivalent about this PR. It adds a lot of complications. So far the main benefit is that it makes linkedClass insensitive to naming issues. However, I would prefer simply to get naming right instead of inventing another mechanism to patch any faults it might have. And it looks that this (getting naming right) requires altogether less effort than this PR. There would be a win in my mind if we could at the same time get rid of isCoDefinedWith which is fragile and very dependent on how the compiler is used. But so far the PR does not do that. |
@odersky, can you please tell which complications you mean in your comment? All this pr does:
|
Yes, and it also gives us guarantees that any tool that somehow changes or interacts with TASTY files, or any compiler plugin, becomes easier to implement as there is one less thing that they can break: links between companions cannot be silently broken without intention anymore. I believe that this is an improvement on its own. |
Regarding the TreeTypeMap issue, the problem is if you duplicate a code like this:
I do not see how the link between the copies of the C's could be maintained. |
Complications: I just look at (1) lines added, (2) files touched, and the pretty hairy code in Namer. It certainly looks like we cannot contain this to a single point, and have to add complications to several places. Regarding robustness, I am still not sure. I am more of the school of "fail early". That is, if somebody gets naming wrong it's better to fail quickly rather than have another mechanism that works around it. Otherwise put, try to get to a state where every piece of information is encoded in exactly one way. One could argue that companion methods are what defines companionship and names do not matter. But then we need to (1) get rid of references where names do matter as in scalacLinkedClass and (2) make sure that names will never matter in any other way. If we fail to do that, it's probably better to make sure names work right, because that way we do not duplicate info and if we get it wrong we fail early. But I noted another aspect where the new scheme beats the old: We no longer need to traverse the tree to find companions of inner classes. That's a big win! And furthermore, one could argue that scalac unpickling is the only reason we still need scalacLinkedClass, and hopefully that will go away and be replaced with TASTY. So that tilts the balance back in favor of this PR. |
@odersky, in your example, are you TreeTypeMap-ing If you are duplicating I propose to take this discussion offline, but it would help me if you could tell me what do you find complicated in this PR, as I will have time to address this comments and come up with simpler implementation. The only complicated thing that I see around is |
I meant: duplicate |
Overall I am now in favor of the PR. I would try hard to find a better implementation in Namer, however. |
As private symbols aren't inherited, this does not break caching.
OK, good! Then let's add this to the comment, to make it more understandable. |
That's all I have. |
This reverts commit b653007.
use methods to find companion class
No description provided.