Skip to content

Commit f0f9095

Browse files
committed
auto merge of #14250 : alexcrichton/rust/gc, r=brson
This commit removes `@T` from the compiler by moving the AST to using `Gc<T>`. This also starts treating `Gc<T>` as `@T` in the same way that `Box<T>` is the same as `~T` in the compiler. After this hits a snapshot, the `@T` syntax should be able to be removed completely.
2 parents c54ce27 + 54c2a1e commit f0f9095

Some content is hidden

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

119 files changed

+2818
-2668
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

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

src/libcollections/hash/mod.rs

-7
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,6 @@ impl<S: Writer, T: Hash<S>> Hash<S> for Box<T> {
248248
}
249249
}
250250

251-
impl<S: Writer, T: Hash<S>> Hash<S> for @T {
252-
#[inline]
253-
fn hash(&self, state: &mut S) {
254-
(**self).hash(state);
255-
}
256-
}
257-
258251
impl<S: Writer, T: Hash<S>> Hash<S> for Rc<T> {
259252
#[inline]
260253
fn hash(&self, state: &mut S) {

src/libcore/clone.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ pub trait Clone {
3939
}
4040
}
4141

42-
impl<T> Clone for @T {
43-
/// Return a shallow copy of the managed box.
44-
#[inline]
45-
fn clone(&self) -> @T { *self }
46-
}
47-
4842
impl<'a, T> Clone for &'a T {
4943
/// Return a shallow copy of the reference.
5044
#[inline]
@@ -116,6 +110,7 @@ extern_fn_clone!(A, B, C, D, E, F, G, H)
116110
mod test {
117111
use prelude::*;
118112
use realstd::owned::Box;
113+
use realstd::gc::{Gc, GC};
119114

120115
fn realclone<T: ::realstd::clone::Clone>(t: &T) -> T {
121116
use realstd::clone::Clone;
@@ -136,9 +131,9 @@ mod test {
136131

137132
#[test]
138133
fn test_managed_clone() {
139-
let a = @5i;
140-
let b: @int = a.clone();
141-
assert_eq!(a, b);
134+
let a = box(GC) 5i;
135+
let b: Gc<int> = realclone(&a);
136+
assert!(a == b);
142137
}
143138

144139
#[test]

src/libcore/cmp.rs

-23
Original file line numberDiff line numberDiff line change
@@ -326,29 +326,6 @@ mod impls {
326326
fn cmp(&self, other: &&'a mut T) -> Ordering { (**self).cmp(*other) }
327327
}
328328
impl<'a, T: Eq> Eq for &'a mut T {}
329-
330-
// @ pointers
331-
impl<T:PartialEq> PartialEq for @T {
332-
#[inline]
333-
fn eq(&self, other: &@T) -> bool { *(*self) == *(*other) }
334-
#[inline]
335-
fn ne(&self, other: &@T) -> bool { *(*self) != *(*other) }
336-
}
337-
impl<T:PartialOrd> PartialOrd for @T {
338-
#[inline]
339-
fn lt(&self, other: &@T) -> bool { *(*self) < *(*other) }
340-
#[inline]
341-
fn le(&self, other: &@T) -> bool { *(*self) <= *(*other) }
342-
#[inline]
343-
fn ge(&self, other: &@T) -> bool { *(*self) >= *(*other) }
344-
#[inline]
345-
fn gt(&self, other: &@T) -> bool { *(*self) > *(*other) }
346-
}
347-
impl<T: Ord> Ord for @T {
348-
#[inline]
349-
fn cmp(&self, other: &@T) -> Ordering { (**self).cmp(*other) }
350-
}
351-
impl<T: Eq> Eq for @T {}
352329
}
353330

354331
#[cfg(test)]

src/libcore/default.rs

-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,3 @@ default_impl!(i64, 0i64)
4343

4444
default_impl!(f32, 0.0f32)
4545
default_impl!(f64, 0.0f64)
46-
47-
impl<T: Default + 'static> Default for @T {
48-
fn default() -> @T { @Default::default() }
49-
}

src/libcore/fmt/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -628,9 +628,6 @@ pub fn argumentuint<'a>(s: &'a uint) -> Argument<'a> {
628628

629629
// Implementations of the core formatting traits
630630

631-
impl<T: Show> Show for @T {
632-
fn fmt(&self, f: &mut Formatter) -> Result { secret_show(&**self, f) }
633-
}
634631
impl<'a, T: Show> Show for &'a T {
635632
fn fmt(&self, f: &mut Formatter) -> Result { secret_show(*self, f) }
636633
}

src/libcore/raw.rs

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ pub trait Repr<T> {
7979

8080
impl<'a, T> Repr<Slice<T>> for &'a [T] {}
8181
impl<'a> Repr<Slice<u8>> for &'a str {}
82-
impl<T> Repr<*Box<T>> for @T {}
8382
impl<T> Repr<*Vec<T>> for ~[T] {}
8483

8584
#[cfg(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(),

0 commit comments

Comments
 (0)