@@ -26,7 +26,7 @@ use super::{
26
26
pub struct AutoInsertApplyDeferredPass {
27
27
/// Dependency edges that will **not** automatically insert an instance of `ApplyDeferred` on the edge.
28
28
no_sync_edges : BTreeSet < ( NodeId , NodeId ) > ,
29
- auto_sync_node_ids : HashMap < u32 , NodeId > ,
29
+ auto_sync_node_ids : HashMap < u32 , SystemKey > ,
30
30
}
31
31
32
32
/// If added to a dependency edge, the edge will not be considered for auto sync point insertions.
@@ -35,14 +35,14 @@ pub struct IgnoreDeferred;
35
35
impl AutoInsertApplyDeferredPass {
36
36
/// Returns the `NodeId` of the cached auto sync point. Will create
37
37
/// a new one if needed.
38
- fn get_sync_point ( & mut self , graph : & mut ScheduleGraph , distance : u32 ) -> NodeId {
38
+ fn get_sync_point ( & mut self , graph : & mut ScheduleGraph , distance : u32 ) -> SystemKey {
39
39
self . auto_sync_node_ids
40
40
. get ( & distance)
41
41
. copied ( )
42
42
. unwrap_or_else ( || {
43
- let node_id = NodeId :: System ( self . add_auto_sync ( graph) ) ;
44
- self . auto_sync_node_ids . insert ( distance, node_id ) ;
45
- node_id
43
+ let key = self . add_auto_sync ( graph) ;
44
+ self . auto_sync_node_ids . insert ( distance, key ) ;
45
+ key
46
46
} )
47
47
}
48
48
/// add an [`ApplyDeferred`] system with no config
@@ -72,7 +72,7 @@ impl ScheduleBuildPass for AutoInsertApplyDeferredPass {
72
72
& mut self ,
73
73
_world : & mut World ,
74
74
graph : & mut ScheduleGraph ,
75
- dependency_flattened : & mut DiGraph ,
75
+ dependency_flattened : & mut DiGraph < SystemKey > ,
76
76
) -> Result < ( ) , ScheduleBuildError > {
77
77
let mut sync_point_graph = dependency_flattened. clone ( ) ;
78
78
let topo = graph. topsort_graph ( dependency_flattened, ReportCycles :: Dependency ) ?;
@@ -119,14 +119,10 @@ impl ScheduleBuildPass for AutoInsertApplyDeferredPass {
119
119
HashMap :: with_capacity_and_hasher ( topo. len ( ) , Default :: default ( ) ) ;
120
120
121
121
// Keep track of any explicit sync nodes for a specific distance.
122
- let mut distance_to_explicit_sync_node: HashMap < u32 , NodeId > = HashMap :: default ( ) ;
122
+ let mut distance_to_explicit_sync_node: HashMap < u32 , SystemKey > = HashMap :: default ( ) ;
123
123
124
124
// Determine the distance for every node and collect the explicit sync points.
125
- for node in & topo {
126
- let & NodeId :: System ( key) = node else {
127
- panic ! ( "Encountered a non-system node in the flattened dependency graph: {node:?}" ) ;
128
- } ;
129
-
125
+ for & key in & topo {
130
126
let ( node_distance, mut node_needs_sync) = distances_and_pending_sync
131
127
. get ( & key)
132
128
. copied ( )
@@ -137,7 +133,7 @@ impl ScheduleBuildPass for AutoInsertApplyDeferredPass {
137
133
// makes sure that this node is no unvisited target of another node.
138
134
// Because of this, the sync point can be stored for this distance to be reused as
139
135
// automatically added sync points later.
140
- distance_to_explicit_sync_node. insert ( node_distance, NodeId :: System ( key) ) ;
136
+ distance_to_explicit_sync_node. insert ( node_distance, key) ;
141
137
142
138
// This node just did a sync, so the only reason to do another sync is if one was
143
139
// explicitly scheduled afterwards.
@@ -148,10 +144,7 @@ impl ScheduleBuildPass for AutoInsertApplyDeferredPass {
148
144
node_needs_sync = graph. systems [ key] . has_deferred ( ) ;
149
145
}
150
146
151
- for target in dependency_flattened. neighbors_directed ( * node, Direction :: Outgoing ) {
152
- let NodeId :: System ( target) = target else {
153
- panic ! ( "Encountered a non-system node in the flattened dependency graph: {target:?}" ) ;
154
- } ;
147
+ for target in dependency_flattened. neighbors_directed ( key, Direction :: Outgoing ) {
155
148
let ( target_distance, target_pending_sync) =
156
149
distances_and_pending_sync. entry ( target) . or_default ( ) ;
157
150
@@ -160,7 +153,7 @@ impl ScheduleBuildPass for AutoInsertApplyDeferredPass {
160
153
&& !graph. systems [ target] . is_exclusive ( )
161
154
&& self
162
155
. no_sync_edges
163
- . contains ( & ( * node , NodeId :: System ( target) ) )
156
+ . contains ( & ( NodeId :: System ( key ) , NodeId :: System ( target) ) )
164
157
{
165
158
// The node has deferred params to apply, but this edge is ignoring sync points.
166
159
// Mark the target as 'delaying' those commands to a future edge and the current
@@ -184,19 +177,13 @@ impl ScheduleBuildPass for AutoInsertApplyDeferredPass {
184
177
185
178
// Find any edges which have a different number of sync points between them and make sure
186
179
// there is a sync point between them.
187
- for node in & topo {
188
- let & NodeId :: System ( key) = node else {
189
- panic ! ( "Encountered a non-system node in the flattened dependency graph: {node:?}" ) ;
190
- } ;
180
+ for & key in & topo {
191
181
let ( node_distance, _) = distances_and_pending_sync
192
182
. get ( & key)
193
183
. copied ( )
194
184
. unwrap_or_default ( ) ;
195
185
196
- for target in dependency_flattened. neighbors_directed ( * node, Direction :: Outgoing ) {
197
- let NodeId :: System ( target) = target else {
198
- panic ! ( "Encountered a non-system node in the flattened dependency graph: {target:?}" ) ;
199
- } ;
186
+ for target in dependency_flattened. neighbors_directed ( key, Direction :: Outgoing ) {
200
187
let ( target_distance, _) = distances_and_pending_sync
201
188
. get ( & target)
202
189
. copied ( )
@@ -218,11 +205,11 @@ impl ScheduleBuildPass for AutoInsertApplyDeferredPass {
218
205
. copied ( )
219
206
. unwrap_or_else ( || self . get_sync_point ( graph, target_distance) ) ;
220
207
221
- sync_point_graph. add_edge ( * node , sync_point) ;
222
- sync_point_graph. add_edge ( sync_point, NodeId :: System ( target) ) ;
208
+ sync_point_graph. add_edge ( key , sync_point) ;
209
+ sync_point_graph. add_edge ( sync_point, target) ;
223
210
224
211
// The edge without the sync point is now redundant.
225
- sync_point_graph. remove_edge ( * node , NodeId :: System ( target) ) ;
212
+ sync_point_graph. remove_edge ( key , target) ;
226
213
}
227
214
}
228
215
@@ -234,14 +221,14 @@ impl ScheduleBuildPass for AutoInsertApplyDeferredPass {
234
221
& mut self ,
235
222
set : SystemSetKey ,
236
223
systems : & [ SystemKey ] ,
237
- dependency_flattened : & DiGraph ,
224
+ dependency_flattening : & DiGraph < NodeId > ,
238
225
) -> impl Iterator < Item = ( NodeId , NodeId ) > {
239
226
if systems. is_empty ( ) {
240
227
// collapse dependencies for empty sets
241
- for a in dependency_flattened . neighbors_directed ( NodeId :: Set ( set) , Direction :: Incoming )
228
+ for a in dependency_flattening . neighbors_directed ( NodeId :: Set ( set) , Direction :: Incoming )
242
229
{
243
230
for b in
244
- dependency_flattened . neighbors_directed ( NodeId :: Set ( set) , Direction :: Outgoing )
231
+ dependency_flattening . neighbors_directed ( NodeId :: Set ( set) , Direction :: Outgoing )
245
232
{
246
233
if self . no_sync_edges . contains ( & ( a, NodeId :: Set ( set) ) )
247
234
&& self . no_sync_edges . contains ( & ( NodeId :: Set ( set) , b) )
@@ -251,7 +238,7 @@ impl ScheduleBuildPass for AutoInsertApplyDeferredPass {
251
238
}
252
239
}
253
240
} else {
254
- for a in dependency_flattened . neighbors_directed ( NodeId :: Set ( set) , Direction :: Incoming )
241
+ for a in dependency_flattening . neighbors_directed ( NodeId :: Set ( set) , Direction :: Incoming )
255
242
{
256
243
for & sys in systems {
257
244
if self . no_sync_edges . contains ( & ( a, NodeId :: Set ( set) ) ) {
@@ -260,7 +247,7 @@ impl ScheduleBuildPass for AutoInsertApplyDeferredPass {
260
247
}
261
248
}
262
249
263
- for b in dependency_flattened . neighbors_directed ( NodeId :: Set ( set) , Direction :: Outgoing )
250
+ for b in dependency_flattening . neighbors_directed ( NodeId :: Set ( set) , Direction :: Outgoing )
264
251
{
265
252
for & sys in systems {
266
253
if self . no_sync_edges . contains ( & ( NodeId :: Set ( set) , b) ) {
0 commit comments