Skip to content

Commit 1f956fc

Browse files
committed
auto merge of #4999 : erickt/rust/incoming, r=brson
This patch series is doing a couple things with the ultimate goal of removing `#[allow(vecs_implicitly_copyable)]`, although I'm not quite there yet. The main change is passing around `@~str`s in most places, and using `ref`s in others. As far as I could tell, there are no performance changes with these patches, and all the tests pass on my mac.
2 parents a782efc + 68746cd commit 1f956fc

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

+898
-853
lines changed

src/librustc/back/link.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -466,14 +466,14 @@ pub fn build_link_meta(sess: Session, c: &ast::crate, output: &Path,
466466
let linkage_metas = attr::find_linkage_metas(c.node.attrs);
467467
attr::require_unique_names(sess.diagnostic(), linkage_metas);
468468
for linkage_metas.each |meta| {
469-
if attr::get_meta_item_name(*meta) == ~"name" {
469+
if *attr::get_meta_item_name(*meta) == ~"name" {
470470
match attr::get_meta_item_value_str(*meta) {
471471
// Changing attr would avoid the need for the copy
472472
// here
473473
Some(v) => { name = Some(v.to_managed()); }
474474
None => cmh_items.push(*meta)
475475
}
476-
} else if attr::get_meta_item_name(*meta) == ~"vers" {
476+
} else if *attr::get_meta_item_name(*meta) == ~"vers" {
477477
match attr::get_meta_item_value_str(*meta) {
478478
Some(v) => { vers = Some(v.to_managed()); }
479479
None => cmh_items.push(*meta)
@@ -487,27 +487,27 @@ pub fn build_link_meta(sess: Session, c: &ast::crate, output: &Path,
487487
fn crate_meta_extras_hash(symbol_hasher: &hash::State,
488488
-cmh_items: ~[@ast::meta_item],
489489
dep_hashes: ~[~str]) -> @str {
490-
fn len_and_str(s: ~str) -> ~str {
491-
return fmt!("%u_%s", str::len(s), s);
490+
fn len_and_str(s: &str) -> ~str {
491+
fmt!("%u_%s", s.len(), s)
492492
}
493493

494494
fn len_and_str_lit(l: ast::lit) -> ~str {
495-
return len_and_str(pprust::lit_to_str(@l));
495+
len_and_str(pprust::lit_to_str(@l))
496496
}
497497

498498
let cmh_items = attr::sort_meta_items(cmh_items);
499499

500500
fn hash(symbol_hasher: &hash::State, m: &@ast::meta_item) {
501501
match m.node {
502-
ast::meta_name_value(ref key, value) => {
503-
symbol_hasher.write_str(len_and_str((*key)));
502+
ast::meta_name_value(key, value) => {
503+
symbol_hasher.write_str(len_and_str(*key));
504504
symbol_hasher.write_str(len_and_str_lit(value));
505505
}
506-
ast::meta_word(ref name) => {
507-
symbol_hasher.write_str(len_and_str((*name)));
506+
ast::meta_word(name) => {
507+
symbol_hasher.write_str(len_and_str(*name));
508508
}
509-
ast::meta_list(ref name, ref mis) => {
510-
symbol_hasher.write_str(len_and_str((*name)));
509+
ast::meta_list(name, ref mis) => {
510+
symbol_hasher.write_str(len_and_str(*name));
511511
for mis.each |m_| {
512512
hash(symbol_hasher, m_);
513513
}
@@ -615,7 +615,7 @@ pub fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> @str {
615615
616616
// Name sanitation. LLVM will happily accept identifiers with weird names, but
617617
// gas doesn't!
618-
pub fn sanitize(s: ~str) -> ~str {
618+
pub fn sanitize(s: &str) -> ~str {
619619
let mut result = ~"";
620620
for str::chars_each(s) |c| {
621621
match c {
@@ -629,10 +629,10 @@ pub fn sanitize(s: ~str) -> ~str {
629629
'a' .. 'z'
630630
| 'A' .. 'Z'
631631
| '0' .. '9'
632-
| '_' => str::push_char(&mut result, c),
632+
| '_' => result.push_char(c),
633633
_ => {
634634
if c > 'z' && char::is_XID_continue(c) {
635-
str::push_char(&mut result, c);
635+
result.push_char(c);
636636
}
637637
}
638638
}
@@ -655,7 +655,7 @@ pub fn mangle(sess: Session, ss: path) -> ~str {
655655

656656
for ss.each |s| {
657657
match *s { path_name(s) | path_mod(s) => {
658-
let sani = sanitize(sess.str_of(s));
658+
let sani = sanitize(*sess.str_of(s));
659659
n += fmt!("%u%s", str::len(sani), sani);
660660
} }
661661
}

src/librustc/driver/driver.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn anon_src() -> ~str { ~"<anon>" }
6262
6363
pub fn source_name(input: input) -> ~str {
6464
match input {
65-
file_input(ref ifile) => (*ifile).to_str(),
65+
file_input(ref ifile) => ifile.to_str(),
6666
str_input(_) => anon_src()
6767
}
6868
}
@@ -97,24 +97,24 @@ pub fn default_configuration(sess: Session, +argv0: ~str, input: input) ->
9797
};
9898

9999
return ~[ // Target bindings.
100-
attr::mk_word_item(str::from_slice(os::FAMILY)),
101-
mk(~"target_os", tos),
102-
mk(~"target_family", str::from_slice(os::FAMILY)),
103-
mk(~"target_arch", arch),
104-
mk(~"target_endian", end),
105-
mk(~"target_word_size", wordsz),
106-
mk(~"target_libc", libc),
100+
attr::mk_word_item(@str::from_slice(os::FAMILY)),
101+
mk(@~"target_os", @tos),
102+
mk(@~"target_family", @str::from_slice(os::FAMILY)),
103+
mk(@~"target_arch", @arch),
104+
mk(@~"target_endian", @end),
105+
mk(@~"target_word_size", @wordsz),
106+
mk(@~"target_libc", @libc),
107107
// Build bindings.
108-
mk(~"build_compiler", argv0),
109-
mk(~"build_input", source_name(input))];
108+
mk(@~"build_compiler", @argv0),
109+
mk(@~"build_input", @source_name(input))];
110110
}
111111

112112
pub fn append_configuration(+cfg: ast::crate_cfg, +name: ~str)
113113
-> ast::crate_cfg {
114114
if attr::contains_name(cfg, name) {
115-
return cfg;
115+
cfg
116116
} else {
117-
return vec::append_one(cfg, attr::mk_word_item(name));
117+
vec::append_one(cfg, attr::mk_word_item(@name))
118118
}
119119
}
120120

@@ -142,7 +142,7 @@ pub fn parse_cfgspecs(cfgspecs: ~[~str]) -> ast::crate_cfg {
142142
// meta_word variant.
143143
let mut words = ~[];
144144
for cfgspecs.each |s| {
145-
words.push(attr::mk_word_item(/*bad*/copy *s));
145+
words.push(attr::mk_word_item(@/*bad*/copy *s));
146146
}
147147
return words;
148148
}
@@ -541,11 +541,11 @@ pub fn build_session_options(+binary: ~str,
541541
let flags = vec::append(getopts::opt_strs(matches, level_short),
542542
getopts::opt_strs(matches, level_name));
543543
for flags.each |lint_name| {
544-
let lint_name = str::replace(*lint_name, ~"-", ~"_");
544+
let lint_name = @str::replace(*lint_name, ~"-", ~"_");
545545
match lint_dict.find(&lint_name) {
546546
None => {
547547
early_error(demitter, fmt!("unknown %s flag: %s",
548-
level_name, lint_name));
548+
level_name, *lint_name));
549549
}
550550
Some(lint) => {
551551
lint_opts.push((lint.lint, *level));

src/librustc/driver/session.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ pub impl Session {
253253
self.debugging_opt(no_monomorphic_collapse)
254254
}
255255

256-
fn str_of(id: ast::ident) -> ~str {
257-
/*bad*/copy *self.parse_sess.interner.get(id)
256+
fn str_of(id: ast::ident) -> @~str {
257+
self.parse_sess.interner.get(id)
258258
}
259259
fn ident_of(+st: ~str) -> ast::ident {
260260
self.parse_sess.interner.intern(@st)
@@ -310,7 +310,7 @@ pub fn building_library(req_crate_type: crate_type,
310310
match syntax::attr::first_attr_value_str_by_name(
311311
crate.node.attrs,
312312
~"crate_type") {
313-
option::Some(~"lib") => true,
313+
Some(@~"lib") => true,
314314
_ => false
315315
}
316316
}
@@ -346,7 +346,7 @@ pub mod test {
346346
style: ast::attr_outer,
347347
value: codemap::respan(codemap::dummy_sp(),
348348
ast::meta_name_value(
349-
~"crate_type",
349+
@~"crate_type",
350350
codemap::respan(codemap::dummy_sp(),
351351
ast::lit_str(@t)))),
352352
is_sugared_doc: false

src/librustc/front/core_inject.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn inject_libcore_ref(sess: Session,
5151
spanned(ast::attribute_ {
5252
style: ast::attr_inner,
5353
value: spanned(ast::meta_name_value(
54-
~"vers",
54+
@~"vers",
5555
spanned(ast::lit_str(@CORE_VERSION.to_str()))
5656
)),
5757
is_sugared_doc: false

src/librustc/front/test.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn modify_for_testing(sess: session::Session,
5757
// configuration, either with the '--test' or '--cfg test'
5858
// command line options.
5959
let should_test = attr::contains(crate.node.config,
60-
attr::mk_word_item(~"test"));
60+
attr::mk_word_item(@~"test"));
6161

6262
if should_test {
6363
generate_test_harness(sess, crate)
@@ -111,7 +111,7 @@ fn fold_mod(cx: @mut TestCtxt,
111111
fn nomain(cx: @mut TestCtxt, item: @ast::item) -> @ast::item {
112112
if !*cx.sess.building_library {
113113
@ast::item{attrs: item.attrs.filtered(|attr| {
114-
attr::get_attr_name(*attr) != ~"main"
114+
*attr::get_attr_name(attr) != ~"main"
115115
}),.. copy *item}
116116
} else { item }
117117
}
@@ -262,7 +262,7 @@ mod __test {
262262
fn mk_std(cx: &TestCtxt) -> @ast::view_item {
263263
let vers = ast::lit_str(@~"0.6");
264264
let vers = nospan(vers);
265-
let mi = ast::meta_name_value(~"vers", vers);
265+
let mi = ast::meta_name_value(@~"vers", vers);
266266
let mi = nospan(mi);
267267
let id_std = cx.sess.ident_of(~"std");
268268
let vi = if is_std(cx) {
@@ -310,7 +310,7 @@ fn mk_test_module(cx: &TestCtxt) -> @ast::item {
310310

311311
// This attribute tells resolve to let us call unexported functions
312312
let resolve_unexported_attr =
313-
attr::mk_attr(attr::mk_word_item(~"!resolve_unexported"));
313+
attr::mk_attr(attr::mk_word_item(@~"!resolve_unexported"));
314314

315315
let item = ast::item {
316316
ident: cx.sess.ident_of(~"__test"),
@@ -366,7 +366,7 @@ fn is_std(cx: &TestCtxt) -> bool {
366366
let is_std = {
367367
let items = attr::find_linkage_metas(cx.crate.node.attrs);
368368
match attr::last_meta_item_value_str_by_name(items, ~"name") {
369-
Some(~"std") => true,
369+
Some(@~"std") => true,
370370
_ => false
371371
}
372372
};

0 commit comments

Comments
 (0)