runtime/symbols.h (826 lines of code) (raw):
/* Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com) */
#pragma once
#include "heap.h"
#include "visitor.h"
namespace py {
class Runtime;
// List of predefined symbols, one per line
#define FOREACH_SYMBOL(V) \
V(ArithmeticError) \
V(AssertionError) \
V(AttributeError) \
V(BaseException) \
V(BlockingIOError) \
V(BrokenPipeError) \
V(BufferError) \
V(BufferedRandom) \
V(BufferedReader) \
V(BufferedWriter) \
V(BytesIO) \
V(BytesWarning) \
V(ChildProcessError) \
V(ConnectionAbortedError) \
V(ConnectionError) \
V(ConnectionRefusedError) \
V(ConnectionResetError) \
V(Context) \
V(ContextVar) \
V(DeprecationWarning) \
V(EOFError) \
V(Error) \
V(Exception) \
V(ExceptionState) \
V(False) \
V(FileExistsError) \
V(FileIO) \
V(FileNotFoundError) \
V(FloatingPointError) \
V(FutureWarning) \
V(GeneratorExit) \
V(ImportError) \
V(ImportWarning) \
V(IncrementalNewlineDecoder) \
V(IndentationError) \
V(IndexError) \
V(InterruptedError) \
V(IsADirectoryError) \
V(JSONDecodeError) \
V(KeyError) \
V(KeyboardInterrupt) \
V(LookupError) \
V(MAP_SHARED) \
V(MAP_PRIVATE) \
V(MemoryError) \
V(ModuleNotFoundError) \
V(NSIG) \
V(NameError) \
V(None) \
V(NoneType) \
V(NotADirectoryError) \
V(NotImplemented) \
V(NotImplementedError) \
V(NotImplementedType) \
V(OSError) \
V(OverflowError) \
V(PAGESIZE) \
V(PendingDeprecationWarning) \
V(PermissionError) \
V(ProcessLookupError) \
V(PROT_EXEC) \
V(PROT_READ) \
V(PROT_WRITE) \
V(PYRO_RAISE_ON_UNIMPLEMENTED) \
V(RTLD_GLOBAL) \
V(RTLD_LOCAL) \
V(RecursionError) \
V(ReferenceError) \
V(ResourceWarning) \
V(RuntimeError) \
V(RuntimeWarning) \
V(SIG_DFL) \
V(SIG_IGN) \
V(SimpleNamespace) \
V(SourceFileLoader) \
V(SourcelessFileLoader) \
V(StopAsyncIteration) \
V(StopIteration) \
V(StringIO) \
V(SyntaxError) \
V(SyntaxWarning) \
V(SystemError) \
V(SystemExit) \
V(TabError) \
V(TextIOWrapper) \
V(TimeoutError) \
V(Token) \
V(True) \
V(TypeError) \
V(UCD) \
V(UnboundLocalError) \
V(UnicodeDecodeError) \
V(UnicodeEncodeError) \
V(UnicodeError) \
V(UnicodeTranslateError) \
V(UnicodeWarning) \
V(UserWarning) \
V(ValueError) \
V(Warning) \
V(ZeroDivisionError) \
V(_BufferedIOBase) \
V(_BufferedIOMixin) \
V(_BytesIO__num_items) \
V(_HashInfo) \
V(_IOBase) \
V(_RawIOBase) \
V(_TextIOBase) \
V(_Unbound) \
V(_UnboundType) \
V(_UserBytes__value) \
V(_UserFloat__value) \
V(_UserInt__value) \
V(_UserStr__value) \
V(_UserTuple__value) \
V(__abs__) \
V(__abstractmethods__) \
V(__add__) \
V(__aenter__) \
V(__aexit__) \
V(__aiter__) \
V(__all__) \
V(__and__) \
V(__anext__) \
V(__annotations__) \
V(__await__) \
V(__bases__) \
V(__bool__) \
V(__build_class__) \
V(__builtins__) \
V(__bytes__) \
V(__cached__) \
V(__call__) \
V(__class__) \
V(__class_getitem__) \
V(__classcell__) \
V(__code__) \
V(__complex__) \
V(__contains__) \
V(__debug__) \
V(__del__) \
V(__delattr__) \
V(__delete__) \
V(__delitem__) \
V(__dict__) \
V(__dir__) \
V(__divmod__) \
V(__doc__) \
V(__enter__) \
V(__eq__) \
V(__exit__) \
V(__file__) \
V(__float__) \
V(__floordiv__) \
V(__format__) \
V(__func__) \
V(__ge__) \
V(__get__) \
V(__getattr__) \
V(__getattribute__) \
V(__getitem__) \
V(__globals__) \
V(__gt__) \
V(__hash__) \
V(__iadd__) \
V(__iand__) \
V(__ifloordiv__) \
V(__ilshift__) \
V(__imatmul__) \
V(__imod__) \
V(__import__) \
V(__imul__) \
V(__index__) \
V(__init__) \
V(__init_subclass__) \
V(__int__) \
V(__interactivehook__) \
V(__invert__) \
V(__ior__) \
V(__ipow__) \
V(__irshift__) \
V(__isabstractmethod__) \
V(__isub__) \
V(__iter__) \
V(__itruediv__) \
V(__ixor__) \
V(__le__) \
V(__len__) \
V(__length_hint__) \
V(__loader__) \
V(__lshift__) \
V(__lt__) \
V(__main__) \
V(__matmul__) \
V(__mod__) \
V(__module__) \
V(__module_object__) \
V(__mro__) \
V(__mro_entries__) \
V(__mul__) \
V(__name__) \
V(__ne__) \
V(__neg__) \
V(__new__) \
V(__next__) \
V(__objclass__) \
V(__or__) \
V(__orig_bases__) \
V(__package__) \
V(__pos__) \
V(__pow__) \
V(__prepare__) \
V(__qualname__) \
V(__radd__) \
V(__rand__) \
V(__rdivmod__) \
V(__repr__) \
V(__rfloordiv__) \
V(__rlshift__) \
V(__rmatmul__) \
V(__rmod__) \
V(__rmul__) \
V(__ror__) \
V(__rpow__) \
V(__rrshift__) \
V(__rshift__) \
V(__rsub__) \
V(__rtruediv__) \
V(__rxor__) \
V(__self__) \
V(__self_class__) \
V(__set__) \
V(__set_name__) \
V(__setattr__) \
V(__setitem__) \
V(__slots__) \
V(__spec__) \
V(__str__) \
V(__sub__) \
V(__suppress_context__) \
V(__thisclass__) \
V(__truediv__) \
V(__weaklink__callback) \
V(__weaklink__hash) \
V(__weaklink__link) \
V(__weaklink__next) \
V(__weaklink__prev) \
V(__weaklink__referent) \
V(__xor__) \
V(_appending) \
V(_array__buffer) \
V(_array__length) \
V(_async_generator__exception_state) \
V(_async_generator__finalizer) \
V(_async_generator__frame) \
V(_async_generator__hooks_inited) \
V(_async_generator__running) \
V(_async_generator_aclose__generator) \
V(_async_generator_aclose__state) \
V(_async_generator_asend__generator) \
V(_async_generator_asend__state) \
V(_async_generator_asend__value) \
V(_async_generator_athrow__exception_traceback) \
V(_async_generator_athrow__exception_type) \
V(_async_generator_athrow__exception_value) \
V(_async_generator_athrow__generator) \
V(_async_generator_athrow__state) \
V(_async_generator_wrapped_value__value) \
V(_base_exception__cause) \
V(_base_exception__context) \
V(_base_exception__traceback) \
V(_b2cratio) \
V(_buffer) \
V(_buffer_num_bytes) \
V(_buffer_size) \
V(_buffered_reader__read_buf) \
V(_builtins) \
V(_bytearray__bytes) \
V(_bytearray__num_items) \
V(_bytearray_iterator__index) \
V(_bytearray_iterator__iterable) \
V(_bytes_iterator__index) \
V(_bytes_iterator__iterable) \
V(_bytes_new) \
V(_calculate_path) \
V(_cast_addr) \
V(_closed) \
V(_closefd) \
V(_code__cell2arg) \
V(_code__intrinsic) \
V(_codecs) \
V(_compiler) \
V(_compile_flags_mask) \
V(_context__data) \
V(_context__prev_context) \
V(_context_var__default_value) \
V(_coroutine__await) \
V(_coroutine__exception_state) \
V(_coroutine__frame) \
V(_coroutine__origin) \
V(_coroutine_wrapper__cw_coroutine) \
V(_created) \
V(_decode_with_cls) \
V(_decoded_chars) \
V(_decoded_chars_used) \
V(_decoder) \
V(_deque__items) \
V(_deque__left) \
V(_deque__num_items) \
V(_deque__state) \
V(_deque_iterator) \
V(_deque_iterator__index) \
V(_deque_iterator__iterable) \
V(_deque_iterator__state) \
V(_deque_reverse_iterator) \
V(_deque_reverse_iterator__index) \
V(_deque_reverse_iterator__iterable) \
V(_deque_reverse_iterator__state) \
V(_descrclassmethod) \
V(_dict__data) \
V(_dict__first_empty_item_index) \
V(_dict__num_items) \
V(_dict__sparse) \
V(_dict_item_iterator__index) \
V(_dict_item_iterator__iterable) \
V(_dict_item_iterator__num_found) \
V(_dict_items__dict) \
V(_dict_key_iterator__index) \
V(_dict_key_iterator__iterable) \
V(_dict_key_iterator__num_found) \
V(_dict_keys__dict) \
V(_dict_value_iterator__index) \
V(_dict_value_iterator__iterable) \
V(_dict_value_iterator__num_found) \
V(_dict_values__dict) \
V(_enable_threads) \
V(_encoder) \
V(_encoding) \
V(_err_program_text) \
V(_errors) \
V(_escape_decode_stateful) \
V(_exception_new) \
V(_exception_state__previous) \
V(_exception_state__traceback) \
V(_exception_state__type) \
V(_exception_state__value) \
V(_fd) \
V(_float) \
V(_frozen_importlib) \
V(_frozen_importlib_external) \
V(_frozenset__data) \
V(_frozenset__num_filled) \
V(_frozenset__num_items) \
V(_fspath) \
V(_function) \
V(_function__annotations) \
V(_function__argcount) \
V(_function__caches) \
V(_function__closure) \
V(_function__defaults) \
V(_function__dict) \
V(_function__entry) \
V(_function__entry_asm) \
V(_function__entry_ex) \
V(_function__entry_kw) \
V(_function__flags) \
V(_function__kw_defaults) \
V(_function__rewritten_bytecode) \
V(_function__stack_size) \
V(_function__total_args) \
V(_function__total_vars) \
V(_function__intrinsic) \
V(_generator__exception_state) \
V(_generator__frame) \
V(_generator__yield_from) \
V(_has_read1) \
V(_import_all_from) \
V(_index_or_int) \
V(_init) \
V(_instance) \
V(_instance_dunder_dict_set) \
V(_int_ctor) \
V(_int_ctor_obj) \
V(_int_new_from_str) \
V(_io) \
V(_iterator__index) \
V(_iterator__iterable) \
V(_json) \
V(_layout__described_type) \
V(_layout__in_object_attributes) \
V(_layout__overflow_attributes) \
V(_layout__additions) \
V(_layout__deletions) \
V(_layout__num_in_object_attributes) \
V(_line_buffering) \
V(_list__items) \
V(_list__num_items) \
V(_list_iterator__index) \
V(_list_ctor) \
V(_list_iterator__iterable) \
V(_longrange_iterator__next) \
V(_longrange_iterator__step) \
V(_longrange_iterator__stop) \
V(_lookup_text) \
V(_lt) \
V(_lt_key) \
V(_mappingproxy__mapping) \
V(_memmove_addr) \
V(_memoryview__buffer) \
V(_memoryview__length) \
V(_memoryview__start) \
V(_memset_addr) \
V(_mmap__access) \
V(_mmap__data) \
V(_mmap__fd) \
V(_module__attributes) \
V(_module__attributes_remaining) \
V(_module__def) \
V(_module__name) \
V(_module__proxy) \
V(_module__state) \
V(_mutablebytes) \
V(_mutabletuple) \
V(_new_member_get_bool) \
V(_new_member_get_byte) \
V(_new_member_get_char) \
V(_new_member_get_double) \
V(_new_member_get_float) \
V(_new_member_get_int) \
V(_new_member_get_long) \
V(_new_member_get_pyobject) \
V(_new_member_get_short) \
V(_new_member_get_string) \
V(_new_member_get_ubyte) \
V(_new_member_get_uint) \
V(_new_member_get_ulong) \
V(_new_member_get_ushort) \
V(_new_member_set_bool) \
V(_new_member_set_char) \
V(_new_member_set_double) \
V(_new_member_set_float) \
V(_new_member_set_integral) \
V(_new_member_set_integral_unsigned) \
V(_new_member_set_pyobject) \
V(_new_member_set_readonly) \
V(_new_member_set_readonly_strings) \
V(_pendingcr) \
V(_pointer) \
V(_pointer__cptr) \
V(_pointer__length) \
V(_pos) \
V(_range_iterator__length) \
V(_range_iterator__next) \
V(_range_iterator__step) \
V(_raw) \
V(_read_pos) \
V(_readable) \
V(_reader) \
V(_readnl) \
V(_readtranslate) \
V(_readuniversal) \
V(_ref__callback) \
V(_ref__hash) \
V(_ref__link) \
V(_ref__referent) \
V(_run_module_as_main) \
V(_seekable) \
V(_seennl) \
V(_set__data) \
V(_set__num_items) \
V(_set__num_filled) \
V(_set_iterator__consumed_count) \
V(_set_iterator__index) \
V(_set_iterator__iterable) \
V(_signal) \
V(_slice_index) \
V(_slot_descriptor__offset) \
V(_snapshot) \
V(_stderr_fd) \
V(_stdin_fd) \
V(_stdout_fd) \
V(_stop_iteration_ctor) \
V(_str_array) \
V(_str_array__items) \
V(_str_array__num_items) \
V(_str_array_ctor) \
V(_str_ctor) \
V(_str_ctor_obj) \
V(_str_iterator__index) \
V(_str_iterator__iterable) \
V(_string_at_addr) \
V(_structseq_field) \
V(_structseq_field_names) \
V(_structseq_new) \
V(_structseq_repr) \
V(_super_ctor) \
V(_telling) \
V(_thread) \
V(_traceback__function) \
V(_traceback__lineno) \
V(_token__context) \
V(_token__used) \
V(_traceback__next) \
V(_translate) \
V(_try_run_package) \
V(_tuple_iterator__index) \
V(_tuple_iterator__iterable) \
V(_tuple_iterator__length) \
V(_tuple_len) \
V(_type__abstract_methods) \
V(_type__attributes) \
V(_type__attributes_remaining) \
V(_type__bases) \
V(_type__ctor) \
V(_type__flags) \
V(_type__instance_layout) \
V(_type__instance_layout_id) \
V(_type__name) \
V(_type__proxy) \
V(_type__qualname) \
V(_type__slots) \
V(_type__subclasses) \
V(_type_ctor) \
V(_type_dunder_call) \
V(_type_proxy__type) \
V(_unicode_escape_decode_stateful) \
V(_valuecell__dependency_link) \
V(_valuecell__value) \
V(_version_releaselevel) \
V(_weaklink) \
V(_weakref) \
V(_writable) \
V(_write_buf) \
V(_write_lock) \
V(_writenl) \
V(_writetranslate) \
V(_wstring_at_addr) \
V(abs) \
V(add) \
V(and_) \
V(args) \
V(argv) \
V(array) \
V(ascii) \
V(ascii_decode) \
V(ascii_encode) \
V(async_generator) \
V(async_generator_aclose) \
V(async_generator_asend) \
V(async_generator_athrow) \
V(async_generator_wrapped_value) \
V(backslashreplace) \
V(big) \
V(bool) \
V(buffer_size) \
V(builtin_module_names) \
V(builtins) \
V(bytearray) \
V(bytearray_iterator) \
V(byteorder) \
V(bytes) \
V(bytes_iterator) \
V(callable_iterator) \
V(cell) \
V(cell_contents) \
V(classmethod) \
V(co_argcount) \
V(co_cellvars) \
V(co_code) \
V(co_consts) \
V(co_filename) \
V(co_firstlineno) \
V(co_flags) \
V(co_freevars) \
V(co_kwonlyargcount) \
V(co_lnotab) \
V(co_name) \
V(co_names) \
V(co_nlocals) \
V(co_posonlyargcount) \
V(co_stacksize) \
V(co_varnames) \
V(code) \
V(compile) \
V(complex) \
V(contains) \
V(coroutine) \
V(coroutine_wrapper) \
V(countOf) \
V(cr_running) \
V(decode) \
V(default_int_handler) \
V(deque) \
V(dict) \
V(dict_itemiterator) \
V(dict_items) \
V(dict_keyiterator) \
V(dict_keys) \
V(dict_valueiterator) \
V(dict_values) \
V(displayhook) \
V(divmod) \
V(ellipsis) \
V(encode) \
V(encoding) \
V(end) \
V(enumerate) \
V(eval) \
V(excepthook) \
V(exec) \
V(extend) \
V(f_back) \
V(f_lasti) \
V(f_locals) \
V(fdel) \
V(fget) \
V(filename) \
V(fileno) \
V(float) \
V(floordiv) \
V(flush) \
V(format) \
V(frame) \
V(frozenset) \
V(fset) \
V(function) \
V(generator) \
V(getline) \
V(getsizeof) \
V(gi_running) \
V(hash_info) \
V(hexversion) \
V(iadd) \
V(iand) \
V(iconcat) \
V(ifloordiv) \
V(ignore) \
V(ilshift) \
V(imag) \
V(imatmul) \
V(imod) \
V(imul) \
V(index) \
V(indexOf) \
V(instance) \
V(instance_proxy) \
V(instancemethod) \
V(int) \
V(invert) \
V(ior) \
V(ipow) \
V(irepeat) \
V(irshift) \
V(isidentifier) \
V(isinstance) \
V(issubclass) \
V(isub) \
V(items) \
V(iter) \
V(iterator) \
V(itruediv) \
V(ixor) \
V(join) \
V(key) \
V(keys) \
V(kwargs) \
V(largebytes) \
V(largeint) \
V(largestr) \
V(last_traceback) \
V(last_type) \
V(last_value) \
V(latin_1_decode) \
V(latin_1_encode) \
V(layout) \
V(len) \
V(linecache) \
V(lineno) \
V(list) \
V(list_iterator) \
V(little) \
V(longrange_iterator) \
V(lshift) \
V(magic_number) \
V(mappingproxy) \
V(matmul) \
V(maxlen) \
V(maxsize) \
V(maxunicode) \
V(memoryview) \
V(method) \
V(mmap) \
V(mod) \
V(mode) \
V(module) \
V(module_proxy) \
V(modules) \
V(mro) \
V(msg) \
V(mul) \
V(n_fields) \
V(n_sequence_fields) \
V(n_unnamed_fields) \
V(name) \
V(ndim) \
V(neg) \
V(obj) \
V(object) \
V(offset) \
V(old_value) \
V(operator) \
V(or_) \
V(owner) \
V(partition) \
V(path) \
V(platform) \
V(pos) \
V(pow) \
V(print_file_and_line) \
V(property) \
V(proxy) \
V(pycache_prefix) \
V(range) \
V(range_iterator) \
V(read) \
V(readall) \
V(readonly) \
V(real) \
V(reason) \
V(ref_obj) \
V(replace) \
V(repr) \
V(reset) \
V(rpartition) \
V(rshift) \
V(rsplit) \
V(runpy) \
V(self) \
V(send) \
V(set) \
V(set_iterator) \
V(shape) \
V(single) \
V(siphash24) \
V(slice) \
V(slot_descriptor) \
V(smallbytes) \
V(smallint) \
V(smallstr) \
V(sorted) \
V(split) \
V(start) \
V(staticmethod) \
V(stderr) \
V(stdin) \
V(stdout) \
V(step) \
V(stop) \
V(str) \
V(str_iterator) \
V(strict) \
V(strict_errors) \
V(strides) \
V(sub) \
V(super) \
V(surrogateescape) \
V(surrogatepass) \
V(sys) \
V(tb_lasti) \
V(text) \
V(throw) \
V(time) \
V(traceback) \
V(tracebacklimit) \
V(truediv) \
V(tuple) \
V(tuple_iterator) \
V(type) \
V(type_proxy) \
V(typecode) \
V(ucd_3_2_0) \
V(unicodedata) \
V(utf_16_encode) \
V(utf_32_encode) \
V(utf_8_decode) \
V(utf_8_encode) \
V(value) \
V(valuecell) \
V(var) \
V(version) \
V(warn) \
V(warn_explicit) \
V(warnings) \
V(weakref) \
V(weakcallableproxy) \
V(weakproxy) \
V(write) \
V(xor)
// clang-format off
enum class SymbolId {
kInvalid = -1,
#define DEFINE_SYMBOL_INDEX(symbol) k_##symbol,
FOREACH_SYMBOL(DEFINE_SYMBOL_INDEX)
#undef DEFINE_SYMBOL_INDEX
kMaxId,
};
// clang-format on
// Provides convenient, fast access to commonly used names. Stolen from Dart.
class Symbols {
public:
explicit Symbols(Runtime* runtime);
~Symbols();
void visit(PointerVisitor* visitor);
RawStr at(SymbolId id) {
int index = static_cast<int>(id);
DCHECK_INDEX(index, static_cast<int>(SymbolId::kMaxId));
return RawStr::cast(symbols_[index]);
}
static const char* predefinedSymbolAt(SymbolId id);
private:
// TODO(T25010996) - Benchmark whether this is faster than an Tuple
RawObject* symbols_;
};
#define ID(x) SymbolId::k_##x
} // namespace py