This commit is contained in:
Matthew McPherrin 2013-02-08 15:21:46 -05:00
commit 46df7985a5
234 changed files with 3011 additions and 4160 deletions

View File

@ -1,3 +1,9 @@
Version 0.6 (?)
---------------------------
* Libraries
* `core::send_map` renamed to `core::hashmap`
Version 0.5 (December 2012)
---------------------------

2
configure vendored
View File

@ -515,7 +515,7 @@ then
| cut -d ' ' -f 2)
case $CFG_CLANG_VERSION in
(3.0svn | 3.0 | 3.1* | 3.2* | 4.0* | 4.1*)
(3.0svn | 3.0 | 3.1* | 3.2* | 4.0* | 4.1* | 4.2*)
step_msg "found ok version of CLANG: $CFG_CLANG_VERSION"
CFG_C_COMPILER="clang"
;;

View File

@ -45,7 +45,7 @@ doc/rust.html: rust.md doc/version_info.html doc/rust.css doc/manual.css
--from=markdown --to=html \
--css=rust.css \
--css=manual.css \
--include-before-body=doc/version_info.html \
--include-before-body=doc/version_info.html \
--output=$@
endif
@ -66,6 +66,7 @@ doc/rust.tex: rust.md doc/version.md
"$(CFG_PANDOC)" \
--standalone --toc \
--number-sections \
--include-before-body=doc/version.md \
--from=markdown --to=latex \
--output=$@
@ -199,16 +200,17 @@ ifdef CFG_DISABLE_DOCS
endif
doc/version.md: $(MKFILE_DEPS) rust.md
doc/version.md: $(MKFILE_DEPS) $(wildcard $(S)doc/*.*)
@$(call E, version-stamp: $@)
$(Q)echo "$(CFG_VERSION)" >$@
doc/version_info.html: version_info.html.template
doc/version_info.html: version_info.html.template $(MKFILE_DEPS) \
$(wildcard $(S)doc/*.*)
@$(call E, version-info: $@)
sed -e "s/VERSION/$(CFG_RELEASE)/; s/SHORT_HASH/$(shell echo \
$(CFG_VER_HASH) | head -c 8)/;\
s/STAMP/$(CFG_VER_HASH)/;" $< >$@
GENERATED += doc/version.md
GENERATED += doc/version.md doc/version_info.html
docs: $(DOCS)

View File

@ -159,7 +159,7 @@ pub fn test_opts(config: config) -> test::TestOpts {
}
}
pub fn make_tests(config: config) -> ~[test::TestDesc] {
pub fn make_tests(config: config) -> ~[test::TestDescAndFn] {
debug!("making tests from %s",
config.src_base.to_str());
let mut tests = ~[];
@ -196,13 +196,14 @@ pub fn is_test(config: config, testfile: &Path) -> bool {
return valid;
}
pub fn make_test(config: config, testfile: &Path) ->
test::TestDesc {
test::TestDesc {
name: make_test_name(config, testfile),
pub fn make_test(config: config, testfile: &Path) -> test::TestDescAndFn {
test::TestDescAndFn {
desc: test::TestDesc {
name: make_test_name(config, testfile),
ignore: header::is_test_ignored(config, testfile),
should_fail: false
},
testfn: make_test_closure(config, testfile),
ignore: header::is_test_ignored(config, testfile),
should_fail: false
}
}

View File

@ -731,7 +731,7 @@ pub fn configure(opts: Options) -> Cargo {
need_dir(&c.bindir);
for sources.each_key_ref |&k| {
let mut s = sources.get(k);
let mut s = sources.get(&k);
load_source_packages(&c, s);
sources.insert(k, s);
}
@ -981,7 +981,7 @@ pub fn install_named(c: &mut Cargo, wd: &Path, name: ~str) {
pub fn install_uuid_specific(c: &mut Cargo, wd: &Path, src: ~str,
uuid: ~str) {
match c.sources.find(src) {
match c.sources.find(&src) {
Some(s) => {
for s.packages.each |p| {
if p.uuid == uuid {
@ -997,7 +997,7 @@ pub fn install_uuid_specific(c: &mut Cargo, wd: &Path, src: ~str,
pub fn install_named_specific(c: &mut Cargo, wd: &Path, src: ~str,
name: ~str) {
match c.sources.find(src) {
match c.sources.find(&src) {
Some(s) => {
for s.packages.each |p| {
if p.name == name {
@ -1064,7 +1064,7 @@ pub fn cmd_uninstall(c: &Cargo) {
}
pub fn install_query(c: &mut Cargo, wd: &Path, target: ~str) {
match c.dep_cache.find(target) {
match c.dep_cache.find(&target) {
Some(inst) => {
if inst {
return;
@ -1156,7 +1156,7 @@ pub fn cmd_install(c: &mut Cargo) {
pub fn sync(c: &Cargo) {
for c.sources.each_key_ref |&k| {
let mut s = c.sources.get(k);
let mut s = c.sources.get(&k);
sync_one(c, s);
c.sources.insert(k, s);
}
@ -1558,7 +1558,7 @@ pub fn cmd_list(c: &Cargo) {
if !valid_pkg_name(*name) {
error(fmt!("'%s' is an invalid source name", *name));
} else {
match c.sources.find(*name) {
match c.sources.find(name) {
Some(source) => {
print_source(source);
}
@ -1754,7 +1754,7 @@ pub fn cmd_sources(c: &Cargo) {
return;
}
match c.sources.find(name) {
match c.sources.find(&name) {
Some(source) => {
let old = copy source.url;
let method = assume_source_method(url);
@ -1785,7 +1785,7 @@ pub fn cmd_sources(c: &Cargo) {
return;
}
match c.sources.find(name) {
match c.sources.find(&name) {
Some(source) => {
let old = copy source.method;
@ -1823,7 +1823,7 @@ pub fn cmd_sources(c: &Cargo) {
return;
}
match c.sources.find(name) {
match c.sources.find(&name) {
Some(source) => {
c.sources.remove(&name);
c.sources.insert(newn, source);

View File

@ -10,10 +10,6 @@
//! Managed vectors
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use cast::transmute;
use kinds::Copy;
use iter;

View File

@ -9,10 +9,6 @@
// except according to those terms.
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
//! Boolean logic
use bool;

View File

@ -8,9 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! Unsafe operations
#[forbid(deprecated_mode)]
#[abi = "rust-intrinsic"]
extern mod rusti {
fn forget<T>(-x: T);

View File

@ -10,10 +10,6 @@
//! Utilities for manipulating the char type
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use char;
use cmp::Eq;
use option::{None, Option, Some};

View File

@ -10,10 +10,6 @@
#[doc(hidden)];
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use libc::{c_char, c_void, intptr_t, uintptr_t};
use ptr::{mut_null, null, to_unsafe_ptr};
use repr::BoxRepr;

View File

@ -20,10 +20,6 @@ and `Eq` to overload the `==` and `!=` operators.
*/
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
/**
* Trait for values that can be compared for equality
* and inequality.

View File

@ -10,9 +10,6 @@
//! Container traits
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use option::Option;
pub trait Container {

View File

@ -48,8 +48,6 @@ Implicitly, all crates behave as if they included the following prologue:
// Don't link to core. We are core.
#[no_core];
#[warn(deprecated_mode)];
#[warn(deprecated_pattern)];
#[warn(vecs_implicitly_copyable)];
#[deny(non_camel_case_types)];
#[allow(deprecated_self)];

View File

@ -18,10 +18,6 @@ Do not use ==, !=, <, etc on doubly-linked lists -- it may not terminate.
*/
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use kinds::Copy;
use managed;
use option::{None, Option, Some};

View File

@ -19,10 +19,6 @@ Note that recursive use is not permitted.
*/
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use cast;
use cast::reinterpret_cast;
use prelude::*;

View File

@ -8,10 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
//! A type that represents one of two alternatives
use cmp::Eq;

View File

@ -51,10 +51,6 @@
//! * s - str (any flavor)
//! * ? - arbitrary type (does not use the to_str trait)
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
// Transitional
#[allow(structural_records)]; // Macros -- needs a snapshot
@ -499,12 +495,6 @@ pub mod rt {
pub enum Ty { TyDefault, TyBits, TyHexUpper, TyHexLower, TyOctal, }
#[cfg(stage0)]
pub type Conv = {flags: u32, width: Count, precision: Count, ty: Ty};
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
pub struct Conv {
flags: u32,
width: Count,

View File

@ -14,10 +14,6 @@ Simple compression
*/
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use libc;
use libc::{c_void, size_t, c_int};
use ptr;

View File

@ -10,10 +10,6 @@
//! The trait for types that can be created from strings
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use option::Option;
pub trait FromStr {

View File

@ -35,9 +35,6 @@ with destructors.
*/
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
// Transitional
#[allow(structural_records)];

View File

@ -8,10 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
/*!
* Implementation of SipHash 2-4
*

View File

@ -10,10 +10,6 @@
//! Sendable hash maps.
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use container::{Container, Mutable, Map, Set};
use cmp::Eq;
use hash::Hash;
@ -49,9 +45,8 @@ pub mod linear {
buckets: ~[Option<Bucket<K, V>>],
}
// FIXME(#3148) -- we could rewrite FoundEntry
// to have type Option<&Bucket<K, V>> which would be nifty
// However, that won't work until #3148 is fixed
// We could rewrite FoundEntry to have type Option<&Bucket<K, V>>
// which would be nifty
enum SearchResult {
FoundEntry(uint), FoundHole(uint), TableFull
}
@ -296,8 +291,6 @@ pub mod linear {
FoundEntry(idx) => {
match self.buckets[idx] {
Some(ref bkt) => {
// FIXME(#3148)---should be inferred
let bkt: &self/Bucket<K, V> = bkt;
Some(&bkt.value)
}
None => {

View File

@ -14,9 +14,6 @@ Basic input/output
*/
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use result::Result;
use cmp::Eq;
@ -490,11 +487,11 @@ pub fn FILERes(f: *libc::FILE) -> FILERes {
}
}
pub fn FILE_reader(f: *libc::FILE, cleanup: bool) -> Reader {
pub fn FILE_reader(f: *libc::FILE, cleanup: bool) -> @Reader {
if cleanup {
Wrapper { base: f, cleanup: FILERes(f) } as Reader
@Wrapper { base: f, cleanup: FILERes(f) } as @Reader
} else {
f as Reader
@f as @Reader
}
}
@ -502,13 +499,13 @@ pub fn FILE_reader(f: *libc::FILE, cleanup: bool) -> Reader {
// top-level functions that take a reader, or a set of default methods on
// reader (which can then be called reader)
pub fn stdin() -> Reader {
pub fn stdin() -> @Reader {
unsafe {
rustrt::rust_get_stdin() as Reader
rustrt::rust_get_stdin() as @Reader
}
}
pub fn file_reader(path: &Path) -> Result<Reader, ~str> {
pub fn file_reader(path: &Path) -> Result<@Reader, ~str> {
unsafe {
let f = os::as_c_charp(path.to_str(), |pathbuf| {
os::as_c_charp("r", |modebuf|
@ -555,11 +552,11 @@ impl BytesReader: Reader {
fn tell(&self) -> uint { self.pos }
}
pub pure fn with_bytes_reader<t>(bytes: &[u8], f: fn(Reader) -> t) -> t {
f(BytesReader { bytes: bytes, pos: 0u } as Reader)
pub pure fn with_bytes_reader<t>(bytes: &[u8], f: fn(@Reader) -> t) -> t {
f(@BytesReader { bytes: bytes, pos: 0u } as @Reader)
}
pub pure fn with_str_reader<T>(s: &str, f: fn(Reader) -> T) -> T {
pub pure fn with_str_reader<T>(s: &str, f: fn(@Reader) -> T) -> T {
str::byte_slice(s, |bytes| with_bytes_reader(bytes, f))
}

View File

@ -12,9 +12,6 @@
// workaround our lack of traits and lack of macros. See core.{rc,rs} for
// how this file is used.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use cmp::{Eq, Ord};
use iter::BaseIter;
use iter;

View File

@ -14,9 +14,6 @@ The iteration traits and common implementation
*/
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use cmp::{Eq, Ord};
use kinds::Copy;
use option::{None, Option, Some};

View File

@ -8,9 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
/*!
* Bindings for libc.
*

View File

@ -10,10 +10,6 @@
//! Logging
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use cast::transmute;
use io;
use libc;

View File

@ -10,10 +10,6 @@
//! Operations on managed box types
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use cast::transmute;
use cmp::{Eq, Ord};
use managed::raw::BoxRepr;

View File

@ -18,8 +18,6 @@ dynamic checks: your program will fail if you attempt to perform
mutation when the data structure should be immutable.
*/
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use util::with;
use cast::transmute_immut;

View File

@ -14,10 +14,6 @@ Functions for the unit type.
*/
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use cmp::{Eq, Ord};
#[cfg(notest)]

View File

@ -9,9 +9,6 @@
// except according to those terms.
#[doc(hidden)]; // FIXME #3538
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use libc::c_int;
use libc::c_float;

View File

@ -8,10 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
//! Operations and constants for `f32`
use cmath;

View File

@ -8,10 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
//! Operations and constants for `f64`
use cmath;

View File

@ -8,10 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
//! Operations and constants for `float`
// Even though this module exports everything defined in it,

View File

@ -8,10 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use T = self::inst::T;
use char;

View File

@ -8,10 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use T = self::inst::T;
use T_SIGNED = self::inst::T_SIGNED;

View File

@ -10,9 +10,6 @@
// Core operators
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
#[lang="drop"]
pub trait Drop {
fn finalize(&self); // FIXME(#4332): Rename to "drop"? --pcwalton

View File

@ -41,9 +41,6 @@ let unwrapped_msg = match move msg {
*/
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use cmp::Eq;
use kinds::Copy;
use option;

View File

@ -8,9 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
#[allow(structural_records)];
/*!

View File

@ -10,10 +10,6 @@
//! Operations on unique pointer types
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use cmp::{Eq, Ord};
#[cfg(notest)]

View File

@ -14,10 +14,6 @@ Cross-platform file path handling
*/
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use cmp::Eq;
use libc;
use option::{None, Option, Some};

View File

@ -82,11 +82,6 @@ bounded and unbounded protocols allows for less code duplication.
*/
// NB: transitionary, de-mode-ing.
// tjc: allowing deprecated modes due to function issue,
// re-forbid after snapshot
#[forbid(deprecated_pattern)];
// Transitional -- needs snapshot
#[allow(structural_records)];
@ -142,15 +137,6 @@ pub fn BufferHeader() -> BufferHeader {
// This is for protocols to associate extra data to thread around.
#[doc(hidden)]
#[cfg(stage0)]
type Buffer<T: Owned> = {
header: BufferHeader,
data: T,
};
#[doc(hidden)]
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
pub struct Buffer<T> {
header: BufferHeader,
data: T,
@ -212,14 +198,6 @@ impl PacketHeader {
}
#[doc(hidden)]
#[cfg(stage0)]
pub struct Packet<T: Owned> {
header: PacketHeader,
mut payload: Option<T>,
}
#[doc(hidden)]
#[cfg(stage1)]
#[cfg(stage2)]
pub struct Packet<T> {
header: PacketHeader,
mut payload: Option<T>,
@ -228,16 +206,12 @@ pub struct Packet<T> {
#[doc(hidden)]
pub trait HasBuffer {
fn set_buffer(b: *libc::c_void);
// FIXME #4421 remove after snapshot
fn set_buffer_(b: *libc::c_void);
}
impl<T: Owned> Packet<T>: HasBuffer {
fn set_buffer(b: *libc::c_void) {
self.header.buffer = b;
}
// FIXME #4421 remove after snapshot
fn set_buffer_(b: *libc::c_void) { self.set_buffer(b) }
}
#[doc(hidden)]
@ -247,27 +221,7 @@ pub fn mk_packet<T: Owned>() -> Packet<T> {
payload: None,
}
}
#[doc(hidden)]
#[cfg(stage0)]
fn unibuffer<T: Owned>() -> ~Buffer<Packet<T>> {
let b = ~{
header: BufferHeader(),
data: Packet {
header: PacketHeader(),
payload: None,
}
};
unsafe {
b.data.header.buffer = reinterpret_cast(&b);
}
move b
}
#[doc(hidden)]
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn unibuffer<T>() -> ~Buffer<Packet<T>> {
let b = ~Buffer {
header: BufferHeader(),
@ -284,17 +238,6 @@ fn unibuffer<T>() -> ~Buffer<Packet<T>> {
}
#[doc(hidden)]
#[cfg(stage0)]
pub fn packet<T: Owned>() -> *Packet<T> {
let b = unibuffer();
let p = ptr::addr_of(&(b.data));
// We'll take over memory management from here.
unsafe { forget(move b) }
p
}
#[doc(hidden)]
#[cfg(stage1)]
#[cfg(stage2)]
pub fn packet<T>() -> *Packet<T> {
let b = unibuffer();
let p = ptr::addr_of(&(b.data));
@ -405,42 +348,11 @@ fn swap_state_rel(dst: &mut State, src: State) -> State {
}
#[doc(hidden)]
#[cfg(stage0)]
pub unsafe fn get_buffer<T: Owned>(p: *PacketHeader) -> ~Buffer<T> {
transmute((*p).buf_header())
}
#[doc(hidden)]
#[cfg(stage1)]
#[cfg(stage2)]
pub unsafe fn get_buffer<T>(p: *PacketHeader) -> ~Buffer<T> {
transmute((*p).buf_header())
}
// This could probably be done with SharedMutableState to avoid move_it!().
#[cfg(stage0)]
struct BufferResource<T: Owned> {
buffer: ~Buffer<T>,
drop {
unsafe {
let b = move_it!(self.buffer);
//let p = ptr::addr_of(*b);
//error!("drop %?", p);
let old_count = atomic_sub_rel(&mut b.header.ref_count, 1);
//let old_count = atomic_xchng_rel(b.header.ref_count, 0);
if old_count == 1 {
// The new count is 0.
// go go gadget drop glue
}
else {
forget(move b)
}
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
struct BufferResource<T> {
buffer: ~Buffer<T>,
@ -463,19 +375,6 @@ struct BufferResource<T> {
}
}
#[cfg(stage0)]
fn BufferResource<T: Owned>(b: ~Buffer<T>) -> BufferResource<T> {
//let p = ptr::addr_of(*b);
//error!("take %?", p);
atomic_add_acq(&mut b.header.ref_count, 1);
BufferResource {
// tjc: ????
buffer: move b
}
}
#[cfg(stage1)]
#[cfg(stage2)]
fn BufferResource<T>(b: ~Buffer<T>) -> BufferResource<T> {
//let p = ptr::addr_of(*b);
//error!("take %?", p);
@ -488,51 +387,6 @@ fn BufferResource<T>(b: ~Buffer<T>) -> BufferResource<T> {
}
#[doc(hidden)]
#[cfg(stage0)]
pub fn send<T: Owned, Tbuffer: Owned>(p: SendPacketBuffered<T, Tbuffer>,
payload: T) -> bool {
let header = p.header();
let p_ = p.unwrap();
let p = unsafe { &*p_ };
assert ptr::addr_of(&(p.header)) == header;
assert p.payload.is_none();
p.payload = move Some(move payload);
let old_state = swap_state_rel(&mut p.header.state, Full);
match old_state {
Empty => {
// Yay, fastpath.
// The receiver will eventually clean this up.
//unsafe { forget(p); }
return true;
}
Full => die!(~"duplicate send"),
Blocked => {
debug!("waking up task for %?", p_);
let old_task = swap_task(&mut p.header.blocked_task, ptr::null());
if !old_task.is_null() {
unsafe {
rustrt::task_signal_event(
old_task,
ptr::addr_of(&(p.header)) as *libc::c_void);
rustrt::rust_task_deref(old_task);
}
}
// The receiver will eventually clean this up.
//unsafe { forget(p); }
return true;
}
Terminated => {
// The receiver will never receive this. Rely on drop_glue
// to clean everything up.
return false;
}
}
}
#[doc(hidden)]
#[cfg(stage1)]
#[cfg(stage2)]
pub fn send<T,Tbuffer>(p: SendPacketBuffered<T,Tbuffer>, payload: T) -> bool {
let header = p.header();
let p_ = p.unwrap();
@ -918,44 +772,13 @@ pub fn select<T: Owned, Tb: Owned>(endpoints: ~[RecvPacketBuffered<T, Tb>])
message.
*/
#[cfg(stage0)]
pub type SendPacket<T: Owned> = SendPacketBuffered<T, Packet<T>>;
#[cfg(stage1)]
#[cfg(stage2)]
pub type SendPacket<T> = SendPacketBuffered<T, Packet<T>>;
#[doc(hidden)]
#[cfg(stage0)]
pub fn SendPacket<T: Owned>(p: *Packet<T>) -> SendPacket<T> {
SendPacketBuffered(p)
}
#[cfg(stage1)]
#[cfg(stage2)]
pub fn SendPacket<T>(p: *Packet<T>) -> SendPacket<T> {
SendPacketBuffered(p)
}
#[cfg(stage0)]
pub struct SendPacketBuffered<T: Owned, Tbuffer: Owned> {
mut p: Option<*Packet<T>>,
mut buffer: Option<BufferResource<Tbuffer>>,
drop {
//if self.p != none {
// debug!("drop send %?", option::get(self.p));
//}
if self.p != None {
let mut p = None;
p <-> self.p;
sender_terminate(option::unwrap(move p))
}
//unsafe { error!("send_drop: %?",
// if self.buffer == none {
// "none"
// } else { "some" }); }
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub struct SendPacketBuffered<T, Tbuffer> {
mut p: Option<*Packet<T>>,
mut buffer: Option<BufferResource<Tbuffer>>,
@ -978,20 +801,6 @@ impl<T:Owned,Tbuffer:Owned> SendPacketBuffered<T,Tbuffer> : ::ops::Drop {
}
}
#[cfg(stage0)]
pub fn SendPacketBuffered<T: Owned, Tbuffer: Owned>(p: *Packet<T>)
-> SendPacketBuffered<T, Tbuffer> {
//debug!("take send %?", p);
SendPacketBuffered {
p: Some(p),
buffer: unsafe {
Some(BufferResource(
get_buffer(ptr::addr_of(&((*p).header)))))
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub fn SendPacketBuffered<T,Tbuffer>(p: *Packet<T>)
-> SendPacketBuffered<T, Tbuffer> {
//debug!("take send %?", p);
@ -1004,35 +813,6 @@ pub fn SendPacketBuffered<T,Tbuffer>(p: *Packet<T>)
}
}
#[cfg(stage0)]
impl<T:Owned,Tbuffer:Owned> SendPacketBuffered<T,Tbuffer> {
fn unwrap() -> *Packet<T> {
let mut p = None;
p <-> self.p;
option::unwrap(move p)
}
pure fn header() -> *PacketHeader {
match self.p {
Some(packet) => unsafe {
let packet = &*packet;
let header = ptr::addr_of(&(packet.header));
//forget(packet);
header
},
None => die!(~"packet already consumed")
}
}
fn reuse_buffer() -> BufferResource<Tbuffer> {
//error!("send reuse_buffer");
let mut tmp = None;
tmp <-> self.buffer;
option::unwrap(move tmp)
}
}
#[cfg(stage1)]
#[cfg(stage2)]
impl<T,Tbuffer> SendPacketBuffered<T,Tbuffer> {
fn unwrap() -> *Packet<T> {
let mut p = None;
@ -1062,45 +842,12 @@ impl<T,Tbuffer> SendPacketBuffered<T,Tbuffer> {
/// Represents the receive end of a pipe. It can receive exactly one
/// message.
#[cfg(stage0)]
pub type RecvPacket<T: Owned> = RecvPacketBuffered<T, Packet<T>>;
#[cfg(stage1)]
#[cfg(stage2)]
pub type RecvPacket<T> = RecvPacketBuffered<T, Packet<T>>;
#[doc(hidden)]
#[cfg(stage0)]
pub fn RecvPacket<T: Owned>(p: *Packet<T>) -> RecvPacket<T> {
RecvPacketBuffered(p)
}
#[doc(hidden)]
#[cfg(stage1)]
#[cfg(stage2)]
pub fn RecvPacket<T>(p: *Packet<T>) -> RecvPacket<T> {
RecvPacketBuffered(p)
}
#[cfg(stage0)]
pub struct RecvPacketBuffered<T: Owned, Tbuffer: Owned> {
mut p: Option<*Packet<T>>,
mut buffer: Option<BufferResource<Tbuffer>>,
drop {
//if self.p != none {
// debug!("drop recv %?", option::get(self.p));
//}
if self.p != None {
let mut p = None;
p <-> self.p;
receiver_terminate(option::unwrap(move p))
}
//unsafe { error!("recv_drop: %?",
// if self.buffer == none {
// "none"
// } else { "some" }); }
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub struct RecvPacketBuffered<T, Tbuffer> {
mut p: Option<*Packet<T>>,
mut buffer: Option<BufferResource<Tbuffer>>,
@ -1152,20 +899,6 @@ impl<T: Owned, Tbuffer: Owned> RecvPacketBuffered<T, Tbuffer> : Selectable {
}
}
#[cfg(stage0)]
pub fn RecvPacketBuffered<T: Owned, Tbuffer: Owned>(p: *Packet<T>)
-> RecvPacketBuffered<T, Tbuffer> {
//debug!("take recv %?", p);
RecvPacketBuffered {
p: Some(p),
buffer: unsafe {
Some(BufferResource(
get_buffer(ptr::addr_of(&((*p).header)))))
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
pub fn RecvPacketBuffered<T,Tbuffer>(p: *Packet<T>)
-> RecvPacketBuffered<T,Tbuffer> {
//debug!("take recv %?", p);
@ -1179,14 +912,6 @@ pub fn RecvPacketBuffered<T,Tbuffer>(p: *Packet<T>)
}
#[doc(hidden)]
#[cfg(stage0)]
pub fn entangle<T: Owned>() -> (SendPacket<T>, RecvPacket<T>) {
let p = packet();
(SendPacket(p), RecvPacket(p))
}
#[doc(hidden)]
#[cfg(stage1)]
#[cfg(stage2)]
pub fn entangle<T>() -> (SendPacket<T>, RecvPacket<T>) {
let p = packet();
(SendPacket(p), RecvPacket(p))
@ -1282,47 +1007,21 @@ pub trait Peekable<T> {
}
#[doc(hidden)]
#[cfg(stage0)]
struct Chan_<T:Owned> {
mut endp: Option<streamp::client::Open<T>>
}
#[doc(hidden)]
#[cfg(stage1)]
#[cfg(stage2)]
struct Chan_<T> {
mut endp: Option<streamp::client::Open<T>>
}
/// An endpoint that can send many messages.
#[cfg(stage0)]
pub enum Chan<T:Owned> {
Chan_(Chan_<T>)
}
#[cfg(stage1)]
#[cfg(stage2)]
pub enum Chan<T> {
Chan_(Chan_<T>)
}
#[doc(hidden)]
#[cfg(stage0)]
struct Port_<T:Owned> {
mut endp: Option<streamp::server::Open<T>>,
}
#[doc(hidden)]
#[cfg(stage1)]
#[cfg(stage2)]
struct Port_<T> {
mut endp: Option<streamp::server::Open<T>>,
}
/// An endpoint that can receive many messages.
#[cfg(stage0)]
pub enum Port<T:Owned> {
Port_(Port_<T>)
}
#[cfg(stage1)]
#[cfg(stage2)]
pub enum Port<T> {
Port_(Port_<T>)
}
@ -1411,12 +1110,6 @@ impl<T: Owned> Port<T>: Selectable {
}
/// Treat many ports as one.
#[cfg(stage0)]
pub struct PortSet<T: Owned> {
mut ports: ~[pipes::Port<T>],
}
#[cfg(stage1)]
#[cfg(stage2)]
pub struct PortSet<T> {
mut ports: ~[pipes::Port<T>],
}
@ -1482,10 +1175,6 @@ impl<T: Owned> PortSet<T> : Peekable<T> {
}
/// A channel that can be shared between many senders.
#[cfg(stage0)]
pub type SharedChan<T: Owned> = private::Exclusive<Chan<T>>;
#[cfg(stage1)]
#[cfg(stage2)]
pub type SharedChan<T> = private::Exclusive<Chan<T>>;
impl<T: Owned> SharedChan<T>: GenericChan<T> {
@ -1554,16 +1243,8 @@ proto! oneshot (
)
/// The send end of a oneshot pipe.
#[cfg(stage0)]
pub type ChanOne<T: Owned> = oneshot::client::Oneshot<T>;
#[cfg(stage1)]
#[cfg(stage2)]
pub type ChanOne<T> = oneshot::client::Oneshot<T>;
/// The receive end of a oneshot pipe.
#[cfg(stage0)]
pub type PortOne<T: Owned> = oneshot::server::Oneshot<T>;
#[cfg(stage1)]
#[cfg(stage2)]
pub type PortOne<T> = oneshot::server::Oneshot<T>;
/// Initialiase a (send-endpoint, recv-endpoint) oneshot pipe pair.

View File

@ -36,7 +36,7 @@ pub use path::PosixPath;
pub use path::WindowsPath;
pub use pipes::{GenericChan, GenericPort};
pub use ptr::Ptr;
pub use str::{StrSlice, Trimmable};
pub use str::{StrSlice, Trimmable, OwnedStr};
pub use to_bytes::IterBytes;
pub use to_str::ToStr;
pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps};

View File

@ -8,11 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// NB: transitionary, de-mode-ing.
// tjc: Re-forbid deprecated modes once a snapshot fixes the
// function problem
#[forbid(deprecated_pattern)];
#[doc(hidden)];
use cast;
@ -486,7 +481,7 @@ pub mod tests {
res.recv();
}
#[test] #[should_fail] #[ignore(cfg(windows))]
#[test] #[should_fail] #[ignore(reason = "random red")]
pub fn exclusive_unwrap_conflict() {
let x = exclusive(~~"hello");
let x2 = ~mut Some(x.clone());

View File

@ -26,10 +26,19 @@ 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> &fn() -> T: Finally<T> {
// FIXME #4518: Should not require a mode here
fn finally(&self, +dtor: &fn()) -> T {
@ -41,6 +50,19 @@ impl<T> &fn() -> T: Finally<T> {
}
}
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
impl<T> &fn() -> T: Finally<T> {
fn finally(&self, dtor: &fn()) -> T {
let _d = Finallyalizer {
dtor: dtor
};
(*self)()
}
}
struct Finallyalizer {
dtor: &fn()
}

View File

@ -10,9 +10,6 @@
//! Unsafe pointer utility functions
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use cast;
use cmp::{Eq, Ord};
use libc;

View File

@ -10,10 +10,6 @@
//! Random number generation
// NB: transitional, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use int;
use prelude::*;
use str;
@ -23,6 +19,102 @@ use uint;
use util;
use vec;
/// A type that can be randomly generated using an RNG
pub trait Rand {
static fn rand(rng: rand::Rng) -> Self;
}
impl int: Rand {
static fn rand(rng: rand::Rng) -> int {
rng.gen_int()
}
}
impl i8: Rand {
static fn rand(rng: rand::Rng) -> i8 {
rng.gen_i8()
}
}
impl i16: Rand {
static fn rand(rng: rand::Rng) -> i16 {
rng.gen_i16()
}
}
impl i32: Rand {
static fn rand(rng: rand::Rng) -> i32 {
rng.gen_i32()
}
}
impl i64: Rand {
static fn rand(rng: rand::Rng) -> i64 {
rng.gen_i64()
}
}
impl u8: Rand {
static fn rand(rng: rand::Rng) -> u8 {
rng.gen_u8()
}
}
impl u16: Rand {
static fn rand(rng: rand::Rng) -> u16 {
rng.gen_u16()
}
}
impl u32: Rand {
static fn rand(rng: rand::Rng) -> u32 {
rng.gen_u32()
}
}
impl u64: Rand {
static fn rand(rng: rand::Rng) -> u64 {
rng.gen_u64()
}
}
impl float: Rand {
static fn rand(rng: rand::Rng) -> float {
rng.gen_float()
}
}
impl f32: Rand {
static fn rand(rng: rand::Rng) -> f32 {
rng.gen_f32()
}
}
impl f64: Rand {
static fn rand(rng: rand::Rng) -> f64 {
rng.gen_f64()
}
}
impl char: Rand {
static fn rand(rng: rand::Rng) -> char {
rng.gen_char()
}
}
impl bool: Rand {
static fn rand(rng: rand::Rng) -> bool {
rng.gen_bool()
}
}
impl<T: Rand> Option<T>: Rand {
static fn rand(rng: rand::Rng) -> Option<T> {
if rng.gen_bool() { Some(Rand::rand(rng)) }
else { None }
}
}
#[allow(non_camel_case_types)] // runtime type
enum rctx {}
@ -49,6 +141,10 @@ pub struct Weighted<T> {
/// Extension methods for random number generators
impl Rng {
/// Return a random value for a Rand type
fn gen<T: Rand>() -> T {
Rand::rand(self)
}
/// Return a random int
fn gen_int() -> int {

View File

@ -14,9 +14,6 @@ Runtime type reflection
*/
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use intrinsic::{TyDesc, get_tydesc, visit_tydesc, TyVisitor};
use libc::c_void;
use sys;
@ -75,434 +72,6 @@ impl<V: TyVisitor MovePtr> MovePtrAdaptor<V> {
}
/// Abstract type-directed pointer-movement using the MovePtr trait
#[cfg(stage0)]
impl<V: TyVisitor MovePtr> MovePtrAdaptor<V>: TyVisitor {
fn visit_bot() -> bool {
self.align_to::<()>();
if ! self.inner.visit_bot() { return false; }
self.bump_past::<()>();
true
}
fn visit_nil() -> bool {
self.align_to::<()>();
if ! self.inner.visit_nil() { return false; }
self.bump_past::<()>();
true
}
fn visit_bool() -> bool {
self.align_to::<bool>();
if ! self.inner.visit_bool() { return false; }
self.bump_past::<bool>();
true
}
fn visit_int() -> bool {
self.align_to::<int>();
if ! self.inner.visit_int() { return false; }
self.bump_past::<int>();
true
}
fn visit_i8() -> bool {
self.align_to::<i8>();
if ! self.inner.visit_i8() { return false; }
self.bump_past::<i8>();
true
}
fn visit_i16() -> bool {
self.align_to::<i16>();
if ! self.inner.visit_i16() { return false; }
self.bump_past::<i16>();
true
}
fn visit_i32() -> bool {
self.align_to::<i32>();
if ! self.inner.visit_i32() { return false; }
self.bump_past::<i32>();
true
}
fn visit_i64() -> bool {
self.align_to::<i64>();
if ! self.inner.visit_i64() { return false; }
self.bump_past::<i64>();
true
}
fn visit_uint() -> bool {
self.align_to::<uint>();
if ! self.inner.visit_uint() { return false; }
self.bump_past::<uint>();
true
}
fn visit_u8() -> bool {
self.align_to::<u8>();
if ! self.inner.visit_u8() { return false; }
self.bump_past::<u8>();
true
}
fn visit_u16() -> bool {
self.align_to::<u16>();
if ! self.inner.visit_u16() { return false; }
self.bump_past::<u16>();
true
}
fn visit_u32() -> bool {
self.align_to::<u32>();
if ! self.inner.visit_u32() { return false; }
self.bump_past::<u32>();
true
}
fn visit_u64() -> bool {
self.align_to::<u64>();
if ! self.inner.visit_u64() { return false; }
self.bump_past::<u64>();
true
}
fn visit_float() -> bool {
self.align_to::<float>();
if ! self.inner.visit_float() { return false; }
self.bump_past::<float>();
true
}
fn visit_f32() -> bool {
self.align_to::<f32>();
if ! self.inner.visit_f32() { return false; }
self.bump_past::<f32>();
true
}
fn visit_f64() -> bool {
self.align_to::<f64>();
if ! self.inner.visit_f64() { return false; }
self.bump_past::<f64>();
true
}
fn visit_char() -> bool {
self.align_to::<char>();
if ! self.inner.visit_char() { return false; }
self.bump_past::<char>();
true
}
fn visit_str() -> bool {
self.align_to::<~str>();
if ! self.inner.visit_str() { return false; }
self.bump_past::<~str>();
true
}
fn visit_estr_box() -> bool {
self.align_to::<@str>();
if ! self.inner.visit_estr_box() { return false; }
self.bump_past::<@str>();
true
}
fn visit_estr_uniq() -> bool {
self.align_to::<~str>();
if ! self.inner.visit_estr_uniq() { return false; }
self.bump_past::<~str>();
true
}
fn visit_estr_slice() -> bool {
self.align_to::<&static/str>();
if ! self.inner.visit_estr_slice() { return false; }
self.bump_past::<&static/str>();
true
}
fn visit_estr_fixed(n: uint,
sz: uint,
align: uint) -> bool {
self.align(align);
if ! self.inner.visit_estr_fixed(n, sz, align) { return false; }
self.bump(sz);
true
}
fn visit_box(mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<@u8>();
if ! self.inner.visit_box(mtbl, inner) { return false; }
self.bump_past::<@u8>();
true
}
fn visit_uniq(mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<~u8>();
if ! self.inner.visit_uniq(mtbl, inner) { return false; }
self.bump_past::<~u8>();
true
}
fn visit_ptr(mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<*u8>();
if ! self.inner.visit_ptr(mtbl, inner) { return false; }
self.bump_past::<*u8>();
true
}
fn visit_rptr(mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<&static/u8>();
if ! self.inner.visit_rptr(mtbl, inner) { return false; }
self.bump_past::<&static/u8>();
true
}
fn visit_unboxed_vec(mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<vec::UnboxedVecRepr>();
if ! self.inner.visit_vec(mtbl, inner) { return false; }
true
}
fn visit_vec(mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<~[u8]>();
if ! self.inner.visit_vec(mtbl, inner) { return false; }
self.bump_past::<~[u8]>();
true
}
fn visit_evec_box(mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<@[u8]>();
if ! self.inner.visit_evec_box(mtbl, inner) { return false; }
self.bump_past::<@[u8]>();
true
}
fn visit_evec_uniq(mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<~[u8]>();
if ! self.inner.visit_evec_uniq(mtbl, inner) { return false; }
self.bump_past::<~[u8]>();
true
}
fn visit_evec_slice(mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<&static/[u8]>();
if ! self.inner.visit_evec_slice(mtbl, inner) { return false; }
self.bump_past::<&static/[u8]>();
true
}
fn visit_evec_fixed(n: uint, sz: uint, align: uint,
mtbl: uint, inner: *TyDesc) -> bool {
self.align(align);
if ! self.inner.visit_evec_fixed(n, sz, align, mtbl, inner) {
return false;
}
self.bump(sz);
true
}
fn visit_enter_rec(n_fields: uint, sz: uint, align: uint) -> bool {
self.align(align);
if ! self.inner.visit_enter_rec(n_fields, sz, align) { return false; }
true
}
fn visit_rec_field(i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool {
unsafe { self.align((*inner).align); }
if ! self.inner.visit_rec_field(i, name, mtbl, inner) {
return false;
}
unsafe { self.bump((*inner).size); }
true
}
fn visit_leave_rec(n_fields: uint, sz: uint, align: uint) -> bool {
if ! self.inner.visit_leave_rec(n_fields, sz, align) { return false; }
true
}
fn visit_enter_class(n_fields: uint, sz: uint, align: uint)
-> bool {
self.align(align);
if ! self.inner.visit_enter_class(n_fields, sz, align) {
return false;
}
true
}
fn visit_class_field(i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool {
unsafe { self.align((*inner).align); }
if ! self.inner.visit_class_field(i, name, mtbl, inner) {
return false;
}
unsafe { self.bump((*inner).size); }
true
}
fn visit_leave_class(n_fields: uint, sz: uint, align: uint)
-> bool {
if ! self.inner.visit_leave_class(n_fields, sz, align) {
return false;
}
true
}
fn visit_enter_tup(n_fields: uint, sz: uint, align: uint) -> bool {
self.align(align);
if ! self.inner.visit_enter_tup(n_fields, sz, align) { return false; }
true
}
fn visit_tup_field(i: uint, inner: *TyDesc) -> bool {
unsafe { self.align((*inner).align); }
if ! self.inner.visit_tup_field(i, inner) { return false; }
unsafe { self.bump((*inner).size); }
true
}
fn visit_leave_tup(n_fields: uint, sz: uint, align: uint) -> bool {
if ! self.inner.visit_leave_tup(n_fields, sz, align) { return false; }
true
}
fn visit_enter_fn(purity: uint, proto: uint,
n_inputs: uint, retstyle: uint) -> bool {
if ! self.inner.visit_enter_fn(purity, proto, n_inputs, retstyle) {
return false
}
true
}
fn visit_fn_input(i: uint, mode: uint, inner: *TyDesc) -> bool {
if ! self.inner.visit_fn_input(i, mode, inner) { return false; }
true
}
fn visit_fn_output(retstyle: uint, inner: *TyDesc) -> bool {
if ! self.inner.visit_fn_output(retstyle, inner) { return false; }
true
}
fn visit_leave_fn(purity: uint, proto: uint,
n_inputs: uint, retstyle: uint) -> bool {
if ! self.inner.visit_leave_fn(purity, proto, n_inputs, retstyle) {
return false;
}
true
}
fn visit_enter_enum(n_variants: uint, sz: uint, align: uint)
-> bool {
self.align(align);
if ! self.inner.visit_enter_enum(n_variants, sz, align) {
return false;
}
true
}
fn visit_enter_enum_variant(variant: uint,
disr_val: int,
n_fields: uint,
name: &str) -> bool {
self.inner.push_ptr();
if ! self.inner.visit_enter_enum_variant(variant, disr_val,
n_fields, name) {
return false;
}
true
}
fn visit_enum_variant_field(i: uint, inner: *TyDesc) -> bool {
unsafe { self.align((*inner).align); }
if ! self.inner.visit_enum_variant_field(i, inner) { return false; }
unsafe { self.bump((*inner).size); }
true
}
fn visit_leave_enum_variant(variant: uint,
disr_val: int,
n_fields: uint,
name: &str) -> bool {
if ! self.inner.visit_leave_enum_variant(variant, disr_val,
n_fields, name) {
return false;
}
self.inner.pop_ptr();
true
}
fn visit_leave_enum(n_variants: uint, sz: uint, align: uint)
-> bool {
if ! self.inner.visit_leave_enum(n_variants, sz, align) {
return false;
}
self.bump(sz);
true
}
fn visit_trait() -> bool {
self.align_to::<TyVisitor>();
if ! self.inner.visit_trait() { return false; }
self.bump_past::<TyVisitor>();
true
}
fn visit_var() -> bool {
if ! self.inner.visit_var() { return false; }
true
}
fn visit_var_integral() -> bool {
if ! self.inner.visit_var_integral() { return false; }
true
}
fn visit_param(i: uint) -> bool {
if ! self.inner.visit_param(i) { return false; }
true
}
fn visit_self() -> bool {
self.align_to::<&static/u8>();
if ! self.inner.visit_self() { return false; }
self.align_to::<&static/u8>();
true
}
fn visit_type() -> bool {
if ! self.inner.visit_type() { return false; }
true
}
fn visit_opaque_box() -> bool {
self.align_to::<@u8>();
if ! self.inner.visit_opaque_box() { return false; }
self.bump_past::<@u8>();
true
}
fn visit_constr(inner: *TyDesc) -> bool {
if ! self.inner.visit_constr(inner) { return false; }
true
}
fn visit_closure_ptr(ck: uint) -> bool {
self.align_to::<fn@()>();
if ! self.inner.visit_closure_ptr(ck) { return false; }
self.bump_past::<fn@()>();
true
}
}
/// Abstract type-directed pointer-movement using the MovePtr trait
#[cfg(stage1)]
#[cfg(stage2)]
impl<V: TyVisitor MovePtr> MovePtrAdaptor<V>: TyVisitor {
fn visit_bot(&self) -> bool {
self.align_to::<()>();

View File

@ -14,9 +14,6 @@ More runtime type reflection
*/
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use cast::transmute;
use cast;
use char;
@ -265,303 +262,6 @@ impl ReprVisitor {
}
#[cfg(stage0)]
impl ReprVisitor : TyVisitor {
fn visit_bot() -> bool {
self.writer.write_str("!");
true
}
fn visit_nil() -> bool { self.write::<()>() }
fn visit_bool() -> bool { self.write::<bool>() }
fn visit_int() -> bool { self.write::<int>() }
fn visit_i8() -> bool { self.write::<i8>() }
fn visit_i16() -> bool { self.write::<i16>() }
fn visit_i32() -> bool { self.write::<i32>() }
fn visit_i64() -> bool { self.write::<i64>() }
fn visit_uint() -> bool { self.write::<uint>() }
fn visit_u8() -> bool { self.write::<u8>() }
fn visit_u16() -> bool { self.write::<u16>() }
fn visit_u32() -> bool { self.write::<u32>() }
fn visit_u64() -> bool { self.write::<u64>() }
fn visit_float() -> bool { self.write::<float>() }
fn visit_f32() -> bool { self.write::<f32>() }
fn visit_f64() -> bool { self.write::<f64>() }
fn visit_char() -> bool {
do self.get::<char> |&ch| {
self.writer.write_char('\'');
self.writer.write_escaped_char(ch);
self.writer.write_char('\'');
}
}
// Type no longer exists, vestigial function.
fn visit_str() -> bool { die!(); }
fn visit_estr_box() -> bool {
do self.get::<@str> |s| {
self.writer.write_char('@');
self.write_escaped_slice(*s);
}
}
fn visit_estr_uniq() -> bool {
do self.get::<~str> |s| {
self.writer.write_char('~');
self.write_escaped_slice(*s);
}
}
fn visit_estr_slice() -> bool {
do self.get::<&str> |s| {
self.write_escaped_slice(*s);
}
}
// Type no longer exists, vestigial function.
fn visit_estr_fixed(_n: uint, _sz: uint,
_align: uint) -> bool { die!(); }
fn visit_box(mtbl: uint, inner: *TyDesc) -> bool {
self.writer.write_char('@');
self.write_mut_qualifier(mtbl);
do self.get::<&managed::raw::BoxRepr> |b| {
let p = ptr::to_unsafe_ptr(&b.data) as *c_void;
self.visit_ptr_inner(p, inner);
}
}
fn visit_uniq(mtbl: uint, inner: *TyDesc) -> bool {
self.writer.write_char('~');
self.write_mut_qualifier(mtbl);
do self.get::<&managed::raw::BoxRepr> |b| {
let p = ptr::to_unsafe_ptr(&b.data) as *c_void;
self.visit_ptr_inner(p, inner);
}
}
fn visit_ptr(_mtbl: uint, _inner: *TyDesc) -> bool {
do self.get::<*c_void> |p| {
self.writer.write_str(fmt!("(0x%x as *())",
*p as uint));
}
}
fn visit_rptr(mtbl: uint, inner: *TyDesc) -> bool {
self.writer.write_char('&');
self.write_mut_qualifier(mtbl);
do self.get::<*c_void> |p| {
self.visit_ptr_inner(*p, inner);
}
}
// Type no longer exists, vestigial function.
fn visit_vec(_mtbl: uint, _inner: *TyDesc) -> bool { die!(); }
fn visit_unboxed_vec(mtbl: uint, inner: *TyDesc) -> bool {
do self.get::<vec::UnboxedVecRepr> |b| {
self.write_unboxed_vec_repr(mtbl, b, inner);
}
}
fn visit_evec_box(mtbl: uint, inner: *TyDesc) -> bool {
do self.get::<&VecRepr> |b| {
self.writer.write_char('@');
self.write_unboxed_vec_repr(mtbl, &b.unboxed, inner);
}
}
fn visit_evec_uniq(mtbl: uint, inner: *TyDesc) -> bool {
do self.get::<&VecRepr> |b| {
self.writer.write_char('~');
self.write_unboxed_vec_repr(mtbl, &b.unboxed, inner);
}
}
fn visit_evec_slice(mtbl: uint, inner: *TyDesc) -> bool {
do self.get::<SliceRepr> |s| {
self.writer.write_char('&');
self.write_vec_range(mtbl, s.data, s.len, inner);
}
}
fn visit_evec_fixed(_n: uint, sz: uint, _align: uint,
mtbl: uint, inner: *TyDesc) -> bool {
do self.get::<u8> |b| {
self.write_vec_range(mtbl, ptr::to_unsafe_ptr(b), sz, inner);
}
}
fn visit_enter_rec(_n_fields: uint,
_sz: uint, _align: uint) -> bool {
self.writer.write_char('{');
true
}
fn visit_rec_field(i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool {
if i != 0 {
self.writer.write_str(", ");
}
self.write_mut_qualifier(mtbl);
self.writer.write_str(name);
self.writer.write_str(": ");
self.visit_inner(inner);
true
}
fn visit_leave_rec(_n_fields: uint,
_sz: uint, _align: uint) -> bool {
self.writer.write_char('}');
true
}
fn visit_enter_class(_n_fields: uint,
_sz: uint, _align: uint) -> bool {
self.writer.write_char('{');
true
}
fn visit_class_field(i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool {
if i != 0 {
self.writer.write_str(", ");
}
self.write_mut_qualifier(mtbl);
self.writer.write_str(name);
self.writer.write_str(": ");
self.visit_inner(inner);
true
}
fn visit_leave_class(_n_fields: uint,
_sz: uint, _align: uint) -> bool {
self.writer.write_char('}');
true
}
fn visit_enter_tup(_n_fields: uint,
_sz: uint, _align: uint) -> bool {
self.writer.write_char('(');
true
}
fn visit_tup_field(i: uint, inner: *TyDesc) -> bool {
if i != 0 {
self.writer.write_str(", ");
}
self.visit_inner(inner);
true
}
fn visit_leave_tup(_n_fields: uint,
_sz: uint, _align: uint) -> bool {
self.writer.write_char(')');
true
}
fn visit_enter_enum(n_variants: uint,
_sz: uint, _align: uint) -> bool {
if n_variants == 1 {
self.var_stk.push(Degenerate)
} else {
self.var_stk.push(TagMatch)
}
true
}
fn visit_enter_enum_variant(_variant: uint,
disr_val: int,
n_fields: uint,
name: &str) -> bool {
let mut write = false;
match self.var_stk.pop() {
Degenerate => {
write = true;
self.var_stk.push(Degenerate);
}
TagMatch | TagMismatch => {
do self.get::<int>() |t| {
if disr_val == *t {
write = true;
self.var_stk.push(TagMatch);
} else {
self.var_stk.push(TagMismatch);
}
};
self.bump_past::<int>();
}
}
if write {
self.writer.write_str(name);
if n_fields > 0 {
self.writer.write_char('(');
}
}
true
}
fn visit_enum_variant_field(i: uint, inner: *TyDesc) -> bool {
match self.var_stk.last() {
Degenerate | TagMatch => {
if i != 0 {
self.writer.write_str(", ");
}
if ! self.visit_inner(inner) {
return false;
}
}
TagMismatch => ()
}
true
}
fn visit_leave_enum_variant(_variant: uint,
_disr_val: int,
n_fields: uint,
_name: &str) -> bool {
match self.var_stk.last() {
Degenerate | TagMatch => {
if n_fields > 0 {
self.writer.write_char(')');
}
}
TagMismatch => ()
}
true
}
fn visit_leave_enum(_n_variants: uint,
_sz: uint, _align: uint) -> bool {
self.var_stk.pop();
true
}
fn visit_enter_fn(_purity: uint, _proto: uint,
_n_inputs: uint, _retstyle: uint) -> bool { true }
fn visit_fn_input(_i: uint, _mode: uint, _inner: *TyDesc) -> bool { true }
fn visit_fn_output(_retstyle: uint, _inner: *TyDesc) -> bool { true }
fn visit_leave_fn(_purity: uint, _proto: uint,
_n_inputs: uint, _retstyle: uint) -> bool { true }
fn visit_trait() -> bool { true }
fn visit_var() -> bool { true }
fn visit_var_integral() -> bool { true }
fn visit_param(_i: uint) -> bool { true }
fn visit_self() -> bool { true }
fn visit_type() -> bool { true }
fn visit_opaque_box() -> bool {
self.writer.write_char('@');
do self.get::<&managed::raw::BoxRepr> |b| {
let p = ptr::to_unsafe_ptr(&b.data) as *c_void;
self.visit_ptr_inner(p, b.header.type_desc);
}
}
// Type no longer exists, vestigial function.
fn visit_constr(_inner: *TyDesc) -> bool { die!(); }
fn visit_closure_ptr(_ck: uint) -> bool { true }
}
#[cfg(stage1)]
#[cfg(stage2)]
impl ReprVisitor : TyVisitor {
fn visit_bot(&self) -> bool {
self.writer.write_str("!");

View File

@ -12,9 +12,6 @@
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use cmp;
use cmp::Eq;
use either;

View File

@ -8,9 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
//! Runtime calls emitted by the compiler.
use cast::transmute;

View File

@ -8,9 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
#[allow(structural_records)];
//! Process spawning

View File

@ -11,12 +11,7 @@
#[doc(hidden)]; // FIXME #3538
#[legacy_modes]; // tjc: remove after snapshot
// NB: transitionary, de-mode-ing.
// FIXME #4425: Can't forbid this because frame_address needs a deprecated
// mode.
#[allow(deprecated_mode)];
#[forbid(deprecated_pattern)];
use cast::reinterpret_cast;
use ptr::offset;

View File

@ -17,9 +17,6 @@
* some heavy-duty uses, try std::rope.
*/
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use at_vec;
use cast;
use char;
@ -2314,6 +2311,21 @@ impl &str: StrSlice {
pure fn char_at(i: uint) -> char { char_at(self, i) }
}
pub trait OwnedStr {
fn push_str(&mut self, v: &str);
fn push_char(&mut self, c: char);
}
pub impl ~str : OwnedStr {
fn push_str(&mut self, v: &str) {
push_str(self, v);
}
fn push_char(&mut self, c: char) {
push_char(self, c);
}
}
#[cfg(test)]
mod tests {
use char;

View File

@ -10,10 +10,6 @@
//! Misc low level stuff
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use cast;
use cmp::{Eq, Ord};
use gc;

View File

@ -8,11 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// NB: transitionary, de-mode-ing.
// tjc: Deprecated modes allowed because of function arg issue
// in task::spawn. Re-forbid after snapshot.
#[forbid(deprecated_pattern)];
/*!
* Task management.
*

View File

@ -71,7 +71,6 @@
****************************************************************************/
#[doc(hidden)]; // FIXME #3538
#[warn(deprecated_mode)];
use cast;
use container::Map;

View File

@ -14,16 +14,12 @@ The `ToBytes` and `IterBytes` traits
*/
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use io;
use io::Writer;
use option::{None, Option, Some};
use str;
pub type Cb = fn(buf: &[const u8]) -> bool;
pub type Cb = &fn(buf: &[const u8]) -> bool;
/**
* A trait to implement in order to make a type hashable;

View File

@ -14,10 +14,6 @@ The `ToStr` trait for converting to strings
*/
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use kinds::Copy;
use str;
use vec;

View File

@ -8,10 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
//! Operations on tuples
use cmp::{Eq, Ord};

View File

@ -9,9 +9,6 @@
// except according to those terms.
#[doc(hidden)]; // FIXME #3538
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
pub mod general_category {
pub pure fn Cc(c: char) -> bool {

View File

@ -14,10 +14,6 @@ Miscellaneous helpers for common patterns.
*/
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use cmp::Eq;
use prelude::*;

View File

@ -10,8 +10,6 @@
//! Vectors
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
#[warn(non_camel_case_types)];
use container::{Container, Mutable};
@ -841,14 +839,37 @@ pub pure fn map2<T: Copy, U: Copy, V>(v0: &[T], v1: &[U],
u
}
/**
* Apply a function to each element of a vector and return the results
*
* If function `f` returns `none` then that element is excluded from
* the resulting vector.
*/
pub pure fn filter_map<T, U: Copy>(v: &[T], f: fn(t: &T) -> Option<U>)
-> ~[U] {
pub fn filter_map<T, U>(
v: ~[T],
f: fn(t: T) -> Option<U>) -> ~[U]
{
/*!
*
* Apply a function to each element of a vector and return the results.
* Consumes the input vector. If function `f` returns `None` then that
* element is excluded from the resulting vector.
*/
let mut result = ~[];
do consume(v) |_, elem| {
match f(elem) {
None => {}
Some(result_elem) => { result.push(result_elem); }
}
}
result
}
pub pure fn filter_mapped<T, U: Copy>(
v: &[T],
f: fn(t: &T) -> Option<U>) -> ~[U]
{
/*!
*
* Like `filter_map()`, but operates on a borrowed slice
* and does not consume the input.
*/
let mut result = ~[];
for each(v) |elem| {
match f(elem) {
@ -1695,7 +1716,7 @@ pub trait ImmutableVector<T> {
fn map_r<U>(&self, f: fn(x: &T) -> U) -> ~[U];
pure fn alli(&self, f: fn(uint, t: &T) -> bool) -> bool;
pure fn flat_map<U>(&self, f: fn(t: &T) -> ~[U]) -> ~[U];
pure fn filter_map<U: Copy>(&self, f: fn(t: &T) -> Option<U>) -> ~[U];
pure fn filter_mapped<U: Copy>(&self, f: fn(t: &T) -> Option<U>) -> ~[U];
}
/// Extension methods for vectors
@ -1758,8 +1779,8 @@ impl<T> &[T]: ImmutableVector<T> {
* the resulting vector.
*/
#[inline]
pure fn filter_map<U: Copy>(&self, f: fn(t: &T) -> Option<U>) -> ~[U] {
filter_map(*self, f)
pure fn filter_mapped<U: Copy>(&self, f: fn(t: &T) -> Option<U>) -> ~[U] {
filter_mapped(*self, f)
}
}
@ -2439,10 +2460,14 @@ mod tests {
pure fn is_equal(x: &uint, y:&uint) -> bool { return *x == *y; }
fn square_if_odd(n: &uint) -> Option<uint> {
fn square_if_odd_r(n: &uint) -> Option<uint> {
return if *n % 2u == 1u { Some(*n * *n) } else { None };
}
fn square_if_odd_v(n: uint) -> Option<uint> {
return if n % 2u == 1u { Some(n * n) } else { None };
}
fn add(x: uint, y: &uint) -> uint { return x + *y; }
#[test]
@ -2775,17 +2800,17 @@ mod tests {
}
#[test]
fn test_filter_map() {
fn test_filter_mapped() {
// Test on-stack filter-map.
let mut v = ~[1u, 2u, 3u];
let mut w = filter_map(v, square_if_odd);
let mut w = filter_mapped(v, square_if_odd_r);
assert (len(w) == 2u);
assert (w[0] == 1u);
assert (w[1] == 9u);
// Test on-heap filter-map.
v = ~[1u, 2u, 3u, 4u, 5u];
w = filter_map(v, square_if_odd);
w = filter_mapped(v, square_if_odd_r);
assert (len(w) == 3u);
assert (w[0] == 1u);
assert (w[1] == 9u);
@ -2804,7 +2829,46 @@ mod tests {
let all_odd2: ~[int] = ~[];
let mix: ~[int] = ~[9, 2, 6, 7, 1, 0, 0, 3];
let mix_dest: ~[int] = ~[1, 3, 0, 0];
assert (filter_map(all_even, halve) == map(all_even, halve_for_sure));
assert (filter_mapped(all_even, halve) ==
map(all_even, halve_for_sure));
assert (filter_mapped(all_odd1, halve) == ~[]);
assert (filter_mapped(all_odd2, halve) == ~[]);
assert (filter_mapped(mix, halve) == mix_dest);
}
#[test]
fn test_filter_map() {
// Test on-stack filter-map.
let mut v = ~[1u, 2u, 3u];
let mut w = filter_map(v, square_if_odd_v);
assert (len(w) == 2u);
assert (w[0] == 1u);
assert (w[1] == 9u);
// Test on-heap filter-map.
v = ~[1u, 2u, 3u, 4u, 5u];
w = filter_map(v, square_if_odd_v);
assert (len(w) == 3u);
assert (w[0] == 1u);
assert (w[1] == 9u);
assert (w[2] == 25u);
fn halve(i: int) -> Option<int> {
if i % 2 == 0 {
return option::Some::<int>(i / 2);
} else {
return option::None::<int>;
}
}
fn halve_for_sure(i: &int) -> int { return *i / 2; }
let all_even: ~[int] = ~[0, 2, 8, 6];
let all_even0: ~[int] = copy all_even;
let all_odd1: ~[int] = ~[1, 7, 3];
let all_odd2: ~[int] = ~[];
let mix: ~[int] = ~[9, 2, 6, 7, 1, 0, 0, 3];
let mix_dest: ~[int] = ~[1, 3, 0, 0];
assert (filter_map(all_even, halve) ==
map(all_even0, halve_for_sure));
assert (filter_map(all_odd1, halve) == ~[]);
assert (filter_map(all_odd2, halve) == ~[]);
assert (filter_map(mix, halve) == mix_dest);
@ -3664,10 +3728,10 @@ mod tests {
#[ignore(windows)]
#[should_fail]
#[allow(non_implicitly_copyable_typarams)]
fn test_filter_map_fail() {
fn test_filter_mapped_fail() {
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
let mut i = 0;
do filter_map(v) |_elt| {
do filter_mapped(v) |_elt| {
if i == 2 {
die!()
}

View File

@ -596,7 +596,7 @@ pub fn symbol_hash(tcx: ty::ctxt, symbol_hasher: &hash::State, t: ty::t,
}
pub fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> @str {
match ccx.type_hashcodes.find(t) {
match ccx.type_hashcodes.find(&t) {
Some(h) => h,
None => {
let hash = symbol_hash(ccx.tcx, ccx.symbol_hasher, t, ccx.link_meta);

View File

@ -538,7 +538,7 @@ pub fn build_session_options(+binary: ~str,
getopts::opt_strs(matches, level_name));
for flags.each |lint_name| {
let lint_name = str::replace(*lint_name, ~"-", ~"_");
match lint_dict.find(/*bad*/ copy lint_name) {
match lint_dict.find(&lint_name) {
None => {
early_error(demitter, fmt!("unknown %s flag: %s",
level_name, lint_name));

View File

@ -64,12 +64,13 @@ fn filter_view_item(cx: ctxt, &&view_item: @ast::view_item
}
fn fold_mod(cx: ctxt, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod {
let filtered_items = vec::filter_map(m.items, |a| filter_item(cx, *a));
let filtered_view_items = vec::filter_map(m.view_items,
|a| filter_view_item(cx, *a));
let filtered_items =
m.items.filter_mapped(|a| filter_item(cx, *a));
let filtered_view_items =
m.view_items.filter_mapped(|a| filter_view_item(cx, *a));
ast::_mod {
view_items: filtered_view_items.map(|x| fld.fold_view_item(*x)),
items: filtered_items.filter_map(|x| fld.fold_item(*x)),
items: vec::filter_map(filtered_items, |x| fld.fold_item(x))
}
}
@ -85,10 +86,10 @@ fn fold_foreign_mod(
nm: ast::foreign_mod,
fld: fold::ast_fold
) -> ast::foreign_mod {
let filtered_items = vec::filter_map(nm.items,
|a| filter_foreign_item(cx, *a));
let filtered_view_items = vec::filter_map(nm.view_items,
|a| filter_view_item(cx, *a));
let filtered_items =
nm.items.filter_mapped(|a| filter_foreign_item(cx, *a));
let filtered_view_items =
nm.view_items.filter_mapped(|a| filter_view_item(cx, *a));
ast::foreign_mod {
sort: nm.sort,
abi: nm.abi,
@ -136,7 +137,8 @@ fn fold_block(
b: ast::blk_,
fld: fold::ast_fold
) -> ast::blk_ {
let filtered_stmts = vec::filter_map(b.stmts, |a| filter_stmt(cx, *a));
let filtered_stmts =
b.stmts.filter_mapped(|a| filter_stmt(cx, *a));
ast::blk_ {
view_items: /*bad*/copy b.view_items,
stmts: vec::map(filtered_stmts, |x| fld.fold_stmt(*x)),
@ -183,8 +185,9 @@ pub fn metas_in_cfg(cfg: ast::crate_cfg,
// Pull the inner meta_items from the #[cfg(meta_item, ...)] attributes,
// so we can match against them. This is the list of configurations for
// which the item is valid
let cfg_metas = vec::concat(vec::filter_map(cfg_metas,
|i| attr::get_meta_item_list(*i)));
let cfg_metas =
vec::concat(
vec::filter_map(cfg_metas, |i| attr::get_meta_item_list(i)));
let has_cfg_metas = vec::len(cfg_metas) > 0u;
if !has_cfg_metas { return true; }

View File

@ -168,9 +168,11 @@ fn is_test_fn(i: @ast::item) -> bool {
fn is_ignored(cx: test_ctxt, i: @ast::item) -> bool {
let ignoreattrs = attr::find_attrs_by_name(i.attrs, "ignore");
let ignoreitems = attr::attr_metas(ignoreattrs);
let cfg_metas = vec::concat(vec::filter_map(ignoreitems,
|i| attr::get_meta_item_list(*i)));
return if !ignoreitems.is_empty() {
let cfg_metas =
vec::concat(
vec::filter_map(ignoreitems,
|i| attr::get_meta_item_list(i)));
config::metas_in_cfg(/*bad*/copy cx.crate.node.config, cfg_metas)
} else {
false
@ -277,7 +279,7 @@ fn mk_std(cx: test_ctxt) -> @ast::view_item {
}
fn mk_tests(cx: test_ctxt) -> @ast::item {
let ret_ty = mk_test_desc_vec_ty(cx);
let ret_ty = mk_test_desc_and_fn_vec_ty(cx);
let decl = ast::fn_decl {
inputs: ~[],
@ -286,7 +288,7 @@ fn mk_tests(cx: test_ctxt) -> @ast::item {
};
// The vector of test_descs for this crate
let test_descs = mk_test_desc_vec(cx);
let test_descs = mk_test_desc_and_fn_vec(cx);
let body_: ast::blk_ =
default_block(~[], option::Some(test_descs), cx.sess.next_node_id());
@ -327,19 +329,21 @@ fn mk_path(cx: test_ctxt, +path: ~[ast::ident]) -> @ast::path {
}
}
// The ast::Ty of ~[std::test::test_desc]
fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::Ty {
let test_desc_ty_path =
// The ast::Ty of ~[std::test::TestDescAndFn]
fn mk_test_desc_and_fn_vec_ty(cx: test_ctxt) -> @ast::Ty {
let test_desc_and_fn_ty_path =
mk_path(cx, ~[cx.sess.ident_of(~"test"),
cx.sess.ident_of(~"TestDesc")]);
cx.sess.ident_of(~"TestDescAndFn")]);
let test_desc_ty = ast::Ty {
let test_desc_and_fn_ty = ast::Ty {
id: cx.sess.next_node_id(),
node: ast::ty_path(test_desc_ty_path, cx.sess.next_node_id()),
node: ast::ty_path(test_desc_and_fn_ty_path,
cx.sess.next_node_id()),
span: dummy_sp(),
};
let vec_mt = ast::mt {ty: @test_desc_ty, mutbl: ast::m_imm};
let vec_mt = ast::mt {ty: @test_desc_and_fn_ty,
mutbl: ast::m_imm};
let inner_ty = @ast::Ty {
id: cx.sess.next_node_id(),
@ -354,11 +358,11 @@ fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::Ty {
}
}
fn mk_test_desc_vec(cx: test_ctxt) -> @ast::expr {
fn mk_test_desc_and_fn_vec(cx: test_ctxt) -> @ast::expr {
debug!("building test vector from %u tests", cx.testfns.len());
let mut descs = ~[];
for cx.testfns.each |test| {
descs.push(mk_test_desc_rec(cx, *test));
descs.push(mk_test_desc_and_fn_rec(cx, *test));
}
let inner_expr = @ast::expr {
@ -376,7 +380,7 @@ fn mk_test_desc_vec(cx: test_ctxt) -> @ast::expr {
}
}
fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
fn mk_test_desc_and_fn_rec(cx: test_ctxt, test: test) -> @ast::expr {
let span = test.span;
let path = /*bad*/copy test.path;
@ -407,23 +411,6 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
expr: @name_expr,
});
let fn_path = path_node_global(path);
let fn_expr = ast::expr {
id: cx.sess.next_node_id(),
callee_id: cx.sess.next_node_id(),
node: ast::expr_path(fn_path),
span: span,
};
let fn_wrapper_expr = mk_test_wrapper(cx, fn_expr, span);
let fn_field = nospan(ast::field_ {
mutbl: ast::m_imm,
ident: cx.sess.ident_of(~"testfn"),
expr: fn_wrapper_expr,
});
let ignore_lit: ast::lit = nospan(ast::lit_bool(test.ignore));
let ignore_expr = ast::expr {
@ -460,62 +447,52 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
let desc_rec_ = ast::expr_struct(
test_desc_path,
~[name_field, fn_field, ignore_field, fail_field],
~[name_field, ignore_field, fail_field],
option::None
);
let desc_rec = ast::expr {
let desc_rec = @ast::expr {
id: cx.sess.next_node_id(),
callee_id: cx.sess.next_node_id(),
node: desc_rec_,
span: span,
};
return @desc_rec;
}
let desc_field = nospan(ast::field_ {
mutbl: ast::m_imm,
ident: cx.sess.ident_of(~"desc"),
expr: desc_rec
});
// Produces a bare function that wraps the test function
let fn_path = path_node_global(path);
// FIXME (#1281): This can go away once fn is the type of bare function.
fn mk_test_wrapper(cx: test_ctxt,
+fn_path_expr: ast::expr,
span: span) -> @ast::expr {
let call_expr = ast::expr {
let fn_expr = @ast::expr {
id: cx.sess.next_node_id(),
callee_id: cx.sess.next_node_id(),
node: ast::expr_call(@fn_path_expr, ~[], false),
node: ast::expr_path(fn_path),
span: span,
};
let call_stmt: ast::stmt = nospan(
ast::stmt_semi(@call_expr, cx.sess.next_node_id()));
let wrapper_decl = ast::fn_decl {
inputs: ~[],
output: @ast::Ty {
id: cx.sess.next_node_id(),
node: ast::ty_nil,
span: span,
},
cf: ast::return_val
};
let wrapper_body = nospan(ast::blk_ {
view_items: ~[],
stmts: ~[@call_stmt],
expr: option::None,
id: cx.sess.next_node_id(),
rules: ast::default_blk
let fn_field = nospan(ast::field_ {
mutbl: ast::m_imm,
ident: cx.sess.ident_of(~"testfn"),
expr: fn_expr,
});
let wrapper_expr = ast::expr {
let test_desc_and_fn_path =
mk_path(cx, ~[cx.sess.ident_of(~"test"),
cx.sess.ident_of(~"TestDescAndFn")]);
let desc_and_fn_rec = @ast::expr {
id: cx.sess.next_node_id(),
callee_id: cx.sess.next_node_id(),
node: ast::expr_fn(ast::ProtoBare, wrapper_decl, wrapper_body, @()),
span: span
node: ast::expr_struct(test_desc_and_fn_path,
~[fn_field, desc_field],
option::None),
span: span,
};
return @wrapper_expr;
return desc_and_fn_rec;
}
fn mk_main(cx: test_ctxt) -> @ast::item {
@ -567,7 +544,7 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr {
let args_call_expr = ast::expr {
id: cx.sess.next_node_id(),
callee_id: cx.sess.next_node_id(),
node: ast::expr_call(@args_path_expr, ~[], false),
node: ast::expr_call(@args_path_expr, ~[], ast::NoSugar),
span: dummy_sp(),
};
@ -584,7 +561,7 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr {
let test_call_expr = ast::expr {
id: cx.sess.next_node_id(),
callee_id: cx.sess.next_node_id(),
node: ast::expr_call(@test_path_expr, ~[], false),
node: ast::expr_call(@test_path_expr, ~[], ast::NoSugar),
span: dummy_sp(),
};
@ -606,7 +583,7 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr {
node: ast::expr_call(
@test_main_path_expr,
~[@args_call_expr, @test_call_expr],
false
ast::NoSugar
),
span: dummy_sp(),
};

View File

@ -445,14 +445,19 @@ pub extern mod llvm {
Count: c_uint,
Packed: Bool) -> ValueRef;
pub unsafe fn LLVMConstString(Str: *c_char, Length: c_uint,
DontNullTerminate: Bool) -> ValueRef;
pub unsafe fn LLVMConstArray(ElementTy: TypeRef, ConstantVals: *ValueRef,
Length: c_uint) -> ValueRef;
pub unsafe fn LLVMConstString(Str: *c_char,
Length: c_uint,
DontNullTerminate: Bool)
-> ValueRef;
pub unsafe fn LLVMConstArray(ElementTy: TypeRef,
ConstantVals: *ValueRef,
Length: c_uint)
-> ValueRef;
pub unsafe fn LLVMConstStruct(ConstantVals: *ValueRef,
Count: c_uint, Packed: Bool) -> ValueRef;
Count: c_uint,
Packed: Bool) -> ValueRef;
pub unsafe fn LLVMConstVector(ScalarConstantVals: *ValueRef,
Size: c_uint) -> ValueRef;
Size: c_uint) -> ValueRef;
/* Constant expressions */
pub unsafe fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
@ -463,8 +468,8 @@ pub extern mod llvm {
pub unsafe fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
pub unsafe fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
pub unsafe fn LLVMConstAdd(LHSConstant: ValueRef,
RHSConstant: ValueRef)
-> ValueRef;
RHSConstant: ValueRef)
-> ValueRef;
pub unsafe fn LLVMConstNSWAdd(LHSConstant: ValueRef,
RHSConstant: ValueRef)
-> ValueRef;
@ -475,14 +480,14 @@ pub extern mod llvm {
RHSConstant: ValueRef)
-> ValueRef;
pub unsafe fn LLVMConstSub(LHSConstant: ValueRef,
RHSConstant: ValueRef)
-> ValueRef;
RHSConstant: ValueRef)
-> ValueRef;
pub unsafe fn LLVMConstNSWSub(LHSConstant: ValueRef,
RHSConstant: ValueRef)
-> ValueRef;
RHSConstant: ValueRef)
-> ValueRef;
pub unsafe fn LLVMConstNUWSub(LHSConstant: ValueRef,
RHSConstant: ValueRef)
-> ValueRef;
RHSConstant: ValueRef)
-> ValueRef;
pub unsafe fn LLVMConstFSub(LHSConstant: ValueRef,
RHSConstant: ValueRef)
-> ValueRef;
@ -1331,11 +1336,11 @@ pub fn associate_type(tn: type_names, s: @str, t: TypeRef) {
}
pub fn type_has_name(tn: type_names, t: TypeRef) -> Option<@str> {
return tn.type_names.find(t);
return tn.type_names.find(&t);
}
pub fn name_has_type(tn: type_names, s: @str) -> Option<TypeRef> {
return tn.named_types.find(s);
return tn.named_types.find(&s);
}
pub fn mk_type_names() -> type_names {

View File

@ -74,7 +74,7 @@ pub fn mk_cstore(intr: @ident_interner) -> CStore {
pub fn get_crate_data(cstore: CStore, cnum: ast::crate_num)
-> crate_metadata {
return p(cstore).metas.get(cnum);
return p(cstore).metas.get(&cnum);
}
pub fn get_crate_hash(cstore: CStore, cnum: ast::crate_num) -> ~str {
@ -139,7 +139,7 @@ pub fn add_use_stmt_cnum(cstore: CStore, use_id: ast::node_id,
pub fn find_use_stmt_cnum(cstore: CStore,
use_id: ast::node_id) -> Option<ast::crate_num> {
p(cstore).use_crate_map.find(use_id)
p(cstore).use_crate_map.find(&use_id)
}
// returns hashes of crates directly used by this crate. Hashes are

View File

@ -586,10 +586,8 @@ pub fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::node_id,
item, tcx, cdata);
let name = item_name(intr, item);
let arg_tys = match ty::get(ctor_ty).sty {
ty::ty_fn(ref f) => (*f).sig.inputs.map(|a| a.ty),
// Nullary enum variant.
_ => ~[],
ty::ty_bare_fn(ref f) => f.sig.inputs.map(|a| a.ty),
_ => ~[], // Nullary enum variant.
};
match variant_disr_val(item) {
Some(val) => { disr_val = val; }
@ -705,11 +703,12 @@ pub fn get_trait_methods(intr: @ident_interner, cdata: cmd, id: ast::node_id,
let ty = doc_type(mth, tcx, cdata);
let def_id = item_def_id(mth, cdata);
let fty = match ty::get(ty).sty {
ty::ty_fn(ref f) => (/*bad*/copy *f),
_ => {
tcx.diag.handler().bug(
~"get_trait_methods: id has non-function type");
} };
ty::ty_bare_fn(ref f) => copy *f,
_ => {
tcx.diag.handler().bug(
~"get_trait_methods: id has non-function type");
}
};
let self_ty = get_self_ty(mth);
result.push({ident: name, tps: bounds, fty: fty, self_ty: self_ty,
vis: ast::public, def_id: def_id});
@ -734,14 +733,13 @@ pub fn get_provided_trait_methods(intr: @ident_interner, cdata: cmd,
let name = item_name(intr, mth);
let ty = doc_type(mth, tcx, cdata);
let fty;
match ty::get(ty).sty {
ty::ty_fn(ref f) => fty = (/*bad*/copy *f),
let fty = match ty::get(ty).sty {
ty::ty_bare_fn(ref f) => copy *f,
_ => {
tcx.diag.handler().bug(~"get_provided_trait_methods(): id \
has non-function type");
}
}
};
let self_ty = get_self_ty(mth);
let ty_method = {ident: name, tps: bounds, fty: fty, self_ty: self_ty,
@ -1099,7 +1097,7 @@ pub fn translate_def_id(cdata: cmd, did: ast::def_id) -> ast::def_id {
return ast::def_id { crate: cdata.cnum, node: did.node };
}
match cdata.cnum_map.find(did.crate) {
match cdata.cnum_map.find(&did.crate) {
option::Some(n) => ast::def_id { crate: n, node: did.node },
option::None => die!(~"didn't find a crate in the cnum_map")
}

View File

@ -118,7 +118,7 @@ pub fn encode_def_id(ebml_w: writer::Encoder, id: def_id) {
fn encode_region_param(ecx: @encode_ctxt, ebml_w: writer::Encoder,
it: @ast::item) {
let opt_rp = ecx.tcx.region_paramd_items.find(it.id);
let opt_rp = ecx.tcx.region_paramd_items.find(&it.id);
for opt_rp.each |rp| {
do ebml_w.wr_tag(tag_region_param) {
(*rp).encode(&ebml_w);
@ -184,7 +184,7 @@ fn encode_ty_type_param_bounds(ebml_w: writer::Encoder, ecx: @encode_ctxt,
fn encode_type_param_bounds(ebml_w: writer::Encoder, ecx: @encode_ctxt,
params: &[ty_param]) {
let ty_param_bounds =
@params.map(|param| ecx.tcx.ty_param_bounds.get(param.id));
@params.map(|param| ecx.tcx.ty_param_bounds.get(&param.id));
encode_ty_type_param_bounds(ebml_w, ecx, ty_param_bounds);
}
@ -224,7 +224,7 @@ fn encode_type(ecx: @encode_ctxt, ebml_w: writer::Encoder, typ: ty::t) {
fn encode_symbol(ecx: @encode_ctxt, ebml_w: writer::Encoder, id: node_id) {
ebml_w.start_tag(tag_items_data_item_symbol);
let sym = match ecx.item_symbols.find(id) {
let sym = match ecx.item_symbols.find(&id) {
Some(ref x) => (/*bad*/copy *x),
None => {
ecx.diag.handler().bug(
@ -238,7 +238,7 @@ fn encode_symbol(ecx: @encode_ctxt, ebml_w: writer::Encoder, id: node_id) {
fn encode_discriminant(ecx: @encode_ctxt, ebml_w: writer::Encoder,
id: node_id) {
ebml_w.start_tag(tag_items_data_item_symbol);
ebml_w.writer.write(str::to_bytes(ecx.discrim_symbols.get(id)));
ebml_w.writer.write(str::to_bytes(ecx.discrim_symbols.get(&id)));
ebml_w.end_tag();
}
@ -349,7 +349,7 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: writer::Encoder,
// Encode the reexports of this module.
debug!("(encoding info for module) encoding reexports for %d", id);
match ecx.reexports2.find(id) {
match ecx.reexports2.find(&id) {
Some(ref exports) => {
debug!("(encoding info for module) found reexports for %d", id);
for (*exports).each |exp| {
@ -768,8 +768,9 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
encode_name(ecx, ebml_w, mty.ident);
encode_type_param_bounds(ebml_w, ecx,
(*ty_m).tps);
encode_type(ecx, ebml_w, ty::mk_fn(tcx, /*bad*/copy mty.fty));
encode_family(ebml_w, purity_fn_family(mty.fty.meta.purity));
encode_type(ecx, ebml_w,
ty::mk_bare_fn(tcx, copy mty.fty));
encode_family(ebml_w, purity_fn_family(mty.fty.purity));
encode_self_type(ebml_w, mty.self_ty);
encode_method_sort(ebml_w, 'r');
ebml_w.end_tag();
@ -781,8 +782,9 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
encode_def_id(ebml_w, local_def(m.id));
encode_name(ecx, ebml_w, mty.ident);
encode_type_param_bounds(ebml_w, ecx, m.tps);
encode_type(ecx, ebml_w, ty::mk_fn(tcx, /*bad*/copy mty.fty));
encode_family(ebml_w, purity_fn_family(mty.fty.meta.purity));
encode_type(ecx, ebml_w,
ty::mk_bare_fn(tcx, copy mty.fty));
encode_family(ebml_w, purity_fn_family(mty.fty.purity));
encode_self_type(ebml_w, mty.self_ty);
encode_method_sort(ebml_w, 'p');
ebml_w.end_tag();
@ -813,7 +815,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
encode_name(ecx, ebml_w, ty_m.ident);
encode_family(ebml_w,
purity_static_method_family(ty_m.purity));
let polyty = ecx.tcx.tcache.get(local_def(ty_m.id));
let polyty = ecx.tcx.tcache.get(&local_def(ty_m.id));
encode_ty_type_param_bounds(ebml_w, ecx, polyty.bounds);
encode_type(ecx, ebml_w, polyty.ty);
let mut m_path = vec::append(~[], path); // :-(
@ -881,7 +883,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: writer::Encoder,
let ebml_w = copy ebml_w;
|i, cx, v| {
visit::visit_item(i, cx, v);
match ecx.tcx.items.get(i.id) {
match ecx.tcx.items.get(&i.id) {
ast_map::node_item(_, pt) => {
encode_info_for_item(ecx, ebml_w, i,
index, *pt);
@ -894,7 +896,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: writer::Encoder,
let ebml_w = copy ebml_w;
|ni, cx, v| {
visit::visit_foreign_item(ni, cx, v);
match ecx.tcx.items.get(ni.id) {
match ecx.tcx.items.get(&ni.id) {
ast_map::node_foreign_item(_, abi, pt) => {
encode_info_for_foreign_item(ecx, ebml_w, ni,
index, /*bad*/copy *pt,

View File

@ -17,8 +17,6 @@
use core::prelude::*;
use middle::ty;
use middle::ty::{FnTyBase, FnMeta, FnSig, arg, creader_cache_key, field};
use middle::ty::{substs};
use core::io;
use core::str;
@ -124,17 +122,12 @@ fn parse_path(st: @pstate) -> @ast::path {
};
}
fn parse_ty_rust_fn(st: @pstate, conv: conv_did) -> ty::t {
return ty::mk_fn(st.tcx, parse_ty_fn(st, conv));
}
fn parse_proto(st: @pstate) -> ast::Proto {
fn parse_sigil(st: @pstate) -> ast::Sigil {
match next(st) {
'_' => ast::ProtoBare,
'@' => ast::ProtoBox,
'~' => ast::ProtoUniq,
'&' => ast::ProtoBorrowed,
_ => die!(~"parse_proto(): bad input")
'@' => ast::ManagedSigil,
'~' => ast::OwnedSigil,
'&' => ast::BorrowedSigil,
c => st.tcx.sess.bug(fmt!("parse_sigil(): bad input '%c'", c))
}
}
@ -152,7 +145,7 @@ fn parse_vstore(st: @pstate) -> ty::vstore {
'~' => ty::vstore_uniq,
'@' => ty::vstore_box,
'&' => ty::vstore_slice(parse_region(st)),
_ => die!(~"parse_vstore: bad input")
c => st.tcx.sess.bug(fmt!("parse_vstore(): bad input '%c'", c))
}
}
@ -166,7 +159,7 @@ fn parse_substs(st: @pstate, conv: conv_did) -> ty::substs {
while peek(st) != ']' { params.push(parse_ty(st, conv)); }
st.pos = st.pos + 1u;
return substs {
return ty::substs {
self_r: self_r,
self_ty: self_ty,
tps: params
@ -316,20 +309,25 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
return ty::mk_tup(st.tcx, params);
}
'f' => {
parse_ty_rust_fn(st, conv)
return ty::mk_closure(st.tcx, parse_closure_ty(st, conv));
}
'F' => {
return ty::mk_bare_fn(st.tcx, parse_bare_fn_ty(st, conv));
}
'Y' => return ty::mk_type(st.tcx),
'C' => {
let proto = parse_proto(st);
return ty::mk_opaque_closure_ptr(st.tcx, proto);
let sigil = parse_sigil(st);
return ty::mk_opaque_closure_ptr(st.tcx, sigil);
}
'#' => {
let pos = parse_hex(st);
assert (next(st) == ':');
let len = parse_hex(st);
assert (next(st) == '#');
let key = creader_cache_key { cnum: st.crate, pos: pos, len: len };
match st.tcx.rcache.find(key) {
let key = ty::creader_cache_key {cnum: st.crate,
pos: pos,
len: len };
match st.tcx.rcache.find(&key) {
Some(tt) => return tt,
None => {
let ps = @{pos: pos ,.. copy *st};
@ -408,6 +406,13 @@ fn parse_purity(c: char) -> purity {
}
}
fn parse_abi(c: char) -> Abi {
match c {
'r' => ast::RustAbi,
_ => die!(fmt!("parse_abi: bad ABI '%c'", c))
}
}
fn parse_onceness(c: char) -> ast::Onceness {
match c {
'o' => ast::Once,
@ -430,12 +435,33 @@ fn parse_mode(st: @pstate) -> ast::mode {
return m;
}
fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::FnTy {
let proto = parse_proto(st);
fn parse_closure_ty(st: @pstate, conv: conv_did) -> ty::ClosureTy {
let sigil = parse_sigil(st);
let purity = parse_purity(next(st));
let onceness = parse_onceness(next(st));
let region = parse_region(st);
let bounds = parse_bounds(st, conv);
let sig = parse_sig(st, conv);
ty::ClosureTy {
purity: purity,
sigil: sigil,
onceness: onceness,
region: region,
sig: sig
}
}
fn parse_bare_fn_ty(st: @pstate, conv: conv_did) -> ty::BareFnTy {
let purity = parse_purity(next(st));
let abi = parse_abi(next(st));
let sig = parse_sig(st, conv);
ty::BareFnTy {
purity: purity,
abi: abi,
sig: sig
}
}
fn parse_sig(st: @pstate, conv: conv_did) -> ty::FnSig {
assert (next(st) == '[');
let mut inputs: ~[ty::arg] = ~[];
while peek(st) != ']' {
@ -444,18 +470,9 @@ fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::FnTy {
}
st.pos += 1u; // eat the ']'
let ret_ty = parse_ty(st, conv);
return FnTyBase {
meta: FnMeta {purity: purity,
proto: proto,
onceness: onceness,
bounds: bounds,
region: region},
sig: FnSig {inputs: inputs,
output: ret_ty}
};
ty::FnSig {inputs: inputs, output: ret_ty}
}
// Rust metadata parsing
pub fn parse_def_id(buf: &[u8]) -> ast::def_id {
let mut colon_idx = 0u;

View File

@ -56,7 +56,7 @@ fn cx_uses_abbrevs(cx: @ctxt) -> bool {
pub fn enc_ty(w: io::Writer, cx: @ctxt, t: ty::t) {
match cx.abbrevs {
ac_no_abbrevs => {
let result_str = match cx.tcx.short_names_cache.find(t) {
let result_str = match cx.tcx.short_names_cache.find(&t) {
Some(s) => /*bad*/copy *s,
None => {
let s = do io::with_str_writer |wr| {
@ -69,7 +69,7 @@ pub fn enc_ty(w: io::Writer, cx: @ctxt, t: ty::t) {
w.write_str(result_str);
}
ac_use_abbrevs(abbrevs) => {
match abbrevs.find(t) {
match abbrevs.find(&t) {
Some(a) => { w.write_str(*a.s); return; }
None => {
let pos = w.tell();
@ -288,8 +288,13 @@ fn enc_sty(w: io::Writer, cx: @ctxt, +st: ty::sty) {
}
w.write_char(']');
}
ty::ty_fn(ref f) => {
enc_ty_fn(w, cx, (*f));
ty::ty_closure(ref f) => {
w.write_char('f');
enc_closure_ty(w, cx, f);
}
ty::ty_bare_fn(ref f) => {
w.write_char('F');
enc_bare_fn_ty(w, cx, f);
}
ty::ty_infer(_) => {
cx.diag.handler().bug(~"Cannot encode inference variable types");
@ -306,7 +311,7 @@ fn enc_sty(w: io::Writer, cx: @ctxt, +st: ty::sty) {
ty::ty_type => w.write_char('Y'),
ty::ty_opaque_closure_ptr(p) => {
w.write_str(&"C&");
enc_proto(w, p);
enc_sigil(w, p);
}
ty::ty_opaque_box => w.write_char('B'),
ty::ty_struct(def, ref substs) => {
@ -325,13 +330,11 @@ fn enc_sty(w: io::Writer, cx: @ctxt, +st: ty::sty) {
}
}
fn enc_proto(w: io::Writer, proto: Proto) {
w.write_str(&"f");
match proto {
ProtoBare => w.write_str(&"_"),
ProtoBox => w.write_str(&"@"),
ProtoUniq => w.write_str(&"~"),
ProtoBorrowed => w.write_str(&"&"),
fn enc_sigil(w: io::Writer, sigil: Sigil) {
match sigil {
ManagedSigil => w.write_str("@"),
OwnedSigil => w.write_str("~"),
BorrowedSigil => w.write_str("&"),
}
}
@ -357,6 +360,12 @@ fn enc_purity(w: io::Writer, p: purity) {
}
}
fn enc_abi(w: io::Writer, a: Abi) {
match a {
RustAbi => w.write_char('r'),
}
}
fn enc_onceness(w: io::Writer, o: Onceness) {
match o {
Once => w.write_char('o'),
@ -364,18 +373,27 @@ fn enc_onceness(w: io::Writer, o: Onceness) {
}
}
fn enc_ty_fn(w: io::Writer, cx: @ctxt, ft: ty::FnTy) {
enc_proto(w, ft.meta.proto);
enc_purity(w, ft.meta.purity);
enc_onceness(w, ft.meta.onceness);
enc_region(w, cx, ft.meta.region);
enc_bounds(w, cx, ft.meta.bounds);
fn enc_bare_fn_ty(w: io::Writer, cx: @ctxt, ft: &ty::BareFnTy) {
enc_purity(w, ft.purity);
enc_abi(w, ft.abi);
enc_fn_sig(w, cx, &ft.sig);
}
fn enc_closure_ty(w: io::Writer, cx: @ctxt, ft: &ty::ClosureTy) {
enc_sigil(w, ft.sigil);
enc_purity(w, ft.purity);
enc_onceness(w, ft.onceness);
enc_region(w, cx, ft.region);
enc_fn_sig(w, cx, &ft.sig);
}
fn enc_fn_sig(w: io::Writer, cx: @ctxt, fsig: &ty::FnSig) {
w.write_char('[');
for ft.sig.inputs.each |arg| {
for fsig.inputs.each |arg| {
enc_arg(w, cx, *arg);
}
w.write_char(']');
enc_ty(w, cx, ft.sig.output);
enc_ty(w, cx, fsig.output);
}
pub fn enc_bounds(w: io::Writer, cx: @ctxt, bs: @~[ty::param_bound]) {

View File

@ -838,7 +838,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
debug!("Encoding side tables for id %d", id);
do option::iter(&tcx.def_map.find(id)) |def| {
do option::iter(&tcx.def_map.find(&id)) |def| {
do ebml_w.tag(c::tag_table_def) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
@ -855,7 +855,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
}
}
do option::iter(&tcx.node_type_substs.find(id)) |tys| {
do option::iter(&tcx.node_type_substs.find(&id)) |tys| {
do ebml_w.tag(c::tag_table_node_type_subst) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
@ -864,7 +864,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
}
}
do option::iter(&tcx.freevars.find(id)) |fv| {
do option::iter(&tcx.freevars.find(&id)) |fv| {
do ebml_w.tag(c::tag_table_freevars) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
@ -876,7 +876,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
}
let lid = ast::def_id { crate: ast::local_crate, node: id };
do option::iter(&tcx.tcache.find(lid)) |tpbt| {
do option::iter(&tcx.tcache.find(&lid)) |tpbt| {
do ebml_w.tag(c::tag_table_tcache) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
@ -885,7 +885,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
}
}
do option::iter(&tcx.ty_param_bounds.find(id)) |pbs| {
do option::iter(&tcx.ty_param_bounds.find(&id)) |pbs| {
do ebml_w.tag(c::tag_table_param_bounds) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
@ -899,7 +899,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
// is what we actually use in trans, all modes will have been
// resolved.
//
//option::iter(tcx.inferred_modes.find(id)) {|m|
//option::iter(tcx.inferred_modes.find(&id)) {|m|
// ebml_w.tag(c::tag_table_inferred_modes) {||
// ebml_w.id(id);
// ebml_w.tag(c::tag_table_val) {||
@ -908,13 +908,13 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
// }
//}
do option::iter(&maps.mutbl_map.find(id)) |_m| {
do option::iter(&maps.mutbl_map.find(&id)) |_m| {
do ebml_w.tag(c::tag_table_mutbl) {
ebml_w.id(id);
}
}
do option::iter(&maps.last_use_map.find(id)) |m| {
do option::iter(&maps.last_use_map.find(&id)) |m| {
do ebml_w.tag(c::tag_table_last_use) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
@ -925,7 +925,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
}
}
do option::iter(&maps.method_map.find(id)) |mme| {
do option::iter(&maps.method_map.find(&id)) |mme| {
do ebml_w.tag(c::tag_table_method_map) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
@ -934,7 +934,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
}
}
do option::iter(&maps.vtable_map.find(id)) |dr| {
do option::iter(&maps.vtable_map.find(&id)) |dr| {
do ebml_w.tag(c::tag_table_vtable_map) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
@ -943,7 +943,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
}
}
do option::iter(&tcx.adjustments.find(id)) |adj| {
do option::iter(&tcx.adjustments.find(&id)) |adj| {
do ebml_w.tag(c::tag_table_adjustments) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {
@ -952,19 +952,19 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
}
}
do option::iter(&tcx.legacy_boxed_traits.find(id)) |_x| {
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 |_| {
for maps.moves_map.find(&id).each |_| {
do ebml_w.tag(c::tag_table_moves_map) {
ebml_w.id(id);
}
}
for maps.capture_map.find(id).each |cap_vars| {
for maps.capture_map.find(&id).each |cap_vars| {
do ebml_w.tag(c::tag_table_capture_map) {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) {

View File

@ -126,12 +126,12 @@ impl check_loan_ctxt {
let region_map = self.tcx().region_map;
let pure_map = self.req_maps.pure_map;
loop {
match pure_map.find(scope_id) {
match pure_map.find(&scope_id) {
None => (),
Some(ref e) => return Some(pc_cmt((*e)))
}
match region_map.find(scope_id) {
match region_map.find(&scope_id) {
None => return default_purity,
Some(next_scope_id) => scope_id = next_scope_id
}
@ -144,13 +144,13 @@ impl check_loan_ctxt {
let req_loan_map = self.req_maps.req_loan_map;
loop {
for req_loan_map.find(scope_id).each |loans| {
for req_loan_map.find(&scope_id).each |loans| {
for loans.each |loan| {
if !f(loan) { return; }
}
}
match region_map.find(scope_id) {
match region_map.find(&scope_id) {
None => return,
Some(next_scope_id) => scope_id = next_scope_id,
}
@ -199,7 +199,7 @@ impl check_loan_ctxt {
Some(expr) => {
match expr.node {
ast::expr_path(_) if pc == pc_pure_fn => {
let def = self.tcx().def_map.get(expr.id);
let def = self.tcx().def_map.get(&expr.id);
let did = ast_util::def_id_of_def(def);
let is_fn_arg =
did.crate == ast::local_crate &&
@ -221,18 +221,19 @@ impl check_loan_ctxt {
let callee_ty = ty::node_id_to_type(tcx, callee_id);
match ty::get(callee_ty).sty {
ty::ty_fn(ref fn_ty) => {
match fn_ty.meta.purity {
ast::pure_fn => return, // case (c) above
ast::impure_fn | ast::unsafe_fn | ast::extern_fn => {
self.report_purity_error(
pc, callee_span,
fmt!("access to %s function",
fn_ty.meta.purity.to_str()));
}
ty::ty_bare_fn(ty::BareFnTy {purity: purity, _}) |
ty::ty_closure(ty::ClosureTy {purity: purity, _}) => {
match purity {
ast::pure_fn => return, // case (c) above
ast::impure_fn | ast::unsafe_fn | ast::extern_fn => {
self.report_purity_error(
pc, callee_span,
fmt!("access to %s function",
purity.to_str()));
}
}
}
}
_ => return, // case (d) above
_ => return, // case (d) above
}
}
@ -240,14 +241,17 @@ impl check_loan_ctxt {
// The expression must be an expr_fn(*) or expr_fn_block(*)
fn is_stack_closure(id: ast::node_id) -> bool {
let fn_ty = ty::node_id_to_type(self.tcx(), id);
let proto = ty::ty_fn_proto(fn_ty);
return proto == ast::ProtoBorrowed;
match ty::get(fn_ty).sty {
ty::ty_closure(ty::ClosureTy {sigil: ast::BorrowedSigil,
_}) => true,
_ => false
}
}
fn is_allowed_pure_arg(expr: @ast::expr) -> bool {
return match expr.node {
ast::expr_path(_) => {
let def = self.tcx().def_map.get(expr.id);
let def = self.tcx().def_map.get(&expr.id);
let did = ast_util::def_id_of_def(def);
did.crate == ast::local_crate &&
(*self.fn_args).contains(&(did.node))
@ -262,14 +266,14 @@ impl check_loan_ctxt {
fn check_for_conflicting_loans(scope_id: ast::node_id) {
debug!("check_for_conflicting_loans(scope_id=%?)", scope_id);
let new_loans = match self.req_maps.req_loan_map.find(scope_id) {
let new_loans = match self.req_maps.req_loan_map.find(&scope_id) {
None => return,
Some(loans) => loans
};
debug!("new_loans has length %?", new_loans.len());
let par_scope_id = self.tcx().region_map.get(scope_id);
let par_scope_id = self.tcx().region_map.get(&scope_id);
for self.walk_loans(par_scope_id) |old_loan| {
debug!("old_loan=%?", self.bccx.loan_to_repr(old_loan));
@ -325,7 +329,7 @@ impl check_loan_ctxt {
fn check_assignment(at: assignment_type, ex: @ast::expr) {
// We don't use cat_expr() here because we don't want to treat
// auto-ref'd parameters in overloaded operators as rvalues.
let cmt = match self.bccx.tcx.adjustments.find(ex.id) {
let cmt = match self.bccx.tcx.adjustments.find(&ex.id) {
None => self.bccx.cat_expr_unadjusted(ex),
Some(adj) => self.bccx.cat_expr_autoderefd(ex, adj)
};
@ -564,17 +568,27 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
{
let is_stack_closure = self.is_stack_closure(id);
let fty = ty::node_id_to_type(self.tcx(), id);
let fty_proto = ty::ty_fn_proto(fty);
check_moves_from_captured_variables(self, id, fty_proto);
let declared_purity;
match fk {
visit::fk_item_fn(*) | visit::fk_method(*) |
visit::fk_dtor(*) => {
declared_purity = ty::ty_fn_purity(fty);
}
visit::fk_anon(*) | visit::fk_fn_block(*) => {
let fty_sigil = ty::ty_closure_sigil(fty);
check_moves_from_captured_variables(self, id, fty_sigil);
declared_purity = ty::determine_inherited_purity(
copy self.declared_purity, ty::ty_fn_purity(fty),
fty_sigil);
}
}
debug!("purity on entry=%?", copy self.declared_purity);
do save_and_restore(&mut(self.declared_purity)) {
do save_and_restore(&mut(self.fn_args)) {
self.declared_purity = ty::determine_inherited_purity(
copy self.declared_purity,
ty::ty_fn_purity(fty),
fty_proto);
self.declared_purity = declared_purity;
match fk {
visit::fk_anon(*) |
@ -608,11 +622,11 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
fn check_moves_from_captured_variables(&&self: check_loan_ctxt,
id: ast::node_id,
fty_proto: ast::Proto)
fty_sigil: ast::Sigil)
{
match fty_proto {
ast::ProtoBox | ast::ProtoUniq => {
let cap_vars = self.bccx.capture_map.get(id);
match fty_sigil {
ast::ManagedSigil | ast::OwnedSigil => {
let cap_vars = self.bccx.capture_map.get(&id);
for cap_vars.each |cap_var| {
match cap_var.mode {
moves::CapRef | moves::CapCopy => { loop; }
@ -646,7 +660,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
}
}
ast::ProtoBorrowed | ast::ProtoBare => {}
ast::BorrowedSigil => {}
}
}
}

View File

@ -126,7 +126,7 @@ fn req_loans_in_expr(ex: @ast::expr,
// If this expression is borrowed, have to ensure it remains valid:
if !self.ignore_adjustments.contains(&ex.id) {
for tcx.adjustments.find(ex.id).each |adjustments| {
for tcx.adjustments.find(&ex.id).each |adjustments| {
self.guarantee_adjustments(ex, *adjustments);
}
}
@ -172,7 +172,7 @@ fn req_loans_in_expr(ex: @ast::expr,
}
}
match self.bccx.method_map.find(ex.id) {
match self.bccx.method_map.find(&ex.id) {
Some(ref method_map_entry) => {
match (*method_map_entry).explicit_self {
ast::sty_by_ref => {
@ -250,7 +250,7 @@ fn req_loans_in_expr(ex: @ast::expr,
// (if used like `a.b(...)`), the call where it's an argument
// (if used like `x(a.b)`), or the block (if used like `let x
// = a.b`).
let scope_r = ty::re_scope(self.tcx().region_map.get(ex.id));
let scope_r = ty::re_scope(self.tcx().region_map.get(&ex.id));
let rcvr_cmt = self.bccx.cat_expr(rcvr);
self.guarantee_valid(rcvr_cmt, m_imm, scope_r);
visit::visit_expr(ex, self, vt);
@ -536,7 +536,7 @@ impl gather_loan_ctxt {
fn add_loans_to_scope_id(&self, scope_id: ast::node_id, +loans: ~[Loan]) {
debug!("adding %u loans to scope_id %?", loans.len(), scope_id);
match self.req_maps.req_loan_map.find(scope_id) {
match self.req_maps.req_loan_map.find(&scope_id) {
Some(req_loans) => {
req_loans.push_all(loans);
}

View File

@ -129,7 +129,7 @@ impl LoanContext {
~"rvalue with a non-none lp");
}
cat_local(local_id) | cat_arg(local_id) | cat_self(local_id) => {
let local_scope_id = self.tcx().region_map.get(local_id);
let local_scope_id = self.tcx().region_map.get(&local_id);
self.issue_loan(cmt, ty::re_scope(local_scope_id), req_mutbl,
owns_lent_data)
}

View File

@ -109,7 +109,7 @@ impl PreserveCtxt {
// Maybe if we pass in the parent instead here,
// we can prevent the "scope not found" error
debug!("scope_region thing: %? ", cmt.id);
ty::re_scope(self.tcx().region_map.get(cmt.id))
ty::re_scope(self.tcx().region_map.get(&cmt.id))
};
self.compare_scope(cmt, scope_region)
@ -129,14 +129,14 @@ impl PreserveCtxt {
cmt.span,
~"preserve() called with local and !root_managed_data");
}
let local_scope_id = self.tcx().region_map.get(local_id);
let local_scope_id = self.tcx().region_map.get(&local_id);
self.compare_scope(cmt, ty::re_scope(local_scope_id))
}
cat_binding(local_id) => {
// Bindings are these kind of weird implicit pointers (cc
// #2329). We require (in gather_loans) that they be
// rooted in an immutable location.
let local_scope_id = self.tcx().region_map.get(local_id);
let local_scope_id = self.tcx().region_map.get(&local_id);
self.compare_scope(cmt, ty::re_scope(local_scope_id))
}
cat_arg(local_id) => {
@ -144,11 +144,11 @@ impl PreserveCtxt {
// modes). In that case, the caller guarantees stability
// for at least the scope of the fn. This is basically a
// deref of a region ptr.
let local_scope_id = self.tcx().region_map.get(local_id);
let local_scope_id = self.tcx().region_map.get(&local_id);
self.compare_scope(cmt, ty::re_scope(local_scope_id))
}
cat_self(local_id) => {
let local_scope_id = self.tcx().region_map.get(local_id);
let local_scope_id = self.tcx().region_map.get(&local_id);
self.compare_scope(cmt, ty::re_scope(local_scope_id))
}
cat_comp(cmt_base, comp_field(*)) |

View File

@ -126,7 +126,7 @@ pub fn check_expr(sess: Session,
e.span, ~"paths in constants may only refer to \
items without type parameters");
}
match def_map.find(e.id) {
match def_map.find(&e.id) {
Some(def_const(def_id)) |
Some(def_fn(def_id, _)) |
Some(def_variant(_, def_id)) |
@ -150,8 +150,8 @@ pub fn check_expr(sess: Session,
}
}
}
expr_call(callee, _, false) => {
match def_map.find(callee.id) {
expr_call(callee, _, NoSugar) => {
match def_map.find(&callee.id) {
Some(def_struct(*)) => {} // OK.
Some(def_variant(*)) => {} // OK.
_ => {
@ -247,9 +247,9 @@ pub fn check_item_recursion(sess: Session,
fn visit_expr(e: @expr, &&env: env, v: visit::vt<env>) {
match e.node {
expr_path(*) => {
match env.def_map.find(e.id) {
match env.def_map.find(&e.id) {
Some(def_const(def_id)) => {
match env.ast_map.get(def_id.node) {
match env.ast_map.get(&def_id.node) {
ast_map::node_item(it, _) => {
(v.visit_item)(it, env, v);
}

View File

@ -39,8 +39,8 @@ pub fn check_crate(tcx: ty::ctxt, crate: @crate) {
(v.visit_block)((*b), {in_loop: false, can_ret: false}, v);
}
expr_loop_body(@expr {node: expr_fn_block(_, ref b), _}) => {
let proto = ty::ty_fn_proto(ty::expr_ty(tcx, e));
let blk = (proto == ProtoBorrowed);
let sigil = ty::ty_closure_sigil(ty::expr_ty(tcx, e));
let blk = (sigil == BorrowedSigil);
(v.visit_block)((*b), {in_loop: true, can_ret: blk}, v);
}
expr_break(_) => {

View File

@ -100,7 +100,7 @@ pub fn check_expr(cx: @MatchCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) {
}
_ => { /* We assume only enum types can be uninhabited */ }
}
let arms = vec::concat(vec::filter_map((*arms), unguarded_pat));
let arms = vec::concat(arms.filter_mapped(unguarded_pat));
check_exhaustive(cx, ex.span, arms);
}
_ => ()
@ -255,7 +255,8 @@ pub fn is_useful(cx: @MatchCheckCtxt, +m: matrix, +v: &[@pat]) -> useful {
}
}
Some(ref ctor) => {
match is_useful(cx, vec::filter_map(m, |r| default(cx, copy *r)),
match is_useful(cx,
vec::filter_map(m, |r| default(cx, r)),
vec::tail(v)) {
useful_ => useful(left_ty, (/*bad*/copy *ctor)),
ref u => (/*bad*/copy *u)
@ -277,8 +278,7 @@ pub fn is_useful_specialized(cx: @MatchCheckCtxt,
arity: uint,
lty: ty::t)
-> useful {
let ms = vec::filter_map(m, |r| specialize(cx, *r,
ctor, arity, lty));
let ms = m.filter_mapped(|r| specialize(cx, *r, ctor, arity, lty));
let could_be_useful = is_useful(
cx, ms, specialize(cx, v, ctor, arity, lty).get());
match could_be_useful {
@ -292,7 +292,7 @@ pub fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option<ctor> {
match /*bad*/copy pat.node {
pat_wild => { None }
pat_ident(_, _, _) | pat_enum(_, _) => {
match cx.tcx.def_map.find(pat.id) {
match cx.tcx.def_map.find(&pat.id) {
Some(def_variant(_, id)) => Some(variant(id)),
Some(def_const(did)) => {
let const_expr = lookup_const_by_id(cx.tcx, did).get();
@ -306,7 +306,7 @@ pub fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option<ctor> {
Some(range(eval_const_expr(cx.tcx, lo), eval_const_expr(cx.tcx, hi)))
}
pat_struct(*) => {
match cx.tcx.def_map.find(pat.id) {
match cx.tcx.def_map.find(&pat.id) {
Some(def_variant(_, id)) => Some(variant(id)),
_ => Some(single)
}
@ -329,7 +329,7 @@ pub fn is_wild(cx: @MatchCheckCtxt, p: @pat) -> bool {
match pat.node {
pat_wild => { true }
pat_ident(_, _, _) => {
match cx.tcx.def_map.find(pat.id) {
match cx.tcx.def_map.find(&pat.id) {
Some(def_variant(_, _)) | Some(def_const(*)) => { false }
_ => { true }
}
@ -387,9 +387,9 @@ pub fn missing_ctor(cx: @MatchCheckCtxt,
ty::ty_unboxed_vec(*) | ty::ty_evec(*) => {
// Find the lengths and tails of all vector patterns.
let vec_pat_lens = do m.filter_map |r| {
match /*bad*/copy r[0].node {
pat_vec(elems, tail) => {
let vec_pat_lens = do m.filter_mapped |r| {
match r[0].node {
pat_vec(ref elems, ref tail) => {
Some((elems.len(), tail.is_some()))
}
_ => None
@ -480,7 +480,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
pat_wild => Some(vec::append(vec::from_elem(arity, wild()),
vec::tail(r))),
pat_ident(_, _, _) => {
match cx.tcx.def_map.find(pat_id) {
match cx.tcx.def_map.find(&pat_id) {
Some(def_variant(_, id)) => {
if variant(id) == ctor_id { Some(vec::tail(r)) }
else { None }
@ -505,7 +505,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
}
}
pat_enum(_, args) => {
match cx.tcx.def_map.get(pat_id) {
match cx.tcx.def_map.get(&pat_id) {
def_variant(_, id) if variant(id) == ctor_id => {
let args = match args {
Some(args) => args,
@ -541,7 +541,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
}
pat_struct(_, ref flds, _) => {
// Is this a struct or an enum variant?
match cx.tcx.def_map.get(pat_id) {
match cx.tcx.def_map.get(&pat_id) {
def_variant(_, variant_id) => {
if variant(variant_id) == ctor_id {
// FIXME #4731: Is this right? --pcw
@ -678,7 +678,7 @@ pub fn check_fn(cx: @MatchCheckCtxt,
}
pub fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool {
match cx.tcx.def_map.find(pat.id) {
match cx.tcx.def_map.find(&pat.id) {
Some(def_variant(enum_id, _)) => {
if vec::len(*ty::enum_variants(cx.tcx, enum_id)) != 1u {
return true;

View File

@ -78,7 +78,7 @@ pub fn classify(e: @expr,
tcx: ty::ctxt)
-> constness {
let did = ast_util::local_def(e.id);
match tcx.ccache.find(did) {
match tcx.ccache.find(&did) {
Some(x) => x,
None => {
let cn =
@ -170,7 +170,7 @@ pub fn classify(e: @expr,
}
pub fn lookup_const(tcx: ty::ctxt, e: @expr) -> Option<@expr> {
match tcx.def_map.find(e.id) {
match tcx.def_map.find(&e.id) {
Some(ast::def_const(def_id)) => lookup_const_by_id(tcx, def_id),
_ => None
}
@ -180,7 +180,7 @@ pub fn lookup_const_by_id(tcx: ty::ctxt,
def_id: ast::def_id)
-> Option<@expr> {
if ast_util::is_local(def_id) {
match tcx.items.find(def_id.node) {
match tcx.items.find(&def_id.node) {
None => None,
Some(ast_map::node_item(it, _)) => match it.node {
item_const(_, const_expr) => Some(const_expr),

View File

@ -48,17 +48,15 @@ fn collect_freevars(def_map: resolve::DefMap, blk: ast::blk)
let walk_expr = fn@(expr: @ast::expr, &&depth: int, v: visit::vt<int>) {
match expr.node {
ast::expr_fn(proto, _, _, _) => {
if proto != ast::ProtoBare {
visit::visit_expr(expr, depth + 1, v);
}
ast::expr_fn(_, _, _, _) => {
visit::visit_expr(expr, depth + 1, v);
}
ast::expr_fn_block(*) => {
visit::visit_expr(expr, depth + 1, v);
}
ast::expr_path(*) => {
let mut i = 0;
match def_map.find(expr.id) {
match def_map.find(&expr.id) {
None => die!(~"path not found"),
Some(df) => {
let mut def = df;
@ -118,7 +116,7 @@ pub fn annotate_freevars(def_map: resolve::DefMap, crate: @ast::crate) ->
}
pub fn get_freevars(tcx: ty::ctxt, fid: ast::node_id) -> freevar_info {
match tcx.freevars.find(fid) {
match tcx.freevars.find(&fid) {
None => die!(~"get_freevars: " + int::str(fid) + ~" has no freevars"),
Some(d) => return d
}

View File

@ -150,11 +150,23 @@ fn with_appropriate_checker(cx: ctx, id: node_id, b: fn(check_fn)) {
}
let fty = ty::node_id_to_type(cx.tcx, id);
match ty::ty_fn_proto(fty) {
ProtoUniq => b(check_for_uniq),
ProtoBox => b(check_for_box),
ProtoBare => b(check_for_bare),
ProtoBorrowed => b(check_for_block),
match ty::get(fty).sty {
ty::ty_closure(ty::ClosureTy {sigil: OwnedSigil, _}) => {
b(check_for_uniq)
}
ty::ty_closure(ty::ClosureTy {sigil: ManagedSigil, _}) => {
b(check_for_box)
}
ty::ty_closure(ty::ClosureTy {sigil: BorrowedSigil, _}) => {
b(check_for_block)
}
ty::ty_bare_fn(_) => {
b(check_for_bare)
}
ref s => {
cx.tcx.sess.bug(
fmt!("expect fn type in kind checker, not %?", s));
}
}
}
@ -195,10 +207,10 @@ pub fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
expr_unary(*)|expr_binary(*)|expr_method_call(*) => e.callee_id,
_ => e.id
};
do option::iter(&cx.tcx.node_type_substs.find(type_parameter_id)) |ts| {
do option::iter(&cx.tcx.node_type_substs.find(&type_parameter_id)) |ts| {
let bounds = match e.node {
expr_path(_) => {
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(e.id));
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(&e.id));
ty::lookup_item_type(cx.tcx, did).bounds
}
_ => {
@ -240,42 +252,6 @@ pub fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
expr.span,
"explicit copy requires a copyable argument");
}
expr_rec(ref fields, def) | expr_struct(_, ref fields, def) => {
match def {
Some(ex) => {
// All noncopyable fields must be overridden
let t = ty::expr_ty(cx.tcx, ex);
let ty_fields = match ty::get(t).sty {
ty::ty_rec(ref f) => {
copy *f
}
ty::ty_struct(did, ref substs) => {
ty::struct_fields(cx.tcx, did, substs)
}
_ => {
cx.tcx.sess.span_bug(
ex.span,
~"bad base expr type in record")
}
};
for ty_fields.each |tf| {
// If this field would not be copied, ok.
if fields.any(|f| f.node.ident == tf.ident) { loop; }
// If this field is copyable, ok.
let kind = ty::type_kind(cx.tcx, tf.mt.ty);
if ty::kind_can_be_copied(kind) { loop; }
cx.tcx.sess.span_err(
e.span,
fmt!("cannot copy field `%s` of base expression, \
which has a noncopyable type",
*cx.tcx.sess.intr().get(tf.ident)));
}
}
_ => {}
}
}
expr_repeat(element, count_expr, _) => {
let count = ty::eval_repeat_count(cx.tcx, count_expr, e.span);
if count > 1 {
@ -292,8 +268,8 @@ pub fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
fn check_ty(aty: @Ty, cx: ctx, v: visit::vt<ctx>) {
match aty.node {
ty_path(_, id) => {
do option::iter(&cx.tcx.node_type_substs.find(id)) |ts| {
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(id));
do option::iter(&cx.tcx.node_type_substs.find(&id)) |ts| {
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(&id));
let bounds = ty::lookup_item_type(cx.tcx, did).bounds;
for vec::each2(*ts, *bounds) |ty, bound| {
check_bounds(cx, aty.id, aty.span, *ty, *bound)
@ -334,7 +310,7 @@ pub fn check_bounds(cx: ctx, id: node_id, sp: span,
fn is_nullary_variant(cx: ctx, ex: @expr) -> bool {
match ex.node {
expr_path(_) => {
match cx.tcx.def_map.get(ex.id) {
match cx.tcx.def_map.get(&ex.id) {
def_variant(edid, vdid) => {
vec::len(ty::enum_variant_with_id(cx.tcx, edid, vdid).args) == 0u
}

View File

@ -352,7 +352,7 @@ impl LanguageItemCollector {
return; // Didn't match.
}
match self.item_refs.find(/*bad*/copy value) {
match self.item_refs.find(&value) {
None => {
// Didn't match.
}

View File

@ -265,7 +265,7 @@ pub fn get_lint_settings_level(settings: lint_settings,
_expr_id: ast::node_id,
item_id: ast::node_id)
-> level {
match settings.settings_map.find(item_id) {
match settings.settings_map.find(&item_id) {
Some(modes) => get_lint_level(modes, lint_mode),
None => get_lint_level(settings.default_settings, lint_mode)
}
@ -346,7 +346,7 @@ impl ctxt {
for triples.each |pair| {
let (meta, level, lintname) = /*bad*/copy *pair;
match self.dict.find(/*bad*/ copy lintname) {
match self.dict.find(&lintname) {
None => {
self.span_lint(
new_ctxt.get_level(unrecognized_lint),
@ -684,7 +684,7 @@ fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
for vec::each(vec::append_one(tys, decl.output)) |ty| {
match ty.node {
ast::ty_path(_, id) => {
match cx.def_map.get(id) {
match cx.def_map.get(&id) {
ast::def_prim_ty(ast::ty_int(ast::ty_i)) => {
cx.sess.span_lint(
ctypes, id, fn_id,
@ -897,9 +897,10 @@ fn check_fn(tcx: ty::ctxt, fk: visit::fn_kind, decl: ast::fn_decl,
fn check_fn_deprecated_modes(tcx: ty::ctxt, fn_ty: ty::t, decl: ast::fn_decl,
span: span, id: ast::node_id) {
match ty::get(fn_ty).sty {
ty::ty_fn(ref fn_ty) => {
ty::ty_closure(ty::ClosureTy {sig: ref sig, _}) |
ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, _}) => {
let mut counter = 0;
for vec::each2(fn_ty.sig.inputs, decl.inputs) |arg_ty, arg_ast| {
for vec::each2(sig.inputs, decl.inputs) |arg_ty, arg_ast| {
counter += 1;
debug!("arg %d, ty=%s, mode=%s",
counter,
@ -938,13 +939,14 @@ fn check_fn_deprecated_modes(tcx: ty::ctxt, fn_ty: ty::t, decl: ast::fn_decl,
}
match ty::get(arg_ty.ty).sty {
ty::ty_fn(*) => {
ty::ty_closure(*) | ty::ty_bare_fn(*) => {
let span = arg_ast.ty.span;
// Recurse to check fn-type argument
match arg_ast.ty.node {
ast::ty_fn(f) => {
ast::ty_closure(@ast::TyClosure{decl: ref d, _}) |
ast::ty_bare_fn(@ast::TyBareFn{decl: ref d, _})=>{
check_fn_deprecated_modes(tcx, arg_ty.ty,
f.decl, span, id);
*d, span, id);
}
ast::ty_path(*) => {
// This is probably a typedef, so we can't
@ -976,10 +978,11 @@ fn check_item_deprecated_modes(tcx: ty::ctxt, it: @ast::item) {
match it.node {
ast::item_ty(ty, _) => {
match ty.node {
ast::ty_fn(f) => {
ast::ty_closure(@ast::TyClosure {decl: ref decl, _}) |
ast::ty_bare_fn(@ast::TyBareFn {decl: ref decl, _}) => {
let fn_ty = ty::node_id_to_type(tcx, it.id);
check_fn_deprecated_modes(
tcx, fn_ty, f.decl, ty.span, it.id)
tcx, fn_ty, *decl, ty.span, it.id)
}
_ => ()
}

View File

@ -368,7 +368,7 @@ impl IrMaps {
}
fn variable(node_id: node_id, span: span) -> Variable {
match self.variable_map.find(node_id) {
match self.variable_map.find(&node_id) {
Some(var) => var,
None => {
self.tcx.sess.span_bug(
@ -390,7 +390,7 @@ impl IrMaps {
}
fn captures(expr: @expr) -> @~[CaptureInfo] {
match self.capture_info_map.find(expr.id) {
match self.capture_info_map.find(&expr.id) {
Some(caps) => caps,
None => {
self.tcx.sess.span_bug(expr.span, ~"no registered caps");
@ -410,7 +410,7 @@ impl IrMaps {
Local(LocalInfo {id: id, kind: FromLetNoInitializer, _}) |
Local(LocalInfo {id: id, kind: FromLetWithInitializer, _}) |
Local(LocalInfo {id: id, kind: FromMatch(_), _}) => {
let v = match self.last_use_map.find(expr_id) {
let v = match self.last_use_map.find(&expr_id) {
Some(v) => v,
None => {
let v = @DVec();
@ -552,7 +552,7 @@ fn visit_expr(expr: @expr, &&self: @IrMaps, vt: vt<@IrMaps>) {
match expr.node {
// live nodes required for uses or definitions of variables:
expr_path(_) => {
let def = self.tcx.def_map.get(expr.id);
let def = self.tcx.def_map.get(&expr.id);
debug!("expr %d: path that leads to %?", expr.id, def);
if relevant_def(def).is_some() {
self.add_live_node_for_node(expr.id, ExprNode(expr.span));
@ -569,7 +569,7 @@ fn visit_expr(expr: @expr, &&self: @IrMaps, vt: vt<@IrMaps>) {
// being the location that the variable is used. This results
// in better error messages than just pointing at the closure
// construction site.
let cvs = self.capture_map.get(expr.id);
let cvs = self.capture_map.get(&expr.id);
let mut call_caps = ~[];
for cvs.each |cv| {
match relevant_def(cv.def) {
@ -685,7 +685,7 @@ fn Liveness(ir: @IrMaps, specials: Specials) -> Liveness {
impl Liveness {
fn live_node(node_id: node_id, span: span) -> LiveNode {
match self.ir.live_node_map.find(node_id) {
match self.ir.live_node_map.find(&node_id) {
Some(ln) => ln,
None => {
// This must be a mismatch between the ir_map construction
@ -702,7 +702,7 @@ impl Liveness {
fn variable_from_path(expr: @expr) -> Option<Variable> {
match expr.node {
expr_path(_) => {
let def = self.tcx.def_map.get(expr.id);
let def = self.tcx.def_map.get(&expr.id);
relevant_def(def).map(
|rdef| self.variable(*rdef, expr.span)
)
@ -717,7 +717,7 @@ impl Liveness {
fn variable_from_def_map(node_id: node_id,
span: span) -> Option<Variable> {
match self.tcx.def_map.find(node_id) {
match self.tcx.def_map.find(&node_id) {
Some(def) => {
relevant_def(def).map(
|rdef| self.variable(*rdef, span)
@ -837,7 +837,7 @@ impl Liveness {
match opt_label {
Some(_) => // Refers to a labeled loop. Use the results of resolve
// to find with one
match self.tcx.def_map.find(id) {
match self.tcx.def_map.find(&id) {
Some(def_label(loop_id)) => loop_id,
_ => self.tcx.sess.span_bug(sp, ~"Label on break/loop \
doesn't refer to a loop")
@ -1203,7 +1203,7 @@ impl Liveness {
// Now that we know the label we're going to,
// look it up in the break loop nodes table
match self.break_ln.find(sc) {
match self.break_ln.find(&sc) {
Some(b) => b,
None => self.tcx.sess.span_bug(expr.span,
~"Break to unknown label")
@ -1217,7 +1217,7 @@ impl Liveness {
// Now that we know the label we're going to,
// look it up in the continue loop nodes table
match self.cont_ln.find(sc) {
match self.cont_ln.find(&sc) {
Some(b) => b,
None => self.tcx.sess.span_bug(expr.span,
~"Loop to unknown label")
@ -1424,7 +1424,7 @@ impl Liveness {
}
fn access_path(expr: @expr, succ: LiveNode, acc: uint) -> LiveNode {
let def = self.tcx.def_map.get(expr.id);
let def = self.tcx.def_map.get(&expr.id);
match relevant_def(def) {
Some(nid) => {
let ln = self.live_node(expr.id, expr.span);
@ -1560,7 +1560,7 @@ fn check_expr(expr: @expr, &&self: @Liveness, vt: vt<@Liveness>) {
let ln = self.live_node(expr.id, expr.span);
self.consider_last_use(expr, ln, *var);
match self.ir.variable_moves_map.find(expr.id) {
match self.ir.variable_moves_map.find(&expr.id) {
None => {}
Some(entire_expr) => {
debug!("(checking expr) is a move: `%s`",
@ -1689,7 +1689,7 @@ impl @Liveness {
fn check_lvalue(expr: @expr, vt: vt<@Liveness>) {
match expr.node {
expr_path(_) => {
match self.tcx.def_map.get(expr.id) {
match self.tcx.def_map.get(&expr.id) {
def_local(nid, false) => {
// Assignment to an immutable variable or argument:
// only legal if there is no later assignment.

View File

@ -146,63 +146,55 @@ pub enum deref_kind {deref_ptr(ptr_kind), deref_comp(comp_kind)}
// pointer adjustment).
pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
match ty::get(t).sty {
ty::ty_uniq(*) |
ty::ty_evec(_, ty::vstore_uniq) |
ty::ty_estr(ty::vstore_uniq) => {
Some(deref_ptr(uniq_ptr))
}
ty::ty_uniq(*) |
ty::ty_evec(_, ty::vstore_uniq) |
ty::ty_estr(ty::vstore_uniq) |
ty::ty_closure(ty::ClosureTy {sigil: ast::OwnedSigil, _}) => {
Some(deref_ptr(uniq_ptr))
}
ty::ty_fn(ref f) if (*f).meta.proto == ast::ProtoUniq => {
Some(deref_ptr(uniq_ptr))
}
ty::ty_rptr(r, mt) |
ty::ty_evec(mt, ty::vstore_slice(r)) => {
Some(deref_ptr(region_ptr(mt.mutbl, r)))
}
ty::ty_rptr(r, mt) |
ty::ty_evec(mt, ty::vstore_slice(r)) => {
Some(deref_ptr(region_ptr(mt.mutbl, r)))
}
ty::ty_estr(ty::vstore_slice(r)) |
ty::ty_closure(ty::ClosureTy {sigil: ast::BorrowedSigil,
region: r, _}) => {
Some(deref_ptr(region_ptr(ast::m_imm, r)))
}
ty::ty_estr(ty::vstore_slice(r)) => {
Some(deref_ptr(region_ptr(ast::m_imm, r)))
}
ty::ty_box(mt) |
ty::ty_evec(mt, ty::vstore_box) => {
Some(deref_ptr(gc_ptr(mt.mutbl)))
}
ty::ty_fn(ref f) if (*f).meta.proto == ast::ProtoBorrowed => {
Some(deref_ptr(region_ptr(ast::m_imm, (*f).meta.region)))
}
ty::ty_estr(ty::vstore_box) |
ty::ty_closure(ty::ClosureTy {sigil: ast::ManagedSigil, _}) => {
Some(deref_ptr(gc_ptr(ast::m_imm)))
}
ty::ty_box(mt) |
ty::ty_evec(mt, ty::vstore_box) => {
Some(deref_ptr(gc_ptr(mt.mutbl)))
}
ty::ty_ptr(*) => {
Some(deref_ptr(unsafe_ptr))
}
ty::ty_estr(ty::vstore_box) => {
Some(deref_ptr(gc_ptr(ast::m_imm)))
}
ty::ty_enum(did, _) => {
Some(deref_comp(comp_variant(did)))
}
ty::ty_fn(ref f) if (*f).meta.proto == ast::ProtoBox => {
Some(deref_ptr(gc_ptr(ast::m_imm)))
}
ty::ty_struct(_, _) => {
Some(deref_comp(comp_anon_field))
}
ty::ty_ptr(*) => {
Some(deref_ptr(unsafe_ptr))
}
ty::ty_evec(mt, ty::vstore_fixed(_)) => {
Some(deref_comp(comp_index(t, mt.mutbl)))
}
ty::ty_enum(did, _) => {
Some(deref_comp(comp_variant(did)))
}
ty::ty_estr(ty::vstore_fixed(_)) => {
Some(deref_comp(comp_index(t, m_imm)))
}
ty::ty_struct(_, _) => {
Some(deref_comp(comp_anon_field))
}
ty::ty_evec(mt, ty::vstore_fixed(_)) => {
Some(deref_comp(comp_index(t, mt.mutbl)))
}
ty::ty_estr(ty::vstore_fixed(_)) => {
Some(deref_comp(comp_index(t, m_imm)))
}
_ => None
_ => None
}
}
@ -308,7 +300,7 @@ pub struct mem_categorization_ctxt {
pub impl &mem_categorization_ctxt {
fn cat_expr(expr: @ast::expr) -> cmt {
match self.tcx.adjustments.find(expr.id) {
match self.tcx.adjustments.find(&expr.id) {
None => {
// No adjustments.
self.cat_expr_unadjusted(expr)
@ -375,7 +367,7 @@ pub impl &mem_categorization_ctxt {
}
ast::expr_path(_) => {
let def = self.tcx.def_map.get(expr.id);
let def = self.tcx.def_map.get(&expr.id);
self.cat_def(expr.id, expr.span, expr_ty, def)
}
@ -473,9 +465,9 @@ pub impl &mem_categorization_ctxt {
ast::def_upvar(_, inner, fn_node_id, _) => {
let ty = ty::node_id_to_type(self.tcx, fn_node_id);
let proto = ty::ty_fn_proto(ty);
match proto {
ast::ProtoBorrowed => {
let sigil = ty::ty_closure_sigil(ty);
match sigil {
ast::BorrowedSigil => {
let upcmt = self.cat_def(id, span, expr_ty, *inner);
@cmt_ {
id:id,
@ -486,7 +478,7 @@ pub impl &mem_categorization_ctxt {
ty:upcmt.ty
}
}
ast::ProtoUniq | ast::ProtoBox => {
ast::OwnedSigil | ast::ManagedSigil => {
// FIXME #2152 allow mutation of moved upvars
@cmt_ {
id:id,
@ -497,11 +489,6 @@ pub impl &mem_categorization_ctxt {
ty:expr_ty
}
}
ast::ProtoBare => {
self.tcx.sess.span_bug(
span,
fmt!("Upvar in a bare closure?"));
}
}
}
@ -840,7 +827,7 @@ pub impl &mem_categorization_ctxt {
// variant(*)
}
ast::pat_enum(_, Some(ref subpats)) => {
match self.tcx.def_map.find(pat.id) {
match self.tcx.def_map.find(&pat.id) {
Some(ast::def_variant(enum_did, _)) => {
// variant(x, y, z)
for subpats.each |subpat| {
@ -1063,7 +1050,7 @@ pub fn field_mutbl(tcx: ty::ctxt,
}
}
ty::ty_enum(*) => {
match tcx.def_map.get(node_id) {
match tcx.def_map.get(&node_id) {
ast::def_variant(_, variant_id) => {
for ty::lookup_struct_fields(tcx, variant_id).each |fld| {
if fld.ident == f_name {

View File

@ -409,7 +409,7 @@ impl VisitContext {
// `expr_mode` refers to the post-adjustment value. If one of
// those adjustments is to take a reference, then it's only
// reading the underlying expression, not moving it.
let comp_mode = match self.tcx.adjustments.find(expr.id) {
let comp_mode = match self.tcx.adjustments.find(&expr.id) {
Some(adj) if adj.autoref.is_some() => Read,
_ => expr_mode.component_mode(expr)
};
@ -474,7 +474,35 @@ impl VisitContext {
}
for opt_with.each |with_expr| {
self.consume_expr(*with_expr, visitor);
// If there are any fields whose type is move-by-default,
// then `with` is consumed, otherwise it is only read
let with_ty = ty::expr_ty(self.tcx, *with_expr);
let with_fields = match ty::get(with_ty).sty {
ty::ty_rec(ref f) => copy *f,
ty::ty_struct(did, ref substs) => {
ty::struct_fields(self.tcx, did, substs)
}
ref r => {
self.tcx.sess.span_bug(
with_expr.span,
fmt!("bad base expr type in record: %?", r))
}
};
// The `with` expr must be consumed if it contains
// any fields which (1) were not explicitly
// specified and (2) have a type that
// moves-by-default:
let consume_with = with_fields.any(|tf| {
!fields.any(|f| f.node.ident == tf.ident) &&
ty::type_implicitly_moves(self.tcx, tf.mt.ty)
});
if consume_with {
self.consume_expr(*with_expr, visitor);
} else {
self.use_expr(*with_expr, Read, visitor);
}
}
}
@ -713,7 +741,7 @@ impl VisitContext {
receiver_expr: @expr,
visitor: vt<VisitContext>)
{
let callee_mode = match self.method_map.find(expr_id) {
let callee_mode = match self.method_map.find(&expr_id) {
Some(ref method_map_entry) => {
match method_map_entry.explicit_self {
sty_by_ref => by_ref,
@ -786,9 +814,9 @@ impl VisitContext {
let _indenter = indenter();
let fn_ty = ty::node_id_to_type(self.tcx, fn_expr_id);
let proto = ty::ty_fn_proto(fn_ty);
let sigil = ty::ty_closure_sigil(fn_ty);
let freevars = freevars::get_freevars(self.tcx, fn_expr_id);
if proto == ProtoBorrowed {
if sigil == BorrowedSigil {
// &fn() captures everything by ref
at_vec::from_fn(freevars.len(), |i| {
let fvar = &freevars[i];

View File

@ -35,7 +35,7 @@ pub fn pat_id_map(dm: resolve::DefMap, pat: @pat) -> PatIdMap {
pub fn pat_is_variant_or_struct(dm: resolve::DefMap, pat: @pat) -> bool {
match pat.node {
pat_enum(_, _) | pat_ident(_, _, None) | pat_struct(*) => {
match dm.find(pat.id) {
match dm.find(&pat.id) {
Some(def_variant(*)) | Some(def_struct(*)) => true,
_ => false
}
@ -47,7 +47,7 @@ pub fn pat_is_variant_or_struct(dm: resolve::DefMap, pat: @pat) -> bool {
pub fn pat_is_const(dm: resolve::DefMap, pat: &pat) -> bool {
match pat.node {
pat_ident(_, _, None) => {
match dm.find(pat.id) {
match dm.find(&pat.id) {
Some(def_const(*)) => true,
_ => false
}

View File

@ -105,7 +105,7 @@ pub fn check_crate(tcx: ty::ctxt,
match *origin {
method_static(method_id) => {
if method_id.crate == local_crate {
match tcx.items.find(method_id.node) {
match tcx.items.find(&method_id.node) {
Some(node_method(method, impl_id, _)) => {
if method.vis == private &&
(impl_id.crate != local_crate ||
@ -143,7 +143,7 @@ pub fn check_crate(tcx: ty::ctxt,
method_self(trait_id, method_num) |
method_super(trait_id, method_num) => {
if trait_id.crate == local_crate {
match tcx.items.find(trait_id.node) {
match tcx.items.find(&trait_id.node) {
Some(node_item(item, _)) => {
match item.node {
item_trait(_, _, ref methods) => {
@ -221,7 +221,7 @@ pub fn check_crate(tcx: ty::ctxt,
ty_struct(id, _)
if id.crate != local_crate ||
!privileged_items.contains(&(id.node)) => {
match method_map.find(expr.id) {
match method_map.find(&expr.id) {
None => {
debug!("(privacy checking) checking \
field access");
@ -244,7 +244,7 @@ pub fn check_crate(tcx: ty::ctxt,
ty_struct(id, _)
if id.crate != local_crate ||
!privileged_items.contains(&(id.node)) => {
match method_map.find(expr.id) {
match method_map.find(&expr.id) {
None => {
tcx.sess.span_bug(expr.span,
~"method call not in \
@ -276,7 +276,7 @@ pub fn check_crate(tcx: ty::ctxt,
ty_enum(id, _) => {
if id.crate != local_crate ||
!privileged_items.contains(&(id.node)) {
match tcx.def_map.get(expr.id) {
match tcx.def_map.get(&expr.id) {
def_variant(_, variant_id) => {
for (*fields).each |field| {
debug!("(privacy checking) \
@ -343,7 +343,7 @@ pub fn check_crate(tcx: ty::ctxt,
if enum_id.crate != local_crate ||
!privileged_items.contains(
&enum_id.node) {
match tcx.def_map.find(pattern.id) {
match tcx.def_map.find(&pattern.id) {
Some(def_variant(_, variant_id)) => {
for fields.each |field| {
debug!("(privacy checking) \

View File

@ -115,7 +115,7 @@ pub fn scope_contains(region_map: region_map, superscope: ast::node_id,
subscope: ast::node_id) -> bool {
let mut subscope = subscope;
while superscope != subscope {
match region_map.find(subscope) {
match region_map.find(&subscope) {
None => return false,
Some(scope) => subscope = scope
}
@ -159,7 +159,7 @@ pub fn nearest_common_ancestor(region_map: region_map,
let mut result = ~[scope];
let mut scope = scope;
loop {
match region_map.find(scope) {
match region_map.find(&scope) {
None => return result,
Some(superscope) => {
result.push(superscope);
@ -237,7 +237,7 @@ pub fn resolve_arm(arm: ast::arm, cx: ctxt, visitor: visit::vt<ctxt>) {
pub fn resolve_pat(pat: @ast::pat, cx: ctxt, visitor: visit::vt<ctxt>) {
match pat.node {
ast::pat_ident(*) => {
let defn_opt = cx.def_map.find(pat.id);
let defn_opt = cx.def_map.find(&pat.id);
match defn_opt {
Some(ast::def_variant(_,_)) => {
/* Nothing to do; this names a variant. */
@ -475,7 +475,7 @@ pub impl determine_rp_ctxt {
/// the new variance is joined with the old variance.
fn add_rp(id: ast::node_id, variance: region_variance) {
assert id != 0;
let old_variance = self.region_paramd_items.find(id);
let old_variance = self.region_paramd_items.find(&id);
let joined_variance = match old_variance {
None => variance,
Some(v) => join_variance(v, variance)
@ -505,7 +505,7 @@ pub impl determine_rp_ctxt {
ast_map::node_id_to_str(self.ast_map, self.item_id,
self.sess.parse_sess.interner),
copy self.ambient_variance);
let vec = match self.dep_map.find(from) {
let vec = match self.dep_map.find(&from) {
Some(vec) => vec,
None => {
let vec = @DVec();
@ -657,7 +657,7 @@ pub fn determine_rp_in_ty(ty: @ast::Ty,
}
}
ast::ty_fn(f) => {
ast::ty_closure(ref f) => {
debug!("referenced fn type: %s",
pprust::ty_to_str(ty, cx.sess.intr()));
match f.region {
@ -668,7 +668,7 @@ pub fn determine_rp_in_ty(ty: @ast::Ty,
}
}
None => {
if f.proto == ast::ProtoBorrowed && cx.anon_implies_rp {
if f.sigil == ast::BorrowedSigil && cx.anon_implies_rp {
cx.add_rp(cx.item_id,
cx.add_variance(rv_contravariant));
}
@ -685,7 +685,7 @@ pub fn determine_rp_in_ty(ty: @ast::Ty,
// that as a direct dependency.
match ty.node {
ast::ty_path(path, id) => {
match cx.def_map.find(id) {
match cx.def_map.find(&id) {
Some(ast::def_ty(did)) | Some(ast::def_struct(did)) => {
if did.crate == ast::local_crate {
if cx.opt_region_is_relevant(path.rp) {
@ -732,18 +732,18 @@ pub fn determine_rp_in_ty(ty: @ast::Ty,
}
}
ast::ty_fn(f) => {
ast::ty_closure(@ast::TyClosure {decl: ref decl, _}) |
ast::ty_bare_fn(@ast::TyBareFn {decl: ref decl, _}) => {
// fn() binds the & region, so do not consider &T types that
// appear *inside* a fn() type to affect the enclosing item:
do cx.with(cx.item_id, false) {
// parameters are contravariant
do cx.with_ambient_variance(rv_contravariant) {
for f.decl.inputs.each |a| {
for decl.inputs.each |a| {
(visitor.visit_ty)(a.ty, cx, visitor);
}
}
visit::visit_ty_param_bounds(f.bounds, cx, visitor);
(visitor.visit_ty)(f.decl.output, cx, visitor);
(visitor.visit_ty)(decl.output, cx, visitor);
}
}
@ -818,9 +818,9 @@ pub fn determine_rp_in_crate(sess: Session,
// update the region-parameterization of D to reflect the result.
while cx.worklist.len() != 0 {
let c_id = cx.worklist.pop();
let c_variance = cx.region_paramd_items.get(c_id);
let c_variance = cx.region_paramd_items.get(&c_id);
debug!("popped %d from worklist", c_id);
match cx.dep_map.find(c_id) {
match cx.dep_map.find(&c_id) {
None => {}
Some(deps) => {
for deps.each |dep| {

View File

@ -947,7 +947,7 @@ pub impl Resolver {
// Add or reuse the child.
let new_parent = ModuleReducedGraphParent(module_);
match module_.children.find(name) {
match module_.children.find(&name) {
None => {
let child = @NameBindings();
module_.children.insert(name, child);
@ -1558,7 +1558,7 @@ pub impl Resolver {
%s", final_ident);
let parent_link = self.get_parent_link(new_parent, ident);
match modules.find(def_id) {
match modules.find(&def_id) {
None => {
child_name_bindings.define_module(Public,
parent_link,
@ -1582,7 +1582,8 @@ pub impl Resolver {
die!(~"can't happen");
}
ModuleParentLink(parent_module, ident) => {
let name_bindings = parent_module.children.get(ident);
let name_bindings = parent_module.children.get(
&ident);
resolution.type_target =
Some(Target(parent_module, name_bindings));
}
@ -1841,7 +1842,7 @@ pub impl Resolver {
self.idents_to_str(module_path.get()),
self.session.str_of(target));
match module_.import_resolutions.find(target) {
match module_.import_resolutions.find(&target) {
Some(resolution) => {
debug!("(building import directive) bumping \
reference");
@ -2112,7 +2113,7 @@ pub impl Resolver {
let mut type_result = UnknownResult;
// Search for direct children of the containing module.
match containing_module.children.find(source) {
match containing_module.children.find(&source) {
None => {
// Continue.
}
@ -2148,7 +2149,7 @@ pub impl Resolver {
// Now search the exported imports within the containing
// module.
match containing_module.import_resolutions.find(source) {
match containing_module.import_resolutions.find(&source) {
None => {
// The containing module definitely doesn't have an
// exported import with the name in question. We can
@ -2212,7 +2213,7 @@ pub impl Resolver {
// We've successfully resolved the import. Write the results in.
assert module_.import_resolutions.contains_key_ref(&target);
let import_resolution = module_.import_resolutions.get(target);
let import_resolution = module_.import_resolutions.get(&target);
match value_result {
BoundResult(target_module, name_bindings) => {
@ -2297,7 +2298,7 @@ pub impl Resolver {
let mut module_result = UnknownResult;
// Search for direct children of the containing module.
match containing_module.children.find(source) {
match containing_module.children.find(&source) {
None => {
// Continue.
}
@ -2327,7 +2328,7 @@ pub impl Resolver {
// Now search the exported imports within the containing
// module.
match containing_module.import_resolutions.find(source) {
match containing_module.import_resolutions.find(&source) {
None => {
// The containing module definitely doesn't have an
// exported import with the name in question. We can
@ -2371,7 +2372,7 @@ pub impl Resolver {
// We've successfully resolved the import. Write the results in.
assert module_.import_resolutions.contains_key_ref(&target);
let import_resolution = module_.import_resolutions.get(target);
let import_resolution = module_.import_resolutions.get(&target);
match module_result {
BoundResult(target_module, name_bindings) => {
@ -2439,7 +2440,7 @@ pub impl Resolver {
self.module_to_str(module_));
// Here we merge two import resolutions.
match module_.import_resolutions.find(ident) {
match module_.import_resolutions.find(&ident) {
None => {
// Simple: just copy the old import resolution.
let new_import_resolution =
@ -2482,7 +2483,7 @@ pub impl Resolver {
// Add all children from the containing module.
for containing_module.children.each_ref |&ident, &name_bindings| {
let mut dest_import_resolution;
match module_.import_resolutions.find(ident) {
match module_.import_resolutions.find(&ident) {
None => {
// Create a new import resolution from this child.
dest_import_resolution = @ImportResolution(privacy, span);
@ -2686,7 +2687,7 @@ pub impl Resolver {
// The current module node is handled specially. First, check for
// its immediate children.
match module_.children.find(name) {
match module_.children.find(&name) {
Some(name_bindings)
if (*name_bindings).defined_in_namespace(namespace) => {
return Success(Target(module_, name_bindings));
@ -2699,7 +2700,7 @@ pub impl Resolver {
// adjacent import statements are processed as though they mutated the
// current scope.
match module_.import_resolutions.find(name) {
match module_.import_resolutions.find(&name) {
None => {
// Not found; continue.
}
@ -2923,7 +2924,7 @@ pub impl Resolver {
self.module_to_str(module_));
// First, check the direct children of the module.
match module_.children.find(name) {
match module_.children.find(&name) {
Some(name_bindings)
if (*name_bindings).defined_in_namespace(namespace) => {
@ -2944,7 +2945,7 @@ pub impl Resolver {
}
// Otherwise, we check the list of resolved imports.
match module_.import_resolutions.find(name) {
match module_.import_resolutions.find(&name) {
Some(import_resolution) => {
if import_resolution.outstanding_references != 0 {
debug!("(resolving name in module) import unresolved; \
@ -3114,7 +3115,7 @@ pub impl Resolver {
}
// Otherwise, proceed and write in the bindings.
match module_.import_resolutions.find(target_name) {
match module_.import_resolutions.find(&target_name) {
None => {
die!(~"(resolving one-level renaming import) reduced graph \
construction or glob importing should have created the \
@ -3328,7 +3329,7 @@ pub impl Resolver {
// Nothing to do.
}
Some(name) => {
match orig_module.children.find(name) {
match orig_module.children.find(&name) {
None => {
debug!("!!! (with scope) didn't find `%s` in `%s`",
self.session.str_of(name),
@ -3405,7 +3406,7 @@ pub impl Resolver {
// If the def is a ty param, and came from the parent
// item, it's ok
match def {
def_ty_param(did, _) if self.def_map.find(copy(did.node))
def_ty_param(did, _) if self.def_map.find(&did.node)
== Some(def_typaram_binder(item_id)) => {
// ok
}
@ -3477,7 +3478,7 @@ pub impl Resolver {
while i != 0 {
i -= 1;
let rib = (*ribs).get_elt(i);
match rib.bindings.find(name) {
match rib.bindings.find(&name) {
Some(def_like) => {
return self.upvarify(ribs, i, def_like, span,
allow_capturing_self);
@ -4069,7 +4070,7 @@ pub impl Resolver {
let map_i = self.binding_mode_map(*p);
for map_0.each_ref |&key, &binding_0| {
match map_i.find(key) {
match map_i.find(&key) {
None => {
self.session.span_err(
p.span,
@ -4126,7 +4127,7 @@ pub impl Resolver {
// Move down in the graph, if there's an anonymous module rooted here.
let orig_module = self.current_module;
match self.current_module.anonymous_children.find(block.node.id) {
match self.current_module.anonymous_children.find(&block.node.id) {
None => { /* Nothing to do. */ }
Some(anonymous_module) => {
debug!("(resolving block) found anonymous module, moving \
@ -4161,7 +4162,7 @@ pub impl Resolver {
match self.primitive_type_table
.primitive_types
.find(name) {
.find(&name) {
Some(primitive_type) => {
result_def =
@ -4327,7 +4328,7 @@ pub impl Resolver {
bindings_list.insert(ident, pat_id);
}
Some(b) => {
if b.find(ident) == Some(pat_id) {
if b.find(&ident) == Some(pat_id) {
// Then this is a duplicate variable
// in the same disjunct, which is an
// error
@ -4526,7 +4527,7 @@ pub impl Resolver {
-> NameDefinition {
// First, search children.
match containing_module.children.find(name) {
match containing_module.children.find(&name) {
Some(child_name_bindings) => {
match (child_name_bindings.def_for_namespace(namespace),
child_name_bindings.privacy_for_namespace(namespace)) {
@ -4549,7 +4550,7 @@ pub impl Resolver {
}
// Next, search import resolutions.
match containing_module.import_resolutions.find(name) {
match containing_module.import_resolutions.find(&name) {
Some(import_resolution) if import_resolution.privacy == Public ||
xray == Xray => {
match (*import_resolution).target_for_namespace(namespace) {
@ -5076,7 +5077,7 @@ pub impl Resolver {
trait_def_id.node,
self.session.str_of(name));
match self.trait_info.find(trait_def_id) {
match self.trait_info.find(&trait_def_id) {
Some(trait_info) if trait_info.contains_key_ref(&name) => {
debug!("(adding trait info if containing method) found trait \
%d:%d for method '%s'",

View File

@ -282,7 +282,7 @@ pub fn trans_opt(bcx: block, o: &Opt) -> opt_result {
}
pub fn variant_opt(tcx: ty::ctxt, pat_id: ast::node_id) -> Opt {
match tcx.def_map.get(pat_id) {
match tcx.def_map.get(&pat_id) {
ast::def_variant(enum_id, var_id) => {
let variants = ty::enum_variants(tcx, enum_id);
for vec::each(*variants) |v| {
@ -377,7 +377,7 @@ pub fn expand_nested_bindings(bcx: block, m: &[@Match/&r],
vec::view(br.pats, col + 1u, br.pats.len())));
let binding_info =
br.data.bindings_map.get(path_to_ident(path));
br.data.bindings_map.get(&path_to_ident(path));
Store(bcx, val, binding_info.llmatch);
@Match {pats: pats, data: br.data}
@ -424,7 +424,8 @@ pub fn enter_match(bcx: block, dm: DefMap, m: &[@Match/&r],
ast::pat_ident(_, path, None) => {
if pat_is_binding(dm, self) {
let binding_info =
br.data.bindings_map.get(path_to_ident(path));
br.data.bindings_map.get(
&path_to_ident(path));
Store(bcx, val, binding_info.llmatch);
}
}
@ -518,7 +519,7 @@ pub fn enter_opt(bcx: block, m: &[@Match/&r], opt: &Opt, col: uint,
}
}
ast::pat_ident(_, _, None) if pat_is_const(tcx.def_map, p) => {
let const_def = tcx.def_map.get(p.id);
let const_def = tcx.def_map.get(&p.id);
let const_def_id = ast_util::def_id_of_def(const_def);
if opt_eq(tcx, &lit(ConstLit(const_def_id)), opt) {
Some(~[])
@ -536,7 +537,7 @@ pub fn enter_opt(bcx: block, m: &[@Match/&r], opt: &Opt, col: uint,
if opt_eq(tcx, &variant_opt(tcx, p.id), opt) {
// Look up the struct variant ID.
let struct_id;
match tcx.def_map.get(p.id) {
match tcx.def_map.get(&p.id) {
ast::def_variant(_, found_struct_id) => {
struct_id = found_struct_id;
}
@ -774,7 +775,7 @@ pub fn get_options(ccx: @crate_ctxt, m: &[@Match], col: uint) -> ~[Opt] {
ast::pat_ident(*) => {
// This is one of: an enum variant, a unit-like struct, or a
// variable binding.
match ccx.tcx.def_map.find(cur.id) {
match ccx.tcx.def_map.find(&cur.id) {
Some(ast::def_variant(*)) => {
add_to_set(ccx.tcx, &found,
variant_opt(ccx.tcx, cur.id));
@ -793,7 +794,7 @@ pub fn get_options(ccx: @crate_ctxt, m: &[@Match], col: uint) -> ~[Opt] {
ast::pat_enum(*) | ast::pat_struct(*) => {
// This could be one of: a tuple-like enum variant, a
// struct-like enum variant, or a struct.
match ccx.tcx.def_map.find(cur.id) {
match ccx.tcx.def_map.find(&cur.id) {
Some(ast::def_variant(*)) => {
add_to_set(ccx.tcx, &found,
variant_opt(ccx.tcx, cur.id));
@ -926,7 +927,7 @@ pub fn root_pats_as_necessary(bcx: block,
let pat_id = br.pats[col].id;
let key = root_map_key {id: pat_id, derefs: 0u };
match bcx.ccx().maps.root_map.find(key) {
match bcx.ccx().maps.root_map.find(&key) {
None => (),
Some(root_info) => {
// Note: the scope_id will always be the id of the match. See
@ -981,7 +982,7 @@ pub fn any_tuple_struct_pat(bcx: block, m: &[@Match], col: uint) -> bool {
let pat = br.pats[col];
match pat.node {
ast::pat_enum(_, Some(_)) => {
match bcx.tcx().def_map.find(pat.id) {
match bcx.tcx().def_map.find(&pat.id) {
Some(ast::def_struct(*)) => true,
_ => false
}
@ -1027,6 +1028,8 @@ pub fn pick_col(m: &[@Match]) -> uint {
pub enum branch_kind { no_branch, single, switch, compare, compare_vec_len, }
// Compiles a comparison between two things.
//
// NB: This must produce an i1, not a Rust bool (i8).
pub fn compare_values(cx: block,
lhs: ValueRef,
rhs: ValueRef,
@ -1052,7 +1055,11 @@ pub fn compare_values(cx: block,
scratch_rhs],
expr::SaveIn(
scratch_result.val));
return scratch_result.to_result(bcx);
let result = scratch_result.to_result(bcx);
Result {
bcx: result.bcx,
val: bool_to_i1(result.bcx, result.val)
}
}
ty::ty_estr(_) => {
let scratch_result = scratch_datum(cx, ty::mk_bool(cx.tcx()),
@ -1062,7 +1069,11 @@ pub fn compare_values(cx: block,
~[lhs, rhs],
expr::SaveIn(
scratch_result.val));
return scratch_result.to_result(bcx);
let result = scratch_result.to_result(bcx);
Result {
bcx: result.bcx,
val: bool_to_i1(result.bcx, result.val)
}
}
_ => {
cx.tcx().sess.bug(~"only scalars and strings supported in \
@ -1175,6 +1186,7 @@ pub fn compile_guard(bcx: block,
expr::trans_to_datum(bcx, guard_expr).to_result()
}
});
let val = bool_to_i1(bcx, val);
// Revoke the temp cleanups now that the guard successfully executed.
for temp_cleanups.each |llval| {
@ -1640,7 +1652,7 @@ pub fn trans_match_inner(scope_cx: block,
// insert bindings into the lllocals map and add cleanups
bcx = insert_lllocals(bcx, *arm_data, true);
bcx = controlflow::trans_block(bcx, arm_data.arm.body, dest);
bcx = controlflow::trans_block(bcx, &arm_data.arm.body, dest);
bcx = trans_block_cleanups(bcx, block_cleanups(arm_data.bodycx));
arm_cxs.push(bcx);
}
@ -1717,9 +1729,9 @@ pub fn bind_irrefutable_pat(bcx: block,
}
}
ast::pat_enum(_, sub_pats) => {
match bcx.tcx().def_map.find(pat.id) {
match bcx.tcx().def_map.find(&pat.id) {
Some(ast::def_variant(*)) => {
let pat_def = ccx.tcx.def_map.get(pat.id);
let pat_def = ccx.tcx.def_map.get(&pat.id);
let vdefs = ast_util::variant_def_ids(pat_def);
let args = extract_variant_args(bcx, pat.id, vdefs, val);
for sub_pats.each |sub_pat| {

View File

@ -137,7 +137,7 @@ pub fn log_fn_time(ccx: @crate_ctxt, +name: ~str, start: time::Timespec,
ccx.stats.fn_times.push({ident: name, time: elapsed});
}
pub fn decl_fn(llmod: ModuleRef, name: ~str, cc: lib::llvm::CallConv,
pub fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv,
llty: TypeRef) -> ValueRef {
let llfn: ValueRef = str::as_c_str(name, |buf| {
unsafe {
@ -150,7 +150,7 @@ pub fn decl_fn(llmod: ModuleRef, name: ~str, cc: lib::llvm::CallConv,
return llfn;
}
pub fn decl_cdecl_fn(llmod: ModuleRef, +name: ~str, llty: TypeRef)
pub fn decl_cdecl_fn(llmod: ModuleRef, name: &str, llty: TypeRef)
-> ValueRef {
return decl_fn(llmod, name, lib::llvm::CCallConv, llty);
}
@ -164,22 +164,21 @@ pub fn decl_internal_cdecl_fn(llmod: ModuleRef, +name: ~str, llty: TypeRef) ->
return llfn;
}
pub fn get_extern_fn(externs: HashMap<~str, ValueRef>,
pub fn get_extern_fn(externs: ExternMap,
llmod: ModuleRef,
+name: ~str,
name: @str,
cc: lib::llvm::CallConv,
ty: TypeRef) -> ValueRef {
if externs.contains_key_ref(&name) { return externs.get(name); }
// XXX: Bad copy.
let f = decl_fn(llmod, copy name, cc, ty);
if externs.contains_key_ref(&name) { return externs.get(&name); }
let f = decl_fn(llmod, name, cc, ty);
externs.insert(name, f);
return f;
}
pub fn get_extern_const(externs: HashMap<~str, ValueRef>, llmod: ModuleRef,
+name: ~str, ty: TypeRef) -> ValueRef {
pub fn get_extern_const(externs: ExternMap, llmod: ModuleRef,
name: @str, ty: TypeRef) -> ValueRef {
unsafe {
if externs.contains_key_ref(&name) { return externs.get(name); }
if externs.contains_key_ref(&name) { return externs.get(&name); }
let c = str::as_c_str(name, |buf| {
llvm::LLVMAddGlobal(llmod, ty, buf)
});
@ -189,9 +188,9 @@ pub fn get_extern_const(externs: HashMap<~str, ValueRef>, llmod: ModuleRef,
}
fn get_simple_extern_fn(cx: block,
externs: HashMap<~str, ValueRef>,
externs: ExternMap,
llmod: ModuleRef,
+name: ~str,
name: @str,
n_args: int) -> ValueRef {
let _icx = cx.insn_ctxt("get_simple_extern_fn");
let ccx = cx.fcx.ccx;
@ -201,8 +200,8 @@ pub fn get_extern_const(externs: HashMap<~str, ValueRef>, llmod: ModuleRef,
return get_extern_fn(externs, llmod, name, lib::llvm::CCallConv, t);
}
pub fn trans_foreign_call(cx: block, externs: HashMap<~str, ValueRef>,
llmod: ModuleRef, +name: ~str, args: ~[ValueRef]) ->
pub fn trans_foreign_call(cx: block, externs: ExternMap,
llmod: ModuleRef, name: @str, args: ~[ValueRef]) ->
ValueRef {
let _icx = cx.insn_ctxt("trans_foreign_call");
let n = args.len() as int;
@ -372,7 +371,7 @@ pub fn get_tydesc_simple(ccx: @crate_ctxt, t: ty::t) -> ValueRef {
}
pub fn get_tydesc(ccx: @crate_ctxt, t: ty::t) -> @tydesc_info {
match ccx.tydescs.find(t) {
match ccx.tydescs.find(&t) {
Some(inf) => inf,
_ => {
ccx.stats.n_static_tydescs += 1u;
@ -474,6 +473,7 @@ pub fn get_res_dtor(ccx: @crate_ctxt, did: ast::def_id,
let class_ty = ty::subst_tps(tcx, substs, None,
ty::lookup_item_type(tcx, parent_id).ty);
let llty = type_of_dtor(ccx, class_ty);
let name = name.to_managed(); // :-(
get_extern_fn(ccx.externs, ccx.llmod, name, lib::llvm::CCallConv,
llty)
}
@ -494,8 +494,13 @@ pub fn maybe_name_value(cx: @crate_ctxt, v: ValueRef, s: ~str) {
// Used only for creating scalar comparison glue.
pub enum scalar_type { nil_type, signed_int, unsigned_int, floating_point, }
pub fn compare_scalar_types(cx: block, lhs: ValueRef, rhs: ValueRef,
t: ty::t, op: ast::binop) -> Result {
// NB: This produces an i1, not a Rust bool (i8).
pub fn compare_scalar_types(cx: block,
lhs: ValueRef,
rhs: ValueRef,
t: ty::t,
op: ast::binop)
-> Result {
let f = |a| compare_scalar_values(cx, lhs, rhs, a, op);
match ty::get(t).sty {
@ -521,8 +526,12 @@ pub fn compare_scalar_types(cx: block, lhs: ValueRef, rhs: ValueRef,
// A helper function to do the actual comparison of scalar values.
pub fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef,
nt: scalar_type, op: ast::binop) -> ValueRef {
pub fn compare_scalar_values(cx: block,
lhs: ValueRef,
rhs: ValueRef,
nt: scalar_type,
op: ast::binop)
-> ValueRef {
let _icx = cx.insn_ctxt("compare_scalar_values");
fn die(cx: block) -> ! {
cx.tcx().sess.bug(~"compare_scalar_values: must be a\
@ -533,8 +542,8 @@ pub fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef,
// We don't need to do actual comparisons for nil.
// () == () holds but () < () does not.
match op {
ast::eq | ast::le | ast::ge => return C_bool(true),
ast::ne | ast::lt | ast::gt => return C_bool(false),
ast::eq | ast::le | ast::ge => return C_i1(true),
ast::ne | ast::lt | ast::gt => return C_i1(false),
// refinements would be nice
_ => die(cx)
}
@ -604,7 +613,7 @@ pub fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
let ccx = cx.ccx();
let mut cx = cx;
match ty::get(fn_ty).sty {
ty::ty_fn(ref fn_ty) => {
ty::ty_bare_fn(ref fn_ty) => {
let mut j = 0u;
let v_id = variant.id;
for vec::each(fn_ty.sig.inputs) |a| {
@ -766,12 +775,12 @@ pub fn null_env_ptr(bcx: block) -> ValueRef {
pub fn trans_external_path(ccx: @crate_ctxt, did: ast::def_id, t: ty::t)
-> ValueRef {
let name = csearch::get_symbol(ccx.sess.cstore, did);
let name = csearch::get_symbol(ccx.sess.cstore, did).to_managed(); // Sad
match ty::get(t).sty {
ty::ty_fn(_) => {
ty::ty_bare_fn(_) | ty::ty_closure(_) => {
let llty = type_of_fn_from_ty(ccx, t);
return get_extern_fn(ccx.externs, ccx.llmod, name,
lib::llvm::CCallConv, llty);
lib::llvm::CCallConv, llty);
}
_ => {
let llty = type_of(ccx, t);
@ -804,27 +813,6 @@ pub fn get_discrim_val(cx: @crate_ctxt, span: span, enum_did: ast::def_id,
}
}
pub fn lookup_discriminant(ccx: @crate_ctxt, vid: ast::def_id) -> ValueRef {
unsafe {
let _icx = ccx.insn_ctxt("lookup_discriminant");
match ccx.discrims.find(vid) {
None => {
// It's an external discriminant that we haven't seen yet.
assert (vid.crate != ast::local_crate);
let sym = csearch::get_symbol(ccx.sess.cstore, vid);
let gvar = str::as_c_str(sym, |buf| {
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf)
});
lib::llvm::SetLinkage(gvar, lib::llvm::ExternalLinkage);
llvm::LLVMSetGlobalConstant(gvar, True);
ccx.discrims.insert(vid, gvar);
return gvar;
}
Some(llval) => return llval,
}
}
}
pub fn invoke(bcx: block, llfn: ValueRef, +llargs: ~[ValueRef]) -> block {
let _icx = bcx.insn_ctxt("invoke_");
if bcx.unreachable { return bcx; }
@ -1095,7 +1083,7 @@ pub fn init_local(bcx: block, local: @ast::local) -> block {
}
}
let llptr = match bcx.fcx.lllocals.find(local.node.id) {
let llptr = match bcx.fcx.lllocals.find(&local.node.id) {
Some(local_mem(v)) => v,
_ => { bcx.tcx().sess.span_bug(local.span,
~"init_local: Someone forgot to document why it's\
@ -1375,7 +1363,7 @@ pub fn with_scope_datumblock(bcx: block, opt_node_info: Option<node_info>,
DatumBlock {bcx: leave_block(bcx, scope_cx), datum: datum}
}
pub fn block_locals(b: ast::blk, it: fn(@ast::local)) {
pub fn block_locals(b: &ast::blk, it: fn(@ast::local)) {
for vec::each(b.node.stmts) |s| {
match s.node {
ast::stmt_decl(d, _) => {
@ -1437,12 +1425,12 @@ pub fn call_memcpy(cx: block, dst: ValueRef, src: ValueRef,
session::arch_x86 | session::arch_arm => ~"llvm.memcpy.p0i8.p0i8.i32",
session::arch_x86_64 => ~"llvm.memcpy.p0i8.p0i8.i64"
};
let memcpy = ccx.intrinsics.get(key);
let memcpy = ccx.intrinsics.get(&key);
let src_ptr = PointerCast(cx, src, T_ptr(T_i8()));
let dst_ptr = PointerCast(cx, dst, T_ptr(T_i8()));
let size = IntCast(cx, n_bytes, ccx.int_type);
let align = C_i32(1i32);
let volatile = C_bool(false);
let volatile = C_i1(false);
Call(cx, memcpy, ~[dst_ptr, src_ptr, size, align, volatile]);
}
@ -1484,12 +1472,12 @@ pub fn memzero(cx: block, llptr: ValueRef, llty: TypeRef) {
}
}
let llintrinsicfn = ccx.intrinsics.get(intrinsic_key);
let llintrinsicfn = ccx.intrinsics.get(&intrinsic_key);
let llptr = PointerCast(cx, llptr, T_ptr(T_i8()));
let llzeroval = C_u8(0);
let size = IntCast(cx, machine::llsize_of(ccx, llty), ccx.int_type);
let align = C_i32(1i32);
let volatile = C_bool(false);
let volatile = C_i1(false);
Call(cx, llintrinsicfn, ~[llptr, llzeroval, size, align, volatile]);
}
@ -1739,8 +1727,8 @@ pub enum self_arg { impl_self(ty::t), impl_owned_self(ty::t), no_self, }
// returned.
pub fn trans_closure(ccx: @crate_ctxt,
+path: path,
decl: ast::fn_decl,
body: ast::blk,
decl: &ast::fn_decl,
body: &ast::blk,
llfndecl: ValueRef,
ty_self: self_arg,
+param_substs: Option<param_substs>,
@ -1803,8 +1791,8 @@ pub fn trans_closure(ccx: @crate_ctxt,
// function.
pub fn trans_fn(ccx: @crate_ctxt,
+path: path,
decl: ast::fn_decl,
body: ast::blk,
decl: &ast::fn_decl,
body: &ast::blk,
llfndecl: ValueRef,
ty_self: self_arg,
+param_substs: Option<param_substs>,
@ -1884,7 +1872,7 @@ pub fn trans_enum_variant(ccx: @crate_ctxt,
// If this argument to this function is a enum, it'll have come in to
// this function as an opaque blob due to the way that type_of()
// works. So we have to cast to the destination's view of the type.
let llarg = match fcx.llargs.find(va.id) {
let llarg = match fcx.llargs.find(&va.id) {
Some(local_mem(x)) => x,
_ => die!(~"trans_enum_variant: how do we know this works?"),
};
@ -1930,7 +1918,7 @@ pub fn trans_tuple_struct(ccx: @crate_ctxt,
for fields.eachi |i, field| {
let lldestptr = GEPi(bcx, fcx.llretptr, [0, 0, i]);
let llarg = match fcx.llargs.get(field.node.id) {
let llarg = match fcx.llargs.get(&field.node.id) {
local_mem(x) => x,
_ => {
ccx.tcx.sess.bug(~"trans_tuple_struct: llarg wasn't \
@ -1947,7 +1935,7 @@ pub fn trans_tuple_struct(ccx: @crate_ctxt,
pub fn trans_struct_dtor(ccx: @crate_ctxt,
+path: path,
body: ast::blk,
body: &ast::blk,
dtor_id: ast::node_id,
+psubsts: Option<param_substs>,
hash_id: Option<mono_id>,
@ -1978,8 +1966,9 @@ pub fn trans_struct_dtor(ccx: @crate_ctxt,
ccx.monomorphized.insert(*h_id, lldecl);
}
/* Translate the dtor body */
trans_fn(ccx, path, ast_util::dtor_dec(),
body, lldecl, impl_self(class_ty), psubsts, dtor_id, None);
let decl = ast_util::dtor_dec();
trans_fn(ccx, path, &decl, body, lldecl,
impl_self(class_ty), psubsts, dtor_id, None);
lldecl
}
@ -2019,26 +2008,25 @@ pub fn trans_enum_def(ccx: @crate_ctxt, enum_definition: ast::enum_def,
pub fn trans_item(ccx: @crate_ctxt, item: ast::item) {
let _icx = ccx.insn_ctxt("trans_item");
let path = match ccx.tcx.items.get(item.id) {
let path = match ccx.tcx.items.get(&item.id) {
ast_map::node_item(_, p) => p,
// tjc: ?
_ => die!(~"trans_item"),
};
match /*bad*/copy item.node {
// XXX: Bad copies.
ast::item_fn(copy decl, purity, copy tps, ref body) => {
ast::item_fn(ref decl, purity, ref tps, ref body) => {
if purity == ast::extern_fn {
let llfndecl = get_item_val(ccx, item.id);
foreign::trans_foreign_fn(ccx,
vec::append(
/*bad*/copy *path,
~[path_name(item.ident)]),
decl, (*body), llfndecl, item.id);
decl, body, llfndecl, item.id);
} else if tps.is_empty() {
let llfndecl = get_item_val(ccx, item.id);
trans_fn(ccx,
vec::append(/*bad*/copy *path, ~[path_name(item.ident)]),
decl, (*body), llfndecl, no_self, None, item.id, None);
decl, body, llfndecl, no_self, None, item.id, None);
} else {
for vec::each((*body).node.stmts) |stmt| {
match stmt.node {
@ -2090,7 +2078,7 @@ pub fn trans_struct_def(ccx: @crate_ctxt, struct_def: @ast::struct_def,
id: ast::node_id) {
// Translate the destructor.
do option::iter(&struct_def.dtor) |dtor| {
trans_struct_dtor(ccx, /*bad*/copy *path, dtor.node.body,
trans_struct_dtor(ccx, /*bad*/copy *path, &dtor.node.body,
dtor.node.id, None, None, local_def(id));
};
@ -2275,7 +2263,7 @@ pub fn fill_fn_pair(bcx: block, pair: ValueRef, llfn: ValueRef,
pub fn item_path(ccx: @crate_ctxt, i: @ast::item) -> path {
vec::append(
/*bad*/copy *match ccx.tcx.items.get(i.id) {
/*bad*/copy *match ccx.tcx.items.get(&i.id) {
ast_map::node_item(_, p) => p,
// separate map for paths?
_ => die!(~"item_path")
@ -2291,7 +2279,7 @@ pub fn get_dtor_symbol(ccx: @crate_ctxt,
+substs: Option<param_substs>)
-> ~str {
let t = ty::node_id_to_type(ccx.tcx, id);
match ccx.item_symbols.find(id) {
match ccx.item_symbols.find(&id) {
Some(ref s) => (/*bad*/copy *s),
None if substs.is_none() => {
let s = mangle_exported_name(
@ -2326,12 +2314,12 @@ pub fn get_dtor_symbol(ccx: @crate_ctxt,
pub fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
debug!("get_item_val(id=`%?`)", id);
let tcx = ccx.tcx;
match ccx.item_vals.find(id) {
match ccx.item_vals.find(&id) {
Some(v) => v,
None => {
let mut exprt = false;
let val = match ccx.tcx.items.get(id) {
let val = match ccx.tcx.items.get(&id) {
ast_map::node_item(i, pth) => {
let my_path = vec::append(/*bad*/copy *pth,
~[path_name(i.ident)]);
@ -2770,7 +2758,7 @@ pub fn declare_dbg_intrinsics(llmod: ModuleRef,
pub fn trap(bcx: block) {
let v: ~[ValueRef] = ~[];
match bcx.ccx().intrinsics.find(~"llvm.trap") {
match bcx.ccx().intrinsics.find(&~"llvm.trap") {
Some(x) => { Call(bcx, x, v); },
_ => bcx.sess().bug(~"unbound llvm.trap in trap")
}

View File

@ -70,7 +70,7 @@ pub fn count_insn(cx: block, category: &str) {
i = 0u;
while i < len {
let e = /*bad*/copy v[i];
i = mm.get(/*bad*/ copy e);
i = mm.get(&e);
s += ~"/";
s += e;
i += 1u;
@ -79,7 +79,7 @@ pub fn count_insn(cx: block, category: &str) {
s += ~"/";
s += category;
let n = match h.find(/*bad*/ copy s) {
let n = match h.find(&s) {
Some(n) => n,
_ => 0u
};

View File

@ -70,7 +70,7 @@ pub fn trans(bcx: block, expr: @ast::expr) -> Callee {
return trans_def(bcx, bcx.def(expr.id), expr);
}
ast::expr_field(base, _, _) => {
match bcx.ccx().maps.method_map.find(expr.id) {
match bcx.ccx().maps.method_map.find(&expr.id) {
Some(ref origin) => { // An impl method
return meth::trans_method_callee(bcx, expr.id,
base, (*origin));
@ -208,7 +208,7 @@ pub fn trans_fn_ref_with_vtables(
// Modify the def_id if this is a default method; we want to be
// monomorphizing the trait's code.
let (def_id, opt_impl_did) =
match tcx.provided_method_sources.find(def_id) {
match tcx.provided_method_sources.find(&def_id) {
None => (def_id, None),
Some(source) => (source.method_id, Some(source.impl_id))
};
@ -234,7 +234,7 @@ pub fn trans_fn_ref_with_vtables(
} else if def_id.crate == ast::local_crate {
let map_node = session::expect(
ccx.sess,
ccx.tcx.items.find(def_id.node),
ccx.tcx.items.find(&def_id.node),
|| fmt!("local item should be in ast map"));
match map_node {
@ -313,7 +313,7 @@ pub fn trans_method_call(in_cx: block,
node_id_type(in_cx, call_ex.callee_id),
expr_ty(in_cx, call_ex),
|cx| {
match cx.ccx().maps.method_map.find(call_ex.id) {
match cx.ccx().maps.method_map.find(&call_ex.id) {
Some(ref origin) => {
meth::trans_method_callee(cx,
call_ex.callee_id,
@ -438,7 +438,9 @@ pub fn trans_call_inner(
let flag = alloca(bcx, T_bool());
Store(bcx, C_bool(false), flag);
Some(flag)
} else { None };
} else {
None
};
let (llfn, llenv) = unsafe {
match callee.data {
@ -506,7 +508,8 @@ pub fn trans_call_inner(
if ty::type_is_bot(ret_ty) {
Unreachable(bcx);
} else if ret_in_loop {
bcx = do with_cond(bcx, Load(bcx, ret_flag.get())) |bcx| {
let ret_flag_result = bool_to_i1(bcx, Load(bcx, ret_flag.get()));
bcx = do with_cond(bcx, ret_flag_result) |bcx| {
do option::iter(&copy bcx.fcx.loop_ret) |lret| {
Store(bcx, C_bool(true), lret.flagptr);
Store(bcx, C_bool(false), bcx.fcx.llretptr);
@ -624,18 +627,17 @@ pub fn trans_arg_expr(bcx: block,
Some(_) => {
match arg_expr.node {
ast::expr_loop_body(
// XXX: Bad copy.
blk@@ast::expr {
node: ast::expr_fn_block(copy decl, ref body),
blk @ @ast::expr {
node: ast::expr_fn_block(ref decl, ref body),
_
}) =>
{
let scratch_ty = expr_ty(bcx, arg_expr);
let scratch = alloc_ty(bcx, scratch_ty);
let arg_ty = expr_ty(bcx, arg_expr);
let proto = ty::ty_fn_proto(arg_ty);
let sigil = ty::ty_closure_sigil(arg_ty);
let bcx = closure::trans_expr_fn(
bcx, proto, decl, /*bad*/copy *body, arg_expr.id,
bcx, sigil, decl, body, arg_expr.id,
blk.id, Some(ret_flag), expr::SaveIn(scratch));
DatumBlock {bcx: bcx,
datum: Datum {val: scratch,

View File

@ -160,7 +160,7 @@ pub fn mk_closure_tys(tcx: ty::ctxt,
return cdata_ty;
}
pub fn allocate_cbox(bcx: block, proto: ast::Proto, cdata_ty: ty::t)
pub fn allocate_cbox(bcx: block, sigil: ast::Sigil, cdata_ty: ty::t)
-> Result {
let _icx = bcx.insn_ctxt("closure::allocate_cbox");
let ccx = bcx.ccx(), tcx = ccx.tcx;
@ -176,23 +176,19 @@ pub fn allocate_cbox(bcx: block, proto: ast::Proto, cdata_ty: ty::t)
}
// Allocate and initialize the box:
match proto {
ast::ProtoBox => {
match sigil {
ast::ManagedSigil => {
malloc_raw(bcx, cdata_ty, heap_shared)
}
ast::ProtoUniq => {
ast::OwnedSigil => {
malloc_raw(bcx, cdata_ty, heap_exchange)
}
ast::ProtoBorrowed => {
ast::BorrowedSigil => {
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
let llbox = base::alloc_ty(bcx, cbox_ty);
nuke_ref_count(bcx, llbox);
rslt(bcx, llbox)
}
ast::ProtoBare => {
let cdata_llty = type_of(bcx.ccx(), cdata_ty);
rslt(bcx, C_null(cdata_llty))
}
}
}
@ -208,7 +204,7 @@ pub type closure_result = {
// Otherwise, it is stack allocated and copies pointers to the upvars.
pub fn store_environment(bcx: block,
bound_values: ~[EnvValue],
proto: ast::Proto) -> closure_result {
sigil: ast::Sigil) -> closure_result {
let _icx = bcx.insn_ctxt("closure::store_environment");
let ccx = bcx.ccx(), tcx = ccx.tcx;
@ -217,7 +213,7 @@ pub fn store_environment(bcx: block,
let cdata_ty = mk_closure_tys(tcx, copy bound_values);
// allocate closure in the heap
let Result {bcx: bcx, val: llbox} = allocate_cbox(bcx, proto, cdata_ty);
let Result {bcx: bcx, val: llbox} = allocate_cbox(bcx, sigil, cdata_ty);
let mut temp_cleanups = ~[];
// cbox_ty has the form of a tuple: (a, b, c) we want a ptr to a
@ -265,7 +261,7 @@ pub fn store_environment(bcx: block,
// collects the upvars and packages them up for store_environment.
pub fn build_closure(bcx0: block,
cap_vars: &[moves::CaptureVar],
proto: ast::Proto,
sigil: ast::Sigil,
include_ret_handle: Option<ValueRef>) -> closure_result {
let _icx = bcx0.insn_ctxt("closure::build_closure");
// If we need to, package up the iterator body to call
@ -279,7 +275,7 @@ pub fn build_closure(bcx0: block,
let datum = expr::trans_local_var(bcx, cap_var.def);
match cap_var.mode {
moves::CapRef => {
assert proto == ast::ProtoBorrowed;
assert sigil == ast::BorrowedSigil;
env_vals.push(EnvValue {action: EnvRef,
datum: datum});
}
@ -316,7 +312,7 @@ pub fn build_closure(bcx0: block,
datum: ret_datum});
}
return store_environment(bcx, env_vals, proto);
return store_environment(bcx, env_vals, sigil);
}
// Given an enclosing block context, a new function context, a closure type,
@ -326,7 +322,7 @@ pub fn load_environment(fcx: fn_ctxt,
cdata_ty: ty::t,
cap_vars: &[moves::CaptureVar],
load_ret_handle: bool,
proto: ast::Proto) {
sigil: ast::Sigil) {
let _icx = fcx.insn_ctxt("closure::load_environment");
let llloadenv = match fcx.llloadenv {
@ -352,9 +348,9 @@ pub fn load_environment(fcx: fn_ctxt,
let mut i = 0u;
for cap_vars.each |cap_var| {
let mut upvarptr = GEPi(bcx, llcdata, [0u, i]);
match proto {
ast::ProtoBorrowed => { upvarptr = Load(bcx, upvarptr); }
ast::ProtoBox | ast::ProtoUniq | ast::ProtoBare => {}
match sigil {
ast::BorrowedSigil => { upvarptr = Load(bcx, upvarptr); }
ast::ManagedSigil | ast::OwnedSigil => {}
}
let def_id = ast_util::def_id_of_def(cap_var.def);
fcx.llupvars.insert(def_id.node, upvarptr);
@ -369,9 +365,9 @@ pub fn load_environment(fcx: fn_ctxt,
}
pub fn trans_expr_fn(bcx: block,
proto: ast::Proto,
+decl: ast::fn_decl,
+body: ast::blk,
sigil: ast::Sigil,
decl: &ast::fn_decl,
body: &ast::blk,
outer_id: ast::node_id,
user_id: ast::node_id,
is_loop_body: Option<Option<ValueRef>>,
@ -381,7 +377,7 @@ pub fn trans_expr_fn(bcx: block,
*
* Translates the body of a closure expression.
*
* - `proto`
* - `sigil`
* - `decl`
* - `body`
* - `outer_id`: The id of the closure expression with the correct
@ -417,18 +413,18 @@ pub fn trans_expr_fn(bcx: block,
~"expr_fn");
let llfn = decl_internal_cdecl_fn(ccx.llmod, s, llfnty);
let Result {bcx: bcx, val: closure} = match proto {
ast::ProtoBorrowed | ast::ProtoBox | ast::ProtoUniq => {
let cap_vars = ccx.maps.capture_map.get(user_id);
let Result {bcx: bcx, val: closure} = match sigil {
ast::BorrowedSigil | ast::ManagedSigil | ast::OwnedSigil => {
let cap_vars = ccx.maps.capture_map.get(&user_id);
let ret_handle = match is_loop_body {Some(x) => x,
None => None};
let {llbox, cdata_ty, bcx} = build_closure(bcx, cap_vars, proto,
let {llbox, cdata_ty, bcx} = build_closure(bcx, cap_vars, sigil,
ret_handle);
trans_closure(ccx, sub_path, decl,
body, llfn, no_self,
/*bad*/ copy bcx.fcx.param_substs, user_id, None,
|fcx| load_environment(fcx, cdata_ty, cap_vars,
ret_handle.is_some(), proto),
ret_handle.is_some(), sigil),
|bcx| {
if is_loop_body.is_some() {
Store(bcx, C_bool(true), bcx.fcx.llretptr);
@ -436,34 +432,30 @@ pub fn trans_expr_fn(bcx: block,
});
rslt(bcx, llbox)
}
ast::ProtoBare => {
trans_closure(ccx, sub_path, decl, body, llfn, no_self, None,
user_id, None, |_fcx| { }, |_bcx| { });
rslt(bcx, C_null(T_opaque_box_ptr(ccx)))
}
};
fill_fn_pair(bcx, dest_addr, llfn, closure);
return bcx;
}
pub fn make_fn_glue(cx: block,
v: ValueRef,
t: ty::t,
glue_fn: fn@(block, v: ValueRef, t: ty::t) -> block)
-> block {
let _icx = cx.insn_ctxt("closure::make_fn_glue");
pub fn make_closure_glue(
cx: block,
v: ValueRef,
t: ty::t,
glue_fn: fn@(block, v: ValueRef, t: ty::t) -> block) -> block
{
let _icx = cx.insn_ctxt("closure::make_closure_glue");
let bcx = cx;
let tcx = cx.tcx();
let proto = ty::ty_fn_proto(t);
match proto {
ast::ProtoBare | ast::ProtoBorrowed => bcx,
ast::ProtoUniq | ast::ProtoBox => {
let sigil = ty::ty_closure_sigil(t);
match sigil {
ast::BorrowedSigil => bcx,
ast::OwnedSigil | ast::ManagedSigil => {
let box_cell_v = GEPi(cx, v, [0u, abi::fn_field_box]);
let box_ptr_v = Load(cx, box_cell_v);
do with_cond(cx, IsNotNull(cx, box_ptr_v)) |bcx| {
let closure_ty = ty::mk_opaque_closure_ptr(tcx, proto);
let closure_ty = ty::mk_opaque_closure_ptr(tcx, sigil);
glue_fn(bcx, box_cell_v, closure_ty)
}
}
@ -472,20 +464,20 @@ pub fn make_fn_glue(cx: block,
pub fn make_opaque_cbox_take_glue(
bcx: block,
proto: ast::Proto,
sigil: ast::Sigil,
cboxptr: ValueRef) // ptr to ptr to the opaque closure
-> block {
// Easy cases:
let _icx = bcx.insn_ctxt("closure::make_opaque_cbox_take_glue");
match proto {
ast::ProtoBare | ast::ProtoBorrowed => {
match sigil {
ast::BorrowedSigil => {
return bcx;
}
ast::ProtoBox => {
ast::ManagedSigil => {
glue::incr_refcnt_of_boxed(bcx, Load(bcx, cboxptr));
return bcx;
}
ast::ProtoUniq => {
ast::OwnedSigil => {
/* hard case: fallthrough to code below */
}
}
@ -531,36 +523,36 @@ pub fn make_opaque_cbox_take_glue(
pub fn make_opaque_cbox_drop_glue(
bcx: block,
proto: ast::Proto,
sigil: ast::Sigil,
cboxptr: ValueRef) // ptr to the opaque closure
-> block {
let _icx = bcx.insn_ctxt("closure::make_opaque_cbox_drop_glue");
match proto {
ast::ProtoBare | ast::ProtoBorrowed => bcx,
ast::ProtoBox => {
match sigil {
ast::BorrowedSigil => bcx,
ast::ManagedSigil => {
glue::decr_refcnt_maybe_free(
bcx, Load(bcx, cboxptr),
ty::mk_opaque_closure_ptr(bcx.tcx(), proto))
ty::mk_opaque_closure_ptr(bcx.tcx(), sigil))
}
ast::ProtoUniq => {
ast::OwnedSigil => {
glue::free_ty(
bcx, cboxptr,
ty::mk_opaque_closure_ptr(bcx.tcx(), proto))
ty::mk_opaque_closure_ptr(bcx.tcx(), sigil))
}
}
}
pub fn make_opaque_cbox_free_glue(
bcx: block,
proto: ast::Proto,
sigil: ast::Sigil,
cbox: ValueRef) // ptr to ptr to the opaque closure
-> block {
let _icx = bcx.insn_ctxt("closure::make_opaque_cbox_free_glue");
match proto {
ast::ProtoBare | ast::ProtoBorrowed => {
match sigil {
ast::BorrowedSigil => {
return bcx;
}
ast::ProtoBox | ast::ProtoUniq => {
ast::ManagedSigil | ast::OwnedSigil => {
/* hard cases: fallthrough to code below */
}
}
@ -580,10 +572,10 @@ pub fn make_opaque_cbox_free_glue(
abi::tydesc_field_drop_glue, None);
// Free the ty descr (if necc) and the box itself
match proto {
ast::ProtoBox => glue::trans_free(bcx, cbox),
ast::ProtoUniq => glue::trans_unique_free(bcx, cbox),
ast::ProtoBare | ast::ProtoBorrowed => {
match sigil {
ast::ManagedSigil => glue::trans_free(bcx, cbox),
ast::OwnedSigil => glue::trans_unique_free(bcx, cbox),
ast::BorrowedSigil => {
bcx.sess().bug(~"impossible")
}
}

View File

@ -152,13 +152,15 @@ pub fn BuilderRef_res(B: BuilderRef) -> BuilderRef_res {
}
}
type ExternMap = HashMap<@str, ValueRef>;
// Crate context. Every crate we compile has one of these.
pub struct crate_ctxt {
sess: session::Session,
llmod: ModuleRef,
td: target_data,
tn: type_names,
externs: HashMap<~str, ValueRef>,
externs: ExternMap,
intrinsics: HashMap<~str, ValueRef>,
item_vals: HashMap<ast::node_id, ValueRef>,
exp_map2: resolve::ExportMap2,
@ -700,7 +702,7 @@ pub impl block {
}
fn def(nid: ast::node_id) -> ast::def {
match self.tcx().def_map.find(nid) {
match self.tcx().def_map.find(&nid) {
Some(v) => v,
None => {
self.tcx().sess.bug(fmt!(
@ -759,7 +761,7 @@ pub fn T_f32() -> TypeRef { unsafe { return llvm::LLVMFloatType(); } }
pub fn T_f64() -> TypeRef { unsafe { return llvm::LLVMDoubleType(); } }
pub fn T_bool() -> TypeRef { return T_i1(); }
pub fn T_bool() -> TypeRef { return T_i8(); }
pub fn T_int(targ_cfg: @session::config) -> TypeRef {
return match targ_cfg.arch {
@ -1109,6 +1111,10 @@ pub fn C_bool(b: bool) -> ValueRef {
C_integral(T_bool(), if b { 1u64 } else { 0u64 }, False)
}
pub fn C_i1(b: bool) -> ValueRef {
return C_integral(T_i1(), if b { 1 } else { 0 }, False);
}
pub fn C_i32(i: i32) -> ValueRef {
return C_integral(T_i32(), i as u64, True);
}
@ -1134,7 +1140,7 @@ pub fn C_u8(i: uint) -> ValueRef {
// our boxed-and-length-annotated strings.
pub fn C_cstr(cx: @crate_ctxt, +s: ~str) -> ValueRef {
unsafe {
match cx.const_cstr_cache.find(/*bad*/copy s) {
match cx.const_cstr_cache.find(&s) {
Some(llval) => return llval,
None => ()
}
@ -1356,7 +1362,7 @@ pub fn node_id_type_params(bcx: block, id: ast::node_id) -> ~[ty::t] {
pub fn node_vtables(bcx: block, id: ast::node_id)
-> Option<typeck::vtable_res> {
let raw_vtables = bcx.ccx().maps.vtable_map.find(id);
let raw_vtables = bcx.ccx().maps.vtable_map.find(&id);
raw_vtables.map(
|vts| resolve_vtables_in_fn_ctxt(bcx.fcx, *vts))
}
@ -1435,6 +1441,11 @@ pub fn struct_dtor() -> [uint * 2] {
[0, 1]
}
// Casts a Rust bool value to an i1.
pub fn bool_to_i1(bcx: block, llval: ValueRef) -> ValueRef {
build::ICmp(bcx, lib::llvm::IntNE, llval, C_bool(false))
}
//
// Local Variables:
// mode: rust

View File

@ -82,7 +82,7 @@ pub fn const_vec(cx: @crate_ctxt, e: @ast::expr, es: &[@ast::expr])
pub fn const_deref(cx: @crate_ctxt, v: ValueRef) -> ValueRef {
unsafe {
let v = match cx.const_globals.find(v as int) {
let v = match cx.const_globals.find(&(v as int)) {
Some(v) => v,
None => v
};
@ -127,7 +127,7 @@ pub fn get_const_val(cx: @crate_ctxt, def_id: ast::def_id) -> ValueRef {
cx.tcx.sess.bug(~"cross-crate constants");
}
if !cx.const_values.contains_key_ref(&def_id.node) {
match cx.tcx.items.get(def_id.node) {
match cx.tcx.items.get(&def_id.node) {
ast_map::node_item(@ast::item {
node: ast::item_const(_, subexpr), _
}, _) => {
@ -136,7 +136,7 @@ pub fn get_const_val(cx: @crate_ctxt, def_id: ast::def_id) -> ValueRef {
_ => cx.tcx.sess.bug(~"expected a const to be an item")
}
}
cx.const_values.get(def_id.node)
cx.const_values.get(&def_id.node)
}
pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
@ -204,7 +204,18 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
ast::box(_) |
ast::uniq(_) |
ast::deref => const_deref(cx, te),
ast::not => llvm::LLVMConstNot(te),
ast::not => {
match ty::get(ty).sty {
ty::ty_bool => {
// Somewhat questionable, but I believe this is
// correct.
let te = llvm::LLVMConstTrunc(te, T_i1());
let te = llvm::LLVMConstNot(te);
llvm::LLVMConstZExt(te, T_bool())
}
_ => llvm::LLVMConstNot(te),
}
}
ast::neg => {
if is_float { llvm::LLVMConstFNeg(te) }
else { llvm::LLVMConstNeg(te) }
@ -402,7 +413,7 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
}
ast::expr_path(pth) => {
assert pth.types.len() == 0;
match cx.tcx.def_map.find(e.id) {
match cx.tcx.def_map.find(&e.id) {
Some(ast::def_fn(def_id, purity)) => {
assert ast_util::is_local(def_id);
let f = base::get_item_val(cx, def_id.node);
@ -437,7 +448,7 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
}
}
ast::expr_call(callee, args, _) => {
match cx.tcx.def_map.find(callee.id) {
match cx.tcx.def_map.find(&callee.id) {
Some(ast::def_struct(def_id)) => {
let ety = ty::expr_ty(cx.tcx, e);
let llty = type_of::type_of(cx, ety);
@ -482,7 +493,7 @@ pub fn trans_const(ccx: @crate_ctxt, _e: @ast::expr, id: ast::node_id) {
let g = base::get_item_val(ccx, id);
// At this point, get_item_val has already translated the
// constant's initializer to determine its LLVM type.
let v = ccx.const_values.get(id);
let v = ccx.const_values.get(&id);
llvm::LLVMSetInitializer(g, v);
llvm::LLVMSetGlobalConstant(g, True);
}

Some files were not shown because too many files have changed in this diff Show More