[naga] Use HandleVec in Typeifier.

Change `naga::front::Typifier::resolutions` to be a
`HandleVec<Expression, TypeResolution>`, not a plain `Vec`.
This commit is contained in:
Jim Blandy 2024-06-22 23:40:56 -07:00 committed by Teodor Tanasoaia
parent 4b485fdb0e
commit 056d0db43e
2 changed files with 10 additions and 9 deletions

View File

@ -798,6 +798,7 @@ where
///
/// [`insert`]: HandleVec::insert
/// [`HashMap::insert`]: std::collections::HashMap::insert
#[derive(Debug)]
pub(crate) struct HandleVec<T, U> {
inner: Vec<U>,
as_keys: PhantomData<T>,

View File

@ -15,7 +15,7 @@ pub mod spv;
pub mod wgsl;
use crate::{
arena::{Arena, Handle, UniqueArena},
arena::{Arena, Handle, HandleVec, UniqueArena},
proc::{ResolveContext, ResolveError, TypeResolution},
FastHashMap,
};
@ -52,13 +52,13 @@ use std::ops;
/// [`LocalVariable`]: crate::LocalVariable
#[derive(Debug, Default)]
pub struct Typifier {
resolutions: Vec<TypeResolution>,
resolutions: HandleVec<crate::Expression, TypeResolution>,
}
impl Typifier {
pub const fn new() -> Self {
Typifier {
resolutions: Vec::new(),
resolutions: HandleVec::new(),
}
}
@ -71,7 +71,7 @@ impl Typifier {
expr_handle: Handle<crate::Expression>,
types: &'a UniqueArena<crate::Type>,
) -> &'a crate::TypeInner {
self.resolutions[expr_handle.index()].inner_with(types)
self.resolutions[expr_handle].inner_with(types)
}
/// Add an expression's type to an `Arena<Type>`.
@ -111,9 +111,9 @@ impl Typifier {
if self.resolutions.len() <= expr_handle.index() {
for (eh, expr) in expressions.iter().skip(self.resolutions.len()) {
//Note: the closure can't `Err` by construction
let resolution = ctx.resolve(expr, |h| Ok(&self.resolutions[h.index()]))?;
let resolution = ctx.resolve(expr, |h| Ok(&self.resolutions[h]))?;
log::debug!("Resolving {:?} = {:?} : {:?}", eh, expr, resolution);
self.resolutions.push(resolution);
self.resolutions.insert(eh, resolution);
}
}
Ok(())
@ -137,8 +137,8 @@ impl Typifier {
} else {
let expr = &expressions[expr_handle];
//Note: the closure can't `Err` by construction
let resolution = ctx.resolve(expr, |h| Ok(&self.resolutions[h.index()]))?;
self.resolutions[expr_handle.index()] = resolution;
let resolution = ctx.resolve(expr, |h| Ok(&self.resolutions[h]))?;
self.resolutions[expr_handle] = resolution;
Ok(())
}
}
@ -147,7 +147,7 @@ impl Typifier {
impl ops::Index<Handle<crate::Expression>> for Typifier {
type Output = TypeResolution;
fn index(&self, handle: Handle<crate::Expression>) -> &Self::Output {
&self.resolutions[handle.index()]
&self.resolutions[handle]
}
}