Skip to content

Commit 5aedabf

Browse files
committed
rustc: Run all intrinsics through the monomorphiser
Intrinsics always want to be inlined.
1 parent bb348cc commit 5aedabf

File tree

3 files changed

+22
-39
lines changed

3 files changed

+22
-39
lines changed

src/rustc/middle/trans/base.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,7 +2504,6 @@ fn lval_static_fn_inner(bcx: block, fn_id: ast::def_id, id: ast::node_id,
25042504

25052505
// Check whether this fn has an inlined copy and, if so, redirect fn_id to
25062506
// the local id of the inlined copy.
2507-
let original_crate = fn_id.crate;
25082507
let fn_id = if fn_id.crate != ast::local_crate {
25092508
maybe_instantiate_inline(ccx, fn_id)
25102509
} else { fn_id };
@@ -2513,27 +2512,27 @@ fn lval_static_fn_inner(bcx: block, fn_id: ast::def_id, id: ast::node_id,
25132512
let local_with_type_params =
25142513
fn_id.crate == ast::local_crate && tys.len() > 0u;
25152514

2516-
// Rust intrinsic functions should always be monomorphised
2517-
let inlined_rust_intrinsic = {
2518-
if fn_id.crate == ast::local_crate
2519-
&& original_crate != ast::local_crate {
2515+
// Intrinsic functions should always be monomorphised. In particular,
2516+
// if we see an intrinsic that is inlined from a different crate, we
2517+
// want to reemit the intrinsic instead of trying to call it in the
2518+
// other crate.
2519+
let rust_intrinsic = if fn_id.crate == ast::local_crate {
25202520

2521-
let map_node = session::expect(
2522-
ccx.sess,
2523-
ccx.tcx.items.find(fn_id.node),
2524-
|| fmt!("inlined item should be in ast map"));
2521+
let map_node = session::expect(
2522+
ccx.sess,
2523+
ccx.tcx.items.find(fn_id.node),
2524+
|| fmt!("local item should be in ast map"));
25252525

2526-
match map_node {
2527-
ast_map::node_foreign_item(
2528-
_, ast::foreign_abi_rust_intrinsic, _) => true,
2529-
_ => false
2530-
}
2531-
} else {
2532-
false
2526+
match map_node {
2527+
ast_map::node_foreign_item(
2528+
_, ast::foreign_abi_rust_intrinsic, _) => true,
2529+
_ => false
25332530
}
2531+
} else {
2532+
false
25342533
};
25352534

2536-
local_with_type_params || inlined_rust_intrinsic
2535+
local_with_type_params || rust_intrinsic
25372536
};
25382537

25392538
if must_monomorphise {

src/rustc/middle/trans/foreign.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ fn trans_foreign_mod(ccx: @crate_ctxt,
759759

760760
for vec::each(foreign_mod.items) |foreign_item| {
761761
match foreign_item.node {
762-
ast::foreign_item_fn(_, _, typarams) => {
762+
ast::foreign_item_fn(*) => {
763763
let id = foreign_item.id;
764764
if abi != ast::foreign_abi_rust_intrinsic {
765765
let llwrapfn = get_item_val(ccx, id);
@@ -772,25 +772,7 @@ fn trans_foreign_mod(ccx: @crate_ctxt,
772772
build_wrap_fn(ccx, tys, llshimfn, llwrapfn);
773773
}
774774
} else {
775-
// Intrinsics with type parameters are emitted by
776-
// monomorphic_fn, but ones without are emitted here
777-
if typarams.is_empty() {
778-
let llwrapfn = get_item_val(ccx, id);
779-
let path = match ccx.tcx.items.find(id) {
780-
Some(ast_map::node_foreign_item(_, _, pt)) => pt,
781-
_ => {
782-
ccx.sess.span_bug(foreign_item.span,
783-
~"can't find intrinsic path")
784-
}
785-
};
786-
let psubsts = {
787-
tys: ~[],
788-
vtables: None,
789-
bounds: @~[]
790-
};
791-
trans_intrinsic(ccx, llwrapfn, foreign_item,
792-
*path, psubsts, None);
793-
}
775+
// Intrinsics are emitted by monomorphic fn
794776
}
795777
}
796778
ast::foreign_item_const(*) => {

src/rustc/middle/trans/type_use.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,13 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
9494
~"atomic_xchg_acq" | ~"atomic_xadd_acq" | ~"atomic_xsub_acq" |
9595
~"atomic_xchg_rel" | ~"atomic_xadd_rel" | ~"atomic_xsub_rel" =>
9696
{ 0u }
97-
~"visit_tydesc" | ~"forget" | ~"addr_of" => {
97+
~"visit_tydesc" | ~"forget" | ~"addr_of" |
98+
~"frame_address" | ~"morestack_addr" => {
9899
0u
99100
}
100101
// would be cool to make these an enum instead of strings!
101-
_ => fail ~"unknown intrinsic in type_use"
102+
_ => fail fmt!("unknown intrinsic in type_use %?",
103+
cx.ccx.sess.str_of(i.ident))
102104
};
103105
for uint::range(0u, n_tps) |n| { cx.uses[n] |= flags;}
104106
}

0 commit comments

Comments
 (0)