Skip to content

Commit

Permalink
Rollup merge of rust-lang#115634 - nnethercote:IntVid-FloatVid, r=oli…
Browse files Browse the repository at this point in the history
…-obk

Use `newtype_index` for `IntVid` and `FloatVid`.

`TyVid` already uses `newtype_index`.
  • Loading branch information
GuillaumeGomez authored Sep 7, 2023
2 parents 791db52 + a932990 commit d533ddf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,13 +764,13 @@ impl<'tcx> InferCtxt<'tcx> {
.collect();
vars.extend(
(0..inner.int_unification_table().len())
.map(|i| ty::IntVid { index: i as u32 })
.map(|i| ty::IntVid::from_u32(i as u32))
.filter(|&vid| inner.int_unification_table().probe_value(vid).is_none())
.map(|v| Ty::new_int_var(self.tcx, v)),
);
vars.extend(
(0..inner.float_unification_table().len())
.map(|i| ty::FloatVid { index: i as u32 })
.map(|i| ty::FloatVid::from_u32(i as u32))
.filter(|&vid| inner.float_unification_table().probe_value(vid).is_none())
.map(|v| Ty::new_float_var(self.tcx, v)),
);
Expand Down
36 changes: 12 additions & 24 deletions compiler/rustc_type_ir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,16 +574,16 @@ rustc_index::newtype_index! {
pub struct TyVid {}
}

/// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
pub struct IntVid {
pub index: u32,
rustc_index::newtype_index! {
/// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**.
#[debug_format = "?{}i"]
pub struct IntVid {}
}

/// An **float**ing-point (`f32` or `f64`) type **v**ariable **ID**.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
pub struct FloatVid {
pub index: u32,
rustc_index::newtype_index! {
/// A **float**ing-point (`f32` or `f64`) type **v**ariable **ID**.
#[debug_format = "?{}f"]
pub struct FloatVid {}
}

/// A placeholder for a type that hasn't been inferred yet.
Expand Down Expand Up @@ -645,11 +645,11 @@ impl UnifyKey for IntVid {
type Value = Option<IntVarValue>;
#[inline] // make this function eligible for inlining - it is quite hot.
fn index(&self) -> u32 {
self.index
self.as_u32()
}
#[inline]
fn from_index(i: u32) -> IntVid {
IntVid { index: i }
IntVid::from_u32(i)
}
fn tag() -> &'static str {
"IntVid"
Expand All @@ -662,11 +662,11 @@ impl UnifyKey for FloatVid {
type Value = Option<FloatVarValue>;
#[inline]
fn index(&self) -> u32 {
self.index
self.as_u32()
}
#[inline]
fn from_index(i: u32) -> FloatVid {
FloatVid { index: i }
FloatVid::from_u32(i)
}
fn tag() -> &'static str {
"FloatVid"
Expand Down Expand Up @@ -770,18 +770,6 @@ impl fmt::Debug for FloatVarValue {
}
}

impl fmt::Debug for IntVid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "?{}i", self.index)
}
}

impl fmt::Debug for FloatVid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "?{}f", self.index)
}
}

impl fmt::Debug for Variance {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match *self {
Expand Down

0 comments on commit d533ddf

Please sign in to comment.