@@ -1056,14 +1056,20 @@ def truncated_graph_inputs(
10561056 truncated_inputs .append (node )
10571057 # no more actions are needed
10581058 return truncated_inputs
1059+
10591060 blockers : Set [Variable ] = set (ancestors_to_include )
10601061 # enforce O(1) check for node in ancestors to include
10611062 ancestors_to_include = blockers .copy ()
10621063
10631064 while candidates :
10641065 # on any new candidate
10651066 node = candidates .pop ()
1066- # check if the node is independent, never go above blockers
1067+
1068+ # There was a repeated reference to this node, we have already investigated it
1069+ if node in truncated_inputs :
1070+ continue
1071+
1072+ # check if the node is independent, never go above blockers;
10671073 # blockers are independent nodes and ancestors to include
10681074 if node in ancestors_to_include :
10691075 # The case where node is in ancestors to include so we check if it depends on others
@@ -1073,30 +1079,25 @@ def truncated_graph_inputs(
10731079 # should be added to truncated_inputs
10741080 truncated_inputs .append (node )
10751081 if dependent :
1076- # if the ancestors to include is still dependent we need to go above,
1077- # the search is not yet finished
1078- # the node _has_ to have owner to be dependent
1079- # so we do not check it
1080- # and populate search to go above
1082+ # if the ancestors to include is still dependent we need to go above, the search is not yet finished
10811083 # owner can never be None for a dependent node
10821084 candidates .extend (node .owner .inputs )
10831085 else :
10841086 # A regular node to check
10851087 dependent = variable_depends_on (node , blockers )
1086- # all regular nodes fall to blockes
1088+ # all regular nodes fall to blockers
10871089 # 1. it is dependent - further search irrelevant
10881090 # 2. it is independent - the search node is inside the closure
10891091 blockers .add (node )
10901092 # if we've found an independent node and it is not in blockers so far
1091- # it is a new indepenent node not present in ancestors to include
1092- if not dependent :
1093- # we've found an independent node
1094- # do not search beyond
1095- truncated_inputs .append (node )
1096- else :
1097- # populate search otherwise
1093+ # it is a new independent node not present in ancestors to include
1094+ if dependent :
1095+ # populate search if it's not an independent node
10981096 # owner can never be None for a dependent node
10991097 candidates .extend (node .owner .inputs )
1098+ else :
1099+ # otherwise, do not search beyond
1100+ truncated_inputs .append (node )
11001101 return truncated_inputs
11011102
11021103
0 commit comments