Rollup merge of #100761 - lcnr:mir-typeck-cleanup, r=compiler-errors
some general mir typeck cleanup this pr contains the parts of #95763 which already work correctly. the remaining commits of that PR have some issues which are more complex to fix. r? types
This commit is contained in:
commit
9cf3bacfb2
3 changed files with 59 additions and 91 deletions
|
@ -90,12 +90,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
locations: Locations,
|
locations: Locations,
|
||||||
category: ConstraintCategory<'tcx>,
|
category: ConstraintCategory<'tcx>,
|
||||||
) {
|
) {
|
||||||
self.prove_predicates(
|
self.prove_predicate(
|
||||||
Some(ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
|
ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
|
||||||
trait_ref,
|
trait_ref,
|
||||||
constness: ty::BoundConstness::NotConst,
|
constness: ty::BoundConstness::NotConst,
|
||||||
polarity: ty::ImplPolarity::Positive,
|
polarity: ty::ImplPolarity::Positive,
|
||||||
}))),
|
}))
|
||||||
|
.to_predicate(self.tcx()),
|
||||||
locations,
|
locations,
|
||||||
category,
|
category,
|
||||||
);
|
);
|
||||||
|
|
|
@ -178,19 +178,29 @@ pub(crate) fn type_check<'mir, 'tcx>(
|
||||||
upvars,
|
upvars,
|
||||||
};
|
};
|
||||||
|
|
||||||
let opaque_type_values = type_check_internal(
|
let mut checker = TypeChecker::new(
|
||||||
infcx,
|
infcx,
|
||||||
param_env,
|
|
||||||
body,
|
body,
|
||||||
promoted,
|
param_env,
|
||||||
®ion_bound_pairs,
|
®ion_bound_pairs,
|
||||||
implicit_region_bound,
|
implicit_region_bound,
|
||||||
&mut borrowck_context,
|
&mut borrowck_context,
|
||||||
|mut cx| {
|
);
|
||||||
debug!("inside extra closure of type_check_internal");
|
|
||||||
cx.equate_inputs_and_outputs(&body, universal_regions, &normalized_inputs_and_output);
|
let errors_reported = {
|
||||||
|
let mut verifier = TypeVerifier::new(&mut checker, promoted);
|
||||||
|
verifier.visit_body(&body);
|
||||||
|
verifier.errors_reported
|
||||||
|
};
|
||||||
|
|
||||||
|
if !errors_reported {
|
||||||
|
// if verifier failed, don't do further checks to avoid ICEs
|
||||||
|
checker.typeck_mir(body);
|
||||||
|
}
|
||||||
|
|
||||||
|
checker.equate_inputs_and_outputs(&body, universal_regions, &normalized_inputs_and_output);
|
||||||
liveness::generate(
|
liveness::generate(
|
||||||
&mut cx,
|
&mut checker,
|
||||||
body,
|
body,
|
||||||
elements,
|
elements,
|
||||||
flow_inits,
|
flow_inits,
|
||||||
|
@ -199,14 +209,14 @@ pub(crate) fn type_check<'mir, 'tcx>(
|
||||||
use_polonius,
|
use_polonius,
|
||||||
);
|
);
|
||||||
|
|
||||||
translate_outlives_facts(&mut cx);
|
translate_outlives_facts(&mut checker);
|
||||||
let opaque_type_values =
|
let opaque_type_values = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
|
||||||
infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
|
|
||||||
|
|
||||||
opaque_type_values
|
let opaque_type_values = opaque_type_values
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(opaque_type_key, decl)| {
|
.map(|(opaque_type_key, decl)| {
|
||||||
cx.fully_perform_op(
|
checker
|
||||||
|
.fully_perform_op(
|
||||||
Locations::All(body.span),
|
Locations::All(body.span),
|
||||||
ConstraintCategory::OpaqueType,
|
ConstraintCategory::OpaqueType,
|
||||||
CustomTypeOp::new(
|
CustomTypeOp::new(
|
||||||
|
@ -224,11 +234,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
|
let mut hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
|
||||||
trace!(
|
trace!("finalized opaque type {:?} to {:#?}", opaque_type_key, hidden_type.ty.kind());
|
||||||
"finalized opaque type {:?} to {:#?}",
|
|
||||||
opaque_type_key,
|
|
||||||
hidden_type.ty.kind()
|
|
||||||
);
|
|
||||||
if hidden_type.has_infer_types_or_consts() {
|
if hidden_type.has_infer_types_or_consts() {
|
||||||
infcx.tcx.sess.delay_span_bug(
|
infcx.tcx.sess.delay_span_bug(
|
||||||
decl.hidden_type.span,
|
decl.hidden_type.span,
|
||||||
|
@ -239,50 +245,11 @@ pub(crate) fn type_check<'mir, 'tcx>(
|
||||||
|
|
||||||
(opaque_type_key, (hidden_type, decl.origin))
|
(opaque_type_key, (hidden_type, decl.origin))
|
||||||
})
|
})
|
||||||
.collect()
|
.collect();
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
MirTypeckResults { constraints, universal_region_relations, opaque_type_values }
|
MirTypeckResults { constraints, universal_region_relations, opaque_type_values }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(
|
|
||||||
skip(infcx, body, promoted, region_bound_pairs, borrowck_context, extra),
|
|
||||||
level = "debug"
|
|
||||||
)]
|
|
||||||
fn type_check_internal<'a, 'tcx, R>(
|
|
||||||
infcx: &'a InferCtxt<'a, 'tcx>,
|
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
|
||||||
body: &'a Body<'tcx>,
|
|
||||||
promoted: &'a IndexVec<Promoted, Body<'tcx>>,
|
|
||||||
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
|
|
||||||
implicit_region_bound: ty::Region<'tcx>,
|
|
||||||
borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>,
|
|
||||||
extra: impl FnOnce(TypeChecker<'a, 'tcx>) -> R,
|
|
||||||
) -> R {
|
|
||||||
debug!("body: {:#?}", body);
|
|
||||||
let mut checker = TypeChecker::new(
|
|
||||||
infcx,
|
|
||||||
body,
|
|
||||||
param_env,
|
|
||||||
region_bound_pairs,
|
|
||||||
implicit_region_bound,
|
|
||||||
borrowck_context,
|
|
||||||
);
|
|
||||||
let errors_reported = {
|
|
||||||
let mut verifier = TypeVerifier::new(&mut checker, promoted);
|
|
||||||
verifier.visit_body(&body);
|
|
||||||
verifier.errors_reported
|
|
||||||
};
|
|
||||||
|
|
||||||
if !errors_reported {
|
|
||||||
// if verifier failed, don't do further checks to avoid ICEs
|
|
||||||
checker.typeck_mir(body);
|
|
||||||
}
|
|
||||||
|
|
||||||
extra(checker)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn translate_outlives_facts(typeck: &mut TypeChecker<'_, '_>) {
|
fn translate_outlives_facts(typeck: &mut TypeChecker<'_, '_>) {
|
||||||
let cx = &mut typeck.borrowck_context;
|
let cx = &mut typeck.borrowck_context;
|
||||||
if let Some(facts) = cx.all_facts {
|
if let Some(facts) = cx.all_facts {
|
||||||
|
@ -1911,7 +1878,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&Rvalue::NullaryOp(_, ty) => {
|
&Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => {
|
||||||
let trait_ref = ty::TraitRef {
|
let trait_ref = ty::TraitRef {
|
||||||
def_id: tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
|
def_id: tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
|
||||||
substs: tcx.mk_substs_trait(ty, &[]),
|
substs: tcx.mk_substs_trait(ty, &[]),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue