Skip to content

Commit f72480e

Browse files
committed
Remove remaining legacy function ops
1 parent 88a59d5 commit f72480e

File tree

9 files changed

+25
-87
lines changed

9 files changed

+25
-87
lines changed

mypyc/irbuild/builder.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
from mypyc.primitives.generic_ops import iter_op, next_op, py_setattr_op
135135
from mypyc.primitives.list_ops import list_get_item_unsafe_op, list_pop_last, to_list
136136
from mypyc.primitives.misc_ops import check_unpack_count_op, get_module_dict_op, import_op
137-
from mypyc.primitives.registry import CFunctionDescription, function_ops, legacy_function_ops
137+
from mypyc.primitives.registry import CFunctionDescription, function_ops
138138

139139
# These int binary operations can borrow their operands safely, since the
140140
# primitives take this into consideration.
@@ -1051,12 +1051,6 @@ def call_refexpr_with_args(
10511051
# Handle data-driven special-cased primitive call ops.
10521052
if callee.fullname and expr.arg_kinds == [ARG_POS] * len(arg_values):
10531053
fullname = get_call_target_fullname(callee)
1054-
call_c_ops_candidates = legacy_function_ops.get(fullname, [])
1055-
target = self.builder.matching_call_c(
1056-
call_c_ops_candidates, arg_values, expr.line, self.node_type(expr)
1057-
)
1058-
if target:
1059-
return target
10601054
primitive_candidates = function_ops.get(fullname, [])
10611055
target = self.builder.matching_primitive_op(
10621056
primitive_candidates, arg_values, expr.line, self.node_type(expr)

mypyc/primitives/bytes_ops.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
ERR_NEG_INT,
1919
binary_op,
2020
custom_op,
21-
legacy_function_op,
21+
function_op,
2222
load_address_op,
2323
method_op,
2424
)
@@ -27,7 +27,7 @@
2727
load_address_op(name="builtins.bytes", type=object_rprimitive, src="PyBytes_Type")
2828

2929
# bytes(obj)
30-
legacy_function_op(
30+
function_op(
3131
name="builtins.bytes",
3232
arg_types=[RUnion([list_rprimitive, dict_rprimitive, str_rprimitive])],
3333
return_type=bytes_rprimitive,
@@ -36,7 +36,7 @@
3636
)
3737

3838
# bytearray(obj)
39-
legacy_function_op(
39+
function_op(
4040
name="builtins.bytearray",
4141
arg_types=[object_rprimitive],
4242
return_type=bytes_rprimitive,

mypyc/primitives/dict_ops.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
ERR_NEG_INT,
2020
binary_op,
2121
custom_op,
22-
legacy_function_op,
22+
function_op,
2323
load_address_op,
2424
method_op,
2525
)
@@ -28,7 +28,7 @@
2828
load_address_op(name="builtins.dict", type=object_rprimitive, src="PyDict_Type")
2929

3030
# Construct an empty dictionary via dict().
31-
legacy_function_op(
31+
function_op(
3232
name="builtins.dict",
3333
arg_types=[],
3434
return_type=dict_rprimitive,
@@ -53,7 +53,7 @@
5353
)
5454

5555
# Construct a dictionary from another dictionary.
56-
legacy_function_op(
56+
function_op(
5757
name="builtins.dict",
5858
arg_types=[dict_rprimitive],
5959
return_type=dict_rprimitive,
@@ -63,7 +63,7 @@
6363
)
6464

6565
# Generic one-argument dict constructor: dict(obj)
66-
dict_copy = legacy_function_op(
66+
dict_copy = function_op(
6767
name="builtins.dict",
6868
arg_types=[object_rprimitive],
6969
return_type=dict_rprimitive,

mypyc/primitives/list_ops.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
custom_op,
2121
custom_primitive_op,
2222
function_op,
23-
legacy_function_op,
2423
load_address_op,
2524
method_op,
2625
)
@@ -38,7 +37,7 @@
3837
)
3938

4039
# Construct an empty list via list().
41-
legacy_function_op(
40+
function_op(
4241
name="builtins.list",
4342
arg_types=[],
4443
return_type=list_rprimitive,

mypyc/primitives/misc_ops.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
ERR_NEG_INT,
2222
custom_op,
2323
custom_primitive_op,
24-
legacy_function_op,
24+
function_op,
2525
load_address_op,
2626
)
2727

@@ -48,7 +48,7 @@
4848
)
4949

5050
# id(obj)
51-
legacy_function_op(
51+
function_op(
5252
name="builtins.id",
5353
arg_types=[object_rprimitive],
5454
return_type=int_rprimitive,
@@ -161,7 +161,7 @@
161161
)
162162

163163
# isinstance(obj, cls)
164-
slow_isinstance_op = legacy_function_op(
164+
slow_isinstance_op = function_op(
165165
name="builtins.isinstance",
166166
arg_types=[object_rprimitive, object_rprimitive],
167167
return_type=c_int_rprimitive,
@@ -172,7 +172,7 @@
172172

173173
# Faster isinstance(obj, cls) that only works with native classes and doesn't perform
174174
# type checking of the type argument.
175-
fast_isinstance_op = legacy_function_op(
175+
fast_isinstance_op = function_op(
176176
"builtins.isinstance",
177177
arg_types=[object_rprimitive, object_rprimitive],
178178
return_type=bool_rprimitive,
@@ -182,7 +182,7 @@
182182
)
183183

184184
# bool(obj) with unboxed result
185-
bool_op = legacy_function_op(
185+
bool_op = function_op(
186186
name="builtins.bool",
187187
arg_types=[object_rprimitive],
188188
return_type=c_int_rprimitive,
@@ -192,7 +192,7 @@
192192
)
193193

194194
# slice(start, stop, step)
195-
new_slice_op = legacy_function_op(
195+
new_slice_op = function_op(
196196
name="builtins.slice",
197197
arg_types=[object_rprimitive, object_rprimitive, object_rprimitive],
198198
c_function_name="PySlice_New",
@@ -201,7 +201,7 @@
201201
)
202202

203203
# type(obj)
204-
type_op = legacy_function_op(
204+
type_op = function_op(
205205
name="builtins.type",
206206
arg_types=[object_rprimitive],
207207
c_function_name="PyObject_Type",

mypyc/primitives/registry.py

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ class LoadAddressDescription(NamedTuple):
7676
# Primitive ops for top level function call (such as 'builtins.list')
7777
function_ops: dict[str, list[PrimitiveDescription]] = {}
7878

79-
# Legacy CallC ops for top level function call (such as 'builtins.list')
80-
legacy_function_ops: dict[str, list[CFunctionDescription]] = {}
81-
82-
# CallC op for binary ops
79+
# Primitive ops for binary operations
8380
binary_ops: dict[str, list[PrimitiveDescription]] = {}
8481

8582
# CallC op for unary ops
@@ -151,54 +148,6 @@ def method_op(
151148
return desc
152149

153150

154-
def legacy_function_op(
155-
name: str,
156-
arg_types: list[RType],
157-
return_type: RType,
158-
c_function_name: str,
159-
error_kind: int,
160-
var_arg_type: RType | None = None,
161-
truncated_type: RType | None = None,
162-
ordering: list[int] | None = None,
163-
extra_int_constants: list[tuple[int, RType]] | None = None,
164-
steals: StealsDescription = False,
165-
is_borrowed: bool = False,
166-
priority: int = 1,
167-
) -> CFunctionDescription:
168-
"""Define a C function call op that replaces a function call.
169-
170-
NOTE: Use function_op instead for new use cases.
171-
172-
This will be automatically generated by matching against the AST.
173-
174-
Most arguments are similar to method_op().
175-
176-
Args:
177-
name: full name of the function
178-
arg_types: positional argument types for which this applies
179-
"""
180-
if extra_int_constants is None:
181-
extra_int_constants = []
182-
ops = legacy_function_ops.setdefault(name, [])
183-
desc = CFunctionDescription(
184-
name,
185-
arg_types,
186-
return_type,
187-
var_arg_type,
188-
truncated_type,
189-
c_function_name,
190-
error_kind,
191-
steals,
192-
is_borrowed,
193-
ordering,
194-
extra_int_constants,
195-
priority,
196-
is_pure=False,
197-
)
198-
ops.append(desc)
199-
return desc
200-
201-
202151
def function_op(
203152
name: str,
204153
arg_types: list[RType],

mypyc/primitives/set_ops.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from mypyc.primitives.registry import (
1515
ERR_NEG_INT,
1616
binary_op,
17-
legacy_function_op,
17+
function_op,
1818
load_address_op,
1919
method_op,
2020
)
@@ -26,7 +26,7 @@
2626
load_address_op(name="builtins.frozenset", type=object_rprimitive, src="PyFrozenSet_Type")
2727

2828
# Construct an empty set.
29-
new_set_op = legacy_function_op(
29+
new_set_op = function_op(
3030
name="builtins.set",
3131
arg_types=[],
3232
return_type=set_rprimitive,
@@ -36,7 +36,7 @@
3636
)
3737

3838
# set(obj)
39-
legacy_function_op(
39+
function_op(
4040
name="builtins.set",
4141
arg_types=[object_rprimitive],
4242
return_type=set_rprimitive,
@@ -45,7 +45,7 @@
4545
)
4646

4747
# frozenset(obj)
48-
legacy_function_op(
48+
function_op(
4949
name="builtins.frozenset",
5050
arg_types=[object_rprimitive],
5151
return_type=object_rprimitive,

mypyc/primitives/tuple_ops.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
object_rprimitive,
1616
tuple_rprimitive,
1717
)
18-
from mypyc.primitives.registry import custom_op, legacy_function_op, load_address_op, method_op
18+
from mypyc.primitives.registry import custom_op, function_op, load_address_op, method_op
1919

2020
# Get the 'builtins.tuple' type object.
2121
load_address_op(name="builtins.tuple", type=object_rprimitive, src="PyTuple_Type")
@@ -56,7 +56,7 @@
5656
)
5757

5858
# Construct tuple from a list.
59-
list_tuple_op = legacy_function_op(
59+
list_tuple_op = function_op(
6060
name="builtins.tuple",
6161
arg_types=[list_rprimitive],
6262
return_type=tuple_rprimitive,
@@ -66,7 +66,7 @@
6666
)
6767

6868
# Construct tuple from an arbitrary (iterable) object.
69-
legacy_function_op(
69+
function_op(
7070
name="builtins.tuple",
7171
arg_types=[object_rprimitive],
7272
return_type=tuple_rprimitive,

mypyc/test/test_cheader.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ def check_name(name: str) -> None:
2626
rf"\b{name}\b", header
2727
), f'"{name}" is used in mypyc.primitives but not declared in CPy.h'
2828

29-
for old_values in [
30-
registry.method_call_ops.values(),
31-
registry.legacy_function_ops.values(),
32-
registry.unary_ops.values(),
33-
]:
29+
for old_values in [registry.method_call_ops.values(), registry.unary_ops.values()]:
3430
for old_ops in old_values:
3531
if isinstance(old_ops, CFunctionDescription):
3632
old_ops = [old_ops]

0 commit comments

Comments
 (0)