summaryrefslogtreecommitdiff
path: root/compile.c
AgeCommit message (Collapse)Author
2018-01-02rb_insn_func_t is incompatible with void*shyouhei
Why not just use void* ? git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61543 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-01iseq.h: Extract position array from iseq_insn_info_entrymame
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
2018-01-01vm_core.h: refactoring of insns_infomame
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
2017-12-25Set first line numbers for empty iseqs.ko1
* compile.c (iseq_compile_each): for empty method, block and so on, `last_line` is not set so that line number of `putnil` instruction will be zero. This patch set `first_lineno` for such `putnil`. Problem is reported by deivid-rodriguez via Yuichiro Kaneko. * test/ruby/test_iseq.rb: add a test for this spec. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61457 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-24compile.c: toplevel return argumentsnobu
* compile.c (compile_return): evaluate arguments to top-level return but ignore the results. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61437 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-23fix last commitko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61428 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-23RubyVM::InstructionSequence#trace_points.ko1
* 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
2017-12-23revert line number spec of *return events.ko1
* compile.c (rb_iseq_compile_node): line number spec of :return, :b_return and :end events of 'TracePoint` is changed for [Feature #14104]. Quoted from [Feature #14104]: > Line numbers on :return/:b_return events show the last executed lines, > instead of end lines (without return statement). Note that :end event also affected. However, "buybug", a well-known ruby debugger depends on previous behavior so that I reverted this specification. * test/ruby/test_settracefunc.rb: catch up this fix. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-21revert r61371 for [Bug #14214]ko1
Reverted patch doesn't check overwritten value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61387 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-20compile.c: branch on block paramnobu
* compile.c (compile_branch_condition): replace block param value in branch conditions with `defined(yield)`, to get rid of creating proc value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61371 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-20compile.c: add a RUBY_EVENT_COVERAGE_LINE event for line coveragemame
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
2017-12-19compile.c: pop splat resultnobu
* compile.c (compile_array): pop splat result without creating a new hash if the whole hash is popped. [ruby-core:84340] [Bug #14201] From: Nobuyoshi Nakada <nobu@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61331 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-19compile.c: side effect in splatnobu
* compile.c (compile_array): splat which may have side effects should be compiled even if the result will be popped. [ruby-core:84340] [Bug #14201] From: Nobuyoshi Nakada <nobu@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61329 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-18iseq.c (finish_iseq_build): fix coverage leakage [Bug #14191]mame
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
2017-12-14node.[ch], parse.y, compile.c: rename nd_column to nd_first_columnmame
nd_set_column -> nd_first_set_column nd_lineno -> nd_first_lineno nd_set_lineno -> nd_first_set_lineno git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-06compile.c (rb_iseq_compile_node): Move the check for imemo_ifunc to topmame
Applying nd_type to imemo_ifunc object seems harmless fortunately, but very dirty (to me). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-06vm_core.h (RUBY_EVENT_COVERAGE_BRANCH): renamedmame
This change moves RUBY_EVENT_COVERAGE from include/ruby/ruby.h to vm_core.h and renames it to RUBY_EVENT_COVERAGE_BRANCH. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61049 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-06insns.def (tracebranch): renamed from `trace2`mame
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61047 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-06thread.c (update_branch_coverage): renamed from `update_coverage`mame
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-06thread.c (update_line_coverage): Use RUBY_EVENT_LINEmame
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-05vm_core.h (rb_iseq_locatoin_t): add a field `code_range`mame
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-05Revamp method coverage to support define_methodmame
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-11-18introduce `trace_events' info for iseq.ko1
* 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-16Refactoring out the direct accesses of NODE's u1, u2, and u3mame
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60812 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-16Add a last location to branch coverageyui-knk
* 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-15fix uninitialized memory reference.ko1
* 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-14compile.c: fixup TRACEnobu
* 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-14fix prefix.ko1
* 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-14remove `trace` instruction. [Feature #14104]ko1
* 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-14compile.c: comments for concatstrings optimization [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-13compile.c: fixup r60727nobu
* 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-09compile.c: optimize nested string interpolationsnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-09insn_info/insns_infoko1
* 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-09fix peephole optimization.ko1
* 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-04Avoid usage of the magic number `(NODE*)-1`mame
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-04compile.c (setup_args): Fix a typoyui-knk
* 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-04Remove RNODE cast from NODE utility functionsmame
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-02compile.c: kw splat after splatnobu
* 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-01compile.c: refactored compile_returnnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-31compile.c: ensure after return in library toplevelnobu
* 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-31compile.c: compile_returnnobu
* 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-31Use NODE_CASE2 if case expressions don't existyui-knk
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-30Use nd_lineno instead of nd_line for branch coveragesyui-knk
* 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-28fix compile error.ko1
* 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-27compile.c: make node arguments invariantnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60494 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-27compile.c: stop modifying NODE treemame
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-27compile.c, iseq.c: consitfied NODE pointersnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-26some functions accept `ec` instead of `th`.ko1
* 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-26Use rb_execution_context_t instead of rb_thread_tko1
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-26common conversion functionsnobu
* 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