3838from rez .vendor .version .requirement import VersionedObject , Requirement , \
3939 RequirementList
4040from rez .vendor .enum import Enum
41- from rez .vendor .sortedcontainers .sortedset import SortedSet
4241from contextlib import contextmanager
42+ from itertools import product , chain
4343import copy
4444import time
4545import sys
@@ -1419,47 +1419,46 @@ def _create_phase(status=None):
14191419 changed_scopes_i = set (range (num_scopes ))
14201420 prev_num_scopes = num_scopes
14211421
1422- # create set of pending reductions from the list of changed scopes
1423- # and list of added scopes. We use a sorted set because the solver
1424- # must be deterministic, ie its behavior must always be the same for
1425- # a given solve. A normal set does not guarantee order.
1422+ # Create set of pending reductions from the list of changed scopes
1423+ # and list of added scopes. Each item is an (x, y) tuple, where
1424+ # scope[x] will reduce by scope[y].package_request.
14261425 #
1427- # Each item is an (x, y) tuple, where scope[x] will reduce by
1428- # scope[y].package_request.
1429- #
1430- pending_reducts = SortedSet ()
14311426 all_scopes_i = range (num_scopes )
1427+ prev_scopes_i = range (prev_num_scopes )
14321428 added_scopes_i = range (prev_num_scopes , num_scopes )
14331429
1434- for x in range (prev_num_scopes ):
1430+ pending_reducts = set (chain (
1431+
14351432 # existing scopes must reduce against changed scopes
1436- for y in changed_scopes_i :
1437- if x != y :
1438- pending_reducts .add ((x , y ))
1433+ product (prev_scopes_i , changed_scopes_i ),
14391434
14401435 # existing scopes must reduce against newly added scopes
1441- for y in added_scopes_i :
1442- pending_reducts .add ((x , y ))
1443-
1444- # newly added scopes must reduce against all other scopes
1445- for x in added_scopes_i :
1446- for y in all_scopes_i :
1447- if x != y :
1448- pending_reducts .add ((x , y ))
1449-
1450- # 'widened' scopes (see earlier comment in this func) must reduce
1451- # against all other scopes
1452- for x in widened_scopes_i :
1453- for y in all_scopes_i :
1454- if x != y :
1455- pending_reducts .add ((x , y ))
1436+ product (prev_scopes_i , added_scopes_i ),
1437+
1438+ # newly added scopes must reduce against all other scopes
1439+ product (added_scopes_i , all_scopes_i ),
1440+
1441+ # 'widened' scopes (see earlier comment in this func) must reduce
1442+ # against all other scopes
1443+ #
1444+ product (widened_scopes_i , all_scopes_i )
1445+ ))
14561446
14571447 # iteratively reduce until there are no more pending reductions.
14581448 # Note that if a scope is reduced, then other scopes need to reduce
14591449 # against it once again.
1450+ #
14601451 with self .solver .timed (self .solver .reduction_test_time ):
1452+
1453+ # A different order here wouldn't cause an invalid solve, however
1454+ # rez solves must be deterministic, so this is why we sort.
1455+ #
1456+ pending_reducts = sorted (pending_reducts )
1457+
14611458 while pending_reducts :
14621459 x , y = pending_reducts .pop ()
1460+ if x == y :
1461+ continue
14631462
14641463 new_scope , reductions = scopes [x ].reduce_by (
14651464 scopes [y ].package_request )
@@ -1474,7 +1473,7 @@ def _create_phase(status=None):
14741473 # other scopes need to reduce against x again
14751474 for j in all_scopes_i :
14761475 if j != x :
1477- pending_reducts .add ((j , x ))
1476+ pending_reducts .append ((j , x ))
14781477
14791478 changed_scopes_i = set ()
14801479
0 commit comments