83561 Commits

Author SHA1 Message Date
Peter Zhu
28709d591d Remove unused argument in cc_table_free 2024-02-14 16:25:05 -05:00
Alan Wu
72f8883a2f YJIT: Extract keyword handling to make gen_send_iseq() shorter
This should make it easier to grok the order of operations.
2024-02-14 16:09:11 -05:00
Peter Zhu
ae8db4b65a Remove unused function rb_cc_table_free 2024-02-14 15:52:15 -05:00
Aaron Patterson
c9ed59c2e2 Update yjit/src/codegen.rs
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2024-02-14 12:49:36 -08:00
Aaron Patterson
7943cb22f6 Consider rb_str_getbyte as leaf sometimes
If YJIT knows the parameter to rb_str_getbyte is a fixnum, then I think
we can consider the function to be a leaf
2024-02-14 12:49:36 -08:00
Peter Zhu
fadb7d412b Remove duplicated include in weakmap.c 2024-02-14 15:37:53 -05:00
Kevin Newton
9933377c34 [PRISM] Correctly hook up line numbers for eval 2024-02-14 15:29:26 -05:00
Peter Zhu
1d3b306753 Move rb_class_allocate_instance from gc.c to object.c 2024-02-14 13:43:02 -05:00
Kevin Newton
fc2c128e7e [PRISM] Set eval encoding based on string encoding 2024-02-14 13:24:43 -05:00
Takashi Kokubun
7177731282
YJIT: Add --yjit-perf=codegen option (#9957) 2024-02-14 09:09:14 -08:00
Alan Wu
ee3b4bec0e
YJIT: Simplify Kernel#send guards and admit more cases (#9956)
Previously, our compile time check rejected dynamic symbols (e.g. what
String#to_sym could return) even though we could handle them just fine.
The runtime guards for the type of method name was also overly
restrictive and didn't accept dynamic symbols.

Fold the type check into the rb_get_symbol_id() and take advantage of
the guard already checking for 0. This also avoids generating the same
call twice in case the same method name is presented as different
types.
2024-02-14 11:19:04 -05:00
Benoit Daloze
f4a0e1cdb4 Prefer Array.new(n) {} to n.times.map {}
* It is quite a bit faster:
  ruby -rbenchmark/ips -e 'Benchmark.ips { |x| x.report("times.map") { 1000.times.map {} }; x.report("Array.new") { Array.new(1000) {} }; x.compare! }'
  ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-linux]
  Warming up --------------------------------------
         times.map   976.000 i/100ms
         Array.new     1.641k i/100ms
  Calculating -------------------------------------
         times.map      9.808k (± 0.3%) i/s -     49.776k in   5.075013s
         Array.new     16.601k (± 1.0%) i/s -     83.691k in   5.041970s

  Comparison:
         Array.new:    16600.8 i/s
         times.map:     9808.2 i/s - 1.69x  slower
2024-02-14 15:56:42 +00:00
Benoit Daloze
c2d8d6eba6 Initialize the Prism::Source directly with all 3 fields for the C extension
* Faster that way:
  $ ruby -Ilib -rprism -rbenchmark/ips -e 'Benchmark.ips { |x| x.report("parse") { Prism.parse("1 + 2") } }'
  195.722k (± 0.5%) i/s
  rb_iv_set():
  179.609k (± 0.5%) i/s
  rb_funcall():
  190.030k (± 0.3%) i/s
  before this PR:
  183.319k (± 0.4%) i/s
2024-02-14 15:48:33 +00:00
Benoit Daloze
1b2708b123 [ruby/prism] Remove attr_writer's for ParseResult#start_line and #offsets
* As the user should not set these.
* Use #instance_variable_set/rb_iv_set() instead internally.

https://github.com/ruby/prism/commit/cace09fb8c
2024-02-14 15:48:33 +00:00
Benoit Daloze
f0f6ffef42 [ruby/prism] Serialize the newline_list to avoid recomputing it again later
* Fixes https://github.com/ruby/prism/issues/2380

https://github.com/ruby/prism/commit/4eaaa90114
2024-02-14 15:48:32 +00:00
Burdette Lamar
65f5435540
[DOC] Doc compliance (#9955) 2024-02-14 10:47:42 -05:00
git
f1136e73e8 Update default gems list at 12b0e67fec2cc59a6f7da4a4bfbd52 [ci skip] 2024-02-14 14:59:30 +00:00
Kevin Newton
12b0e67fec
[PRISM] Sync to latest prism 2024-02-14 09:58:36 -05:00
Stan Lo
c84581f1d9 [ruby/irb] Repurpose the help command to display the help message
(https://github.com/ruby/irb/pull/872)

See #787 for more details.

https://github.com/ruby/irb/commit/d9192d92d0
2024-02-14 13:47:45 +00:00
tomoya ishida
d0412599e0 [ruby/irb] Improve constant lookup in SourceFinder
(https://github.com/ruby/irb/pull/871)

https://github.com/ruby/irb/commit/87c279ccf2
2024-02-14 13:46:49 +00:00
dependabot[bot]
eea7ce55de Bump github/codeql-action from 3.24.0 to 3.24.1
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.24.0 to 3.24.1.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v3.24.0...e675ced7a7522a761fc9c8eb26682c8b27c42b2b)

---
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-02-14 12:17:23 +09:00
Kevin Newton
1fc7c79dea
[PRISM] Exclude additional tests from rebase 2024-02-13 21:40:47 -05:00
Kevin Newton
8ec955d1f5 [PRISM] Switch bootstraptest syntax error assertions to handle multiline 2024-02-13 21:19:12 -05:00
Kevin Newton
5de3e3057a [PRISM] Add temporary test exclusions to get eval passing 2024-02-13 21:19:12 -05:00
Matt Valentine-House
adb2fbf69a [PRISM] Prism/eval should handle file names provided 2024-02-13 21:19:12 -05:00
Matt Valentine-House
f70a4a0336 [PRISM] yield is invalid inside eval 2024-02-13 21:19:12 -05:00
Matt Valentine-House
0285b533e9 [PRISM] Don't rb_bug if redo/break/next used during eval 2024-02-13 21:19:12 -05:00
Matt Valentine-House
edb755c84b [PRISM] Add eval tests 2024-02-13 21:19:12 -05:00
Matt Valentine-House
c2af974e67 [PRISM] Build wrapper scopes for eval
- Don't use `build_options_scopes` We can inline the code here instead
  and avoid allocating all the extra arrays.

- Create `pm_scope_node_t` objects with the correct local table, for the
  scope node returned from the parser.

Co-Authored-By: Kevin Newton <kddnewton@gmail.com>
2024-02-13 21:19:12 -05:00
Matt Valentine-House
fd3f776a05 [PRISM] Use Prism for eval if enabled 2024-02-13 21:19:12 -05:00
Kevin Newton
068b19bd53 [ruby/prism] Match up token name to CRuby
https://github.com/ruby/prism/commit/cf0369a5c7
2024-02-14 01:42:01 +00:00
Kazuhiro NISHIYAMA
c54622c657
Fix a warning with USE_RUBY_DEBUG_LOG=1 on macOS
```
compiling ../thread.c
In file included from ../thread.c:263:
In file included from ../thread_pthread.c:2870:
../thread_pthread_mn.c:777:43: warning: format specifies type 'unsigned long' but the argument has type 'rb_hrtime_t' (aka 'unsigned long long') [-Wformat]
		RUBY_DEBUG_LOG("abs:%lu", abs);
				    ~~~   ^~~
				    %llu
../vm_debug.h:110:74: note: expanded from macro 'RUBY_DEBUG_LOG'
	ruby_debug_log(__FILE__, __LINE__, RUBY_FUNCTION_NAME_STRING, "" __VA_ARGS__); \
									 ^~~~~~~~~~~
1 warning generated.
```
2024-02-14 10:40:26 +09:00
Kevin Newton
8e3eb8c9b4
[PRISM] Fix up common.mk dependencies 2024-02-13 20:32:19 -05:00
Kevin Newton
2fa051f627 [ruby/prism] Validate multibyte characters in strings
Check that multibyte characters are valid using pm_strpbrk. We need
to add a couple of codepaths to ensure all encodings are covered.

Importantly this doesn't check regular expressions, because
apparently you're allowed to have invalid multibyte characters
inside regular expression comment groups/extended mode.

https://github.com/ruby/prism/commit/2857d3e1b5
2024-02-14 01:01:37 +00:00
Kevin Newton
dc5191d695 [ruby/prism] Fix KOI-8 char width check
https://github.com/ruby/prism/commit/06d3747c5b
2024-02-13 21:12:10 +00:00
Peter Zhu
a5869e5d8c [PRISM] Replace assert with RUBY_ASSERT
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
2024-02-13 15:54:04 -05:00
Peter Zhu
83c158fdfc [PRISM] Replace assert with rb_bug 2024-02-13 15:54:04 -05:00
Kevin Newton
a96110f7ef [ruby/prism] Convert more error messages to match specs
https://github.com/ruby/prism/commit/7987b7aa20
2024-02-13 20:35:02 +00:00
Peter Zhu
4d3fc96b8b Change dsymbol_alloc to use NEWOBJ_OF 2024-02-13 15:30:06 -05:00
Kevin Newton
b1964a9204 [ruby/prism] Add code unit APIs to location
LSPs need this because the protocol dictates that you return code
units for offsets. None of our existing APIs provided that
information, and since we hid the source it's not nearly as useful
for them. Now they can pass an encoding directly to:

* Location#start_code_units_offset
* Location#end_code_units_offset
* Location#start_code_units_column
* Location#end_code_units_column

https://github.com/ruby/prism/commit/4757a2cc06

Co-Authored-By: Vinicius Stock <vinicius.stock@shopify.com>
2024-02-13 20:10:25 +00:00
Alan Wu
6261d4b4d8 Fix use-after-move in Symbol#inspect
The allocation could re-embed `orig_str` and invalidate the data
pointer from RSTRING_GETMEM() if the string is embedded.

Found on CI, where the test introduced in 7002e776944 ("Fix
Symbol#inspect for GC compaction") recently failed.

See: <https://github.com/ruby/ruby/actions/runs/7880657560/job/21503019659>
2024-02-13 14:49:54 -05:00
Alan Wu
5add999dee Comment about not marking RSYMBOL(obj)->fstr [ci skip] 2024-02-13 14:49:54 -05:00
Burdette Lamar
21297293f4
[DOC] Doc compliance (#9944) 2024-02-13 13:49:35 -05:00
Kevin Newton
29d04bb0c4 [ruby/prism] Introduce version: "3.4.0"
This is effectively an alias for "latest" right now. In the future
it will change to be its own enum value.

https://github.com/ruby/prism/commit/2c86036022
2024-02-13 18:26:28 +00:00
Koichi ITO
246005f5bd [ruby/prism] Fix an error when specifying the parsing version latest
This PR fixes following error when using `version: latest` argument.

```console
$ ruby -rprism -e "p Prism.parse('-> { it }', version: 'latest')"
-e:1:in `parse': invalid version: latest (ArgumentError)

p Prism.parse('-> { it }', version: 'latest')
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        from -e:1:in `<main>'
```

The argument `version: latest` in the added test is commented as potentially being
better replaced with `version: 3.4.0` in the future.

https://github.com/ruby/prism/commit/27b5c933cb
2024-02-13 18:15:48 +00:00
Aaron Patterson
a93f4e3d1a byteslice can return nil so we have to push an "unknown" value 2024-02-13 10:10:19 -08:00
Alan Wu
fdaef7a72e YJIT: Fixup kwrest stack base
I was a little rushed and didn't notice that it was still using the
final stack size even though we don't grow the stack before kwrest
handling anymore. Oh well, we got a new test out of it.

Fix: cbdabd5890
2024-02-13 12:16:36 -05:00
Aaron Patterson
c35fea8509
Specialize String#byteslice(a, b) (#9939)
* Specialize String#byteslice(a, b)

This adds a specialization for String#byteslice when there are two
parameters.

This makes our protobuf parser go from 5.84x slower to 5.33x slower

```
Comparison:
decode upstream (53738 bytes):     7228.5 i/s
decode protobuff (53738 bytes):     1236.8 i/s - 5.84x  slower

Comparison:
decode upstream (53738 bytes):     7024.8 i/s
decode protobuff (53738 bytes):     1318.5 i/s - 5.33x  slower
```

* Update yjit/src/codegen.rs

---------

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
2024-02-13 16:20:27 +00:00
Peter Zhu
a71d1ed838 Fix memory leak when parsing invalid hash symbol
For example:

    10.times do
      100_000.times do
        eval('{"\xC3": 1}')
      rescue EncodingError
      end

      puts `ps -o rss= -p #{$$}`
    end

Before:

    32032
    48464
    66112
    84192
    100592
    117520
    134096
    150656
    167168
    183760

After:

    17120
    17120
    17120
    17120
    18560
    18560
    18560
    18560
    18560
    18560
2024-02-13 11:05:56 -05:00
Alan Wu
e4272fd292 Avoid allocation when passing no keywords to anonymous kwrest methods
Thanks to the new semantics from [ruby-core:115808], `**nil` is now
equivalent to `**{}`. Since the only thing one could do with anonymous
keyword rest parameter is to delegate it with `**`, nil is just as good
as an empty hash. Using nil avoids allocating an empty hash.

This is particularly important for `...` methods since they now use
`**kwrest` under the hood after 4f77d8d328. Most calls don't pass
keywords.

    Comparison:
                             fw_no_kw
                    post:   9816800.9 i/s
                     pre:   8570297.0 i/s - 1.15x  slower
2024-02-13 11:05:26 -05:00