aboutsummaryrefslogtreecommitdiffstats
path: root/compile.c
Commit message (Collapse)AuthorAgeFilesLines
* compile.c: optimize nested string interpolationsnobu2017-11-091-1/+66
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* insn_info/insns_infoko12017-11-091-44/+69
| | | | | | | | | | | | | | * 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
* fix peephole optimization.ko12017-11-091-3/+0
| | | | | | | | | | | | * 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
* Avoid usage of the magic number `(NODE*)-1`mame2017-11-041-3/+3
| | | | | | | | | | | | | 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): Fix a typoyui-knk2017-11-041-1/+1
| | | | | | | | | * 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
* Remove RNODE cast from NODE utility functionsmame2017-11-041-1/+1
| | | | | | | | 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: kw splat after splatnobu2017-11-021-0/+2
| | | | | | | * 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
* compile.c: refactored compile_returnnobu2017-11-011-9/+15
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: ensure after return in library toplevelnobu2017-10-311-14/+5
| | | | | | | | | | * 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
* compile.c: compile_returnnobu2017-10-311-56/+62
| | | | | | * 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
* Use NODE_CASE2 if case expressions don't existyui-knk2017-10-311-11/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Use nd_lineno instead of nd_line for branch coveragesyui-knk2017-10-301-13/+17
| | | | | | | | | | | | | | | | | | | | * 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
* fix compile error.ko12017-10-281-2/+2
| | | | | | | * 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
* compile.c: make node arguments invariantnobu2017-10-271-48/+48
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60494 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: stop modifying NODE treemame2017-10-271-7/+3
| | | | | | This fixes some modification remained in r60479 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60487 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c, iseq.c: consitfied NODE pointersnobu2017-10-271-105/+114
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* some functions accept `ec` instead of `th`.ko12017-10-261-2/+2
| | | | | | | | | | | | | | | | | | | | | * 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
* Use rb_execution_context_t instead of rb_thread_tko12017-10-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* common conversion functionsnobu2017-10-261-9/+7
| | | | | | | | | | | | | * 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
* compile.c: refine error messagesnobu2017-10-251-10/+14
| | | | | | | * 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
* Lazy Proc allocation for block parametersko12017-10-241-8/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [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
* Removed NODE_OPT_Nnobu2017-10-241-9/+2
| | | | | | | | | * 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
* Remove dynamic NODE allocation out of parsermame2017-10-241-5/+8
| | | | | | | | 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
* Add column numbers to branch coverageyui-knk2017-10-221-18/+25
| | | | | | | | | | | | | | | * 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
* compile.c: optimize local variable assignmentsnobu2017-10-221-3/+7
| | | | | | | | * 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: optimize local variable assignmentsnobu2017-10-211-4/+41
| | | | | | | * 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
* Remove not used node_type NODE_CVDECLyui-knk2017-10-211-1/+0
| | | | | | | | | | * 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
* Remove not used node_type NODE_IASGN2yui-knk2017-10-211-3/+1
| | | | | | | | | | | * 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
* moved node generation for dregex_once to parse.ynobu2017-10-211-4/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: compile_fornobu2017-10-171-26/+37
| | | | | | * 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
* compile.c: compile_iternobu2017-10-171-32/+38
| | | | | | * 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
* use rb_hash_new_with_size()nobu2017-10-021-2/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60101 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: fix stack consitency errornobu2017-10-021-1/+4
| | | | | | | | * 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
* Enable to take branch coverages for safe method invocationsyui-knk2017-09-231-5/+14
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* intern instructionnobu2017-09-181-4/+1
| | | | | | | * 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
* refinements in string interpolationnobu2017-09-181-0/+8
| | | | | | | | | | | | | | * 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
* literal symbol by internnobu2017-09-171-1/+4
| | | | | | | | | | * 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: optimize unnecessary concatstringsnobu2017-09-171-0/+8
| | | | | | | | | * 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
* suppress warningsnobu2017-09-171-4/+4
| | | | | | * 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
* compile.c: iseq_pop_newarraynobu2017-09-141-3/+31
| | | | | | | * 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
* Introduce NODE_UNLESS for branch coveragemame2017-09-141-7/+11
| | | | | | | `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
* Add method coveragemame2017-09-141-0/+14
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add branch coverage for case-when statementmame2017-09-141-1/+13
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add branch coverage for while and until statementsmame2017-09-141-0/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add branch coverage for if statementmame2017-09-141-0/+37
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add a new instruction `trace2` for hooking with custom datamame2017-09-141-4/+9
| | | | | | | 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: pop coverage tracenobu2017-09-101-1/+2
| | | | | | | * 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: replaced switch by TYPEnobu2017-09-091-15/+9
| | | | | | | * 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
* Remove unneeded trace instruction for coveragemame2017-09-071-0/+5
| | | | | | | | | | | | | | 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
* Refactor the internal data format for coverage measurementmame2017-09-031-1/+2
| | | | | | | | | | | 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