Skip to content

Commit 1fab20e

Browse files
alexmalyshevmeta-codesync[bot]
authored andcommitted
Replace x-macro of interned strings with DEFINE_STATIC_STRING
Summary: Makes it simpler, no longer needs dedicated init/fini steps. Reviewed By: jbower-fb Differential Revision: D88219220 fbshipit-source-id: acefc2dfb0622c0c81fbd0ba0b54cfe7429f4c72
1 parent dd3f484 commit 1fab20e

1 file changed

Lines changed: 20 additions & 44 deletions

File tree

cinderx/Jit/pyjit.cpp

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "cinderx/Common/import.h"
1818
#include "cinderx/Common/log.h"
1919
#include "cinderx/Common/ref.h"
20+
#include "cinderx/Common/string.h"
2021
#include "cinderx/Common/util.h"
2122
#include "cinderx/Interpreter/interpreter.h"
2223
#include "cinderx/Jit/code_allocator.h"
@@ -102,30 +103,6 @@ UnitDeletedCallback handle_unit_deleted_during_preload = nullptr;
102103
std::unordered_map<BorrowedRef<PyCodeObject>, BorrowedRef<PyFunctionObject>>
103104
jit_code_outer_funcs;
104105

105-
// Frequently-used strings that we intern at JIT startup and hold references to.
106-
#define INTERNED_STRINGS(X) \
107-
X(bc_offset) \
108-
X(code_hash) \
109-
X(count) \
110-
X(description) \
111-
X(filename) \
112-
X(firstlineno) \
113-
X(func_qualname) \
114-
X(guilty_type) \
115-
X(int) \
116-
X(lineno) \
117-
X(normal) \
118-
X(normvector) \
119-
X(opname) \
120-
X(reason) \
121-
X(split_dict_keys) \
122-
X(type_name) \
123-
X(types)
124-
125-
#define DECLARE_STR(s) static PyObject* s_str_##s{nullptr};
126-
INTERNED_STRINGS(DECLARE_STR)
127-
#undef DECLARE_STR
128-
129106
std::array<PyObject*, hir::kNumOpcodes> s_hir_opnames;
130107

131108
std::atomic<int> g_compile_workers_attempted;
@@ -2029,6 +2006,16 @@ int check(int ret) {
20292006
}
20302007

20312008
Ref<> make_deopt_stats() {
2009+
DEFINE_STATIC_STRING(count);
2010+
DEFINE_STATIC_STRING(description);
2011+
DEFINE_STATIC_STRING(filename);
2012+
DEFINE_STATIC_STRING(func_qualname);
2013+
DEFINE_STATIC_STRING(guilty_type);
2014+
DEFINE_STATIC_STRING(lineno);
2015+
DEFINE_STATIC_STRING(normal);
2016+
DEFINE_STATIC_STRING(int);
2017+
DEFINE_STATIC_STRING(reason);
2018+
20322019
auto runtime = Runtime::get();
20332020
auto stats = Ref<>::steal(check(PyList_New(0)));
20342021

@@ -2066,19 +2053,19 @@ Ref<> make_deopt_stats() {
20662053
auto normals = Ref<>::steal(check(PyDict_New()));
20672054
auto ints = Ref<>::steal(check(PyDict_New()));
20682055

2069-
check(PyDict_SetItem(event, s_str_normal, normals));
2070-
check(PyDict_SetItem(event, s_str_int, ints));
2071-
check(PyDict_SetItem(normals, s_str_func_qualname, func_qualname));
2072-
check(PyDict_SetItem(normals, s_str_filename, code->co_filename));
2073-
check(PyDict_SetItem(ints, s_str_lineno, lineno));
2074-
check(PyDict_SetItem(normals, s_str_reason, reason));
2075-
check(PyDict_SetItem(normals, s_str_description, description));
2056+
check(PyDict_SetItem(event, s_normal, normals));
2057+
check(PyDict_SetItem(event, s_int, ints));
2058+
check(PyDict_SetItem(normals, s_func_qualname, func_qualname));
2059+
check(PyDict_SetItem(normals, s_filename, code->co_filename));
2060+
check(PyDict_SetItem(ints, s_lineno, lineno));
2061+
check(PyDict_SetItem(normals, s_reason, reason));
2062+
check(PyDict_SetItem(normals, s_description, description));
20762063

20772064
auto count = Ref<>::steal(check(PyLong_FromSize_t(count_raw)));
2078-
check(PyDict_SetItem(ints, s_str_count, count));
2065+
check(PyDict_SetItem(ints, s_count, count));
20792066
auto type_str =
20802067
Ref<>::steal(check(PyUnicode_InternFromString(type_name)));
2081-
check(PyDict_SetItem(normals, s_str_guilty_type, type_str) < 0);
2068+
check(PyDict_SetItem(normals, s_guilty_type, type_str) < 0);
20822069
check(PyList_Append(stats, event));
20832070
};
20842071

@@ -2792,13 +2779,6 @@ int register_fork_callback(BorrowedRef<> cinderjit_module) {
27922779

27932780
// Initialize some interned strings that can be used even when the JIT is off.
27942781
int initializeInternedStrings() {
2795-
#define INTERN_STR(s) \
2796-
if ((s_str_##s = PyUnicode_InternFromString(#s)) == nullptr) { \
2797-
return -1; \
2798-
}
2799-
INTERNED_STRINGS(INTERN_STR)
2800-
#undef INTERN_STR
2801-
28022782
#define HIR_OP(opname) \
28032783
if ((s_hir_opnames.at(static_cast<size_t>(hir::Opcode::k##opname)) = \
28042784
PyUnicode_InternFromString(#opname)) == nullptr) { \
@@ -2859,10 +2839,6 @@ void dump_jit_stats() {
28592839
}
28602840

28612841
void finalizeInternedStrings() {
2862-
#define CLEAR_STR(s) Py_CLEAR(s_str_##s);
2863-
INTERNED_STRINGS(CLEAR_STR)
2864-
#undef CLEAR_STR
2865-
28662842
for (PyObject*& opname : s_hir_opnames) {
28672843
Py_CLEAR(opname);
28682844
}

0 commit comments

Comments
 (0)