Merge remote-tracking branch 'remotes/origin/incoming' into incoming
This commit is contained in:
commit
85fecd0ba7
@ -2304,11 +2304,10 @@ mod farm {
|
||||
farmer: Human
|
||||
}
|
||||
|
||||
// Note - visibility modifiers on impls currently have no effect
|
||||
impl Farm {
|
||||
priv fn feed_chickens(&self) { ... }
|
||||
priv fn feed_cows(&self) { ... }
|
||||
fn add_chicken(&self, c: Chicken) { ... }
|
||||
pub fn add_chicken(&self, c: Chicken) { ... }
|
||||
}
|
||||
|
||||
pub fn feed_animals(farm: &Farm) {
|
||||
|
11
src/etc/gedit/readme.txt
Normal file
11
src/etc/gedit/readme.txt
Normal file
@ -0,0 +1,11 @@
|
||||
Add syntax highlighting for Mozilla Rust in GtkSourceView (used by GEdit).
|
||||
|
||||
|
||||
Instructions for Ubuntu Linux 12.04+
|
||||
|
||||
1) Close all instances of GEdit
|
||||
|
||||
2) Copy the included "share" folder into "~/.local/"
|
||||
|
||||
3) Open a shell in "~/.local/share/" and run "update-mime-database mime"
|
||||
|
264
src/etc/gedit/share/gtksourceview-3.0/language-specs/rust.lang
Normal file
264
src/etc/gedit/share/gtksourceview-3.0/language-specs/rust.lang
Normal file
@ -0,0 +1,264 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!-- Syntax highlighting for the under-development Mozilla Rust language -->
|
||||
|
||||
<language id="rust" _name="Rust" version="2.0" _section="Sources">
|
||||
<metadata>
|
||||
<property name="mimetypes">text/x-rust</property>
|
||||
<property name="globs">*.rs;*.rc</property>
|
||||
<property name="line-comment-start">//</property>
|
||||
<property name="block-comment-start">/*</property>
|
||||
<property name="block-comment-end">*/</property>
|
||||
</metadata>
|
||||
|
||||
<styles>
|
||||
<style id="comment" _name="Comment" map-to="def:comment"/>
|
||||
<style id="string" _name="String" map-to="def:string"/>
|
||||
<style id="char" _name="Character" map-to="def:character"/>
|
||||
<style id="keyword" _name="Keyword" map-to="def:keyword"/>
|
||||
<style id="type" _name="Data Type" map-to="def:type"/>
|
||||
<style id="constant" _name="Constant" map-to="def:constant"/>
|
||||
<style id="identifier" _name="Identifier" map-to="def:identifier"/>
|
||||
<style id="number" _name="Number" map-to="def:decimal"/>
|
||||
<style id="scope" _name="Scope" map-to="def:preprocessor"/>
|
||||
</styles>
|
||||
|
||||
<definitions>
|
||||
|
||||
<context id="function" style-ref="keyword">
|
||||
<keyword>fn</keyword>
|
||||
</context>
|
||||
|
||||
<context id="type" style-ref="keyword">
|
||||
<keyword>type</keyword>
|
||||
</context>
|
||||
|
||||
<context id="keywords" style-ref="keyword">
|
||||
<keyword>as</keyword>
|
||||
<keyword>assert</keyword>
|
||||
<keyword>break</keyword>
|
||||
<keyword>const</keyword>
|
||||
<keyword>copy</keyword>
|
||||
<keyword>do</keyword>
|
||||
<keyword>drop</keyword>
|
||||
<keyword>else</keyword>
|
||||
<keyword>enum</keyword>
|
||||
<keyword>export</keyword>
|
||||
<keyword>extern</keyword>
|
||||
<keyword>fail</keyword>
|
||||
<keyword>for</keyword>
|
||||
<keyword>if</keyword>
|
||||
<keyword>impl</keyword>
|
||||
<keyword>let</keyword>
|
||||
<keyword>log</keyword>
|
||||
<keyword>loop</keyword>
|
||||
<keyword>match</keyword>
|
||||
<keyword>mod</keyword>
|
||||
<keyword>move</keyword>
|
||||
<keyword>mut</keyword>
|
||||
<keyword>priv</keyword>
|
||||
<keyword>pub</keyword>
|
||||
<keyword>pure</keyword>
|
||||
<keyword>ref</keyword>
|
||||
<keyword>return</keyword>
|
||||
<keyword>static</keyword>
|
||||
<keyword>struct</keyword>
|
||||
<keyword>trait</keyword>
|
||||
<keyword>unsafe</keyword>
|
||||
<keyword>use</keyword>
|
||||
<keyword>while</keyword>
|
||||
</context>
|
||||
|
||||
<context id="types" style-ref="type">
|
||||
<keyword>bool</keyword>
|
||||
<keyword>int</keyword>
|
||||
<keyword>uint</keyword>
|
||||
<keyword>i8</keyword>
|
||||
<keyword>i16</keyword>
|
||||
<keyword>i32</keyword>
|
||||
<keyword>i64</keyword>
|
||||
<keyword>u8</keyword>
|
||||
<keyword>u16</keyword>
|
||||
<keyword>u32</keyword>
|
||||
<keyword>u64</keyword>
|
||||
<keyword>f32</keyword>
|
||||
<keyword>f64</keyword>
|
||||
<keyword>float</keyword>
|
||||
<keyword>char</keyword>
|
||||
<keyword>str</keyword>
|
||||
<keyword>Either</keyword>
|
||||
<keyword>Option</keyword>
|
||||
<keyword>Result</keyword>
|
||||
</context>
|
||||
|
||||
<context id="ctypes" style-ref="type">
|
||||
<keyword>c_float</keyword>
|
||||
<keyword>c_double</keyword>
|
||||
<keyword>c_void</keyword>
|
||||
<keyword>FILE</keyword>
|
||||
<keyword>fpos_t</keyword>
|
||||
<keyword>DIR</keyword>
|
||||
<keyword>dirent</keyword>
|
||||
<keyword>c_char</keyword>
|
||||
<keyword>c_schar</keyword>
|
||||
<keyword>c_uchar</keyword>
|
||||
<keyword>c_short</keyword>
|
||||
<keyword>c_ushort</keyword>
|
||||
<keyword>c_int</keyword>
|
||||
<keyword>c_uint</keyword>
|
||||
<keyword>c_long</keyword>
|
||||
<keyword>c_ulong</keyword>
|
||||
<keyword>size_t</keyword>
|
||||
<keyword>ptrdiff_t</keyword>
|
||||
<keyword>clock_t</keyword>
|
||||
<keyword>time_t</keyword>
|
||||
<keyword>c_longlong</keyword>
|
||||
<keyword>c_ulonglong</keyword>
|
||||
<keyword>intptr_t</keyword>
|
||||
<keyword>uintptr_t</keyword>
|
||||
<keyword>off_t</keyword>
|
||||
<keyword>dev_t</keyword>
|
||||
<keyword>ino_t</keyword>
|
||||
<keyword>pid_t</keyword>
|
||||
<keyword>mode_t</keyword>
|
||||
<keyword>ssize_t</keyword>
|
||||
</context>
|
||||
|
||||
<context id="self" style-ref="identifier">
|
||||
<keyword>self</keyword>
|
||||
</context>
|
||||
|
||||
<context id="constants" style-ref="constant">
|
||||
<keyword>true</keyword>
|
||||
<keyword>false</keyword>
|
||||
<keyword>Some</keyword>
|
||||
<keyword>None</keyword>
|
||||
<keyword>Left</keyword>
|
||||
<keyword>Right</keyword>
|
||||
<keyword>Ok</keyword>
|
||||
<keyword>Err</keyword>
|
||||
<keyword>Success</keyword>
|
||||
<keyword>Failure</keyword>
|
||||
<keyword>Cons</keyword>
|
||||
<keyword>Nil</keyword>
|
||||
</context>
|
||||
|
||||
<context id="cconstants" style-ref="constant">
|
||||
<keyword>EXIT_FAILURE</keyword>
|
||||
<keyword>EXIT_SUCCESS</keyword>
|
||||
<keyword>RAND_MAX</keyword>
|
||||
<keyword>EOF</keyword>
|
||||
<keyword>SEEK_SET</keyword>
|
||||
<keyword>SEEK_CUR</keyword>
|
||||
<keyword>SEEK_END</keyword>
|
||||
<keyword>_IOFBF</keyword>
|
||||
<keyword>_IONBF</keyword>
|
||||
<keyword>_IOLBF</keyword>
|
||||
<keyword>BUFSIZ</keyword>
|
||||
<keyword>FOPEN_MAX</keyword>
|
||||
<keyword>FILENAME_MAX</keyword>
|
||||
<keyword>L_tmpnam</keyword>
|
||||
<keyword>TMP_MAX</keyword>
|
||||
<keyword>O_RDONLY</keyword>
|
||||
<keyword>O_WRONLY</keyword>
|
||||
<keyword>O_RDWR</keyword>
|
||||
<keyword>O_APPEND</keyword>
|
||||
<keyword>O_CREAT</keyword>
|
||||
<keyword>O_EXCL</keyword>
|
||||
<keyword>O_TRUNC</keyword>
|
||||
<keyword>S_IFIFO</keyword>
|
||||
<keyword>S_IFCHR</keyword>
|
||||
<keyword>S_IFBLK</keyword>
|
||||
<keyword>S_IFDIR</keyword>
|
||||
<keyword>S_IFREG</keyword>
|
||||
<keyword>S_IFMT</keyword>
|
||||
<keyword>S_IEXEC</keyword>
|
||||
<keyword>S_IWRITE</keyword>
|
||||
<keyword>S_IREAD</keyword>
|
||||
<keyword>S_IRWXU</keyword>
|
||||
<keyword>S_IXUSR</keyword>
|
||||
<keyword>S_IWUSR</keyword>
|
||||
<keyword>S_IRUSR</keyword>
|
||||
<keyword>F_OK</keyword>
|
||||
<keyword>R_OK</keyword>
|
||||
<keyword>W_OK</keyword>
|
||||
<keyword>X_OK</keyword>
|
||||
<keyword>STDIN_FILENO</keyword>
|
||||
<keyword>STDOUT_FILENO</keyword>
|
||||
<keyword>STDERR_FILENO</keyword>
|
||||
</context>
|
||||
|
||||
<context id="line-comment" style-ref="comment" end-at-line-end="true" class="comment" class-disabled="no-spell-check">
|
||||
<start>//</start>
|
||||
<include>
|
||||
<context ref="def:in-line-comment"/>
|
||||
</include>
|
||||
</context>
|
||||
|
||||
<context id="block-comment" style-ref="comment" class="comment" class-disabled="no-spell-check">
|
||||
<start>/\*</start>
|
||||
<end>\*/</end>
|
||||
<include>
|
||||
<context ref="def:in-comment"/>
|
||||
</include>
|
||||
</context>
|
||||
|
||||
<context id="number" style-ref="number">
|
||||
<match extended="true">
|
||||
(?<![\w\.])
|
||||
(
|
||||
0x[0-9a-fA-F_]+(u8|u16|u32|u64|i8|i16|i32|i64|u|i)?|
|
||||
0b[0-1_]+(u8|u16|u32|u64|i8|i16|i32|i64|u|i)?|
|
||||
[0-9][0-9_]*\.[0-9_]*([eE][+-]?[0-9_]+)?(f32|f64|f)?|
|
||||
[0-9][0-9_]*(u8|u16|u32|u64|i8|i16|i32|i64|u|i)?
|
||||
)
|
||||
(?![\w\.])
|
||||
</match>
|
||||
</context>
|
||||
|
||||
<context id="scope" style-ref="scope">
|
||||
<match extended="true">
|
||||
[a-zA-Z_][a-zA-Z0-9_]*::
|
||||
</match>
|
||||
</context>
|
||||
|
||||
<context id="string" style-ref="string" class="string" class-disabled="no-spell-check">
|
||||
<start>"</start>
|
||||
<end>"</end>
|
||||
<include>
|
||||
<context ref="def:escape"/>
|
||||
<context ref="def:line-continue"/>
|
||||
</include>
|
||||
</context>
|
||||
|
||||
<context id="char" style-ref="char" end-at-line-end="true" class="char" class-disabled="no-spell-check">
|
||||
<start>'</start>
|
||||
<end>'</end>
|
||||
<include>
|
||||
<context ref="def:escape"/>
|
||||
</include>
|
||||
</context>
|
||||
|
||||
<context id="rust" class="no-spell-check">
|
||||
<include>
|
||||
<context ref="function"/>
|
||||
<context ref="type"/>
|
||||
<context ref="keywords"/>
|
||||
<context ref="types"/>
|
||||
<context ref="ctypes"/>
|
||||
<context ref="self"/>
|
||||
<context ref="constants"/>
|
||||
<context ref="cconstants"/>
|
||||
<context ref="line-comment"/>
|
||||
<context ref="block-comment"/>
|
||||
<context ref="number"/>
|
||||
<context ref="scope"/>
|
||||
<context ref="string"/>
|
||||
<context ref="char"/>
|
||||
</include>
|
||||
</context>
|
||||
|
||||
</definitions>
|
||||
|
||||
</language>
|
||||
|
7
src/etc/gedit/share/mime/packages/rust.xml
Normal file
7
src/etc/gedit/share/mime/packages/rust.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
|
||||
<mime-type type="text/x-rust">
|
||||
<comment>Rust Source</comment>
|
||||
<glob pattern="*.rs"/>
|
||||
<glob pattern="*.rc"/>
|
||||
</mime-type>
|
||||
</mime-info>
|
@ -28,7 +28,7 @@ pub pure fn empty_cell<T>() -> Cell<T> {
|
||||
Cell { value: None }
|
||||
}
|
||||
|
||||
impl<T> Cell<T> {
|
||||
pub impl<T> Cell<T> {
|
||||
/// Yields the value, failing if the cell is empty.
|
||||
fn take() -> T {
|
||||
if self.is_empty() {
|
||||
|
@ -8,9 +8,6 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Transitional -- needs snapshot
|
||||
#[allow(structural_records)];
|
||||
|
||||
use either::{Either, Left, Right};
|
||||
use kinds::Owned;
|
||||
use option;
|
||||
@ -190,7 +187,7 @@ pub fn PortSet<T: Owned>() -> PortSet<T>{
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Owned> PortSet<T> {
|
||||
pub impl<T: Owned> PortSet<T> {
|
||||
|
||||
fn add(port: Port<T>) {
|
||||
self.ports.push(port)
|
||||
@ -323,12 +320,12 @@ pub fn oneshot<T: Owned>() -> (PortOne<T>, ChanOne<T>) {
|
||||
(port, chan)
|
||||
}
|
||||
|
||||
impl<T: Owned> PortOne<T> {
|
||||
pub impl<T: Owned> PortOne<T> {
|
||||
fn recv(self) -> T { recv_one(self) }
|
||||
fn try_recv(self) -> Option<T> { try_recv_one(self) }
|
||||
}
|
||||
|
||||
impl<T: Owned> ChanOne<T> {
|
||||
pub impl<T: Owned> ChanOne<T> {
|
||||
fn send(self, data: T) { send_one(self, data) }
|
||||
fn try_send(self, data: T) -> bool { try_send_one(self, data) }
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ pub struct Condition<T, U> {
|
||||
key: task::local_data::LocalDataKey<Handler<T, U>>
|
||||
}
|
||||
|
||||
impl<T, U> Condition<T, U> {
|
||||
pub impl<T, U> Condition<T, U> {
|
||||
fn trap(&self, h: &self/fn(T) -> U) -> Trap/&self<T, U> {
|
||||
unsafe {
|
||||
let p : *RustClosure = ::cast::transmute(&h);
|
||||
@ -69,7 +69,7 @@ struct Trap<T, U> {
|
||||
handler: @Handler<T, U>
|
||||
}
|
||||
|
||||
impl<T, U> Trap<T, U> {
|
||||
pub impl<T, U> Trap<T, U> {
|
||||
fn in<V>(&self, inner: &self/fn() -> V) -> V {
|
||||
unsafe {
|
||||
let _g = Guard { cond: self.cond };
|
||||
|
@ -227,10 +227,6 @@ pub const debug : u32 = 4_u32;
|
||||
|
||||
// The runtime interface used by the compiler
|
||||
#[cfg(notest)] pub mod rt;
|
||||
// The runtime and compiler interface to fmt!
|
||||
#[cfg(stage0)]
|
||||
#[path = "private/extfmt.rs"]
|
||||
pub mod extfmt;
|
||||
// Private APIs
|
||||
pub mod private;
|
||||
|
||||
|
@ -62,7 +62,7 @@ priv impl<T> DListNode<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> DListNode<T> {
|
||||
pub impl<T> DListNode<T> {
|
||||
/// Get the next node in the list, if there is one.
|
||||
pure fn next_link(@mut self) -> DListLink<T> {
|
||||
self.assert_links();
|
||||
@ -208,7 +208,7 @@ priv impl<T> DList<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> DList<T> {
|
||||
pub impl<T> DList<T> {
|
||||
/// Get the size of the list. O(1).
|
||||
pure fn len(@mut self) -> uint { self.size }
|
||||
/// Returns true if the list is empty. O(1).
|
||||
@ -457,7 +457,7 @@ impl<T> DList<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy> DList<T> {
|
||||
pub impl<T:Copy> DList<T> {
|
||||
/// Remove data from the head of the list. O(1).
|
||||
fn pop(@mut self) -> Option<T> {
|
||||
self.pop_n().map(|nobe| nobe.data)
|
||||
|
@ -92,17 +92,6 @@ priv impl<A> DVec<A> {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn check_out<B>(f: &fn(v: ~[A]) -> B) -> B {
|
||||
unsafe {
|
||||
let mut data = cast::reinterpret_cast(&null::<()>());
|
||||
data <-> self.data;
|
||||
let data_ptr: *() = cast::reinterpret_cast(&data);
|
||||
if data_ptr.is_null() { fail!(~"Recursive use of dvec"); }
|
||||
return f(data);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn give_back(data: ~[A]) {
|
||||
unsafe {
|
||||
@ -117,7 +106,19 @@ priv impl<A> DVec<A> {
|
||||
// In theory, most everything should work with any A, but in practice
|
||||
// almost nothing works without the copy bound due to limitations
|
||||
// around closures.
|
||||
impl<A> DVec<A> {
|
||||
pub impl<A> DVec<A> {
|
||||
// FIXME (#3758): This should not need to be public.
|
||||
#[inline(always)]
|
||||
fn check_out<B>(f: &fn(v: ~[A]) -> B) -> B {
|
||||
unsafe {
|
||||
let mut data = cast::reinterpret_cast(&null::<()>());
|
||||
data <-> self.data;
|
||||
let data_ptr: *() = cast::reinterpret_cast(&data);
|
||||
if data_ptr.is_null() { fail!(~"Recursive use of dvec"); }
|
||||
return f(data);
|
||||
}
|
||||
}
|
||||
|
||||
/// Reserves space for N elements
|
||||
fn reserve(count: uint) {
|
||||
vec::reserve(&mut self.data, count)
|
||||
@ -215,7 +216,7 @@ impl<A> DVec<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<A:Copy> DVec<A> {
|
||||
pub impl<A:Copy> DVec<A> {
|
||||
/**
|
||||
* Append all elements of a vector to the end of the list
|
||||
*
|
||||
|
@ -10,14 +10,12 @@
|
||||
|
||||
//! Sendable hash maps.
|
||||
|
||||
use container::{Container, Mutable, Map, Set};
|
||||
use cmp::Eq;
|
||||
use hash::Hash;
|
||||
use to_bytes::IterBytes;
|
||||
|
||||
/// Open addressing with linear probing.
|
||||
pub mod linear {
|
||||
use super::*;
|
||||
use container::{Container, Mutable, Map, Set};
|
||||
use cmp::Eq;
|
||||
use hash::Hash;
|
||||
use to_bytes::IterBytes;
|
||||
use iter::BaseIter;
|
||||
use hash::Hash;
|
||||
use iter;
|
||||
@ -752,7 +750,8 @@ mod test_map {
|
||||
|
||||
#[test]
|
||||
mod test_set {
|
||||
use super::*;
|
||||
use hashmap::linear;
|
||||
use container::{Container, Mutable, Map, Set};
|
||||
use vec;
|
||||
|
||||
#[test]
|
||||
|
@ -504,7 +504,7 @@ pub fn FILE_reader(f: *libc::FILE, cleanup: bool) -> @Reader {
|
||||
|
||||
pub fn stdin() -> @Reader {
|
||||
unsafe {
|
||||
rustrt::rust_get_stdin() as @Reader
|
||||
@rustrt::rust_get_stdin() as @Reader
|
||||
}
|
||||
}
|
||||
|
||||
@ -642,11 +642,11 @@ impl Writer for *libc::FILE {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn FILE_writer(f: *libc::FILE, cleanup: bool) -> Writer {
|
||||
pub fn FILE_writer(f: *libc::FILE, cleanup: bool) -> @Writer {
|
||||
if cleanup {
|
||||
Wrapper { base: f, cleanup: FILERes(f) } as Writer
|
||||
@Wrapper { base: f, cleanup: FILERes(f) } as @Writer
|
||||
} else {
|
||||
f as Writer
|
||||
@f as @Writer
|
||||
}
|
||||
}
|
||||
|
||||
@ -702,11 +702,11 @@ pub fn FdRes(fd: fd_t) -> FdRes {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fd_writer(fd: fd_t, cleanup: bool) -> Writer {
|
||||
pub fn fd_writer(fd: fd_t, cleanup: bool) -> @Writer {
|
||||
if cleanup {
|
||||
Wrapper { base: fd, cleanup: FdRes(fd) } as Writer
|
||||
@Wrapper { base: fd, cleanup: FdRes(fd) } as @Writer
|
||||
} else {
|
||||
fd as Writer
|
||||
@fd as @Writer
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ pub fn unwrap<T>(m: Mut<T>) -> T {
|
||||
value
|
||||
}
|
||||
|
||||
impl<T> Data<T> {
|
||||
pub impl<T> Data<T> {
|
||||
fn borrow_mut<R>(op: &fn(t: &mut T) -> R) -> R {
|
||||
match self.mode {
|
||||
Immutable => fail!(fmt!("%? currently immutable",
|
||||
|
@ -281,7 +281,7 @@ pub pure fn expect<T>(opt: Option<T>, reason: &str) -> T {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Option<T> {
|
||||
pub impl<T> Option<T> {
|
||||
/// Returns true if the option equals `none`
|
||||
#[inline(always)]
|
||||
pure fn is_none(&self) -> bool { is_none(self) }
|
||||
@ -393,7 +393,7 @@ impl<T> Option<T> {
|
||||
pure fn expect(self, reason: &str) -> T { expect(self, reason) }
|
||||
}
|
||||
|
||||
impl<T:Copy> Option<T> {
|
||||
pub impl<T:Copy> Option<T> {
|
||||
/**
|
||||
Gets the value out of an option
|
||||
|
||||
@ -421,7 +421,7 @@ impl<T:Copy> Option<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Zero> Option<T> {
|
||||
pub impl<T:Copy + Zero> Option<T> {
|
||||
#[inline(always)]
|
||||
pure fn get_or_zero(self) -> T { get_or_zero(self) }
|
||||
}
|
||||
|
@ -1021,10 +1021,10 @@ extern {
|
||||
pub mod consts {
|
||||
|
||||
#[cfg(unix)]
|
||||
use os::consts::unix::*;
|
||||
pub use os::consts::unix::*;
|
||||
|
||||
#[cfg(windows)]
|
||||
use os::consts::windows::*;
|
||||
pub use os::consts::windows::*;
|
||||
|
||||
pub mod unix {
|
||||
pub const FAMILY: &str = "unix";
|
||||
@ -1035,19 +1035,19 @@ pub mod consts {
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
use os::consts::macos::*;
|
||||
pub use os::consts::macos::*;
|
||||
|
||||
#[cfg(target_os = "freebsd")]
|
||||
use os::consts::freebsd::*;
|
||||
pub use os::consts::freebsd::*;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
use os::consts::linux::*;
|
||||
pub use os::consts::linux::*;
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
use os::consts::android::*;
|
||||
pub use os::consts::android::*;
|
||||
|
||||
#[cfg(target_os = "win32")]
|
||||
use os::consts::win32::*;
|
||||
pub use os::consts::win32::*;
|
||||
|
||||
pub mod macos {
|
||||
pub const SYSNAME: &str = "macos";
|
||||
@ -1086,13 +1086,13 @@ pub mod consts {
|
||||
|
||||
|
||||
#[cfg(target_arch = "x86")]
|
||||
use os::consts::x86::*;
|
||||
pub use os::consts::x86::*;
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use os::consts::x86_64::*;
|
||||
pub use os::consts::x86_64::*;
|
||||
|
||||
#[cfg(target_arch = "arm")]
|
||||
use os::consts::arm::*;
|
||||
pub use os::consts::arm::*;
|
||||
|
||||
pub mod x86 {
|
||||
pub const ARCH: &str = "x86";
|
||||
|
@ -241,7 +241,7 @@ mod stat {
|
||||
}
|
||||
|
||||
|
||||
impl Path {
|
||||
pub impl Path {
|
||||
fn stat(&self) -> Option<libc::stat> {
|
||||
unsafe {
|
||||
do str::as_c_str(self.to_str()) |buf| {
|
||||
@ -290,7 +290,7 @@ impl Path {
|
||||
#[cfg(target_os = "freebsd")]
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(target_os = "macos")]
|
||||
impl Path {
|
||||
pub impl Path {
|
||||
fn get_atime(&self) -> Option<(i64, int)> {
|
||||
match self.stat() {
|
||||
None => None,
|
||||
@ -324,7 +324,7 @@ impl Path {
|
||||
|
||||
#[cfg(target_os = "freebsd")]
|
||||
#[cfg(target_os = "macos")]
|
||||
impl Path {
|
||||
pub impl Path {
|
||||
fn get_birthtime(&self) -> Option<(i64, int)> {
|
||||
match self.stat() {
|
||||
None => None,
|
||||
@ -337,7 +337,7 @@ impl Path {
|
||||
}
|
||||
|
||||
#[cfg(target_os = "win32")]
|
||||
impl Path {
|
||||
pub impl Path {
|
||||
fn get_atime(&self) -> Option<(i64, int)> {
|
||||
match self.stat() {
|
||||
None => None,
|
||||
|
@ -82,8 +82,6 @@ bounded and unbounded protocols allows for less code duplication.
|
||||
|
||||
*/
|
||||
|
||||
#[allow(structural_records)]; // Macros -- needs another snapshot
|
||||
|
||||
use cmp::Eq;
|
||||
use cast::{forget, reinterpret_cast, transmute};
|
||||
use cell::Cell;
|
||||
@ -800,7 +798,7 @@ pub fn SendPacketBuffered<T,Tbuffer>(p: *Packet<T>)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T,Tbuffer> SendPacketBuffered<T,Tbuffer> {
|
||||
pub impl<T,Tbuffer> SendPacketBuffered<T,Tbuffer> {
|
||||
fn unwrap() -> *Packet<T> {
|
||||
let mut p = None;
|
||||
p <-> self.p;
|
||||
@ -857,7 +855,7 @@ impl<T:Owned,Tbuffer:Owned> ::ops::Drop for RecvPacketBuffered<T,Tbuffer> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Owned,Tbuffer:Owned> RecvPacketBuffered<T, Tbuffer> {
|
||||
pub impl<T:Owned,Tbuffer:Owned> RecvPacketBuffered<T, Tbuffer> {
|
||||
fn unwrap() -> *Packet<T> {
|
||||
let mut p = None;
|
||||
p <-> self.p;
|
||||
|
@ -107,20 +107,9 @@ fn compare_and_swap(address: &mut int, oldval: int, newval: int) -> bool {
|
||||
* Shared state & exclusive ARC
|
||||
****************************************************************************/
|
||||
|
||||
struct UnwrapProtoInner {
|
||||
contents: Option<(comm::ChanOne<()>, comm::PortOne<bool>)>,
|
||||
}
|
||||
|
||||
// An unwrapper uses this protocol to communicate with the "other" task that
|
||||
// drops the last refcount on an arc. Unfortunately this can't be a proper
|
||||
// pipe protocol because the unwrapper has to access both stages at once.
|
||||
type UnwrapProto = ~UnwrapProtoInner;
|
||||
|
||||
struct ArcData<T> {
|
||||
mut count: libc::intptr_t,
|
||||
mut unwrapper: int, // either a UnwrapProto or 0
|
||||
// FIXME(#3224) should be able to make this non-option to save memory, and
|
||||
// in unwrap() use "let ~ArcData { data: result, _ } = thing" to unwrap it
|
||||
// FIXME(#3224) should be able to make this non-option to save memory
|
||||
mut data: Option<T>,
|
||||
}
|
||||
|
||||
@ -131,37 +120,13 @@ struct ArcDestruct<T> {
|
||||
impl<T> Drop for ArcDestruct<T>{
|
||||
fn finalize(&self) {
|
||||
unsafe {
|
||||
if self.data.is_null() {
|
||||
return; // Happens when destructing an unwrapper's handle.
|
||||
}
|
||||
do task::unkillable {
|
||||
let data: ~ArcData<T> = cast::reinterpret_cast(&self.data);
|
||||
let new_count =
|
||||
intrinsics::atomic_xsub(&mut data.count, 1) - 1;
|
||||
assert new_count >= 0;
|
||||
if new_count == 0 {
|
||||
// Were we really last, or should we hand off to an
|
||||
// unwrapper? It's safe to not xchg because the unwrapper
|
||||
// will set the unwrap lock *before* dropping his/her
|
||||
// reference. In effect, being here means we're the only
|
||||
// *awake* task with the data.
|
||||
if data.unwrapper != 0 {
|
||||
let mut p: UnwrapProto =
|
||||
cast::reinterpret_cast(&data.unwrapper);
|
||||
let (message, response) =
|
||||
option::swap_unwrap(&mut p.contents);
|
||||
// Send 'ready' and wait for a response.
|
||||
comm::send_one(message, ());
|
||||
// Unkillable wait. Message guaranteed to come.
|
||||
if comm::recv_one(response) {
|
||||
// Other task got the data.
|
||||
cast::forget(data);
|
||||
} else {
|
||||
// Other task was killed. drop glue takes over.
|
||||
}
|
||||
} else {
|
||||
// drop glue takes over.
|
||||
}
|
||||
// drop glue takes over.
|
||||
} else {
|
||||
cast::forget(data);
|
||||
}
|
||||
@ -176,79 +141,6 @@ fn ArcDestruct<T>(data: *libc::c_void) -> ArcDestruct<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn unwrap_shared_mutable_state<T:Owned>(rc: SharedMutableState<T>)
|
||||
-> T {
|
||||
struct DeathThroes<T> {
|
||||
mut ptr: Option<~ArcData<T>>,
|
||||
mut response: Option<comm::ChanOne<bool>>,
|
||||
}
|
||||
|
||||
impl<T> Drop for DeathThroes<T>{
|
||||
fn finalize(&self) {
|
||||
unsafe {
|
||||
let response = option::swap_unwrap(&mut self.response);
|
||||
// In case we get killed early, we need to tell the person who
|
||||
// tried to wake us whether they should hand-off the data to
|
||||
// us.
|
||||
if task::failing() {
|
||||
comm::send_one(response, false);
|
||||
// Either this swap_unwrap or the one below (at "Got
|
||||
// here") ought to run.
|
||||
cast::forget(option::swap_unwrap(&mut self.ptr));
|
||||
} else {
|
||||
assert self.ptr.is_none();
|
||||
comm::send_one(response, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
do task::unkillable {
|
||||
let ptr: ~ArcData<T> = cast::reinterpret_cast(&rc.data);
|
||||
let (p1,c1) = comm::oneshot(); // ()
|
||||
let (p2,c2) = comm::oneshot(); // bool
|
||||
let mut server: UnwrapProto = ~UnwrapProtoInner {
|
||||
contents: Some((c1,p2))
|
||||
};
|
||||
let serverp: int = cast::transmute(server);
|
||||
// Try to put our server end in the unwrapper slot.
|
||||
if compare_and_swap(&mut ptr.unwrapper, 0, serverp) {
|
||||
// Got in. Step 0: Tell destructor not to run. We are now it.
|
||||
rc.data = ptr::null();
|
||||
// Step 1 - drop our own reference.
|
||||
let new_count = intrinsics::atomic_xsub(&mut ptr.count, 1) - 1;
|
||||
//assert new_count >= 0;
|
||||
if new_count == 0 {
|
||||
// We were the last owner. Can unwrap immediately.
|
||||
// Also we have to free the server endpoints.
|
||||
let _server: UnwrapProto = cast::transmute(serverp);
|
||||
option::swap_unwrap(&mut ptr.data)
|
||||
// drop glue takes over.
|
||||
} else {
|
||||
// The *next* person who sees the refcount hit 0 will wake us.
|
||||
let end_result =
|
||||
DeathThroes { ptr: Some(ptr),
|
||||
response: Some(c2) };
|
||||
let mut p1 = Some(p1); // argh
|
||||
do task::rekillable {
|
||||
comm::recv_one(option::swap_unwrap(&mut p1));
|
||||
}
|
||||
// Got here. Back in the 'unkillable' without getting killed.
|
||||
// Recover ownership of ptr, then take the data out.
|
||||
let ptr = option::swap_unwrap(&mut end_result.ptr);
|
||||
option::swap_unwrap(&mut ptr.data)
|
||||
// drop glue takes over.
|
||||
}
|
||||
} else {
|
||||
// Somebody else was trying to unwrap. Avoid guaranteed deadlock.
|
||||
cast::forget(ptr);
|
||||
// Also we have to free the (rejected) server endpoints.
|
||||
let _server: UnwrapProto = cast::transmute(serverp);
|
||||
fail!(~"Another task is already unwrapping this ARC!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* COMPLETELY UNSAFE. Used as a primitive for the safe versions in std::arc.
|
||||
*
|
||||
@ -259,7 +151,7 @@ pub type SharedMutableState<T> = ArcDestruct<T>;
|
||||
|
||||
pub unsafe fn shared_mutable_state<T:Owned>(data: T) ->
|
||||
SharedMutableState<T> {
|
||||
let data = ~ArcData { count: 1, unwrapper: 0, data: Some(data) };
|
||||
let data = ~ArcData { count: 1, data: Some(data) };
|
||||
unsafe {
|
||||
let ptr = cast::transmute(data);
|
||||
ArcDestruct(ptr)
|
||||
@ -335,7 +227,7 @@ fn LittleLock() -> LittleLock {
|
||||
}
|
||||
}
|
||||
|
||||
impl LittleLock {
|
||||
pub impl LittleLock {
|
||||
#[inline(always)]
|
||||
unsafe fn lock<T>(f: fn() -> T) -> T {
|
||||
struct Unlock {
|
||||
@ -381,7 +273,7 @@ impl<T:Owned> Clone for Exclusive<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Owned> Exclusive<T> {
|
||||
pub impl<T:Owned> Exclusive<T> {
|
||||
// Exactly like std::arc::mutex_arc,access(), but with the little_lock
|
||||
// instead of a proper mutex. Same reason for being unsafe.
|
||||
//
|
||||
@ -413,14 +305,6 @@ impl<T:Owned> Exclusive<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(#3724) make this a by-move method on the exclusive
|
||||
pub fn unwrap_exclusive<T:Owned>(arc: Exclusive<T>) -> T {
|
||||
let Exclusive { x: x } = arc;
|
||||
let inner = unsafe { unwrap_shared_mutable_state(x) };
|
||||
let ExData { data: data, _ } = inner;
|
||||
data
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use core::option::{None, Some};
|
||||
@ -428,7 +312,7 @@ pub mod tests {
|
||||
use cell::Cell;
|
||||
use comm;
|
||||
use option;
|
||||
use private::{exclusive, unwrap_exclusive};
|
||||
use private::exclusive;
|
||||
use result;
|
||||
use task;
|
||||
use uint;
|
||||
@ -479,70 +363,4 @@ pub mod tests {
|
||||
assert *one == 1;
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn exclusive_unwrap_basic() {
|
||||
let x = exclusive(~~"hello");
|
||||
assert unwrap_exclusive(x) == ~~"hello";
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn exclusive_unwrap_contended() {
|
||||
let x = exclusive(~~"hello");
|
||||
let x2 = Cell(x.clone());
|
||||
do task::spawn {
|
||||
let x2 = x2.take();
|
||||
do x2.with |_hello| { }
|
||||
task::yield();
|
||||
}
|
||||
assert unwrap_exclusive(x) == ~~"hello";
|
||||
|
||||
// Now try the same thing, but with the child task blocking.
|
||||
let x = exclusive(~~"hello");
|
||||
let x2 = Cell(x.clone());
|
||||
let mut res = None;
|
||||
do task::task().future_result(|+r| res = Some(r)).spawn {
|
||||
let x2 = x2.take();
|
||||
assert unwrap_exclusive(x2) == ~~"hello";
|
||||
}
|
||||
// Have to get rid of our reference before blocking.
|
||||
{ let _x = x; } // FIXME(#3161) util::ignore doesn't work here
|
||||
let res = option::swap_unwrap(&mut res);
|
||||
res.recv();
|
||||
}
|
||||
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
pub fn exclusive_unwrap_conflict() {
|
||||
let x = exclusive(~~"hello");
|
||||
let x2 = Cell(x.clone());
|
||||
let mut res = None;
|
||||
do task::task().future_result(|+r| res = Some(r)).spawn {
|
||||
let x2 = x2.take();
|
||||
assert unwrap_exclusive(x2) == ~~"hello";
|
||||
}
|
||||
assert unwrap_exclusive(x) == ~~"hello";
|
||||
let res = option::swap_unwrap(&mut res);
|
||||
// See #4689 for why this can't be just "res.recv()".
|
||||
assert res.recv() == task::Success;
|
||||
}
|
||||
|
||||
#[test] #[ignore(cfg(windows))]
|
||||
pub fn exclusive_unwrap_deadlock() {
|
||||
// This is not guaranteed to get to the deadlock before being killed,
|
||||
// but it will show up sometimes, and if the deadlock were not there,
|
||||
// the test would nondeterministically fail.
|
||||
let result = do task::try {
|
||||
// a task that has two references to the same exclusive will
|
||||
// deadlock when it unwraps. nothing to be done about that.
|
||||
let x = exclusive(~~"hello");
|
||||
let x2 = x.clone();
|
||||
do task::spawn {
|
||||
for 10.times { task::yield(); } // try to let the unwrapper go
|
||||
fail!(); // punt it awake from its deadlock
|
||||
}
|
||||
let _z = unwrap_exclusive(x);
|
||||
do x2.with |_hello| { }
|
||||
};
|
||||
assert result.is_err();
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ pub mod ct {
|
||||
next: uint
|
||||
}
|
||||
|
||||
impl<T> Parsed<T> {
|
||||
pub impl<T> Parsed<T> {
|
||||
static pure fn new(val: T, next: uint) -> Parsed<T> {
|
||||
Parsed {val: val, next: next}
|
||||
}
|
||||
|
@ -26,33 +26,10 @@ do || {
|
||||
use ops::Drop;
|
||||
use task::{spawn, failing};
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub trait Finally<T> {
|
||||
fn finally(&self, +dtor: &fn()) -> T;
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
pub trait Finally<T> {
|
||||
fn finally(&self, dtor: &fn()) -> T;
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<T> Finally<T> for &fn() -> T {
|
||||
// FIXME #4518: Should not require a mode here
|
||||
fn finally(&self, +dtor: &fn()) -> T {
|
||||
let _d = Finallyalizer {
|
||||
dtor: dtor
|
||||
};
|
||||
|
||||
(*self)()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
impl<T> Finally<T> for &fn() -> T {
|
||||
fn finally(&self, dtor: &fn()) -> T {
|
||||
let _d = Finallyalizer {
|
||||
|
@ -141,7 +141,7 @@ pub struct Weighted<T> {
|
||||
}
|
||||
|
||||
/// Extension methods for random number generators
|
||||
impl Rng {
|
||||
pub impl Rng {
|
||||
/// Return a random value for a Rand type
|
||||
fn gen<T:Rand>() -> T {
|
||||
Rand::rand(self)
|
||||
@ -412,8 +412,8 @@ pub fn Rng() -> Rng {
|
||||
* all other generators constructed with the same seed. The seed may be any
|
||||
* length.
|
||||
*/
|
||||
pub fn seeded_rng(seed: &[u8]) -> Rng {
|
||||
seeded_randres(seed) as Rng
|
||||
pub fn seeded_rng(seed: &[u8]) -> @Rng {
|
||||
@seeded_randres(seed) as @Rng
|
||||
}
|
||||
|
||||
fn seeded_randres(seed: &[u8]) -> @RandRes {
|
||||
@ -449,8 +449,8 @@ pub pure fn xorshift() -> Rng {
|
||||
seeded_xorshift(123456789u32, 362436069u32, 521288629u32, 88675123u32)
|
||||
}
|
||||
|
||||
pub pure fn seeded_xorshift(x: u32, y: u32, z: u32, w: u32) -> Rng {
|
||||
XorShiftState { x: x, y: y, z: z, w: w } as Rng
|
||||
pub pure fn seeded_xorshift(x: u32, y: u32, z: u32, w: u32) -> @Rng {
|
||||
@XorShiftState { x: x, y: y, z: z, w: w } as @Rng
|
||||
}
|
||||
|
||||
|
||||
@ -472,10 +472,10 @@ pub fn task_rng() -> Rng {
|
||||
unsafe {
|
||||
let rng = seeded_randres(seed());
|
||||
task::local_data::local_data_set(tls_rng_state, rng);
|
||||
rng as Rng
|
||||
@rng as @Rng
|
||||
}
|
||||
}
|
||||
Some(rng) => rng as Rng
|
||||
Some(rng) => @rng as @Rng
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ pub fn MovePtrAdaptor<V:TyVisitor + MovePtr>(v: V) -> MovePtrAdaptor<V> {
|
||||
MovePtrAdaptor { inner: v }
|
||||
}
|
||||
|
||||
impl<V:TyVisitor + MovePtr> MovePtrAdaptor<V> {
|
||||
pub impl<V:TyVisitor + MovePtr> MovePtrAdaptor<V> {
|
||||
#[inline(always)]
|
||||
fn bump(sz: uint) {
|
||||
do self.inner.move_ptr() |p| {
|
||||
|
@ -167,7 +167,7 @@ impl MovePtr for ReprVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
impl ReprVisitor {
|
||||
pub impl ReprVisitor {
|
||||
|
||||
// Various helpers for the TyVisitor impl
|
||||
|
||||
@ -201,7 +201,7 @@ impl ReprVisitor {
|
||||
unsafe {
|
||||
let mut u = ReprVisitor(ptr, self.writer);
|
||||
let v = reflect::MovePtrAdaptor(u);
|
||||
visit_tydesc(inner, (v) as @TyVisitor);
|
||||
visit_tydesc(inner, @v as @TyVisitor);
|
||||
true
|
||||
}
|
||||
}
|
||||
@ -570,7 +570,7 @@ pub fn write_repr<T>(writer: @Writer, object: &T) {
|
||||
let tydesc = intrinsic::get_tydesc::<T>();
|
||||
let mut u = ReprVisitor(ptr, writer);
|
||||
let v = reflect::MovePtrAdaptor(u);
|
||||
visit_tydesc(tydesc, (v) as @TyVisitor)
|
||||
visit_tydesc(tydesc, @v as @TyVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -228,7 +228,7 @@ pub pure fn map_err<T:Copy,E,F:Copy>(res: &Result<T, E>, op: fn(&E) -> F)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, E> Result<T, E> {
|
||||
pub impl<T, E> Result<T, E> {
|
||||
#[inline(always)]
|
||||
pure fn get_ref(&self) -> &self/T { get_ref(self) }
|
||||
|
||||
@ -261,7 +261,7 @@ impl<T, E> Result<T, E> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy,E> Result<T, E> {
|
||||
pub impl<T:Copy,E> Result<T, E> {
|
||||
#[inline(always)]
|
||||
pure fn get(&self) -> T { get(self) }
|
||||
|
||||
@ -271,7 +271,7 @@ impl<T:Copy,E> Result<T, E> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, E: Copy> Result<T, E> {
|
||||
pub impl<T, E: Copy> Result<T, E> {
|
||||
#[inline(always)]
|
||||
pure fn get_err(&self) -> E { get_err(self) }
|
||||
|
||||
|
@ -288,7 +288,7 @@ pub fn start_program(prog: &str, args: &[~str]) -> Program {
|
||||
finished: false,
|
||||
};
|
||||
|
||||
ProgRes(repr) as Program
|
||||
@ProgRes(repr) as @Program
|
||||
}
|
||||
|
||||
fn read_all(rd: io::Reader) -> ~str {
|
||||
|
@ -10,9 +10,6 @@
|
||||
|
||||
#[doc(hidden)]; // FIXME #3538
|
||||
|
||||
#[legacy_modes]; // tjc: remove after snapshot
|
||||
#[allow(deprecated_mode)];
|
||||
|
||||
use cast::reinterpret_cast;
|
||||
use ptr::offset;
|
||||
use sys::size_of;
|
||||
|
@ -2375,6 +2375,7 @@ impl OwnedStr for ~str {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use char;
|
||||
use option::Some;
|
||||
use debug;
|
||||
use libc::c_char;
|
||||
use libc;
|
||||
|
@ -155,7 +155,7 @@ pub unsafe fn local_set<T:Durable>(
|
||||
// does not have a reference associated with it, so it may become invalid
|
||||
// when the box is destroyed.
|
||||
let data_ptr = cast::reinterpret_cast(&data);
|
||||
let data_box = data as LocalData;
|
||||
let data_box = @data as @LocalData;
|
||||
// Construct new entry to store in the map.
|
||||
let new_entry = Some((keyval, data_ptr, data_box));
|
||||
// Find a place to put it.
|
||||
|
@ -232,7 +232,7 @@ priv impl TaskBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
impl TaskBuilder {
|
||||
pub impl TaskBuilder {
|
||||
/**
|
||||
* Decouple the child task's failure from the parent's. If either fails,
|
||||
* the other will not be killed.
|
||||
|
@ -1444,7 +1444,7 @@ pub fn each2<U, T>(v1: &[U], v2: &[T], f: fn(u: &U, t: &T) -> bool) {
|
||||
* The total number of permutations produced is `len(v)!`. If `v` contains
|
||||
* repeated elements, then some permutations are repeated.
|
||||
*/
|
||||
pure fn each_permutation<T:Copy>(v: &[T], put: fn(ts: &[T]) -> bool) {
|
||||
pub pure fn each_permutation<T:Copy>(v: &[T], put: fn(ts: &[T]) -> bool) {
|
||||
let ln = len(v);
|
||||
if ln <= 1 {
|
||||
put(v);
|
||||
@ -2427,6 +2427,7 @@ impl<A:Copy> iter::CopyableNonstrictIter<A> for @[A] {
|
||||
mod tests {
|
||||
use option::{None, Option, Some};
|
||||
use option;
|
||||
use sys;
|
||||
use vec::*;
|
||||
|
||||
fn square(n: uint) -> uint { return n * n; }
|
||||
|
@ -132,9 +132,8 @@ pub enum astencode_tag { // Reserves 0x50 -- 0x6f
|
||||
tag_table_method_map = 0x60,
|
||||
tag_table_vtable_map = 0x61,
|
||||
tag_table_adjustments = 0x62,
|
||||
tag_table_legacy_boxed_trait = 0x63,
|
||||
tag_table_moves_map = 0x64,
|
||||
tag_table_capture_map = 0x65
|
||||
tag_table_moves_map = 0x63,
|
||||
tag_table_capture_map = 0x64
|
||||
}
|
||||
|
||||
pub const tag_item_trait_method_sort: uint = 0x70;
|
||||
@ -155,6 +154,7 @@ pub const tag_lang_items_item_node_id: uint = 0x75;
|
||||
|
||||
pub const tag_item_unnamed_field: uint = 0x76;
|
||||
pub const tag_items_data_item_struct_ctor: uint = 0x77;
|
||||
pub const tag_items_data_item_visibility: uint = 0x78;
|
||||
|
||||
pub struct LinkMeta {
|
||||
name: @str,
|
||||
|
@ -234,6 +234,14 @@ pub fn struct_dtor(cstore: @mut cstore::CStore, def: ast::def_id)
|
||||
let cdata = cstore::get_crate_data(cstore, def.crate);
|
||||
decoder::struct_dtor(cdata, def.node)
|
||||
}
|
||||
|
||||
pub fn get_method_visibility(cstore: @mut cstore::CStore,
|
||||
def_id: ast::def_id)
|
||||
-> ast::visibility {
|
||||
let cdata = cstore::get_crate_data(cstore, def_id.crate);
|
||||
decoder::get_method_visibility(cdata, def_id.node)
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
// mode: rust
|
||||
// fill-column: 78;
|
||||
|
@ -151,6 +151,16 @@ fn item_family(item: ebml::Doc) -> Family {
|
||||
}
|
||||
}
|
||||
|
||||
fn item_visibility(item: ebml::Doc) -> ast::visibility {
|
||||
let visibility = reader::get_doc(item, tag_items_data_item_visibility);
|
||||
match reader::doc_as_u8(visibility) as char {
|
||||
'y' => ast::public,
|
||||
'n' => ast::private,
|
||||
'i' => ast::inherited,
|
||||
_ => fail!(~"unknown visibility character"),
|
||||
}
|
||||
}
|
||||
|
||||
fn item_method_sort(item: ebml::Doc) -> char {
|
||||
for reader::tagged_docs(item, tag_item_trait_method_sort) |doc| {
|
||||
return str::from_bytes(reader::doc_data(doc))[0] as char;
|
||||
@ -860,7 +870,7 @@ pub fn get_item_attrs(cdata: cmd,
|
||||
}
|
||||
}
|
||||
|
||||
pure fn family_to_visibility(family: Family) -> ast::visibility {
|
||||
pure fn struct_field_family_to_visibility(family: Family) -> ast::visibility {
|
||||
match family {
|
||||
PublicField => ast::public,
|
||||
PrivateField => ast::private,
|
||||
@ -883,7 +893,7 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id)
|
||||
result.push(ty::field_ty {
|
||||
ident: name,
|
||||
id: did, vis:
|
||||
family_to_visibility(f),
|
||||
struct_field_family_to_visibility(f),
|
||||
mutability: mt,
|
||||
});
|
||||
}
|
||||
@ -900,6 +910,11 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id)
|
||||
result
|
||||
}
|
||||
|
||||
pub fn get_method_visibility(cdata: cmd, id: ast::node_id)
|
||||
-> ast::visibility {
|
||||
item_visibility(lookup_item(id, cdata.data))
|
||||
}
|
||||
|
||||
fn family_has_type_params(fam: Family) -> bool {
|
||||
match fam {
|
||||
Const | ForeignType | Mod | ForeignMod | PublicField | PrivateField
|
||||
|
@ -383,7 +383,8 @@ fn encode_info_for_mod(ecx: @EncodeContext, ebml_w: writer::Encoder,
|
||||
ebml_w.end_tag();
|
||||
}
|
||||
|
||||
fn encode_visibility(ebml_w: writer::Encoder, visibility: visibility) {
|
||||
fn encode_struct_field_family(ebml_w: writer::Encoder,
|
||||
visibility: visibility) {
|
||||
encode_family(ebml_w, match visibility {
|
||||
public => 'g',
|
||||
private => 'j',
|
||||
@ -391,6 +392,17 @@ fn encode_visibility(ebml_w: writer::Encoder, visibility: visibility) {
|
||||
});
|
||||
}
|
||||
|
||||
fn encode_visibility(ebml_w: writer::Encoder, visibility: visibility) {
|
||||
ebml_w.start_tag(tag_items_data_item_visibility);
|
||||
let ch = match visibility {
|
||||
public => 'y',
|
||||
private => 'n',
|
||||
inherited => 'i',
|
||||
};
|
||||
ebml_w.wr_str(str::from_char(ch));
|
||||
ebml_w.end_tag();
|
||||
}
|
||||
|
||||
fn encode_self_type(ebml_w: writer::Encoder, self_type: ast::self_ty_) {
|
||||
ebml_w.start_tag(tag_item_trait_method_self_ty);
|
||||
|
||||
@ -456,7 +468,7 @@ fn encode_info_for_struct(ecx: @EncodeContext, ebml_w: writer::Encoder,
|
||||
ebml_w.start_tag(tag_items_data_item);
|
||||
debug!("encode_info_for_struct: doing %s %d",
|
||||
*tcx.sess.str_of(nm), id);
|
||||
encode_visibility(ebml_w, vis);
|
||||
encode_struct_field_family(ebml_w, vis);
|
||||
encode_name(ecx, ebml_w, nm);
|
||||
encode_path(ecx, ebml_w, path, ast_map::path_name(nm));
|
||||
encode_type(ecx, ebml_w, node_id_to_type(tcx, id));
|
||||
@ -525,6 +537,7 @@ fn encode_info_for_method(ecx: @EncodeContext,
|
||||
should_inline: bool,
|
||||
parent_id: node_id,
|
||||
m: @method,
|
||||
parent_visibility: ast::visibility,
|
||||
owner_generics: &ast::Generics,
|
||||
method_generics: &ast::Generics) {
|
||||
debug!("encode_info_for_method: %d %s %u %u", m.id,
|
||||
@ -533,6 +546,7 @@ fn encode_info_for_method(ecx: @EncodeContext,
|
||||
method_generics.ty_params.len());
|
||||
ebml_w.start_tag(tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(m.id));
|
||||
|
||||
match m.self_ty.node {
|
||||
ast::sty_static => {
|
||||
encode_family(ebml_w, purity_static_method_family(m.purity));
|
||||
@ -550,6 +564,14 @@ fn encode_info_for_method(ecx: @EncodeContext,
|
||||
encode_name(ecx, ebml_w, m.ident);
|
||||
encode_path(ecx, ebml_w, impl_path, ast_map::path_name(m.ident));
|
||||
encode_self_type(ebml_w, m.self_ty.node);
|
||||
|
||||
// Combine parent visibility and this visibility.
|
||||
let visibility = match m.vis {
|
||||
ast::inherited => parent_visibility,
|
||||
vis => vis,
|
||||
};
|
||||
encode_visibility(ebml_w, visibility);
|
||||
|
||||
if len > 0u || should_inline {
|
||||
(ecx.encode_inlined_item)(
|
||||
ecx, ebml_w, impl_path,
|
||||
@ -568,6 +590,7 @@ fn purity_fn_family(p: purity) -> char {
|
||||
extern_fn => 'e'
|
||||
}
|
||||
}
|
||||
|
||||
fn purity_static_method_family(p: purity) -> char {
|
||||
match p {
|
||||
unsafe_fn => 'U',
|
||||
@ -757,7 +780,7 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
|
||||
match f.node.kind {
|
||||
named_field(ident, _, vis) => {
|
||||
ebml_w.start_tag(tag_item_field);
|
||||
encode_visibility(ebml_w, vis);
|
||||
encode_struct_field_family(ebml_w, vis);
|
||||
encode_name(ecx, ebml_w, ident);
|
||||
encode_def_id(ebml_w, local_def(f.node.id));
|
||||
ebml_w.end_tag();
|
||||
@ -808,12 +831,28 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
|
||||
let mut impl_path = vec::append(~[], path);
|
||||
impl_path += ~[ast_map::path_name(item.ident)];
|
||||
|
||||
// If there is a trait reference, treat the methods as always public.
|
||||
// This is to work around some incorrect behavior in privacy checking:
|
||||
// when the method belongs to a trait, it should acquire the privacy
|
||||
// from the trait, not the impl. Forcing the visibility to be public
|
||||
// makes things sorta work.
|
||||
let parent_visibility = if opt_trait.is_some() {
|
||||
ast::public
|
||||
} else {
|
||||
item.vis
|
||||
};
|
||||
|
||||
for methods.each |m| {
|
||||
index.push(entry {val: m.id, pos: ebml_w.writer.tell()});
|
||||
encode_info_for_method(ecx, ebml_w, impl_path,
|
||||
encode_info_for_method(ecx,
|
||||
ebml_w,
|
||||
impl_path,
|
||||
should_inline(m.attrs),
|
||||
item.id, *m,
|
||||
generics, &m.generics);
|
||||
item.id,
|
||||
*m,
|
||||
parent_visibility,
|
||||
generics,
|
||||
&m.generics);
|
||||
}
|
||||
}
|
||||
item_trait(ref generics, ref traits, ref ms) => {
|
||||
@ -902,9 +941,15 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
|
||||
// of provided methods. I am not sure why this is. -ndm
|
||||
let owner_generics = ast_util::empty_generics();
|
||||
|
||||
encode_info_for_method(ecx, ebml_w, /*bad*/copy path,
|
||||
true, item.id, *m,
|
||||
&owner_generics, &m.generics);
|
||||
encode_info_for_method(ecx,
|
||||
ebml_w,
|
||||
/*bad*/copy path,
|
||||
true,
|
||||
item.id,
|
||||
*m,
|
||||
item.vis,
|
||||
&owner_generics,
|
||||
&m.generics);
|
||||
}
|
||||
}
|
||||
item_mac(*) => fail!(~"item macros unimplemented")
|
||||
|
@ -71,11 +71,11 @@ pub fn mk_filesearch(maybe_sysroot: Option<Path>,
|
||||
|
||||
let sysroot = get_sysroot(maybe_sysroot);
|
||||
debug!("using sysroot = %s", sysroot.to_str());
|
||||
FileSearchImpl {
|
||||
@FileSearchImpl {
|
||||
sysroot: sysroot,
|
||||
addl_lib_search_paths: addl_lib_search_paths,
|
||||
target_triple: str::from_slice(target_triple)
|
||||
} as FileSearch
|
||||
} as @FileSearch
|
||||
}
|
||||
|
||||
pub fn search<T:Copy>(filesearch: FileSearch, pick: pick<T>) -> Option<T> {
|
||||
|
@ -167,7 +167,7 @@ fn reserve_id_range(sess: Session,
|
||||
ast_util::id_range { min: to_id_min, max: to_id_min }
|
||||
}
|
||||
|
||||
impl ExtendedDecodeContext {
|
||||
pub impl ExtendedDecodeContext {
|
||||
fn tr_id(&self, id: ast::node_id) -> ast::node_id {
|
||||
/*!
|
||||
*
|
||||
@ -966,12 +966,6 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
|
||||
}
|
||||
}
|
||||
|
||||
do option::iter(&tcx.legacy_boxed_traits.find(&id)) |_x| {
|
||||
do ebml_w.tag(c::tag_table_legacy_boxed_trait) {
|
||||
ebml_w.id(id);
|
||||
}
|
||||
}
|
||||
|
||||
for maps.moves_map.find(&id).each |_| {
|
||||
do ebml_w.tag(c::tag_table_moves_map) {
|
||||
ebml_w.id(id);
|
||||
@ -1121,8 +1115,6 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext,
|
||||
|
||||
if tag == (c::tag_table_mutbl as uint) {
|
||||
dcx.maps.mutbl_map.insert(id, ());
|
||||
} else if tag == (c::tag_table_legacy_boxed_trait as uint) {
|
||||
dcx.tcx.legacy_boxed_traits.insert(id, ());
|
||||
} else if tag == (c::tag_table_moves_map as uint) {
|
||||
dcx.maps.moves_map.insert(id, ());
|
||||
} else {
|
||||
@ -1230,7 +1222,7 @@ impl fake_ext_ctxt for fake_session {
|
||||
|
||||
#[cfg(test)]
|
||||
fn mk_ctxt() -> fake_ext_ctxt {
|
||||
parse::new_parse_sess(None) as fake_ext_ctxt
|
||||
@parse::new_parse_sess(None) as fake_ext_ctxt
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -89,7 +89,7 @@ enum assignment_type {
|
||||
at_swap
|
||||
}
|
||||
|
||||
impl assignment_type {
|
||||
pub impl assignment_type {
|
||||
fn checked_by_liveness(&self) -> bool {
|
||||
// the liveness pass guarantees that immutable local variables
|
||||
// are only assigned once; but it doesn't consider &mut
|
||||
@ -106,7 +106,7 @@ impl assignment_type {
|
||||
}
|
||||
}
|
||||
|
||||
impl CheckLoanCtxt {
|
||||
pub impl CheckLoanCtxt {
|
||||
fn tcx(@mut self) -> ty::ctxt { self.bccx.tcx }
|
||||
|
||||
fn purity(@mut self, scope_id: ast::node_id) -> Option<purity_cause> {
|
||||
|
@ -289,7 +289,7 @@ fn req_loans_in_expr(ex: @ast::expr,
|
||||
self.root_ub = old_root_ub;
|
||||
}
|
||||
|
||||
impl GatherLoanCtxt {
|
||||
pub impl GatherLoanCtxt {
|
||||
fn tcx(@mut self) -> ty::ctxt { self.bccx.tcx }
|
||||
|
||||
fn guarantee_adjustments(@mut self,
|
||||
|
@ -87,7 +87,7 @@ struct LoanContext {
|
||||
loans: ~[Loan]
|
||||
}
|
||||
|
||||
impl LoanContext {
|
||||
pub impl LoanContext {
|
||||
fn tcx(&self) -> ty::ctxt { self.bccx.tcx }
|
||||
|
||||
fn loan(&mut self,
|
||||
|
@ -230,6 +230,7 @@ use middle::liveness;
|
||||
use middle::mem_categorization::*;
|
||||
use middle::region;
|
||||
use middle::ty;
|
||||
use middle::typeck;
|
||||
use middle::moves;
|
||||
use util::common::{indenter, stmt_set};
|
||||
use util::ppaux::{expr_repr, note_and_explain_region};
|
||||
@ -239,6 +240,7 @@ use core::cmp;
|
||||
use core::dvec::DVec;
|
||||
use core::io;
|
||||
use core::result::{Result, Ok, Err};
|
||||
use core::to_bytes;
|
||||
use std::list::{List, Cons, Nil};
|
||||
use std::list;
|
||||
use std::oldmap::{HashMap, Set};
|
||||
@ -433,7 +435,7 @@ pub fn save_and_restore_managed<T:Copy,U>(save_and_restore_t: @mut T,
|
||||
u
|
||||
}
|
||||
|
||||
impl LoanKind {
|
||||
pub impl LoanKind {
|
||||
fn is_freeze(&self) -> bool {
|
||||
match *self {
|
||||
TotalFreeze | PartialFreeze => true,
|
||||
|
@ -35,7 +35,7 @@ pub enum PreserveCondition {
|
||||
PcIfPure(bckerr)
|
||||
}
|
||||
|
||||
impl PreserveCondition {
|
||||
pub impl PreserveCondition {
|
||||
// combines two preservation conditions such that if either of
|
||||
// them requires purity, the result requires purity
|
||||
fn combine(&self, pc: PreserveCondition) -> PreserveCondition {
|
||||
@ -46,7 +46,7 @@ impl PreserveCondition {
|
||||
}
|
||||
}
|
||||
|
||||
impl BorrowckCtxt {
|
||||
pub impl BorrowckCtxt {
|
||||
fn preserve(&self,
|
||||
cmt: cmt,
|
||||
scope_region: ty::Region,
|
||||
@ -80,7 +80,7 @@ struct PreserveCtxt {
|
||||
root_managed_data: bool
|
||||
}
|
||||
|
||||
impl PreserveCtxt {
|
||||
pub impl PreserveCtxt {
|
||||
fn tcx(&self) -> ty::ctxt { self.bccx.tcx }
|
||||
|
||||
fn preserve(&self, cmt: cmt) -> bckres<PreserveCondition> {
|
||||
|
@ -322,7 +322,7 @@ struct LanguageItemCollector {
|
||||
item_refs: HashMap<@~str, uint>,
|
||||
}
|
||||
|
||||
impl LanguageItemCollector {
|
||||
pub impl LanguageItemCollector {
|
||||
fn match_and_collect_meta_item(&self, item_def_id: def_id,
|
||||
meta_item: @meta_item) {
|
||||
match meta_item.node {
|
||||
|
@ -331,7 +331,7 @@ struct Context {
|
||||
sess: Session
|
||||
}
|
||||
|
||||
impl Context {
|
||||
pub impl Context {
|
||||
fn get_level(&self, lint: lint) -> level {
|
||||
get_lint_level(self.curr, lint)
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ impl to_str::ToStr for Variable {
|
||||
// variable must not be assigned if there is some successor
|
||||
// assignment. And so forth.
|
||||
|
||||
impl LiveNode {
|
||||
pub impl LiveNode {
|
||||
pure fn is_valid(&self) -> bool { **self != uint::max_value }
|
||||
}
|
||||
|
||||
@ -334,7 +334,7 @@ fn IrMaps(tcx: ty::ctxt,
|
||||
}
|
||||
}
|
||||
|
||||
impl IrMaps {
|
||||
pub impl IrMaps {
|
||||
fn add_live_node(&mut self, lnk: LiveNodeKind) -> LiveNode {
|
||||
let ln = LiveNode(self.num_live_nodes);
|
||||
self.lnks.push(lnk);
|
||||
@ -693,7 +693,7 @@ fn Liveness(ir: @mut IrMaps, specials: Specials) -> Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
impl Liveness {
|
||||
pub impl Liveness {
|
||||
fn live_node(&self, node_id: node_id, span: span) -> LiveNode {
|
||||
match self.ir.live_node_map.find(&node_id) {
|
||||
Some(ln) => ln,
|
||||
@ -1649,7 +1649,7 @@ enum ReadKind {
|
||||
PartiallyMovedValue
|
||||
}
|
||||
|
||||
impl @Liveness {
|
||||
pub impl @Liveness {
|
||||
fn check_ret(&self, id: node_id, sp: span, _fk: &visit::fn_kind,
|
||||
entry_ln: LiveNode) {
|
||||
if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() {
|
||||
|
@ -312,7 +312,7 @@ impl ToStr for MutabilityCategory {
|
||||
}
|
||||
}
|
||||
|
||||
impl MutabilityCategory {
|
||||
pub impl MutabilityCategory {
|
||||
static fn from_mutbl(&self, m: ast::mutability) -> MutabilityCategory {
|
||||
match m {
|
||||
m_imm => McImmutable,
|
||||
|
@ -301,7 +301,7 @@ fn compute_modes_for_expr(expr: @expr,
|
||||
cx.consume_expr(expr, v);
|
||||
}
|
||||
|
||||
impl UseMode {
|
||||
pub impl UseMode {
|
||||
fn component_mode(&self, expr: @expr) -> UseMode {
|
||||
/*!
|
||||
*
|
||||
@ -316,7 +316,7 @@ impl UseMode {
|
||||
}
|
||||
}
|
||||
|
||||
impl VisitContext {
|
||||
pub impl VisitContext {
|
||||
fn consume_exprs(&self,
|
||||
exprs: &[@expr],
|
||||
visitor: vt<VisitContext>)
|
||||
|
@ -14,10 +14,11 @@
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use metadata::csearch;
|
||||
use middle::ty::{ty_struct, ty_enum};
|
||||
use middle::ty;
|
||||
use middle::typeck::{method_map, method_origin, method_param, method_self,
|
||||
method_super};
|
||||
use middle::typeck::{method_map, method_origin, method_param, method_self};
|
||||
use middle::typeck::{method_super};
|
||||
use middle::typeck::{method_static, method_trait};
|
||||
|
||||
use core::dvec::DVec;
|
||||
@ -25,7 +26,7 @@ use core::util::ignore;
|
||||
use syntax::ast::{def_variant, expr_field, expr_method_call, expr_struct};
|
||||
use syntax::ast::{expr_unary, ident, item_struct, item_enum, item_impl};
|
||||
use syntax::ast::{item_trait, local_crate, node_id, pat_struct, private};
|
||||
use syntax::ast::{provided, required};
|
||||
use syntax::ast::{provided, public, required};
|
||||
use syntax::ast;
|
||||
use syntax::ast_map::{node_item, node_method};
|
||||
use syntax::ast_map;
|
||||
@ -100,14 +101,52 @@ pub fn check_crate(tcx: ty::ctxt,
|
||||
};
|
||||
|
||||
// Checks that a private method is in scope.
|
||||
let check_method: @fn(span: span, origin: &method_origin) =
|
||||
|span, origin| {
|
||||
let check_method: @fn(span: span,
|
||||
origin: &method_origin,
|
||||
ident: ast::ident) =
|
||||
|span, origin, ident| {
|
||||
match *origin {
|
||||
method_static(method_id) => {
|
||||
if method_id.crate == local_crate {
|
||||
match tcx.items.find(&method_id.node) {
|
||||
Some(node_method(method, impl_id, _)) => {
|
||||
if method.vis == private &&
|
||||
let mut is_private = false;
|
||||
if method.vis == private {
|
||||
is_private = true;
|
||||
} else if method.vis == public {
|
||||
is_private = false;
|
||||
} else {
|
||||
// Look up the enclosing impl.
|
||||
if impl_id.crate != local_crate {
|
||||
tcx.sess.span_bug(span,
|
||||
~"local method isn't \
|
||||
in local impl?!");
|
||||
}
|
||||
|
||||
match tcx.items.find(&impl_id.node) {
|
||||
Some(node_item(item, _)) => {
|
||||
match item.node {
|
||||
item_impl(_, None, _, _)
|
||||
if item.vis != public => {
|
||||
is_private = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Some(_) => {
|
||||
tcx.sess.span_bug(span,
|
||||
~"impl wasn't an \
|
||||
item?!");
|
||||
}
|
||||
None => {
|
||||
tcx.sess.span_bug(span,
|
||||
~"impl wasn't in \
|
||||
AST map?!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if is_private &&
|
||||
(impl_id.crate != local_crate ||
|
||||
!privileged_items
|
||||
.contains(&(impl_id.node))) {
|
||||
@ -131,7 +170,15 @@ pub fn check_crate(tcx: ty::ctxt,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// FIXME #4732: External crates.
|
||||
let visibility =
|
||||
csearch::get_method_visibility(tcx.sess.cstore,
|
||||
method_id);
|
||||
if visibility != public {
|
||||
tcx.sess.span_err(span,
|
||||
fmt!("method `%s` is private",
|
||||
*tcx.sess.parse_sess.interner
|
||||
.get(ident)));
|
||||
}
|
||||
}
|
||||
}
|
||||
method_param(method_param {
|
||||
@ -230,14 +277,16 @@ pub fn check_crate(tcx: ty::ctxt,
|
||||
Some(ref entry) => {
|
||||
debug!("(privacy checking) checking \
|
||||
impl method");
|
||||
check_method(expr.span, &(*entry).origin);
|
||||
check_method(expr.span,
|
||||
&entry.origin,
|
||||
ident);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
expr_method_call(base, _, _, _, _) => {
|
||||
expr_method_call(base, ident, _, _, _) => {
|
||||
// Ditto
|
||||
match ty::get(ty::type_autoderef(tcx, ty::expr_ty(tcx,
|
||||
base))).sty {
|
||||
@ -253,7 +302,9 @@ pub fn check_crate(tcx: ty::ctxt,
|
||||
Some(ref entry) => {
|
||||
debug!("(privacy checking) checking \
|
||||
impl method");
|
||||
check_method(expr.span, &(*entry).origin);
|
||||
check_method(expr.span,
|
||||
&entry.origin,
|
||||
ident);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -622,6 +622,19 @@ pub impl NameBindings {
|
||||
}
|
||||
}
|
||||
|
||||
fn defined_in_public_namespace(namespace: Namespace) -> bool {
|
||||
match namespace {
|
||||
TypeNS => match self.type_def {
|
||||
Some(def) => def.privacy != Private,
|
||||
None => false
|
||||
},
|
||||
ValueNS => match self.value_def {
|
||||
Some(def) => def.privacy != Private,
|
||||
None => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn def_for_namespace(namespace: Namespace) -> Option<def> {
|
||||
match namespace {
|
||||
TypeNS => {
|
||||
@ -2480,7 +2493,7 @@ pub impl Resolver {
|
||||
|
||||
// Here we merge two import resolutions.
|
||||
match module_.import_resolutions.find(&ident) {
|
||||
None => {
|
||||
None if target_import_resolution.privacy == Public => {
|
||||
// Simple: just copy the old import resolution.
|
||||
let new_import_resolution =
|
||||
@mut ImportResolution(privacy,
|
||||
@ -2494,6 +2507,7 @@ pub impl Resolver {
|
||||
module_.import_resolutions.insert
|
||||
(ident, new_import_resolution);
|
||||
}
|
||||
None => { /* continue ... */ }
|
||||
Some(dest_import_resolution) => {
|
||||
// Merge the two import resolutions at a finer-grained
|
||||
// level.
|
||||
@ -2537,7 +2551,6 @@ pub impl Resolver {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
debug!("(resolving glob import) writing resolution `%s` in `%s` \
|
||||
to `%s`, privacy=%?",
|
||||
*self.session.str_of(ident),
|
||||
@ -2546,12 +2559,12 @@ pub impl Resolver {
|
||||
dest_import_resolution.privacy);
|
||||
|
||||
// Merge the child item into the import resolution.
|
||||
if (*name_bindings).defined_in_namespace(ValueNS) {
|
||||
if (*name_bindings).defined_in_public_namespace(ValueNS) {
|
||||
debug!("(resolving glob import) ... for value target");
|
||||
dest_import_resolution.value_target =
|
||||
Some(Target(containing_module, name_bindings));
|
||||
}
|
||||
if (*name_bindings).defined_in_namespace(TypeNS) {
|
||||
if (*name_bindings).defined_in_public_namespace(TypeNS) {
|
||||
debug!("(resolving glob import) ... for type target");
|
||||
dest_import_resolution.type_target =
|
||||
Some(Target(containing_module, name_bindings));
|
||||
@ -2756,6 +2769,8 @@ pub impl Resolver {
|
||||
namespace);
|
||||
}
|
||||
Some(target) => {
|
||||
debug!("(resolving item in lexical scope) using \
|
||||
import resolution");
|
||||
import_resolution.state.used = true;
|
||||
return Success(copy target);
|
||||
}
|
||||
|
@ -145,9 +145,10 @@
|
||||
use core::prelude::*;
|
||||
|
||||
use back::abi;
|
||||
use lib::llvm::llvm;
|
||||
use lib::llvm::{ValueRef, BasicBlockRef};
|
||||
use lib;
|
||||
use lib::llvm::{llvm, ValueRef, BasicBlockRef};
|
||||
use middle::const_eval;
|
||||
use middle::borrowck::root_map_key;
|
||||
use middle::pat_util::*;
|
||||
use middle::resolve::DefMap;
|
||||
use middle::trans::base::*;
|
||||
@ -156,20 +157,26 @@ use middle::trans::callee;
|
||||
use middle::trans::common::*;
|
||||
use middle::trans::consts;
|
||||
use middle::trans::controlflow;
|
||||
use middle::trans::datum;
|
||||
use middle::trans::datum::*;
|
||||
use middle::trans::expr::Dest;
|
||||
use middle::trans::expr;
|
||||
use middle::trans::glue;
|
||||
use middle::trans::tvec;
|
||||
use middle::trans::type_of;
|
||||
use middle::ty;
|
||||
use util::common::indenter;
|
||||
|
||||
use core::dvec::DVec;
|
||||
use core::dvec;
|
||||
use core::libc::c_ulonglong;
|
||||
use std::oldmap::HashMap;
|
||||
use syntax::ast::def_id;
|
||||
use syntax::ast;
|
||||
use syntax::ast_util::{dummy_sp, path_to_ident};
|
||||
use syntax::ast::ident;
|
||||
use syntax::ast_util::path_to_ident;
|
||||
use syntax::ast_util;
|
||||
use syntax::codemap::span;
|
||||
use syntax::codemap::{span, dummy_sp};
|
||||
use syntax::print::pprust::pat_to_str;
|
||||
|
||||
// An option identifying a literal: either a unit-like struct or an
|
||||
|
@ -44,6 +44,7 @@ use middle::borrowck::RootInfo;
|
||||
use middle::pat_util::*;
|
||||
use middle::resolve;
|
||||
use middle::trans::_match;
|
||||
use middle::trans::base;
|
||||
use middle::trans::build::*;
|
||||
use middle::trans::callee;
|
||||
use middle::trans::common::*;
|
||||
@ -56,12 +57,15 @@ use middle::trans::foreign;
|
||||
use middle::trans::glue;
|
||||
use middle::trans::inline;
|
||||
use middle::trans::machine;
|
||||
use middle::trans::machine::llsize_of;
|
||||
use middle::trans::meth;
|
||||
use middle::trans::monomorphize;
|
||||
use middle::trans::reachable;
|
||||
use middle::trans::shape::*;
|
||||
use middle::trans::tvec;
|
||||
use middle::trans::type_of;
|
||||
use middle::trans::type_of::*;
|
||||
use middle::ty;
|
||||
use middle::ty::arg;
|
||||
use util::common::indenter;
|
||||
use util::ppaux::{ty_to_str, ty_to_short_str};
|
||||
@ -77,6 +81,7 @@ use core::option;
|
||||
use core::uint;
|
||||
use std::oldmap::HashMap;
|
||||
use std::{oldmap, time, list};
|
||||
use syntax::ast::ident;
|
||||
use syntax::ast_map::{path, path_elt_to_str, path_mod, path_name};
|
||||
use syntax::ast_util::{def_id_of_def, local_def, path_to_ident};
|
||||
use syntax::attr;
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
|
||||
use codemap::span;
|
||||
use lib;
|
||||
use lib::llvm::llvm;
|
||||
use lib::llvm::{CallConv, TypeKind, AtomicBinOp, AtomicOrdering};
|
||||
use lib::llvm::{Opcode, IntPredicate, RealPredicate, True, False};
|
||||
@ -18,9 +19,12 @@ use libc::{c_uint, c_int, c_ulonglong};
|
||||
use middle::trans::common::*;
|
||||
use middle::trans::machine::llsize_of_real;
|
||||
|
||||
use core::prelude::*;
|
||||
use core::cast::transmute;
|
||||
use core::cast;
|
||||
use core::libc;
|
||||
use core::option::Some;
|
||||
use core::ptr;
|
||||
use core::str;
|
||||
use core::vec;
|
||||
use std::oldmap::HashMap;
|
||||
|
@ -13,6 +13,10 @@ use middle::trans::base::*;
|
||||
use middle::trans::build::*;
|
||||
use middle::trans::common::*;
|
||||
|
||||
use core::libc::c_uint;
|
||||
use core::option;
|
||||
use core::vec;
|
||||
|
||||
pub trait ABIInfo {
|
||||
fn compute_info(&self,
|
||||
atys: &[TypeRef],
|
||||
@ -28,7 +32,7 @@ pub struct LLVMType {
|
||||
pub struct FnType {
|
||||
arg_tys: ~[LLVMType],
|
||||
ret_ty: LLVMType,
|
||||
attrs: ~[Option<Attribute>],
|
||||
attrs: ~[option::Option<Attribute>],
|
||||
sret: bool
|
||||
}
|
||||
|
||||
@ -93,7 +97,7 @@ pub impl FnType {
|
||||
llargbundle: ValueRef, llretval: ValueRef) {
|
||||
for vec::eachi(self.attrs) |i, a| {
|
||||
match *a {
|
||||
Some(attr) => {
|
||||
option::Some(attr) => {
|
||||
unsafe {
|
||||
llvm::LLVMAddInstrAttribute(
|
||||
llretval, (i + 1u) as c_uint,
|
||||
@ -205,8 +209,8 @@ impl ABIInfo for LLVM_ABIInfo {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn llvm_abi_info() -> ABIInfo {
|
||||
return LLVM_ABIInfo as ABIInfo;
|
||||
pub fn llvm_abi_info() -> @ABIInfo {
|
||||
return @LLVM_ABIInfo as @ABIInfo;
|
||||
}
|
||||
|
||||
|
||||
|
@ -159,6 +159,6 @@ impl ABIInfo for ARM_ABIInfo {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn abi_info() -> ABIInfo {
|
||||
return ARM_ABIInfo as ABIInfo;
|
||||
pub fn abi_info() -> @ABIInfo {
|
||||
return @ARM_ABIInfo as @ABIInfo;
|
||||
}
|
||||
|
@ -18,6 +18,14 @@ use lib::llvm::struct_tys;
|
||||
use middle::trans::common::*;
|
||||
use middle::trans::cabi::*;
|
||||
|
||||
use core::cmp;
|
||||
use core::libc::c_uint;
|
||||
use core::option;
|
||||
use core::option::Option;
|
||||
use core::ptr;
|
||||
use core::uint;
|
||||
use core::vec;
|
||||
|
||||
enum x86_64_reg_class {
|
||||
no_class,
|
||||
integer_class,
|
||||
@ -400,5 +408,5 @@ impl ABIInfo for X86_64_ABIInfo {
|
||||
}
|
||||
|
||||
pub fn x86_64_abi_info() -> ABIInfo {
|
||||
return X86_64_ABIInfo as ABIInfo;
|
||||
return @X86_64_ABIInfo as @ABIInfo;
|
||||
}
|
||||
|
@ -18,21 +18,33 @@
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use lib::llvm::ValueRef;
|
||||
use middle::trans::base::{get_item_val, trans_external_path};
|
||||
use back::abi;
|
||||
use driver::session;
|
||||
use lib;
|
||||
use lib::llvm::{ValueRef, TypeRef};
|
||||
use lib::llvm::llvm;
|
||||
use metadata::csearch;
|
||||
use middle::trans::base;
|
||||
use middle::trans::base::*;
|
||||
use middle::trans::build::*;
|
||||
use middle::trans::callee;
|
||||
use middle::trans::closure;
|
||||
use middle::trans::common::{block, node_id_type_params};
|
||||
use middle::trans::common;
|
||||
use middle::trans::common::*;
|
||||
use middle::trans::datum::*;
|
||||
use middle::trans::datum::Datum;
|
||||
use middle::trans::expr;
|
||||
use middle::trans::glue;
|
||||
use middle::trans::inline;
|
||||
use middle::trans::meth;
|
||||
use middle::trans::monomorphize;
|
||||
use middle::trans::type_of;
|
||||
use middle::ty;
|
||||
use middle::typeck;
|
||||
use util::common::indenter;
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::ast_map;
|
||||
use syntax::print::pprust::{expr_to_str, stmt_to_str, path_to_str};
|
||||
use syntax::visit;
|
||||
|
||||
|
@ -13,8 +13,7 @@ use core::prelude::*;
|
||||
use back::abi;
|
||||
use back::link::{mangle_internal_name_by_path_and_seq};
|
||||
use back::link::{mangle_internal_name_by_path};
|
||||
use lib::llvm::llvm;
|
||||
use lib::llvm::{ValueRef, TypeRef};
|
||||
use lib::llvm::{llvm, ValueRef, TypeRef};
|
||||
use middle::moves;
|
||||
use middle::trans::base::*;
|
||||
use middle::trans::build::*;
|
||||
@ -25,6 +24,7 @@ use middle::trans::expr;
|
||||
use middle::trans::glue;
|
||||
use middle::trans::machine;
|
||||
use middle::trans::type_of::*;
|
||||
use middle::ty;
|
||||
use util::ppaux::ty_to_str;
|
||||
|
||||
use core::libc::c_uint;
|
||||
@ -33,6 +33,7 @@ use syntax::ast;
|
||||
use syntax::ast_map::{path, path_mod, path_name};
|
||||
use syntax::ast_util;
|
||||
use syntax::codemap::span;
|
||||
use syntax::parse::token::special_idents;
|
||||
use syntax::print::pprust::expr_to_str;
|
||||
|
||||
// ___Good to know (tm)__________________________________________________
|
||||
@ -185,7 +186,7 @@ pub fn allocate_cbox(bcx: block, sigil: ast::Sigil, cdata_ty: ty::t)
|
||||
}
|
||||
ast::BorrowedSigil => {
|
||||
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
|
||||
let llbox = base::alloc_ty(bcx, cbox_ty);
|
||||
let llbox = alloc_ty(bcx, cbox_ty);
|
||||
nuke_ref_count(bcx, llbox);
|
||||
rslt(bcx, llbox)
|
||||
}
|
||||
@ -342,7 +343,7 @@ pub fn load_environment(fcx: fn_ctxt,
|
||||
let bcx = raw_block(fcx, false, llloadenv);
|
||||
|
||||
// Load a pointer to the closure data, skipping over the box header:
|
||||
let llcdata = base::opaque_box_body(bcx, cdata_ty, fcx.llenv);
|
||||
let llcdata = opaque_box_body(bcx, cdata_ty, fcx.llenv);
|
||||
|
||||
// Populate the upvars from the environment.
|
||||
let mut i = 0u;
|
||||
|
@ -157,7 +157,7 @@ pub fn BuilderRef_res(B: BuilderRef) -> BuilderRef_res {
|
||||
}
|
||||
}
|
||||
|
||||
type ExternMap = HashMap<@str, ValueRef>;
|
||||
pub type ExternMap = HashMap<@str, ValueRef>;
|
||||
|
||||
// Crate context. Every crate we compile has one of these.
|
||||
pub struct CrateContext {
|
||||
@ -553,10 +553,7 @@ impl get_node_info for ast::blk {
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: Work around a trait parsing bug. remove after snapshot
|
||||
pub type optional_boxed_ast_expr = Option<@ast::expr>;
|
||||
|
||||
impl get_node_info for optional_boxed_ast_expr {
|
||||
impl get_node_info for Option<@ast::expr> {
|
||||
fn info(&self) -> Option<NodeInfo> {
|
||||
self.chain_ref(|s| s.info())
|
||||
}
|
||||
|
@ -10,14 +10,18 @@
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use lib::llvm::{llvm, ValueRef, True, TypeRef, False};
|
||||
use middle::const_eval;
|
||||
use middle::trans::base;
|
||||
use middle::trans::base::get_insn_ctxt;
|
||||
use middle::trans::common::*;
|
||||
use middle::trans::consts;
|
||||
use middle::trans::expr;
|
||||
use middle::trans::machine;
|
||||
use middle::trans::type_of;
|
||||
use middle::ty;
|
||||
|
||||
use core::libc::c_uint;
|
||||
use syntax::{ast, ast_util, codemap, ast_map};
|
||||
|
||||
pub fn const_lit(cx: @CrateContext, e: @ast::expr, lit: ast::lit)
|
||||
|
@ -10,13 +10,28 @@
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use lib::llvm::ValueRef;
|
||||
use back::link;
|
||||
use lib;
|
||||
use lib::llvm::*;
|
||||
use middle::trans::base::*;
|
||||
use middle::trans::build::*;
|
||||
use middle::trans::callee;
|
||||
use middle::trans::common::*;
|
||||
use middle::trans::datum::*;
|
||||
use middle::trans::debuginfo;
|
||||
use middle::trans::expr;
|
||||
use middle::trans::type_of::*;
|
||||
use middle::ty;
|
||||
use util::common::indenter;
|
||||
use util::ppaux;
|
||||
|
||||
use core::str;
|
||||
use syntax::ast;
|
||||
use syntax::ast::ident;
|
||||
use syntax::ast_map::path_mod;
|
||||
use syntax::ast_util;
|
||||
use syntax::codemap::span;
|
||||
use syntax::print::pprust::expr_to_str;
|
||||
|
||||
pub fn trans_block(bcx: block, b: &ast::blk, dest: expr::Dest) -> block {
|
||||
let _icx = bcx.insn_ctxt("trans_block");
|
||||
|
@ -87,21 +87,29 @@
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use lib;
|
||||
use lib::llvm::ValueRef;
|
||||
use middle::borrowck::{RootInfo, root_map_key};
|
||||
use middle::trans::base::*;
|
||||
use middle::trans::build::*;
|
||||
use middle::trans::callee;
|
||||
use middle::trans::common::*;
|
||||
use middle::trans::common;
|
||||
use middle::trans::expr;
|
||||
use middle::trans::glue;
|
||||
use middle::trans::tvec;
|
||||
use middle::trans::type_of;
|
||||
use middle::ty;
|
||||
use middle::typeck;
|
||||
use util::common::indenter;
|
||||
use util::ppaux::ty_to_str;
|
||||
|
||||
use core::cmp;
|
||||
use core::option;
|
||||
use core::to_bytes;
|
||||
use core::uint;
|
||||
use core::vec;
|
||||
use syntax::ast;
|
||||
use syntax::parse::token::special_idents;
|
||||
|
||||
#[deriving_eq]
|
||||
@ -326,7 +334,7 @@ pub impl Datum {
|
||||
Store(bcx, self.val, dst);
|
||||
}
|
||||
ByRef => {
|
||||
base::memcpy_ty(bcx, dst, self.val, self.ty);
|
||||
memcpy_ty(bcx, dst, self.val, self.ty);
|
||||
}
|
||||
}
|
||||
|
||||
@ -354,7 +362,7 @@ pub impl Datum {
|
||||
|
||||
match self.mode {
|
||||
ByRef => {
|
||||
base::memcpy_ty(bcx, dst, self.val, self.ty);
|
||||
memcpy_ty(bcx, dst, self.val, self.ty);
|
||||
}
|
||||
ByValue => {
|
||||
Store(bcx, self.val, dst);
|
||||
@ -540,7 +548,7 @@ pub impl Datum {
|
||||
|
||||
let scratch = scratch_datum(bcx, self.ty, true);
|
||||
self.copy_to_datum(bcx, INIT, scratch);
|
||||
base::add_root_cleanup(bcx, root_info, scratch.val, scratch.ty);
|
||||
add_root_cleanup(bcx, root_info, scratch.val, scratch.ty);
|
||||
|
||||
// If we need to freeze the box, do that now.
|
||||
if root_info.freezes {
|
||||
|
@ -121,10 +121,15 @@ lvalues are *never* stored by value.
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use lib::llvm::ValueRef;
|
||||
use back::abi;
|
||||
use lib;
|
||||
use lib::llvm::{ValueRef, TypeRef, llvm, True};
|
||||
use middle::borrowck::root_map_key;
|
||||
use middle::resolve;
|
||||
use middle::trans::_match;
|
||||
use middle::trans::base;
|
||||
use middle::trans::base::*;
|
||||
use middle::trans::build::*;
|
||||
use middle::trans::callee::{AutorefArg, DoAutorefArg, DontAutorefArg};
|
||||
use middle::trans::callee;
|
||||
use middle::trans::closure;
|
||||
@ -132,16 +137,21 @@ use middle::trans::common::*;
|
||||
use middle::trans::consts;
|
||||
use middle::trans::controlflow;
|
||||
use middle::trans::datum::*;
|
||||
use middle::trans::debuginfo;
|
||||
use middle::trans::machine;
|
||||
use middle::trans::meth;
|
||||
use middle::trans::tvec;
|
||||
use middle::trans::type_of;
|
||||
use middle::ty;
|
||||
use middle::ty::struct_mutable_fields;
|
||||
use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowVecRef, AutoBorrowFn};
|
||||
use util::common::indenter;
|
||||
use util::ppaux::ty_to_str;
|
||||
|
||||
use std::oldmap::HashMap;
|
||||
use syntax::print::pprust::{expr_to_str};
|
||||
use syntax::ast;
|
||||
use syntax::codemap;
|
||||
use syntax::codemap::spanned;
|
||||
|
||||
// Destinations
|
||||
@ -154,7 +164,7 @@ pub enum Dest {
|
||||
Ignore,
|
||||
}
|
||||
|
||||
impl Dest {
|
||||
pub impl Dest {
|
||||
fn to_str(&self, ccx: @CrateContext) -> ~str {
|
||||
match *self {
|
||||
SaveIn(v) => fmt!("SaveIn(%s)", val_str(ccx.tn, v)),
|
||||
@ -1128,7 +1138,7 @@ fn trans_rec_or_struct(bcx: block,
|
||||
let fields = ty::struct_mutable_fields(
|
||||
tcx, variant_id, substs);
|
||||
let field_lltys = do fields.map |field| {
|
||||
type_of(bcx.ccx(),
|
||||
type_of::type_of(bcx.ccx(),
|
||||
ty::subst_tps(
|
||||
tcx, substs.tps, None, field.mt.ty))
|
||||
};
|
||||
|
@ -11,6 +11,7 @@
|
||||
use core::prelude::*;
|
||||
|
||||
use back::{link, abi};
|
||||
use driver::session;
|
||||
use driver::session::arch_x86_64;
|
||||
use driver::session::arch_arm;
|
||||
use lib::llvm::{SequentiallyConsistent, Acquire, Release, Xchg};
|
||||
@ -27,11 +28,13 @@ use middle::trans::callee::*;
|
||||
use middle::trans::common::*;
|
||||
use middle::trans::datum::*;
|
||||
use middle::trans::expr::{Dest, Ignore};
|
||||
use middle::trans::machine::llsize_of;
|
||||
use middle::trans::glue;
|
||||
use middle::trans::machine;
|
||||
use middle::trans::shape;
|
||||
use middle::trans::type_of::*;
|
||||
use middle::trans::type_of;
|
||||
use middle::ty;
|
||||
use middle::ty::{FnSig, arg};
|
||||
use util::ppaux::ty_to_str;
|
||||
|
||||
|
@ -14,19 +14,32 @@
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use lib::llvm::{ValueRef, TypeRef};
|
||||
use back::abi;
|
||||
use back::link::*;
|
||||
use driver::session;
|
||||
use lib;
|
||||
use lib::llvm::{llvm, ValueRef, TypeRef, True};
|
||||
use middle::trans::base::*;
|
||||
use middle::trans::callee;
|
||||
use middle::trans::closure;
|
||||
use middle::trans::common::*;
|
||||
use middle::trans::build::*;
|
||||
use middle::trans::expr;
|
||||
use middle::trans::machine::*;
|
||||
use middle::trans::reflect;
|
||||
use middle::trans::tvec;
|
||||
use middle::trans::type_of::type_of;
|
||||
use middle::trans::type_of::{type_of, type_of_glue_fn};
|
||||
use middle::trans::uniq;
|
||||
use middle::ty;
|
||||
use util::ppaux;
|
||||
use util::ppaux::ty_to_short_str;
|
||||
|
||||
use core::io;
|
||||
use core::libc::c_uint;
|
||||
use core::str;
|
||||
use std::time;
|
||||
use syntax::ast;
|
||||
use syntax::parse::token::special_idents;
|
||||
|
||||
pub fn trans_free(cx: block, v: ValueRef) -> block {
|
||||
let _icx = cx.insn_ctxt("trans_free");
|
||||
@ -218,7 +231,7 @@ pub fn lazily_emit_simplified_tydesc_glue(ccx: @CrateContext,
|
||||
let _icx = ccx.insn_ctxt("lazily_emit_simplified_tydesc_glue");
|
||||
let simpl = simplified_glue_type(ccx.tcx, field, ti.ty);
|
||||
if simpl != ti.ty {
|
||||
let simpl_ti = base::get_tydesc(ccx, simpl);
|
||||
let simpl_ti = get_tydesc(ccx, simpl);
|
||||
lazily_emit_tydesc_glue(ccx, field, simpl_ti);
|
||||
if field == abi::tydesc_field_take_glue {
|
||||
ti.take_glue =
|
||||
@ -661,7 +674,7 @@ pub fn declare_tydesc(ccx: @CrateContext, t: ty::t) -> @mut tydesc_info {
|
||||
if ccx.sess.count_type_sizes() {
|
||||
io::println(fmt!("%u\t%s",
|
||||
llsize_of_real(ccx, llty),
|
||||
ty_to_str(ccx.tcx, t)));
|
||||
ppaux::ty_to_str(ccx.tcx, t)));
|
||||
}
|
||||
|
||||
let llsize = llsize_of(ccx, llty);
|
||||
@ -675,7 +688,7 @@ pub fn declare_tydesc(ccx: @CrateContext, t: ty::t) -> @mut tydesc_info {
|
||||
};
|
||||
// XXX: Bad copy.
|
||||
note_unique_llvm_symbol(ccx, copy name);
|
||||
log(debug, fmt!("+++ declare_tydesc %s %s", ty_to_str(ccx.tcx, t), name));
|
||||
debug!("+++ declare_tydesc %s %s", ppaux::ty_to_str(ccx.tcx, t), name);
|
||||
let gvar = str::as_c_str(name, |buf| {
|
||||
unsafe {
|
||||
llvm::LLVMAddGlobal(ccx.llmod, ccx.tydesc_type, buf)
|
||||
@ -709,7 +722,7 @@ pub fn declare_generic_glue(ccx: @CrateContext, t: ty::t, llfnty: TypeRef,
|
||||
} else {
|
||||
fn_nm = mangle_internal_name_by_seq(ccx, (~"glue_" + name));
|
||||
}
|
||||
debug!("%s is for type %s", fn_nm, ty_to_str(ccx.tcx, t));
|
||||
debug!("%s is for type %s", fn_nm, ppaux::ty_to_str(ccx.tcx, t));
|
||||
// XXX: Bad copy.
|
||||
note_unique_llvm_symbol(ccx, copy fn_nm);
|
||||
let llfn = decl_cdecl_fn(ccx.llmod, fn_nm, llfnty);
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use metadata::csearch;
|
||||
use middle::astencode;
|
||||
use middle::trans::base::{get_insn_ctxt};
|
||||
use middle::trans::base::{impl_owned_self, impl_self, no_self};
|
||||
@ -18,6 +19,8 @@ use middle::trans::common::*;
|
||||
use middle::trans::common;
|
||||
use middle::trans::inline;
|
||||
use middle::trans::monomorphize;
|
||||
use middle::ty;
|
||||
use util::ppaux::ty_to_str;
|
||||
|
||||
use core::vec;
|
||||
use syntax::ast;
|
||||
|
@ -11,6 +11,9 @@
|
||||
// Information concerning the machine representation of various types.
|
||||
|
||||
|
||||
use lib::llvm::{ModuleRef, ValueRef, TypeRef, BasicBlockRef, BuilderRef};
|
||||
use lib::llvm::{True, False, Bool};
|
||||
use lib::llvm::llvm;
|
||||
use middle::trans::common::*;
|
||||
use middle::trans::type_of;
|
||||
use middle::ty;
|
||||
@ -122,7 +125,7 @@ pub fn llalign_of_min(cx: @CrateContext, t: TypeRef) -> uint {
|
||||
pub fn llalign_of(cx: @CrateContext, t: TypeRef) -> ValueRef {
|
||||
unsafe {
|
||||
return llvm::LLVMConstIntCast(
|
||||
lib::llvm::llvm::LLVMAlignOf(t), cx.int_type, False);
|
||||
llvm::LLVMAlignOf(t), cx.int_type, False);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,14 +28,16 @@ use middle::trans::glue;
|
||||
use middle::trans::inline;
|
||||
use middle::trans::monomorphize;
|
||||
use middle::trans::type_of::*;
|
||||
use middle::ty;
|
||||
use middle::ty::arg;
|
||||
use middle::typeck;
|
||||
use util::common::indenter;
|
||||
use util::ppaux::{ty_to_str, tys_to_str};
|
||||
|
||||
use core::libc::c_uint;
|
||||
use std::oldmap::HashMap;
|
||||
use syntax::ast_map::{path, path_mod, path_name, node_id_to_str};
|
||||
use syntax::ast_util::local_def;
|
||||
use syntax::ast_util;
|
||||
use syntax::print::pprust::expr_to_str;
|
||||
use syntax::{ast, ast_map};
|
||||
|
||||
@ -351,7 +353,7 @@ pub fn trans_static_method_callee(bcx: block,
|
||||
|
||||
pub fn method_from_methods(ms: ~[@ast::method], name: ast::ident)
|
||||
-> Option<ast::def_id> {
|
||||
ms.find(|m| m.ident == name).map(|m| local_def(m.id))
|
||||
ms.find(|m| m.ident == name).map(|m| ast_util::local_def(m.id))
|
||||
}
|
||||
|
||||
pub fn method_with_name(ccx: @CrateContext, impl_id: ast::def_id,
|
||||
@ -725,7 +727,7 @@ pub fn trans_trait_callee_from_llval(bcx: block,
|
||||
|
||||
// Load the function from the vtable and cast it to the expected type.
|
||||
debug!("(translating trait callee) loading method");
|
||||
let llcallee_ty = type_of::type_of_fn_from_ty(ccx, callee_ty);
|
||||
let llcallee_ty = type_of_fn_from_ty(ccx, callee_ty);
|
||||
let mptr = Load(bcx, GEPi(bcx, llvtable, [0u, n_method]));
|
||||
let mptr = PointerCast(bcx, mptr, T_ptr(llcallee_ty));
|
||||
|
||||
@ -868,27 +870,11 @@ pub fn trans_trait_cast(bcx: block,
|
||||
match vstore {
|
||||
ty::vstore_slice(*) | ty::vstore_box => {
|
||||
let mut llboxdest = GEPi(bcx, lldest, [0u, 1u]);
|
||||
if bcx.tcx().legacy_boxed_traits.contains_key(&id) {
|
||||
// Allocate an @ box and store the value into it
|
||||
let MallocResult {bcx: new_bcx, box: llbox, body: body} =
|
||||
malloc_boxed(bcx, v_ty);
|
||||
bcx = new_bcx;
|
||||
add_clean_free(bcx, llbox, heap_managed);
|
||||
bcx = expr::trans_into(bcx, val, SaveIn(body));
|
||||
revoke_clean(bcx, llbox);
|
||||
|
||||
// Store the @ box into the pair
|
||||
Store(bcx, llbox, PointerCast(bcx,
|
||||
llboxdest,
|
||||
T_ptr(val_ty(llbox))));
|
||||
} else {
|
||||
// Just store the pointer into the pair.
|
||||
llboxdest = PointerCast(bcx,
|
||||
llboxdest,
|
||||
T_ptr(type_of::type_of(bcx.ccx(),
|
||||
v_ty)));
|
||||
bcx = expr::trans_into(bcx, val, SaveIn(llboxdest));
|
||||
}
|
||||
// Just store the pointer into the pair.
|
||||
llboxdest = PointerCast(bcx,
|
||||
llboxdest,
|
||||
T_ptr(type_of(bcx.ccx(), v_ty)));
|
||||
bcx = expr::trans_into(bcx, val, SaveIn(llboxdest));
|
||||
}
|
||||
ty::vstore_uniq => {
|
||||
// Translate the uniquely-owned value into the second element of
|
||||
@ -896,7 +882,7 @@ pub fn trans_trait_cast(bcx: block,
|
||||
let mut llvaldest = GEPi(bcx, lldest, [0, 1]);
|
||||
llvaldest = PointerCast(bcx,
|
||||
llvaldest,
|
||||
T_ptr(type_of::type_of(bcx.ccx(), v_ty)));
|
||||
T_ptr(type_of(bcx.ccx(), v_ty)));
|
||||
bcx = expr::trans_into(bcx, val, SaveIn(llvaldest));
|
||||
|
||||
// Get the type descriptor of the wrapped value and store it into
|
||||
|
@ -11,6 +11,8 @@
|
||||
use core::prelude::*;
|
||||
|
||||
use back::link::mangle_exported_name;
|
||||
use driver::session;
|
||||
use lib::llvm::ValueRef;
|
||||
use middle::trans::base::{get_insn_ctxt};
|
||||
use middle::trans::base::{set_inline_hint_if_appr, set_inline_hint};
|
||||
use middle::trans::base::{trans_enum_variant, trans_struct_dtor};
|
||||
@ -26,12 +28,15 @@ use middle::trans::shape;
|
||||
use middle::trans::type_of::type_of_fn_from_ty;
|
||||
use middle::trans::type_of;
|
||||
use middle::trans::type_use;
|
||||
use middle::ty;
|
||||
use middle::ty::{FnSig};
|
||||
use middle::typeck;
|
||||
use util::ppaux::ty_to_str;
|
||||
|
||||
use core::option;
|
||||
use core::vec;
|
||||
use syntax::ast;
|
||||
use syntax::ast_map;
|
||||
use syntax::ast_map::{path, path_mod, path_name};
|
||||
use syntax::ast_util::local_def;
|
||||
use syntax::parse::token::special_idents;
|
||||
|
@ -21,11 +21,13 @@ use middle::resolve;
|
||||
use middle::ty;
|
||||
use middle::typeck;
|
||||
|
||||
use core::vec;
|
||||
use core::prelude::*;
|
||||
use std::oldmap::HashMap;
|
||||
use syntax::ast;
|
||||
use syntax::ast::*;
|
||||
use syntax::ast_util::def_id_of_def;
|
||||
use syntax::attr;
|
||||
use syntax::codemap;
|
||||
use syntax::print::pprust::expr_to_str;
|
||||
use syntax::{visit, ast_util, ast_map};
|
||||
|
||||
|
@ -22,8 +22,11 @@ use middle::trans::glue;
|
||||
use middle::trans::machine;
|
||||
use middle::trans::meth;
|
||||
use middle::trans::type_of::*;
|
||||
use middle::ty;
|
||||
use util::ppaux::ty_to_str;
|
||||
|
||||
use core::option::None;
|
||||
use core::vec;
|
||||
use std::oldmap::HashMap;
|
||||
use syntax::ast::def_id;
|
||||
use syntax::ast;
|
||||
@ -60,7 +63,7 @@ pub impl Reflector {
|
||||
}
|
||||
|
||||
fn c_size_and_align(&mut self, t: ty::t) -> ~[ValueRef] {
|
||||
let tr = type_of::type_of(self.bcx.ccx(), t);
|
||||
let tr = type_of(self.bcx.ccx(), t);
|
||||
let s = machine::llsize_of_real(self.bcx.ccx(), tr);
|
||||
let a = machine::llalign_of_min(self.bcx.ccx(), tr);
|
||||
return ~[self.c_uint(s),
|
||||
@ -351,7 +354,7 @@ pub fn emit_calls_to_trait_visit_ty(bcx: block,
|
||||
let final = sub_block(bcx, ~"final");
|
||||
assert bcx.ccx().tcx.intrinsic_defs.contains_key(&tydesc);
|
||||
let (_, tydesc_ty) = bcx.ccx().tcx.intrinsic_defs.get(&tydesc);
|
||||
let tydesc_ty = type_of::type_of(bcx.ccx(), tydesc_ty);
|
||||
let tydesc_ty = type_of(bcx.ccx(), tydesc_ty);
|
||||
let mut r = Reflector {
|
||||
visitor_val: visitor_val,
|
||||
visitor_methods: ty::trait_methods(bcx.tcx(), visitor_trait_id),
|
||||
|
@ -25,6 +25,7 @@ use util::ppaux::ty_to_str;
|
||||
|
||||
use core::dvec::DVec;
|
||||
use core::option::is_some;
|
||||
use core::str;
|
||||
use core::vec;
|
||||
use std::oldmap::HashMap;
|
||||
use syntax::ast;
|
||||
|
@ -10,20 +10,27 @@
|
||||
|
||||
|
||||
use back::abi;
|
||||
use lib::llvm::{ValueRef, TypeRef};
|
||||
use lib;
|
||||
use lib::llvm::{llvm, ValueRef, TypeRef};
|
||||
use middle::trans::base;
|
||||
use middle::trans::base::*;
|
||||
use middle::trans::build::*;
|
||||
use middle::trans::callee;
|
||||
use middle::trans::common::*;
|
||||
use middle::trans::datum::*;
|
||||
use middle::trans::expr::{Dest, Ignore, SaveIn};
|
||||
use middle::trans::expr;
|
||||
use middle::trans::glue;
|
||||
use middle::trans::shape::{llsize_of, nonzero_llsize_of};
|
||||
use middle::trans::machine::{llsize_of, nonzero_llsize_of};
|
||||
use middle::trans::type_of;
|
||||
use middle::ty;
|
||||
use util::common::indenter;
|
||||
use util::ppaux::ty_to_str;
|
||||
|
||||
use core::uint;
|
||||
use core::vec;
|
||||
use syntax::ast;
|
||||
use syntax::codemap;
|
||||
use syntax::codemap::span;
|
||||
use syntax::print::pprust::{expr_to_str};
|
||||
|
||||
@ -81,7 +88,7 @@ pub fn alloc_raw(bcx: block, unit_ty: ty::t,
|
||||
let vecbodyty = ty::mk_mut_unboxed_vec(bcx.tcx(), unit_ty);
|
||||
let vecsize = Add(bcx, alloc, llsize_of(ccx, ccx.opaque_vec_type));
|
||||
|
||||
let MallocResult {bcx, box: bx, body} =
|
||||
let base::MallocResult {bcx, box: bx, body} =
|
||||
base::malloc_general_dyn(bcx, vecbodyty, heap, vecsize);
|
||||
Store(bcx, fill, GEPi(bcx, body, [0u, abi::vec_elt_fill]));
|
||||
Store(bcx, alloc, GEPi(bcx, body, [0u, abi::vec_elt_alloc]));
|
||||
@ -91,7 +98,7 @@ pub fn alloc_raw(bcx: block, unit_ty: ty::t,
|
||||
|
||||
pub fn alloc_uniq_raw(bcx: block, unit_ty: ty::t,
|
||||
fill: ValueRef, alloc: ValueRef) -> Result {
|
||||
alloc_raw(bcx, unit_ty, fill, alloc, heap_for_unique(bcx, unit_ty))
|
||||
alloc_raw(bcx, unit_ty, fill, alloc, base::heap_for_unique(bcx, unit_ty))
|
||||
}
|
||||
|
||||
pub fn alloc_vec(bcx: block,
|
||||
@ -305,13 +312,13 @@ pub fn trans_uniq_or_managed_vstore(bcx: block,
|
||||
let llptrval = PointerCast(bcx, llptrval, T_ptr(T_i8()));
|
||||
let llsizeval = C_uint(bcx.ccx(), s.len());
|
||||
let typ = ty::mk_estr(bcx.tcx(), ty::vstore_uniq);
|
||||
let lldestval = datum::scratch_datum(bcx, typ, false);
|
||||
let lldestval = scratch_datum(bcx, typ, false);
|
||||
let bcx = callee::trans_lang_call(
|
||||
bcx,
|
||||
bcx.tcx().lang_items.strdup_uniq_fn(),
|
||||
~[ llptrval, llsizeval ],
|
||||
expr::SaveIn(lldestval.to_ref_llval(bcx)));
|
||||
return datum::DatumBlock {
|
||||
return DatumBlock {
|
||||
bcx: bcx,
|
||||
datum: lldestval
|
||||
};
|
||||
@ -508,8 +515,8 @@ pub fn get_base_and_len(bcx: block,
|
||||
(base, len)
|
||||
}
|
||||
ty::vstore_uniq | ty::vstore_box => {
|
||||
let body = tvec::get_bodyptr(bcx, llval);
|
||||
(tvec::get_dataptr(bcx, body), tvec::get_fill(bcx, body))
|
||||
let body = get_bodyptr(bcx, llval);
|
||||
(get_dataptr(bcx, body), get_fill(bcx, body))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,12 +11,16 @@
|
||||
|
||||
use lib::llvm::llvm;
|
||||
use lib::llvm::{TypeRef};
|
||||
use middle::trans::base;
|
||||
use middle::trans::common::*;
|
||||
use middle::trans::common;
|
||||
use middle::trans::expr;
|
||||
use middle::trans::machine;
|
||||
use middle::ty;
|
||||
use util::ppaux;
|
||||
|
||||
use core::option::None;
|
||||
use core::vec;
|
||||
use std::oldmap::HashMap;
|
||||
use syntax::ast;
|
||||
|
||||
@ -387,7 +391,7 @@ pub fn type_of_dtor(ccx: @CrateContext, self_ty: ty::t) -> TypeRef {
|
||||
pub fn type_of_rooted(ccx: @CrateContext, t: ty::t) -> TypeRef {
|
||||
let addrspace = base::get_tydesc(ccx, t).addrspace;
|
||||
debug!("type_of_rooted %s in addrspace %u",
|
||||
ty_to_str(ccx.tcx, t), addrspace as uint);
|
||||
ppaux::ty_to_str(ccx.tcx, t), addrspace as uint);
|
||||
return T_root(type_of(ccx, t), addrspace);
|
||||
}
|
||||
|
||||
|
@ -32,13 +32,17 @@ use metadata::csearch;
|
||||
use middle::freevars;
|
||||
use middle::trans::common::*;
|
||||
use middle::trans::inline;
|
||||
use middle::ty;
|
||||
use middle::typeck;
|
||||
|
||||
use core::option;
|
||||
use core::option::{Some, None, Option};
|
||||
use core::uint;
|
||||
use core::vec;
|
||||
use std::list::{List, Cons, Nil};
|
||||
use std::list;
|
||||
use std::oldmap::HashMap;
|
||||
use syntax::ast;
|
||||
use syntax::ast::*;
|
||||
use syntax::ast_map;
|
||||
use syntax::ast_util;
|
||||
|
@ -17,6 +17,7 @@ use middle::trans::common::*;
|
||||
use middle::trans::datum::immediate_rvalue;
|
||||
use middle::trans::datum;
|
||||
use middle::trans::glue;
|
||||
use middle::ty;
|
||||
|
||||
use syntax::ast;
|
||||
|
||||
|
@ -269,7 +269,6 @@ struct ctxt_ {
|
||||
adjustments: HashMap<ast::node_id, @AutoAdjustment>,
|
||||
normalized_cache: HashMap<t, t>,
|
||||
lang_items: middle::lang_items::LanguageItems,
|
||||
legacy_boxed_traits: HashMap<node_id, ()>,
|
||||
// A mapping from an implementation ID to the method info and trait
|
||||
// method ID of the provided (a.k.a. default) methods in the traits that
|
||||
// that implementation implements.
|
||||
@ -831,7 +830,6 @@ pub fn mk_ctxt(s: session::Session,
|
||||
adjustments: HashMap(),
|
||||
normalized_cache: new_ty_hash(),
|
||||
lang_items: lang_items,
|
||||
legacy_boxed_traits: HashMap(),
|
||||
provided_methods: HashMap(),
|
||||
provided_method_sources: HashMap(),
|
||||
supertraits: HashMap(),
|
||||
@ -3714,7 +3712,7 @@ pub enum DtorKind {
|
||||
TraitDtor(def_id)
|
||||
}
|
||||
|
||||
impl DtorKind {
|
||||
pub impl DtorKind {
|
||||
pure fn is_not_present(&const self) -> bool {
|
||||
match *self {
|
||||
NoDtor => true,
|
||||
|
@ -97,8 +97,8 @@ pub fn lookup_vtables(vcx: &VtableContext,
|
||||
let mut result = ~[], i = 0u;
|
||||
for substs.tps.each |ty| {
|
||||
for ty::iter_bound_traits_and_supertraits(
|
||||
tcx, bounds[i]) |trait_ty| {
|
||||
|
||||
tcx, bounds[i]) |trait_ty|
|
||||
{
|
||||
debug!("about to subst: %?, %?",
|
||||
ppaux::ty_to_str(tcx, trait_ty),
|
||||
ty::substs_to_str(tcx, substs));
|
||||
@ -585,138 +585,102 @@ pub fn early_resolve_expr(ex: @ast::expr,
|
||||
}
|
||||
}
|
||||
ast::expr_cast(src, _) => {
|
||||
let target_ty = fcx.expr_ty(ex);
|
||||
match ty::get(target_ty).sty {
|
||||
ty::ty_trait(_, _, vstore) => {
|
||||
// Look up vtables for the type we're casting to, passing in the
|
||||
// source and target type.
|
||||
//
|
||||
// XXX: This is invariant and shouldn't be. --pcw
|
||||
let target_ty = fcx.expr_ty(ex);
|
||||
match ty::get(target_ty).sty {
|
||||
ty::ty_trait(_, _, vstore) => {
|
||||
// Look up vtables for the type we're casting to,
|
||||
// passing in the source and target type. The source
|
||||
// must be a pointer type suitable to the object sigil,
|
||||
// e.g.: `@x as @Trait`, `&x as &Trait` or `~x as ~Trait`
|
||||
let ty = structurally_resolved_type(fcx, ex.span,
|
||||
fcx.expr_ty(src));
|
||||
match (&ty::get(ty).sty, vstore) {
|
||||
(&ty::ty_box(mt), ty::vstore_box) |
|
||||
(&ty::ty_uniq(mt), ty::vstore_uniq) |
|
||||
(&ty::ty_rptr(_, mt), ty::vstore_slice(*)) => {
|
||||
let location_info =
|
||||
&location_info_for_expr(ex);
|
||||
let vcx = VtableContext {
|
||||
ccx: fcx.ccx,
|
||||
infcx: fcx.infcx()
|
||||
};
|
||||
let vtable_opt =
|
||||
lookup_vtable(&vcx,
|
||||
location_info,
|
||||
mt.ty,
|
||||
target_ty,
|
||||
true,
|
||||
is_early);
|
||||
match vtable_opt {
|
||||
Some(vtable) => {
|
||||
// Map this expression to that
|
||||
// vtable (that is: "ex has vtable
|
||||
// <vtable>")
|
||||
if !is_early {
|
||||
let vtable_map =
|
||||
cx.vtable_map;
|
||||
vtable_map.insert(ex.id,
|
||||
@~[vtable]);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
fcx.tcx().sess.span_err(
|
||||
ex.span,
|
||||
fmt!("failed to find an implementation \
|
||||
of trait %s for %s",
|
||||
fcx.infcx().ty_to_str(target_ty),
|
||||
fcx.infcx().ty_to_str(mt.ty)));
|
||||
}
|
||||
}
|
||||
|
||||
let ty = fcx.expr_ty(src);
|
||||
let vcx = VtableContext { ccx: fcx.ccx, infcx: fcx.infcx() };
|
||||
let vtable_opt =
|
||||
lookup_vtable(&vcx,
|
||||
&location_info_for_expr(ex),
|
||||
ty,
|
||||
target_ty,
|
||||
true,
|
||||
is_early);
|
||||
match vtable_opt {
|
||||
None => {
|
||||
// Try the new-style boxed trait; "@int as @Trait".
|
||||
// Or the new-style region trait; "&int as &Trait".
|
||||
// Or the new-style uniquely-owned trait; "~int as
|
||||
// ~Trait".
|
||||
let mut err = false;
|
||||
let ty = structurally_resolved_type(fcx, ex.span, ty);
|
||||
match ty::get(ty).sty {
|
||||
ty::ty_box(mt) | ty::ty_rptr(_, mt) |
|
||||
ty::ty_uniq(mt) => {
|
||||
// Ensure that the trait vstore and the pointer
|
||||
// type match.
|
||||
match (&ty::get(ty).sty, vstore) {
|
||||
(&ty::ty_box(_), ty::vstore_box) |
|
||||
(&ty::ty_uniq(_), ty::vstore_uniq) |
|
||||
(&ty::ty_rptr(*), ty::vstore_slice(*)) => {
|
||||
let location_info =
|
||||
&location_info_for_expr(ex);
|
||||
let vtable_opt =
|
||||
lookup_vtable(&vcx,
|
||||
location_info,
|
||||
mt.ty,
|
||||
target_ty,
|
||||
true,
|
||||
is_early);
|
||||
match vtable_opt {
|
||||
Some(vtable) => {
|
||||
// Map this expression to that
|
||||
// vtable (that is: "ex has vtable
|
||||
// <vtable>")
|
||||
if !is_early {
|
||||
let vtable_map =
|
||||
cx.vtable_map;
|
||||
vtable_map.insert(ex.id,
|
||||
@~[vtable]);
|
||||
}
|
||||
}
|
||||
None => err = true
|
||||
}
|
||||
// Now, if this is &trait, we need to link the
|
||||
// regions.
|
||||
match (&ty::get(ty).sty, vstore) {
|
||||
(&ty::ty_rptr(ra, _),
|
||||
ty::vstore_slice(rb)) => {
|
||||
infer::mk_subr(fcx.infcx(),
|
||||
false,
|
||||
ex.span,
|
||||
rb,
|
||||
ra);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
// Now, if this is &trait, we need to link
|
||||
// the regions.
|
||||
match (&ty::get(ty).sty, vstore) {
|
||||
(&ty::ty_rptr(ra, _),
|
||||
ty::vstore_slice(rb)) => {
|
||||
infer::mk_subr(fcx.infcx(),
|
||||
false,
|
||||
ex.span,
|
||||
rb,
|
||||
ra);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
(&ty::ty_box(_), _) => {
|
||||
fcx.ccx.tcx.sess.span_err(ex.span,
|
||||
~"must cast \
|
||||
a boxed \
|
||||
pointer to \
|
||||
a boxed
|
||||
trait");
|
||||
err = true;
|
||||
}
|
||||
(&ty::ty_rptr(*), _) => {
|
||||
fcx.ccx.tcx.sess.span_err(ex.span,
|
||||
~"must cast \
|
||||
a borrowed \
|
||||
pointer to \
|
||||
a borrowed \
|
||||
trait");
|
||||
}
|
||||
(&ty::ty_uniq(*), _) => {
|
||||
fcx.ccx.tcx.sess.span_err(ex.span,
|
||||
~"must cast \
|
||||
a unique \
|
||||
pointer to \
|
||||
a uniquely-\
|
||||
owned trait");
|
||||
}
|
||||
_ => {
|
||||
fcx.ccx.tcx.sess.impossible_case(
|
||||
ex.span,
|
||||
~"impossible combination of type and \
|
||||
trait vstore");
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => err = true
|
||||
}
|
||||
(_, ty::vstore_box(*)) => {
|
||||
fcx.ccx.tcx.sess.span_err(
|
||||
ex.span,
|
||||
fmt!("can only cast an @-pointer \
|
||||
to an @-object, not a %s",
|
||||
ty::ty_sort_str(fcx.tcx(), ty)));
|
||||
}
|
||||
|
||||
if err {
|
||||
fcx.tcx().sess.span_fatal(
|
||||
ex.span,
|
||||
fmt!("failed to find an implementation of trait \
|
||||
%s for %s",
|
||||
fcx.infcx().ty_to_str(target_ty),
|
||||
fcx.infcx().ty_to_str(ty)));
|
||||
}
|
||||
}
|
||||
Some(vtable) => {
|
||||
/*
|
||||
Map this expression to that vtable (that is: "ex has
|
||||
vtable <vtable>")
|
||||
*/
|
||||
if !is_early {
|
||||
let vtable_map = cx.vtable_map;
|
||||
vtable_map.insert(ex.id, @~[vtable]);
|
||||
}
|
||||
fcx.tcx().legacy_boxed_traits.insert(ex.id, ());
|
||||
}
|
||||
}
|
||||
(_, ty::vstore_uniq(*)) => {
|
||||
fcx.ccx.tcx.sess.span_err(
|
||||
ex.span,
|
||||
fmt!("can only cast an ~-pointer \
|
||||
to a ~-object, not a %s",
|
||||
ty::ty_sort_str(fcx.tcx(), ty)));
|
||||
}
|
||||
|
||||
(_, ty::vstore_slice(*)) => {
|
||||
fcx.ccx.tcx.sess.span_err(
|
||||
ex.span,
|
||||
fmt!("can only cast an &-pointer \
|
||||
to an &-object, not a %s",
|
||||
ty::ty_sort_str(fcx.tcx(), ty)));
|
||||
}
|
||||
|
||||
(_, ty::vstore_fixed(*)) => {
|
||||
fcx.tcx().sess.span_bug(
|
||||
ex.span,
|
||||
fmt!("trait with fixed vstore"));
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => { /* not a cast to a trait; ignore */ }
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ use syntax::ast;
|
||||
// function.
|
||||
pub enum Coerce = CombineFields;
|
||||
|
||||
impl Coerce {
|
||||
pub impl Coerce {
|
||||
fn tys(&self, a: ty::t, b: ty::t) -> CoerceResult {
|
||||
debug!("Coerce.tys(%s => %s)",
|
||||
a.inf_str(self.infcx),
|
||||
|
@ -316,7 +316,7 @@ pub fn super_modes<C:Combine>(
|
||||
ty::unify_mode(tcx, expected_found(self, a, b))
|
||||
}
|
||||
|
||||
fn super_args<C:Combine>(
|
||||
pub fn super_args<C:Combine>(
|
||||
self: &C, a: ty::arg, b: ty::arg)
|
||||
-> cres<ty::arg> {
|
||||
|
||||
|
@ -18,9 +18,14 @@ use middle::typeck::infer::lattice::*;
|
||||
use middle::typeck::infer::lub::Lub;
|
||||
use middle::typeck::infer::sub::Sub;
|
||||
use middle::typeck::infer::to_str::InferStr;
|
||||
use middle::typeck::infer::{cres, InferCtxt};
|
||||
use middle::typeck::isr_alist;
|
||||
use syntax::ast;
|
||||
use syntax::ast::{Many, Once, extern_fn, impure_fn, m_const, m_imm, m_mutbl};
|
||||
use syntax::ast::{noreturn, pure_fn, ret_style, return_val, unsafe_fn};
|
||||
use syntax::ast::{Onceness, purity};
|
||||
use syntax::codemap::span;
|
||||
use util::common::{indent, indenter};
|
||||
use util::ppaux::mt_to_str;
|
||||
|
||||
use std::list;
|
||||
|
@ -34,7 +34,7 @@
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use middle::ty::{RegionVid, TyVar};
|
||||
use middle::ty::{RegionVid, TyVar, Vid};
|
||||
use middle::ty;
|
||||
use middle::typeck::isr_alist;
|
||||
use middle::typeck::infer::*;
|
||||
@ -46,6 +46,7 @@ use middle::typeck::infer::sub::Sub;
|
||||
use middle::typeck::infer::lub::Lub;
|
||||
use middle::typeck::infer::glb::Glb;
|
||||
use middle::typeck::infer::to_str::InferStr;
|
||||
use util::common::indenter;
|
||||
|
||||
use std::list;
|
||||
|
||||
|
@ -17,12 +17,17 @@ use middle::typeck::infer::glb::Glb;
|
||||
use middle::typeck::infer::lattice::*;
|
||||
use middle::typeck::infer::sub::Sub;
|
||||
use middle::typeck::infer::to_str::InferStr;
|
||||
use middle::typeck::infer::{cres, InferCtxt};
|
||||
use middle::typeck::isr_alist;
|
||||
use util::common::indent;
|
||||
use util::ppaux::mt_to_str;
|
||||
|
||||
use std::list;
|
||||
use syntax::ast;
|
||||
use syntax::ast::{Many, Once, extern_fn, m_const, impure_fn, noreturn};
|
||||
use syntax::ast::{pure_fn, ret_style, return_val, unsafe_fn};
|
||||
use syntax::ast::{Onceness, purity};
|
||||
use syntax::codemap::span;
|
||||
|
||||
pub enum Lub = CombineFields; // least-upper-bound: common supertype
|
||||
|
||||
|
@ -551,7 +551,7 @@ struct Snapshot {
|
||||
region_vars_snapshot: uint,
|
||||
}
|
||||
|
||||
impl @mut InferCtxt {
|
||||
pub impl @mut InferCtxt {
|
||||
fn combine_fields(&self, a_is_expected: bool,
|
||||
span: span) -> CombineFields {
|
||||
CombineFields {infcx: *self,
|
||||
@ -643,7 +643,7 @@ fn next_simple_var<V:Copy,T:Copy>(
|
||||
return id;
|
||||
}
|
||||
|
||||
impl @mut InferCtxt {
|
||||
pub impl @mut InferCtxt {
|
||||
fn next_ty_var_id(&self) -> TyVid {
|
||||
let id = self.ty_var_counter;
|
||||
self.ty_var_counter += 1;
|
||||
|
@ -1218,7 +1218,7 @@ fn TwoRegionsMap() -> TwoRegionsMap {
|
||||
return HashMap();
|
||||
}
|
||||
|
||||
impl RegionVarBindings {
|
||||
pub impl RegionVarBindings {
|
||||
fn infer_variable_values(&mut self) -> ~[GraphNodeValue] {
|
||||
let mut graph = self.construct_graph();
|
||||
self.expansion(&mut graph);
|
||||
|
@ -11,6 +11,7 @@
|
||||
use core::prelude::*;
|
||||
|
||||
use middle::ty;
|
||||
use middle::ty::TyVar;
|
||||
use middle::typeck::check::regionmanip::replace_bound_regions_in_fn_sig;
|
||||
use middle::typeck::infer::combine::*;
|
||||
use middle::typeck::infer::cres;
|
||||
@ -19,11 +20,14 @@ use middle::typeck::infer::InferCtxt;
|
||||
use middle::typeck::infer::lub::Lub;
|
||||
use middle::typeck::infer::to_str::InferStr;
|
||||
use middle::typeck::infer::unify::*;
|
||||
use util::common::{indent, indenter};
|
||||
use util::ppaux::bound_region_to_str;
|
||||
|
||||
use std::list::Nil;
|
||||
use std::list;
|
||||
use syntax::ast::{m_const, purity, ret_style};
|
||||
use syntax::ast;
|
||||
use syntax::ast::{Onceness, m_const, purity, ret_style};
|
||||
use syntax::codemap::span;
|
||||
|
||||
|
||||
pub enum Sub = CombineFields; // "subtype", "subregion" etc
|
||||
|
@ -79,7 +79,7 @@ fn setup_env(test_name: &str, source_string: &str) -> Env {
|
||||
err_messages: messages};
|
||||
}
|
||||
|
||||
impl Env {
|
||||
pub impl Env {
|
||||
fn create_region_hierarchy(&self, rh: &RH) {
|
||||
for rh.sub.each |child_rh| {
|
||||
self.create_region_hierarchy(child_rh);
|
||||
|
@ -70,11 +70,11 @@ pub fn bound_self_region(rp: Option<ty::region_variance>)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct anon_rscope { anon: ty::Region, base: region_scope }
|
||||
pub struct anon_rscope { anon: ty::Region, base: @region_scope }
|
||||
pub fn in_anon_rscope<RS:region_scope + Copy + Durable>(self: RS,
|
||||
r: ty::Region)
|
||||
-> @anon_rscope {
|
||||
@anon_rscope {anon: r, base: self as region_scope}
|
||||
@anon_rscope {anon: r, base: @self as @region_scope}
|
||||
}
|
||||
|
||||
impl region_scope for @anon_rscope {
|
||||
@ -97,7 +97,7 @@ pub struct binding_rscope {
|
||||
|
||||
pub fn in_binding_rscope<RS:region_scope + Copy + Durable>(self: RS)
|
||||
-> @mut binding_rscope {
|
||||
let base = self as region_scope;
|
||||
let base = @self as @region_scope;
|
||||
@mut binding_rscope { base: base, anon_bindings: 0 }
|
||||
}
|
||||
|
||||
|
@ -174,7 +174,7 @@ pub struct IndexEntry {
|
||||
link: ~str
|
||||
}
|
||||
|
||||
impl Doc {
|
||||
pub impl Doc {
|
||||
fn CrateDoc(&self) -> CrateDoc {
|
||||
option::get(vec::foldl(None, self.pages, |_m, page| {
|
||||
match copy *page {
|
||||
@ -190,7 +190,7 @@ impl Doc {
|
||||
}
|
||||
|
||||
/// Some helper methods on ModDoc, mostly for testing
|
||||
impl ModDoc {
|
||||
pub impl ModDoc {
|
||||
fn mods(&self) -> ~[ModDoc] {
|
||||
do vec::filter_mapped(self.items) |itemtag| {
|
||||
match copy *itemtag {
|
||||
|
@ -51,7 +51,7 @@ fn test() {
|
||||
fn ifn() { } \
|
||||
enum ienum { ivar } \
|
||||
trait itrait { fn a(); } \
|
||||
impl int { fn a() { } } \
|
||||
pub impl int { fn a() { } } \
|
||||
type itype = int; \
|
||||
struct istruct { f: () }";
|
||||
do astsrv::from_str(source) |srv| {
|
||||
|
@ -21,7 +21,7 @@ use core::cell::Cell;
|
||||
use core::pipes;
|
||||
use core::prelude::*;
|
||||
use core::private::{SharedMutableState, shared_mutable_state};
|
||||
use core::private::{clone_shared_mutable_state, unwrap_shared_mutable_state};
|
||||
use core::private::{clone_shared_mutable_state};
|
||||
use core::private::{get_shared_mutable_state, get_shared_immutable_state};
|
||||
use core::ptr;
|
||||
use core::task;
|
||||
@ -30,7 +30,7 @@ use core::util;
|
||||
/// As sync::condvar, a mechanism for unlock-and-descheduling and signalling.
|
||||
pub struct Condvar { is_mutex: bool, failed: &mut bool, cond: &sync::Condvar }
|
||||
|
||||
impl &Condvar {
|
||||
pub impl &Condvar {
|
||||
/// Atomically exit the associated ARC and block until a signal is sent.
|
||||
#[inline(always)]
|
||||
fn wait() { self.wait_on(0) }
|
||||
@ -104,20 +104,6 @@ pub fn clone<T:Const + Owned>(rc: &ARC<T>) -> ARC<T> {
|
||||
ARC { x: unsafe { clone_shared_mutable_state(&rc.x) } }
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the data back out of the ARC. This function blocks until the
|
||||
* reference given to it is the last existing one, and then unwrap the data
|
||||
* instead of destroying it.
|
||||
*
|
||||
* If multiple tasks call unwrap, all but the first will fail. Do not call
|
||||
* unwrap from a task that holds another reference to the same ARC; it is
|
||||
* guaranteed to deadlock.
|
||||
*/
|
||||
pub fn unwrap<T:Const + Owned>(rc: ARC<T>) -> T {
|
||||
let ARC { x: x } = rc;
|
||||
unsafe { unwrap_shared_mutable_state(x) }
|
||||
}
|
||||
|
||||
impl<T:Const + Owned> Clone for ARC<T> {
|
||||
fn clone(&self) -> ARC<T> {
|
||||
clone(self)
|
||||
@ -158,7 +144,7 @@ impl<T:Owned> Clone for MutexARC<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Owned> &MutexARC<T> {
|
||||
pub impl<T:Owned> &MutexARC<T> {
|
||||
|
||||
/**
|
||||
* Access the underlying mutable data with mutual exclusion from other
|
||||
@ -213,23 +199,6 @@ impl<T:Owned> &MutexARC<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the data, blocking until all other references are dropped,
|
||||
* exactly as arc::unwrap.
|
||||
*
|
||||
* Will additionally fail if another task has failed while accessing the arc.
|
||||
*/
|
||||
// FIXME(#3724) make this a by-move method on the arc
|
||||
pub fn unwrap_mutex_arc<T:Owned>(arc: MutexARC<T>) -> T {
|
||||
let MutexARC { x: x } = arc;
|
||||
let inner = unsafe { unwrap_shared_mutable_state(x) };
|
||||
let MutexARCInner { failed: failed, data: data, _ } = inner;
|
||||
if failed {
|
||||
fail!(~"Can't unwrap poisoned MutexARC - another task failed inside!")
|
||||
}
|
||||
data
|
||||
}
|
||||
|
||||
// Common code for {mutex.access,rwlock.write}{,_cond}.
|
||||
#[inline(always)]
|
||||
#[doc(hidden)]
|
||||
@ -301,7 +270,7 @@ pub fn rw_arc_with_condvars<T:Const + Owned>(
|
||||
RWARC { x: unsafe { shared_mutable_state(data) }, cant_nest: () }
|
||||
}
|
||||
|
||||
impl<T:Const + Owned> RWARC<T> {
|
||||
pub impl<T:Const + Owned> RWARC<T> {
|
||||
/// Duplicate a rwlock-protected ARC, as arc::clone.
|
||||
fn clone(&self) -> RWARC<T> {
|
||||
RWARC { x: unsafe { clone_shared_mutable_state(&self.x) },
|
||||
@ -310,7 +279,7 @@ impl<T:Const + Owned> RWARC<T> {
|
||||
|
||||
}
|
||||
|
||||
impl<T:Const + Owned> &RWARC<T> {
|
||||
pub impl<T:Const + Owned> &RWARC<T> {
|
||||
/**
|
||||
* Access the underlying data mutably. Locks the rwlock in write mode;
|
||||
* other readers and writers will block.
|
||||
@ -411,24 +380,6 @@ impl<T:Const + Owned> &RWARC<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the data, blocking until all other references are dropped,
|
||||
* exactly as arc::unwrap.
|
||||
*
|
||||
* Will additionally fail if another task has failed while accessing the arc
|
||||
* in write mode.
|
||||
*/
|
||||
// FIXME(#3724) make this a by-move method on the arc
|
||||
pub fn unwrap_rw_arc<T:Const + Owned>(arc: RWARC<T>) -> T {
|
||||
let RWARC { x: x, _ } = arc;
|
||||
let inner = unsafe { unwrap_shared_mutable_state(x) };
|
||||
let RWARCInner { failed: failed, data: data, _ } = inner;
|
||||
if failed {
|
||||
fail!(~"Can't unwrap poisoned RWARC - another task failed inside!")
|
||||
}
|
||||
data
|
||||
}
|
||||
|
||||
// Borrowck rightly complains about immutably aliasing the rwlock in order to
|
||||
// lock it. This wraps the unsafety, with the justification that the 'lock'
|
||||
// field is never overwritten; only 'failed' and 'data'.
|
||||
@ -445,7 +396,7 @@ pub enum RWWriteMode<T> =
|
||||
/// The "read permission" token used for RWARC.write_downgrade().
|
||||
pub enum RWReadMode<T> = (&T, sync::RWlockReadMode);
|
||||
|
||||
impl<T:Const + Owned> &RWWriteMode<T> {
|
||||
pub impl<T:Const + Owned> &RWWriteMode<T> {
|
||||
/// Access the pre-downgrade RWARC in write mode.
|
||||
fn write<U>(blk: fn(x: &mut T) -> U) -> U {
|
||||
match *self {
|
||||
@ -475,7 +426,7 @@ impl<T:Const + Owned> &RWWriteMode<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Const + Owned> &RWReadMode<T> {
|
||||
pub impl<T:Const + Owned> &RWReadMode<T> {
|
||||
/// Access the post-downgrade rwlock in read mode.
|
||||
fn read<U>(blk: fn(x: &T) -> U) -> U {
|
||||
match *self {
|
||||
@ -497,6 +448,7 @@ mod tests {
|
||||
use arc::*;
|
||||
use arc;
|
||||
|
||||
use core::cell::Cell;
|
||||
use core::option::{Some, None};
|
||||
use core::option;
|
||||
use core::pipes;
|
||||
@ -585,21 +537,6 @@ mod tests {
|
||||
}
|
||||
}
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
pub fn test_mutex_arc_unwrap_poison() {
|
||||
let arc = MutexARC(1);
|
||||
let arc2 = ~(&arc).clone();
|
||||
let (p, c) = comm::stream();
|
||||
do task::spawn || {
|
||||
do arc2.access |one| {
|
||||
c.send(());
|
||||
assert *one == 2;
|
||||
}
|
||||
}
|
||||
let _ = p.recv();
|
||||
let one = unwrap_mutex_arc(arc);
|
||||
assert one == 1;
|
||||
}
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
pub fn test_rw_arc_poison_wr() {
|
||||
let arc = ~RWARC(1);
|
||||
let arc2 = ~arc.clone();
|
||||
|
@ -161,7 +161,7 @@ unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TypeDesc, bool) {
|
||||
(reinterpret_cast(&(p & !1)), p & 1 == 1)
|
||||
}
|
||||
|
||||
impl &Arena {
|
||||
pub impl &Arena {
|
||||
// Functions for the POD part of the arena
|
||||
fn alloc_pod_grow(n_bytes: uint, align: uint) -> *u8 {
|
||||
// Allocate a new chunk.
|
||||
|
@ -27,7 +27,7 @@ fn small_mask(nbits: uint) -> uint {
|
||||
(1 << nbits) - 1
|
||||
}
|
||||
|
||||
impl SmallBitv {
|
||||
pub impl SmallBitv {
|
||||
static fn new(bits: uint) -> SmallBitv {
|
||||
SmallBitv {bits: bits}
|
||||
}
|
||||
@ -124,7 +124,7 @@ fn big_mask(nbits: uint, elem: uint) -> uint {
|
||||
}
|
||||
}
|
||||
|
||||
impl BigBitv {
|
||||
pub impl BigBitv {
|
||||
static fn new(storage: ~[uint]) -> BigBitv {
|
||||
BigBitv {storage: storage}
|
||||
}
|
||||
@ -256,7 +256,7 @@ priv impl Bitv {
|
||||
|
||||
}
|
||||
|
||||
impl Bitv {
|
||||
pub impl Bitv {
|
||||
static fn new(nbits: uint, init: bool) -> Bitv {
|
||||
let rep = if nbits <= uint::bits {
|
||||
Small(~SmallBitv::new(if init {!0} else {0}))
|
||||
@ -591,7 +591,7 @@ pub struct BitvSet {
|
||||
priv bitv: BigBitv
|
||||
}
|
||||
|
||||
impl BitvSet {
|
||||
pub impl BitvSet {
|
||||
/// Creates a new bit vector set with initially no contents
|
||||
static fn new() -> BitvSet {
|
||||
BitvSet{ size: 0, bitv: BigBitv::new(~[0]) }
|
||||
|
@ -37,7 +37,7 @@ impl<T> Mutable for Deque<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deque<T> {
|
||||
pub impl<T> Deque<T> {
|
||||
static pure fn new() -> Deque<T> {
|
||||
Deque{nelts: 0, lo: 0, hi: 0,
|
||||
elts: vec::from_fn(initial_capacity, |_| None)}
|
||||
@ -116,6 +116,9 @@ fn get<T>(elts: &r/[Option<T>], i: uint) -> &r/T {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use core::cmp::Eq;
|
||||
use core::kinds::{Durable, Copy};
|
||||
use core::prelude::debug;
|
||||
|
||||
#[test]
|
||||
fn test_simple() {
|
||||
|
@ -279,7 +279,7 @@ pub mod reader {
|
||||
}
|
||||
}
|
||||
|
||||
impl Decoder {
|
||||
pub impl Decoder {
|
||||
fn read_opaque<R>(&self, op: fn(Doc) -> R) -> R {
|
||||
do self.push_doc(self.next_doc(EsOpaque)) {
|
||||
op(copy self.parent)
|
||||
@ -451,7 +451,7 @@ pub mod writer {
|
||||
}
|
||||
|
||||
// FIXME (#2741): Provide a function to write the standard ebml header.
|
||||
impl Encoder {
|
||||
pub impl Encoder {
|
||||
fn start_tag(tag_id: uint) {
|
||||
debug!("Start tag %u", tag_id);
|
||||
|
||||
@ -571,7 +571,7 @@ pub mod writer {
|
||||
}
|
||||
}
|
||||
|
||||
impl Encoder {
|
||||
pub impl Encoder {
|
||||
fn emit_opaque(&self, f: fn()) {
|
||||
do self.wr_tag(EsOpaque as uint) {
|
||||
f()
|
||||
|
@ -636,6 +636,7 @@ mod test {
|
||||
use DefaultEncoder = json::Encoder;
|
||||
use DefaultDecoder = json::Decoder;
|
||||
|
||||
use flatpipes::{Flattener, Unflattener};
|
||||
use flatpipes::flatteners::*;
|
||||
use flatpipes::bytepipes::*;
|
||||
use flatpipes::pod;
|
||||
@ -647,7 +648,7 @@ mod test {
|
||||
|
||||
use core::dvec::DVec;
|
||||
use core::int;
|
||||
use core::io::BytesReader;
|
||||
use core::io::{BytesReader, BytesWriter};
|
||||
use core::io;
|
||||
use core::prelude::*;
|
||||
use core::result;
|
||||
|
@ -49,14 +49,14 @@ priv enum FutureState<A> {
|
||||
}
|
||||
|
||||
/// Methods on the `future` type
|
||||
impl<A:Copy> Future<A> {
|
||||
pub impl<A:Copy> Future<A> {
|
||||
fn get() -> A {
|
||||
//! Get the value of the future
|
||||
*(self.get_ref())
|
||||
}
|
||||
}
|
||||
|
||||
impl<A> Future<A> {
|
||||
pub impl<A> Future<A> {
|
||||
|
||||
pure fn get_ref(&self) -> &self/A {
|
||||
/*!
|
||||
@ -150,7 +150,7 @@ pub mod test {
|
||||
|
||||
use future::*;
|
||||
|
||||
use core::comm::oneshot;
|
||||
use core::comm::{oneshot, send_one};
|
||||
use core::task;
|
||||
|
||||
#[test]
|
||||
|
@ -445,7 +445,7 @@ pub fn opt_default(mm: &Matches, nm: &str, def: &str) -> Option<~str> {
|
||||
}
|
||||
|
||||
#[deriving_eq]
|
||||
enum FailType {
|
||||
pub enum FailType {
|
||||
ArgumentMissing_,
|
||||
UnrecognizedOption_,
|
||||
OptionMissing_,
|
||||
|
@ -1208,6 +1208,7 @@ mod tests {
|
||||
use core::prelude::*;
|
||||
|
||||
use json::*;
|
||||
use serialize;
|
||||
|
||||
use core::result;
|
||||
use core::hashmap::linear::LinearMap;
|
||||
|
@ -820,7 +820,7 @@ pub fn socket_buf(sock: TcpSocket) -> TcpSocketBuf {
|
||||
}
|
||||
|
||||
/// Convenience methods extending `net::tcp::tcp_socket`
|
||||
impl TcpSocket {
|
||||
pub impl TcpSocket {
|
||||
pub fn read_start() -> result::Result<@Port<
|
||||
result::Result<~[u8], TcpErrData>>, TcpErrData> {
|
||||
read_start(&self)
|
||||
|
@ -730,6 +730,91 @@ impl to_bytes::IterBytes for Url {
|
||||
}
|
||||
}
|
||||
|
||||
// Put a few tests outside of the 'test' module so they can test the internal
|
||||
// functions and those functions don't need 'pub'
|
||||
|
||||
#[test]
|
||||
fn test_split_char_first() {
|
||||
let (u,v) = split_char_first(~"hello, sweet world", ',');
|
||||
assert u == ~"hello";
|
||||
assert v == ~" sweet world";
|
||||
|
||||
let (u,v) = split_char_first(~"hello sweet world", ',');
|
||||
assert u == ~"hello sweet world";
|
||||
assert v == ~"";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_authority() {
|
||||
let (u, h, p, r) = get_authority(
|
||||
"//user:pass@rust-lang.org/something").unwrap();
|
||||
assert u == Some(UserInfo::new(~"user", Some(~"pass")));
|
||||
assert h == ~"rust-lang.org";
|
||||
assert p.is_none();
|
||||
assert r == ~"/something";
|
||||
|
||||
let (u, h, p, r) = get_authority(
|
||||
"//rust-lang.org:8000?something").unwrap();
|
||||
assert u.is_none();
|
||||
assert h == ~"rust-lang.org";
|
||||
assert p == Some(~"8000");
|
||||
assert r == ~"?something";
|
||||
|
||||
let (u, h, p, r) = get_authority(
|
||||
"//rust-lang.org#blah").unwrap();
|
||||
assert u.is_none();
|
||||
assert h == ~"rust-lang.org";
|
||||
assert p.is_none();
|
||||
assert r == ~"#blah";
|
||||
|
||||
// ipv6 tests
|
||||
let (_, h, _, _) = get_authority(
|
||||
"//2001:0db8:85a3:0042:0000:8a2e:0370:7334#blah").unwrap();
|
||||
assert h == ~"2001:0db8:85a3:0042:0000:8a2e:0370:7334";
|
||||
|
||||
let (_, h, p, _) = get_authority(
|
||||
"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000#blah").unwrap();
|
||||
assert h == ~"2001:0db8:85a3:0042:0000:8a2e:0370:7334";
|
||||
assert p == Some(~"8000");
|
||||
|
||||
let (u, h, p, _) = get_authority(
|
||||
"//us:p@2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000#blah"
|
||||
).unwrap();
|
||||
assert u == Some(UserInfo::new(~"us", Some(~"p")));
|
||||
assert h == ~"2001:0db8:85a3:0042:0000:8a2e:0370:7334";
|
||||
assert p == Some(~"8000");
|
||||
|
||||
// invalid authorities;
|
||||
assert get_authority("//user:pass@rust-lang:something").is_err();
|
||||
assert get_authority("//user@rust-lang:something:/path").is_err();
|
||||
assert get_authority(
|
||||
"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:800a").is_err();
|
||||
assert get_authority(
|
||||
"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000:00").is_err();
|
||||
|
||||
// these parse as empty, because they don't start with '//'
|
||||
let (_, h, _, _) = get_authority(~"user:pass@rust-lang").unwrap();
|
||||
assert h == ~"";
|
||||
let (_, h, _, _) = get_authority(~"rust-lang.org").unwrap();
|
||||
assert h == ~"";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_path() {
|
||||
let (p, r) = get_path("/something+%20orother", true).unwrap();
|
||||
assert p == ~"/something+ orother";
|
||||
assert r == ~"";
|
||||
let (p, r) = get_path("test@email.com#fragment", false).unwrap();
|
||||
assert p == ~"test@email.com";
|
||||
assert r == ~"#fragment";
|
||||
let (p, r) = get_path(~"/gen/:addr=?q=v", false).unwrap();
|
||||
assert p == ~"/gen/:addr=";
|
||||
assert r == ~"?q=v";
|
||||
|
||||
//failure cases
|
||||
assert get_path(~"something?q", true).is_err();
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use core::prelude::*;
|
||||
@ -737,91 +822,10 @@ mod tests {
|
||||
use net_url::*;
|
||||
use net_url::UserInfo;
|
||||
|
||||
use core::hashmap::linear::LinearMap;
|
||||
use core::result;
|
||||
use core::str;
|
||||
|
||||
#[test]
|
||||
pub fn test_split_char_first() {
|
||||
let (u,v) = split_char_first(~"hello, sweet world", ',');
|
||||
assert u == ~"hello";
|
||||
assert v == ~" sweet world";
|
||||
|
||||
let (u,v) = split_char_first(~"hello sweet world", ',');
|
||||
assert u == ~"hello sweet world";
|
||||
assert v == ~"";
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_get_authority() {
|
||||
let (u, h, p, r) = get_authority(
|
||||
"//user:pass@rust-lang.org/something").unwrap();
|
||||
assert u == Some(UserInfo::new(~"user", Some(~"pass")));
|
||||
assert h == ~"rust-lang.org";
|
||||
assert p.is_none();
|
||||
assert r == ~"/something";
|
||||
|
||||
let (u, h, p, r) = get_authority(
|
||||
"//rust-lang.org:8000?something").unwrap();
|
||||
assert u.is_none();
|
||||
assert h == ~"rust-lang.org";
|
||||
assert p == Some(~"8000");
|
||||
assert r == ~"?something";
|
||||
|
||||
let (u, h, p, r) = get_authority(
|
||||
"//rust-lang.org#blah").unwrap();
|
||||
assert u.is_none();
|
||||
assert h == ~"rust-lang.org";
|
||||
assert p.is_none();
|
||||
assert r == ~"#blah";
|
||||
|
||||
// ipv6 tests
|
||||
let (_, h, _, _) = get_authority(
|
||||
"//2001:0db8:85a3:0042:0000:8a2e:0370:7334#blah").unwrap();
|
||||
assert h == ~"2001:0db8:85a3:0042:0000:8a2e:0370:7334";
|
||||
|
||||
let (_, h, p, _) = get_authority(
|
||||
"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000#blah").unwrap();
|
||||
assert h == ~"2001:0db8:85a3:0042:0000:8a2e:0370:7334";
|
||||
assert p == Some(~"8000");
|
||||
|
||||
let (u, h, p, _) = get_authority(
|
||||
"//us:p@2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000#blah"
|
||||
).unwrap();
|
||||
assert u == Some(UserInfo::new(~"us", Some(~"p")));
|
||||
assert h == ~"2001:0db8:85a3:0042:0000:8a2e:0370:7334";
|
||||
assert p == Some(~"8000");
|
||||
|
||||
// invalid authorities;
|
||||
assert get_authority("//user:pass@rust-lang:something").is_err();
|
||||
assert get_authority("//user@rust-lang:something:/path").is_err();
|
||||
assert get_authority(
|
||||
"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:800a").is_err();
|
||||
assert get_authority(
|
||||
"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000:00").is_err();
|
||||
|
||||
// these parse as empty, because they don't start with '//'
|
||||
let (_, h, _, _) = get_authority(~"user:pass@rust-lang").unwrap();
|
||||
assert h == ~"";
|
||||
let (_, h, _, _) = get_authority(~"rust-lang.org").unwrap();
|
||||
assert h == ~"";
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_get_path() {
|
||||
let (p, r) = get_path("/something+%20orother", true).unwrap();
|
||||
assert p == ~"/something+ orother";
|
||||
assert r == ~"";
|
||||
let (p, r) = get_path("test@email.com#fragment", false).unwrap();
|
||||
assert p == ~"test@email.com";
|
||||
assert r == ~"#fragment";
|
||||
let (p, r) = get_path(~"/gen/:addr=?q=v", false).unwrap();
|
||||
assert p == ~"/gen/:addr=";
|
||||
assert r == ~"?q=v";
|
||||
|
||||
//failure cases
|
||||
assert get_path(~"something?q", true).is_err();
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_url_parse() {
|
||||
let url = ~"http://user:pass@rust-lang.org/doc?s=v#something";
|
||||
|
@ -134,7 +134,9 @@ pub mod chained {
|
||||
}
|
||||
self.chains = new_chains;
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<K:Eq + IterBytes + Hash,V> T<K, V> {
|
||||
pure fn each_entry(blk: fn(@Entry<K,V>) -> bool) {
|
||||
// n.b. we can't use vec::iter() here because self.chains
|
||||
// is stored in a mutable location.
|
||||
@ -168,7 +170,7 @@ pub mod chained {
|
||||
}
|
||||
}
|
||||
|
||||
impl<K:Eq + IterBytes + Hash,V> T<K, V> {
|
||||
pub impl<K:Eq + IterBytes + Hash,V> T<K, V> {
|
||||
pure fn contains_key(&self, k: &K) -> bool {
|
||||
let hash = k.hash_keyed(0,0) as uint;
|
||||
match self.search_tbl(k, hash) {
|
||||
@ -252,7 +254,7 @@ pub mod chained {
|
||||
}
|
||||
}
|
||||
|
||||
impl<K:Eq + IterBytes + Hash + Copy,V:Copy> T<K, V> {
|
||||
pub impl<K:Eq + IterBytes + Hash + Copy,V:Copy> T<K, V> {
|
||||
pure fn find(&self, k: &K) -> Option<V> {
|
||||
match self.search_tbl(k, k.hash_keyed(0,0) as uint) {
|
||||
NotFound => None,
|
||||
@ -325,7 +327,7 @@ pub mod chained {
|
||||
}
|
||||
}
|
||||
|
||||
impl<K:Eq + IterBytes + Hash + Copy + ToStr,V:ToStr + Copy> T<K, V> {
|
||||
pub impl<K:Eq + IterBytes + Hash + Copy + ToStr,V:ToStr + Copy> T<K, V> {
|
||||
fn to_writer(wr: io::Writer) {
|
||||
if self.count == 0u {
|
||||
wr.write_str(~"{}");
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user