summaryrefslogtreecommitdiff
path: root/compile.c
AgeCommit message (Collapse)Author
2021-10-16merge revision(s) 217df51f0e5d9824ed712a4d175f555d932e44d8: [Backport #18232]nagachika
Dump outer variables tables when dumping an iseq to binary This commit dumps the outer variables table when dumping an iseq to binary. This fixes a case where Ractors aren't able to tell what outer variables belong to a lambda after the lambda is loaded via ISeq.load_from_binary [Bug #18232] [ruby-core:105504] --- compile.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++- test/ruby/test_iseq.rb | 10 +++++++++ 2 files changed, 64 insertions(+), 1 deletion(-)
2021-05-22merge revision(s) ↵nagachika
2bc293e899c9d32dcd794a73de8925c49ecf8f15,d0e6c6e682b9ba2b0309a5177933a0628e8ef316,cc0dc67bbbe1951ff90004bc987f78545625d772,e1eff837cf12a8e813de9d4ff2db50c9b68b86b5,0ab0b86c8491d639b9ff1335ddf35e341ecd867e,6911b4bc82889860ff7da4ecf975504cdc3e5314: [Backport #17854] cdhash_cmp: can take rational literals Rational literals are those integers suffixed with `r`. They tend to be a part of more complex expressions like `123/456r`, but in theory they can live alone. When such "bare" rational literals are passed to case-when branch, we have to take care of them. Fixes [Bug #17854] --- common.mk | 1 + compile.c | 7 +++++++ internal/rational.h | 1 + rational.c | 13 ++++++++++--- test/ruby/test_rational.rb | 7 +++++++ 5 files changed, 26 insertions(+), 3 deletions(-) cdhash_cmp: rational literals with fractions Nobu kindly pointed out that rational literals can have fractions. --- compile.c | 5 +++-- test/ruby/test_rational.rb | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) cdhash_cmp: can also take complex There are complex literals `123i`, which can also be a case condition. --- compile.c | 15 +++++++++++---- complex.c | 12 +++++++++--- internal/complex.h | 1 + test/ruby/test_rational.rb | 4 ++++ 4 files changed, 25 insertions(+), 7 deletions(-) cdhash_cmp: recursively apply For instance a rational's numerator can be a bignum. Comparison using C's == can be insufficient. --- compile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) cdhash_cmp: should use || cf: https://github.com/ruby/ruby/pull/4469#discussion_r628386707 --- compile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) test_cdhash: refactor change class It is now strange to test Complex in a class named Rational_Test. --- test/ruby/test_rational.rb | 15 --------------- test/ruby/test_syntax.rb | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 15 deletions(-)
2021-05-22merge revision(s) 5026f9a5d5012248729a0052cd6cec811748291b: [Backport #17868]nagachika
compile.c: stop the jump-jump optimization if the second has any event Fixes [Bug #17868] --- compile.c | 3 ++- test/ruby/test_settracefunc.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)
2021-02-02merge revision(s) 1b89b99941548fdb65305dd9a412082e7fdba45a: [Backport #17534]NARUSE, Yui
Mark pattern labels as unremoveable Peephole optimization doesn't play well with find pattern at least. The only case when a pattern matching could have unreachable patterns is when we have lasgn/dasgn node, which shouldn't happen in real-life. Fixes https://bugs.ruby-lang.org/issues/17534 --- compile.c | 2 +- test/ruby/test_pattern_matching.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-)
2021-02-01merge revision(s) ↵NARUSE, Yui
efcdf68e6443ab70fbff1703b9dabbfc5090df31,5e26619660f20272a53c7f839dde36cce034bb35: [Backport #17539] Guard callinfo Callinfo was being written in to an array and the GC would not see the reference on the stack. `new_insn_send` creates a new callinfo object, then it calls `new_insn_core`. `new_insn_core` allocates a new INSN linked list item, which can end up calling `xmalloc` which will trigger a GC: https://github.com/ruby/ruby/blob/70cd351c7c71c48ee18d7c01e851a89614086f8f/compile.c#L968-L969 Since the callinfo object isn't on the stack, the GC won't see it, and it can get collected. This patch just refactors `new_insn_send` to keep the object on the stack Co-authored-by: John Hawthorn <john@hawthorn.email> --- compile.c | 7 +++++-- test/ruby/test_gc.rb | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) Fix WB for callinfo The WB for callinfo needs to be executed *after* the reference is written. Otherwise we get a WB miss. --- compile.c | 1 + 1 file changed, 1 insertion(+)
2021-01-13enable constant cache on ractorsKoichi Sasada
constant cache `IC` is accessed by non-atomic manner and there are thread-safety issues, so Ruby 3.0 disables to use const cache on non-main ractors. This patch enables it by introducing `imemo_constcache` and allocates it by every re-fill of const cache like `imemo_callcache`. [Bug #17510] Now `IC` only has one entry `IC::entry` and it points to `iseq_inline_constant_cache_entry`, managed by T_IMEMO object. `IC` is atomic data structure so `rb_mjit_before_vm_ic_update()` and `rb_mjit_after_vm_ic_update()` is not needed.
2020-12-25Adjusted indents [ci skip]Nobuyoshi Nakada
2020-12-14Skip defined check in NODE_OP_ASGN_OR with ivarJohn Hawthorn
Previously we would add code to check if an ivar was defined when using `@foo ||= 123`, which was slower than `@foo || (@foo = 123)` when `@foo` was already defined. Recently 01b7d5acc702df22d306ae95f1a9c3096e63e624 made it so that accessing an undefined variable no longer generates a warning, making the defined check unnecessary and both statements exactly equal. This commit avoids emitting the defined instruction when compiling NODE_OP_ASGN_OR with a NODE_IVAR. Before: $ ruby --dump=insn -e '@foo ||= 123' == disasm: #<ISeq:<main>@-e:1 (1,0)-(1,12)> (catch: FALSE) 0000 putnil ( 1)[Li] 0001 defined instance-variable, :@foo, false 0005 branchunless 14 0007 getinstancevariable :@foo, <is:0> 0010 dup 0011 branchif 20 0013 pop 0014 putobject 123 0016 dup 0017 setinstancevariable :@foo, <is:0> 0020 leave After: $ ./ruby --dump=insn -e '@foo ||= 123' == disasm: #<ISeq:<main>@-e:1 (1,0)-(1,12)> (catch: FALSE) 0000 getinstancevariable :@foo, <is:0> ( 1)[Li] 0003 dup 0004 branchif 13 0006 pop 0007 putobject 123 0009 dup 0010 setinstancevariable :@foo, <is:0> 0013 leave This seems to be about 50% faster in this benchmark: require "benchmark/ips" class Foo def initialize @foo = nil end def test1 @foo ||= 123 end def test2 @foo || (@foo = 123) end end FOO = Foo.new Benchmark.ips do |x| x.report("test1", "FOO.test1") x.report("test2", "FOO.test2") end Before: $ ruby benchmark_ivar.rb Warming up -------------------------------------- test1 1.957M i/100ms test2 3.125M i/100ms Calculating ------------------------------------- test1 20.030M (± 1.7%) i/s - 101.780M in 5.083040s test2 31.227M (± 4.5%) i/s - 156.262M in 5.015936s After: $ ./ruby benchmark_ivar.rb Warming up -------------------------------------- test1 3.205M i/100ms test2 3.197M i/100ms Calculating ------------------------------------- test1 32.066M (± 1.1%) i/s - 163.440M in 5.097581s test2 31.438M (± 4.9%) i/s - 159.860M in 5.098961s Notes: Merged: https://github.com/ruby/ruby/pull/3904
2020-11-30Raise when loading unprovided builtin function [Bug #17192]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/3622 Merged-By: nobu <nobu@ruby-lang.org>
2020-11-02Add `GC.auto_compact= true/false` and `GC.auto_compact`Aaron Patterson
* `GC.auto_compact=`, `GC.auto_compact` can be used to control when compaction runs. Setting `auto_compact=` to true will cause compaction to occurr duing major collections. At the moment, compaction adds significant overhead to major collections, so please test first! [Feature #17176]
2020-10-31Revert "Use adjusted sp on `iseq_set_sequence()`" and "Delay ↵wanabe
`remove_unreachable_chunk()` after `iseq_set_sequence()`" This reverts commit 3685ed7303fc08bf68cd3cc8d11e22a8ce63a067 and 5dc107b03f5cf32656a5308574b90458486c633c. Because of some CI failures https://github.com/ruby/ruby/pull/3404#issuecomment-719868313.
2020-10-31Removed unused variableNobuyoshi Nakada
2020-10-31Use adjusted sp on `iseq_set_sequence()`wanabe
Notes: Merged: https://github.com/ruby/ruby/pull/3404
2020-10-31Delay `remove_unreachable_chunk()` after `iseq_set_sequence()`wanabe
Notes: Merged: https://github.com/ruby/ruby/pull/3404
2020-10-30strip trailing spaces [ci skip]Nobuyoshi Nakada
2020-10-29check isolated Proc more strictlyKoichi Sasada
Isolated Proc prohibit to access outer local variables, but it was violated by binding and so on, so they should be error. Notes: Merged: https://github.com/ruby/ruby/pull/3721
2020-10-28compile.c: separate compile_builtin_function_call (#3711)Kenta Murata
Notes: Merged-By: mrkn <mrkn@ruby-lang.org>
2020-10-21Don't redefine #rb_intern over and over againStefan Stüben
Notes: Merged: https://github.com/ruby/ruby/pull/3589
2020-10-17sync RClass::ext::iv_index_tblKoichi Sasada
iv_index_tbl manages instance variable indexes (ID -> index). This data structure should be synchronized with other ractors so introduce some VM locks. This patch also introduced atomic ivar cache used by set/getinlinecache instructions. To make updating ivar cache (IVC), we changed iv_index_tbl data structure to manage (ID -> entry) and an entry points serial and index. IVC points to this entry so that cache update becomes atomically. Notes: Merged: https://github.com/ruby/ruby/pull/3662
2020-10-16Adjust sp for `if true or ...`/`if false and ...`wanabe
Notes: Merged: https://github.com/ruby/ruby/pull/3445
2020-10-16Adjust sp for `x = false; y = (return until x unless x)` [Bug #16695]wanabe
Notes: Merged: https://github.com/ruby/ruby/pull/3445
2020-10-07Add missing WB for iseqAaron Patterson
The write barrier wasn't being called for this object, so add the missing WB. Automatic compaction moved the reference because it didn't know about the relationship (that's how I found the missing WB).
2020-10-03Added the room for builtin inline prefixNobuyoshi Nakada
2020-10-03Check builtin inline function index overflowNobuyoshi Nakada
2020-10-02Put same frozen Range literal if possibleKoichi Sasada
Range literal is now frozen so we can reuse same Range object if the begin and the last are Numeric (frozen), such as `(1..2)`. Notes: Merged: https://github.com/ruby/ruby/pull/3587
2020-09-30Unfreeze string-literal-only interpolated string-literalNobuyoshi Nakada
[Feature #17104]
2020-09-15Interpolated strings are no longer frozen with frozen-string-literal: trueBenoit Daloze
* Remove freezestring instruction since this was the only usage for it. * [Feature #17104] Notes: Merged: https://github.com/ruby/ruby/pull/3488
2020-09-03Introduce Ractor mechanism for parallel executionKoichi Sasada
This commit introduces Ractor mechanism to run Ruby program in parallel. See doc/ractor.md for more details about Ractor. See ticket [Feature #17100] to see the implementation details and discussions. [Feature #17100] This commit does not complete the implementation. You can find many bugs on using Ractor. Also the specification will be changed so that this feature is experimental. You will see a warning when you make the first Ractor with `Ractor.new`. I hope this feature can help programmers from thread-safety issues. Notes: Merged: https://github.com/ruby/ruby/pull/3365
2020-08-17procnames-start-lines [ci skip]Nobuyoshi Nakada
2020-08-17Revisit "Refactor to reduce "swap" instruction of pattern matching"Nobuyoshi Nakada
Just moved "case base" after allocating cache space.
2020-08-17Revert "Refactor to reduce "swap" instruction of pattern matching"Kazuhiro NISHIYAMA
This reverts commit 3a4be429b50062122d1616256de38649464d3146. To fix following warning: ``` compiling ../compile.c ../compile.c:6336:20: warning: variable 'line' is uninitialized when used here [-Wuninitialized] ADD_INSN(head, line, putnil); /* allocate stack for cached #deconstruct value */ ^~~~ ../compile.c:220:57: note: expanded from macro 'ADD_INSN' ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (line), BIN(insn), 0)) ^~~~ ../compile.c:6327:13: note: initialize the variable 'line' to silence this warning int line; ^ = 0 1 warning generated. ```
2020-08-16Refactor to reduce "swap" instruction of pattern matchingwanabe
2020-08-16Adjust sp for `case ... in a: 0 ... end`wanabe
Notes: Merged: https://github.com/ruby/ruby/pull/3403
2020-08-16Adjust sp for `case ... in *, a, * end`wanabe
Notes: Merged: https://github.com/ruby/ruby/pull/3403
2020-08-16Adjust sp for `case ... in *v end`/`case ... in v1, v2 end`wanabe
Notes: Merged: https://github.com/ruby/ruby/pull/3403
2020-08-16Adjust sp for `case ... in v1 ... in v2 end`wanabe
Notes: Merged: https://github.com/ruby/ruby/pull/3403
2020-08-16Adjust sp for `case ... in v1, v2 ... end`wanabe
Notes: Merged: https://github.com/ruby/ruby/pull/3403
2020-08-16Adjust sp for `case ... in pat => var ... end`wanabe
Notes: Merged: https://github.com/ruby/ruby/pull/3403
2020-08-16Adjust sp for `case ... in pat1 | pat2 ... end`wanabe
Notes: Merged: https://github.com/ruby/ruby/pull/3403
2020-08-16Adjust sp for pattern matching implicit/explicit "else"wanabe
Notes: Merged: https://github.com/ruby/ruby/pull/3403
2020-08-16Warn sp overwriting on compile timewanabe
Notes: Merged: https://github.com/ruby/ruby/pull/3401
2020-08-16Show hidden object and TS_BUILTIN for halfbaked insn datawanabe
Notes: Merged: https://github.com/ruby/ruby/pull/3401
2020-07-03Use ID instead of GENTRY for gvars. (#3278)Koichi Sasada
Use ID instead of GENTRY for gvars. Global variables are compiled into GENTRY (a pointer to struct rb_global_entry). This patch replace this GENTRY to ID and make the code simple. We need to search GENTRY from ID every time (st_lookup), so additional overhead will be introduced. However, the performance of accessing global variables is not important now a day and this simplicity helps Ractor development. Notes: Merged-By: ko1 <ko1@atdot.net>
2020-06-29compile_redo: fix wrong condition卜部昌平
Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29ibf_dump_object_object: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29compile_call: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29compile_redo: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29compile_next: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29compile_break: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29compile_branch_condition: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247