8000 GH-128682: Account for escapes in `DECREF_INPUTS` by markshannon · Pull Request #129953 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-128682: Account for escapes in DECREF_INPUTS #129953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Refactor cast_type
  • Loading branch information
markshannon committed Feb 4, 2025
commit 8fc556228f588401fdc08c271ad1cf91b6fcb6a0
4 changes: 4 additions & 0 deletions Tools/cases_generator/generators_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ def decref_inputs(
self.out.emit(f"{close}({var.name});\n")
for input in storage.inputs:
input.defined = False
#try:
#storage.close_inputs(self.out)
#except StackError as ex:
#raise analysis_error(ex.args[0], tkn)
return True

def kill_inputs(
Expand Down
6 changes: 3 additions & 3 deletions Tools/cases_generator/optimizer_generator.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ def write_uop(
var.defined = False
storage = emitter.emit_tokens(override, storage, None)
out.start_line()
storage.flush(out, cast_type="JitOptSymbol *")
storage.flush(out)
else:
emit_default(out, uop, stack)
out.start_line()
stack.flush(out, cast_type="JitOptSymbol *")
stack.flush(out)
except StackError as ex:
raise analysis_error(ex.args[0], prototype.body[0]) # from None

Expand Down Expand Up @@ -201,7 +201,7 @@ def generate_abstract_interpreter(
declare_variables(override, out, skip_inputs=False)
else:
declare_variables(uop, out, skip_inputs=True)
stack = Stack(False)
stack = Stack(extract_bits=False, cast_type="JitOptSymbol *")
write_uop(override, uop, out, stack, debug, skip_inputs=(override is None))
out.start_line()
out.emit("break;\n")
Expand Down
20 changes: 10 additions & 10 deletions Tools/cases_generator/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,13 @@ def array_or_scalar(var: StackItem | Local) -> str:
return "array" if var.is_array() else "scalar"

class Stack:
def __init__(self, extract_bits: bool=True) -> None:
def __init__(self, extract_bits: bool=True, cast_type: str = "uintptr_t") -> None:
self.top_offset = StackOffset.empty()
self.base_offset = StackOffset.empty()
self.variables: list[Local] = []
self.defined: set[str] = set()
self.extract_bits = extract_bits
self.cast_type = cast_type

def pop(self, var: StackItem) -> tuple[str, Local]:
self.top_offset.pop(var)
Expand Down Expand Up @@ -298,8 +299,8 @@ def _do_emit(
out: CWriter,
var: StackItem,
base_offset: StackOffset,
cast_type: str = "uintptr_t",
extract_bits: bool = True,
cast_type: str,
extract_bits: bool,
) -> None:
cast = f"({cast_type})" if var.type else ""
bits = ".bits" if cast and extract_bits else ""
Expand All @@ -315,17 +316,15 @@ def _adjust_stack_pointer(self, out: CWriter, number: str) -> None:
out.emit(f"stack_pointer += {number};\n")
out.emit("assert(WITHIN_STACK_BOUNDS());\n")

def flush(
self, out: CWriter, cast_type: str = "uintptr_t"
) -> None:
def flush(self, out: CWriter) -> None:
out.start_line()
var_offset = self.base_offset.copy()
for var in self.variables:
if (
var.defined and
not var.in_memory
):
Stack._do_emit(out, var.item, var_offset, cast_type, self.extract_bits)
Stack._do_emit(out, var.item, var_offset, self.cast_type, self.extract_bits)
var.in_memory = True
var_offset.push(var.item)
number = self.top_offset.to_c()
Expand All @@ -347,7 +346,7 @@ def as_comment(self) -> str:
)

def copy(self) -> "Stack":
other = Stack(self.extract_bits)
other = Stack(self.extract_bits, self.cast_type)
other.top_offset = self.top_offset.copy()
other.base_offset = self.base_offset.copy()
other.variables = [var.copy() for var in self.variables]
Expand Down Expand Up @@ -508,10 +507,10 @@ def locals_cached(self) -> bool:
return True
return False

def flush(self, out: CWriter, cast_type: str = "uintptr_t") -> None:
def flush(self, out: CWriter) -> None:
self.clear_dead_inputs()
self._push_defined_outputs()
self.stack.flush(out, cast_type)
self.stack.flush(out)

def save(self, out: CWriter) -> None:
assert self.spilled >= 0
Expand Down Expand Up @@ -637,3 +636,4 @@ def as_comment(self) -> str:
outputs = ", ".join([var.compact_str() for var in self.outputs])
peeks = ", ".join([var.name for var in self.peeks])
return f"{stack_comment[:-2]}{next_line}inputs: {inputs}{next_line}outputs: {outputs}{next_line}peeks: {peeks} */"

0