From 57e0908af395af1c10e28600b785b5366a43660c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 2 Apr 2014 01:19:41 -0700 Subject: syntax: Remove AbiSet, use one Abi This change removes the AbiSet from the AST, converting all usage to have just one Abi value. The current scheme selects a relevant ABI given a list of ABIs based on the target architecture and how relevant each ABI is to that architecture. Instead of this mildly complicated scheme, only one ABI will be allowed in abi strings, and pseudo-abis will be created for special cases as necessary. For example the "system" abi exists for stdcall on win32 and C on win64. Closes #10049 --- src/libsyntax/abi.rs | 274 ++++-------------------------------------- src/libsyntax/ast.rs | 8 +- src/libsyntax/ast_map.rs | 14 +-- src/libsyntax/ext/build.rs | 4 +- src/libsyntax/fold.rs | 4 +- src/libsyntax/parse/mod.rs | 2 +- src/libsyntax/parse/parser.rs | 85 ++++++------- src/libsyntax/print/pprust.rs | 53 ++++---- src/libsyntax/visit.rs | 4 +- 9 files changed, 100 insertions(+), 348 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index caded1dc0b8..a40899de931 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -9,12 +9,11 @@ // except according to those terms. use std::fmt; -use std::fmt::Show; #[deriving(Eq)] pub enum Os { OsWin32, OsMacos, OsLinux, OsAndroid, OsFreebsd, } -#[deriving(Eq, TotalEq, Hash)] +#[deriving(Eq, TotalEq, Hash, Encodable, Decodable, Clone)] pub enum Abi { // NB: This ordering MUST match the AbiDatas array below. // (This is ensured by the test indices_are_correct().) @@ -65,11 +64,6 @@ pub enum AbiArchitecture { Archs(u32) // Multiple architectures (bitset) } -#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] -pub struct AbiSet { - bits: u32 // each bit represents one of the abis below -} - static AbiDatas: &'static [AbiData] = &[ // Platform-specific ABIs AbiData {abi: Cdecl, name: "cdecl", abi_arch: Archs(IntelBits)}, @@ -136,12 +130,20 @@ impl Abi { self.data().name } - pub fn for_target(&self, os: Os, arch: Architecture) -> Abi { - match (*self, os, arch) { + pub fn for_target(&self, os: Os, arch: Architecture) -> Option { + // If this ABI isn't actually for the specified architecture, then we + // short circuit early + match self.data().abi_arch { + Archs(a) if a & arch.bit() == 0 => return None, + Archs(_) | RustArch | AllArch => {} + } + // Transform this ABI as appropriate for the requested os/arch + // combination. + Some(match (*self, os, arch) { (System, OsWin32, X86) => Stdcall, (System, _, _) => C, (me, _, _) => me, - } + }) } } @@ -151,138 +153,9 @@ impl Architecture { } } -impl AbiSet { - pub fn from(abi: Abi) -> AbiSet { - AbiSet { bits: (1 << abi.index()) } - } - - #[inline] - pub fn Rust() -> AbiSet { - AbiSet::from(Rust) - } - - #[inline] - pub fn C() -> AbiSet { - AbiSet::from(C) - } - - #[inline] - pub fn Intrinsic() -> AbiSet { - AbiSet::from(RustIntrinsic) - } - - pub fn default() -> AbiSet { - AbiSet::C() - } - - pub fn empty() -> AbiSet { - AbiSet { bits: 0 } - } - - #[inline] - pub fn is_rust(&self) -> bool { - self.bits == 1 << Rust.index() - } - - #[inline] - pub fn is_c(&self) -> bool { - self.bits == 1 << C.index() - } - - #[inline] - pub fn is_intrinsic(&self) -> bool { - self.bits == 1 << RustIntrinsic.index() - } - - pub fn contains(&self, abi: Abi) -> bool { - (self.bits & (1 << abi.index())) != 0 - } - - pub fn subset_of(&self, other_abi_set: AbiSet) -> bool { - (self.bits & other_abi_set.bits) == self.bits - } - - pub fn add(&mut self, abi: Abi) { - self.bits |= 1 << abi.index(); - } - - pub fn each(&self, op: |abi: Abi| -> bool) -> bool { - each_abi(|abi| !self.contains(abi) || op(abi)) - } - - pub fn is_empty(&self) -> bool { - self.bits == 0 - } - - pub fn for_target(&self, os: Os, arch: Architecture) -> Option { - // NB---Single platform ABIs come first - - let mut res = None; - - self.each(|abi| { - let data = abi.data(); - match data.abi_arch { - Archs(a) if (a & arch.bit()) != 0 => { res = Some(abi); false } - Archs(_) => { true } - RustArch | AllArch => { res = Some(abi); false } - } - }); - - res.map(|r| r.for_target(os, arch)) - } - - pub fn check_valid(&self) -> Option<(Abi, Abi)> { - let mut abis = Vec::new(); - self.each(|abi| { abis.push(abi); true }); - - for (i, abi) in abis.iter().enumerate() { - let data = abi.data(); - for other_abi in abis.slice(0, i).iter() { - let other_data = other_abi.data(); - debug!("abis=({:?},{:?}) datas=({:?},{:?})", - abi, data.abi_arch, - other_abi, other_data.abi_arch); - match (&data.abi_arch, &other_data.abi_arch) { - (&AllArch, &AllArch) => { - // Two cross-architecture ABIs - return Some((*abi, *other_abi)); - } - (_, &RustArch) | - (&RustArch, _) => { - // Cannot combine Rust or Rust-Intrinsic with - // anything else. - return Some((*abi, *other_abi)); - } - (&Archs(is), &Archs(js)) if (is & js) != 0 => { - // Two ABIs for same architecture - return Some((*abi, *other_abi)); - } - _ => {} - } - } - } - - return None; - } -} - impl fmt::Show for Abi { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.data().name.fmt(f) - } -} - -impl fmt::Show for AbiSet { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - try!(write!(f.buf, "\"")); - let mut first = true; - self.each(|abi| { - if first { first = false; } - else { let _ = write!(f.buf, " "); } - let _ = write!(f.buf, "{}", abi.data().name); - true - }); - write!(f.buf, "\"") + write!(f.buf, "\"{}\"", self.name()) } } @@ -304,95 +177,6 @@ fn lookup_baz() { assert!(abi.is_none()); } -#[cfg(test)] -fn cannot_combine(n: Abi, m: Abi) { - let mut set = AbiSet::empty(); - set.add(n); - set.add(m); - match set.check_valid() { - Some((a, b)) => { - assert!((n == a && m == b) || - (m == a && n == b)); - } - None => { - fail!("invalid match not detected"); - } - } -} - -#[cfg(test)] -fn can_combine(n: Abi, m: Abi) { - let mut set = AbiSet::empty(); - set.add(n); - set.add(m); - match set.check_valid() { - Some((_, _)) => { - fail!("valid match declared invalid"); - } - None => {} - } -} - -#[test] -fn cannot_combine_cdecl_and_stdcall() { - cannot_combine(Cdecl, Stdcall); -} - -#[test] -fn cannot_combine_c_and_rust() { - cannot_combine(C, Rust); -} - -#[test] -fn cannot_combine_rust_and_cdecl() { - cannot_combine(Rust, Cdecl); -} - -#[test] -fn cannot_combine_rust_intrinsic_and_cdecl() { - cannot_combine(RustIntrinsic, Cdecl); -} - -#[test] -fn can_combine_system_and_cdecl() { - can_combine(System, Cdecl); -} - -#[test] -fn can_combine_c_and_stdcall() { - can_combine(C, Stdcall); -} - -#[test] -fn can_combine_aapcs_and_stdcall() { - can_combine(Aapcs, Stdcall); -} - -#[test] -fn abi_to_str_stdcall_aaps() { - let mut set = AbiSet::empty(); - set.add(Aapcs); - set.add(Stdcall); - assert!(set.to_str() == ~"\"stdcall aapcs\""); -} - -#[test] -fn abi_to_str_c_aaps() { - let mut set = AbiSet::empty(); - set.add(Aapcs); - set.add(C); - debug!("set = {}", set.to_str()); - assert!(set.to_str() == ~"\"aapcs C\""); -} - -#[test] -fn abi_to_str_rust() { - let mut set = AbiSet::empty(); - set.add(Rust); - debug!("set = {}", set.to_str()); - assert!(set.to_str() == ~"\"Rust\""); -} - #[test] fn indices_are_correct() { for (i, abi_data) in AbiDatas.iter().enumerate() { @@ -407,30 +191,14 @@ fn indices_are_correct() { assert_eq!(ArmBits, bits); } -#[cfg(test)] -fn get_arch(abis: &[Abi], os: Os, arch: Architecture) -> Option { - let mut set = AbiSet::empty(); - for &abi in abis.iter() { - set.add(abi); - } - set.for_target(os, arch) -} - -#[test] -fn pick_multiplatform() { - assert_eq!(get_arch([C, Cdecl], OsLinux, X86), Some(Cdecl)); - assert_eq!(get_arch([C, Cdecl], OsLinux, X86_64), Some(Cdecl)); - assert_eq!(get_arch([C, Cdecl], OsLinux, Arm), Some(C)); -} - #[test] fn pick_uniplatform() { - assert_eq!(get_arch([Stdcall], OsLinux, X86), Some(Stdcall)); - assert_eq!(get_arch([Stdcall], OsLinux, Arm), None); - assert_eq!(get_arch([System], OsLinux, X86), Some(C)); - assert_eq!(get_arch([System], OsWin32, X86), Some(Stdcall)); - assert_eq!(get_arch([System], OsWin32, X86_64), Some(C)); - assert_eq!(get_arch([System], OsWin32, Arm), Some(C)); - assert_eq!(get_arch([Stdcall], OsWin32, X86), Some(Stdcall)); - assert_eq!(get_arch([Stdcall], OsWin32, X86_64), Some(Stdcall)); + assert_eq!(Stdcall.for_arch(OsLinux, X86), Some(Stdcall)); + assert_eq!(Stdcall.for_arch(OsLinux, Arm), None); + assert_eq!(System.for_arch(OsLinux, X86), Some(C)); + assert_eq!(System.for_arch(OsWin32, X86), Some(Stdcall)); + assert_eq!(System.for_arch(OsWin32, X86_64), Some(C)); + assert_eq!(System.for_arch(OsWin32, Arm), Some(C)); + assert_eq!(Stdcall.for_arch(OsWin32, X86), Some(Stdcall)); + assert_eq!(Stdcall.for_arch(OsWin32, X86_64), Some(Stdcall)); } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 3a9cdfb56e3..4612f8e6673 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -11,7 +11,7 @@ // The Rust abstract syntax tree. use codemap::{Span, Spanned, DUMMY_SP}; -use abi::AbiSet; +use abi::Abi; use ast_util; use owned_slice::OwnedSlice; use parse::token::{InternedString, special_idents, str_to_ident}; @@ -807,7 +807,7 @@ pub struct ClosureTy { #[deriving(Eq, TotalEq, Encodable, Decodable, Hash)] pub struct BareFnTy { pub purity: Purity, - pub abis: AbiSet, + pub abi: Abi, pub lifetimes: Vec, pub decl: P } @@ -941,7 +941,7 @@ pub struct Mod { #[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct ForeignMod { - pub abis: AbiSet, + pub abi: Abi, pub view_items: Vec, pub items: Vec<@ForeignItem>, } @@ -1119,7 +1119,7 @@ pub struct Item { #[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum Item_ { ItemStatic(P, Mutability, @Expr), - ItemFn(P, Purity, AbiSet, Generics, P), + ItemFn(P, Purity, Abi, Generics, P), ItemMod(Mod), ItemForeignMod(ForeignMod), ItemTy(P, Generics), diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index f07b0e71c1c..e098dcd99fd 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use abi::AbiSet; +use abi; use ast::*; use ast_util; use codemap::Span; @@ -224,19 +224,19 @@ impl Map { } } - pub fn get_foreign_abis(&self, id: NodeId) -> AbiSet { + pub fn get_foreign_abi(&self, id: NodeId) -> abi::Abi { let parent = self.get_parent(id); - let abis = match self.find_entry(parent) { + let abi = match self.find_entry(parent) { Some(EntryItem(_, i)) => match i.node { - ItemForeignMod(ref nm) => Some(nm.abis), + ItemForeignMod(ref nm) => Some(nm.abi), _ => None }, // Wrong but OK, because the only inlined foreign items are intrinsics. - Some(RootInlinedParent(_)) => Some(AbiSet::Intrinsic()), + Some(RootInlinedParent(_)) => Some(abi::RustIntrinsic), _ => None }; - match abis { - Some(abis) => abis, + match abi { + Some(abi) => abi, None => fail!("expected foreign mod or inlined parent, found {}", self.node_to_str(parent)) } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 489af0fc2d4..ef62f0a01f6 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use abi::AbiSet; +use abi; use ast::{P, Ident}; use ast; use ast_util; @@ -826,7 +826,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { Vec::new(), ast::ItemFn(self.fn_decl(inputs, output), ast::ImpureFn, - AbiSet::Rust(), + abi::Rust, generics, body)) } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 03963219d52..06bf892771d 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -170,7 +170,7 @@ pub trait Folder { TyBareFn(@BareFnTy { lifetimes: f.lifetimes.iter().map(|l| fold_lifetime(l, self)).collect(), purity: f.purity, - abis: f.abis, + abi: f.abi, decl: self.fold_fn_decl(f.decl) }) } @@ -198,7 +198,7 @@ pub trait Folder { fn fold_foreign_mod(&mut self, nm: &ForeignMod) -> ForeignMod { ast::ForeignMod { - abis: nm.abis, + abi: nm.abi, view_items: nm.view_items .iter() .map(|x| self.fold_view_item(x)) diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 76126e6780a..dbb85972774 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -657,7 +657,7 @@ mod test { variadic: false }), ast::ImpureFn, - abi::AbiSet::Rust(), + abi::Rust, ast::Generics{ // no idea on either of these: lifetimes: Vec::new(), ty_params: OwnedSlice::empty(), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index b3e488a464d..2d78bfe5694 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -11,7 +11,6 @@ #![macro_escape] use abi; -use abi::AbiSet; use ast::{Sigil, BorrowedSigil, ManagedSigil, OwnedSigil}; use ast::{BareFnTy, ClosureTy}; use ast::{RegionTyParamBound, TraitTyParamBound}; @@ -873,17 +872,17 @@ impl<'a> Parser<'a> { */ - let abis = if self.eat_keyword(keywords::Extern) { - self.parse_opt_abis().unwrap_or(AbiSet::C()) + let abi = if self.eat_keyword(keywords::Extern) { + self.parse_opt_abi().unwrap_or(abi::C) } else { - AbiSet::Rust() + abi::Rust }; let purity = self.parse_unsafety(); self.expect_keyword(keywords::Fn); let (decl, lifetimes) = self.parse_ty_fn_decl(true); return TyBareFn(@BareFnTy { - abis: abis, + abi: abi, purity: purity, lifetimes: lifetimes, decl: decl @@ -3770,11 +3769,11 @@ impl<'a> Parser<'a> { } // parse an item-position function declaration. - fn parse_item_fn(&mut self, purity: Purity, abis: AbiSet) -> ItemInfo { + fn parse_item_fn(&mut self, purity: Purity, abi: abi::Abi) -> ItemInfo { let (ident, generics) = self.parse_fn_header(); let decl = self.parse_fn_decl(false); let (inner_attrs, body) = self.parse_inner_attrs_and_block(); - (ident, ItemFn(decl, purity, abis, generics, body), Some(inner_attrs)) + (ident, ItemFn(decl, purity, abi, generics, body), Some(inner_attrs)) } // parse a method in a trait impl, starting with `attrs` attributes. @@ -4237,7 +4236,7 @@ impl<'a> Parser<'a> { // at this point, this is essentially a wrapper for // parse_foreign_items. fn parse_foreign_mod_items(&mut self, - abis: AbiSet, + abi: abi::Abi, first_item_attrs: Vec ) -> ForeignMod { let ParsedItemsAndViewItems { @@ -4252,7 +4251,7 @@ impl<'a> Parser<'a> { } assert!(self.token == token::RBRACE); ast::ForeignMod { - abis: abis, + abi: abi, view_items: view_items, items: foreign_items } @@ -4310,17 +4309,17 @@ impl<'a> Parser<'a> { /// extern {} fn parse_item_foreign_mod(&mut self, lo: BytePos, - opt_abis: Option, + opt_abi: Option, visibility: Visibility, attrs: Vec ) -> ItemOrViewItem { self.expect(&token::LBRACE); - let abis = opt_abis.unwrap_or(AbiSet::C()); + let abi = opt_abi.unwrap_or(abi::C); let (inner, next) = self.parse_inner_attrs_and_next(); - let m = self.parse_foreign_mod_items(abis, next); + let m = self.parse_foreign_mod_items(abi, next); self.expect(&token::RBRACE); let item = self.mk_item(lo, @@ -4440,45 +4439,29 @@ impl<'a> Parser<'a> { // Parses a string as an ABI spec on an extern type or module. Consumes // the `extern` keyword, if one is found. - fn parse_opt_abis(&mut self) -> Option { + fn parse_opt_abi(&mut self) -> Option { match self.token { - token::LIT_STR(s) - | token::LIT_STR_RAW(s, _) => { + token::LIT_STR(s) | token::LIT_STR_RAW(s, _) => { self.bump(); let identifier_string = token::get_ident(s); let the_string = identifier_string.get(); - let mut abis = AbiSet::empty(); - for word in the_string.words() { - match abi::lookup(word) { - Some(abi) => { - if abis.contains(abi) { - self.span_err( - self.span, - format!("ABI `{}` appears twice", - word)); - } else { - abis.add(abi); - } - } - - None => { - self.span_err( - self.span, - format!("illegal ABI: \ - expected one of [{}], \ - found `{}`", - abi::all_names().connect(", "), - word)); - } - } - } - Some(abis) + match abi::lookup(the_string) { + Some(abi) => Some(abi), + None => { + self.span_err( + self.span, + format!("illegal ABI: \ + expected one of [{}], \ + found `{}`", + abi::all_names().connect(", "), + the_string)); + None + } + } } - _ => { - None - } - } + _ => None, + } } // parse one of the items or view items allowed by the @@ -4531,13 +4514,13 @@ impl<'a> Parser<'a> { return self.parse_item_extern_crate(lo, visibility, attrs); } - let opt_abis = self.parse_opt_abis(); + let opt_abi = self.parse_opt_abi(); if self.eat_keyword(keywords::Fn) { // EXTERN FUNCTION ITEM - let abis = opt_abis.unwrap_or(AbiSet::C()); + let abi = opt_abi.unwrap_or(abi::C); let (ident, item_, extra_attrs) = - self.parse_item_fn(ExternFn, abis); + self.parse_item_fn(ExternFn, abi); let item = self.mk_item(lo, self.last_span.hi, ident, @@ -4546,7 +4529,7 @@ impl<'a> Parser<'a> { maybe_append(attrs, extra_attrs)); return IoviItem(item); } else if self.token == token::LBRACE { - return self.parse_item_foreign_mod(lo, opt_abis, visibility, attrs); + return self.parse_item_foreign_mod(lo, opt_abi, visibility, attrs); } let token_str = self.this_token_to_str(); @@ -4572,7 +4555,7 @@ impl<'a> Parser<'a> { // FUNCTION ITEM self.bump(); let (ident, item_, extra_attrs) = - self.parse_item_fn(ImpureFn, AbiSet::Rust()); + self.parse_item_fn(ImpureFn, abi::Rust); let item = self.mk_item(lo, self.last_span.hi, ident, @@ -4587,7 +4570,7 @@ impl<'a> Parser<'a> { self.bump(); self.expect_keyword(keywords::Fn); let (ident, item_, extra_attrs) = - self.parse_item_fn(UnsafeFn, AbiSet::Rust()); + self.parse_item_fn(UnsafeFn, abi::Rust); let item = self.mk_item(lo, self.last_span.hi, ident, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 98a3ff30916..1eee0fb87d6 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use abi::AbiSet; +use abi; use ast::{P, RegionTyParamBound, TraitTyParamBound, Required, Provided}; use ast; use ast_util; @@ -190,7 +190,7 @@ pub fn fun_to_str(decl: &ast::FnDecl, purity: ast::Purity, name: ast::Ident, opt_explicit_self: Option, generics: &ast::Generics) -> ~str { to_str(|s| { - try!(s.print_fn(decl, Some(purity), AbiSet::Rust(), + try!(s.print_fn(decl, Some(purity), abi::Rust, name, generics, opt_explicit_self, ast::Inherited)); try!(s.end()); // Close the head box s.end() // Close the outer box @@ -478,7 +478,7 @@ impl<'a> State<'a> { lifetimes: f.lifetimes.clone(), ty_params: OwnedSlice::empty() }; - try!(self.print_ty_fn(Some(f.abis), None, &None, + try!(self.print_ty_fn(Some(f.abi), None, &None, f.purity, ast::Many, f.decl, None, &None, Some(&generics), None)); } @@ -524,7 +524,7 @@ impl<'a> State<'a> { try!(self.print_outer_attributes(item.attrs.as_slice())); match item.node { ast::ForeignItemFn(decl, ref generics) => { - try!(self.print_fn(decl, None, AbiSet::Rust(), item.ident, generics, + try!(self.print_fn(decl, None, abi::Rust, item.ident, generics, None, item.vis)); try!(self.end()); // end head-ibox try!(word(&mut self.s, ";")); @@ -590,7 +590,7 @@ impl<'a> State<'a> { } ast::ItemForeignMod(ref nmod) => { try!(self.head("extern")); - try!(self.word_nbsp(nmod.abis.to_str())); + try!(self.word_nbsp(nmod.abi.to_str())); try!(self.bopen()); try!(self.print_foreign_mod(nmod, item.attrs.as_slice())); try!(self.bclose(item.span)); @@ -883,7 +883,7 @@ impl<'a> State<'a> { try!(self.hardbreak_if_not_bol()); try!(self.maybe_print_comment(meth.span.lo)); try!(self.print_outer_attributes(meth.attrs.as_slice())); - try!(self.print_fn(meth.decl, Some(meth.purity), AbiSet::Rust(), + try!(self.print_fn(meth.decl, Some(meth.purity), abi::Rust, meth.ident, &meth.generics, Some(meth.explicit_self.node), meth.vis)); try!(word(&mut self.s, " ")); @@ -1717,14 +1717,14 @@ impl<'a> State<'a> { pub fn print_fn(&mut self, decl: &ast::FnDecl, purity: Option, - abis: AbiSet, + abi: abi::Abi, name: ast::Ident, generics: &ast::Generics, opt_explicit_self: Option, vis: ast::Visibility) -> IoResult<()> { try!(self.head("")); - try!(self.print_fn_header_info(opt_explicit_self, purity, abis, - ast::Many, None, vis)); + try!(self.print_fn_header_info(opt_explicit_self, purity, abi, + ast::Many, None, vis)); try!(self.nbsp()); try!(self.print_ident(name)); try!(self.print_generics(generics)); @@ -2016,7 +2016,7 @@ impl<'a> State<'a> { } pub fn print_ty_fn(&mut self, - opt_abis: Option, + opt_abi: Option, opt_sigil: Option, opt_region: &Option, purity: ast::Purity, @@ -2034,14 +2034,14 @@ impl<'a> State<'a> { if opt_sigil == Some(ast::OwnedSigil) && onceness == ast::Once { try!(word(&mut self.s, "proc")); } else if opt_sigil == Some(ast::BorrowedSigil) { - try!(self.print_extern_opt_abis(opt_abis)); + try!(self.print_extern_opt_abi(opt_abi)); for lifetime in opt_region.iter() { try!(self.print_lifetime(lifetime)); } try!(self.print_purity(purity)); try!(self.print_onceness(onceness)); } else { - try!(self.print_opt_abis_and_extern_if_nondefault(opt_abis)); + try!(self.print_opt_abi_and_extern_if_nondefault(opt_abi)); try!(self.print_opt_sigil(opt_sigil)); try!(self.print_opt_lifetime(opt_region)); try!(self.print_purity(purity)); @@ -2303,24 +2303,25 @@ impl<'a> State<'a> { } } - pub fn print_opt_abis_and_extern_if_nondefault(&mut self, - opt_abis: Option) + pub fn print_opt_abi_and_extern_if_nondefault(&mut self, + opt_abi: Option) -> IoResult<()> { - match opt_abis { - Some(abis) if !abis.is_rust() => { + match opt_abi { + Some(abi::Rust) => Ok(()), + Some(abi) => { try!(self.word_nbsp("extern")); - self.word_nbsp(abis.to_str()) + self.word_nbsp(abi.to_str()) } - Some(_) | None => Ok(()) + None => Ok(()) } } - pub fn print_extern_opt_abis(&mut self, - opt_abis: Option) -> IoResult<()> { - match opt_abis { - Some(abis) => { + pub fn print_extern_opt_abi(&mut self, + opt_abi: Option) -> IoResult<()> { + match opt_abi { + Some(abi) => { try!(self.word_nbsp("extern")); - self.word_nbsp(abis.to_str()) + self.word_nbsp(abi.to_str()) } None => Ok(()) } @@ -2339,15 +2340,15 @@ impl<'a> State<'a> { pub fn print_fn_header_info(&mut self, _opt_explicit_self: Option, opt_purity: Option, - abis: AbiSet, + abi: abi::Abi, onceness: ast::Onceness, opt_sigil: Option, vis: ast::Visibility) -> IoResult<()> { try!(word(&mut self.s, visibility_qualified(vis, ""))); - if abis != AbiSet::Rust() { + if abi != abi::Rust { try!(self.word_nbsp("extern")); - try!(self.word_nbsp(abis.to_str())); + try!(self.word_nbsp(abi.to_str())); if opt_purity != Some(ast::ExternFn) { try!(self.print_opt_purity(opt_purity)); diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index de3eb1b9b8d..eb03bb1f0bb 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use abi::AbiSet; +use abi::Abi; use ast::*; use ast; use codemap::Span; @@ -29,7 +29,7 @@ use owned_slice::OwnedSlice; pub enum FnKind<'a> { // fn foo() or extern "Abi" fn foo() - FkItemFn(Ident, &'a Generics, Purity, AbiSet), + FkItemFn(Ident, &'a Generics, Purity, Abi), // fn foo(&self) FkMethod(Ident, &'a Generics, &'a Method), -- cgit 1.4.1-3-g733a5 From 487fa9568b69753fecb74a8460109239f4bf3631 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 3 Apr 2014 14:09:16 -0700 Subject: Test fixes from the rollup --- src/libstd/rt/global_heap.rs | 10 +++++----- src/libsyntax/abi.rs | 16 ++++++++-------- src/test/bench/rt-spawn-rate.rs | 10 ++++++++++ 3 files changed, 23 insertions(+), 13 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libstd/rt/global_heap.rs b/src/libstd/rt/global_heap.rs index 3917857e1af..5c1b6cd4791 100644 --- a/src/libstd/rt/global_heap.rs +++ b/src/libstd/rt/global_heap.rs @@ -64,16 +64,16 @@ pub unsafe fn realloc_raw(ptr: *mut u8, size: uint) -> *mut u8 { } } -// The compiler never calls `exchange_free` on ~ZeroSizeType, so zero-size -// allocations can point to this `static`. It would be incorrect to use a null -// pointer, due to enums assuming types like unique pointers are never null. -static EMPTY: () = (); - /// The allocator for unique pointers without contained managed pointers. #[cfg(not(test))] #[lang="exchange_malloc"] #[inline] pub unsafe fn exchange_malloc(size: uint) -> *mut u8 { + // The compiler never calls `exchange_free` on ~ZeroSizeType, so zero-size + // allocations can point to this `static`. It would be incorrect to use a null + // pointer, due to enums assuming types like unique pointers are never null. + static EMPTY: () = (); + if size == 0 { &EMPTY as *() as *mut u8 } else { diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index a40899de931..17251d31351 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -193,12 +193,12 @@ fn indices_are_correct() { #[test] fn pick_uniplatform() { - assert_eq!(Stdcall.for_arch(OsLinux, X86), Some(Stdcall)); - assert_eq!(Stdcall.for_arch(OsLinux, Arm), None); - assert_eq!(System.for_arch(OsLinux, X86), Some(C)); - assert_eq!(System.for_arch(OsWin32, X86), Some(Stdcall)); - assert_eq!(System.for_arch(OsWin32, X86_64), Some(C)); - assert_eq!(System.for_arch(OsWin32, Arm), Some(C)); - assert_eq!(Stdcall.for_arch(OsWin32, X86), Some(Stdcall)); - assert_eq!(Stdcall.for_arch(OsWin32, X86_64), Some(Stdcall)); + assert_eq!(Stdcall.for_target(OsLinux, X86), Some(Stdcall)); + assert_eq!(Stdcall.for_target(OsLinux, Arm), None); + assert_eq!(System.for_target(OsLinux, X86), Some(C)); + assert_eq!(System.for_target(OsWin32, X86), Some(Stdcall)); + assert_eq!(System.for_target(OsWin32, X86_64), Some(C)); + assert_eq!(System.for_target(OsWin32, Arm), Some(C)); + assert_eq!(Stdcall.for_target(OsWin32, X86), Some(Stdcall)); + assert_eq!(Stdcall.for_target(OsWin32, X86_64), Some(Stdcall)); } diff --git a/src/test/bench/rt-spawn-rate.rs b/src/test/bench/rt-spawn-rate.rs index 5f445de069c..4f07660779b 100644 --- a/src/test/bench/rt-spawn-rate.rs +++ b/src/test/bench/rt-spawn-rate.rs @@ -8,6 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![no_start] + +extern crate green; +extern crate rustuv; + use std::task::spawn; use std::os; use std::uint; @@ -15,6 +20,11 @@ use std::uint; // Very simple spawn rate test. Spawn N tasks that do nothing and // return. +#[start] +fn start(argc: int, argv: **u8) -> int { + green::start(argc, argv, rustuv::event_loop, main) +} + fn main() { let args = os::args(); -- cgit 1.4.1-3-g733a5