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

ruby-changes:41584

From: nobu <ko1@a...>
Date: Tue, 26 Jan 2016 15:14:08 +0900 (JST)
Subject: [ruby-changes:41584] nobu:r53658 (trunk): compile.c: fix tailcall optimization

nobu	2016-01-26 15:14:59 +0900 (Tue, 26 Jan 2016)

  New Revision: 53658

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

  Log:
    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]

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/test/ruby/test_optimization.rb
Index: compile.c
===================================================================
--- compile.c	(revision 53657)
+++ compile.c	(revision 53658)
@@ -2248,8 +2248,12 @@ iseq_peephole_optimize(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/compile.c#L2248
 
 	if (piobj) {
 	    struct rb_call_info *ci = (struct rb_call_info *)piobj->operands[0];
-	    rb_iseq_t *blockiseq = (rb_iseq_t *)piobj->operands[1];
-	    if (blockiseq == 0) {
+	    if (piobj->insn_id == BIN(send) || piobj->insn_id == BIN(invokesuper)) {
+		if (piobj->operands[2] == 0) { /* no blockiseq */
+		    ci->flag |= VM_CALL_TAILCALL;
+		}
+	    }
+	    else {
 		ci->flag |= VM_CALL_TAILCALL;
 	    }
 	}
Index: test/ruby/test_optimization.rb
===================================================================
--- test/ruby/test_optimization.rb	(revision 53657)
+++ test/ruby/test_optimization.rb	(revision 53658)
@@ -275,6 +275,22 @@ class TestRubyOptimization < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_optimization.rb#L275
     assert_equal(123, delay { 123 }.call, bug6901)
   end
 
+  def just_yield
+    yield
+  end
+
+  def test_tailcall_inhibited_by_block
+    assert_separately([], <<~'end;')
+      def just_yield
+        yield
+      end
+      iseq = RubyVM::InstructionSequence
+      result = iseq.compile("just_yield {:ok}", __FILE__, __FILE__, __LINE__,
+                            tailcall_optimization: true).eval
+      assert_equal(:ok, result)
+    end;
+  end
+
   class Bug10557
     def [](_)
       block_given?
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53657)
+++ ChangeLog	(revision 53658)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jan 26 15:14:01 2016  Kazuki Yamaguchi  <k@r...>
+
+	* 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]
+
 Tue Jan 26 14:26:46 2016  Eric Wong  <e@8...>
 
 	* signal.c (sig_list): use fstring for hash key

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

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