Skip to content

Commit fc9c8bf

Browse files
andyleisersonLiamoluckoErichDonGubler
committed
refactor(msl-out): add NamedKeyExt trait with local helper method
-- Co-authored-by: Liam Murphy <[email protected]> Co-Authored-By: Erich Gubler <[email protected]>
1 parent 587aea2 commit fc9c8bf

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

naga/src/back/msl/writer.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -599,11 +599,23 @@ impl crate::Type {
599599
}
600600
}
601601

602+
#[derive(Clone, Copy)]
602603
enum FunctionOrigin {
603604
Handle(Handle<crate::Function>),
604605
EntryPoint(proc::EntryPointIndex),
605606
}
606607

608+
trait NameKeyExt {
609+
fn local(origin: FunctionOrigin, local_handle: Handle<crate::LocalVariable>) -> NameKey {
610+
match origin {
611+
FunctionOrigin::Handle(handle) => NameKey::FunctionLocal(handle, local_handle),
612+
FunctionOrigin::EntryPoint(idx) => NameKey::EntryPointLocal(idx, local_handle),
613+
}
614+
}
615+
}
616+
617+
impl NameKeyExt for NameKey {}
618+
607619
/// A level of detail argument.
608620
///
609621
/// When [`BoundsCheckPolicy::Restrict`] applies to an [`ImageLoad`] access, we
@@ -1750,14 +1762,7 @@ impl<W: Write> Writer<W> {
17501762
write!(self.out, "{name}")?;
17511763
}
17521764
crate::Expression::LocalVariable(handle) => {
1753-
let name_key = match context.origin {
1754-
FunctionOrigin::Handle(fun_handle) => {
1755-
NameKey::FunctionLocal(fun_handle, handle)
1756-
}
1757-
FunctionOrigin::EntryPoint(ep_index) => {
1758-
NameKey::EntryPointLocal(ep_index, handle)
1759-
}
1760-
};
1765+
let name_key = NameKey::local(context.origin, handle);
17611766
let name = &self.names[&name_key];
17621767
write!(self.out, "{name}")?;
17631768
}

0 commit comments

Comments
 (0)