Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 13 pull requests #32759

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
313eb32
Address FIXMEs related to short lifetimes in `HashMap`.
frewsxcv Apr 1, 2016
a2f6d29
Remove error description of `move`
tclfs Apr 2, 2016
c822546
mk: Hardcode the bootstrap key for each release
alexcrichton Apr 4, 2016
4815f7e
Handle integer-extending for C ABI
Aatch Feb 17, 2016
a447124
Mention that it's not actually a data race
Manishearth Mar 27, 2016
0936b58
Remove strange names created by lack of privacy-conscious name lookup
tbu- Apr 5, 2016
af047d9
Fix infinite loop in Arc::downgrade
Amanieu Apr 5, 2016
8f463ea
doc: make env::consts summaries less confusing
tshepang Apr 5, 2016
9ba3d5e
Reinstate fast_reject for overlap checking
aturon Apr 5, 2016
d841c15
Doc fix: function takes argument by reference.
Mar 31, 2016
a7d15ce
Doc fix: list all module files Rust looks for.
Mar 31, 2016
6da3f85
Rollup merge of #31762 - tshepang:in-which-case, r=steveklabnik
Manishearth Apr 6, 2016
d940bf1
Rollup merge of #32538 - Manishearth:no-data-race, r=steveklabnik
Manishearth Apr 6, 2016
0863f0f
Rollup merge of #32634 - varunvats:docs-fix, r=steveklabnik
Manishearth Apr 6, 2016
0082881
Fix typos in atomic compare_exchange.
taralx Apr 6, 2016
8a89e49
Rollup merge of #32668 - frewsxcv:hashmap-address-fixme, r=alexcrichton
Manishearth Apr 6, 2016
2d3e9b3
Rollup merge of #32679 - tclfs:patch-1, r=steveklabnik
Manishearth Apr 6, 2016
ef39a8d
Rollup merge of #32731 - alexcrichton:known-bootstrap-key, r=brson
Manishearth Apr 6, 2016
81d3d71
Rollup merge of #32732 - dotdash:ext_arg, r=eddyb
Manishearth Apr 6, 2016
5042ac2
Rollup merge of #32741 - tbu-:pr_remove_fixme_12808, r=bluss
Manishearth Apr 6, 2016
96ab5a8
Rollup merge of #32745 - Amanieu:arc_fix, r=alexcrichton
Manishearth Apr 6, 2016
fd6b40c
Rollup merge of #32748 - aturon:simplified-spec, r=nikomatsakis
Manishearth Apr 6, 2016
ee55501
Rollup merge of #32757 - taralx:patch-1, r=brson
Manishearth Apr 6, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -717,18 +717,6 @@ if [ -n "$CFG_ENABLE_DEBUG_JEMALLOC" ]; then putvar CFG_ENABLE_DEBUG_JEMALLOC; f

if [ -n "$CFG_ENABLE_ORBIT" ]; then putvar CFG_ENABLE_ORBIT; fi

# A magic value that allows the compiler to use unstable features
# during the bootstrap even when doing so would normally be an error
# because of feature staging or because the build turns on
# warnings-as-errors and unstable features default to warnings. The
# build has to match this key in an env var. Meant to be a mild
# deterrent from users just turning on unstable features on the stable
# channel.
# Basing CFG_BOOTSTRAP_KEY on CFG_BOOTSTRAP_KEY lets it get picked up
# during a Makefile reconfig.
CFG_BOOTSTRAP_KEY="${CFG_BOOTSTRAP_KEY-`date +%H:%M:%S`}"
putvar CFG_BOOTSTRAP_KEY

step_msg "looking for build programs"

probe_need CFG_CURLORWGET curl wget
Expand Down
11 changes: 11 additions & 0 deletions mk/main.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ CFG_PRERELEASE_VERSION=.1
# versions in the same place
CFG_FILENAME_EXTRA=$(shell printf '%s' $(CFG_RELEASE)$(CFG_EXTRA_FILENAME) | $(CFG_HASH_COMMAND))

# A magic value that allows the compiler to use unstable features during the
# bootstrap even when doing so would normally be an error because of feature
# staging or because the build turns on warnings-as-errors and unstable features
# default to warnings. The build has to match this key in an env var.
#
# This value is keyed off the release to ensure that all compilers for one
# particular release have the same bootstrap key. Note that this is
# intentionally not "secure" by any definition, this is largely just a deterrent
# from users enabling unstable features on the stable compiler.
CFG_BOOTSTRAP_KEY=$(CFG_FILENAME_EXTRA)

ifeq ($(CFG_RELEASE_CHANNEL),stable)
# This is the normal semver version string, e.g. "0.12.0", "0.12.0-nightly"
CFG_RELEASE=$(CFG_RELEASE_NUM)
Expand Down
11 changes: 7 additions & 4 deletions src/doc/book/concurrency.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ thread may outlive the scope of `x`, leading to a dangling pointer.

To fix this, we use a `move` closure as mentioned in the error message. `move`
closures are explained in depth [here](closures.html#move-closures); basically
they move variables from their environment into themselves. This means that `x`
is now owned by the closure, and cannot be used in `main()` after the call to
`spawn()`.
they move variables from their environment into themselves.

```rust
use std::thread;
Expand Down Expand Up @@ -164,7 +162,7 @@ The same [ownership system](ownership.html) that helps prevent using pointers
incorrectly also helps rule out data races, one of the worst kinds of
concurrency bugs.

As an example, here is a Rust program that would have a data race in many
As an example, here is a Rust program that could have a data race in many
languages. It will not compile:

```ignore
Expand Down Expand Up @@ -197,6 +195,11 @@ thread, and the thread takes ownership of the reference, we'd have three owners!
`data` gets moved out of `main` in the first call to `spawn()`, so subsequent
calls in the loop cannot use this variable.

Note that this specific example will not cause a data race since different array
indices are being accessed. But this can't be determined at compile time, and in
a similar situation where `i` is a constant or is random, you would have a data
race.

So, we need some type that lets us have more than one owning reference to a
value. Usually, we'd use `Rc<T>` for this, which is a reference counted type
that provides shared ownership. It has some runtime bookkeeping that keeps track
Expand Down
22 changes: 14 additions & 8 deletions src/doc/book/crates-and-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ build deps examples libphrases-a7448e02a0468eaa.rlib native
`libphrases-hash.rlib` is the compiled crate. Before we see how to use this
crate from another crate, let’s break it up into multiple files.

# Multiple file crates
# Multiple File Crates

If each crate were just one file, these files would get very large. It’s often
easier to split up crates into multiple files, and Rust supports this in two
Expand Down Expand Up @@ -190,13 +190,19 @@ mod farewells;
```

Again, these declarations tell Rust to look for either
`src/english/greetings.rs` and `src/japanese/greetings.rs` or
`src/english/farewells/mod.rs` and `src/japanese/farewells/mod.rs`. Because
these sub-modules don’t have their own sub-modules, we’ve chosen to make them
`src/english/greetings.rs` and `src/japanese/farewells.rs`. Whew!

The contents of `src/english/greetings.rs` and `src/japanese/farewells.rs` are
both empty at the moment. Let’s add some functions.
`src/english/greetings.rs`, `src/english/farewells.rs`,
`src/japanese/greetings.rs` and `src/japanese/farewells.rs` or
`src/english/greetings/mod.rs`, `src/english/farewells/mod.rs`,
`src/japanese/greetings/mod.rs` and
`src/japanese/farewells/mod.rs`. Because these sub-modules don’t have
their own sub-modules, we’ve chosen to make them
`src/english/greetings.rs`, `src/english/farewells.rs`,
`src/japanese/greetings.rs` and `src/japanese/farewells.rs`. Whew!

The contents of `src/english/greetings.rs`,
`src/english/farewells.rs`, `src/japanese/greetings.rs` and
`src/japanese/farewells.rs` are all empty at the moment. Let’s add
some functions.

Put this in `src/english/greetings.rs`:

Expand Down
4 changes: 2 additions & 2 deletions src/doc/book/lifetimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ To fix this, we have to make sure that step four never happens after step
three. The ownership system in Rust does this through a concept called
lifetimes, which describe the scope that a reference is valid for.

When we have a function that takes a reference by argument, we can be implicit
or explicit about the lifetime of the reference:
When we have a function that takes an argument by reference, we can be
implicit or explicit about the lifetime of the reference:

```rust
// implicit
Expand Down
45 changes: 21 additions & 24 deletions src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
#[unsafe_no_drop_flag]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Arc<T: ?Sized> {
// FIXME #12808: strange name to try to avoid interfering with
// field accesses of the contained type via Deref
_ptr: Shared<ArcInner<T>>,
ptr: Shared<ArcInner<T>>,
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -144,9 +142,7 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Arc<U>> for Arc<T> {}
#[unsafe_no_drop_flag]
#[stable(feature = "arc_weak", since = "1.4.0")]
pub struct Weak<T: ?Sized> {
// FIXME #12808: strange name to try to avoid interfering with
// field accesses of the contained type via Deref
_ptr: Shared<ArcInner<T>>,
ptr: Shared<ArcInner<T>>,
}

#[stable(feature = "arc_weak", since = "1.4.0")]
Expand Down Expand Up @@ -198,7 +194,7 @@ impl<T> Arc<T> {
weak: atomic::AtomicUsize::new(1),
data: data,
};
Arc { _ptr: unsafe { Shared::new(Box::into_raw(x)) } }
Arc { ptr: unsafe { Shared::new(Box::into_raw(x)) } }
}

/// Unwraps the contained value if the `Arc<T>` has exactly one strong reference.
Expand Down Expand Up @@ -230,11 +226,11 @@ impl<T> Arc<T> {
atomic::fence(Acquire);

unsafe {
let ptr = *this._ptr;
let ptr = *this.ptr;
let elem = ptr::read(&(*ptr).data);

// Make a weak pointer to clean up the implicit strong-weak reference
let _weak = Weak { _ptr: this._ptr };
let _weak = Weak { ptr: this.ptr };
mem::forget(this);

Ok(elem)
Expand Down Expand Up @@ -263,6 +259,7 @@ impl<T: ?Sized> Arc<T> {
loop {
// check if the weak counter is currently "locked"; if so, spin.
if cur == usize::MAX {
cur = this.inner().weak.load(Relaxed);
continue;
}

Expand All @@ -274,7 +271,7 @@ impl<T: ?Sized> Arc<T> {
// synchronize with the write coming from `is_unique`, so that the
// events prior to that write happen before this read.
match this.inner().weak.compare_exchange_weak(cur, cur + 1, Acquire, Relaxed) {
Ok(_) => return Weak { _ptr: this._ptr },
Ok(_) => return Weak { ptr: this.ptr },
Err(old) => cur = old,
}
}
Expand Down Expand Up @@ -303,13 +300,13 @@ impl<T: ?Sized> Arc<T> {
// `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 }
unsafe { &**self.ptr }
}

// Non-inlined part of `drop`.
#[inline(never)]
unsafe fn drop_slow(&mut self) {
let ptr = *self._ptr;
let ptr = *self.ptr;

// Destroy the data at this time, even though we may not free the box
// allocation itself (there may still be weak pointers lying around).
Expand Down Expand Up @@ -367,7 +364,7 @@ impl<T: ?Sized> Clone for Arc<T> {
}
}

Arc { _ptr: self._ptr }
Arc { ptr: self.ptr }
}
}

Expand Down Expand Up @@ -435,15 +432,15 @@ impl<T: Clone> Arc<T> {

// Materialize our own implicit weak pointer, so that it can clean
// up the ArcInner as needed.
let weak = Weak { _ptr: this._ptr };
let weak = Weak { ptr: this.ptr };

// mark the data itself as already deallocated
unsafe {
// there is no data race in the implicit write caused by `read`
// here (due to zeroing) because data is no longer accessed by
// other threads (due to there being no more strong refs at this
// point).
let mut swap = Arc::new(ptr::read(&(**weak._ptr).data));
let mut swap = Arc::new(ptr::read(&(**weak.ptr).data));
mem::swap(this, &mut swap);
mem::forget(swap);
}
Expand All @@ -456,7 +453,7 @@ impl<T: Clone> Arc<T> {
// As with `get_mut()`, the unsafety is ok because our reference was
// either unique to begin with, or became one upon cloning the contents.
unsafe {
let inner = &mut **this._ptr;
let inner = &mut **this.ptr;
&mut inner.data
}
}
Expand Down Expand Up @@ -488,7 +485,7 @@ impl<T: ?Sized> Arc<T> {
// the Arc itself to be `mut`, so we're returning the only possible
// reference to the inner data.
unsafe {
let inner = &mut **this._ptr;
let inner = &mut **this.ptr;
Some(&mut inner.data)
}
} else {
Expand Down Expand Up @@ -557,7 +554,7 @@ impl<T: ?Sized> Drop for Arc<T> {
// 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
// it's run more than once)
let thin = *self._ptr as *const ();
let thin = *self.ptr as *const ();

if thin as usize == mem::POST_DROP_USIZE {
return;
Expand Down Expand Up @@ -638,7 +635,7 @@ impl<T: ?Sized> Weak<T> {

// Relaxed is valid for the same reason it is on Arc's Clone impl
match inner.strong.compare_exchange_weak(n, n + 1, Relaxed, Relaxed) {
Ok(_) => return Some(Arc { _ptr: self._ptr }),
Ok(_) => return Some(Arc { ptr: self.ptr }),
Err(old) => n = old,
}
}
Expand All @@ -647,7 +644,7 @@ impl<T: ?Sized> Weak<T> {
#[inline]
fn inner(&self) -> &ArcInner<T> {
// See comments above for why this is "safe"
unsafe { &**self._ptr }
unsafe { &**self.ptr }
}
}

Expand Down Expand Up @@ -681,7 +678,7 @@ impl<T: ?Sized> Clone for Weak<T> {
}
}

return Weak { _ptr: self._ptr };
return Weak { ptr: self.ptr };
}
}

Expand Down Expand Up @@ -713,7 +710,7 @@ impl<T: ?Sized> Drop for Weak<T> {
/// } // implicit drop
/// ```
fn drop(&mut self) {
let ptr = *self._ptr;
let ptr = *self.ptr;
let thin = ptr as *const ();

// see comments above for why this check is here
Expand Down Expand Up @@ -885,7 +882,7 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Arc<T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> fmt::Pointer for Arc<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Pointer::fmt(&*self._ptr, f)
fmt::Pointer::fmt(&*self.ptr, f)
}
}

Expand Down Expand Up @@ -930,7 +927,7 @@ impl<T> Weak<T> {
issue = "30425")]
pub fn new() -> Weak<T> {
unsafe {
Weak { _ptr: Shared::new(Box::into_raw(box ArcInner {
Weak { ptr: Shared::new(Box::into_raw(box ArcInner {
strong: atomic::AtomicUsize::new(0),
weak: atomic::AtomicUsize::new(1),
data: uninitialized(),
Expand Down
Loading