Skip to content

rustc: Remove abi from ast::native_mod #1205

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

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
23 changes: 22 additions & 1 deletion src/comp/front/attr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Functions dealing with attributes and meta_items

import std::{vec, map, option};
import std::{either, vec, map, option};
import syntax::{ast, ast_util};
import driver::session;

Expand All @@ -24,6 +24,7 @@ export mk_name_value_item;
export mk_list_item;
export mk_word_item;
export mk_attr;
export native_abi;

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

fn native_abi(attrs: [ast::attribute]) -> either::t<str, ast::native_abi> {
ret alt attr::get_meta_item_value_str_by_name(attrs, "abi") {
option::none. {
either::right(ast::native_abi_cdecl)
}
option::some("rust-intrinsic") {
either::right(ast::native_abi_rust_intrinsic)
}
option::some("cdecl") {
either::right(ast::native_abi_cdecl)
}
option::some("stdcall") {
either::right(ast::native_abi_stdcall)
}
option::some(t) {
either::left("unsupported abi: " + t)
}
};
}

fn span<copy T>(item: T) -> ast::spanned<T> {
ret {node: item, span: ast_util::dummy_sp()};
}
Expand Down
3 changes: 1 addition & 2 deletions src/comp/front/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ fn fold_native_mod(cfg: ast::crate_cfg, nm: ast::native_mod,
fld: fold::ast_fold) -> ast::native_mod {
let filter = bind filter_native_item(cfg, _);
let filtered_items = vec::filter_map(filter, nm.items);
ret {abi: nm.abi,
view_items: vec::map(fld.fold_view_item, nm.view_items),
ret {view_items: vec::map(fld.fold_view_item, nm.view_items),
items: filtered_items};
}

Expand Down
11 changes: 7 additions & 4 deletions src/comp/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import front::attr;
import syntax::visit;
import syntax::codemap::span;
import util::{filesearch};
import std::{vec, str, fs, io, option};
import std::{either, vec, str, fs, io, option};
import std::option::{none, some};
import std::map::{hashmap, new_int_hash};
import syntax::print::pprust;
Expand Down Expand Up @@ -49,9 +49,12 @@ fn visit_view_item(e: env, i: @ast::view_item) {
fn visit_item(e: env, i: @ast::item) {
alt i.node {
ast::item_native_mod(m) {
if m.abi != ast::native_abi_cdecl &&
m.abi != ast::native_abi_stdcall {
ret;
alt attr::native_abi(i.attrs) {
either::right(abi) {
if abi != ast::native_abi_cdecl &&
abi != ast::native_abi_stdcall { ret; }
}
either::left(msg) { e.sess.span_fatal(i.span, msg); }
}
let cstore = e.sess.get_cstore();
let native_name = i.ident;
Expand Down
8 changes: 1 addition & 7 deletions src/comp/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,8 @@ fn parse_ty(st: @pstate, sd: str_def) -> ty::t {
func.cs);
}
'N' {
let abi;
alt next(st) as char {
'i' { abi = ast::native_abi_rust_intrinsic; }
'C' { abi = ast::native_abi_cdecl; }
'S' { abi = ast::native_abi_stdcall; }
}
let func = parse_ty_fn(st, sd);
ret ty::mk_native_fn(st.tcx, abi, func.args, func.ty);
ret ty::mk_native_fn(st.tcx, func.args, func.ty);
}
'O' {
assert (next(st) as char == '[');
Expand Down
7 changes: 1 addition & 6 deletions src/comp/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,8 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
enc_proto(w, proto);
enc_ty_fn(w, cx, args, out, cf, constrs);
}
ty::ty_native_fn(abi, args, out) {
ty::ty_native_fn(args, out) {
w.write_char('N');
alt abi {
native_abi_rust_intrinsic. { w.write_char('i'); }
native_abi_cdecl. { w.write_char('C'); }
native_abi_stdcall. { w.write_char('S'); }
}
enc_ty_fn(w, cx, args, out, return_val, []);
}
ty::ty_obj(methods) {
Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ fn copy_is_expensive(tcx: ty::ctxt, ty: ty::t) -> bool {
ty::ty_ptr(_) { 1u }
ty::ty_box(_) { 3u }
ty::ty_constr(t, _) | ty::ty_res(_, t, _) { score_ty(tcx, t) }
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _, _) |
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _) |
ty::ty_obj(_) { 4u }
ty::ty_str. | ty::ty_vec(_) | ty::ty_param(_, _) { 50u }
ty::ty_uniq(mt) { 1u + score_ty(tcx, mt.ty) }
Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn type_is_gc_relevant(cx: ty::ctxt, ty: ty::t) -> bool {


ty::ty_box(_) | ty::ty_uniq(_) | ty::ty_fn(_, _, _, _, _) |
ty::ty_native_fn(_, _, _) | ty::ty_obj(_) | ty::ty_param(_, _) |
ty::ty_native_fn(_, _) | ty::ty_obj(_) | ty::ty_param(_, _) |
ty::ty_res(_, _, _) {
ret true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint],
ty::ty_fn(_, _, _, _, _) {
s += [shape_fn];
}
ty::ty_native_fn(_, _, _) { s += [shape_u32]; }
ty::ty_native_fn(_, _) { s += [shape_u32]; }
ty::ty_obj(_) { s += [shape_obj]; }


Expand Down
68 changes: 48 additions & 20 deletions src/comp/middle/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// pcwalton). You can, instead, find out its TypeRef by calling val_ty,
// but many TypeRefs correspond to one ty::t; for instance, tup(int, int,
// int) and rec(x=int, y=int, z=int) will have the same TypeRef.
import std::{str, uint, map, option, time, vec};
import std::{either, str, uint, map, option, time, vec};
import std::map::hashmap;
import std::map::{new_int_hash, new_str_hash};
import std::option::{some, none};
Expand Down Expand Up @@ -182,7 +182,7 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
check returns_non_ty_var(cx, t);
T_fn_pair(cx, type_of_fn_from_ty(cx, sp, t, 0u))
}
ty::ty_native_fn(abi, args, out) {
ty::ty_native_fn(args, out) {
let nft = native_fn_wrapper_type(cx, sp, 0u, t);
T_fn_pair(cx, nft)
}
Expand Down Expand Up @@ -235,7 +235,7 @@ fn type_of_ty_param_kinds_and_ty(lcx: @local_ctxt, sp: span,
let cx = lcx.ccx;
let t = tpt.ty;
alt ty::struct(cx.tcx, t) {
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _, _) {
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _) {
check returns_non_ty_var(cx, t);
ret type_of_fn_from_ty(cx, sp, t, std::vec::len(tpt.kinds));
}
Expand Down Expand Up @@ -1727,7 +1727,7 @@ fn iter_structural_ty(cx: @block_ctxt, av: ValueRef, t: ty::t,
}
ret next_cx;
}
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _, _) {
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _) {
let box_cell_a = GEPi(cx, av, [0, abi::fn_field_box]);
ret iter_boxpp(cx, box_cell_a, f);
}
Expand Down Expand Up @@ -5305,7 +5305,7 @@ fn c_stack_tys(ccx: @crate_ctxt,
sp: span,
id: ast::node_id) -> @c_stack_tys {
alt ty::struct(ccx.tcx, ty::node_id_to_type(ccx.tcx, id)) {
ty::ty_native_fn(_, arg_tys, ret_ty) {
ty::ty_native_fn(arg_tys, ret_ty) {
let tcx = ccx.tcx;
let llargtys = type_of_explicit_args(ccx, sp, arg_tys);
check non_ty_var(ccx, ret_ty); // NDM does this truly hold?
Expand Down Expand Up @@ -5365,7 +5365,8 @@ fn c_stack_tys(ccx: @crate_ctxt,
// stack pointer appropriately to avoid a round of copies. (In fact, the shim
// function itself is unnecessary). We used to do this, in fact, and will
// perhaps do so in the future.
fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod) {
fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
abi: ast::native_abi) {
fn build_shim_fn(lcx: @local_ctxt,
native_item: @ast::native_item,
tys: @c_stack_tys,
Expand Down Expand Up @@ -5448,7 +5449,7 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod) {

let ccx = lcx_ccx(lcx);
let cc: uint = lib::llvm::LLVMCCallConv;
alt native_mod.abi {
alt abi {
ast::native_abi_rust_intrinsic. { ret; }
ast::native_abi_cdecl. { cc = lib::llvm::LLVMCCallConv; }
ast::native_abi_stdcall. { cc = lib::llvm::LLVMX86StdcallCallConv; }
Expand Down Expand Up @@ -5529,13 +5530,16 @@ fn trans_item(cx: @local_ctxt, item: ast::item) {
}
ast::item_const(_, expr) { trans_const(cx.ccx, expr, item.id); }
ast::item_native_mod(native_mod) {
trans_native_mod(cx, native_mod);
let abi = alt attr::native_abi(item.attrs) {
either::right(abi_) { abi_ }
either::left(msg) { cx.ccx.sess.span_fatal(item.span, msg) }
};
trans_native_mod(cx, native_mod, abi);
}
_ {/* fall through */ }
}
}


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

fn collect_native_item(ccx: @crate_ctxt, i: @ast::native_item, &&pt: [str],
fn collect_native_item(ccx: @crate_ctxt,
abi: @mutable option::t<ast::native_abi>,
i: @ast::native_item,
&&pt: [str],
_v: vt<[str]>) {
alt i.node {
ast::native_item_fn(_, tps) {
if !ccx.obj_methods.contains_key(i.id) {
let sp = i.span;
let id = i.id;
let node_type = node_id_type(ccx, id);
// FIXME NDM abi should come from attr
let abi = ty::ty_fn_abi(ccx.tcx, node_type);

alt abi {
let fn_abi =
alt attr::get_meta_item_value_str_by_name(i.attrs, "abi") {
option::none. {
// if abi isn't specified for this function, inherit from
// its enclosing native module
option::get(*abi)
}
_ {
alt attr::native_abi(i.attrs) {
either::right(abi_) { abi_ }
either::left(msg) { ccx.sess.span_fatal(i.span, msg) }
}
}
};
alt fn_abi {
ast::native_abi_rust_intrinsic. {
// For intrinsics: link the function directly to the intrinsic
// function itself.
Expand Down Expand Up @@ -5760,9 +5778,8 @@ fn collect_native_item(ccx: @crate_ctxt, i: @ast::native_item, &&pt: [str],
}
}

fn collect_item_1(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
v: vt<[str]>) {
visit::visit_item(i, pt + item_path(i), v);
fn collect_item_1(ccx: @crate_ctxt, abi: @mutable option::t<ast::native_abi>,
i: @ast::item, &&pt: [str], v: vt<[str]>) {
alt i.node {
ast::item_const(_, _) {
let typ = node_id_type(ccx, i.id);
Expand All @@ -5778,8 +5795,18 @@ fn collect_item_1(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
ccx.item_symbols.insert(i.id, s);
ccx.consts.insert(i.id, g);
}
ast::item_native_mod(native_mod) {
// Propagate the native ABI down to collect_native_item(),
alt attr::native_abi(i.attrs) {
either::left(msg) { ccx.sess.span_fatal(i.span, msg); }
either::right(abi_) {
*abi = option::some(abi_);
}
}
}
_ { }
}
visit::visit_item(i, pt + item_path(i), v);
}

fn collect_item_2(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
Expand Down Expand Up @@ -5814,10 +5841,11 @@ fn collect_item_2(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
}

fn collect_items(ccx: @crate_ctxt, crate: @ast::crate) {
let abi = @mutable none::<ast::native_abi>;
let visitor0 = visit::default_visitor();
let visitor1 =
@{visit_native_item: bind collect_native_item(ccx, _, _, _),
visit_item: bind collect_item_1(ccx, _, _, _) with *visitor0};
@{visit_native_item: bind collect_native_item(ccx, abi, _, _, _),
visit_item: bind collect_item_1(ccx, abi, _, _, _) with *visitor0};
let visitor2 =
@{visit_item: bind collect_item_2(ccx, _, _, _) with *visitor0};
visit::visit_crate(*crate, [], visit::mk_vt(visitor1));
Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/tstate/auxiliary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ fn callee_modes(fcx: fn_ctxt, callee: node_id) -> [ty::mode] {
ty::type_autoderef(fcx.ccx.tcx,
ty::node_id_to_type(fcx.ccx.tcx, callee));
alt ty::struct(fcx.ccx.tcx, ty) {
ty::ty_fn(_, args, _, _, _) | ty::ty_native_fn(_, args, _) {
ty::ty_fn(_, args, _, _, _) | ty::ty_native_fn(args, _) {
let modes = [];
for arg: ty::arg in args { modes += [arg.mode]; }
ret modes;
Expand Down
Loading