cinderx 2026.1.16.2__cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. __static__/__init__.py +641 -0
  2. __static__/compiler_flags.py +8 -0
  3. __static__/enum.py +160 -0
  4. __static__/native_utils.py +77 -0
  5. __static__/type_code.py +48 -0
  6. __strict__/__init__.py +39 -0
  7. _cinderx.so +0 -0
  8. cinderx/__init__.py +577 -0
  9. cinderx/__pycache__/__init__.cpython-314.pyc +0 -0
  10. cinderx/_asyncio.py +156 -0
  11. cinderx/compileall.py +710 -0
  12. cinderx/compiler/__init__.py +40 -0
  13. cinderx/compiler/__main__.py +137 -0
  14. cinderx/compiler/config.py +7 -0
  15. cinderx/compiler/consts.py +72 -0
  16. cinderx/compiler/debug.py +70 -0
  17. cinderx/compiler/dis_stable.py +283 -0
  18. cinderx/compiler/errors.py +151 -0
  19. cinderx/compiler/flow_graph_optimizer.py +1287 -0
  20. cinderx/compiler/future.py +91 -0
  21. cinderx/compiler/misc.py +32 -0
  22. cinderx/compiler/opcode_cinder.py +18 -0
  23. cinderx/compiler/opcode_static.py +100 -0
  24. cinderx/compiler/opcodebase.py +158 -0
  25. cinderx/compiler/opcodes.py +991 -0
  26. cinderx/compiler/optimizer.py +547 -0
  27. cinderx/compiler/pyassem.py +3711 -0
  28. cinderx/compiler/pycodegen.py +7660 -0
  29. cinderx/compiler/pysourceloader.py +62 -0
  30. cinderx/compiler/static/__init__.py +1404 -0
  31. cinderx/compiler/static/compiler.py +629 -0
  32. cinderx/compiler/static/declaration_visitor.py +335 -0
  33. cinderx/compiler/static/definite_assignment_checker.py +280 -0
  34. cinderx/compiler/static/effects.py +160 -0
  35. cinderx/compiler/static/module_table.py +666 -0
  36. cinderx/compiler/static/type_binder.py +2176 -0
  37. cinderx/compiler/static/types.py +10580 -0
  38. cinderx/compiler/static/util.py +81 -0
  39. cinderx/compiler/static/visitor.py +91 -0
  40. cinderx/compiler/strict/__init__.py +69 -0
  41. cinderx/compiler/strict/class_conflict_checker.py +249 -0
  42. cinderx/compiler/strict/code_gen_base.py +409 -0
  43. cinderx/compiler/strict/common.py +507 -0
  44. cinderx/compiler/strict/compiler.py +352 -0
  45. cinderx/compiler/strict/feature_extractor.py +130 -0
  46. cinderx/compiler/strict/flag_extractor.py +97 -0
  47. cinderx/compiler/strict/loader.py +827 -0
  48. cinderx/compiler/strict/preprocessor.py +11 -0
  49. cinderx/compiler/strict/rewriter/__init__.py +5 -0
  50. cinderx/compiler/strict/rewriter/remove_annotations.py +84 -0
  51. cinderx/compiler/strict/rewriter/rewriter.py +975 -0
  52. cinderx/compiler/strict/runtime.py +77 -0
  53. cinderx/compiler/symbols.py +1754 -0
  54. cinderx/compiler/unparse.py +414 -0
  55. cinderx/compiler/visitor.py +194 -0
  56. cinderx/jit.py +230 -0
  57. cinderx/opcode.py +202 -0
  58. cinderx/static.py +113 -0
  59. cinderx/strictmodule.py +6 -0
  60. cinderx/test_support.py +341 -0
  61. cinderx-2026.1.16.2.dist-info/METADATA +15 -0
  62. cinderx-2026.1.16.2.dist-info/RECORD +68 -0
  63. cinderx-2026.1.16.2.dist-info/WHEEL +6 -0
  64. cinderx-2026.1.16.2.dist-info/licenses/LICENSE +21 -0
  65. cinderx-2026.1.16.2.dist-info/top_level.txt +5 -0
  66. opcodes/__init__.py +0 -0
  67. opcodes/assign_opcode_numbers.py +272 -0
  68. opcodes/cinderx_opcodes.py +121 -0
@@ -0,0 +1,629 @@
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ # pyre-strict
4
+
5
+ from __future__ import annotations
6
+
7
+ from __static__ import posix_clock_gettime_ns, rand, RAND_MAX
8
+
9
+ import ast
10
+ import builtins
11
+ import sys
12
+ from ast import AST
13
+ from collections import deque
14
+ from types import CodeType
15
+ from typing import Any, cast, TYPE_CHECKING
16
+
17
+ from .. import consts
18
+ from ..errors import ErrorSink
19
+ from ..optimizer import AstOptimizer
20
+ from ..pycodegen import find_futures
21
+ from ..symbols import SymbolVisitor
22
+ from .declaration_visitor import DeclarationVisitor
23
+ from .module_table import IntrinsicModuleTable, ModuleTable
24
+ from .type_binder import TypeBinder
25
+ from .types import (
26
+ BoxFunction,
27
+ CastFunction,
28
+ Class,
29
+ CRangeFunction,
30
+ ExtremumFunction,
31
+ IdentityDecorator,
32
+ IsInstanceFunction,
33
+ IsSubclassFunction,
34
+ LenFunction,
35
+ NumClass,
36
+ Object,
37
+ ProdAssertFunction,
38
+ reflect_builtin_function,
39
+ RevealTypeFunction,
40
+ SortedFunction,
41
+ TypeEnvironment,
42
+ TypeName,
43
+ UnboxFunction,
44
+ Value,
45
+ )
46
+
47
+
48
+ if TYPE_CHECKING:
49
+ from . import Static310CodeGenerator, StaticCodeGenBase
50
+
51
+ try:
52
+ import xxclassloader
53
+ except ImportError:
54
+ xxclassloader = None
55
+
56
+
57
+ class StrictBuiltins(Object[Class]):
58
+ def __init__(self, builtins: dict[str, Value], type_env: TypeEnvironment) -> None:
59
+ super().__init__(type_env.dict)
60
+ self.builtins = builtins
61
+
62
+ def bind_subscr(
63
+ self,
64
+ node: ast.Subscript,
65
+ type: Value,
66
+ visitor: TypeBinder,
67
+ type_ctx: Class | None = None,
68
+ ) -> None:
69
+ slice = node.slice
70
+ type = visitor.type_env.DYNAMIC
71
+ if isinstance(slice, ast.Constant):
72
+ svalue = slice.value
73
+ if isinstance(svalue, str):
74
+ builtin = self.builtins.get(svalue)
75
+ if builtin is not None:
76
+ type = builtin
77
+
78
+ visitor.set_type(node, type)
79
+
80
+
81
+ class Compiler:
82
+ def __init__(
83
+ self,
84
+ code_generator: type[StaticCodeGenBase],
85
+ error_sink: ErrorSink | None = None,
86
+ ) -> None:
87
+ self.modules: dict[str, ModuleTable] = {}
88
+ self.ast_cache: dict[
89
+ str | bytes | ast.Module | ast.Expression | ast.Interactive, ast.Module
90
+ ] = {}
91
+ self.code_generator = code_generator
92
+ self.error_sink: ErrorSink = error_sink or ErrorSink()
93
+ self.type_env: TypeEnvironment = TypeEnvironment()
94
+ rand_max = NumClass(
95
+ TypeName("builtins", "int"),
96
+ self.type_env,
97
+ pytype=int,
98
+ # pyre-fixme[16]: Module `__static__` has no attribute `RAND_MAX`.
99
+ literal_value=RAND_MAX,
100
+ is_final=True,
101
+ )
102
+ builtins_children = {
103
+ "ArithmeticError": self.type_env.arithmetic_error,
104
+ "AssertionError": self.type_env.assertion_error,
105
+ "AttributeError": self.type_env.attribute_error,
106
+ "BaseException": self.type_env.base_exception.exact_type(),
107
+ "BlockingIOError": self.type_env.blocking_io_error,
108
+ "BrokenPipeError": self.type_env.broken_pipe_error,
109
+ "BufferError": self.type_env.buffer_error,
110
+ "BytesWarning": self.type_env.bytes_warning,
111
+ "ChildProcessError": self.type_env.child_process_error,
112
+ "ConnectionAbortedError": self.type_env.connection_aborted_error,
113
+ "ConnectionError": self.type_env.connection_error,
114
+ "ConnectionRefusedError": self.type_env.connection_refused_error,
115
+ "ConnectionResetError": self.type_env.connection_reset_error,
116
+ "DeprecationWarning": self.type_env.deprecation_warning,
117
+ "EncodingWarning": self.type_env.encoding_warning,
118
+ "EOFError": self.type_env.eof_error,
119
+ "Ellipsis": self.type_env.DYNAMIC,
120
+ "EnvironmentError": self.type_env.environment_error,
121
+ "Exception": self.type_env.exception.exact_type(),
122
+ "FileExistsError": self.type_env.file_exists_error,
123
+ "FileNotFoundError": self.type_env.file_not_found_error,
124
+ "FloatingPointError": self.type_env.floating_point_error,
125
+ "FutureWarning": self.type_env.future_warning,
126
+ "GeneratorExit": self.type_env.generator_exit,
127
+ "IOError": self.type_env.io_error,
128
+ "ImportError": self.type_env.import_error,
129
+ "ImportWarning": self.type_env.import_warning,
130
+ "IndentationError": self.type_env.indentation_error,
131
+ "IndexError": self.type_env.index_error,
132
+ "InterruptedError": self.type_env.interrupted_error,
133
+ "IsADirectoryError": self.type_env.is_a_directory_error,
134
+ "KeyError": self.type_env.key_error,
135
+ "KeyboardInterrupt": self.type_env.keyboard_interrupt,
136
+ "LookupError": self.type_env.lookup_error,
137
+ "MemoryError": self.type_env.memory_error,
138
+ "ModuleNotFoundError": self.type_env.module_not_found_error,
139
+ "NameError": self.type_env.name_error,
140
+ "None": self.type_env.none.instance,
141
+ "NotADirectoryError": self.type_env.not_a_directory_error,
142
+ "NotImplemented": self.type_env.not_implemented,
143
+ "NotImplementedError": self.type_env.not_implemented_error,
144
+ "OSError": self.type_env.os_error,
145
+ "OverflowError": self.type_env.overflow_error,
146
+ "PendingDeprecationWarning": self.type_env.pending_deprecation_warning,
147
+ "PermissionError": self.type_env.permission_error,
148
+ "ProcessLookupError": self.type_env.process_lookup_error,
149
+ "RecursionError": self.type_env.recursion_error,
150
+ "ReferenceError": self.type_env.reference_error,
151
+ "ResourceWarning": self.type_env.resource_warning,
152
+ "RuntimeError": self.type_env.runtime_error,
153
+ "RuntimeWarning": self.type_env.runtime_warning,
154
+ "StopAsyncIteration": self.type_env.stop_async_iteration,
155
+ "StopIteration": self.type_env.stop_iteration,
156
+ "SyntaxError": self.type_env.syntax_error,
157
+ "SyntaxWarning": self.type_env.syntax_warning,
158
+ "SystemError": self.type_env.system_error,
159
+ "SystemExit": self.type_env.system_exit,
160
+ "TabError": self.type_env.tab_error,
161
+ "TimeoutError": self.type_env.timeout_error,
162
+ "TypeError": self.type_env.type_error,
163
+ "UnboundLocalError": self.type_env.unbound_local_error,
164
+ "UnicodeDecodeError": self.type_env.unicode_decode_error,
165
+ "UnicodeEncodeError": self.type_env.unicode_encode_error,
166
+ "UnicodeError": self.type_env.unicode_error,
167
+ "UnicodeTranslateError": self.type_env.unicode_translate_error,
168
+ "UnicodeWarning": self.type_env.unicode_warning,
169
+ "UserWarning": self.type_env.user_warning,
170
+ "ValueError": self.type_env.value_error,
171
+ "Warning": self.type_env.warning,
172
+ "ZeroDivisionError": self.type_env.zero_division_error,
173
+ "__name__": self.type_env.str.instance,
174
+ "__file__": self.type_env.str.instance,
175
+ "bool": self.type_env.bool.exact_type(),
176
+ "bytes": self.type_env.bytes.exact_type(),
177
+ "bytearray": self.type_env.DYNAMIC,
178
+ "classmethod": self.type_env.class_method,
179
+ "complex": self.type_env.complex.exact_type(),
180
+ "delattr": self.type_env.DYNAMIC,
181
+ "dict": self.type_env.dict.exact_type(),
182
+ "enumerate": self.type_env.DYNAMIC,
183
+ "exit": self.type_env.DYNAMIC,
184
+ "float": self.type_env.float.exact_type(),
185
+ "frozenset": self.type_env.frozenset.exact_type(),
186
+ "getattr": self.type_env.DYNAMIC,
187
+ "globals": self.type_env.DYNAMIC,
188
+ "hasattr": self.type_env.DYNAMIC,
189
+ "memoryview": self.type_env.DYNAMIC,
190
+ "int": self.type_env.int.exact_type(),
191
+ "isinstance": IsInstanceFunction(self.type_env),
192
+ "issubclass": IsSubclassFunction(self.type_env),
193
+ "len": LenFunction(self.type_env.function, boxed=True),
194
+ "list": self.type_env.list.exact_type(),
195
+ "locals": self.type_env.DYNAMIC,
196
+ "max": ExtremumFunction(self.type_env.function, is_min=False),
197
+ "min": ExtremumFunction(self.type_env.function, is_min=True),
198
+ "object": self.type_env.object.exact_type(),
199
+ "property": self.type_env.property.exact_type(),
200
+ "quit": self.type_env.DYNAMIC,
201
+ "range": self.type_env.range,
202
+ "reveal_type": RevealTypeFunction(self.type_env),
203
+ "set": self.type_env.set.exact_type(),
204
+ "setattr": self.type_env.DYNAMIC,
205
+ "slice": self.type_env.DYNAMIC,
206
+ "sorted": SortedFunction(self.type_env.function),
207
+ "staticmethod": self.type_env.static_method,
208
+ "str": self.type_env.str.exact_type(),
209
+ "super": self.type_env.super,
210
+ "tuple": self.type_env.tuple.exact_type(),
211
+ "type": self.type_env.type.exact_type(),
212
+ "<mutable>": IdentityDecorator(
213
+ TypeName("__strict__", "<mutable>"), self.type_env
214
+ ),
215
+ "filter": self.type_env.DYNAMIC,
216
+ "map": self.type_env.DYNAMIC,
217
+ "reversed": self.type_env.DYNAMIC,
218
+ "zip": self.type_env.DYNAMIC,
219
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
220
+ "abs": reflect_builtin_function(abs, None, self.type_env),
221
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
222
+ "all": reflect_builtin_function(all, None, self.type_env),
223
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
224
+ "any": reflect_builtin_function(any, None, self.type_env),
225
+ "anext": reflect_builtin_function(anext, None, self.type_env),
226
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
227
+ "ascii": reflect_builtin_function(ascii, None, self.type_env),
228
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
229
+ "bin": reflect_builtin_function(bin, None, self.type_env),
230
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
231
+ "breakpoint": reflect_builtin_function(breakpoint, None, self.type_env),
232
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
233
+ "callable": reflect_builtin_function(callable, None, self.type_env),
234
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
235
+ "chr": reflect_builtin_function(chr, None, self.type_env),
236
+ "compile": reflect_builtin_function(compile, None, self.type_env),
237
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
238
+ "dir": reflect_builtin_function(dir, None, self.type_env),
239
+ "divmod": reflect_builtin_function(divmod, None, self.type_env),
240
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
241
+ "eval": reflect_builtin_function(eval, None, self.type_env),
242
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
243
+ "exec": reflect_builtin_function(exec, None, self.type_env),
244
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
245
+ "format": reflect_builtin_function(format, None, self.type_env),
246
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
247
+ "hash": reflect_builtin_function(hash, None, self.type_env),
248
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
249
+ "hex": reflect_builtin_function(hex, None, self.type_env),
250
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
251
+ "id": reflect_builtin_function(id, None, self.type_env),
252
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
253
+ "input": reflect_builtin_function(input, None, self.type_env),
254
+ "iter": reflect_builtin_function(iter, None, self.type_env),
255
+ "next": reflect_builtin_function(next, None, self.type_env),
256
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
257
+ "oct": reflect_builtin_function(oct, None, self.type_env),
258
+ "open": reflect_builtin_function(open, None, self.type_env),
259
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
260
+ "ord": reflect_builtin_function(ord, None, self.type_env),
261
+ "pow": reflect_builtin_function(pow, None, self.type_env),
262
+ "print": reflect_builtin_function(print, None, self.type_env),
263
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
264
+ "repr": reflect_builtin_function(repr, None, self.type_env),
265
+ "round": reflect_builtin_function(round, None, self.type_env),
266
+ "sum": reflect_builtin_function(sum, None, self.type_env),
267
+ "vars": reflect_builtin_function(vars, None, self.type_env),
268
+ # FIXME: This is IG-specific. Add a way to customize the set of builtins
269
+ # while initializing the loader.
270
+ # List from https://www.internalfb.com/code/fbsource/[5f9467ab16be43bf56aa9d7f18580a14bff36de7]/fbcode/instagram-server/distillery/bootstrap/dev.py?lines=49
271
+ "slog": self.type_env.DYNAMIC,
272
+ "slogo": self.type_env.DYNAMIC,
273
+ "slogb": self.type_env.DYNAMIC,
274
+ "slogg": self.type_env.DYNAMIC,
275
+ "slogv": self.type_env.DYNAMIC,
276
+ "slogp": self.type_env.DYNAMIC,
277
+ "slogy": self.type_env.DYNAMIC,
278
+ "slogr": self.type_env.DYNAMIC,
279
+ "slogdor": self.type_env.DYNAMIC,
280
+ "sloga": self.type_env.DYNAMIC,
281
+ "slogf": self.type_env.DYNAMIC,
282
+ "slogrq": self.type_env.DYNAMIC,
283
+ "slog0": self.type_env.DYNAMIC,
284
+ }
285
+ if import_cycle_error := self.type_env.import_cycle_error:
286
+ builtins_children["ImportCycleError"] = import_cycle_error
287
+
288
+ strict_builtins = StrictBuiltins(builtins_children, self.type_env)
289
+ typing_children = {
290
+ "Annotated": self.type_env.annotated,
291
+ "Any": self.type_env.dynamic,
292
+ "Awaitable": self.type_env.dynamic,
293
+ "Callable": self.type_env.dynamic,
294
+ "Coroutine": self.type_env.dynamic,
295
+ "ClassVar": self.type_env.classvar,
296
+ "Collection": self.type_env.dynamic,
297
+ # TODO: Need typed members for dict
298
+ "Dict": self.type_env.dict,
299
+ "List": self.type_env.list,
300
+ "Final": self.type_env.final,
301
+ "final": self.type_env.final_method,
302
+ "Generic": self.type_env.dynamic,
303
+ "Iterable": self.type_env.dynamic,
304
+ "Iterator": self.type_env.dynamic,
305
+ "Literal": self.type_env.literal,
306
+ "NamedTuple": self.type_env.named_tuple,
307
+ "Protocol": self.type_env.protocol,
308
+ "Optional": self.type_env.optional,
309
+ "overload": self.type_env.overload,
310
+ "Union": self.type_env.union,
311
+ "Tuple": self.type_env.tuple,
312
+ "Type": self.type_env.dynamic,
313
+ "TypedDict": self.type_env.typed_dict,
314
+ "TypeVar": self.type_env.dynamic,
315
+ "TYPE_CHECKING": self.type_env.bool.instance,
316
+ }
317
+ typing_extensions_children: dict[str, Value] = {
318
+ "Annotated": self.type_env.annotated,
319
+ "Protocol": self.type_env.protocol,
320
+ "TypedDict": self.type_env.typed_dict,
321
+ }
322
+ strict_modules_children: dict[str, Value] = {
323
+ "mutable": IdentityDecorator(
324
+ TypeName("__strict__", "mutable"), self.type_env
325
+ ),
326
+ "strict_slots": IdentityDecorator(
327
+ TypeName("__strict__", "strict_slots"), self.type_env
328
+ ),
329
+ "loose_slots": IdentityDecorator(
330
+ TypeName("__strict__", "loose_slots"), self.type_env
331
+ ),
332
+ "freeze_type": IdentityDecorator(
333
+ TypeName("__strict__", "freeze_type"), self.type_env
334
+ ),
335
+ }
336
+
337
+ builtins_children["<builtins>"] = strict_builtins
338
+ self.modules["strict_modules"] = self.modules["__strict__"] = ModuleTable(
339
+ "strict_modules", "<strict-modules>", self, strict_modules_children
340
+ )
341
+ fixed_modules: dict[str, Value] = {
342
+ "typing": StrictBuiltins(typing_children, self.type_env),
343
+ "typing_extensions": StrictBuiltins(
344
+ typing_extensions_children, self.type_env
345
+ ),
346
+ "__strict__": StrictBuiltins(strict_modules_children, self.type_env),
347
+ "strict_modules": StrictBuiltins(
348
+ dict(strict_modules_children), self.type_env
349
+ ),
350
+ }
351
+
352
+ builtins_children["<fixed-modules>"] = StrictBuiltins(
353
+ fixed_modules, self.type_env
354
+ )
355
+
356
+ self.builtins = self.modules["builtins"] = IntrinsicModuleTable(
357
+ "builtins",
358
+ "<builtins>",
359
+ self,
360
+ builtins_children,
361
+ )
362
+ self.typing = self.modules["typing"] = IntrinsicModuleTable(
363
+ "typing", "<typing>", self, typing_children
364
+ )
365
+ self.modules["typing_extensions"] = ModuleTable(
366
+ "typing_extensions", "<typing_extensions>", self, typing_extensions_children
367
+ )
368
+ self.statics = self.modules["__static__"] = IntrinsicModuleTable(
369
+ "__static__",
370
+ "<__static__>",
371
+ self,
372
+ {
373
+ "Array": self.type_env.array,
374
+ "CheckedDict": self.type_env.checked_dict.exact_type(),
375
+ "CheckedList": self.type_env.checked_list.exact_type(),
376
+ "Enum": self.type_env.enum,
377
+ "IntEnum": self.type_env.int_enum,
378
+ "StringEnum": self.type_env.string_enum,
379
+ "allow_weakrefs": self.type_env.allow_weakrefs,
380
+ "box": BoxFunction(self.type_env.function),
381
+ "cast": CastFunction(self.type_env.function),
382
+ "clen": LenFunction(self.type_env.function, boxed=False),
383
+ "crange": CRangeFunction(self.type_env.function),
384
+ "ExcContextDecorator": self.type_env.exc_context_decorator.exact_type(),
385
+ "ContextDecorator": self.type_env.context_decorator.exact_type(),
386
+ "dynamic_return": self.type_env.dynamic_return,
387
+ "size_t": self.type_env.uint64.exact_type(),
388
+ "ssize_t": self.type_env.int64.exact_type(),
389
+ "cbool": self.type_env.cbool.exact_type(),
390
+ "inline": self.type_env.inline,
391
+ # This is a way to disable the static compiler for
392
+ # individual functions/methods
393
+ "_donotcompile": self.type_env.donotcompile,
394
+ "int8": self.type_env.int8.exact_type(),
395
+ "int16": self.type_env.int16.exact_type(),
396
+ "int32": self.type_env.int32.exact_type(),
397
+ "int64": self.type_env.int64.exact_type(),
398
+ "uint8": self.type_env.uint8.exact_type(),
399
+ "uint16": self.type_env.uint16.exact_type(),
400
+ "uint32": self.type_env.uint32.exact_type(),
401
+ "uint64": self.type_env.uint64.exact_type(),
402
+ "char": self.type_env.char.exact_type(),
403
+ "double": self.type_env.double.exact_type(),
404
+ "unbox": UnboxFunction(self.type_env.function),
405
+ "checked_dicts": self.type_env.bool.instance,
406
+ "prod_assert": ProdAssertFunction(self.type_env),
407
+ "pydict": self.type_env.dict.exact_type(),
408
+ "PyDict": self.type_env.dict.exact_type(),
409
+ "RAND_MAX": rand_max.instance,
410
+ "posix_clock_gettime_ns": reflect_builtin_function(
411
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
412
+ posix_clock_gettime_ns,
413
+ None,
414
+ self.type_env,
415
+ ),
416
+ "rand": reflect_builtin_function(
417
+ # pyre-ignore[6]: Pyre can't know this callable is a BuiltinFunctionType
418
+ rand,
419
+ None,
420
+ self.type_env,
421
+ ),
422
+ "set_type_static": self.type_env.DYNAMIC,
423
+ "native": self.type_env.native_decorator,
424
+ "mixin": self.type_env.function.exact_type(),
425
+ "ClassDecorator": self.type_env.class_decorator.exact_type(),
426
+ "TClass": self.type_env.class_typevar.exact_type(),
427
+ },
428
+ )
429
+
430
+ self.modules["dataclasses"] = ModuleTable(
431
+ "dataclasses",
432
+ "Lib/dataclasses.py",
433
+ self,
434
+ {
435
+ "Field": self.type_env.dataclass_field,
436
+ "InitVar": self.type_env.initvar,
437
+ "dataclass": self.type_env.dataclass,
438
+ "field": self.type_env.dataclass_field_function,
439
+ },
440
+ )
441
+
442
+ self.modules["cinder"] = self.modules["cinderx"] = ModuleTable(
443
+ "cinder",
444
+ "<cinder>",
445
+ self,
446
+ {
447
+ "cached_property": self.type_env.cached_property,
448
+ "async_cached_property": self.type_env.async_cached_property,
449
+ },
450
+ )
451
+
452
+ if xxclassloader is not None:
453
+ spam_obj = self.type_env.spam_obj
454
+ assert spam_obj is not None
455
+ if hasattr(xxclassloader, "foo"):
456
+ funcs = {
457
+ "foo": reflect_builtin_function(
458
+ xxclassloader.foo,
459
+ None,
460
+ self.type_env,
461
+ ),
462
+ "bar": reflect_builtin_function(
463
+ xxclassloader.bar,
464
+ None,
465
+ self.type_env,
466
+ ),
467
+ "neg": reflect_builtin_function(
468
+ xxclassloader.neg,
469
+ None,
470
+ self.type_env,
471
+ ),
472
+ }
473
+ else:
474
+ funcs = {}
475
+
476
+ self.modules["xxclassloader"] = ModuleTable(
477
+ "xxclassloader",
478
+ "<xxclassloader>",
479
+ self,
480
+ {
481
+ "spamobj": spam_obj.exact_type(),
482
+ "XXGeneric": self.type_env.xx_generic.exact_type(),
483
+ **funcs,
484
+ },
485
+ )
486
+
487
+ self.intrinsic_modules: set[str] = set(self.modules.keys())
488
+ self.decl_visitors: deque[DeclarationVisitor] = deque()
489
+
490
+ def __getitem__(self, name: str) -> ModuleTable:
491
+ return self.modules[name]
492
+
493
+ def __setitem__(self, name: str, value: ModuleTable) -> None:
494
+ self.modules[name] = value
495
+
496
+ def add_module(
497
+ self,
498
+ name: str,
499
+ filename: str,
500
+ tree: AST,
501
+ source: str | bytes | ast.Module | ast.Expression | ast.Interactive,
502
+ optimize: int,
503
+ ) -> ast.Module:
504
+ optimized = AstOptimizer(optimize=optimize > 0).visit(tree)
505
+ assert isinstance(optimized, ast.Module)
506
+ tree = optimized
507
+
508
+ self.ast_cache[source] = tree
509
+
510
+ # Track if we're the first module being compiled, if we are then
511
+ # we want to finish up the validation of all of the modules that
512
+ # are imported and compiled for the first time because they were
513
+ # imported from this module, this is a little bit odd because we
514
+ # need to finish_bind first before we can validate the overrides
515
+ # and we may have circular references between modules.
516
+ validate_classes = not self.decl_visitors
517
+ decl_visit = DeclarationVisitor(name, filename, self, optimize)
518
+ self.decl_visitors.append(decl_visit)
519
+ decl_visit.visit(tree)
520
+ decl_visit.finish_bind()
521
+
522
+ if validate_classes:
523
+ # Validate that the overrides for all of the modules we
524
+ # have compiled from this top-level module.
525
+ while self.decl_visitors:
526
+ decl_visit = self.decl_visitors.popleft()
527
+ decl_visit.module.validate_overrides()
528
+
529
+ return tree
530
+
531
+ def bind(
532
+ self,
533
+ name: str,
534
+ filename: str,
535
+ tree: AST,
536
+ source: str | bytes,
537
+ optimize: int,
538
+ enable_patching: bool = False,
539
+ ) -> None:
540
+ self._bind(name, filename, tree, source, optimize, enable_patching)
541
+
542
+ def _bind(
543
+ self,
544
+ name: str,
545
+ filename: str,
546
+ tree: AST,
547
+ source: str | bytes | ast.Module | ast.Expression | ast.Interactive,
548
+ optimize: int,
549
+ enable_patching: bool = False,
550
+ ) -> tuple[ast.Module, SymbolVisitor]:
551
+ cached_tree = self.ast_cache.get(source)
552
+ if cached_tree is None:
553
+ tree = self.add_module(name, filename, tree, source, optimize)
554
+ else:
555
+ tree = cached_tree
556
+ # Analyze variable scopes
557
+ future_flags = find_futures(0, tree)
558
+ # TASK(TT209531178): This class still implicitly assumes 3.10
559
+ code_generator = cast("Static310CodeGenerator", self.code_generator)
560
+ s = code_generator._SymbolVisitor(future_flags)
561
+ s.visit(tree)
562
+
563
+ # Analyze the types of objects within local scopes
564
+ type_binder = TypeBinder(
565
+ s,
566
+ filename,
567
+ self,
568
+ name,
569
+ optimize,
570
+ enable_patching=enable_patching,
571
+ )
572
+ type_binder.visit(tree)
573
+ return tree, s
574
+
575
+ def compile(
576
+ self,
577
+ name: str,
578
+ filename: str,
579
+ tree: AST,
580
+ source: str | bytes,
581
+ optimize: int,
582
+ enable_patching: bool = False,
583
+ builtins: dict[str, Any] = builtins.__dict__,
584
+ ) -> CodeType:
585
+ code_gen = self.code_gen(
586
+ name, filename, tree, source, optimize, enable_patching, builtins
587
+ )
588
+ return code_gen.getCode()
589
+
590
+ def code_gen(
591
+ self,
592
+ name: str,
593
+ filename: str,
594
+ tree: AST,
595
+ source: str | bytes | ast.Module | ast.Expression | ast.Interactive,
596
+ optimize: int,
597
+ enable_patching: bool = False,
598
+ builtins: dict[str, Any] = builtins.__dict__,
599
+ ) -> Static310CodeGenerator:
600
+ tree, s = self._bind(name, filename, tree, source, optimize, enable_patching)
601
+ if self.error_sink.has_errors:
602
+ raise self.error_sink.errors[0]
603
+
604
+ # Compile the code w/ the static compiler
605
+ graph = self.code_generator.flow_graph(name, filename, s.scopes[tree])
606
+ graph.setFlag(consts.CI_CO_STATICALLY_COMPILED)
607
+ graph.extra_consts.append(tuple(self.modules[name].imported_from.items()))
608
+
609
+ future_flags = find_futures(0, tree)
610
+
611
+ code_gen = self.code_generator(
612
+ None,
613
+ tree,
614
+ s,
615
+ graph,
616
+ self,
617
+ name,
618
+ flags=0,
619
+ optimization_lvl=optimize,
620
+ enable_patching=enable_patching,
621
+ builtins=builtins,
622
+ future_flags=future_flags,
623
+ )
624
+ code_gen.visit(tree)
625
+ del self.ast_cache[source]
626
+ return cast("Static310CodeGenerator", code_gen)
627
+
628
+ def import_module(self, name: str, optimize: int) -> ModuleTable | None:
629
+ pass