summaryrefslogtreecommitdiff
path: root/internal
AgeCommit message (Collapse)Author
2025-03-04[Bug #21144] Win32: Use Windows time zone ID if TZ is not setNobuyoshi Nakada
If the TZ environment variable is not set, the time zone names retrieved from the system are localized for UI display and may vary across editions and language packs for the same time zone. Use the time zone IDs that are invariant across environments instead.
2025-02-13merge revision(s) fb18bb183c24ca82b8f114ed090d62bd69b5df84: [Backport #20989]Takashi Kokubun
[Bug #20989] Ripper: Pass `compile_error` For the universal parser, `rb_parser_reg_fragment_check` function is shared between the parser and ripper. However `parser_params` struct is partially different, and `compile_error` function depends on that part indirectly.
2024-12-19[Bug #20969] Pass `assignable` from ripperNobuyoshi Nakada
For the universal parser, `rb_reg_named_capture_assign_iter_impl` function is shared between the parser and ripper. However `parser_params` struct is partially different, and `assignable` function depends on that part indirectly. Notes: Merged: https://github.com/ruby/ruby/pull/12400
2024-12-19Prefix asan_poison_object with rbPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12385
2024-12-19Export asan_poison_objectPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12385
2024-12-19Make asan_poison_object poison the whole slotPeter Zhu
This change poisons the whole slot of the object rather than just the flags. This allows ASAN to find any reads/writes into the slot after it has been freed. Notes: Merged: https://github.com/ruby/ruby/pull/12385
2024-12-16Detect ASAN when using older GCC versionsAlan Wu
Newer GCCs have __has_feature and older ones have __SANITIZE_ADDRESS__[1]. Relevant since ASAN with GCC 11 on the popular Ubuntu Jammy failed to build previously. [1]: https://gcc.gnu.org/onlinedocs/gcc-4.8.0/cpp/Common-Predefined-Macros.html
2024-12-16Check whether object is valid in allocation_info_tracer_compactPeter Zhu
When reference updating ObjectSpace.trace_object_allocations, we need to check whether the object is valid or not because it does not mark the object so the object may be dead. This can cause a segmentation fault if the object is on a free heap page. For example, the following script crashes: require "objspace" objs = [] ObjectSpace.trace_object_allocations do 1_000_000.times do objs << Object.new end end objs = nil # Free pages that the objs were on GC.start # Run compaction and check that it doesn't crash GC.compact Notes: Merged: https://github.com/ruby/ruby/pull/12360
2024-12-13Fix use-after-free in ep in Proc#dup for ifunc procsPeter Zhu
[Bug #20950] ifunc proc has the ep allocated in the cfunc_proc_t which is the data of the TypedData object. If an ifunc proc is duplicated, the ep points to the ep of the source object. If the source object is freed, then the ep of the duplicated object now points to a freed memory region. If we try to use the ep we could crash. For example, the following script crashes: p = { a: 1 }.to_proc 100.times do p = p.dup GC.start p.call rescue ArgumentError end This commit changes ifunc proc to also duplicate the ep when it is duplicated. Notes: Merged: https://github.com/ruby/ruby/pull/12319
2024-12-12Implement rb_bug_without_diePeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12309
2024-12-12Add `rb_warn_reserved_name_at`Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12315
2024-12-06Add rb_gc_impl_active_gc_name to gc/gc_impl.hPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12271
2024-12-05Use rb_gc_enable/rb_gc_disable_no_rest instead of ruby_disable_gcPeter Zhu
We should use the rb_gc_enable/rb_gc_disable_no_rest APIs instead of directly setting the ruby_disable_gc variable. Notes: Merged: https://github.com/ruby/ruby/pull/12264
2024-12-05Standardize on the name "modular GC"Peter Zhu
We have name fragmentation for this feature, including "shared GC", "modular GC", and "external GC". This commit standardizes the feature name to "modular GC" and the implementation to "GC library". Notes: Merged: https://github.com/ruby/ruby/pull/12261
2024-12-04Fix ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS for MSANPeter Zhu
There's no case for when RUBY_MSAN_ENABLED, so the macro ends up doing nothing when it should instead have __attribute__((__no_sanitize__("memory"))). Notes: Merged: https://github.com/ruby/ruby/pull/12219
2024-11-26Optimize instructions when creating an array just to call `include?` (#12123)Randy Stauner
* Add opt_duparray_send insn to skip the allocation on `#include?` If the method isn't going to modify the array we don't need to copy it. This avoids the allocation / array copy for things like `[:a, :b].include?(x)`. This adds a BOP for include? and tracks redefinition for it on Array. Co-authored-by: Andrew Novoselac <andrew.novoselac@shopify.com> * YJIT: Implement opt_duparray_send include_p Co-authored-by: Andrew Novoselac <andrew.novoselac@shopify.com> * Update opt_newarray_send to support simple forms of include?(arg) Similar to opt_duparray_send but for non-static arrays. * YJIT: Implement opt_newarray_send include_p --------- Co-authored-by: Andrew Novoselac <andrew.novoselac@shopify.com> Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2024-11-25Place all non-default GC API behind USE_SHARED_GCMatt Valentine-House
So that it doesn't get included in the generated binaries for builds that don't support loading shared GC modules Co-Authored-By: Peter Zhu <peter@peterzhu.ca> Notes: Merged: https://github.com/ruby/ruby/pull/12149
2024-11-21Annotate anonymous mmapKunshan Wang
Use PR_SET_VMA_ANON_NAME to set human-readable names for anonymous virtual memory areas mapped by `mmap()` when compiled and run on Linux 5.17 or higher. This makes it convenient for developers to debug mmap. Notes: Merged: https://github.com/ruby/ruby/pull/12119
2024-11-20Introduce `Fiber::Scheduler#blocking_operation_wait`. (#12016)Samuel Williams
Redirect `rb_nogvl` blocking operations to the fiber scheduler if possible to prevent stalling the event loop. [Feature #20876] Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2024-11-14Include the currently active GC in RUBY_DESCRIPTIONMatt Valentine-House
This will add +MOD_GC to the version string and Ruby description when Ruby is compiled with shared gc support. When shared GC support is compiled in and a GC module has been loaded using RUBY_GC_LIBRARY, the version string will include the name of the currently active GC as reported by the rb_gc_active_gc_name function in the form +MOD_GC[gc_name] [Feature #20794] Notes: Merged: https://github.com/ruby/ruby/pull/11872
2024-11-13YJIT: Specialize `String#[]` (`String#slice`) with fixnum arguments (#12069)Randy Stauner
* YJIT: Specialize `String#[]` (`String#slice`) with fixnum arguments String#[] is in the top few C calls of several YJIT benchmarks: liquid-compile rubocop mail sudoku This speeds up these benchmarks by 1-2%. * YJIT: Try harder to get type info for `String#[]` In the large generated code of the mail gem the context doesn't have the type info. In that case if we peek at the stack and add a guard we can still apply the specialization and it speeds up the mail benchmark by 5%. Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com> Co-authored-by: Takashi Kokubun (k0kubun) <takashikkbn@gmail.com> --------- Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com> Co-authored-by: Takashi Kokubun (k0kubun) <takashikkbn@gmail.com> Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2024-11-13Mark strings returned by Symbol#to_s as chilled (#12065)Jean byroot Boussier
* Use FL_USER0 for ELTS_SHARED This makes space in RString for two bits for chilled strings. * Mark strings returned by `Symbol#to_s` as chilled [Feature #20350] `STR_CHILLED` now spans on two user flags. If one bit is set it marks a chilled string literal, if it's the other it marks a `Symbol#to_s` chilled string. Since it's not possible, and doesn't make much sense to include debug info when `--debug-frozen-string-literal` is set, we can't include allocation source, but we can safely include the symbol name in the warning message, making it much easier to find the source of the issue. Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com> --------- Co-authored-by: Étienne Barrié <etienne.barrie@gmail.com> Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2024-11-13string.c: Directly create strings with the correct encodingJean Boussier
While profiling msgpack-ruby I noticed a very substantial amout of time spent in `rb_enc_associate_index`, called by `rb_utf8_str_new`. On that benchmark, `rb_utf8_str_new` is 33% of the total runtime, in big part because it cause GC to trigger often, but even then `5.3%` of the total runtime is spent in `rb_enc_associate_index` called by `rb_utf8_str_new`. After closer inspection, it appears that it's performing a lot of safety check we can assert we don't need, and other extra useless operations, because strings are first created and filled as ASCII-8BIT and then later reassociated to the desired encoding. By directly allocating the string with the right encoding, it allow to skip a lot of duplicated and useless operations. After this change, the time spent in `rb_utf8_str_new` is down to `28.4%` of total runtime, and most of that is GC. Notes: Merged: https://github.com/ruby/ruby/pull/12076
2024-11-09Add integer overflow check macros for add/sub as well as mulNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12034
2024-11-08introduce `rb_ec_check_ints()`Koichi Sasada
to avoid TLS issue with N:M threads. Notes: Merged: https://github.com/ruby/ruby/pull/11142
2024-11-08`interrupt_exec`Koichi Sasada
introduce - rb_threadptr_interrupt_exec - rb_ractor_interrupt_exec to intercept the thread/ractor execution. Notes: Merged: https://github.com/ruby/ruby/pull/11142
2024-10-24Fix shared GC with -DRUBY_DEBUGMatt Valentine-House
RUBY_DEBUG enables ractor assertions, which sets up some space at the end of each RVALUE to store the associated ractor ID. We need to make sure the function that does this is visible to shared GC libraries. Notes: Merged: https://github.com/ruby/ruby/pull/11945
2024-10-21Show where mutated chilled strings were allocatedÉtienne Barrié
[Feature #20205] The warning now suggests running with --debug-frozen-string-literal: ``` test.rb:3: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information) ``` When using --debug-frozen-string-literal, the location where the string was created is shown: ``` test.rb:3: warning: literal string will be frozen in the future test.rb:1: info: the string was created here ``` When resurrecting strings and debug mode is not enabled, the overhead is a simple FL_TEST_RAW. When mutating chilled strings and deprecation warnings are not enabled, the overhead is a simple warning category enabled check. Co-authored-by: Jean Boussier <byroot@ruby-lang.org> Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org> Co-authored-by: Jean Boussier <byroot@ruby-lang.org> Notes: Merged: https://github.com/ruby/ruby/pull/11893
2024-10-11Remove 1 allocation in Enumerable#each_with_index (#11868)Alan Wu
* Remove 1 allocation in Enumerable#each_with_index Previously, each call to Enumerable#each_with_index allocates 2 objects, one for the counting index, the other an imemo_ifunc passed to `self.each` as a block. Use `struct vm_ifunc::data` to hold the counting index directly to remove 1 allocation. * [DOC] Brief summary for usages of `struct vm_ifunc` Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2024-10-10Remove duplicate struct declarationAlan Wu
2024-10-08Fix extra semicolon outside of a function in `NO_SANITIZE`Nobuyoshi Nakada
``` internal/sanitizers.h:57:26: error: ISO C does not allow extra ‘;’ outside of a function [-Wpedantic] 57 | COMPILER_WARNING_PUSH; \ | ^ ``` and so many. Remove semicolons following pragma, and repeat the given declaration at the end to consume a semicolon following the macro call. As many `NO_SANITIZE` calls including bigdecimal that is a gem have a trailing semicolon, it was not able to move the semicolon inside `NO_SANITIZE`.
2024-10-08`rb_fix_mul_fix` needs internal/bits.h for `MUL_OVERFLOW_FIXNUM_P`Nobuyoshi Nakada
2024-10-05Introduce `rb_io_blocking_region` which takes `struct rb_io` argument. (#11795)Samuel Williams
This does not change any actual behaviour, but provides a choke point for blocking IO operations. * Update `IO::Buffer` to use `rb_io_blocking_region`. * Update `File` to use `rb_io_blocking_region`. * Update `IO` to use `rb_io_blocking_region`. Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2024-10-03Rename size_pool -> heapMatt Valentine-House
Now that we've inlined the eden_heap into the size_pool, we should rename the size_pool to heap. So that Ruby contains multiple heaps, with different sized objects. The term heap as a collection of memory pages is more in memory management nomenclature, whereas size_pool was a name chosen out of necessity during the development of the Variable Width Allocation features of Ruby. The concept of size pools was introduced in order to facilitate different sized objects (other than the default 40 bytes). They wrapped the eden heap and the tomb heap, and some related state, and provided a reasonably simple way of duplicating all related concerns, to provide multiple pools that all shared the same structure but held different objects. Since then various changes have happend in Ruby's memory layout: * The concept of tomb heaps has been replaced by a global free pages list, with each page having it's slot size reconfigured at the point when it is resurrected * the eden heap has been inlined into the size pool itself, so that now the size pool directly controls the free_pages list, the sweeping page, the compaction cursor and the other state that was previously being managed by the eden heap. Now that there is no need for a heap wrapper, we should refer to the collection of pages containing Ruby objects as a heap again rather than a size pool Notes: Merged: https://github.com/ruby/ruby/pull/11771
2024-10-02Make default parser enum and define getter/setterNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/11761
2024-09-25Fix memory leak in Ripper for indented heredocsPeter Zhu
The allocated parser string is never freed, which causes a memory leak. The following code leaks memory: Ripper.sexp_raw(DATA.read) __END__ <<~EOF a #{1} a EOF Notes: Merged: https://github.com/ruby/ruby/pull/11669
2024-09-23Unpoison page->freelist before trying to assert on itKJ Tsanaktsidis
Otherwise trying to deref the pointer can cause an ASAN crash, even though the only reason we're dereferencing it is so that we can assert on it. Notes: Merged: https://github.com/ruby/ruby/pull/11660
2024-09-22Reuse dedent_string function in rb_ruby_ripper_dedent_string functionS-H-GAMELINKS
This change is reduce Ruby C API dependency for Universal Parser. Reuse dedent_string functions in rb_ruby_ripper_dedent_string functions and remove dependencies on rb_str_modify and rb_str_set_len from the parser. Notes: Merged: https://github.com/ruby/ruby/pull/11658
2024-09-17Ensure fiber scheduler is woken up when close interrupts readKJ Tsanaktsidis
If one thread is reading and another closes that socket, the close blocks waiting for the read to abort cleanly. This ensures that Ruby is totally done with the file descriptor _BEFORE_ we tell the OS to close and potentially re-use it. When the read is correctly terminated, the close should be unblocked. That currently works if closing is happening on a thread, but if it's happening on a fiber with a fiber scheduler, it does NOT work. This patch ensures that if the close happened in a fiber scheduled thread, that the scheduler is notified that the fiber is unblocked. [Bug #20723] Notes: Merged: https://github.com/ruby/ruby/pull/11614
2024-09-16Don't export unnecessary string functionsPeter Zhu
These functions are not used publicly, so we don't need to export them. Notes: Merged: https://github.com/ruby/ruby/pull/11634
2024-09-12Switch the default parser from parse.y to PrismKevin Newton
This commit switches the default parser to Prism. There are a couple of additional changes related to this that are a part of this as well to make this happen. * Switch the default parser in parse.h * Remove the Prism-specific workflow and add a parse.y-specific workflow to CI so that it continues to be tested * Update a few test exclusions since Prism has the correct behavior but parse.y doesn't per https://bugs.ruby-lang.org/issues/20504. * Skips a couple of tests on RBS which are failing because they are using RubyVM::AbstractSyntaxTree.of. Fixes [Feature #20564] Notes: Merged: https://github.com/ruby/ruby/pull/11497
2024-09-05Optimized instruction for Hash#freezeÉtienne Barrié
If a Hash which is empty or only using literals is frozen, we detect this as a peephole optimization and change the instructions to be `opt_hash_freeze`. [Feature #20684] Co-authored-by: Jean Boussier <byroot@ruby-lang.org> Notes: Merged: https://github.com/ruby/ruby/pull/11406
2024-09-05Optimized instruction for Array#freezeÉtienne Barrié
If an Array which is empty or only using literals is frozen, we detect this as a peephole optimization and change the instructions to be `opt_ary_freeze`. [Feature #20684] Co-authored-by: Jean Boussier <byroot@ruby-lang.org> Notes: Merged: https://github.com/ruby/ruby/pull/11406
2024-09-05Proof of Concept: Allow to prevent fork from happening in known fork unsafe APIJean Boussier
[Feature #20590] For better of for worse, fork(2) remain the primary provider of parallelism in Ruby programs. Even though it's frowned uppon in many circles, and a lot of literature will simply state that only async-signal safe APIs are safe to use after `fork()`, in practice most APIs work well as long as you are careful about not forking while another thread is holding a pthread mutex. One of the APIs that is known cause fork safety issues is `getaddrinfo`. If you fork while another thread is inside `getaddrinfo`, a mutex may be left locked in the child, with no way to unlock it. I think we could reduce the impact of these problem by preventing in for the most notorious and common cases, by locking around `fork(2)` and known unsafe APIs with a read-write lock. Notes: Merged: https://github.com/ruby/ruby/pull/10864
2024-08-27Add RB_DEFAULT_PARSER preprocessor macroAlan Wu
This way there is one place to change for switching the default. This also allows for building the same commit with different cppflags. Notes: Merged: https://github.com/ruby/ruby/pull/11473 Merged-By: XrXr
2024-08-07Delete unused rb_check_funcall_with_hook()Alan Wu
Notes: Merged: https://github.com/ruby/ruby/pull/11331
2024-07-10Add rb_block_call2, a flexible variant of rb_block_callYusuke Endoh
This function accepts flags: RB_NO_KEYWORDS, RB_PASS_KEYWORDS, RB_PASS_CALLED_KEYWORDS: Works as the same as rb_block_call_kw. RB_BLOCK_NO_USE_PACKED_ARGS: The given block ("bl_proc") does not use "yielded_arg" of rb_block_call_func_t. Instead, the block accesses the yielded arguments via "argc" and "argv". This flag allows the called method to yield arguments without allocating an Array.
2024-07-03Move ruby_load_external_gc_from_argv to gc.hPeter Zhu
2024-07-03[Feature #20470] Split GC into gc_impl.cPeter Zhu
This commit splits gc.c into two files: - gc.c now only contains code not specific to Ruby GC. This includes code to mark objects (which the GC implementation may choose not to use) and wrappers for internal APIs that the implementation may need to use (e.g. locking the VM). - gc_impl.c now contains the implementation of Ruby's GC. This includes marking, sweeping, compaction, and statistics. Most importantly, gc_impl.c only uses public APIs in Ruby and a limited set of functions exposed in gc.c. This allows us to build gc_impl.c independently of Ruby and plug Ruby's GC into itself.
2024-05-31Revert 528c4501f46fbe1e06028d673a777ef124d29829Yusuke Endoh
Recently, `TestRubyLiteral#test_float` fails randomly. ``` 1) Error: TestRubyLiteral#test_float: ArgumentError: SyntaxError#path changed: "(eval at /home/chkbuild/chkbuild/tmp/build/20240527T050036Z/ruby/test/ruby/test_literal.rb:642)"->"(eval at /home/chkbuild/chkbuild/tmp/build/20240527T050036Z/ruby/test/ruby/test_literal.rb:642)" ``` https://rubyci.s3.amazonaws.com/s390x/ruby-master/log/20240527T050036Z.fail.html.gz According to Launchable, the first failure was on Apr 30. This is just when 528c4501f46fbe1e06028d673a777ef124d29829 was committed. I don't know if the change is really the cause, but I want to revert it once to see if the random failure disappears.