Skip to content

Commit 5ca8355

Browse files
lhtmarijnh
authored andcommitted
rustc: Remove abi from ast::native_mod
1 parent 7a7f060 commit 5ca8355

File tree

16 files changed

+126
-128
lines changed

16 files changed

+126
-128
lines changed

src/comp/front/attr.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Functions dealing with attributes and meta_items
22

3-
import std::{vec, map, option};
3+
import std::{either, vec, map, option};
44
import syntax::{ast, ast_util};
55
import driver::session;
66

@@ -24,6 +24,7 @@ export mk_name_value_item;
2424
export mk_list_item;
2525
export mk_word_item;
2626
export mk_attr;
27+
export native_abi;
2728

2829
// From a list of crate attributes get only the meta_items that impact crate
2930
// linkage
@@ -199,6 +200,26 @@ fn require_unique_names(sess: session::session, metas: [@ast::meta_item]) {
199200
}
200201
}
201202

203+
fn native_abi(attrs: [ast::attribute]) -> either::t<str, ast::native_abi> {
204+
ret alt attr::get_meta_item_value_str_by_name(attrs, "abi") {
205+
option::none. {
206+
either::right(ast::native_abi_cdecl)
207+
}
208+
option::some("rust-intrinsic") {
209+
either::right(ast::native_abi_rust_intrinsic)
210+
}
211+
option::some("cdecl") {
212+
either::right(ast::native_abi_cdecl)
213+
}
214+
option::some("stdcall") {
215+
either::right(ast::native_abi_stdcall)
216+
}
217+
option::some(t) {
218+
either::left("unsupported abi: " + t)
219+
}
220+
};
221+
}
222+
202223
fn span<copy T>(item: T) -> ast::spanned<T> {
203224
ret {node: item, span: ast_util::dummy_sp()};
204225
}

src/comp/front/config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ fn fold_native_mod(cfg: ast::crate_cfg, nm: ast::native_mod,
4545
fld: fold::ast_fold) -> ast::native_mod {
4646
let filter = bind filter_native_item(cfg, _);
4747
let filtered_items = vec::filter_map(filter, nm.items);
48-
ret {abi: nm.abi,
49-
view_items: vec::map(fld.fold_view_item, nm.view_items),
48+
ret {view_items: vec::map(fld.fold_view_item, nm.view_items),
5049
items: filtered_items};
5150
}
5251

src/comp/metadata/creader.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import front::attr;
77
import syntax::visit;
88
import syntax::codemap::span;
99
import util::{filesearch};
10-
import std::{vec, str, fs, io, option};
10+
import std::{either, vec, str, fs, io, option};
1111
import std::option::{none, some};
1212
import std::map::{hashmap, new_int_hash};
1313
import syntax::print::pprust;
@@ -49,9 +49,12 @@ fn visit_view_item(e: env, i: @ast::view_item) {
4949
fn visit_item(e: env, i: @ast::item) {
5050
alt i.node {
5151
ast::item_native_mod(m) {
52-
if m.abi != ast::native_abi_cdecl &&
53-
m.abi != ast::native_abi_stdcall {
54-
ret;
52+
alt attr::native_abi(i.attrs) {
53+
either::right(abi) {
54+
if abi != ast::native_abi_cdecl &&
55+
abi != ast::native_abi_stdcall { ret; }
56+
}
57+
either::left(msg) { e.sess.span_fatal(i.span, msg); }
5558
}
5659
let cstore = e.sess.get_cstore();
5760
let native_name = i.ident;

src/comp/metadata/tydecode.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,8 @@ fn parse_ty(st: @pstate, sd: str_def) -> ty::t {
257257
func.cs);
258258
}
259259
'N' {
260-
let abi;
261-
alt next(st) as char {
262-
'i' { abi = ast::native_abi_rust_intrinsic; }
263-
'C' { abi = ast::native_abi_cdecl; }
264-
'S' { abi = ast::native_abi_stdcall; }
265-
}
266260
let func = parse_ty_fn(st, sd);
267-
ret ty::mk_native_fn(st.tcx, abi, func.args, func.ty);
261+
ret ty::mk_native_fn(st.tcx, func.args, func.ty);
268262
}
269263
'O' {
270264
assert (next(st) as char == '[');

src/comp/metadata/tyencode.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,8 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
138138
enc_proto(w, proto);
139139
enc_ty_fn(w, cx, args, out, cf, constrs);
140140
}
141-
ty::ty_native_fn(abi, args, out) {
141+
ty::ty_native_fn(args, out) {
142142
w.write_char('N');
143-
alt abi {
144-
native_abi_rust_intrinsic. { w.write_char('i'); }
145-
native_abi_cdecl. { w.write_char('C'); }
146-
native_abi_stdcall. { w.write_char('S'); }
147-
}
148143
enc_ty_fn(w, cx, args, out, return_val, []);
149144
}
150145
ty::ty_obj(methods) {

src/comp/middle/alias.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ fn copy_is_expensive(tcx: ty::ctxt, ty: ty::t) -> bool {
651651
ty::ty_ptr(_) { 1u }
652652
ty::ty_box(_) { 3u }
653653
ty::ty_constr(t, _) | ty::ty_res(_, t, _) { score_ty(tcx, t) }
654-
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _, _) |
654+
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _) |
655655
ty::ty_obj(_) { 4u }
656656
ty::ty_str. | ty::ty_vec(_) | ty::ty_param(_, _) { 50u }
657657
ty::ty_uniq(mt) { 1u + score_ty(tcx, mt.ty) }

src/comp/middle/gc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fn type_is_gc_relevant(cx: ty::ctxt, ty: ty::t) -> bool {
151151

152152

153153
ty::ty_box(_) | ty::ty_uniq(_) | ty::ty_fn(_, _, _, _, _) |
154-
ty::ty_native_fn(_, _, _) | ty::ty_obj(_) | ty::ty_param(_, _) |
154+
ty::ty_native_fn(_, _) | ty::ty_obj(_) | ty::ty_param(_, _) |
155155
ty::ty_res(_, _, _) {
156156
ret true;
157157
}

src/comp/middle/shape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint],
419419
ty::ty_fn(_, _, _, _, _) {
420420
s += [shape_fn];
421421
}
422-
ty::ty_native_fn(_, _, _) { s += [shape_u32]; }
422+
ty::ty_native_fn(_, _) { s += [shape_u32]; }
423423
ty::ty_obj(_) { s += [shape_obj]; }
424424

425425

src/comp/middle/trans.rs

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// pcwalton). You can, instead, find out its TypeRef by calling val_ty,
1313
// but many TypeRefs correspond to one ty::t; for instance, tup(int, int,
1414
// int) and rec(x=int, y=int, z=int) will have the same TypeRef.
15-
import std::{str, uint, map, option, time, vec};
15+
import std::{either, str, uint, map, option, time, vec};
1616
import std::map::hashmap;
1717
import std::map::{new_int_hash, new_str_hash};
1818
import std::option::{some, none};
@@ -182,7 +182,7 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
182182
check returns_non_ty_var(cx, t);
183183
T_fn_pair(cx, type_of_fn_from_ty(cx, sp, t, 0u))
184184
}
185-
ty::ty_native_fn(abi, args, out) {
185+
ty::ty_native_fn(args, out) {
186186
let nft = native_fn_wrapper_type(cx, sp, 0u, t);
187187
T_fn_pair(cx, nft)
188188
}
@@ -235,7 +235,7 @@ fn type_of_ty_param_kinds_and_ty(lcx: @local_ctxt, sp: span,
235235
let cx = lcx.ccx;
236236
let t = tpt.ty;
237237
alt ty::struct(cx.tcx, t) {
238-
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _, _) {
238+
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _) {
239239
check returns_non_ty_var(cx, t);
240240
ret type_of_fn_from_ty(cx, sp, t, std::vec::len(tpt.kinds));
241241
}
@@ -1727,7 +1727,7 @@ fn iter_structural_ty(cx: @block_ctxt, av: ValueRef, t: ty::t,
17271727
}
17281728
ret next_cx;
17291729
}
1730-
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _, _) {
1730+
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _) {
17311731
let box_cell_a = GEPi(cx, av, [0, abi::fn_field_box]);
17321732
ret iter_boxpp(cx, box_cell_a, f);
17331733
}
@@ -5305,7 +5305,7 @@ fn c_stack_tys(ccx: @crate_ctxt,
53055305
sp: span,
53065306
id: ast::node_id) -> @c_stack_tys {
53075307
alt ty::struct(ccx.tcx, ty::node_id_to_type(ccx.tcx, id)) {
5308-
ty::ty_native_fn(_, arg_tys, ret_ty) {
5308+
ty::ty_native_fn(arg_tys, ret_ty) {
53095309
let tcx = ccx.tcx;
53105310
let llargtys = type_of_explicit_args(ccx, sp, arg_tys);
53115311
check non_ty_var(ccx, ret_ty); // NDM does this truly hold?
@@ -5365,7 +5365,8 @@ fn c_stack_tys(ccx: @crate_ctxt,
53655365
// stack pointer appropriately to avoid a round of copies. (In fact, the shim
53665366
// function itself is unnecessary). We used to do this, in fact, and will
53675367
// perhaps do so in the future.
5368-
fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod) {
5368+
fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
5369+
abi: ast::native_abi) {
53695370
fn build_shim_fn(lcx: @local_ctxt,
53705371
native_item: @ast::native_item,
53715372
tys: @c_stack_tys,
@@ -5448,7 +5449,7 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod) {
54485449

54495450
let ccx = lcx_ccx(lcx);
54505451
let cc: uint = lib::llvm::LLVMCCallConv;
5451-
alt native_mod.abi {
5452+
alt abi {
54525453
ast::native_abi_rust_intrinsic. { ret; }
54535454
ast::native_abi_cdecl. { cc = lib::llvm::LLVMCCallConv; }
54545455
ast::native_abi_stdcall. { cc = lib::llvm::LLVMX86StdcallCallConv; }
@@ -5529,13 +5530,16 @@ fn trans_item(cx: @local_ctxt, item: ast::item) {
55295530
}
55305531
ast::item_const(_, expr) { trans_const(cx.ccx, expr, item.id); }
55315532
ast::item_native_mod(native_mod) {
5532-
trans_native_mod(cx, native_mod);
5533+
let abi = alt attr::native_abi(item.attrs) {
5534+
either::right(abi_) { abi_ }
5535+
either::left(msg) { cx.ccx.sess.span_fatal(item.span, msg) }
5536+
};
5537+
trans_native_mod(cx, native_mod, abi);
55335538
}
55345539
_ {/* fall through */ }
55355540
}
55365541
}
55375542

5538-
55395543
// Translate a module. Doing this amounts to translating the items in the
55405544
// module; there ends up being no artifact (aside from linkage names) of
55415545
// separate modules in the compiled program. That's because modules exist
@@ -5697,7 +5701,7 @@ fn native_fn_ty_param_count(cx: @crate_ctxt, id: ast::node_id) -> uint {
56975701
fn native_fn_wrapper_type(cx: @crate_ctxt, sp: span, ty_param_count: uint,
56985702
x: ty::t) -> TypeRef {
56995703
alt ty::struct(cx.tcx, x) {
5700-
ty::ty_native_fn(abi, args, out) {
5704+
ty::ty_native_fn(args, out) {
57015705
check non_ty_var(cx, out);
57025706
ret type_of_fn(cx, sp, false, false, args, out, ty_param_count);
57035707
}
@@ -5719,18 +5723,32 @@ fn link_name(i: @ast::native_item) -> str {
57195723
}
57205724
}
57215725

5722-
fn collect_native_item(ccx: @crate_ctxt, i: @ast::native_item, &&pt: [str],
5726+
fn collect_native_item(ccx: @crate_ctxt,
5727+
abi: @mutable option::t<ast::native_abi>,
5728+
i: @ast::native_item,
5729+
&&pt: [str],
57235730
_v: vt<[str]>) {
57245731
alt i.node {
57255732
ast::native_item_fn(_, tps) {
57265733
if !ccx.obj_methods.contains_key(i.id) {
57275734
let sp = i.span;
57285735
let id = i.id;
57295736
let node_type = node_id_type(ccx, id);
5730-
// FIXME NDM abi should come from attr
5731-
let abi = ty::ty_fn_abi(ccx.tcx, node_type);
5732-
5733-
alt abi {
5737+
let fn_abi =
5738+
alt attr::get_meta_item_value_str_by_name(i.attrs, "abi") {
5739+
option::none. {
5740+
// if abi isn't specified for this function, inherit from
5741+
// its enclosing native module
5742+
option::get(*abi)
5743+
}
5744+
_ {
5745+
alt attr::native_abi(i.attrs) {
5746+
either::right(abi_) { abi_ }
5747+
either::left(msg) { ccx.sess.span_fatal(i.span, msg) }
5748+
}
5749+
}
5750+
};
5751+
alt fn_abi {
57345752
ast::native_abi_rust_intrinsic. {
57355753
// For intrinsics: link the function directly to the intrinsic
57365754
// function itself.
@@ -5760,9 +5778,8 @@ fn collect_native_item(ccx: @crate_ctxt, i: @ast::native_item, &&pt: [str],
57605778
}
57615779
}
57625780

5763-
fn collect_item_1(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
5764-
v: vt<[str]>) {
5765-
visit::visit_item(i, pt + item_path(i), v);
5781+
fn collect_item_1(ccx: @crate_ctxt, abi: @mutable option::t<ast::native_abi>,
5782+
i: @ast::item, &&pt: [str], v: vt<[str]>) {
57665783
alt i.node {
57675784
ast::item_const(_, _) {
57685785
let typ = node_id_type(ccx, i.id);
@@ -5778,8 +5795,18 @@ fn collect_item_1(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
57785795
ccx.item_symbols.insert(i.id, s);
57795796
ccx.consts.insert(i.id, g);
57805797
}
5798+
ast::item_native_mod(native_mod) {
5799+
// Propagate the native ABI down to collect_native_item(),
5800+
alt attr::native_abi(i.attrs) {
5801+
either::left(msg) { ccx.sess.span_fatal(i.span, msg); }
5802+
either::right(abi_) {
5803+
*abi = option::some(abi_);
5804+
}
5805+
}
5806+
}
57815807
_ { }
57825808
}
5809+
visit::visit_item(i, pt + item_path(i), v);
57835810
}
57845811

57855812
fn collect_item_2(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
@@ -5814,10 +5841,11 @@ fn collect_item_2(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
58145841
}
58155842

58165843
fn collect_items(ccx: @crate_ctxt, crate: @ast::crate) {
5844+
let abi = @mutable none::<ast::native_abi>;
58175845
let visitor0 = visit::default_visitor();
58185846
let visitor1 =
5819-
@{visit_native_item: bind collect_native_item(ccx, _, _, _),
5820-
visit_item: bind collect_item_1(ccx, _, _, _) with *visitor0};
5847+
@{visit_native_item: bind collect_native_item(ccx, abi, _, _, _),
5848+
visit_item: bind collect_item_1(ccx, abi, _, _, _) with *visitor0};
58215849
let visitor2 =
58225850
@{visit_item: bind collect_item_2(ccx, _, _, _) with *visitor0};
58235851
visit::visit_crate(*crate, [], visit::mk_vt(visitor1));

src/comp/middle/tstate/auxiliary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ fn callee_modes(fcx: fn_ctxt, callee: node_id) -> [ty::mode] {
10701070
ty::type_autoderef(fcx.ccx.tcx,
10711071
ty::node_id_to_type(fcx.ccx.tcx, callee));
10721072
alt ty::struct(fcx.ccx.tcx, ty) {
1073-
ty::ty_fn(_, args, _, _, _) | ty::ty_native_fn(_, args, _) {
1073+
ty::ty_fn(_, args, _, _, _) | ty::ty_native_fn(args, _) {
10741074
let modes = [];
10751075
for arg: ty::arg in args { modes += [arg.mode]; }
10761076
ret modes;

0 commit comments

Comments
 (0)