Commit graph

126 commits

Author SHA1 Message Date
Étienne Barrié
12be40ae6b Implement chilled strings
[Feature #20205]

As a path toward enabling frozen string literals by default in the future,
this commit introduce "chilled strings". From a user perspective chilled
strings pretend to be frozen, but on the first attempt to mutate them,
they lose their frozen status and emit a warning rather than to raise a
`FrozenError`.

Implementation wise, `rb_compile_option_struct.frozen_string_literal` is
no longer a boolean but a tri-state of `enabled/disabled/unset`.

When code is compiled with frozen string literals neither explictly enabled
or disabled, string literals are compiled with a new `putchilledstring`
instruction. This instruction is identical to `putstring` except it marks
the String with the `STR_CHILLED (FL_USER3)` and `FL_FREEZE` flags.

Chilled strings have the `FL_FREEZE` flag as to minimize the need to check
for chilled strings across the codebase, and to improve compatibility with
C extensions.

Notes:
  - `String#freeze`: clears the chilled flag.
  - `String#-@`: acts as if the string was mutable.
  - `String#+@`: acts as if the string was mutable.
  - `String#clone`: copies the chilled flag.

Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
2024-03-19 09:26:49 +01:00
Jean Boussier
b4a69351ec Move FL_SINGLETON to FL_USER1
This frees FL_USER0 on both T_MODULE and T_CLASS.

Note: prior to this, FL_SINGLETON was never set on T_MODULE,
so checking for `FL_SINGLETON` without first checking that
`FL_TYPE` was `T_CLASS` was valid. That's no longer the case.
2024-03-06 13:11:41 -05:00
Alan Wu
7b253cfea4 RJIT: Properly reject keyword splat with yield
See the fix for YJIT.
2024-01-18 20:22:40 -05:00
Takashi Kokubun
e37a37e696 Drop obsoleted BUILTIN_ATTR_NO_GC attribute
The thing that has used this in the past was very buggy, and we've never
revisied it. Let's remove it until we need it again.
2024-01-16 17:27:53 -08:00
Hiroshi SHIBATA
27ead9907d
Typofix under lib and test, tool directories 2023-12-25 11:32:42 +09:00
Takashi Kokubun
f263e44746 RJIT: Avoid retaining unrelated local variables in memory 2023-12-21 23:00:18 -08:00
Takashi Kokubun
f3c82df944 RJIT: Minimize string allocations in InsnCompiler 2023-12-21 21:59:33 -08:00
Takashi Kokubun
9a3c49ee5d RJIT: Convert opt_case_dispatch keys with #to_value
comptime_key is a Ruby object and the value is not valid in machine code.

This PR also implements `CMP r/m64, imm32 (Mod 01: [reg]+disp8)` that is
now needed for running mail.gem benchmark.
2023-12-21 17:47:36 -08:00
Jean Boussier
d898e8d6f8 Refactor rb_shape_transition_shape_capa out
Right now the `rb_shape_get_next` shape caller need to
first check if there is capacity left, and if not call
`rb_shape_transition_shape_capa` before it can call `rb_shape_get_next`.

And on each of these it needs to checks if we got a TOO_COMPLEX
back.

All this logic is duplicated in the interpreter, YJIT and RJIT.

Instead we can have `rb_shape_get_next` do the capacity transition
when needed. The caller can compare the old and new shapes capacity
to know if resizing is needed. It also can check for TOO_COMPLEX
only once.
2023-11-08 11:02:55 +01:00
Jean Boussier
5cc44f48c5 Refactor rb_shape_transition_shape_capa to not accept capacity
This way the groth factor is encapsulated, which allows
rb_shape_transition_shape_capa to be smarter about ideal sizes.
2023-10-10 14:47:54 +02:00
Alan Wu
85aa28e8a6 RJIT: Remove Type::CArray and limit use of Type::CString
See previous similar YJIT commit.
2023-08-28 17:14:33 -04:00
Alan Wu
f302e725e1
Remove __bp__ and speed-up bmethod calls (#8060)
Remove rb_control_frame_t::__bp__ and optimize bmethod calls

This commit removes the __bp__ field from rb_control_frame_t. It was
introduced to help MJIT, but since MJIT was replaced by RJIT, we can use
vm_base_ptr() to compute it from the SP of the previous control frame
instead. Removing the field avoids needing to set it up when pushing new
frames.

Simply removing __bp__ would cause crashes since RJIT and YJIT used a
slightly different stack layout for bmethod calls than the interpreter.
At the moment of the call, the two layouts looked as follows:

                   ┌────────────┐    ┌────────────┐
                   │ frame_base │    │ frame_base │
                   ├────────────┤    ├────────────┤
                   │    ...     │    │    ...     │
                   ├────────────┤    ├────────────┤
                   │    args    │    │    args    │
                   ├────────────┤    └────────────┘<─prev_frame_sp
                   │  receiver  │
    prev_frame_sp─>└────────────┘
                     RJIT & YJIT      interpreter

Essentially, vm_base_ptr() needs to compute the address to frame_base
given prev_frame_sp in the diagrams. The presence of the receiver
created an off-by-one situation.

Make the interpreter use the layout the JITs use for iseq-to-iseq
bmethod calls. Doing so removes unnecessary argument shifting and
vm_exec_core() re-entry from the interpreter, yielding a speed
improvement visible through `benchmark/vm_defined_method.yml`:

     patched:   7578743.1 i/s
      master:   4796596.3 i/s - 1.58x  slower

C-to-iseq bmethod calls now store one more VALUE than before, but that
should have negligible impact on overall performance.

Note that re-entering vm_exec_core() used to be necessary for firing
TracePoint events, but that's no longer the case since
9121e57a5f.

Closes ruby/ruby#6428
2023-07-17 13:57:58 -04:00
Peter Zhu
3223181284 Remove RARRAY_CONST_PTR_TRANSIENT
RARRAY_CONST_PTR now does the same things as RARRAY_CONST_PTR_TRANSIENT.
2023-07-13 14:48:14 -04:00
Alan Wu
296782ab60
YJIT: Fix autosplat miscomp for blocks with optionals (#8006)
* YJIT: Fix autosplat miscomp for blocks with optionals

When passing an array as the sole argument to `yield`, and the yieldee
takes more than 1 optional parameter, the array is expanded similar
to `*array` splat calls. This is called "autosplat" in
`setup_parameters_complex()`.

Previously, YJIT did not detect this autosplat condition. It passed the
array without expanding it, deviating from interpreter behavior.
Detect this conditon and refuse to compile it.

Fixes: Shopify/yjit#313

* RJIT: Fix autosplat miscomp for blocks with optionals

This is mirrors the same issue as YJIT. See previous commit.
2023-07-04 10:45:29 -04:00
Peter Zhu
7577c101ed
Unify length field for embedded and heap strings (#7908)
* Unify length field for embedded and heap strings

The length field is of the same type and position in RString for both
embedded and heap allocated strings, so we can unify it.

* Remove RSTRING_EMBED_LEN
2023-06-06 10:19:20 -04:00
Takashi Kokubun
cbfb5fbb25 RJIT: Fix unspecified_bits with locals 2023-04-26 18:12:53 -07:00
Aaron Patterson
bdffcd6df3 Update RJIT to support newarray_send
This also adds max / hash support
2023-04-18 17:16:22 -07:00
John Hawthorn
be08e1b14c RJIT: argc check in known cfuncs 2023-04-12 17:48:34 -07:00
Takashi Kokubun
65d27d3c0a RJIT: Skip a class guard if known to be T_STRING 2023-04-05 00:46:10 -07:00
Takashi Kokubun
9bef39de74 RJIT: Handle include_all argument of respond_to? 2023-04-05 00:38:38 -07:00
Takashi Kokubun
66fe64b269 RJIT: Remove unused variables 2023-04-04 23:55:19 -07:00
Takashi Kokubun
2ddf6079f1 RJIT: Always use guard_two_fixnums 2023-04-04 23:52:14 -07:00
Takashi Kokubun
4e9c3b4518 RJIT: Eliminate known-result guards for blockarg 2023-04-04 23:42:14 -07:00
Takashi Kokubun
4f77d1cdb8 RJIT: Eliminate known-result branches 2023-04-04 23:30:26 -07:00
Takashi Kokubun
e06bebff5e RJIT: Propagate argument types on method calls 2023-04-04 22:13:25 -07:00
Takashi Kokubun
6d8875b5d7 RJIT: Fix mapping offsets in stack_swap 2023-04-04 22:05:45 -07: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
51b2f4c0f5 RJIT: Fix the argument of shift_stack 2023-04-04 01:17:23 -07:00
Takashi Kokubun
98f0e2c330 RJIT: Fix the argument for defined 2023-04-04 00:41:58 -07:00
Takashi Kokubun
19506650ef RJIT: Add --rjit-verify-ctx option 2023-04-04 00:35:29 -07:00
Takashi Kokubun
2c560b976e RJIT: Fix arguments to SPECIAL_CONST_P 2023-04-04 00:30:57 -07:00
Takashi Kokubun
6a4087702b RJIT: Update type information on setlocal 2023-04-03 22:42:21 -07:00
Takashi Kokubun
6ab86e4626 RJIT: Fix arguments for shift_stack 2023-04-03 21:26:40 -07:00
Takashi Kokubun
3cb5e7558d Fix a test_rubyoptions failure 2023-04-03 08:44:16 -07:00
Takashi Kokubun
46e93ef53d RJIT: Propagate self's type information 2023-04-03 00:49:10 -07:00
Takashi Kokubun
ca8102355a RJIT: Upgrade type on jit_guard_known_class 2023-04-03 00:39:29 -07:00
Takashi Kokubun
1d452c2cf8 RJIT: Upgrade type to Fixnum after guard 2023-04-03 00:02:45 -07:00
Takashi Kokubun
0abe9d8b32 RJIT: Upgrade type to String after guard 2023-04-02 23:54:08 -07:00
Takashi Kokubun
f0b69eb14f RJIT: Upgrade type to Array after guard 2023-04-02 23:49:55 -07:00
Takashi Kokubun
eb51248c4c RJIT: Upgrade type to UnknownHeap after guard 2023-04-02 23:11:18 -07:00
Takashi Kokubun
be4e16bc1a RJIT: Update type information on setn insn 2023-04-02 23:07:58 -07:00
Takashi Kokubun
50285d2864 RJIT: Swap type information on swap insn 2023-04-02 23:06:30 -07:00
Takashi Kokubun
d546f8c518 RJIT: Store type information in Context 2023-04-02 22:32:16 -07:00
Takashi Kokubun
8968b47ba8 RJIT: Refactor getlocal and setlocal 2023-04-02 16:50:54 -07:00
Takashi Kokubun
ad2b719fc2 RJIT: C::FL_TEST_RAW returns RBOOL 2023-04-02 14:32:51 -07:00
Takashi Kokubun
57ee627929 RJIT: Lazily guard block arg
to simplify the implementation
2023-04-02 14:22:42 -07:00
Takashi Kokubun
66f8efc342 RJIT: Simplify cfunc implementation 2023-04-02 13:58:39 -07:00
Takashi Kokubun
284a0ff96c RJIT: Remove an unneeded branch 2023-04-02 12:28:49 -07:00
Takashi Kokubun
3fe134759c Skip assert_linear_performance for RJIT 2023-04-02 12:23:23 -07:00
Takashi Kokubun
bf7587748d RJIT: Simplify invokesuper implementation 2023-04-02 11:42:16 -07:00