Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use newtype_index for IntVid and FloatVid. #115634

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading