Skip to content

Commit 6e29099

Browse files
committed
infer: Turn normalize_associated_type into a method on TyCtxt.
1 parent 0907c19 commit 6e29099

File tree

13 files changed

+51
-58
lines changed

13 files changed

+51
-58
lines changed

src/librustc/infer/mod.rs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -523,34 +523,36 @@ pub struct CombinedSnapshot {
523523
}
524524

525525
// NOTE: Callable from trans only!
526-
pub fn normalize_associated_type<'tcx,T>(tcx: &TyCtxt<'tcx>, value: &T) -> T
527-
where T : TypeFoldable<'tcx>
528-
{
529-
debug!("normalize_associated_type(t={:?})", value);
526+
impl<'tcx> TyCtxt<'tcx> {
527+
pub fn normalize_associated_type<T>(&self, value: &T) -> T
528+
where T : TypeFoldable<'tcx>
529+
{
530+
debug!("normalize_associated_type(t={:?})", value);
530531

531-
let value = tcx.erase_regions(value);
532+
let value = self.erase_regions(value);
532533

533-
if !value.has_projection_types() {
534-
return value;
535-
}
534+
if !value.has_projection_types() {
535+
return value;
536+
}
536537

537-
let infcx = InferCtxt::new(tcx, &tcx.tables, None, ProjectionMode::Any);
538-
let mut selcx = traits::SelectionContext::new(&infcx);
539-
let cause = traits::ObligationCause::dummy();
540-
let traits::Normalized { value: result, obligations } =
541-
traits::normalize(&mut selcx, cause, &value);
538+
let infcx = InferCtxt::new(self, &self.tables, None, ProjectionMode::Any);
539+
let mut selcx = traits::SelectionContext::new(&infcx);
540+
let cause = traits::ObligationCause::dummy();
541+
let traits::Normalized { value: result, obligations } =
542+
traits::normalize(&mut selcx, cause, &value);
542543

543-
debug!("normalize_associated_type: result={:?} obligations={:?}",
544-
result,
545-
obligations);
544+
debug!("normalize_associated_type: result={:?} obligations={:?}",
545+
result,
546+
obligations);
546547

547-
let mut fulfill_cx = traits::FulfillmentContext::new();
548+
let mut fulfill_cx = traits::FulfillmentContext::new();
548549

549-
for obligation in obligations {
550-
fulfill_cx.register_predicate_obligation(&infcx, obligation);
551-
}
550+
for obligation in obligations {
551+
fulfill_cx.register_predicate_obligation(&infcx, obligation);
552+
}
552553

553-
drain_fulfillment_cx_or_panic(DUMMY_SP, &infcx, &mut fulfill_cx, &result)
554+
drain_fulfillment_cx_or_panic(DUMMY_SP, &infcx, &mut fulfill_cx, &result)
555+
}
554556
}
555557

556558
pub fn drain_fulfillment_cx_or_panic<'a,'tcx,T>(span: Span,
@@ -1617,7 +1619,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16171619
substs);
16181620

16191621
if self.normalize {
1620-
normalize_associated_type(&self.tcx, &closure_ty)
1622+
self.tcx.normalize_associated_type(&closure_ty)
16211623
} else {
16221624
closure_ty
16231625
}

src/librustc_lint/types.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#![allow(non_snake_case)]
1212

1313
use rustc::hir::def_id::DefId;
14-
use rustc::infer;
1514
use rustc::ty::subst::Substs;
1615
use rustc::ty::{self, Ty, TyCtxt};
1716
use middle::const_val::ConstVal;
@@ -439,7 +438,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
439438
}
440439

441440
for field in &def.struct_variant().fields {
442-
let field_ty = infer::normalize_associated_type(cx, &field.ty(cx, substs));
441+
let field_ty = cx.normalize_associated_type(&field.ty(cx, substs));
443442
let r = self.check_type_for_ffi(cache, field_ty);
444443
match r {
445444
FfiSafe => {}
@@ -494,7 +493,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
494493
// Check the contained variants.
495494
for variant in &def.variants {
496495
for field in &variant.fields {
497-
let arg = infer::normalize_associated_type(cx, &field.ty(cx, substs));
496+
let arg = cx.normalize_associated_type(&field.ty(cx, substs));
498497
let r = self.check_type_for_ffi(cache, arg);
499498
match r {
500499
FfiSafe => {}
@@ -596,7 +595,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
596595
fn check_type_for_ffi_and_report_errors(&mut self, sp: Span, ty: Ty<'tcx>) {
597596
// it is only OK to use this function because extern fns cannot have
598597
// any generic types right now:
599-
let ty = infer::normalize_associated_type(self.cx.tcx, &ty);
598+
let ty = self.cx.tcx.normalize_associated_type(&ty);
600599

601600
match self.check_type_for_ffi(&mut FnvHashSet(), ty) {
602601
FfiResult::FfiSafe => {}

src/librustc_trans/base.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use llvm::{BasicBlockRef, Linkage, ValueRef, Vector, get_param};
3636
use llvm;
3737
use rustc::cfg;
3838
use rustc::hir::def_id::DefId;
39-
use rustc::infer;
4039
use middle::lang_items::{LangItem, ExchangeMallocFnLangItem, StartFnLangItem};
4140
use middle::weak_lang_items;
4241
use rustc::hir::pat_util::simple_name;
@@ -1923,7 +1922,7 @@ pub fn trans_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
19231922
let fn_ty = ccx.tcx().lookup_item_type(def_id).ty;
19241923
let fn_ty = monomorphize::apply_param_substs(ccx.tcx(), param_substs, &fn_ty);
19251924
let sig = ccx.tcx().erase_late_bound_regions(fn_ty.fn_sig());
1926-
let sig = infer::normalize_associated_type(ccx.tcx(), &sig);
1925+
let sig = ccx.tcx().normalize_associated_type(&sig);
19271926
let abi = fn_ty.fn_abi();
19281927
trans_closure(ccx,
19291928
decl,
@@ -1947,7 +1946,7 @@ pub fn trans_named_tuple_constructor<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
19471946
let ccx = bcx.fcx.ccx;
19481947

19491948
let sig = ccx.tcx().erase_late_bound_regions(&ctor_ty.fn_sig());
1950-
let sig = infer::normalize_associated_type(ccx.tcx(), &sig);
1949+
let sig = ccx.tcx().normalize_associated_type(&sig);
19511950
let result_ty = sig.output.unwrap();
19521951

19531952
// Get location to store the result. If the user does not care about
@@ -2017,7 +2016,7 @@ pub fn trans_ctor_shim<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
20172016
let ctor_ty = monomorphize::apply_param_substs(ccx.tcx(), param_substs, &ctor_ty);
20182017

20192018
let sig = ccx.tcx().erase_late_bound_regions(&ctor_ty.fn_sig());
2020-
let sig = infer::normalize_associated_type(ccx.tcx(), &sig);
2019+
let sig = ccx.tcx().normalize_associated_type(&sig);
20212020
let fn_ty = FnType::new(ccx, Abi::Rust, &sig, &[]);
20222021

20232022
let (arena, fcx): (TypedArena<_>, FunctionContext);

src/librustc_trans/callee.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use back::symbol_names;
2222
use llvm::{self, ValueRef, get_params};
2323
use middle::cstore::LOCAL_CRATE;
2424
use rustc::hir::def_id::DefId;
25-
use rustc::infer;
2625
use rustc::ty::subst;
2726
use rustc::traits;
2827
use rustc::hir::map as hir_map;
@@ -221,7 +220,7 @@ impl<'tcx> Callee<'tcx> {
221220
extra_args: &[Ty<'tcx>]) -> FnType {
222221
let abi = self.ty.fn_abi();
223222
let sig = ccx.tcx().erase_late_bound_regions(self.ty.fn_sig());
224-
let sig = infer::normalize_associated_type(ccx.tcx(), &sig);
223+
let sig = ccx.tcx().normalize_associated_type(&sig);
225224
let mut fn_ty = FnType::unadjusted(ccx, abi, &sig, extra_args);
226225
if let Virtual(_) = self.data {
227226
// Don't pass the vtable, it's not an argument of the virtual fn.
@@ -361,7 +360,7 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(
361360
}
362361
};
363362
let sig = tcx.erase_late_bound_regions(sig);
364-
let sig = infer::normalize_associated_type(ccx.tcx(), &sig);
363+
let sig = ccx.tcx().normalize_associated_type(&sig);
365364
let tuple_input_ty = tcx.mk_tup(sig.inputs.to_vec());
366365
let sig = ty::FnSig {
367366
inputs: vec![bare_fn_ty_maybe_ref,
@@ -491,7 +490,7 @@ fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
491490
let fn_ptr_ty = match ty.sty {
492491
ty::TyFnDef(_, _, fty) => {
493492
// Create a fn pointer with the normalized signature.
494-
tcx.mk_fn_ptr(infer::normalize_associated_type(tcx, fty))
493+
tcx.mk_fn_ptr(tcx.normalize_associated_type(fty))
495494
}
496495
_ => bug!("expected fn item type, found {}", ty)
497496
};
@@ -623,7 +622,7 @@ fn trans_call_inner<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
623622
let abi = callee.ty.fn_abi();
624623
let sig = callee.ty.fn_sig();
625624
let output = bcx.tcx().erase_late_bound_regions(&sig.output());
626-
let output = infer::normalize_associated_type(bcx.tcx(), &output);
625+
let output = bcx.tcx().normalize_associated_type(&output);
627626

628627
let extra_args = match args {
629628
ArgExprs(args) if abi != Abi::RustCall => {

src/librustc_trans/closure.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use arena::TypedArena;
1212
use back::symbol_names;
1313
use llvm::{ValueRef, get_param, get_params};
1414
use rustc::hir::def_id::DefId;
15-
use rustc::infer::{self, InferCtxt};
15+
use rustc::infer::InferCtxt;
1616
use rustc::traits::ProjectionMode;
1717
use abi::{Abi, FnType};
1818
use adt;
@@ -158,7 +158,7 @@ fn get_or_create_closure_declaration<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
158158
let infcx = InferCtxt::normalizing(tcx, &tcx.tables, ProjectionMode::Any);
159159
let sig = &infcx.closure_type(closure_id, &substs).sig;
160160
let sig = tcx.erase_late_bound_regions(sig);
161-
let sig = infer::normalize_associated_type(tcx, &sig);
161+
let sig = tcx.normalize_associated_type(&sig);
162162
let closure_type = tcx.mk_closure_from_closure_substs(closure_id, Box::new(substs));
163163
let function_type = tcx.mk_fn_ptr(ty::BareFnTy {
164164
unsafety: hir::Unsafety::Normal,
@@ -224,7 +224,7 @@ pub fn trans_closure_expr<'a, 'tcx>(dest: Dest<'a, 'tcx>,
224224
let function_type = infcx.closure_type(closure_def_id, closure_substs);
225225

226226
let sig = tcx.erase_late_bound_regions(&function_type.sig);
227-
let sig = infer::normalize_associated_type(ccx.tcx(), &sig);
227+
let sig = ccx.tcx().normalize_associated_type(&sig);
228228

229229
let closure_type = tcx.mk_closure_from_closure_substs(closure_def_id,
230230
Box::new(closure_substs.clone()));
@@ -369,7 +369,7 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
369369
sig.0.inputs[0] = closure_ty;
370370

371371
let sig = tcx.erase_late_bound_regions(&sig);
372-
let sig = infer::normalize_associated_type(ccx.tcx(), &sig);
372+
let sig = ccx.tcx().normalize_associated_type(&sig);
373373
let fn_ty = FnType::new(ccx, abi, &sig, &[]);
374374

375375
let llonce_fn_ty = tcx.mk_fn_ptr(ty::BareFnTy {

src/librustc_trans/debuginfo/metadata.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use llvm::{self, ValueRef};
2424
use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor, DICompositeType};
2525

2626
use rustc::hir::def_id::DefId;
27-
use rustc::infer;
2827
use rustc::hir::pat_util;
2928
use rustc::ty::subst;
3029
use rustc::hir::map as hir_map;
@@ -263,7 +262,7 @@ impl<'tcx> TypeMap<'tcx> {
263262
unique_type_id.push_str(" fn(");
264263

265264
let sig = cx.tcx().erase_late_bound_regions(sig);
266-
let sig = infer::normalize_associated_type(cx.tcx(), &sig);
265+
let sig = cx.tcx().normalize_associated_type(&sig);
267266

268267
for &parameter_type in &sig.inputs {
269268
let parameter_type_id =

src/librustc_trans/debuginfo/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use rustc::hir;
3434
use abi::Abi;
3535
use common::{NodeIdAndSpan, CrateContext, FunctionContext, Block, BlockAndBuilder};
3636
use monomorphize::Instance;
37-
use rustc::infer::normalize_associated_type;
3837
use rustc::ty::{self, Ty};
3938
use session::config::{self, FullDebugInfo, LimitedDebugInfo, NoDebugInfo};
4039
use util::nodemap::{DefIdMap, NodeMap, FnvHashMap, FnvHashSet};
@@ -369,7 +368,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
369368

370369
name_to_append_suffix_to.push('<');
371370
for (i, &actual_type) in actual_types.iter().enumerate() {
372-
let actual_type = normalize_associated_type(cx.tcx(), &actual_type);
371+
let actual_type = cx.tcx().normalize_associated_type(&actual_type);
373372
// Add actual type name to <...> clause of function name
374373
let actual_type_name = compute_debuginfo_type_name(cx,
375374
actual_type,
@@ -385,7 +384,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
385384
// Again, only create type information if full debuginfo is enabled
386385
let template_params: Vec<_> = if cx.sess().opts.debuginfo == FullDebugInfo {
387386
generics.types.as_slice().iter().enumerate().map(|(i, param)| {
388-
let actual_type = normalize_associated_type(cx.tcx(), &actual_types[i]);
387+
let actual_type = cx.tcx().normalize_associated_type(&actual_types[i]);
389388
let actual_type_metadata = type_metadata(cx, actual_type, codemap::DUMMY_SP);
390389
let name = CString::new(param.name.as_str().as_bytes()).unwrap();
391390
unsafe {

src/librustc_trans/debuginfo/type_names.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
use common::CrateContext;
1414
use rustc::hir::def_id::DefId;
15-
use rustc::infer;
1615
use rustc::ty::subst;
1716
use rustc::ty::{self, Ty};
1817

@@ -114,7 +113,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
114113
output.push_str("fn(");
115114

116115
let sig = cx.tcx().erase_late_bound_regions(sig);
117-
let sig = infer::normalize_associated_type(cx.tcx(), &sig);
116+
let sig = cx.tcx().normalize_associated_type(&sig);
118117
if !sig.inputs.is_empty() {
119118
for &parameter_type in &sig.inputs {
120119
push_debuginfo_type_name(cx, parameter_type, true, output);

src/librustc_trans/declare.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
//! * When in doubt, define.
2222
use llvm::{self, ValueRef};
2323
use rustc::ty;
24-
use rustc::infer;
2524
use abi::{Abi, FnType};
2625
use attributes;
2726
use context::CrateContext;
@@ -105,7 +104,7 @@ pub fn declare_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, name: &str,
105104
debug!("declare_rust_fn(name={:?}, fn_type={:?})", name, fn_type);
106105
let abi = fn_type.fn_abi();
107106
let sig = ccx.tcx().erase_late_bound_regions(fn_type.fn_sig());
108-
let sig = infer::normalize_associated_type(ccx.tcx(), &sig);
107+
let sig = ccx.tcx().normalize_associated_type(&sig);
109108
debug!("declare_rust_fn (after region erasure) sig={:?}", sig);
110109

111110
let fty = FnType::new(ccx, abi, &sig, &[]);

src/librustc_trans/intrinsic.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use intrinsics::{self, Intrinsic};
1515
use libc;
1616
use llvm;
1717
use llvm::{ValueRef, TypeKind};
18-
use rustc::infer;
1918
use rustc::ty::subst;
2019
use rustc::ty::subst::FnSpace;
2120
use abi::{Abi, FnType};
@@ -114,7 +113,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
114113
let (def_id, substs, sig) = match callee_ty.sty {
115114
ty::TyFnDef(def_id, substs, fty) => {
116115
let sig = tcx.erase_late_bound_regions(&fty.sig);
117-
(def_id, substs, infer::normalize_associated_type(tcx, &sig))
116+
(def_id, substs, tcx.normalize_associated_type(&sig))
118117
}
119118
_ => bug!("expected fn item type, found {}", callee_ty)
120119
};
@@ -1352,7 +1351,7 @@ fn generic_simd_intrinsic<'blk, 'tcx, 'a>
13521351

13531352
let tcx = bcx.tcx();
13541353
let sig = tcx.erase_late_bound_regions(callee_ty.fn_sig());
1355-
let sig = infer::normalize_associated_type(tcx, &sig);
1354+
let sig = tcx.normalize_associated_type(&sig);
13561355
let arg_tys = sig.inputs;
13571356

13581357
// every intrinsic takes a SIMD vector as its first argument

src/librustc_trans/meth.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use arena::TypedArena;
1414
use back::symbol_names;
1515
use llvm::{ValueRef, get_params};
1616
use rustc::hir::def_id::DefId;
17-
use rustc::infer::{self, InferCtxt};
17+
use rustc::infer::InferCtxt;
1818
use rustc::ty::subst::{FnSpace, Subst, Substs};
1919
use rustc::ty::subst;
2020
use rustc::traits::{self, ProjectionMode};
@@ -86,7 +86,7 @@ pub fn trans_object_shim<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>,
8686
method_ty);
8787

8888
let sig = tcx.erase_late_bound_regions(&method_ty.fn_sig());
89-
let sig = infer::normalize_associated_type(tcx, &sig);
89+
let sig = tcx.normalize_associated_type(&sig);
9090
let fn_ty = FnType::new(ccx, method_ty.fn_abi(), &sig, &[]);
9191

9292
let function_name =

src/librustc_trans/monomorphize.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use back::symbol_names;
1212
use llvm::ValueRef;
1313
use llvm;
1414
use rustc::hir::def_id::DefId;
15-
use rustc::infer::normalize_associated_type;
1615
use rustc::ty::subst;
1716
use rustc::ty::subst::{Subst, Substs};
1817
use rustc::ty::{self, Ty, TypeFoldable, TyCtxt};
@@ -197,7 +196,7 @@ pub fn apply_param_substs<'tcx,T>(tcx: &TyCtxt<'tcx>,
197196
where T : TypeFoldable<'tcx>
198197
{
199198
let substituted = value.subst(tcx, param_substs);
200-
normalize_associated_type(tcx, &substituted)
199+
tcx.normalize_associated_type(&substituted)
201200
}
202201

203202

@@ -207,5 +206,5 @@ pub fn field_ty<'tcx>(tcx: &TyCtxt<'tcx>,
207206
f: ty::FieldDef<'tcx>)
208207
-> Ty<'tcx>
209208
{
210-
normalize_associated_type(tcx, &f.ty(tcx, param_substs))
209+
tcx.normalize_associated_type(&f.ty(tcx, param_substs))
211210
}

src/librustc_trans/type_of.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#![allow(non_camel_case_types)]
1212

1313
use rustc::hir::def_id::DefId;
14-
use rustc::infer::{self, InferCtxt};
14+
use rustc::infer::InferCtxt;
1515
use rustc::ty::subst;
1616
use abi::FnType;
1717
use adt;
@@ -296,7 +296,7 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) ->
296296
ty::TyFnDef(..) => Type::nil(cx),
297297
ty::TyFnPtr(f) => {
298298
let sig = cx.tcx().erase_late_bound_regions(&f.sig);
299-
let sig = infer::normalize_associated_type(cx.tcx(), &sig);
299+
let sig = cx.tcx().normalize_associated_type(&sig);
300300
FnType::new(cx, f.abi, &sig, &[]).llvm_type(cx).ptr_to()
301301
}
302302
ty::TyTuple(ref tys) if tys.is_empty() => Type::nil(cx),

0 commit comments

Comments
 (0)