* 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
* 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
* 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
* 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
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
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
* 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 (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_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
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 (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
* 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 (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
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
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
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
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 (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_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 (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
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
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
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 (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
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
* 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
* compile.c (iseq_setup): bail out if any errors found.
[ruby-core:76531] [Bug #12613]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57368 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (append_compile_error): set Qtrue for erred state with
showing the message immediately.
* iseq.c (prepare_iseq_build): make immediate message mode if main
or top level context, not to show the failed path twice in the
first line.
* iseq.c (cleanup_iseq_build): raise default message exception if
immediate message mode.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57313 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_compile_each): yield cannot be in the main
context as well as a top context.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57312 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (iseq_compile_each): push fallback nil only when
defined guard is added.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c (defined_expr): omit unnecessary defined guard when
method call has no receiver and no arguments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57258 b2dd03c8-39d4-4d8f-98ff-823fe69b080e