1
Fork 0

Fallout from glob shadowing

This commit is contained in:
Nick Cameron 2014-12-29 10:22:37 +13:00
parent f53314cd70
commit 9c1567e622
5 changed files with 50 additions and 67 deletions

View file

@ -1554,8 +1554,7 @@ pub fn arg_kind<'a, 'tcx>(cx: &FunctionContext<'a, 'tcx>, t: Ty<'tcx>)
} }
// work around bizarre resolve errors // work around bizarre resolve errors
pub type RvalueDatum<'tcx> = datum::Datum<'tcx, datum::Rvalue>; type RvalueDatum<'tcx> = datum::Datum<'tcx, datum::Rvalue>;
pub type LvalueDatum<'tcx> = datum::Datum<'tcx, datum::Lvalue>;
// create_datums_for_fn_args: creates rvalue datums for each of the // create_datums_for_fn_args: creates rvalue datums for each of the
// incoming function arguments. These will later be stored into // incoming function arguments. These will later be stored into

View file

@ -190,8 +190,8 @@ pub fn validate_substs(substs: &Substs) {
} }
// work around bizarre resolve errors // work around bizarre resolve errors
pub type RvalueDatum<'tcx> = datum::Datum<'tcx, datum::Rvalue>; type RvalueDatum<'tcx> = datum::Datum<'tcx, datum::Rvalue>;
pub type LvalueDatum<'tcx> = datum::Datum<'tcx, datum::Lvalue>; type LvalueDatum<'tcx> = datum::Datum<'tcx, datum::Lvalue>;
// Function context. Every LLVM function we create will have one of // Function context. Every LLVM function we create will have one of
// these. // these.

View file

@ -181,7 +181,7 @@
// senders. Under the hood, however, there are actually three flavors of // senders. Under the hood, however, there are actually three flavors of
// channels in play. // channels in play.
// //
// * Oneshots - these channels are highly optimized for the one-send use case. // * Flavor::Oneshots - these channels are highly optimized for the one-send use case.
// They contain as few atomics as possible and involve one and // They contain as few atomics as possible and involve one and
// exactly one allocation. // exactly one allocation.
// * Streams - these channels are optimized for the non-shared use case. They // * Streams - these channels are optimized for the non-shared use case. They
@ -316,7 +316,6 @@ use core::prelude::*;
pub use self::TryRecvError::*; pub use self::TryRecvError::*;
pub use self::TrySendError::*; pub use self::TrySendError::*;
use self::Flavor::*;
use alloc::arc::Arc; use alloc::arc::Arc;
use core::kinds; use core::kinds;
@ -478,7 +477,7 @@ impl<T> UnsafeFlavor<T> for Receiver<T> {
#[unstable] #[unstable]
pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) { pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) {
let a = Arc::new(RacyCell::new(oneshot::Packet::new())); let a = Arc::new(RacyCell::new(oneshot::Packet::new()));
(Sender::new(Oneshot(a.clone())), Receiver::new(Oneshot(a))) (Sender::new(Flavor::Oneshot(a.clone())), Receiver::new(Flavor::Oneshot(a)))
} }
/// Creates a new synchronous, bounded channel. /// Creates a new synchronous, bounded channel.
@ -518,7 +517,7 @@ pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) {
of channel that is is creating"] of channel that is is creating"]
pub fn sync_channel<T: Send>(bound: uint) -> (SyncSender<T>, Receiver<T>) { pub fn sync_channel<T: Send>(bound: uint) -> (SyncSender<T>, Receiver<T>) {
let a = Arc::new(RacyCell::new(sync::Packet::new(bound))); let a = Arc::new(RacyCell::new(sync::Packet::new(bound)));
(SyncSender::new(a.clone()), Receiver::new(Sync(a))) (SyncSender::new(a.clone()), Receiver::new(Flavor::Sync(a)))
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -592,7 +591,7 @@ impl<T: Send> Sender<T> {
#[unstable = "this function may be renamed to send() in the future"] #[unstable = "this function may be renamed to send() in the future"]
pub fn send_opt(&self, t: T) -> Result<(), T> { pub fn send_opt(&self, t: T) -> Result<(), T> {
let (new_inner, ret) = match *unsafe { self.inner() } { let (new_inner, ret) = match *unsafe { self.inner() } {
Oneshot(ref p) => { Flavor::Oneshot(ref p) => {
unsafe { unsafe {
let p = p.get(); let p = p.get();
if !(*p).sent() { if !(*p).sent() {
@ -600,7 +599,7 @@ impl<T: Send> Sender<T> {
} else { } else {
let a = let a =
Arc::new(RacyCell::new(stream::Packet::new())); Arc::new(RacyCell::new(stream::Packet::new()));
match (*p).upgrade(Receiver::new(Stream(a.clone()))) { match (*p).upgrade(Receiver::new(Flavor::Stream(a.clone()))) {
oneshot::UpSuccess => { oneshot::UpSuccess => {
let ret = (*a.get()).send(t); let ret = (*a.get()).send(t);
(a, ret) (a, ret)
@ -618,13 +617,13 @@ impl<T: Send> Sender<T> {
} }
} }
} }
Stream(ref p) => return unsafe { (*p.get()).send(t) }, Flavor::Stream(ref p) => return unsafe { (*p.get()).send(t) },
Shared(ref p) => return unsafe { (*p.get()).send(t) }, Flavor::Shared(ref p) => return unsafe { (*p.get()).send(t) },
Sync(..) => unreachable!(), Flavor::Sync(..) => unreachable!(),
}; };
unsafe { unsafe {
let tmp = Sender::new(Stream(new_inner)); let tmp = Sender::new(Flavor::Stream(new_inner));
mem::swap(self.inner_mut(), tmp.inner_mut()); mem::swap(self.inner_mut(), tmp.inner_mut());
} }
return ret; return ret;
@ -635,42 +634,42 @@ impl<T: Send> Sender<T> {
impl<T: Send> Clone for Sender<T> { impl<T: Send> Clone for Sender<T> {
fn clone(&self) -> Sender<T> { fn clone(&self) -> Sender<T> {
let (packet, sleeper, guard) = match *unsafe { self.inner() } { let (packet, sleeper, guard) = match *unsafe { self.inner() } {
Oneshot(ref p) => { Flavor::Oneshot(ref p) => {
let a = Arc::new(RacyCell::new(shared::Packet::new())); let a = Arc::new(RacyCell::new(shared::Packet::new()));
unsafe { unsafe {
let guard = (*a.get()).postinit_lock(); let guard = (*a.get()).postinit_lock();
match (*p.get()).upgrade(Receiver::new(Shared(a.clone()))) { match (*p.get()).upgrade(Receiver::new(Flavor::Shared(a.clone()))) {
oneshot::UpSuccess | oneshot::UpSuccess |
oneshot::UpDisconnected => (a, None, guard), oneshot::UpDisconnected => (a, None, guard),
oneshot::UpWoke(task) => (a, Some(task), guard) oneshot::UpWoke(task) => (a, Some(task), guard)
} }
} }
} }
Stream(ref p) => { Flavor::Stream(ref p) => {
let a = Arc::new(RacyCell::new(shared::Packet::new())); let a = Arc::new(RacyCell::new(shared::Packet::new()));
unsafe { unsafe {
let guard = (*a.get()).postinit_lock(); let guard = (*a.get()).postinit_lock();
match (*p.get()).upgrade(Receiver::new(Shared(a.clone()))) { match (*p.get()).upgrade(Receiver::new(Flavor::Shared(a.clone()))) {
stream::UpSuccess | stream::UpSuccess |
stream::UpDisconnected => (a, None, guard), stream::UpDisconnected => (a, None, guard),
stream::UpWoke(task) => (a, Some(task), guard), stream::UpWoke(task) => (a, Some(task), guard),
} }
} }
} }
Shared(ref p) => { Flavor::Shared(ref p) => {
unsafe { (*p.get()).clone_chan(); } unsafe { (*p.get()).clone_chan(); }
return Sender::new(Shared(p.clone())); return Sender::new(Flavor::Shared(p.clone()));
} }
Sync(..) => unreachable!(), Flavor::Sync(..) => unreachable!(),
}; };
unsafe { unsafe {
(*packet.get()).inherit_blocker(sleeper, guard); (*packet.get()).inherit_blocker(sleeper, guard);
let tmp = Sender::new(Shared(packet.clone())); let tmp = Sender::new(Flavor::Shared(packet.clone()));
mem::swap(self.inner_mut(), tmp.inner_mut()); mem::swap(self.inner_mut(), tmp.inner_mut());
} }
Sender::new(Shared(packet)) Sender::new(Flavor::Shared(packet))
} }
} }
@ -678,10 +677,10 @@ impl<T: Send> Clone for Sender<T> {
impl<T: Send> Drop for Sender<T> { impl<T: Send> Drop for Sender<T> {
fn drop(&mut self) { fn drop(&mut self) {
match *unsafe { self.inner_mut() } { match *unsafe { self.inner_mut() } {
Oneshot(ref mut p) => unsafe { (*p.get()).drop_chan(); }, Flavor::Oneshot(ref mut p) => unsafe { (*p.get()).drop_chan(); },
Stream(ref mut p) => unsafe { (*p.get()).drop_chan(); }, Flavor::Stream(ref mut p) => unsafe { (*p.get()).drop_chan(); },
Shared(ref mut p) => unsafe { (*p.get()).drop_chan(); }, Flavor::Shared(ref mut p) => unsafe { (*p.get()).drop_chan(); },
Sync(..) => unreachable!(), Flavor::Sync(..) => unreachable!(),
} }
} }
} }
@ -827,7 +826,7 @@ impl<T: Send> Receiver<T> {
pub fn try_recv(&self) -> Result<T, TryRecvError> { pub fn try_recv(&self) -> Result<T, TryRecvError> {
loop { loop {
let new_port = match *unsafe { self.inner() } { let new_port = match *unsafe { self.inner() } {
Oneshot(ref p) => { Flavor::Oneshot(ref p) => {
match unsafe { (*p.get()).try_recv() } { match unsafe { (*p.get()).try_recv() } {
Ok(t) => return Ok(t), Ok(t) => return Ok(t),
Err(oneshot::Empty) => return Err(Empty), Err(oneshot::Empty) => return Err(Empty),
@ -835,7 +834,7 @@ impl<T: Send> Receiver<T> {
Err(oneshot::Upgraded(rx)) => rx, Err(oneshot::Upgraded(rx)) => rx,
} }
} }
Stream(ref p) => { Flavor::Stream(ref p) => {
match unsafe { (*p.get()).try_recv() } { match unsafe { (*p.get()).try_recv() } {
Ok(t) => return Ok(t), Ok(t) => return Ok(t),
Err(stream::Empty) => return Err(Empty), Err(stream::Empty) => return Err(Empty),
@ -843,14 +842,14 @@ impl<T: Send> Receiver<T> {
Err(stream::Upgraded(rx)) => rx, Err(stream::Upgraded(rx)) => rx,
} }
} }
Shared(ref p) => { Flavor::Shared(ref p) => {
match unsafe { (*p.get()).try_recv() } { match unsafe { (*p.get()).try_recv() } {
Ok(t) => return Ok(t), Ok(t) => return Ok(t),
Err(shared::Empty) => return Err(Empty), Err(shared::Empty) => return Err(Empty),
Err(shared::Disconnected) => return Err(Disconnected), Err(shared::Disconnected) => return Err(Disconnected),
} }
} }
Sync(ref p) => { Flavor::Sync(ref p) => {
match unsafe { (*p.get()).try_recv() } { match unsafe { (*p.get()).try_recv() } {
Ok(t) => return Ok(t), Ok(t) => return Ok(t),
Err(sync::Empty) => return Err(Empty), Err(sync::Empty) => return Err(Empty),
@ -881,7 +880,7 @@ impl<T: Send> Receiver<T> {
pub fn recv_opt(&self) -> Result<T, ()> { pub fn recv_opt(&self) -> Result<T, ()> {
loop { loop {
let new_port = match *unsafe { self.inner() } { let new_port = match *unsafe { self.inner() } {
Oneshot(ref p) => { Flavor::Oneshot(ref p) => {
match unsafe { (*p.get()).recv() } { match unsafe { (*p.get()).recv() } {
Ok(t) => return Ok(t), Ok(t) => return Ok(t),
Err(oneshot::Empty) => return unreachable!(), Err(oneshot::Empty) => return unreachable!(),
@ -889,7 +888,7 @@ impl<T: Send> Receiver<T> {
Err(oneshot::Upgraded(rx)) => rx, Err(oneshot::Upgraded(rx)) => rx,
} }
} }
Stream(ref p) => { Flavor::Stream(ref p) => {
match unsafe { (*p.get()).recv() } { match unsafe { (*p.get()).recv() } {
Ok(t) => return Ok(t), Ok(t) => return Ok(t),
Err(stream::Empty) => return unreachable!(), Err(stream::Empty) => return unreachable!(),
@ -897,14 +896,14 @@ impl<T: Send> Receiver<T> {
Err(stream::Upgraded(rx)) => rx, Err(stream::Upgraded(rx)) => rx,
} }
} }
Shared(ref p) => { Flavor::Shared(ref p) => {
match unsafe { (*p.get()).recv() } { match unsafe { (*p.get()).recv() } {
Ok(t) => return Ok(t), Ok(t) => return Ok(t),
Err(shared::Empty) => return unreachable!(), Err(shared::Empty) => return unreachable!(),
Err(shared::Disconnected) => return Err(()), Err(shared::Disconnected) => return Err(()),
} }
} }
Sync(ref p) => return unsafe { (*p.get()).recv() } Flavor::Sync(ref p) => return unsafe { (*p.get()).recv() }
}; };
unsafe { unsafe {
mem::swap(self.inner_mut(), new_port.inner_mut()); mem::swap(self.inner_mut(), new_port.inner_mut());
@ -924,22 +923,22 @@ impl<T: Send> select::Packet for Receiver<T> {
fn can_recv(&self) -> bool { fn can_recv(&self) -> bool {
loop { loop {
let new_port = match *unsafe { self.inner() } { let new_port = match *unsafe { self.inner() } {
Oneshot(ref p) => { Flavor::Oneshot(ref p) => {
match unsafe { (*p.get()).can_recv() } { match unsafe { (*p.get()).can_recv() } {
Ok(ret) => return ret, Ok(ret) => return ret,
Err(upgrade) => upgrade, Err(upgrade) => upgrade,
} }
} }
Stream(ref p) => { Flavor::Stream(ref p) => {
match unsafe { (*p.get()).can_recv() } { match unsafe { (*p.get()).can_recv() } {
Ok(ret) => return ret, Ok(ret) => return ret,
Err(upgrade) => upgrade, Err(upgrade) => upgrade,
} }
} }
Shared(ref p) => { Flavor::Shared(ref p) => {
return unsafe { (*p.get()).can_recv() }; return unsafe { (*p.get()).can_recv() };
} }
Sync(ref p) => { Flavor::Sync(ref p) => {
return unsafe { (*p.get()).can_recv() }; return unsafe { (*p.get()).can_recv() };
} }
}; };
@ -953,24 +952,24 @@ impl<T: Send> select::Packet for Receiver<T> {
fn start_selection(&self, mut token: SignalToken) -> StartResult { fn start_selection(&self, mut token: SignalToken) -> StartResult {
loop { loop {
let (t, new_port) = match *unsafe { self.inner() } { let (t, new_port) = match *unsafe { self.inner() } {
Oneshot(ref p) => { Flavor::Oneshot(ref p) => {
match unsafe { (*p.get()).start_selection(token) } { match unsafe { (*p.get()).start_selection(token) } {
oneshot::SelSuccess => return Installed, oneshot::SelSuccess => return Installed,
oneshot::SelCanceled => return Abort, oneshot::SelCanceled => return Abort,
oneshot::SelUpgraded(t, rx) => (t, rx), oneshot::SelUpgraded(t, rx) => (t, rx),
} }
} }
Stream(ref p) => { Flavor::Stream(ref p) => {
match unsafe { (*p.get()).start_selection(token) } { match unsafe { (*p.get()).start_selection(token) } {
stream::SelSuccess => return Installed, stream::SelSuccess => return Installed,
stream::SelCanceled => return Abort, stream::SelCanceled => return Abort,
stream::SelUpgraded(t, rx) => (t, rx), stream::SelUpgraded(t, rx) => (t, rx),
} }
} }
Shared(ref p) => { Flavor::Shared(ref p) => {
return unsafe { (*p.get()).start_selection(token) }; return unsafe { (*p.get()).start_selection(token) };
} }
Sync(ref p) => { Flavor::Sync(ref p) => {
return unsafe { (*p.get()).start_selection(token) }; return unsafe { (*p.get()).start_selection(token) };
} }
}; };
@ -985,14 +984,14 @@ impl<T: Send> select::Packet for Receiver<T> {
let mut was_upgrade = false; let mut was_upgrade = false;
loop { loop {
let result = match *unsafe { self.inner() } { let result = match *unsafe { self.inner() } {
Oneshot(ref p) => unsafe { (*p.get()).abort_selection() }, Flavor::Oneshot(ref p) => unsafe { (*p.get()).abort_selection() },
Stream(ref p) => unsafe { Flavor::Stream(ref p) => unsafe {
(*p.get()).abort_selection(was_upgrade) (*p.get()).abort_selection(was_upgrade)
}, },
Shared(ref p) => return unsafe { Flavor::Shared(ref p) => return unsafe {
(*p.get()).abort_selection(was_upgrade) (*p.get()).abort_selection(was_upgrade)
}, },
Sync(ref p) => return unsafe { Flavor::Sync(ref p) => return unsafe {
(*p.get()).abort_selection() (*p.get()).abort_selection()
}, },
}; };
@ -1015,10 +1014,10 @@ impl<'a, T: Send> Iterator<T> for Messages<'a, T> {
impl<T: Send> Drop for Receiver<T> { impl<T: Send> Drop for Receiver<T> {
fn drop(&mut self) { fn drop(&mut self) {
match *unsafe { self.inner_mut() } { match *unsafe { self.inner_mut() } {
Oneshot(ref mut p) => unsafe { (*p.get()).drop_port(); }, Flavor::Oneshot(ref mut p) => unsafe { (*p.get()).drop_port(); },
Stream(ref mut p) => unsafe { (*p.get()).drop_port(); }, Flavor::Stream(ref mut p) => unsafe { (*p.get()).drop_port(); },
Shared(ref mut p) => unsafe { (*p.get()).drop_port(); }, Flavor::Shared(ref mut p) => unsafe { (*p.get()).drop_port(); },
Sync(ref mut p) => unsafe { (*p.get()).drop_port(); }, Flavor::Sync(ref mut p) => unsafe { (*p.get()).drop_port(); },
} }
} }
} }

View file

@ -17,8 +17,7 @@ mod test1 {
mod bar { pub fn p() -> int { 2 } } mod bar { pub fn p() -> int { 2 } }
pub mod baz { pub mod baz {
use test1::foo::*; use test1::bar::p;
use test1::bar::*;
pub fn my_main() { assert!(p() == 2); } pub fn my_main() { assert!(p() == 2); }
} }
@ -36,20 +35,7 @@ mod test2 {
} }
} }
mod test3 {
mod foo { pub fn p() -> int { 1 } }
mod bar { pub fn p() -> int { 2 } }
pub mod baz {
use test3::bar::p;
pub fn my_main() { assert!(p() == 2); }
}
}
fn main() { fn main() {
test1::baz::my_main(); test1::baz::my_main();
test2::baz::my_main(); test2::baz::my_main();
test3::baz::my_main();
} }

View file

@ -23,7 +23,6 @@
#![allow(unused_imports)] #![allow(unused_imports)]
use std::io::*; use std::io::*;
use std::io::net::tcp::*;
use std::io::test::*; use std::io::test::*;
use std::io; use std::io;
use std::time::Duration; use std::time::Duration;