[pypy-commit] pypy non-null-app-dict: add a way to specify "cannot be null" on other dicts
fijal
noreply at buildbot.pypy.org
Tue Jun 28 18:48:35 CEST 2011
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: non-null-app-dict
Changeset: r45164:9ce43d8bc53f
Date: 2011-06-28 18:54 +0200
http://bitbucket.org/pypy/pypy/changeset/9ce43d8bc53f/
Log: add a way to specify "cannot be null" on other dicts
diff --git a/pypy/rlib/debug.py b/pypy/rlib/debug.py
--- a/pypy/rlib/debug.py
+++ b/pypy/rlib/debug.py
@@ -262,6 +262,28 @@
return hop.inputarg(hop.args_r[0], arg=0)
+def mark_dict_non_null(d):
+ """ Mark dictionary as having non-null keys and values. A warning would
+ be emitted (not an error!) in case annotation disagrees.
+ """
+ assert isinstance(d, dict)
+ return d
+
+
+class DictMarkEntry(ExtRegistryEntry):
+ _about_ = mark_dict_non_null
+
+ def compute_result_annotation(self, s_dict):
+ from pypy.annotation.model import SomeDict, s_None
+
+ assert isinstance(s_dict, SomeDict)
+ s_dict.dictdef.force_non_null = True
+ return s_dict
+
+ def specialize_call(self, hop):
+ hop.exception_cannot_occur()
+ return hop.inputarg(hop.args_r[0], arg=0)
+
class IntegerCanBeNegative(Exception):
pass
diff --git a/pypy/rlib/test/test_debug.py b/pypy/rlib/test/test_debug.py
--- a/pypy/rlib/test/test_debug.py
+++ b/pypy/rlib/test/test_debug.py
@@ -1,11 +1,12 @@
import py
-from pypy.rlib.debug import check_annotation, make_sure_not_resized
-from pypy.rlib.debug import debug_print, debug_start, debug_stop
-from pypy.rlib.debug import have_debug_prints, debug_offset, debug_flush
-from pypy.rlib.debug import check_nonneg, IntegerCanBeNegative
+from pypy.rlib.debug import (check_annotation, make_sure_not_resized,
+ debug_print, debug_start, debug_stop,
+ have_debug_prints, debug_offset, debug_flush,
+ check_nonneg, IntegerCanBeNegative,
+ mark_dict_non_null)
from pypy.rlib import debug
-from pypy.rpython.test.test_llinterp import interpret
+from pypy.rpython.test.test_llinterp import interpret, gengraph
def test_check_annotation():
class Error(Exception):
@@ -52,8 +53,17 @@
py.test.raises(ListChangeUnallowed, interpret, f, [],
list_comprehension_operations=True)
+def test_mark_dict_non_null():
+ def f():
+ d = {"ac": "bx"}
+ mark_dict_non_null(d)
+ return d
-class DebugTests:
+ t, typer, graph = gengraph(f, [])
+ assert sorted(graph.returnblock.inputargs[0].concretetype.TO.entries.TO.OF._flds.keys()) == ['key', 'value']
+
+
+class DebugTests(object):
def test_debug_print_start_stop(self):
def f(x):
More information about the pypy-commit
mailing list