summaryrefslogtreecommitdiff
path: root/compile.c
AgeCommit message (Collapse)Author
2020-07-03Use ID instead of GENTRY for gvars. (#3278)Koichi Sasada
Use ID instead of GENTRY for gvars. Global variables are compiled into GENTRY (a pointer to struct rb_global_entry). This patch replace this GENTRY to ID and make the code simple. We need to search GENTRY from ID every time (st_lookup), so additional overhead will be introduced. However, the performance of accessing global variables is not important now a day and this simplicity helps Ractor development. Notes: Merged-By: ko1 <ko1@atdot.net>
2020-06-29compile_redo: fix wrong condition卜部昌平
Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29ibf_dump_object_object: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29compile_call: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29compile_redo: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29compile_next: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29compile_break: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29compile_branch_condition: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29optimize_checktype: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29iseq_set_exception_table: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-27Removed non-ASCII code to suppress warnings by localized compilersNobuyoshi Nakada
2020-06-27Cosmetic changeKazuki Tsujimoto
2020-06-27Add #deconstruct cache to find patternVladimir Dementyev
Notes: Merged: https://github.com/ruby/ruby/pull/3104
2020-06-27Optimize array pattern matching by caching #deconstruct valueVladimir Dementyev
Notes: Merged: https://github.com/ruby/ruby/pull/3104
2020-06-27Removed no longer used flagsNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/3262
2020-06-27Not to rewrite node while compilingNobuyoshi Nakada
Moved this hack mark to an argument to `compile_hash`. > Bad Hack: temporarily mark hash node with flag so > compile_hash can compile call differently. Notes: Merged: https://github.com/ruby/ruby/pull/3262
2020-06-20Introduce Primitive.attr! to annotate 'inline' (#3242)Takashi Kokubun
[Feature #15589] Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2020-06-20compile.c: Improve branch coverage instrumentation [Bug #16967]Yusuke Endoh
Formerly, branch coverage measurement counters are generated for each compilation traverse of the AST. However, ensure clause node is traversed twice; one is for normal-exit case (the resulted bytecode is embedded in its outer scope), and the other is for exceptional case (the resulted bytecode is used in catch table). Two branch coverage counters are generated for the two cases, but it is not desired. This changeset revamps the internal representation of branch coverage measurement. Branch coverage counters are generated only at the first visit of a branch node. Visiting the same node reuses the already-generated counter, so double counting is avoided. Notes: Merged: https://github.com/ruby/ruby/pull/3240
2020-06-20compile.c: pass NODE* instead of a quadruple of code locationYusuke Endoh
Notes: Merged: https://github.com/ruby/ruby/pull/3240
2020-06-20compile.c (branch_coverage_valid_p): Refactored outYusuke Endoh
Notes: Merged: https://github.com/ruby/ruby/pull/3240
2020-06-20compile.c: Use functions for building branch coverage instructionsYusuke Endoh
instead of maros. Just refactoring. Notes: Merged: https://github.com/ruby/ruby/pull/3240
2020-06-19[Feature #16254] Allow `Primitive.func` styleNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/3165
2020-06-19[Feature #16254] Allow `__builtin.func` styleNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/3165
2020-06-18Dup splat array in certain cases where there is a block argumentJeremy Evans
This makes: ```ruby args = [1, 2, -> {}]; foo(*args, &args.pop) ``` call `foo` with 1, 2, and the lambda, in addition to passing the lambda as a block. This is different from the previous behavior, which passed the lambda as a block but not as a regular argument, which goes against the expected left-to-right evaluation order. This is how Ruby already compiled arguments if using leading arguments, trailing arguments, or keywords in the same call. This works by disabling the optimization that skipped duplicating the array during the splat (splatarray instruction argument switches from false to true). In the above example, the splat call duplicates the array. I've tested and cases where a local variable or symbol are used do not duplicate the array, so I don't expect this to decrease the performance of most Ruby programs. However, programs such as: ```ruby foo(*args, &bar) ``` could see a decrease in performance, if `bar` is a method call and not a local variable. This is not a perfect solution, there are ways to get around this: ```ruby args = Struct.new(:a).new([:x, :y]) def args.to_a; a; end def args.to_proc; a.pop; ->{}; end foo(*args, &args) # calls foo with 1 argument (:x) # not 2 arguments (:x and :y) ``` A perfect solution would require completely disabling the optimization. Fixes [Bug #16504] Fixes [Bug #16500] Notes: Merged: https://github.com/ruby/ruby/pull/3157
2020-06-17Replaced accessors of `Struct` with `invokebuiltin`Nobuyoshi Nakada
2020-06-16Revert "Replaced accessors of `Struct` with `invokebuiltin`"Nobuyoshi Nakada
This reverts commit 19cabe8b09d92d033c244f32ff622b8e513375f1, which didn't support tool/lib/iseq_loader_checker.rb.
2020-06-16Replaced accessors of `Struct` with `invokebuiltin`Nobuyoshi Nakada
2020-06-14Introduce find pattern [Feature #16828]Kazuki Tsujimoto
2020-06-08Fix crashes in the peephole optimizer on OpenBSD/sparc64Jeremy Evans
These crashes are due to alignment issues, casting ADJUST to INSN and then accessing after the end of the ADJUST. These patches come from Stefan Sperling <stsp@apache.org>, who reported the issue. Notes: Merged: https://github.com/ruby/ruby/pull/2961
2020-05-31compile.c: Mark cursor in debug listNobuyoshi Nakada
2020-05-31compile.c: Removed wrong conversionNobuyoshi Nakada
2020-05-30Adjusted an indentNobuyoshi Nakada
2020-05-29add indent for debug disasm outputKoichi Sasada
2020-05-22Fixed potential memory leakNobuyoshi Nakada
Create a wrapper object first, then buffer allocation which can fail.
2020-05-20Use a pinning list for keeping objects alive during assembly.Aaron Patterson
The GC will not disassemble incomplete instruction sequences. So it is important that when instructions are being assembled, any objects the instructions point at should not be moved. This patch implements a fixed width array that pins its references. When the instructions are done being assembled, the pinning array goes away and the objects inside the iseqs are allowed to move.
2020-05-18Prefer dedicated enum over intNobuyoshi Nakada
2020-05-18built-in method call must not have a receiverNobuyoshi Nakada
2020-05-11drop varargs.h support卜部昌平
This header file is simply out of date (for decades since at least 1989). It's the 21st century. Just stop using it.
2020-05-11sed -i 's|ruby/impl|ruby/internal|'卜部昌平
To fix build failures. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-05-11sed -i s|ruby/3|ruby/impl|g卜部昌平
This shall fix compile errors. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-05-11Added more NORETURN declarationsNobuyoshi Nakada
2020-05-04Fix pseudo code for NODE_ARYPTN, NODE_HSHPTNKazuki Tsujimoto
Due to the change in 3893a8dd42fb3bbd71750648c3c0de118955a6ea, there is no longer a need to put true/false.
2020-04-15Create succ_index_table as a part of `iseq_setup`Nobuyoshi Nakada
With compiling `CPDEBUG >= 2`, `rb_iseq_disasm` segfaults if this table has not been created. Also `ibf_load_iseq_each` calls `rb_iseq_insns_info_encode_positions`. Notes: Merged: https://github.com/ruby/ruby/pull/3033
2020-04-15Disassemble nop-inserted listNobuyoshi Nakada
2020-04-15Show heading for update_catch_except_flagsNobuyoshi Nakada
2020-04-12Avoid UB with flexible array memberAlan Wu
Accessing past the end of an array is technically UB. Use C99 flexible array member instead to avoid the UB and simplify allocation size calculation. See also: DCL38-C in the SEI CERT C Coding Standard Notes: Merged: https://github.com/ruby/ruby/pull/3017 Merged-By: XrXr
2020-04-08Suppress -Wswitch warningsNobuyoshi Nakada
2020-04-08Merge pull request #2991 from shyouhei/ruby.h卜部昌平
Split ruby.h Notes: Merged-By: shyouhei <shyouhei@ruby-lang.org>
2020-03-17Reduce allocations for keyword argument hashesJeremy Evans
Previously, passing a keyword splat to a method always allocated a hash on the caller side, and accepting arbitrary keywords in a method allocated a separate hash on the callee side. Passing explicit keywords to a method that accepted a keyword splat did not allocate a hash on the caller side, but resulted in two hashes allocated on the callee side. This commit makes passing a single keyword splat to a method not allocate a hash on the caller side. Passing multiple keyword splats or a mix of explicit keywords and a keyword splat still generates a hash on the caller side. On the callee side, if arbitrary keywords are not accepted, it does not allocate a hash. If arbitrary keywords are accepted, it will allocate a hash, but this commit uses a callinfo flag to indicate whether the caller already allocated a hash, and if so, the callee can use the passed hash without duplicating it. So this commit should make it so that a maximum of a single hash is allocated during method calls. To set the callinfo flag appropriately, method call argument compilation checks if only a single keyword splat is given. If only one keyword splat is given, the VM_CALL_KW_SPLAT_MUT callinfo flag is not set, since in that case the keyword splat is passed directly and not mutable. If more than one splat is used, a new hash needs to be generated on the caller side, and in that case the callinfo flag is set, indicating the keyword splat is mutable by the callee. In compile_hash, used for both hash and keyword argument compilation, if compiling keyword arguments and only a single keyword splat is used, pass the argument directly. On the caller side, in vm_args.c, the callinfo flag needs to be recognized and handled. Because the keyword splat argument may not be a hash, it needs to be converted to a hash first if not. Then, unless the callinfo flag is set, the hash needs to be duplicated. The temporary copy of the callinfo flag, kw_flag, is updated if a hash was duplicated, to prevent the need to duplicate it again. If we are converting to a hash or duplicating a hash, we need to update the argument array, which can including duplicating the positional splat array if one was passed. CALLER_SETUP_ARG and a couple other places needs to be modified to handle similar issues for other types of calls. This includes fairly comprehensive tests for different ways keywords are handled internally, checking that you get equal results but that keyword splats on the caller side result in distinct objects for keyword rest parameters. Included are benchmarks for keyword argument calls. Brief results when compiled without optimization: def kw(a: 1) a end def kws(**kw) kw end h = {a: 1} kw(a: 1) # about same kw(**h) # 2.37x faster kws(a: 1) # 1.30x faster kws(**h) # 2.19x faster kw(a: 1, **h) # 1.03x slower kw(**h, **h) # about same kws(a: 1, **h) # 1.16x faster kws(**h, **h) # 1.14x faster Notes: Merged: https://github.com/ruby/ruby/pull/2945
2020-03-17Make {**{}} return unfrozen empty hashJeremy Evans
Previously, method call keyword splats and hash keyword splats were compiled exactly the same. This is because parse-wise, they operate on indentical nodes when it comes to compiling the **{}. Fix this by using an ugly hack of temporarily modifying the nd_brace flag in the method call keyword splat case. Inside compile_hash, only optimize the **{} case for hashes where the nd_brace flag has been modified to reflect we are in the method call keyword splat case and it is safe to do so. Since compile_keyword_args is only called in one place, move the keyword_node_p call out of that method to the single caller to avoid duplicating the code. Notes: Merged: https://github.com/ruby/ruby/pull/2945