summaryrefslogtreecommitdiff
path: root/test/ruby
AgeCommit message (Collapse)Author
2024-02-13Fix memory leak when parsing invalid hash symbolPeter Zhu
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[PRISM] Fix lambda start column numberNikita Vasilevsky
Co-Authored-By: Kevin Newton <kddnewton@gmail.com>
2024-02-13Fix [Bug #20246]: Don't set next_head_exact if a capture is called (#9897)Hiroya Fujinami
2024-02-13Warn duplication of `__ENCODING__` on the hashyui-knk
``` $ ruby -e 'h = { __ENCODING__ => 1, __ENCODING__ => 2 }' -e:1: warning: key #<Encoding:UTF-8> is duplicated and overwritten on line 1 ```
2024-02-12YJIT: Add support for `**kwrest` parametersAlan Wu
Now that `...` uses `**kwrest` instead of regular splat and ruby2keywords, we need to support these type of methods to support `...` well.
2024-02-12Allow `foo(**nil, &block_arg)`Alan Wu
Previously, `**nil` by itself worked, but if you add a block argument, it raised a conversion error. The presence of the block argument shouldn't change how keyword splat works. See: <https://bugs.ruby-lang.org/issues/20064>
2024-02-11Fix crash when passing large keyword splat to method accepting keywords and ↵Jeremy Evans
keyword splat The following code previously caused a crash: ```ruby h = {} 1000000.times{|i| h[i.to_s.to_sym] = i} def f(kw: 1, **kws) end f(**h) ``` Inside a thread or fiber, the size of the keyword splat could be much smaller and still cause a crash. I found this issue while optimizing method calling by reducing implicit allocations. Given the following code: ```ruby def f(kw: , **kws) end kw = {kw: 1} f(**kw) ``` The `f(**kw)` call previously allocated two hashes callee side instead of a single hash. This is because `setup_parameters_complex` would extract the keywords from the keyword splat hash to the C stack, to attempt to mirror the case when literal keywords are passed without a keyword splat. Then, `make_rest_kw_hash` would build a new hash based on the extracted keywords that weren't used for literal keywords. Switch the implementation so that if a keyword splat is passed, literal keywords are deleted from the keyword splat hash (or a copy of the hash if the hash is not mutable). In addition to avoiding the crash, this new approach is much more efficient in all cases. With the included benchmark: ``` 1 miniruby: 5247879.9 i/s miniruby-before: 2474050.2 i/s - 2.12x slower 1_mutable miniruby: 1797036.5 i/s miniruby-before: 1239543.3 i/s - 1.45x slower 10 miniruby: 1094750.1 i/s miniruby-before: 365529.6 i/s - 2.99x slower 10_mutable miniruby: 407781.7 i/s miniruby-before: 225364.0 i/s - 1.81x slower 100 miniruby: 100992.3 i/s miniruby-before: 32703.6 i/s - 3.09x slower 100_mutable miniruby: 40092.3 i/s miniruby-before: 21266.9 i/s - 1.89x slower 1000 miniruby: 21694.2 i/s miniruby-before: 4949.8 i/s - 4.38x slower 1000_mutable miniruby: 5819.5 i/s miniruby-before: 2995.0 i/s - 1.94x slower ```
2024-02-11[PRISM] Fix error handling in `pm_parse_prism`eileencodes
Following changes made in ruby/prism#2365 this implements error handling for when `pm_string_mapped_init` returns `false`. Related: ruby/prism#2207
2024-02-10Fix constant name of `Ractor::IsolationError` messageyui-knk
`dest` of `const_decl_path` is `NODE_COLON2` or `NODE_COLON3` in some cases. For example, `B::C ||= [“Not ” + “shareable”]` passes `NODE_COLON2` and `::C ||= [“Not ” + “shareable”]` passes `NODE_COLON3`. This commit fixes `Ractor::IsolationError` message for such case. ``` # shareable_constant_value: literal ::C ||= ["Not " + "shareable"] # Before # => cannot assign unshareable object to C (Ractor::IsolationError) # After # => cannot assign unshareable object to ::C (Ractor::IsolationError) ```
2024-02-10Include the first constant name into `Ractor::IsolationError` messageyui-knk
If lhs of assignment is top-level constant reference, the first constant name is omitted from error message. This commit fixes it. ``` # shareable_constant_value: literal ::C = ["Not " + "shareable"] # Before # => cannot assign unshareable object to (Ractor::IsolationError) # After # => cannot assign unshareable object to ::C (Ractor::IsolationError) ```
2024-02-09rb_obj_setup: do not copy RUBY_FL_SEEN_OBJ_IDJean Boussier
[Bug #20250] We're seting up a new instance, so it never had an associated object_id.
2024-02-08Fix crash when checking symbol encodingPeter Zhu
[Bug #20245] We sometimes pass in a fake string to sym_check_asciionly. This can crash if sym_check_asciionly raises because it creates a CFP with the fake string as the receiver which will crash if GC tries to mark the CFP. For example, the following script crashes: GC.stress = true Object.const_defined?("\xC3")
2024-02-06[PRISM] Use block node location when building block iseqNikita Vasilevsky
Co-Authored-By: Kevin Newton <kddnewton@gmail.com>
2024-02-04Remove TestProcess#test_low_memory_startupYusuke Endoh
It is too flaky on many platforms. Nobody is willing to fix it. Let's just stop it.
2024-02-05[PRISM] Fix encoding of interpolated stringsPeter Zhu
Fixes ruby/prism#2313.
2024-02-05[PRISM] Implement opt_aset_withJenny Shen
Part of ruby/prism#2231 Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com> Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2024-02-02[PRISM] Fix numbered parameters stealing local namesAlan Wu
Previously, the local index of numbered parameters were assigned to names of regular locals, making it hard to read both of them. Use proper `_[1-9]` numbered parameters. This fixes `test_shapes.rb`. Also, properly mark the iseq as having lead parameters.
2024-02-02Add memory leak test for Regexp timeoutPeter Zhu
[Bug #20228]
2024-02-02Add an assertion that `%x` literals call `` ` `` methodNobuyoshi Nakada
2024-02-01[PRISM] Respect string encoding override in array literalsAlan Wu
Fixes `TestZlibGzipReader#test_gets2`, `Psych_Unit_Tests#test_spec_explicit_families`, and many failures in `test_unicode_normalize.rb`.
2024-02-01[PRISM] dedup hash string keysJenny Shen
Fixes ruby/prism#2321 Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com> Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2024-02-01[PRISM] Do not shell out in prism testsKevin Newton
2024-02-01[PRISM] Fix multiple return with splat and splat+kwsplatAlan Wu
Previously, `return *array, 1` didn't behave like `return [*array, 1]` properly. Also, it crashed when splat and kwsplat is combined like in `array = [*things, **hash]`. Fix this by grouping `PM_ARGUMENTS_NODE` with `PM_ARRAY_NODE` handling and combining splat and kwsplat handling.
2024-01-31Do not modify provided argument splat when using ruby2_keywords with ↵Jeremy Evans
anonymous splat Previously, this would push the provided keywords onto the argument splat. Add ruby2_keywords to the list of other checks for whether it is safe for treating a given splat as mutable when the called method accepts an anonymous splat.
2024-01-31[PRISM] Fix else with rescuePeter Zhu
Fixes ruby/prism#2307.
2024-01-30[PRISM] pm_compile_logical: Fix OrNode in IfNode predicateMatt Valentine-House
Fixes: https://github.com/ruby/prism/issues/2294
2024-01-30Update forwarding locals for prismAaron Patterson
2024-01-29[PRISM] Fix crash when multiple underscoresPeter Zhu
Fixes ruby/prism#2295.
2024-01-29Fix RegExp warning causing flaky Ripper failureAlan Wu
Sometimes this file get picked up and break Ripper tests: TestRipper::Generic#test_parse_files:test/ruby assert_separately failed with error message pid 63392 exit 0 | test_regexp.rb:2025: warning: character class has duplicated range https://github.com/ruby/ruby/actions/runs/7699956651/job/20982702553#step:12:103
2024-01-29Fix test/ruby/test_rubyoptions.rb + --parser=prismKevin Newton
2024-01-29[PRISM] Use opt_str_freeze instructionPeter Zhu
Fixes ruby/prism#2290.
2024-01-29[PRISM] Support US-ASCII symbolsPeter Zhu
2024-01-29[PRISM] Support ASCII-8BIT symbolsPeter Zhu
2024-01-29[PRISM] Support UTF-8 symbolsPeter Zhu
Fixes ruby/prism#2242.
2024-01-29YJIT: Fix tailcall and JIT entry eating up FINISH frames (#9729)Alan Wu
Suppose YJIT runs a rb_vm_opt_send_without_block() fallback and the control frame stack looks like: ``` will_tailcall_bar [FINISH] caller_that_used_fallback ``` will_tailcall_bar() runs in the interpreter and sets up a tailcall. Right before JIT_EXEC() in the `send` instruction, the stack will look like: ``` bar [FINISH] caller_that_used_fallback ``` Previously, JIT_EXEC() ran bar() in JIT code, which caused the `FINISH` flag to return to the interpreter instead of to the JIT code running caller_that_used_fallback(), causing code to run twice and probably crash. Recent flaky failures on CI about "each stub expects a particular iseq" are probably due to leaving methods twice in `test_optimizations.rb`. Only run JIT code from the interpreter if a new frame is pushed.
2024-01-29[PRISM] Use the splatkw instructionPeter Zhu
Fixes ruby/prism#2272.
2024-01-29Correctly handle consecutive lookarounds (#9738)Hiroya Fujinami
Fix [Bug #20207] Fix [Bug #20212] Handling consecutive lookarounds in init_cache_opcodes is buggy, so it causes invalid memory access reported in [Bug #20207] and [Bug #20212]. This fixes it by using recursive functions to detected lookarounds nesting correctly.
2024-01-28[Bug #20219] `gettable` returns NULL on errorNobuyoshi Nakada
2024-01-28[Bug #20217] `rescue` block is void only if all children are voidNobuyoshi Nakada
2024-01-28[Bug #20217] `return` with `ensure` is a void value expressionNobuyoshi Nakada
2024-01-26[PRISM] Fix loop in rescue blocksPeter Zhu
Fixes ruby/prism#2250. Co-Authored-By: Kevin Newton <kddnewton@gmail.com>
2024-01-26[PRISM] Keyword arguments incorrectly passed as mutablePeter Zhu
Fixes ruby/prism#2279.
2024-01-25Fix incorrect use of VM_CALL_KW_SPLAT_MUT in zsuper with keyword splatJeremy Evans
For zsuper calls with a keyword splat but no actual keywords, the keyword splat is passed directly, so it cannot be mutable, because if the callee accepts a keyword splat, changes to the keyword splat by the callee would be reflected in the caller. While here, simplify the logic when the method supports literal keywords. I don't think it is possible for a method with has_kw param flags to not have keywords, so add an assertion for that, and set VM_CALL_KW_SPLAT_MUT in a single place.
2024-01-25[PRISM] Add raw option to assert_prism_evalPeter Zhu
2024-01-25[PRISM] Fix next inside rescueMatt Valentine-House
2024-01-25[PRISM] Fix indentation of test_ScopeNodePeter Zhu
2024-01-25Simplified test case for encoding optionHiroshi SHIBATA
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2024-01-25Use Encoding.local_charmap instead of localeHiroshi SHIBATA
In my windows environment uses cp932 for terminal encoding.
2024-01-24Do not use ruby2_keywords for ... argument forwardingJeremy Evans
This allows ... argument forwarding to benefit from Allocationless Anonymous Splat Forwarding, allowing the `f` call below to not allocate an array or a hash. ```ruby a = [1] kw = {b: 2} def c(a, b:) end def f(...) c(...) end f(*a, **kw) ``` This temporarily skips prism locals tests until prism is changed to use * and ** for ..., instead of using ruby2_keywords. Ignore failures in rbs bundled gems tests, since they fail due to this change.
2024-01-25Use echo with all platformsHiroshi SHIBATA