Skip to content

Commit

Permalink
Add bottom checks, first approximation
Browse files Browse the repository at this point in the history
  • Loading branch information
gvanrossum committed Feb 29, 2024
1 parent f4e1382 commit 23d8a15
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 7 deletions.
10 changes: 10 additions & 0 deletions Python/optimizer_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ optimize_uops(
_PyUOpName(opcode),
oparg);
switch (opcode) {

#include "optimizer_cases.c.h"

default:
Expand All @@ -363,6 +364,15 @@ optimize_uops(
DPRINTF(1, "Encountered error in abstract interpreter\n");
_Py_uop_abstractcontext_fini(ctx);
return 0;

hit_bottom:
// Attempted to push a "bottom" (contradition) symbol onto the stack.
// This means that the abstract interpreter has hit unreachable code.
// We *could* generate an _EXIT_TRACE or _FATAL_ERROR here, but it's
// simpler to just admit failure and not create the executor.
DPRINTF(1, "Hit bottom in abstract interpreter\n");
_Py_uop_abstractcontext_fini(ctx);
return 0;
}


Expand Down
143 changes: 138 additions & 5 deletions Python/optimizer_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Tools/cases_generator/optimizer_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def write_uop(
if not var.peek or is_override:
out.emit(stack.push(var))
out.start_line()
stack.flush(out, cast_type="_Py_UopsSymbol *")
stack.flush(out, cast_type="_Py_UopsSymbol *", add_bottom_check=bool(override))
except SizeMismatch as ex:
raise analysis_error(ex.args[0], uop.body[0])

Expand Down
Loading

0 comments on commit 23d8a15

Please sign in to comment.