Do not hide ZSUPER methods, fix consistency of owner and instance_methods - #6242
Conversation
|
I'll review if matz approves the behavior change at the developer meeting. |
|
@matz agreed during the meeting to remove ZSUPER methods, i.e., |
|
Replaced by #6251 |
|
No, it's opposite. I agree with this request, and disagree with #6251. I disagree to making copy, to keep symbolic semantics, i.e., |
|
@matz Oh, I thought during the meeting you said you were OK with copy-semantics #6251 and the semantics of the example shown as part of the meeting log, I even tried to confirm during the meeting to be sure I understood correctly, but apparently I must have misunderstood. IMHO #6251 is much cleaner and unifies the behavior with TruffleRuby and JRuby.
@matz Could you confirm you want this PR and not #6251 given these trade-offs? |
|
An example in Ruby code: class P
private def foo
1
end
end
class C < P
public :foo
end
m = C.new.method(:foo)
p m
p m.call
class P
alias old_foo foo # silence warning
private def foo
2
end
end
p m
p m.callOn 3.0.3, TruffleRuby, JRuby and #6251: On this PR: So this an unfortunate side effect, and I think unsolvable (except by removing ZSUPER methods). The semantics of #6251 are clear and already proven (it's the same semantics as |
|
Sorry for miscommunication. See the following example: class C
private def foo(); "C" end
end
class D<C
public :foo
end
m = D.instance_method(:foo)
class C
def foo(); "D" end
end
d=D.new
d.foo #=> should be "D"; "C" is *unacceptable*
m.bind_call(d) #=> "D" or "C"; negotiable; "C" is better (?)
m.owner #=> C or D; D is acceptable
m2 = D.instance_method(:foo)
m2.bind_call(d) #=> should be "D"Making copy by public/private/protected (by CRuby) is unacceptable, because it ignores the method redefinition afterwards. That's the difference from alias (it was intentionally designed to keep the definition at the moment). In other words, if it could follow the latest definition, it's OK to copy internally. It's implementation detail. And I admit that it's a very slight edge case, so the other implementations may choose to behave differently as implementation dependent. I am not sure how desirable it is, considering the effort that have already put in the JRuby/TruffleRuby to keep compatibility with CRuby. |
As I said above, "the same semantics as alias_method" is unacceptable. Maybe we just abandon this PR as well, and just make Method#owner point to the class that made the method public. |
|
Thank you for clarifying.
I think that's very hard (to implement and to reason about) without allowing Lines 1703 to 1720 in 7c1ed47 So I think this PR is as close as it gets to fixing Method#owner with minimal changes and still preserve compatibility for {Method,UnboundMethod}#== to compare methods. Results of the script above:
So this PR fits your semantics requirements, and fixes |
|
I also realized, with this PR |
jeremyevans
left a comment
There was a problem hiding this comment.
This looks mostly good. See inline comments.
d358bf6 to
80d2d1c
Compare
Based on jeremyevans@c95e7e5 Among other things, this fixes calling visibility methods (public?, protected?, and private?) on them. It also fixes #owner to show the class the zsuper method entry is defined in, instead of the original class it references. For some backwards compatibility, adjust #parameters and #source_location, to show the parameters and source location of the method originally defined. Also have the parameters and source location still be shown by #inspect. Clarify documentation of {Method,UnboundMethod}#owner. Add tests based on the description of https://bugs.ruby-lang.org/issues/18435 and based on ruby#5356 (comment) Fixes [Bug #18435] [Bug #18729] Co-authored-by: Benoit Daloze <[email protected]>
e71a6f5 to
bf151da
Compare
|
I've cleaned up the PR, the diff should be easier to review now as it's quite a bit smaller/clearer. |
bf151da to
3ad79b7
Compare
…7d32a5e54088b6b4014529bbf2b4b8c1a96029,c6319026caa6c8f0f569f80011e8502349a04b14,aa490f9442c32cd0e1e449ac817f410bd5924c8b: [Backport #18435]
Fix {Method,UnboundMethod}#super_method for zsuper methods
* We need to resolve the zsuper method first, and then look the super
method of that.
---
proc.c | 25 ++++++++++++-----------
spec/ruby/core/method/super_method_spec.rb | 15 +++-----------
spec/ruby/core/unboundmethod/super_method_spec.rb | 16 ++++++---------
3 files changed, 22 insertions(+), 34 deletions(-)
Add specs for {Method,UnboundMethod}#owner of a zsuper method
---
spec/ruby/core/method/owner_spec.rb | 6 ++++++
spec/ruby/core/unboundmethod/owner_spec.rb | 7 +++++++
2 files changed, 13 insertions(+)
Resolve zsuper method during lookup but preserve owner separately
* See https://bugs.ruby-lang.org/issues/18729#note-34
* See [Bug #18729]
---
proc.c | 109 +++++++++++++++++++++++++----------------------
test/ruby/test_method.rb | 66 +++++++++++++++++++++++-----
2 files changed, 114 insertions(+), 61 deletions(-)
Extend tests for a zsuper method of which the method it resolved to
has been removed
---
test/ruby/test_method.rb | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
Reduce diff to proc.c @ b0b9f72
* So it's easy to review #6242 +
#6467 and there are less changes
overall.
---
proc.c | 76 ++++++++++++++++++------------------------------
test/ruby/test_method.rb | 7 +++--
2 files changed, 34 insertions(+), 49 deletions(-)
Fixes:
Based on jeremyevans@c95e7e5
Add tests based on the description of https://bugs.ruby-lang.org/issues/18435
and based on #5356 (comment)