Skip to content

Commit 1e43cf4

Browse files
authored
Rollup merge of #95559 - lcnr:inferctxt-typeck, r=oli-obk
small type system refactoring
2 parents dc11de6 + 389c83b commit 1e43cf4

File tree

8 files changed

+17
-52
lines changed

8 files changed

+17
-52
lines changed

compiler/rustc_infer/src/infer/canonical/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
4949
/// At the end of processing, the substitution S (once
5050
/// canonicalized) then represents the values that you computed
5151
/// for each of the canonical inputs to your query.
52-
5352
pub fn instantiate_canonical_with_fresh_inference_vars<T>(
5453
&self,
5554
span: Span,

compiler/rustc_infer/src/infer/combine.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,12 @@ use super::glb::Glb;
2727
use super::lub::Lub;
2828
use super::sub::Sub;
2929
use super::type_variable::TypeVariableValue;
30-
use super::unify_key::replace_if_possible;
31-
use super::unify_key::{ConstVarValue, ConstVariableValue};
32-
use super::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
3330
use super::{InferCtxt, MiscVariable, TypeTrace};
34-
3531
use crate::traits::{Obligation, PredicateObligations};
36-
3732
use rustc_data_structures::sso::SsoHashMap;
3833
use rustc_hir::def_id::DefId;
34+
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
35+
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
3936
use rustc_middle::traits::ObligationCause;
4037
use rustc_middle::ty::error::{ExpectedFound, TypeError};
4138
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
@@ -140,8 +137,8 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
140137
return Ok(a);
141138
}
142139

143-
let a = replace_if_possible(&mut self.inner.borrow_mut().const_unification_table(), a);
144-
let b = replace_if_possible(&mut self.inner.borrow_mut().const_unification_table(), b);
140+
let a = self.shallow_resolve(a);
141+
let b = self.shallow_resolve(b);
145142

146143
let a_is_expected = relation.a_is_expected();
147144

compiler/rustc_infer/src/infer/freshen.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,13 @@
3030
//! solving a set of constraints. In contrast, the type inferencer assigns a value to each type
3131
//! variable only once, and it does so as soon as it can, so it is reasonable to ask what the type
3232
//! inferencer knows "so far".
33-
33+
use super::InferCtxt;
34+
use rustc_data_structures::fx::FxHashMap;
35+
use rustc_middle::infer::unify_key::ToType;
3436
use rustc_middle::ty::fold::TypeFolder;
3537
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
36-
37-
use rustc_data_structures::fx::FxHashMap;
38-
3938
use std::collections::hash_map::Entry;
4039

41-
use super::unify_key::ToType;
42-
use super::InferCtxt;
43-
4440
pub struct TypeFreshener<'a, 'tcx> {
4541
infcx: &'a InferCtxt<'a, 'tcx>,
4642
ty_freshen_count: u32,

compiler/rustc_infer/src/infer/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ mod sub;
7070
pub mod type_variable;
7171
mod undo_log;
7272

73-
pub use rustc_middle::infer::unify_key;
74-
7573
#[must_use]
7674
#[derive(Debug)]
7775
pub struct InferOk<'tcx, T> {
@@ -558,9 +556,9 @@ impl<'tcx> fmt::Display for FixupError<'tcx> {
558556
}
559557
}
560558

561-
/// Helper type of a temporary returned by `tcx.infer_ctxt()`.
562-
/// Necessary because we can't write the following bound:
563-
/// `F: for<'b, 'tcx> where 'tcx FnOnce(InferCtxt<'b, 'tcx>)`.
559+
/// A temporary returned by `tcx.infer_ctxt()`. This is necessary
560+
/// for multiple `InferCtxt` to share the same `in_progress_typeck_results`
561+
/// without using `Rc` or something similar.
564562
pub struct InferCtxtBuilder<'tcx> {
565563
tcx: TyCtxt<'tcx>,
566564
fresh_typeck_results: Option<RefCell<ty::TypeckResults<'tcx>>>,

compiler/rustc_middle/src/infer/unify_key.rs

+2-27
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
use crate::ty::{self, InferConst, Ty, TyCtxt};
2-
use rustc_data_structures::snapshot_vec;
3-
use rustc_data_structures::undo_log::UndoLogs;
4-
use rustc_data_structures::unify::{
5-
self, EqUnifyValue, InPlace, NoError, UnificationTable, UnifyKey, UnifyValue,
6-
};
1+
use crate::ty::{self, Ty, TyCtxt};
2+
use rustc_data_structures::unify::{NoError, UnifyKey, UnifyValue};
73
use rustc_span::def_id::DefId;
84
use rustc_span::symbol::Symbol;
95
use rustc_span::Span;
10-
116
use std::cmp;
127
use std::marker::PhantomData;
138

@@ -165,23 +160,3 @@ impl<'tcx> UnifyValue for ConstVarValue<'tcx> {
165160
})
166161
}
167162
}
168-
169-
impl<'tcx> EqUnifyValue for ty::Const<'tcx> {}
170-
171-
pub fn replace_if_possible<'tcx, V, L>(
172-
table: &mut UnificationTable<InPlace<ty::ConstVid<'tcx>, V, L>>,
173-
c: ty::Const<'tcx>,
174-
) -> ty::Const<'tcx>
175-
where
176-
V: snapshot_vec::VecLike<unify::Delegate<ty::ConstVid<'tcx>>>,
177-
L: UndoLogs<snapshot_vec::UndoLog<unify::Delegate<ty::ConstVid<'tcx>>>>,
178-
{
179-
if let ty::ConstKind::Infer(InferConst::Var(vid)) = c.val() {
180-
match table.probe_value(vid).val.known() {
181-
Some(c) => c,
182-
None => c,
183-
}
184-
} else {
185-
c
186-
}
187-
}

compiler/rustc_typeck/src/check/fn_ctxt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_hir as hir;
1414
use rustc_hir::def_id::DefId;
1515
use rustc_infer::infer;
1616
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
17-
use rustc_infer::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
17+
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
1818
use rustc_middle::ty::fold::TypeFoldable;
1919
use rustc_middle::ty::subst::GenericArgKind;
2020
use rustc_middle::ty::{self, Const, Ty, TyCtxt};

compiler/rustc_typeck/src/check/inherited.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ impl<'a, 'tcx> Deref for Inherited<'a, 'tcx> {
6868
}
6969
}
7070

71-
/// Helper type of a temporary returned by `Inherited::build(...)`.
72-
/// Necessary because we can't write the following bound:
73-
/// `F: for<'b, 'tcx> where 'tcx FnOnce(Inherited<'b, 'tcx>)`.
71+
/// A temporary returned by `Inherited::build(...)`. This is necessary
72+
/// for multiple `InferCtxt` to share the same `in_progress_typeck_results`
73+
/// without using `Rc` or something similar.
7474
pub struct InheritedBuilder<'tcx> {
7575
infcx: infer::InferCtxtBuilder<'tcx>,
7676
def_id: LocalDefId,

compiler/rustc_typeck/src/check/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use rustc_hir::def::Namespace;
1515
use rustc_infer::infer::canonical::OriginalQueryValues;
1616
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
1717
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
18-
use rustc_infer::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
1918
use rustc_infer::infer::{self, InferOk, TyCtxtInferExt};
19+
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
2020
use rustc_middle::middle::stability;
2121
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
2222
use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};

0 commit comments

Comments
 (0)