Skip to content

Commit ffda18a

Browse files
committed
[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.
1 parent c55c38e commit ffda18a

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

naga/src/back/wgsl/writer.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -399,28 +399,7 @@ impl<W: Write> Writer<W> {
399399

400400
Ok(())
401401
}
402-
}
403-
404-
struct WriterTypeContext<'m> {
405-
module: &'m Module,
406-
names: &'m crate::FastHashMap<NameKey, String>,
407-
}
408-
409-
impl<W: Write> TypeContext<W> for WriterTypeContext<'_> {
410-
fn lookup_type(&self, handle: Handle<crate::Type>) -> &crate::Type {
411-
&self.module.types[handle]
412-
}
413-
414-
fn type_name(&self, handle: Handle<crate::Type>) -> &str {
415-
self.names[&NameKey::Type(handle)].as_str()
416-
}
417-
418-
fn write_override(&self, _: Handle<crate::Override>, _: &mut W) -> core::fmt::Result {
419-
unreachable!("overrides should be validated out");
420-
}
421-
}
422402

423-
impl<W: Write> Writer<W> {
424403
fn write_type(&mut self, module: &Module, ty: Handle<crate::Type>) -> BackendResult {
425404
let type_context = WriterTypeContext {
426405
module,
@@ -1707,6 +1686,25 @@ impl<W: Write> Writer<W> {
17071686
}
17081687
}
17091688

1689+
struct WriterTypeContext<'m> {
1690+
module: &'m Module,
1691+
names: &'m crate::FastHashMap<NameKey, String>,
1692+
}
1693+
1694+
impl<W: Write> TypeContext<W> for WriterTypeContext<'_> {
1695+
fn lookup_type(&self, handle: Handle<crate::Type>) -> &crate::Type {
1696+
&self.module.types[handle]
1697+
}
1698+
1699+
fn type_name(&self, handle: Handle<crate::Type>) -> &str {
1700+
self.names[&NameKey::Type(handle)].as_str()
1701+
}
1702+
1703+
fn write_override(&self, _: Handle<crate::Override>, _: &mut W) -> core::fmt::Result {
1704+
unreachable!("overrides should be validated out");
1705+
}
1706+
}
1707+
17101708
fn map_binding_to_attribute(binding: &crate::Binding) -> Vec<Attribute> {
17111709
match *binding {
17121710
crate::Binding::BuiltIn(built_in) => {

0 commit comments

Comments
 (0)