Skip to content

Commit 6ac41c3

Browse files
committed
chore: rename true dict to exact dict
1 parent 6c697df commit 6ac41c3

24 files changed

+227
-227
lines changed

mypyc/analysis/ircheck.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
range_rprimitive,
7171
set_rprimitive,
7272
str_rprimitive,
73-
true_dict_rprimitive,
73+
exact_dict_rprimitive,
7474
tuple_rprimitive,
7575
)
7676

@@ -177,7 +177,7 @@ def check_op_sources_valid(fn: FuncIR) -> list[FnError]:
177177
int_rprimitive.name,
178178
bytes_rprimitive.name,
179179
str_rprimitive.name,
180-
true_dict_rprimitive.name,
180+
exact_dict_rprimitive.name,
181181
dict_rprimitive.name,
182182
list_rprimitive.name,
183183
set_rprimitive.name,

mypyc/ir/rtypes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,8 @@ def __hash__(self) -> int:
488488
)
489489

490490
# Python dict object.
491-
true_dict_rprimitive: Final = RPrimitive(
492-
"builtins.dict[confirmed]", is_unboxed=False, is_refcounted=True
491+
exact_dict_rprimitive: Final = RPrimitive(
492+
"builtins.dict[exact]", is_unboxed=False, is_refcounted=True
493493
)
494494
"""A primitive for dicts that are confirmed to be actual instances of builtins.dict, not a subclass."""
495495

@@ -608,12 +608,12 @@ def is_list_rprimitive(rtype: RType) -> bool:
608608
def is_dict_rprimitive(rtype: RType) -> bool:
609609
return isinstance(rtype, RPrimitive) and rtype.name in (
610610
"builtins.dict",
611-
"builtins.dict[confirmed]",
611+
"builtins.dict[exact]",
612612
)
613613

614614

615-
def is_true_dict_rprimitive(rtype: RType) -> bool:
616-
return isinstance(rtype, RPrimitive) and rtype.name == "builtins.dict[confirmed]"
615+
def is_exact_dict_rprimitive(rtype: RType) -> bool:
616+
return isinstance(rtype, RPrimitive) and rtype.name == "builtins.dict[exact]"
617617

618618

619619
def is_set_rprimitive(rtype: RType) -> bool:

mypyc/irbuild/builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
none_rprimitive,
103103
object_rprimitive,
104104
str_rprimitive,
105-
true_dict_rprimitive,
105+
exact_dict_rprimitive,
106106
)
107107
from mypyc.irbuild.context import FuncInfo, ImplicitClass
108108
from mypyc.irbuild.ll_builder import LowLevelIRBuilder
@@ -1383,7 +1383,7 @@ def load_global_str(self, name: str, line: int) -> Value:
13831383
return self.primitive_op(true_dict_get_item_op, [_globals, reg], line)
13841384

13851385
def load_globals_dict(self) -> Value:
1386-
return self.add(LoadStatic(true_dict_rprimitive, "globals", self.module_name))
1386+
return self.add(LoadStatic(exact_dict_rprimitive, "globals", self.module_name))
13871387

13881388
def load_module_attr_by_fullname(self, fullname: str, line: int) -> Value:
13891389
module, _, name = fullname.rpartition(".")

mypyc/irbuild/classdef.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
is_object_rprimitive,
5555
is_optional_type,
5656
object_rprimitive,
57-
true_dict_rprimitive,
57+
exact_dict_rprimitive,
5858
)
5959
from mypyc.irbuild.builder import IRBuilder, create_type_params
6060
from mypyc.irbuild.function import (
@@ -611,7 +611,7 @@ def setup_non_ext_dict(
611611
py_hasattr_op, [metaclass, builder.load_str("__prepare__")], cdef.line
612612
)
613613

614-
non_ext_dict = Register(true_dict_rprimitive)
614+
non_ext_dict = Register(exact_dict_rprimitive)
615615

616616
true_block, false_block, exit_block = BasicBlock(), BasicBlock(), BasicBlock()
617617
builder.add_bool_branch(has_prepare, true_block, false_block)

mypyc/irbuild/for_helpers.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
is_sequence_rprimitive,
5353
is_short_int_rprimitive,
5454
is_str_rprimitive,
55-
is_true_dict_rprimitive,
55+
is_exact_dict_rprimitive,
5656
is_tuple_rprimitive,
5757
object_pointer_rprimitive,
5858
object_rprimitive,
@@ -422,7 +422,7 @@ def make_for_loop_generator(
422422
expr_reg = builder.accept(expr)
423423
target_type = builder.get_dict_key_type(expr)
424424
for_loop_cls = (
425-
ForTrueDictionaryKeys if is_true_dict_rprimitive(rtyp) else ForDictionaryKeys
425+
ForExactDictionaryKeys if is_exact_dict_rprimitive(rtyp) else ForDictionaryKeys
426426
)
427427
for_dict = for_loop_cls(builder, index, body_block, loop_exit, line, nested)
428428
for_dict.init(expr_reg, target_type)
@@ -506,20 +506,20 @@ def make_for_loop_generator(
506506
for_dict_type: type[ForGenerator] | None = None
507507
if expr.callee.name == "keys":
508508
target_type = builder.get_dict_key_type(expr.callee.expr)
509-
if is_true_dict_rprimitive(rtype):
510-
for_dict_type = ForTrueDictionaryKeys
509+
if is_exact_dict_rprimitive(rtype):
510+
for_dict_type = ForExactDictionaryKeys
511511
else:
512512
for_dict_type = ForDictionaryKeys
513513
elif expr.callee.name == "values":
514514
target_type = builder.get_dict_value_type(expr.callee.expr)
515-
if is_true_dict_rprimitive(rtype):
516-
for_dict_type = ForTrueDictionaryValues
515+
if is_exact_dict_rprimitive(rtype):
516+
for_dict_type = ForExactDictionaryValues
517517
else:
518518
for_dict_type = ForDictionaryValues
519519
else:
520520
target_type = builder.get_dict_item_type(expr.callee.expr)
521-
if is_true_dict_rprimitive(rtype):
522-
for_dict_type = ForTrueDictionaryItems
521+
if is_exact_dict_rprimitive(rtype):
522+
for_dict_type = ForExactDictionaryItems
523523
else:
524524
for_dict_type = ForDictionaryItems
525525
for_dict_gen = for_dict_type(builder, index, body_block, loop_exit, line, nested)
@@ -1009,23 +1009,23 @@ def begin_body(self) -> None:
10091009
builder.assign(target, rvalue, line)
10101010

10111011

1012-
class ForTrueDictionaryKeys(ForDictionaryKeys):
1012+
class ForExactDictionaryKeys(ForDictionaryKeys):
10131013
"""Generate optimized IR for a for loop over dictionary items without type checks."""
10141014

10151015
dict_next_op = true_dict_next_key_op
10161016
dict_iter_op = true_dict_iter_fast_path_op
10171017
dict_size_op = true_dict_check_size_op
10181018

10191019

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

10231023
dict_next_op = true_dict_next_value_op
10241024
dict_iter_op = true_dict_iter_fast_path_op
10251025
dict_size_op = true_dict_check_size_op
10261026

10271027

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

10311031
dict_next_op = true_dict_next_item_op

mypyc/irbuild/function.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
bool_rprimitive,
5959
int_rprimitive,
6060
object_rprimitive,
61-
true_dict_rprimitive,
61+
exact_dict_rprimitive,
6262
)
6363
from mypyc.irbuild.builder import IRBuilder, calculate_arg_defaults, gen_arg_defaults
6464
from mypyc.irbuild.callable_class import (
@@ -801,7 +801,7 @@ def generate_singledispatch_dispatch_function(
801801

802802
arg_type = builder.builder.get_type_of_obj(arg_info.args[0], line)
803803
dispatch_cache = builder.builder.get_attr(
804-
dispatch_func_obj, "dispatch_cache", true_dict_rprimitive, line
804+
dispatch_func_obj, "dispatch_cache", exact_dict_rprimitive, line
805805
)
806806
call_find_impl, use_cache, call_func = BasicBlock(), BasicBlock(), BasicBlock()
807807
get_result = builder.primitive_op(
@@ -883,8 +883,8 @@ def gen_dispatch_func_ir(
883883
"""
884884
builder.enter(FuncInfo(fitem, dispatch_name))
885885
setup_callable_class(builder)
886-
builder.fn_info.callable_class.ir.attributes["registry"] = true_dict_rprimitive
887-
builder.fn_info.callable_class.ir.attributes["dispatch_cache"] = true_dict_rprimitive
886+
builder.fn_info.callable_class.ir.attributes["registry"] = exact_dict_rprimitive
887+
builder.fn_info.callable_class.ir.attributes["dispatch_cache"] = exact_dict_rprimitive
888888
builder.fn_info.callable_class.ir.has_dict = True
889889
builder.fn_info.callable_class.ir.needs_getseters = True
890890
generate_singledispatch_callable_class_ctor(builder)
@@ -947,7 +947,7 @@ def add_register_method_to_callable_class(builder: IRBuilder, fn_info: FuncInfo)
947947

948948

949949
def load_singledispatch_registry(builder: IRBuilder, dispatch_func_obj: Value, line: int) -> Value:
950-
return builder.builder.get_attr(dispatch_func_obj, "registry", true_dict_rprimitive, line)
950+
return builder.builder.get_attr(dispatch_func_obj, "registry", exact_dict_rprimitive, line)
951951

952952

953953
def singledispatch_main_func_name(orig_name: str) -> str:
@@ -998,7 +998,7 @@ def maybe_insert_into_registry_dict(builder: IRBuilder, fitem: FuncDef) -> None:
998998
loaded_type = load_type(builder, typ, None, line)
999999
builder.primitive_op(true_dict_set_item_op, [registry, loaded_type, to_insert], line)
10001000
dispatch_cache = builder.builder.get_attr(
1001-
dispatch_func_obj, "dispatch_cache", true_dict_rprimitive, line
1001+
dispatch_func_obj, "dispatch_cache", exact_dict_rprimitive, line
10021002
)
10031003
builder.gen_method_call(dispatch_cache, "clear", [], None, line)
10041004

mypyc/irbuild/ll_builder.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
is_short_int_rprimitive,
112112
is_str_rprimitive,
113113
is_tagged,
114-
is_true_dict_rprimitive,
114+
is_exact_dict_rprimitive,
115115
is_tuple_rprimitive,
116116
is_uint8_rprimitive,
117117
list_rprimitive,
@@ -122,7 +122,7 @@
122122
pointer_rprimitive,
123123
short_int_rprimitive,
124124
str_rprimitive,
125-
true_dict_rprimitive,
125+
exact_dict_rprimitive,
126126
)
127127
from mypyc.irbuild.util import concrete_arg_kind
128128
from mypyc.options import CompilerOptions
@@ -799,7 +799,7 @@ def _construct_varargs(
799799
elif kind == ARG_STAR2:
800800
if star2_result is None:
801801
star2_result = self._create_dict(star2_keys, star2_values, line)
802-
if is_true_dict_rprimitive(value.type):
802+
if is_exact_dict_rprimitive(value.type):
803803
op = true_dict_update_in_display_op
804804
else:
805805
op = dict_update_in_display_op
@@ -1667,13 +1667,13 @@ def make_dict(self, key_value_pairs: Sequence[DictEntry], line: int) -> Value:
16671667
else:
16681668
# **value
16691669
if result is None:
1670-
if len(key_value_pairs) == 1 and is_true_dict_rprimitive(value.type):
1670+
if len(key_value_pairs) == 1 and is_exact_dict_rprimitive(value.type):
16711671
# fast path for cases like `my_func(**dict(zip(iterable, other)))` and similar
16721672
return self.call_c(true_dict_copy_op, [value], line=line)
16731673

16741674
result = self._create_dict(keys, values, line)
16751675

1676-
if is_true_dict_rprimitive(value.type):
1676+
if is_exact_dict_rprimitive(value.type):
16771677
op = true_dict_update_in_display_op
16781678
else:
16791679
op = dict_update_in_display_op
@@ -1782,7 +1782,7 @@ def bool_value(self, value: Value) -> Value:
17821782
result = self.add(ComparisonOp(value, zero, ComparisonOp.NEQ))
17831783
elif is_same_type(value.type, str_rprimitive):
17841784
result = self.call_c(str_check_if_true, [value], value.line)
1785-
elif is_same_type(value.type, true_dict_rprimitive):
1785+
elif is_same_type(value.type, exact_dict_rprimitive):
17861786
result = self.call_c(dict_is_true_op, [value], line=value.line)
17871787
elif is_same_type(value.type, list_rprimitive) or is_same_type(
17881788
value.type, dict_rprimitive
@@ -2289,7 +2289,7 @@ def builtin_len(self, val: Value, line: int, use_pyssize_t: bool = False) -> Val
22892289
elem_address = self.add(GetElementPtr(val, PySetObject, "used"))
22902290
size_value = self.load_mem(elem_address, c_pyssize_t_rprimitive)
22912291
self.add(KeepAlive([val]))
2292-
elif is_true_dict_rprimitive(typ):
2292+
elif is_exact_dict_rprimitive(typ):
22932293
size_value = self.call_c(true_dict_ssize_t_size_op, [val], line)
22942294
elif is_dict_rprimitive(typ):
22952295
size_value = self.call_c(dict_ssize_t_size_op, [val], line)

mypyc/irbuild/mapper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
range_rprimitive,
4545
set_rprimitive,
4646
str_rprimitive,
47-
true_dict_rprimitive,
47+
exact_dict_rprimitive,
4848
tuple_rprimitive,
4949
uint8_rprimitive,
5050
)
@@ -94,7 +94,7 @@ def type_to_rtype(self, typ: Type | None) -> RType:
9494
# specifically support them, so make sure that dict operations
9595
# get optimized on them.
9696
elif typ.type.fullname == "builtins.dict":
97-
return true_dict_rprimitive
97+
return exact_dict_rprimitive
9898
elif any(cls.fullname == "builtins.dict" for cls in typ.type.mro):
9999
return dict_rprimitive
100100
elif typ.type.fullname == "builtins.set":
@@ -154,7 +154,7 @@ def type_to_rtype(self, typ: Type | None) -> RType:
154154
elif isinstance(typ, Overloaded):
155155
return object_rprimitive
156156
elif isinstance(typ, TypedDictType):
157-
return true_dict_rprimitive
157+
return exact_dict_rprimitive
158158
elif isinstance(typ, LiteralType):
159159
return self.type_to_rtype(typ.fallback)
160160
elif isinstance(typ, (UninhabitedType, UnboundType)):
@@ -169,7 +169,7 @@ def get_arg_rtype(self, typ: Type, kind: ArgKind) -> RType:
169169
if kind == ARG_STAR:
170170
return tuple_rprimitive
171171
elif kind == ARG_STAR2:
172-
return true_dict_rprimitive
172+
return exact_dict_rprimitive
173173
else:
174174
return self.type_to_rtype(typ)
175175

mypyc/irbuild/prepare.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
none_rprimitive,
5858
object_pointer_rprimitive,
5959
object_rprimitive,
60-
true_dict_rprimitive,
60+
exact_dict_rprimitive,
6161
tuple_rprimitive,
6262
)
6363
from mypyc.irbuild.mapper import Mapper
@@ -543,7 +543,7 @@ def prepare_init_method(cdef: ClassDef, ir: ClassIR, module_name: str, mapper: M
543543
[
544544
init_sig.args[0],
545545
RuntimeArg("args", tuple_rprimitive, ARG_STAR),
546-
RuntimeArg("kwargs", true_dict_rprimitive, ARG_STAR2),
546+
RuntimeArg("kwargs", exact_dict_rprimitive, ARG_STAR2),
547547
],
548548
init_sig.ret_type,
549549
)

mypyc/irbuild/specialize.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@
6464
is_int64_rprimitive,
6565
is_int_rprimitive,
6666
is_list_rprimitive,
67-
is_true_dict_rprimitive,
67+
is_exact_dict_rprimitive,
6868
is_uint8_rprimitive,
6969
list_rprimitive,
7070
set_rprimitive,
7171
str_rprimitive,
72-
true_dict_rprimitive,
72+
exact_dict_rprimitive,
7373
uint8_rprimitive,
7474
)
7575
from mypyc.irbuild.builder import IRBuilder
@@ -254,17 +254,17 @@ def dict_methods_fast_path(builder: IRBuilder, expr: CallExpr, callee: RefExpr)
254254
# so the corresponding helpers in CPy.h fallback to (inlined)
255255
# generic logic.
256256
if attr == "keys":
257-
if is_true_dict_rprimitive(rtype):
257+
if is_exact_dict_rprimitive(rtype):
258258
op = true_dict_keys_op
259259
else:
260260
op = dict_keys_op
261261
elif attr == "values":
262-
if is_true_dict_rprimitive(rtype):
262+
if is_exact_dict_rprimitive(rtype):
263263
op = true_dict_values_op
264264
else:
265265
op = dict_values_op
266266
else:
267-
if is_true_dict_rprimitive(rtype):
267+
if is_exact_dict_rprimitive(rtype):
268268
op = true_dict_items_op
269269
else:
270270
op = dict_items_op
@@ -378,7 +378,7 @@ def faster_min_max(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Value
378378
@specialize_function("join", str_rprimitive)
379379
@specialize_function("extend", list_rprimitive)
380380
@specialize_function("update", dict_rprimitive)
381-
@specialize_function("update", true_dict_rprimitive)
381+
@specialize_function("update", exact_dict_rprimitive)
382382
@specialize_function("update", set_rprimitive)
383383
def translate_safe_generator_call(
384384
builder: IRBuilder, expr: CallExpr, callee: RefExpr
@@ -620,7 +620,7 @@ def translate_isinstance(builder: IRBuilder, expr: CallExpr, callee: RefExpr) ->
620620

621621

622622
@specialize_function("setdefault", dict_rprimitive)
623-
@specialize_function("setdefault", true_dict_rprimitive)
623+
@specialize_function("setdefault", exact_dict_rprimitive)
624624
def translate_dict_setdefault(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Value | None:
625625
"""Special case for 'dict.setdefault' which would only construct
626626
default empty collection when needed.

0 commit comments

Comments
 (0)