Skip to content

Commit a385e56

Browse files
committed
Auto merge of #122392 - BoxyUwU:misc_cleanup, r=lcnr
misc cleanups from debugging something rename `instantiate_canonical_with_fresh_inference_vars` to `instantiate_canonical` the substs for the canonical are not solely infer vars as that would be wildly wrong and it is rather confusing to see this method called and think that the entire canonicalization setup is completely broken when it is not 👍 also update region debug printing to be more like the custom impls for Ty/Const, right now regions in debug output are horribly verbose and make it incredibly hard to read but with this atleast boundvars and placeholders when debugging the new solver do not take up excessive amounts of space. r? `@lcnr`
2 parents 200e3f7 + e34e344 commit a385e56

File tree

38 files changed

+205
-173
lines changed

38 files changed

+205
-173
lines changed

compiler/rustc_borrowck/src/type_check/canonical.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
6161
Ok(output)
6262
}
6363

64-
pub(super) fn instantiate_canonical_with_fresh_inference_vars<T>(
64+
pub(super) fn instantiate_canonical<T>(
6565
&mut self,
6666
span: Span,
6767
canonical: &Canonical<'tcx, T>,
6868
) -> T
6969
where
7070
T: TypeFoldable<TyCtxt<'tcx>>,
7171
{
72-
let (instantiated, _) =
73-
self.infcx.instantiate_canonical_with_fresh_inference_vars(span, canonical);
72+
let (instantiated, _) = self.infcx.instantiate_canonical(span, canonical);
7473
instantiated
7574
}
7675

compiler/rustc_borrowck/src/type_check/input_output.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
3939
// (e.g., the `_` in the code above) with fresh variables.
4040
// Then replace the bound items in the fn sig with fresh variables,
4141
// so that they represent the view from "inside" the closure.
42-
let user_provided_sig = self
43-
.instantiate_canonical_with_fresh_inference_vars(body.span, &user_provided_poly_sig);
42+
let user_provided_sig = self.instantiate_canonical(body.span, &user_provided_poly_sig);
4443
let mut user_provided_sig = self.infcx.instantiate_binder_with_fresh_vars(
4544
body.span,
4645
BoundRegionConversionTime::FnCall,

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
11091109
let tcx = self.tcx();
11101110
for user_annotation in self.user_type_annotations {
11111111
let CanonicalUserTypeAnnotation { span, ref user_ty, inferred_ty } = *user_annotation;
1112-
let annotation = self.instantiate_canonical_with_fresh_inference_vars(span, user_ty);
1112+
let annotation = self.instantiate_canonical(span, user_ty);
11131113
if let ty::UserType::TypeOf(def, args) = annotation
11141114
&& let DefKind::InlineConst = tcx.def_kind(def)
11151115
{

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
386386

387387
let infcx = &self.infcx;
388388
let (ParamEnvAnd { param_env: _, value: self_ty }, canonical_inference_vars) =
389-
infcx.instantiate_canonical_with_fresh_inference_vars(
390-
span,
391-
&param_env_and_self_ty,
392-
);
389+
infcx.instantiate_canonical(span, &param_env_and_self_ty);
393390
debug!(
394391
"probe_op: Mode::Path, param_env_and_self_ty={:?} self_ty={:?}",
395392
param_env_and_self_ty, self_ty
@@ -661,13 +658,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
661658
// of the iterations in the autoderef loop, so there is no problem with it
662659
// being discoverable in another one of these iterations.
663660
//
664-
// Using `instantiate_canonical_with_fresh_inference_vars` on our
661+
// Using `instantiate_canonical` on our
665662
// `Canonical<QueryResponse<Ty<'tcx>>>` and then *throwing away* the
666663
// `CanonicalVarValues` will exactly give us such a generalization - it
667664
// will still match the original object type, but it won't pollute our
668665
// type variables in any form, so just do that!
669666
let (QueryResponse { value: generalized_self_ty, .. }, _ignored_var_values) =
670-
self.fcx.instantiate_canonical_with_fresh_inference_vars(self.span, self_ty);
667+
self.fcx.instantiate_canonical(self.span, self_ty);
671668

672669
self.assemble_inherent_candidates_from_object(generalized_self_ty);
673670
self.assemble_inherent_impl_candidates_for_type(p.def_id());

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ mod instantiate;
3838
pub mod query_response;
3939

4040
impl<'tcx> InferCtxt<'tcx> {
41-
/// Creates an instantiation S for the canonical value with fresh
42-
/// inference variables and applies it to the canonical value.
41+
/// Creates an instantiation S for the canonical value with fresh inference
42+
/// variables and placeholders then applies it to the canonical value.
4343
/// Returns both the instantiated result *and* the instantiation S.
4444
///
4545
/// This can be invoked as part of constructing an
@@ -50,7 +50,7 @@ impl<'tcx> InferCtxt<'tcx> {
5050
/// At the end of processing, the instantiation S (once
5151
/// canonicalized) then represents the values that you computed
5252
/// for each of the canonical inputs to your query.
53-
pub fn instantiate_canonical_with_fresh_inference_vars<T>(
53+
pub fn instantiate_canonical<T>(
5454
&self,
5555
span: Span,
5656
canonical: &Canonical<'tcx, T>,

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
678678
T: TypeFoldable<TyCtxt<'tcx>>,
679679
{
680680
let infcx = self.build();
681-
let (value, args) = infcx.instantiate_canonical_with_fresh_inference_vars(span, canonical);
681+
let (value, args) = infcx.instantiate_canonical(span, canonical);
682682
(infcx, value, args)
683683
}
684684

compiler/rustc_middle/src/ty/region.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,9 @@ pub struct EarlyParamRegion {
336336

337337
impl std::fmt::Debug for EarlyParamRegion {
338338
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
339-
write!(f, "{:?}, {}, {}", self.def_id, self.index, self.name)
339+
// FIXME(BoxyUwU): self.def_id goes first because of `erased-regions-in-hidden-ty.rs` being impossible to write
340+
// error annotations for otherwise. :). Ideally this would be `self.name, self.index, self.def_id`.
341+
write!(f, "{:?}_{}/#{}", self.def_id, self.name, self.index)
340342
}
341343
}
342344

@@ -381,13 +383,25 @@ pub enum BoundRegionKind {
381383
BrEnv,
382384
}
383385

384-
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, PartialOrd, Ord)]
386+
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, PartialOrd, Ord)]
385387
#[derive(HashStable)]
386388
pub struct BoundRegion {
387389
pub var: BoundVar,
388390
pub kind: BoundRegionKind,
389391
}
390392

393+
impl core::fmt::Debug for BoundRegion {
394+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
395+
match self.kind {
396+
BoundRegionKind::BrAnon => write!(f, "{:?}", self.var),
397+
BoundRegionKind::BrEnv => write!(f, "{:?}.Env", self.var),
398+
BoundRegionKind::BrNamed(def, symbol) => {
399+
write!(f, "{:?}.Named({:?}, {:?})", self.var, def, symbol)
400+
}
401+
}
402+
}
403+
}
404+
391405
impl BoundRegionKind {
392406
pub fn is_named(&self) -> bool {
393407
match *self {

compiler/rustc_type_ir/src/region_kind.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,23 +223,27 @@ impl<I: Interner> DebugWithInfcx<I> for RegionKind<I> {
223223
f: &mut core::fmt::Formatter<'_>,
224224
) -> core::fmt::Result {
225225
match this.data {
226-
ReEarlyParam(data) => write!(f, "ReEarlyParam({data:?})"),
226+
ReEarlyParam(data) => write!(f, "{data:?}"),
227227

228228
ReBound(binder_id, bound_region) => {
229-
write!(f, "ReBound({binder_id:?}, {bound_region:?})")
229+
write!(f, "'")?;
230+
crate::debug_bound_var(f, *binder_id, bound_region)
230231
}
231232

232233
ReLateParam(fr) => write!(f, "{fr:?}"),
233234

234-
ReStatic => f.write_str("ReStatic"),
235+
ReStatic => f.write_str("'static"),
235236

236237
ReVar(vid) => write!(f, "{:?}", &this.wrap(vid)),
237238

238-
RePlaceholder(placeholder) => write!(f, "RePlaceholder({placeholder:?})"),
239+
RePlaceholder(placeholder) => write!(f, "{placeholder:?}"),
239240

240-
ReErased => f.write_str("ReErased"),
241+
// Use `'{erased}` as the output instead of `'erased` so that its more obviously distinct from
242+
// a `ReEarlyParam` named `'erased`. Technically that would print as `'erased/#IDX` so this is
243+
// not strictly necessary but *shrug*
244+
ReErased => f.write_str("'{erased}"),
241245

242-
ReError(_) => f.write_str("ReError"),
246+
ReError(_) => f.write_str("'{region error}"),
243247
}
244248
}
245249
}

tests/mir-opt/issue_99325.main.built.after.32bit.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
| User Type Annotations
44
| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:13:16: 13:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5-
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}), args: [] }: &ReStatic [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5+
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}), args: [] }: &'static [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
66
|
77
fn main() -> () {
88
let mut _0: ();

tests/mir-opt/issue_99325.main.built.after.64bit.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
| User Type Annotations
44
| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:13:16: 13:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5-
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}), args: [] }: &ReStatic [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5+
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}), args: [] }: &'static [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
66
|
77
fn main() -> () {
88
let mut _0: ();

0 commit comments

Comments
 (0)