aboutsummaryrefslogtreecommitdiffstats
path: root/compile.c
Commit message (Collapse)AuthorAgeFilesLines
* compile.c: dump and error before allocationnobu2017-06-141-3/+4
| | | | | | | * 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
* simply call xfree().ko12017-06-141-2/+2
| | | | | | | | * compile.c (BADINSN_ERROR): mixing (void) and (int) will fail solaris compiler. [ruby-core:81668], [Bug #13658] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59078 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * compile.c (dump_disasm_list_with_cursor): replace withnobu2017-06-131-12/+8
| | | | | | dump_disasm_list_with_cursor_dest. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59075 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* fix to free unallocated memory.ko12017-06-131-4/+4
| | | | | | | | * compile.c (iseq_set_sequence): initialize with NULL for line_info_table and generated_iseq and check NULL at BADINSN_ERROR. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59074 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: refine error messagenobu2017-06-131-7/+14
| | | | | | | * compile.c (insn_set_sc_state): dump the whole instructions and mark the destination when label state mismatch. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59073 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: refine error messagesnobu2017-06-131-10/+8
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59071 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* expand ruby_sourcefilenobu2017-06-111-3/+2
| | | | | | | * compile.c: expand ruby_sourcefile not to evaluate twice in RSTRING_PTR. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* check break target correctly.ko12017-06-081-4/+7
| | | | | | | | | | | | | | | | | | | | | * compile.c (iseq_compile_each0): save target child_iseq in the catch-table for break. This iseq is not for continuation, but for search key at vm_throw_start(). * vm_insnhelper.c (vm_throw_start): check saved iseq first. * iseq.h: add comment for it. * test/ruby/test_iterator.rb (test_ljump): add a test for the issue: def call b; b.call; end call(Proc.new{break}){} #=> (1) should raise LocalJumpError call(Proc.new{break}) #=> (2) shoudd raies LocalJumpError, too. but (1) doesn't raise LocalJumpError. This issue is reported by Matz. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* use NULL instead of 0.ko12017-06-081-10/+7
| | | | | | | | * compile.c: use NULL instead of 0 for ADD_CATCH_ENTRY() to specify don't pass iseq. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rename absolute_path to realpath internally and introduce pathobj.ko12017-06-011-20/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
* Improve performance of implicit type conversionwatson19782017-05-311-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: fix possible use of uninitialized valuerhe2017-05-261-0/+1
| | | | | | | LABEL::unremovable added by r58810 is not initialized by new_label_body(), making the optimization unstable. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58894 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* LABEL_FORMATnobu2017-05-231-2/+3
| | | | | | * compile.c (LABEL_FORMAT): extract format string for labels. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: optimize branchesnobu2017-05-201-7/+16
| | | | | | | * compile.c (compile_branch_condition, iseq_compile_each0): eliminate unreachable branches in NODE_IF. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58815 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: binary logop checknobu2017-05-201-6/+5
| | | | | | | | * compile.c (compile_branch_condition): turn recursion at binary logical operator into loop by goto, and check the result of RHS of NODE_OR. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: fix catch-table labels optimizationnobu2017-05-201-14/+32
| | | | | | | * compile.c (remove_unreachable_chunk): do not eliminate chunks followed by labels in catch-table entries. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58810 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: dump_disasm_list_with_cursornobu2017-05-191-3/+11
| | | | | | | * compile.c (dump_disasm_list_with_cursor): improve disassemble list. show whole elemetns and mark the current element. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58797 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rb_execution_context_t: move stack, stack_size and cfp from rb_thread_tnormal2017-05-091-1/+1
| | | | | | | | | | The goal is to reduce rb_context_t and rb_fiber_t size by removing the need to store the entire rb_thread_t in there. [ruby-core:81045] Work-in-progress: soon, we will move more fields here. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58614 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: wrong optimizationnobu2017-04-181-11/+1
| | | | | | | | * compile.c (compile_branch_condition): expression which has side effects should not be eliminated. [ruby-core:80740] [Bug #13444] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58398 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* introduce imemo_type_p(v, imemo_type)ko12017-04-071-1/+1
| | | | | | | | * internal.h: introduce imemo_type_p() which checks the given value is T_IMEMO and imemo_type() == given imemo_type. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: remove side effects by debug macrosnobu2017-04-051-17/+5
| | | | | | | | * compile.c (debugp_param): do not evaluate arguments of debug macros, unless the debug mode is enabled. these macros should not have side effects. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58253 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: avoid duplicate mark entry for string literal Rangenormal2017-04-021-1/+1
| | | | | | | | | | | | iseq_add_mark_object is called in iseq_set_sequence later on, so we only need to call iseq_add_mark_object_compile_time in iseq_peephole_optimize. Without this change, there would've been a duplicate entry in the long-lived iseq mark_ary. * compile.c (iseq_peephole_optimize): avoid duplicate mark object entry [ruby-core:80536] [Feature #13355] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: optimize literal String range in case/when dispatchnormal2017-04-011-0/+31
| | | | | | | | | | | | | | | | | | | This is similar in spirit to opt_case_dispatch as the literal Range here is guaranteed to be immutable when used for checkmatch. Normal range literals with non-frozen strings are actually mutable, as Range#begin and Range#end exposes the strings to modification. So those Range objects cannot be frozen without breaking compatibility, but Ranges in case/when dispatch can be frozen at compile time. * compile.c (iseq_peephole_optimize): persistent Range creation when String literals are used as beginning and end of range when used for case/when dispatch. [ruby-core:80290] [Feature #13355] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58233 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* fix redefinition optimization for -"literal string" (UMinus)normal2017-03-271-1/+6
| | | | | | | | | | | | | | | | | Unfortunately this enlarges insns.def by yet another instruction. However, it is much prettier than opt_str_freeze in use, and maybe we can avoid having so many instructions in the future. [ruby-core:80368] * insns.def (DEFINE_INSN): new instruction: opt_str_uminus (maybe temporary) * compile.c (iseq_compile_each0): split instructions * test/ruby/test_optimization.rb (test_string_uminus): new test * vm.c (vm_init_redefined_flag): set redefinintion flag for uminus * vm_core.h (enum ruby_basic_operators): add BOP_UMINUS git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58144 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* remove branches in dmark and dfree GC callbacksnormal2017-03-171-11/+7
| | | | | | | | | | | | | | | | | dmark and dfree callbacks are never called in gc.c for NULL DATA_PTR values, not even for zombie objects. * compile.c (ibf_loader_mark): remove branch for pointer validity * compile.c (ibf_loader_free): ditto * cont.c (cont_free): ditto * cont.c (fiber_free): ditto * dir.c (dir_free): ditto * ext/stringio/stringio.c (strio_mark): ditto * proc.c (binding_free): ditto * thread_sync.c (mutex_free): ditto * vm.c (thread_free): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58006 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Fix a consistency bug of ISEQ_COVERAGE [Bug #13305]mame2017-03-141-1/+4
| | | | | | | | | There is an invariant that ISEQ_COVERAGE(iseq) must be Qnil if and only if option->coverage_enabled is false. This invariant was broken by NODE_PRELUDE which updates option->coverage_enabled but not ISEQ_COVERAGE(iseq). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: compile flip-flopnobu2017-03-131-1/+2
| | | | | | * compile.c (iseq_compile_each0): compile flip-flop directly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57947 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: omit newrangenobu2017-03-131-8/+5
| | | | | | | * compile.c (iseq_compile_each): omit creating literal-only range to be popped immediately. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57946 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: compile_const_prefixnobu2017-03-121-7/+7
| | | | | | | * compile.c (compile_const_prefix): rename, and check the result of parts of the prefix. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57908 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: omit newhashnobu2017-03-121-5/+2
| | | | | | | * compile.c (iseq_compile_each): omit creating literal-only hash to be popped immediately. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57892 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: NODE_VALUES must not be poppednobu2017-03-121-3/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57891 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: iseq_compile_each0nobu2017-03-111-10/+13
| | | | | | | * compile.c (iseq_compile_each0): split from null node case to constify line and type. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57890 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: compile_whennobu2017-03-111-50/+56
| | | | | | * compile.c (compile_when): extract from iseq_compile_each. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57889 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: compile_casenobu2017-03-111-107/+115
| | | | | | * compile.c (compile_case): extract from iseq_compile_each. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: constify flagsnobu2017-03-111-11/+9
| | | | | | | | | * compile.c (compile_cpath): return `noscoped` bit flag, instead of boolean flag. * compile.c (iseq_compile_each): constify flags. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57836 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: apply opt_str_freeze to String#-@ (uminus)normal2017-03-101-1/+2
| | | | | | | | The same optimization used for "literal string".freeze can easily apply to uminus without introducing any compatibility problems. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57828 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* revert RB_FIXABLE related changesets [Bug #13288][Bug #13293][Bug #13294]shyouhei2017-03-091-1/+1
| | | | | | | | | This commit is auto-generated using following command: svn diff -r57807:57788 include internal.h bignum.c numeric.c compile.c insns.def object.c sprintf.c | patch -p0 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* optimize FIXABLE macroshyouhei2017-03-061-1/+1
| | | | | | | | | | | | Looking at the source code, FIXABLE tends to be just before LOING2FIX to check applicability of that operation. Why not try computing first then check for overflow, which should be optimial. I also tried the same thing for unsigned types but resulted in slower execution. It seems RB_POSFIXABLE() is fast enough on modern CPUs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57789 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: variable typenobu2017-03-051-1/+1
| | | | | | | | * compile.c (iseq_compile_each): fix variable type, use VALUE for Symbol. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?revision=57772&view=revision git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57783 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: operand size checknobu2017-03-041-2/+4
| | | | | | | * compile.c (ibf_load_code): raise an exception on invalid operand size. should not use assert() to validate incoming data. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57774 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: memory leaknobu2017-03-041-8/+17
| | | | | | | * compile.c (iseq_set_sequence): fix potential memory leaks on an invalid instruction sequence. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: fix invalid label messagenobu2017-03-041-2/+2
| | | | | | | * compile.c (validate_label): fix invalid label message. registered labels are Symbols, not IDs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* deduplicate strings sooner at load and compilenormal2017-03-011-2/+2
| | | | | | | | | | | | We can use rb_fstring_cstr in some places to prevent an intermediate object from being created before deduplication via rb_fstring. * compile.c (iseq_compile_each): use rb_fstring_cstr (rb_insns_name_array): ditto * load.c (rb_load_internal0): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57745 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* kwrest arg namenobu2017-02-271-3/+3
| | | | | | | | | | * compile.c (iseq_set_arguments_keywords): make keyword rest argument name nd_vid consistently, regardless of whether other keyword arguments are present. [Fix GH-1529] * parse.y (new_args_tail_gen): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: Fix a typoyui-knk2017-02-201-1/+1
| | | | | | | * compile.c (compile_branch_condition): NODE_LIT is always true. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: suppress a warningnobu2017-02-131-1/+1
| | | | | | | * compile.c (iseq_build_kw): suppress an alloc-size-larger-than warning by gcc 7. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57617 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: restore catch entry spnobu2017-02-021-1/+8
| | | | | | | | * compile.c (iseq_build_from_ary_exception): restore stack depth of catch entries. accurate stack depths cannot be calculated from dumped array. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57498 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: restore misc paramsnobu2017-02-021-5/+13
| | | | | | | * compile.c (rb_iseq_build_from_ary): restore misc params. accurate stack depths cannot be calculated from dumped array. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57497 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: keyword table for required kwargnobu2017-02-021-1/+2
| | | | | | | * compile.c (iseq_build_kw): keyword table is necessary also when required keyword argumetns only. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57496 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: optimization of defined? in conditionnobu2017-01-201-20/+34
| | | | | | | | * compile.c (compile_branch_condition): trivial optimization of defined? expression in a branch condition, where a string is not needed, but just a boolean. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57381 b2dd03c8-39d4-4d8f-98ff-823fe69b080e