Skip to content

Commit 3dce1ee

Browse files
Mingshen Sunmssun
Mingshen Sun
authored andcommitted
Use "UNSAFE" keyword in docstring to represent unsafe list operations
- change compilation flag from RPY_LL_ASSERT to RPY_ASSERT - record "UNSAFE" "keyword" from docstring in translator - modify flowspace model and pygraph to propagate unsafe state - change rtyper to propagate unsafe state to rlist - add unsafe getitem/setitem functions in low level rlist - modify rlist to check hop's unsafe state, if it is unsafe then use unsafe getitem/setitem functions, ll rlist at last
1 parent c8192ea commit 3dce1ee

File tree

10 files changed

+581
-74
lines changed

10 files changed

+581
-74
lines changed

rpython/flowspace/model.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
class FunctionGraph(object):
14-
def __init__(self, name, startblock, return_var=None):
14+
def __init__(self, name, startblock, return_var=None, unsafe=False):
1515
self.name = name # function name (possibly mangled already)
1616
self.startblock = startblock
1717
# build default returnblock
@@ -24,6 +24,7 @@ def __init__(self, name, startblock, return_var=None):
2424
self.exceptblock.operations = ()
2525
self.exceptblock.exits = ()
2626
self.tag = None
27+
self.unsafe = unsafe
2728

2829
def getargs(self):
2930
return self.startblock.inputargs
@@ -65,12 +66,14 @@ def __repr__(self):
6566

6667
def iterblocks(self):
6768
block = self.startblock
69+
block.unsafe = self.unsafe
6870
yield block
6971
seen = {block: True}
7072
stack = list(block.exits[::-1])
7173
while stack:
7274
block = stack.pop().target
7375
if block not in seen:
76+
block.unsafe = self.unsafe
7477
yield block
7578
seen[block] = True
7679
stack += block.exits[::-1]
@@ -170,14 +173,15 @@ def show(self):
170173

171174
class Block(object):
172175
__slots__ = """inputargs operations exitswitch
173-
exits blockcolor generation""".split()
176+
exits blockcolor generation unsafe""".split()
174177

175178
def __init__(self, inputargs):
176179
self.inputargs = list(inputargs) # mixed list of variable/const XXX
177180
self.operations = [] # list of SpaceOperation(s)
178181
self.exitswitch = None # a variable or
179182
# Constant(last_exception), see below
180183
self.exits = [] # list of Link(s)
184+
self.unsafe = False
181185

182186
def is_final_block(self):
183187
return self.operations == () # return or except block
@@ -539,6 +543,7 @@ def copyoplist(oplist):
539543
return result
540544
newblock.operations = copyoplist(block.operations)
541545
newblock.exitswitch = copyvar(block.exitswitch)
546+
newblock.unsafe = block.unsafe
542547
return newblock
543548

544549
for block in graph.iterblocks():
@@ -558,7 +563,7 @@ def copyoplist(oplist):
558563
newblock.closeblock(*newlinks)
559564

560565
newstartblock = blockmap[graph.startblock]
561-
newgraph = FunctionGraph(graph.name, newstartblock)
566+
newgraph = FunctionGraph(graph.name, newstartblock, unsafe=graph.unsafe)
562567
newgraph.returnblock = blockmap[graph.returnblock]
563568
newgraph.exceptblock = blockmap[graph.exceptblock]
564569
for key, value in graph.__dict__.items():

rpython/flowspace/pygraph.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ def __init__(self, func, code):
1616
locals[i] = Variable(code.co_varnames[i])
1717
state = FrameState(locals, [], None, [], 0)
1818
initialblock = SpamBlock(state)
19-
super(PyGraph, self).__init__(self._sanitize_funcname(func), initialblock)
19+
unsafe = False
20+
if func.func_doc and func.func_doc.lstrip().startswith('UNSAFE'):
21+
unsafe = True
22+
super(PyGraph, self).__init__(self._sanitize_funcname(func), initialblock, unsafe=unsafe)
2023
self.func = func
2124
self.signature = code.signature
2225
self.defaults = func.func_defaults or ()

0 commit comments

Comments
 (0)