[#115565] [Ruby master Feature#20034] [mkmf] Support creating a compilation database for C language tooling — "pounce (Calvin Lee) via ruby-core" <ruby-core@...>

Issue #20034 has been reported by pounce (Calvin Lee).

7 messages 2023/12/01

[#115595] [Ruby master Bug#20043] `defined?` checks for method existence but only sometimes — "tenderlovemaking (Aaron Patterson) via ruby-core" <ruby-core@...>

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

10 messages 2023/12/05

[#115598] [Ruby master Bug#20044] Add runtime flag and environment variable for prism — "HParker (Adam Hess) via ruby-core" <ruby-core@...>

Issue #20044 has been reported by HParker (Adam Hess).

7 messages 2023/12/06

[#115647] [Ruby master Bug#20048] UDPSocket#remote_address spec errors — "vo.x (Vit Ondruch) via ruby-core" <ruby-core@...>

Issue #20048 has been reported by vo.x (Vit Ondruch).

9 messages 2023/12/07

[#115648] [Ruby master Feature#20049] Destructive drop_while for Array and Hash — "chucke (Tiago Cardoso) via ruby-core" <ruby-core@...>

Issue #20049 has been reported by chucke (Tiago Cardoso).

8 messages 2023/12/07

[#115649] [Ruby master Bug#20050] Segfault on Ruby 3.2.2 on x86_64 Darwin 20 (maybe in Array#hash) — "martinemde (Martin Emde) via ruby-core" <ruby-core@...>

Issue #20050 has been reported by martinemde (Martin Emde).

11 messages 2023/12/07

[#115671] [Ruby master Feature#20054] Replace the use of `def` in endless method definitions with a new sigil — "sawa (Tsuyoshi Sawada) via ruby-core" <ruby-core@...>

Issue #20054 has been reported by sawa (Tsuyoshi Sawada).

7 messages 2023/12/09

[#115682] [Ruby master Misc#20056] Dir#chdir inconsistency with Dir.chdir — "zverok (Victor Shepelev) via ruby-core" <ruby-core@...>

Issue #20056 has been reported by zverok (Victor Shepelev).

12 messages 2023/12/10

[#115684] [Ruby master Feature#20057] Change behaviour of rb_register_postponed_job for Ruby 3.3 — "kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core" <ruby-core@...>

Issue #20057 has been reported by kjtsanaktsidis (KJ Tsanaktsidis).

8 messages 2023/12/11

[#115688] [Ruby master Bug#20058] `warning: bigdecimal/util is found in bigdecimal` even if the gem spec has the `add_dependency "bigdecimal"` entry — "yahonda (Yasuo Honda) via ruby-core" <ruby-core@...>

Issue #20058 has been reported by yahonda (Yasuo Honda).

10 messages 2023/12/11

[#115749] [Ruby master Feature#20066] Reduce Implicit Array/Hash Allocations For Method Calls Involving Splats — "jeremyevans0 (Jeremy Evans) via ruby-core" <ruby-core@...>

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

19 messages 2023/12/15

[#115764] [Ruby master Feature#20069] Buffer class in stdlib — "pynix (Pynix wang) via ruby-core" <ruby-core@...>

Issue #20069 has been reported by pynix (Pynix wang).

9 messages 2023/12/16

[#115830] [Ruby master Misc#20075] DevMeeting-2024-01-17 — "mame (Yusuke Endoh) via ruby-core" <ruby-core@...>

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

9 messages 2023/12/21

[#115831] [Ruby master Bug#20076] M:N scheduler crashes on macOS with RUBY_MN_THREADS=1 — "hsbt (Hiroshi SHIBATA) via ruby-core" <ruby-core@...>

Issue #20076 has been reported by hsbt (Hiroshi SHIBATA).

7 messages 2023/12/21

[#115847] [Ruby master Bug#20079] alexandria testsuite began to segfault recently — "mtasaka (Mamoru TASAKA) via ruby-core" <ruby-core@...>

Issue #20079 has been reported by mtasaka (Mamoru TASAKA).

15 messages 2023/12/22

[#115864] [Ruby master Feature#20080] Implement #begin_and_end method on Range — "stuyam (Stuart Yamartino) via ruby-core" <ruby-core@...>

Issue #20080 has been reported by stuyam (Stuart Yamartino).

17 messages 2023/12/22

[#115892] [Ruby master Bug#20085] Fiber.new{ }.resume causes Segmentation fault for Ruby 3.3.0 on aarch64-linux — "oleksii (Oleksii Leonov) via ruby-core" <ruby-core@...>

Issue #20085 has been reported by oleksii (Oleksii Leonov).

27 messages 2023/12/25

[#115912] [Ruby master Bug#20090] Anonymous arguments are now syntax errors in unambiguous cases — "willcosgrove (Will Cosgrove) via ruby-core" <ruby-core@...>

Issue #20090 has been reported by willcosgrove (Will Cosgrove).

8 messages 2023/12/26

[#115919] [Ruby master Feature#20093] Syntax or keyword to reopen existing classs/modules, never to define new classs/modules — "tagomoris (Satoshi Tagomori) via ruby-core" <ruby-core@...>

Issue #20093 has been reported by tagomoris (Satoshi Tagomori).

11 messages 2023/12/27

[#115923] [Ruby master Bug#20094] Inline while loop behavior changed unexpectedly in 3.3.0 — "sisyphus_cg (Sisyphus CG) via ruby-core" <ruby-core@...>

Issue #20094 has been reported by sisyphus_cg (Sisyphus CG).

12 messages 2023/12/27

[#115925] [Ruby master Bug#20096] Ruby 3.2.2 win32/registry: Junk appended to Windows Registry String Value — "jay4rubydev (Jay M) via ruby-core" <ruby-core@...>

SXNzdWUgIzIwMDk2IGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGpheTRydWJ5ZGV2IChKYXkgTSkuDQ0K

8 messages 2023/12/27

[ruby-core:115754] [Ruby master Feature#20057] Change behaviour of rb_register_postponed_job for Ruby 3.3

From: "ko1 (Koichi Sasada) via ruby-core" <ruby-core@...>
Date: 2023-12-15 19:50:59 UTC
List: ruby-core #115754
Issue #20057 has been updated by ko1 (Koichi Sasada).


`rb_postponed_job_preregister()`, `rb_postponed_job_register/_once()` run O(n) where n is registered jobs.
`rb_postponed_job_trigger()` is O(1).
We believe `n` is enough small though...

----------------------------------------
Feature #20057: Change behaviour of rb_register_postponed_job for Ruby 3.3
https://bugs.ruby-lang.org/issues/20057#change-105692

* Author: kjtsanaktsidis (KJ Tsanaktsidis)
* Status: Open
* Priority: Normal
----------------------------------------
This ticket is to discuss some changes to `rb_register_postponed_job` that @ko1 and myself propose to make for Ruby 3.3. The motivation for this work is to fix a bug in the current implementation, which can cause the registered functions to be called with the wrong `data` argument (https://bugs.ruby-lang.org/issues/19991).

There's a long discussion on the associated PR (https://github.com/ruby/ruby/pull/8949) but in the end we came to the conclusion that the best way to fix this bug involved actually changing the current semantics of `rb_register_postponed_job`. I'm opening this issue to get feedback on this approach and to see if anybody knows of a reason why we should not release this for Ruby 3.3.

## Current behaviour in Ruby 3.2

Currently, Ruby has two functions for interacting with postponed jobs. These jobs can be enqueued from anywhere (including signal handlers), and will be executed next time Ruby checks for `RUBY_VM_CHECK_INTS()`.

* `rb_postponed_job_register(func, data)`: Schedules `func(data)` to be executed the next time `RUBY_VM_CHECK_INTS` is checked.
* `rb_postponed_job_register_once(func, data)`: Works like `rb_postponed_job_register`, _except_ if `func` is already scheduled to be executed (either with this `data` or with different `data`), in which case it does nothing.

The postponed jobs are stored in a fixed sized array (of length 1024), so it's possible that enqueuing them could fail if the buffer is full. In this case, they signal this by returning `0` (otherwise, they return `1` for successful enqueue or `2` because `rb_postponed_job_register_once` did nothing because `func` was already in the queue).

Unfortunately, as I mentioned before, the implementation of these functions are subject to a race condition because `func` and `data` are not written into the postponed job buffer together atomically (they are two separate variables and CPUs tend not to have double-word atomic instructions). Again, see https://bugs.ruby-lang.org/issues/19991 for the full details.

## What we have done

Whilst working on this issue, we had a look at all of the in-the-wild usages of these APIs on rubygems. The only real usage of these APIs is for profiling tools, and the following was true for essentially all of them:

* Each gem only is registering a single callback function,
* Almost all of the usages either make no use of the `data` argument at all, or pass some kind of never-changing global context into it.
* There are only a very small handful of gems using these APIs at all

Thus, we concluded that the current behaviour of allowing scheduling and execution of arbitrary `(func, data)` pairs is actually not really needed. Instead, we could offer a more limited API which would meet the needs of all current users, whilst making it easy to avoid the race conditions in the current implementation.

The new API is as follows:

* `rb_postponed_job_preregister(func, data)`: This function registers `func`/`data` into a small, fixed-size table, and return a handle to this registration. Subsequent calls to this function with the same `func` will return the same handle, and overwrite the `data` with new data if it is different. The size of the table is 32 entries on most systems, which is still enough to use literally every gem on rubygems that actually uses these APIs at the same time. The intention is that libraries would call this function in their initialization routines, storing the handle for later.
* `rb_postponed_job_trigger(handle)`: This function takes the handle from `rb_postponed_job_preregister` and schedules it for execution the next time `RUBY_VM_CHECK_INTS` is called. If the handle is already scheduled, this will not cause it to be scheduled twice; each `func` can only be called a maximum of one time for each call to `RUBY_VM_CHECK_INTS`, essentially.

All of the usages of the old `rb_postponed_job_register{,_once}` functions in the Ruby tree have been replaced by calls to the above two functions, and these two old functions have been marked with the deprecated attribute. They have also been re-implemented in terms of the new functions; both `rb_postponed_job_register` and `rb_postponed_job_register_once` are now both equivalent to `rb_postponed_job_trigger(rb_postponed_job_prereigster(func, data))`. This means that:

* `rb_postponed_job_register` now works like `rb_postponed_job_register_once` i.e. `func` can only be executed one time per `RUBY_VM_CHECK_INTS`, no matter how many times it is registered
* They are also called with the _last_ `data` to be registered, not the first (which is how `rb_postponed_job_register_once` previously worked)

I verified that stackprof still builds & works correctly with the new implementation of `rb_postponed_job_register`.

## What else we tried

I tried a couple of things to keep the current semantics of `rb_postponed_job_register{,_once}` intact, without introducing new APIs.

* First, I tried protecting postponed job buffer by masking signals around the critical section & using a POSIX semaphore instead of a pthread mutex: https://github.com/ruby/ruby/pull/8856. However, there was a concern that this would be too slow (since `RUBY_VM_CHECK_INTS` is called very often, and both the semaphore and the signal mask require calling into the kernel).
* Then, I implemented a lock-free ringbuffer to store the postponed job queue: https://github.com/ruby/ruby/compare/master...KJTsanaktsidis:ruby:old_circular_ringbuffer. However, the concern with this implementation was that it was too complex.

## Ruby 3.3

As of right now, we have merged these changes (from https://github.com/ruby/ruby/pull/8949), and @ko1 plans for them to go out in 3.3-rc1. The point of opening this issue is to ask: does anybody foresee any problem with our approach?



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

In This Thread