Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax: Remove AbiSet, use one Abi #13263

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/front/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn fold_foreign_mod(cx: &mut Context, nm: &ast::ForeignMod) -> ast::ForeignMod {
filter_view_item(cx, a).map(|x| cx.fold_view_item(x))
}).collect();
ast::ForeignMod {
abis: nm.abis,
abi: nm.abi,
view_items: filtered_view_items,
items: filtered_items
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn extract_crate_info(e: &Env, i: &ast::ViewItem) -> Option<CrateInfo> {
fn visit_item(e: &Env, i: &ast::Item) {
match i.node {
ast::ItemForeignMod(ref fm) => {
if fm.abis.is_rust() || fm.abis.is_intrinsic() {
if fm.abi == abi::Rust || fm.abi == abi::RustIntrinsic {
return;
}

Expand Down
10 changes: 5 additions & 5 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use std::hash::Hash;
use std::io::MemWriter;
use std::str;
use collections::HashMap;
use syntax::abi::AbiSet;
use syntax::abi;
use syntax::ast::*;
use syntax::ast;
use syntax::ast_map::{PathElem, PathElems};
Expand Down Expand Up @@ -1217,7 +1217,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
nitem: &ForeignItem,
index: @RefCell<Vec<entry<i64>> >,
path: PathElems,
abi: AbiSet) {
abi: abi::Abi) {
index.borrow_mut().push(entry {
val: nitem.id as i64,
pos: ebml_w.writer.tell().unwrap(),
Expand All @@ -1231,7 +1231,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
encode_bounds_and_type(ebml_w, ecx,
&lookup_item_type(ecx.tcx,local_def(nitem.id)));
encode_name(ebml_w, nitem.ident.name);
if abi.is_intrinsic() {
if abi == abi::RustIntrinsic {
(ecx.encode_inlined_item)(ecx, ebml_w, IIForeignRef(nitem));
} else {
encode_symbol(ecx, ebml_w, nitem.id);
Expand Down Expand Up @@ -1279,11 +1279,11 @@ fn my_visit_foreign_item(ni: &ForeignItem,
let mut ebml_w = unsafe {
ebml_w.unsafe_clone()
};
let abis = ecx.tcx.map.get_foreign_abis(ni.id);
let abi = ecx.tcx.map.get_foreign_abi(ni.id);
ecx.tcx.map.with_path(ni.id, |path| {
encode_info_for_foreign_item(ecx, &mut ebml_w,
ni, index,
path, abis);
path, abi);
});
}

Expand Down
19 changes: 6 additions & 13 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use middle::ty;

use std::str;
use std::uint;
use syntax::abi::AbiSet;
use syntax::abi;
use syntax::ast;
use syntax::ast::*;
Expand Down Expand Up @@ -460,18 +459,12 @@ fn parse_purity(c: char) -> Purity {
}
}

fn parse_abi_set(st: &mut PState) -> AbiSet {
fn parse_abi_set(st: &mut PState) -> abi::Abi {
assert_eq!(next(st), '[');
let mut abis = AbiSet::empty();
while peek(st) != ']' {
scan(st, |c| c == ',', |bytes| {
let abi_str = str::from_utf8(bytes).unwrap().to_owned();
let abi = abi::lookup(abi_str).expect(abi_str);
abis.add(abi);
});
}
assert_eq!(next(st), ']');
return abis;
scan(st, |c| c == ']', |bytes| {
let abi_str = str::from_utf8(bytes).unwrap().to_owned();
abi::lookup(abi_str).expect(abi_str)
})
}

fn parse_onceness(c: char) -> ast::Onceness {
Expand Down Expand Up @@ -505,7 +498,7 @@ fn parse_bare_fn_ty(st: &mut PState, conv: conv_did) -> ty::BareFnTy {
let sig = parse_sig(st, |x,y| conv(x,y));
ty::BareFnTy {
purity: purity,
abis: abi,
abi: abi,
sig: sig
}
}
Expand Down
11 changes: 4 additions & 7 deletions src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::fmt;
use middle::ty::param_ty;
use middle::ty;

use syntax::abi::AbiSet;
use syntax::abi::Abi;
use syntax::ast;
use syntax::ast::*;
use syntax::diagnostic::SpanHandler;
Expand Down Expand Up @@ -341,12 +341,9 @@ fn enc_purity(w: &mut MemWriter, p: Purity) {
}
}

fn enc_abi_set(w: &mut MemWriter, abis: AbiSet) {
fn enc_abi(w: &mut MemWriter, abi: Abi) {
mywrite!(w, "[");
abis.each(|abi| {
mywrite!(w, "{},", abi.name());
true
});
mywrite!(w, "{}", abi.name());
mywrite!(w, "]")
}

Expand All @@ -359,7 +356,7 @@ fn enc_onceness(w: &mut MemWriter, o: Onceness) {

pub fn enc_bare_fn_ty(w: &mut MemWriter, cx: &ctxt, ft: &ty::BareFnTy) {
enc_purity(w, ft.purity);
enc_abi_set(w, ft.abis);
enc_abi(w, ft.abi);
enc_fn_sig(w, cx, &ft.sig);
}

Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use std::u32;
use std::u64;
use std::u8;
use collections::SmallIntMap;
use syntax::abi;
use syntax::ast_map;
use syntax::ast_util::IdVisitingOperation;
use syntax::attr::{AttrMetaMethods, AttributeMethods};
Expand Down Expand Up @@ -892,7 +893,7 @@ fn check_item_ctypes(cx: &Context, it: &ast::Item) {
}

match it.node {
ast::ItemForeignMod(ref nmod) if !nmod.abis.is_intrinsic() => {
ast::ItemForeignMod(ref nmod) if nmod.abi != abi::RustIntrinsic => {
for ni in nmod.items.iter() {
match ni.node {
ast::ForeignItemFn(decl, _) => check_foreign_fn(cx, decl),
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,8 +855,8 @@ pub fn trans_external_path(ccx: &CrateContext, did: ast::DefId, t: ty::t) -> Val
let name = csearch::get_symbol(&ccx.sess().cstore, did);
match ty::get(t).sty {
ty::ty_bare_fn(ref fn_ty) => {
match fn_ty.abis.for_target(ccx.sess().targ_cfg.os,
ccx.sess().targ_cfg.arch) {
match fn_ty.abi.for_target(ccx.sess().targ_cfg.os,
ccx.sess().targ_cfg.arch) {
Some(Rust) | Some(RustIntrinsic) => {
get_extern_rust_fn(ccx,
fn_ty.sig.inputs.as_slice(),
Expand All @@ -865,7 +865,7 @@ pub fn trans_external_path(ccx: &CrateContext, did: ast::DefId, t: ty::t) -> Val
did)
}
Some(..) | None => {
let c = foreign::llvm_calling_convention(ccx, fn_ty.abis);
let c = foreign::llvm_calling_convention(ccx, fn_ty.abi);
let cconv = c.unwrap_or(lib::llvm::CCallConv);
let llty = type_of_fn_from_ty(ccx, t);
get_extern_fn(&mut *ccx.externs.borrow_mut(), ccx.llmod,
Expand Down Expand Up @@ -1601,7 +1601,7 @@ impl<'a> Visitor<()> for TransItemVisitor<'a> {
pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
let _icx = push_ctxt("trans_item");
match item.node {
ast::ItemFn(decl, purity, _abis, ref generics, body) => {
ast::ItemFn(decl, purity, _abi, ref generics, body) => {
if purity == ast::ExternFn {
let llfndecl = get_item_val(ccx, item.id);
foreign::trans_rust_fn_with_foreign_abi(
Expand Down Expand Up @@ -1721,7 +1721,7 @@ fn register_fn(ccx: &CrateContext,
-> ValueRef {
let f = match ty::get(node_type).sty {
ty::ty_bare_fn(ref f) => {
assert!(f.abis.is_rust() || f.abis.is_intrinsic());
assert!(f.abi == Rust || f.abi == RustIntrinsic);
f
}
_ => fail!("expected bare rust fn or an intrinsic")
Expand Down Expand Up @@ -1997,8 +1997,8 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {

match ni.node {
ast::ForeignItemFn(..) => {
let abis = ccx.tcx.map.get_foreign_abis(id);
foreign::register_foreign_item_fn(ccx, abis, ni)
let abi = ccx.tcx.map.get_foreign_abi(id);
foreign::register_foreign_item_fn(ccx, abi, ni)
}
ast::ForeignItemStatic(..) => {
foreign::register_static(ccx, ni)
Expand Down
12 changes: 5 additions & 7 deletions src/librustc/middle/trans/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use util::ppaux::Repr;
use middle::trans::type_::Type;

use syntax::ast;
use syntax::abi::AbiSet;
use synabi = syntax::abi;
use syntax::ast_map;

pub struct MethodData {
Expand Down Expand Up @@ -363,7 +363,7 @@ pub fn trans_fn_ref_with_vtables(

match map_node {
ast_map::NodeForeignItem(_) => {
tcx.map.get_foreign_abis(def_id.node).is_intrinsic()
tcx.map.get_foreign_abi(def_id.node) == synabi::RustIntrinsic
}
_ => false
}
Expand Down Expand Up @@ -572,13 +572,11 @@ pub fn trans_call_inner<'a>(
};

let (abi, ret_ty) = match ty::get(callee_ty).sty {
ty::ty_bare_fn(ref f) => (f.abis, f.sig.output),
ty::ty_closure(ref f) => (AbiSet::Rust(), f.sig.output),
ty::ty_bare_fn(ref f) => (f.abi, f.sig.output),
ty::ty_closure(ref f) => (synabi::Rust, f.sig.output),
_ => fail!("expected bare rust fn or closure in trans_call_inner")
};
let is_rust_fn =
abi.is_rust() ||
abi.is_intrinsic();
let is_rust_fn = abi == synabi::Rust || abi == synabi::RustIntrinsic;

// Generate a location to store the result. If the user does
// not care about the result, just make a stack slot.
Expand Down
34 changes: 17 additions & 17 deletions src/librustc/middle/trans/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use middle::ty::FnSig;
use middle::ty;
use std::cmp;
use std::libc::c_uint;
use syntax::abi::{Cdecl, Aapcs, C, AbiSet, Win64};
use syntax::abi::{Cdecl, Aapcs, C, Win64, Abi};
use syntax::abi::{RustIntrinsic, Rust, Stdcall, Fastcall, System};
use syntax::codemap::Span;
use syntax::parse::token::{InternedString, special_idents};
Expand Down Expand Up @@ -73,10 +73,10 @@ struct LlvmSignature {
// Calls to external functions

pub fn llvm_calling_convention(ccx: &CrateContext,
abis: AbiSet) -> Option<CallConv> {
abi: Abi) -> Option<CallConv> {
let os = ccx.sess().targ_cfg.os;
let arch = ccx.sess().targ_cfg.arch;
abis.for_target(os, arch).map(|abi| {
abi.for_target(os, arch).map(|abi| {
match abi {
RustIntrinsic => {
// Intrinsics are emitted by monomorphic fn
Expand Down Expand Up @@ -180,27 +180,27 @@ pub fn register_static(ccx: &CrateContext,
}
}

pub fn register_foreign_item_fn(ccx: &CrateContext, abis: AbiSet,
pub fn register_foreign_item_fn(ccx: &CrateContext, abi: Abi,
foreign_item: &ast::ForeignItem) -> ValueRef {
/*!
* Registers a foreign function found in a library.
* Just adds a LLVM global.
*/

debug!("register_foreign_item_fn(abis={}, \
debug!("register_foreign_item_fn(abi={}, \
path={}, \
foreign_item.id={})",
abis.repr(ccx.tcx()),
abi.repr(ccx.tcx()),
ccx.tcx.map.path_to_str(foreign_item.id),
foreign_item.id);

let cc = match llvm_calling_convention(ccx, abis) {
let cc = match llvm_calling_convention(ccx, abi) {
Some(cc) => cc,
None => {
ccx.sess().span_fatal(foreign_item.span,
format!("ABI `{}` has no suitable calling convention \
for target architecture",
abis.user_string(ccx.tcx())));
abi.user_string(ccx.tcx())));
}
};

Expand Down Expand Up @@ -263,8 +263,8 @@ pub fn trans_native_call<'a>(
ccx.tn.val_to_str(llfn),
ccx.tn.val_to_str(llretptr));

let (fn_abis, fn_sig) = match ty::get(callee_ty).sty {
ty::ty_bare_fn(ref fn_ty) => (fn_ty.abis, fn_ty.sig.clone()),
let (fn_abi, fn_sig) = match ty::get(callee_ty).sty {
ty::ty_bare_fn(ref fn_ty) => (fn_ty.abi, fn_ty.sig.clone()),
_ => ccx.sess().bug("trans_native_call called on non-function type")
};
let llsig = foreign_signature(ccx, &fn_sig, passed_arg_tys.as_slice());
Expand Down Expand Up @@ -354,14 +354,14 @@ pub fn trans_native_call<'a>(
llargs_foreign.push(llarg_foreign);
}

let cc = match llvm_calling_convention(ccx, fn_abis) {
let cc = match llvm_calling_convention(ccx, fn_abi) {
Some(cc) => cc,
None => {
// FIXME(#8357) We really ought to report a span here
ccx.sess().fatal(
format!("ABI string `{}` has no suitable ABI \
for target architecture",
fn_abis.user_string(ccx.tcx())));
fn_abi.user_string(ccx.tcx())));
}
};

Expand Down Expand Up @@ -435,9 +435,9 @@ pub fn trans_foreign_mod(ccx: &CrateContext, foreign_mod: &ast::ForeignMod) {
for &foreign_item in foreign_mod.items.iter() {
match foreign_item.node {
ast::ForeignItemFn(..) => {
let abis = foreign_mod.abis;
if !(abis.is_rust() || abis.is_intrinsic()) {
register_foreign_item_fn(ccx, abis, foreign_item);
match foreign_mod.abi {
Rust | RustIntrinsic => {}
abi => { register_foreign_item_fn(ccx, abi, foreign_item); }
}
}
_ => {}
Expand Down Expand Up @@ -486,7 +486,7 @@ pub fn register_rust_fn_with_foreign_abi(ccx: &CrateContext,
let t = ty::node_id_to_type(ccx.tcx(), node_id);
let (cconv, output) = match ty::get(t).sty {
ty::ty_bare_fn(ref fn_ty) => {
let c = llvm_calling_convention(ccx, fn_ty.abis);
let c = llvm_calling_convention(ccx, fn_ty.abi);
(c.unwrap_or(lib::llvm::CCallConv), fn_ty.sig.output)
}
_ => fail!("expected bare fn in register_rust_fn_with_foreign_abi")
Expand Down Expand Up @@ -534,7 +534,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
// normal Rust function. This will be the type of the wrappee fn.
let f = match ty::get(t).sty {
ty::ty_bare_fn(ref f) => {
assert!(!f.abis.is_rust() && !f.abis.is_intrinsic());
assert!(f.abi != Rust && f.abi != RustIntrinsic);
f
}
_ => {
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/trans/meth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use util::common::indenter;
use util::ppaux::Repr;

use std::c_str::ToCStr;
use syntax::abi::Rust;
use syntax::parse::token;
use syntax::{ast, ast_map, visit};

Expand Down Expand Up @@ -393,7 +394,7 @@ pub fn trans_trait_callee_from_llval<'a>(bcx: &'a Block<'a>,
debug!("(translating trait callee) loading method");
// Replace the self type (&Self or ~Self) with an opaque pointer.
let llcallee_ty = match ty::get(callee_ty).sty {
ty::ty_bare_fn(ref f) if f.abis.is_rust() => {
ty::ty_bare_fn(ref f) if f.abi == Rust => {
type_of_rust_fn(ccx, true, f.sig.inputs.slice_from(1), f.sig.output)
}
_ => {
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/middle/trans/monomorphize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use middle::ty;
use middle::typeck;
use util::ppaux::Repr;

use syntax::abi;
use syntax::ast;
use syntax::ast_map;
use syntax::ast_util::local_def;
Expand Down Expand Up @@ -99,7 +100,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,

match map_node {
ast_map::NodeForeignItem(_) => {
if !ccx.tcx.map.get_foreign_abis(fn_id.node).is_intrinsic() {
if ccx.tcx.map.get_foreign_abi(fn_id.node) != abi::RustIntrinsic {
// Foreign externs don't have to be monomorphized.
return (get_item_val(ccx, fn_id.node), true);
}
Expand Down Expand Up @@ -150,7 +151,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,

let f = match ty::get(mono_ty).sty {
ty::ty_bare_fn(ref f) => {
assert!(f.abis.is_rust() || f.abis.is_intrinsic());
assert!(f.abi == abi::Rust || f.abi == abi::RustIntrinsic);
f
}
_ => fail!("expected bare rust fn or an intrinsic")
Expand Down
Loading