From 116897fa6cba39ba43180debf0f9136be6a44205 Mon Sep 17 00:00:00 2001 From: Corey Richardson Date: Fri, 21 Jun 2013 18:10:23 -0400 Subject: [PATCH 1/8] Remove `ast::pure_fn` and all concept of `pure` from the compiler --- src/librustc/metadata/decoder.rs | 14 +------------- src/librustc/metadata/encoder.rs | 2 -- src/librustc/metadata/tydecode.rs | 3 +-- src/librustc/metadata/tyencode.rs | 1 - src/librustc/middle/trans/reflect.rs | 1 - src/librustc/middle/ty.rs | 2 +- src/librustc/middle/typeck/check/mod.rs | 2 +- src/librustc/middle/typeck/infer/glb.rs | 3 +-- src/librustc/middle/typeck/infer/lub.rs | 5 ++--- src/libsyntax/ast.rs | 2 -- src/libsyntax/print/pprust.rs | 25 ++++++++++++++----------- 11 files changed, 21 insertions(+), 39 deletions(-) diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 7f06953663b3c..9521b391b190b 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -100,10 +100,8 @@ enum Family { Const, // c Fn, // f UnsafeFn, // u - PureFn, // p StaticMethod, // F UnsafeStaticMethod, // U - PureStaticMethod, // P ForeignFn, // e Type, // y ForeignType, // T @@ -125,10 +123,8 @@ fn item_family(item: ebml::Doc) -> Family { 'c' => Const, 'f' => Fn, 'u' => UnsafeFn, - 'p' => PureFn, 'F' => StaticMethod, 'U' => UnsafeStaticMethod, - 'P' => PureStaticMethod, 'e' => ForeignFn, 'y' => Type, 'T' => ForeignType, @@ -325,7 +321,6 @@ fn item_to_def_like(item: ebml::Doc, did: ast::def_id, cnum: ast::crate_num) Struct => dl_def(ast::def_struct(did)), UnsafeFn => dl_def(ast::def_fn(did, ast::unsafe_fn)), Fn => dl_def(ast::def_fn(did, ast::impure_fn)), - PureFn => dl_def(ast::def_fn(did, ast::pure_fn)), ForeignFn => dl_def(ast::def_fn(did, ast::extern_fn)), UnsafeStaticMethod => { let trait_did_opt = translated_parent_item_opt(cnum, item); @@ -335,10 +330,6 @@ fn item_to_def_like(item: ebml::Doc, did: ast::def_id, cnum: ast::crate_num) let trait_did_opt = translated_parent_item_opt(cnum, item); dl_def(ast::def_static_method(did, trait_did_opt, ast::impure_fn)) } - PureStaticMethod => { - let trait_did_opt = translated_parent_item_opt(cnum, item); - dl_def(ast::def_static_method(did, trait_did_opt, ast::pure_fn)) - } Type | ForeignType => dl_def(ast::def_ty(did)), Mod => dl_def(ast::def_mod(did)), ForeignMod => dl_def(ast::def_foreign_mod(did)), @@ -822,12 +813,11 @@ pub fn get_static_methods_if_impl(intr: @ident_interner, let impl_method_doc = lookup_item(impl_method_id.node, cdata.data); let family = item_family(impl_method_doc); match family { - StaticMethod | UnsafeStaticMethod | PureStaticMethod => { + StaticMethod | UnsafeStaticMethod => { let purity; match item_family(impl_method_doc) { StaticMethod => purity = ast::impure_fn, UnsafeStaticMethod => purity = ast::unsafe_fn, - PureStaticMethod => purity = ast::pure_fn, _ => fail!() } @@ -934,10 +924,8 @@ fn item_family_to_str(fam: Family) -> ~str { Const => ~"const", Fn => ~"fn", UnsafeFn => ~"unsafe fn", - PureFn => ~"pure fn", StaticMethod => ~"static method", UnsafeStaticMethod => ~"unsafe static method", - PureStaticMethod => ~"pure static method", ForeignFn => ~"foreign fn", Type => ~"type", ForeignType => ~"foreign type", diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index bc2e95f4d1b10..d2724400be5d4 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -753,7 +753,6 @@ fn encode_info_for_method(ecx: &EncodeContext, fn purity_fn_family(p: purity) -> char { match p { unsafe_fn => 'u', - pure_fn => 'p', impure_fn => 'f', extern_fn => 'e' } @@ -762,7 +761,6 @@ fn purity_fn_family(p: purity) -> char { fn purity_static_method_family(p: purity) -> char { match p { unsafe_fn => 'U', - pure_fn => 'P', impure_fn => 'F', _ => fail!("extern fn can't be static") } diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index cf2a92b291f28..91917cb807f0d 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -439,10 +439,9 @@ fn parse_hex(st: &mut PState) -> uint { fn parse_purity(c: char) -> purity { match c { 'u' => unsafe_fn, - 'p' => pure_fn, 'i' => impure_fn, 'c' => extern_fn, - _ => fail!("parse_purity: bad purity") + _ => fail!("parse_purity: bad purity %c", c) } } diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index d9377afa9a527..a96e07862ac3a 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -347,7 +347,6 @@ fn enc_sigil(w: @io::Writer, sigil: Sigil) { fn enc_purity(w: @io::Writer, p: purity) { match p { - pure_fn => w.write_char('p'), impure_fn => w.write_char('i'), unsafe_fn => w.write_char('u'), extern_fn => w.write_char('c') diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs index 16a6d62f17675..65a6e8d3c4b5c 100644 --- a/src/librustc/middle/trans/reflect.rs +++ b/src/librustc/middle/trans/reflect.rs @@ -398,7 +398,6 @@ pub fn ast_sigil_constant(sigil: ast::Sigil) -> uint { pub fn ast_purity_constant(purity: ast::purity) -> uint { match purity { - ast::pure_fn => 0u, ast::unsafe_fn => 1u, ast::impure_fn => 2u, ast::extern_fn => 3u diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 8595adcd1c733..eb42945e6393d 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -1253,7 +1253,7 @@ pub fn mk_ctor_fn(cx: ctxt, input_tys: &[ty::t], output: ty::t) -> t { let input_args = input_tys.map(|t| *t); mk_bare_fn(cx, BareFnTy { - purity: ast::pure_fn, + purity: ast::impure_fn, abis: AbiSet::Rust(), sig: FnSig { bound_lifetime_names: opt_vec::Empty, diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 13ded50167939..b00c963c2912c 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -275,7 +275,7 @@ pub fn blank_fn_ctxt(ccx: @mut CrateCtxt, err_count_on_creation: ccx.tcx.sess.err_count(), ret_ty: rty, indirect_ret_ty: None, - ps: PurityState::function(ast::pure_fn, 0), + ps: PurityState::function(ast::impure_fn, 0), region_lb: region_bnd, in_scope_regions: @Nil, fn_kind: Vanilla, diff --git a/src/librustc/middle/typeck/infer/glb.rs b/src/librustc/middle/typeck/infer/glb.rs index 700a78699b1e2..7d2d8dd523dd9 100644 --- a/src/librustc/middle/typeck/infer/glb.rs +++ b/src/librustc/middle/typeck/infer/glb.rs @@ -23,7 +23,7 @@ use middle::typeck::infer::fold_regions_in_sig; use middle::typeck::isr_alist; use syntax::ast; use syntax::ast::{Many, Once, extern_fn, impure_fn, m_const, m_imm, m_mutbl}; -use syntax::ast::{pure_fn, unsafe_fn}; +use syntax::ast::{unsafe_fn}; use syntax::ast::{Onceness, purity}; use syntax::abi::AbiSet; use syntax::codemap::span; @@ -103,7 +103,6 @@ impl Combine for Glb { fn purities(&self, a: purity, b: purity) -> cres { match (a, b) { - (pure_fn, _) | (_, pure_fn) => Ok(pure_fn), (extern_fn, _) | (_, extern_fn) => Ok(extern_fn), (impure_fn, _) | (_, impure_fn) => Ok(impure_fn), (unsafe_fn, unsafe_fn) => Ok(unsafe_fn) diff --git a/src/librustc/middle/typeck/infer/lub.rs b/src/librustc/middle/typeck/infer/lub.rs index 213af316549a9..c77bef835e4f8 100644 --- a/src/librustc/middle/typeck/infer/lub.rs +++ b/src/librustc/middle/typeck/infer/lub.rs @@ -28,7 +28,7 @@ use extra::list; use syntax::abi::AbiSet; use syntax::ast; use syntax::ast::{Many, Once, extern_fn, m_const, impure_fn}; -use syntax::ast::{pure_fn, unsafe_fn}; +use syntax::ast::{unsafe_fn}; use syntax::ast::{Onceness, purity}; use syntax::codemap::span; @@ -92,8 +92,7 @@ impl Combine for Lub { match (a, b) { (unsafe_fn, _) | (_, unsafe_fn) => Ok(unsafe_fn), (impure_fn, _) | (_, impure_fn) => Ok(impure_fn), - (extern_fn, _) | (_, extern_fn) => Ok(extern_fn), - (pure_fn, pure_fn) => Ok(pure_fn) + (extern_fn, extern_fn) => Ok(extern_fn), } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 1758433aa7375..a3ead99a71433 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -845,7 +845,6 @@ pub struct fn_decl { #[deriving(Eq, Encodable, Decodable)] pub enum purity { - pure_fn, // declared with "pure fn" unsafe_fn, // declared with "unsafe fn" impure_fn, // declared with "fn" extern_fn, // declared with "extern fn" @@ -856,7 +855,6 @@ impl ToStr for purity { match *self { impure_fn => ~"impure", unsafe_fn => ~"unsafe", - pure_fn => ~"pure", extern_fn => ~"extern" } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index d73c5240a1c02..e166e30bd78bc 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2188,26 +2188,29 @@ pub fn print_fn_header_info(s: @ps, print_opt_sigil(s, opt_sigil); } -pub fn opt_sigil_to_str(opt_p: Option) -> ~str { +pub fn opt_sigil_to_str(opt_p: Option) -> &'static str { match opt_p { - None => ~"fn", - Some(p) => fmt!("fn%s", p.to_str()) + None => "fn", + Some(p) => match p { + ast::BorrowedSigil => "fn&", + ast::OwnedSigil => "fn~", + ast::ManagedSigil => "fn@" + } } } -pub fn purity_to_str(p: ast::purity) -> ~str { +pub fn purity_to_str(p: ast::purity) -> &'static str { match p { - ast::impure_fn => ~"impure", - ast::unsafe_fn => ~"unsafe", - ast::pure_fn => ~"pure", - ast::extern_fn => ~"extern" + ast::impure_fn => "impure", + ast::unsafe_fn => "unsafe", + ast::extern_fn => "extern" } } -pub fn onceness_to_str(o: ast::Onceness) -> ~str { +pub fn onceness_to_str(o: ast::Onceness) -> &'static str { match o { - ast::Once => ~"once", - ast::Many => ~"many" + ast::Once => "once", + ast::Many => "many" } } From 9b2d9a9539d77695e915ebed189575d1249e7064 Mon Sep 17 00:00:00 2001 From: reus Date: Sat, 22 Jun 2013 17:49:32 +0800 Subject: [PATCH 2/8] replaced some 'std::' with 'extra::' in comments --- src/libextra/arc.rs | 2 +- src/libextra/base64.rs | 20 ++++++++++---------- src/libextra/future.rs | 2 +- src/libextra/net_ip.rs | 4 ++-- src/libstd/os.rs | 2 +- src/libstd/str.rs | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/libextra/arc.rs b/src/libextra/arc.rs index 661224b0a8037..7746e0f06a658 100644 --- a/src/libextra/arc.rs +++ b/src/libextra/arc.rs @@ -19,7 +19,7 @@ * * ~~~ {.rust} * extern mod std; - * use std::arc; + * use extra::arc; * let numbers=vec::from_fn(100, |ind| (ind as float)*rand::random()); * let shared_numbers=arc::ARC(numbers); * diff --git a/src/libextra/base64.rs b/src/libextra/base64.rs index 5bf4dd517a5b2..392e7ff29a226 100644 --- a/src/libextra/base64.rs +++ b/src/libextra/base64.rs @@ -36,8 +36,8 @@ impl<'self> ToBase64 for &'self [u8] { * # Example * * ~~~ {.rust} - * extern mod std; - * use std::base64::ToBase64; + * extern mod extra; + * use extra::base64::ToBase64; * * fn main () { * let str = [52,32].to_base64(); @@ -99,8 +99,8 @@ impl<'self> ToBase64 for &'self str { * # Example * * ~~~ {.rust} - * extern mod std; - * use std::base64::ToBase64; + * extern mod extra; + * use extra::base64::ToBase64; * * fn main () { * let str = "Hello, World".to_base64(); @@ -127,9 +127,9 @@ impl<'self> FromBase64 for &'self [u8] { * # Example * * ~~~ {.rust} - * extern mod std; - * use std::base64::ToBase64; - * use std::base64::FromBase64; + * extern mod extra; + * use extra::base64::ToBase64; + * use extra::base64::FromBase64; * * fn main () { * let str = [52,32].to_base64(); @@ -207,9 +207,9 @@ impl<'self> FromBase64 for &'self str { * This converts a string literal to base64 and back. * * ~~~ {.rust} - * extern mod std; - * use std::base64::ToBase64; - * use std::base64::FromBase64; + * extern mod extra; + * use extra::base64::ToBase64; + * use extra::base64::FromBase64; * use core::str; * * fn main () { diff --git a/src/libextra/future.rs b/src/libextra/future.rs index 4652e1d647701..030e63adca967 100644 --- a/src/libextra/future.rs +++ b/src/libextra/future.rs @@ -17,7 +17,7 @@ * ~~~ {.rust} * # fn fib(n: uint) -> uint {42}; * # fn make_a_sandwich() {}; - * let mut delayed_fib = std::future::spawn (|| fib(5000) ); + * let mut delayed_fib = extra::future::spawn (|| fib(5000) ); * make_a_sandwich(); * println(fmt!("fib(5000) = %?", delayed_fib.get())) * ~~~ diff --git a/src/libextra/net_ip.rs b/src/libextra/net_ip.rs index 91c357088c98b..718da87af250e 100644 --- a/src/libextra/net_ip.rs +++ b/src/libextra/net_ip.rs @@ -55,7 +55,7 @@ pub struct ParseAddrErr { * * # Arguments * - * * ip - a `std::net::ip::IpAddr` + * * ip - a `extra::net::ip::IpAddr` */ pub fn format_addr(ip: &IpAddr) -> ~str { match *ip { @@ -80,7 +80,7 @@ pub fn format_addr(ip: &IpAddr) -> ~str { * Get the associated port * * # Arguments - * * ip - a `std::net::ip::IpAddr` + * * ip - a `extra::net::ip::IpAddr` */ pub fn get_port(ip: &IpAddr) -> uint { match *ip { diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 59b40b93d4d16..dff72e844bf90 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -1716,5 +1716,5 @@ mod tests { assert!(!os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32)); } - // More recursive_mkdir tests are in std::tempfile + // More recursive_mkdir tests are in extra::tempfile } diff --git a/src/libstd/str.rs b/src/libstd/str.rs index f3226b27d1be3..33380c9e15062 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -14,7 +14,7 @@ * Strings are a packed UTF-8 representation of text, stored as null * terminated buffers of u8 bytes. Strings should be indexed in bytes, * for efficiency, but UTF-8 unsafe operations should be avoided. For - * some heavy-duty uses, try std::rope. + * some heavy-duty uses, try extra::rope. */ use at_vec; From 0f55c9cc7ec4613bc3f85c25799b6020d57e7605 Mon Sep 17 00:00:00 2001 From: Steven Stewart-Gallus Date: Sat, 22 Jun 2013 18:58:41 -0700 Subject: [PATCH 3/8] Cleaned up middle a bit. The only really tricky change is that a long chain of ifs, and elses was turned into a single if, and a match in astencode.rs. Some methods can only be called in certain cases, and so have to come after the if. --- src/librustc/metadata/common.rs | 16 ++- src/librustc/middle/astencode.rs | 175 +++++++++++++++-------------- src/librustc/middle/check_const.rs | 29 ++--- src/librustc/middle/const_eval.rs | 71 +++--------- 4 files changed, 128 insertions(+), 163 deletions(-) diff --git a/src/librustc/metadata/common.rs b/src/librustc/metadata/common.rs index 9426cd6041d91..f487c73372fad 100644 --- a/src/librustc/metadata/common.rs +++ b/src/librustc/metadata/common.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// 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. // @@ -7,7 +7,8 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. - +use core::prelude::*; +use core::cast; // EBML enum definitions and utils shared by the encoder and decoder @@ -111,6 +112,7 @@ pub static tag_items_data_item_reexport_def_id: uint = 0x4e; pub static tag_items_data_item_reexport_name: uint = 0x4f; // used to encode crate_ctxt side tables +#[deriving(Eq)] pub enum astencode_tag { // Reserves 0x50 -- 0x6f tag_ast = 0x50, @@ -136,6 +138,16 @@ pub enum astencode_tag { // Reserves 0x50 -- 0x6f tag_table_moves_map = 0x63, tag_table_capture_map = 0x64 } +static first_astencode_tag : uint = tag_ast as uint; +static last_astencode_tag : uint = tag_table_capture_map as uint; +impl astencode_tag { + pub fn from_uint(value : uint) -> Option { + let is_a_tag = first_astencode_tag <= value && value <= last_astencode_tag; + if !is_a_tag { None } else { + Some(unsafe { cast::transmute(value as int) }) + } + } +} pub static tag_item_trait_method_sort: uint = 0x70; diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 925b1f506d75d..d405dc0bc2073 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// 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. // @@ -319,15 +319,10 @@ fn simplify_ast(ii: &ast::inlined_item) -> ast::inlined_item { }); match *ii { - ast::ii_item(i) => { - ast::ii_item(fld.fold_item(i).get()) //hack: we're not dropping items - } - ast::ii_method(d, m) => { - ast::ii_method(d, fld.fold_method(m)) - } - ast::ii_foreign(i) => { - ast::ii_foreign(fld.fold_foreign_item(i)) - } + //hack: we're not dropping items + ast::ii_item(i) => ast::ii_item(fld.fold_item(i).get()), + ast::ii_method(d, m) => ast::ii_method(d, fld.fold_method(m)), + ast::ii_foreign(i) => ast::ii_foreign(fld.fold_foreign_item(i)) } } @@ -346,16 +341,10 @@ fn renumber_ast(xcx: @ExtendedDecodeContext, ii: ast::inlined_item) }); match ii { - ast::ii_item(i) => { - ast::ii_item(fld.fold_item(i).get()) - } - ast::ii_method(d, m) => { - ast::ii_method(xcx.tr_def_id(d), fld.fold_method(m)) - } - ast::ii_foreign(i) => { - ast::ii_foreign(fld.fold_foreign_item(i)) - } - } + ast::ii_item(i) => ast::ii_item(fld.fold_item(i).get()), + ast::ii_method(d, m) => ast::ii_method(xcx.tr_def_id(d), fld.fold_method(m)), + ast::ii_foreign(i) => ast::ii_foreign(fld.fold_foreign_item(i)), + } } // ______________________________________________________________________ @@ -374,22 +363,22 @@ fn decode_def(xcx: @ExtendedDecodeContext, doc: ebml::Doc) -> ast::def { impl tr for ast::def { fn tr(&self, xcx: @ExtendedDecodeContext) -> ast::def { match *self { - ast::def_fn(did, p) => { ast::def_fn(did.tr(xcx), p) } + ast::def_fn(did, p) => ast::def_fn(did.tr(xcx), p), ast::def_static_method(did, did2_opt, p) => { ast::def_static_method(did.tr(xcx), did2_opt.map(|did2| did2.tr(xcx)), p) - } - ast::def_self_ty(nid) => { ast::def_self_ty(xcx.tr_id(nid)) } - ast::def_self(nid, i) => { ast::def_self(xcx.tr_id(nid), i) } - ast::def_mod(did) => { ast::def_mod(did.tr(xcx)) } - ast::def_foreign_mod(did) => { ast::def_foreign_mod(did.tr(xcx)) } - ast::def_const(did) => { ast::def_const(did.tr(xcx)) } - ast::def_arg(nid, b) => { ast::def_arg(xcx.tr_id(nid), b) } - ast::def_local(nid, b) => { ast::def_local(xcx.tr_id(nid), b) } + }, + ast::def_self_ty(nid) => ast::def_self_ty(xcx.tr_id(nid)), + ast::def_self(nid, i) => ast::def_self(xcx.tr_id(nid), i), + ast::def_mod(did) => ast::def_mod(did.tr(xcx)), + ast::def_foreign_mod(did) => ast::def_foreign_mod(did.tr(xcx)), + ast::def_const(did) => ast::def_const(did.tr(xcx)), + ast::def_arg(nid, b) => ast::def_arg(xcx.tr_id(nid), b), + ast::def_local(nid, b) => ast::def_local(xcx.tr_id(nid), b), ast::def_variant(e_did, v_did) => { ast::def_variant(e_did.tr(xcx), v_did.tr(xcx)) - } + }, ast::def_trait(did) => ast::def_trait(did.tr(xcx)), ast::def_ty(did) => ast::def_ty(did.tr(xcx)), ast::def_prim_ty(p) => ast::def_prim_ty(p), @@ -402,9 +391,7 @@ impl tr for ast::def { xcx.tr_id(nid2), xcx.tr_id(nid3)) } - ast::def_struct(did) => { - ast::def_struct(did.tr(xcx)) - } + ast::def_struct(did) => ast::def_struct(did.tr(xcx)), ast::def_region(nid) => ast::def_region(xcx.tr_id(nid)), ast::def_typaram_binder(nid) => { ast::def_typaram_binder(xcx.tr_id(nid)) @@ -419,12 +406,9 @@ impl tr for ast::def { impl tr for ty::AutoAdjustment { fn tr(&self, xcx: @ExtendedDecodeContext) -> ty::AutoAdjustment { - match self { - &ty::AutoAddEnv(r, s) => { - ty::AutoAddEnv(r.tr(xcx), s) - } - - &ty::AutoDerefRef(ref adr) => { + match *self { + ty::AutoAddEnv(r, s) => ty::AutoAddEnv(r.tr(xcx), s), + ty::AutoDerefRef(ref adr) => { ty::AutoDerefRef(ty::AutoDerefRef { autoderefs: adr.autoderefs, autoref: adr.autoref.map(|ar| ar.tr(xcx)), @@ -1110,56 +1094,75 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext, found for id %d (orig %d)", tag, id, id0); - if tag == (c::tag_table_moves_map as uint) { - dcx.maps.moves_map.insert(id); - } else { - let val_doc = entry_doc.get(c::tag_table_val as uint); - let mut val_dsr = reader::Decoder(val_doc); - let val_dsr = &mut val_dsr; - if tag == (c::tag_table_def as uint) { - let def = decode_def(xcx, val_doc); - dcx.tcx.def_map.insert(id, def); - } else if tag == (c::tag_table_node_type as uint) { - let ty = val_dsr.read_ty(xcx); - debug!("inserting ty for node %?: %s", - id, ty_to_str(dcx.tcx, ty)); - dcx.tcx.node_types.insert(id as uint, ty); - } else if tag == (c::tag_table_node_type_subst as uint) { - let tys = val_dsr.read_tys(xcx); - dcx.tcx.node_type_substs.insert(id, tys); - } else if tag == (c::tag_table_freevars as uint) { - let fv_info = @val_dsr.read_to_vec(|val_dsr| { - @val_dsr.read_freevar_entry(xcx) - }); - dcx.tcx.freevars.insert(id, fv_info); - } else if tag == (c::tag_table_tcache as uint) { - let tpbt = val_dsr.read_ty_param_bounds_and_ty(xcx); - let lid = ast::def_id { crate: ast::local_crate, node: id }; - dcx.tcx.tcache.insert(lid, tpbt); - } else if tag == (c::tag_table_param_defs as uint) { - let bounds = val_dsr.read_type_param_def(xcx); - dcx.tcx.ty_param_defs.insert(id, bounds); - } else if tag == (c::tag_table_method_map as uint) { - dcx.maps.method_map.insert( - id, - val_dsr.read_method_map_entry(xcx)); - } else if tag == (c::tag_table_vtable_map as uint) { - dcx.maps.vtable_map.insert(id, - val_dsr.read_vtable_res(xcx)); - } else if tag == (c::tag_table_adjustments as uint) { - let adj: @ty::AutoAdjustment = @Decodable::decode(val_dsr); - adj.tr(xcx); - dcx.tcx.adjustments.insert(id, adj); - } else if tag == (c::tag_table_capture_map as uint) { - let cvars = - at_vec::to_managed_consume( - val_dsr.read_to_vec( - |val_dsr| val_dsr.read_capture_var(xcx))); - dcx.maps.capture_map.insert(id, cvars); - } else { + match c::astencode_tag::from_uint(tag) { + None => { xcx.dcx.tcx.sess.bug( fmt!("unknown tag found in side tables: %x", tag)); } + Some(value) => if value == c::tag_table_moves_map { + dcx.maps.moves_map.insert(id); + } else { + let val_doc = entry_doc.get(c::tag_table_val as uint); + let mut val_dsr = reader::Decoder(val_doc); + let val_dsr = &mut val_dsr; + + match value { + c::tag_table_def => { + let def = decode_def(xcx, val_doc); + dcx.tcx.def_map.insert(id, def); + } + c::tag_table_node_type => { + let ty = val_dsr.read_ty(xcx); + debug!("inserting ty for node %?: %s", + id, ty_to_str(dcx.tcx, ty)); + dcx.tcx.node_types.insert(id as uint, ty); + } + c::tag_table_node_type_subst => { + let tys = val_dsr.read_tys(xcx); + dcx.tcx.node_type_substs.insert(id, tys); + } + c::tag_table_freevars => { + let fv_info = @val_dsr.read_to_vec(|val_dsr| { + @val_dsr.read_freevar_entry(xcx) + }); + dcx.tcx.freevars.insert(id, fv_info); + } + c::tag_table_tcache => { + let tpbt = val_dsr.read_ty_param_bounds_and_ty(xcx); + let lid = ast::def_id { crate: ast::local_crate, node: id }; + dcx.tcx.tcache.insert(lid, tpbt); + } + c::tag_table_param_defs => { + let bounds = val_dsr.read_type_param_def(xcx); + dcx.tcx.ty_param_defs.insert(id, bounds); + } + c::tag_table_method_map => { + dcx.maps.method_map.insert( + id, + val_dsr.read_method_map_entry(xcx)); + } + c::tag_table_vtable_map => { + dcx.maps.vtable_map.insert(id, + val_dsr.read_vtable_res(xcx)); + } + c::tag_table_adjustments => { + let adj: @ty::AutoAdjustment = @Decodable::decode(val_dsr); + adj.tr(xcx); + dcx.tcx.adjustments.insert(id, adj); + } + c::tag_table_capture_map => { + let cvars = + at_vec::to_managed_consume( + val_dsr.read_to_vec( + |val_dsr| val_dsr.read_capture_var(xcx))); + dcx.maps.capture_map.insert(id, cvars); + } + _ => { + xcx.dcx.tcx.sess.bug( + fmt!("unknown tag found in side tables: %x", tag)); + } + } + } } debug!(">< Side table doc loaded"); diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 79fe6420e2787..3722a5ba5a937 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// 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. // @@ -235,22 +235,17 @@ pub fn check_item_recursion(sess: Session, fn visit_expr(e: @expr, (env, v): (env, visit::vt)) { match e.node { - expr_path(*) => { - match env.def_map.find(&e.id) { - Some(&def_const(def_id)) => { - if ast_util::is_local(def_id) { - match env.ast_map.get_copy(&def_id.node) { - ast_map::node_item(it, _) => { - (v.visit_item)(it, (env, v)); - } - _ => fail!("const not bound to an item") - } - } - } - _ => () - } - } - _ => () + expr_path(*) => match env.def_map.find(&e.id) { + Some(&def_const(def_id)) if ast_util::is_local(def_id) => + match env.ast_map.get_copy(&def_id.node) { + ast_map::node_item(it, _) => { + (v.visit_item)(it, (env, v)); + } + _ => fail!("const not bound to an item") + }, + _ => () + }, + _ => () } visit::visit_expr(e, (env, v)); } diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 988ad519f42bc..78bc59c5647d9 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// 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. // @@ -420,57 +420,18 @@ pub fn lit_to_const(lit: @lit) -> const_val { } } +fn compare_vals(a: T, b: T) -> Option { + Some(if a == b { 0 } else if a < b { -1 } else { 1 }) +} pub fn compare_const_vals(a: &const_val, b: &const_val) -> Option { - match (a, b) { - (&const_int(a), &const_int(b)) => { - if a == b { - Some(0) - } else if a < b { - Some(-1) - } else { - Some(1) - } - } - (&const_uint(a), &const_uint(b)) => { - if a == b { - Some(0) - } else if a < b { - Some(-1) - } else { - Some(1) - } - } - (&const_float(a), &const_float(b)) => { - if a == b { - Some(0) - } else if a < b { - Some(-1) - } else { - Some(1) - } - } - (&const_str(ref a), &const_str(ref b)) => { - if (*a) == (*b) { - Some(0) - } else if (*a) < (*b) { - Some(-1) - } else { - Some(1) - } - } - (&const_bool(a), &const_bool(b)) => { - if a == b { - Some(0) - } else if a < b { - Some(-1) - } else { - Some(1) - } - } - _ => { - None + match (a, b) { + (&const_int(a), &const_int(b)) => compare_vals(a, b), + (&const_uint(a), &const_uint(b)) => compare_vals(a, b), + (&const_float(a), &const_float(b)) => compare_vals(a, b), + (&const_str(a), &const_str(b)) => compare_vals(a, b), + (&const_bool(a), &const_bool(b)) => compare_vals(a, b), + _ => None } - } } pub fn compare_lit_exprs(tcx: middle::ty::ctxt, a: @expr, b: @expr) -> Option { @@ -478,15 +439,9 @@ pub fn compare_lit_exprs(tcx: middle::ty::ctxt, a: @expr, b: @expr) -> Option Option { - match compare_lit_exprs(tcx, a, b) { - Some(val) => Some(val == 0), - None => None, - } + compare_lit_exprs(tcx, a, b).map(|&val| val == 0) } pub fn lit_eq(a: @lit, b: @lit) -> Option { - match compare_const_vals(&lit_to_const(a), &lit_to_const(b)) { - Some(val) => Some(val == 0), - None => None, - } + compare_const_vals(&lit_to_const(a), &lit_to_const(b)).map(|&val| val == 0) } From 8cadca4e41f2aad72391b834f295ae01f9c29551 Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Mon, 24 Jun 2013 00:03:29 +0530 Subject: [PATCH 4/8] abi: remove dead code Signed-off-by: Ramkumar Ramachandra --- src/librustc/back/abi.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/librustc/back/abi.rs b/src/librustc/back/abi.rs index 004170dea7fe6..65db2d4701c0c 100644 --- a/src/librustc/back/abi.rs +++ b/src/librustc/back/abi.rs @@ -74,11 +74,3 @@ 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"; } From 3da7c8f7e11952df0737a1578b87b626a5f4b05a Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 23 Jun 2013 01:27:34 -0700 Subject: [PATCH 5/8] compiletest: Shorten test names --- src/compiletest/compiletest.rc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/compiletest/compiletest.rc b/src/compiletest/compiletest.rc index e832534b227a9..7594a3739df9c 100644 --- a/src/compiletest/compiletest.rc +++ b/src/compiletest/compiletest.rc @@ -253,9 +253,17 @@ pub fn make_test(config: &config, testfile: &Path) -> test::TestDescAndFn { } pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName { + + // Try to elide redundant long paths + fn shorten(path: &Path) -> ~str { + let filename = path.filename(); + let dir = path.pop().filename(); + fmt!("%s/%s", dir.get_or_default(~""), filename.get_or_default(~"")) + } + test::DynTestName(fmt!("[%s] %s", mode_str(config.mode), - testfile.to_str())) + shorten(testfile))) } pub fn make_test_closure(config: &config, testfile: &Path) -> test::TestFn { From fe6a4fd74a0a640fa9291f7cd4d31778da85e39b Mon Sep 17 00:00:00 2001 From: Corey Richardson Date: Mon, 24 Jun 2013 08:05:41 -0400 Subject: [PATCH 6/8] Un-xfail working test --- src/test/run-pass/newlambdas-ret-infer2.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/run-pass/newlambdas-ret-infer2.rs b/src/test/run-pass/newlambdas-ret-infer2.rs index 4b580e7fa797a..4dfe3575eb591 100644 --- a/src/test/run-pass/newlambdas-ret-infer2.rs +++ b/src/test/run-pass/newlambdas-ret-infer2.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// xfail-test ~fn is not inferred // Test that the lambda kind is inferred correctly as a return // expression From 0a74ffcf042cfd6d4b1890e2c2b46e3e0ebaacfd Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Mon, 24 Jun 2013 18:35:43 +0200 Subject: [PATCH 7/8] vim/syntax/rust.vim: fix date header The last change was made in 2013 not 2012. --- src/etc/vim/syntax/rust.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim index 625424ac8709e..2c3e09a3e179f 100644 --- a/src/etc/vim/syntax/rust.vim +++ b/src/etc/vim/syntax/rust.vim @@ -2,7 +2,7 @@ " Language: Rust " Maintainer: Patrick Walton " Maintainer: Ben Blum -" Last Change: 2012 Jun 14 +" Last Change: 2013 Jun 14 if version < 600 syntax clear From 332671c4794f159129eeb948aef4b5e928d38894 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 26 Jun 2013 15:34:12 -0700 Subject: [PATCH 8/8] Whitespace --- src/compiletest/compiletest.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 527e472b0b7be..683d5fecc3491 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -261,7 +261,7 @@ pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName { let dir = path.pop().filename(); fmt!("%s/%s", dir.get_or_default(~""), filename.get_or_default(~"")) } - + test::DynTestName(fmt!("[%s] %s", mode_str(config.mode), shorten(testfile)))