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.
- __static__/__init__.py +641 -0
- __static__/compiler_flags.py +8 -0
- __static__/enum.py +160 -0
- __static__/native_utils.py +77 -0
- __static__/type_code.py +48 -0
- __strict__/__init__.py +39 -0
- _cinderx.so +0 -0
- cinderx/__init__.py +577 -0
- cinderx/__pycache__/__init__.cpython-314.pyc +0 -0
- cinderx/_asyncio.py +156 -0
- cinderx/compileall.py +710 -0
- cinderx/compiler/__init__.py +40 -0
- cinderx/compiler/__main__.py +137 -0
- cinderx/compiler/config.py +7 -0
- cinderx/compiler/consts.py +72 -0
- cinderx/compiler/debug.py +70 -0
- cinderx/compiler/dis_stable.py +283 -0
- cinderx/compiler/errors.py +151 -0
- cinderx/compiler/flow_graph_optimizer.py +1287 -0
- cinderx/compiler/future.py +91 -0
- cinderx/compiler/misc.py +32 -0
- cinderx/compiler/opcode_cinder.py +18 -0
- cinderx/compiler/opcode_static.py +100 -0
- cinderx/compiler/opcodebase.py +158 -0
- cinderx/compiler/opcodes.py +991 -0
- cinderx/compiler/optimizer.py +547 -0
- cinderx/compiler/pyassem.py +3711 -0
- cinderx/compiler/pycodegen.py +7660 -0
- cinderx/compiler/pysourceloader.py +62 -0
- cinderx/compiler/static/__init__.py +1404 -0
- cinderx/compiler/static/compiler.py +629 -0
- cinderx/compiler/static/declaration_visitor.py +335 -0
- cinderx/compiler/static/definite_assignment_checker.py +280 -0
- cinderx/compiler/static/effects.py +160 -0
- cinderx/compiler/static/module_table.py +666 -0
- cinderx/compiler/static/type_binder.py +2176 -0
- cinderx/compiler/static/types.py +10580 -0
- cinderx/compiler/static/util.py +81 -0
- cinderx/compiler/static/visitor.py +91 -0
- cinderx/compiler/strict/__init__.py +69 -0
- cinderx/compiler/strict/class_conflict_checker.py +249 -0
- cinderx/compiler/strict/code_gen_base.py +409 -0
- cinderx/compiler/strict/common.py +507 -0
- cinderx/compiler/strict/compiler.py +352 -0
- cinderx/compiler/strict/feature_extractor.py +130 -0
- cinderx/compiler/strict/flag_extractor.py +97 -0
- cinderx/compiler/strict/loader.py +827 -0
- cinderx/compiler/strict/preprocessor.py +11 -0
- cinderx/compiler/strict/rewriter/__init__.py +5 -0
- cinderx/compiler/strict/rewriter/remove_annotations.py +84 -0
- cinderx/compiler/strict/rewriter/rewriter.py +975 -0
- cinderx/compiler/strict/runtime.py +77 -0
- cinderx/compiler/symbols.py +1754 -0
- cinderx/compiler/unparse.py +414 -0
- cinderx/compiler/visitor.py +194 -0
- cinderx/jit.py +230 -0
- cinderx/opcode.py +202 -0
- cinderx/static.py +113 -0
- cinderx/strictmodule.py +6 -0
- cinderx/test_support.py +341 -0
- cinderx-2026.1.16.2.dist-info/METADATA +15 -0
- cinderx-2026.1.16.2.dist-info/RECORD +68 -0
- cinderx-2026.1.16.2.dist-info/WHEEL +6 -0
- cinderx-2026.1.16.2.dist-info/licenses/LICENSE +21 -0
- cinderx-2026.1.16.2.dist-info/top_level.txt +5 -0
- opcodes/__init__.py +0 -0
- opcodes/assign_opcode_numbers.py +272 -0
- opcodes/cinderx_opcodes.py +121 -0
cinderx/_asyncio.py
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
# pyre-strict
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from asyncio import AbstractEventLoop, CancelledError, Future, get_event_loop
|
|
7
|
+
from collections.abc import Awaitable, Callable, Generator
|
|
8
|
+
from typing import NoReturn, Optional, TypeVar
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
# pyre-ignore[21]: Unknwn import
|
|
13
|
+
from _cinderx import AsyncLazyValue, AwaitableValue
|
|
14
|
+
except ImportError:
|
|
15
|
+
|
|
16
|
+
class _AsyncLazyValueState:
|
|
17
|
+
NotStarted = 0
|
|
18
|
+
Running = 1
|
|
19
|
+
Done = 2
|
|
20
|
+
|
|
21
|
+
_TParams = TypeVar("_TParams")
|
|
22
|
+
_T = TypeVar("_T", covariant=True)
|
|
23
|
+
|
|
24
|
+
class AsyncLazyValue(Awaitable[_T]):
|
|
25
|
+
"""
|
|
26
|
+
This is a low-level class used mainly for two things:
|
|
27
|
+
* It helps to avoid calling a coroutine multiple times, by caching the
|
|
28
|
+
result of a previous call
|
|
29
|
+
* It ensures that the coroutine is called only once
|
|
30
|
+
|
|
31
|
+
AsyncLazyValue has well defined cancellation behavior in these cases:
|
|
32
|
+
|
|
33
|
+
1. When we have a single task stack (call stack for you JS folks), which is
|
|
34
|
+
awaiting on the AsyncLazyValue
|
|
35
|
+
-> In this case, we mimic the behavior of a normal await. i.e: If the
|
|
36
|
+
task stack gets cancelled, we cancel the coroutine (by raising a
|
|
37
|
+
CancelledError in the underlying future)
|
|
38
|
+
|
|
39
|
+
2. When we have multiple task stacks awaiting on the future.
|
|
40
|
+
We have two sub cases here.
|
|
41
|
+
|
|
42
|
+
2.1. The initial task stack (which resulted in an await of the coroutine)
|
|
43
|
+
gets cancelled.
|
|
44
|
+
-> In this case, we cancel the coroutine, and all the tasks depending
|
|
45
|
+
on it. If we don't do that, we'd have to implement retry logic,
|
|
46
|
+
which is a bad idea in such low level code. Even if we do implement
|
|
47
|
+
retries, there's no guarantee that they would succeed, so it's better
|
|
48
|
+
to just fail here.
|
|
49
|
+
|
|
50
|
+
Also, the number of times this happens is very small (I don't have
|
|
51
|
+
data to prove it, but qualitative arguments suggest this is the
|
|
52
|
+
case).
|
|
53
|
+
|
|
54
|
+
2.2. One of the many task stacks gets cancelled (but not the one which ended
|
|
55
|
+
up awaiting the coroutine)
|
|
56
|
+
-> In this case, we just allow the task stack to be cancelled, but
|
|
57
|
+
the rest of them are processed without being affected.
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
def __init__(
|
|
61
|
+
self,
|
|
62
|
+
# pyre-fixme[31]: Expression `typing.Callable[(_TParams,
|
|
63
|
+
# typing.Awaitable[_T])]` is not a valid type.
|
|
64
|
+
coro_func: Callable[_TParams, Awaitable[_T]],
|
|
65
|
+
# pyre-fixme[11]: Annotation `args` is not defined as a type.
|
|
66
|
+
*args: _TParams.args,
|
|
67
|
+
# pyre-fixme[11]: Annotation `kwargs` is not defined as a type.
|
|
68
|
+
**kwargs: _TParams.kwargs,
|
|
69
|
+
) -> None:
|
|
70
|
+
# pyre-fixme[31]: Expression `typing.Optional[typing.Callable[(_TParams,
|
|
71
|
+
# typing.Awaitable[_T])]]` is not a valid type.
|
|
72
|
+
self.coro_func: Optional[Callable[_TParams, Awaitable[_T]]] = coro_func
|
|
73
|
+
self.args: tuple[object, ...] = args
|
|
74
|
+
self.kwargs: dict[str, object] = kwargs
|
|
75
|
+
self.state: int = _AsyncLazyValueState.NotStarted
|
|
76
|
+
self.res: Optional[_T] = None
|
|
77
|
+
self._futures: list[Future] = []
|
|
78
|
+
self._awaiting_tasks = 0
|
|
79
|
+
|
|
80
|
+
async def _async_compute(self) -> _T:
|
|
81
|
+
futures = self._futures
|
|
82
|
+
try:
|
|
83
|
+
coro_func = self.coro_func
|
|
84
|
+
# lint-fixme: NoAssertsRule
|
|
85
|
+
assert coro_func is not None
|
|
86
|
+
self.res = res = await coro_func(*self.args, **self.kwargs)
|
|
87
|
+
|
|
88
|
+
self.state = _AsyncLazyValueState.Done
|
|
89
|
+
|
|
90
|
+
# pyre-ignore[1001]: Pyre is worried about how we're accessing futures
|
|
91
|
+
# without awaiting them.
|
|
92
|
+
for value in futures:
|
|
93
|
+
if not value.done():
|
|
94
|
+
value.set_result(self.res)
|
|
95
|
+
|
|
96
|
+
self.args = ()
|
|
97
|
+
self.kwargs.clear()
|
|
98
|
+
del self._futures[:]
|
|
99
|
+
self.coro_func = None
|
|
100
|
+
|
|
101
|
+
return res
|
|
102
|
+
|
|
103
|
+
except (Exception, CancelledError) as e:
|
|
104
|
+
# pyre-ignore[1001]: Pyre is worried about how we're accessing futures
|
|
105
|
+
# without awaiting them.
|
|
106
|
+
for value in futures:
|
|
107
|
+
if not value.done():
|
|
108
|
+
value.set_exception(e)
|
|
109
|
+
self._futures = []
|
|
110
|
+
self.state = _AsyncLazyValueState.NotStarted
|
|
111
|
+
raise
|
|
112
|
+
|
|
113
|
+
def _get_future(self, loop: Optional[AbstractEventLoop]) -> Future:
|
|
114
|
+
if loop is None:
|
|
115
|
+
loop = get_event_loop()
|
|
116
|
+
f = Future(loop=loop)
|
|
117
|
+
self._futures.append(f)
|
|
118
|
+
self._awaiting_tasks += 1
|
|
119
|
+
return f
|
|
120
|
+
|
|
121
|
+
def __iter__(self) -> AsyncLazyValue[_T]:
|
|
122
|
+
return self
|
|
123
|
+
|
|
124
|
+
def __next__(self) -> NoReturn:
|
|
125
|
+
raise StopIteration(self.res)
|
|
126
|
+
|
|
127
|
+
def __await__(self) -> Generator[None, None, _T]:
|
|
128
|
+
if self.state == _AsyncLazyValueState.Done:
|
|
129
|
+
# pyre-ignore[7]: Expected `Generator[None, None, Variable[_T](covariant)]`
|
|
130
|
+
# but got `_AsyncLazyValue[Variable[_T](covariant)]`.
|
|
131
|
+
return self
|
|
132
|
+
elif self.state == _AsyncLazyValueState.Running:
|
|
133
|
+
c = self._get_future(None)
|
|
134
|
+
return c.__await__()
|
|
135
|
+
else:
|
|
136
|
+
self.state = _AsyncLazyValueState.Running
|
|
137
|
+
c = self._async_compute()
|
|
138
|
+
return c.__await__()
|
|
139
|
+
|
|
140
|
+
def as_future(self, loop: AbstractEventLoop) -> Future:
|
|
141
|
+
if self.state == _AsyncLazyValueState.Done:
|
|
142
|
+
f = Future(loop=loop)
|
|
143
|
+
f.set_result(self.res)
|
|
144
|
+
return f
|
|
145
|
+
elif self.state == _AsyncLazyValueState.Running:
|
|
146
|
+
return self._get_future(loop)
|
|
147
|
+
else:
|
|
148
|
+
if loop is None:
|
|
149
|
+
loop = get_event_loop()
|
|
150
|
+
t = loop.create_task(self._async_compute())
|
|
151
|
+
self.state = _AsyncLazyValueState.Running
|
|
152
|
+
# pyre-ignore[16]: Undefined attribute `asyncio.tasks.Task`
|
|
153
|
+
# has no attribute `_source_traceback`.
|
|
154
|
+
if t._source_traceback:
|
|
155
|
+
del t._source_traceback[-1]
|
|
156
|
+
return t
|