[naga wgsl-out] Rearrange Writer and WriterTypeContext.

In `naga::back::wgsl`, move `WriterTypeContext` out of the way, and
coalesce `Writer`'s methods back into a single `impl` block.

This is just code motion; there should be no change in behavior.
This commit is contained in:
Jim Blandy
2025-03-05 20:59:13 -08:00
committed by Erich Gubler
parent 2942dc0cb2
commit 84a4a66bc4

View File

@@ -429,28 +429,7 @@ impl<W: Write> Writer<W> {
Ok(())
}
}
struct WriterTypeContext<'m> {
module: &'m Module,
names: &'m crate::FastHashMap<NameKey, String>,
}
impl<W: Write> TypeContext<W> for WriterTypeContext<'_> {
fn lookup_type(&self, handle: Handle<crate::Type>) -> &crate::Type {
&self.module.types[handle]
}
fn type_name(&self, handle: Handle<crate::Type>) -> &str {
self.names[&NameKey::Type(handle)].as_str()
}
fn write_override(&self, _: Handle<crate::Override>, _: &mut W) -> core::fmt::Result {
unreachable!("overrides should be validated out");
}
}
impl<W: Write> Writer<W> {
fn write_type(&mut self, module: &Module, ty: Handle<crate::Type>) -> BackendResult {
// This actually can't be factored out into a nice constructor method,
// because the borrow checker needs to be able to see that the borrows
@@ -1741,6 +1720,25 @@ impl<W: Write> Writer<W> {
}
}
struct WriterTypeContext<'m> {
module: &'m Module,
names: &'m crate::FastHashMap<NameKey, String>,
}
impl<W: Write> TypeContext<W> for WriterTypeContext<'_> {
fn lookup_type(&self, handle: Handle<crate::Type>) -> &crate::Type {
&self.module.types[handle]
}
fn type_name(&self, handle: Handle<crate::Type>) -> &str {
self.names[&NameKey::Type(handle)].as_str()
}
fn write_override(&self, _: Handle<crate::Override>, _: &mut W) -> core::fmt::Result {
unreachable!("overrides should be validated out");
}
}
fn map_binding_to_attribute(binding: &crate::Binding) -> Vec<Attribute> {
match *binding {
crate::Binding::BuiltIn(built_in) => {