mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 16:24:24 +00:00
[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:
parent
4b485fdb0e
commit
056d0db43e
@ -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>,
|
||||
|
@ -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]
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user