Project

General

Profile

Actions

Misc #17502

open

C vs Ruby

Added by marcandre (Marc-Andre Lafortune) almost 4 years ago. Updated 8 months ago.

Status:
Assigned
[ruby-core:101881]

Description

Some features are coded in a mix of Ruby and C (e.g. ractor.rb).

External gems don't have access to this. The C-API to deal with keyword parameters is also very verbose the parsing and the engine does not know it.

Moreover, some optimization PRs are simply rewriting C-code into Ruby using pseudo C code.

I understand the intentions are great, but changes like https://github.com/ruby/ruby/pull/4018/files seem a symptom that something needs to be improved with the C api.

-static VALUE
- flo_zero_p(VALUE num)
- {
-     return flo_iszero(num) ? Qtrue : Qfalse;
- }
# in different file:
+ def zero?
+   Primitive.attr! 'inline'
+   Primitive.cexpr! 'flo_iszero(self) ? Qtrue : Qfalse'
+ end

It seems to me that this is a way to circumvent a deeper issue. Is this the right direction?

Is there a plan for an API that would:

  1. be accessible to C extensions
  2. can't be re-written any faster in pseuso-C in Ruby
  3. has an easy way to define keyword parameters?

I realize that RBS may give perfect signatures, but ideally parameters would be more informative for C-functions too.

Ractor.method(:yield).parameters
# => [[:req, :obj], [:key, :move]] # good!
Fiber.method(:initialize).parameters
# => [[:rest]] # not good, should be [[:key, :blocking]]

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #16254: MRI internal: Define built-in classes in Ruby with `__intrinsic__` syntaxClosedko1 (Koichi Sasada)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0