-
Notifications
You must be signed in to change notification settings - Fork 186
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
[Ruby 3.0 support] Handle Kernel#clone with freeze: true
argument
#2512
[Ruby 3.0 support] Handle Kernel#clone with freeze: true
argument
#2512
Conversation
I, probably, need help with passing a keyword argument to the initializeCloneNode.call(newObject, "initialize_clone", object); I haven't found any similar example of calling a Ruby method from Java code with keyword arguments. Could you please point me to such an example? |
Because we didn't do the keyword arguments changes yet for Ruby 3 it's just about passing a Hash with (One easier way would be to create a (Ruby) method on Truffle::KernelOperations that calls it, and call that method, but that would then introduce an extra call which feels rather suboptimal.) |
If you need any help don't hesitate to join our Slack as then it's easier to reply in real time. |
f3869b6
to
f85852e
Compare
I would appreciate any advice regarding failed specs:
So actually I suppose there is an issue with a string representation of RubyHash. Actually, it's a correct Hash And finally a key |
if (toForceFreezing(freeze) || toForceUnfreezing(freeze)) { | ||
final String string = "freeze"; | ||
final LeafRope rope = RopeOperations.encodeAscii(string, USASCIIEncoding.INSTANCE); | ||
final RubySymbol key = new RubySymbol(string, rope, Encodings.US_ASCII); |
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.
The RubySymbol should be package-private so it's clear it shouldn't be used directly.
There is already coreSymbols().FREEZE
which you can use :)
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.
Thank you. It fixed the failed specs as well 🎆
def clone(freeze: true) | ||
unless freeze | ||
def clone(freeze: nil) | ||
if freeze == false |
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.
Primitive.object_equal
or false == freeze
is safer here to avoid calling ==
on some potentially random object.
final String string = "freeze"; | ||
final LeafRope rope = RopeOperations.encodeAscii(string, USASCIIEncoding.INSTANCE); | ||
final RubySymbol key = new RubySymbol(string, rope, Encodings.US_ASCII); | ||
final boolean value = toForceFreezing(freeze); |
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.
We can just use freeze
later instead of value
, it can only be a boolean
at this point.
final int hashed = hashNode.execute(key); | ||
PackedHashStoreLibrary.setHashedKeyValue(newStore, 0, hashed, key, value); | ||
|
||
final RubyHash hash = new RubyHash( |
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 logic to create the Hash is a bit verbose, could you extract it to a method createFreezeBooleanHash()
or so?
Done. Please review. |
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.
Thank you for the great work on this PR!
Thank you for your help 🙇. I will squash commits and rebase on the master branch soon. |
I pushed a couple commits on top, I'll do the rebase now. |
baaa212
to
bb9b468
Compare
I squashed the second commit in the first one to make it easier to rebase, should be all good now. |
0cdfaa3
to
43d574c
Compare
This PR addresses issues:
and
Related issue - #2453
Changes
freeze: true
freeze: nil
freeze:
to#initialize_clone