Now this function only deals with branch events, so this change renames
it and remove complexity that is no longer needed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61046 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
Traditionally, method coverage measurement was implemented by inserting
`trace2` instruction to the head of method iseq. So, it just measured
methods defined by `def` keyword.
This commit drastically changes the measuring mechanism of method
coverage; at `RUBY_EVENT_CALL`, it keeps a hash from rb_method_entry_t*
to runs (i.e., it counts the runs per method entry), and at
`Coverage.result`, it creates the result hash by enumerating all
`rb_method_entry_t*` objects (by `ObjectSpace.each_object`).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61023 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
* compile.c (DECL_BRANCH_BASE, ADD_TRACE_BRANCH_COVERAGE): Add
a last location to arguments.
* compile.c (compile_if, compile_case, compile_case2, compile_loop, iseq_compile_each0):
Pass a last location to macros.
* ext/coverage/coverage.c (branch_coverage): Add a last location to
a return value.
* test/coverage/test_coverage.rb: Follow-up these changes.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_set_sequence): clear kwargs (in ci_entries) memory area.
kwargs ci entries are initialized by compiler. However, sometimes these
initializations are skipped because corresponding calls are eliminated
by some optimizations (for example, `if true` syntax elimnates else code).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60771 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
* compile.c (iseq_peephole_optimize): skip next `freezestring`
instruction after `concatstrings` instruction when frozen string
literal is enabled.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60756 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
* compile.c (iseq_peephole_optimize): do not need to put `pop`
instruction.
* test/ruby/test_optimization.rb (test_peephole_optimization_without_trace):
This code "def foo; 1.times{|(a), &b| nil && a}; end" fails to compile
by stack underflow because of above bug (fixed by this patch).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60724 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This magic number has two meanings depending upon the context:
* "required keyword argument (no name)" on NODE_LASGN (`def foo(x:)`)
* "rest argument (no name)" on NODE_MASGN and NODE_POSTARG
('a, b, * = ary` or `a, b, *, z = ary`)
To show this intention explicitly, two macros are introduced:
NODE_SPECIAL_REQUIRED_KEYWORD and NODE_SPECIAL_NO_NAME_REST.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (setup_args): In this function,
an argument of nd_line is argn except this line.
And argn is a pointer of NODE. So I think this
is a typo.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60649 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Now, casting NODE to VALUE is not recommended. This change requires an
explicit cast from VALUE to NODE to use the NODE utility functions such
as `nd_type`.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (compile_return): execute ensure clause after toplevel
return even in library toplevel other than the main script.
[ruby-core:83589] [Bug #14061]
test
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
When NODE_WHEN is compiled by iseq_compile_each0,
the node passed to compile_when is NODE_WHEN (not NODE_CASE).
So we can not handle the location of NODE_CASE of
case statements which don't have case expressions.
e.g. :
```
case; when 1; foo; when 2; bar; else baz; end
```
This commit adds NODE_CASE2, and compiles it by
iseq_compile_each0.
* compile.c (compile_case): Does not call COMPILE_ when
NODE_CASE does not have case expressions.
* compile.c (compile_case2): Compile NODE_CASE2 by compile_case2.
* compile.c (compile_when): Delete an obsoleted function.
* compile.c (iseq_compile_each0): Compile NODE_CASE2.
* ext/objspace/objspace.c (count_nodes): Add NODE_CASE2 case.
* node.c (dump_node, rb_gc_mark_node): Add NODE_CASE2 case.
* node.h (node_type): Add NODE_CASE2.
* node.h (NEW_CASE2): Add a macro which generates NODE_CASE2.
* parse.y: Generate NODE_CASE2 if case expressions don't exist.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60585 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (compile_if, compile_case, compile_loop, iseq_compile_each0):
Use nd_lineno of nodes for branch coverages.
nd_lineno is not adjusted line number of nodes.
Sometimes nd_line is adjusted by fixpos. These
adjustments lead to confusing result.
For example, lineno of NODE_IF is 1, but
line is 2 (line number is one-based).
```
;;;;;;;;;;;;;;;;;;;;if
1 + 1
2
end
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60581 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
[Feature #14045]
* insns.def (getblockparam, setblockparam): add special access
instructions for block parameters.
getblockparam checks VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM and
if it is not set this instruction creates a Proc object from
a given blcok and set VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM.
setblockparam is similar to setlocal, but set
VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM.
* compile.c: use get/setblockparm instead get/setlocal instructions.
Note that they are used for method local block parameters (def m(&b)),
not for block local method parameters (iter{|&b|).
* proc.c (get_local_variable_ptr): creates Proc object for
Binding#local_variable_get/set.
* safe.c (safe_setter): we need to create Proc objects for postponed
block parameters when $SAFE is changed.
* vm_args.c (args_setup_block_parameter): used only for block local blcok
parameters.
* vm_args.c (vm_caller_setup_arg_block): if called with
VM_CALL_ARGS_BLOCKARG_BLOCKPARAM flag then passed block values should be
a block handler.
* test/ruby/test_optimization.rb: add tests.
* benchmark/bm_vm1_blockparam*: added.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
A temporary NODE object was allocated to create iseq. Instead, this
patch allocates a dummy NODE as auto variable, and discard it soon.
This change is intended as a preparation to manage AST NODEs out of GC.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60390 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_peephole_optimize): eliminate simple self
assignments of a local variable when the result is used.
follow-up of r60322.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_peephole_optimize): eliminate repeated
assignments and copy from/to a same local variable.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (defined_expr0): This node_type has
not been used since r11614.
* ext/objspace/objspace.c (count_nodes): ditto
* node.c (dump_node): ditto
* node.h (node_type, NEW_CVDECL): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60307 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_compile_each0): fix stack consitency error on
attr-assign with safe navigation operator when the receiver is
nil, should pop it too. [ruby-core:83078] [Bug #13964]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* insns.def (intern): new instruction to turn string into symbol.
opt_call_c_function can not dump.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59951 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_compile_each0): insert to_s method call, so that
refinements activated at the caller should take place.
[Feature #13812]
* insns.def (tostring): fix up converted object to a string,
infect and fallback.
* insns.def (branchiftype): new instruction for conversion.
branches if TOS is an instance of the given type.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59950 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_compile_each0): literal symbol should not be
affected by redefinition of String#intern method.
* vm_insnhelper.c (rb_vm_str_intern): intern a string into a
symbol directly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59946 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_peephole_optimize): optimize away unnecessary
concatenation of single string, following tostring which always
puts a String instance.
https://github.com/ruby/ruby/pull/1626#discussion_r139285653
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59945 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
`unless` statement was a syntactic sugar for `if` statement,
which made the result of branch coverage hard to understand.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59889 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This is needed for passing to the hook function the measuring target
type (line/branch/method) and the site of coverage event fired.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59871 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_compile_each0): pop trace for coverage only and
clear its corresponding line. [ruby-core:82726] [Bug #13886]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59828 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (int_param): prefer FIXNUM_P and NIL_P to switch by
TYPE.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59788 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
When no instruction is emitted in `iseq_compile_each0`
(i.e., when the line has no significant code), trace
instruction for `RUBY_EVENT_LINE` has been optimized out.
But trace for `RUBY_EVENT_COVERAGE` has not been removed.
Now, it is also removed.
`TestISeq#test_to_a_lines` has failed a long time under
coverage measurement (`make test-all COVERAGE=true`).
This change makes it pass.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59769 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
To prepare new measuring targets: branch and method coverages.
So far, iseq->coverage was an array of counts executed for line coverage.
Now, it is a three-element array for each measuring target,
whose first element is an array for line coverage.
The second element is planned for branch coverage, and the third will be
for method coverage.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59738 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (ibf_load_iseq_each): location.pathobj may not be a
mere string now.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59709 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_peephole_optimize): remove unreachable chunk
which appeared by useless jump elimination.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59656 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* template/insns.inc.tmpl (ASSERT_VM_INSTRUCTION_SIZE): static
assertion for VM instruction info tables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (compile_array_keyword_arg): fix the condition of
KW_SPLAT flag. splat is value node only without key node,
simple assoc argument is not. [ruby-core:82291] [Bug #13793]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59556 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_set_sequence): replace adjuststack with pop, or
remove if possible instead of two nops.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59446 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_compile_each0): as compile_flip_flop always ends
with a jump instruction, successive instruction is never reached,
but caused stack consistency error without peephole optimization.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59442 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: raise COMPILE_ERROR instead of compile_bug which is
very rarely (or never, actually) useful to debug instruction
sequence. COMPILE_ERROR is usually SyntaxError, or fatal error
if compile_debug is enabled,
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59388 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_compile_each0): restore the stack depth after
return to the previous depth, to fix the stack depth at
returning from rescue iseq. [ruby-core:82108] [Bug #13755]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_compile_each0): turned dregx context in "once"
into "guarded" type from "block" type, to disallow `next`,
`break`, `redo` as well as outside "once".
[ruby-core:81805] [Bug #13690]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59202 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_compile_each0): adjust stack after return in
toplevel ensure, when the value is used.
[ruby-core:81777] [Bug #13682]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59184 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_compile_each0): debugs/ruby_debug_printf do not
support PRIsVALUE.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (fix_sp_depth): separate fix-up of sp depth from code
generation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59171 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_compile_each0): adjust the stack before return
in an evstr/argument (reported by Balazs <balazs@kutilovi.cz>)
to fix stack consistency error. [ruby-core:81761] [Bug #13678]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59169 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_set_sequence): separate instruction dump and
error, before allocation of sequence.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59079 b2dd03c8-39d4-4d8f-98ff-823fe69b080e