Skip to content

Commit 0f25155

Browse files
committed
auto merge of #7615 : Aatch/rust/syntax-deshare, r=graydon
In an ideal world, the AST would be completely sendable, this gets us a step closer. It removes the local heap allocations for `view_item`, `Path`, `Lifetime` `trait_ref` `OptVec<TyParamBounds>` and `Ty`. There are also a few other smaller changes I made as things went along.
2 parents d91ac39 + 280e424 commit 0f25155

Some content is hidden

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

61 files changed

+753
-770
lines changed

src/librustc/front/config.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use std::option;
1313
use syntax::{ast, fold, attr};
1414

15-
type in_cfg_pred = @fn(attrs: ~[ast::attribute]) -> bool;
15+
type in_cfg_pred = @fn(attrs: &[ast::attribute]) -> bool;
1616

1717
struct Context {
1818
in_cfg: in_cfg_pred
@@ -50,8 +50,7 @@ fn filter_item(cx: @Context, item: @ast::item) ->
5050
if item_in_cfg(cx, item) { option::Some(item) } else { option::None }
5151
}
5252

53-
fn filter_view_item(cx: @Context, view_item: @ast::view_item
54-
)-> Option<@ast::view_item> {
53+
fn filter_view_item<'r>(cx: @Context, view_item: &'r ast::view_item)-> Option<&'r ast::view_item> {
5554
if view_item_in_cfg(cx, view_item) {
5655
option::Some(view_item)
5756
} else {
@@ -64,7 +63,7 @@ fn fold_mod(cx: @Context, m: &ast::_mod, fld: @fold::ast_fold) -> ast::_mod {
6463
filter_item(cx, *a).chain(|x| fld.fold_item(x))
6564
}.collect();
6665
let filtered_view_items = do m.view_items.iter().filter_map |a| {
67-
filter_view_item(cx, *a).map(|x| fld.fold_view_item(*x))
66+
filter_view_item(cx, a).map(|&x| fld.fold_view_item(x))
6867
}.collect();
6968
ast::_mod {
7069
view_items: filtered_view_items,
@@ -86,7 +85,7 @@ fn fold_foreign_mod(
8685
) -> ast::foreign_mod {
8786
let filtered_items = nm.items.iter().filter_map(|a| filter_foreign_item(cx, *a)).collect();
8887
let filtered_view_items = do nm.view_items.iter().filter_map |a| {
89-
filter_view_item(cx, *a).map(|x| fld.fold_view_item(*x))
88+
filter_view_item(cx, a).map(|&x| fld.fold_view_item(x))
9089
}.collect();
9190
ast::foreign_mod {
9291
sort: nm.sort,
@@ -99,10 +98,10 @@ fn fold_foreign_mod(
9998
fn fold_item_underscore(cx: @Context, item: &ast::item_,
10099
fld: @fold::ast_fold) -> ast::item_ {
101100
let item = match *item {
102-
ast::item_impl(ref a, b, c, ref methods) => {
101+
ast::item_impl(ref a, ref b, ref c, ref methods) => {
103102
let methods = methods.iter().filter(|m| method_in_cfg(cx, **m))
104103
.transform(|x| *x).collect();
105-
ast::item_impl(/*bad*/ copy *a, b, c, methods)
104+
ast::item_impl(/*bad*/ copy *a, /*bad*/ copy *b, /*bad*/ copy *c, methods)
106105
}
107106
ast::item_trait(ref a, ref b, ref methods) => {
108107
let methods = methods.iter().filter(|m| trait_method_in_cfg(cx, *m) )
@@ -141,7 +140,7 @@ fn fold_block(
141140
filter_stmt(cx, *a).chain(|stmt| fld.fold_stmt(stmt))
142141
}.collect();
143142
let filtered_view_items = do b.view_items.iter().filter_map |a| {
144-
filter_view_item(cx, *a).map(|x| fld.fold_view_item(*x))
143+
filter_view_item(cx, a).map(|&x| fld.fold_view_item(x))
145144
}.collect();
146145
ast::blk_ {
147146
view_items: filtered_view_items,
@@ -160,8 +159,8 @@ fn foreign_item_in_cfg(cx: @Context, item: @ast::foreign_item) -> bool {
160159
return (cx.in_cfg)(/*bad*/copy item.attrs);
161160
}
162161

163-
fn view_item_in_cfg(cx: @Context, item: @ast::view_item) -> bool {
164-
return (cx.in_cfg)(/*bad*/copy item.attrs);
162+
fn view_item_in_cfg(cx: @Context, item: &ast::view_item) -> bool {
163+
return (cx.in_cfg)(item.attrs);
165164
}
166165

167166
fn method_in_cfg(cx: @Context, meth: @ast::method) -> bool {

src/librustc/front/std_inject.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn inject_libstd_ref(sess: Session, crate: &ast::crate) -> @ast::crate {
4141
let precursor = @fold::AstFoldFns {
4242
fold_crate: |crate, span, fld| {
4343
let n1 = sess.next_node_id();
44-
let vi1 = @ast::view_item {
44+
let vi1 = ast::view_item {
4545
node: ast::view_item_extern_mod(
4646
sess.ident_of("std"), ~[], n1),
4747
attrs: ~[
@@ -75,7 +75,7 @@ fn inject_libstd_ref(sess: Session, crate: &ast::crate) -> @ast::crate {
7575
fold_mod: |module, fld| {
7676
let n2 = sess.next_node_id();
7777

78-
let prelude_path = @ast::Path {
78+
let prelude_path = ast::Path {
7979
span: dummy_sp(),
8080
global: false,
8181
idents: ~[
@@ -87,7 +87,7 @@ fn inject_libstd_ref(sess: Session, crate: &ast::crate) -> @ast::crate {
8787
};
8888

8989
let vp = @spanned(ast::view_path_glob(prelude_path, n2));
90-
let vi2 = @ast::view_item { node: ast::view_item_use(~[vp]),
90+
let vi2 = ast::view_item { node: ast::view_item_use(~[vp]),
9191
attrs: ~[],
9292
vis: ast::private,
9393
span: dummy_sp() };

src/librustc/front/test.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ mod __test {
272272
273273
*/
274274

275-
fn mk_std(cx: &TestCtxt) -> @ast::view_item {
275+
fn mk_std(cx: &TestCtxt) -> ast::view_item {
276276
let vers = ast::lit_str(@"0.7");
277277
let vers = nospan(vers);
278278
let mi = ast::meta_name_value(@"vers", vers);
@@ -287,13 +287,12 @@ fn mk_std(cx: &TestCtxt) -> @ast::view_item {
287287
ast::view_item_extern_mod(id_std, ~[@mi],
288288
cx.sess.next_node_id())
289289
};
290-
let vi = ast::view_item {
290+
ast::view_item {
291291
node: vi,
292292
attrs: ~[],
293293
vis: ast::public,
294294
span: dummy_sp()
295-
};
296-
return @vi;
295+
}
297296
}
298297

299298
fn mk_test_module(cx: &TestCtxt) -> @ast::item {
@@ -343,16 +342,16 @@ fn nospan<T:Copy>(t: T) -> codemap::spanned<T> {
343342
codemap::spanned { node: t, span: dummy_sp() }
344343
}
345344

346-
fn path_node(ids: ~[ast::ident]) -> @ast::Path {
347-
@ast::Path { span: dummy_sp(),
345+
fn path_node(ids: ~[ast::ident]) -> ast::Path {
346+
ast::Path { span: dummy_sp(),
348347
global: false,
349348
idents: ids,
350349
rp: None,
351350
types: ~[] }
352351
}
353352

354-
fn path_node_global(ids: ~[ast::ident]) -> @ast::Path {
355-
@ast::Path { span: dummy_sp(),
353+
fn path_node_global(ids: ~[ast::ident]) -> ast::Path {
354+
ast::Path { span: dummy_sp(),
356355
global: true,
357356
idents: ids,
358357
rp: None,

src/librustc/metadata/creader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn visit_crate(e: &Env, c: &ast::crate) {
136136
}
137137
}
138138

139-
fn visit_view_item(e: @mut Env, i: @ast::view_item) {
139+
fn visit_view_item(e: @mut Env, i: &ast::view_item) {
140140
match i.node {
141141
ast::view_item_extern_mod(ident, ref meta_items, id) => {
142142
debug!("resolving extern mod stmt. ident: %?, meta: %?",

src/librustc/metadata/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ fn list_crate_attributes(intr: @ident_interner, md: ebml::Doc, hash: &str,
11411141

11421142
let r = get_attributes(md);
11431143
for r.iter().advance |attr| {
1144-
out.write_str(fmt!("%s\n", pprust::attribute_to_str(*attr, intr)));
1144+
out.write_str(fmt!("%s\n", pprust::attribute_to_str(attr, intr)));
11451145
}
11461146

11471147
out.write_str("\n\n");

src/librustc/metadata/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
10031003
index);
10041004
}
10051005
}
1006-
item_impl(ref generics, opt_trait, ty, ref methods) => {
1006+
item_impl(ref generics, ref opt_trait, ref ty, ref methods) => {
10071007
add_to_index();
10081008
ebml_w.start_tag(tag_items_data_item);
10091009
encode_def_id(ebml_w, local_def(item.id));
@@ -1014,7 +1014,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
10141014
encode_name(ecx, ebml_w, item.ident);
10151015
encode_attributes(ebml_w, item.attrs);
10161016
match ty.node {
1017-
ast::ty_path(path, bounds, _) if path.idents.len() == 1 => {
1017+
ast::ty_path(ref path, ref bounds, _) if path.idents.len() == 1 => {
10181018
assert!(bounds.is_none());
10191019
encode_impl_type_basename(ecx, ebml_w,
10201020
ast_util::path_to_ident(path));

src/librustc/middle/check_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub fn check_expr(sess: Session,
112112
"` in a constant expression");
113113
}
114114
}
115-
expr_path(pth) => {
115+
expr_path(ref pth) => {
116116
// NB: In the future you might wish to relax this slightly
117117
// to handle on-demand instantiation of functions via
118118
// foo::<bar> in a const. Currently that is only done on

src/librustc/middle/kind.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ fn check_item(item: @item, (cx, visitor): (Context, visit::vt<Context>)) {
117117
// If this is a destructor, check kinds.
118118
if !attrs_contains_name(item.attrs, "unsafe_destructor") {
119119
match item.node {
120-
item_impl(_, Some(trait_ref), self_type, _) => {
120+
item_impl(_, Some(ref trait_ref), ref self_type, _) => {
121121
match cx.tcx.def_map.find(&trait_ref.ref_id) {
122122
None => cx.tcx.sess.bug("trait ref not in def map!"),
123123
Some(&trait_def) => {
124124
let trait_def_id = ast_util::def_id_of_def(trait_def);
125125
if cx.tcx.lang_items.drop_trait() == trait_def_id {
126126
// Yes, it's a destructor.
127127
match self_type.node {
128-
ty_path(_, bounds, path_node_id) => {
128+
ty_path(_, ref bounds, path_node_id) => {
129129
assert!(bounds.is_none());
130130
let struct_def = cx.tcx.def_map.get_copy(
131131
&path_node_id);
@@ -321,7 +321,7 @@ pub fn check_expr(e: @expr, (cx, v): (Context, visit::vt<Context>)) {
321321
visit::visit_expr(e, (cx, v));
322322
}
323323

324-
fn check_ty(aty: @Ty, (cx, v): (Context, visit::vt<Context>)) {
324+
fn check_ty(aty: &Ty, (cx, v): (Context, visit::vt<Context>)) {
325325
match aty.node {
326326
ty_path(_, _, id) => {
327327
let r = cx.tcx.node_type_substs.find(&id);

src/librustc/middle/lint.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -747,9 +747,9 @@ fn check_item_ctypes(cx: &Context, it: &ast::item) {
747747

748748
fn check_foreign_fn(cx: &Context, decl: &ast::fn_decl) {
749749
for decl.inputs.iter().advance |in| {
750-
check_ty(cx, in.ty);
750+
check_ty(cx, &in.ty);
751751
}
752-
check_ty(cx, decl.output)
752+
check_ty(cx, &decl.output)
753753
}
754754

755755
match it.node {
@@ -759,7 +759,7 @@ fn check_item_ctypes(cx: &Context, it: &ast::item) {
759759
ast::foreign_item_fn(ref decl, _, _) => {
760760
check_foreign_fn(cx, decl);
761761
}
762-
ast::foreign_item_static(t, _) => { check_ty(cx, t); }
762+
ast::foreign_item_static(ref t, _) => { check_ty(cx, t); }
763763
}
764764
}
765765
}

src/librustc/middle/pat_util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ pub fn pat_is_binding_or_wild(dm: resolve::DefMap, pat: @pat) -> bool {
7171
}
7272

7373
pub fn pat_bindings(dm: resolve::DefMap, pat: @pat,
74-
it: &fn(binding_mode, node_id, span, @Path)) {
74+
it: &fn(binding_mode, node_id, span, &Path)) {
7575
for walk_pat(pat) |p| {
7676
match p.node {
77-
pat_ident(binding_mode, pth, _) if pat_is_binding(dm, p) => {
77+
pat_ident(binding_mode, ref pth, _) if pat_is_binding(dm, p) => {
7878
it(binding_mode, p.id, p.span, pth);
7979
}
8080
_ => {}

src/librustc/middle/privacy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt,
276276
};
277277

278278
// Checks that a private path is in scope.
279-
let check_path: @fn(span: span, def: def, path: @Path) =
279+
let check_path: @fn(span: span, def: def, path: &Path) =
280280
|span, def, path| {
281281
debug!("checking path");
282282
match def {
@@ -449,7 +449,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt,
449449
_ => {}
450450
}
451451
}
452-
expr_path(path) => {
452+
expr_path(ref path) => {
453453
check_path(expr.span, tcx.def_map.get_copy(&expr.id), path);
454454
}
455455
expr_struct(_, ref fields, _) => {

src/librustc/middle/reachable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl ReachableContext {
141141
}
142142
}
143143
}
144-
item_impl(ref generics, trait_ref, _, ref methods) => {
144+
item_impl(ref generics, ref trait_ref, _, ref methods) => {
145145
// XXX(pcwalton): We conservatively assume any methods
146146
// on a trait implementation are reachable, when this
147147
// is not the case. We could be more precise by only

0 commit comments

Comments
 (0)