Skip to content

Commit 009cd9c

Browse files
committedDec 19, 2023
Remove unnecessary param-env from lexical region resolution and fully structural relations
1 parent e6d6b1d commit 009cd9c

File tree

9 files changed

+28
-68
lines changed

9 files changed

+28
-68
lines changed
 

Diff for: ‎compiler/rustc_borrowck/src/region_infer/mod.rs

+6-23
Original file line numberDiff line numberDiff line change
@@ -674,13 +674,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
674674
// eagerly.
675675
let mut outlives_requirements = infcx.tcx.is_typeck_child(mir_def_id).then(Vec::new);
676676

677-
self.check_type_tests(
678-
infcx,
679-
param_env,
680-
body,
681-
outlives_requirements.as_mut(),
682-
&mut errors_buffer,
683-
);
677+
self.check_type_tests(infcx, body, outlives_requirements.as_mut(), &mut errors_buffer);
684678

685679
debug!(?errors_buffer);
686680
debug!(?outlives_requirements);
@@ -938,7 +932,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
938932
fn check_type_tests(
939933
&self,
940934
infcx: &InferCtxt<'tcx>,
941-
param_env: ty::ParamEnv<'tcx>,
942935
body: &Body<'tcx>,
943936
mut propagated_outlives_requirements: Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
944937
errors_buffer: &mut RegionErrors<'tcx>,
@@ -956,7 +949,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
956949
let generic_ty = type_test.generic_kind.to_ty(tcx);
957950
if self.eval_verify_bound(
958951
infcx,
959-
param_env,
960952
generic_ty,
961953
type_test.lower_bound,
962954
&type_test.verify_bound,
@@ -967,7 +959,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
967959
if let Some(propagated_outlives_requirements) = &mut propagated_outlives_requirements {
968960
if self.try_promote_type_test(
969961
infcx,
970-
param_env,
971962
body,
972963
type_test,
973964
propagated_outlives_requirements,
@@ -1025,7 +1016,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
10251016
fn try_promote_type_test(
10261017
&self,
10271018
infcx: &InferCtxt<'tcx>,
1028-
param_env: ty::ParamEnv<'tcx>,
10291019
body: &Body<'tcx>,
10301020
type_test: &TypeTest<'tcx>,
10311021
propagated_outlives_requirements: &mut Vec<ClosureOutlivesRequirement<'tcx>>,
@@ -1087,7 +1077,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
10871077
// where `ur` is a local bound -- we are sometimes in a
10881078
// position to prove things that our caller cannot. See
10891079
// #53570 for an example.
1090-
if self.eval_verify_bound(infcx, param_env, generic_ty, ur, &type_test.verify_bound) {
1080+
if self.eval_verify_bound(infcx, generic_ty, ur, &type_test.verify_bound) {
10911081
continue;
10921082
}
10931083

@@ -1270,7 +1260,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
12701260
fn eval_verify_bound(
12711261
&self,
12721262
infcx: &InferCtxt<'tcx>,
1273-
param_env: ty::ParamEnv<'tcx>,
12741263
generic_ty: Ty<'tcx>,
12751264
lower_bound: RegionVid,
12761265
verify_bound: &VerifyBound<'tcx>,
@@ -1279,7 +1268,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
12791268

12801269
match verify_bound {
12811270
VerifyBound::IfEq(verify_if_eq_b) => {
1282-
self.eval_if_eq(infcx, param_env, generic_ty, lower_bound, *verify_if_eq_b)
1271+
self.eval_if_eq(infcx, generic_ty, lower_bound, *verify_if_eq_b)
12831272
}
12841273

12851274
VerifyBound::IsEmpty => {
@@ -1293,31 +1282,25 @@ impl<'tcx> RegionInferenceContext<'tcx> {
12931282
}
12941283

12951284
VerifyBound::AnyBound(verify_bounds) => verify_bounds.iter().any(|verify_bound| {
1296-
self.eval_verify_bound(infcx, param_env, generic_ty, lower_bound, verify_bound)
1285+
self.eval_verify_bound(infcx, generic_ty, lower_bound, verify_bound)
12971286
}),
12981287

12991288
VerifyBound::AllBounds(verify_bounds) => verify_bounds.iter().all(|verify_bound| {
1300-
self.eval_verify_bound(infcx, param_env, generic_ty, lower_bound, verify_bound)
1289+
self.eval_verify_bound(infcx, generic_ty, lower_bound, verify_bound)
13011290
}),
13021291
}
13031292
}
13041293

13051294
fn eval_if_eq(
13061295
&self,
13071296
infcx: &InferCtxt<'tcx>,
1308-
param_env: ty::ParamEnv<'tcx>,
13091297
generic_ty: Ty<'tcx>,
13101298
lower_bound: RegionVid,
13111299
verify_if_eq_b: ty::Binder<'tcx, VerifyIfEq<'tcx>>,
13121300
) -> bool {
13131301
let generic_ty = self.normalize_to_scc_representatives(infcx.tcx, generic_ty);
13141302
let verify_if_eq_b = self.normalize_to_scc_representatives(infcx.tcx, verify_if_eq_b);
1315-
match test_type_match::extract_verify_if_eq(
1316-
infcx.tcx,
1317-
param_env,
1318-
&verify_if_eq_b,
1319-
generic_ty,
1320-
) {
1303+
match test_type_match::extract_verify_if_eq(infcx.tcx, &verify_if_eq_b, generic_ty) {
13211304
Some(r) => {
13221305
let r_vid = self.to_region_vid(r);
13231306
self.eval_outlives(r_vid, lower_bound)

Diff for: ‎compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2654,8 +2654,7 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
26542654
}
26552655

26562656
fn param_env(&self) -> ty::ParamEnv<'tcx> {
2657-
// Unused, only for consts which we treat as always equal
2658-
ty::ParamEnv::empty()
2657+
unreachable!("purely structural relation should not need a param-env")
26592658
}
26602659

26612660
fn tag(&self) -> &'static str {

Diff for: ‎compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@ use super::outlives::test_type_match;
3131
/// all the variables as well as a set of errors that must be reported.
3232
#[instrument(level = "debug", skip(region_rels, var_infos, data))]
3333
pub(crate) fn resolve<'tcx>(
34-
param_env: ty::ParamEnv<'tcx>,
3534
region_rels: &RegionRelations<'_, 'tcx>,
3635
var_infos: VarInfos,
3736
data: RegionConstraintData<'tcx>,
3837
) -> (LexicalRegionResolutions<'tcx>, Vec<RegionResolutionError<'tcx>>) {
3938
let mut errors = vec![];
40-
let mut resolver = LexicalResolver { param_env, region_rels, var_infos, data };
39+
let mut resolver = LexicalResolver { region_rels, var_infos, data };
4140
let values = resolver.infer_variable_values(&mut errors);
4241
(values, errors)
4342
}
@@ -120,7 +119,6 @@ struct RegionAndOrigin<'tcx> {
120119
type RegionGraph<'tcx> = Graph<(), Constraint<'tcx>>;
121120

122121
struct LexicalResolver<'cx, 'tcx> {
123-
param_env: ty::ParamEnv<'tcx>,
124122
region_rels: &'cx RegionRelations<'cx, 'tcx>,
125123
var_infos: VarInfos,
126124
data: RegionConstraintData<'tcx>,
@@ -914,12 +912,8 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
914912
match bound {
915913
VerifyBound::IfEq(verify_if_eq_b) => {
916914
let verify_if_eq_b = var_values.normalize(self.region_rels.tcx, *verify_if_eq_b);
917-
match test_type_match::extract_verify_if_eq(
918-
self.tcx(),
919-
self.param_env,
920-
&verify_if_eq_b,
921-
generic_ty,
922-
) {
915+
match test_type_match::extract_verify_if_eq(self.tcx(), &verify_if_eq_b, generic_ty)
916+
{
923917
Some(r) => {
924918
self.bound_is_met(&VerifyBound::OutlivedBy(r), var_values, generic_ty, min)
925919
}

Diff for: ‎compiler/rustc_infer/src/infer/outlives/for_liveness.rs

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ where
8484
} else {
8585
test_type_match::extract_verify_if_eq(
8686
tcx,
87-
param_env,
8887
&outlives.map_bound(|ty::OutlivesPredicate(ty, bound)| {
8988
VerifyIfEq { ty, bound }
9089
}),

Diff for: ‎compiler/rustc_infer/src/infer/outlives/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'tcx> InferCtxt<'tcx> {
6767
let region_rels = &RegionRelations::new(self.tcx, outlives_env.free_region_map());
6868

6969
let (lexical_region_resolutions, errors) =
70-
lexical_region_resolve::resolve(outlives_env.param_env, region_rels, var_infos, data);
70+
lexical_region_resolve::resolve(region_rels, var_infos, data);
7171

7272
let old_value = self.lexical_region_resolutions.replace(Some(lexical_region_resolutions));
7373
assert!(old_value.is_none());

Diff for: ‎compiler/rustc_infer/src/infer/outlives/test_type_match.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@ use crate::infer::region_constraints::VerifyIfEq;
3636
/// like are used. This is a particular challenge since this function is invoked
3737
/// very late in inference and hence cannot make use of the normal inference
3838
/// machinery.
39-
#[instrument(level = "debug", skip(tcx, param_env))]
39+
#[instrument(level = "debug", skip(tcx))]
4040
pub fn extract_verify_if_eq<'tcx>(
4141
tcx: TyCtxt<'tcx>,
42-
param_env: ty::ParamEnv<'tcx>,
4342
verify_if_eq_b: &ty::Binder<'tcx, VerifyIfEq<'tcx>>,
4443
test_ty: Ty<'tcx>,
4544
) -> Option<ty::Region<'tcx>> {
4645
assert!(!verify_if_eq_b.has_escaping_bound_vars());
47-
let mut m = MatchAgainstHigherRankedOutlives::new(tcx, param_env);
46+
let mut m = MatchAgainstHigherRankedOutlives::new(tcx);
4847
let verify_if_eq = verify_if_eq_b.skip_binder();
4948
m.relate(verify_if_eq.ty, test_ty).ok()?;
5049

@@ -73,10 +72,9 @@ pub fn extract_verify_if_eq<'tcx>(
7372
}
7473

7574
/// True if a (potentially higher-ranked) outlives
76-
#[instrument(level = "debug", skip(tcx, param_env))]
75+
#[instrument(level = "debug", skip(tcx))]
7776
pub(super) fn can_match_erased_ty<'tcx>(
7877
tcx: TyCtxt<'tcx>,
79-
param_env: ty::ParamEnv<'tcx>,
8078
outlives_predicate: ty::Binder<'tcx, ty::TypeOutlivesPredicate<'tcx>>,
8179
erased_ty: Ty<'tcx>,
8280
) -> bool {
@@ -87,25 +85,20 @@ pub(super) fn can_match_erased_ty<'tcx>(
8785
// pointless micro-optimization
8886
true
8987
} else {
90-
MatchAgainstHigherRankedOutlives::new(tcx, param_env).relate(outlives_ty, erased_ty).is_ok()
88+
MatchAgainstHigherRankedOutlives::new(tcx).relate(outlives_ty, erased_ty).is_ok()
9189
}
9290
}
9391

9492
struct MatchAgainstHigherRankedOutlives<'tcx> {
9593
tcx: TyCtxt<'tcx>,
96-
param_env: ty::ParamEnv<'tcx>,
9794
pattern_depth: ty::DebruijnIndex,
9895
map: FxHashMap<ty::BoundRegion, ty::Region<'tcx>>,
9996
}
10097

10198
impl<'tcx> MatchAgainstHigherRankedOutlives<'tcx> {
102-
fn new(
103-
tcx: TyCtxt<'tcx>,
104-
param_env: ty::ParamEnv<'tcx>,
105-
) -> MatchAgainstHigherRankedOutlives<'tcx> {
99+
fn new(tcx: TyCtxt<'tcx>) -> MatchAgainstHigherRankedOutlives<'tcx> {
106100
MatchAgainstHigherRankedOutlives {
107101
tcx,
108-
param_env,
109102
pattern_depth: ty::INNERMOST,
110103
map: FxHashMap::default(),
111104
}
@@ -144,15 +137,17 @@ impl<'tcx> MatchAgainstHigherRankedOutlives<'tcx> {
144137

145138
impl<'tcx> TypeRelation<'tcx> for MatchAgainstHigherRankedOutlives<'tcx> {
146139
fn tag(&self) -> &'static str {
147-
"Match"
140+
"MatchAgainstHigherRankedOutlives"
148141
}
149142

150143
fn tcx(&self) -> TyCtxt<'tcx> {
151144
self.tcx
152145
}
146+
153147
fn param_env(&self) -> ty::ParamEnv<'tcx> {
154-
self.param_env
148+
unreachable!("purely structural relation should not need a param-env")
155149
}
150+
156151
fn a_is_expected(&self) -> bool {
157152
true
158153
} // irrelevant

Diff for: ‎compiler/rustc_infer/src/infer/outlives/verify.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,8 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
312312
) -> impl Iterator<Item = ty::Binder<'tcx, ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>>>
313313
{
314314
let tcx = self.tcx;
315-
let param_env = self.param_env;
316315
clauses.filter_map(|p| p.as_type_outlives_clause()).filter(move |outlives_predicate| {
317-
super::test_type_match::can_match_erased_ty(
318-
tcx,
319-
param_env,
320-
*outlives_predicate,
321-
erased_ty,
322-
)
316+
super::test_type_match::can_match_erased_ty(tcx, *outlives_predicate, erased_ty)
323317
})
324318
}
325319
}

Diff for: ‎compiler/rustc_middle/src/ty/_match.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,27 @@ use crate::ty::{self, InferConst, Ty, TyCtxt};
2020
/// affects any type variables or unification state.
2121
pub struct MatchAgainstFreshVars<'tcx> {
2222
tcx: TyCtxt<'tcx>,
23-
param_env: ty::ParamEnv<'tcx>,
2423
}
2524

2625
impl<'tcx> MatchAgainstFreshVars<'tcx> {
27-
pub fn new(tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> MatchAgainstFreshVars<'tcx> {
28-
MatchAgainstFreshVars { tcx, param_env }
26+
pub fn new(tcx: TyCtxt<'tcx>) -> MatchAgainstFreshVars<'tcx> {
27+
MatchAgainstFreshVars { tcx }
2928
}
3029
}
3130

3231
impl<'tcx> TypeRelation<'tcx> for MatchAgainstFreshVars<'tcx> {
3332
fn tag(&self) -> &'static str {
3433
"MatchAgainstFreshVars"
3534
}
35+
3636
fn tcx(&self) -> TyCtxt<'tcx> {
3737
self.tcx
3838
}
3939

4040
fn param_env(&self) -> ty::ParamEnv<'tcx> {
41-
self.param_env
41+
panic!("relation should not need a param-env")
4242
}
43+
4344
fn a_is_expected(&self) -> bool {
4445
true
4546
} // irrelevant

Diff for: ‎compiler/rustc_trait_selection/src/traits/select/mod.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1226,11 +1226,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12261226
if unbound_input_types
12271227
&& stack.iter().skip(1).any(|prev| {
12281228
stack.obligation.param_env == prev.obligation.param_env
1229-
&& self.match_fresh_trait_refs(
1230-
stack.fresh_trait_pred,
1231-
prev.fresh_trait_pred,
1232-
prev.obligation.param_env,
1233-
)
1229+
&& self.match_fresh_trait_refs(stack.fresh_trait_pred, prev.fresh_trait_pred)
12341230
})
12351231
{
12361232
debug!("evaluate_stack --> unbound argument, recursive --> giving up",);
@@ -2632,9 +2628,8 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
26322628
&self,
26332629
previous: ty::PolyTraitPredicate<'tcx>,
26342630
current: ty::PolyTraitPredicate<'tcx>,
2635-
param_env: ty::ParamEnv<'tcx>,
26362631
) -> bool {
2637-
let mut matcher = MatchAgainstFreshVars::new(self.tcx(), param_env);
2632+
let mut matcher = MatchAgainstFreshVars::new(self.tcx());
26382633
matcher.relate(previous, current).is_ok()
26392634
}
26402635

0 commit comments

Comments
 (0)