Skip to content

Commit 87a912d

Browse files
committed
---
yaml --- r: 149353 b: refs/heads/try2 c: 9f68f79 h: refs/heads/master i: 149351: 7b7d9b5 v: v3
1 parent c10c05a commit 87a912d

File tree

30 files changed

+1035
-330
lines changed

30 files changed

+1035
-330
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 54f710fd2dca07313496d0b6f3f2e650d57a0833
8+
refs/heads/try2: 9f68f793d444285e5d7f00f57b5635ece43613b3
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/compiler-rt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit d4606f1818dd8dfeaa3e509cd1cbac4482c3513e
1+
Subproject commit f4b221571ce6f05714c1f1c6fa48f1393499989c

branches/try2/src/doc/guide-tasks.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ spawn(proc() {
226226
});
227227
~~~
228228

229-
Instead we can use a `SharedChan`, a type that allows a single
230-
`Chan` to be shared by multiple senders.
229+
Instead we can clone the `chan`, which allows for multiple senders.
231230

232231
~~~
233232
# use std::task::spawn;
@@ -246,16 +245,13 @@ let result = port.recv() + port.recv() + port.recv();
246245
# fn some_expensive_computation(_i: uint) -> int { 42 }
247246
~~~
248247

249-
Here we transfer ownership of the channel into a new `SharedChan` value. Like
250-
`Chan`, `SharedChan` is a non-copyable, owned type (sometimes also referred to
251-
as an *affine* or *linear* type). Unlike with `Chan`, though, the programmer
252-
may duplicate a `SharedChan`, with the `clone()` method. A cloned
253-
`SharedChan` produces a new handle to the same channel, allowing multiple
254-
tasks to send data to a single port. Between `spawn`, `Chan` and
255-
`SharedChan`, we have enough tools to implement many useful concurrency
256-
patterns.
248+
Cloning a `Chan` produces a new handle to the same channel, allowing multiple
249+
tasks to send data to a single port. It also upgrades the channel internally in
250+
order to allow this functionality, which means that channels that are not
251+
cloned can avoid the overhead required to handle multiple senders. But this
252+
fact has no bearing on the channel's usage: the upgrade is transparent.
257253

258-
Note that the above `SharedChan` example is somewhat contrived since
254+
Note that the above cloning example is somewhat contrived since
259255
you could also simply use three `Chan` pairs, but it serves to
260256
illustrate the point. For reference, written with multiple streams, it
261257
might look like the example below.

branches/try2/src/libextra/json.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ the code for these traits: `#[deriving(Decodable, Encodable)]`
5959
To encode using Encodable :
6060
6161
```rust
62+
extern crate extra;
6263
extern crate serialize;
6364
use extra::json;
6465
use std::io;
@@ -98,6 +99,7 @@ A basic `ToJson` example using a TreeMap of attribute name / attribute value:
9899
99100
100101
```rust
102+
extern crate extra;
101103
extern crate collections;
102104
103105
use extra::json;
@@ -125,9 +127,10 @@ fn main() {
125127
}
126128
```
127129
128-
To decode a json string using `Decodable` trait :
130+
To decode a JSON string using `Decodable` trait :
129131
130132
```rust
133+
extern crate extra;
131134
extern crate serialize;
132135
use serialize::Decodable;
133136
@@ -154,6 +157,7 @@ Create a struct called TestStruct1 and serialize and deserialize it to and from
154157
using the serialization API, using the derived serialization code.
155158
156159
```rust
160+
extern crate extra;
157161
extern crate serialize;
158162
use extra::json;
159163
use serialize::{Encodable, Decodable};
@@ -172,7 +176,7 @@ fn main() {
172176
{data_int: 1, data_str:~"toto", data_vector:~[2,3,4,5]};
173177
let encoded_str: ~str = json::Encoder::str_encode(&to_encode_object);
174178
175-
// To unserialize use the `extra::json::from_str` and `extra::json::Decoder`
179+
// To deserialize use the `extra::json::from_str` and `extra::json::Decoder`
176180
177181
let json_object = extra::json::from_str(encoded_str);
178182
let mut decoder = json::Decoder::new(json_object.unwrap());
@@ -182,10 +186,11 @@ fn main() {
182186
183187
## Using `ToJson`
184188
185-
This example use the ToJson impl to unserialize the json string.
189+
This example use the ToJson impl to deserialize the JSON string.
186190
Example of `ToJson` trait implementation for TestStruct1.
187191
188192
```rust
193+
extern crate extra;
189194
extern crate serialize;
190195
extern crate collections;
191196
@@ -212,13 +217,13 @@ impl ToJson for TestStruct1 {
212217
}
213218
214219
fn main() {
215-
// Seralization using our impl of to_json
220+
// Serialization using our impl of to_json
216221
217222
let test2: TestStruct1 = TestStruct1 {data_int: 1, data_str:~"toto", data_vector:~[2,3,4,5]};
218223
let tjson: json::Json = test2.to_json();
219224
let json_str: ~str = tjson.to_str();
220225
221-
// Unserialize like before.
226+
// Deserialize like before.
222227
223228
let mut decoder = json::Decoder::new(json::from_str(json_str).unwrap());
224229
// create the final object

branches/try2/src/libextra/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ impl MetricMap {
11101110
11111111
// Benchmarking
11121112
1113-
/// A function that is opaque to the optimiser, to allow benchmarks to
1113+
/// A function that is opaque to the optimizer, to allow benchmarks to
11141114
/// pretend to use outputs to assist in avoiding dead-code
11151115
/// elimination.
11161116
///

branches/try2/src/libgreen/sched.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub struct Scheduler {
8686
/// A flag to tell the scheduler loop it needs to do some stealing
8787
/// in order to introduce randomness as part of a yield
8888
steal_for_yield: bool,
89-
/// Bookeeping for the number of tasks which are currently running around
89+
/// Bookkeeping for the number of tasks which are currently running around
9090
/// inside this pool of schedulers
9191
task_state: TaskState,
9292

branches/try2/src/libnative/io/file.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,9 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> {
571571
else {
572572
let fp_vec = vec::from_buf(
573573
fp_buf, wcslen(fp_buf) as uint);
574-
let fp_str = str::from_utf16(fp_vec);
574+
let fp_trimmed = str::truncate_utf16_at_nul(fp_vec);
575+
let fp_str = str::from_utf16(fp_trimmed)
576+
.expect("rust_list_dir_wfd_fp_buf returned invalid UTF-16");
575577
paths.push(Path::new(fp_str));
576578
}
577579
more_files = FindNextFileW(find_handle, wfd_ptr as HANDLE);

branches/try2/src/librustc/middle/privacy.rs

Lines changed: 118 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ pub type ExportedItems = HashSet<ast::NodeId>;
4141
/// reexporting a public struct doesn't inline the doc).
4242
pub type PublicItems = HashSet<ast::NodeId>;
4343

44+
/// Result of a checking operation - None => no errors were found. Some => an
45+
/// error and contains the span and message for reporting that error and
46+
/// optionally the same for a note about the error.
47+
type CheckResult = Option<(Span, ~str, Option<(Span, ~str)>)>;
48+
4449
////////////////////////////////////////////////////////////////////////////////
4550
/// The parent visitor, used to determine what's the parent of what (node-wise)
4651
////////////////////////////////////////////////////////////////////////////////
@@ -510,40 +515,50 @@ impl<'a> PrivacyVisitor<'a> {
510515
}
511516
}
512517

513-
/// Guarantee that a particular definition is public, possibly emitting an
514-
/// error message if it's not.
518+
fn report_error(&self, result: CheckResult) -> bool {
519+
match result {
520+
None => true,
521+
Some((span, msg, note)) => {
522+
self.tcx.sess.span_err(span, msg);
523+
match note {
524+
Some((span, msg)) => self.tcx.sess.span_note(span, msg),
525+
None => {},
526+
}
527+
false
528+
},
529+
}
530+
}
531+
532+
/// Guarantee that a particular definition is public. Returns a CheckResult
533+
/// which contains any errors found. These can be reported using `report_error`.
534+
/// If the result is `None`, no errors were found.
515535
fn ensure_public(&self, span: Span, to_check: ast::DefId,
516-
source_did: Option<ast::DefId>, msg: &str) -> bool {
536+
source_did: Option<ast::DefId>, msg: &str) -> CheckResult {
517537
match self.def_privacy(to_check) {
518-
ExternallyDenied => {
519-
self.tcx.sess.span_err(span, format!("{} is private", msg))
520-
}
538+
ExternallyDenied => Some((span, format!("{} is private", msg), None)),
521539
DisallowedBy(id) => {
522-
if id == source_did.unwrap_or(to_check).node {
523-
self.tcx.sess.span_err(span, format!("{} is private", msg));
524-
return false;
540+
let (err_span, err_msg) = if id == source_did.unwrap_or(to_check).node {
541+
return Some((span, format!("{} is private", msg), None));
525542
} else {
526-
self.tcx.sess.span_err(span, format!("{} is inaccessible",
527-
msg));
528-
}
543+
(span, format!("{} is inaccessible", msg))
544+
};
529545
match self.tcx.map.find(id) {
530546
Some(ast_map::NodeItem(item)) => {
531547
let desc = match item.node {
532548
ast::ItemMod(..) => "module",
533549
ast::ItemTrait(..) => "trait",
534-
_ => return false,
550+
_ => return Some((err_span, err_msg, None)),
535551
};
536552
let msg = format!("{} `{}` is private",
537553
desc,
538554
token::get_ident(item.ident));
539-
self.tcx.sess.span_note(span, msg);
540-
}
541-
Some(..) | None => {}
555+
Some((err_span, err_msg, Some((span, msg))))
556+
},
557+
_ => Some((err_span, err_msg, None)),
542558
}
543-
}
544-
Allowable => return true
559+
},
560+
Allowable => None,
545561
}
546-
return false;
547562
}
548563

549564
// Checks that a field is in scope.
@@ -613,34 +628,99 @@ impl<'a> PrivacyVisitor<'a> {
613628
let method_id = ty::method(self.tcx, method_id).provided_source
614629
.unwrap_or(method_id);
615630

616-
self.ensure_public(span,
617-
method_id,
618-
None,
619-
format!("method `{}`", token::get_ident(name)));
631+
let string = token::get_ident(name);
632+
self.report_error(self.ensure_public(span,
633+
method_id,
634+
None,
635+
format!("method `{}`", string)));
620636
}
621637

622638
// Checks that a path is in scope.
623639
fn check_path(&mut self, span: Span, path_id: ast::NodeId, path: &ast::Path) {
624640
debug!("privacy - path {}", self.nodestr(path_id));
625641
let def_map = self.tcx.def_map.borrow();
626-
let def = def_map.get().get_copy(&path_id);
642+
let orig_def = def_map.get().get_copy(&path_id);
627643
let ck = |tyname: &str| {
628-
let origdid = def_id_of_def(def);
644+
let ck_public = |def: ast::DefId| {
645+
let name = token::get_ident(path.segments
646+
.last()
647+
.unwrap()
648+
.identifier);
649+
let origdid = def_id_of_def(orig_def);
650+
self.ensure_public(span,
651+
def,
652+
Some(origdid),
653+
format!("{} `{}`",
654+
tyname,
655+
name))
656+
};
657+
629658
match *self.last_private_map.get(&path_id) {
630-
resolve::AllPublic => {},
631-
resolve::DependsOn(def) => {
632-
let name = token::get_ident(path.segments
633-
.last()
634-
.unwrap()
635-
.identifier);
636-
self.ensure_public(span,
637-
def,
638-
Some(origdid),
639-
format!("{} `{}`",
640-
tyname, name));
641-
}
659+
resolve::LastMod(resolve::AllPublic) => {},
660+
resolve::LastMod(resolve::DependsOn(def)) => {
661+
self.report_error(ck_public(def));
662+
},
663+
resolve::LastImport{value_priv: value_priv,
664+
value_used: check_value,
665+
type_priv: type_priv,
666+
type_used: check_type} => {
667+
// This dance with found_error is because we don't want to report
668+
// a privacy error twice for the same directive.
669+
let found_error = match (type_priv, check_type) {
670+
(Some(resolve::DependsOn(def)), resolve::Used) => {
671+
!self.report_error(ck_public(def))
672+
},
673+
_ => false,
674+
};
675+
if !found_error {
676+
match (value_priv, check_value) {
677+
(Some(resolve::DependsOn(def)), resolve::Used) => {
678+
self.report_error(ck_public(def));
679+
},
680+
_ => {},
681+
}
682+
}
683+
// If an import is not used in either namespace, we still want to check
684+
// that it could be legal. Therefore we check in both namespaces and only
685+
// report an error if both would be illegal. We only report one error,
686+
// even if it is illegal to import from both namespaces.
687+
match (value_priv, check_value, type_priv, check_type) {
688+
(Some(p), resolve::Unused, None, _) |
689+
(None, _, Some(p), resolve::Unused) => {
690+
let p = match p {
691+
resolve::AllPublic => None,
692+
resolve::DependsOn(def) => ck_public(def),
693+
};
694+
if p.is_some() {
695+
self.report_error(p);
696+
}
697+
},
698+
(Some(v), resolve::Unused, Some(t), resolve::Unused) => {
699+
let v = match v {
700+
resolve::AllPublic => None,
701+
resolve::DependsOn(def) => ck_public(def),
702+
};
703+
let t = match t {
704+
resolve::AllPublic => None,
705+
resolve::DependsOn(def) => ck_public(def),
706+
};
707+
match (v, t) {
708+
(Some(_), Some(t)) => {
709+
self.report_error(Some(t));
710+
},
711+
_ => {},
712+
}
713+
},
714+
_ => {},
715+
}
716+
},
642717
}
643718
};
719+
// FIXME(#12334) Imports can refer to definitions in both the type and
720+
// value namespaces. The privacy information is aware of this, but the
721+
// def map is not. Therefore the names we work out below will not always
722+
// be accurate and we can get slightly wonky error messages (but type
723+
// checking is always correct).
644724
let def_map = self.tcx.def_map.borrow();
645725
match def_map.get().get_copy(&path_id) {
646726
ast::DefStaticMethod(..) => ck("static method"),
@@ -668,7 +748,7 @@ impl<'a> PrivacyVisitor<'a> {
668748
// is whether the trait itself is accessible or not.
669749
method_param(method_param { trait_id: trait_id, .. }) |
670750
method_object(method_object { trait_id: trait_id, .. }) => {
671-
self.ensure_public(span, trait_id, None, "source trait");
751+
self.report_error(self.ensure_public(span, trait_id, None, "source trait"));
672752
}
673753
}
674754
}

0 commit comments

Comments
 (0)