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

1167 Коммитов

Автор SHA1 Сообщение Дата
Nobuyoshi Nakada 0c6f36668a
Adjusted spaces [ci skip] 2019-09-27 10:20:56 +09:00
Aaron Patterson 4808afb360
Replace `freeze_string` with `rb_fstring` 2019-09-26 13:56:42 -07:00
Aaron Patterson 0846d48853
Remove `iseq_add_mark_object_compile_time`
This function is just a synonym for RB_OBJ_WRITTEN, so we can just
directly call that.
2019-09-26 13:56:42 -07:00
Aaron Patterson e197d9ca71
Execute write barrier instead of adding to array
We can mark everything via the instruction objects, so just execute the
write barrier instead of appending to the array
2019-09-26 13:56:41 -07:00
Aaron Patterson 98d7583bfc
Pull `iseq_add_mark_object_compile_time` out of `freeze_string`
`freeze_string` essentially called iseq_add_mark_object_compile_time.  I
need to know where all writes occur on the `rb_iseq_t`, so this commit
separates the function calls so we can add write barriers in the right
place.
2019-09-26 13:56:41 -07:00
Aaron Patterson f639e04699
Pull "mark object" up
Move the "add mark object" function to the location where we should be
calling RB_OBJ_WRITTEN.  I'm going to add verification code next so we
can make sure the objects we're adding to the array are also reachable
from the mark function.
2019-09-26 13:56:41 -07:00
Aaron Patterson 50fadefb7e
Scan the ISEQ arena for markables and mark them
This commit scans the ISEQ arena for objects that can be marked and
marks them.  This should make the mark array unnecessary.
2019-09-26 13:56:41 -07:00
Aaron Patterson a618d64086
Allocate `INSN *` out of a separate arena 2019-09-26 13:56:41 -07:00
Aaron Patterson 3cd8f76f7f
Introduce a secondary arena
We'll scan the secondary arena during GC mark. So, we should only
allocate "markable" instruction linked list nodes out of the secondary
arena.
2019-09-26 13:56:41 -07:00
Aaron Patterson 451776f13d
Pass in arena to allocator
This is so we can configure a new arena later
2019-09-26 13:56:41 -07:00
Nobuyoshi Nakada e81a3e6df5
Allows calling a private method only with bare `self` 2019-09-20 22:05:54 +09:00
Nobuyoshi Nakada e6378cdcd8
Allow calling a private accessor with `self.`
[Feature #11297] [Feature #16123]
2019-09-20 02:21:37 +09:00
Dylan Thacker-Smith 7fbd2f7cc2
Allow calling a private method with `self.`
This makes it consistent with calling private attribute assignment
methods, which currently is allowed (e.g. `self.value =`).

Calling a private method in this way can be useful when trying to
assign the return value to a local variable with the same name.

[Feature #11297] [Feature #16123]
2019-09-20 02:20:59 +09:00
Nobuyoshi Nakada e13b09c450
Use EXPECT_NODE_NONULL 2019-09-19 23:45:09 +09:00
Nobuyoshi Nakada 82f25404ff
Check COMPILE_RECV result 2019-09-19 23:44:37 +09:00
NagayamaRyoga 20baa08d65 Improve the output of `RubyVM::InstructionSequence#to_binary` (#2450)
The output of RubyVM::InstructionSequence#to_binary is extremely large.
We have reduced the output of #to_binary by more than 70%.

The execution speed of RubyVM::InstructionSequence.load_from_binary is about 7% slower, but when reading a binary from a file, it may be faster than the master.

Since Bootsnap gem uses #to_binary, this proposal reduces the compilation cache size of Rails projects to about 1/4.

See details: [Feature #16163]
2019-09-19 17:35:32 +09:00
Koichi Sasada 2da6b328bb introduce IBF_(MAJOR|MINOR)_VERSION.
RubyVM::InstructionSequence.to_binary generates a bytecode binary
representation. To check compatibility with binary and loading
MRI we prepared major/minor version and compare them at loading
time. However, development version of MRI can change this format
but we can not increment minor version to make them consistent
with Ruby's major/minor versions.

To solve this issue, we introduce new minor version scheme
(binary's minor_version = ruby's minor * 10000 + dev ver)
and we can check incompatibility with older dev version.
2019-09-13 16:24:28 +09:00
Kazuhiro NISHIYAMA 0691a748b6
Fix a typo [ci skip] 2019-09-09 20:06:00 +09:00
Yusuke Endoh 46bfe907f1 compile.c (compile_hash): rewrite keyword splat handling
and add some comments.
(I confirm that `foo(**{})` allocates no hash object.)
2019-09-08 03:17:04 +09:00
Yusuke Endoh 95297a15f1 compile.c (compile_hash): rewrite the compilation algorithm
This is a similar refactoring to 8c908c9890,
but the target is compile_hash.
2019-09-08 03:17:04 +09:00
Yusuke Endoh 4f63634af1 compile.c (NODE_OP_ASGN1): Remove unneeded DECL_ANCHOR 2019-09-08 01:22:26 +09:00
Yusuke Endoh 95f9d7c76d compile.c (keyword_node_p): Refactor out keyword node checks 2019-09-08 00:28:03 +09:00
Yusuke Endoh 86b74d1a73 compile.c (compile_hash): Remove redundant check for NODE_ZLIST
NODE_ZLIST case is handled in compile_hash, so iseq_compile_each0
doesn't have to do the same check redundantly.
2019-09-08 00:28:03 +09:00
Yusuke Endoh 050f67c9c6 compile.c (compile_hash): Simplify the keyword handling
The length of NODE_LIST chain in NODE_HASH is always even because it
represents key-value pairs.  There is no need to check for the
odd-length case.
2019-09-08 00:28:03 +09:00
Yusuke Endoh bb78c83678 compile.c (compile_hash): don't add a temporal array to mark_ary
The array is just for a temporal buffer to create a hash, not stored in
the final iseq.
2019-09-08 00:28:03 +09:00
Yusuke Endoh 7cba9a8406 compile.c (compile_array): undef a temporal macro 2019-09-08 00:28:02 +09:00
git a9b63db3b6 * remove trailing spaces. [ci skip] 2019-09-07 22:22:30 +09:00
Yusuke Endoh 8c908c9890 compile.c (compile_array): rewrite the compilation algorithm
The original code looks unnecessarily complicated (to me).
Also, it creates a pre-allocated array only for the prefix of the array.

The new code optimizes not only the prefix but also the subsequence that
is longer than 0x40 elements.

    # not optimized
    10000000.times { [1+1, 1,2,3,4,...,63]    } # 2.12 sec.
    # (1+1; push 1; push 2; ...; puts 63; newarray 64; concatarray)

    # optimized
    10000000.times { [1+1, 1,2,3,4,...,63,64] } # 1.46 sec.
    # (1+1; newarray 1; putobject [1,2,3,...,64]; concatarray)
2019-09-07 22:08:39 +09:00
Yusuke Endoh 07876bf6db compile.c (compile_hash): refactoring
The same refactoring as to b601b13c7267889bf394146353c5f2b0eb488278.
2019-09-07 20:25:12 +09:00
Yusuke Endoh 187328b703 compile.c (compile_array): refactoring
"popped" case can be so simple, so this change moves the branch to the
first, instead of scattering `if (popped)` branches to the main part.
Also, the return value "len" is not used.  So it returns just 0 or 1.
2019-09-07 20:25:12 +09:00
Yusuke Endoh a2260bd636 compile.c: Separate compile_list to two functions for Array and Hash
compile_list was for the compilation of Array literal and Hash literal.
I guess it was originally reasonable to handle them in one function, but
now, compilation of Array is very different from Hash.  So the function
was complicated by many branches for Array and Hash.

This change separates the function to two ones for Array and Hash.
2019-09-07 16:45:49 +09:00
Yusuke Endoh 2f2f8107d0 compile.c (compile_list): allow an odd-length hidden array literal
An array literal [1,2,...,301] was compiled to the following iseq:

  duparray [1,2,...,300]
  putobject [301]
  concatarray

The Array literal optimization took every two elements maybe because it
must handle not only Array but also Hash.
Now the optimization takes each element if it is an Array literal.  So
the new iseq is: duparray [1,2,...,301].
2019-09-07 16:26:38 +09:00
Yusuke Endoh 1e008105bc compile.c (compile_list): emit newarraykwsplat only at the last chunk
`[{}, {}, {}, ..., {}, *{}]` is wrongly created.

A big array literal is created and concatenated for every 256 elements.
The newarraykwsplat must be emitted only at the last chunk.
2019-09-07 16:05:15 +09:00
Yusuke Endoh a7a2be7a31 Rename some function/definition names that handles NODE_LIST
from array to list.
Follow up to ac50ac03aeb210763730cdc45f230e236519223d
2019-09-07 13:56:41 +09:00
Yusuke Endoh 99c9431ea1 Rename NODE_ARRAY to NODE_LIST to reflect its actual use cases
and NODE_ZARRAY to NODE_ZLIST.

NODE_ARRAY is used not only by an Array literal, but also the contents
of Hash literals, method call arguments, dynamic string literals, etc.
In addition, the structure of NODE_ARRAY is a linked list, not an array.

This is very confusing, so I believe `NODE_LIST` is a better name.
2019-09-07 13:56:29 +09:00
Jeremy Evans 1d5066efb0 Make m(**{}) mean call without keywords
Previously, **{} was removed by the parser:

```
$ ruby --dump=parse -e '{**{}}'
 @ NODE_SCOPE (line: 1, location: (1,0)-(1,6))
 +- nd_tbl: (empty)
 +- nd_args:
 |   (null node)
 +- nd_body:
     @ NODE_HASH (line: 1, location: (1,0)-(1,6))*
     +- nd_brace: 1 (hash literal)
     +- nd_head:
         (null node)
```

Since it was removed by the parser, the compiler did not know
about it, and `m(**{})` was therefore treated as `m()`.

This modifies the parser to not remove the `**{}`.  A simple
approach for this is fairly simple by just removing a few
lines from the parser, but that would cause two hash
allocations every time it was used.  The approach taken here
modifies both the parser and the compiler, and results in `**{}`
not allocating any hashes in the usual case.

The basic idea is we use a literal node in the parser containing
a frozen empty hash literal.  In the compiler, we recognize when
that is used, and if it is the only keyword present, we just
push it onto the VM stack (no creation of a new hash or merging
of keywords).  If it is the first keyword present, we push a
new empty hash onto the VM stack, so that later keywords can
merge into it.  If it is not the first keyword present, we can
ignore it, since the there is no reason to merge an empty hash
into the existing hash.

Example instructions for `m(**{})`

Before (note ARGS_SIMPLE):

```
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,7)> (catch: FALSE)
0000 putself                                                          (   1)[Li]
0001 opt_send_without_block       <callinfo!mid:m, argc:0, FCALL|ARGS_SIMPLE>, <callcache>
0004 leave
```

After (note putobject and KW_SPLAT):

```
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,7)> (catch: FALSE)
0000 putself                                                          (   1)[Li]
0001 putobject                    {}
0003 opt_send_without_block       <callinfo!mid:m, argc:1, FCALL|KW_SPLAT>, <callcache>
0006 leave
```

Example instructions for `m(**h, **{})`

Before and After (no change):

```
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,12)> (catch: FALSE)
0000 putself                                                          (   1)[Li]
0001 putspecialobject             1
0003 newhash                      0
0005 putself
0006 opt_send_without_block       <callinfo!mid:h, argc:0, FCALL|VCALL|ARGS_SIMPLE>, <callcache>
0009 opt_send_without_block       <callinfo!mid:core#hash_merge_kwd, argc:2, ARGS_SIMPLE>, <callcache>
0012 opt_send_without_block       <callinfo!mid:m, argc:1, FCALL|KW_SPLAT>, <callcache>
0015 leave
```

Example instructions for `m(**{}, **h)`

Before:

```
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,12)> (catch: FALSE)
0000 putself                                                          (   1)[Li]
0001 putspecialobject             1
0003 newhash                      0
0005 putself
0006 opt_send_without_block       <callinfo!mid:h, argc:0, FCALL|VCALL|ARGS_SIMPLE>, <callcache>
0009 opt_send_without_block       <callinfo!mid:core#hash_merge_kwd, argc:2, ARGS_SIMPLE>, <callcache>
0012 opt_send_without_block       <callinfo!mid:m, argc:1, FCALL|KW_SPLAT>, <callcache>
0015 leave
```

After (basically the same except for the addition of swap):

```
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,12)> (catch: FALSE)
0000 putself                                                          (   1)[Li]
0001 newhash                      0
0003 putspecialobject             1
0005 swap
0006 putself
0007 opt_send_without_block       <callinfo!mid:h, argc:0, FCALL|VCALL|ARGS_SIMPLE>, <callcache>
0010 opt_send_without_block       <callinfo!mid:core#hash_merge_kwd, argc:2, ARGS_SIMPLE>, <callcache>
0013 opt_send_without_block       <callinfo!mid:m, argc:1, FCALL|KW_SPLAT>, <callcache>
0016 leave
```
2019-09-05 09:57:43 -07:00
Takashi Kokubun beaabd2308
Unify SUPPORT_JOKE and OPT_SUPPORT_JOKE
for simplicity and consistency.

Now SUPPORT_JOKE needs to be prefixed with OPT_ to make the config
visible in `RubyVM::VmOptsH`, and the inconsistency was introduced.

As it has never been available for override in configure (no #ifndef
guard), it should be fine to rename the config.
2019-09-03 21:12:31 +09:00
Jeremy Evans f560609d66
Merge pull request #2418 from jeremyevans/array-empty-kwsplat
Ignore empty keyword splats in arrays
2019-09-02 08:21:30 -07:00
Takashi Kokubun ca8ae759d0
Fix compilation error in SUPPORT_JOKE
This seems to have been broken since 4e15be8bad.
2019-09-02 23:37:52 +09:00
Urabe, Shyouhei 8ad7fafcdd opt_regexpmatch1 is actually making things slower.
----

trunk: ruby 2.6.0dev (2018-09-18 trunk 64767) [x86_64-darwin15]
ours: ruby 2.6.0dev (2018-09-18 opt_regexpmatch 64775) [x86_64-darwin15]
last_commit=opt_regexpmatch1 is actually making things slower.
Calculating -------------------------------------
                              trunk        ours
Optcarrot Lan_Master.nes     33.877      35.282 fps

Comparison:
             Optcarrot Lan_Master.nes
                    ours:        35.3 fps
                   trunk:        33.9 fps - 1.04x  slower
2019-09-02 13:56:40 +09:00
Kazuki Tsujimoto 94d6ec1d90
Make pattern matching support **nil syntax 2019-09-01 16:39:34 +09:00
Jeremy Evans 6a9ce1fea8 Support **nil syntax for specifying a method does not accept keyword arguments
This syntax means the method should be treated as a method that
uses keyword arguments, but no specific keyword arguments are
supported, and therefore calling the method with keyword arguments
will raise an ArgumentError.  It is still allowed to double splat
an empty hash when calling the method, as that does not pass
any keyword arguments.
2019-08-30 12:39:31 -07:00
Yusuke Endoh 16c6984bb9 Separate keyword arguments from positional arguments
And, allow non-symbol keys as a keyword arugment
2019-08-30 12:39:31 -07:00
卜部昌平 50f5a0a8d6 rb_hash_foreach now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit adds function prototypes
for rb_hash_foreach / st_foreach_safe.  Also fixes some prototype
mismatches.
2019-08-27 15:52:26 +09:00
卜部昌平 b8fd2e83e7 decouple compile.c usage of imemo_ifunc
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit deletes ANYARGS from
struct vm_ifunc, but in doing so we also have to decouple the usage
of this struct in compile.c, which (I think) is an abuse of ANYARGS.
2019-08-27 15:52:26 +09:00
Yusuke Endoh d53b669948 compile.c: remove const from the first argument of dladdr
Unfortunately, dladdr accepts void*, not const void*, in Solaris.
2019-08-27 14:05:20 +09:00
Jeremy Evans 661927a4c5 Switch to using a VM stack argument instead of 2nd operand for getconstant
Some tooling depends on the current bytecode, and adding an operand
changes the bytecode.  While tooling can be updated for new bytecode,
this support doesn't warrant such a change.
2019-08-14 11:22:07 -07:00
Jeremy Evans 6ac6de84ac Use Qtrue/Qfalse instead of 1/0 for 2nd operand to getconstant
Fixes error when using -Werror,-Wshorten-64-to-32.
2019-08-14 09:59:27 -07:00
git d053a57014 * expand tabs. [ci skip] 2019-08-15 01:51:19 +09:00
Jeremy Evans fbcd065294 Remove support for nil::Constant
This was an intentional bug added in 1.9.

The approach taken here is to add a second operand to the
getconstant instruction for whether nil should be allowed and
treated as current scope.

Fixes [Bug #11718]
2019-08-14 09:50:14 -07:00
git 57288f5dbd * expand tabs. 2019-08-09 01:32:30 +09:00
Alan Wu 050b932152
Iseq#to_binary: Add support for NoMatchingPatternError and TypeError
Binary dumping the iseq for `case foo in []; end` used to crash as
there was no handling for these exception classes.

Pattern matching generates these classes as operands to `putobject`.

[Bug #16088]
Closes: https://github.com/ruby/ruby/pull/2325
2019-08-09 01:29:53 +09:00
Nobuyoshi Nakada 830fd04181
C99 allows trailing comma in enum 2019-08-09 01:27:52 +09:00
Yusuke Endoh 086ffe72c7 Revert "Revert "Add a specialized instruction for `.nil?` calls""
This reverts commit a0980f2446.

Retry for macOS Mojave.
2019-08-02 23:25:38 +09:00
Yusuke Endoh a0980f2446 Revert "Add a specialized instruction for `.nil?` calls"
This reverts commit 9faef3113f.

It seemed to cause a failure on macOS Mojave, though I'm unsure how.
https://rubyci.org/logs/rubyci.s3.amazonaws.com/osx1014/ruby-master/log/20190802T034503Z.fail.html.gz

This tentative revert is to check if the issue is actually caused by the
change or not.
2019-08-02 15:03:34 +09:00
git 714924fd34 * expand tabs. 2019-08-01 08:21:58 +09:00
Aaron Patterson 9faef3113f
Add a specialized instruction for `.nil?` calls
This commit adds a specialized instruction for called to `.nil?`.  It is
about 27% faster than master in the case where the object is nil or not
nil.  In the case where an object implements `nil?`, I think it may be
slightly slower.  Here is a benchmark:

```ruby
require "benchmark/ips"

class Niller
  def nil?; true; end
end

not_nil = Object.new
xnil = nil
niller = Niller.new

Benchmark.ips do |x|
  x.report("nil?")    { xnil.nil? }
  x.report("not nil") { not_nil.nil? }
  x.report("niller")   { niller.nil? }
end
```

On Ruby master:

```
[aaron@TC ~/g/ruby (master)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   429.195k i/100ms
             not nil   437.889k i/100ms
              niller   437.935k i/100ms
Calculating -------------------------------------
                nil?     20.166M (± 8.1%) i/s -    100.002M in   5.002794s
             not nil     20.046M (± 7.6%) i/s -     99.839M in   5.020086s
              niller     22.467M (± 6.1%) i/s -    112.111M in   5.013817s
[aaron@TC ~/g/ruby (master)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   449.660k i/100ms
             not nil   433.836k i/100ms
              niller   443.073k i/100ms
Calculating -------------------------------------
                nil?     19.997M (± 8.8%) i/s -     99.375M in   5.020458s
             not nil     20.529M (± 7.0%) i/s -    102.385M in   5.020689s
              niller     21.796M (± 8.0%) i/s -    108.110M in   5.002300s
[aaron@TC ~/g/ruby (master)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   402.119k i/100ms
             not nil   438.968k i/100ms
              niller   398.226k i/100ms
Calculating -------------------------------------
                nil?     20.050M (±12.2%) i/s -     98.519M in   5.008817s
             not nil     20.614M (± 8.0%) i/s -    102.280M in   5.004531s
              niller     22.223M (± 8.8%) i/s -    110.309M in   5.013106s

```

On this branch:

```
[aaron@TC ~/g/ruby (specialized-nilp)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   468.371k i/100ms
             not nil   456.517k i/100ms
              niller   454.981k i/100ms
Calculating -------------------------------------
                nil?     27.849M (± 7.8%) i/s -    138.169M in   5.001730s
             not nil     26.417M (± 8.7%) i/s -    131.020M in   5.011674s
              niller     21.561M (± 7.5%) i/s -    107.376M in   5.018113s
[aaron@TC ~/g/ruby (specialized-nilp)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   477.259k i/100ms
             not nil   428.712k i/100ms
              niller   446.109k i/100ms
Calculating -------------------------------------
                nil?     28.071M (± 7.3%) i/s -    139.837M in   5.016590s
             not nil     25.789M (±12.9%) i/s -    126.470M in   5.011144s
              niller     20.002M (±12.2%) i/s -     98.144M in   5.001737s
[aaron@TC ~/g/ruby (specialized-nilp)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   467.676k i/100ms
             not nil   445.791k i/100ms
              niller   415.024k i/100ms
Calculating -------------------------------------
                nil?     26.907M (± 8.0%) i/s -    133.755M in   5.013915s
             not nil     25.319M (± 7.9%) i/s -    125.713M in   5.007758s
              niller     19.569M (±11.8%) i/s -     96.286M in   5.008533s
```

Co-Authored-By: Ashe Connor <kivikakk@github.com>
2019-07-31 16:21:25 -07:00
Jeremy Evans aa97410b0a Warn if using return at top-level with an argument
Fixes [Bug #14062]
2019-07-29 09:01:23 -07:00
git bdec1ad9a9 * expand tabs. 2019-07-17 23:42:21 +09:00
Yusuke Endoh 416ead4cda compile.c: add NO_CHECK for the calls to COMPILE whose result is unused
to suppress many warnings of Coverity Scan
2019-07-17 23:41:58 +09:00
git a8e4b7b12f * expand tabs. 2019-07-16 07:19:52 +09:00
Yusuke Endoh c184a1c261 compile.c: add NO_CHECK for the calls to COMPILE whose result is unused
to suppress many warnings of Coverity Scan
2019-07-16 07:18:54 +09:00
Yusuke Endoh 6aab77a7a3 Add a /* fall through */ comment 2019-07-16 07:17:57 +09:00
git f103ed8b7d * expand tabs. 2019-07-15 14:43:39 +09:00
Yusuke Endoh 4b345f9d4b compile.c: ignore the result of COMPILE by marking with NO_CHECK
to suppress many warnings of Coverity Scan
2019-07-15 14:43:24 +09:00
Yusuke Endoh c9a59f491d Add a /* fall through */ comment 2019-07-15 07:59:11 +09:00
Yusuke Endoh 772dae8bef Add a /* fall through */ comment 2019-07-15 07:57:07 +09:00
Yusuke Endoh 3201062adf Add a /* fall through */ comment 2019-07-15 00:31:07 +09:00
Yusuke Endoh 970c12551e Add a /* fall through */ comment 2019-07-15 00:30:35 +09:00
Yusuke Endoh 09187c64b8 Add a /* fall through */ comment 2019-07-15 00:10:39 +09:00
git 83153bbb14 * expand tabs. 2019-07-14 16:18:48 +09:00
Yusuke Endoh 73fab16e76 compile.c (defined_expr): return void instead of int
It always returned 1.
2019-07-14 16:18:32 +09:00
Jeremy Evans f296c260ef Fix segfault when using method reference operator without using result
Fixes [Bug #15985]
2019-07-05 20:43:38 -07:00
git d4929f5185 * expand tabs. 2019-06-16 23:01:46 +09:00
Yusuke Endoh 1ff26dc4c7 Revert "Make constant assignments more conforming to JIS X 3017:2013 11.4.2.2.3"
This reverts commit 44caca11cf.

The change caused a build failure.
http://ci.rvm.jp/results/trunk-vm-asserts@silicon-docker/2102153
2019-06-16 23:00:05 +09:00
git 11f8c89171 * expand tabs. 2019-06-16 22:48:23 +09:00
Yuki Yugui Sonoda 44caca11cf Make constant assignments more conforming to JIS X 3017:2013 11.4.2.2.3
compile.c (NODE_CDECL): Evaluate the module before the value
test/ruby/test_const.rb (test_evaluation_order): added a test case
2019-06-16 22:43:03 +09:00
Kazuki Tsujimoto be6b462489
Use checktype for performance 2019-06-11 00:20:10 +09:00
Yusuke Endoh a6a26e42b1 compile.c: Partially revert r63870 which caused wrong optimization
[Bug #15906]
2019-06-07 14:46:59 +09:00
Martin Dürst f258137083 Fix grammar of macro name: ECCESSED -> ECCESSIVE
Fix the name of the macro variable introduced in 0872ea5330
from NODE_SPECIAL_EXCESSED_COMMA to NODE_SPECIAL_EXCESSIVE_COMMA.
2019-06-05 14:03:50 +09:00
git b31e1b4a7c * expand tabs. 2019-06-04 23:17:38 +09:00
Yusuke Endoh 0b0c6cb7e4 compile.c: Remove the magical `(const NODE*) -1`
It is used to represent "no default expression" for keyword argument:
`def foo(key:)`.  This change uses NODE_SPECIAL_REQUIRED_KEYWORD.
2019-06-04 23:17:19 +09:00
Yusuke Endoh 0872ea5330 node.h: Avoid a magic number to represent excessed comma
`(ID)1` was assigned to NODE_ARGS#rest_arg for `{|x,| }`.
This change removes the magic number by introducing an explicit macro
variable for it: NODE_SPECIAL_EXCESSED_COMMA.
2019-06-04 23:17:18 +09:00
Nobuyoshi Nakada b1aecef873
Use UNALIGNED_MEMBER_PTR
* internal.h (UNALIGNED_MEMBER_ACCESS, UNALIGNED_MEMBER_PTR):
  moved from eval_intern.h.

* compile.c iseq.c, vm.c: use UNALIGNED_MEMBER_PTR for `entries`
  in `struct iseq_catch_table`.

* vm_eval.c, vm_insnhelper.c: use UNALIGNED_MEMBER_PTR for `body`
  in `rb_method_definition_t`.
2019-05-31 16:04:16 +09:00
git f1b52d3a88 * expand tabs. 2019-05-05 11:13:54 +09:00
Nobuyoshi Nakada ff21e75d32
parse.y: duplicated when clause warning
* parse.y (case_args): moved "duplicated when clause" warning from
  compile phase, so that `ruby -wc` shows them.
2019-05-05 00:29:12 +09:00
Lourens Naudé 99084f5401 Lazy allocate the compile data catch table array
Closes: https://github.com/ruby/ruby/pull/2119
2019-04-25 12:37:29 +09:00
ktsj eeee4f404b Remove unnecessary condition
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67653 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-21 02:18:28 +00:00
ktsj 243842f68a Avoid usage of the dummy empty BEGIN node
Use NODE_SPECIAL_NO_NAME_REST instead.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67629 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-20 03:37:22 +00:00
ktsj 9738f96fcf Introduce pattern matching [EXPERIMENTAL]
[ruby-core:87945] [Feature #14912]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-17 06:48:03 +00:00
nobu 025343654d Get rid of a magic number
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67512 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-11 10:36:37 +00:00
nobu 47c82df27f Share the exception local ID table
[Fix GH-2115]

From: Lourens Naudé <lourens@bearmetal.eu>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67511 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-11 10:36:36 +00:00
nobu 54b93ef1ac compile.c: name a hidden local variable as a predefined ID
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67505 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 12:43:34 +00:00
kazu 25c1fd3b90 Reverting all commits from r67479 to r67496 because of CI failures
Because hard to specify commits related to r67479 only.
So please commit again.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 09:15:21 +00:00
nobu 91db3b6c6b compile.c: name a hidden local variable as a predefined ID
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67496 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 07:18:25 +00:00
nobu 9e448d2fd7 compile.c: cast iseqs to suppress warnings
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67490 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 01:18:01 +00:00
tenderlove d099eabbb7 Set a write barrier between iseq and mark objects
ISeq pins references in the mark array during compile, so it manually
marks references in the mark_ary.  This was causing write barrier
misses, so we need to add a write barrier when pushing on the mark
array.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67489 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-09 23:48:17 +00:00
svn 4b53f84326 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67443 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-05 08:15:21 +00:00
ko1 2b5bb8a087 add definemethod/definesmethod insn.
* insns.def: add definemethod and definesmethod (singleton method)
  instructions. Old YARV contains these instructions, but it is moved
  to methods of FrozenCore class because remove number of instructions
  can improve performance for some techniques (static stack caching
  and so on). However, we don't employ these technique and it is hard
  to optimize/analysis definition sequence. So I decide to introduce
  them (and remove definition methods). `putiseq` insn is also removed.

* vm_method.c (rb_scope_visibility_get): renamed to
  `vm_scope_visibility_get()` and make it accept `ec`.
  Same for `vm_scope_module_func_check()`.
  These fixes are result of refactoring `vm_define_method`.

* vm_insnhelper.c (rb_vm_get_cref): renamed to `vm_get_cref`
  because of consistency with other functions.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67442 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-05 08:15:11 +00:00
svn d4f7fac6b8 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67267 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-15 05:19:58 +00:00
mame c36a6f97f2 node.h: introduce nd_brace to determine if a hash literal is a keyword
NODE_HASH#nd_brace is a flag that is 1 for `foo({ k: 1 })` and 0 for
`foo(k: 1)`.
nd_alen had been abused for the flag (and the implementation is
completely the same), but an explicit name is better to read.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67266 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-15 05:19:54 +00:00
mame 3db2041f87 compile.c: fix the corner case of rest and keyword arguments
See https://bugs.ruby-lang.org/issues/10856#note-20 . [Bug #10856]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67256 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-14 09:04:57 +00:00
mame 146bb252a0 compile.c (setup_args): process arguments forward
For unknown reason, setup_args processed the arguments from the last to
the first.  This is not only difficult to read, but also inefficient in
some cases.  For example, the arguments of `foo(*a1, *a2, *a3)` was
compiled like `a1.dup << (a2.dup << a3)`.  The second dup (`a2.dup`) is
not needed.

This change refactors the function so that it processes the arguments
forward: `foo(*a1, *a2, *a3)` is compiled as `a1.dup << a2 << a3`, and
in my opinion, the source code is now much more readable.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-14 08:43:51 +00:00
svn 277af37b42 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67253 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-14 06:43:54 +00:00
mame 4c41dc8945 compile.c: factor out "compile_args" from "compile_array"
compile_array function had three usages: array literal, hash literal,
and method arguments. I think the third is completely different than the
first and second.  For example, method arguments and popped are
meaningless; keywords_ptr and flag parameter for array/hash literal is
also unused.

This change refactors them: a function "compile_args" is created for the
third, and removes no longer used parameters of "compile_array".

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67252 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-14 06:43:50 +00:00
svn 6703277024 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67114 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-21 20:59:12 +00:00
ko1 4e15be8bad refactoring compile.c.
* compile.c: refacetoring:
  * initialize `branches` with Qfalse intead of 0.
  * make compile_call* functions from `iseq_compile_each0()`
    to make modifying them easy.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67113 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-21 20:59:08 +00:00
nobu df2b8c05ba Show proper location for warning [Feature #15575]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67001 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-04 08:13:37 +00:00
ko1 0fc597f29c check and show a warning for incorrect yield.
* compile.c (check_yield_place): this function check the yield location.
  * show a warning if yield in `class` syntax. [Feature #15575]

  * do strict check for toplevel `yield`. Without this patch,
    `1.times{ yield }` in toplevel is valid-syntax (raise LocalJumpError
    at runtime) although toplevel simple `yield` is not valid syntax.
    This patch make them syntax error.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66999 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-04 07:10:05 +00:00
svn 8555c53e74 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-01 05:11:14 +00:00
nobu 1bc6c3f407 Revert r63383, r63248 "compile.c: copy a short insn with leave"
When copying `leave` insn, TRACE also should be copied if it is
present, but this optimization is trivial and not worth the
complexity.  [ruby-core:91366] [Bug #15578]

4cae5353c0
5afd479de6

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-01 05:11:08 +00:00
nobu 78d6e33702 Fix styles [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-09 13:58:49 +00:00
nobu b6b4c7cbb4 compile.c: initialize to suppress false warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-05 14:31:12 +00:00
nobu 4783493236 parse.y: hoisted out qcall_branch_start and qcall_branch_end
* compile.c (qcall_branch_start, qcall_branch_end): hoisted out
  branch coverage traces generation for qcall.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66723 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-05 12:13:39 +00:00
svn f77d381159 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-01 03:03:20 +00:00
mame 9613af6f34 compile.c (iseq_set_sequence): fix branch coverage table
Not only TRACE_ELEMENT but also INSN_ELEMENT may have events.
The old pc2branchindex was created using only events of TRACE_ELEMENTs.
This change uses events of INSN_ELEMENTs too for pc2branchindex table.

[Bug #15476]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66676 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-01 03:03:17 +00:00
svn 99d3631847 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-01 01:51:01 +00:00
mame d58bada6cc compile.c: support branch coverage for `a&.foo = 1`
[Bug #15475]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-01 01:50:57 +00:00
svn 7e035dcda7 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66673 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-01 01:47:17 +00:00
mame 4130969ea1 Revert r66670 because of wrong ticket number
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-01 01:47:14 +00:00
svn 04dec2df73 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66671 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-01 01:41:26 +00:00
mame 67a257cac0 compile.c: support branch coverage for `a&.foo = 1`
[Bug #15476]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-01 01:41:23 +00:00
nobu 67c5747369 Method reference operator
Introduce the new operator for method reference, `.:`.
[Feature #12125] [Feature #13581]
[EXPERIMENTAL]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-31 15:00:37 +00:00
svn 4a6f763330 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-31 14:59:32 +00:00
nobu 705941a492 use a local variable
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66664 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-31 14:59:27 +00:00
ko1 2a70f68c05 hide iseq operand object for duphash. [Bug #15440]
* compile.c (compile_array): hide source Hash object.

* hash.c (rb_hash_resurrect): introduced to dup Hash object
  using rb_cHash.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-20 07:17:55 +00:00
nobu ec7b1e475b Freeze hash literals embedded in duphash instructions
Previously, these hash literals were not frozen, and thus could be
modified by ObjectSpace, resulting in undesired behavior.  Example:

```ruby
require 'objspace'

def a(b={0=>1,1=>4,2=>17})
  b
end

p a
ObjectSpace.each_object(Hash) do |a|
  a[3] = 8 if a.class == Hash && a[0] == 1 && a[1] == 4 && a[2] == 17
end
p a
```

It may be desirable to hide such hashes from ObjectSpace, since
they are internal, but I'm not sure how to do that.

From: Jeremy Evans <code@jeremyevans.net>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66464 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-20 06:44:50 +00:00
tenderlove 589042c063 Don't increment `code_index`
`code_index` doesn't need to be incremented since the mark array has
been removed.  Thanks for the patch ko1!

[ruby-core:90456] [Bug #15406]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-13 03:01:18 +00:00
ko1 447b4dae6f param.flags.has_kw flag should be FALSE before setting param.keyword.
* compile.c (ibf_load_iseq_each): iseq_mark assumes that if
  param.flags.has_kw is TRUE, then param.keyword is not NULL.
  To confirm this assumption, make it FALSE before param.keyword
  is initialized.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66367 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-12 17:12:08 +00:00
ko1 8f0a0f4018 restore `catch_except_p` flag.
* compile.c: we need to restore `catch_except_p` flag at
  `load_from_binary`. [Bug #15395]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66366 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-12 15:59:49 +00:00
nobu b91599c48b Fix infinite loop by ensure
* compile.c (iseq_insert_nop_between_end_and_cont): insert nop so
  that the end of rescue and continuing points are not same, to
  get rid of infinite loop.  [Bug #15385]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66326 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-11 04:14:31 +00:00
svn 8e9aa75df1 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66325 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-11 04:13:13 +00:00
nobu 28eb147484 Modify insn list only when compiling
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66324 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-11 04:13:09 +00:00
nobu a2bc831e15 raise instead of rb_bug
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-09 01:34:23 +00:00
svn 2f1c9e2ac1 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06 18:28:26 +00:00
tenderlove 2f37847820 Speed up hash literals by duping
This commit replaces the `newhashfromarray` instruction with a `duphash`
instruction.  Instead of allocating a new hash from an array stored in
the Instruction Sequences, store a hash directly in the instruction
sequences and dup it on execution.

== Instruction sequence changes ==

```ruby
code = <<-eorby
  { "foo" => "bar", "baz" => "lol" }
eorby

insns = RubyVM::InstructionSequence.compile(code, __FILE__, nil, 0, frozen_string_literal: true)
puts insns.disasm
```

On Ruby 2.5:

```
== disasm: #<ISeq:<compiled>@test.rb:0 (0,0)-(0,36)>====================
0000 putobject        "foo"
0002 putobject        "bar"
0004 putobject        "baz"
0006 putobject        "lol"
0008 newhash          4
0010 leave
```

Ruby 2.6@r66174 3b6321083a2e3525da3b34d08a0b68bac094bd7f:

```
$ ./ruby test.rb
== disasm: #<ISeq:<compiled>@test.rb:0 (0,0)-(0,36)> (catch: FALSE)
0000 newhashfromarray             2, ["foo", "bar", "baz", "lol"]
0003 leave
```

Ruby 2.6 + This commit:

```
$ ./ruby test.rb
== disasm: #<ISeq:<compiled>@test.rb:0 (0,0)-(0,36)> (catch: FALSE)
0000 duphash                      {"foo"=>"bar", "baz"=>"lol"}
0002 leave
```

== Benchmark Results ==

Compared to 2.5.3:

```
$ make benchmark ITEM=hash_literal_small COMPARE_RUBY=/Users/aaron/.rbenv/versions/2.5.3/bin/ruby
generating known_errors.inc
known_errors.inc unchanged
./revision.h unchanged
/Users/aaron/.rbenv/shims/ruby --disable=gems -rrubygems -I./benchmark/lib ./benchmark/benchmark-driver/exe/benchmark-driver \
	            --executables="compare-ruby::/Users/aaron/.rbenv/versions/2.5.3/bin/ruby -I.ext/common --disable-gem" \
	            --executables="built-ruby::./miniruby -I./lib -I. -I.ext/common  -r./prelude --disable-gem" \
	            $(find ./benchmark -maxdepth 1 -name '*hash_literal_small*.yml' -o -name '*hash_literal_small*.rb' | sort)
Calculating -------------------------------------
                     compare-ruby  built-ruby
 hash_literal_small2        1.498       1.877 i/s -       1.000 times in 0.667581s 0.532656s
 hash_literal_small4        1.197       1.642 i/s -       1.000 times in 0.835375s 0.609160s
 hash_literal_small8        0.620       1.215 i/s -       1.000 times in 1.611638s 0.823090s

Comparison:
              hash_literal_small2
          built-ruby:         1.9 i/s
        compare-ruby:         1.5 i/s - 1.25x  slower

              hash_literal_small4
          built-ruby:         1.6 i/s
        compare-ruby:         1.2 i/s - 1.37x  slower

              hash_literal_small8
          built-ruby:         1.2 i/s
        compare-ruby:         0.6 i/s - 1.96x  slower
```

Compared to r66255

```
$ make benchmark ITEM=hash_literal_small COMPARE_RUBY=/Users/aaron/.rbenv/versions/ruby-trunk/bin/ruby
generating known_errors.inc
known_errors.inc unchanged
./revision.h unchanged
/Users/aaron/.rbenv/shims/ruby --disable=gems -rrubygems -I./benchmark/lib ./benchmark/benchmark-driver/exe/benchmark-driver \
	            --executables="compare-ruby::/Users/aaron/.rbenv/versions/ruby-trunk/bin/ruby -I.ext/common --disable-gem" \
	            --executables="built-ruby::./miniruby -I./lib -I. -I.ext/common  -r./prelude --disable-gem" \
	            $(find ./benchmark -maxdepth 1 -name '*hash_literal_small*.yml' -o -name '*hash_literal_small*.rb' | sort)
Calculating -------------------------------------
                     compare-ruby  built-ruby
 hash_literal_small2        1.567       1.831 i/s -       1.000 times in 0.638056s 0.546039s
 hash_literal_small4        1.298       1.652 i/s -       1.000 times in 0.770214s 0.605182s
 hash_literal_small8        0.873       1.216 i/s -       1.000 times in 1.145304s 0.822047s

Comparison:
              hash_literal_small2
          built-ruby:         1.8 i/s
        compare-ruby:         1.6 i/s - 1.17x  slower

              hash_literal_small4
          built-ruby:         1.7 i/s
        compare-ruby:         1.3 i/s - 1.27x  slower

              hash_literal_small8
          built-ruby:         1.2 i/s
        compare-ruby:         0.9 i/s - 1.39x  slower
```

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66258 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06 18:28:21 +00:00
svn a13b1f507b * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66175 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03 23:53:16 +00:00
tenderlove 3b6321083a Collapse putobject, putobject, newarray
This collapses:

```
== disasm: #<ISeq:bar@bench.rb:3 (3,0)-(5,3)> (catch: FALSE)
0000 putobject                    "a"                                 (   4)[LiCa]
0002 putobject                    "b"
0004 putobject                    "c"
0006 putobject                    "d"
0008 putobject                    "e"
0010 putobject                    "f"
0012 putobject                    "g"
0014 putobject                    "h"
0016 putobject                    "i"
0018 putobject                    "j"
0020 putobject                    "k"
0022 newarray                     11
0024 leave                                                            (   5)[Re]
```

In to this:

```
== disasm: #<ISeq:bar@bench.rb:3 (3,0)-(5,3)> (catch: FALSE)
0000 duparray                     ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"](   4)[LiCa]
0002 leave                                                            (   5)[Re]
```

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66174 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03 23:53:11 +00:00
tenderlove 5d3aa0ac58 Revert "Collapse putobject, putobject, newarray"
This reverts commit cbdf5a1842.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66109 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-01 00:08:36 +00:00
svn f86b49c162 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-30 23:58:17 +00:00
tenderlove cbdf5a1842 Collapse putobject, putobject, newarray
This collapses:

```
== disasm: #<ISeq:bar@bench.rb:3 (3,0)-(5,3)> (catch: FALSE)
0000 putobject                    "a"                                 (   4)[LiCa]
0002 putobject                    "b"
0004 putobject                    "c"
0006 putobject                    "d"
0008 putobject                    "e"
0010 putobject                    "f"
0012 putobject                    "g"
0014 putobject                    "h"
0016 putobject                    "i"
0018 putobject                    "j"
0020 putobject                    "k"
0022 newarray                     11
0024 leave                                                            (   5)[Re]
```

In to this:

```
== disasm: #<ISeq:bar@bench.rb:3 (3,0)-(5,3)> (catch: FALSE)
0000 duparray                     ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"](   4)[LiCa]
0002 leave                                                            (   5)[Re]
```

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66106 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-30 23:58:13 +00:00
svn a1c4e0c96b * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66026 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-27 07:34:25 +00:00
mame b7561dafb9 compile.c: prevent out-of-bound initialization of coverage counters
The coverage counters is initialized with `counter[lineno - 1] = 0`,
but lineno may be 0, which led to write access for index -1.
[ruby-core:90085] [Bug#15346]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-27 07:34:21 +00:00
nobu 67099c4505 Fix potential NULL pointer access [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-10 09:29:00 +00:00
nobu dcfb7f6d54 compile.c: compile error than rb_bug [ci skip]
* compile.c (get_local_var_idx, get_dyna_var_idx): raise a compile
  error which is useful than rb_bug, when ID is not found.

* compile.c (iseq_set_sequence): ditto when IC index overflow,
  with dumping generated code.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65617 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-08 01:57:03 +00:00
nobu 7d3e758a44 compile.c: unreachable than rb_bug [ci skip]
* compile.c (iseq_calc_param_size): use UNREACHABLE than rb_bug,
  at where never reachable.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65614 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-08 00:12:53 +00:00
svn ebf5899030 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65601 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-07 08:13:24 +00:00
mame b06649b912 Rename get/setinlinecache to opt_get/opt_setinlinecache
The instructions are just for optimization.  To clarity the intention,
this change adds the prefix "opt_", like "opt_case_dispatch".

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65600 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-07 08:13:20 +00:00
ko1 09821dd2a5 Fix TracePoint for nested iseq loaded from binary [Bug#14702]
When loading iseq from binary while a TracePoint is on, we need to
recompile instructions to their "trace_" variant. Before this commit
we only recompiled instructions in the top level iseq, which meant
that TracePoint was malfunctioning for code inside module/class/method
definitions.

* compile.c: Move rb_iseq_init_trace to rb_ibf_load_iseq_complete.
  It is called on all iseqs during loading.

* test_iseq.rb: Test that tracepoints fire within children iseq when
  using load_from_binary.

This patch is from: Alan Wu <XrXr@users.noreply.github.com>


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65567 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-06 06:36:51 +00:00
yui-knk ce798d08de Implement `RubyVM::AST.of` [Feature #14836]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-05 02:13:45 +00:00
svn d4f1187d31 * remove trailing spaces, expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 22:12:12 +00:00
ko1 8f675cdd00 support theap for T_HASH. [Feature #14989]
* hash.c, internal.h: support theap for small Hash.
  Introduce RHASH_ARRAY (li_table) besides st_table and small Hash
  (<=8 entries) are managed by an array data structure.
  This array data can be managed by theap.
  If st_table is needed, then converting array data to st_table data.

  For st_table using code, we prepare "stlike" APIs which accepts hash value
  and are very similar to st_ APIs.

  This work is based on the GSoC achievement
  by tacinight <tacingiht@gmail.com> and refined by ko1.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 22:11:51 +00:00
svn 437392232a * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65450 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 21:54:13 +00:00
ko1 312b105d0e introduce TransientHeap. [Bug #14858]
* transient_heap.c, transient_heap.h: implement TransientHeap (theap).
  theap is designed for Ruby's object system. theap is like Eden heap
  on generational GC terminology. theap allocation is very fast because
  it only needs to bump up pointer and deallocation is also fast because
  we don't do anything. However we need to evacuate (Copy GC terminology)
  if theap memory is long-lived. Evacuation logic is needed for each type.

  See [Bug #14858] for details.

* array.c: Now, theap for T_ARRAY is supported.

  ary_heap_alloc() tries to allocate memory area from theap. If this trial
  sccesses, this array has theap ptr and RARRAY_TRANSIENT_FLAG is turned on.
  We don't need to free theap ptr.

* ruby.h: RARRAY_CONST_PTR() returns malloc'ed memory area. It menas that
  if ary is allocated at theap, force evacuation to malloc'ed memory.
  It makes programs slow, but very compatible with current code because
  theap memory can be evacuated (theap memory will be recycled).

  If you want to get transient heap ptr, use RARRAY_CONST_PTR_TRANSIENT()
  instead of RARRAY_CONST_PTR(). If you can't understand when evacuation
  will occur, use RARRAY_CONST_PTR().

(re-commit of r65444)


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65449 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 21:53:56 +00:00
svn 69b8ffcd5b * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 21:02:12 +00:00
ko1 7d359f9b69 revert r65444 and r65446 because of commit miss
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 21:01:55 +00:00
svn f926f799e9 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65445 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 20:46:47 +00:00
ko1 90ac549fa6 introduce TransientHeap. [Bug #14858]
* transient_heap.c, transient_heap.h: implement TransientHeap (theap).
  theap is designed for Ruby's object system. theap is like Eden heap
  on generational GC terminology. theap allocation is very fast because
  it only needs to bump up pointer and deallocation is also fast because
  we don't do anything. However we need to evacuate (Copy GC terminology)
  if theap memory is long-lived. Evacuation logic is needed for each type.

  See [Bug #14858] for details.

* array.c: Now, theap for T_ARRAY is supported.

  ary_heap_alloc() tries to allocate memory area from theap. If this trial
  sccesses, this array has theap ptr and RARRAY_TRANSIENT_FLAG is turned on.
  We don't need to free theap ptr.

* ruby.h: RARRAY_CONST_PTR() returns malloc'ed memory area. It menas that
  if ary is allocated at theap, force evacuation to malloc'ed memory.
  It makes programs slow, but very compatible with current code because
  theap memory can be evacuated (theap memory will be recycled).

  If you want to get transient heap ptr, use RARRAY_CONST_PTR_TRANSIENT()
  instead of RARRAY_CONST_PTR(). If you can't understand when evacuation
  will occur, use RARRAY_CONST_PTR().


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 20:46:24 +00:00
svn fae6c6bfd8 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 03:22:09 +00:00
ko1 54726befc3 use RARRAY_AREF() instead of RARRAY_CONST_PTR().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 03:21:56 +00:00
kazu d36ab02b95 compile.c: fix up r65411
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65429 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-29 13:30:01 +00:00
ko1 2d46695c7c use a rb_ function instead of st_ directly.
* compile.c (ibf_dump_object_hash): use `rb_hash_foreach()`
  instead of using `st_foreach()`.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65411 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-28 05:09:58 +00:00
nobu 71b0d20f7e compile.c: fix peephole optimization
* compile.c (iseq_peephole_optimize): should `pop` before jump
  instruction which succeeds to `newarray` of a literal object,
  not after.  [ruby-core:89536] [Bug #15245]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65350 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-24 10:38:39 +00:00
ko1 f3c5239b16 introduce new YARV insn newhashfromarray.
* insns.def (newhashfromarray): added to replace `core_hash_from_ary`
  method to eliminate method call overhead.

  On my environment, I got the following benchmark results:

  x = {x: 1}

                    modified:   7864988.6 i/s
                       trunk:   6004098.1 i/s - 1.31x  slower


  x = {x: 1, y: 2}

                       trunk:   6127338.4 i/s
                    modified:   5232380.0 i/s - 1.17x  slower


  x = {x: 1, y: 2, z: 3}

                    modified:   6089553.1 i/s
                       trunk:   5249333.5 i/s - 1.16x  slower

  This trivial improvement should be reconsider because of usage of
  this instruction.

* compile.c: ditto.

* defs/id.def, vm.c: remove unused functions.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-24 01:57:27 +00:00
svn b5425ad780 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65226 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20 10:45:55 +00:00
mame 6c9a705032 Remove tracecoverage instructions
The instructions were used only for branch coverage.
Instead, it now uses a trace framework [Feature #14104].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20 10:45:48 +00:00
mame 47ea999b46 ext/coverage/: add the oneshot mode
This patch introduces "oneshot_lines" mode for `Coverage.start`, which
checks "whether each line was executed at least once or not", instead of
"how many times each line was executed".  A hook for each line is fired
at most once, and after it is fired, the hook flag was removed; it runs
with zero overhead.

See [Feature #15022] in detail.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20 05:33:04 +00:00
shyouhei 5bb48dc68a compile.c: default_len is positive
Recent GCC warns that default_len can be negative (thus can
overflow PTRDIFF_MAX), which is a false assert.  Suppresses
warnings by adding __builtin_unreachable.

See also: https://travis-ci.org/ruby/ruby/jobs/443568193#L2227


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65167 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-19 08:46:41 +00:00
svn 61634b6768 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65108 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-17 07:16:58 +00:00
mame e88fd0606b Remove the level information from throw instruction
It is no longer used.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-17 07:16:50 +00:00
nobu fa8b08b424 Prefer `rb_fstring_lit` over `rb_fstring_cstr`
The former states explicitly that the argument must be a literal,
and can optimize away `strlen` on all compilers.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-13 09:59:22 +00:00
svn 8ab2230b7f * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64851 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-26 02:38:51 +00:00
k0kubun 6e62e59eec revert r64847, r64846 and r64839
because r64849 seems to fix issues which we were confused about.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64850 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-26 02:38:45 +00:00
svn 1d782010b5 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64847 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-26 01:11:26 +00:00
k0kubun e08f418230 revert r64838 and r64839
because some build failures persisted

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-26 01:11:20 +00:00
k0kubun 2b610ec285 insns.def: drop bitblt insn
as a workaround to fix the build pipeline broken by r64824,
because optimizing Ruby should be prioritized higher than supporting unused jokes.

In the current build system, exceeding 200 insns somehow crashes C
extension build on some of MinGW environments like "mingw32-make[1]:
*** No rule to make target 'note'.  Stop."
https://ci.appveyor.com/project/ruby/ruby/build/9725/job/co4nu9jugm8qwdrp
and on some of Linux environments like "cannot load such file -- stringio (LoadError)"

```
build_install        /home/ko1/ruby/src/trunk_gcc5/lib/rubygems/specification.rb:18:in `require': cannot load such file -- stringio (LoadError)
	from /home/ko1/ruby/src/trunk_gcc5/lib/rubygems/specification.rb:18:in `<top (required)>'
	from /home/ko1/ruby/src/trunk_gcc5/lib/rubygems.rb:1365:in `require'
	from /home/ko1/ruby/src/trunk_gcc5/lib/rubygems.rb:1365:in `<module:Gem>'
	from /home/ko1/ruby/src/trunk_gcc5/lib/rubygems.rb:116:in `<top (required)>'
	from /home/ko1/ruby/src/trunk_gcc5/tool/rbinstall.rb:24:in `require'
	from /home/ko1/ruby/src/trunk_gcc5/tool/rbinstall.rb:24:in `<main>'
make: *** [do-install-nodoc] Error 1
```

http://ci.rvm.jp/results/trunk_gcc5@silicon-docker/1353447

This commit removes "bitblt" and "trace_bitblt" insns, which reduces the
number of insns from 202 to 200 and fixes at least the latter build
failure. I hope this fixes the MinGW build failure as well. Let me
confirm the situation on AppVeyor CI.

Note that this is hard to fix because some MinGW environments (MSP-Greg's
MinGW CI on AppVeyor) don't reproduce this and some Linux environments
(including my local machine) don't reproduce it either. Make sure you
have the reproductive environment and confirm it's fixed when reverting
this commit.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64839 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-25 17:20:02 +00:00
k0kubun 08c9f030f6 Revert "Revert r64824 to fix build failure on AppVeyor"
This reverts commit r64829. I'll prepare another temporary fix, but I'll
separately commit that to make it easier to revert that later.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-25 17:19:51 +00:00
k0kubun f00bf24272 Revert r64824 to fix build failure on AppVeyor
AppVeyor msys2/MinGW build started to fail like:
https://ci.appveyor.com/project/ruby/ruby/build/9722/job/b94kixi004klmye3

Until I can investigate that, I revert this for now.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64829 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-25 04:03:35 +00:00
k0kubun fb80f6c7ba insns.def: optimize & and | of Integer [experimental]
not optimizing Array#& and Array#| because vm_insnhelper.c can't easily
inline it (large amount of array.c code would be needed in vm_insnhelper.c)
and the method body is a little complicated compared to Integer's ones.
So I thought only Integer#& and Integer#| have a significant impact,
and eliminating unnecessary branches would contribute to JIT's performance.

vm_insnhelper.c: ditto

tool/transform_mjit_header.rb: make sure these instructions are inlined
on JIT.

compile.c: compile vm_opt_and and vm_opt_or.
id.def: define id for them to be used in compile.c and vm*.c
vm.c: track redefinition of Integer#& and Integer#|
vm_core.h: allow detecting redefinition of & and |

test/ruby/test_jit.rb: test new insns
test/ruby/test_optimization.rb: ditto

* Optcarrot benchmark

This is a kind of experimental thing but I'm committing this since the
performance impact is significant especially on Optcarrot with JIT.

$ benchmark-driver benchmark.yml --rbenv 'before::before --disable-gems;before+JIT::before --disable-gems --jit;after::after --disable-gems;after+JIT::after --disable-gems --jit' -v --repeat-count 24
before: ruby 2.6.0dev (2018-09-24 trunk 64821) [x86_64-linux]
before+JIT: ruby 2.6.0dev (2018-09-24 trunk 64821) +JIT [x86_64-linux]
after: ruby 2.6.0dev (2018-09-24 opt_and 64821) [x86_64-linux]
last_commit=opt_or
after+JIT: ruby 2.6.0dev (2018-09-24 opt_and 64821) +JIT [x86_64-linux]
last_commit=opt_or
Calculating -------------------------------------
                             before  before+JIT       after   after+JIT
Optcarrot Lan_Master.nes     51.460      66.315      53.023      71.173 fps

Comparison:
             Optcarrot Lan_Master.nes
               after+JIT:        71.2 fps
              before+JIT:        66.3 fps - 1.07x  slower
                   after:        53.0 fps - 1.34x  slower
                  before:        51.5 fps - 1.38x  slower

[close https://github.com/ruby/ruby/pull/1963]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-24 12:40:28 +00:00
mame 32cff956bc * compile.c (compile_case): emit opt_case_dispatch only on optimized mode
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-20 07:36:10 +00:00
nobu 9580586b63 Use opt_{aref,aset} over opt_{aref,aset}_with
* compile.c (iseq_compile_each0): Use `opt_aref`/`opt_aset` over
  `opt_aref_with`/`opt_aset_with` when frozen_string_literal: true,
  not to resurrect the index string on non-Hash receiver.

[Fix GH-1957]

From: chopraanmol1 <chopraanmol1@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64745 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-15 02:20:47 +00:00
k0kubun 402001d6c7 iseq.c: prefix rb_ to non-static iseq functions
I assume we always prefix rb_ to non-static functions to avoid conflict.
These functions are not exported and safe to be renamed.

iseq.h: ditto
compile.c: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64736 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-13 13:59:25 +00:00
shyouhei 02b52b2733 make opt_str_freeze leaf
Simply use DISPATCH_ORIGINAL_INSN instead of rb_funcall.  This is,
when possible, overall performant because method dispatch results are
cached inside of CALL_CACHE.  Should also be good for JIT.

----

trunk: ruby 2.6.0dev (2018-09-12 trunk 64689) [x86_64-darwin15]
ours: ruby 2.6.0dev (2018-09-12 leaf-insn 64688) [x86_64-darwin15]
last_commit=make opt_str_freeze leaf
Calculating -------------------------------------
                          trunk        ours
    vm2_freezestring     5.440M     31.411M i/s -      6.000M times in 1.102968s 0.191017s

Comparison:
                 vm2_freezestring
                ours:  31410864.5 i/s
               trunk:   5439865.4 i/s - 5.77x  slower



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-12 03:39:36 +00:00
shyouhei 33c8171c65 make opt_case_dispatch leaf
This instruction can be written without rb_funcall. It not only boosts
performance of case statements, but also makes room of future JIT
improvements.  Because opt_case_dispatch is about optimization this
should not be a bad thing to have.

----

trunk: ruby 2.6.0dev (2018-09-05 trunk 64634) [x86_64-darwin15]
ours: ruby 2.6.0dev (2018-09-12 leaf-insn 64688) [x86_64-darwin15]
last_commit=make opt_case_dispatch leaf
Calculating -------------------------------------
                          trunk        ours
        vm2_case_lit      1.366       2.012 i/s -       1.000 times in 0.731839s 0.497008s

Comparison:
                     vm2_case_lit
                ours:         2.0 i/s
               trunk:         1.4 i/s - 1.47x  slower



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64689 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-12 01:55:00 +00:00
mame d574683c40 iseq.c: add a map from encoded insn to insn data
This enhances rb_vm_insn_addr2insn which retrieves a decoded insn number
from encoded insn.
The insn data table include not only decoded insn number, but also its
len, trace and non-trace version of encoded insn.
This table can be used to simplify trace instrumentation.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-23 08:32:30 +00:00
nobu bf6e2eb7e7 compile.c: drop unused array
* compile.c (iseq_peephole_optimize): drop unused dynamic array
  literal, without concatenation.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64517 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-23 07:45:39 +00:00
nobu 130ef3b458 compile.c: drop unused string
* compile.c (iseq_peephole_optimize): drop unused dynamic string
  literal, without concatenation.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64516 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-23 07:22:27 +00:00
ko1 8752a1ff4e remove `const` warning.
* compile.c (iseq_ibf_load): remove `const` to pass iseq as no `const`
  parameter.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-23 05:54:38 +00:00
ko1 b85b10c11f check trace flags at loading [Bug #14702]
* iseq.c (iseq_init_trace): at ISeq loading time, we need to check
  `ruby_vm_event_enabled_flags` to turn on trace instructions.
  Seprate this checking code from `finish_iseq_build()` and make
  new function. `iseq_ibf_load()` calls this funcation after loading.

* test/ruby/test_iseq.rb: add a test for this fix.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64514 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-23 04:12:14 +00:00
nobu 37fa201e8f compile.c: pop literal object in condition
* compile.c (compile_branch_condition): pop dynamic literal
  object, which is never nil/false, as the branch condition.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64512 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-22 16:02:03 +00:00
mame 100bf27574 compile.c: remove tracecoverage instruction for line coverage
Line coverage was based on special instruction "tracecoverage".
Now, instead, it uses the mechanism of trace hook [Feature #14104].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-22 11:09:47 +00:00
mame d65f7458bc parse.y: remove coverage-related code fragments
The code fragments that initializes coverage data were scattered into
both parse.y and compile.c.  parse.y allocated a coverage data, and
compile.c initialize the data.

To remove this cross-cutting concern, this change moves the allocation
from "coverage" function of parse.y to "rb_iseq_new_top" of iseq.c.
For the sake, parse.y just counts the line number of the original source
code, and the number is passed via rb_ast_body_t.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-22 10:38:56 +00:00
nobu af2e98ae80 Optimization for case when with splat operator
[Fix GH-1928] [Feature #14984]

From: chopraanmol1 <chopraanmol1@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64318 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-12 08:10:53 +00:00
nobu fe781af377 compile.c: use EXPECT_NODE macro
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64316 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-12 04:50:48 +00:00
nobu e7f88ff684 compile.c: check error in when_vals
* compile.c (when_vals): return a negative value on error.

* compile.c (compile_case): check error in when_vals().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64315 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-12 04:50:14 +00:00
mame 2138f24c70 insns.def (invokesuper): remove a dummy receiever flag hack for ZSUPER
This is just a refactoring.

The receiver of "invokesuper" was a boolean to represent if it is ZSUPER
or not.  This was used in vm_search_super_method to prohibit ZSUPER call
in define_method. (It is currently prohibited because of the limitation
of the implementation.)

This change removes the hack by introducing an explicit flag,
VM_CALL_SUPER, to signal the information.  Now, the implementation of
"invokesuper" is consistent with "send" instruction.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-10 07:45:16 +00:00
tenderlove d8583b132c Remove redundant code in the compiler.
During instruction translation (linked list -> iseq generation), we can
treat `TS_VALUE` and `TS_ISEQ` the same as they are just embedded in the
generated sequences.  The only difference between `TS_ISE` and `TS_IC`
is that an inline storage entry may contain a markable `VALUE` pointer
at some point, so we need to flag the iseq as containing markable
objects.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63923 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-09 20:01:54 +00:00
tenderlove 162cbfe631 Remove test code. ISE generation should not impact write barrier
orz!

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-09 19:20:27 +00:00
tenderlove 7aab72f736 Fix crash when loading iseq from an array
Objects loaded during iseq deserialization using arrays need to be added
to the compile time mark array so that they stay alive until iseqs
finish loading.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63920 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-09 17:47:37 +00:00
nobu 5e7167f8fb compile.c: remove unreachable jump only
* compile.c (iseq_peephole_optimize): remove unreachable jump
  instruction only.  if it is labeled and referred from other
  instructions, it is reachable and must not be removed.
  [ruby-core:87830] [Bug #14897]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63870 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-06 08:01:58 +00:00