Get rid of ERROR_IF's "label" parameter (GH-132654)

This commit is contained in:
Brandt Bucher 2025-04-29 17:21:53 -07:00 committed by GitHub
parent b329096cfb
commit 732d1b0241
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 155 additions and 162 deletions

View file

@ -543,7 +543,6 @@ def tier_variable(node: parser.CodeDef) -> int | None:
def has_error_with_pop(op: parser.CodeDef) -> bool:
return (
variable_used(op, "ERROR_IF")
or variable_used(op, "pop_1_error")
or variable_used(op, "exception_unwind")
)
@ -551,7 +550,6 @@ def has_error_with_pop(op: parser.CodeDef) -> bool:
def has_error_without_pop(op: parser.CodeDef) -> bool:
return (
variable_used(op, "ERROR_NO_POP")
or variable_used(op, "pop_1_error")
or variable_used(op, "exception_unwind")
)

View file

@ -170,12 +170,12 @@ class Emitter:
exit_if = deopt_if
def goto_error(self, offset: int, label: str, storage: Storage) -> str:
def goto_error(self, offset: int, storage: Storage) -> str:
if offset > 0:
return f"JUMP_TO_LABEL(pop_{offset}_{label});"
return f"JUMP_TO_LABEL(pop_{offset}_error);"
if offset < 0:
storage.copy().flush(self.out)
return f"JUMP_TO_LABEL({label});"
return f"JUMP_TO_LABEL(error);"
def error_if(
self,
@ -191,17 +191,13 @@ class Emitter:
unconditional = always_true(first_tkn)
if unconditional:
next(tkn_iter)
comma = next(tkn_iter)
if comma.kind != "COMMA":
raise analysis_error(f"Expected comma, got '{comma.text}'", comma)
next(tkn_iter) # RPAREN
self.out.start_line()
else:
self.out.emit_at("if ", tkn)
self.emit(lparen)
emit_to(self.out, tkn_iter, "COMMA")
emit_to(self.out, tkn_iter, "RPAREN")
self.out.emit(") {\n")
label = next(tkn_iter).text
next(tkn_iter) # RPAREN
next(tkn_iter) # Semi colon
storage.clear_inputs("at ERROR_IF")
@ -210,7 +206,7 @@ class Emitter:
offset = int(c_offset)
except ValueError:
offset = -1
self.out.emit(self.goto_error(offset, label, storage))
self.out.emit(self.goto_error(offset, storage))
self.out.emit("\n")
if not unconditional:
self.out.emit("}\n")
@ -227,7 +223,7 @@ class Emitter:
next(tkn_iter) # LPAREN
next(tkn_iter) # RPAREN
next(tkn_iter) # Semi colon
self.out.emit_at(self.goto_error(0, "error", storage), tkn)
self.out.emit_at(self.goto_error(0, storage), tkn)
return False
def decref_inputs(

View file

@ -184,7 +184,7 @@ part of the DSL.
Those include:
* `DEOPT_IF(cond, instruction)`. Deoptimize if `cond` is met.
* `ERROR_IF(cond, label)`. Jump to error handler at `label` if `cond` is true.
* `ERROR_IF(cond)`. Jump to error handler if `cond` is true.
* `DECREF_INPUTS()`. Generate `Py_DECREF()` calls for the input stack effects.
* `SYNC_SP()`. Synchronizes the physical stack pointer with the stack effects.
* `INSTRUCTION_SIZE`. Replaced with the size of the instruction which is equal
@ -209,7 +209,7 @@ These requirements result in the following constraints on the use of
2. Before the first `ERROR_IF`, all input values must be `DECREF`ed,
and no objects may be allocated or `INCREF`ed, with the exception
of attempting to create an object and checking for success using
`ERROR_IF(result == NULL, label)`. (TODO: Unclear what to do with
`ERROR_IF(result == NULL)`. (TODO: Unclear what to do with
intermediate results.)
3. No `DEOPT_IF` may follow an `ERROR_IF` in the same block.
@ -221,14 +221,14 @@ two idioms are valid:
- Use `goto error`.
- Use a block containing the appropriate `DECREF` calls ending in
`ERROR_IF(true, error)`.
`ERROR_IF(true)`.
An example of the latter would be:
```cc
res = PyObject_Add(left, right);
if (res == NULL) {
DECREF_INPUTS();
ERROR_IF(true, error);
ERROR_IF(true);
}
```
@ -346,7 +346,7 @@ For explanations see "Generating the interpreter" below.
```C
inst ( BUILD_TUPLE, (items[oparg] -- tuple) ) {
tuple = _PyTuple_FromArraySteal(items, oparg);
ERROR_IF(tuple == NULL, error);
ERROR_IF(tuple == NULL);
}
```
```C

View file

@ -64,7 +64,7 @@ class Tier2Emitter(Emitter):
super().__init__(out, labels)
self._replacers["oparg"] = self.oparg
def goto_error(self, offset: int, label: str, storage: Storage) -> str:
def goto_error(self, offset: int, storage: Storage) -> str:
# To do: Add jump targets for popping values.
if offset != 0:
storage.copy().flush(self.out)