diff options
author | Guido van Rossum <guido@python.org> | 2024-02-29 18:55:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-29 18:55:29 (GMT) |
commit | 0656509033948780e6703391daca773c779041f7 (patch) | |
tree | f75c2c923b52ee8367c9f033cb911ac8dc99bfca /Python/optimizer_symbols.c | |
parent | 3b6f4cadf19e6a4edd2cbbbc96a0a4024b395648 (diff) | |
download | cpython-0656509033948780e6703391daca773c779041f7.zip cpython-0656509033948780e6703391daca773c779041f7.tar.gz cpython-0656509033948780e6703391daca773c779041f7.tar.bz2 |
gh-116088: Insert bottom checks after all sym_set_...() calls (#116089)
This changes the `sym_set_...()` functions to return a `bool` which is `false`
when the symbol is `bottom` after the operation.
All calls to such functions now check this result and go to `hit_bottom`,
a special error label that prints a different message and then reports
that it wasn't able to optimize the trace. No executor will be produced
in this case.
Diffstat (limited to 'Python/optimizer_symbols.c')
-rw-r--r-- | Python/optimizer_symbols.c | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/Python/optimizer_symbols.c b/Python/optimizer_symbols.c index a529cc2..5c3ec2b 100644 --- a/Python/optimizer_symbols.c +++ b/Python/optimizer_symbols.c @@ -113,60 +113,68 @@ _Py_uop_sym_get_const(_Py_UopsSymbol *sym) return sym->const_val; } -void +bool _Py_uop_sym_set_type(_Py_UopsSymbol *sym, PyTypeObject *typ) { assert(typ != NULL && PyType_Check(typ)); if (sym->flags & IS_NULL) { sym_set_bottom(sym); - return; + return false; } if (sym->typ != NULL) { if (sym->typ != typ) { sym_set_bottom(sym); + return false; } - return; } - sym_set_flag(sym, NOT_NULL); - sym->typ = typ; + else { + sym_set_flag(sym, NOT_NULL); + sym->typ = typ; + } + return true; } -void +bool _Py_uop_sym_set_const(_Py_UopsSymbol *sym, PyObject *const_val) { assert(const_val != NULL); if (sym->flags & IS_NULL) { sym_set_bottom(sym); - return; + return false; } PyTypeObject *typ = Py_TYPE(const_val); if (sym->typ != NULL && sym->typ != typ) { sym_set_bottom(sym); - return; + return false; } if (sym->const_val != NULL) { if (sym->const_val != const_val) { // TODO: What if they're equal? sym_set_bottom(sym); + return false; } - return; } - sym_set_flag(sym, NOT_NULL); - sym->typ = typ; - sym->const_val = Py_NewRef(const_val); + else { + sym_set_flag(sym, NOT_NULL); + sym->typ = typ; + sym->const_val = Py_NewRef(const_val); + } + return true; } -void +bool _Py_uop_sym_set_null(_Py_UopsSymbol *sym) { sym_set_flag(sym, IS_NULL); + return !_Py_uop_sym_is_bottom(sym); } -void +bool _Py_uop_sym_set_non_null(_Py_UopsSymbol *sym) { sym_set_flag(sym, NOT_NULL); + return !_Py_uop_sym_is_bottom(sym); } |