Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 Include/internal/pycore_interp_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ struct _py_func_state {

/* For now we hard-code this to a value for which we are confident
all the static builtin types will fit (for all builds). */
#define _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES 200
#define _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES 201
#define _Py_MAX_MANAGED_STATIC_EXT_TYPES 10
#define _Py_MAX_MANAGED_STATIC_TYPES \
(_Py_MAX_MANAGED_STATIC_BUILTIN_TYPES + _Py_MAX_MANAGED_STATIC_EXT_TYPES)
Expand Down
42 changes: 42 additions & 0 deletions 42 Lib/test/test_opcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,27 @@ def contains_op_dict():
self.assert_specialized(contains_op_dict, "CONTAINS_OP_DICT")
self.assert_no_opcode(contains_op_dict, "CONTAINS_OP")

def contains_op_frozen_dict():
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
a, b = 1, frozendict({1: 2, 2: 5})
self.assertTrue(a in b)
self.assertFalse(3 in b)

contains_op_frozen_dict()
self.assert_specialized(contains_op_frozen_dict, "CONTAINS_OP_DICT")
self.assert_no_opcode(contains_op_frozen_dict, "CONTAINS_OP")

def contains_op_frozen_dict_subclass():
class MyFrozenDict(frozendict):
pass
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
a, b = 1, MyFrozenDict({1: 2, 2: 5})
self.assertTrue(a in b)
self.assertFalse(3 in b)

contains_op_frozen_dict_subclass()
self.assert_no_opcode(contains_op_frozen_dict_subclass, "CONTAINS_OP_DICT")

def contains_op_set():
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
a, b = 1, {1, 2}
Expand Down Expand Up @@ -1808,6 +1829,27 @@ def binary_subscr_dict():
self.assert_specialized(binary_subscr_dict, "BINARY_OP_SUBSCR_DICT")
self.assert_no_opcode(binary_subscr_dict, "BINARY_OP")

def binary_subscr_frozen_dict():
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
a = frozendict({1: 2, 2: 3})
self.assertEqual(a[1], 2)
self.assertEqual(a[2], 3)

binary_subscr_frozen_dict()
self.assert_specialized(binary_subscr_frozen_dict, "BINARY_OP_SUBSCR_DICT")
self.assert_no_opcode(binary_subscr_frozen_dict, "BINARY_OP")

def binary_subscr_frozen_dict_subclass():
class MyFrozenDict(frozendict):
pass
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
a = MyFrozenDict({1: 2, 2: 3})
self.assertEqual(a[1], 2)
self.assertEqual(a[2], 3)

binary_subscr_frozen_dict_subclass()
self.assert_no_opcode(binary_subscr_frozen_dict_subclass, "BINARY_OP_SUBSCR_DICT")

def binary_subscr_str_int():
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
a = "foobar"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update specializer to support frozendict. Patch by Donghee Na.
10 changes: 5 additions & 5 deletions 10 Modules/_testinternalcapi/test_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions 8 Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1058,12 +1058,12 @@ dummy_func(

op(_GUARD_NOS_DICT, (nos, unused -- nos, unused)) {
PyObject *o = PyStackRef_AsPyObjectBorrow(nos);
EXIT_IF(!PyDict_CheckExact(o));
EXIT_IF(!PyAnyDict_CheckExact(o));
}

op(_GUARD_TOS_DICT, (tos -- tos)) {
PyObject *o = PyStackRef_AsPyObjectBorrow(tos);
EXIT_IF(!PyDict_CheckExact(o));
EXIT_IF(!PyAnyDict_CheckExact(o));
}

macro(BINARY_OP_SUBSCR_DICT) =
Expand All @@ -1073,7 +1073,7 @@ dummy_func(
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
PyObject *dict = PyStackRef_AsPyObjectBorrow(dict_st);

assert(PyDict_CheckExact(dict));
assert(PyAnyDict_CheckExact(dict));
STAT_INC(BINARY_OP, hit);
PyObject *res_o;
int rc = PyDict_GetItemRef(dict, sub, &res_o);
Expand Down Expand Up @@ -2940,7 +2940,7 @@ dummy_func(
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);

assert(PyDict_CheckExact(right_o));
assert(PyAnyDict_CheckExact(right_o));
STAT_INC(CONTAINS_OP, hit);
int res = PyDict_Contains(right_o, left_o);
if (res < 0) {
Expand Down
20 changes: 10 additions & 10 deletions 20 Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions 10 Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions 4 Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -2287,7 +2287,7 @@ _Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *in
}
}
}
if (PyDict_CheckExact(lhs)) {
if (PyAnyDict_CheckExact(lhs)) {
specialize(instr, BINARY_OP_SUBSCR_DICT);
return;
}
Expand Down Expand Up @@ -2767,7 +2767,7 @@ _Py_Specialize_ContainsOp(_PyStackRef value_st, _Py_CODEUNIT *instr)

assert(ENABLE_SPECIALIZATION);
assert(_PyOpcode_Caches[CONTAINS_OP] == INLINE_CACHE_ENTRIES_COMPARE_OP);
if (PyDict_CheckExact(value)) {
if (PyAnyDict_CheckExact(value)) {
specialize(instr, CONTAINS_OP_DICT);
return;
}
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.