[naga] Change HandleSet::insert to return a bool.

Change `HandleSet::insert` to return `true` if the handle was not
already in the set.

Change uses in `naga::compact` which were taking advantage of the
prior return type of `()` to avoid needing to use semicolons in
`match` arms.
This commit is contained in:
Jim Blandy authored and Teodor Tanasoaia committed 2024-06-25 09:34:30 +02:00
1 parent 0656fb8ea8
commit f262dce065
4 files changed
+54 -24

No files matched your search

+4 -2
View File
@@ -31,8 +31,10 @@ impl<T> HandleSet<T> {
}
/// Add `handle` to the set.
pub fn insert(&mut self, handle: Handle<T>) {
self.members.insert(handle.index());
///
/// Return `true` if `handle` was not already present in the set.
pub fn insert(&mut self, handle: Handle<T>) -> bool {
self.members.insert(handle.index())
}
/// Add handles from `iter` to the set.
+42 -16
View File
@@ -88,28 +88,38 @@ impl<'tracer> ExpressionTracer<'tracer> {
match self.global_expressions_used {
Some(ref mut used) => used.insert(init),
None => self.expressions_used.insert(init),
}
};
}
Ex::Override(_) => {
// All overrides are considered used by definition. We mark
// their types and initialization expressions as used in
// `compact::compact`, so we have no more work to do here.
}
Ex::ZeroValue(ty) => self.types_used.insert(ty),
Ex::ZeroValue(ty) => {
self.types_used.insert(ty);
}
Ex::Compose { ty, ref components } => {
self.types_used.insert(ty);
self.expressions_used
.insert_iter(components.iter().cloned());
}
Ex::Access { base, index } => self.expressions_used.insert_iter([base, index]),
Ex::AccessIndex { base, index: _ } => self.expressions_used.insert(base),
Ex::Splat { size: _, value } => self.expressions_used.insert(value),
Ex::AccessIndex { base, index: _ } => {
self.expressions_used.insert(base);
}
Ex::Splat { size: _, value } => {
self.expressions_used.insert(value);
}
Ex::Swizzle {
size: _,
vector,
pattern: _,
} => self.expressions_used.insert(vector),
Ex::Load { pointer } => self.expressions_used.insert(pointer),
} => {
self.expressions_used.insert(vector);
}
Ex::Load { pointer } => {
self.expressions_used.insert(pointer);
}
Ex::ImageSample {
image,
sampler,
@@ -130,7 +140,9 @@ impl<'tracer> ExpressionTracer<'tracer> {
use crate::SampleLevel as Sl;
match *level {
Sl::Auto | Sl::Zero => {}
Sl::Exact(expr) | Sl::Bias(expr) => self.expressions_used.insert(expr),
Sl::Exact(expr) | Sl::Bias(expr) => {
self.expressions_used.insert(expr);
}
Sl::Gradient { x, y } => self.expressions_used.insert_iter([x, y]),
}
self.expressions_used.insert_iter(depth_ref);
@@ -156,7 +168,9 @@ impl<'tracer> ExpressionTracer<'tracer> {
Iq::NumLevels | Iq::NumLayers | Iq::NumSamples => {}
}
}
Ex::Unary { op: _, expr } => self.expressions_used.insert(expr),
Ex::Unary { op: _, expr } => {
self.expressions_used.insert(expr);
}
Ex::Binary { op: _, left, right } => {
self.expressions_used.insert_iter([left, right]);
}
@@ -171,8 +185,12 @@ impl<'tracer> ExpressionTracer<'tracer> {
axis: _,
ctrl: _,
expr,
} => self.expressions_used.insert(expr),
Ex::Relational { fun: _, argument } => self.expressions_used.insert(argument),
} => {
self.expressions_used.insert(expr);
}
Ex::Relational { fun: _, argument } => {
self.expressions_used.insert(argument);
}
Ex::Math {
fun: _,
arg,
@@ -189,15 +207,23 @@ impl<'tracer> ExpressionTracer<'tracer> {
expr,
kind: _,
convert: _,
} => self.expressions_used.insert(expr),
Ex::AtomicResult { ty, comparison: _ } => self.types_used.insert(ty),
Ex::WorkGroupUniformLoadResult { ty } => self.types_used.insert(ty),
Ex::ArrayLength(expr) => self.expressions_used.insert(expr),
Ex::SubgroupOperationResult { ty } => self.types_used.insert(ty),
} => {
self.expressions_used.insert(expr);
}
Ex::ArrayLength(expr) => {
self.expressions_used.insert(expr);
}
Ex::AtomicResult { ty, comparison: _ }
| Ex::WorkGroupUniformLoadResult { ty }
| Ex::SubgroupOperationResult { ty } => {
self.types_used.insert(ty);
}
Ex::RayQueryGetIntersection {
query,
committed: _,
} => self.expressions_used.insert(query),
} => {
self.expressions_used.insert(query);
}
}
}
}
+5 -5
View File
@@ -101,9 +101,9 @@ impl FunctionTracer<'_> {
}
St::SubgroupBallot { result, predicate } => {
if let Some(predicate) = predicate {
self.expressions_used.insert(predicate)
self.expressions_used.insert(predicate);
}
self.expressions_used.insert(result)
self.expressions_used.insert(result);
}
St::SubgroupCollectiveOperation {
op: _,
@@ -112,7 +112,7 @@ impl FunctionTracer<'_> {
result,
} => {
self.expressions_used.insert(argument);
self.expressions_used.insert(result)
self.expressions_used.insert(result);
}
St::SubgroupGather {
mode,
@@ -126,11 +126,11 @@ impl FunctionTracer<'_> {
| crate::GatherMode::ShuffleDown(index)
| crate::GatherMode::ShuffleUp(index)
| crate::GatherMode::ShuffleXor(index) => {
self.expressions_used.insert(index)
self.expressions_used.insert(index);
}
}
self.expressions_used.insert(argument);
self.expressions_used.insert(result)
self.expressions_used.insert(result);
}
// Trivial statements.
+3 -1
View File
@@ -44,7 +44,9 @@ impl<'a> TypeTracer<'a> {
size: _,
stride: _,
}
| Ti::BindingArray { base, size: _ } => self.types_used.insert(base),
| Ti::BindingArray { base, size: _ } => {
self.types_used.insert(base);
}
Ti::Struct {
ref members,
span: _,