summaryrefslogtreecommitdiff
path: root/compile.c
AgeCommit message (Collapse)Author
2019-09-27Drop eliminated catch-entriesNobuyoshi Nakada
Drop catch table entries used in eliminated block, as well as call_infos. [Bug #16184]
2019-09-27Adjusted spaces [ci skip]Nobuyoshi Nakada
2019-09-26Replace `freeze_string` with `rb_fstring`Aaron Patterson
2019-09-26Remove `iseq_add_mark_object_compile_time`Aaron Patterson
This function is just a synonym for RB_OBJ_WRITTEN, so we can just directly call that.
2019-09-26Execute write barrier instead of adding to arrayAaron Patterson
We can mark everything via the instruction objects, so just execute the write barrier instead of appending to the array
2019-09-26Pull `iseq_add_mark_object_compile_time` out of `freeze_string`Aaron Patterson
`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-26Pull "mark object" upAaron Patterson
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-26Scan the ISEQ arena for markables and mark themAaron Patterson
This commit scans the ISEQ arena for objects that can be marked and marks them. This should make the mark array unnecessary.
2019-09-26Allocate `INSN *` out of a separate arenaAaron Patterson
2019-09-26Introduce a secondary arenaAaron Patterson
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-26Pass in arena to allocatorAaron Patterson
This is so we can configure a new arena later
2019-09-20Allows calling a private method only with bare `self`Nobuyoshi Nakada
2019-09-20Allow calling a private accessor with `self.`Nobuyoshi Nakada
[Feature #11297] [Feature #16123] Notes: Merged: https://github.com/ruby/ruby/pull/2474
2019-09-20Allow calling a private method with `self.`Dylan Thacker-Smith
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] Notes: Merged: https://github.com/ruby/ruby/pull/2474
2019-09-19Use EXPECT_NODE_NONULLNobuyoshi Nakada
2019-09-19Check COMPILE_RECV resultNobuyoshi Nakada
2019-09-19Improve the output of `RubyVM::InstructionSequence#to_binary` (#2450)NagayamaRyoga
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-13introduce IBF_(MAJOR|MINOR)_VERSION.Koichi Sasada
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-09Fix a typo [ci skip]Kazuhiro NISHIYAMA
2019-09-08compile.c (compile_hash): rewrite keyword splat handlingYusuke Endoh
and add some comments. (I confirm that `foo(**{})` allocates no hash object.)
2019-09-08compile.c (compile_hash): rewrite the compilation algorithmYusuke Endoh
This is a similar refactoring to 8c908c989077c74eed26e02912b98362e509b8a3, but the target is compile_hash.
2019-09-08compile.c (NODE_OP_ASGN1): Remove unneeded DECL_ANCHORYusuke Endoh
2019-09-08compile.c (keyword_node_p): Refactor out keyword node checksYusuke Endoh
2019-09-08compile.c (compile_hash): Remove redundant check for NODE_ZLISTYusuke Endoh
NODE_ZLIST case is handled in compile_hash, so iseq_compile_each0 doesn't have to do the same check redundantly.
2019-09-08compile.c (compile_hash): Simplify the keyword handlingYusuke Endoh
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-08compile.c (compile_hash): don't add a temporal array to mark_aryYusuke Endoh
The array is just for a temporal buffer to create a hash, not stored in the final iseq.
2019-09-08compile.c (compile_array): undef a temporal macroYusuke Endoh
2019-09-07* remove trailing spaces. [ci skip]git
2019-09-07compile.c (compile_array): rewrite the compilation algorithmYusuke Endoh
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-07compile.c (compile_hash): refactoringYusuke Endoh
The same refactoring as to b601b13c7267889bf394146353c5f2b0eb488278.
2019-09-07compile.c (compile_array): refactoringYusuke Endoh
"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-07compile.c: Separate compile_list to two functions for Array and HashYusuke Endoh
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-07compile.c (compile_list): allow an odd-length hidden array literalYusuke Endoh
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-07compile.c (compile_list): emit newarraykwsplat only at the last chunkYusuke Endoh
`[{}, {}, {}, ..., {}, *{}]` 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-07Rename some function/definition names that handles NODE_LISTYusuke Endoh
from array to list. Follow up to ac50ac03aeb210763730cdc45f230e236519223d
2019-09-07Rename NODE_ARRAY to NODE_LIST to reflect its actual use casesYusuke Endoh
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-05Make m(**{}) mean call without keywordsJeremy Evans
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 ``` Notes: Merged: https://github.com/ruby/ruby/pull/2428
2019-09-03Unify SUPPORT_JOKE and OPT_SUPPORT_JOKETakashi Kokubun
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-02Merge pull request #2418 from jeremyevans/array-empty-kwsplatJeremy Evans
Ignore empty keyword splats in arrays Notes: Merged: https://github.com/ruby/ruby/pull/2418 Merged-By: jeremyevans <code@jeremyevans.net>
2019-09-02Fix compilation error in SUPPORT_JOKETakashi Kokubun
This seems to have been broken since 4e15be8bade.
2019-09-02opt_regexpmatch1 is actually making things slower.Urabe, Shyouhei
---- 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 Notes: Merged: https://github.com/ruby/ruby/pull/1959
2019-09-01Make pattern matching support **nil syntaxKazuki Tsujimoto
2019-08-30Support **nil syntax for specifying a method does not accept keyword argumentsJeremy Evans
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. Notes: Merged: https://github.com/ruby/ruby/pull/2395
2019-08-30Separate keyword arguments from positional argumentsYusuke Endoh
And, allow non-symbol keys as a keyword arugment Notes: Merged: https://github.com/ruby/ruby/pull/2395
2019-08-27rb_hash_foreach now free from ANYARGS卜部昌平
After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, 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-27decouple compile.c usage of imemo_ifunc卜部昌平
After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, 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-27compile.c: remove const from the first argument of dladdrYusuke Endoh
Unfortunately, dladdr accepts void*, not const void*, in Solaris.
2019-08-14Switch to using a VM stack argument instead of 2nd operand for getconstantJeremy Evans
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-14Use Qtrue/Qfalse instead of 1/0 for 2nd operand to getconstantJeremy Evans
Fixes error when using -Werror,-Wshorten-64-to-32.
2019-08-15* expand tabs. [ci skip]git