Skip to content

Commit 15bc4a3

Browse files
committed
Address nits
1 parent e5b3684 commit 15bc4a3

File tree

14 files changed

+92
-151
lines changed

14 files changed

+92
-151
lines changed

src/librustc/middle/astencode.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,12 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
10511051
var_id: var_id,
10521052
closure_expr_id: id
10531053
};
1054-
let upvar_capture = tcx.tables.borrow().upvar_capture_map.get(&upvar_id).unwrap().clone();
1054+
let upvar_capture = tcx.tables
1055+
.borrow()
1056+
.upvar_capture_map
1057+
.get(&upvar_id)
1058+
.unwrap()
1059+
.clone();
10551060
var_id.encode(rbml_w);
10561061
upvar_capture.encode(rbml_w);
10571062
})

src/librustc/middle/infer/mod.rs

+30-12
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ pub struct InferCtxt<'a, 'tcx: 'a> {
8787

8888
pub parameter_environment: ty::ParameterEnvironment<'a, 'tcx>,
8989

90+
// This is a temporary field used for toggling on normalization in the inference context,
91+
// as we move towards the approach described here:
92+
// https://internals.rust-lang.org/t/flattening-the-contexts-for-fun-and-profit/2293
93+
// At a point sometime in the future normalization will be done by the typing context
94+
// directly.
9095
normalize: bool,
9196

9297
err_count_on_creation: usize,
@@ -334,7 +339,7 @@ pub fn new_infer_ctxt<'a, 'tcx>(tcx: &'a ty::ctxt<'tcx>,
334339
float_unification_table: RefCell::new(UnificationTable::new()),
335340
region_vars: RegionVarBindings::new(tcx),
336341
parameter_environment: param_env.unwrap_or(tcx.empty_parameter_environment()),
337-
normalize: true,
342+
normalize: false,
338343
err_count_on_creation: tcx.sess.err_count()
339344
}
340345
}
@@ -487,7 +492,8 @@ impl<'a, 'tcx> mc::Typer<'tcx> for InferCtxt<'a, 'tcx> {
487492
}
488493

489494
fn adjustments(&self) -> Ref<NodeMap<ty::AutoAdjustment<'tcx>>> {
490-
fn project_adjustments<'a, 'tcx>(tables: &'a ty::Tables<'tcx>) -> &'a NodeMap<ty::AutoAdjustment<'tcx>> {
495+
fn project_adjustments<'a, 'tcx>(tables: &'a ty::Tables<'tcx>)
496+
-> &'a NodeMap<ty::AutoAdjustment<'tcx>> {
491497
&tables.adjustments
492498
}
493499

@@ -524,8 +530,7 @@ impl<'a, 'tcx> ty::ClosureTyper<'tcx> for InferCtxt<'a, 'tcx> {
524530
substs: &subst::Substs<'tcx>)
525531
-> ty::ClosureTy<'tcx>
526532
{
527-
// the substitutions in `substs` are already monomorphized,
528-
// but we still must normalize associated types
533+
529534
let closure_ty = self.tables
530535
.borrow()
531536
.closure_tys
@@ -534,8 +539,15 @@ impl<'a, 'tcx> ty::ClosureTyper<'tcx> for InferCtxt<'a, 'tcx> {
534539
.subst(self.tcx, substs);
535540

536541
if self.normalize {
537-
// NOTE: this flag is *always* set to false currently
538-
panic!("issue XXXX: must finish fulfill refactor") // normalize_associated_type(self.param_env.tcx, &closure_ty)
542+
// NOTE: this flag is currently *always* set to false, we are slowly folding
543+
// normalization into this trait and will come back to remove this in the near
544+
// future.
545+
546+
// code from NormalizingClosureTyper:
547+
// the substitutions in `substs` are already monomorphized,
548+
// but we still must normalize associated types
549+
// normalize_associated_type(self.param_env.tcx, &closure_ty)
550+
panic!("see issue 26597: fufillment context refactor must occur")
539551
} else {
540552
closure_ty
541553
}
@@ -546,13 +558,18 @@ impl<'a, 'tcx> ty::ClosureTyper<'tcx> for InferCtxt<'a, 'tcx> {
546558
substs: &Substs<'tcx>)
547559
-> Option<Vec<ty::ClosureUpvar<'tcx>>>
548560
{
549-
// the substitutions in `substs` are already monomorphized,
550-
// but we still must normalize associated types
551-
let result = ty::ctxt::closure_upvars(self, def_id, substs)
561+
let result = ty::ctxt::closure_upvars(self, def_id, substs);
552562

553563
if self.normalize {
554-
// NOTE: this flag is *always* set to false currently
555-
panic!("issue XXXX: must finish fulfill refactor") // monomorphize::normalize_associated_type(self.param_env.tcx, &result)
564+
// NOTE: this flag is currently *always* set to false, we are slowly folding
565+
// normalization into this trait and will come back to remove this in the near
566+
// future.
567+
568+
// code from NormalizingClosureTyper:
569+
// the substitutions in `substs` are already monomorphized,
570+
// but we still must normalize associated types
571+
// monomorphize::normalize_associated_type(self.param_env.tcx, &result)
572+
panic!("see issue 26597: fufillment context refactor must occur")
556573
} else {
557574
result
558575
}
@@ -1004,7 +1021,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10041021
match self.tables.borrow().node_types.get(&id) {
10051022
Some(&t) => t,
10061023
// FIXME
1007-
None if self.tcx.sess.err_count() - self.err_count_on_creation != 0 => self.tcx.types.err,
1024+
None if self.tcx.sess.err_count() - self.err_count_on_creation != 0 =>
1025+
self.tcx.types.err,
10081026
None => {
10091027
self.tcx.sess.bug(
10101028
&format!("no type for node {}: {} in fcx",

src/librustc/middle/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ pub fn type_known_to_meet_builtin_bound<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
351351
}
352352
}
353353

354-
// TODO: this is gonna need to be removed ...
354+
// FIXME: this is gonna need to be removed ...
355355
/// Normalizes the parameter environment, reporting errors if they occur.
356356
pub fn normalize_param_env_or_error<'a,'tcx>(unnormalized_env: ty::ParameterEnvironment<'a,'tcx>,
357357
cause: ObligationCause<'tcx>)

src/librustc/middle/ty.rs

-78
Original file line numberDiff line numberDiff line change
@@ -3222,84 +3222,6 @@ impl<'tcx> CommonTypes<'tcx> {
32223222
}
32233223
}
32243224

3225-
/// Create a type context and call the closure with a `&ty::ctxt` reference
3226-
/// to the context. The closure enforces that the type context and any interned
3227-
/// value (types, substs, etc.) can only be used while `ty::tls` has a valid
3228-
/// reference to the context, to allow formatting values that need it.
3229-
pub fn with_ctxt<'tcx, F, R>(s: Session,
3230-
arenas: &'tcx CtxtArenas<'tcx>,
3231-
def_map: DefMap,
3232-
named_region_map: resolve_lifetime::NamedRegionMap,
3233-
map: ast_map::Map<'tcx>,
3234-
freevars: RefCell<FreevarMap>,
3235-
region_maps: RegionMaps,
3236-
lang_items: middle::lang_items::LanguageItems,
3237-
stability: stability::Index<'tcx>,
3238-
f: F) -> (Session, R)
3239-
where F: FnOnce(&ctxt<'tcx>) -> R
3240-
{
3241-
let mut interner = FnvHashMap();
3242-
let common_types = CommonTypes::new(&arenas.type_, &mut interner);
3243-
3244-
tls::enter(ctxt {
3245-
arenas: arenas,
3246-
interner: RefCell::new(interner),
3247-
substs_interner: RefCell::new(FnvHashMap()),
3248-
bare_fn_interner: RefCell::new(FnvHashMap()),
3249-
region_interner: RefCell::new(FnvHashMap()),
3250-
stability_interner: RefCell::new(FnvHashMap()),
3251-
types: common_types,
3252-
named_region_map: named_region_map,
3253-
region_maps: region_maps,
3254-
free_region_maps: RefCell::new(FnvHashMap()),
3255-
item_variance_map: RefCell::new(DefIdMap()),
3256-
variance_computed: Cell::new(false),
3257-
sess: s,
3258-
def_map: def_map,
3259-
tables: RefCell::new(Tables::empty()),
3260-
impl_trait_refs: RefCell::new(DefIdMap()),
3261-
trait_defs: RefCell::new(DefIdMap()),
3262-
predicates: RefCell::new(DefIdMap()),
3263-
super_predicates: RefCell::new(DefIdMap()),
3264-
fulfilled_predicates: RefCell::new(traits::FulfilledPredicates::new()),
3265-
map: map,
3266-
freevars: freevars,
3267-
tcache: RefCell::new(DefIdMap()),
3268-
rcache: RefCell::new(FnvHashMap()),
3269-
tc_cache: RefCell::new(FnvHashMap()),
3270-
ast_ty_to_ty_cache: RefCell::new(NodeMap()),
3271-
enum_var_cache: RefCell::new(DefIdMap()),
3272-
impl_or_trait_items: RefCell::new(DefIdMap()),
3273-
trait_item_def_ids: RefCell::new(DefIdMap()),
3274-
trait_items_cache: RefCell::new(DefIdMap()),
3275-
ty_param_defs: RefCell::new(NodeMap()),
3276-
normalized_cache: RefCell::new(FnvHashMap()),
3277-
lang_items: lang_items,
3278-
provided_method_sources: RefCell::new(DefIdMap()),
3279-
struct_fields: RefCell::new(DefIdMap()),
3280-
destructor_for_type: RefCell::new(DefIdMap()),
3281-
destructors: RefCell::new(DefIdSet()),
3282-
inherent_impls: RefCell::new(DefIdMap()),
3283-
impl_items: RefCell::new(DefIdMap()),
3284-
used_unsafe: RefCell::new(NodeSet()),
3285-
used_mut_nodes: RefCell::new(NodeSet()),
3286-
populated_external_types: RefCell::new(DefIdSet()),
3287-
populated_external_primitive_impls: RefCell::new(DefIdSet()),
3288-
extern_const_statics: RefCell::new(DefIdMap()),
3289-
extern_const_variants: RefCell::new(DefIdMap()),
3290-
extern_const_fns: RefCell::new(DefIdMap()),
3291-
dependency_formats: RefCell::new(FnvHashMap()),
3292-
node_lint_levels: RefCell::new(FnvHashMap()),
3293-
transmute_restrictions: RefCell::new(Vec::new()),
3294-
stability: RefCell::new(stability),
3295-
selection_cache: traits::SelectionCache::new(),
3296-
repr_hint_cache: RefCell::new(DefIdMap()),
3297-
const_qualif_map: RefCell::new(NodeMap()),
3298-
custom_coerce_unsized_kinds: RefCell::new(DefIdMap()),
3299-
cast_kinds: RefCell::new(NodeMap()),
3300-
}, f)
3301-
}
3302-
33033225
struct FlagComputation {
33043226
flags: TypeFlags,
33053227

src/librustc_driver/driver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: Session,
602602
make_glob_map: resolve::MakeGlobMap,
603603
f: F)
604604
-> (Session, R)
605-
where F: FnOnce(&ty::ctxt<'tcx>,
605+
where F: for<'a> FnOnce(&'a ty::ctxt<'tcx>,
606606
ty::CrateAnalysis) -> R
607607
{
608608
let time_passes = sess.time_passes();

src/librustc_trans/trans/common.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,10 @@ impl<'blk, 'tcx> mc::Typer<'tcx> for BlockS<'blk, 'tcx> {
649649
}
650650

651651
fn adjustments<'a>(&'a self) -> Ref<NodeMap<ty::AutoAdjustment<'tcx>>> {
652-
fn project_adjustments<'a, 'tcx>(tables: &'a ty::Tables<'tcx>) -> &'a NodeMap<ty::AutoAdjustment<'tcx>> {
652+
// FIXME (@jroesch): this is becuase we currently have a HR inference problem
653+
// in the snapshot that causes this code not to work.
654+
fn project_adjustments<'a, 'tcx>(tables: &'a ty::Tables<'tcx>) ->
655+
&'a NodeMap<ty::AutoAdjustment<'tcx>> {
653656
&tables.adjustments
654657
}
655658

src/librustc_typeck/check/compare_method.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
240240
let trait_param_env = impl_param_env.with_caller_bounds(hybrid_preds.into_vec());
241241
let trait_param_env = traits::normalize_param_env_or_error(trait_param_env,
242242
normalize_cause.clone());
243-
// TODO (@jroesch) this seems ugly, but is a temporary change
243+
// FIXME(@jroesch) this seems ugly, but is a temporary change
244244
infcx.parameter_environment = trait_param_env;
245245

246246
debug!("compare_impl_method: trait_bounds={:?}",
@@ -362,7 +362,8 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
362362
// anyway, so it shouldn't be needed there either. Anyway, we can
363363
// always add more relations later (it's backwards compat).
364364
let mut free_regions = FreeRegionMap::new();
365-
free_regions.relate_free_regions_from_predicates(tcx, &infcx.parameter_environment.caller_bounds);
365+
free_regions.relate_free_regions_from_predicates(tcx,
366+
&infcx.parameter_environment.caller_bounds);
366367

367368
infcx.resolve_regions_and_report_errors(&free_regions, impl_m_body_id);
368369

src/librustc_typeck/check/method/confirm.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,8 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
528528
// expects. This is annoying and horrible. We
529529
// ought to recode this routine so it doesn't
530530
// (ab)use the normal type checking paths.
531-
let adj = self.fcx.inh.tables.borrow().adjustments.get(&base_expr.id).cloned();
531+
let adj = self.fcx.inh.tables.borrow().adjustments.get(&base_expr.id)
532+
.cloned();
532533
let (autoderefs, unsize) = match adj {
533534
Some(ty::AdjustDerefRef(adr)) => match adr.autoref {
534535
None => {

src/librustc_typeck/check/mod.rs

+6-42
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ use fmt_macros::{Parser, Piece, Position};
8787
use middle::astconv_util::{check_path_args, NO_TPS, NO_REGIONS};
8888
use middle::def;
8989
use middle::infer;
90-
use middle::mem_categorization as mc;
91-
use middle::mem_categorization::McResult;
9290
use middle::pat_util::{self, pat_id_map};
9391
use middle::privacy::{AllPublic, LastMod};
9492
use middle::region::{self, CodeExtent};
@@ -290,32 +288,6 @@ pub struct FnCtxt<'a, 'tcx: 'a> {
290288
ccx: &'a CrateCtxt<'a, 'tcx>,
291289
}
292290

293-
impl<'a, 'tcx> mc::Typer<'tcx> for FnCtxt<'a, 'tcx> {
294-
fn node_ty(&self, id: ast::NodeId) -> McResult<Ty<'tcx>> {
295-
let ty = self.node_ty(id);
296-
self.resolve_type_vars_or_error(&ty)
297-
}
298-
299-
fn expr_ty_adjusted(&self, expr: &ast::Expr) -> McResult<Ty<'tcx>> {
300-
let ty = self.adjust_expr_ty(expr, self.inh.tables.borrow().adjustments.get(&expr.id));
301-
self.resolve_type_vars_or_error(&ty)
302-
}
303-
304-
fn type_moves_by_default(&self, ty: Ty<'tcx>, span: Span) -> bool {
305-
let ty = self.infcx().resolve_type_vars_if_possible(&ty);
306-
!traits::type_known_to_meet_builtin_bound(self.infcx(), self, ty, ty::BoundCopy, span)
307-
}
308-
309-
fn node_method_ty(&self, method_call: ty::MethodCall)
310-
-> Option<Ty<'tcx>> {
311-
self.inh.tables
312-
.borrow()
313-
.method_map
314-
.get(&method_call)
315-
.map(|method| method.ty)
316-
.map(|ty| self.infcx().resolve_type_vars_if_possible(&ty))
317-
}
318-
319291
impl<'a, 'tcx> Inherited<'a, 'tcx> {
320292
fn new(tcx: &'a ty::ctxt<'tcx>,
321293
tables: &'a RefCell<ty::Tables<'tcx>>,
@@ -368,7 +340,8 @@ pub fn blank_fn_ctxt<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>,
368340
}
369341
}
370342

371-
fn static_inherited_fields<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>, tables: &'a RefCell<ty::Tables<'tcx>>)
343+
fn static_inherited_fields<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>,
344+
tables: &'a RefCell<ty::Tables<'tcx>>)
372345
-> Inherited<'a, 'tcx> {
373346
// It's kind of a kludge to manufacture a fake function context
374347
// and statement context, but we might as well do write the code only once
@@ -1271,16 +1244,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12711244
ty
12721245
}
12731246

1274-
/// Resolves all type variables in `t` and then, if any were left
1275-
/// unresolved, substitutes an error type. This is used after the
1276-
/// main checking when doing a second pass before writeback. The
1277-
/// justification is that writeback will produce an error for
1278-
/// these unconstrained type variables.
1279-
fn resolve_type_vars_or_error(&self, ty: &Ty<'tcx>) -> mc::McResult<Ty<'tcx>> {
1280-
let ty = self.infcx().resolve_type_vars_if_possible(ty);
1281-
if ty.has_infer_types() || ty.references_error() { Err(()) } else { Ok(ty) }
1282-
}
1283-
12841247
fn record_deferred_call_resolution(&self,
12851248
closure_def_id: ast::DefId,
12861249
r: DeferredCallResolutionHandler<'tcx>) {
@@ -1614,9 +1577,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16141577
}
16151578

16161579
pub fn item_substs(&self) -> Ref<NodeMap<ty::ItemSubsts<'tcx>>> {
1617-
// NOTE: @jroesch this is hack that appears to be fixed on nightly, will monitor if it changes
1618-
// when we upgrade the snapshot compiler
1619-
fn project_item_susbts<'a, 'tcx>(tables: &'a ty::Tables<'tcx>) -> &'a NodeMap<ty::ItemSubsts<'tcx>> {
1580+
// NOTE: @jroesch this is hack that appears to be fixed on nightly, will monitor if
1581+
// it changes when we upgrade the snapshot compiler
1582+
fn project_item_susbts<'a, 'tcx>(tables: &'a ty::Tables<'tcx>)
1583+
-> &'a NodeMap<ty::ItemSubsts<'tcx>> {
16201584
&tables.item_substs
16211585
}
16221586

src/librustc_typeck/check/regionck.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ pub fn regionck_expr(fcx: &FnCtxt, e: &ast::Expr) {
125125
pub fn regionck_item(fcx: &FnCtxt, item: &ast::Item) {
126126
let mut rcx = Rcx::new(fcx, RepeatingScope(item.id), item.id, Subject(item.id));
127127
let tcx = fcx.tcx();
128-
rcx.free_region_map.relate_free_regions_from_predicates(tcx, &fcx.inh.infcx.parameter_environment.caller_bounds);
128+
rcx.free_region_map
129+
.relate_free_regions_from_predicates(tcx, &fcx.infcx().parameter_environment.caller_bounds);
129130
rcx.visit_region_obligations(item.id);
130131
rcx.resolve_regions_and_report_errors();
131132
}
@@ -144,7 +145,8 @@ pub fn regionck_fn(fcx: &FnCtxt,
144145
}
145146

146147
let tcx = fcx.tcx();
147-
rcx.free_region_map.relate_free_regions_from_predicates(tcx, &fcx.inh.infcx.parameter_environment.caller_bounds);
148+
rcx.free_region_map
149+
.relate_free_regions_from_predicates(tcx, &fcx.infcx().parameter_environment.caller_bounds);
148150

149151
rcx.resolve_regions_and_report_errors();
150152

src/librustc_typeck/check/upvar.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ impl<'a,'tcx> SeedBorrowKind<'a,'tcx> {
131131
let closure_def_id = ast_util::local_def(expr.id);
132132
if !self.fcx.inh.tables.borrow().closure_kinds.contains_key(&closure_def_id) {
133133
self.closures_with_inferred_kinds.insert(expr.id);
134-
self.fcx.inh.tables.borrow_mut().closure_kinds.insert(closure_def_id, ty::FnClosureKind);
134+
self.fcx.inh.tables.borrow_mut().closure_kinds
135+
.insert(closure_def_id, ty::FnClosureKind);
135136
debug!("check_closure: adding closure_id={:?} to closures_with_inferred_kinds",
136137
closure_def_id);
137138
}
@@ -267,7 +268,10 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> {
267268
// to move out of an upvar, this must be a FnOnce closure
268269
self.adjust_closure_kind(upvar_id.closure_expr_id, ty::FnOnceClosureKind);
269270

270-
let upvar_capture_map = &mut self.fcx.inh.tables.borrow_mut().upvar_capture_map;
271+
let upvar_capture_map = &mut self.fcx
272+
.inh
273+
.tables.borrow_mut()
274+
.upvar_capture_map;
271275
upvar_capture_map.insert(upvar_id, ty::UpvarCapture::ByValue);
272276
}
273277
mc::NoteClosureEnv(upvar_id) => {

0 commit comments

Comments
 (0)