Because the name "code_range" is ambiguous with encoding's.
Abbreviations ("crange", and "cr") are also renamed to "loc".
The traditional "code_location" (a pair of lineno and column) is
renamed to "code_position". Abbreviations are also renamed
(first_loc to beg_pos, and last_loc to end_pos).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61721 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
"loc" was ambiguous; it might refer both a location and a code range.
This change uses "loc" for a location, and "crange" or "cr" for a code
range.
A location (abbr. loc) is a point in a program and consists of line
number and column number. A code range (abbr. crange and cr) is a range
within a program and consists of a pair of locations which is the first
and the last.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
NODE_PRELUDE contains a `BEGIN` node, a main node, and compile_option.
This node is assumed that it must be located immediately under the root
NODE_SCOPE, but this strange assumption is not so good, IMO.
This change removes the assumtion; it integrates the former two nodes by
block_append, and moves compile_option into rb_ast_body_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit removes ISEQ_TYPE_DEFINED_GUARD because it is no longer
needed. And this introduces ISEQ_TYPE_PLAIN which means that the iseq
does nothing special but just wrap an expression. Currently, this is
used for once execution: `/foo#{ bar }baz/o`.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61601 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
It is too error-prone to pass IMEMO_IFUNC object as NODE*.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Currently, VM_INSN_INFO_TABLE_IMPL == 0 means linear search, and
VM_INSN_INFO_TABLE_IMPL == 1 means binary search. I plan to add
succinct bitvector algorithm later.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This makes TracePoint a bit fast by reducing cache misses of
`get_insn_info_binary_search`.
Also, I plan to use succinct bitvector algorithm for `get_insn_info`
instead of binary search. This change will make it easy.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61536 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This factors rb_iseq_constant_body#insns_info and #insns_info_size to
struct iseq_insn_info.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (iseq_inspect): show also code range information.
Note that `iseq_inspect` is used only for header of disasm.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61463 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.h (rb_compile_option_struct): trace instruction is removed so that
remove the trace_instruction compile option.
Don't show warning (just ignore) for Ruby 2.5.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61450 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (iseqw_trace_points): add `RubyVM::InstructionSequence#trace_points`
method for tools which want to manipulate ISeq (and traces).
* test/ruby/test_iseq.rb: add a test for this method.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61427 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (iseqw_each_child): add RubyVM::InstructionSequence#each_child
method for tools which want to manipulate ISeq.
* test/ruby/test_iseq.rb: add a test for this method.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
My motivation was to improve the output of `ruby --dump=insns xxx.rb`.
When one file has many iseqs, it's hard to find the one I want to read.
So I wanted `iseq_disasm` to show first_lineno. I unified the behavior
of `iseqw_disasm` for consistency.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_insn_operand_intern): simplified the condition for
local variable names, assume TS_LINDEX and TS_NUM combinations
are only for local variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_insn_operand_intern): show local variable name at
getblockparam/setblockparam too.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This change introduces get_insn_info_binary_search, which is (should be)
equivalent to the old get_insn_info.
The old get_insn_info is renamed to get_insn_info_linear_search. When
VM_CHECK_MODE > 0, the equivalence is validated at finish_iseq_build.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61353 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2.5's line coverage measurement was about two times slower than 2.4
because of two reasons; (1) vm_trace uses rb_iseq_event_flags (which
takes O(n) currently where n is the length of iseq) to get an event
type, and (2) RUBY_EVENT_LINE uses setjmp to call an event hook.
This change adds a special event for line coverage,
RUBY_EVENT_COVERAGE_LINE, and adds `tracecoverage` instructions where
the event occurs in iseq.
`tracecoverage` instruction calls an event hook without vm_trace.
And, RUBY_EVENT_COVERAGE_LINE is an internal event which does not
use setjmp.
This change also cancells lineno change due to the deletion of trace
instructions [Feature #14104]. So fixes [Bug #14191].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61350 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Before this change, coverage.so had failed to measure some multiple-line
code fragments. This is because removing trace instructions (#14104)
changed TracePoint's lineno (new lineno), and coverage counter array was
based on old lineno.
This change initializes coverage counter array based on new lineno.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61313 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* vm.c: introduce `ruby_vm_event_enabled_flags` which represents which
event flags are enabled before.
* vm_trace.c: do not turn off `trace_` prefix instructions because turn on
overhead is a matter if a program repeats turn on and turn off frequently.
* iseq.c (finish_iseq_build): respect `ruby_vm_event_enabled_flags`.
* vm_insnhelper.c (vm_trace): check `ruby_vm_event_flags` and disable
lazy trace-off technique (do not disable traces).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This change makes coverage use the general event type RUBY_EVENT_LINE
instead of a special event type RUBY_EVENT_COVERAGE.
Just a refactoring.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This change makes each ISeq keep NODE's code range. This information is
needed for method coverage.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_iseq_trace_set): simply return immediately if
ISeq::compile_data is available. Not sure why this state
is allowed, but exception during compile (or `ISeq::load`)
can make such states.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60915 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_iseq_trace_set): at this point ISEQ_USE_COMPILE_DATA
should not be set.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60871 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* vm_core.h (rb_iseq_t::aux): add `trace_events` which represents
which events are enabled on this iseq. With this information,
we can skip useless trace-on changes for ISeqs.
* vm_trace.c (RUBY_EVENTS_TRACE_BY_ISEQ): moved to iseq.h and rename it
with ISEQ_TRACE_EVENTS.
* iseq.h: introduce ISEQ_USE_COMPILE_DATA iseq (imemo) flag to represent
COMPILE_DATA is available. In other words, iseq->aux.trace_events is not
available when this flag is set.
* ISEQ_COMPILE_DATA() is changed from a macro.
* ISEQ_COMPILE_DATA_ALLOC() is added.
* ISEQ_COMPILE_DATA_CLEAR() is added.
* iseq.c: use them.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_iseq_trace_set): remove a wrong assertion.
This assertion checked `insn` is `trace_` prefix instruction
but threaded code `insn` is original code.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60820 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* vm_trace.c (update_global_event_hook): set only when tracing is added.
If tracing was off (event flags are decreased), then ignore them.
Next `trace_` prefix instruction will trace off itself (lazy tracing off).
* vm_insnhelper.c (vm_trace): trace-off for when trace is not needed.
* iseq.c (rb_iseq_trace_set): fix trace-off process (it was never off tracing).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60817 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* tool/instruction.rb: create `trace_` prefix instructions.
* compile.c (ADD_TRACE): do not add `trace` instructions but add
TRACE link elements. TRACE elements will be unified with a next
instruction as instruction information.
* vm_trace.c (update_global_event_hook): modify all ISeqs when
hooks are enabled.
* iseq.c (rb_iseq_trace_set): added to toggle `trace_` instructions.
* vm_insnhelper.c (vm_trace): added.
This function is a body of `trace_` prefix instructions.
* vm_insnhelper.h (JUMP): save PC to a control frame.
* insns.def (trace): removed.
* vm_exec.h (INSN_ENTRY_SIG): add debug output (disabled).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60763 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_iseq_disasm): do not dump repeatedly same iseq which
has been dumped by catch tables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60735 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (find_line_no): renamed to rb_iseq_line_no().
* vm_backtrace.c (calc_lineno): add a comment why we need to use "pos-1".
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_insn_operand_intern): show local variable operand
name in unified instructions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.h (iseq_line_info_entry): rename to iseq_insn_info_entry.
* vm_core.h (rb_iseq_constant_body): rename field name line_info_table
to insns_info and also from line_info_size to insns_info_size.
* compile.c (INSN): add struct insn_info to contain per insn information.
* compile.c (add_insn_info): added to add new insn_info entry.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
You can see ARGS_SIMPLE flag as follows:
$ ruby --dump=insns -e itself
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This re-introduces r60485.
This reverts commit 5a176b75b1.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60488 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
NODEs in AST are no longer objects managed by GC. This change will
remove the restriction imposed by the GC. For example, a NODE can use
more than five words (this is my primary purpose; we want to store the
position data for each NODE, for coverage library), or even a NODE can
have variable length (some kinds of NODEs have unused fields).
To do this, however, we need more work, since Ripper still uses T_NODE
objects managed by the GC.
The life time of NODEs is more obvious than other kinds of objects; they
are created at parsing, and they become disused immediately after
compilation. This change releases all NODEs by a few `xfree`s after
compilation, so performance will be improved a bit. In extreme example,
`eval("x=1;" * 10000000)` runs much faster (40 sec. -> 7.8 sec. on my
machine).
The most important part of this change is `ast_t` struct, which has
three contents: (1) NODE buffer (malloc'ed memory), (2) a reference to
the root NODE, and (3) an array that contains objects that must be
marked during parsing (such as literal objects). Some functions that
had received `NODE*` arguments, must now receive `ast_t*`.
* node.c, node.h: defines `ast_t` struct and related operations.
* gc.c, internal.h: defines `imemo_ast`.
* parse.y: makes `parser_params` struct have a reference to `ast_t`.
Instead of `rb_node_newnode`, use `rb_ast_newnode` to create a NODE.
* iseq.c, load.c, ruby.c, template/prelude.c.tmpl: modifies some
functions to handle `ast_t*` instead of `NODE*`.
* test/ruby/test_gc.rb: ad-hoc fix for a failed test. The test assumes
GC eden is increased at startup by NODE object creation. However,
this change now create no NODE object, so GC eden is not necessarily
increased.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60485 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
to represent execution context [Feature #14038]
* vm_core.h (rb_thread_t): rb_thread_t::ec is now a pointer.
There are many code using `th` to represent execution context
(such as cfp, VM stack and so on). To access `ec`, they need to
use `th->ec->...` (adding one indirection) so that we need to
replace them by passing `ec` instead of `th`.
* vm_core.h (GET_EC()): introduced to access current ec. Also
remove `ruby_current_thread` global variable.
* cont.c (rb_context_t): introduce rb_context_t::thread_ptr instead of
rb_context_t::thread_value.
* cont.c (ec_set_vm_stack): added to update vm_stack explicitly.
* cont.c (ec_switch): added to switch ec explicitly.
* cont.c (rb_fiber_close): added to terminate fibers explicitly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* array.c (rb_to_array_type): make public to share common code
internally.
* hash.c (rb_to_hash_type): make public to share common code
internally.
* symbol.c (rb_to_symbol_type): make public to share common code
internally.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_iseq_disasm_insn): Remove a meaningless
local variable assignment. `insn` is never changed
in this function, so a result of `insn_op_types(insn)`
is also never changed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59629 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* vm_core.h: rename absolute_path to realpath because it is expected name.
external APIs (#absolute_path methods) are remained.
* vm_core.h: remove rb_iseq_location_struct::path and
rb_iseq_location_struct::absolute_path and introduce pathobj.
if given path equals to given absolute_path (and most of case
it is true), pathobj is simply given path String. If it is not same,
pathobj is Array and pathobj[0] is path and pathobj[1] is realpath.
This size optimization reduce 8 bytes and
sizeof(struct rb_iseq_constant_body) is 200 bytes -> 192 bytes
on 64bit CPU.
To support this change, the following functions are introduced:
* pathobj_path() (defined in vm_core.h)
* pathobj_realpath() (ditto)
* rb_iseq_path() (decl. in vm_core.h)
* rb_iseq_realpath() (ditto)
* rb_iseq_pathobj_new() (ditto)
* rb_iseq_pathobj_set() (ditto)
* vm_core.h (rb_binding_t): use pathobj instead of path. If binding
is given at eval methods, realpath (absolute_path) was caller's
realpath. However, they should use binding's realpath.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
To convert the object implicitly, it has had two parts in convert_type() which are
1. lookink up the method's id
2. calling the method
Seems that strncmp() and strcmp() in convert_type() are slightly heavy to look up
the method's id for type conversion.
This patch will add and use internal APIs (rb_convert_type_with_id, rb_check_convert_type_with_id)
to call the method without looking up the method's id when convert the object.
Array#flatten -> 19 % up
Array#+ -> 3 % up
[ruby-dev:50024] [Bug #13341] [Fix GH-1537]
### Before
Array#flatten 104.119k (± 1.1%) i/s - 525.690k in 5.049517s
Array#+ 1.993M (± 1.8%) i/s - 10.010M in 5.024258s
### After
Array#flatten 124.005k (± 1.0%) i/s - 624.240k in 5.034477s
Array#+ 2.058M (± 4.8%) i/s - 10.302M in 5.019328s
### Test Code
require 'benchmark/ips'
class Foo
def to_ary
[1,2,3]
end
end
Benchmark.ips do |x|
ary = []
100.times { |i| ary << i }
array = [ary]
x.report "Array#flatten" do |i|
i.times { array.flatten }
end
x.report "Array#+" do |i|
obj = Foo.new
i.times { array + obj }
end
end
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (append_compile_error): set Qtrue for erred state with
showing the message immediately.
* iseq.c (prepare_iseq_build): make immediate message mode if main
or top level context, not to show the failed path twice in the
first line.
* iseq.c (cleanup_iseq_build): raise default message exception if
immediate message mode.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57313 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (iseqw_s_compile_file): deal with syntax error as well as
compile, and should not abort when rescued.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Use PRIuSIZE instead of PRIdSIZE. This fixes the exception message shown
on too large xmalloc2. This commit also fixes other incorrect use of
PRIdSIZE in other functions; though most of them are debug print.
* gc.c (heap_extend_pages, get_envparam_size, ruby_malloc_size_overflow,
gc_profile_dump_on): Use PRIuSIZE instead of PRIdSIZE as the passed
value is size_t, not ssize_t.
* iseq.c (get_line_info, rb_iseq_disasm_insn): Ditto.
* sprintf.c (rb_str_format): Ditto.
* thread_win32.c (native_thread_create): Ditto.
* vm.c (get_param): Ditto.
* ext/objspace/objspace_dump.c (dump_append_string_content,
dump_object): Ditto.
* ext/socket/raddrinfo.c (host_str, port_str): Ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (Init_ISeq): undefine allocator of InstructionSequence,
to get rid of segfaults at method call on uninitialized object.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55981 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
and VM_FRAME_CFRAME_P().
Most of case, RUBY_VM_NORMAL_ISEQ_P() is no
longer needed.
* vm_core.h: introduce rb_obj_is_iseq().
* cont.c, vm.c: VM_FRAME_MAGIC_DUMMY with
VM_FRAME_FLAG_CFRAME.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55804 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* *.c: rename rb_funcall2 to rb_funcallv, except for extensions
which are/will be/may be gems. [Fix GH-1406]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
[Bug #12628]
This patch introduce many changes.
* Introduce concept of "Block Handler (BH)" to represent
passed blocks.
* move rb_control_frame_t::flag to ep[0] (as a special local
variable). This flags represents not only frame type, but also
env flags such as escaped.
* rename `rb_block_t` to `struct rb_block`.
* Make Proc, Binding and RubyVM::Env objects wb-protected.
Check [Bug #12628] for more details.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55766 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
to prevent calling super classes' methods.
Without this patch, you can write workaround like:
class << RubyVM::InstructionSequence
def translate; end
undef translate
end
* test/ruby/test_iseq.rb: add a test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55656 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
instead of st_table.
* iseq.c (prepare_iseq_build): don't allocate ivar_cache_table
until it has at least one element.
* iseq.c (compile_data_free): free ivar_cache_table only if it
is allocated.
* compile.c (get_ivar_ic_value): allocate if the table is not
allocated yet.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
instance variable accesses. Reducing memory consumption,
rasing cache hit rate and rasing branch prediction hit rate
are expected. A part of [Bug #12274].
* iseq.h (struct iseq_compile_data): introduce instance
variable IC table for sharing.
* iseq.c (prepare_iseq_build, compile_data_free):
construct/destruct above table.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* error.c (rb_compile_err_append): rb_thread_t::base_block is no
longer used.
* iseq.c (rb_iseq_compile_with_option): ditto, no protection is
needed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54345 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (struct parser_params): move parse_in_eval flag from
rb_thread_t.
* parse.y (rb_parser_set_context): set parsing context, not only
mild error flag.
* iseq.c (rb_iseq_compile_with_option): the parser now refers no
thread local states to be restored.
* vm_eval.c (eval_string_with_cref): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_iseq_compile_with_option): make the parser in mild
error.
* load.c (rb_load_internal0): ditto.
* parse.y (yycompile0): return the error message within the error
to be raised. [Feature #11951]
* parse.y (parser_compile_error): accumulate error messages in the
error_buffer.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (prepare_iseq_build): enable coverage by coverage_enabled
option, not by parse_in_eval flag in the thread context.
* iseq.h (rb_compile_option_struct): add coverage_enabled flag.
* parse.y (yycompile0): set coverage_enabled flag if coverage
array is made.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54081 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (prepare_iseq_build): set coverage at once, not
repeatedly resetting.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54076 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
All of the strings created here eventually get converted to
fstrings when they are frozen into the iseq. Prepare the
fstring early so we may reduce a one or two objects.
This is a very minor change, mainly for the '<main>' dedupe.
* compile.c (caller_location): use rb_fstring_cstr for "<compiled>"
(it is converted to fstring anyways inside rb_iseq_new_with_opt)
* iseq.c (iseqw_s_compile): ditto
* iseq.c (rb_iseq_new_main): use rb_fstring_cstr for "<main>"
* vm.c (Init_VM): ditto, share with with above
* iseq.c (iseqw_s_compile_file): rb_fstring before rb_io_t->pathv
share "<main>" with above
* vm.c (rb_binding_add_dynavars): fstring "<temp>" immediately
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (iseqw_mark): as wrapped iseq is isolated from the call
stack, it needs to take care of its parent and ancestors, so
that they do not become orphans. [ruby-core:72620] [Bug #11928]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53514 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_iseq_compile_with_option): no volatile on gcc other
than 4.8.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53465 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_iseq_compile_with_option): prepare arguments outside
EXEC_TAG, and make local variables volatile not to be clobbered
by longjmp.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_iseq_compile_with_option): narrow down protected
region, and check/convert/prepare arguments before setting
base_block which needs to roll back.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53282 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
and a pre-compilation/runtime loader sample.
[Feature #11788]
* iseq.c: add new methods:
* RubyVM::InstructionSequence#to_binary_format(extra_data = nil)
* RubyVM::InstructionSequence.from_binary_format(binary)
* RubyVM::InstructionSequence.from_binary_format_extra_data(binary)
* compile.c: implement body of this new feature.
* load.c (rb_load_internal0), iseq.c (rb_iseq_load_iseq):
call RubyVM::InstructionSequence.load_iseq(fname) with
loading script name if this method is defined.
We can return any ISeq object as a result value.
Otherwise loading will be continue as usual.
This interface is not matured and is not extensible.
So that we don't guarantee the future compatibility of this method.
Basically, you should'nt use this method.
* iseq.h: move ISEQ_MAJOR/MINOR_VERSION (and some definitions)
from iseq.c.
* encoding.c (rb_data_is_encoding), internal.h: added.
* vm_core.h: add several supports for lazy load.
* add USE_LAZY_LOAD macro to specify enable or disable of
this feature.
* add several fields to rb_iseq_t.
* introduce new macro rb_iseq_check().
* insns.def: some check for lazy loading feature.
* vm_insnhelper.c: ditto.
* proc.c: ditto.
* vm.c: ditto.
* test/lib/iseq_loader_checker.rb: enabled iff suitable
environment variables are provided.
* test/runner.rb: enable lib/iseq_loader_checker.rb.
* sample/iseq_loader.rb: add sample compiler and loader.
$ ruby sample/iseq_loader.rb [dir]
will compile all ruby scripts in [dir].
With default setting, this compile creates *.rb.yarb files
in same directory of target .rb scripts.
$ ruby -r sample/iseq_loader.rb [app]
will run with enable to load compiled binary data.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* error.c (name_err_local_variables): new method
NameError#local_variables for internal use only.
[Feature #11777]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52942 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
because apply it multiple times change the sequence.
(iseq != peephole_optimize(load(iseq.to_a)))
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52924 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
call RubyVM::InstructionSequence.translate(iseq) if this method
is defined. If the return value is also an object of
RubyVM::InstructionSequence, then use it instead of created one.
For example, this method is useful to test iseq dumper/loader
such as RubyVM::InstructionSequence#to_a and rb_iseq_load().
Because this method is for such internal experimental usage,
the interface is not matured. For example, this interface has
no extensibility. Two or more translaters can not run
simultaneously.
So that we don't guarantee future compatibility of this method.
Basically, do not use this method.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52921 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Fields in rb_iseq_t::variable_body are contained by
rb_iseq_t::body::mark_ary (hidden Array object).
Index 0 to 2 of mark_ary are reserved by these objects.
* iseq.c: catch up this fix.
* compile.c (rb_iseq_original_iseq): trivial rewrite.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
ISEQ_ORIGINAL_ISEQ_ALLOC() macro.
* compile.c: use them to access original iseq buffer.
* iseq.c: ditto.
* vm_core.h: rename iseq field to support this fix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: use them.
* iseq.c: ditto.
* iseq.c (rb_iseq_coverage): added.
* thread.c (update_coverage): use rb_iseq_coverage().
* vm_core.h: rename coverage field name to support this fix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c, iseq.c: use ISEQ_COMPILE_DATA().
* vm_core.h: rename compile_data field to support this fix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52858 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.h (rb_compile_option_struct): rename the member
frozen_string_literal_debug as debug_frozen_string_literal.
[Feature #11725]
* ruby.c (proc_options): do not set $DEBUG and $VERBOSE only if no
arguments is given.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52749 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Add some comments to clarify the allocated field used for the
allocations while we're at it.
TODO: figure out a better way of testing/maintaining this...
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52419 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
in a made option value.
* vm_opts.h: forgot to add OPT_FROZEN_STRING_LITERAL_DEBUG
at last commit.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52258 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
If this option is enabled, the modify error will be:
can't modify frozen String (RuntimeError) =>
can't modify frozen String, created at test.rb:3 (RuntimeError)
* iseq.h: add compile option frozen_string_literal_debug.
* compile.c: catch up this fix.
* error.c (rb_error_frozen): ditto.
* iseq.c (set_compile_option_from_hash): ditto.
* test/ruby/test_rubyoptions.rb: add a test for this fix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52257 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_insn_operand_intern): change kw in callinfo disasm from the
number of keyword arguments to an ordered list of the keywords used.
[Feature #11589]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52123 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_compile_each): override compile option by option
given by pragma.
* iseq.c (rb_iseq_make_compile_option): extract a function to
overwrite rb_compile_option_t.
* parse.y (parser_set_compile_option_flag): introduce pragma to
override compile options.
* parse.y (magic_comments): new pragma "fronzen-string-literal".
[Feature #8976]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51953 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rb_call_info (ci) has compiled fixed information.
* if ci->flag & VM_CALL_KWARG, then rb_call_info is
also rb_call_info_with_kwarg. This technique reduce one word
for major rb_call_info data.
* rb_calling_info has temporary data (argc, blockptr, recv).
for each method dispatch. This data is allocated only on
machine stack.
* rb_call_cache is for inline method cache.
Before this patch, only rb_call_info_t data is passed.
After this patch, above three structs are passed.
This patch improves:
* data locarity (rb_call_info is now read-only data).
* reduce memory consumption (rb_call_info_with_kwarg,
rb_calling_info).
* compile.c: use above data.
* insns.def: ditto.
* iseq.c: ditto.
* vm_args.c: ditto.
* vm_eval.c: ditto.
* vm_insnhelper.c: ditto.
* vm_insnhelper.h: ditto.
* iseq.h: add iseq_compile_data::ci_index and
iseq_compile_data::ci_kw_indx.
* tool/instruction.rb: introduce TS_CALLCACHE operand type.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51903 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
string literals.
[Feature #11473]
This addition is not specification change, but to try frozen
string literal world discussed on [Feature #11473].
You can try frozen string literal world using this magical line:
RubyVM::InstructionSequence.compile_option =
{frozen_string_literal: true}
Note that this is a global compilation option, so that you need to
compile another script like that:
p 'foo'.frozen? #=> false
RubyVM::InstructionSequence.compile_option =
{frozen_string_literal: true}
p 'foo'.frozen? #=> false, because this line is already compiled.
p eval("'foo'.frozen?") #=> true
Details:
* String literals are deduped by rb_fstring().
* Dynamic string literals ("...#{xyz}...") is now only frozen,
not deduped. Maybe you have other ideas.
Now, please do not use this option on your productions :)
Of course, current specification can be changed.
* compile.c: ditto.
* test/ruby/test_iseq.rb: add a test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
iseq_location_setup always sets path, label and base_label fields,
and the only caller of iseq_location_setup (prepare_iseq_build) will
always pass non-nil `name' and `path' arguments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51581 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (iseq_memsize): reimplement for wrapper
(param_keyword_size): extracted from iseq_memsize
(iseqw_mark): new mark function
(iseqw_data_type): new data type
(iseqw_new): wrap as iseqw_data_type
(iseqw_check): adjust for wrapper
(Init_ISeq): remove iseqw_iseq_key initialization
* test/objspace/test_objspace.rb: new test
[ruby-core:70344] [Feature #11435]
v2 changes:
- added RUBY_TYPED_WB_PROTECTED and write barrier
- account for rb_call_info_kw_arg_t entries
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51547 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
rb_iseq_param_keyword::table and
rb_iseq_param_keyword::default_values.
* compile.c: catch up this fix.
* iseq.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51357 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
All contents of previous rb_iseq_t is in rb_iseq_t::body.
Remove rb_iseq_t::self because rb_iseq_t is an object.
RubyVM::InstructionSequence is wrapper object points T_IMEMO/iseq.
So RubyVM::ISeq.of(something) method returns different wrapper
objects but they point the same T_IMEMO/iseq object.
This patch is big, but most of difference is replacement of
iseq->xxx to iseq->body->xxx.
(previous) rb_iseq_t::compile_data is also located to
rb_iseq_t::compile_data.
It was moved from rb_iseq_body::compile_data.
Now rb_iseq_t has empty two pointers.
I will split rb_iseq_body data into static data and dynamic data.
* compile.c: rename some functions/macros.
Now, we don't need to separate iseq and iseqval (only VALUE).
* eval.c (ruby_exec_internal): `n' is rb_iseq_t (T_IMEMO/iseq).
* ext/objspace/objspace.c (count_imemo_objects): count T_IMEMO/iseq.
* gc.c: check T_IMEMO/iseq.
* internal.h: add imemo_type::imemo_iseq.
* iseq.c: define RubyVM::InstructionSequnce as T_OBJECT.
Methods are implemented by functions named iseqw_....
* load.c (rb_load_internal0): rb_iseq_new_top() returns
rb_iseq_t (T_IMEMO/iesq).
* method.h (rb_add_method_iseq): accept rb_iseq_t (T_IMEMO/iseq).
* vm_core.h (GetISeqPtr): removed because it is not T_DATA now.
* vm_core.h (struct rb_iseq_body): remove padding for
[Bug #10037][ruby-core:63721].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
rb_iseq_t::local_iseq is not constant data because
local_iseq::flip_cnt can be modified (commentted).
* compile.c: catch up this fix.
* iseq.c: ditto.
* vm_insnhelper.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
and VALUE *iseq to code.
* iseq.c (rb_iseq_disasm_insn): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51267 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
gc.c (gc_mark_children)only calls mark_func if the T_DATA ptr is
non-NULL, so avoid redundantly checking for that in each
mark function.
* iseq.c (iseq_mark): remove check for data pointer
* proc.c (binding_mark): ditto
* vm.c (rb_thread_mark): ditto
* vm_trace.c (tp_mark): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51252 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Fix RubyVM::InstructionSequence#to_a after r49517
Keywords were made symbols to fix [Bug #10831] [ruby-core:68031],
so we should dump symbols as-is instead of attempting to convert
them from IDs
* iseq.c (iseq_data_to_ary): dump kw_arg as symbol
* test/-ext-/iseq_load/test_iseq_load.rb: test kw_arg roundtrip
[ruby-core:69891] [Bug #11338]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
clone iseq any more.
* class.c (clone_method): share iseq between cloned methods. All of
method dependent information are able to refer from method entry.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51171 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* internal.h, iseq.c (rb_iseq_klass): remove it because
rb_iseq_t::klass is removed.
* vm_insnhelper.c (vm_super_outside): do not see cfp->iseq, but
check callable method entry on a frame.
This fix simplify the logic to search super class.
* test/ruby/test_method.rb: support super() from Proc.
Now, [Bug #4881] and [Bug #3136] was solved.
* proc.c (rb_mod_define_method): catch up this change.
* vm.c (vm_define_method): ditto.
* vm_backtrace.c (rb_profile_frames): now, each `frame' objects
are rb_callable_method_entry_t data or iseq VALUEs.
This fix introduce minor compatibility issue that
rb_profile_frame_label() always returns
rb_profile_frame_base_label().
* test/-ext-/debug/test_profile_frames.rb: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This simplifies all the callers and makes code easier to use
and review. I was confused about the need for RB_GC_GUARD
in define_{aset,aref}_method of struct.c without reading
rb_add_method_iseq.
Likewise, do the same for rb_iseq_clone, where the GC guard
only seems neccesary iff RGenGC is disabled.
* vm_method.c (rb_add_method_iseq): add RB_GC_GUARD
* class.c (clone_method): remove RB_GC_GUARD
* struct.c (define_aref_method): ditto
(define_aset_method): ditto
* vm.c (vm_define_method):
* iseq.c (rb_iseq_clone): add RB_GC_GUARD
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51079 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_iseq_compile_with_option): check srouce type, must be
an IO or a String. [ruby-core:69219] [Bug #11159]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50541 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_iseq_clone): need WB for iseq1->klass = iseq0->klass
(done in MEMCPY).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50015 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* vm_core.h, method.h: remove rb_iseq_t::cref_stack. CREF is stored
to rb_method_definition_t::body.iseq_body.cref.
* vm_insnhelper.c: modify SVAR usage.
When calling ISEQ type method, push CREF information onto method
frame, SVAR located place. Before this fix, SVAR is simply nil.
After this patch, CREF (or NULL == Qfalse for not iseq methods)
is stored at the method invocation.
When SVAR is requierd, then put NODE_IF onto SVAR location,
and NDOE_IF::nd_reserved points CREF itself.
* vm.c (vm_cref_new, vm_cref_dump, vm_cref_new_toplevel): added.
* vm_insnhelper.c (vm_push_frame): accept CREF.
* method.h, vm_method.c (rb_add_method_iseq): added. This function
accepts iseq and CREF.
* class.c (clone_method): use rb_add_method_iseq().
* gc.c (mark_method_entry): mark method_entry::body.iseq_body.cref.
* iseq.c: remove CREF related codes.
* insns.def (getinlinecache/setinlinecache): CREF should be cache key
because a different CREF has a different namespace.
* node.c (rb_gc_mark_node): mark NODE_IF::nd_reserved for SVAR.
* proc.c: catch up changes.
* struct.c: ditto.
* insns.def: ditto.
* vm_args.c (raise_argument_error): ditto.
* vm_eval.c: ditto.
* test/ruby/test_class.rb: add a test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (rb_method_for_self_aref, rb_method_for_self_aset):
move from iseq.c to build from node instead of arrays.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_build_from_ary_body): enclose funcptr with
Integer as raw pointer cannot appear in an Array.
* iseq.c (iseq_data_to_ary): extract funcptr from Integer.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_insn_operand_intern): show the name of the nearest
run-time symbol if possible.
* compile.c (insn_data_to_s_detail): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48858 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_method_for_self_aref, rb_method_for_self_aset): set
same location as the caller.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48851 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Class and Module objects can be living long life.
* iseq.c: Same for ISeq objects.
* gc.c (RVALUE_AGE_RESET): added.
* gc.c (newobj_of): allow to generate (age != 0) objects.
* gc.c (rb_copy_wb_protected_attribute): reset age for wb unprotected
objects.
* include/ruby/ruby.h: add RUBY_TYPED_PROMOTED1 as an unrecommended
flag.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48771 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* struct.c (define_aref_method, define_aset_method): use iseq
VALUE instead of rb_iseq_t to prevent from GC, as RB_GC_GUARD
makes sense only for local variables. [Feature #10575]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48754 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This avoids O(n) on lookups with structs over 10 members.
This also avoids O(n) behavior on all assignments on Struct members.
Members 0..9 still use existing C methods to read in O(1) time
Benchmark results:
vm2_struct_big_aref_hi* 1.305
vm2_struct_big_aref_lo* 1.157
vm2_struct_big_aset* 3.306
vm2_struct_small_aref* 1.015
vm2_struct_small_aset* 3.273
Note: I chose use loading instructions from an array instead of writing
directly to linked-lists in compile.c for ease-of-maintainability. We
may move the method definitions to prelude.rb-like files in the future.
I have also tested this patch with the following patch to disable
the C ref_func methods and ensured the test suite and rubyspec works
--- a/struct.c
+++ b/struct.c
@@ -209,7 +209,7 @@ setup_struct(VALUE nstr, VALUE members)
ID id = SYM2ID(ptr_members[i]);
VALUE off = LONG2NUM(i);
- if (i < N_REF_FUNC) {
+ if (0 && i < N_REF_FUNC) {
rb_define_method_id(nstr, id, ref_func[i], 0);
}
else {
* iseq.c (rb_method_for_self_aref, rb_method_for_self_aset):
new methods to generate bytecode for struct.c
[Feature #10575]
* struct.c (rb_struct_ref, rb_struct_set): remove
(define_aref_method, define_aset_method): new functions
(setup_struct): use new functions
* test/ruby/test_struct.rb: add test for struct >10 members
* benchmark/bm_vm2_struct_big_aref_hi.rb: new benchmark
* benchmark/bm_vm2_struct_big_aref_lo.rb: ditto
* benchmark/bm_vm2_struct_big_aset.rb: ditto
* benchmark/bm_vm2_struct_small_aref.rb: ditto
* benchmark/bm_vm2_struct_small_aset.rb: ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This allows reporters commenters of [Feature #8543] to load
instruction sequences directly. Some test cases are still failing
but documented in test/-ext-/iseq_load/test_iseq_load.rb.
* compile.c (rb_iseq_build_from_exception): entry->sp is unsigned
(iseq_build_callinfo_from_hash): account for kw_arg
(iseq_build_from_ary_body): update for r35459
(CHECK_STRING, CHECK_INTEGER): remove unused checks
(int_param): new function for checking new `params' hash
(iseq_build_kw): new function for loading rb_iseq_param_keyword
(rb_iseq_build_from_ary): account for `misc' entry and general
structure changes
[Feature #8543]
* iseq.c (CHECK_HASH): new macro (for `misc' and `param' entries)
(iseq_load): account for `misc' and `params' hashes
(iseq_data_to_ary): add final opt to arg_opt_labels,
fix kw support, account for unsigned entry->sp
* ext/-test-/iseq_load/iseq_load.c: new ext for test
* ext/-test-/iseq_load/extconf.rb: ditto
* test/-ext-/iseq_load/test_iseq_load.rb: new test
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48705 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Compile failures will trigger iseq_free before
iseq->callinfo_entries are allocated at all.
* iseq.c (iseq_free): avoid segfault on incomplete iseq
* test/ruby/test_syntax.rb (test_invalid_next): new test
for syntax error, not segfault
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48704 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (iseq_data_to_ary): use local variable indexes for hidden
variable instead of meaningless ID values.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48679 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
We must not ignore hidden variables when rb_id2str fails.
Thanks to wanabe [ruby-core:66566]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
use 0 for rb_data_type_t::reserved instead of NULL, since its type
may be changed in the future and possibly not a pointer type.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48662 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
It seems possible for a compiler to optimize away nbody
because we only access it via RARRAY_AREF and RARRAY_LEN
macros.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48597 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This will prevent some leaked FD warnings in future tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48578 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_insn_operand_intern): preserve encoding of method
name in CALL_INFO at disassembling.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
`opt_num' was the number of optional parameters + 1.
`opt_table' has "opt_num" entries.
Change them to:
`opt_num' is the number of optional parameters.
`opt_talbe' has "opt_num + 1" entries.
This change simplify parameter fitting logics.
* compile.c: catch up this change.
* iseq.c: ditto.
* proc.c: ditto.
* vm_args.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48247 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
https://bugs.ruby-lang.org/issues/10440#change-49694
* change terminology `arg' to `param'.
* move rb_iseq_t::arg_* to rb_iseq_t::param.
* move rb_iseq_t::arg_size to rb_iseq_t::param::size.
* move rb_iseq_t::argc to rb_iseq_t::param::lead_num.
* move rb_iseq_t::arg_opts to rb_iseq_t::param::opt_num.
* move rb_iseq_t::arg_rest to rb_iseq_t::param::rest_start.
* move rb_iseq_t::arg_post_num to rb_iseq_t::param::post_num.
* move rb_iseq_t::arg_post_start to rb_iseq_t::param::post_start.
* move rb_iseq_t::arg_block to rb_iseq_t::param::block_start.
* move rb_iseq_t::arg_keyword* to rb_iseq_t::param::keyword.
rb_iseq_t::param::keyword is allocated only when keyword
parameters are available.
* introduce rb_iseq_t::param::flags to represent parameter
availability. For example, rb_iseq_t::param:🎏:has_kw
represents that this iseq has keyword parameters and
rb_iseq_t::param::keyword is allocated.
We don't need to compare with -1 to check availability.
* remove rb_iseq_t::arg_simple.
* compile.c: catch up this change.
* iseq.c: ditto.
* proc.c: ditto.
* vm.c, vm_args.c, vm_dump.c, vm_insnhelper.c: ditto.
* iseq.c (iseq_data_to_ary): support keyword argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
keyword arguments/parameters and a splat argument.
[Feature #10440] (Details are described in this ticket)
Most of complex part is moved to vm_args.c.
Now, ISeq#to_a does not catch up new instruction format.
* vm_core.h: change iseq data structures.
* introduce rb_call_info_kw_arg_t to represent keyword arguments.
* add rb_call_info_t::kw_arg.
* rename rb_iseq_t::arg_post_len to rb_iseq_t::arg_post_num.
* rename rb_iseq_t::arg_keywords to arg_keyword_num.
* rename rb_iseq_t::arg_keyword to rb_iseq_t::arg_keyword_bits.
to represent keyword bitmap parameter index.
This bitmap parameter shows that which keyword parameters are given
or not given (0 for given).
It is refered by `checkkeyword' instruction described bellow.
* rename rb_iseq_t::arg_keyword_check to rb_iseq_t::arg_keyword_rest
to represent keyword rest parameter index.
* add rb_iseq_t::arg_keyword_default_values to represent default
keyword values.
* rename VM_CALL_ARGS_SKIP_SETUP to VM_CALL_ARGS_SIMPLE
to represent
(ci->flag & (SPLAT|BLOCKARG)) &&
ci->blockiseq == NULL &&
ci->kw_arg == NULL.
* vm_insnhelper.c, vm_args.c: rewrite with refactoring.
* rewrite splat argument code.
* rewrite keyword arguments/parameters code.
* merge method and block parameter fitting code into one code base.
* vm.c, vm_eval.c: catch up these changes.
* compile.c (new_callinfo): callinfo requires kw_arg parameter.
* compile.c (compile_array_): check the last argument Hash object or
not. If Hash object and all keys are Symbol literals, they are
compiled to keyword arguments.
* insns.def (checkkeyword): add new instruction.
This instruction check the availability of corresponding keyword.
For example, a method "def foo k1: 'v1'; end" is cimpiled to the
following instructions.
0000 checkkeyword 2, 0 # check k1 is given.
0003 branchif 9 # if given, jump to address #9
0005 putstring "v1"
0007 setlocal_OP__WC__0 3 # k1 = 'v1'
0009 trace 8
0011 putnil
0012 trace 16
0014 leave
* insns.def (opt_send_simple): removed and add new instruction
"opt_send_without_block".
* parse.y (new_args_tail_gen): reorder variables.
Before this patch, a method "def foo(k1: 1, kr1:, k2: 2, **krest, &b)"
has parameter variables "k1, kr1, k2, &b, internal_id, krest",
but this patch reorders to "kr1, k1, k2, internal_id, krest, &b".
(locate a block variable at last)
* parse.y (vtable_pop): added.
This function remove latest `n' variables from vtable.
* iseq.c: catch up iseq data changes.
* proc.c: ditto.
* class.c (keyword_error): export as rb_keyword_error().
* common.mk: depend vm_args.c for vm.o.
* hash.c (rb_hash_has_key): export.
* internal.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Fix https://travis-ci.org/ruby/ruby/jobs/36814282
Tested with -Wconversion since my gcc lacks -Wshorten-64-to-32
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47760 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Nearly all current uses of iseq->location.first_lineno are as a
VALUE, not a size_t. The only exception was the experimental
(and currently unused) rb_iseq_build_for_ruby2cext function.
* vm_core.h (rb_iseq_location_t): change first_lineno type to VALUE
* iseq.c (rb_iseq_build_for_ruby2cext): update based on argument
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
non-RVALUE data (to non-RVALUE data, of course).
Ruby 2.1 also has a same problem.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47191 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This reduces the iseq_compile_data_storage header from 32 to 16
bytes on 64-bit systems.
pos and size fields cannot exceed 32-bit sizes due to stack size
limits. Using a flexible array for the buffer also saves us 8
bytes of pointer overhead.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
iseq_size and line_info_size may be 32-bit.
4GB instruction sequences should be big enough for anyone.
Other existing line info counters are 32-bit, and nobody
should need all that.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46957 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Most iseq do not have a catch_table, so avoid needlessly adding
4-8 bytes to the struct for the common case.
Changes from v2:
- iseq_catch_table_size removed, use if (...) for (;...;)
Changes from v1:
- renamed iseq->_catch_table to iseq->catch_table
- iseq_catch_table_bytes: made a static inline function
- iseq_catch_table_size: new function replaces the
iseq_catch_table_each iterator macro
* iseq.h (struct iseq_catch_table): new flexible array struct
(iseq_catch_table_bytes): allocated size function
* vm_core.h (struct rb_iseq_struct): uupdate catch_table member
* compile.c (iseq_set_exception_table): update for struct changes
* iseq.c (iseq_free): ditto
* iseq.c (iseq_memsize): ditto
* iseq.c (rb_iseq_disasm): ditto
* iseq.c (iseq_data_to_ary): ditto
* iseq.c (rb_iseq_build_for_ruby2cext): ditto (untested)
* vm.c (vm_exec): ditto
* vm_core.h (struct rb_iseq_struct): ditto
* vm_insnhelper.c (vm_throw): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46811 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (iseq_type_from_id): linear search instead of hash lookup for
small fixed number keys.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44569 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (iseq_load): keep type_map to get rid of memory leak.
based on a patch by Eric Wong at [ruby-core:59699]. [Bug #9399]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_set_arguments): set arg_keyword_check from
nd_cflag, which is set by parser. internal ID is used for
unnamed keyword rest argument, which should be separated from no
keyword check.
* iseq.c (rb_iseq_parameters): if no keyword check, keyword rest is
present.
* parse.y (new_args_tail_gen): set keywords check to nd_cflag, which
equals to that keyword rest is not present.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_iseq_parameters): push argument type symbol only for
unnamed rest keywords argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44414 b2dd03c8-39d4-4d8f-98ff-823fe69b080e