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

ruby-changes:26700

From: ko1 <ko1@a...>
Date: Thu, 10 Jan 2013 03:38:51 +0900 (JST)
Subject: [ruby-changes:26700] ko1:r38751 (trunk): * compile.c (compile_array_): modify wrong optimization.

ko1	2013-01-10 03:38:41 +0900 (Thu, 10 Jan 2013)

  New Revision: 38751

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38751

  Log:
    * compile.c (compile_array_): modify wrong optimization.
      A script "[print(1)]; print(2)" should output "12".
      However, the compiler had eliminted "[print(1)]" expression
      because it is void expression (unused array).
      Of course, side-effect should be remained.
      This issue is reported by Masaya Tarui.
    * bootstraptest/test_literal.rb: add a test.

  Modified files:
    trunk/ChangeLog
    trunk/bootstraptest/test_literal.rb
    trunk/compile.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38750)
+++ ChangeLog	(revision 38751)
@@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jan 10 03:29:55 2013  Koichi Sasada  <ko1@a...>
+
+	* compile.c (compile_array_): modify wrong optimization.
+	  A script "[print(1)]; print(2)" should output "12".
+	  However, the compiler had eliminted "[print(1)]" expression
+	  because it is void expression (unused array).
+	  Of course, side-effect should be remained.
+	  This issue is reported by Masaya Tarui.
+
+	* bootstraptest/test_literal.rb: add a test.
+
 Wed Jan  9 22:07:42 2013  Masaki Matsushita  <glass.saga@g...>
 
 	* load.c (load_lock): if thread shield is destroyed and there is no
Index: bootstraptest/test_literal.rb
===================================================================
--- bootstraptest/test_literal.rb	(revision 38750)
+++ bootstraptest/test_literal.rb	(revision 38751)
@@ -224,3 +224,8 @@ assert_equal 'ok', %q{ #  long hash lite https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_literal.rb#L224
   eval "a = {#{(1..10_000).map{|n| "#{n} => #{n}"}.join(', ')}}"
   :ok
 }
+
+assert_equal 'ok', %q{
+  [print(:ok), exit] # void literal with side-effect
+  :dummy
+}
Index: compile.c
===================================================================
--- compile.c	(revision 38750)
+++ compile.c	(revision 38751)
@@ -2435,6 +2435,7 @@ compile_array_(rb_iseq_t *iseq, LINK_ANC https://github.com/ruby/ruby/blob/trunk/compile.c#L2435
 			else {
 			    ADD_INSN(anchor, line, concatarray);
 			}
+
 			APPEND_LIST(ret, anchor);
 			break;
 		      case COMPILE_ARRAY_TYPE_HASH:
@@ -2461,6 +2462,10 @@ compile_array_(rb_iseq_t *iseq, LINK_ANC https://github.com/ruby/ruby/blob/trunk/compile.c#L2462
 			break;
 		    }
 		}
+		else {
+		    /* poped */
+		    APPEND_LIST(ret, anchor);
+		}
 	    }
 	}
     }

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

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