cinderx 2026.1.16.0__tar.gz
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.
- cinderx-2026.1.16.0/LICENSE +21 -0
- cinderx-2026.1.16.0/PKG-INFO +15 -0
- cinderx-2026.1.16.0/README.md +19 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/__static__/__init__.py +641 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/__static__/compiler_flags.py +8 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/__static__/enum.py +160 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/__static__/native_utils.py +77 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/__static__/type_code.py +48 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/__strict__/__init__.py +39 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/__init__.py +577 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/_asyncio.py +156 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compileall.py +710 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/__init__.py +40 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/__main__.py +137 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/config.py +7 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/consts.py +72 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/debug.py +70 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/dis_stable.py +283 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/errors.py +151 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/flow_graph_optimizer.py +1287 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/future.py +91 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/misc.py +32 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/opcode_cinder.py +18 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/opcode_static.py +100 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/opcodebase.py +158 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/opcodes.py +991 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/optimizer.py +547 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/pyassem.py +3711 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/pycodegen.py +7660 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/pysourceloader.py +62 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/static/__init__.py +1404 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/static/compiler.py +629 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/static/declaration_visitor.py +335 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/static/definite_assignment_checker.py +280 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/static/effects.py +160 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/static/module_table.py +666 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/static/type_binder.py +2176 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/static/types.py +10580 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/static/util.py +81 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/static/visitor.py +91 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/strict/__init__.py +69 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/strict/class_conflict_checker.py +249 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/strict/code_gen_base.py +409 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/strict/common.py +507 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/strict/compiler.py +352 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/strict/feature_extractor.py +130 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/strict/flag_extractor.py +97 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/strict/loader.py +827 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/strict/preprocessor.py +11 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/strict/rewriter/__init__.py +5 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/strict/rewriter/remove_annotations.py +84 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/strict/rewriter/rewriter.py +975 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/strict/runtime.py +77 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/symbols.py +1754 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/unparse.py +414 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/compiler/visitor.py +194 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/jit.py +230 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/static.py +113 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/strictmodule.py +6 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx/test_support.py +341 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx.egg-info/PKG-INFO +15 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx.egg-info/SOURCES.txt +67 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx.egg-info/dependency_links.txt +1 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/cinderx.egg-info/top_level.txt +5 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/opcodes/__init__.py +0 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/opcodes/assign_opcode_numbers.py +272 -0
- cinderx-2026.1.16.0/cinderx/PythonLib/opcodes/cinderx_opcodes.py +121 -0
- cinderx-2026.1.16.0/setup.cfg +4 -0
- cinderx-2026.1.16.0/setup.py +493 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cinderx
|
|
3
|
+
Version: 2026.1.16.0
|
|
4
|
+
Summary: High-performance Python runtime extension
|
|
5
|
+
Home-page: https://www.github.com/facebookincubator/cinderx
|
|
6
|
+
Classifier: Development Status :: 3 - Alpha
|
|
7
|
+
Classifier: Intended Audience :: Developers
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Requires-Python: >=3.14,<3.16
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Dynamic: classifier
|
|
12
|
+
Dynamic: home-page
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
Dynamic: requires-python
|
|
15
|
+
Dynamic: summary
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# CinderX
|
|
2
|
+
|
|
3
|
+
High-performance Python runtime extensions
|
|
4
|
+
|
|
5
|
+
Note: currently the only way to use Cinder is as an [alternative CPython runtime](https://github.com/facebookincubator/cinder),
|
|
6
|
+
which isn't [officially supported](https://github.com/facebookincubator/cinder#is-this-supported).
|
|
7
|
+
This extension is a work-in-progress aimed at extracting parts of Cinder as a pip-installable extension.
|
|
8
|
+
|
|
9
|
+
## License
|
|
10
|
+
CinderX is MIT licensed, as found in the LICENSE file.
|
|
11
|
+
|
|
12
|
+
## Terms of Use
|
|
13
|
+
https://opensource.fb.com/legal/terms
|
|
14
|
+
|
|
15
|
+
## Privacy Policy
|
|
16
|
+
https://opensource.fb.com/legal/privacy
|
|
17
|
+
|
|
18
|
+
##
|
|
19
|
+
Copyright © 2025 Meta Platforms, Inc.
|
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
# pyre-unsafe
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import functools
|
|
7
|
+
import random
|
|
8
|
+
import time
|
|
9
|
+
from asyncio import iscoroutinefunction
|
|
10
|
+
from types import UnionType as typesUnion
|
|
11
|
+
|
|
12
|
+
# pyre-ignore[21]: No _GenericAlias, _tp_cache
|
|
13
|
+
from typing import (
|
|
14
|
+
_GenericAlias,
|
|
15
|
+
_tp_cache,
|
|
16
|
+
Dict,
|
|
17
|
+
final,
|
|
18
|
+
Literal,
|
|
19
|
+
Protocol,
|
|
20
|
+
Type,
|
|
21
|
+
TypeVar,
|
|
22
|
+
Union,
|
|
23
|
+
)
|
|
24
|
+
from weakref import WeakValueDictionary
|
|
25
|
+
|
|
26
|
+
from .enum import Enum, IntEnum, StringEnum # noqa: F401
|
|
27
|
+
from .type_code import ( # noqa: F401
|
|
28
|
+
type_code,
|
|
29
|
+
TYPED_BOOL,
|
|
30
|
+
TYPED_CHAR,
|
|
31
|
+
TYPED_DOUBLE,
|
|
32
|
+
TYPED_INT16,
|
|
33
|
+
TYPED_INT32,
|
|
34
|
+
TYPED_INT64,
|
|
35
|
+
TYPED_INT8,
|
|
36
|
+
TYPED_INT_64BIT,
|
|
37
|
+
TYPED_OBJECT,
|
|
38
|
+
TYPED_SINGLE,
|
|
39
|
+
TYPED_UINT16,
|
|
40
|
+
TYPED_UINT32,
|
|
41
|
+
TYPED_UINT64,
|
|
42
|
+
TYPED_UINT8,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
chkdict = dict[TypeVar("K"), TypeVar("V")]
|
|
46
|
+
chklist = list[TypeVar("V")]
|
|
47
|
+
|
|
48
|
+
FAST_LEN_ARRAY = 0
|
|
49
|
+
FAST_LEN_DICT = 0
|
|
50
|
+
FAST_LEN_INEXACT = 0
|
|
51
|
+
FAST_LEN_LIST = 0
|
|
52
|
+
FAST_LEN_SET = 0
|
|
53
|
+
FAST_LEN_STR = 0
|
|
54
|
+
FAST_LEN_TUPLE = 0
|
|
55
|
+
PRIM_OP_ADD_DBL = 0
|
|
56
|
+
PRIM_OP_ADD_INT = 0
|
|
57
|
+
PRIM_OP_AND_INT = 0
|
|
58
|
+
PRIM_OP_DIV_DBL = 0
|
|
59
|
+
PRIM_OP_DIV_INT = 0
|
|
60
|
+
PRIM_OP_DIV_UN_INT = 0
|
|
61
|
+
PRIM_OP_EQ_DBL = 0
|
|
62
|
+
PRIM_OP_EQ_INT = 0
|
|
63
|
+
PRIM_OP_GE_DBL = 0
|
|
64
|
+
PRIM_OP_GE_INT = 0
|
|
65
|
+
PRIM_OP_GE_UN_INT = 0
|
|
66
|
+
PRIM_OP_GT_DBL = 0
|
|
67
|
+
PRIM_OP_GT_INT = 0
|
|
68
|
+
PRIM_OP_GT_UN_INT = 0
|
|
69
|
+
PRIM_OP_INV_INT = 0
|
|
70
|
+
PRIM_OP_LE_DBL = 0
|
|
71
|
+
PRIM_OP_LE_INT = 0
|
|
72
|
+
PRIM_OP_LE_UN_INT = 0
|
|
73
|
+
PRIM_OP_LSHIFT_INT = 0
|
|
74
|
+
PRIM_OP_LT_DBL = 0
|
|
75
|
+
PRIM_OP_LT_INT = 0
|
|
76
|
+
PRIM_OP_LT_UN_INT = 0
|
|
77
|
+
PRIM_OP_MOD_DBL = 0
|
|
78
|
+
PRIM_OP_MOD_INT = 0
|
|
79
|
+
PRIM_OP_MOD_UN_INT = 0
|
|
80
|
+
PRIM_OP_MUL_DBL = 0
|
|
81
|
+
PRIM_OP_MUL_INT = 0
|
|
82
|
+
PRIM_OP_NE_DBL = 0
|
|
83
|
+
PRIM_OP_NE_INT = 0
|
|
84
|
+
PRIM_OP_NEG_DBL = 0
|
|
85
|
+
PRIM_OP_NEG_INT = 0
|
|
86
|
+
PRIM_OP_NOT_INT = 0
|
|
87
|
+
PRIM_OP_OR_INT = 0
|
|
88
|
+
PRIM_OP_POW_DBL = 0
|
|
89
|
+
PRIM_OP_POW_INT = 0
|
|
90
|
+
PRIM_OP_POW_UN_INT = 0
|
|
91
|
+
PRIM_OP_RSHIFT_INT = 0
|
|
92
|
+
PRIM_OP_RSHIFT_UN_INT = 0
|
|
93
|
+
PRIM_OP_SUB_DBL = 0
|
|
94
|
+
PRIM_OP_SUB_INT = 0
|
|
95
|
+
PRIM_OP_XOR_INT = 0
|
|
96
|
+
SEQ_ARRAY_INT64 = 0
|
|
97
|
+
SEQ_CHECKED_LIST = 0
|
|
98
|
+
SEQ_LIST = 0
|
|
99
|
+
SEQ_LIST_INEXACT = 0
|
|
100
|
+
SEQ_REPEAT_INEXACT_NUM = 0
|
|
101
|
+
SEQ_REPEAT_INEXACT_SEQ = 0
|
|
102
|
+
SEQ_REPEAT_PRIMITIVE_NUM = 0
|
|
103
|
+
SEQ_REPEAT_REVERSED = 0
|
|
104
|
+
SEQ_SUBSCR_UNCHECKED = 0
|
|
105
|
+
SEQ_TUPLE = 0
|
|
106
|
+
|
|
107
|
+
try: # noqa: C901
|
|
108
|
+
from cinderx.static import ( # noqa: F401
|
|
109
|
+
__build_cinder_class__,
|
|
110
|
+
chkdict,
|
|
111
|
+
chklist,
|
|
112
|
+
FAST_LEN_ARRAY,
|
|
113
|
+
FAST_LEN_DICT,
|
|
114
|
+
FAST_LEN_INEXACT,
|
|
115
|
+
FAST_LEN_LIST,
|
|
116
|
+
FAST_LEN_SET,
|
|
117
|
+
FAST_LEN_STR,
|
|
118
|
+
FAST_LEN_TUPLE,
|
|
119
|
+
is_static_callable,
|
|
120
|
+
is_static_module,
|
|
121
|
+
is_type_static,
|
|
122
|
+
make_context_decorator_wrapper,
|
|
123
|
+
make_recreate_cm,
|
|
124
|
+
posix_clock_gettime_ns,
|
|
125
|
+
PRIM_OP_ADD_DBL,
|
|
126
|
+
PRIM_OP_ADD_INT,
|
|
127
|
+
PRIM_OP_AND_INT,
|
|
128
|
+
PRIM_OP_DIV_DBL,
|
|
129
|
+
PRIM_OP_DIV_INT,
|
|
130
|
+
PRIM_OP_DIV_UN_INT,
|
|
131
|
+
PRIM_OP_EQ_DBL,
|
|
132
|
+
PRIM_OP_EQ_INT,
|
|
133
|
+
PRIM_OP_GE_DBL,
|
|
134
|
+
PRIM_OP_GE_INT,
|
|
135
|
+
PRIM_OP_GE_UN_INT,
|
|
136
|
+
PRIM_OP_GT_DBL,
|
|
137
|
+
PRIM_OP_GT_INT,
|
|
138
|
+
PRIM_OP_GT_UN_INT,
|
|
139
|
+
PRIM_OP_INV_INT,
|
|
140
|
+
PRIM_OP_LE_DBL,
|
|
141
|
+
PRIM_OP_LE_INT,
|
|
142
|
+
PRIM_OP_LE_UN_INT,
|
|
143
|
+
PRIM_OP_LSHIFT_INT,
|
|
144
|
+
PRIM_OP_LT_DBL,
|
|
145
|
+
PRIM_OP_LT_INT,
|
|
146
|
+
PRIM_OP_LT_UN_INT,
|
|
147
|
+
PRIM_OP_MOD_DBL,
|
|
148
|
+
PRIM_OP_MOD_INT,
|
|
149
|
+
PRIM_OP_MOD_UN_INT,
|
|
150
|
+
PRIM_OP_MUL_DBL,
|
|
151
|
+
PRIM_OP_MUL_INT,
|
|
152
|
+
PRIM_OP_NE_DBL,
|
|
153
|
+
PRIM_OP_NE_INT,
|
|
154
|
+
PRIM_OP_NEG_DBL,
|
|
155
|
+
PRIM_OP_NEG_INT,
|
|
156
|
+
PRIM_OP_NOT_INT,
|
|
157
|
+
PRIM_OP_OR_INT,
|
|
158
|
+
PRIM_OP_POW_DBL,
|
|
159
|
+
PRIM_OP_POW_INT,
|
|
160
|
+
PRIM_OP_POW_UN_INT,
|
|
161
|
+
PRIM_OP_RSHIFT_INT,
|
|
162
|
+
PRIM_OP_RSHIFT_UN_INT,
|
|
163
|
+
PRIM_OP_SUB_DBL,
|
|
164
|
+
PRIM_OP_SUB_INT,
|
|
165
|
+
PRIM_OP_XOR_INT,
|
|
166
|
+
rand,
|
|
167
|
+
RAND_MAX,
|
|
168
|
+
SEQ_ARRAY_INT64,
|
|
169
|
+
SEQ_CHECKED_LIST,
|
|
170
|
+
SEQ_LIST,
|
|
171
|
+
SEQ_LIST_INEXACT,
|
|
172
|
+
SEQ_REPEAT_INEXACT_NUM,
|
|
173
|
+
SEQ_REPEAT_INEXACT_SEQ,
|
|
174
|
+
SEQ_REPEAT_PRIMITIVE_NUM,
|
|
175
|
+
SEQ_REPEAT_REVERSED,
|
|
176
|
+
SEQ_SUBSCR_UNCHECKED,
|
|
177
|
+
SEQ_TUPLE,
|
|
178
|
+
set_type_final,
|
|
179
|
+
set_type_static,
|
|
180
|
+
set_type_static_final,
|
|
181
|
+
staticarray,
|
|
182
|
+
StaticTypeError,
|
|
183
|
+
)
|
|
184
|
+
except ImportError:
|
|
185
|
+
RAND_MAX = (1 << 31) - 1
|
|
186
|
+
__build_cinder_class__ = __build_class__
|
|
187
|
+
static = None
|
|
188
|
+
|
|
189
|
+
def is_type_static(_t):
|
|
190
|
+
return False
|
|
191
|
+
|
|
192
|
+
def is_static_module(_m):
|
|
193
|
+
return False
|
|
194
|
+
|
|
195
|
+
def is_static_callable(_c):
|
|
196
|
+
return False
|
|
197
|
+
|
|
198
|
+
def make_recreate_cm(_typ):
|
|
199
|
+
def _recreate_cm(self):
|
|
200
|
+
return self
|
|
201
|
+
|
|
202
|
+
return _recreate_cm
|
|
203
|
+
|
|
204
|
+
def make_context_decorator_wrapper(decorator, wrapper_func, wrapped_func):
|
|
205
|
+
return wrapper_func
|
|
206
|
+
|
|
207
|
+
def posix_clock_gettime_ns():
|
|
208
|
+
return time.clock_gettime_ns(time.CLOCK_MONOTONIC)
|
|
209
|
+
|
|
210
|
+
def rand():
|
|
211
|
+
return random.randint(0, RAND_MAX)
|
|
212
|
+
|
|
213
|
+
def set_type_final(_t):
|
|
214
|
+
return _t
|
|
215
|
+
|
|
216
|
+
def set_type_static(_t):
|
|
217
|
+
return _t
|
|
218
|
+
|
|
219
|
+
def set_type_static_final(_t):
|
|
220
|
+
return _t
|
|
221
|
+
|
|
222
|
+
class staticarray:
|
|
223
|
+
def __init__(self, size: int) -> None:
|
|
224
|
+
self._data = [0 for _ in range(size)]
|
|
225
|
+
|
|
226
|
+
def __getitem__(self, idx: int) -> None:
|
|
227
|
+
return self._data[idx]
|
|
228
|
+
|
|
229
|
+
def __setitem__(self, idx: int, val: int) -> None:
|
|
230
|
+
self._data[idx] = val
|
|
231
|
+
|
|
232
|
+
def __len__(self) -> int:
|
|
233
|
+
return len(self._data)
|
|
234
|
+
|
|
235
|
+
def __class_getitem__(cls, key) -> type[staticarray]:
|
|
236
|
+
return staticarray
|
|
237
|
+
|
|
238
|
+
class StaticTypeError(TypeError):
|
|
239
|
+
pass
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
try:
|
|
243
|
+
import cinder
|
|
244
|
+
except ImportError:
|
|
245
|
+
cinder = None
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
pydict = dict
|
|
249
|
+
PyDict = Dict
|
|
250
|
+
|
|
251
|
+
clen = len
|
|
252
|
+
|
|
253
|
+
crange = range
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
@set_type_final
|
|
257
|
+
@type_code(TYPED_UINT64)
|
|
258
|
+
class size_t(int):
|
|
259
|
+
pass
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
@set_type_final
|
|
263
|
+
@type_code(TYPED_INT64)
|
|
264
|
+
class ssize_t(int):
|
|
265
|
+
pass
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
@set_type_final
|
|
269
|
+
@type_code(TYPED_INT8)
|
|
270
|
+
class int8(int):
|
|
271
|
+
pass
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
byte = int8
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
@set_type_final
|
|
278
|
+
@type_code(TYPED_INT16)
|
|
279
|
+
class int16(int):
|
|
280
|
+
pass
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
@set_type_final
|
|
284
|
+
@type_code(TYPED_INT32)
|
|
285
|
+
class int32(int):
|
|
286
|
+
pass
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
@set_type_final
|
|
290
|
+
@type_code(TYPED_INT64)
|
|
291
|
+
class int64(int):
|
|
292
|
+
pass
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
@set_type_final
|
|
296
|
+
@type_code(TYPED_UINT8)
|
|
297
|
+
class uint8(int):
|
|
298
|
+
pass
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
@set_type_final
|
|
302
|
+
@type_code(TYPED_UINT16)
|
|
303
|
+
class uint16(int):
|
|
304
|
+
pass
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
@set_type_final
|
|
308
|
+
@type_code(TYPED_UINT32)
|
|
309
|
+
class uint32(int):
|
|
310
|
+
pass
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
@set_type_final
|
|
314
|
+
@type_code(TYPED_UINT64)
|
|
315
|
+
class uint64(int):
|
|
316
|
+
pass
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
@set_type_final
|
|
320
|
+
@type_code(TYPED_SINGLE)
|
|
321
|
+
class single(float):
|
|
322
|
+
pass
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
@set_type_final
|
|
326
|
+
@type_code(TYPED_DOUBLE)
|
|
327
|
+
class double(float):
|
|
328
|
+
pass
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
@set_type_final
|
|
332
|
+
@type_code(TYPED_CHAR)
|
|
333
|
+
class char(int):
|
|
334
|
+
pass
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
@set_type_final
|
|
338
|
+
@type_code(TYPED_BOOL)
|
|
339
|
+
class cbool(int):
|
|
340
|
+
pass
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
TVarOrType = Union[TypeVar, Type[object]]
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
def _subs_tvars(
|
|
347
|
+
tp: TVarOrType,
|
|
348
|
+
tvars: tuple[TVarOrType, ...],
|
|
349
|
+
subs: tuple[TVarOrType, ...],
|
|
350
|
+
) -> type[object]:
|
|
351
|
+
"""Substitute type variables 'tvars' with substitutions 'subs'.
|
|
352
|
+
These two must have the same length.
|
|
353
|
+
"""
|
|
354
|
+
args = getattr(tp, "__args__", None)
|
|
355
|
+
if args is None:
|
|
356
|
+
# pyre-ignore[7]: Expected `Type[object]` but got `typing.Tuple[Union[Type[object], TypeVar], ...]`.
|
|
357
|
+
return tp
|
|
358
|
+
|
|
359
|
+
new_args = list(args)
|
|
360
|
+
for a, arg in enumerate(new_args):
|
|
361
|
+
if isinstance(arg, TypeVar):
|
|
362
|
+
for i, tvar in enumerate(tvars):
|
|
363
|
+
if arg == tvar:
|
|
364
|
+
if (
|
|
365
|
+
# pyre-ignore[16]: `object` has no attribute `__constraints__`.
|
|
366
|
+
tvar.__constraints__
|
|
367
|
+
and not isinstance(subs[i], TypeVar)
|
|
368
|
+
# pyre-ignore[6]: In call `issubclass`, ...
|
|
369
|
+
and not issubclass(subs[i], tvar.__constraints__)
|
|
370
|
+
):
|
|
371
|
+
raise TypeError(
|
|
372
|
+
f"Invalid type for {tvar.__name__}: {subs[i].__name__} when instantiating {tp.__name__}"
|
|
373
|
+
)
|
|
374
|
+
|
|
375
|
+
new_args[a] = subs[i]
|
|
376
|
+
else:
|
|
377
|
+
new_args[a] = _subs_tvars(arg, tvars, subs)
|
|
378
|
+
|
|
379
|
+
return _replace_types(tp, tuple(new_args))
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
def _collect_type_vars(types: tuple[TVarOrType, ...]) -> tuple[TypeVar, ...]:
|
|
383
|
+
"""Collect all type variable contained in types in order of
|
|
384
|
+
first appearance (lexicographic order). For example::
|
|
385
|
+
|
|
386
|
+
_collect_type_vars((T, List[S, T])) == (T, S)
|
|
387
|
+
"""
|
|
388
|
+
tvars = []
|
|
389
|
+
for t in types:
|
|
390
|
+
if isinstance(t, TypeVar) and t not in tvars:
|
|
391
|
+
tvars.append(t)
|
|
392
|
+
if hasattr(t, "__parameters__"):
|
|
393
|
+
tvars.extend([t for t in t.__parameters__ if t not in tvars])
|
|
394
|
+
return tuple(tvars)
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def make_generic_type(
|
|
398
|
+
gen_type: type[object], params: tuple[TypeVar | type[object], ...]
|
|
399
|
+
) -> Type[object]:
|
|
400
|
+
# pyre-ignore[16]: object has no attribute __parameters__
|
|
401
|
+
if len(params) != len(gen_type.__parameters__):
|
|
402
|
+
raise TypeError(f"Incorrect number of type arguments for {gen_type.__name__}")
|
|
403
|
+
|
|
404
|
+
# Substitute params into __args__ replacing instances of __parameters__
|
|
405
|
+
return _subs_tvars(
|
|
406
|
+
gen_type,
|
|
407
|
+
gen_type.__parameters__,
|
|
408
|
+
params,
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
def _replace_types(
|
|
413
|
+
gen_type: TVarOrType, subs: tuple[type[object], ...]
|
|
414
|
+
) -> type[object]:
|
|
415
|
+
# pyre-ignore[16]: object has no attribute __origin__
|
|
416
|
+
existing_inst = gen_type.__origin__.__insts__.get(subs)
|
|
417
|
+
|
|
418
|
+
if existing_inst is not None:
|
|
419
|
+
return existing_inst
|
|
420
|
+
|
|
421
|
+
# Check if we have a full instantation, and verify the constraints
|
|
422
|
+
new_dict = dict(gen_type.__dict__)
|
|
423
|
+
has_params = False
|
|
424
|
+
for sub in subs:
|
|
425
|
+
if isinstance(sub, TypeVar) or hasattr(sub, "__parameters__"):
|
|
426
|
+
has_params = True
|
|
427
|
+
continue
|
|
428
|
+
|
|
429
|
+
# Remove the existing StaticGeneric base...
|
|
430
|
+
bases = tuple(
|
|
431
|
+
# pyre-ignore[16]: object has no attribute __orig_bases__
|
|
432
|
+
base
|
|
433
|
+
for base in gen_type.__orig_bases__
|
|
434
|
+
if not isinstance(base, StaticGeneric)
|
|
435
|
+
)
|
|
436
|
+
|
|
437
|
+
new_dict["__args__"] = subs
|
|
438
|
+
if not has_params:
|
|
439
|
+
# Instantiated types don't have generic parameters anymore.
|
|
440
|
+
del new_dict["__parameters__"]
|
|
441
|
+
else:
|
|
442
|
+
new_vars = _collect_type_vars(subs)
|
|
443
|
+
new_gen = StaticGeneric()
|
|
444
|
+
new_gen.__parameters__ = new_vars
|
|
445
|
+
new_dict["__orig_bases__"] = bases + (new_gen,)
|
|
446
|
+
bases += (StaticGeneric,)
|
|
447
|
+
new_dict["__parameters__"] = new_vars
|
|
448
|
+
|
|
449
|
+
# Eventually we'll want to have some processing of the members here to
|
|
450
|
+
# bind the generics through. That may be an actual process which creates
|
|
451
|
+
# new objects with the generics bound, or a virtual process. For now
|
|
452
|
+
# we just propagate the members to the new type.
|
|
453
|
+
param_names = ", ".join(param.__name__ for param in subs)
|
|
454
|
+
|
|
455
|
+
res = type(f"{gen_type.__origin__.__name__}[{param_names}]", bases, new_dict)
|
|
456
|
+
res.__origin__ = gen_type
|
|
457
|
+
|
|
458
|
+
if cinder is not None:
|
|
459
|
+
cinder.freeze_type(res)
|
|
460
|
+
|
|
461
|
+
gen_type.__origin__.__insts__[subs] = res
|
|
462
|
+
return res
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
def _runtime_impl(f):
|
|
466
|
+
"""marks a generic function as being runtime-implemented"""
|
|
467
|
+
f.__runtime_impl__ = True
|
|
468
|
+
return f
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
class StaticGeneric:
|
|
472
|
+
"""Base type used to mark static-Generic classes. Instantations of these
|
|
473
|
+
classes share different generic types and the generic type arguments can
|
|
474
|
+
be accessed via __args___"""
|
|
475
|
+
|
|
476
|
+
# pyre-ignore[16]: typing has no attribute _tp_cache
|
|
477
|
+
@_tp_cache
|
|
478
|
+
def __class_getitem__(
|
|
479
|
+
cls, elem_type: tuple[TypeVar | type[object]]
|
|
480
|
+
) -> StaticGeneric | type[object]:
|
|
481
|
+
if not isinstance(elem_type, tuple):
|
|
482
|
+
# we specifically recurse to hit the type cache
|
|
483
|
+
return cls[elem_type,]
|
|
484
|
+
|
|
485
|
+
if cls is StaticGeneric:
|
|
486
|
+
res = StaticGeneric()
|
|
487
|
+
res.__parameters__ = elem_type
|
|
488
|
+
return res
|
|
489
|
+
|
|
490
|
+
return set_type_static_final(make_generic_type(cls, elem_type))
|
|
491
|
+
|
|
492
|
+
def __init_subclass__(cls) -> None:
|
|
493
|
+
# pyre-ignore[16]: StaticGeneric has no attribute __orig__bases__
|
|
494
|
+
type_vars = _collect_type_vars(cls.__orig_bases__)
|
|
495
|
+
cls.__origin__ = cls
|
|
496
|
+
cls.__parameters__ = type_vars
|
|
497
|
+
if not hasattr(cls, "__args__"):
|
|
498
|
+
cls.__args__ = type_vars
|
|
499
|
+
cls.__insts__ = WeakValueDictionary()
|
|
500
|
+
|
|
501
|
+
def __mro_entries__(self, bases) -> tuple[type[object], ...]:
|
|
502
|
+
return (StaticGeneric,)
|
|
503
|
+
|
|
504
|
+
def __repr__(self) -> str:
|
|
505
|
+
return (
|
|
506
|
+
"<StaticGeneric: "
|
|
507
|
+
+ ", ".join([param.__name__ for param in self.__parameters__])
|
|
508
|
+
+ ">"
|
|
509
|
+
)
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
def box(o):
|
|
513
|
+
return o
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
def unbox(o):
|
|
517
|
+
return o
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
def allow_weakrefs(klass):
|
|
521
|
+
return klass
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
def dynamic_return(func):
|
|
525
|
+
return func
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def inline(func):
|
|
529
|
+
return func
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
def _donotcompile(func):
|
|
533
|
+
return func
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
def cast(typ, val):
|
|
537
|
+
union_args = None
|
|
538
|
+
if isinstance(typ, _GenericAlias):
|
|
539
|
+
typ, args = typ.__origin__, typ.__args__
|
|
540
|
+
if typ is Union:
|
|
541
|
+
union_args = args
|
|
542
|
+
elif type(typ) is typesUnion:
|
|
543
|
+
union_args = typ.__args__
|
|
544
|
+
if union_args:
|
|
545
|
+
typ = None
|
|
546
|
+
if len(union_args) == 2:
|
|
547
|
+
if union_args[0] is type(None): # noqa: E721
|
|
548
|
+
typ = union_args[1]
|
|
549
|
+
elif union_args[1] is type(None): # noqa: E721
|
|
550
|
+
typ = union_args[0]
|
|
551
|
+
if typ is None:
|
|
552
|
+
raise ValueError("cast expects type or Optional[T]")
|
|
553
|
+
if val is None:
|
|
554
|
+
return None
|
|
555
|
+
|
|
556
|
+
inst_type = type(val)
|
|
557
|
+
if typ not in inst_type.__mro__:
|
|
558
|
+
raise TypeError(f"expected {typ.__name__}, got {type(val).__name__}")
|
|
559
|
+
|
|
560
|
+
return val
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
def prod_assert(value: bool, message: str | None = None):
|
|
564
|
+
if not value:
|
|
565
|
+
raise AssertionError(message) if message else AssertionError()
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
CheckedDict = chkdict
|
|
569
|
+
CheckedList = chklist
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
async def _return_none():
|
|
573
|
+
"""This exists solely as a helper for the ContextDecorator C implementation"""
|
|
574
|
+
pass
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
class ExcContextDecorator:
|
|
578
|
+
def __enter__(self) -> ExcContextDecorator:
|
|
579
|
+
return self
|
|
580
|
+
|
|
581
|
+
def __exit__(self, exc_type: object, exc_value: object, traceback: object) -> bool:
|
|
582
|
+
return False
|
|
583
|
+
|
|
584
|
+
@final
|
|
585
|
+
def __call__(self, func):
|
|
586
|
+
if not iscoroutinefunction(func):
|
|
587
|
+
|
|
588
|
+
@functools.wraps(func)
|
|
589
|
+
def _no_profile_inner(*args, **kwds):
|
|
590
|
+
with self._recreate_cm():
|
|
591
|
+
return func(*args, **kwds)
|
|
592
|
+
|
|
593
|
+
else:
|
|
594
|
+
|
|
595
|
+
@functools.wraps(func)
|
|
596
|
+
async def _no_profile_inner(*args, **kwds):
|
|
597
|
+
with self._recreate_cm():
|
|
598
|
+
return await func(*args, **kwds)
|
|
599
|
+
|
|
600
|
+
# This will replace the vector call entry point with a C implementation.
|
|
601
|
+
# We still want to return a function object because various things check
|
|
602
|
+
# for functions or if an object is a co-routine.
|
|
603
|
+
return make_context_decorator_wrapper(self, _no_profile_inner, func)
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
# pyre-ignore[16]: `Type` has no attribute `_recreate_cm`.
|
|
607
|
+
ExcContextDecorator._recreate_cm = make_recreate_cm(ExcContextDecorator)
|
|
608
|
+
set_type_static(ExcContextDecorator)
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
class ContextDecorator(ExcContextDecorator):
|
|
612
|
+
"""A ContextDecorator which cannot suppress exceptions."""
|
|
613
|
+
|
|
614
|
+
def __exit__(
|
|
615
|
+
self, exc_type: object, exc_value: object, traceback: object
|
|
616
|
+
) -> Literal[False]:
|
|
617
|
+
return False
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
set_type_static(ContextDecorator)
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
def native(so_path):
|
|
624
|
+
def _inner_native(func):
|
|
625
|
+
return func
|
|
626
|
+
|
|
627
|
+
return _inner_native
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
Array = staticarray # noqa: F811
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
def mixin(cls):
|
|
634
|
+
return cls
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
TClass = TypeVar("TClass", bound=Type[object])
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
class ClassDecorator(Protocol):
|
|
641
|
+
def __call__(self, cls: TClass) -> TClass: ...
|