[pypy-svn] r62889 - in pypy/branch/pyjitpl5/pypy/jit: backend/llgraph metainterp
arigo at codespeak.net
arigo at codespeak.net
Thu Mar 12 15:59:03 CET 2009
Author: arigo
Date: Thu Mar 12 15:59:02 2009
New Revision: 62889
Modified:
pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/executor.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/history.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/resoperation.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/specnode.py
Log:
Add an abstract class, AbstractDescr, inheriting from AbstractValue.
Allows us to do asserts in metainterp. Fix all places found by
these asserts.
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py Thu Mar 12 15:59:02 2009
@@ -14,7 +14,7 @@
pass
-class Descr(history.AbstractValue):
+class Descr(history.AbstractDescr):
def __init__(self, ofs, type='?'):
self.ofs = ofs
self.type = type
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/executor.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/executor.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/executor.py Thu Mar 12 15:59:02 2009
@@ -3,7 +3,7 @@
import py
from pypy.rlib.rarithmetic import ovfcheck, r_uint, intmask
-from pypy.jit.metainterp.history import BoxInt, ConstInt
+from pypy.jit.metainterp.history import BoxInt, ConstInt, check_descr
from pypy.jit.metainterp.resoperation import rop
@@ -214,6 +214,7 @@
get_execute_function._annspecialcase_ = 'specialize:memo'
def execute(cpu, opnum, argboxes, descr=None):
+ check_descr(descr)
func = get_execute_function(cpu, opnum)
return func(cpu, argboxes, descr)
execute._annspecialcase_ = 'specialize:arg(1)'
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/history.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/history.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/history.py Thu Mar 12 15:59:02 2009
@@ -1,4 +1,5 @@
+from pypy.rpython.extregistry import ExtRegistryEntry
from pypy.rpython.lltypesystem import lltype, llmemory
from pypy.rlib.objectmodel import we_are_translated, r_dict, Symbolic
from pypy.rlib.rarithmetic import intmask
@@ -76,6 +77,11 @@
def equals(self, other):
raise NotImplementedError
+
+class AbstractDescr(AbstractValue):
+ pass
+
+
class Const(AbstractValue):
__slots__ = ()
@@ -476,3 +482,25 @@
self.listops = listops
def _freeze_(self):
return True
+
+# ----------------------------------------------------------------
+
+def check_descr(x):
+ """Check that 'x' is None or an instance of AbstractDescr.
+ Explodes if the annotator only thinks it is an instance of AbstractValue.
+ """
+
+class Entry(ExtRegistryEntry):
+ _about_ = check_descr
+
+ def compute_result_annotation(self, s_x):
+ from pypy.annotation import model as annmodel
+ if not annmodel.s_None.contains(s_x):
+ assert isinstance(s_x, annmodel.SomeInstance)
+ # the following assert fails if we somehow did not manage
+ # to ensure that the 'descr' field of ResOperation is really
+ # an instance of AbstractDescr, a subclass of AbstractValue.
+ assert issubclass(s_x.classdef.classdesc.pyobj, AbstractDescr)
+
+ def specialize_call(self, hop):
+ hop.exception_cannot_occur()
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py Thu Mar 12 15:59:02 2009
@@ -1,7 +1,7 @@
from pypy.jit.metainterp.resoperation import rop
from pypy.jit.metainterp.history import (Box, Const, ConstInt, BoxInt,
- ResOperation)
-from pypy.jit.metainterp.history import Options, AbstractValue, ConstPtr
+ ResOperation, AbstractDescr,
+ Options, AbstractValue, ConstPtr)
from pypy.jit.metainterp.specnode import (FixedClassSpecNode,
#FixedListSpecNode,
VirtualInstanceSpecNode,
@@ -781,6 +781,7 @@
[node.source, ofs, valuenode.source],
None, ld.arraydescr))
else:
+ assert isinstance(ofs, AbstractDescr)
newoperations.append(ResOperation(rop.SETFIELD_GC,
[node.source, valuenode.source], None, ofs))
node.dirtyfields = {}
@@ -855,6 +856,7 @@
box = box_from_index(allocated_boxes, allocated_lists,
boxes_from_frame,
index_in_alloc)
+ assert isinstance(ofs, AbstractDescr)
metainterp.execute_and_record(rop.SETFIELD_GC,
[box, fieldbox], ofs)
for index_in_alloc, ad, ofs, index_in_arglist in storage.setitems:
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py Thu Mar 12 15:59:02 2009
@@ -65,6 +65,10 @@
args += (self.load_varargs(), )
elif argspec == "constargs":
args += (self.load_constargs(), )
+ elif argspec == "descr":
+ descr = self.load_const_arg()
+ assert isinstance(descr, history.AbstractDescr)
+ args += (descr, )
elif argspec == "bytecode":
bytecode = self.load_const_arg()
assert isinstance(bytecode, codewriter.JitCode)
@@ -311,38 +315,38 @@
except KeyError:
pass
- @arguments("constbox")
+ @arguments("descr")
def opimpl_new(self, size):
self.execute(rop.NEW, [], descr=size)
- @arguments("constbox", "constbox")
+ @arguments("descr", "constbox")
def opimpl_new_with_vtable(self, size, vtablebox):
self.execute(rop.NEW_WITH_VTABLE, [vtablebox], descr=size)
- @arguments("constbox", "box")
+ @arguments("descr", "box")
def opimpl_new_array(self, itemsize, countbox):
self.execute(rop.NEW_ARRAY, [countbox], descr=itemsize)
- @arguments("box", "constbox", "box")
+ @arguments("box", "descr", "box")
def opimpl_getarrayitem_gc(self, arraybox, arraydesc, indexbox):
self.execute(rop.GETARRAYITEM_GC, [arraybox, indexbox],
descr=arraydesc)
- @arguments("box", "constbox", "box")
+ @arguments("box", "descr", "box")
def opimpl_getarrayitem_gc_pure(self, arraybox, arraydesc, indexbox):
self.execute(rop.GETARRAYITEM_GC_PURE, [arraybox, indexbox],
descr=arraydesc)
- @arguments("box", "constbox", "box", "box")
+ @arguments("box", "descr", "box", "box")
def opimpl_setarrayitem_gc(self, arraybox, arraydesc, indexbox, itembox):
self.execute(rop.SETARRAYITEM_GC, [arraybox, indexbox, itembox],
descr=arraydesc)
- @arguments("box", "constbox")
+ @arguments("box", "descr")
def opimpl_arraylen_gc(self, arraybox, arraydesc):
self.execute(rop.ARRAYLEN_GC, [arraybox], descr=arraydesc)
- @arguments("orgpc", "box", "constbox", "box")
+ @arguments("orgpc", "box", "descr", "box")
def opimpl_check_neg_index(self, pc, arraybox, arraydesc, indexbox):
negbox = self.metainterp.execute_and_record(
rop.INT_LT, [indexbox, ConstInt(0)])
@@ -372,23 +376,23 @@
self.execute(rop.OOISNOT, [box1, box2])
- @arguments("box", "constbox")
+ @arguments("box", "descr")
def opimpl_getfield_gc(self, box, fielddesc):
self.execute(rop.GETFIELD_GC, [box], descr=fielddesc)
- @arguments("box", "constbox")
+ @arguments("box", "descr")
def opimpl_getfield_gc_pure(self, box, fielddesc):
self.execute(rop.GETFIELD_GC_PURE, [box], descr=fielddesc)
- @arguments("box", "constbox", "box")
+ @arguments("box", "descr", "box")
def opimpl_setfield_gc(self, box, fielddesc, valuebox):
self.execute(rop.SETFIELD_GC, [box, valuebox], descr=fielddesc)
- @arguments("box", "constbox")
+ @arguments("box", "descr")
def opimpl_getfield_raw(self, box, fielddesc):
self.execute(rop.GETFIELD_RAW, [box], descr=fielddesc)
- @arguments("box", "constbox")
+ @arguments("box", "descr")
def opimpl_getfield_raw_pure(self, box, fielddesc):
self.execute(rop.GETFIELD_RAW_PURE, [box], descr=fielddesc)
- @arguments("box", "constbox", "box")
+ @arguments("box", "descr", "box")
def opimpl_setfield_raw(self, box, fielddesc, valuebox):
self.execute(rop.SETFIELD_RAW, [box, valuebox], descr=fielddesc)
@@ -407,11 +411,11 @@
f.setup_call(varargs)
return True
- @arguments("constbox", "varargs")
+ @arguments("descr", "varargs")
def opimpl_residual_call(self, calldescr, varargs):
return self.execute_with_exc(rop.CALL, varargs, descr=calldescr)
- @arguments("constbox", "varargs")
+ @arguments("descr", "varargs")
def opimpl_residual_call_pure(self, calldescr, varargs):
self.execute(rop.CALL_PURE, varargs, descr=calldescr)
@@ -512,7 +516,7 @@
## 'len', [builtin.len_func, box], 'int')
## self.generate_guard(pc, "guard_len", box, [intbox])
- @arguments("orgpc", "box", "virtualizabledesc", "constbox")
+ @arguments("orgpc", "box", "virtualizabledesc", "descr")
def opimpl_guard_nonvirtualized(self, pc, box, vdesc, guard_field):
clsbox = self.cls_of_box(box)
op = self.generate_guard(pc, rop.GUARD_NONVIRTUALIZED, box,
@@ -663,6 +667,7 @@
@specialize.arg(1)
def execute_with_exc(self, opnum, argboxes, descr=None):
cpu = self.metainterp.cpu
+ history.check_descr(descr)
resbox = executor.execute(cpu, opnum, argboxes, descr)
if not we_are_translated():
self.metainterp._debug_history.append(['call',
@@ -765,6 +770,7 @@
def execute_and_record(self, opnum, argboxes, descr=None):
# execute the operation first
+ history.check_descr(descr)
resbox = executor.execute(self.cpu, opnum, argboxes, descr)
# check if the operation can be constant-folded away
canfold = False
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/resoperation.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/resoperation.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/resoperation.py Thu Mar 12 15:59:02 2009
@@ -29,10 +29,9 @@
# for 'call', 'new', 'getfield_gc'...: the descr is a number provided
# by the backend holding details about the type of the operation --
# actually an instance of a class, typically Descr, that inherits
- # from AbstractValue
- if descr is not None:
- from pypy.jit.metainterp.history import AbstractValue
- assert isinstance(descr, AbstractValue)
+ # from AbstractDescr
+ from pypy.jit.metainterp.history import check_descr
+ check_descr(descr)
self.descr = descr
def __repr__(self):
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/specnode.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/specnode.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/specnode.py Thu Mar 12 15:59:02 2009
@@ -125,6 +125,8 @@
def extract_runtime_data(self, cpu, valuebox, resultlist):
for ofs, subspecnode in self.fields:
+ from pypy.jit.metainterp.history import AbstractDescr
+ assert isinstance(ofs, AbstractDescr)
fieldbox = executor.execute(cpu, rop.GETFIELD_GC,
[valuebox], ofs)
subspecnode.extract_runtime_data(cpu, fieldbox, resultlist)
@@ -150,6 +152,7 @@
class DelayedSpecNode(VirtualizedSpecNode):
def expand_boxlist(self, instnode, newboxlist, oplist):
+ from pypy.jit.metainterp.history import AbstractDescr
newboxlist.append(instnode.source)
for ofs, subspecnode in self.fields:
assert isinstance(subspecnode, SpecNodeWithBox)
@@ -161,6 +164,7 @@
newboxlist.append(instnode.cleanfields[ofs].source)
else:
box = subspecnode.box.clonebox()
+ assert isinstance(ofs, AbstractDescr)
oplist.append(ResOperation(rop.GETFIELD_GC,
[instnode.source], box, ofs))
newboxlist.append(box)
@@ -193,11 +197,13 @@
def extract_runtime_data(self, cpu, valuebox, resultlist):
from pypy.jit.metainterp.resoperation import rop
from pypy.jit.metainterp.optimize import FixedList
+ from pypy.jit.metainterp.history import check_descr
resultlist.append(valuebox)
cls = self.known_class
assert isinstance(cls, FixedList)
arraydescr = cls.arraydescr
+ check_descr(arraydescr)
for ofs, subspecnode in self.fields:
fieldbox = executor.execute(cpu, rop.GETARRAYITEM_GC,
[valuebox, ofs], arraydescr)
@@ -241,11 +247,12 @@
def extract_runtime_data(self, cpu, valuebox, resultlist):
from pypy.jit.metainterp.resoperation import rop
from pypy.jit.metainterp.optimize import FixedList
-
+ from pypy.jit.metainterp.history import check_descr
+ cls = self.known_class
+ assert isinstance(cls, FixedList)
+ arraydescr = cls.arraydescr
+ check_descr(arraydescr)
for ofs, subspecnode in self.fields:
- cls = self.known_class
- assert isinstance(cls, FixedList)
- arraydescr = cls.arraydescr
fieldbox = executor.execute(cpu, rop.GETARRAYITEM_GC,
[valuebox, ofs], arraydescr)
subspecnode.extract_runtime_data(cpu, fieldbox, resultlist)
More information about the Pypy-commit
mailing list