From a68ed060bdab2d4c5d36062cda24f89d22488271 Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 1 May 2019 23:09:53 +0100 Subject: [PATCH] Split `ct_err` out into `CommonConsts` Co-Authored-By: Gabriel Smith --- src/librustc/infer/resolve.rs | 2 +- src/librustc/ty/context.rs | 25 +++++++++++++++++++++++-- src/librustc_typeck/check/writeback.rs | 4 ++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/librustc/infer/resolve.rs b/src/librustc/infer/resolve.rs index 61563a8ba26..079385368f8 100644 --- a/src/librustc/infer/resolve.rs +++ b/src/librustc/infer/resolve.rs @@ -220,7 +220,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for FullTypeResolver<'a, 'gcx, 'tcx> match c.val { ConstValue::Infer(InferConst::Var(vid)) => { self.err = Some(FixupError::UnresolvedConst(vid)); - return self.tcx().types.ct_err; + return self.tcx().consts.err; } ConstValue::Infer(InferConst::Fresh(_)) => { bug!("Unexpected const in full const resolver: {:?}", c); diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index e7b6a0ff4f4..c07175d9451 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -231,8 +231,10 @@ pub struct CommonLifetimes<'tcx> { pub re_empty: Region<'tcx>, pub re_static: Region<'tcx>, pub re_erased: Region<'tcx>, +} - pub ct_err: &'tcx Const<'tcx>, +pub struct CommonConsts<'tcx> { + pub err: &'tcx Const<'tcx>, } pub struct LocalTableInContext<'a, V: 'a> { @@ -945,7 +947,7 @@ impl<'tcx> CommonTypes<'tcx> { bool: mk(Bool), char: mk(Char), never: mk(Never), - err, + err: mk(Error), isize: mk(Int(ast::IntTy::Isize)), i8: mk(Int(ast::IntTy::I8)), i16: mk(Int(ast::IntTy::I16)), @@ -982,6 +984,20 @@ impl<'tcx> CommonLifetimes<'tcx> { } } +impl<'tcx> CommonConsts<'tcx> { + fn new(interners: &CtxtInterners<'tcx>, types: &CommonTypes<'tcx>) -> CommonConsts<'tcx> { + let mk_const = |c| { + interners.const_.borrow_mut().intern(c, |c| { + Interned(interners.arena.alloc(c)) + }).0 + }; + + CommonConsts { + err: mk_const(ty::Const::zero_sized(types.err)), + } + } +} + // This struct contains information regarding the `ReFree(FreeRegion)` corresponding to a lifetime // conflict. #[derive(Debug)] @@ -1032,6 +1048,9 @@ pub struct GlobalCtxt<'tcx> { /// Common lifetimes, pre-interned for your convenience. pub lifetimes: CommonLifetimes<'tcx>, + /// Common consts, pre-interned for your convenience. + pub consts: CommonConsts<'tcx>, + /// Map indicating what traits are in scope for places where this /// is relevant; generated by resolve. trait_map: FxHashMap TyCtxt<'a, 'gcx, 'tcx> { let interners = CtxtInterners::new(&arenas.interner); let common_types = CommonTypes::new(&interners); let common_lifetimes = CommonLifetimes::new(&interners); + let common_consts = CommonConsts::new(&interners, &common_types); let dep_graph = hir.dep_graph.clone(); let max_cnum = cstore.crates_untracked().iter().map(|c| c.as_usize()).max().unwrap_or(0); let mut providers = IndexVec::from_elem_n(extern_providers, max_cnum + 1); @@ -1286,6 +1306,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { dep_graph, types: common_types, lifetimes: common_lifetimes, + consts: common_consts, trait_map, export_map: resolutions.export_map.into_iter().map(|(k, v)| { let exports: Vec<_> = v.into_iter().map(|e| { diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index e13651d253d..f9d83146e30 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -594,7 +594,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { ), ) .emit(); - return self.tcx().types.ct_err; + return self.tcx().consts.err; } ct } @@ -864,7 +864,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Resolver<'cx, 'gcx, 'tcx> { ); // FIXME: we'd like to use `self.report_error`, but it doesn't yet // accept a &'tcx ty::Const. - self.tcx().types.ct_err + self.tcx().consts.err } } }