Skip to content

Commit fc16b0a

Browse files
committed
Fix rebase from LazyConst removal
1 parent c888af5 commit fc16b0a

File tree

24 files changed

+337
-389
lines changed

24 files changed

+337
-389
lines changed

src/librustc/infer/canonical/canonicalizer.rs

Lines changed: 50 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::sync::atomic::Ordering;
1515
use crate::ty::fold::{TypeFoldable, TypeFolder};
1616
use crate::ty::subst::Kind;
1717
use crate::ty::{self, BoundVar, InferConst, Lift, List, Ty, TyCtxt, TypeFlags};
18+
use crate::ty::flags::FlagComputation;
1819

1920
use rustc_data_structures::fx::FxHashMap;
2021
use rustc_data_structures::indexed_vec::Idx;
@@ -434,59 +435,58 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
434435
}
435436
}
436437

437-
fn fold_const(&mut self, c: &'tcx ty::LazyConst<'tcx>) -> &'tcx ty::LazyConst<'tcx> {
438-
if let ty::LazyConst::Evaluated(ct) = c {
439-
match ct.val {
440-
ConstValue::Infer(InferConst::Var(vid)) => {
441-
debug!("canonical: const var found with vid {:?}", vid);
442-
match self.infcx.unwrap().probe_const_var(vid) {
443-
Ok(c) => {
444-
debug!("(resolved to {:?})", c);
445-
return self.fold_const(c);
446-
}
438+
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
439+
match ct.val {
440+
ConstValue::Infer(InferConst::Var(vid)) => {
441+
debug!("canonical: const var found with vid {:?}", vid);
442+
match self.infcx.unwrap().probe_const_var(vid) {
443+
Ok(c) => {
444+
debug!("(resolved to {:?})", c);
445+
return self.fold_const(c);
446+
}
447447

448-
// `ConstVar(vid)` is unresolved, track its universe index in the
449-
// canonicalized result
450-
Err(mut ui) => {
451-
if !self.infcx.unwrap().tcx.sess.opts.debugging_opts.chalk {
452-
// FIXME: perf problem described in #55921.
453-
ui = ty::UniverseIndex::ROOT;
454-
}
455-
return self.canonicalize_const_var(
456-
CanonicalVarInfo {
457-
kind: CanonicalVarKind::Const(ui),
458-
},
459-
c,
460-
);
448+
// `ConstVar(vid)` is unresolved, track its universe index in the
449+
// canonicalized result
450+
Err(mut ui) => {
451+
if !self.infcx.unwrap().tcx.sess.opts.debugging_opts.chalk {
452+
// FIXME: perf problem described in #55921.
453+
ui = ty::UniverseIndex::ROOT;
461454
}
455+
return self.canonicalize_const_var(
456+
CanonicalVarInfo {
457+
kind: CanonicalVarKind::Const(ui),
458+
},
459+
ct,
460+
);
462461
}
463462
}
464-
ConstValue::Infer(InferConst::Fresh(_)) => {
465-
bug!("encountered a fresh const during canonicalization")
466-
}
467-
ConstValue::Infer(InferConst::Canonical(debruijn, _)) => {
468-
if debruijn >= self.binder_index {
469-
bug!("escaping bound type during canonicalization")
470-
} else {
471-
return c;
472-
}
473-
}
474-
ConstValue::Placeholder(placeholder) => {
475-
return self.canonicalize_const_var(
476-
CanonicalVarInfo {
477-
kind: CanonicalVarKind::PlaceholderConst(placeholder),
478-
},
479-
c,
480-
);
463+
}
464+
ConstValue::Infer(InferConst::Fresh(_)) => {
465+
bug!("encountered a fresh const during canonicalization")
466+
}
467+
ConstValue::Infer(InferConst::Canonical(debruijn, _)) => {
468+
if debruijn >= self.binder_index {
469+
bug!("escaping bound type during canonicalization")
470+
} else {
471+
return ct;
481472
}
482-
_ => {}
483473
}
474+
ConstValue::Placeholder(placeholder) => {
475+
return self.canonicalize_const_var(
476+
CanonicalVarInfo {
477+
kind: CanonicalVarKind::PlaceholderConst(placeholder),
478+
},
479+
ct,
480+
);
481+
}
482+
_ => {}
484483
}
485484

486-
if c.type_flags().intersects(self.needs_canonical_flags) {
487-
c.super_fold_with(self)
485+
let flags = FlagComputation::for_const(ct);
486+
if flags.intersects(self.needs_canonical_flags) {
487+
ct.super_fold_with(self)
488488
} else {
489-
c
489+
ct
490490
}
491491
}
492492
}
@@ -700,25 +700,19 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
700700
fn canonicalize_const_var(
701701
&mut self,
702702
info: CanonicalVarInfo,
703-
const_var: &'tcx ty::LazyConst<'tcx>
704-
) -> &'tcx ty::LazyConst<'tcx> {
703+
const_var: &'tcx ty::Const<'tcx>
704+
) -> &'tcx ty::Const<'tcx> {
705705
let infcx = self.infcx.expect("encountered const-var without infcx");
706706
let bound_to = infcx.resolve_const_var(const_var);
707707
if bound_to != const_var {
708708
self.fold_const(bound_to)
709709
} else {
710-
let ty = match const_var {
711-
ty::LazyConst::Unevaluated(def_id, _) => {
712-
self.tcx.type_of(*def_id)
713-
}
714-
ty::LazyConst::Evaluated(ty::Const { ty, .. }) => ty,
715-
};
716710
let var = self.canonical_var(info, const_var.into());
717-
self.tcx().mk_lazy_const(
718-
ty::LazyConst::Evaluated(ty::Const {
711+
self.tcx().mk_const(
712+
ty::Const {
719713
val: ConstValue::Infer(InferConst::Canonical(self.binder_index, var.into())),
720-
ty,
721-
})
714+
ty: const_var.ty,
715+
}
722716
)
723717
}
724718
}

src/librustc/infer/canonical/mod.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,12 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
419419
universe: universe_mapped,
420420
name,
421421
};
422-
self.tcx.mk_lazy_const(ty::LazyConst::Evaluated(
422+
self.tcx.mk_const(
423423
ty::Const {
424424
val: ConstValue::Placeholder(placeholder_mapped),
425425
ty: self.tcx.types.err, // FIXME(const_generics)
426426
}
427-
)).into()
427+
).into()
428428
}
429429
}
430430
}
@@ -482,18 +482,12 @@ impl<'tcx> CanonicalVarValues<'tcx> {
482482
ty::ReLateBound(ty::INNERMOST, ty::BoundRegion::BrAnon(i))
483483
).into(),
484484
UnpackedKind::Const(ct) => {
485-
let ty = match ct {
486-
ty::LazyConst::Unevaluated(def_id, _) => {
487-
tcx.type_of(*def_id)
488-
}
489-
ty::LazyConst::Evaluated(ty::Const { ty, .. }) => ty,
490-
};
491-
tcx.mk_lazy_const(ty::LazyConst::Evaluated(ty::Const {
492-
ty: ty,
485+
tcx.mk_const(ty::Const {
486+
ty: ct.ty,
493487
val: ConstValue::Infer(
494488
InferConst::Canonical(ty::INNERMOST, ty::BoundVar::from_u32(i))
495489
),
496-
})).into()
490+
}).into()
497491
}
498492
})
499493
.collect()

src/librustc/infer/canonical/query_response.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,10 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
481481
}
482482
}
483483
UnpackedKind::Const(result_value) => {
484-
if let ty::LazyConst::Evaluated(ty::Const {
484+
if let ty::Const {
485485
val: ConstValue::Infer(InferConst::Canonical(debrujin, b)),
486486
..
487-
}) = result_value {
487+
} = result_value {
488488
// ...in which case we would set `canonical_vars[0]` to `Some(const X)`.
489489

490490
// We only allow a `ty::INNERMOST` index in substitutions.

src/librustc/infer/combine.rs

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use super::unify_key::{ConstVarValue, ConstVariableValue, ConstVariableOrigin};
3333
use crate::hir::def_id::DefId;
3434
use crate::mir::interpret::ConstValue;
3535
use crate::ty::{IntType, UintType};
36-
use crate::ty::{self, Ty, TyCtxt, InferConst, LazyConst};
36+
use crate::ty::{self, Ty, TyCtxt, InferConst};
3737
use crate::ty::error::TypeError;
3838
use crate::ty::relate::{self, Relate, RelateResult, TypeRelation};
3939
use crate::ty::subst::SubstsRef;
@@ -118,41 +118,39 @@ impl<'infcx, 'gcx, 'tcx> InferCtxt<'infcx, 'gcx, 'tcx> {
118118
pub fn super_combine_consts<R>(
119119
&self,
120120
relation: &mut R,
121-
a: &'tcx LazyConst<'tcx>,
122-
b: &'tcx LazyConst<'tcx>,
123-
) -> RelateResult<'tcx, &'tcx LazyConst<'tcx>>
121+
a: &'tcx ty::Const<'tcx>,
122+
b: &'tcx ty::Const<'tcx>,
123+
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>>
124124
where
125125
R: TypeRelation<'infcx, 'gcx, 'tcx>,
126126
{
127127
let a_is_expected = relation.a_is_expected();
128128

129-
if let (&ty::LazyConst::Evaluated(a_eval), &ty::LazyConst::Evaluated(b_eval)) = (a, b) {
130-
match (a_eval.val, b_eval.val) {
131-
(ConstValue::Infer(InferConst::Var(a_vid)),
132-
ConstValue::Infer(InferConst::Var(b_vid))) => {
133-
self.const_unification_table
134-
.borrow_mut()
135-
.unify_var_var(a_vid, b_vid)
136-
.map_err(|e| const_unification_error(a_is_expected, e))?;
137-
return Ok(a);
138-
}
139-
140-
// All other cases of inference with other variables are errors.
141-
(ConstValue::Infer(InferConst::Var(_)), ConstValue::Infer(_)) |
142-
(ConstValue::Infer(_), ConstValue::Infer(InferConst::Var(_))) => {
143-
bug!("tried to combine ConstValue::Infer/ConstValue::Infer(InferConst::Var)")
144-
}
129+
match (a.val, b.val) {
130+
(ConstValue::Infer(InferConst::Var(a_vid)),
131+
ConstValue::Infer(InferConst::Var(b_vid))) => {
132+
self.const_unification_table
133+
.borrow_mut()
134+
.unify_var_var(a_vid, b_vid)
135+
.map_err(|e| const_unification_error(a_is_expected, e))?;
136+
return Ok(a);
137+
}
145138

146-
(ConstValue::Infer(InferConst::Var(vid)), _) => {
147-
return self.unify_const_variable(a_is_expected, vid, b);
148-
}
139+
// All other cases of inference with other variables are errors.
140+
(ConstValue::Infer(InferConst::Var(_)), ConstValue::Infer(_)) |
141+
(ConstValue::Infer(_), ConstValue::Infer(InferConst::Var(_))) => {
142+
bug!("tried to combine ConstValue::Infer/ConstValue::Infer(InferConst::Var)")
143+
}
149144

150-
(_, ConstValue::Infer(InferConst::Var(vid))) => {
151-
return self.unify_const_variable(!a_is_expected, vid, a);
152-
}
145+
(ConstValue::Infer(InferConst::Var(vid)), _) => {
146+
return self.unify_const_variable(a_is_expected, vid, b);
147+
}
153148

154-
_ => {}
149+
(_, ConstValue::Infer(InferConst::Var(vid))) => {
150+
return self.unify_const_variable(!a_is_expected, vid, a);
155151
}
152+
153+
_ => {}
156154
}
157155

158156
ty::relate::super_relate_consts(relation, a, b)
@@ -162,8 +160,8 @@ impl<'infcx, 'gcx, 'tcx> InferCtxt<'infcx, 'gcx, 'tcx> {
162160
&self,
163161
vid_is_expected: bool,
164162
vid: ty::ConstVid<'tcx>,
165-
value: &'tcx LazyConst<'tcx>,
166-
) -> RelateResult<'tcx, &'tcx LazyConst<'tcx>> {
163+
value: &'tcx ty::Const<'tcx>,
164+
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
167165
self.const_unification_table
168166
.borrow_mut()
169167
.unify_var_value(vid, ConstVarValue {
@@ -582,16 +580,13 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, '
582580

583581
fn consts(
584582
&mut self,
585-
c: &'tcx ty::LazyConst<'tcx>,
586-
c2: &'tcx ty::LazyConst<'tcx>
587-
) -> RelateResult<'tcx, &'tcx ty::LazyConst<'tcx>> {
583+
c: &'tcx ty::Const<'tcx>,
584+
c2: &'tcx ty::Const<'tcx>
585+
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
588586
assert_eq!(c, c2); // we are abusing TypeRelation here; both LHS and RHS ought to be ==
589587

590588
match c {
591-
LazyConst::Evaluated(ty::Const {
592-
val: ConstValue::Infer(InferConst::Var(vid)),
593-
..
594-
}) => {
589+
ty::Const { val: ConstValue::Infer(InferConst::Var(vid)), .. } => {
595590
let mut variable_table = self.infcx.const_unification_table.borrow_mut();
596591
match variable_table.probe_value(*vid).val.known() {
597592
Some(u) => {
@@ -628,7 +623,7 @@ impl<'tcx, T:Clone + PartialEq> RelateResultCompare<'tcx, T> for RelateResult<'t
628623

629624
pub fn const_unification_error<'tcx>(
630625
a_is_expected: bool,
631-
(a, b): (&'tcx LazyConst<'tcx>, &'tcx LazyConst<'tcx>),
626+
(a, b): (&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>),
632627
) -> TypeError<'tcx> {
633628
TypeError::ConstMismatch(ty::relate::expected_found_bool(a_is_expected, &a, &b))
634629
}

src/librustc/infer/equate.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -104,39 +104,38 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
104104

105105
fn consts(
106106
&mut self,
107-
a: &'tcx ty::LazyConst<'tcx>,
108-
b: &'tcx ty::LazyConst<'tcx>,
109-
) -> RelateResult<'tcx, &'tcx ty::LazyConst<'tcx>> {
107+
a: &'tcx ty::Const<'tcx>,
108+
b: &'tcx ty::Const<'tcx>,
109+
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
110110
debug!("{}.consts({:?}, {:?})", self.tag(), a, b);
111111
if a == b { return Ok(a); }
112112

113113
let infcx = self.fields.infcx;
114114
let a = replace_if_possible(infcx.const_unification_table.borrow_mut(), a);
115115
let b = replace_if_possible(infcx.const_unification_table.borrow_mut(), b);
116116
let a_is_expected = self.a_is_expected();
117-
if let (&ty::LazyConst::Evaluated(a_eval), &ty::LazyConst::Evaluated(b_eval)) = (a, b) {
118-
match (a_eval.val, b_eval.val) {
119-
(ConstValue::Infer(InferConst::Var(a_vid)),
120-
ConstValue::Infer(InferConst::Var(b_vid))) => {
121-
infcx.const_unification_table
122-
.borrow_mut()
123-
.unify_var_var(a_vid, b_vid)
124-
.map_err(|e| const_unification_error(a_is_expected, e))?;
125-
return Ok(a);
126-
}
127-
128-
(ConstValue::Infer(InferConst::Var(a_id)), _) => {
129-
self.fields.infcx.unify_const_variable(a_is_expected, a_id, b)?;
130-
return Ok(a);
131-
}
132-
133-
(_, ConstValue::Infer(InferConst::Var(b_id))) => {
134-
self.fields.infcx.unify_const_variable(!a_is_expected, b_id, a)?;
135-
return Ok(a);
136-
}
137-
138-
_ => {}
117+
118+
match (a.val, b.val) {
119+
(ConstValue::Infer(InferConst::Var(a_vid)),
120+
ConstValue::Infer(InferConst::Var(b_vid))) => {
121+
infcx.const_unification_table
122+
.borrow_mut()
123+
.unify_var_var(a_vid, b_vid)
124+
.map_err(|e| const_unification_error(a_is_expected, e))?;
125+
return Ok(a);
126+
}
127+
128+
(ConstValue::Infer(InferConst::Var(a_id)), _) => {
129+
self.fields.infcx.unify_const_variable(a_is_expected, a_id, b)?;
130+
return Ok(a);
139131
}
132+
133+
(_, ConstValue::Infer(InferConst::Var(b_id))) => {
134+
self.fields.infcx.unify_const_variable(!a_is_expected, b_id, a)?;
135+
return Ok(a);
136+
}
137+
138+
_ => {}
140139
}
141140

142141
self.fields.infcx.super_combine_consts(self, a, b)?;

0 commit comments

Comments
 (0)