Commits

Corbin Simpson  committed 3489a05

Introduce promote_unicode().

This is a companion to promote_string() which promotes Unicode strings by
value. To use, simply ``from rpython.rlib.jit import promote_unicode`` and
then ``promote_unicode(any_unicode_string)``.

A few tests are included, and a couple bits of testing mocks were improved to
permit tests to not fail.

  • Participants
  • Parent commits d4f1606
  • Branches promote-unicode

Comments (0)

Files changed (3)

File rpython/jit/codewriter/jtransform.py

             op1 = SpaceOperation('str_guard_value', [op.args[0], c, descr],
                                  op.result)
             return [SpaceOperation('-live-', [], None), op1, None]
+        if (hints.get('promote_unicode') and
+            op.args[0].concretetype is not lltype.Void):
+            U = lltype.Ptr(rstr.UNICODE)
+            assert op.args[0].concretetype == U
+            self._register_extra_helper(EffectInfo.OS_UNIEQ_NONNULL,
+                                        "str.eq_nonnull",
+                                        [U, U],
+                                        lltype.Signed,
+                                        EffectInfo.EF_ELIDABLE_CANNOT_RAISE)
+            descr, p = self.callcontrol.callinfocollection.callinfo_for_oopspec(
+                EffectInfo.OS_UNIEQ_NONNULL)
+            # XXX this is fairly ugly way of creating a constant,
+            #     however, callinfocollection has no better interface
+            c = Constant(p.adr.ptr, lltype.typeOf(p.adr.ptr))
+            op1 = SpaceOperation('str_guard_value', [op.args[0], c, descr],
+                                 op.result)
+            return [SpaceOperation('-live-', [], None), op1, None]
         if hints.get('force_virtualizable'):
             return SpaceOperation('hint_force_virtualizable', [op.args[0]], None)
         if hints.get('force_no_const'):   # for tests only

File rpython/jit/codewriter/test/test_jtransform.py

                 return True
         return False
     def callinfo_for_oopspec(self, oopspecindex):
-        assert oopspecindex == effectinfo.EffectInfo.OS_STREQ_NONNULL
+        # assert oopspecindex == effectinfo.EffectInfo.OS_STREQ_NONNULL
         class c:
             class adr:
                 ptr = 1
     assert op1.result == v2
     assert op0.opname == '-live-'
 
+def test_unicode_promote():
+    PUNICODE = lltype.Ptr(rstr.UNICODE)
+    v1 = varoftype(PUNICODE)
+    v2 = varoftype(PUNICODE)
+    op = SpaceOperation('hint',
+                        [v1, Constant({'promote_unicode': True}, lltype.Void)],
+                        v2)
+    tr = Transformer(FakeCPU(), FakeBuiltinCallControl())
+    op0, op1, _ = tr.rewrite_operation(op)
+    assert op1.opname == 'str_guard_value'
+    assert op1.args[0] == v1
+    assert op1.args[2] == 'calldescr'
+    assert op1.result == v2
+    assert op0.opname == '-live-'
+
 def test_double_promote_str():
     PSTR = lltype.Ptr(rstr.STR)
     v1 = varoftype(PSTR)

File rpython/rlib/jit.py

 
     * promote - promote the argument from a variable into a constant
     * promote_string - same, but promote string by *value*
+    * promote_unicode - same, but promote unicode string by *value*
     * access_directly - directly access a virtualizable, as a structure
                         and don't treat it as a virtualizable
     * fresh_virtualizable - means that virtualizable was just allocated.
 def promote_string(x):
     return hint(x, promote_string=True)
 
+def promote_unicode(x):
+    return hint(x, promote_unicode=True)
+
 def dont_look_inside(func):
     """ Make sure the JIT does not trace inside decorated function
     (it becomes a call instead)