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

870 Коммитов

Автор SHA1 Сообщение Дата
Nobuyoshi Nakada 81752d2097
Abort when streaming code from stdin with Prism
Do not read STDIN as a String instance.
2024-02-16 15:26:10 +09:00
Nobuyoshi Nakada a64e93a896
Use ID without cache and fix conversion of offset 2024-02-16 15:26:10 +09:00
Nobuyoshi Nakada e0d068aa9c
Extract `process_options_global_setup` 2024-02-16 15:26:10 +09:00
Nobuyoshi Nakada 839ccad20b
Extract functions depending on `--parser` option 2024-02-16 15:26:09 +09:00
Nobuyoshi Nakada 574312dead Extract `show_help` function 2024-02-16 11:20:29 +09:00
Nobuyoshi Nakada 7ac8d3d6ee Dispose AST before exit by yydebug 2024-02-16 11:20:29 +09:00
Yusuke Endoh 25d74b9527 Do not include a backtick in error messages and backtraces
[Feature #16495]
2024-02-15 18:42:31 +09:00
Kevin Newton 9933377c34 [PRISM] Correctly hook up line numbers for eval 2024-02-14 15:29:26 -05:00
Nobuyoshi Nakada 84d8dbe7a5 Enable redefinition check for rbinc methods 2024-02-12 11:51:06 -08:00
Kevin Newton 4a40364c62 [PRISM] Run opt init before parsing 2024-02-08 14:36:39 -05:00
Kevin Newton 3ecfc3e33e [PRISM] Support the DATA constant 2024-02-08 14:36:29 -05:00
Kevin Newton 71f16d498d Raise errors for dumping prism parse tree 2024-01-31 14:54:39 -05:00
Kevin Newton 610636fd6b [PRISM] Mirror iseq APIs
Before this commit, we were mixing a lot of concerns with the prism
compile between RubyVM::InstructionSequence and the general entry
points to the prism parser/compiler.

This commit makes all of the various prism-related APIs mirror
their corresponding APIs in the existing parser/compiler. This means
we now have the correct frame naming, and it's much easier to follow
where the logic actually flows. Furthermore this consolidates a lot
of the prism initialization, making it easier to see where we could
potentially be raising errors.
2024-01-31 13:41:36 -05:00
Matt Valentine-House 4592fdc545 [Prism] path and script name are not the same
When loading Ruby from a file, or parsing using
RubyVM::InstructionSequence.
2024-01-22 15:15:32 -08:00
Kevin Newton 6bcbb9a02b Make prism respect dump_without_opt 2024-01-22 10:18:41 -05:00
Nobuyoshi Nakada 6215b5ba98 Fix off-by-one error of argc
Fix ruby/ruby#9562
2024-01-17 18:26:39 +09:00
Nobuyoshi Nakada 9ba2558b76 Fix possible out-of-bounds access 2024-01-13 23:20:05 +09:00
Takashi Kokubun 64c52cd1c2 RJIT: Add --rjit-trace to allow TracePoint during JIT 2023-12-21 21:05:13 -08:00
HParker 7ef90b3978 Correct free_on_exit env var to free_at_exit 2023-12-20 14:36:32 +09:00
Aaron Patterson df0bfde2b2 We need to load builtins so that they work
Before this commit no methods defined in Ruby were being loaded. For
example `class` or `tap` methods would not exist.

[ruby-core:115793] [Bug #20073]
2023-12-19 08:53:52 -08:00
Matt Valentine-House 893fe30ef2 [PRISM] Fix crash when --parser=prism called with stdin
[Bug #20071]

Currently Ruby crashes when the --parser=prism flag is used either with
no input, or with input that is being redirected from stdin. So all of
the following will crash

ruby --parser=prism
ruby --parser=prism < test_code.rb
cat test_code.rb | ruby --parser=prism

This commit checks whether the input is assumed to be from stdin, and
then processes that as a file.

This will fix the second and third case above, but will cause a slight
behavioural changes for the first case - Ruby will treat stdin as an
empty file in this case and exit, rather than waiting for data to be
piped into stdin.
2023-12-18 19:44:44 +00:00
Nobuyoshi Nakada 2f595c744e
Adjust styles [ci skip] 2023-12-17 00:21:00 +09:00
Adam Hess a604fe4262 update message to clarify compiler, not parser
Co-authored-by: Ufuk Kayserilioglu <ufuk@paralaus.com>
2023-12-15 13:42:19 -05:00
HParker 55326a915f Introduce --parser runtime flag
Introduce runtime flag for specifying the parser,

```
ruby --parser=prism
```

also update the description:

```
$ ruby --parser=prism --version
ruby 3.3.0dev (2023-12-08T04:47:14Z add-parser-runtime.. 0616384c9f) +PRISM [x86_64-darwin23]
```

[Bug #20044]
2023-12-15 13:42:19 -05:00
Takashi Kokubun e282d7b880 Avoid warning --jit when only YJIT is enabled 2023-12-13 00:05:12 -08:00
Adam Hess 6816e8efcf Free everything at shutdown
when the RUBY_FREE_ON_SHUTDOWN environment variable is set, manually free memory at shutdown.

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2023-12-07 15:52:35 -05:00
HParker b8b319dd1a Revert "allow enabling Prism via flag or env var"
This reverts commit 9b76c7fc89.
2023-12-06 10:21:12 +09:00
Nobuyoshi Nakada c146da50bd
Adjust styles [ci skip] 2023-12-06 09:43:10 +09:00
HParker 9b76c7fc89 allow enabling Prism via flag or env var
Enable Prism using either --prism

    ruby --prism test.rb

or via env var

    RUBY_PRISM=1 ruby test.rb
2023-12-05 12:17:14 -05:00
Nobuyoshi Nakada 2e8a4470ae
Remove `rb_libruby_selfpath` for MJIT 2023-12-04 10:32:21 +09:00
Kevin Newton ec86b2eb39
[prism] Update to use new options APIs 2023-11-03 10:13:50 -04:00
Takashi Kokubun ad4f973ecd
YJIT: Always define method codegen table at boot (#8807) 2023-11-02 09:15:48 -07:00
Kevin Newton 55b81e419f
Use new prism prettyprint APIs 2023-10-26 15:23:46 -04:00
Jemma Issroff 2573d56884 [PRISM] Change --dump keyword to prism_parsetree 2023-10-26 13:29:04 -03:00
Jemma Issroff 8f71a5c530 [PRISM] Move scope_node itself to CRuby, create prism_compile.h 2023-10-25 18:18:35 -03:00
Takashi Kokubun 6beb09c2c9
YJIT: Add RubyVM::YJIT.enable (#8705) 2023-10-19 10:54:35 -07:00
Koichi Sasada c9990c8d0f "+MN" in description
If `RUBY_MN_THREADS=1` is given, this patch shows `+MN` in
`RUBY_DESCRIPTION` like:

```
$ RUBY_MN_THREADS=1 ./miniruby  --yjit -v
ruby 3.3.0dev (2023-10-17T04:10:14Z master 908f8fffa2) +YJIT +MN [x86_64-linux]
```

Before this patch, a warning is displayed if `$VERBOSE` is given.
However it can make troubles with tests (with `$VERBOSE`), do not
show any warning with a MN threads configuration.
2023-10-17 17:43:52 +09:00
Jemma Issroff d705885286
[PRISM] Add --dump=prism mode (#8643) 2023-10-13 12:24:40 -07:00
Koichi Sasada be1bbd5b7d M:N thread scheduler for Ractors
This patch introduce M:N thread scheduler for Ractor system.

In general, M:N thread scheduler employs N native threads (OS threads)
to manage M user-level threads (Ruby threads in this case).
On the Ruby interpreter, 1 native thread is provided for 1 Ractor
and all Ruby threads are managed by the native thread.

From Ruby 1.9, the interpreter uses 1:1 thread scheduler which means
1 Ruby thread has 1 native thread. M:N scheduler change this strategy.

Because of compatibility issue (and stableness issue of the implementation)
main Ractor doesn't use M:N scheduler on default. On the other words,
threads on the main Ractor will be managed with 1:1 thread scheduler.

There are additional settings by environment variables:

`RUBY_MN_THREADS=1` enables M:N thread scheduler on the main ractor.
Note that non-main ractors use the M:N scheduler without this
configuration. With this configuration, single ractor applications
run threads on M:1 thread scheduler (green threads, user-level threads).

`RUBY_MAX_CPU=n` specifies maximum number of native threads for
M:N scheduler (default: 8).

This patch will be reverted soon if non-easy issues are found.

[Bug #19842]
2023-10-12 14:47:01 +09:00
Takashi Kokubun 7db6f448ed Use a better variable name for w 2023-10-04 10:25:46 -07:00
Takashi Kokubun 577ff858bc Make the function names consistent 2023-10-04 10:25:46 -07:00
Takashi Kokubun 01c462ce6a YJIT: Move help descriptions to options.rs 2023-10-04 10:25:46 -07:00
Nobuyoshi Nakada 49d27435d0 Split `show_usage_line` and add `ruby_show_usage_line` 2023-10-04 10:25:46 -07:00
Nobuyoshi Nakada 582369bb4b Remove magic numbers from `show_usage_line` 2023-10-04 10:25:46 -07:00
Maxime Chevalier-Boisvert ea491802fa
YJIT: add heuristic to avoid compiling cold ISEQs (#8522)
* YJIT: Add counter to measure how often we compile "cold" ISEQs (#535)

Fix counter name in DEFAULT_COUNTERS

YJIT: add --yjit-cold-threshold, don't compile cold ISEQs

YJIT: increase default cold threshold to 200_000

Remove rb_yjit_call_threshold()

Remove conflict markers

Fix compilation errors

Threshold 1 should compile immediately

Debug deadlock issue with test_ractor

Fix call threshold issue with tests

* Revert exception threshold logic. Document option in yjid.md

* (void) for 0 parameter functions in C99

* Rename iseq_entry_cold => cold_iseq_entry

* Document --yjit-cold-threshold in ruby.c

* Update doc/yjit/yjit.md

Co-authored-by: Jean byroot Boussier <jean.boussier+github@shopify.com>

* Shorten help string to appease test

* Address bug found by Kokubun. Reorder logic.

---------

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
Co-authored-by: Jean byroot Boussier <jean.boussier+github@shopify.com>
2023-10-03 17:45:46 -04:00
Nobuyoshi Nakada bab01d284c [Feature #19790] Rename BUGREPORT_PATH as CRASH_REPORT 2023-09-25 22:57:28 +09:00
Nobuyoshi Nakada f714448be7 Honor the same option given later 2023-09-25 22:57:28 +09:00
Nobuyoshi Nakada 70e8a08295 Add `--bugreport-path` option
It has precedence over the environment variable `RUBY_BUGREPORT_PATH`.
2023-09-25 22:57:28 +09:00
Nobuyoshi Nakada 530b5ef6b6 Test bug_report 2023-09-25 22:57:28 +09:00
Nobuyoshi Nakada c87f2a4f15
[Bug #19887] RUBYOPT should work without leading `-` 2023-09-18 10:14:46 +09:00
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