665 Commits

Author SHA1 Message Date
卜部昌平
60cf8598b2 [nit] refactor rename inline functions
Pretty sure commit 0f64da9672d88921439f6fdb306d16fece9b9c90 didn't
intend to welcome extension libraries to use these functions.
2026-01-13 11:53:43 +09:00
Burdette Lamar
58fb95af36
[DOC] Harmonize #== methods (#15805) 2026-01-06 17:13:15 -05:00
Nobuyoshi Nakada
0f64da9672
Make rb_check_typeddata and rbimpl_check_typeddata identical 2025-12-29 18:40:47 +09:00
Jeremy Evans
76fb0d244b Use actual class instead of singleton class in frozen error message
With the following code:

```ruby
object = []
object.singleton_class
object.freeze
object.instance_variable_set(:@a, 42)
```

The previous error message was:

```
can't modify frozen #<Class:#<Array:0x00000631d1308f78>>: []
```

With this change, the error message is:

```
can't modify frozen Array: []
```

Since we show the inspect value of the affected object, I think
including the singleton class instead of the actual class if it
exists makes the error message harder to understand.
2025-12-10 07:35:50 +09:00
Nobuyoshi Nakada
7840ef2f43
Win32: Allow some mingw implemeations to use old msvcrt 2025-11-19 22:51:09 +09:00
Nobuyoshi Nakada
cdb9893c55 Win32: Drop support for older than MSVC 8.0/_MSC_VER 1400
Visual C++ 2005 (8.0):
- _MSC_VER: 1400
- MSVCRT_VERSION: 80
2025-11-19 11:03:42 +09:00
Étienne Barrié
79b2685675 [DOC] Fix typos
Inspired by 42ba82424d908c290a4a34ced8853f0a403b734b, I looked for other
occurrences of "the the".
2025-10-13 15:21:36 -04:00
Nobuyoshi Nakada
2bb6fe3854
[Bug #21629] Initialize struct RString 2025-10-08 18:19:47 +09:00
Luke Gruber
d869164124 rb_bug shouldn't assume ec is available (don't use GET_EC())
ec is unavailable on timer thread, for instance.
2025-09-24 10:41:04 -07:00
Jean Boussier
bc9781c264 Convert name_err_mesg to use rb_gc_mark_and_move
The `p->field = rb_gc_location(p->field)` isn't ideal because it means all
references are rewritten on compaction, regardless of whether the referenced
object has moved. This isn't good for caches nor for Copy-on-Write.

`rb_gc_mark_and_move` avoid needless writes, and most of the time allow to
have a single function for both marking and updating references.
2025-08-07 21:00:00 +02:00
ydah
3d8af5df11 Fix typo in documentation comment for exc_inspect method in error.c 2025-08-05 21:58:12 +09:00
Nobuyoshi Nakada
6179cc0118
[DOC] Fill undocumented documents 2025-08-04 02:23:43 +09:00
Nobuyoshi Nakada
c218862d3c
Fix style [ci skip] 2025-04-19 22:02:10 +09:00
Nobuyoshi Nakada
022ab41374 [DOC] Improve Errno and SystemCallError.new 2025-01-31 21:30:07 +09:00
Nobuyoshi Nakada
e433e6515e
[DOC] Exclude 'Class' and 'Module' from RDoc's autolinking 2025-01-02 12:36:06 +09:00
Victor Shepelev
58460b4dbd
[DOC] Adjust documentation related to backtraces (#12420) 2024-12-24 20:49:55 +02:00
zverok
3808d29e20 Fix extra 'warning:' prefix for chilled Symbol#to_s 2024-12-22 15:08:19 +09:00
Stan Lo
2a44a57e14 [DOC] Link to special fatal class through rdoc-ref 2024-12-19 14:15:23 -08:00
Takashi Kokubun
923f831804 Suppress -Wsuggest-attribute=format 2024-12-15 23:27:43 -08:00
Stan Lo
ff8570b005 Fix LoadError's linking issue
Original issue: https://github.com/ruby/rdoc/issues/1128

The problem is caused by the `# :stopdoc:` directive in `bundled_gems.rb`,
which's scope covers the redefinition of `LoadError`.

Since the goal of `# :stopdoc:` is to hide the documentation of `Gem::BUNDLED_GEMS`,
we can use `# :nodoc:` on it instead.
2024-12-12 16:43:25 -05:00
Peter Zhu
ca2d19d4e5 Implement rb_bug_without_die 2024-12-12 14:07:56 -05:00
Nobuyoshi Nakada
267ecf5f02 Add rb_warn_reserved_name_at 2024-12-12 17:45:06 +09:00
Peter Zhu
14ce2443db Make rb_bug_without_die static
It's not used outside of error.c.
2024-11-27 11:32:58 -05:00
Jean Boussier
cedcf2d681 error.c: call va_end before jumping
The man page is clear that every `va_start` call MUST be succeeded by
the corresponding `va_end` call.

So `rb_raise` can't call `rb_exc_raise` before `va_end`, otherwise
`va_end` is never called.

Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>
2024-11-25 18:18:39 +01:00
Jean byroot Boussier
6deeec5d45
Mark strings returned by Symbol#to_s as chilled (#12065)
* Use FL_USER0 for ELTS_SHARED

This makes space in RString for two bits for chilled strings.

* Mark strings returned by `Symbol#to_s` as chilled

[Feature #20350]

`STR_CHILLED` now spans on two user flags. If one bit is set it
marks a chilled string literal, if it's the other it marks a
`Symbol#to_s` chilled string.

Since it's not possible, and doesn't make much sense to include
debug info when `--debug-frozen-string-literal` is set, we can't
include allocation source, but we can safely include the symbol
name in the warning message, making it much easier to find the source
of the issue.

Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>

---------

Co-authored-by: Étienne Barrié <etienne.barrie@gmail.com>
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2024-11-13 09:20:00 -05:00
Alan Wu
fca07d73e3
Respect RUBY_CRASH_REPORT path when RUBY_ASSERT() fails
Previously, it always used stderr. Slight shuffle of the first line
of the crash due to reusing code from rb_bug():

```diff
-Assertion Failed: /ruby/object.c:649:rb_obj_itself:false
+/ruby/object.c:649: Assertion Failed: rb_obj_itself:false
```

Tested locally to confirm that it writes to the file given with
RUBY_CRASH_REPORT. Follow-up for [Feature #19790].
2024-11-07 09:35:19 -05:00
Koichi Sasada
ab7ab9e450 Warning[:strict_unused_block]
to show unused block warning strictly.

```ruby
class C
  def f = nil
end

class D
  def f = yield
end

[C.new, D.new].each{|obj| obj.f{}}
```

In this case, `D#f` accepts a block. However `C#f` doesn't
accept a block. There are some cases passing a block with
`obj.f{}` where `obj` is `C` or `D`. To avoid warnings on
such cases, "unused block warning" will be warned only if
there is not same name which accepts a block.
On the above example, `C.new.f{}` doesn't show any warnings
because there is a same name `D#f` which accepts a block.

We call this default behavior as "relax mode".

`strict_unused_block` new warning category changes from
"relax mode" to "strict mode", we don't check same name
methods and `C.new.f{}` will be warned.

[Feature #15554]
2024-11-06 11:06:18 +09:00
Étienne Barrié
257f78fb67 Show where mutated chilled strings were allocated
[Feature #20205]

The warning now suggests running with --debug-frozen-string-literal:

```
test.rb:3: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information)
```

When using --debug-frozen-string-literal, the location where the string
was created is shown:

```
test.rb:3: warning: literal string will be frozen in the future
test.rb:1: info: the string was created here
```

When resurrecting strings and debug mode is not enabled, the overhead is a simple FL_TEST_RAW.
When mutating chilled strings and deprecation warnings are not enabled,
the overhead is a simple warning category enabled check.

Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
2024-10-21 12:33:02 +02:00
John Bampton
3fc1495c30 Fix spelling 2024-10-09 07:14:44 +09:00
David Rodríguez
1172d65926
[DOC] Improve description of LoadError#path and SyntaxError#path 2024-09-27 01:00:34 +09:00
masatoshi_moritsuka
6b46060fc2 doc: Remove description of experimental warnings related pattern matching from documentation
Ruby 3.2.0 has been released and all experimental warnings about pattern matching have been removed.
Experimental warnings about pattern matching are no longer output, so I remove description about it from documentation as well.

cf. https://bugs.ruby-lang.org/issues/18585
cf. db6b23c76cbc7888cd9a9912790c2068703afdd0
cf. https://twitter.com/k_tsj/status/1606956336037900289?s=20&t=-_PSYLhYPtYsB9FZhtXl5A
2024-09-25 07:06:42 +09:00
Alan Wu
8cf708d7b4 Make rb_check_frozen_inline() static inline again
Since 730e3b2ce01915c4a98b79bb281b2c38a9ff1131
("Stop exposing `rb_str_chilled_p`"), we noticed a speed loss on a few
benchmarks that are string operations heavy. This is partially due to
routines no longer having the options to inline rb_check_frozen_inline()
in non-LTO builds. Make it an inlining candidate again to recover speed.

Testing this patch on my machine, the fannkuchredux benchmark gets a
1.15 speed-up with YJIT and 1.03 without YJIT.
2024-07-19 17:47:12 -04:00
Burdette Lamar
43d7db3828
[DOC] Doc for exceptions (#11008) 2024-06-26 13:31:40 -04:00
Nobuyoshi Nakada
bed34b3a52
Show the detail info in the first line 2024-06-25 11:50:03 +09:00
Aaron Patterson
1271ff72d5 Don't call Warning.warn unless the category is enabled
The warning category should be enabled if we want to call
`Warning.warn`.

This commit speeds up the following benchmark:

```ruby
eval "def test; " +
  1000.times.map { "'  '.chomp!" }.join(";") + "; end"

def run_benchmark count
  i = 0
  while i < count
    start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
    yield
    ms = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
    puts "itr ##{i}: #{(ms * 1000).to_i}ms"
    i += 1
  end
end

run_benchmark(25) do
  250.times do
    test
  end
end
```

On `master` this runs at about 92ms per iteration. With this patch, it
is 7ms per iteration.

[Bug #20573]
2024-06-11 14:54:15 -07:00
Burdette Lamar
0b31986909
[DOC] Doc for module Errno (#10913) 2024-06-05 16:27:00 -04:00
Jean Boussier
730e3b2ce0 Stop exposing rb_str_chilled_p
[Feature #20205]

Now that chilled strings no longer appear as frozen, there is no
need to offer an API to check for chilled strings.

We however need to change `rb_check_frozen_internal` to no
longer be a macro, as it needs to check for chilled strings.
2024-06-02 13:53:35 +02:00
Nobuyoshi Nakada
949fabe4e9
[DEBUG] More info when SyntaxError#path changed 2024-05-30 19:05:52 +09:00
Étienne Barrié
1376881e9a Stop marking chilled strings as frozen
They were initially made frozen to avoid false positives for cases such
as:

    str = str.dup if str.frozen?

But this may cause bugs and is generally confusing for users.

[Feature #20205]

Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
2024-05-28 07:32:33 +02:00
Nobuyoshi Nakada
bc50f2a3f1
Debug unexpectedly changed path 2024-05-26 20:14:18 +09:00
Kevin Newton
ba062a6231 [PRISM] Use correct warning encoding 2024-05-08 08:12:17 -04:00
É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
8a8df49174 Update set_backtrace documentation
Followup: https://github.com/ruby/ruby/pull/10017

[Feature #13557]
2024-03-18 08:55:46 +01:00
Jean Boussier
315bde5a0f Exception#set_backtrace accept arrays of Backtrace::Location
[Feature #13557]

Setting the backtrace with an array of strings is lossy. The resulting
exception will return nil on `#backtrace_locations`.

By accepting an array of `Backtrace::Location` instance, we can rebuild
a `Backtrace` instance and have a fully functioning Exception.

Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>
2024-03-14 11:38:40 +01:00
Nobuyoshi Nakada
1ad366134d
[Feature #20293] Add Warning.categories 2024-03-14 17:56:55 +09: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
Takashi Kokubun
8a6740c70e
YJIT: Lazily push a frame for specialized C funcs (#10080)
* YJIT: Lazily push a frame for specialized C funcs

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>

* Fix a comment on pc_to_cfunc

* Rename rb_yjit_check_pc to rb_yjit_lazy_push_frame

* Rename it to jit_prepare_lazy_frame_call

* Fix a typo

* Optimize String#getbyte as well

* Optimize String#byteslice as well

---------

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
2024-02-23 19:08:09 +00:00
Nobuyoshi Nakada
d31a12a210
Optional detail info at assertion failure 2024-02-08 18:08:41 +09:00
Nobuyoshi Nakada
d999ed3a2f
Fix typo 2024-01-13 16:34:32 +09:00
Nobuyoshi Nakada
3edb7f1a07
[DOC] Documentize known_errors 2024-01-13 11:08:00 +09:00