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

610 Коммитов

Автор SHA1 Сообщение Дата
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
ko1 70d6d8ac81 simply call xfree().
* 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
2017-06-14 04:27:14 +00:00
nobu be1d07ca37 * compile.c (dump_disasm_list_with_cursor): replace with
dump_disasm_list_with_cursor_dest.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59075 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-13 03:20:12 +00:00
ko1 eb0777e865 fix to free unallocated memory.
* 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
2017-06-13 02:52:33 +00:00
nobu 121550b041 compile.c: refine error message
* 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
2017-06-13 01:31:32 +00:00
nobu a784132d98 compile.c: refine error messages
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59071 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-13 01:04:56 +00:00
nobu 5aff6f2948 expand ruby_sourcefile
* 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
2017-06-11 11:21:01 +00:00
ko1 7d8a415bc2 check break target correctly.
* 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
2017-06-08 04:13:51 +00:00
ko1 0318de23d4 use NULL instead of 0.
* 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
2017-06-08 04:06:07 +00:00
ko1 478003f6df rename absolute_path to realpath internally and introduce pathobj.
* 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
2017-06-01 00:05:33 +00:00
watson1978 d0015e4ac6 Improve performance of implicit type conversion
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
2017-05-31 12:30:57 +00:00
rhe 8dce62218a compile.c: fix possible use of uninitialized value
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
2017-05-26 01:50:20 +00:00
nobu cffb09aa80 LABEL_FORMAT
* 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
2017-05-23 12:11:57 +00:00
nobu 52de826096 compile.c: optimize branches
* 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
2017-05-20 11:40:57 +00:00
nobu 4b39eaf4cc compile.c: binary logop check
* 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
2017-05-20 10:27:27 +00:00
nobu 35c54a11b3 compile.c: fix catch-table labels optimization
* 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
2017-05-20 02:11:24 +00:00
nobu 0183613bf9 compile.c: dump_disasm_list_with_cursor
* 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
2017-05-19 14:58:38 +00:00
normal 9d09240d9e rb_execution_context_t: move stack, stack_size and cfp from rb_thread_t
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
2017-05-09 05:06:41 +00:00
nobu 5cc56f0d9b compile.c: wrong optimization
* 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
2017-04-18 13:14:06 +00:00
ko1 7519688ed8 introduce imemo_type_p(v, imemo_type)
* 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
2017-04-07 06:41:32 +00:00
nobu 42c13d386c compile.c: remove side effects by debug macros
* 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
2017-04-05 08:34:18 +00:00
normal 6f73c38791 compile.c: avoid duplicate mark entry for string literal Range
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
2017-04-02 20:16:02 +00:00
normal 120976b9f9 compile.c: optimize literal String range in case/when dispatch
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
2017-04-01 21:38:25 +00:00
normal 669a55dfed fix redefinition optimization for -"literal string" (UMinus)
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
2017-03-27 06:12:37 +00:00
normal cad4591086 remove branches in dmark and dfree GC callbacks
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
2017-03-17 19:59:56 +00:00
mame 3c96f9c76a Fix a consistency bug of ISEQ_COVERAGE [Bug #13305]
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
2017-03-14 11:39:58 +00:00
nobu c279ac3615 compile.c: compile flip-flop
* 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
2017-03-13 00:11:25 +00:00
nobu dae32a40d9 compile.c: omit newrange
* 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
2017-03-13 00:11:24 +00:00
nobu c9a1f7a42b compile.c: compile_const_prefix
* 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
2017-03-12 13:51:12 +00:00
nobu c0764a3cd8 compile.c: omit newhash
* 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
2017-03-12 05:52:42 +00:00
nobu ae46708c10 compile.c: NODE_VALUES must not be popped
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57891 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-12 05:48:58 +00:00
nobu cd7b59e4f2 compile.c: iseq_compile_each0
* 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
2017-03-11 22:44:26 +00:00
nobu f19b041837 compile.c: compile_when
* 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
2017-03-11 22:37:50 +00:00
nobu 16e5c20f9a compile.c: compile_case
* 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
2017-03-11 22:25:32 +00:00
nobu 0d45ea8d8a compile.c: constify flags
* 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
2017-03-11 12:26:00 +00:00
normal 568f8adfc8 compile.c: apply opt_str_freeze to String#-@ (uminus)
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
2017-03-10 20:09:06 +00:00
shyouhei c56edb9a59 revert RB_FIXABLE related changesets [Bug #13288][Bug #13293][Bug #13294]
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
2017-03-09 02:31:23 +00:00