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

ruby-changes:50289

From: normal <ko1@a...>
Date: Thu, 15 Feb 2018 07:35:19 +0900 (JST)
Subject: [ruby-changes:50289] normal:r62407 (trunk): compile.c: drop freezestring insn on String#-@

normal	2018-02-15 07:35:13 +0900 (Thu, 15 Feb 2018)

  New Revision: 62407

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

  Log:
    compile.c: drop freezestring insn on String#-@
    
    Followup to r62039 and remove the redundant freezestring
    insn which was preventing deduplication from String#-@
    
    * compile.c (iseq_peephole_optimize): drop freezestring insn on String#-@
      [ruby-core:85542] [Bug #14475]

  Modified files:
    trunk/compile.c
    trunk/test/ruby/test_optimization.rb
Index: compile.c
===================================================================
--- compile.c	(revision 62406)
+++ compile.c	(revision 62407)
@@ -2851,11 +2851,11 @@ iseq_peephole_optimize(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/compile.c#L2851
 	struct rb_call_info *ci = (struct rb_call_info *)OPERAND_AT(niobj, 0);
 	/*
 	 *  freezestring debug_info
-	 *  send <:+@, 0, ARG_SIMPLE>
+	 *  send <:+@, 0, ARG_SIMPLE>  # :-@, too
 	 * =>
-	 *  send <:+@, 0, ARG_SIMPLE>
+	 *  send <:+@, 0, ARG_SIMPLE>  # :-@, too
 	 */
-	if (ci->mid == idUPlus &&
+	if ((ci->mid == idUPlus || ci->mid == idUMinus) &&
 	    (ci->flag & VM_CALL_ARGS_SIMPLE) &&
 	    ci->orig_argc == 0) {
 	    ELEM_REMOVE(list);
Index: test/ruby/test_optimization.rb
===================================================================
--- test/ruby/test_optimization.rb	(revision 62406)
+++ test/ruby/test_optimization.rb	(revision 62407)
@@ -568,6 +568,21 @@ class TestRubyOptimization < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_optimization.rb#L568
     end
   end
 
+  def test_peephole_dstr
+    code = "#{<<~'begin;'}\n#{<<~'end;'}"
+    begin;
+      exp = (-'a').object_id
+      z = 'a'
+      exp == (-"#{z}").object_id
+    end;
+    [ false, true ].each do |fsl|
+      iseq = RubyVM::InstructionSequence.compile(code,
+                                                 frozen_string_literal: fsl)
+      assert_equal(true, iseq.eval,
+                  "[ruby-core:85542] [Bug #14475] fsl: #{fsl}")
+    end
+  end
+
   def test_branch_condition_backquote
     bug = '[ruby-core:80740] [Bug #13444] redefined backquote should be called'
     class << self

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

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