[#99856] [Ruby master Feature#17143] Improve support for warning categories — merch-redmine@...

Issue #17143 has been reported by jeremyevans0 (Jeremy Evans).

16 messages 2020/09/03

[#99868] [Ruby master Bug#17144] Tempfile.open { ... } does not unlink the file — eregontp@...

Issue #17144 has been reported by Eregon (Benoit Daloze).

15 messages 2020/09/03

[#99885] [Ruby master Feature#17145] Ractor-aware `Object#deep_freeze` — marcandre-ruby-core@...

Issue #17145 has been reported by marcandre (Marc-Andre Lafortune).

32 messages 2020/09/03

[#99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen — eregontp@...

Issue #17146 has been reported by Eregon (Benoit Daloze).

16 messages 2020/09/03

[#100016] [Ruby master Feature#17171] Why is the visibility of constants not affected by `private`? — marcandre-ruby-core@...

Issue #17171 has been reported by marcandre (Marc-Andre Lafortune).

10 messages 2020/09/15

[#100024] [Ruby master Bug#17175] Ruby 2.5: OpenSSL related test failures — jaruga@...

Issue #17175 has been reported by jaruga (Jun Aruga).

10 messages 2020/09/16

[#100025] [Ruby master Feature#17176] GC.enable_autocompact / GC.disable_autocompact — tenderlove@...

Issue #17176 has been reported by tenderlovemaking (Aaron Patterson).

11 messages 2020/09/16

[#100099] [Ruby master Bug#17184] No stdlib function to perform simple string replacement — sheerun@...

Issue #17184 has been reported by sheerun (Adam Stankiewicz).

18 messages 2020/09/24

[#100192] [Ruby master Bug#17197] Some Hash methods still have arity 2 instead of 1 — marcandre-ruby-core@...

Issue #17197 has been reported by marcandre (Marc-Andre Lafortune).

14 messages 2020/09/28

[#100200] [Ruby master Misc#17199] id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa — baptiste.courtois@...

Issue #17199 has been reported by Annih (Baptiste Courtois).

7 messages 2020/09/28

[#100206] [Ruby master Misc#17200] DevelopersMeeting20201026Japan — mame@...

Issue #17200 has been reported by mame (Yusuke Endoh).

18 messages 2020/09/28

[#100239] [Ruby master Feature#17206] Introduce new Regexp option to avoid MatchData allocation — fatkodima123@...

Issue #17206 has been reported by fatkodima (Dima Fatko).

8 messages 2020/09/30

[ruby-core:99932] [Ruby master Feature#17151] Support multiple builtin ruby code for implimatation in Ruby & C

From: nobu@...
Date: 2020-09-05 01:21:45 UTC
List: ruby-core #99932
Issue #17151 has been updated by nobu (Nobuyoshi Nakada).


Why do they need to be separate files?

----------------------------------------
Feature #17151: Support multiple builtin ruby code for implimatation in Ruby & C
https://bugs.ruby-lang.org/issues/17151#change-87469

* Author: S_H_ (Shun Hiraoka)
* Status: Open
* Priority: Normal
----------------------------------------
## Summrary

Support these multiple builtin code in implimatation in Ruby & C.

```ruby
# excerpt of trueclass.rb
class TrueClass
  def to_s
    Primitive.attr! 'inline'
    Primitive.cexpr! 'rb_cTrueClass_to_s'
  end
end

```

```ruby
# excerpt of kernel.rb
module Kernel
  def class
    Primitive.attr! 'inline'
    Primitive.cexpr! 'rb_obj_class(self)'
  end
end

```

```c
// excerpt of object.c
#include "kernel.rbinc"
#include "trueclass.rbinc"

```

## Why

I want to running these code, for more faster to TrueClass and other classes.

ref: [Feature #17127 Some TrueClass methods are faster if implemented in Ruby](https://bugs.ruby-lang.org/issues/17127)
ref: [Feature #17054 Some NilClass methods are faster if implemented in Ruby](https://bugs.ruby-lang.org/issues/17054)

## Background

Currently, these multiple builtin code can not build(for redefination error).

Because, `tool/mk_builtin_loader.rb` defined same function.

example
```c
//  Kernel#class method's function defination in kernel.rbinc
static void
mjit_compile_invokebuiltin_for__bi0(FILE *f, long index, unsigned stack_size, bool inlinable_p)
{
    fprintf(f, "    VALUE self = GET_SELF();\n");
    fprintf(f, "    typedef VALUE (*func)(rb_execution_context_t *, VALUE);\n");
    if (inlinable_p) {
        fprintf(f, "%s", "    {\n");
        fprintf(f, "%s", "#line 20 \"../ruby/kernel.rb\"\n");
        fprintf(f, "%s", "    return rb_obj_class(self);\n");
        fprintf(f, "%s", "#line 44 \"../ruby/kernel.rbinc\"\n");
        fprintf(f, "%s", "    }\n");
        fprintf(f, "%s", "    \n");
        return;
    }
    fprintf(f, "    func f = (func)%"PRIdPTR"; /* == builtin_inline_class_20 */\n", (intptr_t)builtin_inline_class_20);
    fprintf(f, "    val = f(ec, self);\n");
}
```

```c
// TrueClass#to_s method's function defination in trueclass.rbinc
static void
mjit_compile_invokebuiltin_for__bi0(FILE *f, long index, unsigned stack_size, bool inlinable_p)
{
    fprintf(f, "    VALUE self = GET_SELF();\n");
    fprintf(f, "    typedef VALUE (*func)(rb_execution_context_t *, VALUE);\n");
    if (inlinable_p) {
        fprintf(f, "%s", "    {\n");
        fprintf(f, "%s", "#line 17 \"../ruby/trueclass.rb\"\n");
        fprintf(f, "%s", "    return rb_cTrueClass_to_s;\n");
        fprintf(f, "%s", "#line 30 \"../ruby/trueclass.rbinc\"\n");
        fprintf(f, "%s", "    }\n");
        fprintf(f, "%s", "    \n");
        return;
    }
    fprintf(f, "    func f = (func)%"PRIdPTR"; /* == builtin_inline_class_17 */\n", (intptr_t)builtin_inline_class_17);
    fprintf(f, "    val = f(ec, self);\n");
}

```

So, this code cause redefination error.

```bash
In file included from ../ruby/object.c:4617:
../ruby/trueclass.rbinc:27:1: エラー: ‘mjit_compile_invokebuiltin_for__bi0’ が再定義されました
   27 | mjit_compile_invokebuiltin_for__bi0(FILE *f, long index, unsigned stack_size, bool inlinable_p)
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../ruby/object.c:4616:
../ruby/kernel.rbinc:41:1: 備考: 前の ‘mjit_compile_invokebuiltin_for__bi0’ の宣言はここです
   41 | mjit_compile_invokebuiltin_for__bi0(FILE *f, long index, unsigned stack_size, bool inlinable_p)
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../ruby/object.c:4617:
../ruby/trueclass.rbinc:45:1: エラー: ‘mjit_compile_invokebuiltin_for__bi1’ が再定義されました
   45 | mjit_compile_invokebuiltin_for__bi1(FILE *f, long index, unsigned stack_size, bool inlinable_p)
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../ruby/object.c:4616:
../ruby/kernel.rbinc:75:1: 備考: 前の ‘mjit_compile_invokebuiltin_for__bi1’ の宣言はここです
   75 | mjit_compile_invokebuiltin_for__bi1(FILE *f, long index, unsigned stack_size, bool inlinable_p)
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: 警告: 認識できないコマンドラインオプション ‘-Wno-self-assign’ です
cc1: 警告: 認識できないコマンドラインオプション ‘-Wno-parentheses-equality’ です
cc1: 警告: 認識できないコマンドラインオプション ‘-Wno-constant-logical-operand’ です
```

## Propasal

Add the class(or module) name to the function definition.

exmaple:

```c
//  Kernel#class method's function defination in kernel.rbinc
static void
mjit_compile_invokebuiltin_for_kernel__bi0(FILE *f, long index, unsigned stack_size, bool inlinable_p)
{
    fprintf(f, "    VALUE self = GET_SELF();\n");
    fprintf(f, "    typedef VALUE (*func)(rb_execution_context_t *, VALUE);\n");
    if (inlinable_p) {
        fprintf(f, "%s", "    {\n");
        fprintf(f, "%s", "#line 20 \"../ruby/kernel.rb\"\n");
        fprintf(f, "%s", "    return rb_obj_class(self);\n");
        fprintf(f, "%s", "#line 44 \"../ruby/kernel.rbinc\"\n");
        fprintf(f, "%s", "    }\n");
        fprintf(f, "%s", "    \n");
        return;
    }
    fprintf(f, "    func f = (func)%"PRIdPTR"; /* == builtin_inline_class_20 */\n", (intptr_t)builtin_inline_class_20);
    fprintf(f, "    val = f(ec, self);\n");
}
```

```c
// TrueClass#to_s method's function defination in trueclass.rbinc
static void
mjit_compile_invokebuiltin_for_trueclass__bi0(FILE *f, long index, unsigned stack_size, bool inlinable_p)
{
    fprintf(f, "    VALUE self = GET_SELF();\n");
    fprintf(f, "    typedef VALUE (*func)(rb_execution_context_t *, VALUE);\n");
    if (inlinable_p) {
        fprintf(f, "%s", "    {\n");
        fprintf(f, "%s", "#line 17 \"../ruby/trueclass.rb\"\n");
        fprintf(f, "%s", "    return rb_cTrueClass_to_s;\n");
        fprintf(f, "%s", "#line 30 \"../ruby/trueclass.rbinc\"\n");
        fprintf(f, "%s", "    }\n");
        fprintf(f, "%s", "    \n");
        return;
    }
    fprintf(f, "    func f = (func)%"PRIdPTR"; /* == builtin_inline_class_17 */\n", (intptr_t)builtin_inline_class_17);
    fprintf(f, "    val = f(ec, self);\n");
}
```

## Pull Request

https://github.com/ruby/ruby/pull/3517





-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread