Skip to content

Commit

Permalink
Tidy up some ceval export name inconsistencies
Browse files Browse the repository at this point in the history
Summary: These existing exported functions should use `Cix_` naming for consistency with the bigger interpreter extraction above.

Reviewed By: alexmalyshev

Differential Revision: D51552735

fbshipit-source-id: 212c111ca30371f009b34e957e93f94a6c4d4791
  • Loading branch information
jbower-fb authored and facebook-github-bot committed Nov 30, 2023
1 parent 734cc3d commit d07bf88
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 46 deletions.
4 changes: 2 additions & 2 deletions CinderX/Jit/codegen/gen_asm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ bool canLoadStoreAddr(asmjit::x86::Gp reg, int64_t addr) {

static void raiseUnboundLocalError(BorrowedRef<> name) {
// name is converted into a `char*` in format_exc_check_arg
format_exc_check_arg(
Cix_format_exc_check_arg(
_PyThreadState_GET(),
PyExc_UnboundLocalError,
"local variable '%.200s' referenced before assignment",
Expand All @@ -1493,7 +1493,7 @@ static void raiseUnboundLocalError(BorrowedRef<> name) {

static void raiseUnboundFreevarError(BorrowedRef<> name) {
// name is converted into a `char*` in format_exc_check_arg
format_exc_check_arg(
Cix_format_exc_check_arg(
_PyThreadState_GET(),
PyExc_NameError,
"free variable '%.200s' referenced before assignment in enclosing scope",
Expand Down
6 changes: 3 additions & 3 deletions CinderX/Jit/jit_rt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ JITRT_LoadGlobal(PyObject* globals, PyObject* builtins, PyObject* name) {
_PyDict_LoadGlobal((PyDictObject*)globals, (PyDictObject*)builtins, name);
if ((result == NULL) && !PyErr_Occurred()) {
// name is converted to a `char*` by format_exc_check_arg
format_exc_check_arg(
Cix_format_exc_check_arg(
_PyThreadState_GET(),
PyExc_NameError,
"name '%.200s' is not defined",
Expand Down Expand Up @@ -1224,7 +1224,7 @@ void JITRT_DoRaise(PyThreadState* tstate, PyObject* exc, PyObject* cause) {
// (3) Calling tstate->c_tracefunc.
// We don't support (3) and handle (1) + (2) between the check above and in
// prepareForDeopt().
do_raise(tstate, exc, cause);
Cix_do_raise(tstate, exc, cause);
}

// JIT generator data free-list globals
Expand Down Expand Up @@ -1821,7 +1821,7 @@ int JITRT_DictMerge(
PyObject* update,
PyObject* func) {
if (_PyDict_MergeEx(dict, update, 2) < 0) {
format_kwargs_error(tstate, func, update);
Cix_format_kwargs_error(tstate, func, update);
return -1;
}
return 0;
Expand Down
16 changes: 6 additions & 10 deletions CinderX/Jit/lir/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
#include <functional>
#include <sstream>

extern "C" {
int eval_frame_handle_pending(PyThreadState*);
}

// XXX: this file needs to be revisited when we optimize HIR-to-LIR translation
// in codegen.cpp/h. Currently, this file is almost an identical copy from
// codegen.cpp with some interfaces changes so that it works with the new
Expand Down Expand Up @@ -1232,7 +1228,7 @@ LIRGenerator::TranslatedBlock LIRGenerator::TranslateOneBasicBlock(
auto instr = static_cast<const LoadAttrSpecial*>(&i);
bbb.AppendCall(
instr->GetOutput(),
special_lookup,
Cix_special_lookup,
"__asm_tstate",
instr->GetOperand(0),
instr->id());
Expand Down Expand Up @@ -1665,7 +1661,7 @@ LIRGenerator::TranslatedBlock LIRGenerator::TranslateOneBasicBlock(
case Opcode::kRaiseAwaitableError: {
const auto& instr = static_cast<const RaiseAwaitableError&>(i);
bbb.AppendInvoke(
format_awaitable_error,
Cix_format_awaitable_error,
"__asm_tstate",
instr.GetOperand(0),
static_cast<int>(instr.with_prev_opcode()),
Expand Down Expand Up @@ -2082,7 +2078,7 @@ LIRGenerator::TranslatedBlock LIRGenerator::TranslateOneBasicBlock(
const auto& instr = static_cast<const MatchClass&>(i);
bbb.AppendCall(
instr.GetOutput(),
Ci_match_class,
Cix_match_class,
"__asm_tstate",
instr.GetOperand(0),
instr.GetOperand(1),
Expand All @@ -2094,7 +2090,7 @@ LIRGenerator::TranslatedBlock LIRGenerator::TranslateOneBasicBlock(
auto instr = static_cast<const MatchKeys*>(&i);
bbb.AppendCall(
instr->dst(),
Ci_match_keys,
Cix_match_keys,
"__asm_tstate",
instr->GetOperand(0),
instr->GetOperand(1));
Expand Down Expand Up @@ -2497,7 +2493,7 @@ LIRGenerator::TranslatedBlock LIRGenerator::TranslateOneBasicBlock(
}
case Opcode::kRunPeriodicTasks: {
bbb.AppendCall(
i.GetOutput(), eval_frame_handle_pending, "__asm_tstate");
i.GetOutput(), Cix_eval_frame_handle_pending, "__asm_tstate");
break;
}
case Opcode::kSnapshot: {
Expand Down Expand Up @@ -2674,7 +2670,7 @@ LIRGenerator::TranslatedBlock LIRGenerator::TranslateOneBasicBlock(
bbb.AppendCode(
"Call {}, {:#x}, __asm_tstate, {}, {}",
GetSafeTempName(),
reinterpret_cast<uint64_t>(&do_raise),
reinterpret_cast<uint64_t>(&Cix_do_raise),
exc,
cause);
appendGuardAlwaysFail(bbb, instr);
Expand Down
16 changes: 8 additions & 8 deletions CinderX/known-core-python-exported-symbols
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ AsyncFunctionDef_fields
builtin_next
cfunction_vectorcall_FASTCALL_KEYWORDS
cfunction_vectorcall_FASTCALL_KEYWORDS_METHOD
check_args_iterable
CiAsyncGen_New_NoFrame
Ci_Builtin_Next_Core
CiCoro_New_NoFrame
Expand All @@ -17,8 +16,6 @@ Ci_GetANext
Ci_hook_PyDescr_NewMethod
Ci_hook_PyJIT_GenDealloc
Ci_list_subscript
Ci_match_class
Ci_match_keys
Ci_module_lookupattro
Ci_PyClassMethod_GetFunc
Ci_PyDict_ForceCombined
Expand Down Expand Up @@ -49,6 +46,13 @@ Ci_tuple_subscript
Cix_cfunction_check_kwargs
Cix_cfunction_enter_call
Cix_descr_get_qualname
Cix_do_raise
Cix_eval_frame_handle_pending
Cix_format_awaitable_error
Cix_format_exc_check_arg
Cix_format_kwargs_error
Cix_match_class
Cix_match_keys
Cix_meth_get__doc__
Cix_meth_get__name__
Cix_meth_get__qualname__
Expand All @@ -57,6 +61,7 @@ Cix_meth_get__text_signature__
Cix_method_enter_call
Cix_method_get_doc
Cix_method_get_text_signature
Cix_special_lookup
ClassDef_fields
Delete_fields
DictComp_fields
Expand All @@ -69,12 +74,8 @@ DirEntry_repr
DirEntry_test_mode
DirEntryType_slots
DirEntryType_spec
do_raise
_DYNAMIC
eval_frame_handle_pending
format_awaitable_error
format_exc_check_arg
format_kwargs_error
__FRAME_END__
FunctionDef_fields
_io_IncrementalNewlineDecoder_decode
Expand Down Expand Up @@ -2001,7 +2002,6 @@ _Py_write
_Py_write_noraise
Py_XNewRef
PyZip_Type
special_lookup
stat_S_IMODE
stat_S_IMODE_doc
stat_S_ISDIR
Expand Down
29 changes: 18 additions & 11 deletions Include/cinder/exports.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ CiAPI_FUNC(int) Ci_Dict_SetItemInternal(PyObject *op, PyObject *key, PyObject *v

CiAPI_FUNC(PyObject **) Ci_PyObject_GetDictPtrAtOffset(PyObject *obj, Py_ssize_t dictoffset);

CiAPI_FUNC(PyObject *) special_lookup(PyThreadState *tstate, PyObject *o, _Py_Identifier *id);
CiAPI_FUNC(int) check_args_iterable(PyThreadState *tstate, PyObject *func, PyObject *args);
CiAPI_FUNC(void) format_kwargs_error(PyThreadState *tstate, PyObject *func, PyObject *kwargs);
CiAPI_FUNC(void) format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, int prevprevopcode, int prevopcode);
CiAPI_FUNC(void) format_exc_check_arg(PyThreadState *, PyObject *, const char *, PyObject *);
CiAPI_FUNC(int) do_raise(PyThreadState *tstate, PyObject *exc, PyObject *cause);

CiAPI_FUNC(PyObject *) Ci_GetAIter(PyThreadState *tstate, PyObject *obj);
CiAPI_FUNC(PyObject *) Ci_GetANext(PyThreadState *tstate, PyObject *aiter);

Expand All @@ -58,10 +51,6 @@ CiAPI_FUNC(void) Ci_ThreadState_SetProfileInterp(PyThreadState *, int);
instructions. */
CiAPI_FUNC(void) Ci_RuntimeState_SetProfileInterpPeriod(long);

CiAPI_FUNC(PyObject *) Ci_match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
Py_ssize_t nargs, PyObject *kwargs);
CiAPI_FUNC(PyObject *) Ci_match_keys(PyThreadState *tstate, PyObject *map, PyObject *keys);

CiAPI_FUNC(int) Ci_set_attribute_error_context(PyObject *v, PyObject *name);

CiAPI_DATA(PyTypeObject) Ci_StrictModuleLoader_Type;
Expand Down Expand Up @@ -182,6 +171,24 @@ CiAPI_FUNC(Ci_PyGCImpl *) Ci_PyGC_GetImpl(struct _gc_runtime_state *gc_state);
*/
CiAPI_FUNC(void) Ci_PyGC_ClearFreeLists(PyInterpreterState *interp);

CiAPI_FUNC(int) Cix_eval_frame_handle_pending(PyThreadState *tstate);
CiAPI_FUNC(PyObject *)
Cix_special_lookup(PyThreadState *tstate, PyObject *o, _Py_Identifier *id);
CiAPI_FUNC(void)
Cix_format_awaitable_error(PyThreadState *tstate, PyTypeObject *type,
int prevprevopcode, int prevopcode);
CiAPI_FUNC(void)
Cix_format_exc_check_arg(PyThreadState *tstate, PyObject *exc,
const char *format_str, PyObject *obj);
CiAPI_FUNC(void) Cix_format_kwargs_error(PyThreadState *tstate, PyObject *func,
PyObject *kwargs);
CiAPI_FUNC(int)
Cix_do_raise(PyThreadState *tstate, PyObject *exc, PyObject *cause);
CiAPI_FUNC(PyObject *)
Cix_match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
Py_ssize_t nargs, PyObject *kwargs);
CiAPI_FUNC(PyObject *)
Cix_match_keys(PyThreadState *tstate, PyObject *map, PyObject *keys);
#ifdef __cplusplus
}
#endif
72 changes: 60 additions & 12 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,18 @@ static void dtrace_function_entry(PyFrameObject *);
static void dtrace_function_return(PyFrameObject *);

static int import_all_from(PyThreadState *, PyObject *, PyObject *);
static void format_exc_check_arg(PyThreadState *, PyObject *, const char *, PyObject *);
static void format_exc_unbound(PyThreadState *tstate, PyCodeObject *co, int oparg);
static PyObject * unicode_concatenate(PyThreadState *, PyObject *, PyObject *,
PyFrameObject *, const _Py_CODEUNIT *);
#ifdef ENABLE_CINDERX
static void try_profile_next_instr(PyFrameObject* f, PyObject** stack_pointer,
const _Py_CODEUNIT* next_instr);
#endif
static PyObject * special_lookup(PyThreadState *, PyObject *, _Py_Identifier *);
static int check_args_iterable(PyThreadState *, PyObject *func, PyObject *vararg);
static void format_kwargs_error(PyThreadState *, PyObject *func, PyObject *kwargs);
static void format_awaitable_error(PyThreadState *, PyTypeObject *, int, int);

#define NAME_ERROR_MSG \
"name '%.200s' is not defined"
Expand Down Expand Up @@ -1038,8 +1043,8 @@ _Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)

// Return a tuple of values corresponding to keys, with error checks for
// duplicate/missing keys.
PyObject*
Ci_match_keys(PyThreadState *tstate, PyObject *map, PyObject *keys)
static PyObject*
match_keys(PyThreadState *tstate, PyObject *map, PyObject *keys)
{
assert(PyTuple_CheckExact(keys));
Py_ssize_t nkeys = PyTuple_GET_SIZE(keys);
Expand Down Expand Up @@ -1140,8 +1145,8 @@ match_class_attr(PyThreadState *tstate, PyObject *subject, PyObject *type,

// On success (match), return a tuple of extracted attributes. On failure (no
// match), return NULL. Use _PyErr_Occurred(tstate) to disambiguate.
PyObject*
Ci_match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
static PyObject*
match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
Py_ssize_t nargs, PyObject *kwargs)
{
if (!PyType_Check(type)) {
Expand Down Expand Up @@ -1249,6 +1254,7 @@ Ci_match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
}


static int do_raise(PyThreadState *tstate, PyObject *exc, PyObject *cause);
static int unpack_iterable(PyThreadState *, PyObject *, int, int, PyObject **);

#ifdef ENABLE_CINDERX
Expand Down Expand Up @@ -3936,7 +3942,7 @@ f->lazy_imports_cache_seq = -1;
PyObject *type = TOP();
PyObject *subject = SECOND();
assert(PyTuple_CheckExact(names));
PyObject *attrs = Ci_match_class(tstate, subject, type, oparg, names);
PyObject *attrs = match_class(tstate, subject, type, oparg, names);
Py_DECREF(names);
if (attrs) {
// Success!
Expand Down Expand Up @@ -3975,7 +3981,7 @@ f->lazy_imports_cache_seq = -1;
// Otherwise, PUSH(None) and PUSH(False).
PyObject *keys = TOP();
PyObject *subject = SECOND();
PyObject *values_or_none = Ci_match_keys(tstate, subject, keys);
PyObject *values_or_none = match_keys(tstate, subject, keys);
if (values_or_none == NULL) {
goto error;
}
Expand Down Expand Up @@ -7150,7 +7156,7 @@ unbox_primitive_bool_and_decref(PyObject *x)
}
#endif

PyObject *
static PyObject *
special_lookup(PyThreadState *tstate, PyObject *o, _Py_Identifier *id)
{
PyObject *res;
Expand All @@ -7165,7 +7171,7 @@ special_lookup(PyThreadState *tstate, PyObject *o, _Py_Identifier *id)

/* Logic for the raise statement (too complicated for inlining).
This *consumes* a reference count to each of its arguments. */
int
static int
do_raise(PyThreadState *tstate, PyObject *exc, PyObject *cause)
{
PyObject *type = NULL, *value = NULL;
Expand Down Expand Up @@ -8491,7 +8497,7 @@ import_all_from(PyThreadState *tstate, PyObject *locals, PyObject *v)
return err;
}

int
static int
check_args_iterable(PyThreadState *tstate, PyObject *func, PyObject *args)
{
if (Py_TYPE(args)->tp_iter == NULL && !PySequence_Check(args)) {
Expand All @@ -8511,7 +8517,7 @@ check_args_iterable(PyThreadState *tstate, PyObject *func, PyObject *args)
return 0;
}

void
static void
format_kwargs_error(PyThreadState *tstate, PyObject *func, PyObject *kwargs)
{
/* _PyDict_MergeEx raises attribute
Expand Down Expand Up @@ -8555,7 +8561,7 @@ format_kwargs_error(PyThreadState *tstate, PyObject *func, PyObject *kwargs)
}
}

void
static void
format_exc_check_arg(PyThreadState *tstate, PyObject *exc,
const char *format_str, PyObject *obj)
{
Expand Down Expand Up @@ -8610,7 +8616,7 @@ format_exc_unbound(PyThreadState *tstate, PyCodeObject *co, int oparg)
}
}

void
static void
format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, int prevprevopcode, int prevopcode)
{
if (type->tp_as_async == NULL || type->tp_as_async->am_await == NULL) {
Expand Down Expand Up @@ -8932,3 +8938,45 @@ void Py_LeaveRecursiveCall(void)
{
_Py_LeaveRecursiveCall_inline();
}


PyObject*
Cix_match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
Py_ssize_t nargs, PyObject *kwargs) {
return match_class(tstate, subject, type, nargs, kwargs);
}

PyObject*
Cix_match_keys(PyThreadState *tstate, PyObject *map, PyObject *keys) {
return match_keys(tstate, map, keys);
}

PyObject*
Cix_special_lookup(PyThreadState *tstate, PyObject *o, _Py_Identifier *id) {
return special_lookup(tstate, o, id);
}

void
Cix_format_kwargs_error(PyThreadState *tstate, PyObject *func, PyObject *kwargs) {
format_kwargs_error(tstate, func, kwargs);
}

void
Cix_format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, int prevprevopcode, int prevopcode) {
format_awaitable_error(tstate, type, prevprevopcode, prevopcode);
}
void
Cix_format_exc_check_arg(PyThreadState *tstate, PyObject *exc,
const char *format_str, PyObject *obj) {
format_exc_check_arg(tstate, exc, format_str, obj);
}

int
Cix_do_raise(PyThreadState *tstate, PyObject *exc, PyObject *cause) {
return do_raise(tstate, exc, cause);
}

int
Cix_eval_frame_handle_pending(PyThreadState *tstate) {
return eval_frame_handle_pending(tstate);
}

0 comments on commit d07bf88

Please sign in to comment.