aboutsummaryrefslogtreecommitdiffstats
path: root/compile.c
Commit message (Collapse)AuthorAgeFilesLines
* Replaced accessors of `Struct` with `invokebuiltin`Nobuyoshi Nakada2020-06-171-9/+8
|
* Revert "Replaced accessors of `Struct` with `invokebuiltin`"Nobuyoshi Nakada2020-06-161-8/+9
| | | | | This reverts commit 19cabe8b09d92d033c244f32ff622b8e513375f1, which didn't support tool/lib/iseq_loader_checker.rb.
* Replaced accessors of `Struct` with `invokebuiltin`Nobuyoshi Nakada2020-06-161-9/+8
|
* Introduce find pattern [Feature #16828]Kazuki Tsujimoto2020-06-141-0/+167
|
* Fix crashes in the peephole optimizer on OpenBSD/sparc64Jeremy Evans2020-06-081-2/+3
| | | | | | | 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.
* compile.c: Mark cursor in debug listNobuyoshi Nakada2020-05-311-5/+5
|
* compile.c: Removed wrong conversionNobuyoshi Nakada2020-05-311-1/+1
|
* Adjusted an indentNobuyoshi Nakada2020-05-301-1/+1
|
* add indent for debug disasm outputKoichi Sasada2020-05-291-3/+3
|
* Fixed potential memory leakNobuyoshi Nakada2020-05-221-3/+4
| | | | | Create a wrapper object first, then buffer allocation which can fail.
* Use a pinning list for keeping objects alive during assembly.Aaron Patterson2020-05-201-14/+87
| | | | | | | | | | 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.
* Prefer dedicated enum over intNobuyoshi Nakada2020-05-181-1/+1
|
* built-in method call must not have a receiverNobuyoshi Nakada2020-05-181-0/+1
|
* drop varargs.h support卜部昌平2020-05-111-1/+1
| | | | | This header file is simply out of date (for decades since at least 1989). It's the 21st century. Just stop using it.
* sed -i 's|ruby/impl|ruby/internal|'卜部昌平2020-05-111-1/+1
| | | | To fix build failures.
* sed -i s|ruby/3|ruby/impl|g卜部昌平2020-05-111-1/+1
| | | | This shall fix compile errors.
* Added more NORETURN declarationsNobuyoshi Nakada2020-05-111-1/+3
|
* Fix pseudo code for NODE_ARYPTN, NODE_HSHPTNKazuki Tsujimoto2020-05-041-2/+0
| | | | | Due to the change in 3893a8dd42fb3bbd71750648c3c0de118955a6ea, there is no longer a need to put true/false.
* Create succ_index_table as a part of `iseq_setup`Nobuyoshi Nakada2020-04-151-0/+7
| | | | | | 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`.
* Disassemble nop-inserted listNobuyoshi Nakada2020-04-151-0/+2
|
* Show heading for update_catch_except_flagsNobuyoshi Nakada2020-04-151-0/+1
|
* Avoid UB with flexible array memberAlan Wu2020-04-121-2/+2
| | | | | | | 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
* Suppress -Wswitch warningsNobuyoshi Nakada2020-04-081-0/+2
|
* Merge pull request #2991 from shyouhei/ruby.h卜部昌平2020-04-081-17/+18
| | | Split ruby.h
* Reduce allocations for keyword argument hashesJeremy Evans2020-03-171-20/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Make {**{}} return unfrozen empty hashJeremy Evans2020-03-171-6/+20
| | | | | | | | | | | | | | | | 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.
* Correctly detect whether strict alignment is needed on OpenBSDJeremy Evans2020-03-121-0/+10
| | | | From Stefan Sperling <stsp@apache.org>
* CI can be NULL.Koichi Sasada2020-02-221-28/+41
| | | | | Unused CI (introduced from peephole optimization, etc) can be NULL so introduce NULL check.
* Introduce disposable call-cache.Koichi Sasada2020-02-221-11/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | This patch contains several ideas: (1) Disposable inline method cache (IMC) for race-free inline method cache * Making call-cache (CC) as a RVALUE (GC target object) and allocate new CC on cache miss. * This technique allows race-free access from parallel processing elements like RCU. (2) Introduce per-Class method cache (pCMC) * Instead of fixed-size global method cache (GMC), pCMC allows flexible cache size. * Caching CCs reduces CC allocation and allow sharing CC's fast-path between same call-info (CI) call-sites. (3) Invalidate an inline method cache by invalidating corresponding method entries (MEs) * Instead of using class serials, we set "invalidated" flag for method entry itself to represent cache invalidation. * Compare with using class serials, the impact of method modification (add/overwrite/delete) is small. * Updating class serials invalidate all method caches of the class and sub-classes. * Proposed approach only invalidate the method cache of only one ME. See [Feature #16614] for more details.
* VALUE size packed callinfo (ci).Koichi Sasada2020-02-221-177/+165
| | | | | | | | | | | | | | | | | | | | Now, rb_call_info contains how to call the method with tuple of (mid, orig_argc, flags, kwarg). Most of cases, kwarg == NULL and mid+argc+flags only requires 64bits. So this patch packed rb_call_info to VALUE (1 word) on such cases. If we can not represent it in VALUE, then use imemo_callinfo which contains conventional callinfo (rb_callinfo, renamed from rb_call_info). iseq->body->ci_kw_size is removed because all of callinfo is VALUE size (packed ci or a pointer to imemo_callinfo). To access ci information, we need to use these functions: vm_ci_mid(ci), _flag(ci), _argc(ci), _kwarg(ci). struct rb_call_info_kw_arg is renamed to rb_callinfo_kwarg. rb_funcallv_with_cc() and rb_method_basic_definition_p_with_cc() is temporary removed because cd->ci should be marked.
* Fixed missing `return`Nobuyoshi Nakada2020-02-201-0/+1
| | | | Get rid of double writing.
* printf can be a macro卜部昌平2020-02-201-0/+1
| | | | | Namely glibc has this macro on -DFORTIFY_SOURCE. We have to prevent macro redefinition with different macro body.
* Split the optimizable range item conditionsNobuyoshi Nakada2020-02-161-1/+9
|
* Reduce begin-less/end-less range allocationMasataka Pocke Kuwabara2020-02-161-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ``` $ cat test.yaml prelude: | def endless 1.. end def beginless ..1 end def endless_substr(str) str[1..] end benchmark: endless: endless beginless: beginless endless_substr: "endless_substr('foo')" $ RBENV_VERSION=trunk ruby -v ruby 2.8.0dev (2020-02-15T12:52:03Z master 961630126b) [x86_64-linux] $ RBENV_VERSION=patched ruby -v ruby 2.8.0dev (2020-02-15T12:52:03Z origin/master 961630126b) [x86_64-linux] $ benchmark-driver test.yaml --rbenv 'patched;trunk' Warming up -------------------------------------- endless 45.948M i/s - 46.076M times in 1.002782s (21.76ns/i, 26clocks/i) beginless 49.986M i/s - 50.237M times in 1.005037s (20.01ns/i, 24clocks/i) endless_substr 8.067M i/s - 8.187M times in 1.014936s (123.96ns/i, 148clocks/i) Calculating ------------------------------------- patched trunk endless 115.679M 21.500M i/s - 137.843M times in 1.191597s 6.411398s beginless 112.599M 22.060M i/s - 149.957M times in 1.331778s 6.797768s endless_substr 8.888M 6.760M i/s - 24.201M times in 2.722995s 3.580038s Comparison: endless patched: 115679391.9 i/s trunk: 21499711.2 i/s - 5.38x slower beginless patched: 112598731.5 i/s trunk: 22059673.0 i/s - 5.10x slower endless_substr patched: 8887513.1 i/s trunk: 6759886.2 i/s - 1.31x slower ```
* Make yield in singleton class definitions in methods a SyntaxErrorJeremy Evans2020-02-111-10/+3
| | | | | | | | This behavior was deprecated in 2.7 and scheduled to be removed in 3.0. Calling yield in a class definition outside a method is now a SyntaxError instead of a LocalJumpError, as well.
* compile.c: Drop obj_list from ibf_dumpNagayamaRyoga2020-02-091-31/+43
| | | | [Feature #16505]
* compile.c: Drop iseq_list from ibf_dumpNagayamaRyoga2020-02-091-19/+34
| | | | [Feature #16505]
* Deduplicate objects efficiently when dumping iseq to binaryNagayamaRyoga2020-02-091-16/+25
| | | | | | | | | We were inefficient in cases where there are a lot of duplicates due to the use of linear search. Use a hash table instead. These cases are not that rare in the wild. [Feature #16505]
* Check type of empty keyword [Bug #16603]Seiei Miyagi2020-02-031-1/+1
| | | | Co-authored-by: Yusuke Endoh <mame@ruby-lang.org>
* compile.c: remove a unused variableYusuke Endoh2020-02-011-2/+1
|
* Optimized branches in pattern matchingNobuyoshi Nakada2020-01-301-61/+46
|
* move internal/debug.h definitions to internal.hKoichi Sasada2020-01-031-1/+0
| | | | Debug utilities should be accessible from any internal code.
* decouple internal.h headers卜部昌平2019-12-261-12/+26
| | | | | | | | | | | | | | | | | | Saves comitters' daily life by avoid #include-ing everything from internal.h to make each file do so instead. This would significantly speed up incremental builds. We take the following inclusion order in this changeset: 1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very first thing among everything). 2. RUBY_EXTCONF_H if any. 3. Standard C headers, sorted alphabetically. 4. Other system headers, maybe guarded by #ifdef 5. Everything else, sorted alphabetically. Exceptions are those win32-related headers, which tend not be self- containing (headers have inclusion order dependencies).
* export a function for MJIT.Koichi Sasada2019-12-251-1/+1
| | | | rb_iseq_complete() can be used by MJIT.
* take care of USE_LAZY_LOAD=1.Koichi Sasada2019-12-251-1/+5
| | | | | | On USE_LAZY_LOAD=1, the iseq should be loaded. So rb_iseq_check() is needed. Furthermore, now lazy loading with builtin_function_table is not supported, so it should cancel lazy loading.
* Manage deprecation warning by the flagNobuyoshi Nakada2019-12-221-2/+4
|
* compile.c: avoid newarraykwsplat for argumentsv2_7_0_rc2Yusuke Endoh2019-12-221-1/+8
| | | | | | | | | | | | | | `foo(*rest, post, **empty_kw)` is compiled like `foo(*rest + [post, **empty_kw])`, and `**empty_kw` is removed by "newarraykwsplat" instruction. However, the method call still has a flag of KW_SPLAT, so "post" is considered as a keyword hash, which caused a segfault. Note that the flag cannot be removed if "empty_kw" is not always empty. This change fixes the issue by compiling arguments with "newarray" instead of "newarraykwsplat". [Bug #16442]
* Fixed misspellingsNobuyoshi Nakada2019-12-201-1/+1
| | | | Fixed misspellings reported at [Bug #16437], only in ruby and rubyspec.
* readable function names for inline functions.Koichi Sasada2019-12-131-1/+1
| | | | | | | Now, C functions written by __builtin_cexpr!(code) and others are named as "__builtin_inline#{n}". However, it is difficult to know what the function is. This patch rename them into "__builtin_foo_#{lineno}" when cexpr! is in 'foo' method.
* add casts卜部昌平2019-12-121-6/+6
| | | | | | %p is for void *. Becuase fprintf is a function with variadic arguments automatic cast from any pointer to void * does not work. We have to be explicit.