summaryrefslogtreecommitdiff
path: root/compile.c
Commit message (Collapse)AuthorAgeFilesLines
* Simplify ibf_dump_object_symbol by delegating to ibf_dump_object_stringJean Boussier2021-03-101-15/+1
|
* Pre-freeze ISeq names to avoid useless duplicationJean Boussier2021-03-101-2/+2
|
* Use rb_enc_interned_str in ibf_load_object_stringJean Boussier2021-03-101-5/+8
|
* Specialize ibf_load_object_symbol and ibf_dump_object_symbolJean Boussier2021-03-101-5/+25
|
* Eliminate useless catch tables and nops from lambdasAaron Patterson2021-02-161-0/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this commit: ``` $ ruby --dump=insn -e '1.times { |x| puts x }' == disasm: #<ISeq:<main>@-e:1 (1,0)-(1,22)> (catch: FALSE) == catch table | catch type: break st: 0000 ed: 0004 sp: 0000 cont: 0004 | == disasm: #<ISeq:block in <main>@-e:1 (1,8)-(1,22)> (catch: FALSE) | == catch table | | catch type: redo st: 0001 ed: 0006 sp: 0000 cont: 0001 | | catch type: next st: 0001 ed: 0006 sp: 0000 cont: 0006 | |------------------------------------------------------------------------ | local table (size: 1, argc: 1 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) | [ 1] x@0<Arg> | 0000 nop ( 1)[Bc] | 0001 putself [Li] | 0002 getlocal_WC_0 x@0 | 0004 opt_send_without_block <calldata!mid:puts, argc:1, FCALL|ARGS_SIMPLE> | 0006 leave [Br] |------------------------------------------------------------------------ 0000 putobject_INT2FIX_1_ ( 1)[Li] 0001 send <calldata!mid:times, argc:0>, block in <main> 0004 leave ``` After this commit: ``` > ruby --dump=insn -e '1.times { |x| puts x }' == disasm: #<ISeq:<main>@-e:1 (1,0)-(1,22)> (catch: FALSE) 0000 putobject_INT2FIX_1_ ( 1)[Li] 0001 send <calldata!mid:times, argc:0>, block in <main> 0004 leave == disasm: #<ISeq:block in <main>@-e:1 (1,8)-(1,22)> (catch: FALSE) local table (size: 1, argc: 1 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) [ 1] x@0<Arg> 0000 putself ( 1)[LiBc] 0001 getlocal_WC_0 x@0 0003 opt_send_without_block <calldata!mid:puts, argc:1, FCALL|ARGS_SIMPLE> 0005 leave ``` Fixes [ruby-core:102418] [Feature #17613] Co-Authored-By: Alan Wu <XrXr@users.noreply.github.com>
* Mark pattern labels as unremoveableVladimir Dementyev2021-01-191-1/+1
| | | | | | | | | 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
* Fix WB for callinfoAaron Patterson2021-01-141-0/+1
| | | | | The WB for callinfo needs to be executed *after* the reference is written. Otherwise we get a WB miss.
* Guard callinfoAaron Patterson2021-01-131-2/+5
| | | | | | | | | | | | | | | | 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>
* only add the trailing nop if the catch table is not break / next / redoAaron Patterson2021-01-131-5/+13
| | | | | | | | We don't need nop padding when the catch tables are only for break / next / redo, so lets avoid them. This eliminates nop padding in many lambdas. Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
* enable constant cache on ractorsKoichi Sasada2021-01-051-10/+4
| | | | | | | | | | | | | | | | 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.
* Hoisted out compile_builtin_arg to refine messagesNobuyoshi Nakada2021-01-011-12/+30
|
* Access to reserved word parameter like as `__builtin.arg!(:if)`Nobuyoshi Nakada2020-12-311-5/+24
|
* Dup kwrest hash when merging other keyword arguments [Bug #17481]Nobuyoshi Nakada2020-12-281-0/+4
|
* Adjusted indents [ci skip]Nobuyoshi Nakada2020-12-251-3/+3
|
* Skip defined check in NODE_OP_ASGN_OR with ivarJohn Hawthorn2020-12-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Raise when loading unprovided builtin function [Bug #17192]Nobuyoshi Nakada2020-11-301-4/+3
|
* Add `GC.auto_compact= true/false` and `GC.auto_compact`Aaron Patterson2020-11-021-0/+3
| | | | | | | | | | * `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]
* Revert "Use adjusted sp on `iseq_set_sequence()`" and "Delay ↵wanabe2020-10-311-43/+18
| | | | | | | `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.
* Removed unused variableNobuyoshi Nakada2020-10-311-1/+0
|
* Use adjusted sp on `iseq_set_sequence()`wanabe2020-10-311-10/+8
|
* Delay `remove_unreachable_chunk()` after `iseq_set_sequence()`wanabe2020-10-311-8/+36
|
* strip trailing spaces [ci skip]Nobuyoshi Nakada2020-10-301-1/+1
|
* check isolated Proc more strictlyKoichi Sasada2020-10-291-7/+52
| | | | | Isolated Proc prohibit to access outer local variables, but it was violated by binding and so on, so they should be error.
* compile.c: separate compile_builtin_function_call (#3711)Kenta Murata2020-10-281-80/+88
|
* Don't redefine #rb_intern over and over againStefan Stüben2020-10-211-17/+15
|
* sync RClass::ext::iv_index_tblKoichi Sasada2020-10-171-0/+2
| | | | | | | | | | | | 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.
* Adjust sp for `if true or ...`/`if false and ...`wanabe2020-10-161-2/+8
|
* Adjust sp for `x = false; y = (return until x unless x)` [Bug #16695]wanabe2020-10-161-5/+3
|
* Add missing WB for iseqAaron Patterson2020-10-071-0/+1
| | | | | | 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).
* Added the room for builtin inline prefixNobuyoshi Nakada2020-10-031-2/+3
|
* Check builtin inline function index overflowNobuyoshi Nakada2020-10-031-2/+5
|
* Put same frozen Range literal if possibleKoichi Sasada2020-10-021-2/+2
| | | | | 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)`.
* Unfreeze string-literal-only interpolated string-literalNobuyoshi Nakada2020-09-301-2/+10
| | | | [Feature #17104]
* Interpolated strings are no longer frozen with frozen-string-literal: trueBenoit Daloze2020-09-151-59/+1
| | | | | * Remove freezestring instruction since this was the only usage for it. * [Feature #17104]
* Introduce Ractor mechanism for parallel executionKoichi Sasada2020-09-031-1/+16
| | | | | | | | | | | | | | | | 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.
* procnames-start-lines [ci skip]Nobuyoshi Nakada2020-08-171-3/+6
|
* Revisit "Refactor to reduce "swap" instruction of pattern matching"Nobuyoshi Nakada2020-08-171-3/+3
| | | | Just moved "case base" after allocating cache space.
* Revert "Refactor to reduce "swap" instruction of pattern matching"Kazuhiro NISHIYAMA2020-08-171-1/+2
| | | | | | | | | | | | | | | | | | | | | 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. ```
* Refactor to reduce "swap" instruction of pattern matchingwanabe2020-08-161-2/+1
|
* Adjust sp for `case ... in a: 0 ... end`wanabe2020-08-161-0/+2
|
* Adjust sp for `case ... in *, a, * end`wanabe2020-08-161-0/+3
|
* Adjust sp for `case ... in *v end`/`case ... in v1, v2 end`wanabe2020-08-161-0/+3
|
* Adjust sp for `case ... in v1 ... in v2 end`wanabe2020-08-161-0/+3
|
* Adjust sp for `case ... in v1, v2 ... end`wanabe2020-08-161-0/+2
|
* Adjust sp for `case ... in pat => var ... end`wanabe2020-08-161-0/+1
|
* Adjust sp for `case ... in pat1 | pat2 ... end`wanabe2020-08-161-0/+1
|
* Adjust sp for pattern matching implicit/explicit "else"wanabe2020-08-161-0/+8
|
* Warn sp overwriting on compile timewanabe2020-08-161-1/+20
|
* Show hidden object and TS_BUILTIN for halfbaked insn datawanabe2020-08-161-2/+6
|
* Use ID instead of GENTRY for gvars. (#3278)Koichi Sasada2020-07-031-46/+4
| | | | | | | | | | | | 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.