Range#size missing from JRuby 1.7.8 in 2.0 mode#1252
Range#size missing from JRuby 1.7.8 in 2.0 mode#1252tedpennings wants to merge 25 commits intojruby:masterfrom tedpennings:master
Conversation
|
RubyRange.java seems like it is where a @JRubyMethod for this should be made. Enumerable size in 2.0+ appears to be a funcall to a size method if it is available or nil. |
|
Ok cool, thanks @enebo ! I'll take a stab at Range#size tonight. I'll give Enumerable some thought but it might be a little too in depth for me. |
Gets Numeric#step.size doing its thing by putting the following pieces in place: * implement Numeric#intervalStepSize closely following the MRI implementation (https://github.com/ruby/ruby/blob/09b02349c212cac6395e9a634e3d4610e9bbc48c/numeric.c#L1799) * implement Numeric#floatStepSize which Numeric#intervalStepSize relies on, again porting from MRI (https://github.com/ruby/ruby/blob/09b02349c212cac6395e9a634e3d4610e9bbc48c/numeric.c#L1748)) * refactor Numeric#floatStep19 to also use the new floatStepSize, which not only avoids duplication, but also fixes some tests * create Numeric#stepSize, and use it to enumeratorizeWithSize our steps We'll be able to un-exclude test_size_for_step from test_enumerator.rb once Range#size is implemented (jruby#1252).
Gets Numeric#step.size doing its thing by putting the following pieces in place: * implement Numeric#intervalStepSize closely following the MRI implementation (https://github.com/ruby/ruby/blob/09b02349c212cac6395e9a634e3d4610e9bbc48c/numeric.c#L1799) * implement Numeric#floatStepSize which Numeric#intervalStepSize relies on, again porting from MRI (https://github.com/ruby/ruby/blob/09b02349c212cac6395e9a634e3d4610e9bbc48c/numeric.c#L1748)) * refactor Numeric#floatStep19 to also use the new floatStepSize, which not only avoids duplication, but also fixes some tests * create Numeric#stepSize, and use it to enumeratorizeWithSize our steps We'll be able to un-exclude test_size_for_step from test_enumerator.rb once Range#size is implemented (jruby#1252).
|
Hey @tedpennings, hopefully I'm not chiming in too late, but there's been a couple of recent changes that should help you fix this up:
Then you'll be able to delete Hope that helps! Let me know if you have any questions... |
|
Thanks @dmarcotte ! I'm going to take a crack at this now. I'll update this issue once I've got something to show 😄 |
|
How do the above two commits look? Is there anything that should be done in there to ensure that the @JRubyMethod is only available in 2.0+ mode? (1.9 doesn't have a Range#size method) I'll take another look at the Range#step and Range#each enumerator size problem tomorrow. I think that's a bit bigger. It might be worth a separate issue. I can create it if that would help. |
|
Looking good @tedpennings! A few notes:
As for 2.0 vs. 1.9: the next major version of JRuby (the version being worked on in master) will only support a single Ruby version, so what you've got here is correct. Finally, good call on Hope that all makes sense! Thanks again, and feel free to let me know if you have more questions. |
|
Ok @dmarcotte - I'll rebase when I get home. You're right re RubyNumeric instead of RubyInteger. I was thinking of the (quirky) MRI 2.0 behavior where it will return a size for a range of floats, and an Enumerable with size for each/step, but it won't return an array for them. Last night another test case came to mind that I think we need to consider. RubyNumeric/intervalStepSize doesn't handle RubyBignum. For a range size, that's actually a significant limitation, so RubyNumeric.intervalStepSize might need refactoring. Here's the error you get with my present PR from Bignums: |
|
Great catch on the class cast error @tedpennings! I'll get that fixed up very soon; I reckon you don't need to worry about it for your PR. |
* More progress inlining code on bench_method_dispatch.rb * The next set of crashers in inlining requires fixes to the WrappedIRClosure operand to take an explicit self arg so that on inlining, the correct (original) self can be passed into the block rather than passing the self from the host scope into which code got inlined. TO BE DONE.
* This fix is required for proper inlining of scopes that contain blocks so that the self prior-to-inlining can be passed into the block after-inlining into another scope. * With this fix, bench_method_dispatch.rb runs with -Xir.profile=true without crashing. Same for bench_fib_recursive, bench_red_black, shootout/meteor, shootout/mandelbrot, bench_richards, bench_neural_net, and bench_tictactoe. * There are still known bugs in the inlining code (search for FIXMEs or 'This is buggy' comments in the relevant code), but the correctness has moved along far enough to enable profiling and inlining on a large enough set of programs without crashing or yielding incorrect results.
This accompanies 2c8e310
Related to #1274. Tests pass now.
…:==, expected one of []
…e format. removed any import or usage of java.util.logging
…ntral (surprised that oss.sonatype.org does not prevent that). that just produces a lot of traffic on that repository and if that repository is inaccessible the artifact can NOT be used anymore [skip ci]
* This prevents IR interpreter from crashing since it always expects a RootNode. * 2 more failing specs now green.
* Thus far, begin/end block were getting their own scope whereas they ought to share their parent's scope just like for-loops. This patch fixes it. * One more spec now green. More debugging needed to figure out why the other BEGIN_spec is still failing.
|
Hm I think I failed at git :( I'll create a new PR for this one change and you can close this as unmerged. For future reference, how would I rebase to make this work but not have a million commits in this PR? |
|
Hrm... looks like you were working on master in your fork, so I think when you rebased it and force-pushed, the commits you pulled in are now in a strict sense "different" from the ones already in jruby/master. You should be able to avoid this by always working on a branch in your fork, and keeping its master up to date from jruby/master with Note that since the rebase monkeyed with your master's history, to get back to a good state, the easiest thing may be to re-fork and apply your changes in a branch there. Hope that solves it for you... as always, more questions are welcome. |
|
Thanks, doing that now. I'll create a new PR once it's done. I think I'm going to add some rspec tests for different strange range conditions too, just so we have our bases covered re integer overflows and casts, e.g., (Fixnum..Bignum).size #=> Fixnum; (Fixnum..Bignum).size #=> Bignum; (Bignum..Bignum).size #=> Fixnum, etc |
|
Sounds good. The specs sound great too, but I'd say they should be sent to RubySpec rather than be added here, so you should be good to go with the PR as-is. Let me know if you need anything else! (Oh, and let me know if it'll be a while before you can send for whatever reason. No worries if that's the case! It's just that I'm putting off sending a change that would conflict with yours to avoid causing you churn, but I don't want to sit on it too long.) |
|
Ok all set, see #1305 . Thanks for all the help! |
Add a size method to RubyRange to resolve #1252
Range#size appears to be missing from the latest JRuby in Ruby 2.0.0 mode. Range#size was added to Ruby in 2.0.0. The other new Range methods added, like #bsearch, appear to be there -- only #range is missing.
Enumerator#size appears to be defective and may be related:
For comparison, here's the MRI 2.0 behavior:
I'd be happy to send in a PR for this if you could point me in the direction of where this should be implemented. It looks like the RubyRange.java and RubyEnumerator.java classes are probably the most obvious places, but I wanted to ask before just sending in a PR for that (+tests).