1
Fork 0

Issue #3511 - Rationalize temporary lifetimes.

Major changes:

- Define temporary scopes in a syntax-based way that basically defaults
  to the innermost statement or conditional block, except for in
  a `let` initializer, where we default to the innermost block. Rules
  are documented in the code, but not in the manual (yet).
  See new test run-pass/cleanup-value-scopes.rs for examples.
- Refactors Datum to better define cleanup roles.
- Refactor cleanup scopes to not be tied to basic blocks, permitting
  us to have a very large number of scopes (one per AST node).
- Introduce nascent documentation in trans/doc.rs covering datums and
  cleanup in a more comprehensive way.
This commit is contained in:
Niko Matsakis 2014-01-15 14:39:08 -05:00
parent 149fc76698
commit 419ac4a1b8
64 changed files with 4826 additions and 3691 deletions

View file

@ -168,7 +168,7 @@ pub fn from_elem<T:Clone>(n_elts: uint, t: T) -> ~[T] {
let mut v = with_capacity(n_elts);
let p = v.as_mut_ptr();
let mut i = 0u;
(|| {
(|| { // FIXME what if we fail in the middle of this loop?
while i < n_elts {
intrinsics::move_val_init(&mut(*ptr::mut_offset(p, i as int)), t.clone());
i += 1u;
@ -239,6 +239,25 @@ pub fn build<A>(size: Option<uint>, builder: |push: |v: A||) -> ~[A] {
vec
}
/**
* Converts a pointer to A into a slice of length 1 (without copying).
*/
pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] {
unsafe {
cast::transmute(Slice { data: s, len: 1 })
}
}
/**
* Converts a pointer to A into a slice of length 1 (without copying).
*/
pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] {
unsafe {
let ptr: *A = cast::transmute(s);
cast::transmute(Slice { data: ptr, len: 1 })
}
}
/// An iterator over the slices of a vector separated by elements that
/// match a predicate function.
pub struct SplitIterator<'a, T> {
@ -2175,6 +2194,9 @@ pub trait MutableVector<'a, T> {
/// Returns an iterator that allows modifying each value
fn mut_iter(self) -> VecMutIterator<'a, T>;
/// Returns a mutable pointer to the last item in the vector.
fn mut_last(self) -> &'a mut T;
/// Returns a reversed iterator that allows modifying each value
fn mut_rev_iter(self) -> MutRevIterator<'a, T>;
@ -2437,6 +2459,13 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] {
}
}
#[inline]
fn mut_last(self) -> &'a mut T {
let len = self.len();
if len == 0 { fail!("mut_last: empty vector") }
&mut self[len - 1]
}
#[inline]
fn mut_rev_iter(self) -> MutRevIterator<'a, T> {
self.mut_iter().invert()