Skip to content

Commit 4fe05f1

Browse files
committed
Add COPY_FREE_VARS instruction to allow specialization of calls to inner functions.
1 parent d891208 commit 4fe05f1

File tree

12 files changed

+118
-72
lines changed

12 files changed

+118
-72
lines changed

Include/opcode.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/importlib/_bootstrap_external.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ def _write_atomic(path, data, mode=0o666):
370370
# active exception)
371371
# Python 3.11a3 3464 (bpo-45636: Merge numeric BINARY_*/INPLACE_* into
372372
# BINARY_OP)
373+
# Python 3.11a3 3465 (Add COPY_FREE_VARS opcode)
373374

374375
#
375376
# MAGIC must change whenever the bytecode emitted by the compiler may no
@@ -379,7 +380,7 @@ def _write_atomic(path, data, mode=0o666):
379380
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
380381
# in PC/launcher.c must also be updated.
381382

382-
MAGIC_NUMBER = (3464).to_bytes(2, 'little') + b'\r\n'
383+
MAGIC_NUMBER = (3465).to_bytes(2, 'little') + b'\r\n'
383384
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
384385

385386
_PYCACHE = '__pycache__'

Lib/opcode.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def jabs_op(name, op):
177177
def_op('MAP_ADD', 147)
178178
def_op('LOAD_CLASSDEREF', 148)
179179
hasfree.append(148)
180+
def_op('COPY_FREE_VARS', 149)
180181

181182
def_op('MATCH_CLASS', 152)
182183

Lib/test/test_code.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@
141141
check_impl_detail, requires_debug_ranges,
142142
gc_collect)
143143
from test.support.script_helper import assert_python_ok
144+
from opcode import opmap
145+
COPY_FREE_VARS = opmap['COPY_FREE_VARS']
144146

145147

146148
def consts(t):
@@ -185,7 +187,7 @@ def create_closure(__class__):
185187

186188
def new_code(c):
187189
'''A new code object with a __class__ cell added to freevars'''
188-
return c.replace(co_freevars=c.co_freevars + ('__class__',))
190+
return c.replace(co_freevars=c.co_freevars + ('__class__',), co_code=bytes([COPY_FREE_VARS, 1])+c.co_code)
189191

190192
def add_foreign_method(cls, name, f):
191193
code = new_code(f.__code__)

Lib/test/test_dis.py

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -459,16 +459,17 @@ def foo(x):
459459

460460
dis_nested_1 = """%s
461461
Disassembly of <code object foo at 0x..., file "%s", line %d>:
462-
0 MAKE_CELL 0 (x)
463-
464-
%3d 2 LOAD_CLOSURE 0 (x)
465-
4 BUILD_TUPLE 1
466-
6 LOAD_CONST 1 (<code object <listcomp> at 0x..., file "%s", line %d>)
467-
8 MAKE_FUNCTION 8 (closure)
468-
10 LOAD_DEREF 1 (y)
469-
12 GET_ITER
470-
14 CALL_FUNCTION 1
471-
16 RETURN_VALUE
462+
0 COPY_FREE_VARS 1
463+
2 MAKE_CELL 0 (x)
464+
465+
%3d 4 LOAD_CLOSURE 0 (x)
466+
6 BUILD_TUPLE 1
467+
8 LOAD_CONST 1 (<code object <listcomp> at 0x..., file "%s", line %d>)
468+
10 MAKE_FUNCTION 8 (closure)
469+
12 LOAD_DEREF 1 (y)
470+
14 GET_ITER
471+
16 CALL_FUNCTION 1
472+
18 RETURN_VALUE
472473
""" % (dis_nested_0,
473474
__file__,
474475
_h.__code__.co_firstlineno + 1,
@@ -479,16 +480,18 @@ def foo(x):
479480

480481
dis_nested_2 = """%s
481482
Disassembly of <code object <listcomp> at 0x..., file "%s", line %d>:
482-
%3d 0 BUILD_LIST 0
483-
2 LOAD_FAST 0 (.0)
484-
>> 4 FOR_ITER 6 (to 18)
485-
6 STORE_FAST 1 (z)
486-
8 LOAD_DEREF 2 (x)
487-
10 LOAD_FAST 1 (z)
488-
12 BINARY_OP 0 (+)
489-
14 LIST_APPEND 2
490-
16 JUMP_ABSOLUTE 2 (to 4)
491-
>> 18 RETURN_VALUE
483+
0 COPY_FREE_VARS 1
484+
485+
%3d 2 BUILD_LIST 0
486+
4 LOAD_FAST 0 (.0)
487+
>> 6 FOR_ITER 6 (to 20)
488+
8 STORE_FAST 1 (z)
489+
10 LOAD_DEREF 2 (x)
490+
12 LOAD_FAST 1 (z)
491+
14 BINARY_OP 0 (+)
492+
16 LIST_APPEND 2
493+
18 JUMP_ABSOLUTE 3 (to 6)
494+
>> 20 RETURN_VALUE
492495
""" % (dis_nested_1,
493496
__file__,
494497
_h.__code__.co_firstlineno + 3,
@@ -1007,42 +1010,43 @@ def _prepare_test_cases():
10071010
Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=40, starts_line=None, is_jump_target=False, positions=None),
10081011
]
10091012

1010-
10111013
expected_opinfo_f = [
1012-
Instruction(opname='MAKE_CELL', opcode=135, arg=0, argval='c', argrepr='c', offset=0, starts_line=None, is_jump_target=False, positions=None),
1013-
Instruction(opname='MAKE_CELL', opcode=135, arg=1, argval='d', argrepr='d', offset=2, starts_line=None, is_jump_target=False, positions=None),
1014-
Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval=(5, 6), argrepr='(5, 6)', offset=4, starts_line=3, is_jump_target=False, positions=None),
1015-
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=3, argval='a', argrepr='a', offset=6, starts_line=None, is_jump_target=False, positions=None),
1016-
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=4, argval='b', argrepr='b', offset=8, starts_line=None, is_jump_target=False, positions=None),
1017-
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=0, argval='c', argrepr='c', offset=10, starts_line=None, is_jump_target=False, positions=None),
1018-
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=1, argval='d', argrepr='d', offset=12, starts_line=None, is_jump_target=False, positions=None),
1019-
Instruction(opname='BUILD_TUPLE', opcode=102, arg=4, argval=4, argrepr='', offset=14, starts_line=None, is_jump_target=False, positions=None),
1020-
Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=code_object_inner, argrepr=repr(code_object_inner), offset=16, starts_line=None, is_jump_target=False, positions=None),
1021-
Instruction(opname='MAKE_FUNCTION', opcode=132, arg=9, argval=9, argrepr='defaults, closure', offset=18, starts_line=None, is_jump_target=False, positions=None),
1022-
Instruction(opname='STORE_FAST', opcode=125, arg=2, argval='inner', argrepr='inner', offset=20, starts_line=None, is_jump_target=False, positions=None),
1023-
Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr='print', offset=22, starts_line=5, is_jump_target=False, positions=None),
1024-
Instruction(opname='LOAD_DEREF', opcode=137, arg=3, argval='a', argrepr='a', offset=24, starts_line=None, is_jump_target=False, positions=None),
1025-
Instruction(opname='LOAD_DEREF', opcode=137, arg=4, argval='b', argrepr='b', offset=26, starts_line=None, is_jump_target=False, positions=None),
1026-
Instruction(opname='LOAD_DEREF', opcode=137, arg=0, argval='c', argrepr='c', offset=28, starts_line=None, is_jump_target=False, positions=None),
1027-
Instruction(opname='LOAD_DEREF', opcode=137, arg=1, argval='d', argrepr='d', offset=30, starts_line=None, is_jump_target=False, positions=None),
1028-
Instruction(opname='CALL_FUNCTION', opcode=131, arg=4, argval=4, argrepr='', offset=32, starts_line=None, is_jump_target=False, positions=None),
1029-
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=34, starts_line=None, is_jump_target=False, positions=None),
1030-
Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='inner', argrepr='inner', offset=36, starts_line=6, is_jump_target=False, positions=None),
1031-
Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=38, starts_line=None, is_jump_target=False, positions=None),
1014+
Instruction(opname='COPY_FREE_VARS', opcode=149, arg=2, argval=2, argrepr='', offset=0, starts_line=None, is_jump_target=False, positions=None),
1015+
Instruction(opname='MAKE_CELL', opcode=135, arg=0, argval='c', argrepr='c', offset=2, starts_line=None, is_jump_target=False, positions=None),
1016+
Instruction(opname='MAKE_CELL', opcode=135, arg=1, argval='d', argrepr='d', offset=4, starts_line=None, is_jump_target=False, positions=None),
1017+
Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval=(5, 6), argrepr='(5, 6)', offset=6, starts_line=3, is_jump_target=False, positions=None),
1018+
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=3, argval='a', argrepr='a', offset=8, starts_line=None, is_jump_target=False, positions=None),
1019+
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=4, argval='b', argrepr='b', offset=10, starts_line=None, is_jump_target=False, positions=None),
1020+
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=0, argval='c', argrepr='c', offset=12, starts_line=None, is_jump_target=False, positions=None),
1021+
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=1, argval='d', argrepr='d', offset=14, starts_line=None, is_jump_target=False, positions=None),
1022+
Instruction(opname='BUILD_TUPLE', opcode=102, arg=4, argval=4, argrepr='', offset=16, starts_line=None, is_jump_target=False, positions=None),
1023+
Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=code_object_inner, argrepr=repr(code_object_inner), offset=18, starts_line=None, is_jump_target=False, positions=None),
1024+
Instruction(opname='MAKE_FUNCTION', opcode=132, arg=9, argval=9, argrepr='defaults, closure', offset=20, starts_line=None, is_jump_target=False, positions=None),
1025+
Instruction(opname='STORE_FAST', opcode=125, arg=2, argval='inner', argrepr='inner', offset=22, starts_line=None, is_jump_target=False, positions=None),
1026+
Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr='print', offset=24, starts_line=5, is_jump_target=False, positions=None),
1027+
Instruction(opname='LOAD_DEREF', opcode=137, arg=3, argval='a', argrepr='a', offset=26, starts_line=None, is_jump_target=False, positions=None),
1028+
Instruction(opname='LOAD_DEREF', opcode=137, arg=4, argval='b', argrepr='b', offset=28, starts_line=None, is_jump_target=False, positions=None),
1029+
Instruction(opname='LOAD_DEREF', opcode=137, arg=0, argval='c', argrepr='c', offset=30, starts_line=None, is_jump_target=False, positions=None),
1030+
Instruction(opname='LOAD_DEREF', opcode=137, arg=1, argval='d', argrepr='d', offset=32, starts_line=None, is_jump_target=False, positions=None),
1031+
Instruction(opname='CALL_FUNCTION', opcode=131, arg=4, argval=4, argrepr='', offset=34, starts_line=None, is_jump_target=False, positions=None),
1032+
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=36, starts_line=None, is_jump_target=False, positions=None),
1033+
Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='inner', argrepr='inner', offset=38, starts_line=6, is_jump_target=False, positions=None),
1034+
Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=40, starts_line=None, is_jump_target=False, positions=None),
10321035
]
10331036

10341037
expected_opinfo_inner = [
1035-
Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr='print', offset=0, starts_line=4, is_jump_target=False, positions=None),
1036-
Instruction(opname='LOAD_DEREF', opcode=137, arg=2, argval='a', argrepr='a', offset=2, starts_line=None, is_jump_target=False, positions=None),
1037-
Instruction(opname='LOAD_DEREF', opcode=137, arg=3, argval='b', argrepr='b', offset=4, starts_line=None, is_jump_target=False, positions=None),
1038-
Instruction(opname='LOAD_DEREF', opcode=137, arg=4, argval='c', argrepr='c', offset=6, starts_line=None, is_jump_target=False, positions=None),
1039-
Instruction(opname='LOAD_DEREF', opcode=137, arg=5, argval='d', argrepr='d', offset=8, starts_line=None, is_jump_target=False, positions=None),
1040-
Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='e', argrepr='e', offset=10, starts_line=None, is_jump_target=False, positions=None),
1041-
Instruction(opname='LOAD_FAST', opcode=124, arg=1, argval='f', argrepr='f', offset=12, starts_line=None, is_jump_target=False, positions=None),
1042-
Instruction(opname='CALL_FUNCTION', opcode=131, arg=6, argval=6, argrepr='', offset=14, starts_line=None, is_jump_target=False, positions=None),
1043-
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=16, starts_line=None, is_jump_target=False, positions=None),
1044-
Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=18, starts_line=None, is_jump_target=False, positions=None),
1045-
Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=20, starts_line=None, is_jump_target=False, positions=None),
1038+
Instruction(opname='COPY_FREE_VARS', opcode=149, arg=4, argval=4, argrepr='', offset=0, starts_line=None, is_jump_target=False, positions=None),
1039+
Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr='print', offset=2, starts_line=4, is_jump_target=False, positions=None),
1040+
Instruction(opname='LOAD_DEREF', opcode=137, arg=2, argval='a', argrepr='a', offset=4, starts_line=None, is_jump_target=False, positions=None),
1041+
Instruction(opname='LOAD_DEREF', opcode=137, arg=3, argval='b', argrepr='b', offset=6, starts_line=None, is_jump_target=False, positions=None),
1042+
Instruction(opname='LOAD_DEREF', opcode=137, arg=4, argval='c', argrepr='c', offset=8, starts_line=None, is_jump_target=False, positions=None),
1043+
Instruction(opname='LOAD_DEREF', opcode=137, arg=5, argval='d', argrepr='d', offset=10, starts_line=None, is_jump_target=False, positions=None),
1044+
Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='e', argrepr='e', offset=12, starts_line=None, is_jump_target=False, positions=None),
1045+
Instruction(opname='LOAD_FAST', opcode=124, arg=1, argval='f', argrepr='f', offset=14, starts_line=None, is_jump_target=False, positions=None),
1046+
Instruction(opname='CALL_FUNCTION', opcode=131, arg=6, argval=6, argrepr='', offset=16, starts_line=None, is_jump_target=False, positions=None),
1047+
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=18, starts_line=None, is_jump_target=False, positions=None),
1048+
Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=20, starts_line=None, is_jump_target=False, positions=None),
1049+
Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=22, starts_line=None, is_jump_target=False, positions=None),
10461050
]
10471051

10481052
expected_opinfo_jumpy = [

Objects/frameobject.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,18 @@ _PyFrame_FastToLocalsWithError(InterpreterFrame *frame) {
915915
}
916916
co = frame->f_code;
917917
fast = _PyFrame_GetLocalsArray(frame);
918+
if (frame->f_lasti < 0 && _Py_OPCODE(co->co_firstinstr[0]) == COPY_FREE_VARS) {
919+
/* Free vars have not been initialized -- Do that */
920+
PyCodeObject *co = frame->f_code;
921+
PyObject *closure = frame->f_func->func_closure;
922+
int offset = co->co_nlocals + co->co_nplaincellvars;
923+
for (int i = 0; i < co->co_nfreevars; ++i) {
924+
PyObject *o = PyTuple_GET_ITEM(closure, i);
925+
Py_INCREF(o);
926+
frame->localsplus[offset + i] = o;
927+
}
928+
frame->f_lasti = 0;
929+
}
918930
for (int i = 0; i < co->co_nlocalsplus; i++) {
919931
_PyLocals_Kind kind = _PyLocals_GetKind(co->co_localspluskinds, i);
920932

@@ -934,8 +946,7 @@ _PyFrame_FastToLocalsWithError(InterpreterFrame *frame) {
934946
PyObject *value = fast[i];
935947
if (frame->f_state != FRAME_CLEARED) {
936948
if (kind & CO_FAST_FREE) {
937-
// The cell was set when the frame was created from
938-
// the function's closure.
949+
// The cell was set by COPY_FREE_VARS.
939950
assert(value != NULL && PyCell_Check(value));
940951
value = PyCell_GET(value);
941952
}

Objects/genobject.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult,
187187
}
188188

189189
assert(_PyFrame_IsRunnable(frame));
190-
assert(frame->f_lasti >= 0 || ((unsigned char *)PyBytes_AS_STRING(gen->gi_code->co_code))[0] == GEN_START);
191190
/* Push arg onto the frame's value stack */
192191
result = arg ? arg : Py_None;
193192
Py_INCREF(result);

Objects/typeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8936,7 +8936,7 @@ super_init_without_args(PyFrameObject *f, PyCodeObject *co,
89368936
// "firstarg" is a cell here unless (very unlikely) super()
89378937
// was called from the C-API before the first MAKE_CELL op.
89388938
if (f->f_frame->f_lasti >= 0) {
8939-
assert(_Py_OPCODE(*co->co_firstinstr) == MAKE_CELL);
8939+
assert(_Py_OPCODE(*co->co_firstinstr) == MAKE_CELL || _Py_OPCODE(*co->co_firstinstr) == COPY_FREE_VARS);
89408940
assert(PyCell_Check(firstarg));
89418941
firstarg = PyCell_GET(firstarg);
89428942
}

Python/ceval.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,6 +3029,20 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
30293029
DISPATCH();
30303030
}
30313031

3032+
TARGET(COPY_FREE_VARS) {
3033+
/* Copy closure variables to free variables */
3034+
PyCodeObject *co = frame->f_code;
3035+
PyObject *closure = frame->f_func->func_closure;
3036+
int offset = co->co_nlocals + co->co_nplaincellvars;
3037+
assert(oparg == co->co_nfreevars);
3038+
for (int i = 0; i < oparg; ++i) {
3039+
PyObject *o = PyTuple_GET_ITEM(closure, i);
3040+
Py_INCREF(o);
3041+
frame->localsplus[offset + i] = o;
3042+
}
3043+
DISPATCH();
3044+
}
3045+
30323046
TARGET(BUILD_STRING) {
30333047
PyObject *str;
30343048
PyObject *empty = PyUnicode_New(0, 0);
@@ -5579,12 +5593,12 @@ initialize_locals(PyThreadState *tstate, PyFunctionObject *func,
55795593
goto fail_post_args;
55805594
}
55815595
}
5582-
/* Copy closure variables to free variables */
5583-
for (i = 0; i < co->co_nfreevars; ++i) {
5584-
PyObject *o = PyTuple_GET_ITEM(func->func_closure, i);
5585-
Py_INCREF(o);
5586-
localsplus[co->co_nlocals + co->co_nplaincellvars + i] = o;
5587-
}
5596+
// /* Copy closure variables to free variables */
5597+
// for (i = 0; i < co->co_nfreevars; ++i) {
5598+
// PyObject *o = PyTuple_GET_ITEM(func->func_closure, i);
5599+
// Py_INCREF(o);
5600+
// localsplus[co->co_nlocals + co->co_nplaincellvars + i] = o;
5601+
// }
55885602
return 0;
55895603

55905604
fail_pre_positional:

Python/compile.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,7 @@ stack_effect(int opcode, int oparg, int jump)
11711171

11721172
/* Closures */
11731173
case MAKE_CELL:
1174+
case COPY_FREE_VARS:
11741175
return 0;
11751176
case LOAD_CLOSURE:
11761177
return 1;
@@ -7611,7 +7612,7 @@ insert_instruction(basicblock *block, int pos, struct instr *instr) {
76117612

76127613
static int
76137614
insert_prefix_instructions(struct compiler *c, basicblock *entryblock,
7614-
int *fixed)
7615+
int *fixed, int nfreevars)
76157616
{
76167617

76177618
int flags = compute_code_flags(c);
@@ -7684,6 +7685,22 @@ insert_prefix_instructions(struct compiler *c, basicblock *entryblock,
76847685
}
76857686
}
76867687

7688+
if (nfreevars) {
7689+
struct instr copy_frees = {
7690+
.i_opcode = COPY_FREE_VARS,
7691+
.i_oparg = nfreevars,
7692+
.i_lineno = -1,
7693+
.i_col_offset = -1,
7694+
.i_end_lineno = -1,
7695+
.i_end_col_offset = -1,
7696+
.i_target = NULL,
7697+
};
7698+
if (insert_instruction(entryblock, 0, &copy_frees) < 0) {
7699+
return -1;
7700+
}
7701+
7702+
}
7703+
76877704
return 0;
76887705
}
76897706

@@ -7818,7 +7835,7 @@ assemble(struct compiler *c, int addNone)
78187835
}
78197836

78207837
// This must be called before fix_cell_offsets().
7821-
if (insert_prefix_instructions(c, entryblock, cellfixedoffsets)) {
7838+
if (insert_prefix_instructions(c, entryblock, cellfixedoffsets, nfreevars)) {
78227839
goto error;
78237840
}
78247841

Python/opcode_targets.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/specialize.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ initial_counter_value(void) {
475475
#define SPEC_FAIL_WRONG_NUMBER_ARGUMENTS 9
476476
#define SPEC_FAIL_CO_NOT_OPTIMIZED 10
477477
/* SPEC_FAIL_METHOD defined as 11 above */
478-
#define SPEC_FAIL_FREE_VARS 12
478+
479479
#define SPEC_FAIL_PYCFUNCTION 13
480480
#define SPEC_FAIL_PYCFUNCTION_WITH_KEYWORDS 14
481481
#define SPEC_FAIL_PYCFUNCTION_FAST_WITH_KEYWORDS 15
@@ -1209,10 +1209,6 @@ specialize_py_call(
12091209
SPECIALIZATION_FAIL(CALL_FUNCTION, SPEC_FAIL_CO_NOT_OPTIMIZED);
12101210
return -1;
12111211
}
1212-
if (code->co_nfreevars) {
1213-
SPECIALIZATION_FAIL(CALL_FUNCTION, SPEC_FAIL_FREE_VARS);
1214-
return -1;
1215-
}
12161212
int argcount = code->co_argcount;
12171213
int defcount = func->func_defaults == NULL ? 0 : (int)PyTuple_GET_SIZE(func->func_defaults);
12181214
assert(defcount <= argcount);

0 commit comments

Comments
 (0)