Navigation Menu

Skip to content

Commit

Permalink
normalize the results of tcx.type_of after substituting
Browse files Browse the repository at this point in the history
Also remove `def_ty`, which was a footgun because it did not do the
above.
  • Loading branch information
arielb1 committed Dec 18, 2017
1 parent 88866b5 commit f6fcfa3
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 21 deletions.
8 changes: 7 additions & 1 deletion src/librustc/traits/trans/mod.rs
Expand Up @@ -17,6 +17,7 @@ use dep_graph::{DepKind, DepTrackingMapConfig};
use infer::TransNormalize;
use std::marker::PhantomData;
use syntax_pos::DUMMY_SP;
use hir::def_id::DefId;
use traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext, Vtable};
use ty::{self, Ty, TyCtxt};
use ty::subst::{Subst, Substs};
Expand Down Expand Up @@ -119,6 +120,12 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
let substituted = self.erase_regions(&substituted);
AssociatedTypeNormalizerEnv::new(self, param_env).fold(&substituted)
}

pub fn trans_impl_self_ty(&self, def_id: DefId, substs: &'tcx Substs<'tcx>)
-> Ty<'tcx>
{
self.trans_apply_param_substs(substs, &self.type_of(def_id))
}
}

struct AssociatedTypeNormalizer<'a, 'gcx: 'a> {
Expand Down Expand Up @@ -214,4 +221,3 @@ impl<'gcx> DepTrackingMapConfig for ProjectionCache<'gcx> {
DepKind::TraitSelect
}
}

7 changes: 1 addition & 6 deletions src/librustc/ty/instance.rs
Expand Up @@ -50,7 +50,7 @@ impl<'a, 'tcx> Instance<'tcx> {
tcx: TyCtxt<'a, 'tcx, 'tcx>)
-> Ty<'tcx>
{
let ty = self.def.def_ty(tcx);
let ty = tcx.type_of(self.def.def_id());
tcx.trans_apply_param_substs(self.substs, &ty)
}
}
Expand All @@ -69,11 +69,6 @@ impl<'tcx> InstanceDef<'tcx> {
}
}

#[inline]
pub fn def_ty<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
tcx.type_of(self.def_id())
}

#[inline]
pub fn attrs<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> ty::Attributes<'tcx> {
tcx.get_attrs(self.def_id())
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_mir/interpret/const_eval.rs
Expand Up @@ -57,9 +57,7 @@ pub fn eval_body<'a, 'tcx>(
if ecx.tcx.has_attr(instance.def_id(), "linkage") {
return Err(ConstEvalError::NotConst("extern global".to_string()).into());
}
// FIXME(eddyb) use `Instance::ty` when it becomes available.
let instance_ty =
ecx.monomorphize(instance.def.def_ty(tcx), instance.substs);
let instance_ty = instance.ty(tcx);
if tcx.interpret_interner.borrow().get_cached(cid).is_none() {
let mir = ecx.load_mir(instance.def)?;
let layout = ecx.layout_of(instance_ty)?;
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_mir/interpret/step.rs
Expand Up @@ -172,9 +172,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
M::global_item_with_linkage(self, cid.instance, mutability)?;
return Ok(false);
}
// FIXME(eddyb) use `Instance::ty` when it becomes available.
let instance_ty =
self.monomorphize(instance.def.def_ty(self.tcx), instance.substs);
let instance_ty = instance.ty(self.tcx);
let layout = self.layout_of(instance_ty)?;
assert!(!layout.is_unsized());
let ptr = self.memory.allocate(
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_mir/interpret/terminator/mod.rs
Expand Up @@ -72,9 +72,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
ty::TyFnPtr(sig) => {
let fn_ptr = self.value_to_primval(func)?.to_ptr()?;
let instance = self.memory.get_fn(fn_ptr)?;
// FIXME(eddyb) use `Instance::ty` when it becomes available.
let instance_ty =
self.monomorphize(instance.def.def_ty(self.tcx), instance.substs);
let instance_ty = instance.ty(self.tcx);
match instance_ty.sty {
ty::TyFnDef(..) => {
let real_sig = instance_ty.fn_sig(self.tcx);
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_mir/monomorphize/partitioning.rs
Expand Up @@ -115,7 +115,6 @@ use syntax::ast::NodeId;
use syntax::symbol::{Symbol, InternedString};
use rustc::mir::mono::MonoItem;
use monomorphize::item::{MonoItemExt, InstantiationMode};
use rustc::ty::subst::Subst;

pub use rustc::mir::mono::CodegenUnit;

Expand Down Expand Up @@ -576,7 +575,7 @@ fn characteristic_def_id_of_trans_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
if let Some(impl_def_id) = tcx.impl_of_method(def_id) {
// This is a method within an inherent impl, find out what the
// self-type is:
let impl_self_ty = tcx.type_of(impl_def_id).subst(tcx, instance.substs);
let impl_self_ty = tcx.trans_impl_self_ty(impl_def_id, instance.substs);
if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) {
return Some(def_id);
}
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_trans/debuginfo/mod.rs
Expand Up @@ -24,7 +24,7 @@ use llvm;
use llvm::{ModuleRef, ContextRef, ValueRef};
use llvm::debuginfo::{DIFile, DIType, DIScope, DIBuilderRef, DISubprogram, DIArray, DIFlags};
use rustc::hir::def_id::{DefId, CrateNum};
use rustc::ty::subst::{Subst, Substs};
use rustc::ty::subst::Substs;

use abi::Abi;
use common::CrateContext;
Expand Down Expand Up @@ -427,8 +427,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let self_type = cx.tcx().impl_of_method(instance.def_id()).and_then(|impl_def_id| {
// If the method does *not* belong to a trait, proceed
if cx.tcx().trait_id_of_impl(impl_def_id).is_none() {
let impl_self_ty =
cx.tcx().type_of(impl_def_id).subst(cx.tcx(), instance.substs);
let impl_self_ty = cx.tcx().trans_impl_self_ty(impl_def_id, instance.substs);

// Only "class" methods are generally understood by LLVM,
// so avoid methods on other types (e.g. `<*mut T>::null`).
Expand Down

0 comments on commit f6fcfa3

Please sign in to comment.