Граф коммитов

746 Коммитов

Автор SHA1 Сообщение Дата
mame c3c0c0745f thread.c (update_branch_coverage): renamed from `update_coverage`
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
2017-12-06 07:04:48 +00:00
mame ec02c4861b thread.c (update_line_coverage): Use RUBY_EVENT_LINE
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
2017-12-06 06:39:05 +00:00
mame a5e02f249d vm_core.h (rb_iseq_locatoin_t): add a field `code_range`
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
2017-12-05 08:56:50 +00:00
mame 0a6816ecd7 Revamp method coverage to support define_method
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
2017-12-05 07:16:42 +00:00
ko1 26451ab3ba introduce `trace_events' info for iseq.
* 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
2017-11-18 09:39:41 +00:00
mame ec3a906bb6 Refactoring out the direct accesses of NODE's u1, u2, and u3
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60812 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-16 11:03:37 +00:00
yui-knk 7fbab01f77 Add a last location to branch coverage
* 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
2017-11-16 03:36:20 +00:00
ko1 1d7247e694 fix uninitialized memory reference.
* 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
2017-11-15 04:52:39 +00:00
nobu c00265bbcc compile.c: fixup TRACE
* compile.c (remove_unreachable_chunk): ignore TRACE elements.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60768 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-14 17:07:47 +00:00
ko1 b000b1d930 fix prefix.
* compile.c: the following functions accept LINK_ELEMENT so
  rename to `ELEM_` prefix names:
  * INSERT_ELEM_NEXT -> ELEM_INSERT_NEXT
  * INSERT_ELEM_PREV -> ELEM_INSERT_PREV
  * REPLACE_ELEM     -> ELEM_REPLACE
  * REMOVE_ELEM      -> ELEM_REMOVE


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-14 13:18:44 +00:00
ko1 665ba24b44 remove `trace` instruction. [Feature #14104]
* 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
2017-11-14 12:58:36 +00:00
nobu 9cabbf849e compile.c: comments for concatstrings optimization [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-14 02:40:04 +00:00
nobu 496b4267b2 compile.c: fixup r60727
* 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
2017-11-13 23:53:00 +00:00
nobu 7b1f3906a0 compile.c: optimize nested string interpolations
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-09 08:27:01 +00:00
ko1 1c5ae5a163 insn_info/insns_info
* 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
2017-11-09 06:57:24 +00:00
ko1 976b6df959 fix peephole optimization.
* 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
2017-11-09 04:27:27 +00:00
mame af9b0da125 Avoid usage of the magic number `(NODE*)-1`
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
2017-11-04 14:24:16 +00:00
yui-knk 6d022ae147 compile.c (setup_args): Fix a typo
* 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
2017-11-04 13:59:34 +00:00
mame b6e80c2260 Remove RNODE cast from NODE utility functions
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
2017-11-04 11:37:19 +00:00
nobu d49fca8894 compile.c: kw splat after splat
* compile.c (setup_args): set keyword splat flag after splat
  arguments.  [ruby-core:83638] [Bug #10856]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60613 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-02 07:52:49 +00:00
nobu ae49dbd392 compile.c: refactored compile_return
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-01 03:26:55 +00:00
nobu 84d931415e compile.c: ensure after return in library toplevel
* 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
2017-10-31 09:33:22 +00:00
nobu 6806c16fef compile.c: compile_return
* compile.c (compile_return): extract from iseq_compile_each.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60589 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-31 09:33:21 +00:00
yui-knk a09e175068 Use NODE_CASE2 if case expressions don't exist
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
2017-10-31 00:46:30 +00:00
yui-knk 4eb38bf59d Use nd_lineno instead of nd_line for branch coverages
* 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
2017-10-30 23:44:42 +00:00
ko1 6b0b79caee fix compile error.
* compile.c (iseq_compile_each): fix declaration because VC shows compile error.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60497 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-28 00:45:43 +00:00
nobu 95cd1aef52 compile.c: make node arguments invariant
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60494 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-27 21:08:35 +00:00
mame 15270f48a9 compile.c: stop modifying NODE tree
This fixes some modification remained in r60479

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60487 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-27 16:34:57 +00:00
nobu fd14454688 compile.c, iseq.c: consitfied NODE pointers
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-27 12:00:38 +00:00
ko1 e95de48f1d some functions accept `ec` instead of `th`.
* vm.c (vm_make_env_object): accepts `ec`.

* vm.c (rb_vm_get_ruby_level_next_cfp): ditto.

* vm.c (rb_vm_make_proc): ditto.

* vm.c (rb_vm_make_proc_lambda): ditto.

* vm_core.h: some macros accept ec instead of th
  (and make them inline functions):
  * RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW
  * RUBY_VM_END_CONTROL_FRAME
  * RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P

* eval.c (frame_func_id): constify for the first parameter.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60441 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-26 08:41:34 +00:00
ko1 837fd5e494 Use rb_execution_context_t instead of rb_thread_t
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
2017-10-26 08:32:49 +00:00
nobu 6b818dd961 common conversion functions
* 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
2017-10-26 07:23:23 +00:00
nobu 9db92694b0 compile.c: refine error messages
* compile.c (rb_iseq_compile_node): raise compile error with exact
  iseq type name.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60412 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-25 01:45:28 +00:00
ko1 5ee9513a71 Lazy Proc allocation for block parameters
[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
2017-10-24 11:13:49 +00:00
nobu 2c786bf35d Removed NODE_OPT_N
* node.h (NODE_OPT_N): removed.

* parse.y (parser_append_options): expand -n option loop to while
  gets loop.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60394 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-24 08:00:36 +00:00
mame ac3bad418c Remove dynamic NODE allocation out of parser
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
2017-10-24 06:16:31 +00:00
yui-knk 755dd9f461 Add column numbers to branch coverage
* compile.c (DECL_BRANCH_BASE, ADD_TRACE_BRANCH_COVERAGE): Add
  column to arguments.

* compile.c (compile_if, compile_case, compile_when, compile_loop, iseq_compile_each0):
  Pass column numbers to macros.

* ext/coverage/coverage.c (branch_coverage): Add column numbers to
  a return value.

* test/coverage/test_coverage.rb: Follow-up these changes.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60362 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22 13:18:40 +00:00
nobu 72f88ebcc1 compile.c: optimize local variable assignments
* 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
2017-10-22 01:46:43 +00:00
nobu bb3f2ce752 compile.c: optimize local variable assignments
* 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
2017-10-21 23:30:39 +00:00
yui-knk d98db55b73 Remove not used node_type NODE_CVDECL
* 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
2017-10-21 16:09:51 +00:00
yui-knk 92746378ab Remove not used node_type NODE_IASGN2
* compile.c (compile_massign_opt, iseq_compile_each0): This
  node_type has not been used since r11813.
* ext/objspace/objspace.c (count_nodes): ditto
* node.c (dump_node, rb_gc_mark_node): ditto
* node.h (node_type, NEW_IASGN2): ditto
* parse.y (node_assign_gen): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 15:56:03 +00:00
nobu 342e9ae38a moved node generation for dregex_once to parse.y
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 01:06:25 +00:00
nobu ee34bbbcbd compile.c: compile_for
* compile.c (compile_for): extract from iseq_compile_each.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-17 12:05:32 +00:00
nobu e0ef514a35 compile.c: compile_iter
* compile.c (compile_iter): extract from iseq_compile_each.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60199 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-17 12:05:30 +00:00
nobu 4fb1438b9d use rb_hash_new_with_size()
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60101 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-02 12:23:17 +00:00
nobu 896e7f2d8d compile.c: fix stack consitency error
* 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
2017-10-02 08:33:30 +00:00
yui-knk 7da13f05fd Enable to take branch coverages for safe method invocations
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-23 00:17:35 +00:00
nobu 5d988300b2 intern instruction
* 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
2017-09-18 05:16:37 +00:00
nobu b2da3824c5 refinements in string interpolation
* 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
2017-09-18 02:27:13 +00:00
nobu df33c063fc literal symbol by intern
* 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
2017-09-17 09:28:58 +00:00
nobu 08bb3640d7 compile.c: optimize unnecessary concatstrings
* 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
2017-09-17 09:21:47 +00:00
nobu ad094e3ac3 suppress warnings
* compile.c: suppress maybe-uninitialized warnings by gcc7.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59941 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-17 05:51:15 +00:00
nobu ea49381e51 compile.c: iseq_pop_newarray
* compile.c (iseq_pop_newarray): optimize array literal in
  condition.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59892 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-14 08:04:30 +00:00
mame 3c8c17d30d Introduce NODE_UNLESS for branch coverage
`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
2017-09-14 05:27:02 +00:00
mame 78cf46078e Add method coverage
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-14 05:12:34 +00:00
mame 1f7abf7283 Add branch coverage for case-when statement
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-14 04:32:58 +00:00
mame 16ab236b88 Add branch coverage for while and until statements
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-14 03:36:05 +00:00
mame ce570370f0 Add branch coverage for if statement
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-14 03:25:36 +00:00
mame d1b290d5ba Add a new instruction `trace2` for hooking with custom data
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
2017-09-14 01:55:30 +00:00
nobu d446f15c97 compile.c: pop coverage trace
* 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
2017-09-10 16:19:40 +00:00
nobu 6c3c48e3d5 compile.c: replaced switch by TYPE
* 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
2017-09-09 09:16:56 +00:00
mame 1a643bac88 Remove unneeded trace instruction for coverage
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
2017-09-07 12:36:01 +00:00
mame cd6df5fb3c Refactor the internal data format for coverage measurement
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
2017-09-03 14:26:06 +00:00
nobu b8243bb8f2 compile.c: fix loading pathobj
* 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
2017-09-01 00:58:52 +00:00
nobu d6347a467d compile.c: ensure after toplevel return
* compile.c (iseq_compile_each0): toplevel returns should fire
  ensures.  [ruby-core:82492] [Bug #13844]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59708 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-01 00:43:00 +00:00
nobu 4446f52896 compile.c: compile_if
* compile.c (compile_if): extract from iseq_compile_each.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-28 14:21:40 +00:00
nobu a2f5275e0b compile.c: compile_ensure
* compile.c (compile_ensure): extract from iseq_compile_each.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-27 16:18:17 +00:00
nobu 7999209019 compile.c: compile_resbody
* compile.c (compile_resbody): extract from iseq_compile_each.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59669 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-27 16:15:19 +00:00
nobu c1b32b5a1b compile.c: compile_rescue
* compile.c (compile_rescue): extract from iseq_compile_each.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-27 16:04:26 +00:00
nobu c0baa381b5 compile.c: unreachable chunk
* 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
2017-08-25 03:41:43 +00:00
nobu ed3a575b59 compile.c: useless jump elimination
* compile.c (iseq_peephole_optimize): eliminate useless if/unless
  just before jump.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59655 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-25 03:33:32 +00:00
nobu 0faeb9039f compile.c: moved comments [ci skip]
* compile.c (iseq_peephole_optimize): moved comments inside proper
  blocks.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59653 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-25 02:37:38 +00:00
nobu 7971a1246b compile.c: show failed instructions
* compile.c (iseq_set_sequence): show failed instructions at
  adjuststack mismatch.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-24 07:31:56 +00:00
nobu 37228c0fe2 compile.c: free before adjust error
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-24 07:26:05 +00:00
nobu 1f89414c20 insns.inc.tmpl: ensure info size
* 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
2017-08-22 03:07:01 +00:00
nobu bc33c5ce0a compile.c: compile_retry
* compile.c (compile_retry): extract from iseq_compile_each.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-15 00:45:14 +00:00
nobu b0e2c2476e compile.c: compile_redo
* compile.c (compile_redo): extract from iseq_compile_each.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-15 00:45:13 +00:00
nobu 7e958b890e compile.c: compile_next
* compile.c (compile_next): extract from iseq_compile_each.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-15 00:18:47 +00:00
nobu 582b7057dc compile.c: compile_break
* compile.c (compile_break): extract from iseq_compile_each.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-14 23:55:34 +00:00
nobu d5b3c0fda6 compile.c: compile_loop
* compile.c (compile_loop): extract from iseq_compile_each.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-14 14:25:27 +00:00
nobu 3bf3108c8e type is invariant inside this block
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59589 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-14 14:18:29 +00:00
nobu 03a2862b98 separate hash literal and keyword arguments
* compile.c (compile_array_keyword_arg): separate keyword splat
  inside hash literal from argument list.

* parse.y (rparen): flag hash literal.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-11 01:27:24 +00:00
nobu 059cf260e7 compile.c: fix KW_SPLAT flag condition
* 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
2017-08-10 00:50:45 +00:00
nobu 26aed9c577 splat keyword hash
* compile.c (compile_array_keyword_arg): set keyword splat flag if
  explicitly splatted.  [ruby-core:68124] [Bug #10856]

* vm_args.c (setup_parameters_complex): try keyword hash splat if
  given.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59519 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-05 06:58:44 +00:00
nobu 44544c036c compile.c: replace adjuststack
* 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
2017-07-30 00:40:43 +00:00
nobu c1d5d16c38 compile.c: fix flip-flop value
* 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
2017-07-29 02:03:11 +00:00
nobu 52bb1dadd5 compile.c: COMPILE_ERROR
* 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
2017-07-22 06:01:38 +00:00
nobu 86dc8c81ce compile.c: dump iseq at adjust bug
* compile.c (fix_sp_depth): dump instructions at adjust bug too.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59387 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-21 22:45:13 +00:00
nobu 8c5e7c59ff compile.c: restore stack at return
* 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
2017-07-20 02:43:45 +00:00
nobu d2dd18ed16 compile.c: simplify defined_expr0
* compile.c (defined_expr0): exapnd defined_expr macro.

* compile.c (defined_expr0): reduce duplicate code.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59309 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-10 11:42:07 +00:00
nobu 703675da95 compile.c: dump iseq
* compile.c (append_compile_error): raise a fatal error when
  compile_debug is enabled.

* compile.c (COMPILE_ERROR): dump the disassembled instruction
  instruction sequence always.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-30 02:09:42 +00:00
nobu 0a11abfc7e compile.c: disallow next in once
* 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
2017-06-29 04:01:30 +00:00
nobu 5cfda37971 fix return in toplevel ensure
* 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
2017-06-27 14:09:08 +00:00
nobu 1474acff3c fix return in toplevel rescue/ensure
* compile.c (iseq_compile_each0): throw TAG_RETURN at return in
  toplevel rescue/ensure to adjust VM stack properly.
  [ruby-core:81777] [Bug #13682]

* vm_insnhelper.c (vm_throw_start): allow return in toplevel
  rescue/ensure.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-27 06:57:34 +00:00
nobu 72c46d217a compile.c: fix debug print
* 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
2017-06-26 00:59:24 +00:00
nobu 04b3328cd9 compile.c: fix_sp_depth
* 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
2017-06-25 08:55:23 +00:00
nobu 8f1c93f409 compile.c: toplevel return in argument
* 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
2017-06-25 05:10:48 +00:00
nobu af4ba5c12a parse.y: should not warn op method call
* parse.y (void_expr_gen): should warn operator expression style
  calls only, but not method style calls.  [Fix GH-1660]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-23 11:56:48 +00:00
ko1 1d248f0429 use NULL instead of 0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59154 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-23 05:55:12 +00:00
nobu e6d9e4c8c6 compile.c: dump and error before allocation
* 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
2017-06-14 05:10:30 +00:00