diff options
Diffstat (limited to 'test/ruby/test_optimization.rb')
| -rw-r--r-- | test/ruby/test_optimization.rb | 109 |
1 files changed, 24 insertions, 85 deletions
diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb index b42314b765..2a4cc19699 100644 --- a/test/ruby/test_optimization.rb +++ b/test/ruby/test_optimization.rb @@ -187,16 +187,6 @@ class TestRubyOptimization < Test::Unit::TestCase assert_redefine_method('String', '<<', 'assert_equal "b", "a" << "b"') end - def test_fixnum_and - assert_equal 1, 1&3 - assert_redefine_method('Integer', '&', 'assert_equal 3, 1&3') - end - - def test_fixnum_or - assert_equal 3, 1|3 - assert_redefine_method('Integer', '|', 'assert_equal 1, 3|1') - end - def test_array_plus assert_equal [1,2], [1]+[2] assert_redefine_method('Array', '+', 'assert_equal [2], [1]+[2]') @@ -272,7 +262,7 @@ class TestRubyOptimization < Test::Unit::TestCase unless file loc, = caller_locations(1, 1) file = loc.path - line ||= loc.lineno + 1 + line ||= loc.lineno end RubyVM::InstructionSequence.new("proc {|_|_.class_eval {#{src}}}", file, (path || file), line, @@ -347,7 +337,7 @@ class TestRubyOptimization < Test::Unit::TestCase def test_tailcall_inhibited_by_rescue bug12082 = '[ruby-core:73871] [Bug #12082]' - EnvUtil.suppress_warning {tailcall("#{<<-"begin;"}\n#{<<~"end;"}")} + tailcall("#{<<-"begin;"}\n#{<<~"end;"}") begin; def to_be_rescued return do_raise @@ -398,7 +388,7 @@ class TestRubyOptimization < Test::Unit::TestCase foo end;1 end; - status, _err = EnvUtil.invoke_ruby([], "", true, true, **{}) { + status, _err = EnvUtil.invoke_ruby([], "", true, true, {}) { |in_p, out_p, err_p, pid| in_p.write(script) in_p.close @@ -425,7 +415,7 @@ class TestRubyOptimization < Test::Unit::TestCase def test_tailcall_condition_block bug = '[ruby-core:78015] [Bug #12905]' - src = "#{<<-"begin;"}\n#{<<~"end;"}", __FILE__, nil, __LINE__+1 + src = "#{<<-"begin;"}\n#{<<~"end;"}" begin; def run(current, final) if current < final @@ -437,13 +427,13 @@ class TestRubyOptimization < Test::Unit::TestCase end; obj = Object.new - self.class.tailcall(obj.singleton_class, *src, tailcall: false) + self.class.tailcall(obj.singleton_class, src, tailcall: false) e = assert_raise(SystemStackError) { obj.run(1, Float::INFINITY) } level = e.backtrace_locations.size obj = Object.new - self.class.tailcall(obj.singleton_class, *src, tailcall: true) + self.class.tailcall(obj.singleton_class, src, tailcall: true) level *= 2 mesg = message {"#{bug}: #{$!.backtrace_locations.size} / #{level} stack levels"} assert_nothing_raised(SystemStackError, mesg) { @@ -451,22 +441,6 @@ class TestRubyOptimization < Test::Unit::TestCase } end - def test_tailcall_not_to_grow_stack - skip 'currently JIT-ed code always creates a new stack frame' if RubyVM::MJIT.enabled? - bug16161 = '[ruby-core:94881]' - - tailcall("#{<<-"begin;"}\n#{<<~"end;"}") - begin; - def foo(n) - return :ok if n < 1 - foo(n - 1) - end - end; - assert_nothing_raised(SystemStackError, bug16161) do - assert_equal(:ok, foo(1_000_000), bug16161) - end - end - class Bug10557 def [](_) block_given? @@ -583,30 +557,12 @@ class TestRubyOptimization < Test::Unit::TestCase when "1.8.0"..."1.8.8" then :bar end end; - [ true, false ].each do |opt| - iseq = RubyVM::InstructionSequence.compile(code, - frozen_string_literal: opt) - insn = iseq.disasm - assert_match %r{putobject\s+#{Regexp.quote('"1.8.0"..."1.8.8"')}}, insn - assert_match %r{putobject\s+#{Regexp.quote('"2.0.0".."2.3.2"')}}, insn - assert_no_match(/putstring/, insn) - assert_no_match(/newrange/, insn) - end - end - - def test_peephole_dstr - code = "#{<<~'begin;'}\n#{<<~'end;'}" - begin; - exp = -'a' - z = 'a' - [exp, -"#{z}"] - end; - [ false, true ].each do |fsl| - iseq = RubyVM::InstructionSequence.compile(code, - frozen_string_literal: fsl) - assert_same(*iseq.eval, - "[ruby-core:85542] [Bug #14475] fsl: #{fsl}") - end + iseq = RubyVM::InstructionSequence.compile(code) + insn = iseq.disasm + assert_match %r{putobject\s+#{Regexp.quote('"1.8.0"..."1.8.8"')}}, insn + assert_match %r{putobject\s+#{Regexp.quote('"2.0.0".."2.3.2"')}}, insn + assert_no_match(/putstring/, insn) + assert_no_match(/newrange/, insn) end def test_branch_condition_backquote @@ -714,6 +670,17 @@ class TestRubyOptimization < Test::Unit::TestCase END end + def test_block_parameter_should_restore_safe_level + assert_separately [], <<-END + # + def foo &b + $SAFE = 1 + b.call + end + assert_equal 0, foo{$SAFE} + END + end + def test_peephole_optimization_without_trace assert_separately [], <<-END RubyVM::InstructionSequence.compile_option = {trace_instruction: false} @@ -722,7 +689,7 @@ class TestRubyOptimization < Test::Unit::TestCase end def test_clear_unreachable_keyword_args - assert_separately [], <<-END, timeout: 60 + assert_separately [], <<-END, timeout: 15 script = <<-EOS if true else @@ -756,7 +723,6 @@ class TestRubyOptimization < Test::Unit::TestCase h = {} assert_equal(bug, eval('{ok: 42, **h}; bug')) assert_equal(:ok, eval('{ok: bug = :ok, **h}; bug')) - assert_empty(h) end def test_overwritten_blockparam @@ -769,18 +735,6 @@ class TestRubyOptimization < Test::Unit::TestCase assert_equal(:ok, obj.a()) end - def test_blockparam_in_rescue - obj = Object.new - def obj.foo(&b) - raise - rescue - b.call - end - result = nil - assert_equal(42, obj.foo {result = 42}) - assert_equal(42, result) - end - def test_unconditional_branch_to_leave_block assert_valid_syntax("#{<<~"begin;"}\n#{<<~'end;'}") begin; @@ -830,19 +784,4 @@ class TestRubyOptimization < Test::Unit::TestCase } end; end - - def test_optimized_rescue - assert_in_out_err("", "#{<<~"begin;"}\n#{<<~'end;'}", [], /END \(RuntimeError\)/) - begin; - if false - begin - require "some_mad_stuff" - rescue LoadError - puts "no mad stuff loaded" - end - end - - raise "END" - end; - end end |
