You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As far as I understand coerce_to is kind of deprecated method in favor of rb_convert_type (and basically Primitive.rb_to_int shares with rb_convert_type logic and helper methods - convert_type and conversion_mismatch).
Should we 1) get rid of the coerce_to completely and 2) replace rb_convert_type calls for Integer with Primitive.rb_to_int instead?
Also a bit off topic question - does it make sense to have such optimised conversion helpers (like Primitive.rb_to_int) that fallback to a generic conversion method for other common Ruby types - String, Hash and Array? When we add implicit type conversion for every core method argument - it may be more visible performance improvement.
Yes, correct. coerce_to is from Rubinius and basically incorrect. rb_convert_type is correct but quite complicated, it would deserve a refactor to simplify it and probably rewrite it to Java (necessary to respect refinements), but not so high priority since coercion is rare.
IIRC, one concern is rb_convert_type is/might be slower than coerce_to.
Yes, exactly, we should avoid coerce_to/rb_convert_type(klass, method) and have Primitive.coerce_to_<method> (or convert_to_<method>). That means we have one such node per usage of that Primitive, which is exactly what we want. 99+% of them will just always receive already an instance of klass. For the remaining ones we'll either want to split for each caller (I'm thinking not worth it), or we accept the polymorphism, but in either case we only want it to affect that one method which is given different types for the same argument to be coerced, and leave the other methods as they are.
Replace e.g.
Truffle::Type.coerce_to obj, Integer, :to_int
withPrimitive.rb_to_int(obj)
The text was updated successfully, but these errors were encountered: