Skip to content

Commit cef1efd

Browse files
committed
fully_perform_op_raw out of TypeChecker
1 parent 5771665 commit cef1efd

File tree

1 file changed

+75
-31
lines changed

1 file changed

+75
-31
lines changed

compiler/rustc_borrowck/src/type_check/canonical.rs

Lines changed: 75 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use std::fmt;
22

33
use rustc_errors::ErrorGuaranteed;
44
use rustc_infer::infer::canonical::Canonical;
5+
use rustc_infer::infer::outlives::env::RegionBoundPairs;
56
use rustc_middle::bug;
6-
use rustc_middle::mir::ConstraintCategory;
7+
use rustc_middle::mir::{Body, ConstraintCategory};
78
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, Upcast};
89
use rustc_span::Span;
910
use rustc_span::def_id::DefId;
@@ -14,7 +15,69 @@ use rustc_trait_selection::traits::query::type_op::{self, TypeOpOutput};
1415
use tracing::{debug, instrument};
1516

1617
use super::{Locations, NormalizeLocation, TypeChecker};
18+
use crate::BorrowckInferCtxt;
1719
use crate::diagnostics::ToUniverseInfo;
20+
use crate::type_check::{MirTypeckRegionConstraints, constraint_conversion};
21+
use crate::universal_regions::UniversalRegions;
22+
23+
#[instrument(skip(infcx, constraints, op), level = "trace")]
24+
pub(crate) fn fully_perform_op_raw<'tcx, R: fmt::Debug, Op>(
25+
infcx: &BorrowckInferCtxt<'tcx>,
26+
body: &Body<'tcx>,
27+
universal_regions: &UniversalRegions<'tcx>,
28+
region_bound_pairs: &RegionBoundPairs<'tcx>,
29+
known_type_outlives_obligations: &[ty::PolyTypeOutlivesPredicate<'tcx>],
30+
constraints: &mut MirTypeckRegionConstraints<'tcx>,
31+
locations: Locations,
32+
category: ConstraintCategory<'tcx>,
33+
op: Op,
34+
) -> Result<R, ErrorGuaranteed>
35+
where
36+
Op: type_op::TypeOp<'tcx, Output = R>,
37+
Op::ErrorInfo: ToUniverseInfo<'tcx>,
38+
{
39+
let old_universe = infcx.universe();
40+
41+
let TypeOpOutput { output, constraints: query_constraints, error_info } =
42+
op.fully_perform(infcx, locations.span(body))?;
43+
if cfg!(debug_assertions) {
44+
let data = infcx.take_and_reset_region_constraints();
45+
if !data.is_empty() {
46+
panic!("leftover region constraints: {data:#?}");
47+
}
48+
}
49+
50+
debug!(?output, ?query_constraints);
51+
52+
if let Some(data) = query_constraints {
53+
constraint_conversion::ConstraintConversion::new(
54+
infcx,
55+
universal_regions,
56+
region_bound_pairs,
57+
infcx.param_env,
58+
known_type_outlives_obligations,
59+
locations,
60+
locations.span(body),
61+
category,
62+
constraints,
63+
)
64+
.convert_all(data);
65+
}
66+
67+
// If the query has created new universes and errors are going to be emitted, register the
68+
// cause of these new universes for improved diagnostics.
69+
let universe = infcx.universe();
70+
if old_universe != universe
71+
&& let Some(error_info) = error_info
72+
{
73+
let universe_info = error_info.to_universe_info(old_universe);
74+
for u in (old_universe + 1)..=universe {
75+
constraints.universe_causes.insert(u, universe_info.clone());
76+
}
77+
}
78+
79+
Ok(output)
80+
}
1881

1982
impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2083
/// Given some operation `op` that manipulates types, proves
@@ -38,36 +101,17 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
38101
Op: type_op::TypeOp<'tcx, Output = R>,
39102
Op::ErrorInfo: ToUniverseInfo<'tcx>,
40103
{
41-
let old_universe = self.infcx.universe();
42-
43-
let TypeOpOutput { output, constraints, error_info } =
44-
op.fully_perform(self.infcx, locations.span(self.body))?;
45-
if cfg!(debug_assertions) {
46-
let data = self.infcx.take_and_reset_region_constraints();
47-
if !data.is_empty() {
48-
panic!("leftover region constraints: {data:#?}");
49-
}
50-
}
51-
52-
debug!(?output, ?constraints);
53-
54-
if let Some(data) = constraints {
55-
self.push_region_constraints(locations, category, data);
56-
}
57-
58-
// If the query has created new universes and errors are going to be emitted, register the
59-
// cause of these new universes for improved diagnostics.
60-
let universe = self.infcx.universe();
61-
if old_universe != universe
62-
&& let Some(error_info) = error_info
63-
{
64-
let universe_info = error_info.to_universe_info(old_universe);
65-
for u in (old_universe + 1)..=universe {
66-
self.constraints.universe_causes.insert(u, universe_info.clone());
67-
}
68-
}
69-
70-
Ok(output)
104+
fully_perform_op_raw(
105+
self.infcx,
106+
self.body,
107+
self.universal_regions,
108+
self.region_bound_pairs,
109+
self.known_type_outlives_obligations,
110+
self.constraints,
111+
locations,
112+
category,
113+
op,
114+
)
71115
}
72116

73117
pub(super) fn instantiate_canonical<T>(

0 commit comments

Comments
 (0)