Skip to content

Commit a9a8152

Browse files
committed
---
yaml --- r: 232727 b: refs/heads/try c: dec4351 h: refs/heads/master i: 232725: da38e5e 232723: ddbe18a 232719: c4f4eba v: v3
1 parent aa613af commit a9a8152

File tree

12 files changed

+102
-236
lines changed

12 files changed

+102
-236
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: edeb4f1c86cbf6af8ef9874d4b3af50f721ea1b8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: a48c29dcea0d0107c3e0bf761f97d65941a3d73d
4+
refs/heads/try: dec43510f1f8f053f86178b0710ec141f4644d20
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/libcore/any.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
//!
1414
//! `Any` itself can be used to get a `TypeId`, and has more features when used
1515
//! as a trait object. As `&Any` (a borrowed trait object), it has the `is` and
16-
//! `as_ref` methods, to test if the contained value is of a given type, and to
17-
//! get a reference to the inner value as a type. As `&mut Any`, there is also
18-
//! the `as_mut` method, for getting a mutable reference to the inner value.
19-
//! `Box<Any>` adds the `move` method, which will unwrap a `Box<T>` from the
20-
//! object. See the extension traits (`*Ext`) for the full details.
16+
//! `downcast_ref` methods, to test if the contained value is of a given type,
17+
//! and to get a reference to the inner value as a type. As `&mut Any`, there
18+
//! is also the `downcast_mut` method, for getting a mutable reference to the
19+
//! inner value. `Box<Any>` adds the `move` method, which will unwrap a
20+
//! `Box<T>` from the object. See the extension traits (`*Ext`) for the full
21+
//! details.
2122
//!
2223
//! Note that &Any is limited to testing whether a value is of a specified
2324
//! concrete type, and cannot be used to test whether a type implements a trait.

branches/try/src/librustc/middle/entry.rs

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@
1111

1212
use ast_map;
1313
use session::{config, Session};
14-
use syntax;
15-
use syntax::ast::{NodeId, Item};
14+
use syntax::ast::{Name, NodeId, Item, ItemFn};
1615
use syntax::attr;
1716
use syntax::codemap::Span;
18-
use syntax::entry::EntryPointType;
17+
use syntax::parse::token;
1918
use syntax::visit;
2019
use syntax::visit::Visitor;
2120

22-
struct EntryContext<'a> {
21+
struct EntryContext<'a, 'ast: 'a> {
2322
session: &'a Session,
2423

25-
// The current depth in the ast
26-
depth: usize,
24+
ast_map: &'a ast_map::Map<'ast>,
25+
26+
// The interned Name for "main".
27+
main_name: Name,
2728

2829
// The top-level function called 'main'
2930
main_fn: Option<(NodeId, Span)>,
@@ -39,11 +40,9 @@ struct EntryContext<'a> {
3940
non_main_fns: Vec<(NodeId, Span)> ,
4041
}
4142

42-
impl<'a, 'v> Visitor<'v> for EntryContext<'a> {
43+
impl<'a, 'ast, 'v> Visitor<'v> for EntryContext<'a, 'ast> {
4344
fn visit_item(&mut self, item: &Item) {
44-
self.depth += 1;
4545
find_item(item, self);
46-
self.depth -= 1;
4746
}
4847
}
4948

@@ -64,7 +63,8 @@ pub fn find_entry_point(session: &Session, ast_map: &ast_map::Map) {
6463

6564
let mut ctxt = EntryContext {
6665
session: session,
67-
depth: 0,
66+
main_name: token::intern("main"),
67+
ast_map: ast_map,
6868
main_fn: None,
6969
attr_main_fn: None,
7070
start_fn: None,
@@ -77,35 +77,44 @@ pub fn find_entry_point(session: &Session, ast_map: &ast_map::Map) {
7777
}
7878

7979
fn find_item(item: &Item, ctxt: &mut EntryContext) {
80-
match syntax::entry::entry_point_type(item, ctxt.depth) {
81-
EntryPointType::MainNamed => {
82-
if ctxt.main_fn.is_none() {
83-
ctxt.main_fn = Some((item.id, item.span));
84-
} else {
85-
span_err!(ctxt.session, item.span, E0136,
86-
"multiple 'main' functions");
80+
match item.node {
81+
ItemFn(..) => {
82+
if item.ident.name == ctxt.main_name {
83+
ctxt.ast_map.with_path(item.id, |path| {
84+
if path.count() == 1 {
85+
// This is a top-level function so can be 'main'
86+
if ctxt.main_fn.is_none() {
87+
ctxt.main_fn = Some((item.id, item.span));
88+
} else {
89+
span_err!(ctxt.session, item.span, E0136,
90+
"multiple 'main' functions");
91+
}
92+
} else {
93+
// This isn't main
94+
ctxt.non_main_fns.push((item.id, item.span));
95+
}
96+
});
8797
}
88-
},
89-
EntryPointType::OtherMain => {
90-
ctxt.non_main_fns.push((item.id, item.span));
91-
},
92-
EntryPointType::MainAttr => {
93-
if ctxt.attr_main_fn.is_none() {
94-
ctxt.attr_main_fn = Some((item.id, item.span));
95-
} else {
96-
span_err!(ctxt.session, item.span, E0137,
97-
"multiple functions with a #[main] attribute");
98+
99+
if attr::contains_name(&item.attrs, "main") {
100+
if ctxt.attr_main_fn.is_none() {
101+
ctxt.attr_main_fn = Some((item.id, item.span));
102+
} else {
103+
span_err!(ctxt.session, item.span, E0137,
104+
"multiple functions with a #[main] attribute");
105+
}
98106
}
99-
},
100-
EntryPointType::Start => {
101-
if ctxt.start_fn.is_none() {
102-
ctxt.start_fn = Some((item.id, item.span));
103-
} else {
104-
span_err!(ctxt.session, item.span, E0138,
105-
"multiple 'start' functions");
107+
108+
if attr::contains_name(&item.attrs, "start") {
109+
if ctxt.start_fn.is_none() {
110+
ctxt.start_fn = Some((item.id, item.span));
111+
} else {
112+
span_err!(ctxt.session, item.span, E0138,
113+
"multiple 'start' functions");
114+
}
106115
}
107-
},
108-
EntryPointType::None => ()
116+
}
117+
_ => ()
109118
}
110119

111120
visit::walk_item(ctxt, item);

branches/try/src/libstd/collections/mod.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
//!
2626
//! Rust's collections can be grouped into four major categories:
2727
//!
28-
//! * Sequences: `Vec`, `VecDeque`, `LinkedList`
29-
//! * Maps: `HashMap`, `BTreeMap`
30-
//! * Sets: `HashSet`, `BTreeSet`
28+
//! * Sequences: `Vec`, `VecDeque`, `LinkedList`, `BitVec`
29+
//! * Maps: `HashMap`, `BTreeMap`, `VecMap`
30+
//! * Sets: `HashSet`, `BTreeSet`, `BitSet`
3131
//! * Misc: `BinaryHeap`
3232
//!
3333
//! # When Should You Use Which Collection?
@@ -70,11 +70,22 @@
7070
//! * You want to be able to get all of the entries in order on-demand.
7171
//! * You want a sorted map.
7272
//!
73+
//! ### Use a `VecMap` when:
74+
//! * You want a `HashMap` but with known to be small `usize` keys.
75+
//! * You want a `BTreeMap`, but with known to be small `usize` keys.
76+
//!
7377
//! ### Use the `Set` variant of any of these `Map`s when:
7478
//! * You just want to remember which keys you've seen.
7579
//! * There is no meaningful value to associate with your keys.
7680
//! * You just want a set.
7781
//!
82+
//! ### Use a `BitVec` when:
83+
//! * You want to store an unbounded number of booleans in a small space.
84+
//! * You want a bit vector.
85+
//!
86+
//! ### Use a `BitSet` when:
87+
//! * You want a `BitVec`, but want `Set` properties
88+
//!
7889
//! ### Use a `BinaryHeap` when:
7990
//!
8091
//! * You want to store a bunch of elements, but only ever want to process the
@@ -112,20 +123,31 @@
112123
//! | Vec | O(1) | O(n-i)* | O(n-i) | O(m)* | O(n-i) |
113124
//! | VecDeque | O(1) | O(min(i, n-i))* | O(min(i, n-i)) | O(m)* | O(min(i, n-i)) |
114125
//! | LinkedList | O(min(i, n-i)) | O(min(i, n-i)) | O(min(i, n-i)) | O(1) | O(min(i, n-i)) |
126+
//! | BitVec | O(1) | O(n-i)* | O(n-i) | O(m)* | O(n-i) |
115127
//!
116128
//! Note that where ties occur, Vec is generally going to be faster than VecDeque, and VecDeque
117-
//! is generally going to be faster than LinkedList.
129+
//! is generally going to be faster than LinkedList. BitVec is not a general purpose collection, and
130+
//! therefore cannot reasonably be compared.
118131
//!
119132
//! ## Maps
120133
//!
121-
//! For Sets, all operations have the cost of the equivalent Map operation.
134+
//! For Sets, all operations have the cost of the equivalent Map operation. For
135+
//! BitSet,
136+
//! refer to VecMap.
122137
//!
123138
//! | | get | insert | remove | predecessor |
124139
//! |----------|-----------|----------|----------|-------------|
125140
//! | HashMap | O(1)~ | O(1)~* | O(1)~ | N/A |
126141
//! | BTreeMap | O(log n) | O(log n) | O(log n) | O(log n) |
142+
//! | VecMap | O(1) | O(1)? | O(1) | O(n) |
143+
//!
144+
//! Note that VecMap is *incredibly* inefficient in terms of space. The O(1)
145+
//! insertion time assumes space for the element is already allocated.
146+
//! Otherwise, a large key may require a massive reallocation, with no direct
147+
//! relation to the number of elements in the collection. VecMap should only be
148+
//! seriously considered for small keys.
127149
//!
128-
//! Note that BTreeMap's precise performance depends on the value of B.
150+
//! Note also that BTreeMap's precise performance depends on the value of B.
129151
//!
130152
//! # Correct and Efficient Usage of Collections
131153
//!

branches/try/src/libsyntax/entry.rs

Lines changed: 0 additions & 42 deletions
This file was deleted.

branches/try/src/libsyntax/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ pub mod attr;
9090
pub mod codemap;
9191
pub mod config;
9292
pub mod diagnostic;
93-
pub mod entry;
9493
pub mod feature_gate;
9594
pub mod fold;
9695
pub mod owned_slice;

branches/try/src/libsyntax/test.rs

Lines changed: 22 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#![allow(unused_imports)]
1515
use self::HasTestSignature::*;
1616

17-
use std::iter;
1817
use std::slice;
1918
use std::mem;
2019
use std::vec;
@@ -25,7 +24,6 @@ use codemap::{DUMMY_SP, Span, ExpnInfo, NameAndSpan, MacroAttribute};
2524
use codemap;
2625
use diagnostic;
2726
use config;
28-
use entry::{self, EntryPointType};
2927
use ext::base::ExtCtxt;
3028
use ext::build::AstBuilder;
3129
use ext::expand::ExpansionConfig;
@@ -175,6 +173,28 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
175173
let tests = mem::replace(&mut self.tests, tests);
176174
let tested_submods = mem::replace(&mut self.tested_submods, tested_submods);
177175

176+
// Remove any #[main] from the AST so it doesn't clash with
177+
// the one we're going to add. Only if compiling an executable.
178+
179+
mod_folded.items = mem::replace(&mut mod_folded.items, vec![]).move_map(|item| {
180+
item.map(|ast::Item {id, ident, attrs, node, vis, span}| {
181+
ast::Item {
182+
id: id,
183+
ident: ident,
184+
attrs: attrs.into_iter().filter_map(|attr| {
185+
if !attr.check_name("main") {
186+
Some(attr)
187+
} else {
188+
None
189+
}
190+
}).collect(),
191+
node: node,
192+
vis: vis,
193+
span: span
194+
}
195+
})
196+
});
197+
178198
if !tests.is_empty() || !tested_submods.is_empty() {
179199
let (it, sym) = mk_reexport_mod(&mut self.cx, tests, tested_submods);
180200
mod_folded.items.push(it);
@@ -191,55 +211,6 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
191211
}
192212
}
193213

194-
struct EntryPointCleaner {
195-
// Current depth in the ast
196-
depth: usize,
197-
}
198-
199-
impl fold::Folder for EntryPointCleaner {
200-
fn fold_item(&mut self, i: P<ast::Item>) -> SmallVector<P<ast::Item>> {
201-
self.depth += 1;
202-
let folded = fold::noop_fold_item(i, self).expect_one("noop did something");
203-
self.depth -= 1;
204-
205-
// Remove any #[main] or #[start] from the AST so it doesn't
206-
// clash with the one we're going to add, but mark it as
207-
// #[allow(dead_code)] to avoid printing warnings.
208-
let folded = match entry::entry_point_type(&*folded, self.depth) {
209-
EntryPointType::MainNamed |
210-
EntryPointType::MainAttr |
211-
EntryPointType::Start =>
212-
folded.map(|ast::Item {id, ident, attrs, node, vis, span}| {
213-
let allow_str = InternedString::new("allow");
214-
let dead_code_str = InternedString::new("dead_code");
215-
let allow_dead_code_item =
216-
attr::mk_list_item(allow_str,
217-
vec![attr::mk_word_item(dead_code_str)]);
218-
let allow_dead_code = attr::mk_attr_outer(attr::mk_attr_id(),
219-
allow_dead_code_item);
220-
221-
ast::Item {
222-
id: id,
223-
ident: ident,
224-
attrs: attrs.into_iter()
225-
.filter(|attr| {
226-
!attr.check_name("main") && !attr.check_name("start")
227-
})
228-
.chain(iter::once(allow_dead_code))
229-
.collect(),
230-
node: node,
231-
vis: vis,
232-
span: span
233-
}
234-
}),
235-
EntryPointType::None |
236-
EntryPointType::OtherMain => folded,
237-
};
238-
239-
SmallVector::one(folded)
240-
}
241-
}
242-
243214
fn mk_reexport_mod(cx: &mut TestCtxt, tests: Vec<ast::Ident>,
244215
tested_submods: Vec<(ast::Ident, ast::Ident)>) -> (P<ast::Item>, ast::Ident) {
245216
let super_ = token::str_to_ident("super");
@@ -275,10 +246,6 @@ fn generate_test_harness(sess: &ParseSess,
275246
krate: ast::Crate,
276247
cfg: &ast::CrateConfig,
277248
sd: &diagnostic::SpanHandler) -> ast::Crate {
278-
// Remove the entry points
279-
let mut cleaner = EntryPointCleaner { depth: 0 };
280-
let krate = cleaner.fold_crate(krate);
281-
282249
let mut feature_gated_cfgs = vec![];
283250
let mut cx: TestCtxt = TestCtxt {
284251
sess: sess,

branches/try/src/test/compile-fail/test-warns-dead-code.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)