Skip to content

Commit b1bf9ef

Browse files
committed
Break fold's circular reference during unwinding
This converts the AST fold into a resource that breaks it's own circular reference (just a temporary workaround until GC), so that failure during fold will unwind correctly. Issue #936
1 parent 939a9dd commit b1bf9ef

File tree

6 files changed

+7
-11
lines changed

6 files changed

+7
-11
lines changed

src/comp/front/config.rs

-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ fn strip_unconfigured_items(crate: @ast::crate) -> @ast::crate {
1717

1818
let fold = fold::make_fold(precursor);
1919
let res = @fold.fold_crate(*crate);
20-
// FIXME: This is necessary to break a circular reference
21-
fold::dummy_out(fold);
2220
ret res;
2321
}
2422

src/comp/front/test.rs

-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ fn modify_for_testing(crate: @ast::crate) -> @ast::crate {
4747

4848
let fold = fold::make_fold(precursor);
4949
let res = @fold.fold_crate(*crate);
50-
// FIXME: This is necessary to break a circular reference
51-
fold::dummy_out(fold);
5250
ret res;
5351
}
5452

src/comp/syntax/ext/expand.rs

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ fn expand_crate(sess: session::session, c: @crate) -> @crate {
5656
with *afp};
5757
let f = make_fold(f_pre);
5858
let res = @f.fold_crate(*c);
59-
dummy_out(f); //temporary: kill circular reference
6059
ret res;
6160

6261
}

src/comp/syntax/ext/simplext.rs

-2
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ fn transcribe(cx: ext_ctxt, b: bindings, body: @expr) -> @expr {
206206
new_span: bind new_span(cx, _) with *afp};
207207
let f = make_fold(f_pre);
208208
let result = f.fold_expr(body);
209-
dummy_out(f); //temporary: kill circular reference
210209
ret result;
211210
}
212211

@@ -258,7 +257,6 @@ iter free_vars(b: bindings, e: @expr) -> ident {
258257
with *default_ast_fold()};
259258
let f = make_fold(f_pre);
260259
f.fold_expr(e); // ignore result
261-
dummy_out(f);
262260
for each id: ident in idents.keys() { put id; }
263261
}
264262

src/comp/syntax/fold.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,13 @@ fn dummy_out(a: ast_fold) {
563563
new_span: noop_span};
564564
}
565565

566+
// FIXME: Fold has a circular reference that has to be broken. With GC this
567+
// can go away
568+
resource foldres(f: ast_fold) {
569+
dummy_out(f);
570+
}
566571

567-
fn make_fold(afp: ast_fold_precursor) -> ast_fold {
572+
fn make_fold(afp: ast_fold_precursor) -> @foldres {
568573
let result: ast_fold =
569574
@mutable {fold_crate: nf_crate_dummy,
570575
fold_crate_directive: nf_crate_directive_dummy,
@@ -699,7 +704,7 @@ fn make_fold(afp: ast_fold_precursor) -> ast_fold {
699704
map_exprs: afp.map_exprs,
700705
new_id: afp.new_id,
701706
new_span: afp.new_span};
702-
ret result;
707+
ret @foldres(result);
703708
}
704709

705710

src/fuzzer/fuzzer.rs

-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ fn replace_expr_in_crate(crate: ast::crate, i: uint, newexpr: ast::expr) ->
149149
with *fold::default_ast_fold()};
150150
let af = fold::make_fold(afp);
151151
let crate2: @ast::crate = @af.fold_crate(crate);
152-
fold::dummy_out(af); // work around a leak (https://github.com/graydon/rust/issues/651)
153152
*crate2
154153
}
155154

@@ -170,7 +169,6 @@ fn replace_ty_in_crate(crate: ast::crate, i: uint, newty: ast::ty) ->
170169
with *fold::default_ast_fold()};
171170
let af = fold::make_fold(afp);
172171
let crate2: @ast::crate = @af.fold_crate(crate);
173-
fold::dummy_out(af); // work around a leak (https://github.com/graydon/rust/issues/651)
174172
*crate2
175173
}
176174

0 commit comments

Comments
 (0)