@@ -121,11 +121,11 @@ unsafe fn is_safe_point(pc: *Word) -> Option<SafePoint> {
121
121
return None ;
122
122
}
123
123
124
- type Visitor < ' self > = & ' self fn ( root : * * Word , tydesc : * TyDesc ) -> bool ;
124
+ type Visitor < ' self > = & ' self fn ( root : * * Word , tydesc : * TyDesc ) ;
125
125
126
126
// Walks the list of roots for the given safe point, and calls visitor
127
127
// on each root.
128
- unsafe fn _walk_safe_point ( fp : * Word , sp : SafePoint , visitor : Visitor ) -> bool {
128
+ unsafe fn _walk_safe_point ( fp : * Word , sp : SafePoint , visitor : Visitor ) {
129
129
let fp_bytes = fp as * u8 ;
130
130
let sp_meta = sp. sp_meta as * u32 ;
131
131
@@ -151,7 +151,7 @@ unsafe fn _walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) -> bool {
151
151
} else {
152
152
ptr:: null ( )
153
153
} ;
154
- if ! visitor ( root, tydesc) { return false ; }
154
+ visitor ( root, tydesc) ;
155
155
}
156
156
sri += 1 ;
157
157
}
@@ -164,10 +164,9 @@ unsafe fn _walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) -> bool {
164
164
}
165
165
rri += 1 ;
166
166
}
167
- return true ;
168
167
}
169
168
170
- unsafe fn walk_safe_point ( fp : * Word , sp : SafePoint , visitor : Visitor ) -> bool {
169
+ unsafe fn walk_safe_point ( fp : * Word , sp : SafePoint , visitor : Visitor ) {
171
170
_walk_safe_point ( fp, sp, visitor)
172
171
}
173
172
@@ -223,15 +222,15 @@ static need_cleanup: Memory = exchange_heap | stack;
223
222
224
223
// Walks stack, searching for roots of the requested type, and passes
225
224
// each root to the visitor.
226
- unsafe fn _walk_gc_roots ( mem : Memory , sentinel : * * Word , visitor : Visitor ) -> bool {
225
+ unsafe fn _walk_gc_roots ( mem : Memory , sentinel : * * Word , visitor : Visitor ) {
227
226
let mut segment = rustrt:: rust_get_stack_segment ( ) ;
228
227
let mut last_ret: * Word = ptr:: null ( ) ;
229
228
// To avoid collecting memory used by the GC itself, skip stack
230
229
// frames until past the root GC stack frame. The root GC stack
231
230
// frame is marked by a sentinel, which is a box pointer stored on
232
231
// the stack.
233
232
let mut reached_sentinel = ptr:: is_null ( sentinel) ;
234
- for walk_stack |frame| {
233
+ do walk_stack |frame| {
235
234
let pc = last_ret;
236
235
let Segment { segment : next_segment, boundary : boundary} =
237
236
find_segment_for_frame ( frame. fp , segment) ;
@@ -248,53 +247,46 @@ unsafe fn _walk_gc_roots(mem: Memory, sentinel: **Word, visitor: Visitor) -> boo
248
247
let ret_offset = if boundary { 4 } else { 1 } ;
249
248
last_ret = * ptr:: offset ( frame. fp , ret_offset as int ) as * Word ;
250
249
251
- if ptr:: is_null ( pc) {
252
- loop ;
253
- }
254
-
255
- let mut delay_reached_sentinel = reached_sentinel;
256
- let sp = is_safe_point ( pc) ;
257
- match sp {
258
- Some ( sp_info) => {
259
- for walk_safe_point( frame. fp, sp_info) |root, tydesc| {
260
- // Skip roots until we see the sentinel.
261
- if !reached_sentinel {
262
- if root == sentinel {
263
- delay_reached_sentinel = true ;
264
- }
265
- loop ;
266
- }
267
-
268
- // Skip null pointers, which can occur when a
269
- // unique pointer has already been freed.
270
- if ptr:: is_null ( * root) {
271
- loop ;
272
- }
273
-
274
- if ptr:: is_null ( tydesc) {
275
- // Root is a generic box.
276
- let refcount = * * root;
277
- if mem | task_local_heap != 0 && refcount != -1 {
278
- if !visitor ( root, tydesc) { return false ; }
279
- } else if mem | exchange_heap != 0 && refcount == -1 {
280
- if !visitor ( root, tydesc) { return false ; }
281
- }
282
- } else {
283
- // Root is a non-immediate.
284
- if mem | stack != 0 {
285
- if !visitor ( root, tydesc) { return false ; }
250
+ if !ptr:: is_null ( pc) {
251
+
252
+ let mut delay_reached_sentinel = reached_sentinel;
253
+ let sp = is_safe_point ( pc) ;
254
+ match sp {
255
+ Some ( sp_info) => {
256
+ do walk_safe_point ( frame. fp , sp_info) |root, tydesc| {
257
+ // Skip roots until we see the sentinel.
258
+ if !reached_sentinel && root == sentinel {
259
+ delay_reached_sentinel = true ;
260
+ }
261
+
262
+ // Skip null pointers, which can occur when a
263
+ // unique pointer has already been freed.
264
+ if reached_sentinel && !ptr:: is_null ( * root) {
265
+ if ptr:: is_null ( tydesc) {
266
+ // Root is a generic box.
267
+ let refcount = * * root;
268
+ if mem | task_local_heap != 0 && refcount != -1 {
269
+ visitor ( root, tydesc) ;
270
+ } else if mem | exchange_heap != 0 && refcount == -1 {
271
+ visitor ( root, tydesc) ;
272
+ }
273
+ } else {
274
+ // Root is a non-immediate.
275
+ if mem | stack != 0 {
276
+ visitor ( root, tydesc) ;
277
+ }
278
+ }
279
+ }
286
280
}
287
281
}
282
+ None => ( )
288
283
}
289
- }
290
- None => ( )
284
+ reached_sentinel = delay_reached_sentinel;
291
285
}
292
- reached_sentinel = delay_reached_sentinel;
293
286
}
294
- return true ;
295
287
}
296
288
297
- unsafe fn walk_gc_roots ( mem : Memory , sentinel : * * Word , visitor : Visitor ) -> bool {
289
+ unsafe fn walk_gc_roots ( mem : Memory , sentinel : * * Word , visitor : Visitor ) {
298
290
_walk_gc_roots ( mem, sentinel, visitor)
299
291
}
300
292
pub fn gc ( ) {
@@ -304,7 +296,7 @@ pub fn gc() {
304
296
return ;
305
297
}
306
298
307
- for walk_gc_roots( task_local_heap, ptr:: null( ) ) |_root, _tydesc| {
299
+ do walk_gc_roots ( task_local_heap, ptr:: null ( ) ) |_root, _tydesc| {
308
300
// FIXME(#2997): Walk roots and mark them.
309
301
io:: stdout ( ) . write ( [ 46 ] ) ; // .
310
302
}
@@ -349,18 +341,17 @@ pub fn cleanup_stack_for_failure() {
349
341
} ;
350
342
351
343
let mut roots = HashSet :: new ( ) ;
352
- for walk_gc_roots( need_cleanup, sentinel) |root, tydesc| {
344
+ do walk_gc_roots ( need_cleanup, sentinel) |root, tydesc| {
353
345
// Track roots to avoid double frees.
354
- if roots. contains ( & * root) {
355
- loop ;
356
- }
357
- roots. insert ( * root) ;
346
+ if !roots. contains ( & * root) {
347
+ roots. insert ( * root) ;
358
348
359
- if ptr:: is_null ( tydesc) {
360
- // FIXME #4420: Destroy this box
361
- // FIXME #4330: Destroy this box
362
- } else {
363
- ( ( * tydesc) . drop_glue ) ( * root as * i8 ) ;
349
+ if ptr:: is_null ( tydesc) {
350
+ // FIXME #4420: Destroy this box
351
+ // FIXME #4330: Destroy this box
352
+ } else {
353
+ ( ( * tydesc) . drop_glue ) ( * root as * i8 ) ;
354
+ }
364
355
}
365
356
}
366
357
}
0 commit comments