summaryrefslogtreecommitdiff
path: root/test/ruby
AgeCommit message (Collapse)Author
2024-02-22[Bug #20292] Truncate embedded string to new capacityNobuyoshi Nakada
2024-02-22Cover all warning category optionsNobuyoshi Nakada
2024-02-21YJIT: Grab stack operands after SP change in String#byteslice (#10060)Alan Wu
Previously, `StackOperand`s caching `sp_offset` was held across a jit_prepare_call_with_gc(), which invalidates the offsets. With the right register allocation state, the canary overlapped with the old address of the receiver and YJIT clobbered the receiver writing the canary.
2024-02-21Re-enable test now that dump is all ASCIIKevin Newton
2024-02-22Ensure that exiting thread invokes end-of-life behaviour. (#10039)Samuel Williams
2024-02-20Add memory leak test for eval kwargsJohn Hawthorn
2024-02-20Fix string value in hash literal being forced frozenAlan Wu
We should pass `false` for `hash_key` for value nodes. Credits to `@kddnewton` for noticing and bisecting.
2024-02-21skip a test on non-UTF-8 localeKoichi Sasada
`ruby --parser=prism -W:no-experimental --dump=parsetree -e :hi` prints non-ASCII char(s) so the following test with non UTF-8 locale fails. ``` $ LANG=C make test-all TESTS='-n /parser/ ruby/rubyoptions' -o encs -o exts Run options: --seed=32323 "--ruby=./miniruby -I/home/ko1/ruby/src/master/lib -I. -I.ext/common /home/ko1/ruby/src/master/tool/runruby.rb --extout=.ext -- --disable-gems" --excludes-dir=/home/ko1/ruby/src/master/test/.excludes --name=!/memory_leak/ -n /parser/ [1/1] TestRubyOptions#test_parser_flag = 0.04 s 1) Failure: TestRubyOptions#test_parser_flag [/home/ko1/ruby/src/master/test/ruby/test_rubyoptions.rb:300]: pid 135869 exit 0. 1. [1/2] Assertion for "stdout" | invalid byte sequence in US-ASCII. Finished tests in 0.044362s, 22.5416 tests/s, 225.4157 assertions/s. 1 tests, 10 assertions, 1 failures, 0 errors, 0 skips ruby -v: ruby 3.4.0dev (2024-02-20T17:13:36Z master c0e5de9567) [x86_64-linux] make: *** [uncommon.mk:945: yes-test-all] Error 1 ``` Now simply skip the test if the locale is not UTF-8. (I'm not familiar with encodings so please fix it if needed)
2024-02-20Add pushtoarraykwsplat instruction to avoid unnecessary array allocationJeremy Evans
This is designed to replace the newarraykwsplat instruction, which is no longer used in the parse.y compiler after this commit. This avoids an unnecessary array allocation in the case where ARGSCAT is followed by LIST with keyword: ```ruby a = [] kw = {} [*a, 1, **kw] ``` Previous Instructions: ``` 0000 newarray 0 ( 1)[Li] 0002 setlocal_WC_0 a@0 0004 newhash 0 ( 2)[Li] 0006 setlocal_WC_0 kw@1 0008 getlocal_WC_0 a@0 ( 3)[Li] 0010 splatarray true 0012 putobject_INT2FIX_1_ 0013 putspecialobject 1 0015 newhash 0 0017 getlocal_WC_0 kw@1 0019 opt_send_without_block <calldata!mid:core#hash_merge_kwd, argc:2, ARGS_SIMPLE> 0021 newarraykwsplat 2 0023 concattoarray 0024 leave ``` New Instructions: ``` 0000 newarray 0 ( 1)[Li] 0002 setlocal_WC_0 a@0 0004 newhash 0 ( 2)[Li] 0006 setlocal_WC_0 kw@1 0008 getlocal_WC_0 a@0 ( 3)[Li] 0010 splatarray true 0012 putobject_INT2FIX_1_ 0013 pushtoarray 1 0015 putspecialobject 1 0017 newhash 0 0019 getlocal_WC_0 kw@1 0021 opt_send_without_block <calldata!mid:core#hash_merge_kwd, argc:2, ARGS_SIMPLE> 0023 pushtoarraykwsplat 0024 leave ``` pushtoarraykwsplat is designed to be simpler than newarraykwsplat. It does not take a variable number of arguments from the stack, it pops the top of the stack, and appends it to the second from the top, unless the top of the stack is an empty hash. During this work, I found the ARGSPUSH followed by HASH with keyword did not compile correctly, as it pushed the generated hash to the array even if the hash was empty. This fixes the behavior, to use pushtoarraykwsplat instead of pushtoarray in that case: ```ruby a = [] kw = {} [*a, **kw] [{}] # Before [] # After ``` This does not remove the newarraykwsplat instruction, as it is still referenced in the prism compiler (which should be updated similar to this), YJIT (only in the bindings, it does not appear to be implemented), and RJIT (in a couple comments). After those are updated, the newarraykwsplat instruction should be removed.
2024-02-20YJIT: Support `**nil` for cfuncsAlan Wu
Similar to the iseq call support. Fairly straight forward.
2024-02-20Update warning flags before dumpNobuyoshi Nakada
2024-02-20Remove never used methodNobuyoshi Nakada
2024-02-20Remove no longer used methodsNobuyoshi Nakada
`find_object_in_recycled_slot` and `memory_location` have not been used since commit:b99833baec2e567e38758f4fd017c90c7ce57d75.
2024-02-19[Bug #20280] Raise SyntaxError on invalid encoding symbolNobuyoshi Nakada
2024-02-16YJIT: Support empty splatAlan Wu
Previously we rejected empty splat calls to methods with no parameters as `iseq_arity_error` which didn't work well with delegated calls.
2024-02-16YJIT: Support `**nil`Alan Wu
This adds YJIT support for VM_CALL_KW_SPLAT with nil, specifically for when we already know from the context that it's done with a nil. This is enough to support forwarding with `...` when there no keyword arguments are present. Amend the kw_rest support to propagate the type of the parameter to help with this. Test interactions with splat, since the splat array sits lower on the stack when a kw_splat argument is present.
2024-02-16[PRISM] Make prism compiler warning experimentalKevin Newton
2024-02-15Do not show an anonymous class as a receiverYusuke Endoh
2024-02-15Show the method owner in backtracesYusuke Endoh
``` test.rb:1:in 'Object#toplevel_meth': unhandled exception from test.rb:4:in 'Foo.class_meth' from test.rb:6:in 'Foo#instance_meth' from test.rb:11:in 'singleton_meth' from test.rb:13:in '<main>' ``` [Feature #19117]
2024-02-15Do not include a backtick in error messages and backtracesYusuke Endoh
[Feature #16495]
2024-02-15Show the invalid source encoding in messagesNobuyoshi Nakada
2024-02-14YJIT: Simplify Kernel#send guards and admit more cases (#9956)Alan Wu
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-13[PRISM] Add eval testsMatt Valentine-House
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