aboutsummaryrefslogtreecommitdiffstats
path: root/compile.c
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* vm_args.c (rb_warn_check): Use iseq_unique_id instead of its pointerYusuke Endoh2019-12-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | (This is the second try of 036bc1da6c6c9b0fa9b7f5968d897a9554dd770e.) If iseq is GC'ed, the pointer of iseq may be reused, which may hide a deprecation warning of keyword argument change. http://ci.rvm.jp/results/trunk-test1@phosphorus-docker/2474221 ``` 1) Failure: TestKeywordArguments#test_explicit_super_kwsplat [/tmp/ruby/v2/src/trunk-test1/test/ruby/test_keyword.rb:549]: --- expected +++ actual @@ -1 +1 @@ -/The keyword argument is passed as the last hash parameter.* for `m'/m +"" ``` This change ad-hocly adds iseq_unique_id for each iseq, and use it instead of iseq pointer. This covers the case where caller is GC'ed. Still, the case where callee is GC'ed, is not covered. But anyway, it is very rare that iseq is GC'ed. Even when it occurs, it just hides some warnings. It's no big deal.
* Introduce an "Inline IVAR cache" structAaron Patterson2019-12-051-0/+5
| | | | | | | | | This commit introduces an "inline ivar cache" struct. The reason we need this is so compaction can differentiate from an ivar cache and a regular inline cache. Regular inline caches contain references to `VALUE` and ivar caches just contain references to the ivar index. With this new struct we can easily update references for inline caches (but not inline var caches as they just contain an int)
* compile.c: stop wrong peephole optimization when covearge is enabledYusuke Endoh2019-12-041-103/+129
| | | | | | | | | | | | | | | | | | | jump-jump optimization ignores the event flags of the jump instruction being skipped, which leads to overlook of line events. This changeset stops the wrong optimization when coverage measurement is neabled and when the jump instruction has any event flag. Note that this issue is not only for coverage but also for TracePoint, and this change does not fix TracePoint. However, fixing it fundamentally is tough (which requires revamp of the compiler). This issue is critical in terms of coverage measurement, but minor for TracePoint (ko1 said), so we here choose a stopgap measurement. [Bug #15980] [Bug #16397] Note for backporters: this changeset can be viewed by `git diff -w`.
* compile.c: trivial refactoringYusuke Endoh2019-12-041-3/+1
| | | | | Use `for` instead of `while` to make it explicit that it is a traverse of bytecode.
* rename __builtin_inline!(code) and introduce others.Koichi Sasada2019-11-271-2/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | rename __builtin_inline!(code) to __builtin_cstmt(code). Also this commit introduce the following inlining C code features. * __builtin_cstmt!(STMT) (renamed from __builtin_inline!) Define a function which run STMT implicitly and call this function at evatuation time. Note that you need to return some value in STMT. If there is a local variables (includes method parameters), you can read these values. static VALUE func(ec, self) { VALUE x = ...; STMT } Usage: def double a # a is readable from C code. __builtin_cstmt! 'return INT2FIX(FIX2INT(a) * 2);' end * __builtin_cexpr!(EXPR) Define a function which invoke EXPR implicitly like `__builtin_cstmt!`. Different from cstmt!, which compiled with `return EXPR;`. (`return` and `;` are added implicitly) static VALUE func(ec, self) { VALUE x = ...; return EXPPR; } Usage: def double a __builtin_cexpr! 'INT2FIX(FIX2INT(a) * 2)' end * __builtin_cconst!(EXPR) Define a function which invoke EXPR implicitly like cexpr!. However, the function is called once at compile time, not evaluated time. Any local variables are not accessible (because there is no local variable at compile time). Usage: GCC = __builtin_cconst! '__GNUC__' * __builtin_cinit!(STMT) STMT are writtein in auto-generated code. This code does not return any value. Usage: __builtin_cinit! '#include <zlib.h>' def no_compression? __builtin_cconst! 'Z_NO_COMPRESSION ? Qtrue : Qfalse' end
* make functions static卜部昌平2019-11-191-1/+1
| | | | | | | These functions are used from within a compilation unit so we can make them static, for better binary size. This changeset reduces the size of generated ruby binary from 26,590,128 bytes to 26,584,472 bytes on my macihne.
* vm_invoke_builtin_delegate with start index.Koichi Sasada2019-11-181-25/+52
| | | | | | | | | | | | | | | | | opt_invokebuiltin_delegate and opt_invokebuiltin_delegate_leave invokes builtin functions with same parameters of the method. This technique eliminate stack push operations. However, delegation parameters should be completely same as given parameters. (e.g. `def foo(a, b, c) __builtin_foo(a, b, c)` is okay, but __builtin_foo(b, c) is not allowed) This patch relaxes this restriction. ISeq has a local variables table which includes parameters. For example, the method defined as `def foo(a, b, c) x=y=nil`, then local variables table contains [a, b, c, x, y]. If calling builtin-function with arguments which are sub-array of the lvar table, use opt_invokebuiltin_delegate instruction with start index. For example, `__builtin_foo(b, c)`, `__builtin_bar(c, x, y)` is okay, and so on.
* More fixes for $SAFE/taint post mergingJeremy Evans2019-11-181-2/+0
|
* Avoid top-level search for nested constant reference from nil in defined?Dylan Thacker-Smith2019-11-131-3/+3
| | | | | | | | | | | | Fixes [Bug #16332] Constant access was changed to no longer allow top-level constant access through `nil`, but `defined?` wasn't changed at the same time to stay consistent. Use a separate defined type to distinguish between a constant referenced from the current lexical scope and one referenced from another namespace.
* Revert "Method reference operator"Nobuyoshi Nakada2019-11-121-9/+0
| | | | | This reverts commit 67c574736912003c377218153f9d3b9c0c96a17b. [Feature #16275]
* Get rid of `__` prefix which is presereved by C standardNobuyoshi Nakada2019-11-121-1/+1
|
* __builtin_inline!Koichi Sasada2019-11-111-3/+13
| | | | | | | | | | | | | | | | | Add an experimental `__builtin_inline!(c_expression)` special intrinsic which run a C code snippet. In `c_expression`, you can access the following variables: * ec (rb_execution_context_t *) * self (const VALUE) * local variables (const VALUE) Not that you can read these variables, but you can not write them. You need to return from this expression and return value will be a result of __builtin_inline!(). Examples: `def foo(x) __builtin_inline!('return rb_p(x);'); end` calls `p(x)`. `def double(x) __builtin_inline!('return INT2NUM(NUM2INT(x) * 2);')` returns x*2.
* Make prefix staticNobuyoshi Nakada2019-11-081-3/+3
|
* cstr -> bytesKoichi Sasada2019-11-081-5/+5
| | | | | rb_iseq_ibf_load_cstr() accepts bytes, but not NUL-terminate C string. To make it clear, rename it to _bytes.
* revival of __func__卜部昌平2019-11-081-2/+2
| | | | | | dad2abc69fdd1af52df353b8604017bd6a5c6a99 deleted __func__ but ruby already use this feature under RUBY_FUNCTION_NAME_STRING macro. Use it.
* do not use __func__.Koichi Sasada2019-11-081-2/+2
| | | | Microsoft Visual Studio 12.0 doesn't support it.
* fix typeKoichi Sasada2019-11-081-1/+1
|
* * remove trailing spaces. [ci skip]git2019-11-081-1/+1
|
* support builtin features with Ruby and C.Koichi Sasada2019-11-081-27/+229
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Support loading builtin features written in Ruby, which implement with C builtin functions. [Feature #16254] Several features: (1) Load .rb file at boottime with native binary. Now, prelude.rb is loaded at boottime. However, this file is contained into the interpreter as a text format and we need to compile it. This patch contains a feature to load from binary format. (2) __builtin_func() in Ruby call func() written in C. In Ruby file, we can write `__builtin_func()` like method call. However this is not a method call, but special syntax to call a function `func()` written in C. C functions should be defined in a file (same compile unit) which load this .rb file. Functions (`func` in above example) should be defined with (a) 1st parameter: rb_execution_context_t *ec (b) rest parameters (0 to 15). (c) VALUE return type. This is very similar requirements for functions used by rb_define_method(), however `rb_execution_context_t *ec` is new requirement. (3) automatic C code generation from .rb files. tool/mk_builtin_loader.rb creates a C code to load .rb files needed by miniruby and ruby command. This script is run by BASERUBY, so *.rb should be written in BASERUBY compatbile syntax. This script load a .rb file and find all of __builtin_ prefix method calls, and generate a part of C code to export functions. tool/mk_builtin_binary.rb creates a C code which contains binary compiled Ruby files needed by ruby command.
* Right size the iseq coverage branches tmp array - initializes with 5 elementsLourens Naudé2019-10-291-1/+1
|
* Pin keys of this st_tableAaron Patterson2019-10-281-1/+1
|
* respect `param.flags.ruby2_keywords` at to_binary.Koichi Sasada2019-10-251-1/+3
| | | | | `param.flags.ruby2_keywords` is not store/load correctly at to_binary so restore this flag correctly.
* Define arguments forwarding as `ruby2_keywords` styleNobuyoshi Nakada2019-10-251-0/+1
| | | | | | | | | | | | Get rid of these redundant and useless warnings. ``` $ ruby -e 'def bar(a) a; end; def foo(...) bar(...) end; foo({})' -e:1: warning: The last argument is used as the keyword parameter -e:1: warning: for `foo' defined here -e:1: warning: The keyword argument is passed as the last hash parameter -e:1: warning: for `bar' defined here ```
* Use CPDEBUG for debug codeAlan Wu2019-10-241-2/+2
|
* Combine call info and cache to speed up method invocationAlan Wu2019-10-241-122/+117
| | | | | | | | | | | | | | | | | | | | | | | | | | To perform a regular method call, the VM needs two structs, `rb_call_info` and `rb_call_cache`. At the moment, we allocate these two structures in separate buffers. In the worst case, the CPU needs to read 4 cache lines to complete a method call. Putting the two structures together reduces the maximum number of cache line reads to 2. Combining the structures also saves 8 bytes per call site as the current layout uses separate two pointers for the call info and the call cache. This saves about 2 MiB on Discourse. This change improves the Optcarrot benchmark at least 3%. For more details, see attached bugs.ruby-lang.org ticket. Complications: - A new instruction attribute `comptime_sp_inc` is introduced to calculate SP increase at compile time without using call caches. At compile time, a `TS_CALLDATA` operand points to a call info struct, but at runtime, the same operand points to a call data struct. Instruction that explicitly define `sp_inc` also need to define `comptime_sp_inc`. - MJIT code for copying call cache becomes slightly more complicated. - This changes the bytecode format, which might break existing tools. [Misc #16258]
* Fix the exception when CPDEBUGNobuyoshi Nakada2019-10-231-1/+4
|
* Fix build for CPDEBUG=1Alan Wu2019-10-221-1/+1
| | | | The declarations went out-of-sync in dcfb7f6.
* Right size the numtable in insn_make_insn_table to VM_INSTRUCTION_SIZELourens Naudé2019-10-111-1/+1
|
* avoid overflow in integer multiplication卜部昌平2019-10-091-16/+30
| | | | | | | This changeset basically replaces `ruby_xmalloc(x * y)` into `ruby_xmalloc2(x, y)`. Some convenient functions are also provided for instance `rb_xmalloc_mul_add(x, y, z)` which allocates x * y + z byes.
* Make parser_params have parent_iseq instead of base_blockYusuke Endoh2019-10-041-8/+4
| | | | | | | | | | | | The parser needs to determine whether a local varaiable is defined or not in outer scope. For the sake, "base_block" field has kept the outer block. However, the whole block was actually unneeded; the parser used only base_block->iseq. So, this change lets parser_params have the iseq directly, instead of the whole block.
* Iseq#to_binary: dump flag for **nil (#2508)Alan Wu2019-10-021-5/+7
| | | | RUBY_ISEQ_DUMP_DEBUG=to_binary and the attached test case was failing. Dump the flag to make sure `**nil` can round-trip properly.
* Drop eliminated catch-entriesNobuyoshi Nakada2019-09-271-0/+12
| | | | | Drop catch table entries used in eliminated block, as well as call_infos. [Bug #16184]
* Adjusted spaces [ci skip]Nobuyoshi Nakada2019-09-271-10/+11
|
* Replace `freeze_string` with `rb_fstring`Aaron Patterson2019-09-261-14/+8
|
* Remove `iseq_add_mark_object_compile_time`Aaron Patterson2019-09-261-37/+28
| | | | | This function is just a synonym for RB_OBJ_WRITTEN, so we can just directly call that.
* Execute write barrier instead of adding to arrayAaron Patterson2019-09-261-1/+1
| | | | | We can mark everything via the instruction objects, so just execute the write barrier instead of appending to the array
* Pull `iseq_add_mark_object_compile_time` out of `freeze_string`Aaron Patterson2019-09-261-4/+11
| | | | | | | `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.
* Pull "mark object" upAaron Patterson2019-09-261-11/+18
| | | | | | | 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.
* Scan the ISEQ arena for markables and mark themAaron Patterson2019-09-261-0/+51
| | | | | This commit scans the ISEQ arena for objects that can be marked and marks them. This should make the mark array unnecessary.
* Allocate `INSN *` out of a separate arenaAaron Patterson2019-09-261-1/+2
|
* Introduce a secondary arenaAaron Patterson2019-09-261-1/+1
| | | | | | We'll scan the secondary arena during GC mark. So, we should only allocate "markable" instruction linked list nodes out of the secondary arena.
* Pass in arena to allocatorAaron Patterson2019-09-261-4/+10
| | | | This is so we can configure a new arena later
* Allows calling a private method only with bare `self`Nobuyoshi Nakada2019-09-201-1/+10
|