Commit graph

84431 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
dependabot[bot]
86b15316a7 Bump github/codeql-action from 3.24.7 to 3.24.8
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.24.7 to 3.24.8.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](3ab4101902...05963f47d8)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-18 22:55:15 -07:00
dependabot[bot]
59849feed8 Bump actions/checkout from 4.1.1 to 4.1.2
Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.1 to 4.1.2.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](b4ffde65f4...9bb56186c3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-19 11:56:22 +09:00
git
6c18b2474d Update default gems list at 0985e58790 [ci skip] 2024-03-19 02:17:51 +00:00
Hiroshi SHIBATA
0985e58790 [ruby/resolv] Bump up 0.4.0
44ae1e8531
2024-03-19 02:16:51 +00:00
Hiroshi SHIBATA
ef0e08f327
Don't replace doc url for vendored files 2024-03-19 10:54:52 +09:00
HASUMI Hitoshi
ce544f8dbd [ruby/prism] [Compatibility] Improve printf format
For better compatibility, this patch suggests using __MINGW_PRINTF_FORMAT that GCC provides for MINGW environment.

a3a792b64f
2024-03-19 01:30:38 +00:00
Yuki Nishijima
6c1e8029d0 [ruby/did_you_mean] Do not use #inspect to avoid unexpected performance degradation
closes https://github.com/ruby/did_you_mean/pull/100

bd11eefd6c
2024-03-19 01:27:32 +00:00
Peter Zhu
3f5f04afa7 Remove duplicated function prototype rb_gc_disable_no_rest 2024-03-18 16:39:04 -04:00
Kevin Newton
0b34b75ba1
[PRISM] Remove unnecessary dependencies in common.mk 2024-03-18 14:18:53 -04:00
Kevin Newton
548203eaf2 [ruby/prism] Warn on frozen_string_literal after tokens
edece87801
2024-03-18 17:00:07 +00:00
Kevin Newton
8514785e94 [ruby/prism] CRuby error message for lonely else
1219a709e4
2024-03-18 16:59:58 +00:00
Koichi ITO
7a1a572428 [ruby/prism] Use require_relative in the Prism codebase
If there are many searches in the `$LOAD_PATH` in the user environment,
require will perform unnecessary searches that are not needed.
In contrast, `require_relative` is efficient because it uses a relative path.

438ccc67bd
2024-03-18 16:12:49 +00:00
Alan Wu
802e857ae6
YJIT: Support arity=-2 cfuncs (#10268)
This type of cfuncs shows up as consume a lot of cycles in profiles of
the lobsters benchmark, even though in the stats they don't happen that
frequently. Might be a bug in the profiling, but these calls are not
too bad to support, so might as well do it.

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
2024-03-18 16:02:22 +00:00
Kevin Newton
97810cbbf2 [PRISM] Process encoding on CLI for -K 2024-03-18 11:55:43 -04:00
Kevin Newton
b7ca4b1e2d [PRISM] Fix up frozen checks for aref 2024-03-18 11:55:43 -04:00
Nobuyoshi Nakada
f5497203b6
Highlight messages in fetch-bundled_gems 2024-03-18 23:29:54 +09:00
Nobuyoshi Nakada
6ccc04cf45
Add more abstract decorations for messaging 2024-03-18 23:29:53 +09:00
Peter Zhu
4469729558 Remove rb_raw_obj_info_basic
It's not used outside of gc.c.
2024-03-18 10:19:11 -04:00
Kevin Newton
c73dd96fe4
[PRISM] Resync 2024-03-18 09:58:53 -04:00
Cody Cutrer
cb029fa4e8 [rubygems/rubygems] Deprecate bundle plugin install --local-git=
It's the exact same implementation as --git

18eb2418c6
2024-03-18 11:42:37 +00: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
Naoto Ono
454b939d7c Launchable: Remove unused codes 2024-03-18 16:49:33 +09:00
tompng
0ff2c7fe6f Faster Integer.sqrt for large bignum
Integer.sqrt uses Newton's method.
This pull request reduces the precision which was unnecessarily high in each calculation step.
2024-03-18 13:52:27 +09:00
Soutaro Matsumoto
dcfbe36cb5
Update unmerged RBS to debug EBADF error (#10275)
Update bundled_gems
2024-03-18 03:32:53 +00:00
OKURA Masafumi
e6487a9263 [ruby/irb] docs(help): Add latest options to ja help message
(https://github.com/ruby/irb/pull/903)

3c6d452495
2024-03-18 02:37:42 +00:00
David Rodriguez
dc06375c4f [rubygems/rubygems] Ignore commented out keys in config file
c4a8d2a930
2024-03-17 22:55:16 +00:00
Nobuyoshi Nakada
5fd6b461c7
Refactor encdb and transdb templates
- Simplify globbed file names.
- Prefer `File.open` over `Kernel#open`.
- Swallow initializer blocks instead of line by line with flip-flop.
- Re-structure converter list.
2024-03-17 19:09:37 +09:00
Nobuyoshi Nakada
e670892497
Remove no longer needed matching 2024-03-17 18:47:18 +09:00
Nobuyoshi Nakada
9e470ebdcd
Revert "Remove flip-flop usages from build scripts"
This reverts commit 301fa452f7.
2024-03-17 18:28:28 +09:00
Nobuyoshi Nakada
28a2105a55
Prefer enum ruby_tag_type over int 2024-03-17 15:57:19 +09:00
Nobuyoshi Nakada
a91800c4a0
Validate tag type to jump 2024-03-17 15:57:19 +09:00
Nobuyoshi Nakada
e69708e5ef
[DOC] Mention about disallowed arguments in index
[Bug #19918]
[Bug #20218]
2024-03-17 13:37:02 +09:00
Nobuyoshi Nakada
0d5b16599a
[Bug #20218] Reject keyword arguments in index 2024-03-17 13:20:23 +09:00
Nobuyoshi Nakada
df5ef28233
[Bug #19918] Reject block passing in index 2024-03-17 13:18:37 +09:00
Koichi ITO
3605d6076d [ruby/prism] Fix token incompatibility for Prism::Translation::Parser::Lexer
This PR fixes token incompatibility for `Prism::Translation::Parser::Lexer` when using backquoted heredoc indetiner:

```ruby
<<-`  FOO`
a
b
     FOO
```

## Parser gem (Expected)

Returns `tXSTRING_BEG` as the first token:

```console
$ bundle exec ruby -Ilib -rparser/ruby33 -ve \
'buf = Parser::Source::Buffer.new("example.rb"); buf.source = File.read("example.rb"); p Parser::Ruby33.new.tokenize(buf)'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
[s(:xstr,
  s(:str, "a\n"),
  s(:str, "b\n")), [], [[:tXSTRING_BEG, ["<<`", #<Parser::Source::Range example.rb 0...10>]],
[:tSTRING_CONTENT, ["a\n", #<Parser::Source::Range example.rb 11...13>]],
[:tSTRING_CONTENT, ["b\n", #<Parser::Source::Range example.rb 13...15>]],
[:tSTRING_END, ["  FOO", #<Parser::Source::Range example.rb 15...23>]], [:tNL, [nil, #<Parser::Source::Range example.rb 10...11>]]]]
```

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

Previously, the tokens returned by the Parser gem were different. The escaped backslash does not match in the `tSTRING_BEG` token and
value of `tSTRING_END` token.

```console
$ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve \
'buf = Parser::Source::Buffer.new("example.rb"); buf.source = File.read("example.rb"); p Prism::Translation::Parser33.new.tokenize(buf)'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
[s(:xstr,
  s(:str, "a\n"),
  s(:str, "b\n")), [], [[:tSTRING_BEG, ["<<\"", #<Parser::Source::Range example.rb 0...10>]],
[:tSTRING_CONTENT, ["a\n", #<Parser::Source::Range example.rb 11...13>]],
[:tSTRING_CONTENT, ["b\n", #<Parser::Source::Range example.rb 13...15>]],
[:tSTRING_END, ["`  FOO`", #<Parser::Source::Range example.rb 15...23>]], [:tNL, [nil, #<Parser::Source::Range example.rb 10...11>]]]]
```

After this correction, the AST and tokens returned by the Parser gem are the same:

```console
$ bunlde exec ruby -Ilib -rprism -rprism/translation/parser33 -ve \
'buf = Parser::Source::Buffer.new("example.rb"); buf.source = File.read("example.rb"); p Prism::Translation::Parser33.new.tokenize(buf)'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
[s(:xstr,
  s(:str, "a\n"),
  s(:str, "b\n")), [], [[:tXSTRING_BEG, ["<<`", #<Parser::Source::Range example.rb 0...10>]],
[:tSTRING_CONTENT, ["a\n", #<Parser::Source::Range example.rb 11...13>]],
[:tSTRING_CONTENT, ["b\n", #<Parser::Source::Range example.rb 13...15>]],
[:tSTRING_END, ["  FOO", #<Parser::Source::Range example.rb 15...23>]], [:tNL, [nil, #<Parser::Source::Range example.rb 10...11>]]]]
```

308f8d85a1
2024-03-16 17:55:38 +00:00
Jeremy Evans
815c7e197c Avoid caller-side hash allocation for f(*a, kw: 1) and f(*a, kw: 1, &block)
Previously, this used:

```
splatarray false
duphash
getlocal/getblockparamproxy # in the block passing case
send ARGS_SPLAT|KW_SPLAT|KW_SPLAT_MUT
```

This changes the duphash to putobject, with putobject using
a frozen version of the hash, and removing the keyword mutability:

```
splatarray false
putobject
getlocal/getblockparamproxy # in the block passing case
send ARGS_SPLAT|KW_SPLAT
```
2024-03-16 09:27:32 -07:00
tomoya ishida
bda5b09937 [ruby/irb] Fix irb_history saved to current directory
(https://github.com/ruby/irb/pull/901)

* Always save irb_history in HOME or XDG_CONFIG_HOME

Also split irbrc search logic from irb_history search logic as a refactor

* Remove IRB.conf[:RC_NAME_GENERATOR] because it's not configurable

This conf is used to specify which irbrc to load. Need to configure before irbrc is loaded, so it's actually not configurable.
This conf is also used for history file search, but it is configurable by conf[:HISTORY_FILE].

* remove rc_file_test because it is tested with rc_files, remove useless test setup

* Make internal irbrc searching method private

11d03a6ff7
2024-03-16 15:20:03 +00:00
Nobuyoshi Nakada
aae9f5628c
Prefer the simple read/write File singleton methods 2024-03-16 23:44:07 +09:00
Nobuyoshi Nakada
d4a53b465a
Prefer the simple read/write File singleton methods 2024-03-16 23:29:06 +09:00
Stan Lo
137b52a881 [ruby/irb] Use markdown format for docs
(https://github.com/ruby/irb/pull/890)

* Convert irb.rb's document into markdown format

* Hide should-be-private top-level methods from docs

* Skip xmp.rb's docs

* Declare lib/irb.rb's markup do it works in ruby/ruby too

* Ignore docs folder

e9a175e06b
2024-03-16 13:51:07 +00:00
Mau Magnaguagno
f1682407c5 [ruby/did_you_mean] Avoid division for small length2
cb518e251a
2024-03-16 09:51:09 +00:00
Mau Magnaguagno
affbc79a10 [ruby/did_you_mean] Remove Integer floor and prefix index from Jaro distance
The variable ``length2`` is an Integer, call to floor returns self.
The variables ``i`` and ``prefix_bonus`` are equally incremented, no need to keep the ``i`` variable.

4408802289
2024-03-16 09:51:09 +00:00
Alan Wu
def7023ee4 Initialize VM stack if VM_CHECK_MODE
Lately there has been a few flaky YJIT CI failures where a new Ruby
thread is finding the canary on the VM stack. For example:

2267950848 (step):14:109

After checking a local rr recording, it's clear that the canary was
written there when YJIT was using a temporary malloc region, and then
later handed to the new Ruby thread. Previously, the VM stack was
uninitialized, so it can have stale values in it, like the canary.

Though unlikely, this can happen without YJIT too. Initialize the stack
if we're spawning canaries.
2024-03-15 19:15:58 -04:00
Peter Zhu
185112f4ff Remove unused macro TF 2024-03-15 16:03:26 -04:00
Koichi ITO
e3a82d79fd [ruby/prism] Fix token incompatibility for Prism::Translation::Parser::Lexer
This PR fixes token incompatibility for `Prism::Translation::Parser::Lexer`
when using escaped backslash in string literal:

```ruby
"\\ foo \\ bar"
```

## Parser gem (Expected)

```console
$ bundle exec ruby -Ilib -rparser/ruby33 -ve \
'buf = Parser::Source::Buffer.new("example.rb"); buf.source = File.read("example.rb"); p Parser::Ruby33.new.tokenize(buf)'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
[s(:str, "\\ foo \\ bar"), [], [[:tSTRING, ["\\ foo \\ bar", #<Parser::Source::Range example.rb 0...15>]],
[:tNL, [nil, #<Parser::Source::Range example.rb 15...16>]]]]
```

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

Previously, the tokens returned by the Parser gem were different. The escaped backslash does not match in the `tSTRING` token:

```console
$ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve \
'buf = Parser::Source::Buffer.new("example.rb"); buf.source = File.read("example.rb"); p Prism::Translation::Parser33.new.tokenize(buf)'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
[s(:str, "\\ foo \\ bar"), [], [[:tSTRING, ["\\\\ foo \\\\ bar", #<Parser::Source::Range example.rb 0...15>]],
[:tNL, [nil, #<Parser::Source::Range example.rb 15...16>]]]]
```

After this correction, the AST and tokens returned by the Parser gem are the same:

```console
$ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve \
'buf = Parser::Source::Buffer.new("example.rb"); buf.source = File.read("example.rb"); p Prism::Translation::Parser33.new.tokenize(buf)'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
[s(:str, "\\ foo \\ bar"), [], [[:tSTRING, ["\\ foo \\ bar", #<Parser::Source::Range example.rb 0...15>]],
[:tNL, [nil, #<Parser::Source::Range example.rb 15...16>]]]]
```

The reproduction test is based on the following strings.txt and exists:
https://github.com/ruby/prism/blob/v0.24.0/test/prism/fixtures/strings.txt#L79

But, the restoration has not yet been performed due to remaining other issues in strings.txt.

2c44e7e307
2024-03-15 18:08:39 +00:00
Koichi ITO
c9da8d67fd [ruby/prism] Fix a token incompatibility for Prism::Translation::Parser::Lexer
This PR fixes a token incompatibility between Parser gem and `Prism::Translation::Parser`
for the heredocs_leading_whitespace.txt test.

7d45fb1eed
2024-03-15 18:07:59 +00:00
Jeremy Evans
aceee71c35 Avoid a hash allocation when calling def f(kw: 1) with keyword splat
c20e819e8b made calling a method
that accepts specific keywords but not a keyword splat with a keyword
splat allocating a hash when it previously did not.

Instead of duplicating the hash and removing hash entries,
lookup in the provided hash without duplicating the hash, and
track to make sure all hash entries in the hash were looked up
(extra hash entries would be errors).
2024-03-15 08:23:41 -07:00
Nobuyoshi Nakada
a83703af79
Skip warnings for duplicate keys 2024-03-16 00:09:29 +09:00
Jean Boussier
91bf7eb274 Refactor frozen_string_literal check during compilation
In preparation for https://bugs.ruby-lang.org/issues/20205.

The `frozen_string_literal` compilation option will no longer
be a boolean but a tri-state: `on/off/default`.
2024-03-15 15:52:33 +01:00