Skip to content

Commit e18779b

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 ae4af65 commit e18779b

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

naga/src/back/wgsl/writer.rs

+19-21
Original file line numberDiff line numberDiff line change
@@ -429,28 +429,7 @@ impl<W: Write> Writer<W> {
429429

430430
Ok(())
431431
}
432-
}
433-
434-
struct WriterTypeContext<'m> {
435-
module: &'m Module,
436-
names: &'m crate::FastHashMap<NameKey, String>,
437-
}
438-
439-
impl<W: Write> TypeContext<W> for WriterTypeContext<'_> {
440-
fn lookup_type(&self, handle: Handle<crate::Type>) -> &crate::Type {
441-
&self.module.types[handle]
442-
}
443-
444-
fn type_name(&self, handle: Handle<crate::Type>) -> &str {
445-
self.names[&NameKey::Type(handle)].as_str()
446-
}
447-
448-
fn write_override(&self, _: Handle<crate::Override>, _: &mut W) -> core::fmt::Result {
449-
unreachable!("overrides should be validated out");
450-
}
451-
}
452432

453-
impl<W: Write> Writer<W> {
454433
fn write_type(&mut self, module: &Module, ty: Handle<crate::Type>) -> BackendResult {
455434
// This actually can't be factored out into a nice constructor method,
456435
// because the borrow checker needs to be able to see that the borrows
@@ -1741,6 +1720,25 @@ impl<W: Write> Writer<W> {
17411720
}
17421721
}
17431722

1723+
struct WriterTypeContext<'m> {
1724+
module: &'m Module,
1725+
names: &'m crate::FastHashMap<NameKey, String>,
1726+
}
1727+
1728+
impl<W: Write> TypeContext<W> for WriterTypeContext<'_> {
1729+
fn lookup_type(&self, handle: Handle<crate::Type>) -> &crate::Type {
1730+
&self.module.types[handle]
1731+
}
1732+
1733+
fn type_name(&self, handle: Handle<crate::Type>) -> &str {
1734+
self.names[&NameKey::Type(handle)].as_str()
1735+
}
1736+
1737+
fn write_override(&self, _: Handle<crate::Override>, _: &mut W) -> core::fmt::Result {
1738+
unreachable!("overrides should be validated out");
1739+
}
1740+
}
1741+
17441742
fn map_binding_to_attribute(binding: &crate::Binding) -> Vec<Attribute> {
17451743
match *binding {
17461744
crate::Binding::BuiltIn(built_in) => {

0 commit comments

Comments
 (0)