[前][次][番号順一覧][スレッド一覧]

ruby-changes:44590

From: nobu <ko1@a...>
Date: Mon, 7 Nov 2016 16:45:23 +0900 (JST)
Subject: [ruby-changes:44590] nobu:r56663 (trunk): test_optimization.rb: for r56208

nobu	2016-11-07 16:45:18 +0900 (Mon, 07 Nov 2016)

  New Revision: 56663

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56663

  Log:
    test_optimization.rb: for r56208
    
    * test/ruby/test_optimization.rb (test_tailcall_condition_block):
      test for r56208.  [ruby-core:78015] [Bug #12905]

  Modified files:
    trunk/test/ruby/test_optimization.rb
Index: test/ruby/test_optimization.rb
===================================================================
--- test/ruby/test_optimization.rb	(revision 56662)
+++ test/ruby/test_optimization.rb	(revision 56663)
@@ -210,7 +210,7 @@ class TestRubyOptimization < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_optimization.rb#L210
     assert_equal true, MyObj.new == nil
   end
 
-  def self.tailcall(klass, src, file = nil, path = nil, line = nil)
+  def self.tailcall(klass, src, file = nil, path = nil, line = nil, tailcall: true)
     unless file
       loc, = caller_locations(1, 1)
       file = loc.path
@@ -218,7 +218,7 @@ class TestRubyOptimization < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_optimization.rb#L218
     end
     RubyVM::InstructionSequence.new("proc {|_|_.class_eval {#{src}}}",
                                     file, (path || file), line,
-                                    tailcall_optimization: true,
+                                    tailcall_optimization: tailcall,
                                     trace_instruction: false)
       .eval[klass]
   end
@@ -357,6 +357,35 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_optimization.rb#L357
     assert_not_equal("SEGV", Signal.signame(status.termsig || 0), bug12576)
   end unless /mswin|mingw/ =~ RUBY_PLATFORM
 
+  def test_tailcall_condition_block
+    bug = '[ruby-core:78015] [Bug #12905]'
+
+    src = "#{<<-"begin;"}\n#{<<-"end;"}"
+    begin;
+      def run(current, final)
+        if current < final
+          run(current+1, final)
+        else
+          nil
+        end
+      end
+    end;
+
+    obj = Object.new
+    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)
+    level *= 2
+    mesg = message {"#{bug}: #{$!.backtrace_locations.size} / #{level} stack levels"}
+    assert_nothing_raised(SystemStackError, mesg) {
+      obj.run(1, level)
+    }
+  end
+
   class Bug10557
     def [](_)
       block_given?

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]