Skip to content

Commit 6d46835

Browse files
committed
---
yaml --- r: 64373 b: refs/heads/snap-stage3 c: 0fd4d5d h: refs/heads/master i: 64371: 996dbe0 v: v3
1 parent 9e4bdff commit 6d46835

File tree

5 files changed

+38
-159
lines changed

5 files changed

+38
-159
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: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 948a62401ef717eb484c2215713291749f0f35ed
4+
refs/heads/snap-stage3: 0fd4d5d7783ffa709bcf089f5167a1871ec278fa
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/middle/lint.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,22 @@ pub fn level_to_str(lv: level) -> &'static str {
108108
}
109109
}
110110

111-
#[deriving(Eq)]
111+
#[deriving(Eq, Ord)]
112112
pub enum level {
113113
allow, warn, deny, forbid
114114
}
115115

116-
struct LintSpec {
116+
#[deriving(Eq)]
117+
pub struct LintSpec {
117118
lint: lint,
118119
desc: &'static str,
119120
default: level
120121
}
121122

123+
impl Ord for LintSpec {
124+
fn lt(&self, other: &LintSpec) -> bool { self.default < other.default }
125+
}
126+
122127
pub type LintDict = HashMap<&'static str, LintSpec>;
123128

124129
enum AttributedNode<'self> {

branches/snap-stage3/src/librustc/rustc.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ Additional help:
144144
}
145145

146146
pub fn describe_warnings() {
147+
use extra::sort::Sort;
147148
io::println(fmt!("
148149
Available lint options:
149150
-W <foo> Warn about <foo>
@@ -153,8 +154,15 @@ Available lint options:
153154
"));
154155

155156
let lint_dict = lint::get_lint_dict();
157+
let mut lint_dict = lint_dict.consume_iter()
158+
.transform(|(k, v)| (v, k))
159+
.collect::<~[(lint::LintSpec, &'static str)]>();
160+
lint_dict.qsort();
161+
156162
let mut max_key = 0;
157-
for lint_dict.each_key |k| { max_key = num::max(k.len(), max_key); }
163+
for lint_dict.iter().advance |&(_, name)| {
164+
max_key = num::max(name.len(), max_key);
165+
}
158166
fn padded(max: uint, s: &str) -> ~str {
159167
str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s
160168
}
@@ -163,17 +171,12 @@ Available lint options:
163171
padded(max_key, "name"), "default", "meaning"));
164172
io::println(fmt!(" %s %7.7s %s\n",
165173
padded(max_key, "----"), "-------", "-------"));
166-
for lint_dict.iter().advance |(k, v)| {
167-
let k = k.replace("_", "-");
174+
for lint_dict.consume_iter().advance |(spec, name)| {
175+
let name = name.replace("_", "-");
168176
io::println(fmt!(" %s %7.7s %s",
169-
padded(max_key, k),
170-
match v.default {
171-
lint::allow => ~"allow",
172-
lint::warn => ~"warn",
173-
lint::deny => ~"deny",
174-
lint::forbid => ~"forbid"
175-
},
176-
v.desc));
177+
padded(max_key, name),
178+
lint::level_to_str(spec.default),
179+
spec.desc));
177180
}
178181
io::println("");
179182
}

branches/snap-stage3/src/libstd/local_data.rs

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ magic.
4141

4242
use prelude::*;
4343

44-
use task::local_data_priv::*;
44+
use task::local_data_priv::{local_get, local_pop, local_set, Handle};
4545

4646
#[cfg(test)] use task;
4747

@@ -95,13 +95,6 @@ pub fn get<T: 'static, U>(key: Key<@T>, f: &fn(Option<&@T>) -> U) -> U {
9595
pub fn get<T: 'static, U>(key: Key<T>, f: &fn(Option<&T>) -> U) -> U {
9696
unsafe { local_get(Handle::new(), key, f) }
9797
}
98-
/**
99-
* Retrieve a mutable borrowed pointer to a task-local data value.
100-
*/
101-
#[cfg(not(stage0))]
102-
pub fn get_mut<T: 'static, U>(key: Key<T>, f: &fn(Option<&mut T>) -> U) -> U {
103-
unsafe { local_get_mut(Handle::new(), key, f) }
104-
}
10598
/**
10699
* Store a value in task-local data. If this key already has a value,
107100
* that value is overwritten (and its destructor is run).
@@ -269,34 +262,6 @@ fn test_static_pointer() {
269262
fn test_owned() {
270263
static key: Key<~int> = &Key;
271264
set(key, ~1);
272-
273-
do get(key) |v| {
274-
do get(key) |v| {
275-
do get(key) |v| {
276-
assert_eq!(**v.unwrap(), 1);
277-
}
278-
assert_eq!(**v.unwrap(), 1);
279-
}
280-
assert_eq!(**v.unwrap(), 1);
281-
}
282-
set(key, ~2);
283-
do get(key) |v| {
284-
assert_eq!(**v.unwrap(), 2);
285-
}
286-
}
287-
288-
#[test]
289-
fn test_get_mut() {
290-
static key: Key<int> = &Key;
291-
set(key, 1);
292-
293-
do get_mut(key) |v| {
294-
*v.unwrap() = 2;
295-
}
296-
297-
do get(key) |v| {
298-
assert_eq!(*v.unwrap(), 2);
299-
}
300265
}
301266

302267
#[test]
@@ -318,43 +283,3 @@ fn test_same_key_type() {
318283
get(key4, |x| assert_eq!(*x.unwrap(), 4));
319284
get(key5, |x| assert_eq!(*x.unwrap(), 5));
320285
}
321-
322-
#[test]
323-
#[should_fail]
324-
fn test_nested_get_set1() {
325-
static key: Key<int> = &Key;
326-
set(key, 4);
327-
do get(key) |_| {
328-
set(key, 4);
329-
}
330-
}
331-
332-
#[test]
333-
#[should_fail]
334-
fn test_nested_get_mut2() {
335-
static key: Key<int> = &Key;
336-
set(key, 4);
337-
do get(key) |_| {
338-
get_mut(key, |_| {})
339-
}
340-
}
341-
342-
#[test]
343-
#[should_fail]
344-
fn test_nested_get_mut3() {
345-
static key: Key<int> = &Key;
346-
set(key, 4);
347-
do get_mut(key) |_| {
348-
get(key, |_| {})
349-
}
350-
}
351-
352-
#[test]
353-
#[should_fail]
354-
fn test_nested_get_mut4() {
355-
static key: Key<int> = &Key;
356-
set(key, 4);
357-
do get_mut(key) |_| {
358-
get_mut(key, |_| {})
359-
}
360-
}

branches/snap-stage3/src/libstd/task/local_data_priv.rs

Lines changed: 15 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,6 @@ impl Handle {
4444
}
4545
}
4646

47-
#[deriving(Eq)]
48-
enum LoanState {
49-
NoLoan, ImmLoan, MutLoan
50-
}
51-
52-
impl LoanState {
53-
fn describe(&self) -> &'static str {
54-
match *self {
55-
NoLoan => "no loan",
56-
ImmLoan => "immutable",
57-
MutLoan => "mutable"
58-
}
59-
}
60-
}
61-
6247
trait LocalData {}
6348
impl<T: 'static> LocalData for T {}
6449

@@ -92,7 +77,7 @@ impl<T: 'static> LocalData for T {}
9277
//
9378
// n.b. If TLS is used heavily in future, this could be made more efficient with
9479
// a proper map.
95-
type TaskLocalMap = ~[Option<(*libc::c_void, TLSValue, LoanState)>];
80+
type TaskLocalMap = ~[Option<(*libc::c_void, TLSValue, uint)>];
9681
type TLSValue = ~LocalData:;
9782

9883
fn cleanup_task_local_map(map_ptr: *libc::c_void) {
@@ -167,10 +152,9 @@ pub unsafe fn local_pop<T: 'static>(handle: Handle,
167152

168153
for map.mut_iter().advance |entry| {
169154
match *entry {
170-
Some((k, _, loan)) if k == key_value => {
171-
if loan != NoLoan {
172-
fail!("TLS value cannot be removed because it is already \
173-
borrowed as %s", loan.describe());
155+
Some((k, _, loans)) if k == key_value => {
156+
if loans != 0 {
157+
fail!("TLS value has been loaned via get already");
174158
}
175159
// Move the data out of the `entry` slot via util::replace. This
176160
// is guaranteed to succeed because we already matched on `Some`
@@ -208,29 +192,6 @@ pub unsafe fn local_pop<T: 'static>(handle: Handle,
208192
pub unsafe fn local_get<T: 'static, U>(handle: Handle,
209193
key: local_data::Key<T>,
210194
f: &fn(Option<&T>) -> U) -> U {
211-
local_get_with(handle, key, ImmLoan, f)
212-
}
213-
214-
pub unsafe fn local_get_mut<T: 'static, U>(handle: Handle,
215-
key: local_data::Key<T>,
216-
f: &fn(Option<&mut T>) -> U) -> U {
217-
do local_get_with(handle, key, MutLoan) |x| {
218-
match x {
219-
None => f(None),
220-
// We're violating a lot of compiler guarantees with this
221-
// invocation of `transmute_mut`, but we're doing runtime checks to
222-
// ensure that it's always valid (only one at a time).
223-
//
224-
// there is no need to be upset!
225-
Some(x) => { f(Some(cast::transmute_mut(x))) }
226-
}
227-
}
228-
}
229-
230-
unsafe fn local_get_with<T: 'static, U>(handle: Handle,
231-
key: local_data::Key<T>,
232-
state: LoanState,
233-
f: &fn(Option<&T>) -> U) -> U {
234195
// This function must be extremely careful. Because TLS can store owned
235196
// values, and we must have some form of `get` function other than `pop`,
236197
// this function has to give a `&` reference back to the caller.
@@ -257,24 +218,12 @@ unsafe fn local_get_with<T: 'static, U>(handle: Handle,
257218
None => { return f(None); }
258219
Some(i) => {
259220
let ret;
260-
let mut return_loan = false;
261221
match map[i] {
262-
Some((_, ref data, ref mut loan)) => {
263-
match (state, *loan) {
264-
(_, NoLoan) => {
265-
*loan = state;
266-
return_loan = true;
267-
}
268-
(ImmLoan, ImmLoan) => {}
269-
(want, cur) => {
270-
fail!("TLS slot cannot be borrowed as %s because \
271-
it is already borrowed as %s",
272-
want.describe(), cur.describe());
273-
}
274-
}
222+
Some((_, ref data, ref mut loans)) => {
223+
*loans = *loans + 1;
275224
// data was created with `~~T as ~LocalData`, so we extract
276225
// pointer part of the trait, (as ~~T), and then use
277-
// compiler coercions to achieve a '&' pointer.
226+
// compiler coercions to achieve a '&' pointer
278227
match *cast::transmute::<&TLSValue, &(uint, ~~T)>(data) {
279228
(_vtable, ref box) => {
280229
let value: &T = **box;
@@ -289,11 +238,9 @@ unsafe fn local_get_with<T: 'static, U>(handle: Handle,
289238
// 'f' returned because `f` could have appended more TLS items which
290239
// in turn relocated the vector. Hence we do another lookup here to
291240
// fixup the loans.
292-
if return_loan {
293-
match map[i] {
294-
Some((_, _, ref mut loan)) => { *loan = NoLoan; }
295-
None => { libc::abort(); }
296-
}
241+
match map[i] {
242+
Some((_, _, ref mut loans)) => { *loans = *loans - 1; }
243+
None => { libc::abort(); }
297244
}
298245
return ret;
299246
}
@@ -322,10 +269,9 @@ pub unsafe fn local_set<T: 'static>(handle: Handle,
322269
// First see if the map contains this key already
323270
let curspot = map.iter().position(|entry| {
324271
match *entry {
325-
Some((ekey, _, loan)) if key == ekey => {
326-
if loan != NoLoan {
327-
fail!("TLS value cannot be overwritten because it is
328-
already borrowed as %s", loan.describe())
272+
Some((ekey, _, loans)) if key == ekey => {
273+
if loans != 0 {
274+
fail!("TLS value has been loaned via get already");
329275
}
330276
true
331277
}
@@ -340,7 +286,7 @@ pub unsafe fn local_set<T: 'static>(handle: Handle,
340286
}
341287

342288
match insertion_position(map, keyval) {
343-
Some(i) => { map[i] = Some((keyval, data, NoLoan)); }
344-
None => { map.push(Some((keyval, data, NoLoan))); }
289+
Some(i) => { map[i] = Some((keyval, data, 0)); }
290+
None => { map.push(Some((keyval, data, 0))); }
345291
}
346292
}

0 commit comments

Comments
 (0)