From f2c5642d134df70755e0aede94074767cd3958eb Mon Sep 17 00:00:00 2001 From: Philipp Brüschweiler Date: Wed, 19 Jun 2013 19:54:54 +0200 Subject: Fix get_tydesc() return type This fixes part of #3730, but not all. Also changes the TyDesc struct to be equivalent with the generated code, with the hope that the above issue may one day be closed for good, i.e. that the TyDesc type can completely be specified in the Rust sources and not be generated. --- src/libstd/unstable/intrinsics.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/unstable/intrinsics.rs b/src/libstd/unstable/intrinsics.rs index c38b013a75a..08fc90fa908 100644 --- a/src/libstd/unstable/intrinsics.rs +++ b/src/libstd/unstable/intrinsics.rs @@ -209,6 +209,9 @@ pub extern "rust-intrinsic" { pub fn pref_align_of() -> uint; /// Get a static pointer to a type descriptor. + #[cfg(not(stage0))] + pub fn get_tydesc() -> *::intrinsic::TyDesc; + #[cfg(stage0)] pub fn get_tydesc() -> *(); /// Create a value initialized to zero. -- cgit 1.4.1-3-g733a5 From 469f394b251feebfb16090303da59206ba25acc6 Mon Sep 17 00:00:00 2001 From: Philipp Brüschweiler Date: Thu, 20 Jun 2013 11:39:49 +0200 Subject: Remove intrinsic module To achieve this, the following changes were made: * Move TyDesc, TyVisitor and Opaque to std::unstable::intrinsics * Convert TyDesc, TyVisitor and Opaque to lang items instead of specially handling the intrinsics module * Removed TypeDesc, FreeGlue and get_type_desc() from sys Fixes #3475. --- src/libextra/arena.rs | 29 ++++--- src/libextra/dbg.rs | 34 +++++--- src/librustc/driver/driver.rs | 3 - src/librustc/front/intrinsic.rs | 148 -------------------------------- src/librustc/front/intrinsic_inject.rs | 47 ---------- src/librustc/middle/lang_items.rs | 24 +++++- src/librustc/middle/trans/reflect.rs | 8 +- src/librustc/middle/ty.rs | 27 ++++-- src/librustc/middle/typeck/check/mod.rs | 8 +- src/librustc/middle/typeck/collect.rs | 55 ++---------- src/librustc/rustc.rc | 1 - src/libstd/at_vec.rs | 13 ++- src/libstd/cleanup.rs | 28 +++--- src/libstd/managed.rs | 2 +- src/libstd/reflect.rs | 6 +- src/libstd/repr.rs | 20 ++++- src/libstd/rt/global_heap.rs | 10 +-- src/libstd/sys.rs | 12 +-- src/libstd/unstable/exchange_alloc.rs | 10 +-- src/libstd/unstable/intrinsics.rs | 129 +++++++++++++++++++++++++++- src/libstd/vec.rs | 15 +++- src/test/run-pass/extern-pub.rs | 6 +- src/test/run-pass/reflect-visit-data.rs | 20 ++--- 23 files changed, 298 insertions(+), 357 deletions(-) delete mode 100644 src/librustc/front/intrinsic.rs delete mode 100644 src/librustc/front/intrinsic_inject.rs (limited to 'src/libstd') diff --git a/src/libextra/arena.rs b/src/libextra/arena.rs index db4cf564bab..a7d5660cd2e 100644 --- a/src/libextra/arena.rs +++ b/src/libextra/arena.rs @@ -43,20 +43,27 @@ use core::cast::{transmute, transmute_mut_region}; use core::cast; use core::libc::size_t; use core::ptr; -use core::sys::TypeDesc; use core::sys; use core::uint; use core::vec; use core::unstable::intrinsics; +#[cfg(stage0)] +use intrinsic::{get_tydesc, TyDesc}; +#[cfg(not(stage0))] +use core::unstable::intrinsics::{get_tydesc, TyDesc}; + pub mod rustrt { use core::libc::size_t; - use core::sys::TypeDesc; + #[cfg(stage0)] + use intrinsic::{TyDesc}; + #[cfg(not(stage0))] + use core::unstable::intrinsics::{TyDesc}; pub extern { #[rust_stack] unsafe fn rust_call_tydesc_glue(root: *u8, - tydesc: *TypeDesc, + tydesc: *TyDesc, field: size_t); } } @@ -136,7 +143,7 @@ unsafe fn destroy_chunk(chunk: &Chunk) { let (tydesc, is_done) = un_bitpack_tydesc_ptr(*tydesc_data); let (size, align) = ((*tydesc).size, (*tydesc).align); - let after_tydesc = idx + sys::size_of::<*TypeDesc>(); + let after_tydesc = idx + sys::size_of::<*TyDesc>(); let start = round_up_to(after_tydesc, align); @@ -148,7 +155,7 @@ unsafe fn destroy_chunk(chunk: &Chunk) { } // Find where the next tydesc lives - idx = round_up_to(start + size, sys::pref_align_of::<*TypeDesc>()); + idx = round_up_to(start + size, sys::pref_align_of::<*TyDesc>()); } } @@ -157,12 +164,12 @@ unsafe fn destroy_chunk(chunk: &Chunk) { // is necessary in order to properly do cleanup if a failure occurs // during an initializer. #[inline] -unsafe fn bitpack_tydesc_ptr(p: *TypeDesc, is_done: bool) -> uint { +unsafe fn bitpack_tydesc_ptr(p: *TyDesc, is_done: bool) -> uint { let p_bits: uint = transmute(p); p_bits | (is_done as uint) } #[inline] -unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TypeDesc, bool) { +unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TyDesc, bool) { (transmute(p & !1), p & 1 == 1) } @@ -202,7 +209,7 @@ impl Arena { #[inline] fn alloc_pod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T { unsafe { - let tydesc = sys::get_type_desc::(); + let tydesc = get_tydesc::(); let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align); let ptr: *mut T = transmute(ptr); intrinsics::move_val_init(&mut (*ptr), op()); @@ -230,13 +237,13 @@ impl Arena { let head = transmute_mut_region(&mut self.head); let tydesc_start = head.fill; - let after_tydesc = head.fill + sys::size_of::<*TypeDesc>(); + let after_tydesc = head.fill + sys::size_of::<*TyDesc>(); let start = round_up_to(after_tydesc, align); let end = start + n_bytes; if end > at_vec::capacity(head.data) { return self.alloc_nonpod_grow(n_bytes, align); } - head.fill = round_up_to(end, sys::pref_align_of::<*TypeDesc>()); + head.fill = round_up_to(end, sys::pref_align_of::<*TyDesc>()); //debug!("idx = %u, size = %u, align = %u, fill = %u", // start, n_bytes, align, head.fill); @@ -249,7 +256,7 @@ impl Arena { #[inline] fn alloc_nonpod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T { unsafe { - let tydesc = sys::get_type_desc::(); + let tydesc = get_tydesc::(); let (ty_ptr, ptr) = self.alloc_nonpod_inner((*tydesc).size, (*tydesc).align); let ty_ptr: *mut uint = transmute(ty_ptr); diff --git a/src/libextra/dbg.rs b/src/libextra/dbg.rs index cbd7cb5e3c0..43c4aecdd27 100644 --- a/src/libextra/dbg.rs +++ b/src/libextra/dbg.rs @@ -13,56 +13,62 @@ #[allow(missing_doc)]; use core::cast::transmute; -use core::sys; +#[cfg(stage0)] +use intrinsic::{get_tydesc}; +#[cfg(not(stage0))] +use core::unstable::intrinsics::{get_tydesc}; pub mod rustrt { - use core::sys; + #[cfg(stage0)] + use intrinsic::{TyDesc}; + #[cfg(not(stage0))] + use core::unstable::intrinsics::{TyDesc}; #[abi = "cdecl"] pub extern { - pub unsafe fn debug_tydesc(td: *sys::TypeDesc); - pub unsafe fn debug_opaque(td: *sys::TypeDesc, x: *()); - pub unsafe fn debug_box(td: *sys::TypeDesc, x: *()); - pub unsafe fn debug_tag(td: *sys::TypeDesc, x: *()); - pub unsafe fn debug_fn(td: *sys::TypeDesc, x: *()); - pub unsafe fn debug_ptrcast(td: *sys::TypeDesc, x: *()) -> *(); + pub unsafe fn debug_tydesc(td: *TyDesc); + pub unsafe fn debug_opaque(td: *TyDesc, x: *()); + pub unsafe fn debug_box(td: *TyDesc, x: *()); + pub unsafe fn debug_tag(td: *TyDesc, x: *()); + pub unsafe fn debug_fn(td: *TyDesc, x: *()); + pub unsafe fn debug_ptrcast(td: *TyDesc, x: *()) -> *(); pub unsafe fn rust_dbg_breakpoint(); } } pub fn debug_tydesc() { unsafe { - rustrt::debug_tydesc(sys::get_type_desc::()); + rustrt::debug_tydesc(get_tydesc::()); } } pub fn debug_opaque(x: T) { unsafe { - rustrt::debug_opaque(sys::get_type_desc::(), transmute(&x)); + rustrt::debug_opaque(get_tydesc::(), transmute(&x)); } } pub fn debug_box(x: @T) { unsafe { - rustrt::debug_box(sys::get_type_desc::(), transmute(&x)); + rustrt::debug_box(get_tydesc::(), transmute(&x)); } } pub fn debug_tag(x: T) { unsafe { - rustrt::debug_tag(sys::get_type_desc::(), transmute(&x)); + rustrt::debug_tag(get_tydesc::(), transmute(&x)); } } pub fn debug_fn(x: T) { unsafe { - rustrt::debug_fn(sys::get_type_desc::(), transmute(&x)); + rustrt::debug_fn(get_tydesc::(), transmute(&x)); } } pub unsafe fn ptr_cast(x: @T) -> @U { transmute( - rustrt::debug_ptrcast(sys::get_type_desc::(), transmute(x))) + rustrt::debug_ptrcast(get_tydesc::(), transmute(x))) } /// Triggers a debugger breakpoint diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 1a7041c0884..fbb273450df 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -206,9 +206,6 @@ pub fn compile_rest(sess: Session, let mut crate = crate_opt.unwrap(); let (llcx, llmod, link_meta) = { - crate = time(time_passes, ~"intrinsic injection", || - front::intrinsic_inject::inject_intrinsic(sess, crate)); - crate = time(time_passes, ~"extra injection", || front::std_inject::maybe_inject_libstd_ref(sess, crate)); diff --git a/src/librustc/front/intrinsic.rs b/src/librustc/front/intrinsic.rs deleted file mode 100644 index f19e3706253..00000000000 --- a/src/librustc/front/intrinsic.rs +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// NB: this file is include_str!'ed into the compiler, re-parsed -// and injected into each crate the compiler builds. Keep it small. - -pub mod intrinsic { - #[allow(missing_doc)]; - - pub use intrinsic::rusti::visit_tydesc; - - // FIXME (#3727): remove this when the interface has settled and the - // version in sys is no longer present. - pub fn get_tydesc() -> *TyDesc { - unsafe { - rusti::get_tydesc::() - } - } - - pub type GlueFn = extern "Rust" fn(**TyDesc, *i8); - - // NB: this has to be kept in sync with the Rust ABI. - pub struct TyDesc { - size: uint, - align: uint, - take_glue: GlueFn, - drop_glue: GlueFn, - free_glue: GlueFn, - visit_glue: GlueFn, - shape: *i8, - shape_tables: *i8 - } - - pub enum Opaque { } - - pub trait TyVisitor { - fn visit_bot(&self) -> bool; - fn visit_nil(&self) -> bool; - fn visit_bool(&self) -> bool; - - fn visit_int(&self) -> bool; - fn visit_i8(&self) -> bool; - fn visit_i16(&self) -> bool; - fn visit_i32(&self) -> bool; - fn visit_i64(&self) -> bool; - - fn visit_uint(&self) -> bool; - fn visit_u8(&self) -> bool; - fn visit_u16(&self) -> bool; - fn visit_u32(&self) -> bool; - fn visit_u64(&self) -> bool; - - fn visit_float(&self) -> bool; - fn visit_f32(&self) -> bool; - fn visit_f64(&self) -> bool; - - fn visit_char(&self) -> bool; - fn visit_str(&self) -> bool; - - fn visit_estr_box(&self) -> bool; - fn visit_estr_uniq(&self) -> bool; - fn visit_estr_slice(&self) -> bool; - fn visit_estr_fixed(&self, n: uint, sz: uint, align: uint) -> bool; - - fn visit_box(&self, mtbl: uint, inner: *TyDesc) -> bool; - fn visit_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool; - fn visit_ptr(&self, mtbl: uint, inner: *TyDesc) -> bool; - fn visit_rptr(&self, mtbl: uint, inner: *TyDesc) -> bool; - - fn visit_vec(&self, mtbl: uint, inner: *TyDesc) -> bool; - fn visit_unboxed_vec(&self, mtbl: uint, inner: *TyDesc) -> bool; - fn visit_evec_box(&self, mtbl: uint, inner: *TyDesc) -> bool; - fn visit_evec_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool; - fn visit_evec_slice(&self, mtbl: uint, inner: *TyDesc) -> bool; - fn visit_evec_fixed(&self, n: uint, sz: uint, align: uint, - mtbl: uint, inner: *TyDesc) -> bool; - - fn visit_enter_rec(&self, n_fields: uint, - sz: uint, align: uint) -> bool; - fn visit_rec_field(&self, i: uint, name: &str, - mtbl: uint, inner: *TyDesc) -> bool; - fn visit_leave_rec(&self, n_fields: uint, - sz: uint, align: uint) -> bool; - - fn visit_enter_class(&self, n_fields: uint, - sz: uint, align: uint) -> bool; - fn visit_class_field(&self, i: uint, name: &str, - mtbl: uint, inner: *TyDesc) -> bool; - fn visit_leave_class(&self, n_fields: uint, - sz: uint, align: uint) -> bool; - - fn visit_enter_tup(&self, n_fields: uint, - sz: uint, align: uint) -> bool; - fn visit_tup_field(&self, i: uint, inner: *TyDesc) -> bool; - fn visit_leave_tup(&self, n_fields: uint, - sz: uint, align: uint) -> bool; - - fn visit_enter_enum(&self, n_variants: uint, - get_disr: extern unsafe fn(ptr: *Opaque) -> int, - sz: uint, align: uint) -> bool; - fn visit_enter_enum_variant(&self, variant: uint, - disr_val: int, - n_fields: uint, - name: &str) -> bool; - fn visit_enum_variant_field(&self, i: uint, offset: uint, inner: *TyDesc) -> bool; - fn visit_leave_enum_variant(&self, variant: uint, - disr_val: int, - n_fields: uint, - name: &str) -> bool; - fn visit_leave_enum(&self, n_variants: uint, - get_disr: extern unsafe fn(ptr: *Opaque) -> int, - sz: uint, align: uint) -> bool; - - fn visit_enter_fn(&self, purity: uint, proto: uint, - n_inputs: uint, retstyle: uint) -> bool; - fn visit_fn_input(&self, i: uint, mode: uint, inner: *TyDesc) -> bool; - fn visit_fn_output(&self, retstyle: uint, inner: *TyDesc) -> bool; - fn visit_leave_fn(&self, purity: uint, proto: uint, - n_inputs: uint, retstyle: uint) -> bool; - - fn visit_trait(&self) -> bool; - fn visit_var(&self) -> bool; - fn visit_var_integral(&self) -> bool; - fn visit_param(&self, i: uint) -> bool; - fn visit_self(&self) -> bool; - fn visit_type(&self) -> bool; - fn visit_opaque_box(&self) -> bool; - fn visit_constr(&self, inner: *TyDesc) -> bool; - fn visit_closure_ptr(&self, ck: uint) -> bool; - } - - pub mod rusti { - use super::{TyDesc, TyVisitor}; - - #[abi = "rust-intrinsic"] - pub extern "rust-intrinsic" { - pub fn get_tydesc() -> *TyDesc; - pub fn visit_tydesc(td: *TyDesc, tv: @TyVisitor); - } - } -} diff --git a/src/librustc/front/intrinsic_inject.rs b/src/librustc/front/intrinsic_inject.rs deleted file mode 100644 index 0caadc8572e..00000000000 --- a/src/librustc/front/intrinsic_inject.rs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use core::prelude::*; - -use core::vec; -use driver::session::Session; -use syntax::parse; -use syntax::ast; -use syntax::codemap::spanned; - -pub fn inject_intrinsic(sess: Session, crate: @ast::crate) -> @ast::crate { - let intrinsic_module = include_str!("intrinsic.rs").to_managed(); - - let item = parse::parse_item_from_source_str(@"", - intrinsic_module, - /*bad*/copy sess.opts.cfg, - ~[], - sess.parse_sess); - let item = - match item { - Some(i) => i, - None => { - sess.fatal("no item found in intrinsic module"); - } - }; - - let items = vec::append(~[item], crate.node.module.items); - - @spanned { - node: ast::crate_ { - module: ast::_mod { - items: items, - .. /*bad*/copy crate.node.module - }, - .. /*bad*/copy crate.node - }, - .. /*bad*/copy *crate - } -} diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 3a8d369469b..d73b019c1ea 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -76,16 +76,20 @@ pub enum LangItem { UnrecordBorrowFnLangItem, // 36 StartFnLangItem, // 37 + + TyDescStructLangItem, // 38 + TyVisitorTraitLangItem, // 39 + OpaqueStructLangItem, // 40 } pub struct LanguageItems { - items: [Option, ..38] + items: [Option, ..41] } impl LanguageItems { pub fn new() -> LanguageItems { LanguageItems { - items: [ None, ..38 ] + items: [ None, ..41 ] } } @@ -138,6 +142,10 @@ impl LanguageItems { 37 => "start", + 38 => "ty_desc", + 39 => "ty_visitor", + 40 => "opaque", + _ => "???" } } @@ -262,6 +270,15 @@ impl LanguageItems { pub fn start_fn(&const self) -> def_id { self.items[StartFnLangItem as uint].get() } + pub fn ty_desc(&const self) -> def_id { + self.items[TyDescStructLangItem as uint].get() + } + pub fn ty_visitor(&const self) -> def_id { + self.items[TyVisitorTraitLangItem as uint].get() + } + pub fn opaque(&const self) -> def_id { + self.items[OpaqueStructLangItem as uint].get() + } } fn LanguageItemCollector(crate: @crate, @@ -313,6 +330,9 @@ fn LanguageItemCollector(crate: @crate, item_refs.insert(@"record_borrow", RecordBorrowFnLangItem as uint); item_refs.insert(@"unrecord_borrow", UnrecordBorrowFnLangItem as uint); item_refs.insert(@"start", StartFnLangItem as uint); + item_refs.insert(@"ty_desc", TyDescStructLangItem as uint); + item_refs.insert(@"ty_visitor", TyVisitorTraitLangItem as uint); + item_refs.insert(@"opaque", OpaqueStructLangItem as uint); LanguageItemCollector { crate: crate, diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs index cb68a2af92b..9e5510fc605 100644 --- a/src/librustc/middle/trans/reflect.rs +++ b/src/librustc/middle/trans/reflect.rs @@ -274,9 +274,7 @@ impl Reflector { let repr = adt::represent_type(bcx.ccx(), t); let variants = ty::substd_enum_variants(ccx.tcx, did, substs); let llptrty = type_of(ccx, t).ptr_to(); - let (_, opaquety) = - ccx.tcx.intrinsic_defs.find_copy(&ccx.sess.ident_of("Opaque")) - .expect("Failed to resolve intrinsic::Opaque"); + let opaquety = ty::get_opaque_ty(ccx.tcx); let opaqueptrty = ty::mk_ptr(ccx.tcx, ty::mt { ty: opaquety, mutbl: ast::m_imm }); let make_get_disr = || { @@ -373,10 +371,8 @@ pub fn emit_calls_to_trait_visit_ty(bcx: block, visitor_val: ValueRef, visitor_trait_id: def_id) -> block { - use syntax::parse::token::special_idents::tydesc; let final = sub_block(bcx, "final"); - assert!(bcx.ccx().tcx.intrinsic_defs.contains_key(&tydesc)); - let (_, tydesc_ty) = bcx.ccx().tcx.intrinsic_defs.get_copy(&tydesc); + let tydesc_ty = ty::get_tydesc_ty(bcx.ccx().tcx); let tydesc_ty = type_of(bcx.ccx(), tydesc_ty); let mut r = Reflector { visitor_val: visitor_val, diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index a367cf4c430..f12ecebc6d5 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -44,7 +44,6 @@ use syntax::attr; use syntax::codemap::span; use syntax::codemap; use syntax::parse::token; -use syntax::parse::token::special_idents; use syntax::{ast, ast_map}; use syntax::opt_vec::OptVec; use syntax::opt_vec; @@ -276,8 +275,7 @@ struct ctxt_ { trait_defs: @mut HashMap, items: ast_map::map, - intrinsic_defs: @mut HashMap, - intrinsic_traits: @mut HashMap, + intrinsic_defs: @mut HashMap, freevars: freevars::freevar_map, tcache: type_cache, rcache: creader_cache, @@ -953,7 +951,6 @@ pub fn mk_ctxt(s: session::Session, node_type_substs: @mut HashMap::new(), trait_refs: @mut HashMap::new(), trait_defs: @mut HashMap::new(), - intrinsic_traits: @mut HashMap::new(), items: amap, intrinsic_defs: @mut HashMap::new(), freevars: freevars, @@ -4449,10 +4446,26 @@ pub fn get_impl_id(tcx: ctxt, trait_id: def_id, self_ty: t) -> def_id { } } +pub fn get_tydesc_ty(tcx: ctxt) -> t { + let tydesc_lang_item = tcx.lang_items.ty_desc(); + tcx.intrinsic_defs.find_copy(&tydesc_lang_item) + .expect("Failed to resolve TyDesc") +} + +pub fn get_opaque_ty(tcx: ctxt) -> t { + let tydesc_lang_item = tcx.lang_items.opaque(); + tcx.intrinsic_defs.find_copy(&tydesc_lang_item) + .expect("Failed to resolve Opaque") +} + pub fn visitor_object_ty(tcx: ctxt) -> (@TraitRef, t) { - let ty_visitor_name = special_idents::ty_visitor; - assert!(tcx.intrinsic_traits.contains_key(&ty_visitor_name)); - let trait_ref = tcx.intrinsic_traits.get_copy(&ty_visitor_name); + let substs = substs { + self_r: None, + self_ty: None, + tps: ~[] + }; + let trait_lang_item = tcx.lang_items.ty_visitor(); + let trait_ref = @TraitRef { def_id: trait_lang_item, substs: substs }; (trait_ref, mk_trait(tcx, trait_ref.def_id, copy trait_ref.substs, BoxTraitStore, ast::m_imm)) } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 4c074ce197e..821daee8bfb 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -3506,9 +3506,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) { } "get_tydesc" => { - let tydesc_name = special_idents::tydesc; - assert!(tcx.intrinsic_defs.contains_key(&tydesc_name)); - let (_, tydesc_ty) = tcx.intrinsic_defs.get_copy(&tydesc_name); + let tydesc_ty = ty::get_tydesc_ty(ccx.tcx); let td_ptr = ty::mk_ptr(ccx.tcx, ty::mt { ty: tydesc_ty, mutbl: ast::m_imm @@ -3516,9 +3514,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) { (1u, ~[], td_ptr) } "visit_tydesc" => { - let tydesc_name = special_idents::tydesc; - assert!(tcx.intrinsic_defs.contains_key(&tydesc_name)); - let (_, tydesc_ty) = tcx.intrinsic_defs.get_copy(&tydesc_name); + let tydesc_ty = ty::get_tydesc_ty(ccx.tcx); let (_, visitor_object_ty) = ty::visitor_object_ty(tcx); let td_ptr = ty::mk_ptr(ccx.tcx, ty::mt { ty: tydesc_ty, diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 7f820d11ac6..756bb4d1bb9 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -62,55 +62,16 @@ use syntax::opt_vec::OptVec; use syntax::opt_vec; pub fn collect_item_types(ccx: @mut CrateCtxt, crate: @ast::crate) { - - // FIXME (#2592): hooking into the "intrinsic" root module is crude. - // There ought to be a better approach. Attributes? - - for crate.node.module.items.iter().advance |crate_item| { - if crate_item.ident - == ::syntax::parse::token::special_idents::intrinsic { - - match crate_item.node { - ast::item_mod(ref m) => { - for m.items.iter().advance |intrinsic_item| { - let def_id = ast::def_id { crate: ast::local_crate, - node: intrinsic_item.id }; - let substs = substs { - self_r: None, - self_ty: None, - tps: ~[] - }; - - match intrinsic_item.node { - ast::item_trait(*) => { - let tref = @ty::TraitRef {def_id: def_id, - substs: substs}; - ccx.tcx.intrinsic_traits.insert - (intrinsic_item.ident, tref); - } - - ast::item_enum(*) => { - let ty = ty::mk_enum(ccx.tcx, def_id, substs); - ccx.tcx.intrinsic_defs.insert - (intrinsic_item.ident, (def_id, ty)); - } - - ast::item_struct(*) => { - let ty = ty::mk_struct(ccx.tcx, def_id, substs); - ccx.tcx.intrinsic_defs.insert - (intrinsic_item.ident, (def_id, ty)); - } - - _ => {} - } - } - } - _ => { } - } - break; - } + fn collect_intrinsic_type(ccx: @mut CrateCtxt, + lang_item: ast::def_id) { + let ty::ty_param_bounds_and_ty { ty: ty, _ } = + ccx.get_item_ty(lang_item); + ccx.tcx.intrinsic_defs.insert(lang_item, ty); } + collect_intrinsic_type(ccx, ccx.tcx.lang_items.ty_desc()); + collect_intrinsic_type(ccx, ccx.tcx.lang_items.opaque()); + visit::visit_crate( crate, ((), visit::mk_simple_visitor(@visit::SimpleVisitor { diff --git a/src/librustc/rustc.rc b/src/librustc/rustc.rc index d59a308beb5..20705b3d797 100644 --- a/src/librustc/rustc.rc +++ b/src/librustc/rustc.rc @@ -86,7 +86,6 @@ pub mod front { pub mod config; pub mod test; pub mod std_inject; - pub mod intrinsic_inject; } pub mod back { diff --git a/src/libstd/at_vec.rs b/src/libstd/at_vec.rs index 2b846c923c4..52115692dbc 100644 --- a/src/libstd/at_vec.rs +++ b/src/libstd/at_vec.rs @@ -26,13 +26,16 @@ use vec::ImmutableVector; pub mod rustrt { use libc; - use sys; use vec; + #[cfg(stage0)] + use intrinsic::{TyDesc}; + #[cfg(not(stage0))] + use unstable::intrinsics::{TyDesc}; #[abi = "cdecl"] #[link_name = "rustrt"] pub extern { - pub unsafe fn vec_reserve_shared_actual(t: *sys::TypeDesc, + pub unsafe fn vec_reserve_shared_actual(t: *TyDesc, v: **vec::raw::VecRepr, n: libc::size_t); } @@ -198,6 +201,10 @@ pub mod raw { use uint; use unstable::intrinsics::{move_val_init}; use vec; + #[cfg(stage0)] + use intrinsic::{get_tydesc}; + #[cfg(not(stage0))] + use unstable::intrinsics::{get_tydesc}; pub type VecRepr = vec::raw::VecRepr; pub type SliceRepr = vec::raw::SliceRepr; @@ -259,7 +266,7 @@ pub mod raw { // Only make the (slow) call into the runtime if we have to if capacity(*v) < n { let ptr: **VecRepr = transmute(v); - rustrt::vec_reserve_shared_actual(sys::get_type_desc::(), + rustrt::vec_reserve_shared_actual(get_tydesc::(), ptr, n as libc::size_t); } } diff --git a/src/libstd/cleanup.rs b/src/libstd/cleanup.rs index d1460b7a3c9..28aab9adad2 100644 --- a/src/libstd/cleanup.rs +++ b/src/libstd/cleanup.rs @@ -10,24 +10,18 @@ #[doc(hidden)]; -use libc::{c_char, c_void, intptr_t, uintptr_t}; -use ptr::mut_null; +use libc::{c_char, intptr_t, uintptr_t}; +use ptr::{mut_null, to_unsafe_ptr}; use repr::BoxRepr; -use sys::TypeDesc; use cast::transmute; #[cfg(not(test))] use unstable::lang::clear_task_borrow_list; -#[cfg(not(test))] use ptr::to_unsafe_ptr; - /** * Runtime structures * * NB: These must match the representation in the C++ runtime. */ -type DropGlue<'self> = &'self fn(**TypeDesc, *c_void); -type FreeGlue<'self> = &'self fn(**TypeDesc, *c_void); - type TaskID = uintptr_t; struct StackSegment { priv opaque: () } @@ -164,6 +158,20 @@ fn debug_mem() -> bool { false } +#[cfg(stage0)] +unsafe fn call_drop_glue(tydesc: *::std::unstable::intrinsics::TyDesc, data: *i8) { + use sys::TypeDesc; + + let tydesc: *TypeDesc = transmute(tydesc); + let drop_glue: extern "Rust" fn(**TypeDesc, *i8) = transmute((*tydesc).drop_glue); + drop_glue(to_unsafe_ptr(&tydesc), data); +} + +#[cfg(not(stage0))] +unsafe fn call_drop_glue(tydesc: *::std::unstable::intrinsics::TyDesc, data: *i8) { + ((*tydesc).drop_glue)(to_unsafe_ptr(&tydesc), data); +} + /// Destroys all managed memory (i.e. @ boxes) held by the current task. #[cfg(not(test))] #[lang="annihilate"] @@ -205,9 +213,7 @@ pub unsafe fn annihilate() { // callback, as the original value may have been freed. for each_live_alloc(false) |box, uniq| { if !uniq { - let tydesc: *TypeDesc = transmute(copy (*box).header.type_desc); - let drop_glue: DropGlue = transmute(((*tydesc).drop_glue, 0)); - drop_glue(to_unsafe_ptr(&tydesc), transmute(&(*box).data)); + call_drop_glue((*box).header.type_desc, transmute(&(*box).data)); } } diff --git a/src/libstd/managed.rs b/src/libstd/managed.rs index d514612b5af..b71b3b503c2 100644 --- a/src/libstd/managed.rs +++ b/src/libstd/managed.rs @@ -15,7 +15,7 @@ use ptr::to_unsafe_ptr; #[cfg(not(test))] use cmp::{Eq, Ord}; pub mod raw { - use intrinsic::TyDesc; + use std::unstable::intrinsics::TyDesc; pub static RC_EXCHANGE_UNIQUE : uint = (-1) as uint; pub static RC_MANAGED_UNIQUE : uint = (-2) as uint; diff --git a/src/libstd/reflect.rs b/src/libstd/reflect.rs index d276abf0c8b..16ab4771d0d 100644 --- a/src/libstd/reflect.rs +++ b/src/libstd/reflect.rs @@ -16,8 +16,10 @@ Runtime type reflection #[allow(missing_doc)]; -use intrinsic::{TyDesc, TyVisitor}; -use intrinsic::Opaque; +#[cfg(stage0)] +use intrinsic::{Opaque, TyDesc, TyVisitor}; +#[cfg(not(stage0))] +use unstable::intrinsics::{Opaque, TyDesc, TyVisitor}; use libc::c_void; use sys; use vec; diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index ab3f83d34d5..f39b5a00ed0 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -19,9 +19,6 @@ More runtime type reflection use cast::transmute; use char; use container::Container; -use intrinsic; -use intrinsic::{TyDesc, TyVisitor, visit_tydesc}; -use intrinsic::Opaque; use io::{Writer, WriterUtil}; use iterator::IteratorUtil; use libc::c_void; @@ -34,6 +31,10 @@ use to_str::ToStr; use vec::raw::{VecRepr, SliceRepr}; use vec; use vec::{OwnedVector, UnboxedVecRepr}; +#[cfg(stage0)] +use intrinsic::{Opaque, TyDesc, TyVisitor, get_tydesc, visit_tydesc}; +#[cfg(not(stage0))] +use unstable::intrinsics::{Opaque, TyDesc, TyVisitor, get_tydesc, visit_tydesc}; #[cfg(test)] use io; @@ -564,6 +565,7 @@ impl TyVisitor for ReprVisitor { fn visit_self(&self) -> bool { true } fn visit_type(&self) -> bool { true } + #[cfg(not(stage0))] fn visit_opaque_box(&self) -> bool { self.writer.write_char('@'); do self.get::<&managed::raw::BoxRepr> |b| { @@ -571,6 +573,16 @@ impl TyVisitor for ReprVisitor { self.visit_ptr_inner(p, b.header.type_desc); } } + #[cfg(stage0)] + fn visit_opaque_box(&self) -> bool { + self.writer.write_char('@'); + do self.get::<&managed::raw::BoxRepr> |b| { + let p = ptr::to_unsafe_ptr(&b.data) as *c_void; + unsafe { + self.visit_ptr_inner(p, transmute(b.header.type_desc)); + } + } + } // Type no longer exists, vestigial function. fn visit_constr(&self, _inner: *TyDesc) -> bool { fail!(); } @@ -581,7 +593,7 @@ impl TyVisitor for ReprVisitor { pub fn write_repr(writer: @Writer, object: &T) { unsafe { let ptr = ptr::to_unsafe_ptr(object) as *c_void; - let tydesc = intrinsic::get_tydesc::(); + let tydesc = get_tydesc::(); let u = ReprVisitor(ptr, writer); let v = reflect::MovePtrAdaptor(u); visit_tydesc(tydesc, @v as @TyVisitor) diff --git a/src/libstd/rt/global_heap.rs b/src/libstd/rt/global_heap.rs index ce7ff87b445..1e9f9aab834 100644 --- a/src/libstd/rt/global_heap.rs +++ b/src/libstd/rt/global_heap.rs @@ -8,26 +8,22 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use sys::{TypeDesc, size_of}; +use sys::{size_of}; use libc::{c_void, size_t, uintptr_t}; use c_malloc = libc::malloc; use c_free = libc::free; use managed::raw::{BoxHeaderRepr, BoxRepr}; use cast::transmute; -use unstable::intrinsics::{atomic_xadd,atomic_xsub}; +use unstable::intrinsics::{atomic_xadd,atomic_xsub,TyDesc}; use ptr::null; -use intrinsic::TyDesc; -pub unsafe fn malloc(td: *TypeDesc, size: uint) -> *c_void { +pub unsafe fn malloc(td: *TyDesc, size: uint) -> *c_void { assert!(td.is_not_null()); let total_size = get_box_size(size, (*td).align); let p = c_malloc(total_size as size_t); assert!(p.is_not_null()); - // FIXME #3475: Converting between our two different tydesc types - let td: *TyDesc = transmute(td); - let box: &mut BoxRepr = transmute(p); box.header.ref_count = -1; // Exchange values not ref counted box.header.type_desc = td; diff --git a/src/libstd/sys.rs b/src/libstd/sys.rs index 79ea60cc224..7f80375c2f6 100644 --- a/src/libstd/sys.rs +++ b/src/libstd/sys.rs @@ -17,14 +17,13 @@ use cast; use gc; use io; use libc; -use libc::{c_void, c_char, size_t}; +use libc::{c_char, size_t}; use repr; use str; use unstable::intrinsics; -pub type FreeGlue<'self> = &'self fn(*TypeDesc, *c_void); - // Corresponds to runtime type_desc type +#[cfg(stage0)] pub struct TypeDesc { size: uint, align: uint, @@ -58,16 +57,11 @@ pub mod rustrt { * performing dark magick. */ #[inline] +#[cfg(stage0)] pub fn get_type_desc() -> *TypeDesc { unsafe { intrinsics::get_tydesc::() as *TypeDesc } } -/// Returns a pointer to a type descriptor. -#[inline] -pub fn get_type_desc_val(_val: &T) -> *TypeDesc { - get_type_desc::() -} - /// Returns the size of a type #[inline] pub fn size_of() -> uint { diff --git a/src/libstd/unstable/exchange_alloc.rs b/src/libstd/unstable/exchange_alloc.rs index 3b35c2fb804..5c47901df48 100644 --- a/src/libstd/unstable/exchange_alloc.rs +++ b/src/libstd/unstable/exchange_alloc.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use sys::{TypeDesc, size_of}; +use sys::size_of; use libc::{c_void, size_t}; use c_malloc = libc::malloc; use c_free = libc::free; @@ -16,18 +16,18 @@ use managed::raw::{BoxHeaderRepr, BoxRepr}; use cast::transmute; use unstable::intrinsics::{atomic_xadd,atomic_xsub}; use ptr::null; +#[cfg(stage0)] use intrinsic::TyDesc; +#[cfg(not(stage0))] +use unstable::intrinsics::TyDesc; -pub unsafe fn malloc(td: *TypeDesc, size: uint) -> *c_void { +pub unsafe fn malloc(td: *TyDesc, size: uint) -> *c_void { assert!(td.is_not_null()); let total_size = get_box_size(size, (*td).align); let p = c_malloc(total_size as size_t); assert!(p.is_not_null()); - // FIXME #3475: Converting between our two different tydesc types - let td: *TyDesc = transmute(td); - let box: &mut BoxRepr = transmute(p); box.header.ref_count = -1; // Exchange values not ref counted box.header.type_desc = td; diff --git a/src/libstd/unstable/intrinsics.rs b/src/libstd/unstable/intrinsics.rs index 08fc90fa908..a51ba05710b 100644 --- a/src/libstd/unstable/intrinsics.rs +++ b/src/libstd/unstable/intrinsics.rs @@ -32,6 +32,128 @@ A quick refresher on memory ordering: */ +// This is needed to prevent duplicate lang item definitions. +#[cfg(test)] +pub use realstd::unstable::intrinsics::{TyDesc, Opaque, TyVisitor}; + +pub type GlueFn = extern "Rust" fn(**TyDesc, *i8); + +// NB: this has to be kept in sync with the Rust ABI. +#[lang="ty_desc"] +#[cfg(not(test))] +pub struct TyDesc { + size: uint, + align: uint, + take_glue: GlueFn, + drop_glue: GlueFn, + free_glue: GlueFn, + visit_glue: GlueFn, + shape: *i8, + shape_tables: *i8 +} + +#[lang="opaque"] +#[cfg(not(test))] +pub enum Opaque { } + +#[lang="ty_visitor"] +#[cfg(not(test))] +pub trait TyVisitor { + fn visit_bot(&self) -> bool; + fn visit_nil(&self) -> bool; + fn visit_bool(&self) -> bool; + + fn visit_int(&self) -> bool; + fn visit_i8(&self) -> bool; + fn visit_i16(&self) -> bool; + fn visit_i32(&self) -> bool; + fn visit_i64(&self) -> bool; + + fn visit_uint(&self) -> bool; + fn visit_u8(&self) -> bool; + fn visit_u16(&self) -> bool; + fn visit_u32(&self) -> bool; + fn visit_u64(&self) -> bool; + + fn visit_float(&self) -> bool; + fn visit_f32(&self) -> bool; + fn visit_f64(&self) -> bool; + + fn visit_char(&self) -> bool; + fn visit_str(&self) -> bool; + + fn visit_estr_box(&self) -> bool; + fn visit_estr_uniq(&self) -> bool; + fn visit_estr_slice(&self) -> bool; + fn visit_estr_fixed(&self, n: uint, sz: uint, align: uint) -> bool; + + fn visit_box(&self, mtbl: uint, inner: *TyDesc) -> bool; + fn visit_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool; + fn visit_ptr(&self, mtbl: uint, inner: *TyDesc) -> bool; + fn visit_rptr(&self, mtbl: uint, inner: *TyDesc) -> bool; + + fn visit_vec(&self, mtbl: uint, inner: *TyDesc) -> bool; + fn visit_unboxed_vec(&self, mtbl: uint, inner: *TyDesc) -> bool; + fn visit_evec_box(&self, mtbl: uint, inner: *TyDesc) -> bool; + fn visit_evec_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool; + fn visit_evec_slice(&self, mtbl: uint, inner: *TyDesc) -> bool; + fn visit_evec_fixed(&self, n: uint, sz: uint, align: uint, + mtbl: uint, inner: *TyDesc) -> bool; + + fn visit_enter_rec(&self, n_fields: uint, + sz: uint, align: uint) -> bool; + fn visit_rec_field(&self, i: uint, name: &str, + mtbl: uint, inner: *TyDesc) -> bool; + fn visit_leave_rec(&self, n_fields: uint, + sz: uint, align: uint) -> bool; + + fn visit_enter_class(&self, n_fields: uint, + sz: uint, align: uint) -> bool; + fn visit_class_field(&self, i: uint, name: &str, + mtbl: uint, inner: *TyDesc) -> bool; + fn visit_leave_class(&self, n_fields: uint, + sz: uint, align: uint) -> bool; + + fn visit_enter_tup(&self, n_fields: uint, + sz: uint, align: uint) -> bool; + fn visit_tup_field(&self, i: uint, inner: *TyDesc) -> bool; + fn visit_leave_tup(&self, n_fields: uint, + sz: uint, align: uint) -> bool; + + fn visit_enter_enum(&self, n_variants: uint, + get_disr: extern unsafe fn(ptr: *Opaque) -> int, + sz: uint, align: uint) -> bool; + fn visit_enter_enum_variant(&self, variant: uint, + disr_val: int, + n_fields: uint, + name: &str) -> bool; + fn visit_enum_variant_field(&self, i: uint, offset: uint, inner: *TyDesc) -> bool; + fn visit_leave_enum_variant(&self, variant: uint, + disr_val: int, + n_fields: uint, + name: &str) -> bool; + fn visit_leave_enum(&self, n_variants: uint, + get_disr: extern unsafe fn(ptr: *Opaque) -> int, + sz: uint, align: uint) -> bool; + + fn visit_enter_fn(&self, purity: uint, proto: uint, + n_inputs: uint, retstyle: uint) -> bool; + fn visit_fn_input(&self, i: uint, mode: uint, inner: *TyDesc) -> bool; + fn visit_fn_output(&self, retstyle: uint, inner: *TyDesc) -> bool; + fn visit_leave_fn(&self, purity: uint, proto: uint, + n_inputs: uint, retstyle: uint) -> bool; + + fn visit_trait(&self) -> bool; + fn visit_var(&self) -> bool; + fn visit_var_integral(&self) -> bool; + fn visit_param(&self, i: uint) -> bool; + fn visit_self(&self) -> bool; + fn visit_type(&self) -> bool; + fn visit_opaque_box(&self) -> bool; + fn visit_constr(&self, inner: *TyDesc) -> bool; + fn visit_closure_ptr(&self, ck: uint) -> bool; +} + #[abi = "rust-intrinsic"] pub extern "rust-intrinsic" { @@ -210,7 +332,7 @@ pub extern "rust-intrinsic" { /// Get a static pointer to a type descriptor. #[cfg(not(stage0))] - pub fn get_tydesc() -> *::intrinsic::TyDesc; + pub fn get_tydesc() -> *TyDesc; #[cfg(stage0)] pub fn get_tydesc() -> *(); @@ -234,9 +356,8 @@ pub extern "rust-intrinsic" { /// Returns `true` if a type requires drop glue. pub fn needs_drop() -> bool; - // XXX: intrinsic uses legacy modes and has reference to TyDesc - // and TyVisitor which are in librustc - //fn visit_tydesc(++td: *TyDesc, &&tv: TyVisitor) -> (); + #[cfg(not(stage0))] + pub fn visit_tydesc(td: *TyDesc, tv: @TyVisitor); pub fn frame_address(f: &once fn(*u8)); diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 17eb7e8e82b..fdf33df3a8a 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -31,6 +31,10 @@ use sys; use sys::size_of; use uint; use unstable::intrinsics; +#[cfg(stage0)] +use intrinsic::{get_tydesc}; +#[cfg(not(stage0))] +use unstable::intrinsics::{get_tydesc}; use vec; use util; @@ -38,19 +42,22 @@ use util; pub mod rustrt { use libc; - use sys; use vec::raw; + #[cfg(stage0)] + use intrinsic::{TyDesc}; + #[cfg(not(stage0))] + use unstable::intrinsics::{TyDesc}; #[abi = "cdecl"] pub extern { // These names are terrible. reserve_shared applies // to ~[] and reserve_shared_actual applies to @[]. #[fast_ffi] - unsafe fn vec_reserve_shared(t: *sys::TypeDesc, + unsafe fn vec_reserve_shared(t: *TyDesc, v: **raw::VecRepr, n: libc::size_t); #[fast_ffi] - unsafe fn vec_reserve_shared_actual(t: *sys::TypeDesc, + unsafe fn vec_reserve_shared_actual(t: *TyDesc, v: **raw::VecRepr, n: libc::size_t); } @@ -79,7 +86,7 @@ pub fn reserve(v: &mut ~[T], n: uint) { if capacity(v) < n { unsafe { let ptr: **raw::VecRepr = cast::transmute(v); - let td = sys::get_type_desc::(); + let td = get_tydesc::(); if ((**ptr).box_header.ref_count == managed::raw::RC_MANAGED_UNIQUE) { rustrt::vec_reserve_shared_actual(td, ptr, n as libc::size_t); diff --git a/src/test/run-pass/extern-pub.rs b/src/test/run-pass/extern-pub.rs index 29b0457fc05..2d6cc2c78de 100644 --- a/src/test/run-pass/extern-pub.rs +++ b/src/test/run-pass/extern-pub.rs @@ -1,11 +1,7 @@ use std::libc; -use std::sys; -use std::vec; extern { - pub unsafe fn vec_reserve_shared_actual(t: *sys::TypeDesc, - v: **vec::raw::VecRepr, - n: libc::size_t); + pub unsafe fn free(p: *libc::c_void); } pub fn main() { diff --git a/src/test/run-pass/reflect-visit-data.rs b/src/test/run-pass/reflect-visit-data.rs index a8571ab7325..176e49e0ea1 100644 --- a/src/test/run-pass/reflect-visit-data.rs +++ b/src/test/run-pass/reflect-visit-data.rs @@ -10,15 +10,14 @@ // xfail-fast -use std::bool; use std::int; use std::libc::c_void; use std::ptr; use std::sys; use std::vec::UnboxedVecRepr; -use intrinsic::{TyDesc, get_tydesc, visit_tydesc, TyVisitor, Opaque}; +use std::unstable::intrinsics::{TyDesc, get_tydesc, visit_tydesc, TyVisitor, Opaque}; -#[doc = "High-level interfaces to `intrinsic::visit_ty` reflection system."] +#[doc = "High-level interfaces to `std::unstable::intrinsics::visit_ty` reflection system."] /// Trait for visitor that wishes to reflect on data. trait movable_ptr { @@ -637,7 +636,9 @@ impl TyVisitor for my_visitor { } fn get_tydesc_for(_t: T) -> *TyDesc { - get_tydesc::() + unsafe { + get_tydesc::() + } } struct Triple { x: int, y: int, z: int } @@ -651,8 +652,8 @@ pub fn main() { vals: ~[]}); let v = ptr_visit_adaptor(Inner {inner: u}); let td = get_tydesc_for(r); - unsafe { error!("tydesc sz: %u, align: %u", - (*td).size, (*td).align); } + error!("tydesc sz: %u, align: %u", + (*td).size, (*td).align); let v = @v as @TyVisitor; visit_tydesc(td, v); @@ -661,8 +662,7 @@ pub fn main() { println(fmt!("val: %s", *s)); } error!("%?", u.vals.clone()); - assert!(u.vals == ~[ - ~"1", ~"2", ~"3", ~"true", ~"false", ~"5", ~"4", ~"3", ~"12" - ]); + assert_eq!(u.vals.clone(), + ~[ ~"1", ~"2", ~"3", ~"true", ~"false", ~"5", ~"4", ~"3", ~"12"]); } - } +} -- cgit 1.4.1-3-g733a5 From 8bf00333455a572bc4c48f947777ed2e7b57af09 Mon Sep 17 00:00:00 2001 From: Philipp Brüschweiler Date: Thu, 20 Jun 2013 14:45:10 +0200 Subject: Remove unused shape fields from typedescs --- src/librustc/back/abi.rs | 4 +--- src/librustc/middle/trans/glue.rs | 18 ++++++------------ src/librustc/middle/trans/type_.rs | 3 +-- src/libstd/unstable/intrinsics.rs | 2 -- src/rt/rust_builtin.cpp | 7 +++---- src/rt/rust_type.h | 2 -- src/rt/rust_util.cpp | 2 -- 7 files changed, 11 insertions(+), 27 deletions(-) (limited to 'src/libstd') diff --git a/src/librustc/back/abi.rs b/src/librustc/back/abi.rs index 004170dea7f..8f15c74ed0e 100644 --- a/src/librustc/back/abi.rs +++ b/src/librustc/back/abi.rs @@ -49,9 +49,7 @@ pub static tydesc_field_take_glue: uint = 2u; pub static tydesc_field_drop_glue: uint = 3u; pub static tydesc_field_free_glue: uint = 4u; pub static tydesc_field_visit_glue: uint = 5u; -pub static tydesc_field_shape: uint = 6u; -pub static tydesc_field_shape_tables: uint = 7u; -pub static n_tydesc_fields: uint = 8u; +pub static n_tydesc_fields: uint = 6u; // The two halves of a closure: code and environment. pub static fn_field_code: uint = 0u; diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index 0930d355035..f9bffb4a36e 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -765,19 +765,13 @@ pub fn emit_tydescs(ccx: &mut CrateContext) { } }; - - let shape = C_null(Type::i8p()); - let shape_tables = C_null(Type::i8p()); - let tydesc = C_named_struct(ccx.tydesc_type, - [ti.size, // size - ti.align, // align - take_glue, // take_glue - drop_glue, // drop_glue - free_glue, // free_glue - visit_glue, // visit_glue - shape, // shape - shape_tables]); // shape_tables + [ti.size, // size + ti.align, // align + take_glue, // take_glue + drop_glue, // drop_glue + free_glue, // free_glue + visit_glue]); // visit_glue unsafe { let gvar = ti.tydesc; diff --git a/src/librustc/middle/trans/type_.rs b/src/librustc/middle/trans/type_.rs index 764bdb026f4..fda8fb4a901 100644 --- a/src/librustc/middle/trans/type_.rs +++ b/src/librustc/middle/trans/type_.rs @@ -211,8 +211,7 @@ impl Type { let elems = [ int_ty, int_ty, - glue_fn_ty, glue_fn_ty, glue_fn_ty, glue_fn_ty, - pvoid, pvoid + glue_fn_ty, glue_fn_ty, glue_fn_ty, glue_fn_ty ]; tydesc.set_struct_body(elems, false); diff --git a/src/libstd/unstable/intrinsics.rs b/src/libstd/unstable/intrinsics.rs index a51ba05710b..84bb2a952f2 100644 --- a/src/libstd/unstable/intrinsics.rs +++ b/src/libstd/unstable/intrinsics.rs @@ -48,8 +48,6 @@ pub struct TyDesc { drop_glue: GlueFn, free_glue: GlueFn, visit_glue: GlueFn, - shape: *i8, - shape_tables: *i8 } #[lang="opaque"] diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index e476fa0ad5e..1a84325c7a9 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -732,10 +732,9 @@ rust_task_deref(rust_task *task) { // Must call on rust stack. extern "C" CDECL void rust_call_tydesc_glue(void *root, size_t *tydesc, size_t glue_index) { - void (*glue_fn)(void *, void *, void *) = - (void (*)(void *, void *, void *))tydesc[glue_index]; - if (glue_fn) - glue_fn(0, 0, root); + glue_fn *fn = (glue_fn*) tydesc[glue_index]; + if (fn) + fn(0, 0, root); } // Don't run on the Rust stack! diff --git a/src/rt/rust_type.h b/src/rt/rust_type.h index 6d36d2c960a..70b5c1dc6be 100644 --- a/src/rt/rust_type.h +++ b/src/rt/rust_type.h @@ -57,8 +57,6 @@ struct type_desc { glue_fn *drop_glue; glue_fn *free_glue; glue_fn *visit_glue; - const uint8_t *unused; - const uint8_t *unused2; }; extern "C" type_desc *rust_clone_type_desc(type_desc*); diff --git a/src/rt/rust_util.cpp b/src/rt/rust_util.cpp index 8d80a344063..4a15830e529 100644 --- a/src/rt/rust_util.cpp +++ b/src/rt/rust_util.cpp @@ -21,8 +21,6 @@ struct type_desc str_body_tydesc = { NULL, // drop_glue NULL, // free_glue NULL, // visit_glue - NULL, // shape - NULL, // shape_tables }; // -- cgit 1.4.1-3-g733a5 From 976c0b3dfb6a0da8a70958f157507b5dcf7c5ceb Mon Sep 17 00:00:00 2001 From: Philipp Brüschweiler Date: Fri, 21 Jun 2013 10:00:49 +0200 Subject: Remove rust_call_tydesc_glue Towards #4812. Also includes some minor cleanups. --- src/libextra/arena.rs | 32 ++++++++------------------------ src/libstd/cleanup.rs | 18 +++--------------- src/libstd/gc.rs | 15 +++++---------- src/libstd/sys.rs | 23 ----------------------- src/rt/rust_builtin.cpp | 8 -------- src/rt/rustrt.def.in | 3 +-- 6 files changed, 17 insertions(+), 82 deletions(-) (limited to 'src/libstd') diff --git a/src/libextra/arena.rs b/src/libextra/arena.rs index a7d5660cd2e..3766af04656 100644 --- a/src/libextra/arena.rs +++ b/src/libextra/arena.rs @@ -41,36 +41,20 @@ use list::{MutList, MutCons, MutNil}; use core::at_vec; use core::cast::{transmute, transmute_mut_region}; use core::cast; -use core::libc::size_t; use core::ptr; use core::sys; use core::uint; use core::vec; use core::unstable::intrinsics; +use core::unstable::intrinsics::{TyDesc}; -#[cfg(stage0)] -use intrinsic::{get_tydesc, TyDesc}; #[cfg(not(stage0))] -use core::unstable::intrinsics::{get_tydesc, TyDesc}; - -pub mod rustrt { - use core::libc::size_t; - #[cfg(stage0)] - use intrinsic::{TyDesc}; - #[cfg(not(stage0))] - use core::unstable::intrinsics::{TyDesc}; - - pub extern { - #[rust_stack] - unsafe fn rust_call_tydesc_glue(root: *u8, - tydesc: *TyDesc, - field: size_t); - } -} +use core::unstable::intrinsics::{get_tydesc}; -// This probably belongs somewhere else. Needs to be kept in sync with -// changes to glue... -static tydesc_drop_glue_index: size_t = 3 as size_t; +#[cfg(stage0)] +unsafe fn get_tydesc() -> *TyDesc { + intrinsics::get_tydesc::() as *TyDesc +} // The way arena uses arrays is really deeply awful. The arrays are // allocated, and have capacities reserved, but the fill for the array @@ -150,8 +134,8 @@ unsafe fn destroy_chunk(chunk: &Chunk) { //debug!("freeing object: idx = %u, size = %u, align = %u, done = %b", // start, size, align, is_done); if is_done { - rustrt::rust_call_tydesc_glue( - ptr::offset(buf, start), tydesc, tydesc_drop_glue_index); + ((*tydesc).drop_glue)(&tydesc as **TyDesc, + ptr::offset(buf, start) as *i8); } // Find where the next tydesc lives diff --git a/src/libstd/cleanup.rs b/src/libstd/cleanup.rs index 28aab9adad2..557a2fbc4ae 100644 --- a/src/libstd/cleanup.rs +++ b/src/libstd/cleanup.rs @@ -158,20 +158,6 @@ fn debug_mem() -> bool { false } -#[cfg(stage0)] -unsafe fn call_drop_glue(tydesc: *::std::unstable::intrinsics::TyDesc, data: *i8) { - use sys::TypeDesc; - - let tydesc: *TypeDesc = transmute(tydesc); - let drop_glue: extern "Rust" fn(**TypeDesc, *i8) = transmute((*tydesc).drop_glue); - drop_glue(to_unsafe_ptr(&tydesc), data); -} - -#[cfg(not(stage0))] -unsafe fn call_drop_glue(tydesc: *::std::unstable::intrinsics::TyDesc, data: *i8) { - ((*tydesc).drop_glue)(to_unsafe_ptr(&tydesc), data); -} - /// Destroys all managed memory (i.e. @ boxes) held by the current task. #[cfg(not(test))] #[lang="annihilate"] @@ -213,7 +199,9 @@ pub unsafe fn annihilate() { // callback, as the original value may have been freed. for each_live_alloc(false) |box, uniq| { if !uniq { - call_drop_glue((*box).header.type_desc, transmute(&(*box).data)); + let tydesc = (*box).header.type_desc; + let data = transmute(&(*box).data); + ((*tydesc).drop_glue)(to_unsafe_ptr(&tydesc), data); } } diff --git a/src/libstd/gc.rs b/src/libstd/gc.rs index 611b95a7745..2a211484e73 100644 --- a/src/libstd/gc.rs +++ b/src/libstd/gc.rs @@ -40,12 +40,13 @@ with destructors. use cast; use container::{Map, Set}; use io; -use libc::{size_t, uintptr_t}; +use libc::{uintptr_t}; use option::{None, Option, Some}; use ptr; use hashmap::HashSet; use stackwalk::walk_stack; use sys; +use unstable::intrinsics::{TyDesc}; pub use stackwalk::Word; @@ -58,17 +59,11 @@ pub struct StackSegment { } pub mod rustrt { - use libc::size_t; use stackwalk::Word; use super::StackSegment; #[link_name = "rustrt"] pub extern { - #[rust_stack] - pub unsafe fn rust_call_tydesc_glue(root: *Word, - tydesc: *Word, - field: size_t); - #[rust_stack] pub unsafe fn rust_gc_metadata() -> *Word; @@ -125,7 +120,7 @@ unsafe fn is_safe_point(pc: *Word) -> Option { return None; } -type Visitor<'self> = &'self fn(root: **Word, tydesc: *Word) -> bool; +type Visitor<'self> = &'self fn(root: **Word, tydesc: *TyDesc) -> bool; // Walks the list of roots for the given safe point, and calls visitor // on each root. @@ -139,7 +134,7 @@ unsafe fn _walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) -> bool { let stack_roots: *u32 = bump(sp_meta, 2); let reg_roots: *u8 = bump(stack_roots, num_stack_roots); let addrspaces: *Word = align_to_pointer(bump(reg_roots, num_reg_roots)); - let tydescs: ***Word = bump(addrspaces, num_stack_roots); + let tydescs: ***TyDesc = bump(addrspaces, num_stack_roots); // Stack roots let mut sri = 0; @@ -364,7 +359,7 @@ pub fn cleanup_stack_for_failure() { // FIXME #4420: Destroy this box // FIXME #4330: Destroy this box } else { - rustrt::rust_call_tydesc_glue(*root, tydesc, 3 as size_t); + ((*tydesc).drop_glue)(&tydesc as **TyDesc, *root as *i8); } } } diff --git a/src/libstd/sys.rs b/src/libstd/sys.rs index 7f80375c2f6..a1d6342323c 100644 --- a/src/libstd/sys.rs +++ b/src/libstd/sys.rs @@ -22,17 +22,6 @@ use repr; use str; use unstable::intrinsics; -// Corresponds to runtime type_desc type -#[cfg(stage0)] -pub struct TypeDesc { - size: uint, - align: uint, - take_glue: uint, - drop_glue: uint, - free_glue: uint - // Remaining fields not listed -} - /// The representation of a Rust closure pub struct Closure { code: *(), @@ -50,18 +39,6 @@ pub mod rustrt { } } -/** - * Returns a pointer to a type descriptor. - * - * Useful for calling certain function in the Rust runtime or otherwise - * performing dark magick. - */ -#[inline] -#[cfg(stage0)] -pub fn get_type_desc() -> *TypeDesc { - unsafe { intrinsics::get_tydesc::() as *TypeDesc } -} - /// Returns the size of a type #[inline] pub fn size_of() -> uint { diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 1a84325c7a9..8d771da32fc 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -729,14 +729,6 @@ rust_task_deref(rust_task *task) { task->deref(); } -// Must call on rust stack. -extern "C" CDECL void -rust_call_tydesc_glue(void *root, size_t *tydesc, size_t glue_index) { - glue_fn *fn = (glue_fn*) tydesc[glue_index]; - if (fn) - fn(0, 0, root); -} - // Don't run on the Rust stack! extern "C" void rust_log_str(uint32_t level, const char *str, size_t size) { diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index ba7ada04a27..7fd948d2cd9 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -174,7 +174,6 @@ rust_set_task_local_data rust_task_local_data_atexit rust_task_ref rust_task_deref -rust_call_tydesc_glue tdefl_compress_mem_to_heap tinfl_decompress_mem_to_heap rust_gc_metadata @@ -239,4 +238,4 @@ rust_valgrind_stack_deregister rust_take_env_lock rust_drop_env_lock rust_update_log_settings -rust_running_on_valgrind \ No newline at end of file +rust_running_on_valgrind -- cgit 1.4.1-3-g733a5 From e2f1049bd5f041f1f219d683e4e29e32ca30cd1c Mon Sep 17 00:00:00 2001 From: Philipp Brüschweiler Date: Sat, 22 Jun 2013 21:36:00 +0200 Subject: Remove unused TyDesc parameter from the glue functions To remove the environment pointer, support for function pointers without an environment argument is needed (i.e. a fixed version of #6661). --- src/libextra/arena.rs | 16 ++++++++++++++-- src/librustc/back/abi.rs | 13 ------------- src/librustc/middle/trans/glue.rs | 14 ++++---------- src/librustc/middle/trans/type_.rs | 11 ++++------- src/libstd/cleanup.rs | 18 ++++++++++++++++-- src/libstd/gc.rs | 15 ++++++++++++++- src/libstd/unstable/intrinsics.rs | 4 ++++ src/rt/rust_task.cpp | 6 +++++- src/rt/rust_type.h | 6 +++++- 9 files changed, 66 insertions(+), 37 deletions(-) (limited to 'src/libstd') diff --git a/src/libextra/arena.rs b/src/libextra/arena.rs index 3766af04656..cec3a2c1e95 100644 --- a/src/libextra/arena.rs +++ b/src/libextra/arena.rs @@ -115,6 +115,19 @@ fn round_up_to(base: uint, align: uint) -> uint { (base + (align - 1)) & !(align - 1) } +#[inline] +#[cfg(not(stage0))] +unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) { + // This function should be inlined when stage0 is gone + ((*tydesc).drop_glue)(data); +} + +#[inline] +#[cfg(stage0)] +unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) { + ((*tydesc).drop_glue)(0 as **TyDesc, data); +} + // Walk down a chunk, running the destructors for any objects stored // in it. unsafe fn destroy_chunk(chunk: &Chunk) { @@ -134,8 +147,7 @@ unsafe fn destroy_chunk(chunk: &Chunk) { //debug!("freeing object: idx = %u, size = %u, align = %u, done = %b", // start, size, align, is_done); if is_done { - ((*tydesc).drop_glue)(&tydesc as **TyDesc, - ptr::offset(buf, start) as *i8); + call_drop_glue(tydesc, ptr::offset(buf, start) as *i8); } // Find where the next tydesc lives diff --git a/src/librustc/back/abi.rs b/src/librustc/back/abi.rs index 8f15c74ed0e..05b6e90c682 100644 --- a/src/librustc/back/abi.rs +++ b/src/librustc/back/abi.rs @@ -8,9 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - pub static rc_base_field_refcnt: uint = 0u; pub static task_field_refcnt: uint = 0u; @@ -69,14 +66,4 @@ pub static vec_elt_elems: uint = 2u; pub static slice_elt_base: uint = 0u; pub static slice_elt_len: uint = 1u; -pub static worst_case_glue_call_args: uint = 7u; - pub static abi_version: uint = 1u; - -pub fn memcpy_glue_name() -> ~str { return ~"rust_memcpy_glue"; } - -pub fn bzero_glue_name() -> ~str { return ~"rust_bzero_glue"; } - -pub fn yield_glue_name() -> ~str { return ~"rust_yield_glue"; } - -pub fn no_op_type_glue_name() -> ~str { return ~"rust_no_op_type_glue"; } diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index f9bffb4a36e..75a1221cca5 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -232,7 +232,7 @@ pub fn lazily_emit_tydesc_glue(ccx: @mut CrateContext, field: uint, ti: @mut tydesc_info) { let _icx = push_ctxt("lazily_emit_tydesc_glue"); - let llfnty = type_of_glue_fn(ccx); + let llfnty = Type::glue_fn(); if lazily_emit_simplified_tydesc_glue(ccx, field, ti) { return; @@ -338,9 +338,7 @@ pub fn call_tydesc_glue_full(bcx: block, } }; - Call(bcx, llfn, [C_null(Type::nil().ptr_to()), - C_null(bcx.ccx().tydesc_type.ptr_to().ptr_to()), - llrawptr]); + Call(bcx, llfn, [C_null(Type::nil().ptr_to()), llrawptr]); } // See [Note-arg-mode] @@ -680,7 +678,7 @@ pub fn make_generic_glue_inner(ccx: @mut CrateContext, let bcx = top_scope_block(fcx, None); let lltop = bcx.llbb; - let rawptr0_arg = fcx.arg_pos(1u); + let rawptr0_arg = fcx.arg_pos(0u); let llrawptr0 = unsafe { llvm::LLVMGetParam(llfn, rawptr0_arg as c_uint) }; let llty = type_of(ccx, t); let llrawptr0 = PointerCast(bcx, llrawptr0, llty.ptr_to()); @@ -715,7 +713,7 @@ pub fn emit_tydescs(ccx: &mut CrateContext) { let _icx = push_ctxt("emit_tydescs"); // As of this point, allow no more tydescs to be created. ccx.finished_tydescs = true; - let glue_fn_ty = Type::generic_glue_fn(ccx); + let glue_fn_ty = Type::generic_glue_fn(ccx).ptr_to(); let tyds = &mut ccx.tydescs; for tyds.each_value |&val| { let ti = val; @@ -782,7 +780,3 @@ pub fn emit_tydescs(ccx: &mut CrateContext) { } }; } - -pub fn type_of_glue_fn(ccx: &CrateContext) -> Type { - Type::glue_fn(ccx.tydesc_type) -} diff --git a/src/librustc/middle/trans/type_.rs b/src/librustc/middle/trans/type_.rs index 7b02030078c..64688ac4134 100644 --- a/src/librustc/middle/trans/type_.rs +++ b/src/librustc/middle/trans/type_.rs @@ -20,7 +20,6 @@ use middle::trans::base; use syntax::ast; use syntax::abi::{Architecture, X86, X86_64, Arm, Mips}; -use back::abi; use core::vec; use core::cast; @@ -189,22 +188,20 @@ impl Type { None => () } - let ty = Type::glue_fn(cx.tydesc_type).ptr_to(); + let ty = Type::glue_fn(); cx.tn.associate_type("glue_fn", &ty); return ty; } - pub fn glue_fn(tydesc: Type) -> Type { - let tydescpp = tydesc.ptr_to().ptr_to(); - Type::func([ Type::nil().ptr_to(), tydescpp, Type::i8p() ], + pub fn glue_fn() -> Type { + Type::func([ Type::nil().ptr_to(), Type::i8p() ], &Type::void()) } pub fn tydesc(arch: Architecture) -> Type { let mut tydesc = Type::named_struct("tydesc"); - let pvoid = Type::i8p(); - let glue_fn_ty = Type::glue_fn(tydesc).ptr_to(); + let glue_fn_ty = Type::glue_fn().ptr_to(); let int_ty = Type::int(arch); diff --git a/src/libstd/cleanup.rs b/src/libstd/cleanup.rs index 557a2fbc4ae..ee9fdd3c620 100644 --- a/src/libstd/cleanup.rs +++ b/src/libstd/cleanup.rs @@ -11,9 +11,10 @@ #[doc(hidden)]; use libc::{c_char, intptr_t, uintptr_t}; -use ptr::{mut_null, to_unsafe_ptr}; +use ptr::{mut_null}; use repr::BoxRepr; use cast::transmute; +use unstable::intrinsics::TyDesc; #[cfg(not(test))] use unstable::lang::clear_task_borrow_list; /** @@ -158,6 +159,19 @@ fn debug_mem() -> bool { false } +#[inline] +#[cfg(not(stage0))] +unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) { + // This function should be inlined when stage0 is gone + ((*tydesc).drop_glue)(data); +} + +#[inline] +#[cfg(stage0)] +unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) { + ((*tydesc).drop_glue)(0 as **TyDesc, data); +} + /// Destroys all managed memory (i.e. @ boxes) held by the current task. #[cfg(not(test))] #[lang="annihilate"] @@ -201,7 +215,7 @@ pub unsafe fn annihilate() { if !uniq { let tydesc = (*box).header.type_desc; let data = transmute(&(*box).data); - ((*tydesc).drop_glue)(to_unsafe_ptr(&tydesc), data); + call_drop_glue(tydesc, data); } } diff --git a/src/libstd/gc.rs b/src/libstd/gc.rs index 2a211484e73..c9e33219fa5 100644 --- a/src/libstd/gc.rs +++ b/src/libstd/gc.rs @@ -316,6 +316,19 @@ fn expect_sentinel() -> bool { true } #[cfg(nogc)] fn expect_sentinel() -> bool { false } +#[inline] +#[cfg(not(stage0))] +unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) { + // This function should be inlined when stage0 is gone + ((*tydesc).drop_glue)(data); +} + +#[inline] +#[cfg(stage0)] +unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) { + ((*tydesc).drop_glue)(0 as **TyDesc, data); +} + // Entry point for GC-based cleanup. Walks stack looking for exchange // heap and stack allocations requiring drop, and runs all // destructors. @@ -359,7 +372,7 @@ pub fn cleanup_stack_for_failure() { // FIXME #4420: Destroy this box // FIXME #4330: Destroy this box } else { - ((*tydesc).drop_glue)(&tydesc as **TyDesc, *root as *i8); + call_drop_glue(tydesc, *root as *i8); } } } diff --git a/src/libstd/unstable/intrinsics.rs b/src/libstd/unstable/intrinsics.rs index 84bb2a952f2..bd34574c3b7 100644 --- a/src/libstd/unstable/intrinsics.rs +++ b/src/libstd/unstable/intrinsics.rs @@ -36,6 +36,10 @@ A quick refresher on memory ordering: #[cfg(test)] pub use realstd::unstable::intrinsics::{TyDesc, Opaque, TyVisitor}; +#[cfg(not(stage0))] +pub type GlueFn = extern "Rust" fn(*i8); + +#[cfg(stage0)] pub type GlueFn = extern "Rust" fn(**TyDesc, *i8); // NB: this has to be kept in sync with the Rust ABI. diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp index fe1b4622137..81ae991623f 100644 --- a/src/rt/rust_task.cpp +++ b/src/rt/rust_task.cpp @@ -183,7 +183,11 @@ void task_start_wrapper(spawn_args *a) if(env) { // free the environment (which should be a unique closure). const type_desc *td = env->td; - td->drop_glue(NULL, NULL, box_body(env)); + td->drop_glue(NULL, +#ifdef _RUST_STAGE0 + NULL, +#endif + box_body(env)); task->kernel->region()->free(env); } diff --git a/src/rt/rust_type.h b/src/rt/rust_type.h index 70b5c1dc6be..30ff5f1fa54 100644 --- a/src/rt/rust_type.h +++ b/src/rt/rust_type.h @@ -25,7 +25,11 @@ typedef void (*CDECL spawn_fn)(rust_opaque_box*, void *); struct type_desc; -typedef void CDECL (glue_fn)(void *, const type_desc **, void *); +typedef void CDECL (glue_fn)(void *, +#ifdef _RUST_STAGE0 + const type_desc **, +#endif + void *); // Corresponds to the boxed data in the @ region. The body follows the // header; you can obtain a ptr via box_body() below. -- cgit 1.4.1-3-g733a5 From 079b07df55636533db6d135f22cc235eb2e2b869 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 20 Jun 2013 13:44:42 +0200 Subject: libc: support functions from sys/mman.h Because its part of POSIX. Values are taken from FreeBSD, linux and OSX header files. --- src/libstd/libc.rs | 271 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 269 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/libc.rs b/src/libstd/libc.rs index 988fb5cc9b1..2aaeda69326 100644 --- a/src/libstd/libc.rs +++ b/src/libstd/libc.rs @@ -102,10 +102,12 @@ pub use libc::funcs::posix88::stdio::*; pub use libc::funcs::posix88::fcntl::*; pub use libc::funcs::posix88::dirent::*; pub use libc::funcs::posix88::unistd::*; +pub use libc::funcs::posix88::mman::*; pub use libc::funcs::posix01::stat_::*; pub use libc::funcs::posix01::unistd::*; pub use libc::funcs::posix01::glob::*; +pub use libc::funcs::posix01::mman::*; pub use libc::funcs::posix08::unistd::*; pub use libc::funcs::bsd44::*; @@ -1043,6 +1045,8 @@ pub mod consts { #[cfg(target_arch = "x86_64")] #[cfg(target_arch = "arm")] pub mod posix88 { + use libc::types::common::c95::c_void; + pub static O_RDONLY : int = 0; pub static O_WRONLY : int = 1; pub static O_RDWR : int = 2; @@ -1085,9 +1089,31 @@ pub mod consts { pub static SIGPIPE : int = 13; pub static SIGALRM : int = 14; pub static SIGTERM : int = 15; + + pub static PROT_NONE : int = 0; + pub static PROT_READ : int = 1; + pub static PROT_WRITE : int = 2; + pub static PROT_EXEC : int = 4; + + pub static MAP_FILE : int = 0x0000; + pub static MAP_SHARED : int = 0x0001; + pub static MAP_PRIVATE : int = 0x0002; + pub static MAP_FIXED : int = 0x0010; + pub static MAP_ANON : int = 0x1000; + + pub static MAP_FAILED : *c_void = -1 as *c_void; + + pub static MCL_CURRENT : int = 0x0001; + pub static MCL_FUTURE : int = 0x0002; + + pub static MS_ASYNC : int = 0x0001; + pub static MS_INVALIDATE : int = 0x0002; + pub static MS_SYNC : int = 0x0004; } #[cfg(target_arch = "mips")] pub mod posix88 { + use libc::types::common::c95::c_void; + pub static O_RDONLY : int = 0; pub static O_WRONLY : int = 1; pub static O_RDWR : int = 2; @@ -1130,6 +1156,26 @@ pub mod consts { pub static SIGPIPE : int = 13; pub static SIGALRM : int = 14; pub static SIGTERM : int = 15; + + pub static PROT_NONE : int = 0; + pub static PROT_READ : int = 1; + pub static PROT_WRITE : int = 2; + pub static PROT_EXEC : int = 4; + + pub static MAP_FILE : int = 0x0000; + pub static MAP_SHARED : int = 0x0001; + pub static MAP_PRIVATE : int = 0x0002; + pub static MAP_FIXED : int = 0x0010; + pub static MAP_ANON : int = 0x1000; + + pub static MAP_FAILED : *c_void = -1 as *c_void; + + pub static MCL_CURRENT : int = 0x0001; + pub static MCL_FUTURE : int = 0x0002; + + pub static MS_ASYNC : int = 0x0001; + pub static MS_INVALIDATE : int = 0x0002; + pub static MS_SYNC : int = 0x0004; } pub mod posix01 { pub static SIGTRAP : int = 5; @@ -1145,10 +1191,27 @@ pub mod consts { pub static GLOB_NOSPACE : int = 1; pub static GLOB_ABORTED : int = 2; pub static GLOB_NOMATCH : int = 3; + + pub static POSIX_MADV_NORMAL : int = 0; + pub static POSIX_MADV_RANDOM : int = 1; + pub static POSIX_MADV_SEQUENTIAL : int = 2; + pub static POSIX_MADV_WILLNEED : int = 3; + pub static POSIX_MADV_DONTNEED : int = 4; } pub mod posix08 { } pub mod bsd44 { + pub static MADV_NORMAL : int = 0; + pub static MADV_RANDOM : int = 1; + pub static MADV_SEQUENTIAL : int = 2; + pub static MADV_WILLNEED : int = 3; + pub static MADV_DONTNEED : int = 4; + pub static MADV_REMOVE : int = 9; + pub static MADV_DONTFORK : int = 10; + pub static MADV_DOFORK : int = 11; + pub static MADV_MERGEABLE : int = 12; + pub static MADV_UNMERGEABLE : int = 13; + pub static MADV_HWPOISON : int = 100; } #[cfg(target_arch = "x86")] #[cfg(target_arch = "x86_64")] @@ -1157,12 +1220,42 @@ pub mod consts { pub static O_RSYNC : int = 1052672; pub static O_DSYNC : int = 4096; pub static O_SYNC : int = 1052672; + + pub static PROT_GROWSDOWN : int = 0x010000000; + pub static PROT_GROWSUP : int = 0x020000000; + + pub static MAP_TYPE : int = 0x000f; + pub static MAP_ANONONYMOUS : int = 0x1000; + pub static MAP_32BIT : int = 0x0040; + pub static MAP_GROWSDOWN : int = 0x0100; + pub static MAP_DENYWRITE : int = 0x0800; + pub static MAP_EXECUTABLE : int = 0x01000; + pub static MAP_LOCKED : int = 0x02000; + pub static MAP_NONRESERVE : int = 0x04000; + pub static MAP_POPULATE : int = 0x08000; + pub static MAP_NONBLOCK : int = 0x010000; + pub static MAP_STACK : int = 0x020000; } #[cfg(target_arch = "mips")] pub mod extra { pub static O_RSYNC : int = 16400; pub static O_DSYNC : int = 16; pub static O_SYNC : int = 16400; + + pub static PROT_GROWSDOWN : int = 0x010000000; + pub static PROT_GROWSUP : int = 0x020000000; + + pub static MAP_TYPE : int = 0x000f; + pub static MAP_ANONONYMOUS : int = 0x1000; + pub static MAP_32BIT : int = 0x0040; + pub static MAP_GROWSDOWN : int = 0x0100; + pub static MAP_DENYWRITE : int = 0x0800; + pub static MAP_EXECUTABLE : int = 0x01000; + pub static MAP_LOCKED : int = 0x02000; + pub static MAP_NONRESERVE : int = 0x04000; + pub static MAP_POPULATE : int = 0x08000; + pub static MAP_NONBLOCK : int = 0x010000; + pub static MAP_STACK : int = 0x020000; } } @@ -1188,6 +1281,8 @@ pub mod consts { pub mod c99 { } pub mod posix88 { + use libc::types::common::c95::c_void; + pub static O_RDONLY : int = 0; pub static O_WRONLY : int = 1; pub static O_RDWR : int = 2; @@ -1230,6 +1325,26 @@ pub mod consts { pub static SIGPIPE : int = 13; pub static SIGALRM : int = 14; pub static SIGTERM : int = 15; + + pub static PROT_NONE : int = 0; + pub static PROT_READ : int = 1; + pub static PROT_WRITE : int = 2; + pub static PROT_EXEC : int = 4; + + pub static MAP_FILE : int = 0x0000; + pub static MAP_SHARED : int = 0x0001; + pub static MAP_PRIVATE : int = 0x0002; + pub static MAP_FIXED : int = 0x0010; + pub static MAP_ANON : int = 0x1000; + + pub static MAP_FAILED : *c_void = -1 as *c_void; + + pub static MCL_CURRENT : int = 0x0001; + pub static MCL_FUTURE : int = 0x0002; + + pub static MS_SYNC : int = 0x0000; + pub static MS_ASYNC : int = 0x0001; + pub static MS_INVALIDATE : int = 0x0002; } pub mod posix01 { pub static SIGTRAP : int = 5; @@ -1245,16 +1360,48 @@ pub mod consts { pub static GLOB_NOSPACE : int = -1; pub static GLOB_ABORTED : int = -2; pub static GLOB_NOMATCH : int = -3; + + pub static POSIX_MADV_NORMAL : int = 0; + pub static POSIX_MADV_RANDOM : int = 1; + pub static POSIX_MADV_SEQUENTIAL : int = 2; + pub static POSIX_MADV_WILLNEED : int = 3; + pub static POSIX_MADV_DONTNEED : int = 4; } pub mod posix08 { } pub mod bsd44 { + pub static MADV_NORMAL : int = 0; + pub static MADV_RANDOM : int = 1; + pub static MADV_SEQUENTIAL : int = 2; + pub static MADV_WILLNEED : int = 3; + pub static MADV_DONTNEED : int = 4; + pub static MADV_FREE : int = 5; + pub static MADV_NOSYNC : int = 6; + pub static MADV_AUTOSYNC : int = 7; + pub static MADV_NOCORE : int = 8; + pub static MADV_CORE : int = 9; + pub static MADV_PROTECT : int = 10; + + pub static MINCORE_INCORE : int = 0x1; + pub static MINCORE_REFERENCED : int = 0x2; + pub static MINCORE_MODIFIED : int = 0x4; + pub static MINCORE_REFERENCED_OTHER : int = 0x8; + pub static MINCORE_MODIFIED_OTHER : int = 0x10; + pub static MINCORE_SUPER : int = 0x20; } pub mod extra { pub static O_SYNC : int = 128; pub static CTL_KERN: int = 1; pub static KERN_PROC: int = 14; pub static KERN_PROC_PATHNAME: int = 12; + + pub static MAP_COPY : int = 0x0002; + pub static MAP_RENAME : int = 0x0020; + pub static MAP_NORESERVE : int = 0x0040; + pub static MAP_HASSEMAPHORE : int = 0x0200; + pub static MAP_STACK : int = 0x0400; + pub static MAP_NOSYNC : int = 0x0800; + pub static MAP_NOCORE : int = 0x020000; } } @@ -1280,6 +1427,8 @@ pub mod consts { pub mod c99 { } pub mod posix88 { + use libc::types::common::c95::c_void; + pub static O_RDONLY : int = 0; pub static O_WRONLY : int = 1; pub static O_RDWR : int = 2; @@ -1322,6 +1471,29 @@ pub mod consts { pub static SIGPIPE : int = 13; pub static SIGALRM : int = 14; pub static SIGTERM : int = 15; + + pub static PROT_NONE : int = 0; + pub static PROT_READ : int = 1; + pub static PROT_WRITE : int = 2; + pub static PROT_EXEC : int = 4; + + pub static MAP_FILE : int = 0x0000; + pub static MAP_SHARED : int = 0x0001; + pub static MAP_PRIVATE : int = 0x0002; + pub static MAP_FIXED : int = 0x0010; + pub static MAP_ANON : int = 0x1000; + + pub static MAP_FAILED : *c_void = -1 as *c_void; + + pub static MCL_CURRENT : int = 0x0001; + pub static MCL_FUTURE : int = 0x0002; + + pub static MS_ASYNC : int = 0x0001; + pub static MS_INVALIDATE : int = 0x0002; + pub static MS_SYNC : int = 0x0010; + + pub static MS_KILLPAGES : int = 0x0004; + pub static MS_DEACTIVATE : int = 0x0008; } pub mod posix01 { pub static SIGTRAP : int = 5; @@ -1337,15 +1509,45 @@ pub mod consts { pub static GLOB_NOSPACE : int = -1; pub static GLOB_ABORTED : int = -2; pub static GLOB_NOMATCH : int = -3; + + pub static POSIX_MADV_NORMAL : int = 0; + pub static POSIX_MADV_RANDOM : int = 1; + pub static POSIX_MADV_SEQUENTIAL : int = 2; + pub static POSIX_MADV_WILLNEED : int = 3; + pub static POSIX_MADV_DONTNEED : int = 4; } pub mod posix08 { } pub mod bsd44 { + pub static MADV_NORMAL : int = 0; + pub static MADV_RANDOM : int = 1; + pub static MADV_SEQUENTIAL : int = 2; + pub static MADV_WILLNEED : int = 3; + pub static MADV_DONTNEED : int = 4; + pub static MADV_FREE : int = 5; + pub static MADV_ZERO_WIRED_PAGES : int = 6; + pub static MADV_FREE_REUSABLE : int = 7; + pub static MADV_FREE_REUSE : int = 8; + pub static MADV_CAN_REUSE : int = 9; + + pub static MINCORE_INCORE : int = 0x1; + pub static MINCORE_REFERENCED : int = 0x2; + pub static MINCORE_MODIFIED : int = 0x4; + pub static MINCORE_REFERENCED_OTHER : int = 0x8; + pub static MINCORE_MODIFIED_OTHER : int = 0x10; } pub mod extra { pub static O_DSYNC : int = 4194304; pub static O_SYNC : int = 128; pub static F_FULLFSYNC : int = 51; + + pub static MAP_COPY : int = 0x0002; + pub static MAP_RENAME : int = 0x0020; + pub static MAP_NORESERVE : int = 0x0040; + pub static MAP_NOEXTEND : int = 0x0100; + pub static MAP_HASSEMAPHORE : int = 0x0200; + pub static MAP_NOCACHE : int = 0x0400; + pub static MAP_JIT : int = 0x0800; } } } @@ -1658,6 +1860,9 @@ pub mod funcs { -> c_int; } } + + pub mod mman { + } } @@ -1835,6 +2040,38 @@ pub mod funcs { unsafe fn kill(pid: pid_t, sig: c_int) -> c_int; } } + + #[nolink] + #[abi = "cdecl"] + pub mod mman { + use libc::types::common::c95::{c_void}; + use libc::types::os::arch::c95::{size_t, c_int, c_char}; + use libc::types::os::arch::posix88::{mode_t, off_t}; + + pub extern { + unsafe fn mlock(addr: *c_void, len: size_t) -> c_int; + unsafe fn munlock(addr: *c_void, len: size_t) -> c_int; + unsafe fn mlockall(flags: c_int) -> c_int; + unsafe fn munlockall() -> c_int; + + unsafe fn mmap(addr: *c_void, + len: size_t, + prot: c_int, + flags: c_int, + fd: c_int, + offset: off_t) -> *mut c_void; + unsafe fn munmap(addr: *c_void, len: size_t) -> c_int; + + unsafe fn mprotect(addr: *c_void, len: size_t, prot: c_int) + -> c_int; + + unsafe fn msync(addr: *c_void, len: size_t, flags: c_int) + -> c_int; + unsafe fn shm_open(name: *c_char, oflag: c_int, mode: mode_t) + -> c_int; + unsafe fn shm_unlink(name: *c_char) -> c_int; + } + } } #[cfg(target_os = "linux")] @@ -1913,6 +2150,19 @@ pub mod funcs { unsafe fn globfree(pglob: *mut glob_t); } } + + #[nolink] + #[abi = "cdecl"] + pub mod mman { + use libc::types::common::c95::{c_void}; + use libc::types::os::arch::c95::{c_int, size_t}; + + pub extern { + unsafe fn posix_madvise(addr: *c_void, + len: size_t, + advice: c_int) -> c_int; + } + } } #[cfg(target_os = "win32")] @@ -1925,6 +2175,9 @@ pub mod funcs { pub mod glob { } + + pub mod mman { + } } @@ -1943,7 +2196,8 @@ pub mod funcs { #[cfg(target_os = "freebsd")] pub mod bsd44 { use libc::types::common::c95::{c_void}; - use libc::types::os::arch::c95::{c_char, c_int, c_uint, size_t}; + use libc::types::os::arch::c95::{c_char, c_uchar, c_int, c_uint, + size_t}; #[abi = "cdecl"] pub extern { @@ -1959,6 +2213,12 @@ pub mod funcs { sizep: *mut size_t) -> c_int; unsafe fn getdtablesize() -> c_int; + + unsafe fn madvise(addr: *c_void, len: size_t, advice: c_int) + -> c_int; + + unsafe fn mincore(addr: *c_void, len: size_t, vec: *c_uchar) + -> c_int; } } @@ -1966,11 +2226,18 @@ pub mod funcs { #[cfg(target_os = "linux")] #[cfg(target_os = "android")] pub mod bsd44 { - use libc::types::os::arch::c95::{c_int}; + use libc::types::common::c95::{c_void}; + use libc::types::os::arch::c95::{c_uchar, c_int, size_t}; #[abi = "cdecl"] pub extern { unsafe fn getdtablesize() -> c_int; + + unsafe fn madvise(addr: *c_void, len: size_t, advice: c_int) + -> c_int; + + unsafe fn mincore(addr: *c_void, len: size_t, vec: *c_uchar) + -> c_int; } } -- cgit 1.4.1-3-g733a5 From ddd6f5928395c67b249ce3ec76a1ff4be303208d Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 20 Jun 2013 16:41:50 +0200 Subject: libc: add POSIX-compatible sysconf consts Because its part of POSIX. Values are taken from FreeBSD, linux and OSX header files. --- src/libstd/libc.rs | 254 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 254 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/libc.rs b/src/libstd/libc.rs index 2aaeda69326..9d6755fc22d 100644 --- a/src/libstd/libc.rs +++ b/src/libstd/libc.rs @@ -1176,6 +1176,63 @@ pub mod consts { pub static MS_ASYNC : int = 0x0001; pub static MS_INVALIDATE : int = 0x0002; pub static MS_SYNC : int = 0x0004; + + pub static _SC_ARG_MAX : int = 0; + pub static _SC_CHILD_MAX : int = 1; + pub static _SC_CLK_TCK : int = 2; + pub static _SC_NGROUPS_MAX : int = 3; + pub static _SC_OPEN_MAX : int = 4; + pub static _SC_STREAM_MAX : int = 5; + pub static _SC_TZNAME_MAX : int = 6; + pub static _SC_JOB_CONTROL : int = 7; + pub static _SC_SAVED_IDS : int = 8; + pub static _SC_REALTIME_SIGNALS : int = 9; + pub static _SC_PRIORITY_SCHEDULING : int = 10; + pub static _SC_TIMERS : int = 11; + pub static _SC_ASYNCHRONOUS_IO : int = 12; + pub static _SC_PRIORITIZED_IO : int = 13; + pub static _SC_SYNCHRONIZED_IO : int = 14; + pub static _SC_FSYNC : int = 15; + pub static _SC_MAPPED_FILES : int = 16; + pub static _SC_MEMLOCK : int = 17; + pub static _SC_MEMLOCK_RANGE : int = 18; + pub static _SC_MEMORY_PROTECTION : int = 19; + pub static _SC_MESSAGE_PASSING : int = 20; + pub static _SC_SEMAPHORES : int = 21; + pub static _SC_SHARED_MEMORY_OBJECTS : int = 22; + pub static _SC_AIO_LISTIO_MAX : int = 23; + pub static _SC_AIO_MAX : int = 24; + pub static _SC_AIO_PRIO_DELTA_MAX : int = 25; + pub static _SC_DELAYTIMER_MAX : int = 26; + pub static _SC_MQ_OPEN_MAX : int = 27; + pub static _SC_VERSION : int = 29; + pub static _SC_PAGESIZE : int = 30; + pub static _SC_RTSIG_MAX : int = 31; + pub static _SC_SEM_NSEMS_MAX : int = 32; + pub static _SC_SEM_VALUE_MAX : int = 33; + pub static _SC_SIGQUEUE_MAX : int = 34; + pub static _SC_TIMER_MAX : int = 35; + pub static _SC_BC_BASE_MAX : int = 36; + pub static _SC_BC_DIM_MAX : int = 37; + pub static _SC_BC_SCALE_MAX : int = 38; + pub static _SC_BC_STRING_MAX : int = 39; + pub static _SC_COLL_WEIGHTS_MAX : int = 40; + pub static _SC_EXPR_NEST_MAX : int = 42; + pub static _SC_LINE_MAX : int = 43; + pub static _SC_RE_DUP_MAX : int = 44; + pub static _SC_2_VERSION : int = 46; + pub static _SC_2_C_BIND : int = 47; + pub static _SC_2_C_DEV : int = 48; + pub static _SC_2_FORT_DEV : int = 49; + pub static _SC_2_FORT_RUN : int = 50; + pub static _SC_2_SW_DEV : int = 51; + pub static _SC_2_LOCALEDEF : int = 52; + pub static _SC_2_CHAR_TERM : int = 95; + pub static _SC_2_C_VERSION : int = 96; + pub static _SC_2_UPE : int = 97; + pub static _SC_XBS5_ILP32_OFF32 : int = 125; + pub static _SC_XBS5_ILP32_OFFBIG : int = 126; + pub static _SC_XBS5_LPBIG_OFFBIG : int = 128; } pub mod posix01 { pub static SIGTRAP : int = 5; @@ -1197,6 +1254,35 @@ pub mod consts { pub static POSIX_MADV_SEQUENTIAL : int = 2; pub static POSIX_MADV_WILLNEED : int = 3; pub static POSIX_MADV_DONTNEED : int = 4; + + pub static _SC_MQ_PRIO_MAX : int = 28; + pub static _SC_IOV_MAX : int = 60; + pub static _SC_GETGR_R_SIZE_MAX : int = 69; + pub static _SC_GETPW_R_SIZE_MAX : int = 70; + pub static _SC_LOGIN_NAME_MAX : int = 71; + pub static _SC_TTY_NAME_MAX : int = 72; + pub static _SC_THREADS : int = 67; + pub static _SC_THREAD_SAFE_FUNCTIONS : int = 68; + pub static _SC_THREAD_DESTRUCTOR_ITERATIONS : int = 73; + pub static _SC_THREAD_KEYS_MAX : int = 74; + pub static _SC_THREAD_STACK_MIN : int = 75; + pub static _SC_THREAD_THREADS_MAX : int = 76; + pub static _SC_THREAD_ATTR_STACKADDR : int = 77; + pub static _SC_THREAD_ATTR_STACKSIZE : int = 78; + pub static _SC_THREAD_PRIORITY_SCHEDULING : int = 79; + pub static _SC_THREAD_PRIO_INHERIT : int = 80; + pub static _SC_THREAD_PRIO_PROTECT : int = 81; + pub static _SC_THREAD_PROCESS_SHARED : int = 82; + pub static _SC_ATEXIT_MAX : int = 87; + pub static _SC_XOPEN_VERSION : int = 89; + pub static _SC_XOPEN_XCU_VERSION : int = 90; + pub static _SC_XOPEN_UNIX : int = 91; + pub static _SC_XOPEN_CRYPT : int = 92; + pub static _SC_XOPEN_ENH_I18N : int = 93; + pub static _SC_XOPEN_SHM : int = 94; + pub static _SC_XOPEN_LEGACY : int = 129; + pub static _SC_XOPEN_REALTIME : int = 130; + pub static _SC_XOPEN_REALTIME_THREADS : int = 131; } pub mod posix08 { } @@ -1345,6 +1431,59 @@ pub mod consts { pub static MS_SYNC : int = 0x0000; pub static MS_ASYNC : int = 0x0001; pub static MS_INVALIDATE : int = 0x0002; + + pub static _SC_ARG_MAX : int = 1; + pub static _SC_CHILD_MAX : int = 2; + pub static _SC_CLK_TCK : int = 3; + pub static _SC_NGROUPS_MAX : int = 4; + pub static _SC_OPEN_MAX : int = 5; + pub static _SC_JOB_CONTROL : int = 6; + pub static _SC_SAVED_IDS : int = 7; + pub static _SC_VERSION : int = 8; + pub static _SC_BC_BASE_MAX : int = 9; + pub static _SC_BC_DIM_MAX : int = 10; + pub static _SC_BC_SCALE_MAX : int = 11; + pub static _SC_BC_STRING_MAX : int = 12; + pub static _SC_COLL_WEIGHTS_MAX : int = 13; + pub static _SC_EXPR_NEST_MAX : int = 14; + pub static _SC_LINE_MAX : int = 15; + pub static _SC_RE_DUP_MAX : int = 16; + pub static _SC_2_VERSION : int = 17; + pub static _SC_2_C_BIND : int = 18; + pub static _SC_2_C_DEV : int = 19; + pub static _SC_2_CHAR_TERM : int = 20; + pub static _SC_2_FORT_DEV : int = 21; + pub static _SC_2_FORT_RUN : int = 22; + pub static _SC_2_LOCALEDEF : int = 23; + pub static _SC_2_SW_DEV : int = 24; + pub static _SC_2_UPE : int = 25; + pub static _SC_STREAM_MAX : int = 26; + pub static _SC_TZNAME_MAX : int = 27; + pub static _SC_ASYNCHRONOUS_IO : int = 28; + pub static _SC_MAPPED_FILES : int = 29; + pub static _SC_MEMLOCK : int = 30; + pub static _SC_MEMLOCK_RANGE : int = 31; + pub static _SC_MEMORY_PROTECTION : int = 32; + pub static _SC_MESSAGE_PASSING : int = 33; + pub static _SC_PRIORITIZED_IO : int = 34; + pub static _SC_PRIORITY_SCHEDULING : int = 35; + pub static _SC_REALTIME_SIGNALS : int = 36; + pub static _SC_SEMAPHORES : int = 37; + pub static _SC_FSYNC : int = 38; + pub static _SC_SHARED_MEMORY_OBJECTS : int = 39; + pub static _SC_SYNCHRONIZED_IO : int = 40; + pub static _SC_TIMERS : int = 41; + pub static _SC_AIO_LISTIO_MAX : int = 42; + pub static _SC_AIO_MAX : int = 43; + pub static _SC_AIO_PRIO_DELTA_MAX : int = 44; + pub static _SC_DELAYTIMER_MAX : int = 45; + pub static _SC_MQ_OPEN_MAX : int = 46; + pub static _SC_PAGESIZE : int = 47; + pub static _SC_RTSIG_MAX : int = 48; + pub static _SC_SEM_NSEMS_MAX : int = 49; + pub static _SC_SEM_VALUE_MAX : int = 50; + pub static _SC_SIGQUEUE_MAX : int = 51; + pub static _SC_TIMER_MAX : int = 52; } pub mod posix01 { pub static SIGTRAP : int = 5; @@ -1366,6 +1505,35 @@ pub mod consts { pub static POSIX_MADV_SEQUENTIAL : int = 2; pub static POSIX_MADV_WILLNEED : int = 3; pub static POSIX_MADV_DONTNEED : int = 4; + + pub static _SC_IOV_MAX : int = 56; + pub static _SC_GETGR_R_SIZE_MAX : int = 70; + pub static _SC_GETPW_R_SIZE_MAX : int = 71; + pub static _SC_LOGIN_NAME_MAX : int = 73; + pub static _SC_MQ_PRIO_MAX : int = 75; + pub static _SC_THREAD_ATTR_STACKADDR : int = 82; + pub static _SC_THREAD_ATTR_STACKSIZE : int = 83; + pub static _SC_THREAD_DESTRUCTOR_ITERATIONS : int = 85; + pub static _SC_THREAD_KEYS_MAX : int = 86; + pub static _SC_THREAD_PRIO_INHERIT : int = 87; + pub static _SC_THREAD_PRIO_PROTECT : int = 88; + pub static _SC_THREAD_PRIORITY_SCHEDULING : int = 89; + pub static _SC_THREAD_PROCESS_SHARED : int = 90; + pub static _SC_THREAD_SAFE_FUNCTIONS : int = 91; + pub static _SC_THREAD_STACK_MIN : int = 93; + pub static _SC_THREAD_THREADS_MAX : int = 94; + pub static _SC_THREADS : int = 96; + pub static _SC_TTY_NAME_MAX : int = 101; + pub static _SC_ATEXIT_MAX : int = 107; + pub static _SC_XOPEN_CRYPT : int = 108; + pub static _SC_XOPEN_ENH_I18N : int = 109; + pub static _SC_XOPEN_LEGACY : int = 110; + pub static _SC_XOPEN_REALTIME : int = 111; + pub static _SC_XOPEN_REALTIME_THREADS : int = 112; + pub static _SC_XOPEN_SHM : int = 113; + pub static _SC_XOPEN_UNIX : int = 115; + pub static _SC_XOPEN_VERSION : int = 116; + pub static _SC_XOPEN_XCU_VERSION : int = 117; } pub mod posix08 { } @@ -1494,6 +1662,63 @@ pub mod consts { pub static MS_KILLPAGES : int = 0x0004; pub static MS_DEACTIVATE : int = 0x0008; + + pub static _SC_ARG_MAX : int = 1; + pub static _SC_CHILD_MAX : int = 2; + pub static _SC_CLK_TCK : int = 3; + pub static _SC_NGROUPS_MAX : int = 4; + pub static _SC_OPEN_MAX : int = 5; + pub static _SC_JOB_CONTROL : int = 6; + pub static _SC_SAVED_IDS : int = 7; + pub static _SC_VERSION : int = 8; + pub static _SC_BC_BASE_MAX : int = 9; + pub static _SC_BC_DIM_MAX : int = 10; + pub static _SC_BC_SCALE_MAX : int = 11; + pub static _SC_BC_STRING_MAX : int = 12; + pub static _SC_COLL_WEIGHTS_MAX : int = 13; + pub static _SC_EXPR_NEST_MAX : int = 14; + pub static _SC_LINE_MAX : int = 15; + pub static _SC_RE_DUP_MAX : int = 16; + pub static _SC_2_VERSION : int = 17; + pub static _SC_2_C_BIND : int = 18; + pub static _SC_2_C_DEV : int = 19; + pub static _SC_2_CHAR_TERM : int = 20; + pub static _SC_2_FORT_DEV : int = 21; + pub static _SC_2_FORT_RUN : int = 22; + pub static _SC_2_LOCALEDEF : int = 23; + pub static _SC_2_SW_DEV : int = 24; + pub static _SC_2_UPE : int = 25; + pub static _SC_STREAM_MAX : int = 26; + pub static _SC_TZNAME_MAX : int = 27; + pub static _SC_ASYNCHRONOUS_IO : int = 28; + pub static _SC_PAGESIZE : int = 29; + pub static _SC_MEMLOCK : int = 30; + pub static _SC_MEMLOCK_RANGE : int = 31; + pub static _SC_MEMORY_PROTECTION : int = 32; + pub static _SC_MESSAGE_PASSING : int = 33; + pub static _SC_PRIORITIZED_IO : int = 34; + pub static _SC_PRIORITY_SCHEDULING : int = 35; + pub static _SC_REALTIME_SIGNALS : int = 36; + pub static _SC_SEMAPHORES : int = 37; + pub static _SC_FSYNC : int = 38; + pub static _SC_SHARED_MEMORY_OBJECTS : int = 39; + pub static _SC_SYNCHRONIZED_IO : int = 40; + pub static _SC_TIMERS : int = 41; + pub static _SC_AIO_LISTIO_MAX : int = 42; + pub static _SC_AIO_MAX : int = 43; + pub static _SC_AIO_PRIO_DELTA_MAX : int = 44; + pub static _SC_DELAYTIMER_MAX : int = 45; + pub static _SC_MQ_OPEN_MAX : int = 46; + pub static _SC_MAPPED_FILES : int = 47; + pub static _SC_RTSIG_MAX : int = 48; + pub static _SC_SEM_NSEMS_MAX : int = 49; + pub static _SC_SEM_VALUE_MAX : int = 50; + pub static _SC_SIGQUEUE_MAX : int = 51; + pub static _SC_TIMER_MAX : int = 52; + pub static _SC_XBS5_ILP32_OFF32 : int = 122; + pub static _SC_XBS5_ILP32_OFFBIG : int = 123; + pub static _SC_XBS5_LP64_OFF64 : int = 124; + pub static _SC_XBS5_LPBIG_OFFBIG : int = 125; } pub mod posix01 { pub static SIGTRAP : int = 5; @@ -1515,6 +1740,35 @@ pub mod consts { pub static POSIX_MADV_SEQUENTIAL : int = 2; pub static POSIX_MADV_WILLNEED : int = 3; pub static POSIX_MADV_DONTNEED : int = 4; + + pub static _SC_IOV_MAX : int = 56; + pub static _SC_GETGR_R_SIZE_MAX : int = 70; + pub static _SC_GETPW_R_SIZE_MAX : int = 71; + pub static _SC_LOGIN_NAME_MAX : int = 73; + pub static _SC_MQ_PRIO_MAX : int = 75; + pub static _SC_THREAD_ATTR_STACKADDR : int = 82; + pub static _SC_THREAD_ATTR_STACKSIZE : int = 83; + pub static _SC_THREAD_DESTRUCTOR_ITERATIONS : int = 85; + pub static _SC_THREAD_KEYS_MAX : int = 86; + pub static _SC_THREAD_PRIO_INHERIT : int = 87; + pub static _SC_THREAD_PRIO_PROTECT : int = 88; + pub static _SC_THREAD_PRIORITY_SCHEDULING : int = 89; + pub static _SC_THREAD_PROCESS_SHARED : int = 90; + pub static _SC_THREAD_SAFE_FUNCTIONS : int = 91; + pub static _SC_THREAD_STACK_MIN : int = 93; + pub static _SC_THREAD_THREADS_MAX : int = 94; + pub static _SC_THREADS : int = 96; + pub static _SC_TTY_NAME_MAX : int = 101; + pub static _SC_ATEXIT_MAX : int = 107; + pub static _SC_XOPEN_CRYPT : int = 108; + pub static _SC_XOPEN_ENH_I18N : int = 109; + pub static _SC_XOPEN_LEGACY : int = 110; + pub static _SC_XOPEN_REALTIME : int = 111; + pub static _SC_XOPEN_REALTIME_THREADS : int = 112; + pub static _SC_XOPEN_SHM : int = 113; + pub static _SC_XOPEN_UNIX : int = 115; + pub static _SC_XOPEN_VERSION : int = 116; + pub static _SC_XOPEN_XCU_VERSION : int = 121; } pub mod posix08 { } -- cgit 1.4.1-3-g733a5 From bc70edbb25487e539386c68bd6e821eedd704194 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Fri, 21 Jun 2013 16:39:37 +0200 Subject: libc: (u)int => c_(u)int for consts --- src/libstd/libc.rs | 1533 +++++++++++++++++++++++++++------------------------- src/libstd/os.rs | 2 +- 2 files changed, 785 insertions(+), 750 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/libc.rs b/src/libstd/libc.rs index 9d6755fc22d..523645e69a5 100644 --- a/src/libstd/libc.rs +++ b/src/libstd/libc.rs @@ -287,7 +287,7 @@ pub mod types { #[cfg(target_arch = "x86")] #[cfg(target_arch = "mips")] pub mod posix01 { - use libc::types::os::arch::c95::{c_short, c_long, c_ulong, time_t}; + use libc::types::os::arch::c95::{c_short, c_long, time_t}; use libc::types::os::arch::posix88::{dev_t, gid_t, ino_t}; use libc::types::os::arch::posix88::{mode_t, off_t}; use libc::types::os::arch::posix88::{uid_t}; @@ -905,52 +905,56 @@ pub mod consts { #[cfg(target_os = "win32")] pub mod os { pub mod c95 { - pub static EXIT_FAILURE : int = 1; - pub static EXIT_SUCCESS : int = 0; - pub static RAND_MAX : int = 32767; - pub static EOF : int = -1; - pub static SEEK_SET : int = 0; - pub static SEEK_CUR : int = 1; - pub static SEEK_END : int = 2; - pub static _IOFBF : int = 0; - pub static _IONBF : int = 4; - pub static _IOLBF : int = 64; - pub static BUFSIZ : uint = 512_u; - pub static FOPEN_MAX : uint = 20_u; - pub static FILENAME_MAX : uint = 260_u; - pub static L_tmpnam : uint = 16_u; - pub static TMP_MAX : uint = 32767_u; + use libc::types::os::arch::c95::{c_int, c_uint}; + + pub static EXIT_FAILURE : c_int = 1; + pub static EXIT_SUCCESS : c_int = 0; + pub static RAND_MAX : c_int = 32767; + pub static EOF : c_int = -1; + pub static SEEK_SET : c_int = 0; + pub static SEEK_CUR : c_int = 1; + pub static SEEK_END : c_int = 2; + pub static _IOFBF : c_int = 0; + pub static _IONBF : c_int = 4; + pub static _IOLBF : c_int = 64; + pub static BUFSIZ : c_uint = 512_u32; + pub static FOPEN_MAX : c_uint = 20_u32; + pub static FILENAME_MAX : c_uint = 260_u32; + pub static L_tmpnam : c_uint = 16_u32; + pub static TMP_MAX : c_uint = 32767_u32; } pub mod c99 { } pub mod posix88 { - pub static O_RDONLY : int = 0; - pub static O_WRONLY : int = 1; - pub static O_RDWR : int = 2; - pub static O_APPEND : int = 8; - pub static O_CREAT : int = 256; - pub static O_EXCL : int = 1024; - pub static O_TRUNC : int = 512; - pub static S_IFIFO : int = 4096; - pub static S_IFCHR : int = 8192; - pub static S_IFBLK : int = 12288; - pub static S_IFDIR : int = 16384; - pub static S_IFREG : int = 32768; - pub static S_IFMT : int = 61440; - pub static S_IEXEC : int = 64; - pub static S_IWRITE : int = 128; - pub static S_IREAD : int = 256; - pub static S_IRWXU : int = 448; - pub static S_IXUSR : int = 64; - pub static S_IWUSR : int = 128; - pub static S_IRUSR : int = 256; - pub static F_OK : int = 0; - pub static R_OK : int = 4; - pub static W_OK : int = 2; - pub static X_OK : int = 1; - pub static STDIN_FILENO : int = 0; - pub static STDOUT_FILENO : int = 1; - pub static STDERR_FILENO : int = 2; + use libc::types::os::arch::c95::c_int; + + pub static O_RDONLY : c_int = 0; + pub static O_WRONLY : c_int = 1; + pub static O_RDWR : c_int = 2; + pub static O_APPEND : c_int = 8; + pub static O_CREAT : c_int = 256; + pub static O_EXCL : c_int = 1024; + pub static O_TRUNC : c_int = 512; + pub static S_IFIFO : c_int = 4096; + pub static S_IFCHR : c_int = 8192; + pub static S_IFBLK : c_int = 12288; + pub static S_IFDIR : c_int = 16384; + pub static S_IFREG : c_int = 32768; + pub static S_IFMT : c_int = 61440; + pub static S_IEXEC : c_int = 64; + pub static S_IWRITE : c_int = 128; + pub static S_IREAD : c_int = 256; + pub static S_IRWXU : c_int = 448; + pub static S_IXUSR : c_int = 64; + pub static S_IWUSR : c_int = 128; + pub static S_IRUSR : c_int = 256; + pub static F_OK : c_int = 0; + pub static R_OK : c_int = 4; + pub static W_OK : c_int = 2; + pub static X_OK : c_int = 1; + pub static STDIN_FILENO : c_int = 0; + pub static STDOUT_FILENO : c_int = 1; + pub static STDERR_FILENO : c_int = 2; } pub mod posix01 { } @@ -959,18 +963,19 @@ pub mod consts { pub mod bsd44 { } pub mod extra { + use libc::types::os::arch::c95::c_int; use libc::types::os::arch::extra::{DWORD, BOOL}; pub static TRUE : BOOL = 1; pub static FALSE : BOOL = 0; - pub static O_TEXT : int = 16384; - pub static O_BINARY : int = 32768; - pub static O_NOINHERIT: int = 128; + pub static O_TEXT : c_int = 16384; + pub static O_BINARY : c_int = 32768; + pub static O_NOINHERIT: c_int = 128; - pub static ERROR_SUCCESS : int = 0; - pub static ERROR_INSUFFICIENT_BUFFER : int = 122; - pub static INVALID_HANDLE_VALUE: int = -1; + pub static ERROR_SUCCESS : c_int = 0; + pub static ERROR_INSUFFICIENT_BUFFER : c_int = 122; + pub static INVALID_HANDLE_VALUE: c_int = -1; pub static DELETE : DWORD = 0x00010000; pub static READ_CONTROL : DWORD = 0x00020000; @@ -1023,21 +1028,23 @@ pub mod consts { #[cfg(target_os = "android")] pub mod os { pub mod c95 { - pub static EXIT_FAILURE : int = 1; - pub static EXIT_SUCCESS : int = 0; - pub static RAND_MAX : int = 2147483647; - pub static EOF : int = -1; - pub static SEEK_SET : int = 0; - pub static SEEK_CUR : int = 1; - pub static SEEK_END : int = 2; - pub static _IOFBF : int = 0; - pub static _IONBF : int = 2; - pub static _IOLBF : int = 1; - pub static BUFSIZ : uint = 8192_u; - pub static FOPEN_MAX : uint = 16_u; - pub static FILENAME_MAX : uint = 4096_u; - pub static L_tmpnam : uint = 20_u; - pub static TMP_MAX : uint = 238328_u; + use libc::types::os::arch::c95::{c_int, c_uint}; + + pub static EXIT_FAILURE : c_int = 1; + pub static EXIT_SUCCESS : c_int = 0; + pub static RAND_MAX : c_int = 2147483647; + pub static EOF : c_int = -1; + pub static SEEK_SET : c_int = 0; + pub static SEEK_CUR : c_int = 1; + pub static SEEK_END : c_int = 2; + pub static _IOFBF : c_int = 0; + pub static _IONBF : c_int = 2; + pub static _IOLBF : c_int = 1; + pub static BUFSIZ : c_uint = 8192_u32; + pub static FOPEN_MAX : c_uint = 16_u32; + pub static FILENAME_MAX : c_uint = 4096_u32; + pub static L_tmpnam : c_uint = 20_u32; + pub static TMP_MAX : c_uint = 238328_u32; } pub mod c99 { } @@ -1045,763 +1052,791 @@ pub mod consts { #[cfg(target_arch = "x86_64")] #[cfg(target_arch = "arm")] pub mod posix88 { + use libc::types::os::arch::c95::c_int; use libc::types::common::c95::c_void; - pub static O_RDONLY : int = 0; - pub static O_WRONLY : int = 1; - pub static O_RDWR : int = 2; - pub static O_APPEND : int = 1024; - pub static O_CREAT : int = 64; - pub static O_EXCL : int = 128; - pub static O_TRUNC : int = 512; - pub static S_IFIFO : int = 4096; - pub static S_IFCHR : int = 8192; - pub static S_IFBLK : int = 24576; - pub static S_IFDIR : int = 16384; - pub static S_IFREG : int = 32768; - pub static S_IFMT : int = 61440; - pub static S_IEXEC : int = 64; - pub static S_IWRITE : int = 128; - pub static S_IREAD : int = 256; - pub static S_IRWXU : int = 448; - pub static S_IXUSR : int = 64; - pub static S_IWUSR : int = 128; - pub static S_IRUSR : int = 256; - pub static F_OK : int = 0; - pub static R_OK : int = 4; - pub static W_OK : int = 2; - pub static X_OK : int = 1; - pub static STDIN_FILENO : int = 0; - pub static STDOUT_FILENO : int = 1; - pub static STDERR_FILENO : int = 2; - pub static F_LOCK : int = 1; - pub static F_TEST : int = 3; - pub static F_TLOCK : int = 2; - pub static F_ULOCK : int = 0; - pub static SIGHUP : int = 1; - pub static SIGINT : int = 2; - pub static SIGQUIT : int = 3; - pub static SIGILL : int = 4; - pub static SIGABRT : int = 6; - pub static SIGFPE : int = 8; - pub static SIGKILL : int = 9; - pub static SIGSEGV : int = 11; - pub static SIGPIPE : int = 13; - pub static SIGALRM : int = 14; - pub static SIGTERM : int = 15; - - pub static PROT_NONE : int = 0; - pub static PROT_READ : int = 1; - pub static PROT_WRITE : int = 2; - pub static PROT_EXEC : int = 4; - - pub static MAP_FILE : int = 0x0000; - pub static MAP_SHARED : int = 0x0001; - pub static MAP_PRIVATE : int = 0x0002; - pub static MAP_FIXED : int = 0x0010; - pub static MAP_ANON : int = 0x1000; + pub static O_RDONLY : c_int = 0; + pub static O_WRONLY : c_int = 1; + pub static O_RDWR : c_int = 2; + pub static O_APPEND : c_int = 1024; + pub static O_CREAT : c_int = 64; + pub static O_EXCL : c_int = 128; + pub static O_TRUNC : c_int = 512; + pub static S_IFIFO : c_int = 4096; + pub static S_IFCHR : c_int = 8192; + pub static S_IFBLK : c_int = 24576; + pub static S_IFDIR : c_int = 16384; + pub static S_IFREG : c_int = 32768; + pub static S_IFMT : c_int = 61440; + pub static S_IEXEC : c_int = 64; + pub static S_IWRITE : c_int = 128; + pub static S_IREAD : c_int = 256; + pub static S_IRWXU : c_int = 448; + pub static S_IXUSR : c_int = 64; + pub static S_IWUSR : c_int = 128; + pub static S_IRUSR : c_int = 256; + pub static F_OK : c_int = 0; + pub static R_OK : c_int = 4; + pub static W_OK : c_int = 2; + pub static X_OK : c_int = 1; + pub static STDIN_FILENO : c_int = 0; + pub static STDOUT_FILENO : c_int = 1; + pub static STDERR_FILENO : c_int = 2; + pub static F_LOCK : c_int = 1; + pub static F_TEST : c_int = 3; + pub static F_TLOCK : c_int = 2; + pub static F_ULOCK : c_int = 0; + pub static SIGHUP : c_int = 1; + pub static SIGINT : c_int = 2; + pub static SIGQUIT : c_int = 3; + pub static SIGILL : c_int = 4; + pub static SIGABRT : c_int = 6; + pub static SIGFPE : c_int = 8; + pub static SIGKILL : c_int = 9; + pub static SIGSEGV : c_int = 11; + pub static SIGPIPE : c_int = 13; + pub static SIGALRM : c_int = 14; + pub static SIGTERM : c_int = 15; + + pub static PROT_NONE : c_int = 0; + pub static PROT_READ : c_int = 1; + pub static PROT_WRITE : c_int = 2; + pub static PROT_EXEC : c_int = 4; + + pub static MAP_FILE : c_int = 0x0000; + pub static MAP_SHARED : c_int = 0x0001; + pub static MAP_PRIVATE : c_int = 0x0002; + pub static MAP_FIXED : c_int = 0x0010; + pub static MAP_ANON : c_int = 0x1000; pub static MAP_FAILED : *c_void = -1 as *c_void; - pub static MCL_CURRENT : int = 0x0001; - pub static MCL_FUTURE : int = 0x0002; + pub static MCL_CURRENT : c_int = 0x0001; + pub static MCL_FUTURE : c_int = 0x0002; - pub static MS_ASYNC : int = 0x0001; - pub static MS_INVALIDATE : int = 0x0002; - pub static MS_SYNC : int = 0x0004; + pub static MS_ASYNC : c_int = 0x0001; + pub static MS_INVALIDATE : c_int = 0x0002; + pub static MS_SYNC : c_int = 0x0004; } #[cfg(target_arch = "mips")] pub mod posix88 { + use libc::types::os::arch::c95::c_int; use libc::types::common::c95::c_void; - pub static O_RDONLY : int = 0; - pub static O_WRONLY : int = 1; - pub static O_RDWR : int = 2; - pub static O_APPEND : int = 8; - pub static O_CREAT : int = 256; - pub static O_EXCL : int = 1024; - pub static O_TRUNC : int = 512; - pub static S_IFIFO : int = 4096; - pub static S_IFCHR : int = 8192; - pub static S_IFBLK : int = 24576; - pub static S_IFDIR : int = 16384; - pub static S_IFREG : int = 32768; - pub static S_IFMT : int = 61440; - pub static S_IEXEC : int = 64; - pub static S_IWRITE : int = 128; - pub static S_IREAD : int = 256; - pub static S_IRWXU : int = 448; - pub static S_IXUSR : int = 64; - pub static S_IWUSR : int = 128; - pub static S_IRUSR : int = 256; - pub static F_OK : int = 0; - pub static R_OK : int = 4; - pub static W_OK : int = 2; - pub static X_OK : int = 1; - pub static STDIN_FILENO : int = 0; - pub static STDOUT_FILENO : int = 1; - pub static STDERR_FILENO : int = 2; - pub static F_LOCK : int = 1; - pub static F_TEST : int = 3; - pub static F_TLOCK : int = 2; - pub static F_ULOCK : int = 0; - pub static SIGHUP : int = 1; - pub static SIGINT : int = 2; - pub static SIGQUIT : int = 3; - pub static SIGILL : int = 4; - pub static SIGABRT : int = 6; - pub static SIGFPE : int = 8; - pub static SIGKILL : int = 9; - pub static SIGSEGV : int = 11; - pub static SIGPIPE : int = 13; - pub static SIGALRM : int = 14; - pub static SIGTERM : int = 15; - - pub static PROT_NONE : int = 0; - pub static PROT_READ : int = 1; - pub static PROT_WRITE : int = 2; - pub static PROT_EXEC : int = 4; - - pub static MAP_FILE : int = 0x0000; - pub static MAP_SHARED : int = 0x0001; - pub static MAP_PRIVATE : int = 0x0002; - pub static MAP_FIXED : int = 0x0010; - pub static MAP_ANON : int = 0x1000; + pub static O_RDONLY : c_int = 0; + pub static O_WRONLY : c_int = 1; + pub static O_RDWR : c_int = 2; + pub static O_APPEND : c_int = 8; + pub static O_CREAT : c_int = 256; + pub static O_EXCL : c_int = 1024; + pub static O_TRUNC : c_int = 512; + pub static S_IFIFO : c_int = 4096; + pub static S_IFCHR : c_int = 8192; + pub static S_IFBLK : c_int = 24576; + pub static S_IFDIR : c_int = 16384; + pub static S_IFREG : c_int = 32768; + pub static S_IFMT : c_int = 61440; + pub static S_IEXEC : c_int = 64; + pub static S_IWRITE : c_int = 128; + pub static S_IREAD : c_int = 256; + pub static S_IRWXU : c_int = 448; + pub static S_IXUSR : c_int = 64; + pub static S_IWUSR : c_int = 128; + pub static S_IRUSR : c_int = 256; + pub static F_OK : c_int = 0; + pub static R_OK : c_int = 4; + pub static W_OK : c_int = 2; + pub static X_OK : c_int = 1; + pub static STDIN_FILENO : c_int = 0; + pub static STDOUT_FILENO : c_int = 1; + pub static STDERR_FILENO : c_int = 2; + pub static F_LOCK : c_int = 1; + pub static F_TEST : c_int = 3; + pub static F_TLOCK : c_int = 2; + pub static F_ULOCK : c_int = 0; + pub static SIGHUP : c_int = 1; + pub static SIGINT : c_int = 2; + pub static SIGQUIT : c_int = 3; + pub static SIGILL : c_int = 4; + pub static SIGABRT : c_int = 6; + pub static SIGFPE : c_int = 8; + pub static SIGKILL : c_int = 9; + pub static SIGSEGV : c_int = 11; + pub static SIGPIPE : c_int = 13; + pub static SIGALRM : c_int = 14; + pub static SIGTERM : c_int = 15; + + pub static PROT_NONE : c_int = 0; + pub static PROT_READ : c_int = 1; + pub static PROT_WRITE : c_int = 2; + pub static PROT_EXEC : c_int = 4; + + pub static MAP_FILE : c_int = 0x0000; + pub static MAP_SHARED : c_int = 0x0001; + pub static MAP_PRIVATE : c_int = 0x0002; + pub static MAP_FIXED : c_int = 0x0010; + pub static MAP_ANON : c_int = 0x1000; pub static MAP_FAILED : *c_void = -1 as *c_void; - pub static MCL_CURRENT : int = 0x0001; - pub static MCL_FUTURE : int = 0x0002; - - pub static MS_ASYNC : int = 0x0001; - pub static MS_INVALIDATE : int = 0x0002; - pub static MS_SYNC : int = 0x0004; - - pub static _SC_ARG_MAX : int = 0; - pub static _SC_CHILD_MAX : int = 1; - pub static _SC_CLK_TCK : int = 2; - pub static _SC_NGROUPS_MAX : int = 3; - pub static _SC_OPEN_MAX : int = 4; - pub static _SC_STREAM_MAX : int = 5; - pub static _SC_TZNAME_MAX : int = 6; - pub static _SC_JOB_CONTROL : int = 7; - pub static _SC_SAVED_IDS : int = 8; - pub static _SC_REALTIME_SIGNALS : int = 9; - pub static _SC_PRIORITY_SCHEDULING : int = 10; - pub static _SC_TIMERS : int = 11; - pub static _SC_ASYNCHRONOUS_IO : int = 12; - pub static _SC_PRIORITIZED_IO : int = 13; - pub static _SC_SYNCHRONIZED_IO : int = 14; - pub static _SC_FSYNC : int = 15; - pub static _SC_MAPPED_FILES : int = 16; - pub static _SC_MEMLOCK : int = 17; - pub static _SC_MEMLOCK_RANGE : int = 18; - pub static _SC_MEMORY_PROTECTION : int = 19; - pub static _SC_MESSAGE_PASSING : int = 20; - pub static _SC_SEMAPHORES : int = 21; - pub static _SC_SHARED_MEMORY_OBJECTS : int = 22; - pub static _SC_AIO_LISTIO_MAX : int = 23; - pub static _SC_AIO_MAX : int = 24; - pub static _SC_AIO_PRIO_DELTA_MAX : int = 25; - pub static _SC_DELAYTIMER_MAX : int = 26; - pub static _SC_MQ_OPEN_MAX : int = 27; - pub static _SC_VERSION : int = 29; - pub static _SC_PAGESIZE : int = 30; - pub static _SC_RTSIG_MAX : int = 31; - pub static _SC_SEM_NSEMS_MAX : int = 32; - pub static _SC_SEM_VALUE_MAX : int = 33; - pub static _SC_SIGQUEUE_MAX : int = 34; - pub static _SC_TIMER_MAX : int = 35; - pub static _SC_BC_BASE_MAX : int = 36; - pub static _SC_BC_DIM_MAX : int = 37; - pub static _SC_BC_SCALE_MAX : int = 38; - pub static _SC_BC_STRING_MAX : int = 39; - pub static _SC_COLL_WEIGHTS_MAX : int = 40; - pub static _SC_EXPR_NEST_MAX : int = 42; - pub static _SC_LINE_MAX : int = 43; - pub static _SC_RE_DUP_MAX : int = 44; - pub static _SC_2_VERSION : int = 46; - pub static _SC_2_C_BIND : int = 47; - pub static _SC_2_C_DEV : int = 48; - pub static _SC_2_FORT_DEV : int = 49; - pub static _SC_2_FORT_RUN : int = 50; - pub static _SC_2_SW_DEV : int = 51; - pub static _SC_2_LOCALEDEF : int = 52; - pub static _SC_2_CHAR_TERM : int = 95; - pub static _SC_2_C_VERSION : int = 96; - pub static _SC_2_UPE : int = 97; - pub static _SC_XBS5_ILP32_OFF32 : int = 125; - pub static _SC_XBS5_ILP32_OFFBIG : int = 126; - pub static _SC_XBS5_LPBIG_OFFBIG : int = 128; + pub static MCL_CURRENT : c_int = 0x0001; + pub static MCL_FUTURE : c_int = 0x0002; + + pub static MS_ASYNC : c_int = 0x0001; + pub static MS_INVALIDATE : c_int = 0x0002; + pub static MS_SYNC : c_int = 0x0004; + + pub static _SC_ARG_MAX : c_int = 0; + pub static _SC_CHILD_MAX : c_int = 1; + pub static _SC_CLK_TCK : c_int = 2; + pub static _SC_NGROUPS_MAX : c_int = 3; + pub static _SC_OPEN_MAX : c_int = 4; + pub static _SC_STREAM_MAX : c_int = 5; + pub static _SC_TZNAME_MAX : c_int = 6; + pub static _SC_JOB_CONTROL : c_int = 7; + pub static _SC_SAVED_IDS : c_int = 8; + pub static _SC_REALTIME_SIGNALS : c_int = 9; + pub static _SC_PRIORITY_SCHEDULING : c_int = 10; + pub static _SC_TIMERS : c_int = 11; + pub static _SC_ASYNCHRONOUS_IO : c_int = 12; + pub static _SC_PRIORITIZED_IO : c_int = 13; + pub static _SC_SYNCHRONIZED_IO : c_int = 14; + pub static _SC_FSYNC : c_int = 15; + pub static _SC_MAPPED_FILES : c_int = 16; + pub static _SC_MEMLOCK : c_int = 17; + pub static _SC_MEMLOCK_RANGE : c_int = 18; + pub static _SC_MEMORY_PROTECTION : c_int = 19; + pub static _SC_MESSAGE_PASSING : c_int = 20; + pub static _SC_SEMAPHORES : c_int = 21; + pub static _SC_SHARED_MEMORY_OBJECTS : c_int = 22; + pub static _SC_AIO_LISTIO_MAX : c_int = 23; + pub static _SC_AIO_MAX : c_int = 24; + pub static _SC_AIO_PRIO_DELTA_MAX : c_int = 25; + pub static _SC_DELAYTIMER_MAX : c_int = 26; + pub static _SC_MQ_OPEN_MAX : c_int = 27; + pub static _SC_VERSION : c_int = 29; + pub static _SC_PAGESIZE : c_int = 30; + pub static _SC_RTSIG_MAX : c_int = 31; + pub static _SC_SEM_NSEMS_MAX : c_int = 32; + pub static _SC_SEM_VALUE_MAX : c_int = 33; + pub static _SC_SIGQUEUE_MAX : c_int = 34; + pub static _SC_TIMER_MAX : c_int = 35; + pub static _SC_BC_BASE_MAX : c_int = 36; + pub static _SC_BC_DIM_MAX : c_int = 37; + pub static _SC_BC_SCALE_MAX : c_int = 38; + pub static _SC_BC_STRING_MAX : c_int = 39; + pub static _SC_COLL_WEIGHTS_MAX : c_int = 40; + pub static _SC_EXPR_NEST_MAX : c_int = 42; + pub static _SC_LINE_MAX : c_int = 43; + pub static _SC_RE_DUP_MAX : c_int = 44; + pub static _SC_2_VERSION : c_int = 46; + pub static _SC_2_C_BIND : c_int = 47; + pub static _SC_2_C_DEV : c_int = 48; + pub static _SC_2_FORT_DEV : c_int = 49; + pub static _SC_2_FORT_RUN : c_int = 50; + pub static _SC_2_SW_DEV : c_int = 51; + pub static _SC_2_LOCALEDEF : c_int = 52; + pub static _SC_2_CHAR_TERM : c_int = 95; + pub static _SC_2_C_VERSION : c_int = 96; + pub static _SC_2_UPE : c_int = 97; + pub static _SC_XBS5_ILP32_OFF32 : c_int = 125; + pub static _SC_XBS5_ILP32_OFFBIG : c_int = 126; + pub static _SC_XBS5_LPBIG_OFFBIG : c_int = 128; } pub mod posix01 { - pub static SIGTRAP : int = 5; - - pub static GLOB_ERR : int = 1 << 0; - pub static GLOB_MARK : int = 1 << 1; - pub static GLOB_NOSORT : int = 1 << 2; - pub static GLOB_DOOFFS : int = 1 << 3; - pub static GLOB_NOCHECK : int = 1 << 4; - pub static GLOB_APPEND : int = 1 << 5; - pub static GLOB_NOESCAPE : int = 1 << 6; - - pub static GLOB_NOSPACE : int = 1; - pub static GLOB_ABORTED : int = 2; - pub static GLOB_NOMATCH : int = 3; - - pub static POSIX_MADV_NORMAL : int = 0; - pub static POSIX_MADV_RANDOM : int = 1; - pub static POSIX_MADV_SEQUENTIAL : int = 2; - pub static POSIX_MADV_WILLNEED : int = 3; - pub static POSIX_MADV_DONTNEED : int = 4; - - pub static _SC_MQ_PRIO_MAX : int = 28; - pub static _SC_IOV_MAX : int = 60; - pub static _SC_GETGR_R_SIZE_MAX : int = 69; - pub static _SC_GETPW_R_SIZE_MAX : int = 70; - pub static _SC_LOGIN_NAME_MAX : int = 71; - pub static _SC_TTY_NAME_MAX : int = 72; - pub static _SC_THREADS : int = 67; - pub static _SC_THREAD_SAFE_FUNCTIONS : int = 68; - pub static _SC_THREAD_DESTRUCTOR_ITERATIONS : int = 73; - pub static _SC_THREAD_KEYS_MAX : int = 74; - pub static _SC_THREAD_STACK_MIN : int = 75; - pub static _SC_THREAD_THREADS_MAX : int = 76; - pub static _SC_THREAD_ATTR_STACKADDR : int = 77; - pub static _SC_THREAD_ATTR_STACKSIZE : int = 78; - pub static _SC_THREAD_PRIORITY_SCHEDULING : int = 79; - pub static _SC_THREAD_PRIO_INHERIT : int = 80; - pub static _SC_THREAD_PRIO_PROTECT : int = 81; - pub static _SC_THREAD_PROCESS_SHARED : int = 82; - pub static _SC_ATEXIT_MAX : int = 87; - pub static _SC_XOPEN_VERSION : int = 89; - pub static _SC_XOPEN_XCU_VERSION : int = 90; - pub static _SC_XOPEN_UNIX : int = 91; - pub static _SC_XOPEN_CRYPT : int = 92; - pub static _SC_XOPEN_ENH_I18N : int = 93; - pub static _SC_XOPEN_SHM : int = 94; - pub static _SC_XOPEN_LEGACY : int = 129; - pub static _SC_XOPEN_REALTIME : int = 130; - pub static _SC_XOPEN_REALTIME_THREADS : int = 131; + use libc::types::os::arch::c95::c_int; + + pub static SIGTRAP : c_int = 5; + + pub static GLOB_ERR : c_int = 1 << 0; + pub static GLOB_MARK : c_int = 1 << 1; + pub static GLOB_NOSORT : c_int = 1 << 2; + pub static GLOB_DOOFFS : c_int = 1 << 3; + pub static GLOB_NOCHECK : c_int = 1 << 4; + pub static GLOB_APPEND : c_int = 1 << 5; + pub static GLOB_NOESCAPE : c_int = 1 << 6; + + pub static GLOB_NOSPACE : c_int = 1; + pub static GLOB_ABORTED : c_int = 2; + pub static GLOB_NOMATCH : c_int = 3; + + pub static POSIX_MADV_NORMAL : c_int = 0; + pub static POSIX_MADV_RANDOM : c_int = 1; + pub static POSIX_MADV_SEQUENTIAL : c_int = 2; + pub static POSIX_MADV_WILLNEED : c_int = 3; + pub static POSIX_MADV_DONTNEED : c_int = 4; + + pub static _SC_MQ_PRIO_MAX : c_int = 28; + pub static _SC_IOV_MAX : c_int = 60; + pub static _SC_GETGR_R_SIZE_MAX : c_int = 69; + pub static _SC_GETPW_R_SIZE_MAX : c_int = 70; + pub static _SC_LOGIN_NAME_MAX : c_int = 71; + pub static _SC_TTY_NAME_MAX : c_int = 72; + pub static _SC_THREADS : c_int = 67; + pub static _SC_THREAD_SAFE_FUNCTIONS : c_int = 68; + pub static _SC_THREAD_DESTRUCTOR_ITERATIONS : c_int = 73; + pub static _SC_THREAD_KEYS_MAX : c_int = 74; + pub static _SC_THREAD_STACK_MIN : c_int = 75; + pub static _SC_THREAD_THREADS_MAX : c_int = 76; + pub static _SC_THREAD_ATTR_STACKADDR : c_int = 77; + pub static _SC_THREAD_ATTR_STACKSIZE : c_int = 78; + pub static _SC_THREAD_PRIORITY_SCHEDULING : c_int = 79; + pub static _SC_THREAD_PRIO_INHERIT : c_int = 80; + pub static _SC_THREAD_PRIO_PROTECT : c_int = 81; + pub static _SC_THREAD_PROCESS_SHARED : c_int = 82; + pub static _SC_ATEXIT_MAX : c_int = 87; + pub static _SC_XOPEN_VERSION : c_int = 89; + pub static _SC_XOPEN_XCU_VERSION : c_int = 90; + pub static _SC_XOPEN_UNIX : c_int = 91; + pub static _SC_XOPEN_CRYPT : c_int = 92; + pub static _SC_XOPEN_ENH_I18N : c_int = 93; + pub static _SC_XOPEN_SHM : c_int = 94; + pub static _SC_XOPEN_LEGACY : c_int = 129; + pub static _SC_XOPEN_REALTIME : c_int = 130; + pub static _SC_XOPEN_REALTIME_THREADS : c_int = 131; } pub mod posix08 { } pub mod bsd44 { - pub static MADV_NORMAL : int = 0; - pub static MADV_RANDOM : int = 1; - pub static MADV_SEQUENTIAL : int = 2; - pub static MADV_WILLNEED : int = 3; - pub static MADV_DONTNEED : int = 4; - pub static MADV_REMOVE : int = 9; - pub static MADV_DONTFORK : int = 10; - pub static MADV_DOFORK : int = 11; - pub static MADV_MERGEABLE : int = 12; - pub static MADV_UNMERGEABLE : int = 13; - pub static MADV_HWPOISON : int = 100; + use libc::types::os::arch::c95::c_int; + + pub static MADV_NORMAL : c_int = 0; + pub static MADV_RANDOM : c_int = 1; + pub static MADV_SEQUENTIAL : c_int = 2; + pub static MADV_WILLNEED : c_int = 3; + pub static MADV_DONTNEED : c_int = 4; + pub static MADV_REMOVE : c_int = 9; + pub static MADV_DONTFORK : c_int = 10; + pub static MADV_DOFORK : c_int = 11; + pub static MADV_MERGEABLE : c_int = 12; + pub static MADV_UNMERGEABLE : c_int = 13; + pub static MADV_HWPOISON : c_int = 100; } #[cfg(target_arch = "x86")] #[cfg(target_arch = "x86_64")] #[cfg(target_arch = "arm")] pub mod extra { - pub static O_RSYNC : int = 1052672; - pub static O_DSYNC : int = 4096; - pub static O_SYNC : int = 1052672; - - pub static PROT_GROWSDOWN : int = 0x010000000; - pub static PROT_GROWSUP : int = 0x020000000; - - pub static MAP_TYPE : int = 0x000f; - pub static MAP_ANONONYMOUS : int = 0x1000; - pub static MAP_32BIT : int = 0x0040; - pub static MAP_GROWSDOWN : int = 0x0100; - pub static MAP_DENYWRITE : int = 0x0800; - pub static MAP_EXECUTABLE : int = 0x01000; - pub static MAP_LOCKED : int = 0x02000; - pub static MAP_NONRESERVE : int = 0x04000; - pub static MAP_POPULATE : int = 0x08000; - pub static MAP_NONBLOCK : int = 0x010000; - pub static MAP_STACK : int = 0x020000; + use libc::types::os::arch::c95::c_int; + + pub static O_RSYNC : c_int = 1052672; + pub static O_DSYNC : c_int = 4096; + pub static O_SYNC : c_int = 1052672; + + pub static PROT_GROWSDOWN : c_int = 0x010000000; + pub static PROT_GROWSUP : c_int = 0x020000000; + + pub static MAP_TYPE : c_int = 0x000f; + pub static MAP_ANONONYMOUS : c_int = 0x1000; + pub static MAP_32BIT : c_int = 0x0040; + pub static MAP_GROWSDOWN : c_int = 0x0100; + pub static MAP_DENYWRITE : c_int = 0x0800; + pub static MAP_EXECUTABLE : c_int = 0x01000; + pub static MAP_LOCKED : c_int = 0x02000; + pub static MAP_NONRESERVE : c_int = 0x04000; + pub static MAP_POPULATE : c_int = 0x08000; + pub static MAP_NONBLOCK : c_int = 0x010000; + pub static MAP_STACK : c_int = 0x020000; } #[cfg(target_arch = "mips")] pub mod extra { - pub static O_RSYNC : int = 16400; - pub static O_DSYNC : int = 16; - pub static O_SYNC : int = 16400; - - pub static PROT_GROWSDOWN : int = 0x010000000; - pub static PROT_GROWSUP : int = 0x020000000; - - pub static MAP_TYPE : int = 0x000f; - pub static MAP_ANONONYMOUS : int = 0x1000; - pub static MAP_32BIT : int = 0x0040; - pub static MAP_GROWSDOWN : int = 0x0100; - pub static MAP_DENYWRITE : int = 0x0800; - pub static MAP_EXECUTABLE : int = 0x01000; - pub static MAP_LOCKED : int = 0x02000; - pub static MAP_NONRESERVE : int = 0x04000; - pub static MAP_POPULATE : int = 0x08000; - pub static MAP_NONBLOCK : int = 0x010000; - pub static MAP_STACK : int = 0x020000; + use libc::types::os::arch::c95::c_int; + + pub static O_RSYNC : c_int = 16400; + pub static O_DSYNC : c_int = 16; + pub static O_SYNC : c_int = 16400; + + pub static PROT_GROWSDOWN : c_int = 0x010000000; + pub static PROT_GROWSUP : c_int = 0x020000000; + + pub static MAP_TYPE : c_int = 0x000f; + pub static MAP_ANONONYMOUS : c_int = 0x1000; + pub static MAP_32BIT : c_int = 0x0040; + pub static MAP_GROWSDOWN : c_int = 0x0100; + pub static MAP_DENYWRITE : c_int = 0x0800; + pub static MAP_EXECUTABLE : c_int = 0x01000; + pub static MAP_LOCKED : c_int = 0x02000; + pub static MAP_NONRESERVE : c_int = 0x04000; + pub static MAP_POPULATE : c_int = 0x08000; + pub static MAP_NONBLOCK : c_int = 0x010000; + pub static MAP_STACK : c_int = 0x020000; } } #[cfg(target_os = "freebsd")] pub mod os { pub mod c95 { - pub static EXIT_FAILURE : int = 1; - pub static EXIT_SUCCESS : int = 0; - pub static RAND_MAX : int = 2147483647; - pub static EOF : int = -1; - pub static SEEK_SET : int = 0; - pub static SEEK_CUR : int = 1; - pub static SEEK_END : int = 2; - pub static _IOFBF : int = 0; - pub static _IONBF : int = 2; - pub static _IOLBF : int = 1; - pub static BUFSIZ : uint = 1024_u; - pub static FOPEN_MAX : uint = 20_u; - pub static FILENAME_MAX : uint = 1024_u; - pub static L_tmpnam : uint = 1024_u; - pub static TMP_MAX : uint = 308915776_u; + use libc::types::os::arch::c95::{c_int, c_uint}; + + pub static EXIT_FAILURE : c_int = 1; + pub static EXIT_SUCCESS : c_int = 0; + pub static RAND_MAX : c_int = 2147483647; + pub static EOF : c_int = -1; + pub static SEEK_SET : c_int = 0; + pub static SEEK_CUR : c_int = 1; + pub static SEEK_END : c_int = 2; + pub static _IOFBF : c_int = 0; + pub static _IONBF : c_int = 2; + pub static _IOLBF : c_int = 1; + pub static BUFSIZ : c_uint = 1024_u32; + pub static FOPEN_MAX : c_uint = 20_u32; + pub static FILENAME_MAX : c_uint = 1024_u32; + pub static L_tmpnam : c_uint = 1024_u32; + pub static TMP_MAX : c_uint = 308915776_u32; } pub mod c99 { } pub mod posix88 { use libc::types::common::c95::c_void; - - pub static O_RDONLY : int = 0; - pub static O_WRONLY : int = 1; - pub static O_RDWR : int = 2; - pub static O_APPEND : int = 8; - pub static O_CREAT : int = 512; - pub static O_EXCL : int = 2048; - pub static O_TRUNC : int = 1024; - pub static S_IFIFO : int = 4096; - pub static S_IFCHR : int = 8192; - pub static S_IFBLK : int = 24576; - pub static S_IFDIR : int = 16384; - pub static S_IFREG : int = 32768; - pub static S_IFMT : int = 61440; - pub static S_IEXEC : int = 64; - pub static S_IWRITE : int = 128; - pub static S_IREAD : int = 256; - pub static S_IRWXU : int = 448; - pub static S_IXUSR : int = 64; - pub static S_IWUSR : int = 128; - pub static S_IRUSR : int = 256; - pub static F_OK : int = 0; - pub static R_OK : int = 4; - pub static W_OK : int = 2; - pub static X_OK : int = 1; - pub static STDIN_FILENO : int = 0; - pub static STDOUT_FILENO : int = 1; - pub static STDERR_FILENO : int = 2; - pub static F_LOCK : int = 1; - pub static F_TEST : int = 3; - pub static F_TLOCK : int = 2; - pub static F_ULOCK : int = 0; - pub static SIGHUP : int = 1; - pub static SIGINT : int = 2; - pub static SIGQUIT : int = 3; - pub static SIGILL : int = 4; - pub static SIGABRT : int = 6; - pub static SIGFPE : int = 8; - pub static SIGKILL : int = 9; - pub static SIGSEGV : int = 11; - pub static SIGPIPE : int = 13; - pub static SIGALRM : int = 14; - pub static SIGTERM : int = 15; - - pub static PROT_NONE : int = 0; - pub static PROT_READ : int = 1; - pub static PROT_WRITE : int = 2; - pub static PROT_EXEC : int = 4; - - pub static MAP_FILE : int = 0x0000; - pub static MAP_SHARED : int = 0x0001; - pub static MAP_PRIVATE : int = 0x0002; - pub static MAP_FIXED : int = 0x0010; - pub static MAP_ANON : int = 0x1000; + use libc::types::os::arch::c95::c_int; + + pub static O_RDONLY : c_int = 0; + pub static O_WRONLY : c_int = 1; + pub static O_RDWR : c_int = 2; + pub static O_APPEND : c_int = 8; + pub static O_CREAT : c_int = 512; + pub static O_EXCL : c_int = 2048; + pub static O_TRUNC : c_int = 1024; + pub static S_IFIFO : c_int = 4096; + pub static S_IFCHR : c_int = 8192; + pub static S_IFBLK : c_int = 24576; + pub static S_IFDIR : c_int = 16384; + pub static S_IFREG : c_int = 32768; + pub static S_IFMT : c_int = 61440; + pub static S_IEXEC : c_int = 64; + pub static S_IWRITE : c_int = 128; + pub static S_IREAD : c_int = 256; + pub static S_IRWXU : c_int = 448; + pub static S_IXUSR : c_int = 64; + pub static S_IWUSR : c_int = 128; + pub static S_IRUSR : c_int = 256; + pub static F_OK : c_int = 0; + pub static R_OK : c_int = 4; + pub static W_OK : c_int = 2; + pub static X_OK : c_int = 1; + pub static STDIN_FILENO : c_int = 0; + pub static STDOUT_FILENO : c_int = 1; + pub static STDERR_FILENO : c_int = 2; + pub static F_LOCK : c_int = 1; + pub static F_TEST : c_int = 3; + pub static F_TLOCK : c_int = 2; + pub static F_ULOCK : c_int = 0; + pub static SIGHUP : c_int = 1; + pub static SIGINT : c_int = 2; + pub static SIGQUIT : c_int = 3; + pub static SIGILL : c_int = 4; + pub static SIGABRT : c_int = 6; + pub static SIGFPE : c_int = 8; + pub static SIGKILL : c_int = 9; + pub static SIGSEGV : c_int = 11; + pub static SIGPIPE : c_int = 13; + pub static SIGALRM : c_int = 14; + pub static SIGTERM : c_int = 15; + + pub static PROT_NONE : c_int = 0; + pub static PROT_READ : c_int = 1; + pub static PROT_WRITE : c_int = 2; + pub static PROT_EXEC : c_int = 4; + + pub static MAP_FILE : c_int = 0x0000; + pub static MAP_SHARED : c_int = 0x0001; + pub static MAP_PRIVATE : c_int = 0x0002; + pub static MAP_FIXED : c_int = 0x0010; + pub static MAP_ANON : c_int = 0x1000; pub static MAP_FAILED : *c_void = -1 as *c_void; - pub static MCL_CURRENT : int = 0x0001; - pub static MCL_FUTURE : int = 0x0002; - - pub static MS_SYNC : int = 0x0000; - pub static MS_ASYNC : int = 0x0001; - pub static MS_INVALIDATE : int = 0x0002; - - pub static _SC_ARG_MAX : int = 1; - pub static _SC_CHILD_MAX : int = 2; - pub static _SC_CLK_TCK : int = 3; - pub static _SC_NGROUPS_MAX : int = 4; - pub static _SC_OPEN_MAX : int = 5; - pub static _SC_JOB_CONTROL : int = 6; - pub static _SC_SAVED_IDS : int = 7; - pub static _SC_VERSION : int = 8; - pub static _SC_BC_BASE_MAX : int = 9; - pub static _SC_BC_DIM_MAX : int = 10; - pub static _SC_BC_SCALE_MAX : int = 11; - pub static _SC_BC_STRING_MAX : int = 12; - pub static _SC_COLL_WEIGHTS_MAX : int = 13; - pub static _SC_EXPR_NEST_MAX : int = 14; - pub static _SC_LINE_MAX : int = 15; - pub static _SC_RE_DUP_MAX : int = 16; - pub static _SC_2_VERSION : int = 17; - pub static _SC_2_C_BIND : int = 18; - pub static _SC_2_C_DEV : int = 19; - pub static _SC_2_CHAR_TERM : int = 20; - pub static _SC_2_FORT_DEV : int = 21; - pub static _SC_2_FORT_RUN : int = 22; - pub static _SC_2_LOCALEDEF : int = 23; - pub static _SC_2_SW_DEV : int = 24; - pub static _SC_2_UPE : int = 25; - pub static _SC_STREAM_MAX : int = 26; - pub static _SC_TZNAME_MAX : int = 27; - pub static _SC_ASYNCHRONOUS_IO : int = 28; - pub static _SC_MAPPED_FILES : int = 29; - pub static _SC_MEMLOCK : int = 30; - pub static _SC_MEMLOCK_RANGE : int = 31; - pub static _SC_MEMORY_PROTECTION : int = 32; - pub static _SC_MESSAGE_PASSING : int = 33; - pub static _SC_PRIORITIZED_IO : int = 34; - pub static _SC_PRIORITY_SCHEDULING : int = 35; - pub static _SC_REALTIME_SIGNALS : int = 36; - pub static _SC_SEMAPHORES : int = 37; - pub static _SC_FSYNC : int = 38; - pub static _SC_SHARED_MEMORY_OBJECTS : int = 39; - pub static _SC_SYNCHRONIZED_IO : int = 40; - pub static _SC_TIMERS : int = 41; - pub static _SC_AIO_LISTIO_MAX : int = 42; - pub static _SC_AIO_MAX : int = 43; - pub static _SC_AIO_PRIO_DELTA_MAX : int = 44; - pub static _SC_DELAYTIMER_MAX : int = 45; - pub static _SC_MQ_OPEN_MAX : int = 46; - pub static _SC_PAGESIZE : int = 47; - pub static _SC_RTSIG_MAX : int = 48; - pub static _SC_SEM_NSEMS_MAX : int = 49; - pub static _SC_SEM_VALUE_MAX : int = 50; - pub static _SC_SIGQUEUE_MAX : int = 51; - pub static _SC_TIMER_MAX : int = 52; + pub static MCL_CURRENT : c_int = 0x0001; + pub static MCL_FUTURE : c_int = 0x0002; + + pub static MS_SYNC : c_int = 0x0000; + pub static MS_ASYNC : c_int = 0x0001; + pub static MS_INVALIDATE : c_int = 0x0002; + + pub static _SC_ARG_MAX : c_int = 1; + pub static _SC_CHILD_MAX : c_int = 2; + pub static _SC_CLK_TCK : c_int = 3; + pub static _SC_NGROUPS_MAX : c_int = 4; + pub static _SC_OPEN_MAX : c_int = 5; + pub static _SC_JOB_CONTROL : c_int = 6; + pub static _SC_SAVED_IDS : c_int = 7; + pub static _SC_VERSION : c_int = 8; + pub static _SC_BC_BASE_MAX : c_int = 9; + pub static _SC_BC_DIM_MAX : c_int = 10; + pub static _SC_BC_SCALE_MAX : c_int = 11; + pub static _SC_BC_STRING_MAX : c_int = 12; + pub static _SC_COLL_WEIGHTS_MAX : c_int = 13; + pub static _SC_EXPR_NEST_MAX : c_int = 14; + pub static _SC_LINE_MAX : c_int = 15; + pub static _SC_RE_DUP_MAX : c_int = 16; + pub static _SC_2_VERSION : c_int = 17; + pub static _SC_2_C_BIND : c_int = 18; + pub static _SC_2_C_DEV : c_int = 19; + pub static _SC_2_CHAR_TERM : c_int = 20; + pub static _SC_2_FORT_DEV : c_int = 21; + pub static _SC_2_FORT_RUN : c_int = 22; + pub static _SC_2_LOCALEDEF : c_int = 23; + pub static _SC_2_SW_DEV : c_int = 24; + pub static _SC_2_UPE : c_int = 25; + pub static _SC_STREAM_MAX : c_int = 26; + pub static _SC_TZNAME_MAX : c_int = 27; + pub static _SC_ASYNCHRONOUS_IO : c_int = 28; + pub static _SC_MAPPED_FILES : c_int = 29; + pub static _SC_MEMLOCK : c_int = 30; + pub static _SC_MEMLOCK_RANGE : c_int = 31; + pub static _SC_MEMORY_PROTECTION : c_int = 32; + pub static _SC_MESSAGE_PASSING : c_int = 33; + pub static _SC_PRIORITIZED_IO : c_int = 34; + pub static _SC_PRIORITY_SCHEDULING : c_int = 35; + pub static _SC_REALTIME_SIGNALS : c_int = 36; + pub static _SC_SEMAPHORES : c_int = 37; + pub static _SC_FSYNC : c_int = 38; + pub static _SC_SHARED_MEMORY_OBJECTS : c_int = 39; + pub static _SC_SYNCHRONIZED_IO : c_int = 40; + pub static _SC_TIMERS : c_int = 41; + pub static _SC_AIO_LISTIO_MAX : c_int = 42; + pub static _SC_AIO_MAX : c_int = 43; + pub static _SC_AIO_PRIO_DELTA_MAX : c_int = 44; + pub static _SC_DELAYTIMER_MAX : c_int = 45; + pub static _SC_MQ_OPEN_MAX : c_int = 46; + pub static _SC_PAGESIZE : c_int = 47; + pub static _SC_RTSIG_MAX : c_int = 48; + pub static _SC_SEM_NSEMS_MAX : c_int = 49; + pub static _SC_SEM_VALUE_MAX : c_int = 50; + pub static _SC_SIGQUEUE_MAX : c_int = 51; + pub static _SC_TIMER_MAX : c_int = 52; } pub mod posix01 { - pub static SIGTRAP : int = 5; - - pub static GLOB_APPEND : int = 0x0001; - pub static GLOB_DOOFFS : int = 0x0002; - pub static GLOB_ERR : int = 0x0004; - pub static GLOB_MARK : int = 0x0008; - pub static GLOB_NOCHECK : int = 0x0010; - pub static GLOB_NOSORT : int = 0x0020; - pub static GLOB_NOESCAPE : int = 0x2000; - - pub static GLOB_NOSPACE : int = -1; - pub static GLOB_ABORTED : int = -2; - pub static GLOB_NOMATCH : int = -3; - - pub static POSIX_MADV_NORMAL : int = 0; - pub static POSIX_MADV_RANDOM : int = 1; - pub static POSIX_MADV_SEQUENTIAL : int = 2; - pub static POSIX_MADV_WILLNEED : int = 3; - pub static POSIX_MADV_DONTNEED : int = 4; - - pub static _SC_IOV_MAX : int = 56; - pub static _SC_GETGR_R_SIZE_MAX : int = 70; - pub static _SC_GETPW_R_SIZE_MAX : int = 71; - pub static _SC_LOGIN_NAME_MAX : int = 73; - pub static _SC_MQ_PRIO_MAX : int = 75; - pub static _SC_THREAD_ATTR_STACKADDR : int = 82; - pub static _SC_THREAD_ATTR_STACKSIZE : int = 83; - pub static _SC_THREAD_DESTRUCTOR_ITERATIONS : int = 85; - pub static _SC_THREAD_KEYS_MAX : int = 86; - pub static _SC_THREAD_PRIO_INHERIT : int = 87; - pub static _SC_THREAD_PRIO_PROTECT : int = 88; - pub static _SC_THREAD_PRIORITY_SCHEDULING : int = 89; - pub static _SC_THREAD_PROCESS_SHARED : int = 90; - pub static _SC_THREAD_SAFE_FUNCTIONS : int = 91; - pub static _SC_THREAD_STACK_MIN : int = 93; - pub static _SC_THREAD_THREADS_MAX : int = 94; - pub static _SC_THREADS : int = 96; - pub static _SC_TTY_NAME_MAX : int = 101; - pub static _SC_ATEXIT_MAX : int = 107; - pub static _SC_XOPEN_CRYPT : int = 108; - pub static _SC_XOPEN_ENH_I18N : int = 109; - pub static _SC_XOPEN_LEGACY : int = 110; - pub static _SC_XOPEN_REALTIME : int = 111; - pub static _SC_XOPEN_REALTIME_THREADS : int = 112; - pub static _SC_XOPEN_SHM : int = 113; - pub static _SC_XOPEN_UNIX : int = 115; - pub static _SC_XOPEN_VERSION : int = 116; - pub static _SC_XOPEN_XCU_VERSION : int = 117; + use libc::types::os::arch::c95::c_int; + + pub static SIGTRAP : c_int = 5; + + pub static GLOB_APPEND : c_int = 0x0001; + pub static GLOB_DOOFFS : c_int = 0x0002; + pub static GLOB_ERR : c_int = 0x0004; + pub static GLOB_MARK : c_int = 0x0008; + pub static GLOB_NOCHECK : c_int = 0x0010; + pub static GLOB_NOSORT : c_int = 0x0020; + pub static GLOB_NOESCAPE : c_int = 0x2000; + + pub static GLOB_NOSPACE : c_int = -1; + pub static GLOB_ABORTED : c_int = -2; + pub static GLOB_NOMATCH : c_int = -3; + + pub static POSIX_MADV_NORMAL : c_int = 0; + pub static POSIX_MADV_RANDOM : c_int = 1; + pub static POSIX_MADV_SEQUENTIAL : c_int = 2; + pub static POSIX_MADV_WILLNEED : c_int = 3; + pub static POSIX_MADV_DONTNEED : c_int = 4; + + pub static _SC_IOV_MAX : c_int = 56; + pub static _SC_GETGR_R_SIZE_MAX : c_int = 70; + pub static _SC_GETPW_R_SIZE_MAX : c_int = 71; + pub static _SC_LOGIN_NAME_MAX : c_int = 73; + pub static _SC_MQ_PRIO_MAX : c_int = 75; + pub static _SC_THREAD_ATTR_STACKADDR : c_int = 82; + pub static _SC_THREAD_ATTR_STACKSIZE : c_int = 83; + pub static _SC_THREAD_DESTRUCTOR_ITERATIONS : c_int = 85; + pub static _SC_THREAD_KEYS_MAX : c_int = 86; + pub static _SC_THREAD_PRIO_INHERIT : c_int = 87; + pub static _SC_THREAD_PRIO_PROTECT : c_int = 88; + pub static _SC_THREAD_PRIORITY_SCHEDULING : c_int = 89; + pub static _SC_THREAD_PROCESS_SHARED : c_int = 90; + pub static _SC_THREAD_SAFE_FUNCTIONS : c_int = 91; + pub static _SC_THREAD_STACK_MIN : c_int = 93; + pub static _SC_THREAD_THREADS_MAX : c_int = 94; + pub static _SC_THREADS : c_int = 96; + pub static _SC_TTY_NAME_MAX : c_int = 101; + pub static _SC_ATEXIT_MAX : c_int = 107; + pub static _SC_XOPEN_CRYPT : c_int = 108; + pub static _SC_XOPEN_ENH_I18N : c_int = 109; + pub static _SC_XOPEN_LEGACY : c_int = 110; + pub static _SC_XOPEN_REALTIME : c_int = 111; + pub static _SC_XOPEN_REALTIME_THREADS : c_int = 112; + pub static _SC_XOPEN_SHM : c_int = 113; + pub static _SC_XOPEN_UNIX : c_int = 115; + pub static _SC_XOPEN_VERSION : c_int = 116; + pub static _SC_XOPEN_XCU_VERSION : c_int = 117; } pub mod posix08 { } pub mod bsd44 { - pub static MADV_NORMAL : int = 0; - pub static MADV_RANDOM : int = 1; - pub static MADV_SEQUENTIAL : int = 2; - pub static MADV_WILLNEED : int = 3; - pub static MADV_DONTNEED : int = 4; - pub static MADV_FREE : int = 5; - pub static MADV_NOSYNC : int = 6; - pub static MADV_AUTOSYNC : int = 7; - pub static MADV_NOCORE : int = 8; - pub static MADV_CORE : int = 9; - pub static MADV_PROTECT : int = 10; - - pub static MINCORE_INCORE : int = 0x1; - pub static MINCORE_REFERENCED : int = 0x2; - pub static MINCORE_MODIFIED : int = 0x4; - pub static MINCORE_REFERENCED_OTHER : int = 0x8; - pub static MINCORE_MODIFIED_OTHER : int = 0x10; - pub static MINCORE_SUPER : int = 0x20; + use libc::types::os::arch::c95::c_int; + + pub static MADV_NORMAL : c_int = 0; + pub static MADV_RANDOM : c_int = 1; + pub static MADV_SEQUENTIAL : c_int = 2; + pub static MADV_WILLNEED : c_int = 3; + pub static MADV_DONTNEED : c_int = 4; + pub static MADV_FREE : c_int = 5; + pub static MADV_NOSYNC : c_int = 6; + pub static MADV_AUTOSYNC : c_int = 7; + pub static MADV_NOCORE : c_int = 8; + pub static MADV_CORE : c_int = 9; + pub static MADV_PROTECT : c_int = 10; + + pub static MINCORE_INCORE : c_int = 0x1; + pub static MINCORE_REFERENCED : c_int = 0x2; + pub static MINCORE_MODIFIED : c_int = 0x4; + pub static MINCORE_REFERENCED_OTHER : c_int = 0x8; + pub static MINCORE_MODIFIED_OTHER : c_int = 0x10; + pub static MINCORE_SUPER : c_int = 0x20; } pub mod extra { - pub static O_SYNC : int = 128; - pub static CTL_KERN: int = 1; - pub static KERN_PROC: int = 14; - pub static KERN_PROC_PATHNAME: int = 12; - - pub static MAP_COPY : int = 0x0002; - pub static MAP_RENAME : int = 0x0020; - pub static MAP_NORESERVE : int = 0x0040; - pub static MAP_HASSEMAPHORE : int = 0x0200; - pub static MAP_STACK : int = 0x0400; - pub static MAP_NOSYNC : int = 0x0800; - pub static MAP_NOCORE : int = 0x020000; + use libc::types::os::arch::c95::c_int; + + pub static O_SYNC : c_int = 128; + pub static CTL_KERN: c_int = 1; + pub static KERN_PROC: c_int = 14; + pub static KERN_PROC_PATHNAME: c_int = 12; + + pub static MAP_COPY : c_int = 0x0002; + pub static MAP_RENAME : c_int = 0x0020; + pub static MAP_NORESERVE : c_int = 0x0040; + pub static MAP_HASSEMAPHORE : c_int = 0x0200; + pub static MAP_STACK : c_int = 0x0400; + pub static MAP_NOSYNC : c_int = 0x0800; + pub static MAP_NOCORE : c_int = 0x020000; } } #[cfg(target_os = "macos")] pub mod os { pub mod c95 { - pub static EXIT_FAILURE : int = 1; - pub static EXIT_SUCCESS : int = 0; - pub static RAND_MAX : int = 2147483647; - pub static EOF : int = -1; - pub static SEEK_SET : int = 0; - pub static SEEK_CUR : int = 1; - pub static SEEK_END : int = 2; - pub static _IOFBF : int = 0; - pub static _IONBF : int = 2; - pub static _IOLBF : int = 1; - pub static BUFSIZ : uint = 1024_u; - pub static FOPEN_MAX : uint = 20_u; - pub static FILENAME_MAX : uint = 1024_u; - pub static L_tmpnam : uint = 1024_u; - pub static TMP_MAX : uint = 308915776_u; + use libc::types::os::arch::c95::{c_int, c_uint}; + + pub static EXIT_FAILURE : c_int = 1; + pub static EXIT_SUCCESS : c_int = 0; + pub static RAND_MAX : c_int = 2147483647; + pub static EOF : c_int = -1; + pub static SEEK_SET : c_int = 0; + pub static SEEK_CUR : c_int = 1; + pub static SEEK_END : c_int = 2; + pub static _IOFBF : c_int = 0; + pub static _IONBF : c_int = 2; + pub static _IOLBF : c_int = 1; + pub static BUFSIZ : c_uint = 1024_u32; + pub static FOPEN_MAX : c_uint = 20_u32; + pub static FILENAME_MAX : c_uint = 1024_u32; + pub static L_tmpnam : c_uint = 1024_u32; + pub static TMP_MAX : c_uint = 308915776_u32; } pub mod c99 { } pub mod posix88 { use libc::types::common::c95::c_void; - - pub static O_RDONLY : int = 0; - pub static O_WRONLY : int = 1; - pub static O_RDWR : int = 2; - pub static O_APPEND : int = 8; - pub static O_CREAT : int = 512; - pub static O_EXCL : int = 2048; - pub static O_TRUNC : int = 1024; - pub static S_IFIFO : int = 4096; - pub static S_IFCHR : int = 8192; - pub static S_IFBLK : int = 24576; - pub static S_IFDIR : int = 16384; - pub static S_IFREG : int = 32768; - pub static S_IFMT : int = 61440; - pub static S_IEXEC : int = 64; - pub static S_IWRITE : int = 128; - pub static S_IREAD : int = 256; - pub static S_IRWXU : int = 448; - pub static S_IXUSR : int = 64; - pub static S_IWUSR : int = 128; - pub static S_IRUSR : int = 256; - pub static F_OK : int = 0; - pub static R_OK : int = 4; - pub static W_OK : int = 2; - pub static X_OK : int = 1; - pub static STDIN_FILENO : int = 0; - pub static STDOUT_FILENO : int = 1; - pub static STDERR_FILENO : int = 2; - pub static F_LOCK : int = 1; - pub static F_TEST : int = 3; - pub static F_TLOCK : int = 2; - pub static F_ULOCK : int = 0; - pub static SIGHUP : int = 1; - pub static SIGINT : int = 2; - pub static SIGQUIT : int = 3; - pub static SIGILL : int = 4; - pub static SIGABRT : int = 6; - pub static SIGFPE : int = 8; - pub static SIGKILL : int = 9; - pub static SIGSEGV : int = 11; - pub static SIGPIPE : int = 13; - pub static SIGALRM : int = 14; - pub static SIGTERM : int = 15; - - pub static PROT_NONE : int = 0; - pub static PROT_READ : int = 1; - pub static PROT_WRITE : int = 2; - pub static PROT_EXEC : int = 4; - - pub static MAP_FILE : int = 0x0000; - pub static MAP_SHARED : int = 0x0001; - pub static MAP_PRIVATE : int = 0x0002; - pub static MAP_FIXED : int = 0x0010; - pub static MAP_ANON : int = 0x1000; + use libc::types::os::arch::c95::c_int; + + pub static O_RDONLY : c_int = 0; + pub static O_WRONLY : c_int = 1; + pub static O_RDWR : c_int = 2; + pub static O_APPEND : c_int = 8; + pub static O_CREAT : c_int = 512; + pub static O_EXCL : c_int = 2048; + pub static O_TRUNC : c_int = 1024; + pub static S_IFIFO : c_int = 4096; + pub static S_IFCHR : c_int = 8192; + pub static S_IFBLK : c_int = 24576; + pub static S_IFDIR : c_int = 16384; + pub static S_IFREG : c_int = 32768; + pub static S_IFMT : c_int = 61440; + pub static S_IEXEC : c_int = 64; + pub static S_IWRITE : c_int = 128; + pub static S_IREAD : c_int = 256; + pub static S_IRWXU : c_int = 448; + pub static S_IXUSR : c_int = 64; + pub static S_IWUSR : c_int = 128; + pub static S_IRUSR : c_int = 256; + pub static F_OK : c_int = 0; + pub static R_OK : c_int = 4; + pub static W_OK : c_int = 2; + pub static X_OK : c_int = 1; + pub static STDIN_FILENO : c_int = 0; + pub static STDOUT_FILENO : c_int = 1; + pub static STDERR_FILENO : c_int = 2; + pub static F_LOCK : c_int = 1; + pub static F_TEST : c_int = 3; + pub static F_TLOCK : c_int = 2; + pub static F_ULOCK : c_int = 0; + pub static SIGHUP : c_int = 1; + pub static SIGINT : c_int = 2; + pub static SIGQUIT : c_int = 3; + pub static SIGILL : c_int = 4; + pub static SIGABRT : c_int = 6; + pub static SIGFPE : c_int = 8; + pub static SIGKILL : c_int = 9; + pub static SIGSEGV : c_int = 11; + pub static SIGPIPE : c_int = 13; + pub static SIGALRM : c_int = 14; + pub static SIGTERM : c_int = 15; + + pub static PROT_NONE : c_int = 0; + pub static PROT_READ : c_int = 1; + pub static PROT_WRITE : c_int = 2; + pub static PROT_EXEC : c_int = 4; + + pub static MAP_FILE : c_int = 0x0000; + pub static MAP_SHARED : c_int = 0x0001; + pub static MAP_PRIVATE : c_int = 0x0002; + pub static MAP_FIXED : c_int = 0x0010; + pub static MAP_ANON : c_int = 0x1000; pub static MAP_FAILED : *c_void = -1 as *c_void; - pub static MCL_CURRENT : int = 0x0001; - pub static MCL_FUTURE : int = 0x0002; - - pub static MS_ASYNC : int = 0x0001; - pub static MS_INVALIDATE : int = 0x0002; - pub static MS_SYNC : int = 0x0010; - - pub static MS_KILLPAGES : int = 0x0004; - pub static MS_DEACTIVATE : int = 0x0008; - - pub static _SC_ARG_MAX : int = 1; - pub static _SC_CHILD_MAX : int = 2; - pub static _SC_CLK_TCK : int = 3; - pub static _SC_NGROUPS_MAX : int = 4; - pub static _SC_OPEN_MAX : int = 5; - pub static _SC_JOB_CONTROL : int = 6; - pub static _SC_SAVED_IDS : int = 7; - pub static _SC_VERSION : int = 8; - pub static _SC_BC_BASE_MAX : int = 9; - pub static _SC_BC_DIM_MAX : int = 10; - pub static _SC_BC_SCALE_MAX : int = 11; - pub static _SC_BC_STRING_MAX : int = 12; - pub static _SC_COLL_WEIGHTS_MAX : int = 13; - pub static _SC_EXPR_NEST_MAX : int = 14; - pub static _SC_LINE_MAX : int = 15; - pub static _SC_RE_DUP_MAX : int = 16; - pub static _SC_2_VERSION : int = 17; - pub static _SC_2_C_BIND : int = 18; - pub static _SC_2_C_DEV : int = 19; - pub static _SC_2_CHAR_TERM : int = 20; - pub static _SC_2_FORT_DEV : int = 21; - pub static _SC_2_FORT_RUN : int = 22; - pub static _SC_2_LOCALEDEF : int = 23; - pub static _SC_2_SW_DEV : int = 24; - pub static _SC_2_UPE : int = 25; - pub static _SC_STREAM_MAX : int = 26; - pub static _SC_TZNAME_MAX : int = 27; - pub static _SC_ASYNCHRONOUS_IO : int = 28; - pub static _SC_PAGESIZE : int = 29; - pub static _SC_MEMLOCK : int = 30; - pub static _SC_MEMLOCK_RANGE : int = 31; - pub static _SC_MEMORY_PROTECTION : int = 32; - pub static _SC_MESSAGE_PASSING : int = 33; - pub static _SC_PRIORITIZED_IO : int = 34; - pub static _SC_PRIORITY_SCHEDULING : int = 35; - pub static _SC_REALTIME_SIGNALS : int = 36; - pub static _SC_SEMAPHORES : int = 37; - pub static _SC_FSYNC : int = 38; - pub static _SC_SHARED_MEMORY_OBJECTS : int = 39; - pub static _SC_SYNCHRONIZED_IO : int = 40; - pub static _SC_TIMERS : int = 41; - pub static _SC_AIO_LISTIO_MAX : int = 42; - pub static _SC_AIO_MAX : int = 43; - pub static _SC_AIO_PRIO_DELTA_MAX : int = 44; - pub static _SC_DELAYTIMER_MAX : int = 45; - pub static _SC_MQ_OPEN_MAX : int = 46; - pub static _SC_MAPPED_FILES : int = 47; - pub static _SC_RTSIG_MAX : int = 48; - pub static _SC_SEM_NSEMS_MAX : int = 49; - pub static _SC_SEM_VALUE_MAX : int = 50; - pub static _SC_SIGQUEUE_MAX : int = 51; - pub static _SC_TIMER_MAX : int = 52; - pub static _SC_XBS5_ILP32_OFF32 : int = 122; - pub static _SC_XBS5_ILP32_OFFBIG : int = 123; - pub static _SC_XBS5_LP64_OFF64 : int = 124; - pub static _SC_XBS5_LPBIG_OFFBIG : int = 125; + pub static MCL_CURRENT : c_int = 0x0001; + pub static MCL_FUTURE : c_int = 0x0002; + + pub static MS_ASYNC : c_int = 0x0001; + pub static MS_INVALIDATE : c_int = 0x0002; + pub static MS_SYNC : c_int = 0x0010; + + pub static MS_KILLPAGES : c_int = 0x0004; + pub static MS_DEACTIVATE : c_int = 0x0008; + + pub static _SC_ARG_MAX : c_int = 1; + pub static _SC_CHILD_MAX : c_int = 2; + pub static _SC_CLK_TCK : c_int = 3; + pub static _SC_NGROUPS_MAX : c_int = 4; + pub static _SC_OPEN_MAX : c_int = 5; + pub static _SC_JOB_CONTROL : c_int = 6; + pub static _SC_SAVED_IDS : c_int = 7; + pub static _SC_VERSION : c_int = 8; + pub static _SC_BC_BASE_MAX : c_int = 9; + pub static _SC_BC_DIM_MAX : c_int = 10; + pub static _SC_BC_SCALE_MAX : c_int = 11; + pub static _SC_BC_STRING_MAX : c_int = 12; + pub static _SC_COLL_WEIGHTS_MAX : c_int = 13; + pub static _SC_EXPR_NEST_MAX : c_int = 14; + pub static _SC_LINE_MAX : c_int = 15; + pub static _SC_RE_DUP_MAX : c_int = 16; + pub static _SC_2_VERSION : c_int = 17; + pub static _SC_2_C_BIND : c_int = 18; + pub static _SC_2_C_DEV : c_int = 19; + pub static _SC_2_CHAR_TERM : c_int = 20; + pub static _SC_2_FORT_DEV : c_int = 21; + pub static _SC_2_FORT_RUN : c_int = 22; + pub static _SC_2_LOCALEDEF : c_int = 23; + pub static _SC_2_SW_DEV : c_int = 24; + pub static _SC_2_UPE : c_int = 25; + pub static _SC_STREAM_MAX : c_int = 26; + pub static _SC_TZNAME_MAX : c_int = 27; + pub static _SC_ASYNCHRONOUS_IO : c_int = 28; + pub static _SC_PAGESIZE : c_int = 29; + pub static _SC_MEMLOCK : c_int = 30; + pub static _SC_MEMLOCK_RANGE : c_int = 31; + pub static _SC_MEMORY_PROTECTION : c_int = 32; + pub static _SC_MESSAGE_PASSING : c_int = 33; + pub static _SC_PRIORITIZED_IO : c_int = 34; + pub static _SC_PRIORITY_SCHEDULING : c_int = 35; + pub static _SC_REALTIME_SIGNALS : c_int = 36; + pub static _SC_SEMAPHORES : c_int = 37; + pub static _SC_FSYNC : c_int = 38; + pub static _SC_SHARED_MEMORY_OBJECTS : c_int = 39; + pub static _SC_SYNCHRONIZED_IO : c_int = 40; + pub static _SC_TIMERS : c_int = 41; + pub static _SC_AIO_LISTIO_MAX : c_int = 42; + pub static _SC_AIO_MAX : c_int = 43; + pub static _SC_AIO_PRIO_DELTA_MAX : c_int = 44; + pub static _SC_DELAYTIMER_MAX : c_int = 45; + pub static _SC_MQ_OPEN_MAX : c_int = 46; + pub static _SC_MAPPED_FILES : c_int = 47; + pub static _SC_RTSIG_MAX : c_int = 48; + pub static _SC_SEM_NSEMS_MAX : c_int = 49; + pub static _SC_SEM_VALUE_MAX : c_int = 50; + pub static _SC_SIGQUEUE_MAX : c_int = 51; + pub static _SC_TIMER_MAX : c_int = 52; + pub static _SC_XBS5_ILP32_OFF32 : c_int = 122; + pub static _SC_XBS5_ILP32_OFFBIG : c_int = 123; + pub static _SC_XBS5_LP64_OFF64 : c_int = 124; + pub static _SC_XBS5_LPBIG_OFFBIG : c_int = 125; } pub mod posix01 { - pub static SIGTRAP : int = 5; - - pub static GLOB_APPEND : int = 0x0001; - pub static GLOB_DOOFFS : int = 0x0002; - pub static GLOB_ERR : int = 0x0004; - pub static GLOB_MARK : int = 0x0008; - pub static GLOB_NOCHECK : int = 0x0010; - pub static GLOB_NOSORT : int = 0x0020; - pub static GLOB_NOESCAPE : int = 0x2000; - - pub static GLOB_NOSPACE : int = -1; - pub static GLOB_ABORTED : int = -2; - pub static GLOB_NOMATCH : int = -3; - - pub static POSIX_MADV_NORMAL : int = 0; - pub static POSIX_MADV_RANDOM : int = 1; - pub static POSIX_MADV_SEQUENTIAL : int = 2; - pub static POSIX_MADV_WILLNEED : int = 3; - pub static POSIX_MADV_DONTNEED : int = 4; - - pub static _SC_IOV_MAX : int = 56; - pub static _SC_GETGR_R_SIZE_MAX : int = 70; - pub static _SC_GETPW_R_SIZE_MAX : int = 71; - pub static _SC_LOGIN_NAME_MAX : int = 73; - pub static _SC_MQ_PRIO_MAX : int = 75; - pub static _SC_THREAD_ATTR_STACKADDR : int = 82; - pub static _SC_THREAD_ATTR_STACKSIZE : int = 83; - pub static _SC_THREAD_DESTRUCTOR_ITERATIONS : int = 85; - pub static _SC_THREAD_KEYS_MAX : int = 86; - pub static _SC_THREAD_PRIO_INHERIT : int = 87; - pub static _SC_THREAD_PRIO_PROTECT : int = 88; - pub static _SC_THREAD_PRIORITY_SCHEDULING : int = 89; - pub static _SC_THREAD_PROCESS_SHARED : int = 90; - pub static _SC_THREAD_SAFE_FUNCTIONS : int = 91; - pub static _SC_THREAD_STACK_MIN : int = 93; - pub static _SC_THREAD_THREADS_MAX : int = 94; - pub static _SC_THREADS : int = 96; - pub static _SC_TTY_NAME_MAX : int = 101; - pub static _SC_ATEXIT_MAX : int = 107; - pub static _SC_XOPEN_CRYPT : int = 108; - pub static _SC_XOPEN_ENH_I18N : int = 109; - pub static _SC_XOPEN_LEGACY : int = 110; - pub static _SC_XOPEN_REALTIME : int = 111; - pub static _SC_XOPEN_REALTIME_THREADS : int = 112; - pub static _SC_XOPEN_SHM : int = 113; - pub static _SC_XOPEN_UNIX : int = 115; - pub static _SC_XOPEN_VERSION : int = 116; - pub static _SC_XOPEN_XCU_VERSION : int = 121; + use libc::types::os::arch::c95::c_int; + + pub static SIGTRAP : c_int = 5; + + pub static GLOB_APPEND : c_int = 0x0001; + pub static GLOB_DOOFFS : c_int = 0x0002; + pub static GLOB_ERR : c_int = 0x0004; + pub static GLOB_MARK : c_int = 0x0008; + pub static GLOB_NOCHECK : c_int = 0x0010; + pub static GLOB_NOSORT : c_int = 0x0020; + pub static GLOB_NOESCAPE : c_int = 0x2000; + + pub static GLOB_NOSPACE : c_int = -1; + pub static GLOB_ABORTED : c_int = -2; + pub static GLOB_NOMATCH : c_int = -3; + + pub static POSIX_MADV_NORMAL : c_int = 0; + pub static POSIX_MADV_RANDOM : c_int = 1; + pub static POSIX_MADV_SEQUENTIAL : c_int = 2; + pub static POSIX_MADV_WILLNEED : c_int = 3; + pub static POSIX_MADV_DONTNEED : c_int = 4; + + pub static _SC_IOV_MAX : c_int = 56; + pub static _SC_GETGR_R_SIZE_MAX : c_int = 70; + pub static _SC_GETPW_R_SIZE_MAX : c_int = 71; + pub static _SC_LOGIN_NAME_MAX : c_int = 73; + pub static _SC_MQ_PRIO_MAX : c_int = 75; + pub static _SC_THREAD_ATTR_STACKADDR : c_int = 82; + pub static _SC_THREAD_ATTR_STACKSIZE : c_int = 83; + pub static _SC_THREAD_DESTRUCTOR_ITERATIONS : c_int = 85; + pub static _SC_THREAD_KEYS_MAX : c_int = 86; + pub static _SC_THREAD_PRIO_INHERIT : c_int = 87; + pub static _SC_THREAD_PRIO_PROTECT : c_int = 88; + pub static _SC_THREAD_PRIORITY_SCHEDULING : c_int = 89; + pub static _SC_THREAD_PROCESS_SHARED : c_int = 90; + pub static _SC_THREAD_SAFE_FUNCTIONS : c_int = 91; + pub static _SC_THREAD_STACK_MIN : c_int = 93; + pub static _SC_THREAD_THREADS_MAX : c_int = 94; + pub static _SC_THREADS : c_int = 96; + pub static _SC_TTY_NAME_MAX : c_int = 101; + pub static _SC_ATEXIT_MAX : c_int = 107; + pub static _SC_XOPEN_CRYPT : c_int = 108; + pub static _SC_XOPEN_ENH_I18N : c_int = 109; + pub static _SC_XOPEN_LEGACY : c_int = 110; + pub static _SC_XOPEN_REALTIME : c_int = 111; + pub static _SC_XOPEN_REALTIME_THREADS : c_int = 112; + pub static _SC_XOPEN_SHM : c_int = 113; + pub static _SC_XOPEN_UNIX : c_int = 115; + pub static _SC_XOPEN_VERSION : c_int = 116; + pub static _SC_XOPEN_XCU_VERSION : c_int = 121; } pub mod posix08 { } pub mod bsd44 { - pub static MADV_NORMAL : int = 0; - pub static MADV_RANDOM : int = 1; - pub static MADV_SEQUENTIAL : int = 2; - pub static MADV_WILLNEED : int = 3; - pub static MADV_DONTNEED : int = 4; - pub static MADV_FREE : int = 5; - pub static MADV_ZERO_WIRED_PAGES : int = 6; - pub static MADV_FREE_REUSABLE : int = 7; - pub static MADV_FREE_REUSE : int = 8; - pub static MADV_CAN_REUSE : int = 9; - - pub static MINCORE_INCORE : int = 0x1; - pub static MINCORE_REFERENCED : int = 0x2; - pub static MINCORE_MODIFIED : int = 0x4; - pub static MINCORE_REFERENCED_OTHER : int = 0x8; - pub static MINCORE_MODIFIED_OTHER : int = 0x10; + use libc::types::os::arch::c95::c_int; + + pub static MADV_NORMAL : c_int = 0; + pub static MADV_RANDOM : c_int = 1; + pub static MADV_SEQUENTIAL : c_int = 2; + pub static MADV_WILLNEED : c_int = 3; + pub static MADV_DONTNEED : c_int = 4; + pub static MADV_FREE : c_int = 5; + pub static MADV_ZERO_WIRED_PAGES : c_int = 6; + pub static MADV_FREE_REUSABLE : c_int = 7; + pub static MADV_FREE_REUSE : c_int = 8; + pub static MADV_CAN_REUSE : c_int = 9; + + pub static MINCORE_INCORE : c_int = 0x1; + pub static MINCORE_REFERENCED : c_int = 0x2; + pub static MINCORE_MODIFIED : c_int = 0x4; + pub static MINCORE_REFERENCED_OTHER : c_int = 0x8; + pub static MINCORE_MODIFIED_OTHER : c_int = 0x10; } pub mod extra { - pub static O_DSYNC : int = 4194304; - pub static O_SYNC : int = 128; - pub static F_FULLFSYNC : int = 51; - - pub static MAP_COPY : int = 0x0002; - pub static MAP_RENAME : int = 0x0020; - pub static MAP_NORESERVE : int = 0x0040; - pub static MAP_NOEXTEND : int = 0x0100; - pub static MAP_HASSEMAPHORE : int = 0x0200; - pub static MAP_NOCACHE : int = 0x0400; - pub static MAP_JIT : int = 0x0800; + use libc::types::os::arch::c95::c_int; + + pub static O_DSYNC : c_int = 4194304; + pub static O_SYNC : c_int = 128; + pub static F_FULLFSYNC : c_int = 51; + + pub static MAP_COPY : c_int = 0x0002; + pub static MAP_RENAME : c_int = 0x0020; + pub static MAP_NORESERVE : c_int = 0x0040; + pub static MAP_NOEXTEND : c_int = 0x0100; + pub static MAP_HASSEMAPHORE : c_int = 0x0200; + pub static MAP_NOCACHE : c_int = 0x0400; + pub static MAP_JIT : c_int = 0x0800; } } } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 1ceb22b20ca..e6b92c0ccc3 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -758,7 +758,7 @@ pub fn list_dir(p: &Path) -> ~[~str] { FindFirstFileW( path_ptr, ::cast::transmute(wfd_ptr)); - if find_handle as int != INVALID_HANDLE_VALUE { + if find_handle as libc::c_int != INVALID_HANDLE_VALUE { let mut more_files = 1 as libc::c_int; while more_files != 0 { let fp_buf = rust_list_dir_wfd_fp_buf(wfd_ptr); -- cgit 1.4.1-3-g733a5 From d9f6dd263c16a21108c27dbf15a3d59a43a5b490 Mon Sep 17 00:00:00 2001 From: James Miller Date: Sun, 23 Jun 2013 16:13:29 +1200 Subject: Set #[no_drop_flag] on Rc and AtomicOption. Add Test --- src/libextra/rc.rs | 20 ++++++++++++-------- src/librustc/middle/ty.rs | 2 +- src/libstd/unstable/atomics.rs | 1 + src/test/run-pass/attr-no-drop-flag-size.rs | 25 +++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 src/test/run-pass/attr-no-drop-flag-size.rs (limited to 'src/libstd') diff --git a/src/libextra/rc.rs b/src/libextra/rc.rs index b90b0983dc2..555cceb5b44 100644 --- a/src/libextra/rc.rs +++ b/src/libextra/rc.rs @@ -70,10 +70,12 @@ impl Rc { impl Drop for Rc { fn finalize(&self) { unsafe { - (*self.ptr).count -= 1; - if (*self.ptr).count == 0 { - ptr::replace_ptr(self.ptr, intrinsics::uninit()); - free(self.ptr as *c_void) + if self.ptr.is_not_null() { + (*self.ptr).count -= 1; + if (*self.ptr).count == 0 { + ptr::replace_ptr(self.ptr, intrinsics::uninit()); + free(self.ptr as *c_void) + } } } } @@ -220,10 +222,12 @@ impl RcMut { impl Drop for RcMut { fn finalize(&self) { unsafe { - (*self.ptr).count -= 1; - if (*self.ptr).count == 0 { - ptr::replace_ptr(self.ptr, uninit()); - free(self.ptr as *c_void) + if self.ptr.is_not_null() { + (*self.ptr).count -= 1; + if (*self.ptr).count == 0 { + ptr::replace_ptr(self.ptr, uninit()); + free(self.ptr as *c_void) + } } } } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 424307502f2..d5a2ed7dbd0 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3883,7 +3883,7 @@ impl DtorKind { pub fn ty_dtor(cx: ctxt, struct_id: def_id) -> DtorKind { match cx.destructor_for_type.find(&struct_id) { Some(&method_def_id) => { - let flag = has_attr(cx, struct_id, "no_drop_flag"); + let flag = !has_attr(cx, struct_id, "no_drop_flag"); TraitDtor(method_def_id, flag) } diff --git a/src/libstd/unstable/atomics.rs b/src/libstd/unstable/atomics.rs index 6e7a7e2b129..7a3a5f51d35 100644 --- a/src/libstd/unstable/atomics.rs +++ b/src/libstd/unstable/atomics.rs @@ -62,6 +62,7 @@ pub struct AtomicPtr { /** * An owned atomic pointer. Ensures that only a single reference to the data is held at any time. */ +#[no_drop_flag] pub struct AtomicOption { priv p: *mut c_void } diff --git a/src/test/run-pass/attr-no-drop-flag-size.rs b/src/test/run-pass/attr-no-drop-flag-size.rs new file mode 100644 index 00000000000..e6f05970cce --- /dev/null +++ b/src/test/run-pass/attr-no-drop-flag-size.rs @@ -0,0 +1,25 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::sys::size_of; + +#[no_drop_flag] +struct Test { + a: T +} + +#[unsafe_destructor] +impl Drop for Test { + fn finalize(&self) { } +} + +fn main() { + assert_eq!(size_of::(), size_of::>()); +} -- cgit 1.4.1-3-g733a5 From caa50ce15d8ed8f0d50c9049053a5e2cd5a0d701 Mon Sep 17 00:00:00 2001 From: James Miller Date: Tue, 25 Jun 2013 17:08:26 +1200 Subject: Remove stage0 cfgs --- src/libstd/iterator.rs | 5 ---- src/libstd/unstable/intrinsics.rs | 50 --------------------------------------- src/libstd/vec.rs | 2 -- 3 files changed, 57 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index d96191f296d..9177ecabed6 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -43,7 +43,6 @@ pub trait Iterator { /// Return a lower bound and upper bound on the remaining length of the iterator. /// /// The common use case for the estimate is pre-allocating space to store the results. - #[cfg(not(stage0))] fn size_hint(&self) -> (Option, Option) { (None, None) } } @@ -610,7 +609,6 @@ impl, U: Iterator> Iterator for ChainIterator { } #[inline] - #[cfg(not(stage0))] fn size_hint(&self) -> (Option, Option) { let (a_lower, a_upper) = self.a.size_hint(); let (b_lower, b_upper) = self.b.size_hint(); @@ -664,7 +662,6 @@ impl<'self, A, B, T: Iterator> Iterator for MapIterator<'self, A, B, T> { } #[inline] - #[cfg(not(stage0))] fn size_hint(&self) -> (Option, Option) { self.iter.size_hint() } @@ -690,7 +687,6 @@ impl<'self, A, T: Iterator> Iterator for FilterIterator<'self, A, T> { } #[inline] - #[cfg(not(stage0))] fn size_hint(&self) -> (Option, Option) { let (_, upper) = self.iter.size_hint(); (None, upper) // can't know a lower bound, due to the predicate @@ -716,7 +712,6 @@ impl<'self, A, B, T: Iterator> Iterator for FilterMapIterator<'self, A, B, } #[inline] - #[cfg(not(stage0))] fn size_hint(&self) -> (Option, Option) { let (_, upper) = self.iter.size_hint(); (None, upper) // can't know a lower bound, due to the predicate diff --git a/src/libstd/unstable/intrinsics.rs b/src/libstd/unstable/intrinsics.rs index c38b013a75a..109f665e41d 100644 --- a/src/libstd/unstable/intrinsics.rs +++ b/src/libstd/unstable/intrinsics.rs @@ -42,9 +42,7 @@ pub extern "rust-intrinsic" { /// Atomic compare and exchange, release ordering. pub fn atomic_cxchg_rel(dst: &mut int, old: int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_cxchg_acqrel(dst: &mut int, old: int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_cxchg_relaxed(dst: &mut int, old: int, src: int) -> int; @@ -53,7 +51,6 @@ pub extern "rust-intrinsic" { /// Atomic load, acquire ordering. pub fn atomic_load_acq(src: &int) -> int; - #[cfg(not(stage0))] pub fn atomic_load_relaxed(src: &int) -> int; /// Atomic store, sequentially consistent. @@ -61,7 +58,6 @@ pub extern "rust-intrinsic" { /// Atomic store, release ordering. pub fn atomic_store_rel(dst: &mut int, val: int); - #[cfg(not(stage0))] pub fn atomic_store_relaxed(dst: &mut int, val: int); /// Atomic exchange, sequentially consistent. @@ -70,9 +66,7 @@ pub extern "rust-intrinsic" { pub fn atomic_xchg_acq(dst: &mut int, src: int) -> int; /// Atomic exchange, release ordering. pub fn atomic_xchg_rel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_xchg_acqrel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_xchg_relaxed(dst: &mut int, src: int) -> int; /// Atomic addition, sequentially consistent. @@ -81,9 +75,7 @@ pub extern "rust-intrinsic" { pub fn atomic_xadd_acq(dst: &mut int, src: int) -> int; /// Atomic addition, release ordering. pub fn atomic_xadd_rel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_xadd_acqrel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_xadd_relaxed(dst: &mut int, src: int) -> int; /// Atomic subtraction, sequentially consistent. @@ -92,97 +84,55 @@ pub extern "rust-intrinsic" { pub fn atomic_xsub_acq(dst: &mut int, src: int) -> int; /// Atomic subtraction, release ordering. pub fn atomic_xsub_rel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_xsub_acqrel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_xsub_relaxed(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_and(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_and_acq(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_and_rel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_and_acqrel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_and_relaxed(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_nand(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_nand_acq(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_nand_rel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_nand_acqrel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_nand_relaxed(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_or(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_or_acq(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_or_rel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_or_acqrel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_or_relaxed(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_xor(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_xor_acq(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_xor_rel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_xor_acqrel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_xor_relaxed(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_max(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_max_acq(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_max_rel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_max_acqrel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_max_relaxed(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_min(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_min_acq(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_min_rel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_min_acqrel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_min_relaxed(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_umin(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_umin_acq(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_umin_rel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_umin_acqrel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_umin_relaxed(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_umax(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_umax_acq(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_umax_rel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_umax_acqrel(dst: &mut int, src: int) -> int; - #[cfg(not(stage0))] pub fn atomic_umax_relaxed(dst: &mut int, src: int) -> int; /// The size of a type in bytes. diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 7b7a3020b93..e39dd262cd9 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -2446,7 +2446,6 @@ macro_rules! iterator { } #[inline] - #[cfg(not(stage0))] fn size_hint(&self) -> (Option, Option) { let exact = Some(((self.end as uint) - (self.ptr as uint)) / size_of::<$elem>()); (exact, exact) @@ -3929,7 +3928,6 @@ mod tests { } #[test] - #[cfg(not(stage0))] fn test_iterator() { use iterator::*; let xs = [1, 2, 5, 10, 11]; -- cgit 1.4.1-3-g733a5 From 6ad31ffb53f9620f9063cb441de9c7338dfbb4de Mon Sep 17 00:00:00 2001 From: James Miller Date: Tue, 25 Jun 2013 17:13:22 +1200 Subject: Warning police --- src/librustc/metadata/decoder.rs | 1 - src/librustc/middle/ty.rs | 2 +- src/librustc/middle/typeck/check/mod.rs | 2 +- src/librustc/middle/typeck/coherence.rs | 4 +--- src/librustc/util/ppaux.rs | 1 - src/libstd/to_str.rs | 2 -- src/libsyntax/parse/parser.rs | 2 +- 7 files changed, 4 insertions(+), 10 deletions(-) (limited to 'src/libstd') diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 9ace8677dab..db44ac5e442 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -35,7 +35,6 @@ use extra::ebml; use extra::serialize::Decodable; use syntax::ast_map; use syntax::attr; -use syntax::diagnostic::span_handler; use syntax::parse::token::{ident_interner, special_idents}; use syntax::print::pprust; use syntax::{ast, ast_util}; diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 90cd8a8665e..632874025e7 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -21,7 +21,7 @@ use middle::ty; use middle::subst::Subst; use middle::typeck; use middle; -use util::ppaux::{note_and_explain_region, bound_region_to_str, bound_region_ptr_to_str}; +use util::ppaux::{note_and_explain_region, bound_region_ptr_to_str}; use util::ppaux::{trait_store_to_str, ty_to_str, vstore_to_str}; use util::ppaux::{Repr, UserString}; use util::common::{indenter}; diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index fa7959c7872..76b7e651ff1 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -107,7 +107,7 @@ use middle::typeck::{isr_alist, lookup_def_ccx}; use middle::typeck::no_params; use middle::typeck::{require_same_types, method_map, vtable_map}; use util::common::{block_query, indenter, loop_query}; -use util::ppaux::{bound_region_to_str,bound_region_ptr_to_str}; +use util::ppaux::{bound_region_ptr_to_str}; use util::ppaux; diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 7ad27077cd8..ae62e768ea2 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -16,10 +16,8 @@ use core::prelude::*; -use driver; use metadata::csearch::{each_path, get_impl_trait}; use metadata::csearch::{get_impls_for_mod}; -use metadata::csearch; use metadata::cstore::{CStore, iter_crate_data}; use metadata::decoder::{dl_def, dl_field, dl_impl}; use middle::resolve::{Impl, MethodInfo}; @@ -39,7 +37,7 @@ use middle::typeck::infer::combine::Combine; use middle::typeck::infer::InferCtxt; use middle::typeck::infer::{new_infer_ctxt, resolve_ivar}; use middle::typeck::infer::{resolve_nested_tvar, resolve_type}; -use syntax::ast::{crate, def_id, def_mod, def_struct, def_trait, def_ty}; +use syntax::ast::{crate, def_id, def_mod, def_struct, def_ty}; use syntax::ast::{item, item_enum, item_impl, item_mod, item_struct}; use syntax::ast::{local_crate, method, trait_ref, ty_path}; use syntax::ast; diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index e25267f4441..3194df269c0 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -32,7 +32,6 @@ use syntax::parse::token; use syntax::print::pprust; use syntax::{ast, ast_util}; -use core::str; use core::vec; /// Produces a string suitable for debugging output. diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs index 9f812288621..2e5c3c01adf 100644 --- a/src/libstd/to_str.rs +++ b/src/libstd/to_str.rs @@ -18,11 +18,9 @@ use str::OwnedStr; use hashmap::HashMap; use hashmap::HashSet; use iterator::IteratorUtil; -use container::Map; use hash::Hash; use cmp::Eq; use vec::ImmutableVector; -use iterator::IteratorUtil; /// A generic trait for converting a value to a string pub trait ToStr { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index f2443f9e533..c9ef1a7a33c 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -60,7 +60,7 @@ use ast::{view_item_, view_item_extern_mod, view_item_use}; use ast::{view_path, view_path_glob, view_path_list, view_path_simple}; use ast::visibility; use ast; -use ast_util::{as_prec, ident_to_path, operator_prec}; +use ast_util::{as_prec, operator_prec}; use ast_util; use codemap::{span, BytePos, spanned, mk_sp}; use codemap; -- cgit 1.4.1-3-g733a5 From 122f25dd5e1dae124bdc8d3beeac55474d7a8ce5 Mon Sep 17 00:00:00 2001 From: James Miller Date: Tue, 25 Jun 2013 18:02:56 +1200 Subject: Add missing import to tests --- src/libstd/to_str.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libstd') diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs index 2e5c3c01adf..4d5bc0f8842 100644 --- a/src/libstd/to_str.rs +++ b/src/libstd/to_str.rs @@ -177,7 +177,7 @@ impl ToStr for @[A] { mod tests { use hashmap::HashMap; use hashmap::HashSet; - use container::Set; + use container::{Set,Map}; #[test] fn test_simple_types() { assert_eq!(1i.to_str(), ~"1"); -- cgit 1.4.1-3-g733a5 From 42b44b21b11ded0a7dbbe196b1c9d338ef33b614 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 10 Jun 2013 13:00:38 -0700 Subject: Rename all files with the 'rc' extension --- Makefile.in | 16 +- mk/tools.mk | 14 +- src/compiletest/compiletest.rc | 267 ----------------- src/compiletest/compiletest.rs | 267 +++++++++++++++++ src/libextra/extra.rs | 155 ++++++++++ src/libextra/std.rc | 155 ---------- src/librust/rust.rc | 255 ---------------- src/librust/rust.rs | 255 ++++++++++++++++ src/librustc/rustc.rc | 369 ----------------------- src/librustc/rustc.rs | 369 +++++++++++++++++++++++ src/librustdoc/rustdoc.rc | 162 ---------- src/librustdoc/rustdoc.rs | 162 ++++++++++ src/librusti/rusti.rc | 665 ----------------------------------------- src/librusti/rusti.rs | 665 +++++++++++++++++++++++++++++++++++++++++ src/librustpkg/rustpkg.rc | 474 ----------------------------- src/librustpkg/rustpkg.rs | 474 +++++++++++++++++++++++++++++ src/libstd/core.rc | 230 -------------- src/libstd/std.rs | 230 ++++++++++++++ src/libsyntax/syntax.rc | 99 ------ src/libsyntax/syntax.rs | 99 ++++++ 20 files changed, 2691 insertions(+), 2691 deletions(-) delete mode 100644 src/compiletest/compiletest.rc create mode 100644 src/compiletest/compiletest.rs create mode 100644 src/libextra/extra.rs delete mode 100644 src/libextra/std.rc delete mode 100644 src/librust/rust.rc create mode 100644 src/librust/rust.rs delete mode 100644 src/librustc/rustc.rc create mode 100644 src/librustc/rustc.rs delete mode 100644 src/librustdoc/rustdoc.rc create mode 100644 src/librustdoc/rustdoc.rs delete mode 100644 src/librusti/rusti.rc create mode 100644 src/librusti/rusti.rs delete mode 100644 src/librustpkg/rustpkg.rc create mode 100644 src/librustpkg/rustpkg.rs delete mode 100644 src/libstd/core.rc create mode 100644 src/libstd/std.rs delete mode 100644 src/libsyntax/syntax.rc create mode 100644 src/libsyntax/syntax.rs (limited to 'src/libstd') diff --git a/Makefile.in b/Makefile.in index baae56c4f40..fa6c7806581 100644 --- a/Makefile.in +++ b/Makefile.in @@ -239,29 +239,29 @@ $(foreach target,$(CFG_TARGET_TRIPLES),\ # Standard library variables ###################################################################### -STDLIB_CRATE := $(S)src/libstd/core.rc +STDLIB_CRATE := $(S)src/libstd/std.rs STDLIB_INPUTS := $(wildcard $(addprefix $(S)src/libstd/, \ - core.rc *.rs */*.rs */*/*rs */*/*/*rs)) + *.rs */*.rs */*/*rs */*/*/*rs)) ###################################################################### # Extra library variables ###################################################################### -EXTRALIB_CRATE := $(S)src/libextra/std.rc +EXTRALIB_CRATE := $(S)src/libextra/extra.rs EXTRALIB_INPUTS := $(wildcard $(addprefix $(S)src/libextra/, \ - std.rc *.rs */*.rs)) + *.rs */*.rs)) ###################################################################### # rustc crate variables ###################################################################### -COMPILER_CRATE := $(S)src/librustc/rustc.rc +COMPILER_CRATE := $(S)src/librustc/rustc.rs COMPILER_INPUTS := $(wildcard $(addprefix $(S)src/librustc/, \ - rustc.rc *.rs */*.rs */*/*.rs */*/*/*.rs)) + *.rs */*.rs */*/*.rs */*/*/*.rs)) -LIBSYNTAX_CRATE := $(S)src/libsyntax/syntax.rc +LIBSYNTAX_CRATE := $(S)src/libsyntax/syntax.rs LIBSYNTAX_INPUTS := $(wildcard $(addprefix $(S)src/libsyntax/, \ - syntax.rc *.rs */*.rs */*/*.rs)) + *.rs */*.rs */*/*.rs)) DRIVER_CRATE := $(S)src/driver/driver.rs diff --git a/mk/tools.mk b/mk/tools.mk index 8319d8d4e48..7b50441b3c7 100644 --- a/mk/tools.mk +++ b/mk/tools.mk @@ -12,23 +12,23 @@ # and host architectures # The test runner that runs the cfail/rfail/rpass and bxench tests -COMPILETEST_CRATE := $(S)src/compiletest/compiletest.rc -COMPILETEST_INPUTS := $(wildcard $(S)src/compiletest/*rs) +COMPILETEST_CRATE := $(S)src/compiletest/compiletest.rs +COMPILETEST_INPUTS := $(wildcard $(S)src/compiletest/*.rs) # Rustpkg, the package manager and build system -RUSTPKG_LIB := $(S)src/librustpkg/rustpkg.rc -RUSTPKG_INPUTS := $(wildcard $(S)src/librustpkg/*rs) +RUSTPKG_LIB := $(S)src/librustpkg/rustpkg.rs +RUSTPKG_INPUTS := $(wildcard $(S)src/librustpkg/*.rs) # Rustdoc, the documentation tool -RUSTDOC_LIB := $(S)src/librustdoc/rustdoc.rc +RUSTDOC_LIB := $(S)src/librustdoc/rustdoc.rs RUSTDOC_INPUTS := $(wildcard $(S)src/librustdoc/*.rs) # Rusti, the JIT REPL -RUSTI_LIB := $(S)src/librusti/rusti.rc +RUSTI_LIB := $(S)src/librusti/rusti.rs RUSTI_INPUTS := $(wildcard $(S)src/librusti/*.rs) # Rust, the convenience tool -RUST_LIB := $(S)src/librust/rust.rc +RUST_LIB := $(S)src/librust/rust.rs RUST_INPUTS := $(wildcard $(S)src/librust/*.rs) # FIXME: These are only built for the host arch. Eventually we'll diff --git a/src/compiletest/compiletest.rc b/src/compiletest/compiletest.rc deleted file mode 100644 index e8876c4851b..00000000000 --- a/src/compiletest/compiletest.rc +++ /dev/null @@ -1,267 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[crate_type = "bin"]; - -#[allow(non_camel_case_types)]; - -#[no_core]; // XXX: Remove after snapshot -#[no_std]; - -extern mod core(name = "std", vers = "0.7-pre"); -extern mod extra(name = "extra", vers = "0.7-pre"); - -use core::prelude::*; -use core::*; - -use extra::getopts; -use extra::test; - -use core::result::{Ok, Err}; - -use common::config; -use common::mode_run_pass; -use common::mode_run_fail; -use common::mode_compile_fail; -use common::mode_pretty; -use common::mode_debug_info; -use common::mode; -use util::logv; - -pub mod procsrv; -pub mod util; -pub mod header; -pub mod runtest; -pub mod common; -pub mod errors; - -mod std { - pub use core::cmp; - pub use core::str; - pub use core::sys; - pub use core::unstable; -} - -pub fn main() { - let args = os::args(); - let config = parse_config(args); - log_config(&config); - run_tests(&config); -} - -pub fn parse_config(args: ~[~str]) -> config { - let opts = - ~[getopts::reqopt("compile-lib-path"), - getopts::reqopt("run-lib-path"), - getopts::reqopt("rustc-path"), getopts::reqopt("src-base"), - getopts::reqopt("build-base"), getopts::reqopt("aux-base"), - getopts::reqopt("stage-id"), - getopts::reqopt("mode"), getopts::optflag("ignored"), - getopts::optopt("runtool"), getopts::optopt("rustcflags"), - getopts::optflag("verbose"), - getopts::optopt("logfile"), - getopts::optflag("jit"), - getopts::optflag("newrt"), - getopts::optopt("target"), - getopts::optopt("adb-path"), - getopts::optopt("adb-test-dir") - ]; - - assert!(!args.is_empty()); - let args_ = vec::tail(args); - let matches = - &match getopts::getopts(args_, opts) { - Ok(m) => m, - Err(f) => fail!(getopts::fail_str(f)) - }; - - fn opt_path(m: &getopts::Matches, nm: &str) -> Path { - Path(getopts::opt_str(m, nm)) - } - - config { - compile_lib_path: getopts::opt_str(matches, "compile-lib-path"), - run_lib_path: getopts::opt_str(matches, "run-lib-path"), - rustc_path: opt_path(matches, "rustc-path"), - src_base: opt_path(matches, "src-base"), - build_base: opt_path(matches, "build-base"), - aux_base: opt_path(matches, "aux-base"), - stage_id: getopts::opt_str(matches, "stage-id"), - mode: str_mode(getopts::opt_str(matches, "mode")), - run_ignored: getopts::opt_present(matches, "ignored"), - filter: - if !matches.free.is_empty() { - option::Some(copy matches.free[0]) - } else { option::None }, - logfile: getopts::opt_maybe_str(matches, "logfile").map(|s| Path(*s)), - runtool: getopts::opt_maybe_str(matches, "runtool"), - rustcflags: getopts::opt_maybe_str(matches, "rustcflags"), - jit: getopts::opt_present(matches, "jit"), - newrt: getopts::opt_present(matches, "newrt"), - target: opt_str2(getopts::opt_maybe_str(matches, "target")).to_str(), - adb_path: opt_str2(getopts::opt_maybe_str(matches, "adb-path")).to_str(), - adb_test_dir: - opt_str2(getopts::opt_maybe_str(matches, "adb-test-dir")).to_str(), - adb_device_status: - if (opt_str2(getopts::opt_maybe_str(matches, "target")) == - ~"arm-linux-androideabi") { - if (opt_str2(getopts::opt_maybe_str(matches, "adb-test-dir")) != - ~"(none)" && - opt_str2(getopts::opt_maybe_str(matches, "adb-test-dir")) != - ~"") { true } - else { false } - } else { false }, - verbose: getopts::opt_present(matches, "verbose") - } -} - -pub fn log_config(config: &config) { - let c = config; - logv(c, fmt!("configuration:")); - logv(c, fmt!("compile_lib_path: %s", config.compile_lib_path)); - logv(c, fmt!("run_lib_path: %s", config.run_lib_path)); - logv(c, fmt!("rustc_path: %s", config.rustc_path.to_str())); - logv(c, fmt!("src_base: %s", config.src_base.to_str())); - logv(c, fmt!("build_base: %s", config.build_base.to_str())); - logv(c, fmt!("stage_id: %s", config.stage_id)); - logv(c, fmt!("mode: %s", mode_str(config.mode))); - logv(c, fmt!("run_ignored: %b", config.run_ignored)); - logv(c, fmt!("filter: %s", opt_str(&config.filter))); - logv(c, fmt!("runtool: %s", opt_str(&config.runtool))); - logv(c, fmt!("rustcflags: %s", opt_str(&config.rustcflags))); - logv(c, fmt!("jit: %b", config.jit)); - logv(c, fmt!("newrt: %b", config.newrt)); - logv(c, fmt!("target: %s", config.target)); - logv(c, fmt!("adb_path: %s", config.adb_path)); - logv(c, fmt!("adb_test_dir: %s", config.adb_test_dir)); - logv(c, fmt!("adb_device_status: %b", config.adb_device_status)); - logv(c, fmt!("verbose: %b", config.verbose)); - logv(c, fmt!("\n")); -} - -pub fn opt_str<'a>(maybestr: &'a Option<~str>) -> &'a str { - match *maybestr { - option::None => "(none)", - option::Some(ref s) => { - let s: &'a str = *s; - s - } - } -} - -pub fn opt_str2(maybestr: Option<~str>) -> ~str { - match maybestr { None => ~"(none)", Some(s) => { s } } -} - -pub fn str_opt(maybestr: ~str) -> Option<~str> { - if maybestr != ~"(none)" { option::Some(maybestr) } else { option::None } -} - -pub fn str_mode(s: ~str) -> mode { - match s { - ~"compile-fail" => mode_compile_fail, - ~"run-fail" => mode_run_fail, - ~"run-pass" => mode_run_pass, - ~"pretty" => mode_pretty, - ~"debug-info" => mode_debug_info, - _ => fail!("invalid mode") - } -} - -pub fn mode_str(mode: mode) -> ~str { - match mode { - mode_compile_fail => ~"compile-fail", - mode_run_fail => ~"run-fail", - mode_run_pass => ~"run-pass", - mode_pretty => ~"pretty", - mode_debug_info => ~"debug-info", - } -} - -pub fn run_tests(config: &config) { - let opts = test_opts(config); - let tests = make_tests(config); - let res = test::run_tests_console(&opts, tests); - if !res { fail!("Some tests failed"); } -} - -pub fn test_opts(config: &config) -> test::TestOpts { - test::TestOpts { - filter: copy config.filter, - run_ignored: config.run_ignored, - logfile: copy config.logfile, - run_tests: true, - run_benchmarks: false, - save_results: option::None, - compare_results: option::None - } -} - -pub fn make_tests(config: &config) -> ~[test::TestDescAndFn] { - debug!("making tests from %s", - config.src_base.to_str()); - let mut tests = ~[]; - let dirs = os::list_dir_path(&config.src_base); - for dirs.iter().advance |file| { - let file = copy *file; - debug!("inspecting file %s", file.to_str()); - if is_test(config, file) { - tests.push(make_test(config, file)) - } - } - tests -} - -pub fn is_test(config: &config, testfile: &Path) -> bool { - // Pretty-printer does not work with .rc files yet - let valid_extensions = - match config.mode { - mode_pretty => ~[~".rs"], - _ => ~[~".rc", ~".rs"] - }; - let invalid_prefixes = ~[~".", ~"#", ~"~"]; - let name = testfile.filename().get(); - - let mut valid = false; - - for valid_extensions.iter().advance |ext| { - if name.ends_with(*ext) { valid = true; } - } - - for invalid_prefixes.iter().advance |pre| { - if name.starts_with(*pre) { valid = false; } - } - - return valid; -} - -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), - } -} - -pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName { - test::DynTestName(fmt!("[%s] %s", - mode_str(config.mode), - testfile.to_str())) -} - -pub fn make_test_closure(config: &config, testfile: &Path) -> test::TestFn { - use core::cell::Cell; - let config = Cell::new(copy *config); - let testfile = Cell::new(testfile.to_str()); - test::DynTestFn(|| { runtest::run(config.take(), testfile.take()) }) -} diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs new file mode 100644 index 00000000000..e8876c4851b --- /dev/null +++ b/src/compiletest/compiletest.rs @@ -0,0 +1,267 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[crate_type = "bin"]; + +#[allow(non_camel_case_types)]; + +#[no_core]; // XXX: Remove after snapshot +#[no_std]; + +extern mod core(name = "std", vers = "0.7-pre"); +extern mod extra(name = "extra", vers = "0.7-pre"); + +use core::prelude::*; +use core::*; + +use extra::getopts; +use extra::test; + +use core::result::{Ok, Err}; + +use common::config; +use common::mode_run_pass; +use common::mode_run_fail; +use common::mode_compile_fail; +use common::mode_pretty; +use common::mode_debug_info; +use common::mode; +use util::logv; + +pub mod procsrv; +pub mod util; +pub mod header; +pub mod runtest; +pub mod common; +pub mod errors; + +mod std { + pub use core::cmp; + pub use core::str; + pub use core::sys; + pub use core::unstable; +} + +pub fn main() { + let args = os::args(); + let config = parse_config(args); + log_config(&config); + run_tests(&config); +} + +pub fn parse_config(args: ~[~str]) -> config { + let opts = + ~[getopts::reqopt("compile-lib-path"), + getopts::reqopt("run-lib-path"), + getopts::reqopt("rustc-path"), getopts::reqopt("src-base"), + getopts::reqopt("build-base"), getopts::reqopt("aux-base"), + getopts::reqopt("stage-id"), + getopts::reqopt("mode"), getopts::optflag("ignored"), + getopts::optopt("runtool"), getopts::optopt("rustcflags"), + getopts::optflag("verbose"), + getopts::optopt("logfile"), + getopts::optflag("jit"), + getopts::optflag("newrt"), + getopts::optopt("target"), + getopts::optopt("adb-path"), + getopts::optopt("adb-test-dir") + ]; + + assert!(!args.is_empty()); + let args_ = vec::tail(args); + let matches = + &match getopts::getopts(args_, opts) { + Ok(m) => m, + Err(f) => fail!(getopts::fail_str(f)) + }; + + fn opt_path(m: &getopts::Matches, nm: &str) -> Path { + Path(getopts::opt_str(m, nm)) + } + + config { + compile_lib_path: getopts::opt_str(matches, "compile-lib-path"), + run_lib_path: getopts::opt_str(matches, "run-lib-path"), + rustc_path: opt_path(matches, "rustc-path"), + src_base: opt_path(matches, "src-base"), + build_base: opt_path(matches, "build-base"), + aux_base: opt_path(matches, "aux-base"), + stage_id: getopts::opt_str(matches, "stage-id"), + mode: str_mode(getopts::opt_str(matches, "mode")), + run_ignored: getopts::opt_present(matches, "ignored"), + filter: + if !matches.free.is_empty() { + option::Some(copy matches.free[0]) + } else { option::None }, + logfile: getopts::opt_maybe_str(matches, "logfile").map(|s| Path(*s)), + runtool: getopts::opt_maybe_str(matches, "runtool"), + rustcflags: getopts::opt_maybe_str(matches, "rustcflags"), + jit: getopts::opt_present(matches, "jit"), + newrt: getopts::opt_present(matches, "newrt"), + target: opt_str2(getopts::opt_maybe_str(matches, "target")).to_str(), + adb_path: opt_str2(getopts::opt_maybe_str(matches, "adb-path")).to_str(), + adb_test_dir: + opt_str2(getopts::opt_maybe_str(matches, "adb-test-dir")).to_str(), + adb_device_status: + if (opt_str2(getopts::opt_maybe_str(matches, "target")) == + ~"arm-linux-androideabi") { + if (opt_str2(getopts::opt_maybe_str(matches, "adb-test-dir")) != + ~"(none)" && + opt_str2(getopts::opt_maybe_str(matches, "adb-test-dir")) != + ~"") { true } + else { false } + } else { false }, + verbose: getopts::opt_present(matches, "verbose") + } +} + +pub fn log_config(config: &config) { + let c = config; + logv(c, fmt!("configuration:")); + logv(c, fmt!("compile_lib_path: %s", config.compile_lib_path)); + logv(c, fmt!("run_lib_path: %s", config.run_lib_path)); + logv(c, fmt!("rustc_path: %s", config.rustc_path.to_str())); + logv(c, fmt!("src_base: %s", config.src_base.to_str())); + logv(c, fmt!("build_base: %s", config.build_base.to_str())); + logv(c, fmt!("stage_id: %s", config.stage_id)); + logv(c, fmt!("mode: %s", mode_str(config.mode))); + logv(c, fmt!("run_ignored: %b", config.run_ignored)); + logv(c, fmt!("filter: %s", opt_str(&config.filter))); + logv(c, fmt!("runtool: %s", opt_str(&config.runtool))); + logv(c, fmt!("rustcflags: %s", opt_str(&config.rustcflags))); + logv(c, fmt!("jit: %b", config.jit)); + logv(c, fmt!("newrt: %b", config.newrt)); + logv(c, fmt!("target: %s", config.target)); + logv(c, fmt!("adb_path: %s", config.adb_path)); + logv(c, fmt!("adb_test_dir: %s", config.adb_test_dir)); + logv(c, fmt!("adb_device_status: %b", config.adb_device_status)); + logv(c, fmt!("verbose: %b", config.verbose)); + logv(c, fmt!("\n")); +} + +pub fn opt_str<'a>(maybestr: &'a Option<~str>) -> &'a str { + match *maybestr { + option::None => "(none)", + option::Some(ref s) => { + let s: &'a str = *s; + s + } + } +} + +pub fn opt_str2(maybestr: Option<~str>) -> ~str { + match maybestr { None => ~"(none)", Some(s) => { s } } +} + +pub fn str_opt(maybestr: ~str) -> Option<~str> { + if maybestr != ~"(none)" { option::Some(maybestr) } else { option::None } +} + +pub fn str_mode(s: ~str) -> mode { + match s { + ~"compile-fail" => mode_compile_fail, + ~"run-fail" => mode_run_fail, + ~"run-pass" => mode_run_pass, + ~"pretty" => mode_pretty, + ~"debug-info" => mode_debug_info, + _ => fail!("invalid mode") + } +} + +pub fn mode_str(mode: mode) -> ~str { + match mode { + mode_compile_fail => ~"compile-fail", + mode_run_fail => ~"run-fail", + mode_run_pass => ~"run-pass", + mode_pretty => ~"pretty", + mode_debug_info => ~"debug-info", + } +} + +pub fn run_tests(config: &config) { + let opts = test_opts(config); + let tests = make_tests(config); + let res = test::run_tests_console(&opts, tests); + if !res { fail!("Some tests failed"); } +} + +pub fn test_opts(config: &config) -> test::TestOpts { + test::TestOpts { + filter: copy config.filter, + run_ignored: config.run_ignored, + logfile: copy config.logfile, + run_tests: true, + run_benchmarks: false, + save_results: option::None, + compare_results: option::None + } +} + +pub fn make_tests(config: &config) -> ~[test::TestDescAndFn] { + debug!("making tests from %s", + config.src_base.to_str()); + let mut tests = ~[]; + let dirs = os::list_dir_path(&config.src_base); + for dirs.iter().advance |file| { + let file = copy *file; + debug!("inspecting file %s", file.to_str()); + if is_test(config, file) { + tests.push(make_test(config, file)) + } + } + tests +} + +pub fn is_test(config: &config, testfile: &Path) -> bool { + // Pretty-printer does not work with .rc files yet + let valid_extensions = + match config.mode { + mode_pretty => ~[~".rs"], + _ => ~[~".rc", ~".rs"] + }; + let invalid_prefixes = ~[~".", ~"#", ~"~"]; + let name = testfile.filename().get(); + + let mut valid = false; + + for valid_extensions.iter().advance |ext| { + if name.ends_with(*ext) { valid = true; } + } + + for invalid_prefixes.iter().advance |pre| { + if name.starts_with(*pre) { valid = false; } + } + + return valid; +} + +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), + } +} + +pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName { + test::DynTestName(fmt!("[%s] %s", + mode_str(config.mode), + testfile.to_str())) +} + +pub fn make_test_closure(config: &config, testfile: &Path) -> test::TestFn { + use core::cell::Cell; + let config = Cell::new(copy *config); + let testfile = Cell::new(testfile.to_str()); + test::DynTestFn(|| { runtest::run(config.take(), testfile.take()) }) +} diff --git a/src/libextra/extra.rs b/src/libextra/extra.rs new file mode 100644 index 00000000000..11aebdf467f --- /dev/null +++ b/src/libextra/extra.rs @@ -0,0 +1,155 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +/*! + +Rust extras. + +The `extra` crate is a set of useful modules for a variety of +purposes, including collections, numerics, I/O, serialization, +and concurrency. + +Rust extras are part of the standard Rust distribution. + +*/ + +#[link(name = "extra", + vers = "0.7-pre", + uuid = "122bed0b-c19b-4b82-b0b7-7ae8aead7297", + url = "https://github.com/mozilla/rust/tree/master/src/libextra")]; + +#[comment = "Rust extras"]; +#[license = "MIT/ASL2"]; +#[crate_type = "lib"]; + +#[deny(non_camel_case_types)]; +#[deny(missing_doc)]; + +#[no_std]; + +extern mod core(name = "std", vers = "0.7-pre"); + +use core::str::{StrSlice, OwnedStr}; + +pub use core::os; + +pub mod uv_ll; + +// General io and system-services modules + +pub mod net; +pub mod net_ip; +pub mod net_tcp; +pub mod net_url; + +// libuv modules +pub mod uv; +pub mod uv_iotask; +pub mod uv_global_loop; + + +// Utility modules + +pub mod c_vec; +pub mod timer; +pub mod io_util; +pub mod rc; + +// Concurrency + +pub mod sync; +pub mod arc; +pub mod comm; +pub mod future; +pub mod task_pool; +pub mod flatpipes; + +// Collections + +pub mod bitv; +pub mod deque; +pub mod fun_treemap; +pub mod list; +pub mod priority_queue; +pub mod rope; +pub mod smallintmap; + +pub mod sort; + +pub mod dlist; +pub mod treemap; + +// Crypto +#[path="crypto/digest.rs"] +pub mod digest; +#[path="crypto/sha1.rs"] +pub mod sha1; +#[path="crypto/sha2.rs"] +pub mod sha2; + +// And ... other stuff + +pub mod ebml; +pub mod dbg; +pub mod getopts; +pub mod json; +pub mod md4; +pub mod tempfile; +pub mod term; +pub mod time; +pub mod arena; +pub mod par; +pub mod base64; +pub mod rl; +pub mod workcache; +#[path="num/bigint.rs"] +pub mod bigint; +#[path="num/rational.rs"] +pub mod rational; +#[path="num/complex.rs"] +pub mod complex; +pub mod stats; +pub mod semver; +pub mod fileinput; +pub mod flate; + +#[cfg(unicode)] +mod unicode; + +#[path="terminfo/terminfo.rs"] +pub mod terminfo; + +// Compiler support modules + +pub mod test; +pub mod serialize; + +// A curious inner-module that's not exported that contains the binding +// 'extra' so that macro-expanded references to extra::serialize and such +// can be resolved within libextra. +#[doc(hidden)] +pub mod std { + pub use serialize; + pub use test; + + // For bootstrapping. + pub use core::clone; + pub use core::condition; + pub use core::cmp; + pub use core::sys; + pub use core::unstable; + pub use core::str; + pub use core::os; +} +#[doc(hidden)] +pub mod extra { + pub use serialize; + pub use test; +} diff --git a/src/libextra/std.rc b/src/libextra/std.rc deleted file mode 100644 index 11aebdf467f..00000000000 --- a/src/libextra/std.rc +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -/*! - -Rust extras. - -The `extra` crate is a set of useful modules for a variety of -purposes, including collections, numerics, I/O, serialization, -and concurrency. - -Rust extras are part of the standard Rust distribution. - -*/ - -#[link(name = "extra", - vers = "0.7-pre", - uuid = "122bed0b-c19b-4b82-b0b7-7ae8aead7297", - url = "https://github.com/mozilla/rust/tree/master/src/libextra")]; - -#[comment = "Rust extras"]; -#[license = "MIT/ASL2"]; -#[crate_type = "lib"]; - -#[deny(non_camel_case_types)]; -#[deny(missing_doc)]; - -#[no_std]; - -extern mod core(name = "std", vers = "0.7-pre"); - -use core::str::{StrSlice, OwnedStr}; - -pub use core::os; - -pub mod uv_ll; - -// General io and system-services modules - -pub mod net; -pub mod net_ip; -pub mod net_tcp; -pub mod net_url; - -// libuv modules -pub mod uv; -pub mod uv_iotask; -pub mod uv_global_loop; - - -// Utility modules - -pub mod c_vec; -pub mod timer; -pub mod io_util; -pub mod rc; - -// Concurrency - -pub mod sync; -pub mod arc; -pub mod comm; -pub mod future; -pub mod task_pool; -pub mod flatpipes; - -// Collections - -pub mod bitv; -pub mod deque; -pub mod fun_treemap; -pub mod list; -pub mod priority_queue; -pub mod rope; -pub mod smallintmap; - -pub mod sort; - -pub mod dlist; -pub mod treemap; - -// Crypto -#[path="crypto/digest.rs"] -pub mod digest; -#[path="crypto/sha1.rs"] -pub mod sha1; -#[path="crypto/sha2.rs"] -pub mod sha2; - -// And ... other stuff - -pub mod ebml; -pub mod dbg; -pub mod getopts; -pub mod json; -pub mod md4; -pub mod tempfile; -pub mod term; -pub mod time; -pub mod arena; -pub mod par; -pub mod base64; -pub mod rl; -pub mod workcache; -#[path="num/bigint.rs"] -pub mod bigint; -#[path="num/rational.rs"] -pub mod rational; -#[path="num/complex.rs"] -pub mod complex; -pub mod stats; -pub mod semver; -pub mod fileinput; -pub mod flate; - -#[cfg(unicode)] -mod unicode; - -#[path="terminfo/terminfo.rs"] -pub mod terminfo; - -// Compiler support modules - -pub mod test; -pub mod serialize; - -// A curious inner-module that's not exported that contains the binding -// 'extra' so that macro-expanded references to extra::serialize and such -// can be resolved within libextra. -#[doc(hidden)] -pub mod std { - pub use serialize; - pub use test; - - // For bootstrapping. - pub use core::clone; - pub use core::condition; - pub use core::cmp; - pub use core::sys; - pub use core::unstable; - pub use core::str; - pub use core::os; -} -#[doc(hidden)] -pub mod extra { - pub use serialize; - pub use test; -} diff --git a/src/librust/rust.rc b/src/librust/rust.rc deleted file mode 100644 index 68427745ff5..00000000000 --- a/src/librust/rust.rc +++ /dev/null @@ -1,255 +0,0 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// rust - central access to other rust tools -// FIXME #2238 Make commands run and test emit proper file endings on windows -// FIXME #2238 Make run only accept source that emits an executable - -#[link(name = "rust", - vers = "0.7-pre", - uuid = "4a24da33-5cc8-4037-9352-2cbe9bd9d27c", - url = "https://github.com/mozilla/rust/tree/master/src/rust")]; - -#[license = "MIT/ASL2"]; -#[crate_type = "lib"]; - -#[no_std]; - -extern mod core(name = "std"); - -extern mod rustpkg; -extern mod rustdoc; -extern mod rusti; -extern mod rustc; - -use core::prelude::*; - -use core::io; -use core::os; -use core::run; -use core::libc::exit; - -// For bootstrapping. -mod std { - pub use core::os; - pub use core::str; - pub use core::unstable; -} - -enum ValidUsage { - Valid(int), Invalid -} - -impl ValidUsage { - fn is_valid(&self) -> bool { - match *self { - Valid(_) => true, - Invalid => false - } - } -} - -enum Action<'self> { - Call(&'self fn(args: &[~str]) -> ValidUsage), - CallMain(&'static str, &'self fn()), -} - -enum UsageSource<'self> { - UsgStr(&'self str), - UsgCall(&'self fn()), -} - -struct Command<'self> { - cmd: &'self str, - action: Action<'self>, - usage_line: &'self str, - usage_full: UsageSource<'self>, -} - -static commands: &'static [Command<'static>] = &[ - Command{ - cmd: "build", - action: CallMain("rustc", rustc::main), - usage_line: "compile rust source files", - usage_full: UsgCall(rustc_help), - }, - Command{ - cmd: "run", - action: Call(cmd_run), - usage_line: "build an executable, and run it", - usage_full: UsgStr( - "The run command is an shortcut for the command line \n\ - \"rustc -o ~ && ./~ [...]\".\ - \n\nUsage:\trust run [...]" - ) - }, - Command{ - cmd: "test", - action: Call(cmd_test), - usage_line: "build a test executable, and run it", - usage_full: UsgStr( - "The test command is an shortcut for the command line \n\ - \"rustc --test -o test~ && \ - ./test~\"\n\nUsage:\trust test " - ) - }, - Command{ - cmd: "doc", - action: CallMain("rustdoc", rustdoc::main), - usage_line: "generate documentation from doc comments", - usage_full: UsgCall(rustdoc::config::usage), - }, - Command{ - cmd: "pkg", - action: CallMain("rustpkg", rustpkg::main), - usage_line: "download, build, install rust packages", - usage_full: UsgCall(rustpkg::usage::general), - }, - Command{ - cmd: "sketch", - action: CallMain("rusti", rusti::main), - usage_line: "run a rust interpreter", - usage_full: UsgStr("\nUsage:\trusti"), - }, - Command{ - cmd: "help", - action: Call(cmd_help), - usage_line: "show detailed usage of a command", - usage_full: UsgStr( - "The help command displays the usage text of another command.\n\ - The text is either build in, or provided by the corresponding \ - program.\n\nUsage:\trust help " - ) - } -]; - -fn rustc_help() { - rustc::usage(copy os::args()[0]) -} - -fn find_cmd(command_string: &str) -> Option { - do commands.iter().find_ |command| { - command.cmd == command_string - }.map_consume(|x| copy *x) -} - -fn cmd_help(args: &[~str]) -> ValidUsage { - fn print_usage(command_string: ~str) -> ValidUsage { - match find_cmd(command_string) { - Some(command) => { - match command.action { - CallMain(prog, _) => io::println(fmt!( - "The %s command is an alias for the %s program.", - command.cmd, prog)), - _ => () - } - match command.usage_full { - UsgStr(msg) => io::println(fmt!("%s\n", msg)), - UsgCall(f) => f(), - } - Valid(0) - }, - None => Invalid - } - } - - match args { - [ref command_string] => print_usage(copy *command_string), - _ => Invalid - } -} - -fn cmd_test(args: &[~str]) -> ValidUsage { - match args { - [ref filename] => { - let test_exec = Path(*filename).filestem().unwrap() + "test~"; - invoke("rustc", &[~"--test", filename.to_owned(), - ~"-o", test_exec.to_owned()], rustc::main); - let exit_code = run::process_status(~"./" + test_exec, []); - Valid(exit_code) - } - _ => Invalid - } -} - -fn cmd_run(args: &[~str]) -> ValidUsage { - match args { - [ref filename, ..prog_args] => { - let exec = Path(*filename).filestem().unwrap() + "~"; - invoke("rustc", &[filename.to_owned(), ~"-o", exec.to_owned()], - rustc::main); - let exit_code = run::process_status(~"./"+exec, prog_args); - Valid(exit_code) - } - _ => Invalid - } -} - -fn invoke(prog: &str, args: &[~str], f: &fn()) { - let mut osargs = ~[prog.to_owned()]; - osargs.push_all_move(args.to_owned()); - os::set_args(osargs); - f(); -} - -fn do_command(command: &Command, args: &[~str]) -> ValidUsage { - match command.action { - Call(f) => f(args), - CallMain(prog, f) => { - invoke(prog, args, f); - Valid(0) - } - } -} - -fn usage() { - static indent: uint = 8; - - io::print( - "The rust tool is a convenience for managing rust source code.\n\ - It acts as a shortcut for programs of the rust tool chain.\n\ - \n\ - Usage:\trust [arguments]\n\ - \n\ - The commands are:\n\ - \n" - ); - - for commands.iter().advance |command| { - let padding = " ".repeat(indent - command.cmd.len()); - io::println(fmt!(" %s%s%s", - command.cmd, padding, command.usage_line)); - } - - io::print( - "\n\ - Use \"rust help \" for more information about a command.\n\ - \n" - ); - -} - -pub fn main() { - let os_args = os::args(); - let args = os_args.tail(); - - if !args.is_empty() { - let r = find_cmd(*args.head()); - for r.iter().advance |command| { - let result = do_command(command, args.tail()); - match result { - Valid(exit_code) => unsafe { exit(exit_code.to_i32()) }, - _ => loop - } - } - } - - usage(); -} diff --git a/src/librust/rust.rs b/src/librust/rust.rs new file mode 100644 index 00000000000..68427745ff5 --- /dev/null +++ b/src/librust/rust.rs @@ -0,0 +1,255 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// rust - central access to other rust tools +// FIXME #2238 Make commands run and test emit proper file endings on windows +// FIXME #2238 Make run only accept source that emits an executable + +#[link(name = "rust", + vers = "0.7-pre", + uuid = "4a24da33-5cc8-4037-9352-2cbe9bd9d27c", + url = "https://github.com/mozilla/rust/tree/master/src/rust")]; + +#[license = "MIT/ASL2"]; +#[crate_type = "lib"]; + +#[no_std]; + +extern mod core(name = "std"); + +extern mod rustpkg; +extern mod rustdoc; +extern mod rusti; +extern mod rustc; + +use core::prelude::*; + +use core::io; +use core::os; +use core::run; +use core::libc::exit; + +// For bootstrapping. +mod std { + pub use core::os; + pub use core::str; + pub use core::unstable; +} + +enum ValidUsage { + Valid(int), Invalid +} + +impl ValidUsage { + fn is_valid(&self) -> bool { + match *self { + Valid(_) => true, + Invalid => false + } + } +} + +enum Action<'self> { + Call(&'self fn(args: &[~str]) -> ValidUsage), + CallMain(&'static str, &'self fn()), +} + +enum UsageSource<'self> { + UsgStr(&'self str), + UsgCall(&'self fn()), +} + +struct Command<'self> { + cmd: &'self str, + action: Action<'self>, + usage_line: &'self str, + usage_full: UsageSource<'self>, +} + +static commands: &'static [Command<'static>] = &[ + Command{ + cmd: "build", + action: CallMain("rustc", rustc::main), + usage_line: "compile rust source files", + usage_full: UsgCall(rustc_help), + }, + Command{ + cmd: "run", + action: Call(cmd_run), + usage_line: "build an executable, and run it", + usage_full: UsgStr( + "The run command is an shortcut for the command line \n\ + \"rustc -o ~ && ./~ [...]\".\ + \n\nUsage:\trust run [...]" + ) + }, + Command{ + cmd: "test", + action: Call(cmd_test), + usage_line: "build a test executable, and run it", + usage_full: UsgStr( + "The test command is an shortcut for the command line \n\ + \"rustc --test -o test~ && \ + ./test~\"\n\nUsage:\trust test " + ) + }, + Command{ + cmd: "doc", + action: CallMain("rustdoc", rustdoc::main), + usage_line: "generate documentation from doc comments", + usage_full: UsgCall(rustdoc::config::usage), + }, + Command{ + cmd: "pkg", + action: CallMain("rustpkg", rustpkg::main), + usage_line: "download, build, install rust packages", + usage_full: UsgCall(rustpkg::usage::general), + }, + Command{ + cmd: "sketch", + action: CallMain("rusti", rusti::main), + usage_line: "run a rust interpreter", + usage_full: UsgStr("\nUsage:\trusti"), + }, + Command{ + cmd: "help", + action: Call(cmd_help), + usage_line: "show detailed usage of a command", + usage_full: UsgStr( + "The help command displays the usage text of another command.\n\ + The text is either build in, or provided by the corresponding \ + program.\n\nUsage:\trust help " + ) + } +]; + +fn rustc_help() { + rustc::usage(copy os::args()[0]) +} + +fn find_cmd(command_string: &str) -> Option { + do commands.iter().find_ |command| { + command.cmd == command_string + }.map_consume(|x| copy *x) +} + +fn cmd_help(args: &[~str]) -> ValidUsage { + fn print_usage(command_string: ~str) -> ValidUsage { + match find_cmd(command_string) { + Some(command) => { + match command.action { + CallMain(prog, _) => io::println(fmt!( + "The %s command is an alias for the %s program.", + command.cmd, prog)), + _ => () + } + match command.usage_full { + UsgStr(msg) => io::println(fmt!("%s\n", msg)), + UsgCall(f) => f(), + } + Valid(0) + }, + None => Invalid + } + } + + match args { + [ref command_string] => print_usage(copy *command_string), + _ => Invalid + } +} + +fn cmd_test(args: &[~str]) -> ValidUsage { + match args { + [ref filename] => { + let test_exec = Path(*filename).filestem().unwrap() + "test~"; + invoke("rustc", &[~"--test", filename.to_owned(), + ~"-o", test_exec.to_owned()], rustc::main); + let exit_code = run::process_status(~"./" + test_exec, []); + Valid(exit_code) + } + _ => Invalid + } +} + +fn cmd_run(args: &[~str]) -> ValidUsage { + match args { + [ref filename, ..prog_args] => { + let exec = Path(*filename).filestem().unwrap() + "~"; + invoke("rustc", &[filename.to_owned(), ~"-o", exec.to_owned()], + rustc::main); + let exit_code = run::process_status(~"./"+exec, prog_args); + Valid(exit_code) + } + _ => Invalid + } +} + +fn invoke(prog: &str, args: &[~str], f: &fn()) { + let mut osargs = ~[prog.to_owned()]; + osargs.push_all_move(args.to_owned()); + os::set_args(osargs); + f(); +} + +fn do_command(command: &Command, args: &[~str]) -> ValidUsage { + match command.action { + Call(f) => f(args), + CallMain(prog, f) => { + invoke(prog, args, f); + Valid(0) + } + } +} + +fn usage() { + static indent: uint = 8; + + io::print( + "The rust tool is a convenience for managing rust source code.\n\ + It acts as a shortcut for programs of the rust tool chain.\n\ + \n\ + Usage:\trust [arguments]\n\ + \n\ + The commands are:\n\ + \n" + ); + + for commands.iter().advance |command| { + let padding = " ".repeat(indent - command.cmd.len()); + io::println(fmt!(" %s%s%s", + command.cmd, padding, command.usage_line)); + } + + io::print( + "\n\ + Use \"rust help \" for more information about a command.\n\ + \n" + ); + +} + +pub fn main() { + let os_args = os::args(); + let args = os_args.tail(); + + if !args.is_empty() { + let r = find_cmd(*args.head()); + for r.iter().advance |command| { + let result = do_command(command, args.tail()); + match result { + Valid(exit_code) => unsafe { exit(exit_code.to_i32()) }, + _ => loop + } + } + } + + usage(); +} diff --git a/src/librustc/rustc.rc b/src/librustc/rustc.rc deleted file mode 100644 index 20705b3d797..00000000000 --- a/src/librustc/rustc.rc +++ /dev/null @@ -1,369 +0,0 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[link(name = "rustc", - vers = "0.7-pre", - uuid = "0ce89b41-2f92-459e-bbc1-8f5fe32f16cf", - url = "https://github.com/mozilla/rust/tree/master/src/rustc")]; - -#[comment = "The Rust compiler"]; -#[license = "MIT/ASL2"]; -#[crate_type = "lib"]; - -#[allow(non_implicitly_copyable_typarams)]; -#[allow(non_camel_case_types)]; -#[deny(deprecated_pattern)]; - -#[no_core]; -#[no_std]; - -extern mod core(name = "std"); -extern mod extra(name = "extra"); -extern mod syntax; - -extern mod std(name = "std", vers = "0.7-pre"); - -use core::prelude::*; - -use driver::driver::{host_triple, optgroups, early_error}; -use driver::driver::{str_input, file_input, build_session_options}; -use driver::driver::{build_session, build_configuration, parse_pretty}; -use driver::driver::{pp_mode, pretty_print_input, list_metadata}; -use driver::driver::{compile_input}; -use driver::session; -use middle::lint; - -use core::io; -use core::os; -use core::result; -use core::str; -use core::task; -use core::uint; -use core::vec; -use extra::getopts::{groups, opt_present}; -use extra::getopts; -use syntax::codemap; -use syntax::diagnostic; - -pub mod middle { - #[path = "trans/mod.rs"] - pub mod trans; - pub mod ty; - pub mod subst; - pub mod resolve; - #[path = "typeck/mod.rs"] - pub mod typeck; - pub mod check_loop; - pub mod check_match; - pub mod check_const; - pub mod lint; - #[path = "borrowck/mod.rs"] - pub mod borrowck; - pub mod dataflow; - pub mod mem_categorization; - pub mod liveness; - pub mod kind; - pub mod freevars; - pub mod pat_util; - pub mod region; - pub mod const_eval; - pub mod astencode; - pub mod lang_items; - pub mod privacy; - pub mod moves; - pub mod entry; - pub mod effect; -} - -pub mod front { - pub mod config; - pub mod test; - pub mod std_inject; -} - -pub mod back { - pub mod link; - pub mod abi; - pub mod upcall; - pub mod arm; - pub mod mips; - pub mod x86; - pub mod x86_64; - pub mod rpath; - pub mod target_strs; - pub mod passes; -} - -#[path = "metadata/mod.rs"] -pub mod metadata; - -#[path = "driver/mod.rs"] -pub mod driver; - -pub mod util { - pub mod common; - pub mod ppaux; - pub mod enum_set; -} - -pub mod lib { - pub mod llvm; -} - -// A curious inner module that allows ::std::foo to be available in here for -// macros. -mod std { - pub use core::cmp; - pub use core::os; - pub use core::str; - pub use core::sys; - pub use core::to_bytes; - pub use core::unstable; - pub use extra::serialize; -} - -pub fn version(argv0: &str) { - let mut vers = ~"unknown version"; - let env_vers = env!("CFG_VERSION"); - if env_vers.len() != 0 { vers = env_vers.to_owned(); } - io::println(fmt!("%s %s", argv0, vers)); - io::println(fmt!("host: %s", host_triple())); -} - -pub fn usage(argv0: &str) { - let message = fmt!("Usage: %s [OPTIONS] INPUT", argv0); - io::println(fmt!("%s\ -Additional help: - -W help Print 'lint' options and default settings - -Z help Print internal options for debugging rustc\n", - groups::usage(message, optgroups()))); -} - -pub fn describe_warnings() { - io::println(fmt!(" -Available lint options: - -W Warn about - -A Allow - -D Deny - -F Forbid (deny, and deny all overrides) -")); - - let lint_dict = lint::get_lint_dict(); - let mut max_key = 0; - for lint_dict.each_key |k| { max_key = uint::max(k.len(), max_key); } - fn padded(max: uint, s: &str) -> ~str { - str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s - } - io::println(fmt!("\nAvailable lint checks:\n")); - io::println(fmt!(" %s %7.7s %s", - padded(max_key, "name"), "default", "meaning")); - io::println(fmt!(" %s %7.7s %s\n", - padded(max_key, "----"), "-------", "-------")); - for lint_dict.each |k, v| { - let k = k.replace("_", "-"); - io::println(fmt!(" %s %7.7s %s", - padded(max_key, k), - match v.default { - lint::allow => ~"allow", - lint::warn => ~"warn", - lint::deny => ~"deny", - lint::forbid => ~"forbid" - }, - v.desc)); - } - io::println(""); -} - -pub fn describe_debug_flags() { - io::println(fmt!("\nAvailable debug options:\n")); - let r = session::debugging_opts_map(); - for r.iter().advance |pair| { - let (name, desc, _) = /*bad*/copy *pair; - io::println(fmt!(" -Z %-20s -- %s", name, desc)); - } -} - -pub fn run_compiler(args: &~[~str], demitter: diagnostic::Emitter) { - // Don't display log spew by default. Can override with RUST_LOG. - ::core::logging::console_off(); - - let mut args = /*bad*/copy *args; - let binary = args.shift().to_managed(); - - if args.is_empty() { usage(binary); return; } - - let matches = - &match getopts::groups::getopts(args, optgroups()) { - Ok(m) => m, - Err(f) => { - early_error(demitter, getopts::fail_str(f)); - } - }; - - if opt_present(matches, "h") || opt_present(matches, "help") { - usage(binary); - return; - } - - // Display the available lint options if "-W help" or only "-W" is given. - let lint_flags = vec::append(getopts::opt_strs(matches, "W"), - getopts::opt_strs(matches, "warn")); - - let show_lint_options = lint_flags.iter().any_(|x| x == &~"help") || - (opt_present(matches, "W") && lint_flags.is_empty()); - - if show_lint_options { - describe_warnings(); - return; - } - - let r = getopts::opt_strs(matches, "Z"); - if r.iter().any_(|x| x == &~"help") { - describe_debug_flags(); - return; - } - - if getopts::opt_maybe_str(matches, "passes") == Some(~"list") { - back::passes::list_passes(); - return; - } - - if opt_present(matches, "v") || opt_present(matches, "version") { - version(binary); - return; - } - let input = match matches.free.len() { - 0u => early_error(demitter, ~"no input filename given"), - 1u => { - let ifile = matches.free[0].as_slice(); - if "-" == ifile { - let src = str::from_bytes(io::stdin().read_whole_stream()); - str_input(src.to_managed()) - } else { - file_input(Path(ifile)) - } - } - _ => early_error(demitter, ~"multiple input filenames provided") - }; - - let sopts = build_session_options(binary, matches, demitter); - let sess = build_session(sopts, demitter); - let odir = getopts::opt_maybe_str(matches, "out-dir"); - let odir = odir.map(|o| Path(*o)); - let ofile = getopts::opt_maybe_str(matches, "o"); - let ofile = ofile.map(|o| Path(*o)); - let cfg = build_configuration(sess, binary, &input); - let pretty = getopts::opt_default(matches, "pretty", "normal").map( - |a| parse_pretty(sess, *a)); - match pretty { - Some::(ppm) => { - pretty_print_input(sess, cfg, &input, ppm); - return; - } - None:: => {/* continue */ } - } - let ls = opt_present(matches, "ls"); - if ls { - match input { - file_input(ref ifile) => { - list_metadata(sess, &(*ifile), io::stdout()); - } - str_input(_) => { - early_error(demitter, ~"can not list metadata for stdin"); - } - } - return; - } - - compile_input(sess, cfg, &input, &odir, &ofile); -} - -#[deriving(Eq)] -pub enum monitor_msg { - fatal, - done, -} - -/* -This is a sanity check that any failure of the compiler is performed -through the diagnostic module and reported properly - we shouldn't be calling -plain-old-fail on any execution path that might be taken. Since we have -console logging off by default, hitting a plain fail statement would make the -compiler silently exit, which would be terrible. - -This method wraps the compiler in a subtask and injects a function into the -diagnostic emitter which records when we hit a fatal error. If the task -fails without recording a fatal error then we've encountered a compiler -bug and need to present an error. -*/ -pub fn monitor(f: ~fn(diagnostic::Emitter)) { - use core::comm::*; - let (p, ch) = stream(); - let ch = SharedChan::new(ch); - let ch_capture = ch.clone(); - match do task::try || { - let ch = ch_capture.clone(); - let ch_capture = ch.clone(); - // The 'diagnostics emitter'. Every error, warning, etc. should - // go through this function. - let demitter: @fn(Option<(@codemap::CodeMap, codemap::span)>, - &str, - diagnostic::level) = - |cmsp, msg, lvl| { - if lvl == diagnostic::fatal { - ch_capture.send(fatal); - } - diagnostic::emit(cmsp, msg, lvl); - }; - - struct finally { - ch: SharedChan, - } - - impl Drop for finally { - fn finalize(&self) { self.ch.send(done); } - } - - let _finally = finally { ch: ch }; - - f(demitter) - } { - result::Ok(_) => { /* fallthrough */ } - result::Err(_) => { - // Task failed without emitting a fatal diagnostic - if p.recv() == done { - diagnostic::emit( - None, - diagnostic::ice_msg("unexpected failure"), - diagnostic::error); - - let xs = [ - ~"the compiler hit an unexpected failure path. \ - this is a bug", - ~"try running with RUST_LOG=rustc=1,::rt::backtrace \ - to get further details and report the results \ - to github.com/mozilla/rust/issues" - ]; - for xs.iter().advance |note| { - diagnostic::emit(None, *note, diagnostic::note) - } - } - // Fail so the process returns a failure code - fail!(); - } - } -} - -pub fn main() { - let args = os::args(); - do monitor |demitter| { - run_compiler(&args, demitter); - } -} diff --git a/src/librustc/rustc.rs b/src/librustc/rustc.rs new file mode 100644 index 00000000000..20705b3d797 --- /dev/null +++ b/src/librustc/rustc.rs @@ -0,0 +1,369 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[link(name = "rustc", + vers = "0.7-pre", + uuid = "0ce89b41-2f92-459e-bbc1-8f5fe32f16cf", + url = "https://github.com/mozilla/rust/tree/master/src/rustc")]; + +#[comment = "The Rust compiler"]; +#[license = "MIT/ASL2"]; +#[crate_type = "lib"]; + +#[allow(non_implicitly_copyable_typarams)]; +#[allow(non_camel_case_types)]; +#[deny(deprecated_pattern)]; + +#[no_core]; +#[no_std]; + +extern mod core(name = "std"); +extern mod extra(name = "extra"); +extern mod syntax; + +extern mod std(name = "std", vers = "0.7-pre"); + +use core::prelude::*; + +use driver::driver::{host_triple, optgroups, early_error}; +use driver::driver::{str_input, file_input, build_session_options}; +use driver::driver::{build_session, build_configuration, parse_pretty}; +use driver::driver::{pp_mode, pretty_print_input, list_metadata}; +use driver::driver::{compile_input}; +use driver::session; +use middle::lint; + +use core::io; +use core::os; +use core::result; +use core::str; +use core::task; +use core::uint; +use core::vec; +use extra::getopts::{groups, opt_present}; +use extra::getopts; +use syntax::codemap; +use syntax::diagnostic; + +pub mod middle { + #[path = "trans/mod.rs"] + pub mod trans; + pub mod ty; + pub mod subst; + pub mod resolve; + #[path = "typeck/mod.rs"] + pub mod typeck; + pub mod check_loop; + pub mod check_match; + pub mod check_const; + pub mod lint; + #[path = "borrowck/mod.rs"] + pub mod borrowck; + pub mod dataflow; + pub mod mem_categorization; + pub mod liveness; + pub mod kind; + pub mod freevars; + pub mod pat_util; + pub mod region; + pub mod const_eval; + pub mod astencode; + pub mod lang_items; + pub mod privacy; + pub mod moves; + pub mod entry; + pub mod effect; +} + +pub mod front { + pub mod config; + pub mod test; + pub mod std_inject; +} + +pub mod back { + pub mod link; + pub mod abi; + pub mod upcall; + pub mod arm; + pub mod mips; + pub mod x86; + pub mod x86_64; + pub mod rpath; + pub mod target_strs; + pub mod passes; +} + +#[path = "metadata/mod.rs"] +pub mod metadata; + +#[path = "driver/mod.rs"] +pub mod driver; + +pub mod util { + pub mod common; + pub mod ppaux; + pub mod enum_set; +} + +pub mod lib { + pub mod llvm; +} + +// A curious inner module that allows ::std::foo to be available in here for +// macros. +mod std { + pub use core::cmp; + pub use core::os; + pub use core::str; + pub use core::sys; + pub use core::to_bytes; + pub use core::unstable; + pub use extra::serialize; +} + +pub fn version(argv0: &str) { + let mut vers = ~"unknown version"; + let env_vers = env!("CFG_VERSION"); + if env_vers.len() != 0 { vers = env_vers.to_owned(); } + io::println(fmt!("%s %s", argv0, vers)); + io::println(fmt!("host: %s", host_triple())); +} + +pub fn usage(argv0: &str) { + let message = fmt!("Usage: %s [OPTIONS] INPUT", argv0); + io::println(fmt!("%s\ +Additional help: + -W help Print 'lint' options and default settings + -Z help Print internal options for debugging rustc\n", + groups::usage(message, optgroups()))); +} + +pub fn describe_warnings() { + io::println(fmt!(" +Available lint options: + -W Warn about + -A Allow + -D Deny + -F Forbid (deny, and deny all overrides) +")); + + let lint_dict = lint::get_lint_dict(); + let mut max_key = 0; + for lint_dict.each_key |k| { max_key = uint::max(k.len(), max_key); } + fn padded(max: uint, s: &str) -> ~str { + str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s + } + io::println(fmt!("\nAvailable lint checks:\n")); + io::println(fmt!(" %s %7.7s %s", + padded(max_key, "name"), "default", "meaning")); + io::println(fmt!(" %s %7.7s %s\n", + padded(max_key, "----"), "-------", "-------")); + for lint_dict.each |k, v| { + let k = k.replace("_", "-"); + io::println(fmt!(" %s %7.7s %s", + padded(max_key, k), + match v.default { + lint::allow => ~"allow", + lint::warn => ~"warn", + lint::deny => ~"deny", + lint::forbid => ~"forbid" + }, + v.desc)); + } + io::println(""); +} + +pub fn describe_debug_flags() { + io::println(fmt!("\nAvailable debug options:\n")); + let r = session::debugging_opts_map(); + for r.iter().advance |pair| { + let (name, desc, _) = /*bad*/copy *pair; + io::println(fmt!(" -Z %-20s -- %s", name, desc)); + } +} + +pub fn run_compiler(args: &~[~str], demitter: diagnostic::Emitter) { + // Don't display log spew by default. Can override with RUST_LOG. + ::core::logging::console_off(); + + let mut args = /*bad*/copy *args; + let binary = args.shift().to_managed(); + + if args.is_empty() { usage(binary); return; } + + let matches = + &match getopts::groups::getopts(args, optgroups()) { + Ok(m) => m, + Err(f) => { + early_error(demitter, getopts::fail_str(f)); + } + }; + + if opt_present(matches, "h") || opt_present(matches, "help") { + usage(binary); + return; + } + + // Display the available lint options if "-W help" or only "-W" is given. + let lint_flags = vec::append(getopts::opt_strs(matches, "W"), + getopts::opt_strs(matches, "warn")); + + let show_lint_options = lint_flags.iter().any_(|x| x == &~"help") || + (opt_present(matches, "W") && lint_flags.is_empty()); + + if show_lint_options { + describe_warnings(); + return; + } + + let r = getopts::opt_strs(matches, "Z"); + if r.iter().any_(|x| x == &~"help") { + describe_debug_flags(); + return; + } + + if getopts::opt_maybe_str(matches, "passes") == Some(~"list") { + back::passes::list_passes(); + return; + } + + if opt_present(matches, "v") || opt_present(matches, "version") { + version(binary); + return; + } + let input = match matches.free.len() { + 0u => early_error(demitter, ~"no input filename given"), + 1u => { + let ifile = matches.free[0].as_slice(); + if "-" == ifile { + let src = str::from_bytes(io::stdin().read_whole_stream()); + str_input(src.to_managed()) + } else { + file_input(Path(ifile)) + } + } + _ => early_error(demitter, ~"multiple input filenames provided") + }; + + let sopts = build_session_options(binary, matches, demitter); + let sess = build_session(sopts, demitter); + let odir = getopts::opt_maybe_str(matches, "out-dir"); + let odir = odir.map(|o| Path(*o)); + let ofile = getopts::opt_maybe_str(matches, "o"); + let ofile = ofile.map(|o| Path(*o)); + let cfg = build_configuration(sess, binary, &input); + let pretty = getopts::opt_default(matches, "pretty", "normal").map( + |a| parse_pretty(sess, *a)); + match pretty { + Some::(ppm) => { + pretty_print_input(sess, cfg, &input, ppm); + return; + } + None:: => {/* continue */ } + } + let ls = opt_present(matches, "ls"); + if ls { + match input { + file_input(ref ifile) => { + list_metadata(sess, &(*ifile), io::stdout()); + } + str_input(_) => { + early_error(demitter, ~"can not list metadata for stdin"); + } + } + return; + } + + compile_input(sess, cfg, &input, &odir, &ofile); +} + +#[deriving(Eq)] +pub enum monitor_msg { + fatal, + done, +} + +/* +This is a sanity check that any failure of the compiler is performed +through the diagnostic module and reported properly - we shouldn't be calling +plain-old-fail on any execution path that might be taken. Since we have +console logging off by default, hitting a plain fail statement would make the +compiler silently exit, which would be terrible. + +This method wraps the compiler in a subtask and injects a function into the +diagnostic emitter which records when we hit a fatal error. If the task +fails without recording a fatal error then we've encountered a compiler +bug and need to present an error. +*/ +pub fn monitor(f: ~fn(diagnostic::Emitter)) { + use core::comm::*; + let (p, ch) = stream(); + let ch = SharedChan::new(ch); + let ch_capture = ch.clone(); + match do task::try || { + let ch = ch_capture.clone(); + let ch_capture = ch.clone(); + // The 'diagnostics emitter'. Every error, warning, etc. should + // go through this function. + let demitter: @fn(Option<(@codemap::CodeMap, codemap::span)>, + &str, + diagnostic::level) = + |cmsp, msg, lvl| { + if lvl == diagnostic::fatal { + ch_capture.send(fatal); + } + diagnostic::emit(cmsp, msg, lvl); + }; + + struct finally { + ch: SharedChan, + } + + impl Drop for finally { + fn finalize(&self) { self.ch.send(done); } + } + + let _finally = finally { ch: ch }; + + f(demitter) + } { + result::Ok(_) => { /* fallthrough */ } + result::Err(_) => { + // Task failed without emitting a fatal diagnostic + if p.recv() == done { + diagnostic::emit( + None, + diagnostic::ice_msg("unexpected failure"), + diagnostic::error); + + let xs = [ + ~"the compiler hit an unexpected failure path. \ + this is a bug", + ~"try running with RUST_LOG=rustc=1,::rt::backtrace \ + to get further details and report the results \ + to github.com/mozilla/rust/issues" + ]; + for xs.iter().advance |note| { + diagnostic::emit(None, *note, diagnostic::note) + } + } + // Fail so the process returns a failure code + fail!(); + } + } +} + +pub fn main() { + let args = os::args(); + do monitor |demitter| { + run_compiler(&args, demitter); + } +} diff --git a/src/librustdoc/rustdoc.rc b/src/librustdoc/rustdoc.rc deleted file mode 100644 index d02620229f5..00000000000 --- a/src/librustdoc/rustdoc.rc +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Rustdoc - The Rust documentation generator - -#[link(name = "rustdoc", - vers = "0.7-pre", - uuid = "f8abd014-b281-484d-a0c3-26e3de8e2412", - url = "https://github.com/mozilla/rust/tree/master/src/rustdoc")]; - -#[comment = "The Rust documentation generator"]; -#[license = "MIT/ASL2"]; -#[crate_type = "lib"]; - -#[allow(non_implicitly_copyable_typarams)]; - -#[no_std]; - -extern mod core(name = "std"); -extern mod extra(name = "extra"); - -extern mod rustc; -extern mod syntax; - -use core::prelude::*; - -use config::Config; -use doc::Item; -use doc::ItemUtils; - -use core::*; - -pub mod pass; -pub mod config; -pub mod parse; -pub mod extract; -pub mod attr_parser; -pub mod doc; -pub mod markdown_index_pass; -pub mod markdown_pass; -pub mod markdown_writer; -pub mod fold; -pub mod path_pass; -pub mod attr_pass; -pub mod tystr_pass; -pub mod prune_hidden_pass; -pub mod desc_to_brief_pass; -pub mod text_pass; -pub mod unindent_pass; -pub mod trim_pass; -pub mod astsrv; -pub mod demo; -pub mod sort_pass; -pub mod sort_item_name_pass; -pub mod sort_item_type_pass; -pub mod page_pass; -pub mod sectionalize_pass; -pub mod escape_pass; -pub mod prune_private_pass; -pub mod util; - -mod std { - pub use core::clone; - pub use core::cmp; - pub use core::os; - pub use core::str; - pub use core::sys; - pub use core::unstable; -} - -pub fn main() { - let args = os::args(); - - if args.iter().any_(|x| "-h" == *x) || args.iter().any_(|x| "--help" == *x) { - config::usage(); - return; - } - - let config = match config::parse_config(args) { - Ok(config) => config, - Err(err) => { - io::println(fmt!("error: %s", err)); - return; - } - }; - - run(config); -} - -/// Runs rustdoc over the given file -fn run(config: Config) { - - let source_file = copy config.input_crate; - - // Create an AST service from the source code - do astsrv::from_file(source_file.to_str()) |srv| { - - // Just time how long it takes for the AST to become available - do time(~"wait_ast") { - do astsrv::exec(srv.clone()) |_ctxt| { } - }; - - // Extract the initial doc tree from the AST. This contains - // just names and node ids. - let doc = time(~"extract", || { - let default_name = copy source_file; - extract::from_srv(srv.clone(), default_name.to_str()) - }); - - // Refine and publish the document - pass::run_passes(srv, doc, ~[ - // Generate type and signature strings - tystr_pass::mk_pass(), - // Record the full paths to various nodes - path_pass::mk_pass(), - // Extract the docs attributes and attach them to doc nodes - attr_pass::mk_pass(), - // Perform various text escaping - escape_pass::mk_pass(), - // Remove things marked doc(hidden) - prune_hidden_pass::mk_pass(), - // Remove things that are private - prune_private_pass::mk_pass(), - // Extract brief documentation from the full descriptions - desc_to_brief_pass::mk_pass(), - // Massage the text to remove extra indentation - unindent_pass::mk_pass(), - // Split text into multiple sections according to headers - sectionalize_pass::mk_pass(), - // Trim extra spaces from text - trim_pass::mk_pass(), - // Sort items by name - sort_item_name_pass::mk_pass(), - // Sort items again by kind - sort_item_type_pass::mk_pass(), - // Create indexes appropriate for markdown - markdown_index_pass::mk_pass(copy config), - // Break the document into pages if required by the - // output format - page_pass::mk_pass(config.output_style), - // Render - markdown_pass::mk_pass( - markdown_writer::make_writer_factory(copy config) - ) - ]); - } -} - -pub fn time(what: ~str, f: &fn() -> T) -> T { - let start = extra::time::precise_time_s(); - let rv = f(); - let end = extra::time::precise_time_s(); - info!("time: %3.3f s %s", end - start, what); - rv -} diff --git a/src/librustdoc/rustdoc.rs b/src/librustdoc/rustdoc.rs new file mode 100644 index 00000000000..d02620229f5 --- /dev/null +++ b/src/librustdoc/rustdoc.rs @@ -0,0 +1,162 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Rustdoc - The Rust documentation generator + +#[link(name = "rustdoc", + vers = "0.7-pre", + uuid = "f8abd014-b281-484d-a0c3-26e3de8e2412", + url = "https://github.com/mozilla/rust/tree/master/src/rustdoc")]; + +#[comment = "The Rust documentation generator"]; +#[license = "MIT/ASL2"]; +#[crate_type = "lib"]; + +#[allow(non_implicitly_copyable_typarams)]; + +#[no_std]; + +extern mod core(name = "std"); +extern mod extra(name = "extra"); + +extern mod rustc; +extern mod syntax; + +use core::prelude::*; + +use config::Config; +use doc::Item; +use doc::ItemUtils; + +use core::*; + +pub mod pass; +pub mod config; +pub mod parse; +pub mod extract; +pub mod attr_parser; +pub mod doc; +pub mod markdown_index_pass; +pub mod markdown_pass; +pub mod markdown_writer; +pub mod fold; +pub mod path_pass; +pub mod attr_pass; +pub mod tystr_pass; +pub mod prune_hidden_pass; +pub mod desc_to_brief_pass; +pub mod text_pass; +pub mod unindent_pass; +pub mod trim_pass; +pub mod astsrv; +pub mod demo; +pub mod sort_pass; +pub mod sort_item_name_pass; +pub mod sort_item_type_pass; +pub mod page_pass; +pub mod sectionalize_pass; +pub mod escape_pass; +pub mod prune_private_pass; +pub mod util; + +mod std { + pub use core::clone; + pub use core::cmp; + pub use core::os; + pub use core::str; + pub use core::sys; + pub use core::unstable; +} + +pub fn main() { + let args = os::args(); + + if args.iter().any_(|x| "-h" == *x) || args.iter().any_(|x| "--help" == *x) { + config::usage(); + return; + } + + let config = match config::parse_config(args) { + Ok(config) => config, + Err(err) => { + io::println(fmt!("error: %s", err)); + return; + } + }; + + run(config); +} + +/// Runs rustdoc over the given file +fn run(config: Config) { + + let source_file = copy config.input_crate; + + // Create an AST service from the source code + do astsrv::from_file(source_file.to_str()) |srv| { + + // Just time how long it takes for the AST to become available + do time(~"wait_ast") { + do astsrv::exec(srv.clone()) |_ctxt| { } + }; + + // Extract the initial doc tree from the AST. This contains + // just names and node ids. + let doc = time(~"extract", || { + let default_name = copy source_file; + extract::from_srv(srv.clone(), default_name.to_str()) + }); + + // Refine and publish the document + pass::run_passes(srv, doc, ~[ + // Generate type and signature strings + tystr_pass::mk_pass(), + // Record the full paths to various nodes + path_pass::mk_pass(), + // Extract the docs attributes and attach them to doc nodes + attr_pass::mk_pass(), + // Perform various text escaping + escape_pass::mk_pass(), + // Remove things marked doc(hidden) + prune_hidden_pass::mk_pass(), + // Remove things that are private + prune_private_pass::mk_pass(), + // Extract brief documentation from the full descriptions + desc_to_brief_pass::mk_pass(), + // Massage the text to remove extra indentation + unindent_pass::mk_pass(), + // Split text into multiple sections according to headers + sectionalize_pass::mk_pass(), + // Trim extra spaces from text + trim_pass::mk_pass(), + // Sort items by name + sort_item_name_pass::mk_pass(), + // Sort items again by kind + sort_item_type_pass::mk_pass(), + // Create indexes appropriate for markdown + markdown_index_pass::mk_pass(copy config), + // Break the document into pages if required by the + // output format + page_pass::mk_pass(config.output_style), + // Render + markdown_pass::mk_pass( + markdown_writer::make_writer_factory(copy config) + ) + ]); + } +} + +pub fn time(what: ~str, f: &fn() -> T) -> T { + let start = extra::time::precise_time_s(); + let rv = f(); + let end = extra::time::precise_time_s(); + info!("time: %3.3f s %s", end - start, what); + rv +} diff --git a/src/librusti/rusti.rc b/src/librusti/rusti.rc deleted file mode 100644 index 57a2a48a0f6..00000000000 --- a/src/librusti/rusti.rc +++ /dev/null @@ -1,665 +0,0 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -/*! - * rusti - A REPL using the JIT backend - * - * Rusti works by serializing state between lines of input. This means that each - * line can be run in a separate task, and the only limiting factor is that all - * local bound variables are encodable. - * - * This is accomplished by feeding in generated input to rustc for execution in - * the JIT compiler. Currently input actually gets fed in three times to get - * information about the program. - * - * - Pass #1 - * In this pass, the input is simply thrown at the parser and the input comes - * back. This validates the structure of the program, and at this stage the - * global items (fns, structs, impls, traits, etc.) are filtered from the - * input into the "global namespace". These declarations shadow all previous - * declarations of an item by the same name. - * - * - Pass #2 - * After items have been stripped, the remaining input is passed to rustc - * along with all local variables declared (initialized to nothing). This pass - * runs up to typechecking. From this, we can learn about the types of each - * bound variable, what variables are bound, and also ensure that all the - * types are encodable (the input can actually be run). - * - * - Pass #3 - * Finally, a program is generated to deserialize the local variable state, - * run the code input, and then reserialize all bindings back into a local - * hash map. Once this code runs, the input has fully been run and the REPL - * waits for new input. - * - * Encoding/decoding is done with EBML, and there is simply a map of ~str -> - * ~[u8] maintaining the values of each local binding (by name). - */ - -#[link(name = "rusti", - vers = "0.7-pre", - uuid = "7fb5bf52-7d45-4fee-8325-5ad3311149fc", - url = "https://github.com/mozilla/rust/tree/master/src/rusti")]; - -#[license = "MIT/ASL2"]; -#[crate_type = "lib"]; - -extern mod extra; -extern mod rustc; -extern mod syntax; - -use std::{libc, io, os, task, vec}; -use std::cell::Cell; -use extra::rl; - -use rustc::driver::{driver, session}; -use syntax::{ast, diagnostic}; -use syntax::ast_util::*; -use syntax::parse::token; -use syntax::print::pprust; - -use program::Program; -use utils::*; - -mod program; -pub mod utils; - -/** - * A structure shared across REPL instances for storing history - * such as statements and view items. I wish the AST was sendable. - */ -pub struct Repl { - prompt: ~str, - binary: ~str, - running: bool, - lib_search_paths: ~[~str], - - program: Program, -} - -// Action to do after reading a :command -enum CmdAction { - action_none, - action_run_line(~str), -} - -/// Run an input string in a Repl, returning the new Repl. -fn run(mut repl: Repl, input: ~str) -> Repl { - // Build some necessary rustc boilerplate for compiling things - let binary = repl.binary.to_managed(); - let options = @session::options { - crate_type: session::unknown_crate, - binary: binary, - addl_lib_search_paths: @mut repl.lib_search_paths.map(|p| Path(*p)), - jit: true, - .. copy *session::basic_options() - }; - // Because we assume that everything is encodable (and assert so), add some - // extra helpful information if the error crops up. Otherwise people are - // bound to be very confused when they find out code is running that they - // never typed in... - let sess = driver::build_session(options, |cm, msg, lvl| { - diagnostic::emit(cm, msg, lvl); - if msg.contains("failed to find an implementation of trait") && - msg.contains("extra::serialize::Encodable") { - diagnostic::emit(cm, - "Currrently rusti serializes bound locals between \ - different lines of input. This means that all \ - values of local variables need to be encodable, \ - and this type isn't encodable", - diagnostic::note); - } - }); - let intr = token::get_ident_interner(); - - // - // Stage 1: parse the input and filter it into the program (as necessary) - // - debug!("parsing: %s", input); - let crate = parse_input(sess, binary, input); - let mut to_run = ~[]; // statements to run (emitted back into code) - let new_locals = @mut ~[]; // new locals being defined - let mut result = None; // resultant expression (to print via pp) - do find_main(crate, sess) |blk| { - // Fish out all the view items, be sure to record 'extern mod' items - // differently beause they must appear before all 'use' statements - for blk.node.view_items.iter().advance |vi| { - let s = do with_pp(intr) |pp, _| { - pprust::print_view_item(pp, *vi); - }; - match vi.node { - ast::view_item_extern_mod(*) => { - repl.program.record_extern(s); - } - ast::view_item_use(*) => { repl.program.record_view_item(s); } - } - } - - // Iterate through all of the block's statements, inserting them into - // the correct portions of the program - for blk.node.stmts.iter().advance |stmt| { - let s = do with_pp(intr) |pp, _| { pprust::print_stmt(pp, *stmt); }; - match stmt.node { - ast::stmt_decl(d, _) => { - match d.node { - ast::decl_item(it) => { - let name = sess.str_of(it.ident); - match it.node { - // Structs are treated specially because to make - // them at all usable they need to be decorated - // with #[deriving(Encoable, Decodable)] - ast::item_struct(*) => { - repl.program.record_struct(name, s); - } - // Item declarations are hoisted out of main() - _ => { repl.program.record_item(name, s); } - } - } - - // Local declarations must be specially dealt with, - // record all local declarations for use later on - ast::decl_local(l) => { - let mutbl = l.node.is_mutbl; - do each_binding(l) |path, _| { - let s = do with_pp(intr) |pp, _| { - pprust::print_path(pp, path, false); - }; - new_locals.push((s, mutbl)); - } - to_run.push(s); - } - } - } - - // run statements with expressions (they have effects) - ast::stmt_mac(*) | ast::stmt_semi(*) | ast::stmt_expr(*) => { - to_run.push(s); - } - } - } - result = do blk.node.expr.map_consume |e| { - do with_pp(intr) |pp, _| { pprust::print_expr(pp, e); } - }; - } - // return fast for empty inputs - if to_run.len() == 0 && result.is_none() { - return repl; - } - - // - // Stage 2: run everything up to typeck to learn the types of the new - // variables introduced into the program - // - info!("Learning about the new types in the program"); - repl.program.set_cache(); // before register_new_vars (which changes them) - let input = to_run.connect("\n"); - let test = repl.program.test_code(input, &result, *new_locals); - debug!("testing with ^^^^^^ %?", (||{ println(test) })()); - let dinput = driver::str_input(test.to_managed()); - let cfg = driver::build_configuration(sess, binary, &dinput); - let outputs = driver::build_output_filenames(&dinput, &None, &None, [], sess); - let (crate, tcx) = driver::compile_upto(sess, copy cfg, &dinput, - driver::cu_typeck, Some(outputs)); - // Once we're typechecked, record the types of all local variables defined - // in this input - do find_main(crate.expect("crate after cu_typeck"), sess) |blk| { - repl.program.register_new_vars(blk, tcx.expect("tcx after cu_typeck")); - } - - // - // Stage 3: Actually run the code in the JIT - // - info!("actually running code"); - let code = repl.program.code(input, &result); - debug!("actually running ^^^^^^ %?", (||{ println(code) })()); - let input = driver::str_input(code.to_managed()); - let cfg = driver::build_configuration(sess, binary, &input); - let outputs = driver::build_output_filenames(&input, &None, &None, [], sess); - let sess = driver::build_session(options, diagnostic::emit); - driver::compile_upto(sess, cfg, &input, driver::cu_everything, - Some(outputs)); - - // - // Stage 4: Inform the program that computation is done so it can update all - // local variable bindings. - // - info!("cleaning up after code"); - repl.program.consume_cache(); - - return repl; - - fn parse_input(sess: session::Session, binary: @str, - input: &str) -> @ast::crate { - let code = fmt!("fn main() {\n %s \n}", input); - let input = driver::str_input(code.to_managed()); - let cfg = driver::build_configuration(sess, binary, &input); - let outputs = driver::build_output_filenames(&input, &None, &None, [], sess); - let (crate, _) = driver::compile_upto(sess, cfg, &input, - driver::cu_parse, Some(outputs)); - crate.expect("parsing should return a crate") - } - - fn find_main(crate: @ast::crate, sess: session::Session, - f: &fn(&ast::blk)) { - for crate.node.module.items.iter().advance |item| { - match item.node { - ast::item_fn(_, _, _, _, ref blk) => { - if item.ident == sess.ident_of("main") { - return f(blk); - } - } - _ => {} - } - } - fail!("main function was expected somewhere..."); - } -} - -// Compiles a crate given by the filename as a library if the compiled -// version doesn't exist or is older than the source file. Binary is -// the name of the compiling executable. Returns Some(true) if it -// successfully compiled, Some(false) if the crate wasn't compiled -// because it already exists and is newer than the source file, or -// None if there were compile errors. -fn compile_crate(src_filename: ~str, binary: ~str) -> Option { - match do task::try { - let src_path = Path(src_filename); - let binary = binary.to_managed(); - let options = @session::options { - binary: binary, - addl_lib_search_paths: @mut ~[os::getcwd()], - .. copy *session::basic_options() - }; - let input = driver::file_input(copy src_path); - let sess = driver::build_session(options, diagnostic::emit); - *sess.building_library = true; - let cfg = driver::build_configuration(sess, binary, &input); - let outputs = driver::build_output_filenames( - &input, &None, &None, [], sess); - // If the library already exists and is newer than the source - // file, skip compilation and return None. - let mut should_compile = true; - let dir = os::list_dir_path(&Path(outputs.out_filename.dirname())); - let maybe_lib_path = do dir.iter().find_ |file| { - // The actual file's name has a hash value and version - // number in it which is unknown at this time, so looking - // for a file that matches out_filename won't work, - // instead we guess which file is the library by matching - // the prefix and suffix of out_filename to files in the - // directory. - let file_str = file.filename().get(); - file_str.starts_with(outputs.out_filename.filestem().get()) - && file_str.ends_with(outputs.out_filename.filetype().get()) - }; - match maybe_lib_path { - Some(lib_path) => { - let (src_mtime, _) = src_path.get_mtime().get(); - let (lib_mtime, _) = lib_path.get_mtime().get(); - if lib_mtime >= src_mtime { - should_compile = false; - } - }, - None => { }, - } - if (should_compile) { - println(fmt!("compiling %s...", src_filename)); - driver::compile_upto(sess, cfg, &input, driver::cu_everything, - Some(outputs)); - true - } else { false } - } { - Ok(true) => Some(true), - Ok(false) => Some(false), - Err(_) => None, - } -} - -/// Tries to get a line from rl after outputting a prompt. Returns -/// None if no input was read (e.g. EOF was reached). -fn get_line(use_rl: bool, prompt: &str) -> Option<~str> { - if use_rl { - let result = unsafe { rl::read(prompt) }; - - match result { - None => None, - Some(line) => { - unsafe { rl::add_history(line) }; - Some(line) - } - } - } else { - if io::stdin().eof() { - None - } else { - Some(io::stdin().read_line()) - } - } -} - -/// Run a command, e.g. :clear, :exit, etc. -fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer, - cmd: ~str, args: ~[~str], use_rl: bool) -> CmdAction { - let mut action = action_none; - match cmd { - ~"exit" => repl.running = false, - ~"clear" => { - repl.program.clear(); - - // XXX: Win32 version of linenoise can't do this - //rl::clear(); - } - ~"help" => { - println( - ":{\\n ..lines.. \\n:}\\n - execute multiline command\n\ - :load ... - loads given crates as dynamic libraries\n\ - :clear - clear the bindings\n\ - :exit - exit from the repl\n\ - :help - show this message"); - } - ~"load" => { - let mut loaded_crates: ~[~str] = ~[]; - for args.iter().advance |arg| { - let (crate, filename) = - if arg.ends_with(".rs") || arg.ends_with(".rc") { - (arg.slice_to(arg.len() - 3).to_owned(), copy *arg) - } else { - (copy *arg, *arg + ".rs") - }; - match compile_crate(filename, copy repl.binary) { - Some(_) => loaded_crates.push(crate), - None => { } - } - } - for loaded_crates.iter().advance |crate| { - let crate_path = Path(*crate); - let crate_dir = crate_path.dirname(); - repl.program.record_extern(fmt!("extern mod %s;", *crate)); - if !repl.lib_search_paths.iter().any_(|x| x == &crate_dir) { - repl.lib_search_paths.push(crate_dir); - } - } - if loaded_crates.is_empty() { - println("no crates loaded"); - } else { - println(fmt!("crates loaded: %s", - loaded_crates.connect(", "))); - } - } - ~"{" => { - let mut multiline_cmd = ~""; - let mut end_multiline = false; - while (!end_multiline) { - match get_line(use_rl, "rusti| ") { - None => fail!("unterminated multiline command :{ .. :}"), - Some(line) => { - if line.trim() == ":}" { - end_multiline = true; - } else { - multiline_cmd += line + "\n"; - } - } - } - } - action = action_run_line(multiline_cmd); - } - _ => println(~"unknown cmd: " + cmd) - } - return action; -} - -/// Executes a line of input, which may either be rust code or a -/// :command. Returns a new Repl if it has changed. -pub fn run_line(repl: &mut Repl, in: @io::Reader, out: @io::Writer, line: ~str, - use_rl: bool) - -> Option { - if line.starts_with(":") { - // drop the : and the \n (one byte each) - let full = line.slice(1, line.len()); - let split: ~[~str] = full.word_iter().transform(|s| s.to_owned()).collect(); - let len = split.len(); - - if len > 0 { - let cmd = copy split[0]; - - if !cmd.is_empty() { - let args = if len > 1 { - vec::slice(split, 1, len).to_owned() - } else { ~[] }; - - match run_cmd(repl, in, out, cmd, args, use_rl) { - action_none => { } - action_run_line(multiline_cmd) => { - if !multiline_cmd.is_empty() { - return run_line(repl, in, out, multiline_cmd, use_rl); - } - } - } - return None; - } - } - } - - let line = Cell::new(line); - let r = Cell::new(copy *repl); - let result = do task::try { - run(r.take(), line.take()) - }; - - if result.is_ok() { - return Some(result.get()); - } - return None; -} - -pub fn main() { - let args = os::args(); - let in = io::stdin(); - let out = io::stdout(); - let mut repl = Repl { - prompt: ~"rusti> ", - binary: copy args[0], - running: true, - lib_search_paths: ~[], - - program: Program::new(), - }; - - let istty = unsafe { libc::isatty(libc::STDIN_FILENO as i32) } != 0; - - // only print this stuff if the user is actually typing into rusti - if istty { - println("WARNING: The Rust REPL is experimental and may be"); - println("unstable. If you encounter problems, please use the"); - println("compiler instead. Type :help for help."); - - unsafe { - do rl::complete |line, suggest| { - if line.starts_with(":") { - suggest(~":clear"); - suggest(~":exit"); - suggest(~":help"); - suggest(~":load"); - } - } - } - } - - while repl.running { - match get_line(istty, repl.prompt) { - None => break, - Some(line) => { - if line.is_empty() { - if istty { - println("()"); - } - loop; - } - match run_line(&mut repl, in, out, line, istty) { - Some(new_repl) => repl = new_repl, - None => { } - } - } - } - } -} - -#[cfg(test)] -mod tests { - use std::io; - use std::iterator::IteratorUtil; - use program::Program; - use super::*; - - fn repl() -> Repl { - Repl { - prompt: ~"rusti> ", - binary: ~"rusti", - running: true, - lib_search_paths: ~[], - program: Program::new(), - } - } - - fn run_program(prog: &str) { - let mut r = repl(); - for prog.split_iter('\n').advance |cmd| { - let result = run_line(&mut r, io::stdin(), io::stdout(), - cmd.to_owned(), false); - r = result.expect(fmt!("the command '%s' failed", cmd)); - } - } - - #[test] - // FIXME: #7220 rusti on 32bit mac doesn't work. - #[cfg(not(target_word_size="32", - target_os="macos"))] - fn run_all() { - // FIXME(#7071): - // By default, unit tests are run in parallel. Rusti, on the other hand, - // does not enjoy doing this. I suspect that it is because the LLVM - // bindings are not thread-safe (when running parallel tests, some tests - // were triggering assertions in LLVM (or segfaults). Hence, this - // function exists to run everything serially (sadface). - // - // To get some interesting output, run with RUST_LOG=rusti::tests - - debug!("hopefully this runs"); - run_program(""); - - debug!("regression test for #5937"); - run_program("use std::hashmap;"); - - debug!("regression test for #5784"); - run_program("let a = 3;"); - - // XXX: can't spawn new tasks because the JIT code is cleaned up - // after the main function is done. - // debug!("regression test for #5803"); - // run_program(" - // spawn( || println(\"Please don't segfault\") ); - // do spawn { println(\"Please?\"); } - // "); - - debug!("inferred integers are usable"); - run_program("let a = 2;\n()\n"); - run_program(" - let a = 3; - let b = 4u; - assert!((a as uint) + b == 7) - "); - - debug!("local variables can be shadowed"); - run_program(" - let a = 3; - let a = 5; - assert!(a == 5) - "); - - debug!("strings are usable"); - run_program(" - let a = ~\"\"; - let b = \"\"; - let c = @\"\"; - let d = a + b + c; - assert!(d.len() == 0); - "); - - debug!("vectors are usable"); - run_program(" - let a = ~[1, 2, 3]; - let b = &[1, 2, 3]; - let c = @[1, 2, 3]; - let d = a + b + c; - assert!(d.len() == 9); - let e: &[int] = []; - "); - - debug!("structs are usable"); - run_program(" - struct A{ a: int } - let b = A{ a: 3 }; - assert!(b.a == 3) - "); - - debug!("mutable variables"); - run_program(" - let mut a = 3; - a = 5; - let mut b = std::hashmap::HashSet::new::(); - b.insert(a); - assert!(b.contains(&5)) - assert!(b.len() == 1) - "); - - debug!("functions are cached"); - run_program(" - fn fib(x: int) -> int { if x < 2 {x} else { fib(x - 1) + fib(x - 2) } } - let a = fib(3); - let a = a + fib(4); - assert!(a == 5) - "); - - debug!("modules are cached"); - run_program(" - mod b { pub fn foo() -> uint { 3 } } - assert!(b::foo() == 3) - "); - - debug!("multiple function definitions are allowed"); - run_program(" - fn f() {} - fn f() {} - f() - "); - - debug!("multiple item definitions are allowed"); - run_program(" - fn f() {} - mod f {} - struct f; - enum f {} - fn f() {} - f() - "); - } - - #[test] - // FIXME: #7220 rusti on 32bit mac doesn't work. - #[cfg(not(target_word_size="32", - target_os="macos"))] - fn exit_quits() { - let mut r = repl(); - assert!(r.running); - let result = run_line(&mut r, io::stdin(), io::stdout(), - ~":exit", false); - assert!(result.is_none()); - assert!(!r.running); - } -} diff --git a/src/librusti/rusti.rs b/src/librusti/rusti.rs new file mode 100644 index 00000000000..57a2a48a0f6 --- /dev/null +++ b/src/librusti/rusti.rs @@ -0,0 +1,665 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +/*! + * rusti - A REPL using the JIT backend + * + * Rusti works by serializing state between lines of input. This means that each + * line can be run in a separate task, and the only limiting factor is that all + * local bound variables are encodable. + * + * This is accomplished by feeding in generated input to rustc for execution in + * the JIT compiler. Currently input actually gets fed in three times to get + * information about the program. + * + * - Pass #1 + * In this pass, the input is simply thrown at the parser and the input comes + * back. This validates the structure of the program, and at this stage the + * global items (fns, structs, impls, traits, etc.) are filtered from the + * input into the "global namespace". These declarations shadow all previous + * declarations of an item by the same name. + * + * - Pass #2 + * After items have been stripped, the remaining input is passed to rustc + * along with all local variables declared (initialized to nothing). This pass + * runs up to typechecking. From this, we can learn about the types of each + * bound variable, what variables are bound, and also ensure that all the + * types are encodable (the input can actually be run). + * + * - Pass #3 + * Finally, a program is generated to deserialize the local variable state, + * run the code input, and then reserialize all bindings back into a local + * hash map. Once this code runs, the input has fully been run and the REPL + * waits for new input. + * + * Encoding/decoding is done with EBML, and there is simply a map of ~str -> + * ~[u8] maintaining the values of each local binding (by name). + */ + +#[link(name = "rusti", + vers = "0.7-pre", + uuid = "7fb5bf52-7d45-4fee-8325-5ad3311149fc", + url = "https://github.com/mozilla/rust/tree/master/src/rusti")]; + +#[license = "MIT/ASL2"]; +#[crate_type = "lib"]; + +extern mod extra; +extern mod rustc; +extern mod syntax; + +use std::{libc, io, os, task, vec}; +use std::cell::Cell; +use extra::rl; + +use rustc::driver::{driver, session}; +use syntax::{ast, diagnostic}; +use syntax::ast_util::*; +use syntax::parse::token; +use syntax::print::pprust; + +use program::Program; +use utils::*; + +mod program; +pub mod utils; + +/** + * A structure shared across REPL instances for storing history + * such as statements and view items. I wish the AST was sendable. + */ +pub struct Repl { + prompt: ~str, + binary: ~str, + running: bool, + lib_search_paths: ~[~str], + + program: Program, +} + +// Action to do after reading a :command +enum CmdAction { + action_none, + action_run_line(~str), +} + +/// Run an input string in a Repl, returning the new Repl. +fn run(mut repl: Repl, input: ~str) -> Repl { + // Build some necessary rustc boilerplate for compiling things + let binary = repl.binary.to_managed(); + let options = @session::options { + crate_type: session::unknown_crate, + binary: binary, + addl_lib_search_paths: @mut repl.lib_search_paths.map(|p| Path(*p)), + jit: true, + .. copy *session::basic_options() + }; + // Because we assume that everything is encodable (and assert so), add some + // extra helpful information if the error crops up. Otherwise people are + // bound to be very confused when they find out code is running that they + // never typed in... + let sess = driver::build_session(options, |cm, msg, lvl| { + diagnostic::emit(cm, msg, lvl); + if msg.contains("failed to find an implementation of trait") && + msg.contains("extra::serialize::Encodable") { + diagnostic::emit(cm, + "Currrently rusti serializes bound locals between \ + different lines of input. This means that all \ + values of local variables need to be encodable, \ + and this type isn't encodable", + diagnostic::note); + } + }); + let intr = token::get_ident_interner(); + + // + // Stage 1: parse the input and filter it into the program (as necessary) + // + debug!("parsing: %s", input); + let crate = parse_input(sess, binary, input); + let mut to_run = ~[]; // statements to run (emitted back into code) + let new_locals = @mut ~[]; // new locals being defined + let mut result = None; // resultant expression (to print via pp) + do find_main(crate, sess) |blk| { + // Fish out all the view items, be sure to record 'extern mod' items + // differently beause they must appear before all 'use' statements + for blk.node.view_items.iter().advance |vi| { + let s = do with_pp(intr) |pp, _| { + pprust::print_view_item(pp, *vi); + }; + match vi.node { + ast::view_item_extern_mod(*) => { + repl.program.record_extern(s); + } + ast::view_item_use(*) => { repl.program.record_view_item(s); } + } + } + + // Iterate through all of the block's statements, inserting them into + // the correct portions of the program + for blk.node.stmts.iter().advance |stmt| { + let s = do with_pp(intr) |pp, _| { pprust::print_stmt(pp, *stmt); }; + match stmt.node { + ast::stmt_decl(d, _) => { + match d.node { + ast::decl_item(it) => { + let name = sess.str_of(it.ident); + match it.node { + // Structs are treated specially because to make + // them at all usable they need to be decorated + // with #[deriving(Encoable, Decodable)] + ast::item_struct(*) => { + repl.program.record_struct(name, s); + } + // Item declarations are hoisted out of main() + _ => { repl.program.record_item(name, s); } + } + } + + // Local declarations must be specially dealt with, + // record all local declarations for use later on + ast::decl_local(l) => { + let mutbl = l.node.is_mutbl; + do each_binding(l) |path, _| { + let s = do with_pp(intr) |pp, _| { + pprust::print_path(pp, path, false); + }; + new_locals.push((s, mutbl)); + } + to_run.push(s); + } + } + } + + // run statements with expressions (they have effects) + ast::stmt_mac(*) | ast::stmt_semi(*) | ast::stmt_expr(*) => { + to_run.push(s); + } + } + } + result = do blk.node.expr.map_consume |e| { + do with_pp(intr) |pp, _| { pprust::print_expr(pp, e); } + }; + } + // return fast for empty inputs + if to_run.len() == 0 && result.is_none() { + return repl; + } + + // + // Stage 2: run everything up to typeck to learn the types of the new + // variables introduced into the program + // + info!("Learning about the new types in the program"); + repl.program.set_cache(); // before register_new_vars (which changes them) + let input = to_run.connect("\n"); + let test = repl.program.test_code(input, &result, *new_locals); + debug!("testing with ^^^^^^ %?", (||{ println(test) })()); + let dinput = driver::str_input(test.to_managed()); + let cfg = driver::build_configuration(sess, binary, &dinput); + let outputs = driver::build_output_filenames(&dinput, &None, &None, [], sess); + let (crate, tcx) = driver::compile_upto(sess, copy cfg, &dinput, + driver::cu_typeck, Some(outputs)); + // Once we're typechecked, record the types of all local variables defined + // in this input + do find_main(crate.expect("crate after cu_typeck"), sess) |blk| { + repl.program.register_new_vars(blk, tcx.expect("tcx after cu_typeck")); + } + + // + // Stage 3: Actually run the code in the JIT + // + info!("actually running code"); + let code = repl.program.code(input, &result); + debug!("actually running ^^^^^^ %?", (||{ println(code) })()); + let input = driver::str_input(code.to_managed()); + let cfg = driver::build_configuration(sess, binary, &input); + let outputs = driver::build_output_filenames(&input, &None, &None, [], sess); + let sess = driver::build_session(options, diagnostic::emit); + driver::compile_upto(sess, cfg, &input, driver::cu_everything, + Some(outputs)); + + // + // Stage 4: Inform the program that computation is done so it can update all + // local variable bindings. + // + info!("cleaning up after code"); + repl.program.consume_cache(); + + return repl; + + fn parse_input(sess: session::Session, binary: @str, + input: &str) -> @ast::crate { + let code = fmt!("fn main() {\n %s \n}", input); + let input = driver::str_input(code.to_managed()); + let cfg = driver::build_configuration(sess, binary, &input); + let outputs = driver::build_output_filenames(&input, &None, &None, [], sess); + let (crate, _) = driver::compile_upto(sess, cfg, &input, + driver::cu_parse, Some(outputs)); + crate.expect("parsing should return a crate") + } + + fn find_main(crate: @ast::crate, sess: session::Session, + f: &fn(&ast::blk)) { + for crate.node.module.items.iter().advance |item| { + match item.node { + ast::item_fn(_, _, _, _, ref blk) => { + if item.ident == sess.ident_of("main") { + return f(blk); + } + } + _ => {} + } + } + fail!("main function was expected somewhere..."); + } +} + +// Compiles a crate given by the filename as a library if the compiled +// version doesn't exist or is older than the source file. Binary is +// the name of the compiling executable. Returns Some(true) if it +// successfully compiled, Some(false) if the crate wasn't compiled +// because it already exists and is newer than the source file, or +// None if there were compile errors. +fn compile_crate(src_filename: ~str, binary: ~str) -> Option { + match do task::try { + let src_path = Path(src_filename); + let binary = binary.to_managed(); + let options = @session::options { + binary: binary, + addl_lib_search_paths: @mut ~[os::getcwd()], + .. copy *session::basic_options() + }; + let input = driver::file_input(copy src_path); + let sess = driver::build_session(options, diagnostic::emit); + *sess.building_library = true; + let cfg = driver::build_configuration(sess, binary, &input); + let outputs = driver::build_output_filenames( + &input, &None, &None, [], sess); + // If the library already exists and is newer than the source + // file, skip compilation and return None. + let mut should_compile = true; + let dir = os::list_dir_path(&Path(outputs.out_filename.dirname())); + let maybe_lib_path = do dir.iter().find_ |file| { + // The actual file's name has a hash value and version + // number in it which is unknown at this time, so looking + // for a file that matches out_filename won't work, + // instead we guess which file is the library by matching + // the prefix and suffix of out_filename to files in the + // directory. + let file_str = file.filename().get(); + file_str.starts_with(outputs.out_filename.filestem().get()) + && file_str.ends_with(outputs.out_filename.filetype().get()) + }; + match maybe_lib_path { + Some(lib_path) => { + let (src_mtime, _) = src_path.get_mtime().get(); + let (lib_mtime, _) = lib_path.get_mtime().get(); + if lib_mtime >= src_mtime { + should_compile = false; + } + }, + None => { }, + } + if (should_compile) { + println(fmt!("compiling %s...", src_filename)); + driver::compile_upto(sess, cfg, &input, driver::cu_everything, + Some(outputs)); + true + } else { false } + } { + Ok(true) => Some(true), + Ok(false) => Some(false), + Err(_) => None, + } +} + +/// Tries to get a line from rl after outputting a prompt. Returns +/// None if no input was read (e.g. EOF was reached). +fn get_line(use_rl: bool, prompt: &str) -> Option<~str> { + if use_rl { + let result = unsafe { rl::read(prompt) }; + + match result { + None => None, + Some(line) => { + unsafe { rl::add_history(line) }; + Some(line) + } + } + } else { + if io::stdin().eof() { + None + } else { + Some(io::stdin().read_line()) + } + } +} + +/// Run a command, e.g. :clear, :exit, etc. +fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer, + cmd: ~str, args: ~[~str], use_rl: bool) -> CmdAction { + let mut action = action_none; + match cmd { + ~"exit" => repl.running = false, + ~"clear" => { + repl.program.clear(); + + // XXX: Win32 version of linenoise can't do this + //rl::clear(); + } + ~"help" => { + println( + ":{\\n ..lines.. \\n:}\\n - execute multiline command\n\ + :load ... - loads given crates as dynamic libraries\n\ + :clear - clear the bindings\n\ + :exit - exit from the repl\n\ + :help - show this message"); + } + ~"load" => { + let mut loaded_crates: ~[~str] = ~[]; + for args.iter().advance |arg| { + let (crate, filename) = + if arg.ends_with(".rs") || arg.ends_with(".rc") { + (arg.slice_to(arg.len() - 3).to_owned(), copy *arg) + } else { + (copy *arg, *arg + ".rs") + }; + match compile_crate(filename, copy repl.binary) { + Some(_) => loaded_crates.push(crate), + None => { } + } + } + for loaded_crates.iter().advance |crate| { + let crate_path = Path(*crate); + let crate_dir = crate_path.dirname(); + repl.program.record_extern(fmt!("extern mod %s;", *crate)); + if !repl.lib_search_paths.iter().any_(|x| x == &crate_dir) { + repl.lib_search_paths.push(crate_dir); + } + } + if loaded_crates.is_empty() { + println("no crates loaded"); + } else { + println(fmt!("crates loaded: %s", + loaded_crates.connect(", "))); + } + } + ~"{" => { + let mut multiline_cmd = ~""; + let mut end_multiline = false; + while (!end_multiline) { + match get_line(use_rl, "rusti| ") { + None => fail!("unterminated multiline command :{ .. :}"), + Some(line) => { + if line.trim() == ":}" { + end_multiline = true; + } else { + multiline_cmd += line + "\n"; + } + } + } + } + action = action_run_line(multiline_cmd); + } + _ => println(~"unknown cmd: " + cmd) + } + return action; +} + +/// Executes a line of input, which may either be rust code or a +/// :command. Returns a new Repl if it has changed. +pub fn run_line(repl: &mut Repl, in: @io::Reader, out: @io::Writer, line: ~str, + use_rl: bool) + -> Option { + if line.starts_with(":") { + // drop the : and the \n (one byte each) + let full = line.slice(1, line.len()); + let split: ~[~str] = full.word_iter().transform(|s| s.to_owned()).collect(); + let len = split.len(); + + if len > 0 { + let cmd = copy split[0]; + + if !cmd.is_empty() { + let args = if len > 1 { + vec::slice(split, 1, len).to_owned() + } else { ~[] }; + + match run_cmd(repl, in, out, cmd, args, use_rl) { + action_none => { } + action_run_line(multiline_cmd) => { + if !multiline_cmd.is_empty() { + return run_line(repl, in, out, multiline_cmd, use_rl); + } + } + } + return None; + } + } + } + + let line = Cell::new(line); + let r = Cell::new(copy *repl); + let result = do task::try { + run(r.take(), line.take()) + }; + + if result.is_ok() { + return Some(result.get()); + } + return None; +} + +pub fn main() { + let args = os::args(); + let in = io::stdin(); + let out = io::stdout(); + let mut repl = Repl { + prompt: ~"rusti> ", + binary: copy args[0], + running: true, + lib_search_paths: ~[], + + program: Program::new(), + }; + + let istty = unsafe { libc::isatty(libc::STDIN_FILENO as i32) } != 0; + + // only print this stuff if the user is actually typing into rusti + if istty { + println("WARNING: The Rust REPL is experimental and may be"); + println("unstable. If you encounter problems, please use the"); + println("compiler instead. Type :help for help."); + + unsafe { + do rl::complete |line, suggest| { + if line.starts_with(":") { + suggest(~":clear"); + suggest(~":exit"); + suggest(~":help"); + suggest(~":load"); + } + } + } + } + + while repl.running { + match get_line(istty, repl.prompt) { + None => break, + Some(line) => { + if line.is_empty() { + if istty { + println("()"); + } + loop; + } + match run_line(&mut repl, in, out, line, istty) { + Some(new_repl) => repl = new_repl, + None => { } + } + } + } + } +} + +#[cfg(test)] +mod tests { + use std::io; + use std::iterator::IteratorUtil; + use program::Program; + use super::*; + + fn repl() -> Repl { + Repl { + prompt: ~"rusti> ", + binary: ~"rusti", + running: true, + lib_search_paths: ~[], + program: Program::new(), + } + } + + fn run_program(prog: &str) { + let mut r = repl(); + for prog.split_iter('\n').advance |cmd| { + let result = run_line(&mut r, io::stdin(), io::stdout(), + cmd.to_owned(), false); + r = result.expect(fmt!("the command '%s' failed", cmd)); + } + } + + #[test] + // FIXME: #7220 rusti on 32bit mac doesn't work. + #[cfg(not(target_word_size="32", + target_os="macos"))] + fn run_all() { + // FIXME(#7071): + // By default, unit tests are run in parallel. Rusti, on the other hand, + // does not enjoy doing this. I suspect that it is because the LLVM + // bindings are not thread-safe (when running parallel tests, some tests + // were triggering assertions in LLVM (or segfaults). Hence, this + // function exists to run everything serially (sadface). + // + // To get some interesting output, run with RUST_LOG=rusti::tests + + debug!("hopefully this runs"); + run_program(""); + + debug!("regression test for #5937"); + run_program("use std::hashmap;"); + + debug!("regression test for #5784"); + run_program("let a = 3;"); + + // XXX: can't spawn new tasks because the JIT code is cleaned up + // after the main function is done. + // debug!("regression test for #5803"); + // run_program(" + // spawn( || println(\"Please don't segfault\") ); + // do spawn { println(\"Please?\"); } + // "); + + debug!("inferred integers are usable"); + run_program("let a = 2;\n()\n"); + run_program(" + let a = 3; + let b = 4u; + assert!((a as uint) + b == 7) + "); + + debug!("local variables can be shadowed"); + run_program(" + let a = 3; + let a = 5; + assert!(a == 5) + "); + + debug!("strings are usable"); + run_program(" + let a = ~\"\"; + let b = \"\"; + let c = @\"\"; + let d = a + b + c; + assert!(d.len() == 0); + "); + + debug!("vectors are usable"); + run_program(" + let a = ~[1, 2, 3]; + let b = &[1, 2, 3]; + let c = @[1, 2, 3]; + let d = a + b + c; + assert!(d.len() == 9); + let e: &[int] = []; + "); + + debug!("structs are usable"); + run_program(" + struct A{ a: int } + let b = A{ a: 3 }; + assert!(b.a == 3) + "); + + debug!("mutable variables"); + run_program(" + let mut a = 3; + a = 5; + let mut b = std::hashmap::HashSet::new::(); + b.insert(a); + assert!(b.contains(&5)) + assert!(b.len() == 1) + "); + + debug!("functions are cached"); + run_program(" + fn fib(x: int) -> int { if x < 2 {x} else { fib(x - 1) + fib(x - 2) } } + let a = fib(3); + let a = a + fib(4); + assert!(a == 5) + "); + + debug!("modules are cached"); + run_program(" + mod b { pub fn foo() -> uint { 3 } } + assert!(b::foo() == 3) + "); + + debug!("multiple function definitions are allowed"); + run_program(" + fn f() {} + fn f() {} + f() + "); + + debug!("multiple item definitions are allowed"); + run_program(" + fn f() {} + mod f {} + struct f; + enum f {} + fn f() {} + f() + "); + } + + #[test] + // FIXME: #7220 rusti on 32bit mac doesn't work. + #[cfg(not(target_word_size="32", + target_os="macos"))] + fn exit_quits() { + let mut r = repl(); + assert!(r.running); + let result = run_line(&mut r, io::stdin(), io::stdout(), + ~":exit", false); + assert!(result.is_none()); + assert!(!r.running); + } +} diff --git a/src/librustpkg/rustpkg.rc b/src/librustpkg/rustpkg.rc deleted file mode 100644 index 9242e450e24..00000000000 --- a/src/librustpkg/rustpkg.rc +++ /dev/null @@ -1,474 +0,0 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// rustpkg - a package manager and build system for Rust - -#[link(name = "rustpkg", - vers = "0.7-pre", - uuid = "25de5e6e-279e-4a20-845c-4cabae92daaf", - url = "https://github.com/mozilla/rust/tree/master/src/librustpkg")]; - -#[license = "MIT/ASL2"]; -#[crate_type = "lib"]; - -#[no_core]; -#[no_std]; - -extern mod core(name = "std"); -extern mod extra(name = "extra"); - -extern mod rustc; -extern mod syntax; - -use core::prelude::*; -use core::*; -pub use core::path::Path; -use core::hashmap::HashMap; -use rustc::driver::{driver, session}; -use rustc::metadata::filesearch; -use extra::{getopts}; -use syntax::{ast, diagnostic}; -use util::*; -use messages::*; -use path_util::{build_pkg_id_in_workspace, first_pkgid_src_in_workspace}; -use path_util::{u_rwx, rust_path}; -use path_util::{built_executable_in_workspace, built_library_in_workspace}; -use path_util::{target_executable_in_workspace, target_library_in_workspace}; -use workspace::{each_pkg_parent_workspace, pkg_parent_workspaces}; -use context::Ctx; -use package_id::PkgId; -use package_source::PkgSrc; - -mod conditions; -mod context; -mod crate; -mod messages; -mod package_id; -mod package_path; -mod package_source; -mod path_util; -mod search; -mod target; -#[cfg(test)] -mod tests; -mod util; -mod version; -mod workspace; - -pub mod usage; - -mod std { - pub use core::cmp; - pub use core::condition; - pub use core::os; - pub use core::str; - pub use core::sys; - pub use core::unstable; -} - -/// A PkgScript represents user-supplied custom logic for -/// special build hooks. This only exists for packages with -/// an explicit package script. -struct PkgScript<'self> { - /// Uniquely identifies this package - id: &'self PkgId, - // Used to have this field: deps: ~[(~str, Option<~str>)] - // but I think it shouldn't be stored here - /// The contents of the package script: either a file path, - /// or a string containing the text of the input - input: driver::input, - /// The session to use *only* for compiling the custom - /// build script - sess: session::Session, - /// The config for compiling the custom build script - cfg: ast::crate_cfg, - /// The crate for the custom build script - crate: @ast::crate, - /// Directory in which to store build output - build_dir: Path -} - -impl<'self> PkgScript<'self> { - /// Given the path name for a package script - /// and a package ID, parse the package script into - /// a PkgScript that we can then execute - fn parse<'a>(script: Path, workspace: &Path, id: &'a PkgId) -> PkgScript<'a> { - // Get the executable name that was invoked - let binary = os::args()[0].to_managed(); - // Build the rustc session data structures to pass - // to the compiler - let options = @session::options { - binary: binary, - crate_type: session::bin_crate, - .. copy *session::basic_options() - }; - let input = driver::file_input(script); - let sess = driver::build_session(options, diagnostic::emit); - let cfg = driver::build_configuration(sess, binary, &input); - let (crate, _) = driver::compile_upto(sess, copy cfg, &input, driver::cu_parse, None); - let work_dir = build_pkg_id_in_workspace(id, workspace); - - debug!("Returning package script with id %?", id); - - PkgScript { - id: id, - input: input, - sess: sess, - cfg: cfg, - crate: crate.unwrap(), - build_dir: work_dir - } - } - - /// Run the contents of this package script, where - /// is the command to pass to it (e.g., "build", "clean", "install") - /// Returns a pair of an exit code and list of configs (obtained by - /// calling the package script's configs() function if it exists - // FIXME (#4432): Use workcache to only compile the script when changed - fn run_custom(&self, what: ~str) -> (~[~str], ExitCode) { - debug!("run_custom: %s", what); - let sess = self.sess; - - debug!("Working directory = %s", self.build_dir.to_str()); - // Collect together any user-defined commands in the package script - let crate = util::ready_crate(sess, self.crate); - debug!("Building output filenames with script name %s", - driver::source_name(&self.input)); - match filesearch::get_rustpkg_sysroot() { - Ok(r) => { - let root = r.pop().pop().pop().pop(); // :-\ - debug!("Root is %s, calling compile_rest", root.to_str()); - let exe = self.build_dir.push(~"pkg" + util::exe_suffix()); - let binary = os::args()[0].to_managed(); - util::compile_crate_from_input(&self.input, - &self.build_dir, - sess, - crate, - driver::build_configuration(sess, - binary, &self.input)); - debug!("Running program: %s %s %s", exe.to_str(), root.to_str(), what); - let status = run::process_status(exe.to_str(), [root.to_str(), what]); - if status != 0 { - return (~[], status); - } - else { - debug!("Running program (configs): %s %s %s", - exe.to_str(), root.to_str(), "configs"); - let output = run::process_output(exe.to_str(), [root.to_str(), ~"configs"]); - // Run the configs() function to get the configs - let cfgs = str::from_bytes_slice(output.output).word_iter() - .transform(|w| w.to_owned()).collect(); - (cfgs, output.status) - } - } - Err(e) => { - fail!("Running package script, couldn't find rustpkg sysroot (%s)", e) - } - } - } - - fn hash(&self) -> ~str { - self.id.hash() - } - -} - -impl Ctx { - - fn run(&self, cmd: &str, args: ~[~str]) { - match cmd { - "build" => { - if args.len() < 1 { - return usage::build(); - } - // The package id is presumed to be the first command-line - // argument - let pkgid = PkgId::new(copy args[0]); - for each_pkg_parent_workspace(&pkgid) |workspace| { - self.build(workspace, &pkgid); - } - } - "clean" => { - if args.len() < 1 { - return usage::build(); - } - // The package id is presumed to be the first command-line - // argument - let pkgid = PkgId::new(copy args[0]); - let cwd = os::getcwd(); - self.clean(&cwd, &pkgid); // tjc: should use workspace, not cwd - } - "do" => { - if args.len() < 2 { - return usage::do_cmd(); - } - - self.do_cmd(copy args[0], copy args[1]); - } - "info" => { - self.info(); - } - "install" => { - if args.len() < 1 { - return usage::install(); - } - - // The package id is presumed to be the first command-line - // argument - let pkgid = PkgId::new(args[0]); - let workspaces = pkg_parent_workspaces(&pkgid); - if workspaces.is_empty() { - let rp = rust_path(); - assert!(!rp.is_empty()); - let src = PkgSrc::new(&rp[0], &build_pkg_id_in_workspace(&pkgid, &rp[0]), - &pkgid); - src.fetch_git(); - self.install(&rp[0], &pkgid); - } - else { - for each_pkg_parent_workspace(&pkgid) |workspace| { - self.install(workspace, &pkgid); - } - } - } - "prefer" => { - if args.len() < 1 { - return usage::uninstall(); - } - - self.prefer(args[0], None); - } - "test" => { - self.test(); - } - "uninstall" => { - if args.len() < 1 { - return usage::uninstall(); - } - - self.uninstall(args[0], None); - } - "unprefer" => { - if args.len() < 1 { - return usage::uninstall(); - } - - self.unprefer(args[0], None); - } - _ => fail!(fmt!("I don't know the command `%s`", cmd)) - } - } - - fn do_cmd(&self, _cmd: &str, _pkgname: &str) { - // stub - fail!("`do` not yet implemented"); - } - - fn build(&self, workspace: &Path, pkgid: &PkgId) { - debug!("build: workspace = %s pkgid = %s", workspace.to_str(), - pkgid.to_str()); - let src_dir = first_pkgid_src_in_workspace(pkgid, workspace); - let build_dir = build_pkg_id_in_workspace(pkgid, workspace); - debug!("Destination dir = %s", build_dir.to_str()); - - // Create the package source - let mut src = PkgSrc::new(workspace, &build_dir, pkgid); - debug!("Package src = %?", src); - - // Is there custom build logic? If so, use it - let pkg_src_dir = src_dir; - let mut custom = false; - debug!("Package source directory = %?", pkg_src_dir); - let cfgs = match pkg_src_dir.chain_ref(|p| src.package_script_option(p)) { - Some(package_script_path) => { - let pscript = PkgScript::parse(package_script_path, - workspace, - pkgid); - // Limited right now -- we're only running the post_build - // hook and probably fail otherwise - // also post_build should be called pre_build - let (cfgs, hook_result) = pscript.run_custom(~"post_build"); - debug!("Command return code = %?", hook_result); - if hook_result != 0 { - fail!("Error running custom build command") - } - custom = true; - // otherwise, the package script succeeded - cfgs - } - None => { - debug!("No package script, continuing"); - ~[] - } - }; - - // If there was a package script, it should have finished - // the build already. Otherwise... - if !custom { - // Find crates inside the workspace - src.find_crates(); - // Build it! - src.build(self, build_dir, cfgs); - } - } - - fn clean(&self, workspace: &Path, id: &PkgId) { - // Could also support a custom build hook in the pkg - // script for cleaning files rustpkg doesn't know about. - // Do something reasonable for now - - let dir = build_pkg_id_in_workspace(id, workspace); - note(fmt!("Cleaning package %s (removing directory %s)", - id.to_str(), dir.to_str())); - if os::path_exists(&dir) { - os::remove_dir_recursive(&dir); - note(fmt!("Removed directory %s", dir.to_str())); - } - - note(fmt!("Cleaned package %s", id.to_str())); - } - - fn info(&self) { - // stub - fail!("info not yet implemented"); - } - - fn install(&self, workspace: &Path, id: &PkgId) { - use conditions::copy_failed::cond; - - // Should use RUST_PATH in the future. - // Also should use workcache to not build if not necessary. - self.build(workspace, id); - debug!("install: workspace = %s, id = %s", workspace.to_str(), - id.to_str()); - - // Now copy stuff into the install dirs - let maybe_executable = built_executable_in_workspace(id, workspace); - let maybe_library = built_library_in_workspace(id, workspace); - let target_exec = target_executable_in_workspace(id, workspace); - let target_lib = maybe_library.map(|_p| target_library_in_workspace(id, workspace)); - - debug!("target_exec = %s target_lib = %? \ - maybe_executable = %? maybe_library = %?", - target_exec.to_str(), target_lib, - maybe_executable, maybe_library); - - for maybe_executable.iter().advance |exec| { - debug!("Copying: %s -> %s", exec.to_str(), target_exec.to_str()); - if !(os::mkdir_recursive(&target_exec.dir_path(), u_rwx) && - os::copy_file(exec, &target_exec)) { - cond.raise((copy *exec, copy target_exec)); - } - } - for maybe_library.iter().advance |lib| { - let target_lib = (copy target_lib).expect(fmt!("I built %s but apparently \ - didn't install it!", lib.to_str())); - debug!("Copying: %s -> %s", lib.to_str(), target_lib.to_str()); - if !(os::mkdir_recursive(&target_lib.dir_path(), u_rwx) && - os::copy_file(lib, &target_lib)) { - cond.raise((copy *lib, copy target_lib)); - } - } - } - - fn prefer(&self, _id: &str, _vers: Option<~str>) { - fail!("prefer not yet implemented"); - } - - fn test(&self) { - // stub - fail!("test not yet implemented"); - } - - fn uninstall(&self, _id: &str, _vers: Option<~str>) { - fail!("uninstall not yet implemented"); - } - - fn unprefer(&self, _id: &str, _vers: Option<~str>) { - fail!("unprefer not yet implemented"); - } -} - - -pub fn main() { - io::println("WARNING: The Rust package manager is experimental and may be unstable"); - - let args = os::args(); - let opts = ~[getopts::optflag("h"), getopts::optflag("help"), - getopts::optflag("j"), getopts::optflag("json"), - getopts::optmulti("c"), getopts::optmulti("cfg")]; - let matches = &match getopts::getopts(args, opts) { - result::Ok(m) => m, - result::Err(f) => { - error(fmt!("%s", getopts::fail_str(f))); - - return; - } - }; - let help = getopts::opt_present(matches, "h") || - getopts::opt_present(matches, "help"); - let json = getopts::opt_present(matches, "j") || - getopts::opt_present(matches, "json"); - let mut args = copy matches.free; - - args.shift(); - - if (args.len() < 1) { - return usage::general(); - } - - let cmd = args.shift(); - - if !util::is_cmd(cmd) { - return usage::general(); - } else if help { - return match cmd { - ~"build" => usage::build(), - ~"clean" => usage::clean(), - ~"do" => usage::do_cmd(), - ~"info" => usage::info(), - ~"install" => usage::install(), - ~"prefer" => usage::prefer(), - ~"test" => usage::test(), - ~"uninstall" => usage::uninstall(), - ~"unprefer" => usage::unprefer(), - _ => usage::general() - }; - } - - let sroot = match filesearch::get_rustpkg_sysroot() { - Ok(r) => Some(@r.pop().pop()), Err(_) => None - }; - debug!("Using sysroot: %?", sroot); - Ctx { - sysroot_opt: sroot, // Currently, only tests override this - json: json, - dep_cache: @mut HashMap::new() - }.run(cmd, args); -} - -/** - * Get the working directory of the package script. - * Assumes that the package script has been compiled - * in is the working directory. - */ -pub fn work_dir() -> Path { - os::self_exe_path().get() -} - -/** - * Get the source directory of the package (i.e. - * where the crates are located). Assumes - * that the cwd is changed to it before - * running this executable. - */ -pub fn src_dir() -> Path { - os::getcwd() -} diff --git a/src/librustpkg/rustpkg.rs b/src/librustpkg/rustpkg.rs new file mode 100644 index 00000000000..9242e450e24 --- /dev/null +++ b/src/librustpkg/rustpkg.rs @@ -0,0 +1,474 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// rustpkg - a package manager and build system for Rust + +#[link(name = "rustpkg", + vers = "0.7-pre", + uuid = "25de5e6e-279e-4a20-845c-4cabae92daaf", + url = "https://github.com/mozilla/rust/tree/master/src/librustpkg")]; + +#[license = "MIT/ASL2"]; +#[crate_type = "lib"]; + +#[no_core]; +#[no_std]; + +extern mod core(name = "std"); +extern mod extra(name = "extra"); + +extern mod rustc; +extern mod syntax; + +use core::prelude::*; +use core::*; +pub use core::path::Path; +use core::hashmap::HashMap; +use rustc::driver::{driver, session}; +use rustc::metadata::filesearch; +use extra::{getopts}; +use syntax::{ast, diagnostic}; +use util::*; +use messages::*; +use path_util::{build_pkg_id_in_workspace, first_pkgid_src_in_workspace}; +use path_util::{u_rwx, rust_path}; +use path_util::{built_executable_in_workspace, built_library_in_workspace}; +use path_util::{target_executable_in_workspace, target_library_in_workspace}; +use workspace::{each_pkg_parent_workspace, pkg_parent_workspaces}; +use context::Ctx; +use package_id::PkgId; +use package_source::PkgSrc; + +mod conditions; +mod context; +mod crate; +mod messages; +mod package_id; +mod package_path; +mod package_source; +mod path_util; +mod search; +mod target; +#[cfg(test)] +mod tests; +mod util; +mod version; +mod workspace; + +pub mod usage; + +mod std { + pub use core::cmp; + pub use core::condition; + pub use core::os; + pub use core::str; + pub use core::sys; + pub use core::unstable; +} + +/// A PkgScript represents user-supplied custom logic for +/// special build hooks. This only exists for packages with +/// an explicit package script. +struct PkgScript<'self> { + /// Uniquely identifies this package + id: &'self PkgId, + // Used to have this field: deps: ~[(~str, Option<~str>)] + // but I think it shouldn't be stored here + /// The contents of the package script: either a file path, + /// or a string containing the text of the input + input: driver::input, + /// The session to use *only* for compiling the custom + /// build script + sess: session::Session, + /// The config for compiling the custom build script + cfg: ast::crate_cfg, + /// The crate for the custom build script + crate: @ast::crate, + /// Directory in which to store build output + build_dir: Path +} + +impl<'self> PkgScript<'self> { + /// Given the path name for a package script + /// and a package ID, parse the package script into + /// a PkgScript that we can then execute + fn parse<'a>(script: Path, workspace: &Path, id: &'a PkgId) -> PkgScript<'a> { + // Get the executable name that was invoked + let binary = os::args()[0].to_managed(); + // Build the rustc session data structures to pass + // to the compiler + let options = @session::options { + binary: binary, + crate_type: session::bin_crate, + .. copy *session::basic_options() + }; + let input = driver::file_input(script); + let sess = driver::build_session(options, diagnostic::emit); + let cfg = driver::build_configuration(sess, binary, &input); + let (crate, _) = driver::compile_upto(sess, copy cfg, &input, driver::cu_parse, None); + let work_dir = build_pkg_id_in_workspace(id, workspace); + + debug!("Returning package script with id %?", id); + + PkgScript { + id: id, + input: input, + sess: sess, + cfg: cfg, + crate: crate.unwrap(), + build_dir: work_dir + } + } + + /// Run the contents of this package script, where + /// is the command to pass to it (e.g., "build", "clean", "install") + /// Returns a pair of an exit code and list of configs (obtained by + /// calling the package script's configs() function if it exists + // FIXME (#4432): Use workcache to only compile the script when changed + fn run_custom(&self, what: ~str) -> (~[~str], ExitCode) { + debug!("run_custom: %s", what); + let sess = self.sess; + + debug!("Working directory = %s", self.build_dir.to_str()); + // Collect together any user-defined commands in the package script + let crate = util::ready_crate(sess, self.crate); + debug!("Building output filenames with script name %s", + driver::source_name(&self.input)); + match filesearch::get_rustpkg_sysroot() { + Ok(r) => { + let root = r.pop().pop().pop().pop(); // :-\ + debug!("Root is %s, calling compile_rest", root.to_str()); + let exe = self.build_dir.push(~"pkg" + util::exe_suffix()); + let binary = os::args()[0].to_managed(); + util::compile_crate_from_input(&self.input, + &self.build_dir, + sess, + crate, + driver::build_configuration(sess, + binary, &self.input)); + debug!("Running program: %s %s %s", exe.to_str(), root.to_str(), what); + let status = run::process_status(exe.to_str(), [root.to_str(), what]); + if status != 0 { + return (~[], status); + } + else { + debug!("Running program (configs): %s %s %s", + exe.to_str(), root.to_str(), "configs"); + let output = run::process_output(exe.to_str(), [root.to_str(), ~"configs"]); + // Run the configs() function to get the configs + let cfgs = str::from_bytes_slice(output.output).word_iter() + .transform(|w| w.to_owned()).collect(); + (cfgs, output.status) + } + } + Err(e) => { + fail!("Running package script, couldn't find rustpkg sysroot (%s)", e) + } + } + } + + fn hash(&self) -> ~str { + self.id.hash() + } + +} + +impl Ctx { + + fn run(&self, cmd: &str, args: ~[~str]) { + match cmd { + "build" => { + if args.len() < 1 { + return usage::build(); + } + // The package id is presumed to be the first command-line + // argument + let pkgid = PkgId::new(copy args[0]); + for each_pkg_parent_workspace(&pkgid) |workspace| { + self.build(workspace, &pkgid); + } + } + "clean" => { + if args.len() < 1 { + return usage::build(); + } + // The package id is presumed to be the first command-line + // argument + let pkgid = PkgId::new(copy args[0]); + let cwd = os::getcwd(); + self.clean(&cwd, &pkgid); // tjc: should use workspace, not cwd + } + "do" => { + if args.len() < 2 { + return usage::do_cmd(); + } + + self.do_cmd(copy args[0], copy args[1]); + } + "info" => { + self.info(); + } + "install" => { + if args.len() < 1 { + return usage::install(); + } + + // The package id is presumed to be the first command-line + // argument + let pkgid = PkgId::new(args[0]); + let workspaces = pkg_parent_workspaces(&pkgid); + if workspaces.is_empty() { + let rp = rust_path(); + assert!(!rp.is_empty()); + let src = PkgSrc::new(&rp[0], &build_pkg_id_in_workspace(&pkgid, &rp[0]), + &pkgid); + src.fetch_git(); + self.install(&rp[0], &pkgid); + } + else { + for each_pkg_parent_workspace(&pkgid) |workspace| { + self.install(workspace, &pkgid); + } + } + } + "prefer" => { + if args.len() < 1 { + return usage::uninstall(); + } + + self.prefer(args[0], None); + } + "test" => { + self.test(); + } + "uninstall" => { + if args.len() < 1 { + return usage::uninstall(); + } + + self.uninstall(args[0], None); + } + "unprefer" => { + if args.len() < 1 { + return usage::uninstall(); + } + + self.unprefer(args[0], None); + } + _ => fail!(fmt!("I don't know the command `%s`", cmd)) + } + } + + fn do_cmd(&self, _cmd: &str, _pkgname: &str) { + // stub + fail!("`do` not yet implemented"); + } + + fn build(&self, workspace: &Path, pkgid: &PkgId) { + debug!("build: workspace = %s pkgid = %s", workspace.to_str(), + pkgid.to_str()); + let src_dir = first_pkgid_src_in_workspace(pkgid, workspace); + let build_dir = build_pkg_id_in_workspace(pkgid, workspace); + debug!("Destination dir = %s", build_dir.to_str()); + + // Create the package source + let mut src = PkgSrc::new(workspace, &build_dir, pkgid); + debug!("Package src = %?", src); + + // Is there custom build logic? If so, use it + let pkg_src_dir = src_dir; + let mut custom = false; + debug!("Package source directory = %?", pkg_src_dir); + let cfgs = match pkg_src_dir.chain_ref(|p| src.package_script_option(p)) { + Some(package_script_path) => { + let pscript = PkgScript::parse(package_script_path, + workspace, + pkgid); + // Limited right now -- we're only running the post_build + // hook and probably fail otherwise + // also post_build should be called pre_build + let (cfgs, hook_result) = pscript.run_custom(~"post_build"); + debug!("Command return code = %?", hook_result); + if hook_result != 0 { + fail!("Error running custom build command") + } + custom = true; + // otherwise, the package script succeeded + cfgs + } + None => { + debug!("No package script, continuing"); + ~[] + } + }; + + // If there was a package script, it should have finished + // the build already. Otherwise... + if !custom { + // Find crates inside the workspace + src.find_crates(); + // Build it! + src.build(self, build_dir, cfgs); + } + } + + fn clean(&self, workspace: &Path, id: &PkgId) { + // Could also support a custom build hook in the pkg + // script for cleaning files rustpkg doesn't know about. + // Do something reasonable for now + + let dir = build_pkg_id_in_workspace(id, workspace); + note(fmt!("Cleaning package %s (removing directory %s)", + id.to_str(), dir.to_str())); + if os::path_exists(&dir) { + os::remove_dir_recursive(&dir); + note(fmt!("Removed directory %s", dir.to_str())); + } + + note(fmt!("Cleaned package %s", id.to_str())); + } + + fn info(&self) { + // stub + fail!("info not yet implemented"); + } + + fn install(&self, workspace: &Path, id: &PkgId) { + use conditions::copy_failed::cond; + + // Should use RUST_PATH in the future. + // Also should use workcache to not build if not necessary. + self.build(workspace, id); + debug!("install: workspace = %s, id = %s", workspace.to_str(), + id.to_str()); + + // Now copy stuff into the install dirs + let maybe_executable = built_executable_in_workspace(id, workspace); + let maybe_library = built_library_in_workspace(id, workspace); + let target_exec = target_executable_in_workspace(id, workspace); + let target_lib = maybe_library.map(|_p| target_library_in_workspace(id, workspace)); + + debug!("target_exec = %s target_lib = %? \ + maybe_executable = %? maybe_library = %?", + target_exec.to_str(), target_lib, + maybe_executable, maybe_library); + + for maybe_executable.iter().advance |exec| { + debug!("Copying: %s -> %s", exec.to_str(), target_exec.to_str()); + if !(os::mkdir_recursive(&target_exec.dir_path(), u_rwx) && + os::copy_file(exec, &target_exec)) { + cond.raise((copy *exec, copy target_exec)); + } + } + for maybe_library.iter().advance |lib| { + let target_lib = (copy target_lib).expect(fmt!("I built %s but apparently \ + didn't install it!", lib.to_str())); + debug!("Copying: %s -> %s", lib.to_str(), target_lib.to_str()); + if !(os::mkdir_recursive(&target_lib.dir_path(), u_rwx) && + os::copy_file(lib, &target_lib)) { + cond.raise((copy *lib, copy target_lib)); + } + } + } + + fn prefer(&self, _id: &str, _vers: Option<~str>) { + fail!("prefer not yet implemented"); + } + + fn test(&self) { + // stub + fail!("test not yet implemented"); + } + + fn uninstall(&self, _id: &str, _vers: Option<~str>) { + fail!("uninstall not yet implemented"); + } + + fn unprefer(&self, _id: &str, _vers: Option<~str>) { + fail!("unprefer not yet implemented"); + } +} + + +pub fn main() { + io::println("WARNING: The Rust package manager is experimental and may be unstable"); + + let args = os::args(); + let opts = ~[getopts::optflag("h"), getopts::optflag("help"), + getopts::optflag("j"), getopts::optflag("json"), + getopts::optmulti("c"), getopts::optmulti("cfg")]; + let matches = &match getopts::getopts(args, opts) { + result::Ok(m) => m, + result::Err(f) => { + error(fmt!("%s", getopts::fail_str(f))); + + return; + } + }; + let help = getopts::opt_present(matches, "h") || + getopts::opt_present(matches, "help"); + let json = getopts::opt_present(matches, "j") || + getopts::opt_present(matches, "json"); + let mut args = copy matches.free; + + args.shift(); + + if (args.len() < 1) { + return usage::general(); + } + + let cmd = args.shift(); + + if !util::is_cmd(cmd) { + return usage::general(); + } else if help { + return match cmd { + ~"build" => usage::build(), + ~"clean" => usage::clean(), + ~"do" => usage::do_cmd(), + ~"info" => usage::info(), + ~"install" => usage::install(), + ~"prefer" => usage::prefer(), + ~"test" => usage::test(), + ~"uninstall" => usage::uninstall(), + ~"unprefer" => usage::unprefer(), + _ => usage::general() + }; + } + + let sroot = match filesearch::get_rustpkg_sysroot() { + Ok(r) => Some(@r.pop().pop()), Err(_) => None + }; + debug!("Using sysroot: %?", sroot); + Ctx { + sysroot_opt: sroot, // Currently, only tests override this + json: json, + dep_cache: @mut HashMap::new() + }.run(cmd, args); +} + +/** + * Get the working directory of the package script. + * Assumes that the package script has been compiled + * in is the working directory. + */ +pub fn work_dir() -> Path { + os::self_exe_path().get() +} + +/** + * Get the source directory of the package (i.e. + * where the crates are located). Assumes + * that the cwd is changed to it before + * running this executable. + */ +pub fn src_dir() -> Path { + os::getcwd() +} diff --git a/src/libstd/core.rc b/src/libstd/core.rc deleted file mode 100644 index 13c54799fac..00000000000 --- a/src/libstd/core.rc +++ /dev/null @@ -1,230 +0,0 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -/*! - -# The Rust standard library - -The Rust standard library is a group of interrelated modules defining -the core language traits, operations on built-in data types, collections, -platform abstractions, the task scheduler, runtime support for language -features and other common functionality. - -`std` includes modules corresponding to each of the integer types, -each of the floating point types, the `bool` type, tuples, characters, -strings (`str`), vectors (`vec`), managed boxes (`managed`), owned -boxes (`owned`), and unsafe and borrowed pointers (`ptr`, `borrowed`). -Additionally, `std` provides pervasive types (`option` and `result`), -task creation and communication primitives (`task`, `comm`), platform -abstractions (`os` and `path`), basic I/O abstractions (`io`), common -traits (`kinds`, `ops`, `cmp`, `num`, `to_str`), and complete bindings -to the C standard library (`libc`). - -# Standard library injection and the Rust prelude - -`std` is imported at the topmost level of every crate by default, as -if the first line of each crate was - - extern mod std; - -This means that the contents of std can be accessed from any context -with the `std::` path prefix, as in `use std::vec`, `use std::task::spawn`, -etc. - -Additionally, `std` contains a `prelude` module that reexports many of the -most common types, traits and functions. The contents of the prelude are -imported into every *module* by default. Implicitly, all modules behave as if -they contained the following prologue: - - use std::prelude::*; - -*/ - - -#[link(name = "std", - vers = "0.7-pre", - uuid = "c70c24a7-5551-4f73-8e37-380b11d80be8", - url = "https://github.com/mozilla/rust/tree/master/src/libstd")]; - -#[comment = "The Rust standard library"]; -#[license = "MIT/ASL2"]; -#[crate_type = "lib"]; - -// Don't link to std. We are std. -#[no_std]; - -#[deny(non_camel_case_types)]; -#[deny(missing_doc)]; - -// Make std testable by not duplicating lang items. See #2912 -#[cfg(test)] extern mod realstd(name = "std"); -#[cfg(test)] pub use kinds = realstd::kinds; -#[cfg(test)] pub use ops = realstd::ops; -#[cfg(test)] pub use cmp = realstd::cmp; - -// On Linux, link to the runtime with -lrt. -#[cfg(target_os = "linux")] -#[doc(hidden)] -pub mod linkhack { - #[link_args="-lrustrt -lrt"] - #[link_args = "-lpthread"] - extern { - } -} - -// Internal macros -mod macros; - -/* The Prelude. */ - -pub mod prelude; - -/* Primitive types */ - -#[path = "num/int_macros.rs"] mod int_macros; -#[path = "num/uint_macros.rs"] mod uint_macros; - -#[path = "num/int.rs"] pub mod int; -#[path = "num/i8.rs"] pub mod i8; -#[path = "num/i16.rs"] pub mod i16; -#[path = "num/i32.rs"] pub mod i32; -#[path = "num/i64.rs"] pub mod i64; - -#[path = "num/uint.rs"] pub mod uint; -#[path = "num/u8.rs"] pub mod u8; -#[path = "num/u16.rs"] pub mod u16; -#[path = "num/u32.rs"] pub mod u32; -#[path = "num/u64.rs"] pub mod u64; - -#[path = "num/float.rs"] pub mod float; -#[path = "num/f32.rs"] pub mod f32; -#[path = "num/f64.rs"] pub mod f64; - -pub mod nil; -pub mod bool; -pub mod char; -pub mod tuple; - -pub mod vec; -pub mod at_vec; -pub mod str; - -#[path = "str/ascii.rs"] -pub mod ascii; - -pub mod ptr; -pub mod owned; -pub mod managed; -pub mod borrow; - - -/* Core language traits */ - -#[cfg(not(test))] pub mod kinds; -#[cfg(not(test))] pub mod ops; -#[cfg(not(test))] pub mod cmp; - - -/* Common traits */ - -pub mod from_str; -#[path = "num/num.rs"] -pub mod num; -pub mod iter; -pub mod iterator; -pub mod to_str; -pub mod to_bytes; -pub mod clone; -pub mod io; -pub mod hash; -pub mod container; - - -/* Common data structures */ - -pub mod option; -pub mod result; -pub mod either; -pub mod hashmap; -pub mod cell; -pub mod trie; - - -/* Tasks and communication */ - -#[path = "task/mod.rs"] -pub mod task; -pub mod comm; -pub mod pipes; -pub mod local_data; - - -/* Runtime and platform support */ - -pub mod gc; -pub mod libc; -pub mod os; -pub mod path; -pub mod rand; -pub mod run; -pub mod sys; -pub mod cast; -pub mod repr; -pub mod cleanup; -pub mod reflect; -pub mod condition; -pub mod logging; -pub mod util; - - -/* Unsupported interfaces */ - -// Private APIs -#[path = "unstable/mod.rs"] -pub mod unstable; - -/* For internal use, not exported */ - -mod unicode; -#[path = "num/cmath.rs"] -mod cmath; -mod stackwalk; - -// XXX: This shouldn't be pub, and it should be reexported under 'unstable' -// but name resolution doesn't work without it being pub. -#[path = "rt/mod.rs"] -pub mod rt; - -// A curious inner-module that's not exported that contains the binding -// 'std' so that macro-expanded references to std::error and such -// can be resolved within libstd. -#[doc(hidden)] -mod core { - pub use clone; - pub use cmp; - pub use condition; - pub use option; - pub use kinds; - pub use sys; - pub use pipes; -} -#[doc(hidden)] -mod std { - pub use clone; - pub use cmp; - pub use condition; - pub use option; - pub use kinds; - pub use sys; - pub use pipes; - pub use unstable; - pub use str; - pub use os; -} diff --git a/src/libstd/std.rs b/src/libstd/std.rs new file mode 100644 index 00000000000..13c54799fac --- /dev/null +++ b/src/libstd/std.rs @@ -0,0 +1,230 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +/*! + +# The Rust standard library + +The Rust standard library is a group of interrelated modules defining +the core language traits, operations on built-in data types, collections, +platform abstractions, the task scheduler, runtime support for language +features and other common functionality. + +`std` includes modules corresponding to each of the integer types, +each of the floating point types, the `bool` type, tuples, characters, +strings (`str`), vectors (`vec`), managed boxes (`managed`), owned +boxes (`owned`), and unsafe and borrowed pointers (`ptr`, `borrowed`). +Additionally, `std` provides pervasive types (`option` and `result`), +task creation and communication primitives (`task`, `comm`), platform +abstractions (`os` and `path`), basic I/O abstractions (`io`), common +traits (`kinds`, `ops`, `cmp`, `num`, `to_str`), and complete bindings +to the C standard library (`libc`). + +# Standard library injection and the Rust prelude + +`std` is imported at the topmost level of every crate by default, as +if the first line of each crate was + + extern mod std; + +This means that the contents of std can be accessed from any context +with the `std::` path prefix, as in `use std::vec`, `use std::task::spawn`, +etc. + +Additionally, `std` contains a `prelude` module that reexports many of the +most common types, traits and functions. The contents of the prelude are +imported into every *module* by default. Implicitly, all modules behave as if +they contained the following prologue: + + use std::prelude::*; + +*/ + + +#[link(name = "std", + vers = "0.7-pre", + uuid = "c70c24a7-5551-4f73-8e37-380b11d80be8", + url = "https://github.com/mozilla/rust/tree/master/src/libstd")]; + +#[comment = "The Rust standard library"]; +#[license = "MIT/ASL2"]; +#[crate_type = "lib"]; + +// Don't link to std. We are std. +#[no_std]; + +#[deny(non_camel_case_types)]; +#[deny(missing_doc)]; + +// Make std testable by not duplicating lang items. See #2912 +#[cfg(test)] extern mod realstd(name = "std"); +#[cfg(test)] pub use kinds = realstd::kinds; +#[cfg(test)] pub use ops = realstd::ops; +#[cfg(test)] pub use cmp = realstd::cmp; + +// On Linux, link to the runtime with -lrt. +#[cfg(target_os = "linux")] +#[doc(hidden)] +pub mod linkhack { + #[link_args="-lrustrt -lrt"] + #[link_args = "-lpthread"] + extern { + } +} + +// Internal macros +mod macros; + +/* The Prelude. */ + +pub mod prelude; + +/* Primitive types */ + +#[path = "num/int_macros.rs"] mod int_macros; +#[path = "num/uint_macros.rs"] mod uint_macros; + +#[path = "num/int.rs"] pub mod int; +#[path = "num/i8.rs"] pub mod i8; +#[path = "num/i16.rs"] pub mod i16; +#[path = "num/i32.rs"] pub mod i32; +#[path = "num/i64.rs"] pub mod i64; + +#[path = "num/uint.rs"] pub mod uint; +#[path = "num/u8.rs"] pub mod u8; +#[path = "num/u16.rs"] pub mod u16; +#[path = "num/u32.rs"] pub mod u32; +#[path = "num/u64.rs"] pub mod u64; + +#[path = "num/float.rs"] pub mod float; +#[path = "num/f32.rs"] pub mod f32; +#[path = "num/f64.rs"] pub mod f64; + +pub mod nil; +pub mod bool; +pub mod char; +pub mod tuple; + +pub mod vec; +pub mod at_vec; +pub mod str; + +#[path = "str/ascii.rs"] +pub mod ascii; + +pub mod ptr; +pub mod owned; +pub mod managed; +pub mod borrow; + + +/* Core language traits */ + +#[cfg(not(test))] pub mod kinds; +#[cfg(not(test))] pub mod ops; +#[cfg(not(test))] pub mod cmp; + + +/* Common traits */ + +pub mod from_str; +#[path = "num/num.rs"] +pub mod num; +pub mod iter; +pub mod iterator; +pub mod to_str; +pub mod to_bytes; +pub mod clone; +pub mod io; +pub mod hash; +pub mod container; + + +/* Common data structures */ + +pub mod option; +pub mod result; +pub mod either; +pub mod hashmap; +pub mod cell; +pub mod trie; + + +/* Tasks and communication */ + +#[path = "task/mod.rs"] +pub mod task; +pub mod comm; +pub mod pipes; +pub mod local_data; + + +/* Runtime and platform support */ + +pub mod gc; +pub mod libc; +pub mod os; +pub mod path; +pub mod rand; +pub mod run; +pub mod sys; +pub mod cast; +pub mod repr; +pub mod cleanup; +pub mod reflect; +pub mod condition; +pub mod logging; +pub mod util; + + +/* Unsupported interfaces */ + +// Private APIs +#[path = "unstable/mod.rs"] +pub mod unstable; + +/* For internal use, not exported */ + +mod unicode; +#[path = "num/cmath.rs"] +mod cmath; +mod stackwalk; + +// XXX: This shouldn't be pub, and it should be reexported under 'unstable' +// but name resolution doesn't work without it being pub. +#[path = "rt/mod.rs"] +pub mod rt; + +// A curious inner-module that's not exported that contains the binding +// 'std' so that macro-expanded references to std::error and such +// can be resolved within libstd. +#[doc(hidden)] +mod core { + pub use clone; + pub use cmp; + pub use condition; + pub use option; + pub use kinds; + pub use sys; + pub use pipes; +} +#[doc(hidden)] +mod std { + pub use clone; + pub use cmp; + pub use condition; + pub use option; + pub use kinds; + pub use sys; + pub use pipes; + pub use unstable; + pub use str; + pub use os; +} diff --git a/src/libsyntax/syntax.rc b/src/libsyntax/syntax.rc deleted file mode 100644 index 278600bc039..00000000000 --- a/src/libsyntax/syntax.rc +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -/*! This module contains the Rust parser. It maps source text - * to token trees and to ASTs. It contains code for expanding - * macros. - */ - -#[link(name = "syntax", - vers = "0.7-pre", - uuid = "9311401b-d6ea-4cd9-a1d9-61f89499c645")]; - -#[license = "MIT/ASL2"]; -#[crate_type = "lib"]; - -#[allow(non_camel_case_types)]; -#[deny(deprecated_pattern)]; - -#[no_core]; -#[no_std]; - -extern mod core(name = "std"); -extern mod extra(name = "extra"); - -// For deriving(Encodable) purposes... -extern mod std(name = "std"); - -use core::prelude::*; - -pub mod util { - pub mod interner; - #[cfg(test)] - pub mod parser_testing; -} - -pub mod syntax { - pub use ext; - pub use parse; -} - -pub mod opt_vec; -pub mod attr; -pub mod diagnostic; -pub mod codemap; -pub mod abi; -pub mod ast; -pub mod ast_util; -pub mod ast_map; -pub mod visit; -pub mod fold; - - -#[path = "parse/mod.rs"] -pub mod parse; - -pub mod print { - pub mod pp; - pub mod pprust; -} - -pub mod ext { - pub mod asm; - pub mod base; - pub mod expand; - - pub mod quote; - - #[path = "deriving/mod.rs"] - pub mod deriving; - - pub mod build; - - pub mod tt { - pub mod transcribe; - pub mod macro_parser; - pub mod macro_rules; - } - - - pub mod fmt; - pub mod env; - pub mod bytes; - pub mod concat_idents; - pub mod log_syntax; - pub mod auto_encode; - pub mod source_util; - - #[path = "pipes/mod.rs"] - pub mod pipes; - - pub mod trace_macros; -} diff --git a/src/libsyntax/syntax.rs b/src/libsyntax/syntax.rs new file mode 100644 index 00000000000..278600bc039 --- /dev/null +++ b/src/libsyntax/syntax.rs @@ -0,0 +1,99 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +/*! This module contains the Rust parser. It maps source text + * to token trees and to ASTs. It contains code for expanding + * macros. + */ + +#[link(name = "syntax", + vers = "0.7-pre", + uuid = "9311401b-d6ea-4cd9-a1d9-61f89499c645")]; + +#[license = "MIT/ASL2"]; +#[crate_type = "lib"]; + +#[allow(non_camel_case_types)]; +#[deny(deprecated_pattern)]; + +#[no_core]; +#[no_std]; + +extern mod core(name = "std"); +extern mod extra(name = "extra"); + +// For deriving(Encodable) purposes... +extern mod std(name = "std"); + +use core::prelude::*; + +pub mod util { + pub mod interner; + #[cfg(test)] + pub mod parser_testing; +} + +pub mod syntax { + pub use ext; + pub use parse; +} + +pub mod opt_vec; +pub mod attr; +pub mod diagnostic; +pub mod codemap; +pub mod abi; +pub mod ast; +pub mod ast_util; +pub mod ast_map; +pub mod visit; +pub mod fold; + + +#[path = "parse/mod.rs"] +pub mod parse; + +pub mod print { + pub mod pp; + pub mod pprust; +} + +pub mod ext { + pub mod asm; + pub mod base; + pub mod expand; + + pub mod quote; + + #[path = "deriving/mod.rs"] + pub mod deriving; + + pub mod build; + + pub mod tt { + pub mod transcribe; + pub mod macro_parser; + pub mod macro_rules; + } + + + pub mod fmt; + pub mod env; + pub mod bytes; + pub mod concat_idents; + pub mod log_syntax; + pub mod auto_encode; + pub mod source_util; + + #[path = "pipes/mod.rs"] + pub mod pipes; + + pub mod trace_macros; +} -- cgit 1.4.1-3-g733a5 From 64ee9668a2e3d4d75b859fd3bca1466a97fae2d8 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Mon, 24 Jun 2013 17:45:00 -0400 Subject: container: remove internal iterators from Map the maps are being migrated to external iterators --- src/libextra/smallintmap.rs | 64 +++++++++++----------- src/libextra/treemap.rs | 40 +++++++------- src/libstd/container.rs | 12 ---- src/libstd/hashmap.rs | 56 +++++++++---------- src/libstd/trie.rs | 48 ++++++++-------- .../class-impl-very-parameterized-trait.rs | 21 ------- 6 files changed, 104 insertions(+), 137 deletions(-) (limited to 'src/libstd') diff --git a/src/libextra/smallintmap.rs b/src/libextra/smallintmap.rs index 17126f0d32b..1d163922955 100644 --- a/src/libextra/smallintmap.rs +++ b/src/libextra/smallintmap.rs @@ -56,38 +56,6 @@ impl Map for SmallIntMap { self.find(key).is_some() } - /// Visit all key-value pairs in order - fn each<'a>(&'a self, it: &fn(&uint, &'a V) -> bool) -> bool { - for uint::range(0, self.v.len()) |i| { - match self.v[i] { - Some(ref elt) => if !it(&i, elt) { return false; }, - None => () - } - } - return true; - } - - /// Visit all keys in order - fn each_key(&self, blk: &fn(key: &uint) -> bool) -> bool { - self.each(|k, _| blk(k)) - } - - /// Visit all values in order - fn each_value<'a>(&'a self, blk: &fn(value: &'a V) -> bool) -> bool { - self.each(|_, v| blk(v)) - } - - /// Iterate over the map and mutate the contained values - fn mutate_values(&mut self, it: &fn(&uint, &mut V) -> bool) -> bool { - for uint::range(0, self.v.len()) |i| { - match self.v[i] { - Some(ref mut elt) => if !it(&i, elt) { return false; }, - None => () - } - } - return true; - } - /// Return a reference to the value corresponding to the key fn find<'a>(&'a self, key: &uint) -> Option<&'a V> { if *key < self.v.len() { @@ -156,6 +124,38 @@ impl SmallIntMap { /// Create an empty SmallIntMap pub fn new() -> SmallIntMap { SmallIntMap{v: ~[]} } + /// Visit all key-value pairs in order + pub fn each<'a>(&'a self, it: &fn(&uint, &'a V) -> bool) -> bool { + for uint::range(0, self.v.len()) |i| { + match self.v[i] { + Some(ref elt) => if !it(&i, elt) { return false; }, + None => () + } + } + return true; + } + + /// Visit all keys in order + pub fn each_key(&self, blk: &fn(key: &uint) -> bool) -> bool { + self.each(|k, _| blk(k)) + } + + /// Visit all values in order + pub fn each_value<'a>(&'a self, blk: &fn(value: &'a V) -> bool) -> bool { + self.each(|_, v| blk(v)) + } + + /// Iterate over the map and mutate the contained values + pub fn mutate_values(&mut self, it: &fn(&uint, &mut V) -> bool) -> bool { + for uint::range(0, self.v.len()) |i| { + match self.v[i] { + Some(ref mut elt) => if !it(&i, elt) { return false; }, + None => () + } + } + return true; + } + /// Visit all key-value pairs in reverse order pub fn each_reverse<'a>(&'a self, it: &fn(uint, &'a V) -> bool) -> bool { for uint::range_rev(self.v.len(), 0) |i| { diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index 4929dea9045..fd83fd19916 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -107,26 +107,6 @@ impl Map for TreeMap { self.find(key).is_some() } - /// Visit all key-value pairs in order - fn each<'a>(&'a self, f: &fn(&'a K, &'a V) -> bool) -> bool { - each(&self.root, f) - } - - /// Visit all keys in order - fn each_key(&self, f: &fn(&K) -> bool) -> bool { - self.each(|k, _| f(k)) - } - - /// Visit all values in order - fn each_value<'a>(&'a self, f: &fn(&'a V) -> bool) -> bool { - self.each(|_, v| f(v)) - } - - /// Iterate over the map and mutate the contained values - fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool) -> bool { - mutate_values(&mut self.root, f) - } - /// Return a reference to the value corresponding to the key fn find<'a>(&'a self, key: &K) -> Option<&'a V> { let mut current: &'a Option<~TreeNode> = &self.root; @@ -184,6 +164,26 @@ impl TreeMap { /// Create an empty TreeMap pub fn new() -> TreeMap { TreeMap{root: None, length: 0} } + /// Visit all key-value pairs in order + pub fn each<'a>(&'a self, f: &fn(&'a K, &'a V) -> bool) -> bool { + each(&self.root, f) + } + + /// Visit all keys in order + pub fn each_key(&self, f: &fn(&K) -> bool) -> bool { + self.each(|k, _| f(k)) + } + + /// Visit all values in order + pub fn each_value<'a>(&'a self, f: &fn(&'a V) -> bool) -> bool { + self.each(|_, v| f(v)) + } + + /// Iterate over the map and mutate the contained values + pub fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool) -> bool { + mutate_values(&mut self.root, f) + } + /// Visit all key-value pairs in reverse order pub fn each_reverse<'a>(&'a self, f: &fn(&'a K, &'a V) -> bool) -> bool { each_reverse(&self.root, f) diff --git a/src/libstd/container.rs b/src/libstd/container.rs index c1b656f1cd9..d6f4c26715a 100644 --- a/src/libstd/container.rs +++ b/src/libstd/container.rs @@ -34,18 +34,6 @@ pub trait Map: Mutable { /// Return true if the map contains a value for the specified key fn contains_key(&self, key: &K) -> bool; - /// Visits all keys and values - fn each<'a>(&'a self, f: &fn(&K, &'a V) -> bool) -> bool; - - /// Visit all keys - fn each_key(&self, f: &fn(&K) -> bool) -> bool; - - /// Visit all values - fn each_value<'a>(&'a self, f: &fn(&'a V) -> bool) -> bool; - - /// Iterate over the map and mutate the contained values - fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool) -> bool; - /// Return a reference to the value corresponding to the key fn find<'a>(&'a self, key: &K) -> Option<&'a V>; diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index 7d55947e818..962025915d2 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -307,34 +307,6 @@ impl Map for HashMap { } } - /// Visit all key-value pairs - fn each<'a>(&'a self, blk: &fn(&K, &'a V) -> bool) -> bool { - self.iter().advance(|(k, v)| blk(k, v)) - } - - /// Visit all keys - fn each_key(&self, blk: &fn(k: &K) -> bool) -> bool { - self.iter().advance(|(k, _)| blk(k)) - } - - /// Visit all values - fn each_value<'a>(&'a self, blk: &fn(v: &'a V) -> bool) -> bool { - self.iter().advance(|(_, v)| blk(v)) - } - - /// Iterate over the map and mutate the contained values - fn mutate_values(&mut self, blk: &fn(&K, &mut V) -> bool) -> bool { - for uint::range(0, self.buckets.len()) |i| { - match self.buckets[i] { - Some(Bucket{key: ref key, value: ref mut value, _}) => { - if !blk(key, value) { return false; } - } - None => () - } - } - return true; - } - /// Return a reference to the value corresponding to the key fn find<'a>(&'a self, k: &K) -> Option<&'a V> { match self.bucket_for_key(k) { @@ -516,6 +488,34 @@ impl HashMap { } } + /// Visit all key-value pairs + pub fn each<'a>(&'a self, blk: &fn(&K, &'a V) -> bool) -> bool { + self.iter().advance(|(k, v)| blk(k, v)) + } + + /// Visit all keys + pub fn each_key(&self, blk: &fn(k: &K) -> bool) -> bool { + self.iter().advance(|(k, _)| blk(k)) + } + + /// Visit all values + pub fn each_value<'a>(&'a self, blk: &fn(v: &'a V) -> bool) -> bool { + self.iter().advance(|(_, v)| blk(v)) + } + + /// Iterate over the map and mutate the contained values + pub fn mutate_values(&mut self, blk: &fn(&K, &mut V) -> bool) -> bool { + for uint::range(0, self.buckets.len()) |i| { + match self.buckets[i] { + Some(Bucket{key: ref key, value: ref mut value, _}) => { + if !blk(key, value) { return false; } + } + None => () + } + } + return true; + } + /// An iterator visiting all key-value pairs in arbitrary order. /// Iterator element type is (&'a K, &'a V). pub fn iter<'a>(&'a self) -> HashMapIterator<'a, K, V> { diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index e6449ef4922..8f70c75439a 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -58,30 +58,6 @@ impl Map for TrieMap { self.find(key).is_some() } - /// Visit all key-value pairs in order - #[inline] - fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool { - self.root.each(f) - } - - /// Visit all keys in order - #[inline] - fn each_key(&self, f: &fn(&uint) -> bool) -> bool { - self.each(|k, _| f(k)) - } - - /// Visit all values in order - #[inline] - fn each_value<'a>(&'a self, f: &fn(&'a T) -> bool) -> bool { - self.each(|_, v| f(v)) - } - - /// Iterate over the map and mutate the contained values - #[inline] - fn mutate_values(&mut self, f: &fn(&uint, &mut T) -> bool) -> bool { - self.root.mutate_values(f) - } - /// Return a reference to the value corresponding to the key #[inline] fn find<'a>(&'a self, key: &uint) -> Option<&'a T> { @@ -158,6 +134,30 @@ impl TrieMap { self.root.each_reverse(f) } + /// Visit all key-value pairs in order + #[inline] + pub fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool { + self.root.each(f) + } + + /// Visit all keys in order + #[inline] + pub fn each_key(&self, f: &fn(&uint) -> bool) -> bool { + self.each(|k, _| f(k)) + } + + /// Visit all values in order + #[inline] + pub fn each_value<'a>(&'a self, f: &fn(&'a T) -> bool) -> bool { + self.each(|_, v| f(v)) + } + + /// Iterate over the map and mutate the contained values + #[inline] + pub fn mutate_values(&mut self, f: &fn(&uint, &mut T) -> bool) -> bool { + self.root.mutate_values(f) + } + /// Visit all keys in reverse order #[inline] pub fn each_key_reverse(&self, f: &fn(&uint) -> bool) -> bool { diff --git a/src/test/run-pass/class-impl-very-parameterized-trait.rs b/src/test/run-pass/class-impl-very-parameterized-trait.rs index c54b8db46c8..2805fec6fce 100644 --- a/src/test/run-pass/class-impl-very-parameterized-trait.rs +++ b/src/test/run-pass/class-impl-very-parameterized-trait.rs @@ -61,29 +61,8 @@ impl Mutable for cat { } impl Map for cat { - fn each<'a>(&'a self, f: &fn(&int, &'a T) -> bool) -> bool { - let mut n = int::abs(self.meows); - while n > 0 { - if !f(&n, &self.name) { return false; } - n -= 1; - } - return true; - } - fn contains_key(&self, k: &int) -> bool { *k <= self.meows } - fn each_key(&self, f: &fn(v: &int) -> bool) -> bool { - self.each(|k, _| f(k)) - } - - fn each_value<'a>(&'a self, f: &fn(v: &'a T) -> bool) -> bool { - self.each(|_, v| f(v)) - } - - fn mutate_values(&mut self, _f: &fn(&int, &mut T) -> bool) -> bool { - fail!("nope") - } - fn insert(&mut self, k: int, _: T) -> bool { self.meows += k; true -- cgit 1.4.1-3-g733a5 From e67c48a5912b85c286113e0d039aae85f18da1d7 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Mon, 24 Jun 2013 18:34:20 -0400 Subject: remove `each` from vec, HashMap and HashSet --- doc/tutorial.md | 57 +++++++--- src/compiletest/runtest.rs | 2 +- src/libextra/arc.rs | 11 +- src/libextra/getopts.rs | 5 +- src/libextra/json.rs | 8 +- src/libextra/net_url.rs | 2 +- src/libextra/serialize.rs | 4 +- src/libextra/sync.rs | 3 +- src/libextra/workcache.rs | 4 +- src/librustc/metadata/cstore.rs | 2 +- src/librustc/middle/kind.rs | 3 +- src/librustc/middle/lang_items.rs | 2 +- src/librustc/middle/lint.rs | 7 +- src/librustc/middle/region.rs | 2 +- src/librustc/middle/resolve.rs | 24 ++-- src/librustc/middle/trans/_match.rs | 2 +- src/librustc/middle/trans/base.rs | 2 +- src/librustc/middle/trans/callee.rs | 4 +- src/librustc/middle/trans/type_use.rs | 3 +- .../middle/typeck/infer/region_inference.rs | 2 +- src/librustc/rustc.rs | 2 +- src/librusti/program.rs | 8 +- src/libstd/hashmap.rs | 11 -- src/libstd/task/spawn.rs | 2 +- src/libstd/vec.rs | 122 ++------------------- src/test/bench/graph500-bfs.rs | 4 +- src/test/bench/msgsend-pipes-shared.rs | 2 +- src/test/bench/msgsend-pipes.rs | 2 +- src/test/bench/shootout-chameneos-redux.rs | 4 +- src/test/bench/shootout-k-nucleotide-pipes.rs | 2 +- .../compile-fail/block-must-not-have-result-for.rs | 4 +- .../compile-fail/borrowck-insert-during-each.rs | 2 +- src/test/compile-fail/issue-2151.rs | 7 +- src/test/compile-fail/liveness-issue-2163.rs | 2 +- src/test/run-pass/assignability-trait.rs | 6 +- src/test/run-pass/auto-loop.rs | 5 +- src/test/run-pass/block-arg.rs | 2 +- src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs | 6 +- src/test/run-pass/break.rs | 6 +- src/test/run-pass/const-vec-of-fns.rs | 4 +- src/test/run-pass/for-destruct.rs | 3 +- src/test/run-pass/rcvr-borrowed-to-slice.rs | 2 +- src/test/run-pass/trait-generic.rs | 5 +- 43 files changed, 139 insertions(+), 223 deletions(-) (limited to 'src/libstd') diff --git a/doc/tutorial.md b/doc/tutorial.md index 9c61a04930a..9e54622688b 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -1552,13 +1552,6 @@ fn each(v: &[int], op: &fn(v: &int)) { } ~~~~ -As an aside, the reason we pass in a *pointer* to an integer rather -than the integer itself is that this is how the actual `each()` -function for vectors works. `vec::each` though is a -[generic](#generics) function, so must be efficient to use for all -types. Passing the elements by pointer avoids copying potentially -large objects. - As a caller, if we use a closure to provide the final operator argument, we can write it in a way that has a pleasant, block-like structure. @@ -1616,6 +1609,9 @@ To enable `debug!` logging, set the RUST_LOG environment variable to the name of ## For loops +> ***Note:*** The closure-based protocol used `for` loop is on the way out. The `for` loop will +> use iterator objects in the future instead. + The most common way to express iteration in Rust is with a `for` loop. Like `do`, `for` is a nice syntax for describing control flow with closures. Additionally, within a `for` loop, `break`, `loop`, @@ -1640,7 +1636,16 @@ fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool { And using this function to iterate over a vector: ~~~~ -# use each = std::vec::each; +# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool { +# let mut n = 0; +# while n < v.len() { +# if !op(&v[n]) { +# return false; +# } +# n += 1; +# } +# return true; +# } each([2, 4, 8, 5, 16], |n| { if *n % 2 != 0 { println("found odd number!"); @@ -1656,7 +1661,16 @@ out of the loop, you just write `break`. To skip ahead to the next iteration, write `loop`. ~~~~ -# use each = std::vec::each; +# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool { +# let mut n = 0; +# while n < v.len() { +# if !op(&v[n]) { +# return false; +# } +# n += 1; +# } +# return true; +# } for each([2, 4, 8, 5, 16]) |n| { if *n % 2 != 0 { println("found odd number!"); @@ -1671,7 +1685,16 @@ normally allowed in closures, in a block that appears as the body of a the enclosing function, not just the loop body. ~~~~ -# use each = std::vec::each; +# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool { +# let mut n = 0; +# while n < v.len() { +# if !op(&v[n]) { +# return false; +# } +# n += 1; +# } +# return true; +# } fn contains(v: &[int], elt: int) -> bool { for each(v) |x| { if (*x == elt) { return true; } @@ -1686,7 +1709,16 @@ In these situations it can be convenient to lean on Rust's argument patterns to bind `x` to the actual value, not the pointer. ~~~~ -# use each = std::vec::each; +# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool { +# let mut n = 0; +# while n < v.len() { +# if !op(&v[n]) { +# return false; +# } +# n += 1; +# } +# return true; +# } # fn contains(v: &[int], elt: int) -> bool { for each(v) |&x| { if (x == elt) { return true; } @@ -1841,10 +1873,9 @@ vector consisting of the result of applying `function` to each element of `vector`: ~~~~ -# use std::vec; fn map(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] { let mut accumulator = ~[]; - for vec::each(vector) |element| { + for vector.iter().advance |element| { accumulator.push(function(element)); } return accumulator; diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index fd56031ccf9..3e2f484ee53 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -529,7 +529,7 @@ fn compose_and_run_compiler( let extra_link_args = ~[~"-L", aux_output_dir_name(config, testfile).to_str()]; - for vec::each(props.aux_builds) |rel_ab| { + for props.aux_builds.iter().advance |rel_ab| { let abs_ab = config.aux_base.push_rel(&Path(*rel_ab)); let aux_args = make_compile_args(config, props, ~[~"--lib"] + extra_link_args, diff --git a/src/libextra/arc.rs b/src/libextra/arc.rs index 32114f4037e..c5fe07f2187 100644 --- a/src/libextra/arc.rs +++ b/src/libextra/arc.rs @@ -521,6 +521,7 @@ mod tests { use core::cell::Cell; use core::comm; use core::task; + use core::uint; #[test] fn manually_share_arc() { @@ -790,18 +791,20 @@ mod tests { } assert_eq!(*state, 42); *state = 31337; + // FIXME: #7372: hits type inference bug with iterators // send to other readers - for vec::each(reader_convos) |x| { - match *x { + for uint::range(0, reader_convos.len()) |i| { + match reader_convos[i] { (ref rc, _) => rc.send(()), } } } let read_mode = arc.downgrade(write_mode); do (&read_mode).read |state| { + // FIXME: #7372: hits type inference bug with iterators // complete handshake with other readers - for vec::each(reader_convos) |x| { - match *x { + for uint::range(0, reader_convos.len()) |i| { + match reader_convos[i] { (_, ref rp) => rp.recv(), } } diff --git a/src/libextra/getopts.rs b/src/libextra/getopts.rs index d97804722f2..9c416550eb7 100644 --- a/src/libextra/getopts.rs +++ b/src/libextra/getopts.rs @@ -418,10 +418,11 @@ pub fn opts_str(mm: &Matches, names: &[~str]) -> ~str { */ pub fn opt_strs(mm: &Matches, nm: &str) -> ~[~str] { let mut acc: ~[~str] = ~[]; - for vec::each(opt_vals(mm, nm)) |v| { + let r = opt_vals(mm, nm); + for r.iter().advance |v| { match *v { Val(ref s) => acc.push(copy *s), _ => () } } - return acc; + acc } /// Returns the string argument supplied to a matching option or none diff --git a/src/libextra/json.rs b/src/libextra/json.rs index 24c4c5b27c4..15553b035f6 100644 --- a/src/libextra/json.rs +++ b/src/libextra/json.rs @@ -1123,7 +1123,7 @@ impl Eq for Json { &Object(ref d1) => { if d0.len() == d1.len() { let mut equal = true; - for d0.each |k, v0| { + for d0.iter().advance |(k, v0)| { match d1.find(k) { Some(v1) if v0 == v1 => { }, _ => { equal = false; break } @@ -1186,12 +1186,12 @@ impl Ord for Json { let mut d1_flat = ~[]; // FIXME #4430: this is horribly inefficient... - for d0.each |k, v| { + for d0.iter().advance |(k, v)| { d0_flat.push((@copy *k, @copy *v)); } d0_flat.qsort(); - for d1.each |k, v| { + for d1.iter().advance |(k, v)| { d1_flat.push((@copy *k, @copy *v)); } d1_flat.qsort(); @@ -1326,7 +1326,7 @@ impl ToJson for ~[A] { impl ToJson for HashMap<~str, A> { fn to_json(&self) -> Json { let mut d = HashMap::new(); - for self.each |key, value| { + for self.iter().advance |(key, value)| { d.insert(copy *key, value.to_json()); } Object(~d) diff --git a/src/libextra/net_url.rs b/src/libextra/net_url.rs index dda4b85df4b..5d3d31fdec4 100644 --- a/src/libextra/net_url.rs +++ b/src/libextra/net_url.rs @@ -207,7 +207,7 @@ pub fn encode_form_urlencoded(m: &HashMap<~str, ~[~str]>) -> ~str { let mut out = ~""; let mut first = true; - for m.each |key, values| { + for m.iter().advance |(key, values)| { let key = encode_plus(*key); for values.iter().advance |value| { diff --git a/src/libextra/serialize.rs b/src/libextra/serialize.rs index 34fd7e9f1ec..345b217871c 100644 --- a/src/libextra/serialize.rs +++ b/src/libextra/serialize.rs @@ -710,7 +710,7 @@ impl< fn encode(&self, e: &mut E) { do e.emit_map(self.len()) |e| { let mut i = 0; - for self.each |key, val| { + for self.iter().advance |(key, val)| { e.emit_map_elt_key(i, |e| key.encode(e)); e.emit_map_elt_val(i, |e| val.encode(e)); i += 1; @@ -744,7 +744,7 @@ impl< fn encode(&self, s: &mut S) { do s.emit_seq(self.len()) |s| { let mut i = 0; - for self.each |e| { + for self.iter().advance |e| { s.emit_seq_elt(i, |s| e.encode(s)); i += 1; } diff --git a/src/libextra/sync.rs b/src/libextra/sync.rs index 6990d35f061..5cb52a7b9df 100644 --- a/src/libextra/sync.rs +++ b/src/libextra/sync.rs @@ -1094,7 +1094,8 @@ mod tests { }; assert!(result.is_err()); // child task must have finished by the time try returns - for vec::each(p.recv()) |p| { p.recv(); } // wait on all its siblings + let r = p.recv(); + for r.iter().advance |p| { p.recv(); } // wait on all its siblings do m.lock_cond |cond| { let woken = cond.broadcast(); assert_eq!(woken, 0); diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs index ed675bf99e9..a014293f063 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -146,7 +146,7 @@ impl WorkMap { impl Encodable for WorkMap { fn encode(&self, s: &mut S) { let mut d = ~[]; - for self.each |k, v| { + for self.iter().advance |(k, v)| { d.push((copy *k, copy *v)) } sort::tim_sort(d); @@ -320,7 +320,7 @@ impl TPrep for Prep { } fn all_fresh(&self, cat: &str, map: &WorkMap) -> bool { - for map.each |k, v| { + for map.iter().advance |(k, v)| { if ! self.is_fresh(cat, k.kind, k.name, *v) { return false; } diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index c6c1ac720e8..b0a955fef8f 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -86,7 +86,7 @@ pub fn have_crate_data(cstore: &CStore, cnum: ast::crate_num) -> bool { pub fn iter_crate_data(cstore: &CStore, i: &fn(ast::crate_num, @crate_metadata)) { - for cstore.metas.each |&k, &v| { + for cstore.metas.iter().advance |(&k, &v)| { i(k, v); } } diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index 7f7a81fa974..b0b2a16cf89 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -240,7 +240,8 @@ fn check_fn( // Check kinds on free variables: do with_appropriate_checker(cx, fn_id) |chk| { - for vec::each(*freevars::get_freevars(cx.tcx, fn_id)) |fv| { + let r = freevars::get_freevars(cx.tcx, fn_id); + for r.iter().advance |fv| { chk(cx, *fv); } } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index d73b019c1ea..9d4064e99bd 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -436,7 +436,7 @@ impl LanguageItemCollector { } pub fn check_completeness(&self) { - for self.item_refs.each |&key, &item_ref| { + for self.item_refs.iter().advance |(&key, &item_ref)| { match self.items.items[item_ref] { None => { self.session.err(fmt!("no item found for `%s`", key)); diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 5c36ab7750c..6da10b7c277 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -361,7 +361,7 @@ impl Context { } fn lint_to_str(&self, lint: lint) -> &'static str { - for self.dict.each |k, v| { + for self.dict.iter().advance |(k, v)| { if v.lint == lint { return *k; } @@ -742,7 +742,8 @@ fn check_item_ctypes(cx: &Context, it: @ast::item) { fn check_foreign_fn(cx: &Context, decl: &ast::fn_decl) { let tys = vec::map(decl.inputs, |a| a.ty ); - for vec::each(vec::append_one(tys, decl.output)) |ty| { + let r = vec::append_one(tys, decl.output); + for r.iter().advance |ty| { check_ty(cx, *ty); } } @@ -1171,7 +1172,7 @@ pub fn check_crate(tcx: ty::ctxt, crate: @ast::crate) { // If we missed any lints added to the session, then there's a bug somewhere // in the iteration code. - for tcx.sess.lints.each |_, v| { + for tcx.sess.lints.iter().advance |(_, v)| { for v.iter().advance |t| { match *t { (lint, span, ref msg) => diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 0e6d8617ba4..7d3e895a0ed 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -948,7 +948,7 @@ pub fn determine_rp_in_crate(sess: Session, debug!("%s", { debug!("Region variance results:"); let region_paramd_items = cx.region_paramd_items; - for region_paramd_items.each |&key, &value| { + for region_paramd_items.iter().advance |(&key, &value)| { debug!("item %? (%s) is parameterized with variance %?", key, ast_map::node_id_to_str(ast_map, key, diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 3a54c224b52..096ab71e424 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -1386,7 +1386,7 @@ impl Resolver { } let def_id = local_def(item.id); - for method_names.each |name, _| { + for method_names.iter().advance |(name, _)| { if !self.method_map.contains_key(name) { self.method_map.insert(*name, HashSet::new()); } @@ -1704,7 +1704,7 @@ impl Resolver { interned_method_names.insert(method_name); } } - for interned_method_names.each |name| { + for interned_method_names.iter().advance |name| { if !self.method_map.contains_key(name) { self.method_map.insert(*name, HashSet::new()); } @@ -2470,8 +2470,8 @@ impl Resolver { assert_eq!(containing_module.glob_count, 0); // Add all resolved imports from the containing module. - for containing_module.import_resolutions.each - |ident, target_import_resolution| { + for containing_module.import_resolutions.iter().advance + |(ident, target_import_resolution)| { debug!("(resolving glob import) writing module resolution \ %? into `%s`", @@ -2555,13 +2555,13 @@ impl Resolver { }; // Add all children from the containing module. - for containing_module.children.each |&ident, name_bindings| { + for containing_module.children.iter().advance |(&ident, name_bindings)| { merge_import_resolution(ident, *name_bindings); } // Add external module children from the containing module. - for containing_module.external_module_children.each - |&ident, module| { + for containing_module.external_module_children.iter().advance + |(&ident, module)| { let name_bindings = @mut Resolver::create_name_bindings_from_module(*module); merge_import_resolution(ident, name_bindings); @@ -3251,7 +3251,7 @@ impl Resolver { pub fn add_exports_for_module(@mut self, exports2: &mut ~[Export2], module_: @mut Module) { - for module_.children.each |ident, namebindings| { + for module_.children.iter().advance |(ident, namebindings)| { debug!("(computing exports) maybe export '%s'", self.session.str_of(*ident)); self.add_exports_of_namebindings(&mut *exports2, @@ -3266,7 +3266,7 @@ impl Resolver { false); } - for module_.import_resolutions.each |ident, importresolution| { + for module_.import_resolutions.iter().advance |(ident, importresolution)| { if importresolution.privacy != Public { debug!("(computing exports) not reexporting private `%s`", self.session.str_of(*ident)); @@ -4039,7 +4039,7 @@ impl Resolver { for arm.pats.iter().enumerate().advance |(i, p)| { let map_i = self.binding_mode_map(*p); - for map_0.each |&key, &binding_0| { + for map_0.iter().advance |(&key, &binding_0)| { match map_i.find(&key) { None => { self.session.span_err( @@ -4060,7 +4060,7 @@ impl Resolver { } } - for map_i.each |&key, &binding| { + for map_i.iter().advance |(&key, &binding)| { if !map_0.contains_key(&key) { self.session.span_err( binding.span, @@ -5355,7 +5355,7 @@ impl Resolver { } debug!("Import resolutions:"); - for module_.import_resolutions.each |name, import_resolution| { + for module_.import_resolutions.iter().advance |(name, import_resolution)| { let value_repr; match import_resolution.target_for_namespace(ValueNS) { None => { value_repr = ~""; } diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 71b416ffe85..63b39b8fe76 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -1673,7 +1673,7 @@ pub fn trans_match_inner(scope_cx: block, let mut arm_datas = ~[]; let mut matches = ~[]; - for vec::each(arms) |arm| { + for arms.iter().advance |arm| { let body = scope_block(bcx, arm.body.info(), "case_body"); let bindings_map = create_bindings_map(bcx, arm.pats[0]); let arm_data = @ArmData {bodycx: body, diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 0e322c187af..5bf0e596ca0 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2945,7 +2945,7 @@ pub fn trans_crate(sess: session::Session, } if ccx.sess.count_llvm_insns() { - for ccx.stats.llvm_insns.each |&k, &v| { + for ccx.stats.llvm_insns.iter().advance |(&k, &v)| { io::println(fmt!("%-7u %s", v, k)); } } diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 593d0beb88c..cb475550638 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -704,11 +704,11 @@ pub fn trans_args(cx: block, // now that all arguments have been successfully built, we can revoke any // temporary cleanups, as they are only needed if argument construction // should fail (for example, cleanup of copy mode args). - for vec::each(temp_cleanups) |c| { + for temp_cleanups.iter().advance |c| { revoke_clean(bcx, *c) } - return bcx; + bcx } pub enum AutorefArg { diff --git a/src/librustc/middle/trans/type_use.rs b/src/librustc/middle/trans/type_use.rs index f2446d1a115..8cd776c99d6 100644 --- a/src/librustc/middle/trans/type_use.rs +++ b/src/librustc/middle/trans/type_use.rs @@ -213,7 +213,8 @@ pub fn type_needs_inner(cx: Context, ty::ty_enum(did, ref substs) => { if list::find(enums_seen, |id| *id == did).is_none() { let seen = @Cons(did, enums_seen); - for vec::each(*ty::enum_variants(cx.ccx.tcx, did)) |v| { + let r = ty::enum_variants(cx.ccx.tcx, did); + for r.iter().advance |v| { for v.args.iter().advance |aty| { let t = ty::subst(cx.ccx.tcx, &(*substs), *aty); type_needs_inner(cx, use_, t, seen); diff --git a/src/librustc/middle/typeck/infer/region_inference.rs b/src/librustc/middle/typeck/infer/region_inference.rs index d9add22479c..0aad161a678 100644 --- a/src/librustc/middle/typeck/infer/region_inference.rs +++ b/src/librustc/middle/typeck/infer/region_inference.rs @@ -1285,7 +1285,7 @@ impl RegionVarBindings { // It would be nice to write this using map(): let mut edges = vec::with_capacity(num_edges); - for self.constraints.each |constraint, span| { + for self.constraints.iter().advance |(constraint, span)| { edges.push(GraphEdge { next_edge: [uint::max_value, uint::max_value], constraint: *constraint, diff --git a/src/librustc/rustc.rs b/src/librustc/rustc.rs index 20705b3d797..ca49d143d48 100644 --- a/src/librustc/rustc.rs +++ b/src/librustc/rustc.rs @@ -166,7 +166,7 @@ Available lint options: padded(max_key, "name"), "default", "meaning")); io::println(fmt!(" %s %7.7s %s\n", padded(max_key, "----"), "-------", "-------")); - for lint_dict.each |k, v| { + for lint_dict.iter().advance |(k, v)| { let k = k.replace("_", "-"); io::println(fmt!(" %s %7.7s %s", padded(max_key, k), diff --git a/src/librusti/program.rs b/src/librusti/program.rs index 91fde3e21ae..f17777559de 100644 --- a/src/librusti/program.rs +++ b/src/librusti/program.rs @@ -96,7 +96,7 @@ impl Program { code.push_str("fn main() {\n"); // It's easy to initialize things if we don't run things... - for self.local_vars.each |name, var| { + for self.local_vars.iter().advance |(name, var)| { let mt = var.mt(); code.push_str(fmt!("let%s %s: %s = fail!();\n", mt, *name, var.ty)); var.alter(*name, &mut code); @@ -149,7 +149,7 @@ impl Program { // Using this __tls_map handle, deserialize each variable binding that // we know about - for self.local_vars.each |name, var| { + for self.local_vars.iter().advance |(name, var)| { let mt = var.mt(); code.push_str(fmt!("let%s %s: %s = { let data = __tls_map.get_copy(&~\"%s\"); @@ -175,7 +175,7 @@ impl Program { // After the input code is run, we can re-serialize everything back out // into tls map (to be read later on by this task) - for self.local_vars.each |name, var| { + for self.local_vars.iter().advance |(name, var)| { code.push_str(fmt!("{ let local: %s = %s; let bytes = do ::std::io::with_bytes_writer |io| { @@ -237,7 +237,7 @@ impl Program { /// program starts pub fn set_cache(&self) { let map = @mut HashMap::new(); - for self.local_vars.each |name, value| { + for self.local_vars.iter().advance |(name, value)| { map.insert(copy *name, @copy value.data); } unsafe { diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index 962025915d2..bfa0f2fa124 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -488,11 +488,6 @@ impl HashMap { } } - /// Visit all key-value pairs - pub fn each<'a>(&'a self, blk: &fn(&K, &'a V) -> bool) -> bool { - self.iter().advance(|(k, v)| blk(k, v)) - } - /// Visit all keys pub fn each_key(&self, blk: &fn(k: &K) -> bool) -> bool { self.iter().advance(|(k, _)| blk(k)) @@ -718,12 +713,6 @@ impl HashSet { self.map.contains_key_equiv(value) } - /// Visit all elements in arbitrary order - /// FIXME: #6978: Remove when all callers are converted - pub fn each(&self, f: &fn(&T) -> bool) -> bool { - self.iter().advance(f) - } - /// An iterator visiting all elements in arbitrary order. /// Iterator element type is &'a T. pub fn iter<'a>(&'a self) -> HashSetIterator<'a, T> { diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 77053f39677..04c0dd79ded 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -111,7 +111,7 @@ fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) { assert!(was_present); } pub fn taskset_each(tasks: &TaskSet, blk: &fn(v: *rust_task) -> bool) -> bool { - tasks.each(|k| blk(*k)) + tasks.iter().advance(|k| blk(*k)) } // One of these per group of linked-failure tasks. diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 72b58307849..2e18a588fae 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -444,7 +444,7 @@ pub fn partitioned(v: &[T], f: &fn(&T) -> bool) -> (~[T], ~[T]) { let mut lefts = ~[]; let mut rights = ~[]; - for each(v) |elt| { + for v.iter().advance |elt| { if f(elt) { lefts.push(copy *elt); } else { @@ -850,7 +850,7 @@ pub fn grow_set(v: &mut ~[T], index: uint, initval: &T, val: T) { /// Apply a function to each element of a vector and return the results pub fn map(v: &[T], f: &fn(t: &T) -> U) -> ~[U] { let mut result = with_capacity(v.len()); - for each(v) |elem| { + for v.iter().advance |elem| { result.push(f(elem)); } result @@ -886,7 +886,7 @@ pub fn mapi(v: &[T], f: &fn(uint, t: &T) -> U) -> ~[U] { */ pub fn flat_map(v: &[T], f: &fn(t: &T) -> ~[U]) -> ~[U] { let mut result = ~[]; - for each(v) |elem| { result.push_all_move(f(elem)); } + for v.iter().advance |elem| { result.push_all_move(f(elem)); } result } @@ -939,7 +939,7 @@ pub fn filter_mapped( */ let mut result = ~[]; - for each(v) |elem| { + for v.iter().advance |elem| { match f(elem) { None => {/* no-op */ } Some(result_elem) => { result.push(result_elem); } @@ -974,7 +974,7 @@ pub fn filter(v: ~[T], f: &fn(t: &T) -> bool) -> ~[T] { */ pub fn filtered(v: &[T], f: &fn(t: &T) -> bool) -> ~[T] { let mut result = ~[]; - for each(v) |elem| { + for v.iter().advance |elem| { if f(elem) { result.push(copy *elem); } } result @@ -1058,7 +1058,7 @@ impl<'self, T:Copy> VectorVector for &'self [&'self [T]] { /// Return true if a vector contains an element with the given value pub fn contains(v: &[T], x: &T) -> bool { - for each(v) |elt| { if *x == *elt { return true; } } + for v.iter().advance |elt| { if *x == *elt { return true; } } false } @@ -1209,7 +1209,7 @@ pub fn bsearch_elem(v: &[T], x: &T) -> Option { */ pub fn unzip_slice(v: &[(T, U)]) -> (~[T], ~[U]) { let mut (ts, us) = (~[], ~[]); - for each(v) |p| { + for v.iter().advance |p| { let (t, u) = copy *p; ts.push(t); us.push(u); @@ -1347,69 +1347,6 @@ pub fn reversed(v: &const [T]) -> ~[T] { rs } -/** - * Iterates over a vector, yielding each element to a closure. - * - * # Arguments - * - * * `v` - A vector, to be iterated over - * * `f` - A closure to do the iterating. Within this closure, return true to - * * continue iterating, false to break. - * - * # Examples - * - * ~~~ {.rust} - * [1,2,3].each(|&i| { - * io::println(int::str(i)); - * true - * }); - * ~~~ - * - * ~~~ {.rust} - * [1,2,3,4,5].each(|&i| { - * if i < 4 { - * io::println(int::str(i)); - * true - * } - * else { - * false - * } - * }); - * ~~~ - * - * You probably will want to use each with a `for`/`do` expression, depending - * on your iteration needs: - * - * ~~~ {.rust} - * for [1,2,3].each |&i| { - * io::println(int::str(i)); - * } - * ~~~ - */ -#[inline] -pub fn each<'r,T>(v: &'r [T], f: &fn(&'r T) -> bool) -> bool { - // ^^^^ - // NB---this CANNOT be &const [T]! The reason - // is that you are passing it to `f()` using - // an immutable. - - let mut broke = false; - do as_imm_buf(v) |p, n| { - let mut n = n; - let mut p = p; - while n > 0u { - unsafe { - let q = cast::copy_lifetime_vec(v, &*p); - if !f(q) { break; } - p = ptr::offset(p, 1u); - } - n -= 1u; - } - broke = n > 0; - } - return !broke; -} - /** * Iterate over all permutations of vector `v`. * @@ -3069,36 +3006,6 @@ mod tests { assert_eq!(v, ~[1, 3, 5]); } - #[test] - fn test_each_empty() { - for each::([]) |_v| { - fail!(); // should never be executed - } - } - - #[test] - fn test_each_nonempty() { - let mut i = 0; - for each([1, 2, 3]) |v| { - i += *v; - } - assert_eq!(i, 6); - } - - #[test] - fn test_each_ret_len0() { - let a0 : [int, .. 0] = []; - assert_eq!(each(a0, |_p| fail!()), true); - } - - #[test] - fn test_each_ret_len1() { - let a1 = [17]; - assert_eq!(each(a1, |_p| true), true); - assert_eq!(each(a1, |_p| false), false); - } - - #[test] fn test_each_permutation() { let mut results: ~[~[int]]; @@ -3854,21 +3761,6 @@ mod tests { }; } - #[test] - #[ignore(windows)] - #[should_fail] - fn test_each_fail() { - let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; - let mut i = 0; - do each(v) |_elt| { - if i == 2 { - fail!() - } - i += 0; - false - }; - } - #[test] #[ignore(windows)] #[should_fail] diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 14aa65219cd..d21888f12ec 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -86,7 +86,7 @@ fn make_graph(N: uint, edges: ~[(node_id, node_id)]) -> graph { HashSet::new() }; - for vec::each(edges) |e| { + for edges.iter().advance |e| { match *e { (i, j) => { graph[i].insert(j); @@ -441,7 +441,7 @@ fn main() { let stop = time::precise_time_s(); let mut total_edges = 0; - vec::each(graph, |edges| { total_edges += edges.len(); true }); + for graph.iter().advance |edges| { total_edges += edges.len(); } io::stdout().write_line(fmt!("Generated graph with %? edges in %? seconds.", total_edges / 2, diff --git a/src/test/bench/msgsend-pipes-shared.rs b/src/test/bench/msgsend-pipes-shared.rs index 7a9be754884..102f7f17065 100644 --- a/src/test/bench/msgsend-pipes-shared.rs +++ b/src/test/bench/msgsend-pipes-shared.rs @@ -83,7 +83,7 @@ fn run(args: &[~str]) { server(&from_parent, &to_parent); } - for vec::each(worker_results) |r| { + for worker_results.iter().advance |r| { r.recv(); } diff --git a/src/test/bench/msgsend-pipes.rs b/src/test/bench/msgsend-pipes.rs index 796072c8485..b8d91bb93e2 100644 --- a/src/test/bench/msgsend-pipes.rs +++ b/src/test/bench/msgsend-pipes.rs @@ -79,7 +79,7 @@ fn run(args: &[~str]) { server(&from_parent, &to_parent); } - for vec::each(worker_results) |r| { + for worker_results.iter().advance |r| { r.recv(); } diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index 3ff123b027a..96c7e4e9b37 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -188,7 +188,7 @@ fn rendezvous(nn: uint, set: ~[color]) { // save each creature's meeting stats let mut report = ~[]; - for vec::each(to_creature) |_to_one| { + for to_creature.iter().advance |_to_one| { report.push(from_creatures_log.recv()); } @@ -196,7 +196,7 @@ fn rendezvous(nn: uint, set: ~[color]) { io::println(show_color_list(set)); // print each creature's stats - for vec::each(report) |rep| { + for report.iter().advance |rep| { io::println(*rep); } diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index c33c2258864..20042aa0e91 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -56,7 +56,7 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str { let mut pairs = ~[]; // map -> [(k,%)] - for mm.each |&key, &val| { + for mm.iter().advance |(&key, &val)| { pairs.push((key, pct(val, total))); } diff --git a/src/test/compile-fail/block-must-not-have-result-for.rs b/src/test/compile-fail/block-must-not-have-result-for.rs index 778309122cb..1aa05a9477d 100644 --- a/src/test/compile-fail/block-must-not-have-result-for.rs +++ b/src/test/compile-fail/block-must-not-have-result-for.rs @@ -8,10 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::vec; - fn main() { - for vec::each(~[0]) |_i| { //~ ERROR A for-loop body must return (), but + for 2.times { //~ ERROR A for-loop body must return (), but true } } diff --git a/src/test/compile-fail/borrowck-insert-during-each.rs b/src/test/compile-fail/borrowck-insert-during-each.rs index 1a0bec7d723..189a0ef9d70 100644 --- a/src/test/compile-fail/borrowck-insert-during-each.rs +++ b/src/test/compile-fail/borrowck-insert-during-each.rs @@ -16,7 +16,7 @@ struct Foo { impl Foo { pub fn foo(&mut self, fun: &fn(&int)) { - for self.n.each |f| { + for self.n.iter().advance |f| { fun(f); } } diff --git a/src/test/compile-fail/issue-2151.rs b/src/test/compile-fail/issue-2151.rs index 8f4bbe4eabc..5559ba344ed 100644 --- a/src/test/compile-fail/issue-2151.rs +++ b/src/test/compile-fail/issue-2151.rs @@ -8,10 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::vec; - fn main() { - for vec::each(fail!()) |i| { - let _ = i * 2; //~ ERROR the type of this value must be known - }; + let x = fail!(); + x.clone(); //~ ERROR the type of this value must be known in this context } diff --git a/src/test/compile-fail/liveness-issue-2163.rs b/src/test/compile-fail/liveness-issue-2163.rs index ec4f3f9a3fd..fbb6d03b220 100644 --- a/src/test/compile-fail/liveness-issue-2163.rs +++ b/src/test/compile-fail/liveness-issue-2163.rs @@ -12,7 +12,7 @@ use std::vec; fn main() { let a: ~[int] = ~[]; - vec::each(a, |_| -> bool { + a.iter().advance(|_| -> bool { //~^ ERROR mismatched types }); } diff --git a/src/test/run-pass/assignability-trait.rs b/src/test/run-pass/assignability-trait.rs index 5d2341ae42d..b65b18e1ab3 100644 --- a/src/test/run-pass/assignability-trait.rs +++ b/src/test/run-pass/assignability-trait.rs @@ -12,21 +12,19 @@ // making method calls, but only if there aren't any matches without // it. -use std::vec; - trait iterable { fn iterate(&self, blk: &fn(x: &A) -> bool) -> bool; } impl<'self,A> iterable for &'self [A] { fn iterate(&self, f: &fn(x: &A) -> bool) -> bool { - vec::each(*self, f) + self.iter().advance(f) } } impl iterable for ~[A] { fn iterate(&self, f: &fn(x: &A) -> bool) -> bool { - vec::each(*self, f) + self.iter().advance(f) } } diff --git a/src/test/run-pass/auto-loop.rs b/src/test/run-pass/auto-loop.rs index f148c509d4d..185a5a6407c 100644 --- a/src/test/run-pass/auto-loop.rs +++ b/src/test/run-pass/auto-loop.rs @@ -8,11 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::vec; - pub fn main() { let mut sum = 0; - for vec::each(~[1, 2, 3, 4, 5]) |x| { + let xs = ~[1, 2, 3, 4, 5]; + for xs.iter().advance |x| { sum += *x; } assert_eq!(sum, 15); diff --git a/src/test/run-pass/block-arg.rs b/src/test/run-pass/block-arg.rs index d860c84dfce..ff5d0e9f05c 100644 --- a/src/test/run-pass/block-arg.rs +++ b/src/test/run-pass/block-arg.rs @@ -15,7 +15,7 @@ pub fn main() { let v = ~[-1f, 0f, 1f, 2f, 3f]; // Statement form does not require parentheses: - for vec::each(v) |i| { + for v.iter().advance |i| { info!("%?", *i); } diff --git a/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs b/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs index d63ebf7d24d..8f74e6cdc29 100644 --- a/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs +++ b/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs @@ -8,12 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::vec; - fn want_slice(v: &[int]) -> int { let mut sum = 0; - for vec::each(v) |i| { sum += *i; } - return sum; + for v.iter().advance |i| { sum += *i; } + sum } fn has_mut_vec(v: ~[int]) -> int { diff --git a/src/test/run-pass/break.rs b/src/test/run-pass/break.rs index 2edb270762c..85c6f90a742 100644 --- a/src/test/run-pass/break.rs +++ b/src/test/run-pass/break.rs @@ -16,7 +16,8 @@ pub fn main() { assert_eq!(i, 10); loop { i += 1; if i == 20 { break; } } assert_eq!(i, 20); - for vec::each(~[1, 2, 3, 4, 5, 6]) |x| { + let xs = [1, 2, 3, 4, 5, 6]; + for xs.iter().advance |x| { if *x == 3 { break; } assert!((*x <= 3)); } i = 0; @@ -26,7 +27,8 @@ pub fn main() { i += 1; if i % 2 == 0 { loop; } assert!((i % 2 != 0)); if i >= 10 { break; } } - for vec::each(~[1, 2, 3, 4, 5, 6]) |x| { + let ys = ~[1, 2, 3, 4, 5, 6]; + for ys.iter().advance |x| { if *x % 2 == 0 { loop; } assert!((*x % 2 != 0)); } diff --git a/src/test/run-pass/const-vec-of-fns.rs b/src/test/run-pass/const-vec-of-fns.rs index 9fc68cd1127..a87d8f30e3a 100644 --- a/src/test/run-pass/const-vec-of-fns.rs +++ b/src/test/run-pass/const-vec-of-fns.rs @@ -23,6 +23,6 @@ struct S<'self>(&'self fn()); static closures: &'static [S<'static>] = &[S(f), S(f)]; pub fn main() { - for std::vec::each(bare_fns) |&bare_fn| { bare_fn() } - for std::vec::each(closures) |&closure| { (*closure)() } + for bare_fns.iter().advance |&bare_fn| { bare_fn() } + for closures.iter().advance |&closure| { (*closure)() } } diff --git a/src/test/run-pass/for-destruct.rs b/src/test/run-pass/for-destruct.rs index 4926dbd0086..dd1cda22e65 100644 --- a/src/test/run-pass/for-destruct.rs +++ b/src/test/run-pass/for-destruct.rs @@ -8,10 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// xfail-test: #3511: does not currently compile, due to rvalue issues + use std::vec; struct Pair { x: int, y: int } - pub fn main() { for vec::each(~[Pair {x: 10, y: 20}, Pair {x: 30, y: 0}]) |elt| { assert_eq!(elt.x + elt.y, 30); diff --git a/src/test/run-pass/rcvr-borrowed-to-slice.rs b/src/test/run-pass/rcvr-borrowed-to-slice.rs index 5eaf12f6a51..b62475ded54 100644 --- a/src/test/run-pass/rcvr-borrowed-to-slice.rs +++ b/src/test/run-pass/rcvr-borrowed-to-slice.rs @@ -18,7 +18,7 @@ trait sum { impl<'self> sum for &'self [int] { fn sum(self) -> int { let mut sum = 0; - for vec::each(self) |e| { sum += *e; } + for self.iter().advance |e| { sum += *e; } return sum; } } diff --git a/src/test/run-pass/trait-generic.rs b/src/test/run-pass/trait-generic.rs index c25cdc85cb6..dc6bdbf5c1a 100644 --- a/src/test/run-pass/trait-generic.rs +++ b/src/test/run-pass/trait-generic.rs @@ -31,7 +31,10 @@ trait map { impl map for ~[T] { fn map(&self, f: &fn(&T) -> U) -> ~[U] { let mut r = ~[]; - for std::vec::each(*self) |x| { r += ~[f(x)]; } + // FIXME: #7355 generates bad code with Iterator + for std::uint::range(0, self.len()) |i| { + r += ~[f(&self[i])]; + } r } } -- cgit 1.4.1-3-g733a5