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

523 Коммитов

Автор SHA1 Сообщение Дата
tarui 44916ec448 * compile.c (iseq_compile_each): share InlineCache during same
instance variable accesses. Reducing memory consumption,
	  rasing cache hit rate and rasing branch prediction hit rate
	  are expected. A part of [Bug #12274].

	* iseq.h (struct iseq_compile_data): introduce instance
	  variable IC table for sharing.

	* iseq.c (prepare_iseq_build, compile_data_free):
	  construct/destruct above table.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-11 12:50:38 +00:00
nobu a170b76906 compile.c: true conditions
* compile.c (compile_branch_condition): add more always-true
  conditions to optimize away unreachable branch.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54775 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-26 08:38:20 +00:00
nobu 2ede24a8f1 compile.c: remove redundant trace insn
* compile.c (iseq_peephole_optimize): remove successive line trace
  instructions except for the last.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-23 14:12:27 +00:00
nobu 12ef609f5e compile.c: instruction ID predicate
* compile.c (IS_INSN_ID): add instruction ID predicate macro.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-23 11:43:52 +00:00
nobu 6871d400eb compile.c: ISeq element type predicates
* compile.c (IS_INSN, IS_LABEL, IS_ADJUST): add ISeq element type
  predicate macros.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54730 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-23 11:39:41 +00:00
nobu 9e8dfaa8b0 compile.c: make SyntaxError after formatting
* compile.c (append_compile_error): make SyntaxError instance by
  rb_syntax_error_append on demand after formatting the message.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-20 02:52:07 +00:00
nobu 97177a2d99 refactor syntax error
* compile.c (append_compile_error): use rb_syntax_error_append.
* error.c (rb_syntax_error_append): append messages into a
  SyntaxError exception instance.
* parse.y (yycompile0): make new SyntaxError instance in main
  mode, otherwize error_buffer should be a SyntaxError if error
  has occurred.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-20 01:25:55 +00:00
nobu 51612505f7 appending compile error without rb_errinfo
* compile.c (append_compile_error, compile_bug): pass iseq and get
  error info and file from it, not by the thread error info.
* error.c (rb_report_bug_valist): take va_list instead of variadic
  arguments, and just report the bug but not abort.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54648 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-19 04:46:20 +00:00
nobu 6ee3a2cd15 compile.c: fix dangling link
* compile.c (iseq_peephole_optimize): should not replace the
  current target INSN, not to follow the replaced dangling link in
  the caller.  [ruby-core:74993] [Bug #11816]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54628 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-18 07:07:03 +00:00
nobu 6648d61578 compile.c: initialize LABEL fields
* compile.c (new_label_body): initialize bit fields, since
  compile_data_alloc does not clear the memory.  [Bug #12082]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-12 02:51:20 +00:00
nobu f0226f0a3c compile.c: disable tco with rescue
* compile.c (iseq_optimize): disable tail call optimization in
  rescued, rescue, and ensure blocks.
  [ruby-core:73871] [Bug #12082]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-11 08:43:06 +00:00
nobu d7935475fc remove rb_thread_t::parse_in_eval
* parse.y (struct parser_params): move parse_in_eval flag from
  rb_thread_t.
* parse.y (rb_parser_set_context): set parsing context, not only
  mild error flag.
* iseq.c (rb_iseq_compile_with_option): the parser now refers no
  thread local states to be restored.
* vm_eval.c (eval_string_with_cref): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-28 21:39:24 +00:00
nobu 3f519a7bfa compile.c: explicit address
* compile.c (prepare_compile_error): add & to explicit address of
  functions to suppress warnings by old VC.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-26 01:34:35 +00:00
nobu e1ee61bfbd compile.c: strict condition
* compile.c (iseq_specialized_instruction): specialize only
  concatenated newarray and send, no labels and no adjusts.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-17 13:19:02 +00:00
nobu 8472c15440 compile.c: move newarray specialization
* compile.c (iseq_specialized_instruction): move specialization
  for opt_newarray_max/min from translation phase.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-17 13:08:35 +00:00
mame 3c7c983300 * compile.c (NODE_CALL): add optimization shortcut for Array#max/min.
Now `[x, y].max` is optimized so that a temporal array object is not
  created in some condition.

* insns.def (opt_newarray_max, opt_newarray_min): added.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54153 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-17 12:47:31 +00:00
nobu 6555077aa0 compile.c: bit flag
* compile.c (LABEL): turn `set` flag a bit field.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54143 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-17 05:47:44 +00:00
nobu ea5e885a95 optimize named capture assignment
* compile.c (compile_named_capture_assign): optimize named capture
  assignments, by replacing repeating global variable accesses
  with `dup`, and by returning the matched result instead of
  re-getting it from the MatchData.

* parse.y (reg_named_capture_assign_gen): build just assignment
  nodes for the optimization.

ex. `/(?<x>.)/ =~ "bar"`

- old
  ```
  0000 putstring        "bar"
  0002 opt_regexpmatch1 /(?<x>.)/
  0004 pop
  0005 getglobal        $~
  0007 branchunless     25
  0009 getglobal        $~
  0011 putobject        :x
  0013 opt_aref         <callinfo!mid:[], argc:1, ARGS_SIMPLE>
  0016 setlocal_OP__WC__0 2
  0018 getglobal        $~
  0020 putobject_OP_INT2FIX_O_0_C_
  0021 opt_send_without_block <callinfo!mid:begin, argc:1, ARGS_SIMPLE>
  0024 leave
  0025 putobject        nil
  0027 setlocal_OP__WC__0 2
  0029 putobject        nil
  0031 leave
  ```

- new
  ```
  0000 putstring        "bar"
  0002 opt_regexpmatch1 /(?<x>.)/
  0004 getglobal        $~
  0006 dup
  0007 branchunless     14
  0009 putobject        :x
  0011 opt_aref         <callinfo!mid:[], argc:1, ARGS_SIMPLE>
  0014 setlocal_OP__WC__0 2
  0016 leave
  ```

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54100 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-14 07:53:39 +00:00
normal 1282a4a895 fstring early for internal iseq
All of the strings created here eventually get converted to
fstrings when they are frozen into the iseq.  Prepare the
fstring early so we may reduce a one or two objects.

This is a very minor change, mainly for the '<main>' dedupe.

* compile.c (caller_location): use rb_fstring_cstr for "<compiled>"
  (it is converted to fstring anyways inside rb_iseq_new_with_opt)
* iseq.c (iseqw_s_compile): ditto
* iseq.c (rb_iseq_new_main): use rb_fstring_cstr for "<main>"
* vm.c (Init_VM): ditto, share with with above
* iseq.c (iseqw_s_compile_file): rb_fstring before rb_io_t->pathv
  share "<main>" with above
* vm.c (rb_binding_add_dynavars): fstring "<temp>" immediately

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-26 06:23:47 +00:00
nobu f4ca0739ec compile.c: fix tailcall optimization
* compile.c (iseq_peephole_optimize): don't apply tailcall
  optimization to send/invokesuper instructions with blockiseq.
  This is a follow-up to the changes in r51903; blockiseq is now
  the third operand of send/invokesuper instructions.
  [ruby-core:73413] [Bug #12018]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-26 06:14:59 +00:00
nobu e6f6c77d1d compile.c: fix lhs splat in massign
* compile.c (compile_massign_lhs): when index ends with splat,
  append rhs value to it like POSTARG, since VM_CALL_ARGS_SPLAT
  splats the last argument only.  [ruby-core:72777] [Bug #11970]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-10 11:57:51 +00:00
nobu 910eb9836d compile.c: adjust call_info count
* compile.c (remove_unreachable_chunk): decrease count of
  call_info in removed instructions.  fix up r53402.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53403 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-01 06:28:58 +00:00
nobu 0094737575 compile.c: remove unreferred label
* compile.c (remove_unreachable_chunk): remove unreferred label
  to optimize away unreachable chunk.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53402 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-01 03:05:55 +00:00
nobu 1403dfbf31 compile.c: adjust label reference
* compile.c (new_adjust_body): labels referred by adjuststack
  shoud not be optimized away.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53367 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-29 08:36:22 +00:00
nobu 22d8481f08 fix common misspelling [ci skip]
* compile.c, cont.c, doc, man: fix common misspelling.
  [ruby-core:72466] [Bug #11870]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-24 23:23:46 +00:00
nobu 26984290eb preserve source file name encoding
* compile.c (append_compile_error), parse.y (compile_error):
  preserve encoding of source file name in exceptions.
* error.c (rb_compile_error_str, rb_compile_bug_str): add.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53278 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-24 08:25:44 +00:00
ko1 9d30ef596c * compile.c (ibf_load_object_string): use fstring if frozen string.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53191 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-18 08:24:29 +00:00
ko1 dd5fd65eef * compile.c (ibf_load_setup): check tainted string argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53187 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-18 07:51:58 +00:00
hsbt 6851be0f0c * compile.c: fix typos.
[ci skip][fix GH-1140] Patch by @jutaz
* dir.c: ditto.
* gc.c: ditto.
* io.c: ditto.
* node.h: ditto.
* thread_pthread.c: ditto.
* vm_insnhelper.c: ditto.
* vsnprintf.c: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53103 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-14 02:51:13 +00:00
nobu 165e10b6cf compile.c: rehash cdhash
* compile.c (iseq_compile_each, ibf_load_object_hash): rehash
  case-dispatch hash to reduce collisions.
  http://d.hatena.ne.jp/ku-ma-me/20151210

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53031 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-11 02:38:20 +00:00
normal 7c41f09342 compile.c (iseq_compile_each): reduce needless rb_str_dup
There is no need to dup the fstring unless we want to set the
debug ivar for it.

[ruby-core:72018] <5668DB6E.8000101@ruby-lang.org>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53021 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-10 02:35:22 +00:00
ko1 6fb2ec5394 * compile.c (iseq_compile_each): do not add debug information
without --debug or --debug=frozen-string-literal option
  because String#dup slows down with debug information.
  [Feature #11725]

* NEWS: apply about it.

* test/ruby/test_rubyoptions.rb: catch up this fix with refactoring.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-09 17:02:02 +00:00
normal a422462a18 compile.c (ibf_dump_object_unsupported): fix spelling error
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52989 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-09 01:34:01 +00:00
ko1 2f5b8f0529 * *.c (*_memsize): do not check ptr.
NULL checking is finished Before call of memsize functions.
  See r52979.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-09 00:38:32 +00:00
ko1 e78bf7976c * compile.c (ibf_dump_memsize): should check NULL.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 17:19:58 +00:00
nobu 745c63e9a0 compile.c: suppress warning
* compile.c (ibf_dump_overwrite): cast to unsigned long to
  suppress sign-compare warning.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 15:59:05 +00:00
ko1 ddba2014c6 * compile.c (iseq_ibf_dump): dump extra data just string length.
* sample/iseq_loader.rb: add using
  RubyVM::InstructionSequence.from_binary_format_extra_data method
  (commented out).




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52969 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 15:30:46 +00:00
nobu 278d90a255 compile.c: fix extra_str
* compile.c (iseq_ibf_load_extra_data): fix offset and
  length of extra_str, which is not NUL-terminated.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 15:26:58 +00:00
ko1 34cfdd2f67 * compile.c (ibf_load_setup): cast to int.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 15:18:30 +00:00
ko1 d0d0898c0a * compile.c (ibf_setup_load): rename to ibf_load_setup().
* compile.c (iseq_load_setup): check binary format.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 15:14:55 +00:00
nobu 2c3f0749c5 free ibf_dump at exception
* compile.c (iseq_ibf_dump): wrap ibf_dump to free tables at
  exception.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 14:50:55 +00:00
nobu 433a5b4693 compile.c: make opt a string value
* compile.c (iseq_ibf_dump): rb_check_string_type() returns nil if
  the object does not have to_str method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 14:47:38 +00:00
nobu 6ee61d4bb9 check loading object index range
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52956 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 14:33:11 +00:00
nobu 6a105387ce suppress warnings
* compile.c (iseq_ibf_dump): check lenght overflow.

* vm_core.h (rb_iseq_check): suppress unused-value warnings.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 14:12:11 +00:00
ko1 b8574cdcff * compile.c (iseq_ibf_dump): fix for clang type checker.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52954 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 14:06:13 +00:00
ko1 3dbb390180 * introduce new ISeq binary format serializer/de-serializer
and a pre-compilation/runtime loader sample.
  [Feature #11788]

* iseq.c: add new methods:
  * RubyVM::InstructionSequence#to_binary_format(extra_data = nil)
  * RubyVM::InstructionSequence.from_binary_format(binary)
  * RubyVM::InstructionSequence.from_binary_format_extra_data(binary)

* compile.c: implement body of this new feature.

* load.c (rb_load_internal0), iseq.c (rb_iseq_load_iseq):
  call RubyVM::InstructionSequence.load_iseq(fname) with
  loading script name if this method is defined.

  We can return any ISeq object as a result value.
  Otherwise loading will be continue as usual.

  This interface is not matured and is not extensible.
  So that we don't guarantee the future compatibility of this method.
  Basically, you should'nt use this method.

* iseq.h: move ISEQ_MAJOR/MINOR_VERSION (and some definitions)
  from iseq.c.

* encoding.c (rb_data_is_encoding), internal.h: added.

* vm_core.h: add several supports for lazy load.
  * add USE_LAZY_LOAD macro to specify enable or disable of
    this feature.
  * add several fields to rb_iseq_t.
  * introduce new macro rb_iseq_check().

* insns.def: some check for lazy loading feature.

* vm_insnhelper.c: ditto.

* proc.c: ditto.

* vm.c: ditto.

* test/lib/iseq_loader_checker.rb: enabled iff suitable
  environment variables are provided.

* test/runner.rb: enable lib/iseq_loader_checker.rb.

* sample/iseq_loader.rb: add sample compiler and loader.

    $ ruby sample/iseq_loader.rb [dir]

  will compile all ruby scripts in [dir].
  With default setting, this compile creates *.rb.yarb files
  in same directory of target .rb scripts.

    $ ruby -r sample/iseq_loader.rb [app]

  will run with enable to load compiled binary data.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 13:58:50 +00:00
normal f2a7ca746f compile.c (iseq_build_from_ary_body): avoid rb_ary_dup for CDHASH
This reverts r16587
("compile.c (iseq_build_body): remove side effect from
  VM::InstructionSequence.load."
as that change was obsoleted by r48705 ("mostly fix rb_iseq_load")

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 04:32:23 +00:00
normal 4ebab10bf5 compile optimized case dispatch for nil/true/false
nil/true/false are special literals just like floats, integers,
literal strings, and symbols.  Optimize when statements with
them by using a jump table, too.

target 0: a (ruby 2.3.0dev (2015-12-08 trunk 52928) [x86_64-linux]) at "/home/ew/rrrr/b/ruby"
target 1: b (ruby 2.3.0dev (2015-12-08 master 52928) [x86_64-linux]) at "/home/ew/ruby/b/ruby"

benchmark results:
minimum results in each 5 measurements.
Execution time (sec)
name	a	b
loop_whileloop2	0.102	0.103
vm2_case_lit*	1.657	0.549

Speedup ratio: compare with the result of `a' (greater is better)
name	b
loop_whileloop2	0.988
vm2_case_lit*	3.017

* benchmark/bm_vm2_case_lit.rb: new benchmark
* compile.c (case_when_optimizable_literal): add nil/true/false
* insns.def (opt_case_dispatch): ditto
* vm.c (vm_redefinition_check_flag): ditto
* vm.c (vm_init_redefined_flag): ditto
* vm_core.h: ditto
* object.c (InitVM_Object): define === explicitly for nil/true/false
* test/ruby/test_case.rb (test_deoptimize_nil): new test
* test/ruby/test_optimization.rb (test_opt_case_dispatch): update
  (test_eqq): new test
  [ruby-core:71923] [Feature #11769]
  Original patch by Aaron Patterson <tenderlove@ruby-lang.org>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 01:46:45 +00:00
ko1 21366b17a5 * compile.c (rb_iseq_build_from_ary): do not allocate table
if table_size is 0.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52923 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-07 18:44:45 +00:00
nobu a560f2a4cc compile.c: no extra parentheses
* compile.c (COMPILE_ERROR): remove extra parentheses to enclose
  variadic arguments.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52889 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-04 17:28:26 +00:00