@@ -297,20 +297,6 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer,
297
297
INST->oparg = ARG; \
298
298
INST->operand = OPERAND;
299
299
300
- #define OUT_OF_SPACE_IF_NULL (EXPR ) \
301
- do { \
302
- if ((EXPR) == NULL) { \
303
- goto out_of_space; \
304
- } \
305
- } while (0);
306
-
307
- #define _LOAD_ATTR_NOT_NULL \
308
- do { \
309
- OUT_OF_SPACE_IF_NULL(attr = _Py_uop_sym_new_not_null(ctx)); \
310
- OUT_OF_SPACE_IF_NULL(null = _Py_uop_sym_new_null(ctx)); \
311
- } while (0);
312
-
313
-
314
300
/* Shortened forms for convenience, used in optimizer_bytecodes.c */
315
301
#define sym_is_not_null _Py_uop_sym_is_not_null
316
302
#define sym_is_const _Py_uop_sym_is_const
@@ -324,10 +310,10 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer,
324
310
#define sym_has_type _Py_uop_sym_has_type
325
311
#define sym_get_type _Py_uop_sym_get_type
326
312
#define sym_matches_type _Py_uop_sym_matches_type
327
- #define sym_set_null _Py_uop_sym_set_null
328
- #define sym_set_non_null _Py_uop_sym_set_non_null
329
- #define sym_set_type _Py_uop_sym_set_type
330
- #define sym_set_const _Py_uop_sym_set_const
313
+ #define sym_set_null ( SYM ) _Py_uop_sym_set_null(ctx, SYM)
314
+ #define sym_set_non_null ( SYM ) _Py_uop_sym_set_non_null(ctx, SYM)
315
+ #define sym_set_type ( SYM , TYPE ) _Py_uop_sym_set_type(ctx, SYM, TYPE)
316
+ #define sym_set_const ( SYM , CNST ) _Py_uop_sym_set_const(ctx, SYM, CNST)
331
317
#define sym_is_bottom _Py_uop_sym_is_bottom
332
318
#define sym_truthiness _Py_uop_sym_truthiness
333
319
#define frame_new _Py_uop_frame_new
@@ -408,18 +394,20 @@ optimize_uops(
408
394
_PyUOpInstruction * first_valid_check_stack = NULL ;
409
395
_PyUOpInstruction * corresponding_check_stack = NULL ;
410
396
411
- if (_Py_uop_abstractcontext_init (ctx ) < 0 ) {
412
- goto out_of_space ;
413
- }
397
+ _Py_uop_abstractcontext_init (ctx );
414
398
_Py_UOpsAbstractFrame * frame = _Py_uop_frame_new (ctx , co , ctx -> n_consumed , 0 , curr_stacklen );
415
399
if (frame == NULL ) {
416
400
return -1 ;
417
401
}
418
402
ctx -> curr_frame_depth ++ ;
419
403
ctx -> frame = frame ;
404
+ ctx -> done = false;
405
+ ctx -> out_of_space = false;
406
+ ctx -> contradiction = false;
420
407
421
408
_PyUOpInstruction * this_instr = NULL ;
422
- for (int i = 0 ; i < trace_len ; i ++ ) {
409
+ for (int i = 0 ; !ctx -> done ; i ++ ) {
410
+ assert (i < trace_len );
423
411
this_instr = & trace [i ];
424
412
425
413
int oparg = this_instr -> oparg ;
@@ -447,32 +435,22 @@ optimize_uops(
447
435
ctx -> frame -> stack_pointer = stack_pointer ;
448
436
assert (STACK_LEVEL () >= 0 );
449
437
}
450
- Py_UNREACHABLE ();
451
-
452
- out_of_space :
453
- DPRINTF (3 , "\n" );
454
- DPRINTF (1 , "Out of space in abstract interpreter\n" );
455
- goto done ;
456
- error :
457
- DPRINTF (3 , "\n" );
458
- DPRINTF (1 , "Encountered error in abstract interpreter\n" );
459
- if (opcode <= MAX_UOP_ID ) {
460
- OPT_ERROR_IN_OPCODE (opcode );
438
+ if (ctx -> out_of_space ) {
439
+ DPRINTF (3 , "\n" );
440
+ DPRINTF (1 , "Out of space in abstract interpreter\n" );
441
+ }
442
+ if (ctx -> contradiction ) {
443
+ // Attempted to push a "bottom" (contradiction) symbol onto the stack.
444
+ // This means that the abstract interpreter has hit unreachable code.
445
+ // We *could* generate an _EXIT_TRACE or _FATAL_ERROR here, but hitting
446
+ // bottom indicates type instability, so we are probably better off
447
+ // retrying later.
448
+ DPRINTF (3 , "\n" );
449
+ DPRINTF (1 , "Hit bottom in abstract interpreter\n" );
450
+ _Py_uop_abstractcontext_fini (ctx );
451
+ return 0 ;
461
452
}
462
- _Py_uop_abstractcontext_fini (ctx );
463
- return -1 ;
464
453
465
- hit_bottom :
466
- // Attempted to push a "bottom" (contradition) symbol onto the stack.
467
- // This means that the abstract interpreter has hit unreachable code.
468
- // We *could* generate an _EXIT_TRACE or _FATAL_ERROR here, but hitting
469
- // bottom indicates type instability, so we are probably better off
470
- // retrying later.
471
- DPRINTF (3 , "\n" );
472
- DPRINTF (1 , "Hit bottom in abstract interpreter\n" );
473
- _Py_uop_abstractcontext_fini (ctx );
474
- return 0 ;
475
- done :
476
454
/* Either reached the end or cannot optimize further, but there
477
455
* would be no benefit in retrying later */
478
456
_Py_uop_abstractcontext_fini (ctx );
@@ -485,6 +463,16 @@ optimize_uops(
485
463
first_valid_check_stack -> operand = max_space ;
486
464
}
487
465
return trace_len ;
466
+
467
+ error :
468
+ DPRINTF (3 , "\n" );
469
+ DPRINTF (1 , "Encountered error in abstract interpreter\n" );
470
+ if (opcode <= MAX_UOP_ID ) {
471
+ OPT_ERROR_IN_OPCODE (opcode );
472
+ }
473
+ _Py_uop_abstractcontext_fini (ctx );
474
+ return -1 ;
475
+
488
476
}
489
477
490
478
0 commit comments