summaryrefslogtreecommitdiff
path: root/test/ruby
AgeCommit message (Collapse)Author
2023-12-24Fix Symbol#inspect for GC compactionPeter Zhu
The test fails when RGENGC_CHECK_MODE is turned on: 1) Failure: TestSymbol#test_inspect_under_gc_compact_stress [test/ruby/test_symbol.rb:123]: <":testing"> expected but was <":\x00\x00\x00\x00\x00\x00\x00">.
2023-12-24Fix off-by-one error for declarative markingPeter Zhu
The for loops for marking and reference updating declaratively marked TypedData objects did not mark/reference update the very last element. When RGENGC_CHECK_MODE is turned on, this caused the test in Enumerator to fail with: tool/lib/test/unit/testcase.rb:173:in `rescue in run': failed to allocate memory (NoMemoryError)
2023-12-25Correctly release the underlying file mapping. (#9340)Samuel Williams
* Avoiding using `Tempfile` which was retaining the file preventing it from unlinking.
2023-12-24Fix Enumerator#with_index for GC compactionPeter Zhu
enumerator_block_call was not safe for compaction because the Array backing the argv was not pinned, so it could get moved during compaction which would make argv point to somewhere else. The test crashes when RGENGC_CHECK_MODE is turned on: TestEnumerator#test_with_index_under_gc_compact_stress check_rvalue_consistency: 0x55db0b399450 is not a Ruby object. test/ruby/test_enumerator.rb:133: [BUG] check_rvalue_consistency_force: there is 1 errors. ruby 3.3.0dev (2023-12-23T23:00:27Z master 50bf437341) [x86_64-linux] -- Control frame information ----------------------------------------------- c:0034 p:---- s:0192 e:000187 CFUNC :with_index c:0033 p:---- s:0185 e:000184 CFUNC :each c:0032 p:---- s:0182 e:000181 CFUNC :to_a c:0031 p:0055 s:0178 e:000175 BLOCK test/ruby/test_enumerator.rb:133 c:0030 p:0024 s:0172 e:000171 METHOD tool/lib/envutil.rb:242 c:0029 p:0024 s:0167 e:000166 METHOD tool/lib/envutil.rb:251 c:0028 p:0005 s:0160 e:000159 METHOD test/ruby/test_enumerator.rb:131 ... -- C level backtrace information ------------------------------------------- build/ruby(rb_print_backtrace+0x14) [0x55db0b1deb21] vm_dump.c:820 build/ruby(rb_vm_bugreport) vm_dump.c:1151 build/ruby(bug_report_end+0x0) [0x55db0b3a53a6] error.c:1042 build/ruby(rb_bug_without_die) error.c:1042 build/ruby(die+0x0) [0x55db0afc77c2] error.c:1050 build/ruby(rb_bug) error.c:1052 build/ruby(gc_move+0x0) [0x55db0afbada0] gc.c:1714 build/ruby(check_rvalue_consistency+0xa) [0x55db0afef0c3] gc.c:1729 build/ruby(is_markable_object) gc.c:4769 build/ruby(gc_mark_stack_values) gc.c:6595 build/ruby(rb_gc_mark_vm_stack_values) gc.c:6605 build/ruby(rb_execution_context_mark+0x39) [0x55db0b1d8589] vm.c:3309 build/ruby(thread_mark+0x15) [0x55db0b1a9805] vm.c:3381 build/ruby(gc_mark_stacked_objects+0x6d) [0x55db0aff2c3d] gc.c:7564 build/ruby(gc_mark_stacked_objects_all) gc.c:7602 build/ruby(gc_marks_rest) gc.c:8797 build/ruby(gc_marks+0xd) [0x55db0aff43d5] gc.c:8855 build/ruby(gc_start) gc.c:9608 build/ruby(rb_multi_ractor_p+0x0) [0x55db0aff5463] gc.c:9489 build/ruby(rb_vm_lock_leave) vm_sync.h:92 build/ruby(garbage_collect) gc.c:9491 build/ruby(newobj_slowpath+0xcb) [0x55db0aff57ab] gc.c:2871 build/ruby(newobj_slowpath_wb_protected) gc.c:2895 build/ruby(newobj_of0+0x24) [0x55db0aff59e4] gc.c:2937 build/ruby(newobj_of) gc.c:2947 build/ruby(rb_wb_protected_newobj_of) gc.c:2962 build/ruby(ary_alloc_embed+0x10) [0x55db0b2f3e40] array.c:668 build/ruby(ary_new) array.c:709 build/ruby(rb_ary_tmp_new_from_values) array.c:759 build/ruby(rb_ary_new_from_values) array.c:771 build/ruby(args_copy+0x18) [0x55db0b1bbb88] vm_args.c:158
2023-12-24Fix Regexp#inspect for GC compactionPeter Zhu
rb_reg_desc was not safe for GC compaction because it took in the C string and length but not the backing String object so it get moved during compaction. This commit changes rb_reg_desc to use the string from the Regexp object. The test fails when RGENGC_CHECK_MODE is turned on: TestRegexp#test_inspect_under_gc_compact_stress [test/ruby/test_regexp.rb:474]: <"(?-mix:\\/)|"> expected but was <"/\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00/">.
2023-12-24Fix Regexp#match for GC compactionPeter Zhu
The test fails when RGENGC_CHECK_MODE is turned on: TestRegexp#test_match_under_gc_compact_stress: NoMethodError: undefined method `match' for nil test_regexp.rb:878:in `block in test_match_under_gc_compact_stress'
2023-12-25IO::Buffer improvements and documentation. (#9329)Samuel Williams
* Restore experimental warnings. * Documentation and code structure improvements. * Improved validation of flags, clarified documentation of argument handling. * Remove inconsistent use of `Example:` and add example to `null?`. * Expose `IO::Buffer#private?` and add test.
2023-12-23Fix String#sub for GC compactionPeter Zhu
The test fails when RGENGC_CHECK_MODE is turned on: TestString#test_sub_gc_compact_stress = 9.42 s 1) Failure: TestString#test_sub_gc_compact_stress [test/ruby/test_string.rb:2089]: <"aaa [amp] yyy"> expected but was <"aaa [] yyy">.
2023-12-23Fix Regexp#to_s for GC compactionPeter Zhu
The test fails when RGENGC_CHECK_MODE is turned on: TestRegexp#test_to_s_under_gc_compact_stress = 13.46 s 1) Failure: TestRegexp#test_to_s_under_gc_compact_stress [test/ruby/test_regexp.rb:81]: <"(?-mix:abcd\u3042)"> expected but was <"(?-mix:\u5C78\u3030\u5C78\u3030\u5C78\u3030\u5C78\u3030\u5C78\u3030)">.
2023-12-23Adjust indent [ci skip]Nobuyoshi Nakada
2023-12-22[Bug #19977] Fix (nil..nil) === x not to raise TypeErrorKouhei Yanagita
2023-12-21RJIT: Convert opt_case_dispatch keys with #to_valueTakashi Kokubun
comptime_key is a Ruby object and the value is not valid in machine code. This PR also implements `CMP r/m64, imm32 (Mod 01: [reg]+disp8)` that is now needed for running mail.gem benchmark.
2023-12-21Fix ary_make_partial_step for compactionPeter Zhu
ary could change embeddedness due to compaction, so we should only get the pointer after allocations. The included test was crashing with: TestArray#test_slice_gc_compact_stress ruby/lib/pp.rb:192: [BUG] Segmentation fault at 0x0000000000000038
2023-12-20Correct free_on_exit env var to free_at_exitHParker
2023-12-19YJIT: Add stats option to RubyVM::YJIT.enable (#9297)Takashi Kokubun
2023-12-19restore the stack pointer on finalizerKoichi Sasada
When error on finalizer, the exception will be ignored. To restart the code, we need to restore the stack pointer. fix [Bug #20042]
2023-12-18Fix flaky test test_stat_heapPeter Zhu
The test sometimes fails with: 1) Failure: TestGc#test_stat_heap [/tmp/ruby/src/trunk-repeat50/test/ruby/test_gc.rb:169]: Expected 33434403 to be <= 33434354.
2023-12-18Make the SHAPE_TOO_COMPLEX performance warning more actionableJean Boussier
As suggested by Mame, we should try to help users fix the issues without having to lookup the meaning of the warning.
2023-12-17Stir the hash value more with encoding indexNobuyoshi Nakada
2023-12-16[Bug #20068] Encoding does not matter to empty stringsNobuyoshi Nakada
2023-12-15[PRISM] Compile CallTargetNodeMatt Valentine-House
2023-12-15[PRISM] Compile IndexTargetNodeMatt Valentine-House
2023-12-15Update error message in test_rubyoptionsKevin Newton
2023-12-15Introduce --parser runtime flagHParker
Introduce runtime flag for specifying the parser, ``` ruby --parser=prism ``` also update the description: ``` $ ruby --parser=prism --version ruby 3.3.0dev (2023-12-08T04:47:14Z add-parser-runtime.. 0616384c9f) +PRISM [x86_64-darwin23] ``` [Bug #20044]
2023-12-16[Bug #20062] Fixed numbered parameter syntax errorNobuyoshi Nakada
At the method definition, the local scope that saves the context of the numbered parameters needs to be pushed before saving.
2023-12-15[PRISM] Fix `compile_prism` when src is a fileeileencodes
`compile_prism` can take a source and file (and other arguments) or a file as the source. `compile` checks if the source is a file and if it is converts it. `compile_prism` is now doing the same thing. On the Ruby side `compile` handles a file [here](https://github.com/ruby/ruby/blob/master/iseq.c#L1159-L1162). Before: ``` "********* Ruby *************" == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(26,21)> local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) [ 1] name@0 0000 putstring "Prism" ( 25)[Li] 0002 setlocal name@0, 0 0005 putself ( 26)[Li] 0006 putobject "hello, " 0008 getlocal name@0, 0 0011 dup 0012 objtostring <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE> 0014 anytostring 0015 concatstrings 2 0017 send <calldata!mid:puts, argc:1, FCALL|ARGS_SIMPLE>, nil 0020 leave hello, Prism "********* PRISM *************" ./test.rb:13:in `compile_prism': wrong argument type File (expected String) (TypeError) from ./test.rb:13:in `<main>' make: *** [run] Error 1 ``` After: ``` "********* Ruby *************" == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(26,21)> local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) [ 1] name@0 0000 putstring "Prism" ( 25)[Li] 0002 setlocal name@0, 0 0005 putself ( 26)[Li] 0006 putobject "hello, " 0008 getlocal name@0, 0 0011 dup 0012 objtostring <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE> 0014 anytostring 0015 concatstrings 2 0017 send <calldata!mid:puts, argc:1, FCALL|ARGS_SIMPLE>, nil 0020 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@test_code.rb:24 (24,0)-(25,21)> local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) [ 1] name@0 0000 putstring "Prism" ( 24)[Li] 0002 setlocal name@0, 0 0005 putself ( 25)[Li] 0006 putobject "hello, " 0008 getlocal name@0, 0 0011 dup 0012 objtostring <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE> 0014 anytostring 0015 concatstrings 2 0017 send <calldata!mid:puts, argc:1, FCALL|ARGS_SIMPLE>, nil 0020 leave ( 24) ``` Fixes ruby/prism#1609
2023-12-15add a testKoichi Sasada
proposed at https://bugs.ruby-lang.org/issues/20050#note-5
2023-12-14Remove unused variables in test_call_op_asgn_keywords_mutableJeremy Evans
2023-12-14[PRISM] Implement safe navigation in CallNodesJemma Issroff
This commit implements safe navigation for CallNodes, CallAndWriteNodes and CallOperatorWriteNodes
2023-12-14[PRISM] Fix keyword hash handling in method callsUfuk Kayserilioglu
* Start using the renamed `PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS` flag to check if all keys of the keyword hash node are symbols. * For arguments passed as a hash, start marking them as `KW_SPLAT_MUT` only if the number of entries in the hash is greater than 1 (which is what the old compiler used to do).
2023-12-14Pattern matchingKevin Newton
2023-12-14[PRISM] Account for multiple anonymous localsJemma Issroff
This commit adjusts the local table size to be consistent regardless of the number of anonymous locals.
2023-12-14[PRISM] Fix bugs in compiling optional keyword parametersJemma Issroff
This PR fixes two bugs when compiling optional keyword parameters: - It moves keyword parameter compilation to STEP 5 in the parameters sequence, where the rest of compilation happens. This is important because keyword parameter compilation relies on the value of body->param.keyword->bits_start which gets set in an earlier step - It compiles array and hash values for keyword parameters, which it didn't previously
2023-12-14[PRISM] Use frozen flag on StringNodeJemma Issroff
2023-12-14Fix op asgn method calls passing mutable keyword splatsJeremy Evans
When passing the keyword splat to [], it cannot be mutable, because mutating the keyword splat inside [] would result in changes to the keyword splat passed to []=.
2023-12-14[PRISM] Add anon KW args to the block local tableMatt Valentine-House
2023-12-13[PRISM] Add a test with a non-static-literal hash keyUfuk Kayserilioglu
2023-12-13[Prism] Fix InterpolatedMatchLastLine Instructionseileencodes
I looked at this at RubyConf with Kevin, and we noticed that there was a `putobject` empty string missing from the instructions. I just got back around to implementing this and pushing a PR and while doing that noticed that we also have a `getspecial` when we want a `getglobal`. This change adds the `putobject` instruction and replaces the `getspecial` with a `getglobal`. If we look at the parsetree for the following code: ```ruby $pit = '.oo'; if /"#{$pit}"/mix; end ``` We can see it has a `NODE_GVAR` and the [Ruby compiler](https://github.com/ruby/ruby/blob/a4b43e92645e46ee5a8c9af42d3de57cd052e87c/compile.c#L10024-L10030) shows that should use `getglobal. ``` @ NODE_SCOPE (id: 14, line: 1, location: (1,0)-(22,36)) +- nd_tbl: (empty) +- nd_args: | (null node) +- nd_body: @ NODE_BLOCK (id: 12, line: 22, location: (22,0)-(22,36)) +- nd_head (1): | @ NODE_GASGN (id: 0, line: 22, location: (22,0)-(22,12))* | +- nd_vid: :$pit | +- nd_value: | @ NODE_STR (id: 1, line: 22, location: (22,7)-(22,12)) | +- nd_lit: ".oo" +- nd_head (2): @ NODE_IF (id: 11, line: 22, location: (22,14)-(22,36))* +- nd_cond: | @ NODE_MATCH2 (id: 10, line: 22, location: (22,14)-(22,36)) | +- nd_recv: | | @ NODE_DREGX (id: 2, line: 22, location: (22,17)-(22,31)) | | +- nd_lit: "\"" | | +- nd_next->nd_head: | | | @ NODE_EVSTR (id: 4, line: 22, location: (22,19)-(22,26)) | | | +- nd_body: | | | @ NODE_GVAR (id: 3, line: 22, location: (22,21)-(22,25)) | | | +- nd_vid: :$pit | | +- nd_next->nd_next: | | @ NODE_LIST (id: 7, line: 22, location: (22,26)-(22,27)) | | +- as.nd_alen: 1 | | +- nd_head: | | | @ NODE_STR (id: 6, line: 22, location: (22,26)-(22,27)) | | | +- nd_lit: "\"" | | +- nd_next: | | (null node) | +- nd_value: | @ NODE_GVAR (id: 9, line: 22, location: (22,14)-(22,36)) | +- nd_vid: :$_ +- nd_body: | @ NODE_BEGIN (id: 8, line: 22, location: (22,32)-(22,32)) | +- nd_body: | (null node) +- nd_else: (null node) ``` I'm struggling with writing a failing test, but the before/after instructions show that `getglobal` is correct here. I compared the instructions for the other `InterpolatedMatchLastLine` node tests and they also used `getglobal`. I've edited the existing `InterpolatedLastMatchLineNode` test so that it will use that instruction when copied out of the test. Without the quotes it thinks it's just a `MatchLastLineNode`. Incorrect instructions: ``` "********* Ruby *************" == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(22,36)> 0000 putstring ".oo" ( 22)[Li] 0002 setglobal :$pit 0004 putobject "\"" 0006 getglobal :$pit 0008 dup 0009 objtostring <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE> 0011 anytostring 0012 putobject "\"" 0014 toregexp 7, 3 0017 getglobal :$_ 0019 send <calldata!mid:=~, argc:1, ARGS_SIMPLE>, nil 0022 branchunless 30 0024 jump 26 0026 putnil 0027 jump 31 0029 pop 0030 putnil 0031 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@<compiled>:21 (21,0)-(21,36)> 0000 putstring ".oo" ( 21)[Li] 0002 setglobal :$pit 0004 putobject "\"" 0006 getglobal :$pit 0008 dup 0009 objtostring <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE> 0011 anytostring 0012 putobject "\"" 0014 toregexp 7, 3 0017 getspecial 0, 0 0020 send <calldata!mid:=~, argc:1, ARGS_SIMPLE>, nil 0023 branchunless 31 0025 jump 27 0027 putnil 0028 jump 32 0030 pop 0031 putnil 0032 leave ``` Fixed instructions: ``` == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(22,36)> 0000 putstring ".oo" ( 22)[Li] 0002 setglobal :$pit 0004 putobject "\"" 0006 getglobal :$pit 0008 dup 0009 objtostring <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE> 0011 anytostring 0012 putobject "\"" 0014 toregexp 7, 3 0017 getglobal :$_ 0019 send <calldata!mid:=~, argc:1, ARGS_SIMPLE>, nil 0022 branchunless 30 0024 jump 26 0026 putnil 0027 jump 31 0029 pop 0030 putnil 0031 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@<compiled>:21 (21,0)-(21,36)> 0000 putstring ".oo" ( 21)[Li] 0002 setglobal :$pit 0004 putobject "\"" 0006 getglobal :$pit 0008 dup 0009 objtostring <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE> 0011 anytostring 0012 putobject "\"" 0014 toregexp 7, 3 0017 getglobal :$_ 0019 send <calldata!mid:=~, argc:1, ARGS_SIMPLE>, nil 0022 branchunless 30 0024 jump 26 0026 putnil 0027 jump 31 0029 pop 0030 putnil 0031 leave ```
2023-12-13Fix memory leak in Hash#compare_by_identityAlan Wu
We didn't free the old ST before overwriting it which caused a leak. Found with RUBY_FREE_ON_EXIT. Co-authored-by: Peter Zhu <[email protected]>
2023-12-13Make String#chomp! raise ArgumentError for 2+ arguments if string is emptyJeremy Evans
String#chomp! returned nil without checking the number of passed arguments in this case.
2023-12-13[PRISM] Generate instruction for when redo_label is setMatt Valentine-House
2023-12-13[PRISM] If receiver on CallNode is SelfNode, use FCALL flagsJemma Issroff
2023-12-13[PRISM] Fix attrset edge caseseileencodes
In some cases code may look like an attrset ID but should actually return the value of the method, not the passed values. In ruby/prism#2051 a flag was added when we have a attribute write call. I used this flag to add the proper instructions when we have a real attrset instead of using `rb_is_attrset_id` which was kind of hacky anyway. The value that should be returned in the newly added test is 42, not 2. Previously the changes we had made returned 2. Related to ruby/prism#1715
2023-12-12Skip a GC test for RJITTakashi Kokubun
It randomly fails like this: https://github.com/ruby/ruby/actions/runs/7191443542/job/19586164973
2023-12-12[PRISM] Correctly parse non-base 10 integers in PrismJemma Issroff
This commit passes an `end` to rb_int_parse_cstr which allows us to correctly parse non-base 10 integers which are enclosed in parenthesis. Prior to this commit, we were getting a putobject nil when compiling `(0o0)` for example.
2023-12-12[PRISM] Fix segv with regex once flageileencodes
When you have an interpolated regex with a `once` flag and local variable is outside the block created by the `once` flag, Prism would see a segv. This is because it was not taking the depth into account. To fix this, we need to add 1 to the `local_depth_offset` on the `scope`. Fixes: ruby/prism#2047
2023-12-12[PRISM] Compile NextNode argumentsMatt Valentine-House
2023-12-12[PRISM] Implementing forwarding of args for ForwardingSuperNodeJemma Issroff
ForwardingSuperNodes need to actually forward any applicable arguments. This commit implements that logic, by using the data stored on the local iseq about the parameters to forward the appropriate arguments.
2023-12-12[Bug #19114] Fix for multiple calls of TracePoint#enableKouhei Yanagita
2023-12-12Fix op asgn calls with keywordsJeremy Evans
Examples of such calls: ```ruby obj[kw: 1] += fo obj[**kw] &&= bar ``` Before this patch, literal keywords would segfault in the compiler, and keyword splat usage would result in TypeError. This handles all cases I can think of: * literal keywords * keyword splats * combined with positional arguments * combined with regular splats * both with and without blocks * both popped and non-popped cases This also makes sure that to_hash is only called once on the keyword splat argument, instead of twice, and make sure it is called before calling to_proc on a passed block. Fixes [Bug #20051] Co-authored-by: Nobuyoshi Nakada <[email protected]>