Skip to content

Commit

Permalink
librustc: Modify all code to use new lifetime binder syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
pcwalton committed Mar 26, 2013
1 parent 2296b16 commit b8621cf
Show file tree
Hide file tree
Showing 139 changed files with 427 additions and 517 deletions.
2 changes: 1 addition & 1 deletion doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ static bit2: uint = 1 << 1;
static bits: [uint, ..2] = [bit1, bit2];
static string: &'static str = "bitstring";
struct BitsNStrings {
struct BitsNStrings<'self> {
mybits: [uint, ..2],
mystring: &'self str
}
Expand Down
20 changes: 10 additions & 10 deletions doc/tutorial-borrowed-ptr.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ For example, we could write a subroutine like this:

~~~
struct Point {x: float, y: float}
fn get_x(p: &'r Point) -> &'r float { &p.x }
fn get_x<'r>(p: &'r Point) -> &'r float { &p.x }
~~~

Here, the function `get_x()` returns a pointer into the structure it
Expand Down Expand Up @@ -571,8 +571,8 @@ function:
# Rectangle(Point, Size) // upper-left, dimensions
# }
# fn compute_area(shape: &Shape) -> float { 0f }
fn select<T>(shape: &'r Shape, threshold: float,
a: &'r T, b: &'r T) -> &'r T {
fn select<'r, T>(shape: &'r Shape, threshold: float,
a: &'r T, b: &'r T) -> &'r T {
if compute_area(shape) > threshold {a} else {b}
}
~~~
Expand All @@ -591,12 +591,12 @@ example:
# Rectangle(Point, Size) // upper-left, dimensions
# }
# fn compute_area(shape: &Shape) -> float { 0f }
# fn select<T>(shape: &Shape, threshold: float,
# a: &'r T, b: &'r T) -> &'r T {
# fn select<'r, T>(shape: &Shape, threshold: float,
# a: &'r T, b: &'r T) -> &'r T {
# if compute_area(shape) > threshold {a} else {b}
# }
// -+ r
fn select_based_on_unit_circle<T>( // |-+ B
fn select_based_on_unit_circle<'r, T>( // |-+ B
threshold: float, a: &'r T, b: &'r T) -> &'r T { // | |
// | |
let shape = Circle(Point {x: 0., y: 0.}, 1.); // | |
Expand Down Expand Up @@ -628,8 +628,8 @@ returned. Here is how the new `select()` might look:
# Rectangle(Point, Size) // upper-left, dimensions
# }
# fn compute_area(shape: &Shape) -> float { 0f }
fn select<T>(shape: &'tmp Shape, threshold: float,
a: &'r T, b: &'r T) -> &'r T {
fn select<'r, 'tmp, T>(shape: &'tmp Shape, threshold: float,
a: &'r T, b: &'r T) -> &'r T {
if compute_area(shape) > threshold {a} else {b}
}
~~~
Expand All @@ -647,8 +647,8 @@ concise to just omit the named lifetime for `shape` altogether:
# Rectangle(Point, Size) // upper-left, dimensions
# }
# fn compute_area(shape: &Shape) -> float { 0f }
fn select<T>(shape: &Shape, threshold: float,
a: &'r T, b: &'r T) -> &'r T {
fn select<'r, T>(shape: &Shape, threshold: float,
a: &'r T, b: &'r T) -> &'r T {
if compute_area(shape) > threshold {a} else {b}
}
~~~
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/at_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub mod traits {
use kinds::Copy;
use ops::Add;

impl<T:Copy> Add<&'self const [T],@[T]> for @[T] {
impl<'self,T:Copy> Add<&'self const [T],@[T]> for @[T] {
#[inline(always)]
fn add(&self, rhs: & &'self const [T]) -> @[T] {
append(*self, (*rhs))
Expand Down
14 changes: 8 additions & 6 deletions src/libcore/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,19 @@ pub unsafe fn transmute<L, G>(thing: L) -> G {

/// Coerce an immutable reference to be mutable.
#[inline(always)]
pub unsafe fn transmute_mut<T>(ptr: &'a T) -> &'a mut T { transmute(ptr) }
pub unsafe fn transmute_mut<'a,T>(ptr: &'a T) -> &'a mut T { transmute(ptr) }

/// Coerce a mutable reference to be immutable.
#[inline(always)]
pub unsafe fn transmute_immut<T>(ptr: &'a mut T) -> &'a T {
pub unsafe fn transmute_immut<'a,T>(ptr: &'a mut T) -> &'a T {
transmute(ptr)
}

/// Coerce a borrowed pointer to have an arbitrary associated region.
#[inline(always)]
pub unsafe fn transmute_region<T>(ptr: &'a T) -> &'b T { transmute(ptr) }
pub unsafe fn transmute_region<'a,'b,T>(ptr: &'a T) -> &'b T {
transmute(ptr)
}

/// Coerce an immutable reference to be mutable.
#[inline(always)]
Expand All @@ -87,19 +89,19 @@ pub unsafe fn transmute_immut_unsafe<T>(ptr: *const T) -> *T {

/// Coerce a borrowed mutable pointer to have an arbitrary associated region.
#[inline(always)]
pub unsafe fn transmute_mut_region<T>(ptr: &'a mut T) -> &'b mut T {
pub unsafe fn transmute_mut_region<'a,'b,T>(ptr: &'a mut T) -> &'b mut T {
transmute(ptr)
}

/// Transforms lifetime of the second pointer to match the first.
#[inline(always)]
pub unsafe fn copy_lifetime<S,T>(_ptr: &'a S, ptr: &T) -> &'a T {
pub unsafe fn copy_lifetime<'a,S,T>(_ptr: &'a S, ptr: &T) -> &'a T {
transmute_region(ptr)
}

/// Transforms lifetime of the second pointer to match the first.
#[inline(always)]
pub unsafe fn copy_lifetime_vec<S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {
pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {
transmute_region(ptr)
}

Expand Down
4 changes: 2 additions & 2 deletions src/libcore/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use cast::transmute;
* NB: These must match the representation in the C++ runtime.
*/

type DropGlue = &'self fn(**TypeDesc, *c_void);
type FreeGlue = &'self fn(**TypeDesc, *c_void);
type DropGlue<'self> = &'self fn(**TypeDesc, *c_void);
type FreeGlue<'self> = &'self fn(**TypeDesc, *c_void);

type TaskID = uintptr_t;

Expand Down
12 changes: 6 additions & 6 deletions src/libcore/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ pub struct Handler<T, U> {
prev: Option<@Handler<T, U>>,
}

pub struct Condition<T, U> {
pub struct Condition<'self, T, U> {
name: &'static str,
key: task::local_data::LocalDataKey<'self, Handler<T, U>>
}

pub impl<T, U> Condition<'self, T, U> {
pub impl<'self, T, U> Condition<'self, T, U> {
fn trap(&self, h: &'self fn(T) -> U) -> Trap<'self, T, U> {
unsafe {
let p : *RustClosure = ::cast::transmute(&h);
Expand Down Expand Up @@ -66,12 +66,12 @@ pub impl<T, U> Condition<'self, T, U> {
}
}

struct Trap<T, U> {
struct Trap<'self, T, U> {
cond: &'self Condition<'self, T, U>,
handler: @Handler<T, U>
}

pub impl<T, U> Trap<'self, T, U> {
pub impl<'self, T, U> Trap<'self, T, U> {
fn in<V>(&self, inner: &'self fn() -> V) -> V {
unsafe {
let _g = Guard { cond: self.cond };
Expand All @@ -82,12 +82,12 @@ pub impl<T, U> Trap<'self, T, U> {
}
}

struct Guard<T, U> {
struct Guard<'self, T, U> {
cond: &'self Condition<'self, T, U>
}

#[unsafe_destructor]
impl<T, U> Drop for Guard<'self, T, U> {
impl<'self, T, U> Drop for Guard<'self, T, U> {
fn finalize(&self) {
unsafe {
debug!("Guard: popping handler from TLS");
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ unsafe fn is_safe_point(pc: *Word) -> Option<SafePoint> {
return None;
}

type Visitor = &'self fn(root: **Word, tydesc: *Word) -> bool;
type Visitor<'self> = &'self fn(root: **Word, tydesc: *Word) -> bool;

// Walks the list of roots for the given safe point, and calls visitor
// on each root.
Expand Down
7 changes: 3 additions & 4 deletions src/libcore/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,8 @@ pub mod linear {
}
}
impl<K:Hash + IterBytes + Eq,V>
BaseIter<(&'self K, &'self V)> for LinearMap<K, V>
{
impl<'self,K:Hash + IterBytes + Eq,V>
BaseIter<(&'self K, &'self V)> for LinearMap<K, V> {
/// Visit all key-value pairs
fn each(&self, blk: &fn(&(&'self K, &'self V)) -> bool) {
for uint::range(0, self.buckets.len()) |i| {
Expand Down Expand Up @@ -315,7 +314,7 @@ pub mod linear {
}
}
impl<K:Hash + IterBytes + Eq,V> Map<K, V> for LinearMap<K, V> {
impl<'self,K:Hash + IterBytes + Eq,V> Map<K, V> for LinearMap<K, V> {
/// Return true if the map contains a value for the specified key
fn contains_key(&self, k: &K) -> bool {
match self.bucket_for_key(k) {
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,12 @@ pub fn file_reader(path: &Path) -> Result<@Reader, ~str> {
// Byte readers
pub struct BytesReader {
pub struct BytesReader<'self> {
bytes: &'self [u8],
mut pos: uint
}
impl Reader for BytesReader<'self> {
impl<'self> Reader for BytesReader<'self> {
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
let count = uint::min(len, self.bytes.len() - self.pos);
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use option::{None, Option, Some};
use vec;

/// A function used to initialize the elements of a sequence
pub type InitOp<T> = &'self fn(uint) -> T;
pub type InitOp<'self,T> = &'self fn(uint) -> T;

pub trait BaseIter<A> {
fn each(&self, blk: &fn(v: &A) -> bool);
Expand Down
12 changes: 7 additions & 5 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub fn get<T:Copy>(opt: Option<T>) -> T {
}
#[inline(always)]
pub fn get_ref<T>(opt: &'r Option<T>) -> &'r T {
pub fn get_ref<'r,T>(opt: &'r Option<T>) -> &'r T {
/*!
Gets an immutable reference to the value inside an option.
Expand All @@ -143,7 +143,7 @@ pub fn get_ref<T>(opt: &'r Option<T>) -> &'r T {
}
}
pub fn get_mut_ref<T>(opt: &'r mut Option<T>) -> &'r mut T {
pub fn get_mut_ref<'r,T>(opt: &'r mut Option<T>) -> &'r mut T {
/*!
Gets a mutable reference to the value inside an option.
Expand All @@ -165,7 +165,7 @@ pub fn get_mut_ref<T>(opt: &'r mut Option<T>) -> &'r mut T {
}
#[inline(always)]
pub fn map<T, U>(opt: &'r Option<T>, f: &fn(x: &'r T) -> U) -> Option<U> {
pub fn map<'r, T, U>(opt: &'r Option<T>, f: &fn(x: &'r T) -> U) -> Option<U> {
//! Maps a `some` value by reference from one type to another
match *opt { Some(ref x) => Some(f(x)), None => None }
Expand Down Expand Up @@ -256,8 +256,10 @@ pub fn get_or_default<T:Copy>(opt: Option<T>, def: T) -> T {
}
#[inline(always)]
pub fn map_default<T, U>(opt: &'r Option<T>, def: U,
f: &fn(&'r T) -> U) -> U {
pub fn map_default<'r, T, U>(opt: &'r Option<T>,
def: U,
f: &fn(&'r T) -> U)
-> U {
//! Applies a function to the contained value or returns a default
match *opt { None => def, Some(ref t) => f(t) }
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>)
let p = unsafe { &*p_ };
#[unsafe_destructor]
struct DropState {
struct DropState<'self> {
p: &'self PacketHeader,
drop {
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pub fn to_uint<T>(thing: &T) -> uint {

/// Determine if two borrowed pointers point to the same thing.
#[inline(always)]
pub fn ref_eq<T>(thing: &'a T, other: &'b T) -> bool {
pub fn ref_eq<'a,'b,T>(thing: &'a T, other: &'b T) -> bool {
to_uint(thing) == to_uint(other)
}

Expand Down Expand Up @@ -312,7 +312,7 @@ impl<T> Ord for *const T {
// Equality for region pointers
#[cfg(notest)]
impl<T:Eq> Eq for &'self const T {
impl<'self,T:Eq> Eq for &'self const T {
#[inline(always)]
fn eq(&self, other: & &'self const T) -> bool {
return *(*self) == *(*other);
Expand All @@ -325,7 +325,7 @@ impl<T:Eq> Eq for &'self const T {
// Comparison for region pointers
#[cfg(notest)]
impl<T:Ord> Ord for &'self const T {
impl<'self,T:Ord> Ord for &'self const T {
#[inline(always)]
fn lt(&self, other: & &'self const T) -> bool {
*(*self) < *(*other)
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn get<T:Copy,U>(res: &Result<T, U>) -> T {
* If the result is an error
*/
#[inline(always)]
pub fn get_ref<T, U>(res: &'a Result<T, U>) -> &'a T {
pub fn get_ref<'a, T, U>(res: &'a Result<T, U>) -> &'a T {
match *res {
Ok(ref t) => t,
Err(ref the_err) => unsafe {
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/rt/uv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ pub fn install_watcher_data<H, W: Watcher + NativeHandle<*H>>(watcher: &mut W) {
}
}
pub fn get_watcher_data<H, W: Watcher + NativeHandle<*H>>(
pub fn get_watcher_data<'r, H, W: Watcher + NativeHandle<*H>>(
watcher: &'r mut W) -> &'r mut WatcherData {
unsafe {
Expand Down
Loading

3 comments on commit b8621cf

@bors
Copy link
Contributor

@bors bors commented on b8621cf Mar 27, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at pcwalton@b8621cf

@bors
Copy link
Contributor

@bors bors commented on b8621cf Mar 27, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pcwalton/rust/lifetime-binders = b8621cf into auto

@bors
Copy link
Contributor

@bors bors commented on b8621cf Mar 27, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pcwalton/rust/lifetime-binders = b8621cf into auto failed

Please sign in to comment.