Граф коммитов

2257 Коммитов

Автор SHA1 Сообщение Дата
卜部昌平 940b3170c1 document for commit 5bbba76489 [ci skip] 2022-12-07 15:09:12 +09:00
Lars Kanis 81e274c990 [DOC] Improve documentation to RB_ALLOCV
Although the storage of the opaque Ruby object is an array of VALUEs, the intention of RB_ALLOCV is to allocate bytes of memory.
2022-12-06 14:55:05 +09:00
Samuel Williams 4fa47eabf2
Clarify the storage argument. (#6849)
* Slightly more consistent indentation with other parts of the document.
2022-12-02 17:49:42 +13:00
Samuel Williams 0436f1e15a
Introduce `Fiber#storage` for inheritable fiber-scoped variables. (#6612) 2022-12-01 23:00:33 +13:00
Koichi Sasada 67766cd55c add debug context APIs for debuggers (frame depth)
The following new debug context APIs are for implementing debugger's
`next` (step over) and similar functionality.

* `rb_debug_inspector_frame_depth(dc, index)` returns `index`-th
  frame's depth.
* `rb_debug_inspector_current_depth()` returns current frame depth.

The frame depth is not related to the frame index because debug
context API skips some special frames but proposed `_depth()` APIs
returns the count of all frames (raw depth).
2022-11-25 14:01:36 +09:00
Takashi Kokubun ab4379e086
Refactor RB_SPECIAL_CONST_P (#6759)
Since https://github.com/ruby/ruby/pull/6599, RUBY_IMMEDIATE_MASK also
overlaps RUBY_Qnil. Now RB_SPECIAL_CONST_P seems confusing since both
RB_IMMEDIATE_P and RB_TEST check for RUBY_Qnil while we only need to
check RUBY_Qnil besides RUBY_IMMEDIATE_MASK. I'd like to make this
change to make it less confusing.

I confirmed that this doesn't change the number of instructions used for
the RUBY_Qfalse check on Linux x86_64 GCC and macOS arm64 Clang.
2022-11-17 17:55:24 -08:00
Samuel Williams ea8a7287e2
Add support for `sockaddr_un` on Windows. (#6513)
* Windows: Fix warning about undefined if_indextoname()

* Windows: Fix UNIXSocket on MINGW and make .pair more reliable

* Windows: Use nonblock=true for read tests with scheduler

* Windows: Move socket detection from File.socket? to File.stat

Add S_IFSOCK to Windows and interpret reparse points accordingly.
Enable tests that work now.

* Windows: Use wide-char functions to UNIXSocket

This fixes behaviour with non-ASCII characters.
It also fixes deletion of temporary UNIXSocket.pair files.

* Windows: Add UNIXSocket tests for specifics of Windows impl.

* Windows: fix VC build due to missing _snwprintf

Avoid usage of _snwprintf, since it fails linking ruby.dll like so:

  linking shared-library x64-vcruntime140-ruby320.dll
  x64-vcruntime140-ruby320.def : error LNK2001: unresolved external symbol snwprintf
  x64-vcruntime140-ruby320.def : error LNK2001: unresolved external symbol vsnwprintf_l

whereas linking miniruby.exe succeeds.

This patch uses snprintf on the UTF-8 string instead.

Also remove branch GetWindowsDirectoryW, since it doesn't work.

* Windows: Fix dangling symlink test failures

Co-authored-by: Lars Kanis <kanis@comcard.de>
2022-11-17 14:50:25 -08:00
Lars Kanis 7b1d23fd29
Windows: Readlink improvements (#6745)
* Windows: Use readlink emulation for File.readlink

This fixes readlink emulation for the ERROR_MORE_DATA case and general error reporting.
It now releases GVL while readlink IO operation.

The dedicated rb_readlink was introduced in commit 2ffb87995a
in order to improve encoding and buffer allocation.
However the encoding issues are solved since ruby-3.0 switched to UTF-8
and the buffer allocation will be improved in a later commit.

* Windows: Increase the default buffer size for reparse point info

So far nearly all queries of reparse points needed two attempts to get enough buffer.

* Windows: Remove declaration of rb_w32_wreadlink

It was removed in commit 2f6fdd3aeb
2022-11-17 01:57:52 -08:00
Jemma Issroff c726c48a3d Remove numiv from RObject
Since object shapes store the capacity of an object, we no longer
need the numiv field on RObjects. This gives us one extra slot which
we can use to give embedded objects one more instance variable (for a
total of 3 ivs). This commit removes the concept of numiv from RObject.
2022-11-10 10:11:34 -05:00
Jemma Issroff 5246f4027e Transition shape when object's capacity changes
This commit adds a `capacity` field to shapes, and adds shape
transitions whenever an object's capacity changes. Objects which are
allocated out of a bigger size pool will also make a transition from the
root shape to the shape with the correct capacity for their size pool
when they are allocated.

This commit will allow us to remove numiv from objects completely, and
will also mean we can guarantee that if two objects share shapes, their
IVs are in the same positions (an embedded and extended object cannot
share shapes). This will enable us to implement ivar sets in YJIT using
object shapes.

Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
2022-11-10 10:11:34 -05:00
Nobuyoshi Nakada b7e8876704
[Bug #19100] Add `init_int32` function to `rb_random_interface_t`
Distinguish initialization by single word from initialization by
array.
2022-11-10 12:06:13 +09:00
Nobuyoshi Nakada 6eaed20e14
Add version to the interface of Random extensions 2022-11-10 11:59:45 +09:00
TSUYUSATO Kitsune 1dc4128e92 Reduce warnings 2022-11-09 23:21:26 +09:00
TSUYUSATO Kitsune a1c1fc558a Revert "Refactor field names"
This reverts commit 1e6673d6bbd2adbf555d82c7c0906ceb148ed6ee.
2022-11-09 23:21:26 +09:00
TSUYUSATO Kitsune 22294731a8 Refactor field names 2022-11-09 23:21:26 +09:00
TSUYUSATO Kitsune f25bb291b4 Support OP_REPEAT and OP_REPEAT_INC 2022-11-09 23:21:26 +09:00
Nobuyoshi Nakada 558137d5f3
[DOC] Fix missing type name 2022-11-09 12:04:22 +09:00
Nobuyoshi Nakada a14611cd54 Fix -Wundef warnings 2022-10-26 18:57:26 +09:00
Yusuke Endoh 1d2d25dcad Prevent potential buffer overrun in onigmo
A code pattern `p + enclen(enc, p, pend)` may lead to a buffer overrun
if incomplete bytes of a UTF-8 character is placed at the end of a
string. Because this pattern is used in several places in onigmo,
this change fixes the issue in the side of `enclen`: the function should
not return a number that is larger than `pend - p`.

Co-Authored-By: Nobuyoshi Nakada <nobu@ruby-lang.org>
2022-10-25 17:02:43 +09:00
Nick Hengeveld ee3da3784e Use CXX14 to allow constexpr with non-return statements
Co-authored-by: Daniel Colson <composerinteralia@github.com>
2022-10-24 16:47:42 -07:00
Ufuk Kayserilioglu 0378e2f4a8 Add Class#attached_object
Implements [Feature #12084]

Returns the object for which the receiver is the singleton class, or
raises TypeError if the receiver is not a singleton class.
2022-10-20 17:30:17 +02:00
Nobuyoshi Nakada 192bc72529 Define `UNDEF_P` and `NIL_OR_UNDEF_P` [EXPERIMENTAL] 2022-10-20 22:05:27 +09:00
Nobuyoshi Nakada f55212bce9 Move "special consts" so `Qundef` and `Qnil` differ just 1 bit 2022-10-20 22:05:27 +09:00
Nobuyoshi Nakada 0a43a040b4
[DOC] Fix RUBY_SYMBOL_FLAG comment [ci skip]
Upper bits than the least significant 4 bits need not be 0.
2022-10-20 11:49:55 +09:00
Nobuyoshi Nakada 412e3c7a8d Assert for RTEST that Qnil and Qfalse differ just 1 bit 2022-10-19 22:55:42 +09:00
Sergey Fedorov 567725ed30
Fix and improve coroutines for Darwin (macOS) ppc/ppc64. (#5975) 2022-10-19 23:49:45 +13:00
Samuel Williams fc3137ef54
Add support for anonymous shared IO buffers. (#6580) 2022-10-19 18:53:38 +13:00
Samuel Williams 7fcad1fa03
Update `Fiber::Scheduler` documentation. (#6562) 2022-10-15 21:43:45 +13:00
Samuel Williams 8a420670a2
Introduce `Fiber::Scheduler#io_select` hook for non-blocking `IO.select`. (#6559) 2022-10-15 19:59:04 +13:00
Samuel Williams ced1d17280
Improvements to IO::Buffer implementation and documentation. (#6525) 2022-10-12 12:59:05 +13:00
Jemma Issroff ad63b668e2
Revert "Revert "This commit implements the Object Shapes technique in CRuby.""
This reverts commit 9a6803c90b.
2022-10-11 08:40:56 -07:00
Jean Boussier 1a7e7bb2d1 object.c: rb_eql returns int not VALUE
It works, but assumes `Qfalse == 0`, which is true today
but might not be forever.
2022-10-10 11:35:16 +02:00
Samuel Williams 844a9dff88
Try `nil` as default for 'default timeout'. (#6509) 2022-10-08 14:02:34 +13:00
Samuel Williams a081fe76de
Simplify default argument specification. (#6507) 2022-10-07 22:51:27 +13:00
Samuel Williams e4f91bbdba
Add IO#timeout attribute and use it for blocking IO operations. (#5653) 2022-10-07 21:48:38 +13:00
Aaron Patterson 9a6803c90b
Revert "This commit implements the Object Shapes technique in CRuby."
This reverts commit 68bc9e2e97d12f80df0d113e284864e225f771c2.
2022-09-30 16:01:50 -07:00
Jemma Issroff d594a5a8bd
This commit implements the Object Shapes technique in CRuby.
Object Shapes is used for accessing instance variables and representing the
"frozenness" of objects.  Object instances have a "shape" and the shape
represents some attributes of the object (currently which instance variables are
set and the "frozenness").  Shapes form a tree data structure, and when a new
instance variable is set on an object, that object "transitions" to a new shape
in the shape tree.  Each shape has an ID that is used for caching. The shape
structure is independent of class, so objects of different types can have the
same shape.

For example:

```ruby
class Foo
  def initialize
    # Starts with shape id 0
    @a = 1 # transitions to shape id 1
    @b = 1 # transitions to shape id 2
  end
end

class Bar
  def initialize
    # Starts with shape id 0
    @a = 1 # transitions to shape id 1
    @b = 1 # transitions to shape id 2
  end
end

foo = Foo.new # `foo` has shape id 2
bar = Bar.new # `bar` has shape id 2
```

Both `foo` and `bar` instances have the same shape because they both set
instance variables of the same name in the same order.

This technique can help to improve inline cache hits as well as generate more
efficient machine code in JIT compilers.

This commit also adds some methods for debugging shapes on objects.  See
`RubyVM::Shape` for more details.

For more context on Object Shapes, see [Feature: #18776]

Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
Co-Authored-By: Eileen M. Uchitelle <eileencodes@gmail.com>
Co-Authored-By: John Hawthorn <john@hawthorn.email>
2022-09-28 08:26:21 -07:00
Aaron Patterson 06abfa5be6
Revert this until we can figure out WB issues or remove shapes from GC
Revert "* expand tabs. [ci skip]"

This reverts commit 830b5b5c35.

Revert "This commit implements the Object Shapes technique in CRuby."

This reverts commit 9ddfd2ca00.
2022-09-26 16:10:11 -07:00
Jemma Issroff 9ddfd2ca00 This commit implements the Object Shapes technique in CRuby.
Object Shapes is used for accessing instance variables and representing the
"frozenness" of objects.  Object instances have a "shape" and the shape
represents some attributes of the object (currently which instance variables are
set and the "frozenness").  Shapes form a tree data structure, and when a new
instance variable is set on an object, that object "transitions" to a new shape
in the shape tree.  Each shape has an ID that is used for caching. The shape
structure is independent of class, so objects of different types can have the
same shape.

For example:

```ruby
class Foo
  def initialize
    # Starts with shape id 0
    @a = 1 # transitions to shape id 1
    @b = 1 # transitions to shape id 2
  end
end

class Bar
  def initialize
    # Starts with shape id 0
    @a = 1 # transitions to shape id 1
    @b = 1 # transitions to shape id 2
  end
end

foo = Foo.new # `foo` has shape id 2
bar = Bar.new # `bar` has shape id 2
```

Both `foo` and `bar` instances have the same shape because they both set
instance variables of the same name in the same order.

This technique can help to improve inline cache hits as well as generate more
efficient machine code in JIT compilers.

This commit also adds some methods for debugging shapes on objects.  See
`RubyVM::Shape` for more details.

For more context on Object Shapes, see [Feature: #18776]

Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
Co-Authored-By: Eileen M. Uchitelle <eileencodes@gmail.com>
Co-Authored-By: John Hawthorn <john@hawthorn.email>
2022-09-26 09:21:30 -07:00
Samuel Williams 1c14e406d3 Fix `io/buffer.h` header guard. 2022-09-26 20:10:15 +13:00
Nobuyoshi Nakada 6e46bf1e54
Just a star [ci skip] 2022-09-23 08:52:15 +09:00
卜部昌平 2f8012c949 rb_define_method: dedicated overload for rb_f_notimplement
rb_f_notimplement was type-compatible with VALUE(*)(ANYARGS), but not
any longer in C23.  Provide a dedicated path for it.
2022-09-21 11:44:09 +09:00
Nobuyoshi Nakada e2ccb316b4 [Bug #5317] Use `rb_off_t` instead of `off_t`
Get rid of the conflict with system-provided small `off_t`.
2022-09-08 23:01:07 +09:00
Takashi Kokubun 83375f47e1
Avoid leaving a period alone [ci skip] 2022-08-27 14:48:15 -07:00
spaette a797ded8e2 typos 2022-08-27 14:42:55 -07:00
Jeremy Evans 6f3857f6a7 Support Encoding::Converter newline: :lf and :lf_newline options
Previously, newline: :lf was accepted but ignored.  Where it
should have been used was commented out code that didn't work,
but unlike all other invalid values, using newline: :lf did
not raise an error.

This adds support for newline: :lf and :lf_newline, for consistency
with newline: :cr and :cr_newline.  This is basically the same as
universal_newline, except that it only affects writing and not
reading due to RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK.

Add tests for the File.open :newline option while here.

Fixes [Bug #12436]
2022-08-19 20:23:36 -07:00
Nobuyoshi Nakada cd1a0b3caa Stop defining `RUBY_ABI_VERSION` if released versions
As commented in include/ruby/internal/abi.h, since teeny versions of
Ruby should guarantee ABI compatibility, `RUBY_ABI_VERSION` has no role
in released versions of Ruby.
2022-08-12 15:57:25 +09:00
Nobuyoshi Nakada a201cfd0cd Add missing `rb_enc_iscntrl` 2022-08-12 15:56:30 +09:00
Nobuyoshi Nakada 9a11d50dc7 [DOC] Use `true`/`false` for `@retval`s which are `bool` 2022-08-12 15:56:30 +09:00
Nobuyoshi Nakada 591ee9d068
[DOC] Add return values of rb_enc_mbcput 2022-08-07 13:09:46 +09:00
Nobuyoshi Nakada f42230ff22
Adjust styles [ci skip] 2022-07-27 18:42:27 +09:00
Peter Zhu efb91ff19b Rename rb_ary_tmp_new to rb_ary_hidden_new
rb_ary_tmp_new suggests that the array is temporary in some way, but
that's not true, it just creates an array that's hidden and not on the
transient heap. This commit renames it to rb_ary_hidden_new.
2022-07-26 09:12:09 -04:00
Yusuke Endoh e763b1118b Move enum definitions out of struct definition 2022-07-22 23:10:24 +09:00
Takashi Kokubun 5b21e94beb Expand tabs [ci skip]
[Misc #18891]
2022-07-21 09:42:04 -07:00
Peter Zhu 4798a4fec2 Remove unused internal macros in rarray.h 2022-07-21 09:02:45 -04:00
Peter Zhu 7424ea184f Implement Objects on VWA
This commit implements Objects on Variable Width Allocation. This allows
Objects with more ivars to be embedded (i.e. contents directly follow the
object header) which improves performance through better cache locality.
2022-07-15 09:21:07 -04:00
Kevin Backhouse 8c1808151f
Fix some UBSAN false positives (#6115)
* Fix some UBSAN false positives.
* ruby tool/update-deps --fix
2022-07-12 11:48:10 -07:00
卜部昌平 7f64989e5c do not define our own version of memcpy
The (sole) use of memcpy in our public header is now replaced to
directly call ruby_nonempty_memcpy, and the previous definition of
memcpy is now internal-only.  [Bug#18893]
2022-07-07 22:10:53 +09:00
Samuel Williams d2166c09b0 Copy `IO#wait*` methods from `io-wait` gem to `io.c`. 2022-06-25 21:17:13 +12:00
Chris Seaton 31b2cd38c5 Include JIT information in crash reports
Since enabling YJIT or MJIT drastically changes what could go wrong at
runtime, it's good to be front and center about whether they are enabled
when dumping a crash report. Previously, `RUBY_DESCRIPTION` and the
description printed when crashing can be different when a JIT is on.

Introduce a new internal data global, `rb_dynamic_description`, and set
it to be the same as `RUBY_DESCRIPTION` during initialization; use it
when crashing.

 * version.c: Init_ruby_description(): Initialize and use
       `rb_dynamic_description`.
 * error.c: Change crash reports to use `rb_dynamic_description`.
 * ruby.c: Call `Init_ruby_description()` earlier. Slightly more work
       for when we exit right after printing the description but that
       was deemed acceptable.
 * include/ruby/version.h: Talk about how JIT info is not in
      `ruby_description`.
 * test/-ext-/bug_reporter/test_bug_reporter.rb: Remove handling for
       crash description being different from `RUBY_DESCRIPTION`.
 * test/ruby/test_rubyoptions.rb: ditto

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Co-authored-by: Alan Wu <alanwu@ruby-lang.org>
2022-06-20 17:18:29 -04:00
Jean Boussier b6c1e1158d GVL Instrumentation API: add STARTED and EXITED events
[Feature #18339]

After experimenting with the initial version of the API I figured there is a need
for an exit event to cleanup instrumentation data. e.g. if you record data in a
{thread_id -> data} table, you need to free associated data when a thread goes away.
2022-06-17 09:08:26 +02:00
Alan Wu 714a4942fd
Remove unused and accidentally public rb_str_shared_root_p()
This function was added to a public header in [1] probably
unintentionally since it's not used anywhere, exposes implementation
details, and isn't related to the goals of that pull request.

[1]: 56cc3e99b6
2022-06-16 07:20:20 -04:00
John Hawthorn 17d260a87f Restore rb_exec_recursive_outer
This was a public method, so we should probably keep it.
2022-06-15 16:07:29 -07:00
Matt Valentine-House 56cc3e99b6 Move String RVALUES between pools
And re-embed any strings that can now fit inside the slot they've been
moved to
2022-06-13 10:11:27 -07:00
John Hawthorn 52da90acee Make method id explicit in rb_exec_recursive_outer
Previously, because opt_aref and opt_aset don't push a frame, when they
would call rb_hash to determine the hash value of the key, the initial
level of recursion would incorrectly use the method id at the top of the
stack instead of "hash".

This commit replaces rb_exec_recursive_outer with
rb_exec_recursive_outer_mid, which takes an explicit method id, so that
we can make the hash calculation behave consistently.

rb_exec_recursive_outer was documented as being internal, so I believe
this should be okay to change.
2022-06-10 14:48:21 -07:00
Jean Boussier 9125374726 [Feature #18339] GVL Instrumentation API
Ref: https://bugs.ruby-lang.org/issues/18339

Design:

- This tries to minimize the overhead when no hook is registered.
  It should only incur an extra unsynchronized boolean check.
- The hook list is protected with a read-write lock as to cause
  contention when some hooks are registered.
- The hooks MUST be thread safe, and MUST NOT call into Ruby as they
  are executed outside the GVL.
- It's simply a noop on Windows.

API:

```
rb_internal_thread_event_hook_t * rb_internal_thread_add_event_hook(rb_internal_thread_event_callback callback, rb_event_flag_t internal_event, void *user_data);
bool rb_internal_thread_remove_event_hook(rb_internal_thread_event_hook_t * hook);
```

You can subscribe to 3 events:

  - READY: called right before attempting to acquire the GVL
  - RESUMED: called right after successfully acquiring the GVL
  - SUSPENDED: called right after releasing the GVL.

The hooks MUST be threadsafe, as they are executed outside of the GVL, they also MUST NOT call any Ruby API.
2022-06-03 15:13:33 +02:00
Jemma Issroff a04d8c9513
Remove trailing comma from FL_USER3 (#5958) 2022-05-26 15:40:34 -07:00
Jemma Issroff 33fdff3c30 Remove unused RMODULE_INCLUDED_INTO_REFINEMENT flag 2022-05-26 12:09:04 -07:00
Jemma Issroff 80ad0e751f Remove unnecessary module flag, add module assertions to other module flags 2022-05-23 11:04:34 -07:00
Daisuke Fujimura (fd0) 3d6fd162a4 Undefine RUBY_DLN_CHECK_ABI on cygwin 2022-05-19 17:15:30 +09:00
Peter Zhu a41fbc2c95 Increase SIZE_POOL_COUNT to 5
Having more size pools will allow us to allocate larger objects
through Variable Width Allocation.

I have attached some benchmark results below.

Discourse:
  On Discourse, we don't see much change in response times. We do see
  a small reduction in RSS.

  Branch RSS: 377.8 MB
  Master RSS: 396.3 MB

railsbench:
  On railsbench, we don't see a big change in RPS or p99 performance.
  We see a small increase in RSS.

  Branch RPS: 815.38
  Master RPS: 811.73

  Branch p99: 1.69 ms
  Master p99: 1.68 ms

  Branch RSS: 90.6 MB
  Master RSS: 89.4 MB

liquid:
  We don't see a significant change in liquid performance.

  Branch parse & render: 29.041 I/s
  Master parse & render: 29.211 I/s
2022-05-09 08:45:24 -04:00
Jean Boussier 4a2b5102c1 Expose `rb_hash_new_capa(long)`
[Feature #18683]

This allows parsers and similar libraries to create Hashes of
a certain capacity in advance. It's useful when the key and values
are streamed, hence `bulk_insert()` can't be used.
2022-04-26 16:12:47 +02:00
卜部昌平 dcc42d4688 [Doc] correct my understanding about nonblocking mode
I was wrong.  Nonblocking mode nowadays does not interface with
IO#read.  Document updated. [ci skip]
2022-04-21 14:59:03 +09:00
Alex Matchneer dbb227d3b6
[DOC] add missing size params in fiber scheduler.h (#5441) 2022-04-14 07:34:49 +12:00
Kevin Newton 6068da8937 Finer-grained constant cache invalidation (take 2)
This commit reintroduces finer-grained constant cache invalidation.
After 8008fb7 got merged, it was causing issues on token-threaded
builds (such as on Windows).

The issue was that when you're iterating through instruction sequences
and using the translator functions to get back the instruction structs,
you're either using `rb_vm_insn_null_translator` or
`rb_vm_insn_addr2insn2` depending if it's a direct-threading build.
`rb_vm_insn_addr2insn2` does some normalization to always return to
you the non-trace version of whatever instruction you're looking at.
`rb_vm_insn_null_translator` does not do that normalization.

This means that when you're looping through the instructions if you're
trying to do an opcode comparison, it can change depending on the type
of threading that you're using. This can be very confusing. So, this
commit creates a new translator function
`rb_vm_insn_normalizing_translator` to always return the non-trace
version so that opcode comparisons don't have to worry about different
configurations.

[Feature #18589]
2022-04-01 14:48:22 -04:00
Yusuke Endoh ffc3b37f96 re.c: Add Regexp.timeout= and Regexp.timeout
[Feature #17837]
2022-03-30 16:50:46 +09:00
Nobuyoshi Nakada 69967ee64e
Revert "Finer-grained inline constant cache invalidation"
This reverts commits for [Feature #18589]:
* 8008fb7352
  "Update formatting per feedback"
* 8f6eaca2e1
  "Delete ID from constant cache table if it becomes empty on ISEQ free"
* 629908586b
  "Finer-grained inline constant cache invalidation"

MSWin builds on AppVeyor have been crashing since the merger.
2022-03-25 20:29:09 +09:00
Kevin Newton 629908586b Finer-grained inline constant cache invalidation
Current behavior - caches depend on a global counter. All constant mutations cause caches to be invalidated.

```ruby
class A
  B = 1
end

def foo
  A::B # inline cache depends on global counter
end

foo # populate inline cache
foo # hit inline cache

C = 1 # global counter increments, all caches are invalidated

foo # misses inline cache due to `C = 1`
```

Proposed behavior - caches depend on name components. Only constant mutations with corresponding names will invalidate the cache.

```ruby
class A
  B = 1
end

def foo
  A::B # inline cache depends constants named "A" and "B"
end

foo # populate inline cache
foo # hit inline cache

C = 1 # caches that depend on the name "C" are invalidated

foo # hits inline cache because IC only depends on "A" and "B"
```

Examples of breaking the new cache:

```ruby
module C
  # Breaks `foo` cache because "A" constant is set and the cache in foo depends
  # on "A" and "B"
  class A; end
end

B = 1
```

We expect the new cache scheme to be invalidated less often because names aren't frequently reused. With the cache being invalidated less, we can rely on its stability more to keep our constant references fast and reduce the need to throw away generated code in YJIT.
2022-03-24 09:14:38 -07:00
Peter Zhu a51f30c671 [Feature #18634] Implement Arrays on Variable Width Allocation
This commit implements arrays on Variable Width Allocation. This allows
longer arrays to be embedded (i.e. contents directly follow the object
header) which improves performance through better cache locality.
2022-03-22 09:42:39 -04:00
Nobuyoshi Nakada f91ea23324
Honor if `_Bool` is available
`AC_HEADER_STDBOOL` rejects stdbool.h in c2x, which is not
conforming to C99.
2022-03-16 17:50:13 +09:00
Peter Zhu 1289721892 Wrap ruby_abi_version in `extern "C"` for C++
Make ruby_abi_version have C linkage so that the symbol can be found
in the shared object.
2022-03-01 13:38:48 -05:00
Peter Zhu 25ad9eabc7 Only define RUBY_DLN_CHECK_ABI when supported 2022-03-01 09:44:39 -05:00
Lars Kanis eebc24218a [DOC] Fix reference in rb_enc_associate() description 2022-03-01 10:11:59 +09:00
Lars Kanis 1a20bb1c98 [DOC] Fix function name in example 2022-03-01 09:59:12 +09:00
Peter Zhu 3df16924b4 [Feature #18249] Implement ABI checking
Header file include/ruby/internal/abi.h contains RUBY_ABI_VERSION which
is the ABI version. This value should be bumped whenever an ABI
incompatible change is introduced.

When loading dynamic libraries, Ruby will compare its own
`ruby_abi_version` and the `ruby_abi_version` of the loaded library. If
these two values don't match it will raise a `LoadError`. This feature
can also be turned off by setting the environment variable
`RUBY_RUBY_ABI_CHECK=0`.

This feature will prevent cases where previously installed native gems
fail in unexpected ways due to incompatibility of changes in header
files. This will force the developer to recompile their gems to use the
same header files as the built Ruby.

In Ruby, the ABI version is exposed through
`RbConfig::CONFIG["ruby_abi_version"]`.
2022-02-22 09:55:21 -05:00
Nobuyoshi Nakada 7470780058 Check if `__assume` is supported 2022-02-19 23:32:52 +09:00
Nobuyoshi Nakada 131154f878 Define `HAVE___BUILTIN_UNREACHABLE` instead of `UNREACHABLE`
`UNREACHABLE` in ruby/internal/has/builtin.h is only used as just
a flag now, and redefined in ruby/backward/2/assume.h then.
2022-02-19 23:32:52 +09:00
Nobuyoshi Nakada 59a91f229b
Mark `rb_clear_constant_cache` as internal use only
In the past, many internal functions are declared in intern.h
under include/ruby directory, because there were no headers for
internal use.
2022-01-20 13:54:37 +09:00
Yuta Saito 528344b8de include/ruby/win32.h: explicitly define HAVE_SHUTDOWN
Configuration for mingw32 can't detect 'shutdown' due to wrong -l
option even though it's available (this has been going on for a while,
and it needs to be fixed).
In this situation, include/ruby/missing.h declares a stub shutdown
function since 7ee786388a, and another shutdown decl is came from
system header. They are incompatible at stdcall attribute, so it
causes compilation failure.
This change defines a HAVE_SHUTDOWN to guard a newly introduced stub
decl in include/ruby/missing.h
2022-01-19 17:52:19 +09:00
Yuta Saito 8c21701968 include/ruby/io.h: use 0 as POLLPRI when no support for it
0x003 is not suitable as a bit mask, and it's ok just to be 0 to avoid
setting unsupported bit.
2022-01-19 13:19:58 +09:00
Yuta Saito 50f1468bfd [wasm] include/ruby/io.h: define RB_WAITFD_PRI by ourselves for wasi
RB_WAITFD_PRI uses POLLPRI for other platforms, but wasi-libc doesn't
have POLLPRI for now.
2022-01-19 11:19:06 +09:00
Yuta Saito 420622b5a7 [wasm] add no thread variant for freestanding environment
This implementation does nothing around preemptive context switching
because there is no native thread.
2022-01-19 11:19:06 +09:00
Yuta Saito 7ee786388a [wasm] wasm/missing.{c,h}: add missing libc stubs for wasi-libc 2022-01-19 11:19:06 +09:00
Jeremy Evans e7b4abf384 Don't assume __builtin_bswap32 and __builtin_bswap64 are defined on OpenBSD
At least OpenBSD/sparc64 doesn't appear to define them, and possibly
some other OpenBSD GCC platforms don't (most OpenBSD platforms have
already switched to clang).
2022-01-18 11:40:13 -08:00
Peter Zhu ffda21b7ba [Feature #18491] Drop support for HP-UX
IA64 support was dropped in ticket #15894, so we can drop support for
HP-UX.
2022-01-18 09:52:15 -05:00
Yuta Saito 6729258839
include/ruby/win32.h: define HAVE_X for the missing prototypes (#5456) 2022-01-18 19:08:07 +09:00
Nobuyoshi Nakada 9fa9cf4006 Suppress possible loss of data warnings 2022-01-14 13:46:12 +09:00
Nobuyoshi Nakada d1a55851e8
[DOC] Fix a typo in a doc 2022-01-13 11:32:35 +09:00
Peter Zhu 98fb0ab60e Enable Variable Width Allocation by default 2022-01-12 12:00:55 -05:00
Peter Zhu 2d81a718ec Make embedded string length a long for VWA
A short (2 bytes) will cause unaligned struct accesses when strings are
used as a buffer to directly store binary data.
2022-01-12 12:00:55 -05:00
Peter Zhu 33cc8816be Revert "Enable Variable Width Allocation by default"
This reverts commit c365c5921e.
2022-01-08 15:07:57 -05:00
Peter Zhu bc643bbe2e Use unsigned short for length of embedded strings 2022-01-07 15:48:06 -05:00
Peter Zhu c365c5921e Enable Variable Width Allocation by default 2022-01-07 13:27:13 -05:00
Peter Zhu aeb344e65c Revert "Enable Variable Width Allocation by default"
This reverts commit d4a95428bb.
2022-01-06 16:47:49 -05:00
Peter Zhu d4a95428bb Enable Variable Width Allocation by default 2022-01-06 14:33:35 -05:00
Nobuyoshi Nakada 8727161fcf
Flush deprecation declarations for versions older than 3.0 2021-12-30 18:52:04 +09:00
Nobuyoshi Nakada a90d188b57 Remove declarations of deprecated functions 2021-12-30 15:33:40 +09:00
U.Nakamura 4e007d705c Fix some bornheads 2021-12-27 17:15:09 +09:00
U.Nakamura 9790f54bff Call FlushInstrucitonCache() when PROT_EXEC is specified to mprotect 2021-12-27 16:38:29 +09:00
U.Nakamura 85a426dc86 Tiny mmap emulation for Windows
- prerequisite of supporting YJIT with VC++.
- note that now can specfily `--yjit` on mswin64, but not enabled
  YJIT'ed code because of YJIT requires `OPT_DIRECT_THREADED_CODE`
  or `OPT_CALL_THREADED_CODE` in `rb_yjit_compile_iseq`.
2021-12-27 15:56:23 +09:00
Nobuyoshi Nakada 7c738ce5e6
Remove deprecate rb_cData [Bug #18433]
Also enable the warning for T_DATA allocator.
2021-12-26 23:28:54 +09:00
Nobuyoshi Nakada 39bc5de833
Remove tainted and trusted features
Already these had been announced to be removed in 3.2.
2021-12-26 23:28:54 +09:00
Yukihiro "Matz" Matsumoto 81c248924d
Development of 3.1.0 started. 2021-12-26 23:22:26 +09:00
Kazuhiro NISHIYAMA 04f07713d1
Fix typos [ci skip] 2021-12-25 10:33:49 +09:00
Samuel Williams acfe2f2655
Improvements to `rb_io_wait` return value handling and internal implementation. (#5340) 2021-12-24 23:11:02 +13:00
Samuel Williams bed920f073
Add fiber scheduler hooks for `pread`/`pwrite`, and add support to `IO::Buffer`. 2021-12-23 12:20:09 +13:00
Samuel Williams e30920354f
Extended interface for IO::Buffer & documentation. 2021-12-22 10:57:34 +13:00
Samuel Williams 617687df09 Rename IMMUTABLE to READONLY. 2021-12-21 12:25:42 +13:00
Samuel Williams 9fbf94ff04 Improve interface for get/set/copy. 2021-12-21 12:25:42 +13:00
Samuel Williams c86bcd434d Mark non-private mapped files as external. 2021-12-21 12:25:42 +13:00
Samuel Williams 49166fc74a Improved exception usage/classes. 2021-12-21 12:25:42 +13:00
Samuel Williams 56811617ab Improve IO::Buffer resize and introduce ownership transfer. 2021-12-20 00:17:17 +13:00
Samuel Williams f3e30b26c5 Default size for IO::Buffer. 2021-12-19 12:25:38 +13:00
Samuel Williams 42d3231154
Introduce io_result wrapper for passing `[-errno, size]` in VALUE. 2021-12-18 18:19:30 +13:00
Yuta Saito ecb2ff6050 intern/select/posix.h: remove unused parameter from rb_fd_dup
This unused parameter seems to be accidently introduced by https://github.com/ruby/ruby/commit/9e6e39c
2021-12-11 02:23:30 +09:00
Nobuyoshi Nakada a5baf8d6bc
Revert zero-check for alloca
Something weird results in int-in-bool-context and
stringop-overflow warnings.
2021-12-10 18:39:48 +09:00
Nobuyoshi Nakada bcc2bb28b0 Fix stack buffer overflow
https://hackerone.com/reports/1306859
2021-12-10 01:04:59 +09:00
Jean Boussier c0c2b31a35 Add Class#subclasses
Implements [Feature #18273]

Returns an array containing the receiver's direct subclasses without
singleton classes.
2021-11-23 10:50:44 +01:00
卜部昌平 33533fabd5 revival of must_not_null()
Presence of RBIMPL_ATTR_NONNULL let C compilers to eliminate
must_not_null().  Because null pointers are not allowed to exist there
are no reason to call the function.  In reality null pointers are still
passed to those functions in a number of ways.  Runtime check for them
are definitely nice to have.  fix [Feature#18280]
2021-11-11 17:14:47 +09:00
卜部昌平 f5dcecf345 rb_file_size: add doxygen
Must not be a bad idea to improve documents. [ci skip]
2021-11-11 11:45:19 +09:00
卜部昌平 ad84c5d1b0 rb_enc_code_to_mbclen: fix doxygen
Wrong parameter name. [ci skip]
2021-11-11 11:45:19 +09:00
卜部昌平 4b3830127f RB_ENCODING_SET_INLINED: fix doxygen
Wrong parameter name. [ci skip]
2021-11-11 11:45:19 +09:00
卜部昌平 a4a6e5cd2e ENCODING_MASK: fix doxygen link [ci skip] 2021-11-11 11:45:19 +09:00
卜部昌平 1370b0876f io/buffer.h: C linkage
Because `make install` installs this header to target systems, it must
be ready to be `#include`d form a C++ program.
2021-11-11 11:45:19 +09:00
Nobuyoshi Nakada 46e46eafd4
size_t is not for file size 2021-11-10 16:41:26 +09:00
Samuel Williams 81d0ce7e97 Mark IO::Buffer as experimental. 2021-11-10 19:21:05 +13:00
Samuel Williams 4b89034218 IO::Buffer for scheduler interface. 2021-11-10 19:21:05 +13:00
Peter Zhu 309406484b [Feature #18290] Deprecate rb_gc_force_recycle and remove invalidate_mark_stack_chunk
This commit deprecates rb_gc_force_recycle and coverts it to a no-op
function. Also removes invalidate_mark_stack_chunk since only
rb_gc_force_recycle uses it.
2021-11-08 14:05:54 -05:00
Kenta Murata 3501e0cbb5
memory_view.c: Add _memory_view_entry member in rb_memory_view_t (#5088) 2021-11-08 12:52:09 +09:00
Nobuyoshi Nakada a202408180
Fix typos 2021-11-02 19:17:37 +09:00
Jeremy Evans 717ab0bb2e
Add Class#descendants
Doesn't include receiver or singleton classes.

Implements [Feature #14394]

Co-authored-by: fatkodima <fatkodima123@gmail.com>
Co-authored-by: Benoit Daloze <eregontp@gmail.com>
2021-10-26 12:35:21 -07:00
卜部昌平 7d4c59203f improve doc coverage [ci skip]
Just split the comment for struct's one and array's one.
2021-10-26 09:30:42 +09:00
卜部昌平 a0029ae2b6 just another evidence that @shyouhei is an idiot [ci skip]
(gdb) ptype/o struct RString
/* offset    |  size */  type = struct RString {
/*    0      |    16 */    struct RBasic {
/*    0      |     8 */        VALUE flags;
/*    8      |     8 */        const VALUE klass;

                               /* total size (bytes):   16 */
                           } basic;
/*   16      |    24 */    union {
/*                24 */        struct {
/*   16      |     8 */            long len;
/*   24      |     8 */            char *ptr;
/*   32      |     8 */            union {
/*                 8 */                long capa;
/*                 8 */                VALUE shared;

                                       /* total size (bytes):    8 */
                                   } aux;

                                   /* total size (bytes):   24 */
                               } heap;
/*                24 */        struct {
/*   16      |    24 */            char ary[24];

                                   /* total size (bytes):   24 */
                               } embed;
/* XXX  8-byte padding  */

                               /* total size (bytes):   24 */
                           } as;

                           /* total size (bytes):   40 */
                         }
(gdb)
2021-10-26 09:30:12 +09:00
Peter Zhu a5b6598192 [Feature #18239] Implement VWA for strings
This commit adds support for embedded strings with variable capacity and
uses Variable Width Allocation to allocate strings.
2021-10-25 13:26:23 -04:00
Peter Zhu 46b66eb9e8 [Feature #18239] Add struct for embedded strings 2021-10-25 13:26:23 -04:00
Shugo Maeda 6606597109
Deprecate include/prepend in refinements and add Refinement#import_methods instead
Refinement#import_methods imports methods from modules.
Unlike Module#include, it copies methods and adds them into the refinement,
so the refinement is activated in the imported methods.

[Bug #17429] [ruby-core:101639]
2021-10-21 16:31:54 +09:00
Nobuyoshi Nakada 702a58e9e5
Remove duplicate type qualifiers
`rb_encoding` is defined as `const OnigEncodingType`.
Fix lots of C4114 warnings for each files by MSVC.
2021-10-06 14:01:43 +09:00
Nobuyoshi Nakada cd182c5ee1
Adjust types to rb_enc_left_char_head
I dislike unnatural casts.
2021-10-05 17:14:29 +09:00
卜部昌平 f032c09bca rb_enc_left_char_head(): take void*
Nobu doesn't like (char*) cast.
2021-10-05 14:18:23 +09:00
卜部昌平 5112a54846 include/ruby/encoding.h: convert macros into inline functions
Less macros == huge win.
2021-10-05 14:18:23 +09:00