use middle::lang_items::{LangItem, ExchangeMallocFnLangItem, StartFnLangItem};
use middle::subst;
use middle::weak_lang_items;
-use middle::subst::Subst;
+use middle::subst::{Subst, Substs};
use middle::ty::{mod, Ty};
use session::config::{mod, NoDebugInfo, FullDebugInfo};
use session::Session;
use trans::common::{Block, C_bool, C_bytes_in_context, C_i32, C_integral};
use trans::common::{C_null, C_struct_in_context, C_u64, C_u8, C_uint, C_undef};
use trans::common::{CrateContext, ExternMap, FunctionContext};
-use trans::common::{NodeInfo, Result, SubstP};
-use trans::common::{node_id_type, param_substs, return_type_is_void};
+use trans::common::{NodeInfo, Result};
+use trans::common::{node_id_type, return_type_is_void};
use trans::common::{tydesc_info, type_is_immediate};
use trans::common::{type_is_zero_size, val_ty};
use trans::common;
id: ast::NodeId,
has_env: bool,
output_type: ty::FnOutput<'tcx>,
- param_substs: &'a param_substs<'tcx>,
+ param_substs: &'a Substs<'tcx>,
sp: Option<Span>,
block_arena: &'a TypedArena<common::BlockS<'a, 'tcx>>)
-> FunctionContext<'a, 'tcx> {
- param_substs.validate();
+ common::validate_substs(param_substs);
debug!("new_fn_ctxt(path={}, id={}, param_substs={})",
if id == -1 {
let uses_outptr = match output_type {
ty::FnConverging(output_type) => {
- let substd_output_type = output_type.substp(ccx.tcx(), param_substs);
+ let substd_output_type = output_type.subst(ccx.tcx(), param_substs);
type_of::return_uses_outptr(ccx, substd_output_type)
}
ty::FnDiverging => false
if let ty::FnConverging(output_type) = output {
// This shouldn't need to recompute the return type,
// as new_fn_ctxt did it already.
- let substd_output_type = output_type.substp(fcx.ccx.tcx(), fcx.param_substs);
+ let substd_output_type = output_type.subst(fcx.ccx.tcx(), fcx.param_substs);
if !return_type_is_void(fcx.ccx, substd_output_type) {
// If the function returns nil/bot, there is no real return
// value, so do not set `llretslotptr`.
// This shouldn't need to recompute the return type,
// as new_fn_ctxt did it already.
- let substd_retty = retty.substp(fcx.ccx.tcx(), fcx.param_substs);
+ let substd_retty = retty.subst(fcx.ccx.tcx(), fcx.param_substs);
build_return_block(fcx, ret_cx, substd_retty);
debuginfo::clear_source_location(fcx);
decl: &ast::FnDecl,
body: &ast::Block,
llfndecl: ValueRef,
- param_substs: ¶m_substs<'tcx>,
+ param_substs: &Substs<'tcx>,
fn_ast_id: ast::NodeId,
_attributes: &[ast::Attribute],
output_type: ty::FnOutput<'tcx>,
decl: &ast::FnDecl,
body: &ast::Block,
llfndecl: ValueRef,
- param_substs: ¶m_substs<'tcx>,
+ param_substs: &Substs<'tcx>,
id: ast::NodeId,
attrs: &[ast::Attribute]) {
let _s = StatRecorder::new(ccx, ccx.tcx().map.path_to_string(id).to_string());
variant: &ast::Variant,
_args: &[ast::VariantArg],
disr: ty::Disr,
- param_substs: ¶m_substs<'tcx>,
+ param_substs: &Substs<'tcx>,
llfndecl: ValueRef) {
let _icx = push_ctxt("trans_enum_variant");
pub fn trans_tuple_struct<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
_fields: &[ast::StructField],
ctor_id: ast::NodeId,
- param_substs: ¶m_substs<'tcx>,
+ param_substs: &Substs<'tcx>,
llfndecl: ValueRef) {
let _icx = push_ctxt("trans_tuple_struct");
fn trans_enum_variant_or_tuple_like_struct<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
ctor_id: ast::NodeId,
disr: ty::Disr,
- param_substs: ¶m_substs<'tcx>,
+ param_substs: &Substs<'tcx>,
llfndecl: ValueRef) {
let ctor_ty = ty::node_id_to_type(ccx.tcx(), ctor_id);
- let ctor_ty = ctor_ty.substp(ccx.tcx(), param_substs);
+ let ctor_ty = ctor_ty.subst(ccx.tcx(), param_substs);
let result_ty = match ty::get(ctor_ty).sty {
ty::ty_bare_fn(ref bft) => bft.sig.output,
&**body,
item.attrs.as_slice(),
llfn,
- ¶m_substs::empty(),
+ &Substs::trans_empty(),
item.id,
None);
} else {
&**decl,
&**body,
llfn,
- ¶m_substs::empty(),
+ &Substs::trans_empty(),
item.id,
item.attrs.as_slice());
}
use metadata::csearch;
use middle::def;
use middle::subst;
-use middle::subst::{Subst};
+use middle::subst::{Subst, Substs};
use trans::adt;
use trans::base;
use trans::base::*;
function_name.as_slice());
let block_arena = TypedArena::new();
- let empty_param_substs = param_substs::empty();
+ let empty_param_substs = Substs::trans_empty();
let return_type = ty::ty_fn_ret(boxed_function_type);
let fcx = new_fn_ctxt(ccx,
llfn,
use llvm::ValueRef;
use middle::def;
use middle::mem_categorization::Typer;
+use middle::subst::Substs;
use trans::adt;
use trans::base::*;
use trans::build::*;
let llfn = get_or_create_declaration_if_unboxed_closure(
bcx,
closure_id,
- bcx.fcx.param_substs.substs()).unwrap();
+ bcx.fcx.param_substs).unwrap();
let function_type = (*bcx.tcx().unboxed_closures.borrow())[closure_id]
.closure_type
let _icx = push_ctxt("closure::get_wrapper_for_bare_fn");
let arena = TypedArena::new();
- let empty_param_substs = param_substs::empty();
+ let empty_param_substs = Substs::trans_empty();
let fcx = new_fn_ctxt(ccx, llfn, ast::DUMMY_NODE_ID, true, f.sig.output,
&empty_param_substs, None, &arena);
let bcx = init_function(&fcx, true, f.sig.output);
use middle::lang_items::LangItem;
use middle::mem_categorization as mc;
use middle::subst;
-use middle::subst::Subst;
+use middle::subst::{Subst, Substs};
use trans::base;
use trans::build;
use trans::cleanup;
pub type ExternMap = FnvHashMap<String, ValueRef>;
-// Here `self_ty` is the real type of the self parameter to this method. It
-// will only be set in the case of default methods.
-pub struct param_substs<'tcx> {
- substs: subst::Substs<'tcx>,
-}
-
-impl<'tcx> param_substs<'tcx> {
- pub fn new(substs: subst::Substs<'tcx>) -> param_substs<'tcx> {
- assert!(substs.types.all(|t| !ty::type_needs_infer(*t)));
- assert!(substs.types.all(|t| !ty::type_has_params(*t)));
- assert!(substs.types.all(|t| !ty::type_has_escaping_regions(*t)));
- param_substs { substs: substs.erase_regions() }
- }
-
- pub fn substs(&self) -> &subst::Substs<'tcx> {
- &self.substs
- }
-
- pub fn empty() -> param_substs<'tcx> {
- param_substs {
- substs: subst::Substs::trans_empty(),
- }
- }
-
- pub fn validate(&self) {
- assert!(self.substs.types.all(|t| !ty::type_needs_infer(*t)));
- }
-}
-
-impl<'tcx> Repr<'tcx> for param_substs<'tcx> {
- fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
- self.substs.repr(tcx)
- }
-}
-
-pub trait SubstP<'tcx> {
- fn substp(&self, tcx: &ty::ctxt<'tcx>, param_substs: ¶m_substs<'tcx>)
- -> Self;
-}
-
-impl<'tcx, T: Subst<'tcx> + Clone> SubstP<'tcx> for T {
- fn substp(&self, tcx: &ty::ctxt<'tcx>, substs: ¶m_substs<'tcx>) -> T {
- self.subst(tcx, &substs.substs)
- }
+pub fn validate_substs(substs: &Substs) {
+ assert!(substs.types.all(|t| !ty::type_needs_infer(*t)));
}
// work around bizarre resolve errors
// If this function is being monomorphized, this contains the type
// substitutions used.
- pub param_substs: &'a param_substs<'tcx>,
+ pub param_substs: &'a Substs<'tcx>,
// The source span and nesting context where this function comes from, for
// error reporting and symbol generation.
}
pub fn monomorphize_type<'blk, 'tcx>(bcx: &BlockS<'blk, 'tcx>, t: Ty<'tcx>) -> Ty<'tcx> {
- t.subst(bcx.tcx(), &bcx.fcx.param_substs.substs)
+ t.subst(bcx.tcx(), bcx.fcx.param_substs)
}
pub fn node_id_type<'blk, 'tcx>(bcx: &BlockS<'blk, 'tcx>, id: ast::NodeId) -> Ty<'tcx> {
}
let substs = substs.erase_regions();
- substs.substp(tcx, bcx.fcx.param_substs)
+ substs.subst(tcx, bcx.fcx.param_substs)
}
pub fn langcall(bcx: Block,
use llvm::{ModuleRef, ContextRef, ValueRef};
use llvm::debuginfo::*;
use metadata::csearch;
-use middle::subst::{mod, Subst};
+use middle::subst::{mod, Subst, Substs};
use trans::adt;
use trans::common::*;
use trans::machine;
/// for the function.
pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
fn_ast_id: ast::NodeId,
- param_substs: ¶m_substs<'tcx>,
+ param_substs: &Substs<'tcx>,
llfn: ValueRef) -> FunctionDebugContext {
if cx.sess().opts.debuginfo == NoDebugInfo {
return FunctionDebugContext { repr: DebugInfoDisabled };
fn get_function_signature<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
fn_ast_id: ast::NodeId,
fn_decl: &ast::FnDecl,
- param_substs: ¶m_substs<'tcx>,
+ param_substs: &Substs<'tcx>,
error_reporting_span: Span) -> DIArray {
if cx.sess().opts.debuginfo == LimitedDebugInfo {
return create_DIArray(DIB(cx), &[]);
assert_type_for_node_id(cx, fn_ast_id, error_reporting_span);
let return_type = ty::node_id_to_type(cx.tcx(), fn_ast_id);
- let return_type = return_type.substp(cx.tcx(), param_substs);
+ let return_type = return_type.subst(cx.tcx(), param_substs);
signature.push(type_metadata(cx, return_type, codemap::DUMMY_SP));
}
}
for arg in fn_decl.inputs.iter() {
assert_type_for_node_id(cx, arg.pat.id, arg.pat.span);
let arg_type = ty::node_id_to_type(cx.tcx(), arg.pat.id);
- let arg_type = arg_type.substp(cx.tcx(), param_substs);
+ let arg_type = arg_type.subst(cx.tcx(), param_substs);
signature.push(type_metadata(cx, arg_type, codemap::DUMMY_SP));
}
fn get_template_parameters<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
generics: &ast::Generics,
- param_substs: ¶m_substs<'tcx>,
+ param_substs: &Substs<'tcx>,
file_metadata: DIFile,
name_to_append_suffix_to: &mut String)
-> DIArray {
- let self_type = param_substs.substs().self_ty();
+ let self_type = param_substs.self_ty();
// Only true for static default methods:
let has_self_type = self_type.is_some();
}
// Handle other generic parameters
- let actual_types = param_substs.substs().types.get_slice(subst::FnSpace);
+ let actual_types = param_substs.types.get_slice(subst::FnSpace);
for (index, &ast::TyParam{ ident, .. }) in generics.ty_params.iter().enumerate() {
let actual_type = actual_types[index];
// Add actual type name to <...> clause of function name
let trait_ref =
Rc::new(ty::TraitRef { def_id: principal.def_id,
substs: substs });
- let trait_ref =
- trait_ref.subst(bcx.tcx(), bcx.fcx.param_substs.substs());
+ let trait_ref = trait_ref.subst(bcx.tcx(), bcx.fcx.param_substs);
let box_ty = mk_ty(unsized_ty);
PointerCast(bcx,
meth::get_vtable(bcx, box_ty, trait_ref),
.get(&expr.id)
.map(|t| (*t).clone())
.unwrap();
- let trait_ref =
- trait_ref.subst(bcx.tcx(), bcx.fcx.param_substs.substs());
+ let trait_ref = trait_ref.subst(bcx.tcx(), bcx.fcx.param_substs);
let datum = unpack_datum!(bcx, trans(bcx, &**val));
meth::trans_trait_cast(bcx, datum, expr.id,
trait_ref, dest)
use trans::type_of;
use middle::ty::FnSig;
use middle::ty::{mod, Ty};
-use middle::subst::Subst;
+use middle::subst::{Subst, Substs};
use std::cmp;
use libc::c_uint;
use syntax::abi::{Cdecl, Aapcs, C, Win64, Abi};
body: &ast::Block,
attrs: &[ast::Attribute],
llwrapfn: ValueRef,
- param_substs: ¶m_substs<'tcx>,
+ param_substs: &Substs<'tcx>,
id: ast::NodeId,
hash: Option<&str>) {
let _icx = push_ctxt("foreign::build_foreign_fn");
let fnty = ty::node_id_to_type(ccx.tcx(), id);
- let mty = fnty.subst(ccx.tcx(), param_substs.substs());
+ let mty = fnty.subst(ccx.tcx(), param_substs);
let tys = foreign_types_for_fn_ty(ccx, mty);
unsafe { // unsafe because we call LLVM operations
fn build_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
decl: &ast::FnDecl,
body: &ast::Block,
- param_substs: ¶m_substs<'tcx>,
+ param_substs: &Substs<'tcx>,
attrs: &[ast::Attribute],
id: ast::NodeId,
hash: Option<&str>)
-> ValueRef {
let _icx = push_ctxt("foreign::foreign::build_rust_fn");
let tcx = ccx.tcx();
- let t = ty::node_id_to_type(tcx, id).subst(
- ccx.tcx(), param_substs.substs());
+ let t = ty::node_id_to_type(tcx, id).subst(ccx.tcx(), param_substs);
let ps = ccx.tcx().map.with_path(id, |path| {
let abi = Some(ast_map::PathName(special_idents::clownshoe_abi.name));
use llvm;
use middle::lang_items::ExchangeFreeFnLangItem;
use middle::subst;
-use middle::subst::Subst;
+use middle::subst::{Subst, Substs};
use trans::adt;
use trans::base::*;
use trans::build::*;
let _s = StatRecorder::new(ccx, glue_name);
let arena = TypedArena::new();
- let empty_param_substs = param_substs::empty();
+ let empty_param_substs = Substs::trans_empty();
let fcx = new_fn_ctxt(ccx, llfn, ast::DUMMY_NODE_ID, false,
ty::FnConverging(ty::mk_nil(ccx.tcx())),
&empty_param_substs, None, &arena);
use llvm::{AvailableExternallyLinkage, InternalLinkage, SetLinkage};
use metadata::csearch;
use middle::astencode;
+use middle::subst::Substs;
use trans::base::{push_ctxt, trans_item, get_item_val, trans_fn};
use trans::common::*;
use middle::ty;
&*mth.pe_fn_decl(),
&*mth.pe_body(),
llfn,
- ¶m_substs::empty(),
+ &Substs::trans_empty(),
mth.id,
&[]);
// Use InternalLinkage so LLVM can optimize more
method.pe_fn_decl(),
method.pe_body(),
llfn,
- ¶m_substs::empty(),
+ &Substs::trans_empty(),
method.id,
&[]);
update_linkage(ccx,
method_num
}) => {
let trait_ref =
- Rc::new(trait_ref.subst(bcx.tcx(),
- bcx.fcx.param_substs.substs()));
+ Rc::new(trait_ref.subst(bcx.tcx(), bcx.fcx.param_substs));
let span = bcx.tcx().map.span(method_call.expr_id);
debug!("method_call={} trait_ref={}",
method_call,
pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
fn_id: ast::DefId,
- real_substs: &subst::Substs<'tcx>,
+ psubsts: &subst::Substs<'tcx>,
ref_id: Option<ast::NodeId>)
-> (ValueRef, bool) {
debug!("monomorphic_fn(\
real_substs={}, \
ref_id={})",
fn_id.repr(ccx.tcx()),
- real_substs.repr(ccx.tcx()),
+ psubsts.repr(ccx.tcx()),
ref_id);
- assert!(real_substs.types.all(|t| {
+ assert!(psubsts.types.all(|t| {
!ty::type_needs_infer(*t) && !ty::type_has_params(*t)
}));
let hash_id = MonoId {
def: fn_id,
- params: real_substs.types.clone()
+ params: psubsts.types.clone()
};
match ccx.monomorphized().borrow().get(&hash_id) {
None => ()
}
- debug!("creating param_substs with real_substs={}", real_substs.repr(ccx.tcx()));
- let psubsts = param_substs::new((*real_substs).clone());
-
debug!("monomorphic_fn(\
fn_id={}, \
psubsts={}, \
}
debug!("monomorphic_fn about to subst into {}", llitem_ty.repr(ccx.tcx()));
- let mono_ty = llitem_ty.subst(ccx.tcx(), real_substs);
+ let mono_ty = llitem_ty.subst(ccx.tcx(), psubsts);
ccx.stats().n_monos.set(ccx.stats().n_monos.get() + 1);
if needs_body {
if abi != abi::Rust {
foreign::trans_rust_fn_with_foreign_abi(
- ccx, &**decl, &**body, &[], d, &psubsts, fn_id.node,
+ ccx, &**decl, &**body, &[], d, psubsts, fn_id.node,
Some(hash.as_slice()));
} else {
- trans_fn(ccx, &**decl, &**body, d, &psubsts, fn_id.node, &[]);
+ trans_fn(ccx, &**decl, &**body, d, psubsts, fn_id.node, &[]);
}
}
&*v,
args.as_slice(),
this_tv.disr_val,
- &psubsts,
+ psubsts,
d);
}
ast::StructVariantKind(_) =>
mth.pe_fn_decl(),
mth.pe_body(),
d,
- &psubsts,
+ psubsts,
mth.id,
&[]);
}
let needs_body = setup_lldecl(d, mth.attrs.as_slice());
if needs_body {
trans_fn(ccx, mth.pe_fn_decl(), mth.pe_body(), d,
- &psubsts, mth.id, &[]);
+ psubsts, mth.id, &[]);
}
d
}
struct_def.fields.as_slice(),
struct_def.ctor_id.expect("ast-mapped tuple struct \
didn't have a ctor id"),
- &psubsts,
+ psubsts,
d);
d
}