]> git.proxmox.com Git - rustc.git/blame - src/librustc_trans/inline.rs
New upstream version 1.12.0+dfsg1
[rustc.git] / src / librustc_trans / inline.rs
CommitLineData
1a4d82fc
JJ
1// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
54a0048b 11use rustc::hir::def_id::DefId;
5bcae85e 12use base::push_ctxt;
54a0048b 13use common::*;
5bcae85e 14use monomorphize::Instance;
1a4d82fc 15
9cc50fc6 16use rustc::dep_graph::DepNode;
1a4d82fc 17
9cc50fc6 18fn instantiate_inline(ccx: &CrateContext, fn_id: DefId) -> Option<DefId> {
62682a34
SL
19 debug!("instantiate_inline({:?})", fn_id);
20 let _icx = push_ctxt("instantiate_inline");
54a0048b
SL
21 let tcx = ccx.tcx();
22 let _task = tcx.dep_graph.in_task(DepNode::TransInlinedItem(fn_id));
62682a34 23
5bcae85e
SL
24 tcx.sess
25 .cstore
26 .maybe_get_item_ast(tcx, fn_id)
27 .map(|(_, inline_id)| {
28 tcx.map.local_def_id(inline_id)
29 })
1a4d82fc
JJ
30}
31
e9174d1e
SL
32pub fn get_local_instance(ccx: &CrateContext, fn_id: DefId)
33 -> Option<DefId> {
b039eaaf 34 if let Some(_) = ccx.tcx().map.as_local_node_id(fn_id) {
1a4d82fc
JJ
35 Some(fn_id)
36 } else {
37 instantiate_inline(ccx, fn_id)
38 }
39}
40
e9174d1e 41pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: DefId) -> DefId {
1a4d82fc
JJ
42 get_local_instance(ccx, fn_id).unwrap_or(fn_id)
43}
5bcae85e
SL
44
45pub fn maybe_inline_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
46 instance: Instance<'tcx>) -> Instance<'tcx> {
47 let def_id = maybe_instantiate_inline(ccx, instance.def);
48 Instance {
49 def: def_id,
50 substs: instance.substs
51 }
52}