Граф коммитов

1167 Коммитов

Автор SHA1 Сообщение Дата
Vladimir Dementyev 1b89b99941
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
2021-01-19 08:34:01 +09:00
Aaron Patterson 5e26619660
Fix WB for callinfo
The WB for callinfo needs to be executed *after* the reference is
written.  Otherwise we get a WB miss.
2021-01-14 09:55:54 -08:00
Aaron Patterson efcdf68e64 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:

  70cd351c7c/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>
2021-01-13 16:13:53 -08:00
Aaron Patterson c8b47eb7c9 only add the trailing nop if the catch table is not break / next / redo
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>
2021-01-13 14:56:05 -08:00
Koichi Sasada e7fc353f04 enable constant cache on ractors
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.
2021-01-05 02:27:58 +09:00
Nobuyoshi Nakada 7156248137
Hoisted out compile_builtin_arg to refine messages 2021-01-01 23:32:07 +09:00
Nobuyoshi Nakada 0fbf4d0374
Access to reserved word parameter like as `__builtin.arg!(:if)` 2020-12-31 15:11:38 +09:00
Nobuyoshi Nakada c8010fcec0
Dup kwrest hash when merging other keyword arguments [Bug #17481] 2020-12-28 01:52:18 +09:00
Nobuyoshi Nakada d143b75f8e
Adjusted indents [ci skip] 2020-12-25 00:56:17 +09:00
John Hawthorn 40b7358e93 Skip defined check in NODE_OP_ASGN_OR with ivar
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 01b7d5acc7 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
2020-12-14 19:38:59 -08:00
Nobuyoshi Nakada 555bd83a8e
Raise when loading unprovided builtin function [Bug #17192] 2020-11-30 15:19:49 +09:00
Aaron Patterson 67b2c21c32
Add `GC.auto_compact= true/false` and `GC.auto_compact`
* `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-11-02 14:42:48 -08:00
wanabe 4f8d9b0db8 Revert "Use adjusted sp on `iseq_set_sequence()`" and "Delay `remove_unreachable_chunk()` after `iseq_set_sequence()`"
This reverts commit 3685ed7303 and 5dc107b03f.
Because of some CI failures https://github.com/ruby/ruby/pull/3404#issuecomment-719868313.
2020-10-31 11:56:41 +09:00
Nobuyoshi Nakada dd2f99d94a
Removed unused variable 2020-10-31 10:51:57 +09:00
wanabe 3685ed7303 Use adjusted sp on `iseq_set_sequence()` 2020-10-31 09:18:37 +09:00
wanabe 5dc107b03f Delay `remove_unreachable_chunk()` after `iseq_set_sequence()` 2020-10-31 09:18:37 +09:00
Nobuyoshi Nakada 799253dc46
strip trailing spaces [ci skip] 2020-10-30 12:26:59 +09:00
Koichi Sasada 07c03bc309 check isolated Proc more strictly
Isolated Proc prohibit to access outer local variables, but it was
violated by binding and so on, so they should be error.
2020-10-29 23:42:55 +09:00
Kenta Murata fb3c711df3
compile.c: separate compile_builtin_function_call (#3711) 2020-10-28 10:22:28 +09:00
Stefan Stüben 8c2e5bbf58 Don't redefine #rb_intern over and over again 2020-10-21 12:45:18 +09:00
Koichi Sasada f6661f5085 sync RClass::ext::iv_index_tbl
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.
2020-10-17 08:18:04 +09:00
wanabe 65ae7f347a Adjust sp for `if true or ...`/`if false and ...` 2020-10-16 08:37:04 +09:00
wanabe ce7a053475 Adjust sp for `x = false; y = (return until x unless x)` [Bug #16695] 2020-10-16 08:37:04 +09:00
Aaron Patterson d528254095
Add missing WB for iseq
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-07 17:01:14 -07:00
Nobuyoshi Nakada fced98f464
Added the room for builtin inline prefix 2020-10-03 12:19:56 +09:00
Nobuyoshi Nakada 5a665f6ce7
Check builtin inline function index overflow 2020-10-03 10:47:24 +09:00
Koichi Sasada 8d76b729a1 Put same frozen Range literal if possible
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)`.
2020-10-02 09:22:17 +09:00
Nobuyoshi Nakada 7b2bea42a2
Unfreeze string-literal-only interpolated string-literal
[Feature #17104]
2020-09-30 22:15:28 +09:00
Benoit Daloze 9b535f3ff7 Interpolated strings are no longer frozen with frozen-string-literal: true
* Remove freezestring instruction since this was the only usage for it.
* [Feature #17104]
2020-09-15 21:32:35 +02:00
Koichi Sasada 79df14c04b Introduce Ractor mechanism for parallel execution
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.
2020-09-03 21:11:06 +09:00
Nobuyoshi Nakada a90f29ebb2
procnames-start-lines [ci skip] 2020-08-17 14:27:34 +09:00
Nobuyoshi Nakada 352e923242
Revisit "Refactor to reduce "swap" instruction of pattern matching"
Just moved "case base" after allocating cache space.
2020-08-17 14:25:09 +09:00
Kazuhiro NISHIYAMA 5849309c5a
Revert "Refactor to reduce "swap" instruction of pattern matching"
This reverts commit 3a4be429b5.

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-17 09:28:15 +09:00
wanabe 3a4be429b5 Refactor to reduce "swap" instruction of pattern matching 2020-08-16 18:53:39 +09:00
wanabe 5c40c88a3e Adjust sp for `case ... in a: 0 ... end` 2020-08-16 18:39:08 +09:00
wanabe 691f10dd89 Adjust sp for `case ... in *, a, * end` 2020-08-16 18:39:08 +09:00
wanabe 6c407b3668 Adjust sp for `case ... in *v end`/`case ... in v1, v2 end` 2020-08-16 18:39:08 +09:00
wanabe c866d6563f Adjust sp for `case ... in v1 ... in v2 end` 2020-08-16 18:39:08 +09:00
wanabe d594078426 Adjust sp for `case ... in v1, v2 ... end` 2020-08-16 18:39:08 +09:00
wanabe 2bbb7c3d1f Adjust sp for `case ... in pat => var ... end` 2020-08-16 18:39:08 +09:00
wanabe 6bc0c6c18b Adjust sp for `case ... in pat1 | pat2 ... end` 2020-08-16 18:39:08 +09:00
wanabe 0759862458 Adjust sp for pattern matching implicit/explicit "else" 2020-08-16 18:39:08 +09:00
wanabe a7bd0ec570 Warn sp overwriting on compile time 2020-08-16 08:43:29 +09:00
wanabe ac399c2c7a Show hidden object and TS_BUILTIN for halfbaked insn data 2020-08-16 08:43:29 +09:00
Koichi Sasada a0f12a0258
Use ID instead of GENTRY for gvars. (#3278)
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.
2020-07-03 16:56:44 +09:00
卜部昌平 bacd03ebdf compile_redo: fix wrong condition 2020-06-29 11:05:41 +09:00
卜部昌平 9c92dcf366 ibf_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.
2020-06-29 11:05:41 +09:00
卜部昌平 a8d992ac00 compile_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.
2020-06-29 11:05:41 +09:00
卜部昌平 aa2cb7f722 compile_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.
2020-06-29 11:05:41 +09:00
卜部昌平 cf29de7e6e compile_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.
2020-06-29 11:05:41 +09:00