653 Commits

Author SHA1 Message Date
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
Nobuyoshi Nakada
8292b01c66
[DOC] Mark up the class name fatal 2024-01-12 22:44:56 +09:00
Peter Zhu
b959263b58 Fix Exception#detailed_message for GC compaction
Before this commit, the test fails with RGENGC_CHECK_MODE enabled:

    TestException#test_detailed_message_under_gc_compact_stress [test/ruby/test_exception.rb:1466]:
    <"\e[1mfoo (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n" +
    "\e[1mbar\e[m\n" +
    "\e[1mbaz\e[m"> expected but was
    <"\e[1mfoo (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n" +
    "\e[1m\x00\x00\x00\x00\x00\x00\x00\e[m">.
2024-01-02 12:03:31 -05:00
Victor Shepelev
e04197aba7
[DOC] Fix NoMethodError example of rendering (#9309)
Fix NoMethodError example of rendering
2023-12-21 22:27:18 +02:00
Jean Boussier
1ac0afab4d rb_bug_for_fatal_signal: exit with the right signal
`die()` calls `abort()` which always exit as it `SIGABRT`
was received.

This isn't very friendly with systems that automatically
collect crashes as the `%s` parameter will be changed.
2023-12-15 17:48:43 +01:00
Victor Shepelev
07734b51c6
[DOC] Small fixes for documentation rendering
Mostly just fixing RDoc's incorrect treatment of `+`
2023-12-09 13:54:33 +09: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
Alan Wu
0346cbbc14 Fix parameter types for rb_ivar_foreach() callbacks
For this public API, the callback is declared to take
`(ID, VALUE, st_data_t)`, but it so happens that using
`(st_data_t, st_data_t, st_data_t)` also
type checks, because the underlying type is identical.
Use it as declared and get rid of some casts.
2023-12-05 18:19:42 -05:00
Jean Boussier
903b0931a1 Refactor NameError::message and make it embeded
These aren't particularly common, but avoiding the malloc churn
for small types is always nice, and this commit also modernize
and cleanup the TypedData API usage.
2023-11-21 16:54:40 +01:00
Peter Zhu
392238e3fd Implement embedded TypedData objects
This commit adds a new flag RUBY_TYPED_EMBEDDABLE that allows the data
of a TypedData object to be embedded after the object itself. This will
improve cache locality and allow us to save the 8 byte data pointer.

Co-Authored-By: Jean Boussier <byroot@ruby-lang.org>
2023-11-07 15:48:06 -05:00
Nobuyoshi Nakada
bab01d284c [Feature #19790] Rename BUGREPORT_PATH as CRASH_REPORT 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
7c48a70c47 Test bug_report 2023-09-25 22:57:28 +09:00