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

ruby-changes:40849

From: normal <ko1@a...>
Date: Tue, 8 Dec 2015 08:57:14 +0900 (JST)
Subject: [ruby-changes:40849] normal:r52928 (trunk): insns.def (opt_case_dispatch): check Float#=== redefinition

normal	2015-12-08 08:56:57 +0900 (Tue, 08 Dec 2015)

  New Revision: 52928

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

  Log:
    insns.def (opt_case_dispatch): check Float#=== redefinition
    
    The missing check for Float#=== redefinition was noticed while
    working on enhancing optimized case dispatch for nil/true/false
    in [ruby-core:71818] https://bugs.ruby-lang.org/issues/11769
    
    So no, I don't normally redefine core classes like this :P
    
    * insns.def (opt_case_dispatch): check Float#=== redefinition
    * test/ruby/test_optimization.rb (test_opt_case_dispatch): new
      [ruby-core:71920] [Bug #11784]

  Modified files:
    trunk/ChangeLog
    trunk/insns.def
    trunk/test/ruby/test_optimization.rb
Index: insns.def
===================================================================
--- insns.def	(revision 52927)
+++ insns.def	(revision 52928)
@@ -1271,6 +1271,7 @@ opt_case_dispatch https://github.com/ruby/ruby/blob/trunk/insns.def#L1271
 	if (BASIC_OP_UNREDEFINED_P(BOP_EQQ,
 				   SYMBOL_REDEFINED_OP_FLAG |
 				   FIXNUM_REDEFINED_OP_FLAG |
+				   FLOAT_REDEFINED_OP_FLAG |
 				   BIGNUM_REDEFINED_OP_FLAG |
 				   STRING_REDEFINED_OP_FLAG)) {
 	    st_data_t val;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52927)
+++ ChangeLog	(revision 52928)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Dec  8 08:56:16 2015  Eric Wong  <e@8...>
+
+	* insns.def (opt_case_dispatch): check Float#=== redefinition
+	* test/ruby/test_optimization.rb (test_opt_case_dispatch): new
+	  [ruby-core:71920] [Bug #11784]
+
 Tue Dec  8 03:56:05 2015  Koichi Sasada  <ko1@a...>
 
 	* test/lib/iseq_loader_checker.rb: add iseq dumper/loader checker.
Index: test/ruby/test_optimization.rb
===================================================================
--- test/ruby/test_optimization.rb	(revision 52927)
+++ test/ruby/test_optimization.rb	(revision 52928)
@@ -308,4 +308,45 @@ class TestRubyOptimization < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_optimization.rb#L308
       assert_equal(false, "block".freeze)
     end;
   end
+
+  def test_opt_case_dispatch
+    code = <<-EOF
+      case foo
+      when "foo" then :foo
+      when :sym then :sym
+      when 6 then :fix
+      when 0.1 then :float
+      when 0xffffffffffffffff then :big
+      else
+        :nomatch
+      end
+    EOF
+    check = {
+      'foo' => :foo,
+      :sym => :sym,
+      6 => :fix,
+      0.1 => :float,
+      0xffffffffffffffff => :big,
+    }
+    iseq = RubyVM::InstructionSequence.compile(code)
+    assert_match %r{\bopt_case_dispatch\b}, iseq.disasm
+    check.each do |foo, expect|
+      assert_equal expect, eval("foo = #{foo.inspect}\n#{code}")
+    end
+    assert_equal :nomatch, eval("foo = :blah\n#{code}")
+    check.each do |foo, _|
+      klass = foo.class.to_s
+      assert_separately([], <<-"end;") # do
+        class #{klass}
+          undef ===
+          def ===(*args)
+            false
+          end
+        end
+        foo = #{foo.inspect}
+        ret = #{code}
+        assert_equal :nomatch, ret, foo.inspect
+      end;
+    end
+  end
 end

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

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