[pypy-commit] pypy jit-cleanup: remove more stuff from rpython.jit.metainterp.typesystem
rlamy
pypy.commits at gmail.com
Mon Apr 1 23:41:08 EDT 2019
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: jit-cleanup
Changeset: r96402:8ffa1a681639
Date: 2019-04-02 03:32 +0100
http://bitbucket.org/pypy/pypy/changeset/8ffa1a681639/
Log: remove more stuff from rpython.jit.metainterp.typesystem
diff --git a/rpython/jit/backend/test/runner_test.py b/rpython/jit/backend/test/runner_test.py
--- a/rpython/jit/backend/test/runner_test.py
+++ b/rpython/jit/backend/test/runner_test.py
@@ -1,14 +1,15 @@
-import py, sys, random, os, struct, operator, math
-from rpython.jit.metainterp.history import (AbstractFailDescr,
- AbstractDescr,
- BasicFailDescr,
- BasicFinalDescr,
- JitCellToken, TargetToken,
- ConstInt, ConstPtr,
- ConstFloat, Const)
-from rpython.jit.metainterp.resoperation import ResOperation, rop, InputArgInt,\
- InputArgFloat, opname, InputArgRef
-from rpython.jit.metainterp.typesystem import deref
+import py
+import sys
+import random
+import os
+import struct
+import operator
+import math
+from rpython.jit.metainterp.history import (
+ AbstractFailDescr, AbstractDescr, BasicFailDescr, BasicFinalDescr,
+ JitCellToken, TargetToken, ConstInt, ConstPtr, ConstFloat, Const)
+from rpython.jit.metainterp.resoperation import (
+ ResOperation, rop, InputArgInt, InputArgFloat, InputArgRef)
from rpython.jit.metainterp.executor import wrap_constant
from rpython.jit.codewriter.effectinfo import EffectInfo
from rpython.jit.tool.oparser import parse
@@ -55,7 +56,7 @@
add_loop_instructions = ['overload for a specific cpu']
bridge_loop_instructions = ['overload for a specific cpu']
-
+
def execute_operation(self, opname, valueboxes, result_type, descr=None):
inputargs, operations = self._get_single_operation_list(opname,
result_type,
@@ -506,7 +507,7 @@
return chr(ord(c) + 1)
FPTR = self.Ptr(self.FuncType([lltype.Char], lltype.Char))
func_ptr = llhelper(FPTR, func)
- calldescr = cpu.calldescrof(deref(FPTR), (lltype.Char,), lltype.Char,
+ calldescr = cpu.calldescrof(FPTR.TO, (lltype.Char,), lltype.Char,
EffectInfo.MOST_GENERAL)
x = cpu.bh_call_i(self.get_funcbox(cpu, func_ptr).value,
[ord('A')], None, None, calldescr)
@@ -519,7 +520,7 @@
FPTR = self.Ptr(self.FuncType([lltype.Float, lltype.Signed],
lltype.Float))
func_ptr = llhelper(FPTR, func)
- FTP = deref(FPTR)
+ FTP = FPTR.TO
calldescr = cpu.calldescrof(FTP, FTP.ARGS, FTP.RESULT,
EffectInfo.MOST_GENERAL)
x = cpu.bh_call_f(self.get_funcbox(cpu, func_ptr).value,
@@ -548,7 +549,7 @@
#
FPTR = self.Ptr(self.FuncType([TP, TP], TP))
func_ptr = llhelper(FPTR, func)
- FUNC = deref(FPTR)
+ FUNC = FPTR.TO
funcbox = self.get_funcbox(cpu, func_ptr)
# first, try it with the "normal" calldescr
calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
@@ -630,7 +631,7 @@
TP = lltype.Signed
FPTR = self.Ptr(self.FuncType([TP, TP], TP))
func_ptr = llhelper(FPTR, f)
- FUNC = deref(FPTR)
+ FUNC = FPTR.TO
funcconst = self.get_funcbox(self.cpu, func_ptr)
funcbox = InputArgInt(funcconst.getint())
calldescr = self.cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
@@ -656,7 +657,7 @@
#
FPTR = self.Ptr(self.FuncType([TP] * nb_args, TP))
func_ptr = llhelper(FPTR, func_ints)
- FUNC = deref(FPTR)
+ FUNC = FPTR.TO
calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
EffectInfo.MOST_GENERAL)
funcbox = self.get_funcbox(cpu, func_ptr)
@@ -1820,7 +1821,7 @@
EffectInfo.OS_MATH_READ_TIMESTAMP)
FPTR = self.Ptr(self.FuncType([], lltype.SignedLongLong))
func_ptr = llhelper(FPTR, rtimer.read_timestamp)
- FUNC = deref(FPTR)
+ FUNC = FPTR.TO
funcbox = self.get_funcbox(self.cpu, func_ptr)
calldescr = self.cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, effectinfo)
@@ -4454,7 +4455,7 @@
effectinfo = EffectInfo([], [], [], [], [], [], EffectInfo.EF_CANNOT_RAISE, EffectInfo.OS_MATH_SQRT)
FPTR = self.Ptr(self.FuncType([lltype.Float], lltype.Float))
func_ptr = llhelper(FPTR, math_sqrt)
- FUNC = deref(FPTR)
+ FUNC = FPTR.TO
funcbox = self.get_funcbox(self.cpu, func_ptr)
calldescr = self.cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, effectinfo)
@@ -4641,12 +4642,12 @@
assert a + 12 == g
assert a + 14 == h
assert a + 16 == i
- FPTR = self.Ptr(self.FuncType([lltype.Signed]*9, lltype.Void))
+ FPTR = self.Ptr(self.FuncType([lltype.Signed] * 9, lltype.Void))
func_ptr = llhelper(FPTR, func)
cpu = self.cpu
- calldescr = cpu.calldescrof(deref(FPTR), (lltype.Signed,)*9, lltype.Void,
+ calldescr = cpu.calldescrof(FPTR.TO, (lltype.Signed,) * 9, lltype.Void,
EffectInfo.MOST_GENERAL)
- faildescr=BasicFailDescr(42)
+ faildescr = BasicFailDescr(42)
loop = parse("""
[i0]
label(i0, descr=targettoken1)
diff --git a/rpython/jit/codewriter/effectinfo.py b/rpython/jit/codewriter/effectinfo.py
--- a/rpython/jit/codewriter/effectinfo.py
+++ b/rpython/jit/codewriter/effectinfo.py
@@ -1,5 +1,4 @@
import sys
-from rpython.jit.metainterp.typesystem import deref, fieldType, arrayItem
from rpython.rtyper.rclass import OBJECT
from rpython.rtyper.lltypesystem import lltype, llmemory
from rpython.translator.backendopt.graphanalyze import BoolGraphAnalyzer
@@ -298,19 +297,19 @@
write_descrs_interiorfields = []
def add_struct(descrs_fields, (_, T, fieldname)):
- T = deref(T)
+ T = T.TO
if consider_struct(T, fieldname):
descr = cpu.fielddescrof(T, fieldname)
descrs_fields.append(descr)
def add_array(descrs_arrays, (_, T)):
- ARRAY = deref(T)
+ ARRAY = T.TO
if consider_array(ARRAY):
descr = cpu.arraydescrof(ARRAY)
descrs_arrays.append(descr)
def add_interiorfield(descrs_interiorfields, (_, T, fieldname)):
- T = deref(T)
+ T = T.TO
if not isinstance(T, lltype.Array):
return # let's not consider structs for now
if not consider_array(T):
@@ -329,7 +328,7 @@
extraef = list()
for tup in effects:
if tup[0] == "interiorfield" or tup[0] == "readinteriorfield":
- T = deref(tup[1])
+ T = tup[1].TO
if isinstance(T, lltype.Array) and consider_array(T):
val = (tup[0].replace("interiorfield", "array"),
tup[1])
@@ -377,7 +376,7 @@
can_collect)
def consider_struct(TYPE, fieldname):
- if fieldType(TYPE, fieldname) is lltype.Void:
+ if getattr(TYPE, fieldname) is lltype.Void:
return False
if not isinstance(TYPE, lltype.GcStruct): # can be a non-GC-struct
return False
@@ -389,7 +388,7 @@
return True
def consider_array(ARRAY):
- if arrayItem(ARRAY) is lltype.Void:
+ if ARRAY.OF is lltype.Void:
return False
if not isinstance(ARRAY, lltype.GcArray): # can be a non-GC-array
return False
diff --git a/rpython/jit/codewriter/jtransform.py b/rpython/jit/codewriter/jtransform.py
--- a/rpython/jit/codewriter/jtransform.py
+++ b/rpython/jit/codewriter/jtransform.py
@@ -6,10 +6,8 @@
from rpython.jit.codewriter.policy import log
from rpython.jit.metainterp import quasiimmut
from rpython.jit.metainterp.history import getkind
-from rpython.jit.metainterp.typesystem import deref, arrayItem
from rpython.jit.metainterp.blackhole import BlackholeInterpreter
-from rpython.flowspace.model import SpaceOperation, Variable, Constant,\
- c_last_exception
+from rpython.flowspace.model import SpaceOperation, Variable, Constant
from rpython.rlib import objectmodel
from rpython.rlib.jit import _we_are_jitted
from rpython.rlib.rgc import lltype_is_gc
@@ -1729,9 +1727,9 @@
(in which case the original call is written as a residual call).
"""
if oopspec_name.startswith('new'):
- LIST = deref(op.result.concretetype)
+ LIST = op.result.concretetype.TO
else:
- LIST = deref(args[0].concretetype)
+ LIST = args[0].concretetype.TO
resizable = isinstance(LIST, lltype.GcStruct)
assert resizable == (not isinstance(LIST, lltype.GcArray))
if resizable:
diff --git a/rpython/jit/codewriter/support.py b/rpython/jit/codewriter/support.py
--- a/rpython/jit/codewriter/support.py
+++ b/rpython/jit/codewriter/support.py
@@ -4,7 +4,6 @@
from rpython.rtyper.llannotation import lltype_to_annotation
from rpython.annotator.policy import AnnotatorPolicy
from rpython.flowspace.model import Variable, Constant
-from rpython.jit.metainterp.typesystem import deref
from rpython.rlib import rgc
from rpython.rlib.jit import elidable, oopspec
from rpython.rlib.rarithmetic import r_longlong, r_ulonglong, r_uint, intmask
@@ -142,7 +141,7 @@
assert len(lst) == len(args_v), (
"not supported so far: 'greens' variables contain Void")
# a crash here means that you have to reorder the variable named in
- # the JitDriver.
+ # the JitDriver.
lst2 = sort_vars(lst)
assert lst == lst2, ("You have to reorder the variables named in "
"the JitDriver (both the 'greens' and 'reds' independently). "
@@ -786,7 +785,7 @@
bk = rtyper.annotator.bookkeeper
ll_restype = ll_res
if impl.need_result_type != 'exact':
- ll_restype = deref(ll_restype)
+ ll_restype = ll_restype.TO
desc = bk.getdesc(ll_restype)
else:
class TestingDesc(object):
diff --git a/rpython/jit/metainterp/pyjitpl.py b/rpython/jit/metainterp/pyjitpl.py
--- a/rpython/jit/metainterp/pyjitpl.py
+++ b/rpython/jit/metainterp/pyjitpl.py
@@ -1352,7 +1352,9 @@
last_exc_value = metainterp.last_exc_value
assert last_exc_value
assert metainterp.class_of_last_exc_is_const
- if not metainterp.cpu.ts.instanceOf(ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, last_exc_value)), vtablebox):
+ if not metainterp.cpu.ts.instanceOf(
+ ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, last_exc_value)),
+ vtablebox):
self.pc = next_exc_target
@arguments("box", "orgpc")
@@ -1824,7 +1826,7 @@
to handle an indirect_call that may need to be inlined."""
if isinstance(funcbox, Const):
sd = self.metainterp.staticdata
- key = sd.cpu.ts.getaddr_for_box(funcbox)
+ key = funcbox.getaddr()
jitcode = sd.bytecode_for_address(key)
if jitcode is not None:
# we should follow calls to this graph
diff --git a/rpython/jit/metainterp/typesystem.py b/rpython/jit/metainterp/typesystem.py
--- a/rpython/jit/metainterp/typesystem.py
+++ b/rpython/jit/metainterp/typesystem.py
@@ -1,24 +1,9 @@
from rpython.rtyper.lltypesystem import lltype, llmemory
from rpython.rtyper import rclass
-from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance, llstr
from rpython.jit.metainterp import history
from rpython.jit.codewriter import heaptracker
-from rpython.rlib.objectmodel import r_dict, specialize
+from rpython.rlib.objectmodel import r_dict
-def deref(T):
- assert isinstance(T, lltype.Ptr)
- return T.TO
-
-
-def fieldType(T, name):
- assert isinstance(T, lltype.Struct)
- return getattr(T, name)
-
-def arrayItem(ARRAY):
- try:
- return ARRAY.OF
- except AttributeError:
- return ARRAY.ITEM
class TypeSystemHelper(object):
@@ -40,14 +25,6 @@
real_instance = instbox.getref(rclass.OBJECTPTR)
return rclass.ll_isinstance(real_instance, bounding_class)
- def get_exception_box(self, etype):
- return history.ConstInt(etype)
-
- def get_exception_obj(self, evaluebox):
- # only works when translated
- obj = evaluebox.getref(rclass.OBJECTPTR)
- return cast_base_ptr_to_instance(Exception, obj)
-
# A dict whose keys are refs (like the .value of BoxPtr).
# It is an r_dict on lltype. Two copies, to avoid conflicts with
# the value type. Note that NULL is not allowed as a key.
@@ -60,13 +37,6 @@
def new_ref_dict_3(self):
return r_dict(rd_eq, rd_hash, simple_hash_eq=True)
- def cast_vtable_to_hashable(self, cpu, ptr):
- adr = llmemory.cast_ptr_to_adr(ptr)
- return heaptracker.adr2int(adr)
-
- def getaddr_for_box(self, box):
- return box.getaddr()
-
def rd_eq(ref1, ref2):
return ref1 == ref2
diff --git a/rpython/jit/metainterp/virtualizable.py b/rpython/jit/metainterp/virtualizable.py
--- a/rpython/jit/metainterp/virtualizable.py
+++ b/rpython/jit/metainterp/virtualizable.py
@@ -1,6 +1,5 @@
from rpython.jit.codewriter.effectinfo import EffectInfo
from rpython.jit.metainterp import history
-from rpython.jit.metainterp.typesystem import deref, fieldType, arrayItem
from rpython.jit.metainterp.warmstate import wrap, unwrap
from rpython.rlib.unroll import unrolling_iterable
from rpython.rtyper import rvirtualizable
@@ -42,12 +41,12 @@
self.static_fields = static_fields
self.array_fields = array_fields
#
- FIELDTYPES = [fieldType(VTYPE, name) for name in static_fields]
+ FIELDTYPES = [getattr(VTYPE, name) for name in static_fields]
ARRAYITEMTYPES = []
for name in array_fields:
- ARRAYPTR = fieldType(VTYPE, name)
- ARRAY = deref(ARRAYPTR)
+ ARRAYPTR = getattr(VTYPE, name)
assert isinstance(ARRAYPTR, lltype.Ptr)
+ ARRAY = ARRAYPTR.TO
if not isinstance(ARRAY, lltype.GcArray):
raise Exception(
"The virtualizable field '%s' is not an array (found %r)."
@@ -55,8 +54,8 @@
" the list is not resized at run-time. You can do that by"
" using rpython.rlib.debug.make_sure_not_resized()." %
(name, ARRAY))
- ARRAYITEMTYPES.append(arrayItem(ARRAY))
- self.array_descrs = [cpu.arraydescrof(deref(fieldType(VTYPE, name)))
+ ARRAYITEMTYPES.append(ARRAY.OF)
+ self.array_descrs = [cpu.arraydescrof(getattr(VTYPE, name).TO)
for name in array_fields]
#
self.num_static_extra_boxes = len(static_fields)
diff --git a/rpython/rtyper/test/test_rclass.py b/rpython/rtyper/test/test_rclass.py
--- a/rpython/rtyper/test/test_rclass.py
+++ b/rpython/rtyper/test/test_rclass.py
@@ -747,7 +747,6 @@
assert summary(graph) == {}
def test_immutable_fields(self):
- from rpython.jit.metainterp.typesystem import deref
class A(object):
_immutable_fields_ = ["x", "y[*]"]
@@ -758,13 +757,12 @@
def f():
return A(3, [])
t, typer, graph = self.gengraph(f, [])
- A_TYPE = deref(graph.getreturnvar().concretetype)
+ A_TYPE = graph.getreturnvar().concretetype.TO
accessor = A_TYPE._hints["immutable_fields"]
assert accessor.fields == {"inst_x": IR_IMMUTABLE,
"inst_y": IR_IMMUTABLE_ARRAY}
def test_immutable_fields_subclass_1(self):
- from rpython.jit.metainterp.typesystem import deref
class A(object):
_immutable_fields_ = ["x"]
def __init__(self, x):
@@ -777,12 +775,11 @@
def f():
return B(3, 5)
t, typer, graph = self.gengraph(f, [])
- B_TYPE = deref(graph.getreturnvar().concretetype)
+ B_TYPE = graph.getreturnvar().concretetype.TO
accessor = B_TYPE._hints["immutable_fields"]
assert accessor.fields == {"inst_x": IR_IMMUTABLE}
def test_immutable_fields_subclass_2(self):
- from rpython.jit.metainterp.typesystem import deref
class A(object):
_immutable_fields_ = ["x"]
def __init__(self, x):
@@ -796,13 +793,12 @@
def f():
return B(3, 5)
t, typer, graph = self.gengraph(f, [])
- B_TYPE = deref(graph.getreturnvar().concretetype)
+ B_TYPE = graph.getreturnvar().concretetype.TO
accessor = B_TYPE._hints["immutable_fields"]
assert accessor.fields == {"inst_x": IR_IMMUTABLE,
"inst_y": IR_IMMUTABLE}
def test_immutable_fields_only_in_subclass(self):
- from rpython.jit.metainterp.typesystem import deref
class A(object):
def __init__(self, x):
self.x = x
@@ -815,7 +811,7 @@
def f():
return B(3, 5)
t, typer, graph = self.gengraph(f, [])
- B_TYPE = deref(graph.getreturnvar().concretetype)
+ B_TYPE = graph.getreturnvar().concretetype.TO
accessor = B_TYPE._hints["immutable_fields"]
assert accessor.fields == {"inst_y": IR_IMMUTABLE}
@@ -844,7 +840,6 @@
py.test.raises(ImmutableConflictError, self.gengraph, f, [])
def test_immutable_ok_inheritance_2(self):
- from rpython.jit.metainterp.typesystem import deref
class A(object):
_immutable_fields_ = ['v']
class B(A):
@@ -854,7 +849,7 @@
B().w = 456
return B()
t, typer, graph = self.gengraph(f, [])
- B_TYPE = deref(graph.getreturnvar().concretetype)
+ B_TYPE = graph.getreturnvar().concretetype.TO
assert B_TYPE._hints["immutable"]
A_TYPE = B_TYPE.super
accessor = A_TYPE._hints["immutable_fields"]
@@ -862,7 +857,6 @@
def test_immutable_subclass_1(self):
from rpython.rtyper.rclass import ImmutableConflictError
- from rpython.jit.metainterp.typesystem import deref
class A(object):
_immutable_ = True
class B(A):
@@ -874,7 +868,6 @@
py.test.raises(ImmutableConflictError, self.gengraph, f, [])
def test_immutable_subclass_2(self):
- from rpython.jit.metainterp.typesystem import deref
class A(object):
pass
class B(A):
@@ -884,11 +877,10 @@
B().v = 123
return B()
t, typer, graph = self.gengraph(f, [])
- B_TYPE = deref(graph.getreturnvar().concretetype)
+ B_TYPE = graph.getreturnvar().concretetype.TO
assert B_TYPE._hints["immutable"]
def test_immutable_subclass_void(self):
- from rpython.jit.metainterp.typesystem import deref
class A(object):
pass
class B(A):
@@ -900,11 +892,10 @@
B().v = 123 # even though only B is declared _immutable_
return B()
t, typer, graph = self.gengraph(f, [])
- B_TYPE = deref(graph.getreturnvar().concretetype)
+ B_TYPE = graph.getreturnvar().concretetype.TO
assert B_TYPE._hints["immutable"]
def test_quasi_immutable(self):
- from rpython.jit.metainterp.typesystem import deref
class A(object):
_immutable_fields_ = ['x', 'y', 'a?', 'b?']
class B(A):
@@ -920,7 +911,7 @@
b.b = 45
return B()
t, typer, graph = self.gengraph(f, [])
- B_TYPE = deref(graph.getreturnvar().concretetype)
+ B_TYPE = graph.getreturnvar().concretetype.TO
accessor = B_TYPE._hints["immutable_fields"]
assert accessor.fields == {"inst_y": IR_IMMUTABLE,
"inst_b": IR_QUASIIMMUTABLE}
@@ -931,7 +922,6 @@
assert found == ['mutate_a', 'mutate_a', 'mutate_b']
def test_quasi_immutable_clashes_with_immutable(self):
- from rpython.jit.metainterp.typesystem import deref
class A(object):
_immutable_ = True
_immutable_fields_ = ['a?']
@@ -944,7 +934,6 @@
self.gengraph(f, [])
def test_quasi_immutable_array(self):
- from rpython.jit.metainterp.typesystem import deref
class A(object):
_immutable_fields_ = ['c?[*]']
class B(A):
@@ -954,7 +943,7 @@
a.c = [3, 4, 5]
return A()
t, typer, graph = self.gengraph(f, [])
- A_TYPE = deref(graph.getreturnvar().concretetype)
+ A_TYPE = graph.getreturnvar().concretetype.TO
accessor = A_TYPE._hints["immutable_fields"]
assert accessor.fields == {"inst_c": IR_QUASIIMMUTABLE_ARRAY}
found = []
More information about the pypy-commit
mailing list