gh-115816: Improve internal symbols API in optimizer (#116028)

- Any `sym_set_...` call that attempts to set conflicting information
  cause the symbol to become `bottom` (contradiction).
- All `sym_is...` and similar calls return false or NULL for `bottom`.
- Everything's tested.
- The tests still pass with `PYTHONUOPSOPTIMIZE=1`.
This commit is contained in:
Guido van Rossum 2024-02-28 09:55:56 -08:00 committed by GitHub
parent f58f8cef74
commit e2a3e4b748
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 190 additions and 66 deletions

View file

@ -27,12 +27,12 @@ extern PyTypeObject _PyUOpExecutor_Type;
extern PyTypeObject _PyUOpOptimizer_Type;
/* Symbols */
/* See explanation in optimizer_symbols.c */
struct _Py_UopsSymbol {
int flags;
PyTypeObject *typ;
// constant propagated value (might be NULL)
PyObject *const_val;
int flags; // 0 bits: Top; 2 or more bits: Bottom
PyTypeObject *typ; // Borrowed reference
PyObject *const_val; // Owned reference (!)
};
// Holds locals, stack, locals, stack ... co_consts (in that order)
@ -92,7 +92,9 @@ extern _Py_UopsSymbol *_Py_uop_sym_new_const(_Py_UOpsContext *ctx, PyObject *con
extern _Py_UopsSymbol *_Py_uop_sym_new_null(_Py_UOpsContext *ctx);
extern bool _Py_uop_sym_matches_type(_Py_UopsSymbol *sym, PyTypeObject *typ);
extern void _Py_uop_sym_set_null(_Py_UopsSymbol *sym);
extern void _Py_uop_sym_set_type(_Py_UopsSymbol *sym, PyTypeObject *tp);
extern void _Py_uop_sym_set_non_null(_Py_UopsSymbol *sym);
extern void _Py_uop_sym_set_type(_Py_UopsSymbol *sym, PyTypeObject *typ);
extern void _Py_uop_sym_set_const(_Py_UopsSymbol *sym, PyObject *const_val);
extern int _Py_uop_abstractcontext_init(_Py_UOpsContext *ctx);
extern void _Py_uop_abstractcontext_fini(_Py_UOpsContext *ctx);