Skip to content

Commit 1c895d0

Browse files
trans: Get rid of the last potential on-demand creation of non-closure functions.
1 parent 5913d3f commit 1c895d0

File tree

3 files changed

+12
-92
lines changed

3 files changed

+12
-92
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

@@ -1925,37 +1923,6 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
19251923
fcx.finish(bcx, fn_cleanup_debug_loc.debug_loc());
19261924
}
19271925

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

@@ -2222,46 +2189,14 @@ pub fn llvm_linkage_by_name(name: &str) -> Option<Linkage> {
22222189
}
22232190
}
22242191

2225-
2226-
/// Enum describing the origin of an LLVM `Value`, for linkage purposes.
2227-
#[derive(Copy, Clone)]
2228-
pub enum ValueOrigin {
2229-
/// The LLVM `Value` is in this context because the corresponding item was
2230-
/// assigned to the current compilation unit.
2231-
OriginalTranslation,
2232-
/// The `Value`'s corresponding item was assigned to some other compilation
2233-
/// unit, but the `Value` was translated in this context anyway because the
2234-
/// item is marked `#[inline]`.
2235-
InlinedCopy,
2236-
}
2237-
22382192
/// Set the appropriate linkage for an LLVM `ValueRef` (function or global).
22392193
/// If the `llval` is the direct translation of a specific Rust item, `id`
22402194
/// should be set to the `NodeId` of that item. (This mapping should be
22412195
/// 1-to-1, so monomorphizations and drop/visit glue should have `id` set to
2242-
/// `None`.) `llval_origin` indicates whether `llval` is the translation of an
2243-
/// item assigned to `ccx`'s compilation unit or an inlined copy of an item
2244-
/// assigned to a different compilation unit.
2196+
/// `None`.)
22452197
pub fn update_linkage(ccx: &CrateContext,
22462198
llval: ValueRef,
2247-
id: Option<ast::NodeId>,
2248-
llval_origin: ValueOrigin) {
2249-
match llval_origin {
2250-
InlinedCopy => {
2251-
// `llval` is a translation of an item defined in a separate
2252-
// compilation unit. This only makes sense if there are at least
2253-
// two compilation units.
2254-
assert!(ccx.sess().opts.cg.codegen_units > 1 ||
2255-
ccx.sess().opts.debugging_opts.incremental.is_some());
2256-
// `llval` is a copy of something defined elsewhere, so use
2257-
// `AvailableExternallyLinkage` to avoid duplicating code in the
2258-
// output.
2259-
llvm::SetLinkage(llval, llvm::AvailableExternallyLinkage);
2260-
return;
2261-
},
2262-
OriginalTranslation => {},
2263-
}
2264-
2199+
id: Option<ast::NodeId>) {
22652200
if let Some(id) = id {
22662201
let item = ccx.tcx().map.get(id);
22672202
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
@@ -281,7 +281,7 @@ fn get_drop_glue_core<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
281281

282282
let bcx = fcx.init(false, None);
283283

284-
update_linkage(ccx, llfn, None, OriginalTranslation);
284+
update_linkage(ccx, llfn, None);
285285

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

src/librustc_trans/monomorphize.rs

Lines changed: 9 additions & 24 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 syntax::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");
@@ -55,7 +53,9 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
5553
debug!("leaving monomorphic fn {:?}", instance);
5654
return (val, mono_ty);
5755
}
58-
None => ()
56+
None => {
57+
assert!(!ccx.codegen_unit().items.contains_key(&TransItem::Fn(instance)));
58+
}
5959
}
6060

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

100100
ccx.instances().borrow_mut().insert(instance, lldecl);
101101

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

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

0 commit comments

Comments
 (0)