Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
78be7d2
wip
kumaraditya303 Mar 31, 2026
86aac31
Merge branch 'main' of https://github.com/python/cpython into jit-dic…
kumaraditya303 Apr 5, 2026
2fdf76f
fix tests
kumaraditya303 Apr 5, 2026
0dad4a0
improve tests
kumaraditya303 Apr 5, 2026
c953a69
fix test
kumaraditya303 Apr 5, 2026
959bdfa
Merge branch 'main' into jit-dict-opt
kumaraditya303 Apr 7, 2026
38cd1d3
fix _BINARY_OP_SUBSCR_DICT_KNOWN_HASH
kumaraditya303 Apr 7, 2026
e38a5d3
add more tests
kumaraditya303 Apr 7, 2026
1c6b354
Merge branch 'jit-dict-opt' of https://github.com/kumaraditya303/cpyt…
kumaraditya303 Apr 7, 2026
6feb117
add type assertions
kumaraditya303 Apr 7, 2026
3e88c41
address review
kumaraditya303 Apr 30, 2026
af3dbab
Merge branch 'main' of https://github.com/python/cpython into jit-dic…
kumaraditya303 Apr 30, 2026
61bb5ba
fix conflict
kumaraditya303 Apr 30, 2026
f7e97bd
reduce diff
kumaraditya303 Apr 30, 2026
f2dc858
fix test
kumaraditya303 Apr 30, 2026
17fb6b8
fix formatting
kumaraditya303 Apr 30, 2026
7aa3c6b
remove assertions and incorrect immutable checks
kumaraditya303 Apr 30, 2026
b40e922
remove more leftover assertions
kumaraditya303 Apr 30, 2026
3387bff
add watchers in all cases
kumaraditya303 May 1, 2026
94a7cbb
Merge branch 'main' of https://github.com/python/cpython into jit-dic…
kumaraditya303 May 1, 2026
f116f96
Merge branch 'main' into jit-dict-opt
kumaraditya303 May 1, 2026
d6b9e26
Merge branch 'main' of https://github.com/python/cpython into jit-dic…
kumaraditya303 May 3, 2026
686d630
Merge branch 'jit-dict-opt' of https://github.com/kumaraditya303/cpyt…
kumaraditya303 May 3, 2026
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
Prev Previous commit
Next Next commit
add more tests
  • Loading branch information
kumaraditya303 committed Apr 7, 2026
commit e38a5d3503aba32c9caa8f9509e6fefd410e6448
40 changes: 40 additions & 0 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2378,6 +2378,24 @@ def testfunc(n):
self.assertIn("_BINARY_OP_SUBSCR_DICT_KNOWN_HASH", uops)
self.assertNotIn("_BINARY_OP_SUBSCR_DICT", uops)

def test_binary_op_subscr_defaultdict_known_hash(self):
# str, int, bytes, float, complex, tuple and any python object which has generic hash
import collections

def testfunc(n):
x = 0
d = collections.defaultdict(lambda: 1)
for _ in range(n):
x += d['a'] + d[1] + d[b'b'] + d[(1, 2)] + d[_GENERIC_KEY] + d[1.5] + d[1+2j]
return x

res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
self.assertEqual(res, 7 * TIER2_THRESHOLD)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertIn("_BINARY_OP_SUBSCR_DICT_KNOWN_HASH", uops)
self.assertNotIn("_BINARY_OP_SUBSCR_DICT", uops)

def test_store_subscr_dict_known_hash(self):
# str, int, bytes, float, complex, tuple and any python object which has generic hash
def testfunc(n):
Expand All @@ -2399,6 +2417,28 @@ def testfunc(n):
self.assertIn("_STORE_SUBSCR_DICT_KNOWN_HASH", uops)
self.assertNotIn("_STORE_SUBSCR_DICT", uops)

def test_store_subscr_defaultdict_known_hash(self):
import collections

def testfunc(n):
d = collections.defaultdict(lambda: 0)
for _ in range(n):
d['a'] += 1
d[1] += 2
d[b'b'] += 3
d[(1, 2)] += 4
d[_GENERIC_KEY] += 5
d[1.5] += 6
d[1+2j] += 7
return d['a'] + d[1] + d[b'b'] + d[(1, 2)] + d[_GENERIC_KEY] + d[1.5] + d[1+2j]

res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
self.assertEqual(res, 28 * TIER2_THRESHOLD)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertIn("_STORE_SUBSCR_DICT_KNOWN_HASH", uops)
self.assertNotIn("_STORE_SUBSCR_DICT", uops)

def test_contains_op(self):
def testfunc(n):
x = 0
Expand Down
5 changes: 2 additions & 3 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ dummy_func(
tier2 op(_BINARY_OP_SUBSCR_DICT_KNOWN_HASH, (dict_st, sub_st, hash/4 -- res, ds, ss)) {
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
PyObject *dict = PyStackRef_AsPyObjectBorrow(dict_st);

assert(Py_TYPE(dict)->tp_as_mapping->mp_subscript == _PyDict_Subscript);
STAT_INC(BINARY_OP, hit);
PyObject *res_o = _PyDict_SubscriptKnownHash(dict, sub, (Py_hash_t)hash);
if (res_o == NULL) {
Expand Down Expand Up @@ -1401,8 +1401,7 @@ dummy_func(

tier2 op(_STORE_SUBSCR_DICT_KNOWN_HASH, (value, dict_st, sub, hash/4 -- st)) {
PyObject *dict = PyStackRef_AsPyObjectBorrow(dict_st);

assert(PyDict_CheckExact(dict));
assert(Py_TYPE(dict)->tp_as_mapping->mp_ass_subscript == _PyDict_StoreSubscript);
STAT_INC(STORE_SUBSCR, hit);
int err = _PyDict_SetItem_Take2_KnownHash((PyDictObject *)dict,
PyStackRef_AsPyObjectSteal(sub),
Expand Down
3 changes: 2 additions & 1 deletion Python/executor_cases.c.h

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