Skip to content

Commit 44f5c49

Browse files
committed
type information for kwargs
1 parent d35071a commit 44f5c49

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Python/optimizer_symbols.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,26 @@ _Py_uop_frame_new(
15341534
frame->locals[i] = local;
15351535
}
15361536

1537+
/* CPython guarantees that *args is always a tuple and **kwargs is always
1538+
* a dict. Mark their slots with the correct types so the JIT optimizer
1539+
* can specialise TO_BOOL (and other ops) on them without needing runtime
1540+
* type guards. */
1541+
if (co->co_flags & (CO_VARARGS | CO_VARKEYWORDS)) {
1542+
int total_args = co->co_argcount + co->co_kwonlyargcount;
1543+
int slot = total_args;
1544+
if (co->co_flags & CO_VARARGS) {
1545+
/* *args lives at slot `total_args` and is always a tuple. */
1546+
assert(slot < co->co_nlocalsplus);
1547+
frame->locals[slot] = _Py_uop_sym_new_type(ctx, &PyTuple_Type);
1548+
slot++;
1549+
}
1550+
if (co->co_flags & CO_VARKEYWORDS) {
1551+
/* **kwargs lives at the next slot and is always a dict. */
1552+
assert(slot < co->co_nlocalsplus);
1553+
frame->locals[slot] = _Py_uop_sym_new_type(ctx, &PyDict_Type);
1554+
}
1555+
}
1556+
15371557
frame->callable = _Py_uop_sym_new_not_null(ctx);
15381558

15391559
/* Most optimizations rely on code objects being immutable (including sys._getframe modifications),

0 commit comments

Comments
 (0)