artichoke / ferrocarril

🚆 Experiments to embed Ruby on Rails in Rust with mruby
https://artichoke.github.io/ferrocarril/mruby/
MIT License
62 stars 2 forks source link

Specialize Enumerable#max and Enumerable#min for Range #4560 #177

Closed lopopolo closed 5 years ago

lopopolo commented 5 years ago

This patch prevents a hang for pathalogical (large) Ranges when computing max and min.

Range inherits its implementation of max and min from Enumerable. Enumerable implements max and min by calling each. For Range objects, this is unnecessary since we know the max and the min by the end and begin attributes.

It is also very slow. This code hangs unnecessarily:

(0..2**32).max
# ... hang
(0..2**32).min
# ... hang

This patch overrides max and min after including enumerable to yield based on the begin and end methods.

Upstream PR is mruby/mruby#4560.

lopopolo commented 5 years ago

Added some fixes to skip some known bad specs:

Ruby spec now can run to completion for core!

$ RUST_BACKTRACE=1 cargo run --bin spec-runner ./**/*.rb
...
Passed 5412, skipped 998, not implemented 201, failed 8629 specs.
lopopolo commented 5 years ago

Filed upstream issue for Float#round spec slowness

https://github.com/mruby/mruby/issues/4566