Skip to content

Commit 16c9f0a

Browse files
committed
Remove strict argument from zip (for Python 3.9 compatibility)
This commit removes the strict argument from all uses of zip and instead places an equivalent assertion on the lengths of the inputs just before the zip. The strict argument only got added to zip in Python 3.10.
1 parent 1935e5e commit 16c9f0a

3 files changed

Lines changed: 49 additions & 26 deletions

File tree

slothy/core/core.py

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,9 +1776,8 @@ def _mark_loop_siblings(self):
17761776
if not self.config.sw_pipelining.enabled:
17771777
return
17781778

1779-
for tlow, thigh in zip(
1780-
self._model.tree.nodes_low, self._model.tree.nodes_high, strict=True
1781-
):
1779+
assert len(self._model.tree.nodes_low) == len(self._model.tree.nodes_high)
1780+
for tlow, thigh in zip(self._model.tree.nodes_low, self._model.tree.nodes_high):
17821781
tlow.sibling = thigh
17831782
thigh.sibling = tlow
17841783

@@ -2346,16 +2345,20 @@ def remember_spill(i, spilled, restore, arg, txt):
23462345
spills[p].append((arg, spill_id))
23472346
restores[restore].append((arg, spill_id))
23482347

2348+
assert len(t.out_spills) == len(t.out_lifetime_start)
2349+
assert len(t.out_spills) == len(t.inst.args_out)
23492350
for i, (spilled, restore, arg) in enumerate(
2350-
zip(t.out_spills, t.out_lifetime_start, t.inst.args_out, strict=True)
2351+
zip(t.out_spills, t.out_lifetime_start, t.inst.args_out)
23512352
):
23522353
remember_spill(i, spilled, restore, arg, "out")
2354+
2355+
assert len(t.in_out_spills) == len(t.inout_lifetime_start)
2356+
assert len(t.in_out_spills) == len(t.inst.args_in_out)
23532357
for i, (spilled, restore, arg) in enumerate(
23542358
zip(
23552359
t.in_out_spills,
23562360
t.inout_lifetime_start,
23572361
t.inst.args_in_out,
2358-
strict=True,
23592362
)
23602363
):
23612364
remember_spill(i, spilled, restore, arg, "inout")
@@ -2521,11 +2524,13 @@ def _add_path_constraint_from(self, consumer, producer, cb_lst):
25212524
or producer.is_virtual
25222525
or consumer.is_virtual
25232526
):
2524-
for cb, bvar in zip(cb_lst, bvars, strict=True):
2527+
assert len(cb_lst) == len(bvars)
2528+
for cb, bvar in zip(cb_lst, bvars):
25252529
cb().OnlyEnforceIf(bvar)
25262530
return
25272531

2528-
for cb, bvar in zip(cb_lst, bvars, strict=True):
2532+
assert len(cb_lst) == len(vars)
2533+
for cb, bvar in zip(cb_lst, bvars):
25292534
constraints = [bvar]
25302535
if self._is_low(producer):
25312536
constraints.append(producer.pre_var.Not())
@@ -2729,11 +2734,12 @@ def _allow_renaming(_):
27292734
self.logger.debug("Create register renaming variables for %s", t)
27302735

27312736
# Iterate through output registers of current instruction
2737+
assert len(t.inst.arg_types_out) == len(t.inst.args_out)
2738+
assert len(t.inst.arg_types_out) == len(t.inst.args_out_restrictions)
27322739
for arg_ty, arg_out, restrictions in zip(
27332740
t.inst.arg_types_out,
27342741
t.inst.args_out,
27352742
t.inst.args_out_restrictions,
2736-
strict=True,
27372743
):
27382744

27392745
self.logger.debug("- Output %s (%s)", arg_out, arg_ty)
@@ -2867,6 +2873,12 @@ def add_arg_combination_vars(combinations, vs, name, t=t):
28672873
self._NewBoolVar("") for _ in t.inst.arg_types_in_out
28682874
]
28692875
ivals = []
2876+
2877+
assert len(t.inst.arg_types_out) == len(t.alloc_out_var)
2878+
assert len(t.inst.arg_types_out) == len(t.out_lifetime_start)
2879+
assert len(t.inst.arg_types_out) == len(t.out_lifetime_duration)
2880+
assert len(t.inst.arg_types_out) == len(t.out_lifetime_end)
2881+
assert len(t.inst.arg_types_out) == len(t.out_spill_vars)
28702882
ivals += list(
28712883
zip(
28722884
t.inst.arg_types_out,
@@ -2875,9 +2887,13 @@ def add_arg_combination_vars(combinations, vs, name, t=t):
28752887
t.out_lifetime_duration,
28762888
t.out_lifetime_end,
28772889
t.out_spill_vars,
2878-
strict=True,
28792890
)
28802891
)
2892+
assert len(t.inst.arg_types_in_out) == len(t.alloc_in_out_var)
2893+
assert len(t.inst.arg_types_in_out) == len(t.inout_lifetime_start)
2894+
assert len(t.inst.arg_types_in_out) == len(t.inout_lifetime_duration)
2895+
assert len(t.inst.arg_types_in_out) == len(t.inout_lifetime_end)
2896+
assert len(t.inst.arg_types_in_out) == len(t.in_out_spill_vars)
28812897
ivals += list(
28822898
zip(
28832899
t.inst.arg_types_in_out,
@@ -2886,7 +2902,6 @@ def add_arg_combination_vars(combinations, vs, name, t=t):
28862902
t.inout_lifetime_duration,
28872903
t.inout_lifetime_end,
28882904
t.in_out_spill_vars,
2889-
strict=True,
28902905
)
28912906
)
28922907

@@ -3006,7 +3021,8 @@ def _has_cross_iteration_dependencies(self):
30063021
def _add_constraints_lifetime_bounds_single(self, t):
30073022

30083023
def _add_basic_constraints(start_list, end_list):
3009-
for start_var, end_var in zip(start_list, end_list, strict=True):
3024+
assert len(start_list) == len(end_list)
3025+
for start_var, end_var in zip(start_list, end_list):
30103026
# Make sure the output argument is considered 'used' for at least
30113027
# one instruction. Otherwise, instructions producing outputs that
30123028
# are never used would be able to overwrite life registers.
@@ -3053,12 +3069,13 @@ def _add_constraints_lifetime_bounds(self):
30533069
def _force_allocation_variant(self, alloc_dict, combinations, combination_vars):
30543070
if combinations is None:
30553071
return
3056-
for (idx_lst, valid_combinations), vs in zip(
3057-
combinations, combination_vars, strict=True
3058-
):
3072+
assert len(combinations) == len(combination_vars)
3073+
for (idx_lst, valid_combinations), vs in zip(combinations, combination_vars):
30593074
self._AddExactlyOne(vs)
3060-
for combination, var in zip(valid_combinations, vs, strict=True):
3061-
for idx, reg in zip(idx_lst, combination, strict=True):
3075+
assert len(valid_combinations) == len(vs)
3076+
for combination, var in zip(valid_combinations, vs):
3077+
assert len(idx_lst) == len(combination)
3078+
for idx, reg in zip(idx_lst, combination):
30623079
self._AddImplication(var, alloc_dict[idx].get(reg, False))
30633080

30643081
def _forbid_renaming_collision_single(self, var_dic_a, var_dic_b, condition=None):
@@ -3091,7 +3108,8 @@ def _force_allocation_restriction_single(self, valid_allocs, var_dict):
30913108
self._Add(v == False) # noqa: E712
30923109

30933110
def _force_allocation_restriction_many(self, restriction_lst, var_dict_lst):
3094-
for r, v in zip(restriction_lst, var_dict_lst, strict=True):
3111+
assert len(restriction_lst) == len(var_dict_lst)
3112+
for r, v in zip(restriction_lst, var_dict_lst):
30953113
if r is None:
30963114
continue
30973115
self._force_allocation_restriction_single(r, v)
@@ -3680,9 +3698,8 @@ def _add_constraints_loop_periodic(self):
36803698
# Additionally, they should use exactly the same registers, so we can roll the
36813699
# loop again
36823700

3683-
for t0, t1 in zip(
3684-
self._model.tree.nodes_low, self._model.tree.nodes_high, strict=True
3685-
):
3701+
assert len(self._model.tree.nodes_low) == len(self._model.tree.nodes_high)
3702+
for t0, t1 in zip(self._model.tree.nodes_low, self._model.tree.nodes_high):
36863703
self._Add(t0.pre_var == t1.pre_var)
36873704
self._Add(t0.post_var == t1.post_var)
36883705
self._Add(t0.core_var == t1.core_var)

slothy/targets/aarch64/aarch64_neon.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -962,9 +962,12 @@ def __init__(
962962
self.in_outs = in_outs
963963

964964
self.pattern = pattern
965-
self.pattern_inputs = list(zip(inputs, arg_types_in, strict=True))
966-
self.pattern_outputs = list(zip(outputs, arg_types_out, strict=True))
967-
self.pattern_in_outs = list(zip(in_outs, arg_types_in_out, strict=True))
965+
assert len(inputs) == len(arg_types_in)
966+
self.pattern_inputs = list(zip(inputs, arg_types_in))
967+
assert len(outputs) == len(arg_types_out)
968+
self.pattern_outputs = list(zip(outputs, arg_types_out))
969+
assert len(in_outs) == len(arg_types_in_out)
970+
self.pattern_in_outs = list(zip(in_outs, arg_types_in_out))
968971

969972
@staticmethod
970973
def _to_reg(ty, s):

slothy/targets/arm_v7m/arch_v7m.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,9 +1184,12 @@ def __init__(
11841184
self.in_outs = in_outs
11851185

11861186
self.pattern = pattern
1187-
self.pattern_inputs = list(zip(inputs, arg_types_in, strict=True))
1188-
self.pattern_outputs = list(zip(outputs, arg_types_out, strict=True))
1189-
self.pattern_in_outs = list(zip(in_outs, arg_types_in_out, strict=True))
1187+
assert len(inputs) == len(arg_types_in)
1188+
self.pattern_inputs = list(zip(inputs, arg_types_in))
1189+
assert len(outputs) == len(arg_types_out)
1190+
self.pattern_outputs = list(zip(outputs, arg_types_out))
1191+
assert len(in_outs) == len(arg_types_in_out)
1192+
self.pattern_in_outs = list(zip(in_outs, arg_types_in_out))
11901193

11911194
@staticmethod
11921195
def _to_reg(ty, s):

0 commit comments

Comments
 (0)