929 Commits
Author SHA1 Message Date
Matt Valentine-House d71692d49f ZJIT: prepare options whenever the zjit feature is enabled
--enable=zjit sets the zjit feature bit without parsing a --zjit option,
so OPTIONS is never initialized and rb_zjit_option_enable() returns
false.

ZJIT then stays disabled at boot. The same happens with --enable-zjit
and RUBYOPT=--enable=zjit, and with --jit, --enable=jit and --enable=all
on ZJIT-only builds.

In this commit we call rb_zjit_prepare_options() whenever the zjit
feature is set, regardless of where the bit came from. It's a no-op
when the --zjit option parser has already initialized OPTIONS, so
--zjit-disable and the other ZJIT options still apply.

[Bug #22427]
2026-10-14 10:25:31 +01:00
Yusuke EndohandClaude Opus 5.5 128308226c Say that Ruby::Prism is the parser that parsed the running program
Ruby::Prism itself does not compile the program (prism_compile.c does,
and other implementations may not even compile an AST into bytecode).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 04:27:15 +09:00
Yusuke EndohandClaude Opus 5.5 fd10fbf4fa Prepare to build prism into the interpreter as Ruby::Prism
The Ruby part of prism moves from lib/prism to lib/ruby/prism and is
namespaced as Ruby::Prism by the sync tool (see the previous commit).
Wire the build for that layout:

- prism_init.c registers the statically linked extension as
  "ruby/prism/prism.so".
- Ruby::Prism is autoloaded from "ruby/prism", so programs that do not
  use it pay nothing.  The autoload is set up after the command line
  options are processed, and only when prism is the parser that parses
  the program: with --parser=parse.y, Ruby::Prism is not defined (an
  explicit `require "ruby/prism"` still works).
- prism/srcs.mk.in generates the templated Ruby files into
  lib/ruby/prism/ (.gitignore follows).

[Bug #22379]

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 04:27:15 +09:00
Hiroshi SHIBATAandClaude Opus 5.5 ee3d6c987b Use rb_len_t for the lengths and indices left in long
These still held String and Array lengths and indices in long, or cast them to long. rb_len_t is still long everywhere, so the generated code does not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 16:45:25 +09:00
Hiroshi SHIBATAandClaude Opus 5 224dc5c110 Use rb_len_t for path lengths
The file, dir, load and ruby.c changes go together because rb_get_expanded_load_path() returns the maximum path length through a pointer. Lengths passed to the Windows string conversion helpers that take `long *` stay `long`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-10-09 14:00:15 +09:00
Hiroshi SHIBATAandClaude Opus 5.5 d5d28336a9 YJIT: Do not suggest ./configure --enable-yjit=dev on mswin
The disasm options and RubyVM::YJIT.disasm need a dev build, which win32/configure.bat cannot make. The warning for builds without YJIT also mentions --enable-yjit, since installing rustc alone does not enable it on mswin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 06:11:37 +09:00
Hiroshi SHIBATAandClaude Opus 5.5 cd3657cf06 Remove CharNext from eval_intern.h
ruby_push_include was its last user. A path separator never appears inside a multibyte character, so walk RUBYLIB and -I by bytes everywhere. This also fixes the same skipped separator on Cygwin, where CharNext came from windows.h.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 08:26:13 +09:00
Hiroshi SHIBATAandClaude Opus 5.5 3e7be38818 Do not skip path separators after multibyte characters on Windows
RUBYLIB and -I are UTF-8 on Windows, but ruby_push_include walked them with CharNext in the ANSI code page. With a DBCS code page such as 932, the last byte of a UTF-8 character was taken as a lead byte and swallowed the following `;`, so `C:/あ;C:/b` became a single load path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 08:26:13 +09:00
Hiroshi SHIBATAandClaude Opus 5 1e16b651ca Remove the unused ptr in moreswitches
It held the base pointer for `ruby_xfree(ptr)` while the loop advanced `argv`. The free became `RB_ALLOCV_END(ptr_obj)` in da4bd3b3df, and nothing has read it since.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-16 17:14:37 +09:00
Yusuke Endoh dac86d0d35 Remove the dependency from internal/cont.h to prism. (#13984) 2026-09-12 08:11:50 +00:00
Nobuyoshi Nakada 8f4a3c9401 [Feature #22215] Extract internal coverage API
Provide a narrow coverage interface so `ext/coverage` does not depend
on GC or VM implementation headers.
2026-08-07 09:59:15 +09:00
Peter Zhu 5f398e864a Make ruby_incpush_expand static 2026-07-25 20:02:17 -04:00
Hiroshi SHIBATAandClaude Opus 4.8 4f84a740ee Default stdin script encoding to UTF-8 on Windows
A script read from stdin used the locale encoding, so on a non-UTF-8
console such as CP932 its source encoding differed from a script read
from a file, which already defaults to UTF-8. Match both the Prism and
legacy paths to magic_comment_spec.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-29 08:09:51 +09:00
Jean Boussier d17f8ecd19 file.c: right size the rb_find_file_ext & rb_find_file buffer
It generally end up frozen in `$LOADED_FEATURES` so it's preferable
to predict its size and only deal with an embedded string most of
the time.

It saves on having to allocate a `MAXPATHLEN + 2` (1026) bytes long
buffer and then realloc it later to shink it.
2026-06-19 21:20:07 +02:00
Satoshi Tagomori 276f0d9b3e [Bug #21881] Separate the master and root box
This change separates the master box from the root box, as the single
master copy of boxes.
Before this change, the root box is the source of copies, and also
it runs builtin classes' code. Builtin code makes changes by
requiring files, thus the source of copies is mutable, be different
from the past one. This causes different internal states of boxes,
depending on when it is created.
After this change, all boxes are created from the master box, and
the master box never runs code, so it realizes the immutable source
of copies.

This also makes is possible to separate RubyGems (and other default
gems) from each boxes. All boxes will have their own copies of RubyGems.
RubyGems has its internal state, but it'll be separated between boxes
after this change.
2026-05-10 09:38:45 +09:00
Étienne Barrié 42b3cdc51a Remove discard qualifiers warning with C23 strchr
C23 has qualifier-preserving standard library functions, so calling
strchr with a `const char *` will return a `const char *`. We can change
the type of the local variables because we don't mutate the strings.
2026-04-22 16:45:35 +09:00
Kevin Newton 78ab3a7ced Leverage new Prism APIs
Prism changed structure quite a bit. Most of the previously-public
structs are now opaque. This requires quite a bit of changes
internally.

It also triggered some unrelated changes, which were necessary
because Prism's main header used to pull in standard headers. So
box.c and jit.c are now no longer transitively getting all the
headers they needed.
2026-03-20 09:37:43 -04:00
Randy Stauner e7cff2e817 ZJIT: Register builtin CMEs before prelude to avoid prepend crash
Split rb_zjit_init into rb_zjit_init_builtin_cmes (called before
ruby_init_prelude) and rb_zjit_init (called after). The prelude may
load bundler via BUNDLER_SETUP which can call Kernel.prepend, moving
core methods to an origin iclass. Registering method annotations
before the prelude ensures we capture CMEs while core classes are
pristine.
2026-02-19 10:57:10 -05:00
Randy Stauner a19becac5b YJIT: Register builtin CMEs before prelude to avoid prepend crash
Split rb_yjit_init into rb_yjit_init_builtin_cmes (called before
ruby_init_prelude) and rb_yjit_init (called after). The prelude may
load bundler via BUNDLER_SETUP which can call Kernel.prepend, moving
core methods to an origin iclass. Registering method codegen before
the prelude ensures we capture CMEs while core classes are pristine.
2026-02-19 10:57:10 -05:00
Nobuyoshi Nakada f486ee3402 [Feature #21872] Search script from $PATH only if no separator 2026-02-10 20:07:47 +09:00
Kevin Newton af4a1ca021 Use slices instead of locations
In the C API, we want to use slices instead of locations in the
AST. In this case a "slice" is effectively the same thing as the
location, expect it is represented using a 32-bit offset and a
32-bit length. This will cut down on half of the space of all of
the locations in the AST.

Note that from the Ruby/Java/JavaScript side, this is effectively
an invisible change. This only impacts the C/Rust side.
2026-01-27 15:30:45 -05:00
Nobuyoshi Nakada ccc8610b66 Remove RUBY_GC_HEAP_INIT_SLOTS environment variable 2025-12-26 15:11:23 +09:00
NARUSE, Yui 479f8682c8 Remove extra help 2025-12-24 23:52:45 +09:00
NARUSE, Yui 29ffc5d624 Reapply "Extract ruby_api_version_name"
This reverts commit ba2f697219.

Box already used ruby_api_version_name.
2025-12-24 23:07:35 +09:00
NARUSE, Yui 285e22edc5 Revert "Add link to Ruby options doc in help text"
This reverts commit 31ff07ed1e.

* Don't add a test which only runs on production release
  * https://github.com/ruby/actions/actions/runs/20486784889/job/58870959976
* Don't add a new line to `ruby --help`
  * https://github.com/ruby/ruby/pull/14142#issuecomment-3689829564
2025-12-24 22:55:44 +09:00
NARUSE, Yui ba2f697219 Revert "Extract ruby_api_version_name"
This reverts commit 9b576cd625.
2025-12-24 22:55:44 +09:00
Kouhei Yanagita 0f45d0c484 Update man and help: -d option set $VERBOSE to true 2025-11-27 16:00:35 +09:00
Godfrey Chan f84bbb4238 ZJIT: add support for lazy RubyVM::ZJIT.enable
This implements Shopify#854:

- Splits boot-time and enable-time initialization,
  tracks progress with `InitializationState` enum

- Introduces `RubyVM::ZJIT.enable` Ruby method for
  enabling the JIT lazily, if not already enabled

- Introduces `--zjit-disable` flag, which can be
  used alongside the other `--zjit-*` flags but
  prevents enabling the JIT at boot time

- Adds ZJIT infra to support JIT hooks, but this
  is not currently exercised (Shopify/ruby#667)

Left for future enhancements:

- Support kwargs for overriding the CLI flags in
  `RubyVM::ZJIT.enable`

Closes Shopify#854
2025-11-18 08:35:09 -08:00
Randy Stauner 3ddb5f99a9 Allow --jit to mean zjit if yjit isn't defined
The --help output suggests this should work
as ZJIT is labeled as the default if YJIT isn't enabled.
2025-11-10 13:14:13 -08:00
Satoshi Tagomori d2a587c791 renaming internal data structures and functions from namespace to box 2025-11-07 13:14:54 +09:00
Peter Zhu da4bd3b3df Fix memory leak when RUBYOPT is invalid
When RUBYOPT is invalid, it raises an error which causes moreswitches
to leak memory. It can be seen when building with LSAN enabled:

    $ RUBY_FREE_AT_EXIT=1 RUBYOPT=f ruby
    ruby: invalid option -f  (-h will show valid options) (RuntimeError)

    Direct leak of 16 byte(s) in 1 object(s) allocated from:
        #0 0x618cef8efa23 in malloc (miniruby+0x64a23)
        #1 0x618cefa0e8d8 in rb_gc_impl_malloc gc/default/default.c:8182:5
        #2 0x618cef9f7f01 in ruby_xmalloc2_body gc.c:5182:12
        #3 0x618cef9f7eac in ruby_xmalloc2 gc.c:5176:34
        #4 0x618cefb547b2 in moreswitches ruby.c:919:18
        #5 0x618cefb526fe in process_options ruby.c:2350:9
        #6 0x618cefb524ac in ruby_process_options ruby.c:3202:12
        #7 0x618cef9dc11f in ruby_options eval.c:119:16
        #8 0x618cef8f2fb5 in rb_main main.c:42:26
        #9 0x618cef8f2f59 in main main.c:62:12
2025-10-22 19:36:47 -04:00
Satoshi Tagomori 52c6b32f80 Initialize the main namespace after loading builtin libraries
* For having the common set of loaded libraries between root and main namespaces
* To have the consistent $LOADED_FEATURES in the main namespace
2025-10-07 14:19:26 +09:00
Satoshi Tagomori 4f47327287 Update current namespace management by using control frames and lexical contexts
to fix inconsistent and wrong current namespace detections.

This includes:
* Moving load_path and related things from rb_vm_t to rb_namespace_t to simplify
  accessing those values via namespace (instead of accessing either vm or ns)
* Initializing root_namespace earlier and consolidate builtin_namespace into root_namespace
* Adding VM_FRAME_FLAG_NS_REQUIRE for checkpoints to detect a namespace to load/require files
* Removing implicit refinements in the root namespace which was used to determine
  the namespace to be loaded (replaced by VM_FRAME_FLAG_NS_REQUIRE)
* Removing namespaces from rb_proc_t because its namespace can be identified by lexical context
* Starting to use ep[VM_ENV_DATA_INDEX_SPECVAL] to store the current namespace when
  the frame type is MAGIC_TOP or MAGIC_CLASS (block handlers don't exist in this case)
2025-09-29 01:15:38 +09:00
Takashi Kokubun 0ab7833773 ruby.c: Fallback FEATURE_BIT(jit) to FEATURE_BIT(zjit)
if it's the only JIT enabled in the build
2025-09-05 12:36:40 -07:00
Alan Wu fdb831fdfc ZJIT: Look for RUBY_ZJIT_ENABLE in combo build with YJIT 2025-08-14 15:38:52 -04:00
Nobuyoshi Nakada 9b576cd625 Extract ruby_api_version_name 2025-08-14 12:39:19 +09:00
Peter Zhu 31ff07ed1e Add link to Ruby options doc in help text
Adds link to https://docs.ruby-lang.org/en/master/ruby/options_md.html in
Ruby help text (-h and --help).
2025-08-13 11:24:50 -04:00
Takashi Kokubun 4f34eddbd3 YJIT, ZJIT: Fix JITs compiling prelude (#14171) 2025-08-11 14:35:34 -07:00
Takashi Kokubun 2cd10de330 ZJIT: Prepare for sharing JIT hooks with ZJIT (#14044) 2025-07-30 10:11:10 -07:00
Takashi Kokubun f1acf47ca2 YJIT: Call YJIT hooks before enabling YJIT (#14032) 2025-07-28 15:17:45 -07:00
Étienne Barrié 31c1f3665a Stop setting TMP_RUBY_PREFIX during prelude
It's unnecessary now that builtin-loader supports sub-libraries:
9faa9ced96
2025-06-28 10:27:44 +09:00
Jean Boussier 96a0c2065a Mark RClass instance that may be namespaced with RCLASS_NAMESPACEABLE 2025-06-23 10:04:58 +01:00
Satoshi Tagomori 382645d440 namespace on read 2025-05-11 23:32:50 +09:00
Takashi Kokubun 608fe6ee53 ZJIT: Handle ZJIT options properly (#13197) 2025-04-29 09:50:05 -07:00
Takashi Kokubun 50ae35054b Resurrect yjit_hook 2025-04-18 21:53:01 +09:00
Takashi Kokubun 0252ce1cd4 Implement Options as part of ZJITState 2025-04-18 21:52:57 +09:00
Takashi Kokubun eb677ec24c Fix the handling of flags 2025-04-18 21:52:56 +09:00
Takashi Kokubun b076037af2 Disable yjit_hook builtin for now 2025-04-18 21:52:56 +09:00
Takashi Kokubun 8d5d5b34cf Hook zjit_init 2025-04-18 21:52:55 +09:00
Takashi Kokubun cabfa3bfe1 Call libzjit from CRuby 2025-04-18 21:52:55 +09:00