Skip to content

Commit 2fa78cc

Browse files
committed
auto merge of #13263 : alexcrichton/rust/no-abi-set, r=cmr
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
2 parents 7bda3df + cd7b39d commit 2fa78cc

32 files changed

+204
-459
lines changed

src/librustc/front/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fn fold_foreign_mod(cx: &mut Context, nm: &ast::ForeignMod) -> ast::ForeignMod {
9090
filter_view_item(cx, a).map(|x| cx.fold_view_item(x))
9191
}).collect();
9292
ast::ForeignMod {
93-
abis: nm.abis,
93+
abi: nm.abi,
9494
view_items: filtered_view_items,
9595
items: filtered_items
9696
}

src/librustc/metadata/creader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ fn extract_crate_info(e: &Env, i: &ast::ViewItem) -> Option<CrateInfo> {
187187
fn visit_item(e: &Env, i: &ast::Item) {
188188
match i.node {
189189
ast::ItemForeignMod(ref fm) => {
190-
if fm.abis.is_rust() || fm.abis.is_intrinsic() {
190+
if fm.abi == abi::Rust || fm.abi == abi::RustIntrinsic {
191191
return;
192192
}
193193

src/librustc/metadata/encoder.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use std::hash::Hash;
3333
use std::io::MemWriter;
3434
use std::str;
3535
use collections::HashMap;
36-
use syntax::abi::AbiSet;
36+
use syntax::abi;
3737
use syntax::ast::*;
3838
use syntax::ast;
3939
use syntax::ast_map::{PathElem, PathElems};
@@ -1217,7 +1217,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
12171217
nitem: &ForeignItem,
12181218
index: @RefCell<Vec<entry<i64>> >,
12191219
path: PathElems,
1220-
abi: AbiSet) {
1220+
abi: abi::Abi) {
12211221
index.borrow_mut().push(entry {
12221222
val: nitem.id as i64,
12231223
pos: ebml_w.writer.tell().unwrap(),
@@ -1231,7 +1231,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
12311231
encode_bounds_and_type(ebml_w, ecx,
12321232
&lookup_item_type(ecx.tcx,local_def(nitem.id)));
12331233
encode_name(ebml_w, nitem.ident.name);
1234-
if abi.is_intrinsic() {
1234+
if abi == abi::RustIntrinsic {
12351235
(ecx.encode_inlined_item)(ecx, ebml_w, IIForeignRef(nitem));
12361236
} else {
12371237
encode_symbol(ecx, ebml_w, nitem.id);
@@ -1279,11 +1279,11 @@ fn my_visit_foreign_item(ni: &ForeignItem,
12791279
let mut ebml_w = unsafe {
12801280
ebml_w.unsafe_clone()
12811281
};
1282-
let abis = ecx.tcx.map.get_foreign_abis(ni.id);
1282+
let abi = ecx.tcx.map.get_foreign_abi(ni.id);
12831283
ecx.tcx.map.with_path(ni.id, |path| {
12841284
encode_info_for_foreign_item(ecx, &mut ebml_w,
12851285
ni, index,
1286-
path, abis);
1286+
path, abi);
12871287
});
12881288
}
12891289

src/librustc/metadata/tydecode.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use middle::ty;
2020

2121
use std::str;
2222
use std::uint;
23-
use syntax::abi::AbiSet;
2423
use syntax::abi;
2524
use syntax::ast;
2625
use syntax::ast::*;
@@ -460,18 +459,12 @@ fn parse_purity(c: char) -> Purity {
460459
}
461460
}
462461

463-
fn parse_abi_set(st: &mut PState) -> AbiSet {
462+
fn parse_abi_set(st: &mut PState) -> abi::Abi {
464463
assert_eq!(next(st), '[');
465-
let mut abis = AbiSet::empty();
466-
while peek(st) != ']' {
467-
scan(st, |c| c == ',', |bytes| {
468-
let abi_str = str::from_utf8(bytes).unwrap().to_owned();
469-
let abi = abi::lookup(abi_str).expect(abi_str);
470-
abis.add(abi);
471-
});
472-
}
473-
assert_eq!(next(st), ']');
474-
return abis;
464+
scan(st, |c| c == ']', |bytes| {
465+
let abi_str = str::from_utf8(bytes).unwrap().to_owned();
466+
abi::lookup(abi_str).expect(abi_str)
467+
})
475468
}
476469

477470
fn parse_onceness(c: char) -> ast::Onceness {
@@ -505,7 +498,7 @@ fn parse_bare_fn_ty(st: &mut PState, conv: conv_did) -> ty::BareFnTy {
505498
let sig = parse_sig(st, |x,y| conv(x,y));
506499
ty::BareFnTy {
507500
purity: purity,
508-
abis: abi,
501+
abi: abi,
509502
sig: sig
510503
}
511504
}

src/librustc/metadata/tyencode.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::fmt;
2323
use middle::ty::param_ty;
2424
use middle::ty;
2525

26-
use syntax::abi::AbiSet;
26+
use syntax::abi::Abi;
2727
use syntax::ast;
2828
use syntax::ast::*;
2929
use syntax::diagnostic::SpanHandler;
@@ -341,12 +341,9 @@ fn enc_purity(w: &mut MemWriter, p: Purity) {
341341
}
342342
}
343343

344-
fn enc_abi_set(w: &mut MemWriter, abis: AbiSet) {
344+
fn enc_abi(w: &mut MemWriter, abi: Abi) {
345345
mywrite!(w, "[");
346-
abis.each(|abi| {
347-
mywrite!(w, "{},", abi.name());
348-
true
349-
});
346+
mywrite!(w, "{}", abi.name());
350347
mywrite!(w, "]")
351348
}
352349

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

360357
pub fn enc_bare_fn_ty(w: &mut MemWriter, cx: &ctxt, ft: &ty::BareFnTy) {
361358
enc_purity(w, ft.purity);
362-
enc_abi_set(w, ft.abis);
359+
enc_abi(w, ft.abi);
363360
enc_fn_sig(w, cx, &ft.sig);
364361
}
365362

src/librustc/middle/lint.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ use std::u32;
5959
use std::u64;
6060
use std::u8;
6161
use collections::SmallIntMap;
62+
use syntax::abi;
6263
use syntax::ast_map;
6364
use syntax::ast_util::IdVisitingOperation;
6465
use syntax::attr::{AttrMetaMethods, AttributeMethods};
@@ -892,7 +893,7 @@ fn check_item_ctypes(cx: &Context, it: &ast::Item) {
892893
}
893894

894895
match it.node {
895-
ast::ItemForeignMod(ref nmod) if !nmod.abis.is_intrinsic() => {
896+
ast::ItemForeignMod(ref nmod) if nmod.abi != abi::RustIntrinsic => {
896897
for ni in nmod.items.iter() {
897898
match ni.node {
898899
ast::ForeignItemFn(decl, _) => check_foreign_fn(cx, decl),

src/librustc/middle/trans/base.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,8 @@ pub fn trans_external_path(ccx: &CrateContext, did: ast::DefId, t: ty::t) -> Val
872872
let name = csearch::get_symbol(&ccx.sess().cstore, did);
873873
match ty::get(t).sty {
874874
ty::ty_bare_fn(ref fn_ty) => {
875-
match fn_ty.abis.for_target(ccx.sess().targ_cfg.os,
876-
ccx.sess().targ_cfg.arch) {
875+
match fn_ty.abi.for_target(ccx.sess().targ_cfg.os,
876+
ccx.sess().targ_cfg.arch) {
877877
Some(Rust) | Some(RustIntrinsic) => {
878878
get_extern_rust_fn(ccx,
879879
fn_ty.sig.inputs.as_slice(),
@@ -882,7 +882,7 @@ pub fn trans_external_path(ccx: &CrateContext, did: ast::DefId, t: ty::t) -> Val
882882
did)
883883
}
884884
Some(..) | None => {
885-
let c = foreign::llvm_calling_convention(ccx, fn_ty.abis);
885+
let c = foreign::llvm_calling_convention(ccx, fn_ty.abi);
886886
let cconv = c.unwrap_or(lib::llvm::CCallConv);
887887
let llty = type_of_fn_from_ty(ccx, t);
888888
get_extern_fn(&mut *ccx.externs.borrow_mut(), ccx.llmod,
@@ -1659,7 +1659,7 @@ impl<'a> Visitor<()> for TransItemVisitor<'a> {
16591659
pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
16601660
let _icx = push_ctxt("trans_item");
16611661
match item.node {
1662-
ast::ItemFn(decl, purity, _abis, ref generics, body) => {
1662+
ast::ItemFn(decl, purity, _abi, ref generics, body) => {
16631663
if purity == ast::ExternFn {
16641664
let llfndecl = get_item_val(ccx, item.id);
16651665
foreign::trans_rust_fn_with_foreign_abi(
@@ -1779,7 +1779,7 @@ fn register_fn(ccx: &CrateContext,
17791779
-> ValueRef {
17801780
let f = match ty::get(node_type).sty {
17811781
ty::ty_bare_fn(ref f) => {
1782-
assert!(f.abis.is_rust() || f.abis.is_intrinsic());
1782+
assert!(f.abi == Rust || f.abi == RustIntrinsic);
17831783
f
17841784
}
17851785
_ => fail!("expected bare rust fn or an intrinsic")
@@ -2055,8 +2055,8 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
20552055

20562056
match ni.node {
20572057
ast::ForeignItemFn(..) => {
2058-
let abis = ccx.tcx.map.get_foreign_abis(id);
2059-
foreign::register_foreign_item_fn(ccx, abis, ni)
2058+
let abi = ccx.tcx.map.get_foreign_abi(id);
2059+
foreign::register_foreign_item_fn(ccx, abi, ni)
20602060
}
20612061
ast::ForeignItemStatic(..) => {
20622062
foreign::register_static(ccx, ni)

src/librustc/middle/trans/callee.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use util::ppaux::Repr;
5050
use middle::trans::type_::Type;
5151

5252
use syntax::ast;
53-
use syntax::abi::AbiSet;
53+
use synabi = syntax::abi;
5454
use syntax::ast_map;
5555

5656
pub struct MethodData {
@@ -363,7 +363,7 @@ pub fn trans_fn_ref_with_vtables(
363363

364364
match map_node {
365365
ast_map::NodeForeignItem(_) => {
366-
tcx.map.get_foreign_abis(def_id.node).is_intrinsic()
366+
tcx.map.get_foreign_abi(def_id.node) == synabi::RustIntrinsic
367367
}
368368
_ => false
369369
}
@@ -614,13 +614,11 @@ pub fn trans_call_inner<'a>(
614614
};
615615

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

625623
// Generate a location to store the result. If the user does
626624
// not care about the result, just make a stack slot.

src/librustc/middle/trans/foreign.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use middle::ty::FnSig;
2727
use middle::ty;
2828
use std::cmp;
2929
use std::libc::c_uint;
30-
use syntax::abi::{Cdecl, Aapcs, C, AbiSet, Win64};
30+
use syntax::abi::{Cdecl, Aapcs, C, Win64, Abi};
3131
use syntax::abi::{RustIntrinsic, Rust, Stdcall, Fastcall, System};
3232
use syntax::codemap::Span;
3333
use syntax::parse::token::{InternedString, special_idents};
@@ -73,10 +73,10 @@ struct LlvmSignature {
7373
// Calls to external functions
7474

7575
pub fn llvm_calling_convention(ccx: &CrateContext,
76-
abis: AbiSet) -> Option<CallConv> {
76+
abi: Abi) -> Option<CallConv> {
7777
let os = ccx.sess().targ_cfg.os;
7878
let arch = ccx.sess().targ_cfg.arch;
79-
abis.for_target(os, arch).map(|abi| {
79+
abi.for_target(os, arch).map(|abi| {
8080
match abi {
8181
RustIntrinsic => {
8282
// Intrinsics are emitted by monomorphic fn
@@ -180,27 +180,27 @@ pub fn register_static(ccx: &CrateContext,
180180
}
181181
}
182182

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

190-
debug!("register_foreign_item_fn(abis={}, \
190+
debug!("register_foreign_item_fn(abi={}, \
191191
path={}, \
192192
foreign_item.id={})",
193-
abis.repr(ccx.tcx()),
193+
abi.repr(ccx.tcx()),
194194
ccx.tcx.map.path_to_str(foreign_item.id),
195195
foreign_item.id);
196196

197-
let cc = match llvm_calling_convention(ccx, abis) {
197+
let cc = match llvm_calling_convention(ccx, abi) {
198198
Some(cc) => cc,
199199
None => {
200200
ccx.sess().span_fatal(foreign_item.span,
201201
format!("ABI `{}` has no suitable calling convention \
202202
for target architecture",
203-
abis.user_string(ccx.tcx())));
203+
abi.user_string(ccx.tcx())));
204204
}
205205
};
206206

@@ -263,8 +263,8 @@ pub fn trans_native_call<'a>(
263263
ccx.tn.val_to_str(llfn),
264264
ccx.tn.val_to_str(llretptr));
265265

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

357-
let cc = match llvm_calling_convention(ccx, fn_abis) {
357+
let cc = match llvm_calling_convention(ccx, fn_abi) {
358358
Some(cc) => cc,
359359
None => {
360360
// FIXME(#8357) We really ought to report a span here
361361
ccx.sess().fatal(
362362
format!("ABI string `{}` has no suitable ABI \
363363
for target architecture",
364-
fn_abis.user_string(ccx.tcx())));
364+
fn_abi.user_string(ccx.tcx())));
365365
}
366366
};
367367

@@ -435,9 +435,9 @@ pub fn trans_foreign_mod(ccx: &CrateContext, foreign_mod: &ast::ForeignMod) {
435435
for &foreign_item in foreign_mod.items.iter() {
436436
match foreign_item.node {
437437
ast::ForeignItemFn(..) => {
438-
let abis = foreign_mod.abis;
439-
if !(abis.is_rust() || abis.is_intrinsic()) {
440-
register_foreign_item_fn(ccx, abis, foreign_item);
438+
match foreign_mod.abi {
439+
Rust | RustIntrinsic => {}
440+
abi => { register_foreign_item_fn(ccx, abi, foreign_item); }
441441
}
442442
}
443443
_ => {}
@@ -486,7 +486,7 @@ pub fn register_rust_fn_with_foreign_abi(ccx: &CrateContext,
486486
let t = ty::node_id_to_type(ccx.tcx(), node_id);
487487
let (cconv, output) = match ty::get(t).sty {
488488
ty::ty_bare_fn(ref fn_ty) => {
489-
let c = llvm_calling_convention(ccx, fn_ty.abis);
489+
let c = llvm_calling_convention(ccx, fn_ty.abi);
490490
(c.unwrap_or(lib::llvm::CCallConv), fn_ty.sig.output)
491491
}
492492
_ => fail!("expected bare fn in register_rust_fn_with_foreign_abi")
@@ -534,7 +534,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
534534
// normal Rust function. This will be the type of the wrappee fn.
535535
let f = match ty::get(t).sty {
536536
ty::ty_bare_fn(ref f) => {
537-
assert!(!f.abis.is_rust() && !f.abis.is_intrinsic());
537+
assert!(f.abi != Rust && f.abi != RustIntrinsic);
538538
f
539539
}
540540
_ => {

src/librustc/middle/trans/meth.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use util::common::indenter;
3434
use util::ppaux::Repr;
3535

3636
use std::c_str::ToCStr;
37+
use syntax::abi::Rust;
3738
use syntax::parse::token;
3839
use syntax::{ast, ast_map, visit};
3940

@@ -409,7 +410,7 @@ pub fn trans_trait_callee_from_llval<'a>(bcx: &'a Block<'a>,
409410
debug!("(translating trait callee) loading method");
410411
// Replace the self type (&Self or ~Self) with an opaque pointer.
411412
let llcallee_ty = match ty::get(callee_ty).sty {
412-
ty::ty_bare_fn(ref f) if f.abis.is_rust() => {
413+
ty::ty_bare_fn(ref f) if f.abi == Rust => {
413414
type_of_rust_fn(ccx, true, f.sig.inputs.slice_from(1), f.sig.output)
414415
}
415416
_ => {

src/librustc/middle/trans/monomorphize.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use middle::ty;
2323
use middle::typeck;
2424
use util::ppaux::Repr;
2525

26+
use syntax::abi;
2627
use syntax::ast;
2728
use syntax::ast_map;
2829
use syntax::ast_util::local_def;
@@ -99,7 +100,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
99100

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

151152
let f = match ty::get(mono_ty).sty {
152153
ty::ty_bare_fn(ref f) => {
153-
assert!(f.abis.is_rust() || f.abis.is_intrinsic());
154+
assert!(f.abi == abi::Rust || f.abi == abi::RustIntrinsic);
154155
f
155156
}
156157
_ => fail!("expected bare rust fn or an intrinsic")

0 commit comments

Comments
 (0)