Skip to content

Commit

Permalink
auto merge of #16285 : alexcrichton/rust/rename-share, r=huonw
Browse files Browse the repository at this point in the history
This leaves the `Share` trait at `std::kinds` via a `#[deprecated]` `pub use`
statement, but the `NoShare` struct is no longer part of `std::kinds::marker`
due to #12660 (the build cannot bootstrap otherwise).

All code referencing the `Share` trait should now reference the `Sync` trait,
and all code referencing the `NoShare` type should now reference the `NoSync`
type. The functionality and meaning of this trait have not changed, only the
naming.

Closes #16281
[breaking-change]
  • Loading branch information
bors committed Aug 8, 2014
2 parents 87d2bf4 + 1f760d5 commit aae7901
Show file tree
Hide file tree
Showing 59 changed files with 199 additions and 190 deletions.
10 changes: 5 additions & 5 deletions src/doc/complement-design-faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ non-deterministic behavior. Rust provides the tools to make using a GC
possible and even pleasant, but it should not be a requirement for
implementing the language.

## Non-`Share` `static mut` is unsafe
## Non-`Sync` `static mut` is unsafe

Types which are [`Share`][share] are thread-safe when multiple shared
references to them are used concurrently. Types which are not `Share` are not
Types which are [`Sync`][sync] are thread-safe when multiple shared
references to them are used concurrently. Types which are not `Sync` are not
thread-safe, and thus when used in a global require unsafe code to use.

[share]: http://doc.rust-lang.org/core/kinds/trait.Share.html
[sync]: http://doc.rust-lang.org/core/kinds/trait.Sync.html

### If mutable static items that implement `Share` are safe, why is taking &mut SHARABLE unsafe?
### If mutable static items that implement `Sync` are safe, why is taking &mut SHARABLE unsafe?

Having multiple aliasing `&mut T`s is never allowed. Due to the nature of
globals, the borrow checker cannot possibly ensure that a static obeys the
Expand Down
4 changes: 2 additions & 2 deletions src/doc/guide-unsafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,10 @@ Other features provided by lang items include:
- stack unwinding and general failure; the `eh_personality`, `fail_`
and `fail_bounds_checks` lang items.
- the traits in `std::kinds` used to indicate types that satisfy
various kinds; lang items `send`, `share` and `copy`.
various kinds; lang items `send`, `sync` and `copy`.
- the marker types and variance indicators found in
`std::kinds::markers`; lang items `covariant_type`,
`contravariant_lifetime`, `no_share_bound`, etc.
`contravariant_lifetime`, `no_sync_bound`, etc.

Lang items are loaded lazily by the compiler; e.g. if one never uses
`Box` then there is no need to define functions for `exchange_malloc`
Expand Down
6 changes: 3 additions & 3 deletions src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -2111,7 +2111,7 @@ A complete list of the built-in language items follows:
: Has a size known at compile time.
* `copy`
: Types that do not move ownership when used by-value.
* `share`
* `sync`
: Able to be safely shared between tasks when aliased.
* `drop`
: Have destructors.
Expand Down Expand Up @@ -2191,8 +2191,8 @@ These types help drive the compiler's analysis
: This type does not implement "send", even if eligible
* `no_copy_bound`
: This type does not implement "copy", even if eligible
* `no_share_bound`
: This type does not implement "share", even if eligible
* `no_sync_bound`
: This type does not implement "sync", even if eligible
* `managed_bound`
: This type implements "managed"

Expand Down
8 changes: 4 additions & 4 deletions src/doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -2196,7 +2196,7 @@ and may not be overridden:
Types are sendable
unless they contain references.

* `Share` - Types that are *threadsafe*.
* `Sync` - Types that are *threadsafe*.
These are types that are safe to be used across several threads with access to
a `&T` pointer. `Mutex<T>` is an example of a *sharable* type with internal mutable data.

Expand Down Expand Up @@ -2250,7 +2250,7 @@ We say that the `Printable` trait _provides_ a `print` method with the
given signature. This means that we can call `print` on an argument
of any type that implements the `Printable` trait.

Rust's built-in `Send` and `Share` types are examples of traits that
Rust's built-in `Send` and `Sync` types are examples of traits that
don't provide any methods.

Traits may be implemented for specific types with [impls]. An impl for
Expand Down Expand Up @@ -2535,7 +2535,7 @@ select the method to call at runtime.

This usage of traits is similar to Java interfaces.

There are some built-in bounds, such as `Send` and `Share`, which are properties
There are some built-in bounds, such as `Send` and `Sync`, which are properties
of the components of types. By design, trait objects don't know the exact type
of their contents and so the compiler cannot reason about those properties.

Expand All @@ -2548,7 +2548,7 @@ trait Foo {}
trait Bar<T> {}

fn sendable_foo(f: Box<Foo + Send>) { /* ... */ }
fn shareable_bar<T: Share>(b: &Bar<T> + Share) { /* ... */ }
fn sync_bar<T: Sync>(b: &Bar<T> + Sync) { /* ... */ }
~~~

When no colon is specified (such as the type `Box<Foo>`), it is inferred that the
Expand Down
2 changes: 1 addition & 1 deletion src/etc/vim/syntax/rust.vim
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ syn keyword rustType f64 i8 i16 i32 i64 str Self
" to make it easy to update.

" Core operators {{{3
syn keyword rustTrait Copy Send Sized Share
syn keyword rustTrait Copy Send Sized Sync
syn keyword rustTrait Add Sub Mul Div Rem Neg Not
syn keyword rustTrait BitAnd BitOr BitXor
syn keyword rustTrait Drop Deref DerefMut
Expand Down
22 changes: 11 additions & 11 deletions src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use core::atomic;
use core::clone::Clone;
use core::kinds::{Share, Send};
use core::kinds::{Sync, Send};
use core::mem::{min_align_of, size_of, drop};
use core::mem;
use core::ops::{Drop, Deref};
Expand Down Expand Up @@ -76,7 +76,7 @@ struct ArcInner<T> {
data: T,
}

impl<T: Share + Send> Arc<T> {
impl<T: Sync + Send> Arc<T> {
/// Create an atomically reference counted wrapper.
#[inline]
#[stable]
Expand All @@ -95,8 +95,8 @@ impl<T: Share + Send> Arc<T> {
fn inner(&self) -> &ArcInner<T> {
// This unsafety is ok because while this arc is alive we're guaranteed
// that the inner pointer is valid. Furthermore, we know that the
// `ArcInner` structure itself is `Share` because the inner data is
// `Share` as well, so we're ok loaning out an immutable pointer to
// `ArcInner` structure itself is `Sync` because the inner data is
// `Sync` as well, so we're ok loaning out an immutable pointer to
// these contents.
unsafe { &*self._ptr }
}
Expand All @@ -115,7 +115,7 @@ impl<T: Share + Send> Arc<T> {
}

#[unstable = "waiting on stability of Clone"]
impl<T: Share + Send> Clone for Arc<T> {
impl<T: Sync + Send> Clone for Arc<T> {
/// Duplicate an atomically reference counted wrapper.
///
/// The resulting two `Arc` objects will point to the same underlying data
Expand All @@ -140,14 +140,14 @@ impl<T: Share + Send> Clone for Arc<T> {
}

#[experimental = "Deref is experimental."]
impl<T: Send + Share> Deref<T> for Arc<T> {
impl<T: Send + Sync> Deref<T> for Arc<T> {
#[inline]
fn deref(&self) -> &T {
&self.inner().data
}
}

impl<T: Send + Share + Clone> Arc<T> {
impl<T: Send + Sync + Clone> Arc<T> {
/// Acquires a mutable pointer to the inner contents by guaranteeing that
/// the reference count is one (no sharing is possible).
///
Expand Down Expand Up @@ -175,7 +175,7 @@ impl<T: Send + Share + Clone> Arc<T> {

#[unsafe_destructor]
#[experimental = "waiting on stability of Drop"]
impl<T: Share + Send> Drop for Arc<T> {
impl<T: Sync + Send> Drop for Arc<T> {
fn drop(&mut self) {
// This structure has #[unsafe_no_drop_flag], so this drop glue may run
// more than once (but it is guaranteed to be zeroed after the first if
Expand Down Expand Up @@ -219,7 +219,7 @@ impl<T: Share + Send> Drop for Arc<T> {
}

#[experimental = "Weak pointers may not belong in this module."]
impl<T: Share + Send> Weak<T> {
impl<T: Sync + Send> Weak<T> {
/// Attempts to upgrade this weak reference to a strong reference.
///
/// This method will fail to upgrade this reference if the strong reference
Expand All @@ -245,7 +245,7 @@ impl<T: Share + Send> Weak<T> {
}

#[experimental = "Weak pointers may not belong in this module."]
impl<T: Share + Send> Clone for Weak<T> {
impl<T: Sync + Send> Clone for Weak<T> {
#[inline]
fn clone(&self) -> Weak<T> {
// See comments in Arc::clone() for why this is relaxed
Expand All @@ -256,7 +256,7 @@ impl<T: Share + Send> Clone for Weak<T> {

#[unsafe_destructor]
#[experimental = "Weak pointers may not belong in this module."]
impl<T: Share + Send> Drop for Weak<T> {
impl<T: Sync + Send> Drop for Weak<T> {
fn drop(&mut self) {
// see comments above for why this check is here
if self._ptr.is_null() { return }
Expand Down
14 changes: 7 additions & 7 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub struct Rc<T> {
// field accesses of the contained type via Deref
_ptr: *mut RcBox<T>,
_nosend: marker::NoSend,
_noshare: marker::NoShare
_noshare: marker::NoSync
}

#[stable]
Expand All @@ -199,7 +199,7 @@ impl<T> Rc<T> {
weak: Cell::new(1)
}),
_nosend: marker::NoSend,
_noshare: marker::NoShare
_noshare: marker::NoSync
}
}
}
Expand All @@ -213,7 +213,7 @@ impl<T> Rc<T> {
Weak {
_ptr: self._ptr,
_nosend: marker::NoSend,
_noshare: marker::NoShare
_noshare: marker::NoSync
}
}
}
Expand Down Expand Up @@ -348,7 +348,7 @@ impl<T> Clone for Rc<T> {
#[inline]
fn clone(&self) -> Rc<T> {
self.inc_strong();
Rc { _ptr: self._ptr, _nosend: marker::NoSend, _noshare: marker::NoShare }
Rc { _ptr: self._ptr, _nosend: marker::NoSend, _noshare: marker::NoSync }
}
}

Expand Down Expand Up @@ -412,7 +412,7 @@ pub struct Weak<T> {
// field accesses of the contained type via Deref
_ptr: *mut RcBox<T>,
_nosend: marker::NoSend,
_noshare: marker::NoShare
_noshare: marker::NoSync
}

#[experimental = "Weak pointers may not belong in this module."]
Expand All @@ -423,7 +423,7 @@ impl<T> Weak<T> {
None
} else {
self.inc_strong();
Some(Rc { _ptr: self._ptr, _nosend: marker::NoSend, _noshare: marker::NoShare })
Some(Rc { _ptr: self._ptr, _nosend: marker::NoSend, _noshare: marker::NoSync })
}
}
}
Expand Down Expand Up @@ -451,7 +451,7 @@ impl<T> Clone for Weak<T> {
#[inline]
fn clone(&self) -> Weak<T> {
self.inc_weak();
Weak { _ptr: self._ptr, _nosend: marker::NoSend, _noshare: marker::NoShare }
Weak { _ptr: self._ptr, _nosend: marker::NoSend, _noshare: marker::NoSync }
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ use option::{None, Option, Some};
#[unstable = "likely to be renamed; otherwise stable"]
pub struct Cell<T> {
value: UnsafeCell<T>,
noshare: marker::NoShare,
noshare: marker::NoSync,
}

#[stable]
Expand All @@ -174,7 +174,7 @@ impl<T:Copy> Cell<T> {
pub fn new(value: T) -> Cell<T> {
Cell {
value: UnsafeCell::new(value),
noshare: marker::NoShare,
noshare: marker::NoSync,
}
}

Expand Down Expand Up @@ -213,7 +213,7 @@ pub struct RefCell<T> {
value: UnsafeCell<T>,
borrow: Cell<BorrowFlag>,
nocopy: marker::NoCopy,
noshare: marker::NoShare,
noshare: marker::NoSync,
}

// Values [1, MAX-1] represent the number of `Ref` active
Expand All @@ -230,7 +230,7 @@ impl<T> RefCell<T> {
value: UnsafeCell::new(value),
borrow: Cell::new(UNUSED),
nocopy: marker::NoCopy,
noshare: marker::NoShare,
noshare: marker::NoSync,
}
}

Expand Down Expand Up @@ -430,7 +430,7 @@ impl<'b, T> DerefMut<T> for RefMut<'b, T> {
///
/// struct NotThreadSafe<T> {
/// value: UnsafeCell<T>,
/// marker: marker::NoShare
/// marker: marker::NoSync
/// }
/// ```
///
Expand Down
Loading

0 comments on commit aae7901

Please sign in to comment.