Skip to content

Commit 392285d

Browse files
committed
chore: rename true_dict ops to exact_dict
1 parent aa81740 commit 392285d

File tree

9 files changed

+65
-65
lines changed

9 files changed

+65
-65
lines changed

mypyc/irbuild/builder.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
)
125125
from mypyc.irbuild.util import bytes_from_str, is_constant
126126
from mypyc.options import CompilerOptions
127-
from mypyc.primitives.dict_ops import dict_set_item_op, true_dict_get_item_op
127+
from mypyc.primitives.dict_ops import dict_set_item_op, exact_dict_get_item_op
128128
from mypyc.primitives.generic_ops import iter_op, next_op, py_setattr_op
129129
from mypyc.primitives.list_ops import list_get_item_unsafe_op, list_pop_last, to_list
130130
from mypyc.primitives.misc_ops import check_unpack_count_op, get_module_dict_op, import_op
@@ -431,7 +431,7 @@ def add_to_non_ext_dict(
431431
) -> None:
432432
# Add an attribute entry into the class dict of a non-extension class.
433433
key_unicode = self.load_str(key)
434-
# must use `dict_set_item_op` instead of `true_dict_set_item_op` because
434+
# must use `dict_set_item_op` instead of `exact_dict_set_item_op` because
435435
# it breaks enums, and probably other stuff, if we take the fast path.
436436
self.primitive_op(dict_set_item_op, [non_ext.dict, key_unicode, val], line)
437437

@@ -464,7 +464,7 @@ def get_module(self, module: str, line: int) -> Value:
464464
# Python 3.7 has a nice 'PyImport_GetModule' function that we can't use :(
465465
mod_dict = self.call_c(get_module_dict_op, [], line)
466466
# Get module object from modules dict.
467-
return self.primitive_op(true_dict_get_item_op, [mod_dict, self.load_str(module)], line)
467+
return self.primitive_op(exact_dict_get_item_op, [mod_dict, self.load_str(module)], line)
468468

469469
def get_module_attr(self, module: str, attr: str, line: int) -> Value:
470470
"""Look up an attribute of a module without storing it in the local namespace.
@@ -1372,7 +1372,7 @@ def load_global(self, expr: NameExpr) -> Value:
13721372
def load_global_str(self, name: str, line: int) -> Value:
13731373
_globals = self.load_globals_dict()
13741374
reg = self.load_str(name)
1375-
return self.primitive_op(true_dict_get_item_op, [_globals, reg], line)
1375+
return self.primitive_op(exact_dict_get_item_op, [_globals, reg], line)
13761376

13771377
def load_globals_dict(self) -> Value:
13781378
return self.add(LoadStatic(exact_dict_rprimitive, "globals", self.module_name))

mypyc/irbuild/classdef.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
)
6767
from mypyc.irbuild.prepare import GENERATOR_HELPER_NAME
6868
from mypyc.irbuild.util import dataclass_type, get_func_def, is_constant, is_dataclass_decorator
69-
from mypyc.primitives.dict_ops import dict_new_op, true_dict_set_item_op
69+
from mypyc.primitives.dict_ops import dict_new_op, exact_dict_set_item_op
7070
from mypyc.primitives.generic_ops import (
7171
iter_op,
7272
next_op,
@@ -269,7 +269,7 @@ def finalize(self, ir: ClassIR) -> None:
269269

270270
# Add the non-extension class to the dict
271271
self.builder.primitive_op(
272-
true_dict_set_item_op,
272+
exact_dict_set_item_op,
273273
[
274274
self.builder.load_globals_dict(),
275275
self.builder.load_str(self.cdef.name),
@@ -480,7 +480,7 @@ def allocate_class(builder: IRBuilder, cdef: ClassDef) -> Value:
480480

481481
# Add it to the dict
482482
builder.primitive_op(
483-
true_dict_set_item_op,
483+
exact_dict_set_item_op,
484484
[builder.load_globals_dict(), builder.load_str(cdef.name), tp],
485485
cdef.line,
486486
)
@@ -666,7 +666,7 @@ def add_non_ext_class_attr_ann(
666666
typ = builder.add(LoadAddress(type_object_op.type, type_object_op.src, stmt.line))
667667

668668
key = builder.load_str(lvalue.name)
669-
builder.primitive_op(true_dict_set_item_op, [non_ext.anns, key, typ], stmt.line)
669+
builder.primitive_op(exact_dict_set_item_op, [non_ext.anns, key, typ], stmt.line)
670670

671671

672672
def add_non_ext_class_attr(

mypyc/irbuild/expression.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
)
9898
from mypyc.irbuild.specialize import apply_function_specialization, apply_method_specialization
9999
from mypyc.primitives.bytes_ops import bytes_slice_op
100-
from mypyc.primitives.dict_ops import dict_new_op, true_dict_get_item_op, true_dict_set_item_op
100+
from mypyc.primitives.dict_ops import dict_new_op, exact_dict_get_item_op, exact_dict_set_item_op
101101
from mypyc.primitives.generic_ops import iter_op
102102
from mypyc.primitives.list_ops import list_append_op, list_extend_op, list_slice_op
103103
from mypyc.primitives.misc_ops import ellipsis_op, get_module_dict_op, new_slice_op, type_op
@@ -183,7 +183,7 @@ def transform_name_expr(builder: IRBuilder, expr: NameExpr) -> Value:
183183
# instead load the module separately on each access.
184184
mod_dict = builder.call_c(get_module_dict_op, [], expr.line)
185185
obj = builder.primitive_op(
186-
true_dict_get_item_op, [mod_dict, builder.load_str(expr.node.fullname)], expr.line
186+
exact_dict_get_item_op, [mod_dict, builder.load_str(expr.node.fullname)], expr.line
187187
)
188188
return obj
189189
else:
@@ -1030,7 +1030,7 @@ def transform_dictionary_comprehension(builder: IRBuilder, o: DictionaryComprehe
10301030
def gen_inner_stmts() -> None:
10311031
k = builder.accept(o.key)
10321032
v = builder.accept(o.value)
1033-
builder.primitive_op(true_dict_set_item_op, [builder.read(d), k, v], o.line)
1033+
builder.primitive_op(exact_dict_set_item_op, [builder.read(d), k, v], o.line)
10341034

10351035
comprehension_helper(builder, loop_params, gen_inner_stmts, o.line)
10361036
return builder.read(d)

mypyc/irbuild/for_helpers.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@
7070
dict_next_key_op,
7171
dict_next_value_op,
7272
dict_value_iter_op,
73-
true_dict_check_size_op,
74-
true_dict_iter_fast_path_op,
75-
true_dict_next_item_op,
76-
true_dict_next_key_op,
77-
true_dict_next_value_op,
73+
exact_dict_check_size_op,
74+
exact_dict_iter_fast_path_op,
75+
exact_dict_next_item_op,
76+
exact_dict_next_key_op,
77+
exact_dict_next_value_op,
7878
)
7979
from mypyc.primitives.exc_ops import no_err_occurred_op, propagate_if_error_op
8080
from mypyc.primitives.generic_ops import aiter_op, anext_op, iter_op, next_op
@@ -1012,25 +1012,25 @@ def begin_body(self) -> None:
10121012
class ForExactDictionaryKeys(ForDictionaryKeys):
10131013
"""Generate optimized IR for a for loop over dictionary items without type checks."""
10141014

1015-
dict_next_op = true_dict_next_key_op
1016-
dict_iter_op = true_dict_iter_fast_path_op
1017-
dict_size_op = true_dict_check_size_op
1015+
dict_next_op = exact_dict_next_key_op
1016+
dict_iter_op = exact_dict_iter_fast_path_op
1017+
dict_size_op = exact_dict_check_size_op
10181018

10191019

10201020
class ForExactDictionaryValues(ForDictionaryValues):
10211021
"""Generate optimized IR for a for loop over dictionary items without type checks."""
10221022

1023-
dict_next_op = true_dict_next_value_op
1024-
dict_iter_op = true_dict_iter_fast_path_op
1025-
dict_size_op = true_dict_check_size_op
1023+
dict_next_op = exact_dict_next_value_op
1024+
dict_iter_op = exact_dict_iter_fast_path_op
1025+
dict_size_op = exact_dict_check_size_op
10261026

10271027

10281028
class ForExactDictionaryItems(ForDictionaryItems):
10291029
"""Generate optimized IR for a for loop over dictionary items without type checks."""
10301030

1031-
dict_next_op = true_dict_next_item_op
1032-
dict_iter_op = true_dict_iter_fast_path_op
1033-
dict_size_op = true_dict_check_size_op
1031+
dict_next_op = exact_dict_next_item_op
1032+
dict_iter_op = exact_dict_iter_fast_path_op
1033+
dict_size_op = exact_dict_check_size_op
10341034

10351035

10361036
class ForRange(ForGenerator):

mypyc/irbuild/function.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@
7878
from mypyc.irbuild.targets import AssignmentTarget
7979
from mypyc.primitives.dict_ops import (
8080
dict_new_op,
81-
true_dict_get_method_with_none,
82-
true_dict_set_item_op,
81+
exact_dict_get_method_with_none,
82+
exact_dict_set_item_op,
8383
)
8484
from mypyc.primitives.generic_ops import py_setattr_op
8585
from mypyc.primitives.misc_ops import register_function
@@ -128,7 +128,7 @@ def transform_decorator(builder: IRBuilder, dec: Decorator) -> None:
128128
if decorated_func is not None:
129129
# Set the callable object representing the decorated function as a global.
130130
builder.primitive_op(
131-
true_dict_set_item_op,
131+
exact_dict_set_item_op,
132132
[builder.load_globals_dict(), builder.load_str(dec.func.name), decorated_func],
133133
decorated_func.line,
134134
)
@@ -805,7 +805,7 @@ def generate_singledispatch_dispatch_function(
805805
)
806806
call_find_impl, use_cache, call_func = BasicBlock(), BasicBlock(), BasicBlock()
807807
get_result = builder.primitive_op(
808-
true_dict_get_method_with_none, [dispatch_cache, arg_type], line
808+
exact_dict_get_method_with_none, [dispatch_cache, arg_type], line
809809
)
810810
is_not_none = builder.translate_is_op(get_result, builder.none_object(), "is not", line)
811811
impl_to_use = Register(object_rprimitive)
@@ -819,7 +819,7 @@ def generate_singledispatch_dispatch_function(
819819
find_impl = builder.load_module_attr_by_fullname("functools._find_impl", line)
820820
registry = load_singledispatch_registry(builder, dispatch_func_obj, line)
821821
uncached_impl = builder.py_call(find_impl, [arg_type, registry], line)
822-
builder.primitive_op(true_dict_set_item_op, [dispatch_cache, arg_type, uncached_impl], line)
822+
builder.primitive_op(exact_dict_set_item_op, [dispatch_cache, arg_type, uncached_impl], line)
823823
builder.assign(impl_to_use, uncached_impl, line)
824824
builder.goto(call_func)
825825

@@ -996,7 +996,7 @@ def maybe_insert_into_registry_dict(builder: IRBuilder, fitem: FuncDef) -> None:
996996
registry = load_singledispatch_registry(builder, dispatch_func_obj, line)
997997
for typ in types:
998998
loaded_type = load_type(builder, typ, None, line)
999-
builder.primitive_op(true_dict_set_item_op, [registry, loaded_type, to_insert], line)
999+
builder.primitive_op(exact_dict_set_item_op, [registry, loaded_type, to_insert], line)
10001000
dispatch_cache = builder.builder.get_attr(
10011001
dispatch_func_obj, "dispatch_cache", exact_dict_rprimitive, line
10021002
)

mypyc/irbuild/ll_builder.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@
130130
dict_new_op,
131131
dict_ssize_t_size_op,
132132
dict_update_in_display_op,
133-
true_dict_copy_op,
134-
true_dict_ssize_t_size_op,
135-
true_dict_update_in_display_op,
133+
exact_dict_copy_op,
134+
exact_dict_ssize_t_size_op,
135+
exact_dict_update_in_display_op,
136136
)
137137
from mypyc.primitives.exc_ops import err_occurred_op, keep_propagating_op
138138
from mypyc.primitives.float_ops import copysign_op, int_to_float_op
@@ -797,7 +797,7 @@ def _construct_varargs(
797797
if star2_result is None:
798798
star2_result = self._create_dict(star2_keys, star2_values, line)
799799
if is_exact_dict_rprimitive(value.type):
800-
op = true_dict_update_in_display_op
800+
op = exact_dict_update_in_display_op
801801
else:
802802
op = dict_update_in_display_op
803803
self.call_c(op, [star2_result, value], line=line)
@@ -1666,12 +1666,12 @@ def make_dict(self, key_value_pairs: Sequence[DictEntry], line: int) -> Value:
16661666
if result is None:
16671667
if len(key_value_pairs) == 1 and is_exact_dict_rprimitive(value.type):
16681668
# fast path for cases like `my_func(**dict(zip(iterable, other)))` and similar
1669-
return self.call_c(true_dict_copy_op, [value], line=line)
1669+
return self.call_c(exact_dict_copy_op, [value], line=line)
16701670

16711671
result = self._create_dict(keys, values, line)
16721672

16731673
if is_exact_dict_rprimitive(value.type):
1674-
op = true_dict_update_in_display_op
1674+
op = exact_dict_update_in_display_op
16751675
else:
16761676
op = dict_update_in_display_op
16771677

@@ -2287,7 +2287,7 @@ def builtin_len(self, val: Value, line: int, use_pyssize_t: bool = False) -> Val
22872287
size_value = self.load_mem(elem_address, c_pyssize_t_rprimitive)
22882288
self.add(KeepAlive([val]))
22892289
elif is_exact_dict_rprimitive(typ):
2290-
size_value = self.call_c(true_dict_ssize_t_size_op, [val], line)
2290+
size_value = self.call_c(exact_dict_ssize_t_size_op, [val], line)
22912291
elif is_dict_rprimitive(typ):
22922292
size_value = self.call_c(dict_ssize_t_size_op, [val], line)
22932293
elif is_str_rprimitive(typ):

mypyc/irbuild/match.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
dict_copy,
2525
mapping_has_key,
2626
supports_mapping_protocol,
27-
true_dict_del_item,
27+
exact_dict_del_item,
2828
)
2929
from mypyc.primitives.generic_ops import generic_ssize_t_len_op
3030
from mypyc.primitives.list_ops import (
@@ -239,7 +239,7 @@ def visit_mapping_pattern(self, pattern: MappingPattern) -> None:
239239
self.builder.assign(target, rest, pattern.rest.line)
240240

241241
for i, key_name in enumerate(keys):
242-
self.builder.call_c(true_dict_del_item, [rest, key_name], pattern.keys[i].line)
242+
self.builder.call_c(exact_dict_del_item, [rest, key_name], pattern.keys[i].line)
243243

244244
self.builder.goto(self.code_block)
245245

mypyc/irbuild/specialize.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@
9292
dict_setdefault_spec_init_op,
9393
dict_values_op,
9494
isinstance_dict,
95-
true_dict_items_op,
96-
true_dict_keys_op,
97-
true_dict_values_op,
95+
exact_dict_items_op,
96+
exact_dict_keys_op,
97+
exact_dict_values_op,
9898
)
9999
from mypyc.primitives.float_ops import isinstance_float
100100
from mypyc.primitives.int_ops import isinstance_int
@@ -255,17 +255,17 @@ def dict_methods_fast_path(builder: IRBuilder, expr: CallExpr, callee: RefExpr)
255255
# generic logic.
256256
if attr == "keys":
257257
if is_exact_dict_rprimitive(rtype):
258-
op = true_dict_keys_op
258+
op = exact_dict_keys_op
259259
else:
260260
op = dict_keys_op
261261
elif attr == "values":
262262
if is_exact_dict_rprimitive(rtype):
263-
op = true_dict_values_op
263+
op = exact_dict_values_op
264264
else:
265265
op = dict_values_op
266266
else:
267267
if is_exact_dict_rprimitive(rtype):
268-
op = true_dict_items_op
268+
op = exact_dict_items_op
269269
else:
270270
op = dict_items_op
271271

0 commit comments

Comments
 (0)