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

870 Коммитов

Автор SHA1 Сообщение Дата
Peter Zhu 0aa404b957 Change heap init environment variable names
This commit changes RUBY_GC_HEAP_INIT_SIZE_{40,80,160,320,640}_SLOTS to
RUBY_GC_HEAP_{0,1,2,3,4}_INIT_SLOTS. This is easier to use because the
user does not need to determine the slot sizes (which can vary between
32 and 64 bit systems). They now just use the heap names
(`GC.stat_heap.keys`).
2023-08-30 19:37:11 -04:00
Peter Zhu 9ea9f99248 [Feature #19785] Deprecate RUBY_GC_HEAP_INIT_SLOTS
This environment variable is replaced by
`RUBY_GC_HEAP_INIT_SIZE_%d_SLOTS`, so it doesn't make sense to keep it.
2023-08-25 21:50:56 -04:00
Nobuyoshi Nakada 6aa16f9ec1 Move SCRIPT_LINES__ away from parse.y 2023-08-25 18:23:05 +09:00
Jeremy Evans 347993e95c Call ruby_init_setproctitle before process_options
Fixes [Bug #11269]
2023-08-22 21:45:20 -07:00
Nobuyoshi Nakada b56e5c6b94 Fix the precedence of `--backtrace-limit` option
In general, if the same option specifying a single value is given
multiple times at the same level, the last one overrides the earlier
ones, unless prohibited.
2023-08-13 02:26:49 +09:00
Nobuyoshi Nakada cc0fca2729 Fix range of `--backtrace-limit`
Also an option command line should have precedence over `RUBYOPT`.
2023-08-11 01:56:50 +09:00
Benoit Daloze 3c41a04b6c Fix encoding switches when RUBYOPT is empty or only spaces
* Follow-up of dbbc3583ba which broke this.
2023-08-02 17:13:38 +02:00
Tom Stuart de68e240c7 Allow -1 as the value of `--backtrace-limit` option
-1 is a legitimate backtrace limit — in fact, it’s the default — so it
should be possible to provide it with the `--backtrace-limit` option.
2023-07-16 00:39:01 +09:00
Tom Stuart 72a3bb7edc Allow `--backtrace-limit` option to appear in RUBYOPT
There’s no reason to prevent RUBYOPT from controlling the backtrace
limit. In fact, Matz said [0] he was expecting this to be possible.

[0] https://bugs.ruby-lang.org/issues/8661#note-27
2023-07-16 00:39:01 +09:00
Nobuyoshi Nakada db3b8f84f5 Set backtrace length limit at last
Command line options should have higher precedence than the same
options in shebang and `RUBYOPT`.
2023-07-13 22:59:26 +09:00
Nobuyoshi Nakada dbbc3583ba Preserve already set options in `moreswitches` 2023-07-13 22:59:26 +09:00
Nobuyoshi Nakada 1c2a4d9682 Shrink `ruby_cmdline_options_t` a bit 2023-07-13 22:59:26 +09:00
Takashi Kokubun 9c1776e6b0
YJIT: Use --yjit-exec-mem-size=128 by default (#8031) 2023-07-05 14:21:02 -07:00
yui-knk b481b673d7 [Feature #19719] Universal Parser
Introduce Universal Parser mode for the parser.
This commit includes these changes:

* Introduce `UNIVERSAL_PARSER` macro. All of CRuby related functions
  are passed via `struct rb_parser_config_struct` when this macro is enabled.
* Add CI task with 'cppflags=-DUNIVERSAL_PARSER' for ubuntu.
2023-06-12 18:23:48 +09:00
Nobuyoshi Nakada 533368ccbd
Split long options from `proc_options` 2023-06-08 12:06:40 +09:00
Nobuyoshi Nakada 6ffbd96147
Split some options from `proc_options`
`-W`, `-e`, `-K`, `-0`, `-E` and `--encoding` options.
2023-06-08 12:06:39 +09:00
Nobuyoshi Nakada 3cdafe9be1 Move per sections in help message 2023-06-05 23:59:39 +09:00
Nobuyoshi Nakada b5467ae38a Add additional info for `-0` to `--help` message 2023-06-05 23:59:39 +09:00
Nobuyoshi Nakada feb946c3e2 Fold option lines in help message 2023-06-05 23:59:39 +09:00
Yla Aioi 3fe0f8c68b
[Bug #19685]: Add `-y` and `--yydebug` document to `--help`
Add -y option information to `--help`
Fix a warning on the man page
2023-06-05 12:05:58 +09:00
Nobuyoshi Nakada e502600fb9
Assertion on message length for the `-h` option 2023-05-31 15:15:59 +09:00
Nobuyoshi Nakada 7f7a8fa555
Put `rb_fork` back into process.c
Now, calling `rb_fork` directly breaks the PID cache and the timer
thread, so must use `rb_fork_ruby` or similar instead.
2023-05-21 23:00:27 +09:00
Nobuyoshi Nakada 0867588980
Use `rb_fork_ruby` for `--help` pager
Instead of `rb_fork`, to update `current_fork_gen` which has been
introduced at 3563e1383f.

Otherwise, the forked process attempts to stop the timer thread, but
raises an exception because the thread is not alive in the child and
dies because already no tag is present at that time.
2023-05-21 16:47:14 +09:00
Nobuyoshi Nakada 2d9bc3efe5 [Bug #19597] Freeze script name 2023-05-10 17:14:20 +09:00
Jean Boussier 6a5c355e4e Add RB_WARN_CATEGORY_DEFAULT_BITS
Followup: ac123f167a

RB_WARN_CATEGORY_ALL_BITS is exposed in a public header, so it
makes sense for it to be updated to contain all valid bits.

Instead we introduce RB_WARN_CATEGORY_DEFAULT_BITS to list the
categories that are enabled by default.
2023-04-14 09:46:10 +02:00
Jean Boussier ac123f167a Emit a performance warning when a class reached max variations
[Feature #19538]

This new `peformance` warning category is disabled by default.
It needs to be specifically enabled via `-W:performance` or `Warning[:performance] = true`
2023-04-13 16:36:17 +02:00
Adam Hess 854baee2c9
YJIT: Add a sampling option to exit tracing (#7693)
Add a sampling option to trace exits

Running YJIT with trace exits enabled can make very large metrics files.
This allows us to configure a sample rate to make tracing exits possible
on larger tests. This also updates the documented YJIT options.

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
Co-authored-by: John Hawthorn <john@hawthorn.email>
Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
2023-04-13 10:07:07 -04:00
Nobuyoshi Nakada 5f8ebcada0
[Bug #19584] Register global variable address before assignment 2023-04-07 11:21:08 +09:00
Peter Zhu 1da2e7fca3
[Feature #19579] Remove !USE_RVARGC code (#7655)
Remove !USE_RVARGC code

[Feature #19579]

The Variable Width Allocation feature was turned on by default in Ruby
3.2. Since then, we haven't received bug reports or backports to the
non-Variable Width Allocation code paths, so we assume that nobody is
using it. We also don't plan on maintaining the non-Variable Width
Allocation code, so we are going to remove it.
2023-04-04 17:30:06 -04:00
Takashi Kokubun d189f8d870 RJIT: Prefix rjit_options with rb_ 2023-03-18 21:28:55 -07:00
Takashi Kokubun 9cd5441d28 RJIT: Implement --rjit-trace-exits 2023-03-12 15:15:08 -07:00
Takashi Kokubun f5909ac6d9 RJIT: Stop allowing leaked globals rjit_* 2023-03-08 23:24:38 -08:00
Takashi Kokubun 4bf037bebd Update documentation about RJIT 2023-03-07 23:31:39 -08:00
Takashi Kokubun 1d39d2d334 Update options available in RJIT 2023-03-07 21:19:04 -08:00
Takashi Kokubun 23ec248e48 s/mjit/rjit/ 2023-03-06 23:44:01 -08:00
Takashi Kokubun 2e875549a9 s/MJIT/RJIT/ 2023-03-06 23:44:01 -08:00
Takashi Kokubun 5760f7fd3c Skip compiling at_exit without --mjit-stats 2023-03-05 22:11:20 -08:00
Takashi Kokubun a9f4e5cc60
YJIT: Fix default call threshold in help (#7424) 2023-03-02 16:16:09 -05:00
Takashi Kokubun 526111290b Revert "reuse open(2) from rb_file_load_ok on POSIX-like system"
This reverts commit 35136e1e9c.

test-spec has been failing since this revision.

.github/workflows/compilers.yml:82
https://github.com/ruby/ruby/actions/runs/4276884159/jobs/7445299562

```
env:
  # Minimal flags to pass the check.
  default_cc: 'gcc-11 -fcf-protection -Wa,--generate-missing-build-notes=yes'
  optflags: '-O2'
  LDFLAGS: '-Wl,-z,now'
  # FIXME: Drop skipping options
  # https://bugs.ruby-lang.org/issues/18061
  # https://sourceware.org/annobin/annobin.html/Test-pie.html
  TEST_ANNOCHECK_OPTS: "--skip-pie --skip-gaps"
```

Failure:

```
  1)
  An exception occurred during: Kernel#require (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded
  /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:317
  Kernel#require (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded ERROR
  LeakError: Leaked file descriptor: 8 : #<File:/__w/ruby/ruby/src/spec/ruby/fixtures/code/load_fixture.ext.rb>
  /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:5:in `<top (required)>'

  2)
  An exception occurred during: Kernel#require ($LOADED_FEATURES) stores an absolute path
  /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:330
  Kernel#require ($LOADED_FEATURES) stores an absolute path ERROR
  LeakError: Closed file descriptor: 8
  /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:5:in `<top (required)>'

  3)
  An exception occurred during: Kernel#require ($LOADED_FEATURES) does not load a non-canonical path for a file already loaded
  /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:535
  Kernel#require ($LOADED_FEATURES) does not load a non-canonical path for a file already loaded ERROR
  LeakError: Leaked file descriptor: 8 : #<File:/__w/ruby/ruby/src/spec/ruby/fixtures/code/load_fixture.rb>
  /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:5:in `<top (required)>'

  4)
  An exception occurred during: Kernel#require ($LOADED_FEATURES) does not load a ../ relative path for a file already loaded
  /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:551
  Kernel#require ($LOADED_FEATURES) does not load a ../ relative path for a file already loaded ERROR
  LeakError: Leaked file descriptor: 9 : #<File:../code/load_fixture.rb>
  /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:5:in `<top (required)>'

  5)
  An exception occurred during: Kernel#require ($LOADED_FEATURES) complex, enumerator, rational, thread, ruby2_keywords are already required
  /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:563
  Kernel#require ($LOADED_FEATURES) complex, enumerator, rational, thread, ruby2_keywords are already required ERROR
  LeakError: Closed file descriptor: 8
  Closed file descriptor: 9
  /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:5:in `<top (required)>'

  6)
  An exception occurred during: Kernel.require (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded
  /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:317
  Kernel.require (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded ERROR
  LeakError: Leaked file descriptor: 8 : #<File:/__w/ruby/ruby/src/spec/ruby/fixtures/code/load_fixture.ext.rb>
  /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:23:in `<top (required)>'

  7)
  An exception occurred during: Kernel.require ($LOADED_FEATURES) stores an absolute path
  /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:330
  Kernel.require ($LOADED_FEATURES) stores an absolute path ERROR
  LeakError: Closed file descriptor: 8
  /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:23:in `<top (required)>'

  8)
  An exception occurred during: Kernel.require ($LOADED_FEATURES) does not load a non-canonical path for a file already loaded
  /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:535
  Kernel.require ($LOADED_FEATURES) does not load a non-canonical path for a file already loaded ERROR
  LeakError: Leaked file descriptor: 8 : #<File:/__w/ruby/ruby/src/spec/ruby/fixtures/code/load_fixture.rb>
  /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:23:in `<top (required)>'

  9)
  An exception occurred during: Kernel.require ($LOADED_FEATURES) does not load a ../ relative path for a file already loaded
  /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:551
  Kernel.require ($LOADED_FEATURES) does not load a ../ relative path for a file already loaded ERROR
  LeakError: Leaked file descriptor: 9 : #<File:../code/load_fixture.rb>
  /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:23:in `<top (required)>'

  10)
  An exception occurred during: Kernel.require ($LOADED_FEATURES) complex, enumerator, rational, thread, ruby2_keywords are already required
  /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:563
  Kernel.require ($LOADED_FEATURES) complex, enumerator, rational, thread, ruby2_keywords are already required ERROR
  LeakError: Closed file descriptor: 8
  Closed file descriptor: 9
  /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:23:in `<top (required)>'

  11)
  An exception occurred during: Kernel#require_relative with a relative path (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded
  /__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:197
  Kernel#require_relative with a relative path (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded ERROR
  LeakError: Leaked file descriptor: 8 : #<File:/__w/ruby/ruby/src/spec/ruby/fixtures/code/load_fixture.ext.rb>
  /__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:4:in `<top (required)>'

  12)
  An exception occurred during: Kernel#require_relative with a relative path ($LOADED_FEATURES) stores an absolute path
  /__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:205
  Kernel#require_relative with a relative path ($LOADED_FEATURES) stores an absolute path ERROR
  LeakError: Closed file descriptor: 8
  /__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:4:in `<top (required)>'

  13)
  An exception occurred during: Kernel#require_relative with an absolute path (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded
  /__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:399
  Kernel#require_relative with an absolute path (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded ERROR
  LeakError: Leaked file descriptor: 8 : #<File:/__w/ruby/ruby/src/spec/ruby/fixtures/code/load_fixture.ext.rb>
  /__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:277:in `<top (required)>'

  14)
  An exception occurred during: Kernel#require_relative with an absolute path ($LOAD_FEATURES) stores an absolute path
  /__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:407
  Kernel#require_relative with an absolute path ($LOAD_FEATURES) stores an absolute path ERROR
  LeakError: Closed file descriptor: 8
  /__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:277:in `<top (required)>'
```
2023-02-27 09:24:45 -08:00
Eric Wong 35136e1e9c reuse open(2) from rb_file_load_ok on POSIX-like system
When loading Ruby source files, we can save the result of
successful opens as open(2)/openat(2) are a fairly expensive
syscalls.  This also avoids a time-of-check-to-time-of-use
(TOCTTOU) problem.

This reduces open(2) syscalls during `require'; but should be
most apparent when users have a small $LOAD_PATH.  Users with
large $LOAD_PATH will benefit less since there'll be more
open(2) failures due to ENOENT.

With `strace -c -e openat ruby -e exit' under Linux, this
results in a ~14% reduction of openat(2) syscalls
(glibc uses openat(2) to implement open(2)).

 % time     seconds  usecs/call     calls    errors syscall
 ------ ----------- ----------- --------- --------- ----------------
   0.00    0.000000           0       296       110 openat
   0.00    0.000000           0       254       110 openat

Additionally, the introduction of `struct ruby_file_load_state'
may make future optimizations more apparent.

This change cannot benefit binary (.so) loading since the
dlopen(3) API requires a filename and I'm not aware of an
alternative that takes a pre-existing FD.  In typical
situations, Ruby source files outnumber the mount of .so
files.
2023-02-26 20:39:41 +00:00
Nobuyoshi Nakada 62146d3cee
Fix a typo 2023-02-01 22:45:45 +09:00
Nobuyoshi Nakada 9445a14d31
Suppress an unused-function warning 2023-02-01 22:42:12 +09:00
Maxime Chevalier-Boisvert 4ce642620f
Make sure RUBY_YJIT_ENABLE only enables YJIT for truthy values (#7208)
* Make sure RUBY_YJIT_ENABLE only enables YJIT for truthy values

Addresses bug reported in: https://github.com/Shopify/yjit/issues/309

* Update ruby.c

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>

---------

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
2023-01-31 12:18:41 -05:00
Takashi Kokubun bcdc9cf159
YJIT: Make --yjit-stats always visible on --help (#6946) 2022-12-19 10:19:56 -05:00
Takashi Kokubun a66a69865d
YJIT: Change the default mem size to 64MiB (#6912)
* YJIT: Change the default mem size to 64MiB

* Also update ruby --help

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
2022-12-13 11:00:22 -05:00
Maxime Chevalier-Boisvert 1004d693b7
Make it so YJIT is no longer marked as experimental (#6909)
Tested on production workloads at Shopify for > 1 year and proven
to be quite stable. Enabling YJIT at run-time is still guarded
behind the --yjit command-line option for now.
2022-12-12 15:13:46 -05:00
Maxime Chevalier-Boisvert 9350c2b12f
Update YJIT warning, mention need to install rustc (#6873) 2022-12-07 15:02:45 -05:00
Nobuyoshi Nakada b7a0ce32da [Bug #19016] `SyntaxError` with parser error messages
Raise a `SyntaxError` with the parser error message, in the case
reading from a file instead of the `-e` option or standard input. So
syntax_suggest can get the message from the caught error.
2022-11-22 00:33:19 +09:00
Takashi Kokubun 120b747b7d
YJIT: Lazily enable YJIT after prelude (#6597)
* YJIT: Lazily enable YJIT after prelude

* Update dependencies

* Use a bit field for opt->yjit
2022-10-24 12:20:44 -04:00
Nobuyoshi Nakada f55212bce9 Move "special consts" so `Qundef` and `Qnil` differ just 1 bit 2022-10-20 22:05:27 +09:00
Takashi Kokubun 2e3b764ad1
Remove a leftover comment [ci skip] 2022-10-19 17:45:36 -07:00
Takashi Kokubun d9d9005a3a
MJIT: Stop using the VM barrier for jit_cont
This solves multiple problems.

First, RB_VM_LOCK_ENTER/LEAVE is a barrier. We could at least use the
_NO_BARRIER variant.

Second, this doesn't need to interfere with GC or other GVL users when
multiple Ractors are used. This needs to be used in very few places, so
the benefit of fine-grained locking would outweigh its small maintenance
cost.

Third, it fixes a crash for YJIT. Because YJIT is never disabled until a
process exits unlike MJIT that finishes earlier, we could call jit_cont_free
when EC no longer exists, which crashes RB_VM_LOCK_ENTER.
2022-10-19 17:20:48 -07:00
Nobuyoshi Nakada 412e3c7a8d Assert for RTEST that Qnil and Qfalse differ just 1 bit 2022-10-19 22:55:42 +09:00
Takashi Kokubun e7c71c6c92
Make mjit_cont sharable with YJIT (#6556)
* Make mjit_cont sharable with YJIT

* Update dependencies

* Update YJIT binding
2022-10-17 09:27:59 -07:00
Nobuyoshi Nakada f178ff3933
Allow abbreviated dump options with additional options 2022-10-09 16:27:34 +09:00
yui-knk 52eaffde86 Support "+error-tolerant" as ruby option
[Feature #19013]
2022-10-08 17:59:11 +09:00
Takashi Kokubun 3767c6a90d
Ruby MJIT (#6028) 2022-09-04 21:53:46 -07:00
Takashi Kokubun cfa40e225a
Prefer stdbool for MJIT options
same motivation as d6f21b308b
2022-09-03 20:01:51 -07:00
schneems a50df1ab0e Setup SyntaxSuggest as default gem
Adds the `syntax_suggest` syntax error display tool to Ruby through the same mechanism as `error_highlight` and `did_you_mean`. Reference ticket: https://bugs.ruby-lang.org/issues/18159

close #4845

## What is syntax_suggest?

When a syntax error is raised by requiring a file, dead_end will use a combination of indentation and lexing to identify the problem.

> Note: Previously this tool was named `dead_end`. 

## Known issues

- SyntaxSearch's approach of showing syntax errors only works through integration with `require`, `load`, `autoload`, and `require_relative` (since it monkeypatches them to detect syntax errors). It does not work with direct Ruby file invocations https://github.com/zombocom/dead_end/issues/31.
  - This causes failure in the test suite (test_expected_backtrace_location_when_inheriting_from_basic_object_and_including_kernel) and confusion when inspecting backtraces if there's a different error when trying to require a file such as measuring memory (https://github.com/zombocom/syntax_suggest/issues/124#issuecomment-1006705016).
  - Discussed fix. We previously talked about opening up `SyntaxError` to be monkeypatched in the same way that other gems hook into `NoMethodError`. This is currently not possible and requires development work. When we last talked about it at RubyKaigi Nobu expressed an ability to make such a change.
2022-08-19 10:02:24 +09:00
Nobuyoshi Nakada ee864beb7c
Simplify around `USE_YJIT` macro (#6240)
* Simplify around `USE_YJIT` macro

- Use `USE_YJIT` macro only instead of `YJIT_BUILD`.
- An intermediate macro `YJIT_SUPPORTED_P` is no longer used.

* Bail out if YJIT is enabled on unsupported platforms
2022-08-15 13:05:12 -04:00
Nobuyoshi Nakada f2423be49d
Duplicate libruby self path
When LOAD_RELATIVE, as `sopath` is truncated to the prefix path, make
the duplicate before it.  Also make `rb_libruby_selfpath` frozen and
hidden.
2022-08-07 14:46:59 +09:00
Nobuyoshi Nakada 58c8b6e862
Adjust styles [ci skip] 2022-08-06 10:13:20 +09:00
Yuta Saito 00f411c58a Add `-bundle_loader` to mjit compilation args on macOS 2022-08-04 16:29:22 +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
Takashi Kokubun 5b21e94beb Expand tabs [ci skip]
[Misc #18891]
2022-07-21 09:42:04 -07:00
Nobuyoshi Nakada 58e7205c82
See the environment variable and then check if JIT options conflict 2022-07-08 19:10:18 +09:00
Nobuyoshi Nakada cd94842922 [Bug #18892] Reset `ARGF.lineno` after reading shebang 2022-07-07 11:33:07 +09:00
Nobuyoshi Nakada 829d726604 Fallback to the default JIT only when no JIT is enabled
Usually, command line options are given precedence first, environment
variables next, and fall back to configuration options at last.
2022-07-02 09:15:20 +09:00
Nobuyoshi Nakada 33100797c4
Remove redundant parentheses [ci skip] 2022-07-01 09:37:00 +09:00
Nobuyoshi Nakada f4d70e1cd8
Make `FEATURE_SET_P` macro to include `FEATURE_BIT` 2022-06-30 16:51:39 +09:00
Nobuyoshi Nakada bd8ed1f904
Do not call `exit()` directly 2022-06-29 20:10:29 +09:00
Alan Wu eb1a84a9c3 When YJIT is not built, hide options and use MJIT for --jit
YJIT is now a build-time opt-in so on platforms that YJIT could support
it could still be unavailable due to user discretion. Use MJIT for --jit
and don't display YJIT related command line options in --help when YJIT
is not included in the build.
2022-06-23 18:12:25 -04: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
Alan Wu f90549cd38 Rust YJIT
In December 2021, we opened an [issue] to solicit feedback regarding the
porting of the YJIT codebase from C99 to Rust. There were some
reservations, but this project was given the go ahead by Ruby core
developers and Matz. Since then, we have successfully completed the port
of YJIT to Rust.

The new Rust version of YJIT has reached parity with the C version, in
that it passes all the CRuby tests, is able to run all of the YJIT
benchmarks, and performs similarly to the C version (because it works
the same way and largely generates the same machine code). We've even
incorporated some design improvements, such as a more fine-grained
constant invalidation mechanism which we expect will make a big
difference in Ruby on Rails applications.

Because we want to be careful, YJIT is guarded behind a configure
option:

```shell
./configure --enable-yjit # Build YJIT in release mode
./configure --enable-yjit=dev # Build YJIT in dev/debug mode
```

By default, YJIT does not get compiled and cargo/rustc is not required.
If YJIT is built in dev mode, then `cargo` is used to fetch development
dependencies, but when building in release, `cargo` is not required,
only `rustc`. At the moment YJIT requires Rust 1.60.0 or newer.

The YJIT command-line options remain mostly unchanged, and more details
about the build process are documented in `doc/yjit/yjit.md`.

The CI tests have been updated and do not take any more resources than
before.

The development history of the Rust port is available at the following
commit for interested parties:
1fd9573d8b

Our hope is that Rust YJIT will be compiled and included as a part of
system packages and compiled binaries of the Ruby 3.2 release. We do not
anticipate any major problems as Rust is well supported on every
platform which YJIT supports, but to make sure that this process works
smoothly, we would like to reach out to those who take care of building
systems packages before the 3.2 release is shipped and resolve any
issues that may come up.

[issue]: https://bugs.ruby-lang.org/issues/18481

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
Co-authored-by: Noah Gibbs <the.codefolio.guy@gmail.com>
Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2022-04-27 11:00:22 -04:00
Yuta Saito be1382b498 ruby.c: initialize extra optional extensions linked statically
Add a hook point to initialize extra extension libraries. The default
hook function is replaced when linking a strong `Init_extra_exts`
symbol. A builder can insert an object file that defines Init_extra_exts
by XLDFLAGS.
2022-01-19 11:19:06 +09: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
Nobuyoshi Nakada 2dff82bfca
`O_NONBLOCK` is not always a preprocessor constant on all platforms 2022-01-16 23:47:10 +09:00
Nobuyoshi Nakada c1bcfeec38
Transfer the responsibility for MJIT options to mjit.c 2022-01-15 18:57:33 +09:00
Nobuyoshi Nakada d853a7886e Define the default JIT feature bit 2022-01-15 18:55:47 +09:00
Nobuyoshi Nakada 26b4aa853f
Show JIT options only when supported 2022-01-12 17:51:14 +09:00
Kazuhiro NISHIYAMA b5310b8975
Fix compile errors
```
compiling ../ruby.c
../ruby.c:1547:17: error: implicit declaration of function 'setup_yjit_options' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                setup_yjit_options(s, &opt->yjit);
                ^
../ruby.c:1547:17: note: did you mean 'setup_mjit_options'?
../ruby.c:1122:1: note: 'setup_mjit_options' declared here
setup_mjit_options(const char *s, struct mjit_options *mjit_opt)
^
../ruby.c:1547:45: error: no member named 'yjit' in 'struct ruby_cmdline_options'; did you mean 'mjit'?
                setup_yjit_options(s, &opt->yjit);
                                            ^~~~
                                            mjit
../ruby.c:192:25: note: 'mjit' declared here
    struct mjit_options mjit;
                        ^
../ruby.c:1924:28: error: no member named 'yjit' in 'struct ruby_cmdline_options'; did you mean 'mjit'?
        rb_yjit_init(&opt->yjit);
                           ^~~~
                           mjit
../ruby.c:192:25: note: 'mjit' declared here
    struct mjit_options mjit;
                        ^
3 errors generated.
```
2022-01-11 17:33:01 +09:00
Nobuyoshi Nakada 3d675c72b9
Use `setup_yjit_options` only when supported 2022-01-11 17:26:21 +09:00
Nobuyoshi Nakada 1c9b5d452e
Reject command line option ending with `-` 2022-01-11 11:49:34 +09:00
Nobuyoshi Nakada 8b585f7460
Define YJIT options only when supported 2022-01-11 10:12:40 +09:00
Kazuhiro NISHIYAMA c764e368bd
Fix default --jit-max-cache in `ruby --help`
changed at 028f1887c2
2022-01-10 20:17:05 +09:00
Kazuhiro NISHIYAMA a7faca51ac
Add `=num` to yjit options
`--yjit-call-threshold` and `--yjit-max-versions` need an argument.
2022-01-09 12:39:34 +09:00
Peter Zhu 44379805b0 Fix crash on bootup when RGENGC_CHECK_MODE=2 with GC stress
We need to unshare the array loaded_features because the shared root
could be old gen (while loaded_features is young) which causes a WB
miss.
2022-01-04 14:46:20 -05:00
Takashi Kokubun 11b8aaa26a
Rename --jit to --mjit (#5248)
* Rename --jit to --mjit

[Feature #18349]

* Fix a few more --jit references

* Fix MJIT Actions

* More s/jit/mjit/ and re-introduce --disable-jit

* Update NEWS.md

* Fix test_bug_reporter_add
2021-12-13 16:08:01 -08:00
Yusuke Endoh a692a1597f ruby.c: Fix typo 2021-12-13 10:29:08 +09:00
Yusuke Endoh 8613c0c675 Introduce an option "--dump=insns_without_opt" for debugging purposes 2021-12-13 10:29:08 +09:00
Aaron Patterson 3b2b28d035
Revert "Force disable yjit on OpenBSD"
This reverts commit 119626da94.
2021-12-01 12:46:30 -08:00
Maxime Chevalier-Boisvert cdebf57ec6
Add --yjit-no-type-prop so we can test YJIT without type propagation (#5135)
* Add --yjit-no-type-prop so we can test YJIT without type propagation

* Fix typo in command line option

* Leave just two test workflows enable for YJIT
2021-11-18 10:44:31 -05: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
Takashi Kokubun 6469038ae2
Fix TestRubyOptions#test_enable for -DMJIT_FORCE_ENABLE
--enable=all didn't work when cppflags=-DMJIT_FORCE_ENABLE was given.
2021-10-21 20:41:14 -07:00
Jeremy Evans 119626da94 Force disable yjit on OpenBSD
TestRubyOptions#test_enable was broken on OpenBSD after the yjit
merge. --yjit (and --enable-all, which enables --yjit) fails on
OpenBSD because yjit uses an insecure mmap call (both writable
and executable), in alloc_exec_mem, which OpenBSD does not allow.

This can probably be reverted if yjit switches to a more secure
mmap design (writable xor executable).  This would involve
initially calling mmap with PROT_READ | PROT_WRITE, and after writing
of executable code has finished, using mprotect to switch to
PROT_READ | PROT_EXEC. I believe Firefox uses this approach for
their Javascript engine since Firefox 46.
2021-10-21 08:26:02 -07:00
Alan Wu 40608d0b7b Fix indentation in ruby.c 2021-10-20 18:19:43 -04:00
Alan Wu 95e337f815 Warn when trying to use YJIT in --disable-jit-support builds 2021-10-20 18:19:43 -04:00
Alan Wu ff863f3818 Show --yjit in help message 2021-10-20 18:19:43 -04:00
Alan Wu 11096da6cc Improve YJIT command line option parsing
Previously, options such as "--yjit123" would enable YJIT. Additionally,
the error message for argument parsing mentioned "--jit-..." instead of
"--yjit-...".
2021-10-20 18:19:43 -04:00
Alan Wu 1f25bba7b7 YJIT_STATS instead of RUBY_DEBUG for --yjit-stats in help printout 2021-10-20 18:19:42 -04:00
Alan Wu d4fae3e390 Say YJIT is disabled by default in ruby --help 2021-10-20 18:19:42 -04:00
Alan Wu d355bf17ba Style fix in ruby.c 2021-10-20 18:19:42 -04:00
Noah Gibbs 21e58acef3 Don't enable YJIT by default. More tests on both Ubuntu and MacOS.
Add RUBY_YJIT_ENABLE env var and YJIT_FORCE_ENABLE compile-time constant.
Rename YJIT_STATS to RUBY_YJIT_STATS.
2021-10-20 18:19:42 -04:00
Noah Gibbs f021b35273 Reduce line length for YJIT option descriptions 2021-10-20 18:19:42 -04:00
Noah Gibbs fab469b678 Document YJIT options in --help 2021-10-20 18:19:42 -04:00
Aaron Patterson afc5db43ca is this right? 2021-10-20 18:19:40 -04:00
Aaron Patterson b78c50d800 Don't check MJIT if it's not enabled 2021-10-20 18:19:40 -04:00
Aaron Patterson 9d5beb6fde Disable YJIT by default if MJIT_FORCE_ENABLE is on
Compile time flag seems pretty forceful, so let MJIT turn on by default
if it is used.
2021-10-20 18:19:40 -04:00
Aaron Patterson ea453acf59 disable MJIT when --enable-all is set 2021-10-20 18:19:40 -04:00
Maxime Chevalier-Boisvert a1d42c37f4 Update ruby.c 2021-10-20 18:19:40 -04:00
Aaron Patterson 234ab816ba Exit if YJIT and MJIT are both enabled
YJIT and MJIT can't be running in the same process otherwise they'll
clobber each other.  We should show an error and exit if they're both
enabled.
2021-10-20 18:19:40 -04:00
Maxime Chevalier-Boisvert 7030cae969 Try running with more YJIT options in CI to surface more bugs 2021-10-20 18:19:36 -04:00
Maxime Chevalier-Boisvert b415ceb92e Increase default YJIT call threshold to 10. Add exec mem size arg. (#52) 2021-10-20 18:19:35 -04:00
Maxime Chevalier-Boisvert 96f4f918b0 Implement greedy versioning. Refactor versioning logic. (#10)
* Implement eager versioning. Refactor versioning logic.

* Add --version-limit and --greedy-versioning command-line args
2021-10-20 18:19:34 -04:00
Jose Narvaez 4e2eb7695e Yet Another Ruby JIT!
Renaming uJIT to YJIT. AKA s/ujit/yjit/g.
2021-10-20 18:19:31 -04:00
Maxime Chevalier-Boisvert 0710bec01e Implement --ujit-call-threshold 2021-10-20 18:19:30 -04:00
Maxime Chevalier-Boisvert a14015e9b5 Report unknown --ujit-* options 2021-10-20 18:19:28 -04:00
Alan Wu b7f93e81df Implement --ujit-stats and instructoin counting
VM and ujit instruction counting in debug builds.

shopify/ruby#19
2021-10-20 18:19:27 -04:00
Maxime Chevalier-Boisvert e4c65ec49c Refactor uJIT code into more files for readability 2021-10-20 18:19:26 -04:00
Alan Wu 726bdd4d35 Show whether MicroJIT is enabled in the version string 2021-10-20 18:19:24 -04:00
Alan Wu a8d784888d Fix mistake in ujit command line parsing 2021-10-20 18:19:24 -04:00
Alan Wu e8c914c250 Implement the --disable-ujit command line option 2021-10-20 18:19:24 -04:00
Nobuyoshi Nakada 842b0008c1 Skip broken strings as the locale encoding 2021-10-01 20:28:44 +09:00
Nobuyoshi Nakada 409dbc951b Replace expanded load path only when modified 2021-10-01 20:28:44 +09:00
Nobuyoshi Nakada b6534691a1 Copy path strings as interned strings 2021-10-01 20:28:44 +09:00
Nobuyoshi Nakada 60d0421ca8 Fix the encoding of loaded feature names [Bug #18191]
The feature names loaded from the default load paths should also
be in the file system encoding.
2021-10-01 20:28:44 +09:00
卜部昌平 f83b14af24 include/ruby/internal/interpreter.h: add doxygen
Must not be a bad idea to improve documents. [ci skip]

In fact many functions declared in the header file are already
documented more or less.  They were just copy & pasted, with applying
some style updates.
2021-09-10 20:00:06 +09:00
S-H-GAMELINKS bdd6d8746f Replace RBOOL macro 2021-09-05 23:01:27 +09:00
Nobuyoshi Nakada 3db7f6353f
Suppress unused-but-set-variable warning 2021-07-06 00:09:27 +09:00
Yusuke Endoh 9438c99590 Rename error_squiggle to error_highlight 2021-06-29 23:45:49 +09:00
Yusuke Endoh e946049665 [WIP] add error_squiggle gem
```
$ ./local/bin/ruby -e '1.time {}'
-e:1:in `<main>': undefined method `time' for 1:Integer (NoMethodError)

1.time {}
 ^^^^^
Did you mean?  times
```

https://bugs.ruby-lang.org/issues/17930
2021-06-29 23:45:49 +09:00
Samuel Williams 45e65f302b Deprecate and rework old (fd) centric functions. 2021-06-22 22:48:57 +12:00
Nobuyoshi Nakada 791d7d4947
Freeze command line script 2021-06-10 15:15:35 +09:00
Benoit Daloze 68d6bd0873 Fix trivial -Wundef warnings
* See [Feature #17752]

Co-authored-by: xtkoba (Tee KOBAYASHI) <xtkoba+ruby@gmail.com>
2021-05-04 14:56:55 +02:00
Nobuyoshi Nakada 1f08b0d18d
Removed dln_a_out
a.out format is considered extinct nowadays.
2021-03-24 20:13:55 +09:00
NARUSE, Yui d58daad37b [Feature #17684] Declare --disable-gems is for debugging 2021-03-17 15:36:05 +09:00
Nobuyoshi Nakada 90c12defb3
Constified variables for getenv 2021-03-12 17:13:53 +09:00
Yusuke Endoh 8ccc12118e Keep libpath length non-negative [Bug #16784]
When runtime_libruby_path does not include '/', it attempts to call
rb_str_resize with negative length. This change makes sure that the
length non-negative.

Co-Authored-By: xtkoba (Tee KOBAYASHI) <xtkoba+ruby@gmail.com>
2021-03-06 00:50:09 +09:00
YO4 (Yoshinao Muramatsu) b94b7965c4
Fixed fallback ENABLE_VIRTUAL_TERMINAL_PROCESSING value [Bug #17639] 2021-02-20 00:50:57 +09:00
Nobuyoshi Nakada d6e43e4723
Moved --verbose, --verbose and --help options to last [ci skip] 2021-01-24 14:59:41 +09:00
Nobuyoshi Nakada 6f6dfdcc68 Make warning values consistent [Bug #17523]
They should be affected, as well as `$VERBOSE`, by `-w`/`-W`
options, not only in the main script but in scripts loaded by `-r`
option too.
2021-01-13 18:12:49 +09:00
Nobuyoshi Nakada dc13bd22bb Ignore failure on unsupported fcntl to drop non-blocking mode
Fixes https://github.com/ruby/ruby/pull/3723
2020-12-26 09:45:06 +09:00
Nobuyoshi Nakada b9d00f42e6
Enable escape sequence on Windows10 console via pager too 2020-12-21 18:12:02 +09:00
Jeremy Evans 05313c914b Use category: :deprecated in warnings that are related to deprecation
Also document that both :deprecated and :experimental are supported
:category option values.

The locations where warnings were marked as deprecation warnings
was previously reviewed by shyouhei.

Comment a couple locations where deprecation warnings should probably
be used but are not currently used because deprecation warning
enablement has not occurred at the time they are called
(RUBY_FREE_MIN, RUBY_HEAP_MIN_SLOTS, -K).

Add assert_deprecated_warn to test assertions.  Use this to simplify
some tests, and fix failing tests after marking some warnings with
deprecated category.
2020-12-18 09:54:11 -08:00
Nobuyoshi Nakada 8b32191a31 Ignore failure on unsupported fcntl to drop non-blocking mode 2020-12-16 17:54:43 +09:00
Jeremy Evans dca13e2bf7 Make ruby -We the same as ruby -W -e
This changes the behavior, which I'm not sure is acceptable.
However, it's odd to allow an option to be combined, but change
the behavior of the option when combined.
2020-12-10 10:16:40 -08:00
Kenta Murata 146b3695c0
ruby.c: remove needless substitution of uenc
uenc has already been initialized the top of the function.
2020-12-08 02:10:03 +09:00
Lars Kanis 94b6933d1c
Set default for Encoding.default_external to UTF-8 on Windows (#2877)
* Use UTF-8 as default for Encoding.default_external on Windows
* Document UTF-8 change on Windows to Encoding.default_external

fix https://bugs.ruby-lang.org/issues/16604
2020-12-08 01:48:37 +09:00
Nobuyoshi Nakada afd765f2ee
Initialize UTF-8 encoding first as it is used always now 2020-11-23 09:45:17 +09:00
Koichi Sasada 99310e3eb5 Some global variables can be accessed from ractors
Some global variables should be used from non-main Ractors.
[Bug #17268]

```ruby
     # ractor-local (derived from created ractor): debug
     '$DEBUG' => $DEBUG,
     '$-d' => $-d,

     # ractor-local (derived from created ractor): verbose
     '$VERBOSE' => $VERBOSE,
     '$-w' => $-w,
     '$-W' => $-W,
     '$-v' => $-v,

     # process-local (readonly): other commandline parameters
     '$-p' => $-p,
     '$-l' => $-l,
     '$-a' => $-a,

     # process-local (readonly): getpid
     '$$'  => $$,

     # thread local: process result
     '$?'  => $?,

     # scope local: match
     '$~'  => $~.inspect,
     '$&'  => $&,
     '$`'  => $`,
     '$\''  => $',
     '$+'  => $+,
     '$1'  => $1,

     # scope local: last line
     '$_' => $_,

     # scope local: last backtrace
     '$@' => $@,
     '$!' => $!,

     # ractor local: stdin, out, err
     '$stdin'  => $stdin.inspect,
     '$stdout' => $stdout.inspect,
     '$stderr' => $stderr.inspect,
```
2020-10-20 15:38:54 +09:00