Skip to content

Commit 54c2a1e

Browse files
committed
rustc: Move the AST from @t to Gc<T>
1 parent 53ad426 commit 54c2a1e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1405
-1348
lines changed

src/doc/tutorial.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1710,14 +1710,14 @@ having ownership of the box. It allows the creation of cycles, and the individua
17101710
not have a destructor.
17111711

17121712
~~~
1713-
use std::gc::Gc;
1713+
use std::gc::GC;
17141714
17151715
// A fixed-size array allocated in a garbage-collected box
1716-
let x = Gc::new([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
1716+
let x = box(GC) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
17171717
let y = x; // does not perform a move, unlike with `Rc`
17181718
let z = x;
17191719
1720-
assert!(*z.borrow() == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
1720+
assert!(*z == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
17211721
~~~
17221722

17231723
With shared ownership, mutability cannot be inherited so the boxes are always immutable. However,

src/liballoc/rc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ mod tests {
320320
#[test]
321321
fn gc_inside() {
322322
// see issue #11532
323-
use realstd::gc::Gc;
323+
use std::gc::GC;
324324
let a = Rc::new(RefCell::new(box(GC) 1));
325325
assert!(a.try_borrow_mut().is_some());
326326
}

src/libcore/clone.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ extern_fn_clone!(A, B, C, D, E, F, G, H)
110110
mod test {
111111
use prelude::*;
112112
use realstd::owned::Box;
113+
use realstd::gc::{Gc, GC};
113114

114115
fn realclone<T: ::realstd::clone::Clone>(t: &T) -> T {
115116
use realstd::clone::Clone;
@@ -130,9 +131,9 @@ mod test {
130131

131132
#[test]
132133
fn test_managed_clone() {
133-
let a = @5i;
134-
let b: @int = a.clone();
135-
assert_eq!(a, b);
134+
let a = box(GC) 5i;
135+
let b: Gc<int> = realclone(&a);
136+
assert!(a == b);
136137
}
137138

138139
#[test]

src/librustc/driver/driver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ fn print_flowgraph<W:io::Writer>(analysis: CrateAnalysis,
705705
block: ast::P<ast::Block>,
706706
mut out: W) -> io::IoResult<()> {
707707
let ty_cx = &analysis.ty_cx;
708-
let cfg = cfg::CFG::new(ty_cx, block);
708+
let cfg = cfg::CFG::new(ty_cx, &*block);
709709
let lcfg = LabelledCFG { ast_map: &ty_cx.map,
710710
cfg: &cfg,
711711
name: format!("block{}", block.id).to_string(), };

src/librustc/front/config.rs

+25-23
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use syntax::fold::Folder;
1212
use syntax::{ast, fold, attr};
1313
use syntax::codemap;
1414

15+
use std::gc::Gc;
16+
1517
struct Context<'a> {
1618
in_cfg: |attrs: &[ast::Attribute]|: 'a -> bool,
1719
}
@@ -36,7 +38,7 @@ impl<'a> fold::Folder for Context<'a> {
3638
fn fold_item_underscore(&mut self, item: &ast::Item_) -> ast::Item_ {
3739
fold_item_underscore(self, item)
3840
}
39-
fn fold_expr(&mut self, expr: @ast::Expr) -> @ast::Expr {
41+
fn fold_expr(&mut self, expr: Gc<ast::Expr>) -> Gc<ast::Expr> {
4042
fold_expr(self, expr)
4143
}
4244
}
@@ -60,8 +62,8 @@ fn filter_view_item<'r>(cx: &mut Context, view_item: &'r ast::ViewItem)
6062
}
6163

6264
fn fold_mod(cx: &mut Context, m: &ast::Mod) -> ast::Mod {
63-
let filtered_items: Vec<&@ast::Item> = m.items.iter()
64-
.filter(|&a| item_in_cfg(cx, *a))
65+
let filtered_items: Vec<&Gc<ast::Item>> = m.items.iter()
66+
.filter(|a| item_in_cfg(cx, &***a))
6567
.collect();
6668
let flattened_items = filtered_items.move_iter()
6769
.flat_map(|&x| cx.fold_item(x).move_iter())
@@ -76,9 +78,9 @@ fn fold_mod(cx: &mut Context, m: &ast::Mod) -> ast::Mod {
7678
}
7779
}
7880

79-
fn filter_foreign_item(cx: &mut Context, item: @ast::ForeignItem)
80-
-> Option<@ast::ForeignItem> {
81-
if foreign_item_in_cfg(cx, item) {
81+
fn filter_foreign_item(cx: &mut Context, item: Gc<ast::ForeignItem>)
82+
-> Option<Gc<ast::ForeignItem>> {
83+
if foreign_item_in_cfg(cx, &*item) {
8284
Some(item)
8385
} else {
8486
None
@@ -103,7 +105,7 @@ fn fold_foreign_mod(cx: &mut Context, nm: &ast::ForeignMod) -> ast::ForeignMod {
103105
fn fold_item_underscore(cx: &mut Context, item: &ast::Item_) -> ast::Item_ {
104106
let item = match *item {
105107
ast::ItemImpl(ref a, ref b, c, ref methods) => {
106-
let methods = methods.iter().filter(|m| method_in_cfg(cx, **m))
108+
let methods = methods.iter().filter(|m| method_in_cfg(cx, &***m))
107109
.map(|x| *x).collect();
108110
ast::ItemImpl((*a).clone(), (*b).clone(), c, methods)
109111
}
@@ -114,8 +116,8 @@ fn fold_item_underscore(cx: &mut Context, item: &ast::Item_) -> ast::Item_ {
114116
.collect();
115117
ast::ItemTrait((*a).clone(), b, (*c).clone(), methods)
116118
}
117-
ast::ItemStruct(def, ref generics) => {
118-
ast::ItemStruct(fold_struct(cx, def), generics.clone())
119+
ast::ItemStruct(ref def, ref generics) => {
120+
ast::ItemStruct(fold_struct(cx, &**def), generics.clone())
119121
}
120122
ast::ItemEnum(ref def, ref generics) => {
121123
let mut variants = def.variants.iter().map(|c| c.clone()).
@@ -125,11 +127,11 @@ fn fold_item_underscore(cx: &mut Context, item: &ast::Item_) -> ast::Item_ {
125127
} else {
126128
Some(match v.node.kind {
127129
ast::TupleVariantKind(..) => v,
128-
ast::StructVariantKind(def) => {
129-
let def = fold_struct(cx, def);
130-
@codemap::Spanned {
130+
ast::StructVariantKind(ref def) => {
131+
let def = fold_struct(cx, &**def);
132+
box(GC) codemap::Spanned {
131133
node: ast::Variant_ {
132-
kind: ast::StructVariantKind(def),
134+
kind: ast::StructVariantKind(def.clone()),
133135
..v.node.clone()
134136
},
135137
..*v
@@ -148,24 +150,24 @@ fn fold_item_underscore(cx: &mut Context, item: &ast::Item_) -> ast::Item_ {
148150
fold::noop_fold_item_underscore(&item, cx)
149151
}
150152

151-
fn fold_struct(cx: &mut Context, def: &ast::StructDef) -> @ast::StructDef {
153+
fn fold_struct(cx: &mut Context, def: &ast::StructDef) -> Gc<ast::StructDef> {
152154
let mut fields = def.fields.iter().map(|c| c.clone()).filter(|m| {
153155
(cx.in_cfg)(m.node.attrs.as_slice())
154156
});
155-
@ast::StructDef {
157+
box(GC) ast::StructDef {
156158
fields: fields.collect(),
157159
ctor_id: def.ctor_id,
158160
super_struct: def.super_struct.clone(),
159161
is_virtual: def.is_virtual,
160162
}
161163
}
162164

163-
fn retain_stmt(cx: &mut Context, stmt: @ast::Stmt) -> bool {
165+
fn retain_stmt(cx: &mut Context, stmt: Gc<ast::Stmt>) -> bool {
164166
match stmt.node {
165167
ast::StmtDecl(decl, _) => {
166168
match decl.node {
167-
ast::DeclItem(item) => {
168-
item_in_cfg(cx, item)
169+
ast::DeclItem(ref item) => {
170+
item_in_cfg(cx, &**item)
169171
}
170172
_ => true
171173
}
@@ -175,10 +177,10 @@ fn retain_stmt(cx: &mut Context, stmt: @ast::Stmt) -> bool {
175177
}
176178

177179
fn fold_block(cx: &mut Context, b: ast::P<ast::Block>) -> ast::P<ast::Block> {
178-
let resulting_stmts: Vec<&@ast::Stmt> =
180+
let resulting_stmts: Vec<&Gc<ast::Stmt>> =
179181
b.stmts.iter().filter(|&a| retain_stmt(cx, *a)).collect();
180182
let resulting_stmts = resulting_stmts.move_iter()
181-
.flat_map(|&stmt| cx.fold_stmt(stmt).move_iter())
183+
.flat_map(|stmt| cx.fold_stmt(&**stmt).move_iter())
182184
.collect();
183185
let filtered_view_items = b.view_items.iter().filter_map(|a| {
184186
filter_view_item(cx, a).map(|x| cx.fold_view_item(x))
@@ -193,14 +195,14 @@ fn fold_block(cx: &mut Context, b: ast::P<ast::Block>) -> ast::P<ast::Block> {
193195
})
194196
}
195197

196-
fn fold_expr(cx: &mut Context, expr: @ast::Expr) -> @ast::Expr {
198+
fn fold_expr(cx: &mut Context, expr: Gc<ast::Expr>) -> Gc<ast::Expr> {
197199
let expr = match expr.node {
198200
ast::ExprMatch(ref m, ref arms) => {
199201
let arms = arms.iter()
200202
.filter(|a| (cx.in_cfg)(a.attrs.as_slice()))
201203
.map(|a| a.clone())
202204
.collect();
203-
@ast::Expr {
205+
box(GC) ast::Expr {
204206
id: expr.id,
205207
span: expr.span.clone(),
206208
node: ast::ExprMatch(m.clone(), arms),
@@ -236,7 +238,7 @@ fn trait_method_in_cfg(cx: &mut Context, meth: &ast::TraitMethod) -> bool {
236238

237239
// Determine if an item should be translated in the current crate
238240
// configuration based on the item's attributes
239-
fn in_cfg(cfg: &[@ast::MetaItem], attrs: &[ast::Attribute]) -> bool {
241+
fn in_cfg(cfg: &[Gc<ast::MetaItem>], attrs: &[ast::Attribute]) -> bool {
240242
attr::test_cfg(cfg, attrs.iter().map(|x| *x))
241243
}
242244

src/librustc/front/std_inject.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use syntax::parse::token;
2323
use syntax::util::small_vector::SmallVector;
2424

2525
use std::mem;
26+
use std::gc::Gc;
2627

2728
pub static VERSION: &'static str = "0.11.0-pre";
2829

@@ -165,12 +166,12 @@ impl<'a> fold::Folder for PreludeInjector<'a> {
165166
krate
166167
}
167168

168-
fn fold_item(&mut self, item: @ast::Item) -> SmallVector<@ast::Item> {
169+
fn fold_item(&mut self, item: Gc<ast::Item>) -> SmallVector<Gc<ast::Item>> {
169170
if !no_prelude(item.attrs.as_slice()) {
170171
// only recur if there wasn't `#![no_implicit_prelude]`
171172
// on this item, i.e. this means that the prelude is not
172173
// implicitly imported though the whole subtree
173-
fold::noop_fold_item(item, self)
174+
fold::noop_fold_item(&*item, self)
174175
} else {
175176
SmallVector::one(item)
176177
}
@@ -193,7 +194,8 @@ impl<'a> fold::Folder for PreludeInjector<'a> {
193194
}),
194195
};
195196

196-
let vp = @codemap::dummy_spanned(ast::ViewPathGlob(prelude_path, ast::DUMMY_NODE_ID));
197+
let vp = box(GC) codemap::dummy_spanned(ast::ViewPathGlob(prelude_path,
198+
ast::DUMMY_NODE_ID));
197199
let vi2 = ast::ViewItem {
198200
node: ast::ViewItemUse(vp),
199201
attrs: Vec::new(),

src/librustc/front/test.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use front::config;
1818
use front::std_inject::with_version;
1919

2020
use std::cell::RefCell;
21+
use std::gc::Gc;
2122
use std::slice;
22-
use std::vec::Vec;
2323
use std::vec;
2424
use syntax::ast_util::*;
2525
use syntax::attr::AttrMetaMethods;
@@ -86,7 +86,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
8686
}
8787
}
8888

89-
fn fold_item(&mut self, i: @ast::Item) -> SmallVector<@ast::Item> {
89+
fn fold_item(&mut self, i: Gc<ast::Item>) -> SmallVector<Gc<ast::Item>> {
9090
self.cx.path.borrow_mut().push(i.ident);
9191
debug!("current path: {}",
9292
ast_util::path_name_i(self.cx.path.borrow().as_slice()));
@@ -115,7 +115,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
115115
}
116116
}
117117

118-
let res = fold::noop_fold_item(i, self);
118+
let res = fold::noop_fold_item(&*i, self);
119119
self.cx.path.borrow_mut().pop();
120120
res
121121
}
@@ -124,8 +124,8 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
124124
// Remove any #[main] from the AST so it doesn't clash with
125125
// the one we're going to add. Only if compiling an executable.
126126

127-
fn nomain(item: @ast::Item) -> @ast::Item {
128-
@ast::Item {
127+
fn nomain(item: Gc<ast::Item>) -> Gc<ast::Item> {
128+
box(GC) ast::Item {
129129
attrs: item.attrs.iter().filter_map(|attr| {
130130
if !attr.name().equiv(&("main")) {
131131
Some(*attr)
@@ -188,10 +188,10 @@ fn strip_test_functions(krate: ast::Crate) -> ast::Crate {
188188
})
189189
}
190190

191-
fn is_test_fn(cx: &TestCtxt, i: @ast::Item) -> bool {
191+
fn is_test_fn(cx: &TestCtxt, i: Gc<ast::Item>) -> bool {
192192
let has_test_attr = attr::contains_name(i.attrs.as_slice(), "test");
193193

194-
fn has_test_signature(i: @ast::Item) -> bool {
194+
fn has_test_signature(i: Gc<ast::Item>) -> bool {
195195
match &i.node {
196196
&ast::ItemFn(ref decl, _, _, ref generics, _) => {
197197
let no_output = match decl.output.node {
@@ -217,10 +217,10 @@ fn is_test_fn(cx: &TestCtxt, i: @ast::Item) -> bool {
217217
return has_test_attr && has_test_signature(i);
218218
}
219219

220-
fn is_bench_fn(cx: &TestCtxt, i: @ast::Item) -> bool {
220+
fn is_bench_fn(cx: &TestCtxt, i: Gc<ast::Item>) -> bool {
221221
let has_bench_attr = attr::contains_name(i.attrs.as_slice(), "bench");
222222

223-
fn has_test_signature(i: @ast::Item) -> bool {
223+
fn has_test_signature(i: Gc<ast::Item>) -> bool {
224224
match i.node {
225225
ast::ItemFn(ref decl, _, _, ref generics, _) => {
226226
let input_cnt = decl.inputs.len();
@@ -247,7 +247,7 @@ fn is_bench_fn(cx: &TestCtxt, i: @ast::Item) -> bool {
247247
return has_bench_attr && has_test_signature(i);
248248
}
249249

250-
fn is_ignored(cx: &TestCtxt, i: @ast::Item) -> bool {
250+
fn is_ignored(cx: &TestCtxt, i: Gc<ast::Item>) -> bool {
251251
i.attrs.iter().any(|attr| {
252252
// check ignore(cfg(foo, bar))
253253
attr.check_name("ignore") && match attr.meta_item_list() {
@@ -259,7 +259,7 @@ fn is_ignored(cx: &TestCtxt, i: @ast::Item) -> bool {
259259
})
260260
}
261261

262-
fn should_fail(i: @ast::Item) -> bool {
262+
fn should_fail(i: Gc<ast::Item>) -> bool {
263263
attr::contains_name(i.attrs.as_slice(), "should_fail")
264264
}
265265

@@ -293,7 +293,7 @@ fn mk_std(cx: &TestCtxt) -> ast::ViewItem {
293293
let id_test = token::str_to_ident("test");
294294
let (vi, vis) = if cx.is_test_crate {
295295
(ast::ViewItemUse(
296-
@nospan(ast::ViewPathSimple(id_test,
296+
box(GC) nospan(ast::ViewPathSimple(id_test,
297297
path_node(vec!(id_test)),
298298
ast::DUMMY_NODE_ID))),
299299
ast::Public)
@@ -311,7 +311,7 @@ fn mk_std(cx: &TestCtxt) -> ast::ViewItem {
311311
}
312312
}
313313

314-
fn mk_test_module(cx: &TestCtxt) -> @ast::Item {
314+
fn mk_test_module(cx: &TestCtxt) -> Gc<ast::Item> {
315315
// Link to test crate
316316
let view_items = vec!(mk_std(cx));
317317

@@ -352,7 +352,7 @@ fn mk_test_module(cx: &TestCtxt) -> @ast::Item {
352352

353353
debug!("Synthetic test module:\n{}\n", pprust::item_to_str(&item));
354354

355-
return @item;
355+
box(GC) item
356356
}
357357

358358
fn nospan<T>(t: T) -> codemap::Spanned<T> {
@@ -383,7 +383,7 @@ fn path_node_global(ids: Vec<ast::Ident> ) -> ast::Path {
383383
}
384384
}
385385

386-
fn mk_tests(cx: &TestCtxt) -> @ast::Item {
386+
fn mk_tests(cx: &TestCtxt) -> Gc<ast::Item> {
387387
// The vector of test_descs for this crate
388388
let test_descs = mk_test_descs(cx);
389389

@@ -401,12 +401,12 @@ fn is_test_crate(krate: &ast::Crate) -> bool {
401401
}
402402
}
403403

404-
fn mk_test_descs(cx: &TestCtxt) -> @ast::Expr {
404+
fn mk_test_descs(cx: &TestCtxt) -> Gc<ast::Expr> {
405405
debug!("building test vector from {} tests", cx.testfns.borrow().len());
406406

407-
@ast::Expr {
407+
box(GC) ast::Expr {
408408
id: ast::DUMMY_NODE_ID,
409-
node: ast::ExprVstore(@ast::Expr {
409+
node: ast::ExprVstore(box(GC) ast::Expr {
410410
id: ast::DUMMY_NODE_ID,
411411
node: ast::ExprVec(cx.testfns.borrow().iter().map(|test| {
412412
mk_test_desc_and_fn_rec(cx, test)
@@ -417,7 +417,7 @@ fn mk_test_descs(cx: &TestCtxt) -> @ast::Expr {
417417
}
418418
}
419419

420-
fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> @ast::Expr {
420+
fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> Gc<ast::Expr> {
421421
let span = test.span;
422422
let path = test.path.clone();
423423

@@ -428,15 +428,15 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> @ast::Expr {
428428
ast_util::path_name_i(path.as_slice()).as_slice()),
429429
ast::CookedStr));
430430

431-
let name_expr = @ast::Expr {
431+
let name_expr = box(GC) ast::Expr {
432432
id: ast::DUMMY_NODE_ID,
433-
node: ast::ExprLit(@name_lit),
433+
node: ast::ExprLit(box(GC) name_lit),
434434
span: span
435435
};
436436

437437
let fn_path = path_node_global(path);
438438

439-
let fn_expr = @ast::Expr {
439+
let fn_expr = box(GC) ast::Expr {
440440
id: ast::DUMMY_NODE_ID,
441441
node: ast::ExprPath(fn_path),
442442
span: span,

0 commit comments

Comments
 (0)