Use IndexMap for handling stable Ty
This commit is contained in:
parent
3f60165d27
commit
17f6df9c63
4 changed files with 23 additions and 29 deletions
|
@ -6,7 +6,7 @@ use super::{
|
|||
use crate::{Filename, Opaque};
|
||||
use std::fmt::{self, Debug, Formatter};
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub struct Ty(pub usize);
|
||||
|
||||
impl Debug for Ty {
|
||||
|
@ -52,15 +52,6 @@ impl Const {
|
|||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct ConstId(pub usize);
|
||||
|
||||
impl IndexedVal for ConstId {
|
||||
fn to_val(index: usize) -> Self {
|
||||
ConstId(index)
|
||||
}
|
||||
fn to_index(&self) -> usize {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
type Ident = Opaque;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -136,15 +127,6 @@ pub struct LineInfo {
|
|||
pub end_col: usize,
|
||||
}
|
||||
|
||||
impl IndexedVal for Span {
|
||||
fn to_val(index: usize) -> Self {
|
||||
Span(index)
|
||||
}
|
||||
fn to_index(&self) -> usize {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum TyKind {
|
||||
RigidTy(RigidTy),
|
||||
|
@ -631,3 +613,20 @@ pub trait IndexedVal {
|
|||
|
||||
fn to_index(&self) -> usize;
|
||||
}
|
||||
|
||||
macro_rules! index_impl {
|
||||
($name:ident) => {
|
||||
impl IndexedVal for $name {
|
||||
fn to_val(index: usize) -> Self {
|
||||
$name(index)
|
||||
}
|
||||
fn to_index(&self) -> usize {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
index_impl!(ConstId);
|
||||
index_impl!(Ty);
|
||||
index_impl!(Span);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue