Skip to content

Commit 6584f37

Browse files
committed
auto merge of #13170 : eddyb/rust/syntax-cleanup, r=alexcrichton
Removes all Cell's/RefCell's from lexer::Reader implementations and a couple @.
2 parents b334f7c + b0e3cb5 commit 6584f37

18 files changed

+445
-486
lines changed

src/librustc/metadata/creader.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use metadata::loader;
2323
use metadata::loader::Os;
2424

2525
use std::cell::RefCell;
26+
use std::rc::Rc;
2627
use collections::HashMap;
2728
use syntax::ast;
2829
use syntax::abi;
@@ -41,7 +42,7 @@ use syntax::visit;
4142
pub fn read_crates(sess: &Session,
4243
krate: &ast::Crate,
4344
os: loader::Os,
44-
intr: @IdentInterner) {
45+
intr: Rc<IdentInterner>) {
4546
let mut e = Env {
4647
sess: sess,
4748
os: os,
@@ -114,7 +115,7 @@ struct Env<'a> {
114115
os: loader::Os,
115116
crate_cache: @RefCell<Vec<cache_entry>>,
116117
next_crate_num: ast::CrateNum,
117-
intr: @IdentInterner
118+
intr: Rc<IdentInterner>
118119
}
119120

120121
fn visit_crate(e: &Env, c: &ast::Crate) {
@@ -295,7 +296,7 @@ fn resolve_crate(e: &mut Env,
295296
id_hash: id_hash,
296297
hash: hash.map(|a| &*a),
297298
os: e.os,
298-
intr: e.intr,
299+
intr: e.intr.clone(),
299300
rejected_via_hash: false,
300301
};
301302
let loader::Library {

src/librustc/metadata/csearch.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn each_child_of_item(cstore: &cstore::CStore,
6363
let get_crate_data: decoder::GetCrateDataCb = |cnum| {
6464
cstore.get_crate_data(cnum)
6565
};
66-
decoder::each_child_of_item(cstore.intr,
66+
decoder::each_child_of_item(cstore.intr.clone(),
6767
crate_data,
6868
def_id.node,
6969
get_crate_data,
@@ -80,7 +80,7 @@ pub fn each_top_level_item_of_crate(cstore: &cstore::CStore,
8080
let get_crate_data: decoder::GetCrateDataCb = |cnum| {
8181
cstore.get_crate_data(cnum)
8282
};
83-
decoder::each_top_level_item_of_crate(cstore.intr,
83+
decoder::each_top_level_item_of_crate(cstore.intr.clone(),
8484
crate_data,
8585
get_crate_data,
8686
callback)
@@ -118,27 +118,27 @@ pub fn get_enum_variants(tcx: &ty::ctxt, def: ast::DefId)
118118
-> Vec<@ty::VariantInfo> {
119119
let cstore = &tcx.sess.cstore;
120120
let cdata = cstore.get_crate_data(def.krate);
121-
return decoder::get_enum_variants(cstore.intr, cdata, def.node, tcx)
121+
return decoder::get_enum_variants(cstore.intr.clone(), cdata, def.node, tcx)
122122
}
123123

124124
/// Returns information about the given implementation.
125125
pub fn get_impl(tcx: &ty::ctxt, impl_def_id: ast::DefId)
126126
-> ty::Impl {
127127
let cdata = tcx.sess.cstore.get_crate_data(impl_def_id.krate);
128-
decoder::get_impl(tcx.sess.cstore.intr, cdata, impl_def_id.node, tcx)
128+
decoder::get_impl(tcx.sess.cstore.intr.clone(), cdata, impl_def_id.node, tcx)
129129
}
130130

131131
pub fn get_method(tcx: &ty::ctxt, def: ast::DefId) -> ty::Method {
132132
let cdata = tcx.sess.cstore.get_crate_data(def.krate);
133-
decoder::get_method(tcx.sess.cstore.intr, cdata, def.node, tcx)
133+
decoder::get_method(tcx.sess.cstore.intr.clone(), cdata, def.node, tcx)
134134
}
135135

136136
pub fn get_method_name_and_explicit_self(cstore: &cstore::CStore,
137137
def: ast::DefId)
138138
-> (ast::Ident, ast::ExplicitSelf_)
139139
{
140140
let cdata = cstore.get_crate_data(def.krate);
141-
decoder::get_method_name_and_explicit_self(cstore.intr, cdata, def.node)
141+
decoder::get_method_name_and_explicit_self(cstore.intr.clone(), cdata, def.node)
142142
}
143143

144144
pub fn get_trait_method_def_ids(cstore: &cstore::CStore,
@@ -158,7 +158,7 @@ pub fn get_provided_trait_methods(tcx: &ty::ctxt,
158158
-> Vec<@ty::Method> {
159159
let cstore = &tcx.sess.cstore;
160160
let cdata = cstore.get_crate_data(def.krate);
161-
decoder::get_provided_trait_methods(cstore.intr, cdata, def.node, tcx)
161+
decoder::get_provided_trait_methods(cstore.intr.clone(), cdata, def.node, tcx)
162162
}
163163

164164
pub fn get_supertraits(tcx: &ty::ctxt, def: ast::DefId) -> Vec<@ty::TraitRef> {
@@ -177,7 +177,7 @@ pub fn get_static_methods_if_impl(cstore: &cstore::CStore,
177177
def: ast::DefId)
178178
-> Option<Vec<StaticMethodInfo> > {
179179
let cdata = cstore.get_crate_data(def.krate);
180-
decoder::get_static_methods_if_impl(cstore.intr, cdata, def.node)
180+
decoder::get_static_methods_if_impl(cstore.intr.clone(), cdata, def.node)
181181
}
182182

183183
pub fn get_item_attrs(cstore: &cstore::CStore,
@@ -191,7 +191,7 @@ pub fn get_struct_fields(cstore: &cstore::CStore,
191191
def: ast::DefId)
192192
-> Vec<ty::field_ty> {
193193
let cdata = cstore.get_crate_data(def.krate);
194-
decoder::get_struct_fields(cstore.intr, cdata, def.node)
194+
decoder::get_struct_fields(cstore.intr.clone(), cdata, def.node)
195195
}
196196

197197
pub fn get_type(tcx: &ty::ctxt,
@@ -251,7 +251,7 @@ pub fn get_impl_method(cstore: &cstore::CStore,
251251
mname: ast::Ident)
252252
-> Option<ast::DefId> {
253253
let cdata = cstore.get_crate_data(def.krate);
254-
decoder::get_impl_method(cstore.intr, cdata, def.node, mname)
254+
decoder::get_impl_method(cstore.intr.clone(), cdata, def.node, mname)
255255
}
256256

257257
pub fn get_item_visibility(cstore: &cstore::CStore,

src/librustc/metadata/cstore.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use metadata::loader;
1919

2020
use std::cell::RefCell;
2121
use std::c_vec::CVec;
22+
use std::rc::Rc;
2223
use collections::HashMap;
2324
use syntax::ast;
2425
use syntax::parse::token::IdentInterner;
@@ -70,14 +71,14 @@ pub struct CStore {
7071
priv used_crate_sources: RefCell<Vec<CrateSource> >,
7172
priv used_libraries: RefCell<Vec<(~str, NativeLibaryKind)> >,
7273
priv used_link_args: RefCell<Vec<~str> >,
73-
intr: @IdentInterner
74+
intr: Rc<IdentInterner>
7475
}
7576

7677
// Map from NodeId's of local extern crate statements to crate numbers
7778
type extern_mod_crate_map = HashMap<ast::NodeId, ast::CrateNum>;
7879

7980
impl CStore {
80-
pub fn new(intr: @IdentInterner) -> CStore {
81+
pub fn new(intr: Rc<IdentInterner>) -> CStore {
8182
CStore {
8283
metas: RefCell::new(HashMap::new()),
8384
extern_mod_crate_map: RefCell::new(HashMap::new()),

src/librustc/metadata/decoder.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ fn item_region_param_defs(item_doc: ebml::Doc, cdata: Cmd)
278278
reader::tagged_docs(item_doc, tag_region_param_def, |rp_doc| {
279279
let ident_str_doc = reader::get_doc(rp_doc,
280280
tag_region_param_def_ident);
281-
let ident = item_name(token::get_ident_interner(), ident_str_doc);
281+
let ident = item_name(&*token::get_ident_interner(), ident_str_doc);
282282
let def_id_doc = reader::get_doc(rp_doc,
283283
tag_region_param_def_def_id);
284284
let def_id = reader::with_doc_data(def_id_doc, parse_def_id);
@@ -460,13 +460,13 @@ pub fn get_impl_vtables(cdata: Cmd,
460460
}
461461

462462

463-
pub fn get_impl_method(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId,
463+
pub fn get_impl_method(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId,
464464
name: ast::Ident) -> Option<ast::DefId> {
465465
let items = reader::get_doc(reader::Doc(cdata.data()), tag_items);
466466
let mut found = None;
467467
reader::tagged_docs(find_item(id, items), tag_item_impl_method, |mid| {
468468
let m_did = reader::with_doc_data(mid, parse_def_id);
469-
if item_name(intr, find_item(m_did.node, items)) == name {
469+
if item_name(&*intr, find_item(m_did.node, items)) == name {
470470
found = Some(translate_def_id(cdata, m_did));
471471
}
472472
true
@@ -509,7 +509,7 @@ pub fn each_lang_item(cdata: Cmd, f: |ast::NodeId, uint| -> bool) -> bool {
509509
})
510510
}
511511

512-
fn each_child_of_item_or_crate(intr: @IdentInterner,
512+
fn each_child_of_item_or_crate(intr: Rc<IdentInterner>,
513513
cdata: Cmd,
514514
item_doc: ebml::Doc,
515515
get_crate_data: GetCrateDataCb,
@@ -536,7 +536,7 @@ fn each_child_of_item_or_crate(intr: @IdentInterner,
536536
None => {}
537537
Some(child_item_doc) => {
538538
// Hand off the item to the callback.
539-
let child_name = item_name(intr, child_item_doc);
539+
let child_name = item_name(&*intr, child_item_doc);
540540
let def_like = item_to_def_like(child_item_doc,
541541
child_def_id,
542542
cdata.cnum);
@@ -577,7 +577,7 @@ fn each_child_of_item_or_crate(intr: @IdentInterner,
577577
// Hand off the static method
578578
// to the callback.
579579
let static_method_name =
580-
item_name(intr, impl_method_doc);
580+
item_name(&*intr, impl_method_doc);
581581
let static_method_def_like =
582582
item_to_def_like(impl_method_doc,
583583
impl_method_def_id,
@@ -638,7 +638,7 @@ fn each_child_of_item_or_crate(intr: @IdentInterner,
638638
}
639639

640640
/// Iterates over each child of the given item.
641-
pub fn each_child_of_item(intr: @IdentInterner,
641+
pub fn each_child_of_item(intr: Rc<IdentInterner>,
642642
cdata: Cmd,
643643
id: ast::NodeId,
644644
get_crate_data: GetCrateDataCb,
@@ -659,7 +659,7 @@ pub fn each_child_of_item(intr: @IdentInterner,
659659
}
660660

661661
/// Iterates over all the top-level crate items.
662-
pub fn each_top_level_item_of_crate(intr: @IdentInterner,
662+
pub fn each_top_level_item_of_crate(intr: Rc<IdentInterner>,
663663
cdata: Cmd,
664664
get_crate_data: GetCrateDataCb,
665665
callback: |DefLike,
@@ -711,7 +711,7 @@ pub fn maybe_get_item_ast(cdata: Cmd, tcx: &ty::ctxt, id: ast::NodeId,
711711
}
712712
}
713713

714-
pub fn get_enum_variants(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId,
714+
pub fn get_enum_variants(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId,
715715
tcx: &ty::ctxt) -> Vec<@ty::VariantInfo> {
716716
let data = cdata.data();
717717
let items = reader::get_doc(reader::Doc(data), tag_items);
@@ -723,7 +723,7 @@ pub fn get_enum_variants(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId,
723723
let item = find_item(did.node, items);
724724
let ctor_ty = item_type(ast::DefId { krate: cdata.cnum, node: id},
725725
item, tcx, cdata);
726-
let name = item_name(intr, item);
726+
let name = item_name(&*intr, item);
727727
let arg_tys = match ty::get(ctor_ty).sty {
728728
ty::ty_bare_fn(ref f) => f.sig.inputs.clone(),
729729
_ => Vec::new(), // Nullary enum variant.
@@ -770,20 +770,20 @@ fn get_explicit_self(item: ebml::Doc) -> ast::ExplicitSelf_ {
770770
}
771771
}
772772

773-
fn item_impl_methods(intr: @IdentInterner, cdata: Cmd, item: ebml::Doc,
773+
fn item_impl_methods(intr: Rc<IdentInterner>, cdata: Cmd, item: ebml::Doc,
774774
tcx: &ty::ctxt) -> Vec<@ty::Method> {
775775
let mut rslt = Vec::new();
776776
reader::tagged_docs(item, tag_item_impl_method, |doc| {
777777
let m_did = reader::with_doc_data(doc, parse_def_id);
778-
rslt.push(@get_method(intr, cdata, m_did.node, tcx));
778+
rslt.push(@get_method(intr.clone(), cdata, m_did.node, tcx));
779779
true
780780
});
781781

782782
rslt
783783
}
784784

785785
/// Returns information about the given implementation.
786-
pub fn get_impl(intr: @IdentInterner, cdata: Cmd, impl_id: ast::NodeId,
786+
pub fn get_impl(intr: Rc<IdentInterner>, cdata: Cmd, impl_id: ast::NodeId,
787787
tcx: &ty::ctxt)
788788
-> ty::Impl {
789789
let data = cdata.data();
@@ -793,23 +793,23 @@ pub fn get_impl(intr: @IdentInterner, cdata: Cmd, impl_id: ast::NodeId,
793793
krate: cdata.cnum,
794794
node: impl_id,
795795
},
796-
ident: item_name(intr, impl_item),
796+
ident: item_name(&*intr, impl_item),
797797
methods: item_impl_methods(intr, cdata, impl_item, tcx),
798798
}
799799
}
800800

801801
pub fn get_method_name_and_explicit_self(
802-
intr: @IdentInterner,
802+
intr: Rc<IdentInterner>,
803803
cdata: Cmd,
804804
id: ast::NodeId) -> (ast::Ident, ast::ExplicitSelf_)
805805
{
806806
let method_doc = lookup_item(id, cdata.data());
807-
let name = item_name(intr, method_doc);
807+
let name = item_name(&*intr, method_doc);
808808
let explicit_self = get_explicit_self(method_doc);
809809
(name, explicit_self)
810810
}
811811

812-
pub fn get_method(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId,
812+
pub fn get_method(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId,
813813
tcx: &ty::ctxt) -> ty::Method
814814
{
815815
let method_doc = lookup_item(id, cdata.data());
@@ -823,7 +823,7 @@ pub fn get_method(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId,
823823
_ => ImplContainer(container_id),
824824
};
825825

826-
let name = item_name(intr, method_doc);
826+
let name = item_name(&*intr, method_doc);
827827
let type_param_defs = item_ty_param_defs(method_doc, tcx, cdata,
828828
tag_item_method_tps);
829829
let rp_defs = item_region_param_defs(method_doc, cdata);
@@ -867,7 +867,7 @@ pub fn get_item_variances(cdata: Cmd, id: ast::NodeId) -> ty::ItemVariances {
867867
unwrap_(Decodable::decode(&mut decoder))
868868
}
869869

870-
pub fn get_provided_trait_methods(intr: @IdentInterner, cdata: Cmd,
870+
pub fn get_provided_trait_methods(intr: Rc<IdentInterner>, cdata: Cmd,
871871
id: ast::NodeId, tcx: &ty::ctxt) ->
872872
Vec<@ty::Method> {
873873
let data = cdata.data();
@@ -879,7 +879,7 @@ pub fn get_provided_trait_methods(intr: @IdentInterner, cdata: Cmd,
879879
let mth = lookup_item(did.node, data);
880880

881881
if item_method_sort(mth) == 'p' {
882-
result.push(@get_method(intr, cdata, did.node, tcx));
882+
result.push(@get_method(intr.clone(), cdata, did.node, tcx));
883883
}
884884
true
885885
});
@@ -921,7 +921,7 @@ pub fn get_type_name_if_impl(cdata: Cmd,
921921
ret
922922
}
923923

924-
pub fn get_static_methods_if_impl(intr: @IdentInterner,
924+
pub fn get_static_methods_if_impl(intr: Rc<IdentInterner>,
925925
cdata: Cmd,
926926
node_id: ast::NodeId)
927927
-> Option<Vec<StaticMethodInfo> > {
@@ -957,7 +957,7 @@ pub fn get_static_methods_if_impl(intr: @IdentInterner,
957957
}
958958

959959
static_impl_methods.push(StaticMethodInfo {
960-
ident: item_name(intr, impl_method_doc),
960+
ident: item_name(&*intr, impl_method_doc),
961961
def_id: item_def_id(impl_method_doc, cdata),
962962
purity: purity,
963963
vis: item_visibility(impl_method_doc),
@@ -1009,7 +1009,7 @@ fn struct_field_family_to_visibility(family: Family) -> ast::Visibility {
10091009
}
10101010
}
10111011

1012-
pub fn get_struct_fields(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId)
1012+
pub fn get_struct_fields(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId)
10131013
-> Vec<ty::field_ty> {
10141014
let data = cdata.data();
10151015
let item = lookup_item(id, data);
@@ -1018,7 +1018,7 @@ pub fn get_struct_fields(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId)
10181018
let f = item_family(an_item);
10191019
if f == PublicField || f == PrivateField || f == InheritedField {
10201020
// FIXME #6993: name should be of type Name, not Ident
1021-
let name = item_name(intr, an_item);
1021+
let name = item_name(&*intr, an_item);
10221022
let did = item_def_id(an_item, cdata);
10231023
result.push(ty::field_ty {
10241024
name: name.name,

src/librustc/metadata/loader.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use std::cast;
2929
use std::cmp;
3030
use std::io;
3131
use std::os::consts::{macos, freebsd, linux, android, win32};
32+
use std::rc::Rc;
3233
use std::str;
3334
use std::slice;
3435

@@ -52,7 +53,7 @@ pub struct Context<'a> {
5253
id_hash: &'a str,
5354
hash: Option<&'a Svh>,
5455
os: Os,
55-
intr: @IdentInterner,
56+
intr: Rc<IdentInterner>,
5657
rejected_via_hash: bool,
5758
}
5859

src/librustdoc/html/highlight.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn highlight(src: &str, class: Option<&str>) -> ~str {
4444
/// it's used. All source code emission is done as slices from the source map,
4545
/// not from the tokens themselves, in order to stay true to the original
4646
/// source.
47-
fn doit(sess: &parse::ParseSess, lexer: lexer::StringReader, class: Option<&str>,
47+
fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader, class: Option<&str>,
4848
out: &mut Writer) -> io::IoResult<()> {
4949
use syntax::parse::lexer::Reader;
5050
@@ -55,7 +55,7 @@ fn doit(sess: &parse::ParseSess, lexer: lexer::StringReader, class: Option<&str>
5555
let mut is_macro_nonterminal = false;
5656
loop {
5757
let next = lexer.next_token();
58-
let test = if next.tok == t::EOF {lexer.pos.get()} else {next.sp.lo};
58+
let test = if next.tok == t::EOF {lexer.pos} else {next.sp.lo};
5959

6060
// The lexer consumes all whitespace and non-doc-comments when iterating
6161
// between tokens. If this token isn't directly adjacent to our last

0 commit comments

Comments
 (0)