Skip to content

Commit a3054cd

Browse files
committed
Address review comments
1 parent 47a9764 commit a3054cd

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

Python/optimizer_bytecodes.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,7 +1643,7 @@ dummy_func(void) {
16431643
op(_GUARD_IP__PUSH_FRAME, (ip/4 --)) {
16441644
stack_pointer = sym_set_stack_depth(this_instr->operand1, stack_pointer);
16451645
// TO DO
1646-
// Normal function calls to a known functions
1646+
// Normal function calls to known functions
16471647
// do not need an IP guard.
16481648
}
16491649

@@ -1663,23 +1663,20 @@ dummy_func(void) {
16631663
REPLACE_OP(this_instr, _NOP, 0, 0);
16641664
}
16651665
stack_pointer = sym_set_stack_depth(this_instr->operand1, stack_pointer);
1666-
assert(stack_pointer != NULL);
16671666
}
16681667

16691668
op(_GUARD_IP_RETURN_VALUE, (ip/4 --)) {
16701669
if (ctx->frame->caller) {
16711670
REPLACE_OP(this_instr, _NOP, 0, 0);
16721671
}
16731672
stack_pointer = sym_set_stack_depth(this_instr->operand1, stack_pointer);
1674-
assert(stack_pointer != NULL);
16751673
}
16761674

16771675
op(_GUARD_IP_RETURN_GENERATOR, (ip/4 --)) {
16781676
if (ctx->frame->caller) {
16791677
REPLACE_OP(this_instr, _NOP, 0, 0);
16801678
}
16811679
stack_pointer = sym_set_stack_depth(this_instr->operand1, stack_pointer);
1682-
assert(stack_pointer != NULL);
16831680
}
16841681

16851682

Python/optimizer_cases.c.h

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

Python/optimizer_symbols.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,9 +1371,14 @@ _Py_uop_sym_set_stack_depth(JitOptContext *ctx, int stack_depth, JitOptRef *curr
13711371
JitOptRef *new_stack_pointer = frame->stack + stack_depth;
13721372
if (current_sp > new_stack_pointer) {
13731373
ctx->done = true;
1374-
ctx->contradiction = "inconsistent recorded stack depths";
1375-
return NULL;
1376-
}
1374+
ctx->contradiction = true;
1375+
return NULL;
1376+
}
1377+
if (new_stack_pointer > ctx->stack.end) {
1378+
ctx->done = true;
1379+
ctx->out_of_space = true;
1380+
return NULL;
1381+
}
13771382
int delta = (int)(new_stack_pointer - current_sp);
13781383
assert(delta >= 0);
13791384
if (delta) {
@@ -1406,15 +1411,18 @@ _Py_uop_abstractcontext_fini(JitOptContext *ctx)
14061411
}
14071412
}
14081413

1414+
// Leave a bit of space to push values before checking that there is space for a new frame
1415+
#define STACK_HEADROOM 2
1416+
14091417
void
14101418
_Py_uop_abstractcontext_init(JitOptContext *ctx, _PyBloomFilter *dependencies)
14111419
{
14121420
static_assert(sizeof(JitOptSymbol) <= 3 * sizeof(uint64_t), "JitOptSymbol has grown");
14131421

14141422
ctx->stack.used = ctx->stack_array;
1415-
ctx->stack.end = &ctx->stack_array[ABSTRACT_INTERP_STACK_SIZE];
1423+
ctx->stack.end = &ctx->stack_array[ABSTRACT_INTERP_STACK_SIZE-STACK_HEADROOM];
14161424
ctx->locals.used = ctx->locals_array;
1417-
ctx->locals.end = &ctx->locals_array[ABSTRACT_INTERP_LOCALS_SIZE];
1425+
ctx->locals.end = &ctx->locals_array[ABSTRACT_INTERP_LOCALS_SIZE-STACK_HEADROOM];
14181426
#ifdef Py_DEBUG // Aids debugging a little. There should never be NULL in the abstract interpreter.
14191427
for (int i = 0 ; i < ABSTRACT_INTERP_STACK_SIZE; i++) {
14201428
ctx->stack_array[i] = PyJitRef_NULL;

0 commit comments

Comments
 (0)