Commit graph

84048 commits

Author SHA1 Message Date
Kevin Newton
f7adee34a3 [ruby/prism] Only define xallocator when not defined
919d682379
2024-03-04 16:49:14 +00:00
Benoit Daloze
6ad0f89d5a [ruby/prism] Use a more efficient StringIO on TruffleRuby
* The stdlib StringIO is synchronized and this occurs a high overhead.
* This is about twice as fast on TruffleRuby but surprisingly it is slower on JRuby.
  I am not sure why but probably @ivar access and integer arithmetic
  is much slower than Java field access/arithmetic on JRuby.
* On CRuby interpreter it is slower, which is expected as the GVL already protects StringIO.
* So we enable this only on TruffleRuby to not slow down other Rubies.
* PRISM_FFI_BACKEND=true ruby -v -Ilib -rprism -rbenchmark -e '300.times { p Benchmark.realtime { Dir.glob("lib/**/*.rb") { |f| Prism.parse_file(f) } } }'
  ruby 3.3.0:         0.215 => 0.251 (cext: 0.062)
  ruby 3.3.0 YJIT:    0.118 => 0.113 (cext: 0.053)
  truffleruby JVM:    0.101 => 0.054
  jruby 9.4.6.0:      0.162 => 0.219
  jruby 9.4.6.0 indy: 0.078 => 0.086
* For the record here are the numbers for using the String directly, without a StringIO-like object:
  ruby 3.3.0:         0.215 => 0.234 (cext: 0.062)
  ruby 3.3.0 YJIT:    0.118 => 0.111 (cext: 0.053)
  truffleruby native: 0.101 => 0.053
  jruby 9.4.6.0:      0.162 => 0.195
  jruby 9.4.6.0 indy: 0.078 => 0.082
  As we can see, that extra object adds a non-trivial overhead on CRuby interpreter and JRuby.
  But we need to make it possible to use StringIO and SimpleStringIO interchangeably.

938677cbd2
2024-03-04 16:41:16 +00:00
Kevin Newton
03a73fdc3d [ruby/prism] Add then keyword loc to when nodes
e1e613df16
2024-03-04 16:40:37 +00:00
Kevin Newton
c0a34a6c8c [ruby/prism] Document xallocator functions
ee1a4acacd
2024-03-04 16:40:24 +00:00
HASUMI Hitoshi
b95e2cdca7 [ruby/prism] Additional fix of adding x prefix after rebase with main branch
08733438bd
2024-03-04 16:40:24 +00:00
HASUMI Hitoshi
54f27549e2 [ruby/prism] Chage some names
- PRISM_CUSTOM_ALLOCATOR -> PRISM_XALLOCATOR
- prism_custom_allocator.h -> prism_xallocator.h

83b4071e5b
2024-03-04 16:40:23 +00:00
HASUMI Hitoshi
c4bd6da298 [ruby/prism] Make alloc interface replaceable
- Add `x` prefix to malloc, calloc, realloc, and free
  (eg: malloc -> xmalloc)
- By default, they are replaced with stdlib's functions at build
- You can use custom functions by defining `PRISM_CUSTOM_ALLOCATOR` macro

7a878af619
2024-03-04 16:40:23 +00:00
Lazarus Lazaridis
61ea202f8b
[DOC] Fix invalid documentation for reachable_objects_from (#10172)
Previous documentation is stating the opposite (that the method won't
work for CRuby).
2024-03-05 01:35:51 +09:00
Kevin Newton
85fe8b6b9c [ruby/prism] Update lib/prism/translation/parser/compiler.rb
dccfd83bc4
2024-03-04 16:26:47 +00:00
Koichi ITO
a03f92923b [ruby/prism] Fix incompatibility AST for regexp match in Prism::Translation::Parser
This PR fixes the following incompatibility AST for regexp match between Parser gem and Prism:

## Parser gem

Returns an `match_with_lvasgn` node:

```console
$ bundle exec ruby -rparser/ruby33 -ve 'p Parser::Ruby33.parse("/foo/ =~ bar")'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
s(:match_with_lvasgn,
  s(:regexp,
    s(:str, "foo"),
    s(:regopt)),
  s(:send, nil, :bar))
```

## Prism (`Prism::Translation::Parser`)

### Before

Returns an `send` node:

```console
$ bundle exec ruby -rprism -rprism/translation/parser33 -ve 'p Prism::Translation::Parser33.parse("/foo/ =~ bar")'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
s(:send,
  s(:regexp,
    s(:str, "foo"),
    s(:regopt)), :=~,
  s(:send, nil, :bar))
```

### After

Returns an `match_with_lvasgn` node:

```console
$ bundle exec ruby -rprism -rprism/translation/parser33 -ve 'p Prism::Translation::Parser33.parse("/foo/ =~ bar")'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
s(:match_with_lvasgn,
  s(:regexp,
    s(:str, "foo"),
    s(:regopt)),
  s(:send, nil, :bar))
```

## Background

Found due to incompatibility with RuboCop's `Performance/EndWith`, `Performance/StringInclude,
and `Performance/StartWith` cops.

## Note

This is the incompatibility when the receiver is a regular expression literal and `=~` is used.
Based on the node name `:match_with_lvasgn`, it appears that Prism's AST becomes more accurate
in cases like `visit_match_write_node` only.

However, as shown in the background, the current behavior of Parser gem is not like this.
Considering compatibility with the published AST of Parser gem, the AST incompatibility will be addressed.

This lvar-injecting feature appears to have not been supported by Parser gem for a long time:
https://github.com/whitequark/parser/issues/69#issuecomment-19506391

There seems to be no indication that it will be supported.

This PR prioritizes AST compatibility between the Parser gem and Prism.
However, it is unclear whether this is the best approach.

dff4abb170
2024-03-04 16:26:46 +00:00
Kevin Newton
26507b92e0 [ruby/prism] Include BSDmakefile
1fe507fe3d
2024-03-04 16:26:36 +00:00
Kevin Newton
5856ea3fd1 [ruby/prism] Fix up some minor parser incompatibilities
c6c771d1fa
2024-03-04 14:39:52 +00:00
Nobuyoshi Nakada
2c787bf90f
Run POSTLINK for rubyspec CAPIEXT objects 2024-03-04 23:25:51 +09:00
Nobuyoshi Nakada
b176315827
[Bug #20324] Uncomparable ranges are not overlapping 2024-03-04 21:02:08 +09:00
Yuta Saito
ef5af32799 [rubygems/rubygems] Clear RUBY_CODESIGN env var while running tests
The `RUBY_CODESIGN` environment variable is used by mkmf-generated
Makefile to sign extension bundles on macOS. The variable specifies a
key identifier to use for signing given by the user. However, the key
is usually stored in `$HOME/Library/Keychains` directory, and the test
suite creates a fake `$HOME` directory. This causes the test suite to
try to find the specified key from the fake home directory, which
results in a failure.

ddcfc65bf7
2024-03-04 06:36:29 +00:00
S-H-GAMELINKS
2d8788e90c Support NODE_ONCE for pattern matching 2024-03-04 12:33:00 +09:00
KJ Tsanaktsidis
5621d794a2 Disable callcc when ASAN is enabled
callcc's implementation is fundamentally incompatible with ASAN. Since
callcc is deprecated and almost never used, it's probably OK to disable
callcc when ruby is compiled with ASAN.

[Bug #20273]
2024-03-04 13:07:26 +11:00
Yuta Saito
0d9a681eff enc: Expand substitution variables in Makefile.in by default
This change makes `make_encmake.rb` expand all substitution variables
when replacing them in `enc/Makefile.in` to avoid propagating all
possibly referenced variables to the generated Makefile. The old
behavior, which don't expand make variables when generating Makefile,
was useful to temporarily override inherited variables like `cflags` in
`CFLAGS` at make-time. However, it's not a common use case and it
requires to propagate all possibly referenced variables properly
considering key name duplication between `enc/Makefile.in` and
`RbConfig::CONFIG`.
2024-03-04 00:57:57 +09:00
Yuta Saito
072761bb3f enc: Define missing POSTLINK variable in enc.mk
This is a follow up change to 71d511615b
2024-03-04 00:57:57 +09:00
Thomas Marshall
7e4b1f8e19
[Bug #20322] Fix rb_enc_interned_str_cstr null encoding
The documentation for `rb_enc_interned_str_cstr` notes that `enc` can be
a null pointer, but this currently causes a segmentation fault when
trying to autoload the encoding. This commit fixes the issue by checking
for NULL before calling `rb_enc_autoload`.
2024-03-03 10:43:35 +00:00
Nobuyoshi Nakada
93556d4620 [ruby/etc] Drop support for old ERB
11677318ac
2024-03-02 16:40:16 +00:00
Nobuyoshi Nakada
e9a7801a93
Drop support for old ERB 2024-03-03 00:55:45 +09:00
Yuta Saito
71d511615b mkmf.rb: Define missing POSTLINK variable in generated Makefile
The `POSTLINK` variable had been used in the `LINK_SO` variable, which
is used to link shared extension libraries. However, the `POSTLINK`
variable had not been defined in the generated Makefile, so extension
libraries were not properly post-processed. It was not a critical issue
for the existing `POSTLINK` usage for darwin platforms, but it would be
a problem for Wasm/WASI platform, which requires *mandatory*
post-processing for shared extension libraries.
2024-03-02 17:07:37 +09:00
Yuta Saito
b000e7bb74 configure.ac: Append POSTLINK to LINK_SO for all platforms
The `POSTLINK` variable had been used only for darwin platforms, but
it's now used for WebAssembly/WASI as well. To make shared extension
libraries properly post-processed, we need to append `POSTLINK` to
`LINK_SO` but it was done only for darwin platforms. This commit
generalizes the appending to all platforms.
2024-03-02 17:07:37 +09:00
Nobuyoshi Nakada
5a4cd732f0
Make File#chown unblocking 2024-03-02 14:37:57 +09:00
Nobuyoshi Nakada
061c684084
Make File#chmod unblocking 2024-03-02 14:37:53 +09:00
Takashi Kokubun
607b86ed1f Update a stubbed type for RJIT
cfunc.func is actually used by RJIT
2024-03-01 15:10:26 -08:00
Takashi Kokubun
317163c79c Update bindgen for YJIT and RJIT 2024-03-01 15:07:41 -08:00
Takashi Kokubun
61fbd29e14 Skip a redundant check for the rb_obj_hash case
Also, refactor the cfunc struct to use a new rb_cfunc_t.
2024-03-01 15:02:28 -08:00
Peter Zhu
5a3ae06a09 Remove dead function rb_obj_rgengc_writebarrier_protected_p 2024-03-01 15:41:16 -05:00
Jeremy Evans
99384bac28 Correctly set anon_kwrest flag for def f(b: 1, **)
In cases where a method accepts both keywords and an anonymous
keyword splat, the method was not marked as taking an anonymous
keyword splat.  Fix that in the compiler.

Doing that broke handling of nil keyword splats in yjit, so
update yjit to handle that.

Add a test to check that calling a method that accepts both
a keyword argument and an anonymous keyword splat does not
modify a passed keyword splat hash.

Move the anon_kwrest check from setup_parameters_complex to
ignore_keyword_hash_p, and only use it if the keyword hash
is already a hash. This should speed things up slightly as
it avoids a check previously used for all callers of
setup_parameters_complex.

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2024-03-01 12:36:19 -08:00
Peter Zhu
6da8f04e01 [ruby/irb] Escape closing square brackets in regexp
Fixes the following warning:

    test/irb/test_command.rb:546: warning: regular expression has ']' without escape

7efadc243b
2024-03-01 19:57:11 +00:00
Takashi Kokubun
70de3b170b
Optimize Hash methods with Kernel#hash (#10160) 2024-03-01 11:16:31 -08:00
Peter Zhu
6f31dd495c Don't check_rvalue_consistency in is_markable_object
is_markable_object is called by rb_objspace_markable_object_p, which
may pass a T_NONE object. check_rvalue_consistency will fail if a T_NONE
object is passed in.
2024-03-01 13:38:49 -05:00
Takashi Kokubun
661f9e6d03
YJIT: Support opt_invokebuiltin_delegate for leaf builtin (#10152) 2024-03-01 13:03:00 -05:00
Alan Wu
88050ec179 YJIT: No need to set cfp->sp when setting escaped locals
While writing to the env object can add it to the remember set,
it shouldn't trigger a GC run.
2024-03-01 12:54:34 -05:00
Stan Lo
57ca5960ad [ruby/irb] Restructure workspace management
(https://github.com/ruby/irb/pull/888)

* Remove dead irb_level method

* Restructure workspace management

Currently, workspace is an attribute of IRB::Context in most use cases.
But when some workspace commands are used, like `pushws` or `popws`, a
workspace will be created and used along side with the original workspace
attribute.

This complexity is not necessary and will prevent us from expanding
multi-workspace support in the future.

So this commit introduces a @workspace_stack ivar to IRB::Context so IRB
can have a more natural way to manage workspaces.

* Fix pushws without args

* Always display workspace stack after related commands are used

61560b99b3
2024-03-01 15:51:29 +00:00
Peter Zhu
162e13c884 Remove pointer check in vm_ccs_free
We don't need to check that the object is pointer to the GC heap in
vm_ccs_free because it is called during sweeping, which does not free
pages so it can never point to an object that is not on the GC heap.
2024-03-01 10:39:51 -05:00
Jean Boussier
f3af5ae7e6 Make Struct memory leak test faster
[Bug #20311]

It times out on some platform, so we can reduce iterations.
On my machine it completes in 250ms and RSS grows 8X.
2024-03-01 16:33:09 +01:00
Jeremy Evans
334e4c65b3 Fix a couple issues noticed by nobu
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2024-03-01 07:10:25 -08:00
Jeremy Evans
f446d68ba6 Add benchmarks for super and zsuper calls of different types
These show gains from the recent optimization commits:

```
                        arg_splat
            miniruby:   7346039.9 i/s
     miniruby-before:   4692240.8 i/s - 1.57x  slower

                  arg_splat_block
            miniruby:   6539749.6 i/s
     miniruby-before:   4358063.6 i/s - 1.50x  slower

                   splat_kw_splat
            miniruby:   5433641.5 i/s
     miniruby-before:   3851048.6 i/s - 1.41x  slower

             splat_kw_splat_block
            miniruby:   4916137.1 i/s
     miniruby-before:   3477090.1 i/s - 1.41x  slower

                   splat_kw_block
            miniruby:   2912829.5 i/s
     miniruby-before:   2465611.7 i/s - 1.18x  slower

                   arg_splat_post
            miniruby:   2195208.2 i/s
     miniruby-before:   1860204.3 i/s - 1.18x  slower
```

zsuper only speeds up in the post argument case, because
it was already set to use splatarray false in cases where
there were no post arguments.
2024-03-01 07:10:25 -08:00
Jeremy Evans
73371450c3 Avoid 1-2 array allocations for zsuper calls with post arguments
These previously resulted in 2 array allocations, one for newarray
and one for concatarray.  This replaces newarray and concatarray
with pushtoarray, and changes splatarray false to splatarray true,
which reduces it to 1 array allocation, in splatarray true.

This also sets VM_CALL_ARGS_SPLAT_MUT, so if the super method
accepts a positional splat, this will avoid an additional array
allocation on the callee side.
2024-03-01 07:10:25 -08:00
Jeremy Evans
32c58753af Fix splatarray false peephole optimization for f(*ary, **kw, &block)
This optimization stopped being using when the splatkw VM instruction
was added.  This change allows the optimization to apply again. This
also optimizes the following cases:

  super(*ary, **kw, &block)
  f(...)
  super(...)
2024-03-01 07:10:25 -08:00
Jeremy Evans
e484ffaf20 Perform splatarray false peephole optimization for invokesuper in addition to send
This optimizes cases such as:

  super(arg, *ary)
  super(arg, *ary, &block)
  super(*ary, **kw)
  super(*ary, kw: 1)
  super(*ary, kw: 1, &block)

The super(*ary, **kw, &block) case does not use the splatarray false
optimization.  This is also true of the send case, since the
introduction of the splatkw VM instruction.  That will be fixed in
a later commit.
2024-03-01 07:10:25 -08:00
Jun Aruga
54d26221b4 .travis.yml: Allow failures for ppc64le and s390x.
Because Travis ppc64le/s390x are unstable.

ppc64le:
* 269211469
* 269204073

s390x:
* 269201221
2024-03-01 13:14:16 +01:00
Jean Boussier
c09e5ad17d Clarify C API documentation about pinned classes
They are not only pinned, but also immortal. Even if the
constant referencing them is removed, they will remain alive.

It's a precision worth noting.
2024-03-01 08:24:16 +01:00
Jean Boussier
e626da82ea Don't pin named structs defined in Ruby
[Bug #20311]

`rb_define_class_under` assumes it's called from C and that the
reference might be held in a C global variable, so it adds the
class to the VM root.

In the case of `Struct.new('Name')` it's wasteful and make
the struct immortal.
2024-03-01 08:23:38 +01:00
Nobuyoshi Nakada
5d76fe6b2a [ruby/optparse] Invoke pager for --help
77dccce37c
2024-03-01 07:10:08 +00:00
Nobuyoshi Nakada
9b75e5f085
Add an example for fallback to sh 2024-03-01 13:56:52 +09:00
Nobuyoshi Nakada
5baee82c76
[DOC] Mention about executable file and fallback to sh 2024-03-01 13:11:29 +09:00