Skip to content

Commit b0cf315

Browse files
cdce8px612skm
authored andcommitted
Update capi_version for mypyc tests to 3.8 (python#18341)
This PR updates the `capi_version` used for mypyc tests to `3.8` (mypy / mypyc requires `>=3.9`). Test data updates done with `--update-data`. For Python 3.8+ mypyc uses `_PyObject_Vectorcall` instead of `PyObject_CallFunctionObjArgs` and `PyObject_Call` where ever possible. Will remove the now unnecessary `use_vectorcall` check in a followup. https://github.com/python/mypy/blob/aa0b6f0288e6a511b750f7fe8f49a0e321362105/mypyc/common.py#L103-L105
1 parent 8794cc0 commit b0cf315

18 files changed

+1218
-853
lines changed

mypyc/lib-rt/pythonsupport.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ update_bases(PyObject *bases)
6969
}
7070
continue;
7171
}
72-
new_base = _PyObject_Vectorcall(meth, stack, 1, NULL);
72+
new_base = PyObject_Vectorcall(meth, stack, 1, NULL);
7373
Py_DECREF(meth);
7474
if (!new_base) {
7575
goto error;
@@ -118,7 +118,7 @@ init_subclass(PyTypeObject *type, PyObject *kwds)
118118
PyObject *super, *func, *result;
119119
PyObject *args[2] = {(PyObject *)type, (PyObject *)type};
120120

121-
super = _PyObject_Vectorcall((PyObject *)&PySuper_Type, args, 2, NULL);
121+
super = PyObject_Vectorcall((PyObject *)&PySuper_Type, args, 2, NULL);
122122
if (super == NULL) {
123123
return -1;
124124
}

mypyc/primitives/generic_ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@
281281
object_rprimitive,
282282
], # Keyword arg names tuple (or NULL)
283283
return_type=object_rprimitive,
284-
c_function_name="_PyObject_Vectorcall",
284+
c_function_name="PyObject_Vectorcall",
285285
error_kind=ERR_MAGIC,
286286
)
287287

mypyc/test-data/exceptions.test

+63-41
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,20 @@ def g():
163163
r5 :: str
164164
r6 :: object
165165
r7 :: str
166-
r8, r9 :: object
167-
r10 :: bit
168-
r11 :: None
166+
r8 :: object
167+
r9 :: object[1]
168+
r10 :: object_ptr
169+
r11 :: object
170+
r12 :: bit
171+
r13 :: None
169172
L0:
170173
L1:
171174
r0 = builtins :: module
172175
r1 = 'object'
173176
r2 = CPyObject_GetAttr(r0, r1)
174177
if is_error(r2) goto L3 (error at g:3) else goto L2
175178
L2:
176-
r3 = PyObject_CallFunctionObjArgs(r2, 0)
179+
r3 = PyObject_Vectorcall(r2, 0, 0, 0)
177180
dec_ref r2
178181
if is_error(r3) goto L3 (error at g:3) else goto L10
179182
L3:
@@ -184,30 +187,32 @@ L3:
184187
r8 = CPyObject_GetAttr(r6, r7)
185188
if is_error(r8) goto L6 (error at g:5) else goto L4
186189
L4:
187-
r9 = PyObject_CallFunctionObjArgs(r8, r5, 0)
190+
r9 = [r5]
191+
r10 = load_address r9
192+
r11 = PyObject_Vectorcall(r8, r10, 1, 0)
188193
dec_ref r8
189-
if is_error(r9) goto L6 (error at g:5) else goto L11
194+
if is_error(r11) goto L6 (error at g:5) else goto L11
190195
L5:
191196
CPy_RestoreExcInfo(r4)
192197
dec_ref r4
193198
goto L8
194199
L6:
195200
CPy_RestoreExcInfo(r4)
196201
dec_ref r4
197-
r10 = CPy_KeepPropagating()
198-
if not r10 goto L9 else goto L7 :: bool
202+
r12 = CPy_KeepPropagating()
203+
if not r12 goto L9 else goto L7 :: bool
199204
L7:
200205
unreachable
201206
L8:
202207
return 1
203208
L9:
204-
r11 = <error> :: None
205-
return r11
209+
r13 = <error> :: None
210+
return r13
206211
L10:
207212
dec_ref r3
208213
goto L8
209214
L11:
210-
dec_ref r9
215+
dec_ref r11
211216
goto L5
212217

213218
[case testGenopsTryFinally]
@@ -229,17 +234,20 @@ def a():
229234
r10 :: str
230235
r11 :: object
231236
r12 :: str
232-
r13, r14 :: object
233-
r15 :: bit
234-
r16 :: str
237+
r13 :: object
238+
r14 :: object[1]
239+
r15 :: object_ptr
240+
r16 :: object
241+
r17 :: bit
242+
r18 :: str
235243
L0:
236244
L1:
237245
r0 = builtins :: module
238246
r1 = 'print'
239247
r2 = CPyObject_GetAttr(r0, r1)
240248
if is_error(r2) goto L5 (error at a:3) else goto L2
241249
L2:
242-
r3 = PyObject_CallFunctionObjArgs(r2, 0)
250+
r3 = PyObject_Vectorcall(r2, 0, 0, 0)
243251
dec_ref r2
244252
if is_error(r3) goto L5 (error at a:3) else goto L19
245253
L3:
@@ -262,9 +270,11 @@ L6:
262270
r13 = CPyObject_GetAttr(r11, r12)
263271
if is_error(r13) goto L20 (error at a:6) else goto L7
264272
L7:
265-
r14 = PyObject_CallFunctionObjArgs(r13, r10, 0)
273+
r14 = [r10]
274+
r15 = load_address r14
275+
r16 = PyObject_Vectorcall(r13, r15, 1, 0)
266276
dec_ref r13
267-
if is_error(r14) goto L20 (error at a:6) else goto L21
277+
if is_error(r16) goto L20 (error at a:6) else goto L21
268278
L8:
269279
if is_error(r7) goto L11 else goto L22
270280
L9:
@@ -282,23 +292,23 @@ L14:
282292
CPy_RestoreExcInfo(r7)
283293
xdec_ref r7
284294
L15:
285-
r15 = CPy_KeepPropagating()
286-
if not r15 goto L18 else goto L16 :: bool
295+
r17 = CPy_KeepPropagating()
296+
if not r17 goto L18 else goto L16 :: bool
287297
L16:
288298
unreachable
289299
L17:
290300
unreachable
291301
L18:
292-
r16 = <error> :: str
293-
return r16
302+
r18 = <error> :: str
303+
return r18
294304
L19:
295305
dec_ref r3
296306
goto L3
297307
L20:
298308
xdec_ref r5
299309
goto L13
300310
L21:
301-
dec_ref r14
311+
dec_ref r16
302312
goto L8
303313
L22:
304314
xdec_ref r5
@@ -446,59 +456,71 @@ def f(b):
446456
r6 :: str
447457
r7 :: object
448458
r8 :: bool
449-
r9 :: object
450-
r10 :: None
459+
r9 :: object[1]
460+
r10 :: object_ptr
461+
r11 :: object
462+
r12 :: bool
463+
r13 :: None
451464
L0:
452465
r0 = <error> :: str
453466
v = r0
454467
r1 = 'a'
455468
inc_ref r1
456469
u = r1
457470
L1:
458-
if b goto L10 else goto L11 :: bool
471+
if b goto L13 else goto L14 :: bool
459472
L2:
460473
r2 = 'b'
461474
inc_ref r2
462475
v = r2
463476
r3 = v == u
464477
r4 = r3 ^ 1
465-
if r4 goto L11 else goto L1 :: bool
478+
if r4 goto L14 else goto L1 :: bool
466479
L3:
467480
r5 = builtins :: module
468481
r6 = 'print'
469482
r7 = CPyObject_GetAttr(r5, r6)
470-
if is_error(r7) goto L12 (error at f:7) else goto L4
483+
if is_error(r7) goto L15 (error at f:7) else goto L4
471484
L4:
472-
if is_error(v) goto L13 else goto L7
485+
if is_error(v) goto L16 else goto L7
473486
L5:
474487
r8 = raise UnboundLocalError('local variable "v" referenced before assignment')
475-
if not r8 goto L9 (error at f:7) else goto L6 :: bool
488+
if not r8 goto L12 (error at f:-1) else goto L6 :: bool
476489
L6:
477490
unreachable
478491
L7:
479-
r9 = PyObject_CallFunctionObjArgs(r7, v, 0)
492+
r9 = [v]
493+
r10 = load_address r9
494+
r11 = PyObject_Vectorcall(r7, r10, 1, 0)
480495
dec_ref r7
481-
xdec_ref v
482-
if is_error(r9) goto L9 (error at f:7) else goto L14
496+
if is_error(r11) goto L15 (error at f:7) else goto L17
483497
L8:
484-
return 1
498+
if is_error(v) goto L9 else goto L11
485499
L9:
486-
r10 = <error> :: None
487-
return r10
500+
r12 = raise UnboundLocalError('local variable "v" referenced before assignment')
501+
if not r12 goto L12 (error at f:-1) else goto L10 :: bool
488502
L10:
503+
unreachable
504+
L11:
505+
xdec_ref v
506+
return 1
507+
L12:
508+
r13 = <error> :: None
509+
return r13
510+
L13:
489511
xdec_ref v
490512
goto L2
491-
L11:
513+
L14:
492514
dec_ref u
493515
goto L3
494-
L12:
516+
L15:
495517
xdec_ref v
496-
goto L9
497-
L13:
518+
goto L12
519+
L16:
498520
dec_ref r7
499521
goto L5
500-
L14:
501-
dec_ref r9
522+
L17:
523+
dec_ref r11
502524
goto L8
503525

504526
[case testExceptionWithOverlappingErrorValue]

0 commit comments

Comments
 (0)