Skip to content

Commit 5f3fefc

Browse files
trans: Get rid of the last potential on-demand creation of non-closure functions.
1 parent 6717106 commit 5f3fefc

File tree

3 files changed

+11
-91
lines changed

3 files changed

+11
-91
lines changed

src/librustc_trans/base.rs

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
2626
#![allow(non_camel_case_types)]
2727

28-
pub use self::ValueOrigin::*;
29-
3028
use super::CrateTranslation;
3129
use super::ModuleTranslation;
3230

@@ -1918,37 +1916,6 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
19181916
fcx.finish(bcx, fn_cleanup_debug_loc.debug_loc());
19191917
}
19201918

1921-
/// Creates an LLVM function corresponding to a source language function.
1922-
pub fn trans_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
1923-
decl: &hir::FnDecl,
1924-
body: &hir::Block,
1925-
llfndecl: ValueRef,
1926-
param_substs: &'tcx Substs<'tcx>,
1927-
id: ast::NodeId) {
1928-
let _s = StatRecorder::new(ccx, ccx.tcx().node_path_str(id));
1929-
debug!("trans_fn(param_substs={:?})", param_substs);
1930-
let _icx = push_ctxt("trans_fn");
1931-
let def_id = if let Some(&def_id) = ccx.external_srcs().borrow().get(&id) {
1932-
def_id
1933-
} else {
1934-
ccx.tcx().map.local_def_id(id)
1935-
};
1936-
let fn_ty = ccx.tcx().lookup_item_type(def_id).ty;
1937-
let fn_ty = monomorphize::apply_param_substs(ccx.tcx(), param_substs, &fn_ty);
1938-
let sig = ccx.tcx().erase_late_bound_regions(fn_ty.fn_sig());
1939-
let sig = ccx.tcx().normalize_associated_type(&sig);
1940-
let abi = fn_ty.fn_abi();
1941-
trans_closure(ccx,
1942-
decl,
1943-
body,
1944-
llfndecl,
1945-
Instance::new(def_id, param_substs),
1946-
id,
1947-
&sig,
1948-
abi,
1949-
closure::ClosureEnv::NotClosure);
1950-
}
1951-
19521919
pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance<'tcx>) {
19531920
let instance = inline::maybe_inline_instance(ccx, instance);
19541921

@@ -2215,46 +2182,14 @@ pub fn llvm_linkage_by_name(name: &str) -> Option<Linkage> {
22152182
}
22162183
}
22172184

2218-
2219-
/// Enum describing the origin of an LLVM `Value`, for linkage purposes.
2220-
#[derive(Copy, Clone)]
2221-
pub enum ValueOrigin {
2222-
/// The LLVM `Value` is in this context because the corresponding item was
2223-
/// assigned to the current compilation unit.
2224-
OriginalTranslation,
2225-
/// The `Value`'s corresponding item was assigned to some other compilation
2226-
/// unit, but the `Value` was translated in this context anyway because the
2227-
/// item is marked `#[inline]`.
2228-
InlinedCopy,
2229-
}
2230-
22312185
/// Set the appropriate linkage for an LLVM `ValueRef` (function or global).
22322186
/// If the `llval` is the direct translation of a specific Rust item, `id`
22332187
/// should be set to the `NodeId` of that item. (This mapping should be
22342188
/// 1-to-1, so monomorphizations and drop/visit glue should have `id` set to
2235-
/// `None`.) `llval_origin` indicates whether `llval` is the translation of an
2236-
/// item assigned to `ccx`'s compilation unit or an inlined copy of an item
2237-
/// assigned to a different compilation unit.
2189+
/// `None`.)
22382190
pub fn update_linkage(ccx: &CrateContext,
22392191
llval: ValueRef,
2240-
id: Option<ast::NodeId>,
2241-
llval_origin: ValueOrigin) {
2242-
match llval_origin {
2243-
InlinedCopy => {
2244-
// `llval` is a translation of an item defined in a separate
2245-
// compilation unit. This only makes sense if there are at least
2246-
// two compilation units.
2247-
assert!(ccx.sess().opts.cg.codegen_units > 1 ||
2248-
ccx.sess().opts.debugging_opts.incremental.is_some());
2249-
// `llval` is a copy of something defined elsewhere, so use
2250-
// `AvailableExternallyLinkage` to avoid duplicating code in the
2251-
// output.
2252-
llvm::SetLinkage(llval, llvm::AvailableExternallyLinkage);
2253-
return;
2254-
},
2255-
OriginalTranslation => {},
2256-
}
2257-
2192+
id: Option<ast::NodeId>) {
22582193
if let Some(id) = id {
22592194
let item = ccx.tcx().map.get(id);
22602195
if let hir_map::NodeItem(i) = item {

src/librustc_trans/glue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ fn get_drop_glue_core<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
285285

286286
let bcx = fcx.init(false, None);
287287

288-
update_linkage(ccx, llfn, None, OriginalTranslation);
288+
update_linkage(ccx, llfn, None);
289289

290290
ccx.stats().n_glues_created.set(ccx.stats().n_glues_created.get() + 1);
291291
// All glue functions take values passed *by alias*; this is a

src/librustc_trans/monomorphize.rs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use rustc::ty::subst::{Subst, Substs};
1717
use rustc::ty::{self, Ty, TypeFoldable, TyCtxt};
1818
use attributes;
1919
use base::{push_ctxt};
20-
use base::trans_fn;
2120
use base;
2221
use common::*;
2322
use declare;
@@ -27,17 +26,16 @@ use rustc::util::ppaux;
2726

2827
use rustc::hir;
2928

30-
use syntax::attr;
3129
use errors;
3230

3331
use std::fmt;
32+
use trans_item::TransItem;
3433

3534
pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
3635
fn_id: DefId,
3736
psubsts: &'tcx subst::Substs<'tcx>)
3837
-> (ValueRef, Ty<'tcx>) {
3938
debug!("monomorphic_fn(fn_id={:?}, real_substs={:?})", fn_id, psubsts);
40-
4139
assert!(!psubsts.types.needs_infer() && !psubsts.types.has_param_types());
4240

4341
let _icx = push_ctxt("monomorphic_fn");
@@ -53,6 +51,8 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
5351
if let Some(&val) = ccx.instances().borrow().get(&instance) {
5452
debug!("leaving monomorphic fn {:?}", instance);
5553
return (val, mono_ty);
54+
} else {
55+
assert!(!ccx.codegen_unit().items.contains_key(&TransItem::Fn(instance)));
5656
}
5757

5858
debug!("monomorphic_fn({:?})", instance);
@@ -96,6 +96,7 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
9696

9797
ccx.instances().borrow_mut().insert(instance, lldecl);
9898

99+
99100
// we can only monomorphize things in this crate (or inlined into it)
100101
let fn_node_id = ccx.tcx().map.as_local_node_id(fn_id).unwrap();
101102
let map_node = errors::expect(
@@ -110,34 +111,18 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
110111
match map_node {
111112
hir_map::NodeItem(&hir::Item {
112113
ref attrs,
113-
node: hir::ItemFn(ref decl, _, _, _, _, ref body), ..
114+
node: hir::ItemFn(..), ..
114115
}) |
115116
hir_map::NodeImplItem(&hir::ImplItem {
116117
ref attrs, node: hir::ImplItemKind::Method(
117-
hir::MethodSig { ref decl, .. }, ref body), ..
118+
hir::MethodSig { .. }, _), ..
118119
}) |
119120
hir_map::NodeTraitItem(&hir::TraitItem {
120121
ref attrs, node: hir::MethodTraitItem(
121-
hir::MethodSig { ref decl, .. }, Some(ref body)), ..
122+
hir::MethodSig { .. }, Some(_)), ..
122123
}) => {
123124
attributes::from_fn_attrs(ccx, attrs, lldecl);
124-
125-
let is_first = !ccx.available_monomorphizations().borrow()
126-
.contains(&symbol);
127-
if is_first {
128-
ccx.available_monomorphizations().borrow_mut().insert(symbol.clone());
129-
}
130-
131-
let trans_everywhere = attr::requests_inline(attrs);
132-
if trans_everywhere || is_first {
133-
let origin = if is_first { base::OriginalTranslation } else { base::InlinedCopy };
134-
base::update_linkage(ccx, lldecl, None, origin);
135-
trans_fn(ccx, decl, body, lldecl, psubsts, fn_node_id);
136-
} else {
137-
// We marked the value as using internal linkage earlier, but that is illegal for
138-
// declarations, so switch back to external linkage.
139-
llvm::SetLinkage(lldecl, llvm::ExternalLinkage);
140-
}
125+
llvm::SetLinkage(lldecl, llvm::ExternalLinkage);
141126
}
142127

143128
hir_map::NodeVariant(_) | hir_map::NodeStructCtor(_) => {

0 commit comments

Comments
 (0)