[tint] Change signature of ApplySubstituteOverrides()
So that it doesn't need to mutate (move) the input program.
Change-Id: I91fe8d06b383e9716f04f0893df3f6f4ac4c8e3a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/154302
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/src/tint/fuzzers/tint_common_fuzzer.cc b/src/tint/fuzzers/tint_common_fuzzer.cc
index 04dd2ef..1b6bd5a 100644
--- a/src/tint/fuzzers/tint_common_fuzzer.cc
+++ b/src/tint/fuzzers/tint_common_fuzzer.cc
@@ -237,9 +237,11 @@
}
// Run SubstituteOverride if required
- program = tint::wgsl::ApplySubstituteOverrides(std::move(program));
- if (!program.IsValid()) {
- return 0;
+ if (auto transformed = tint::wgsl::ApplySubstituteOverrides(program)) {
+ program = std::move(*transformed);
+ if (!program.IsValid()) {
+ return 0;
+ }
}
// For the generates which use MultiPlanar, make sure the configuration options are provided so
diff --git a/src/tint/fuzzers/tint_concurrency_fuzzer.cc b/src/tint/fuzzers/tint_concurrency_fuzzer.cc
index 9c6ac99..acd51eb 100644
--- a/src/tint/fuzzers/tint_concurrency_fuzzer.cc
+++ b/src/tint/fuzzers/tint_concurrency_fuzzer.cc
@@ -53,9 +53,11 @@
return 0; // Not supported
}
- program = tint::wgsl::ApplySubstituteOverrides(std::move(program));
- if (!program.IsValid()) {
- return 0;
+ if (auto transformed = tint::wgsl::ApplySubstituteOverrides(program)) {
+ program = std::move(*transformed);
+ if (!program.IsValid()) {
+ return 0;
+ }
}
tint::inspector::Inspector inspector(program);
diff --git a/src/tint/fuzzers/tint_ir_roundtrip_fuzzer.cc b/src/tint/fuzzers/tint_ir_roundtrip_fuzzer.cc
index 22db596..47fb9ea 100644
--- a/src/tint/fuzzers/tint_ir_roundtrip_fuzzer.cc
+++ b/src/tint/fuzzers/tint_ir_roundtrip_fuzzer.cc
@@ -68,9 +68,11 @@
return 0;
}
- src = tint::wgsl::ApplySubstituteOverrides(std::move(src));
- if (!src.IsValid()) {
- return 0;
+ if (auto transformed = tint::wgsl::ApplySubstituteOverrides(src)) {
+ src = std::move(*transformed);
+ if (!src.IsValid()) {
+ return 0;
+ }
}
auto ir = tint::wgsl::reader::ProgramToIR(src);
diff --git a/src/tint/lang/wgsl/helpers/apply_substitute_overrides.cc b/src/tint/lang/wgsl/helpers/apply_substitute_overrides.cc
index 93990e9..0065689d 100644
--- a/src/tint/lang/wgsl/helpers/apply_substitute_overrides.cc
+++ b/src/tint/lang/wgsl/helpers/apply_substitute_overrides.cc
@@ -24,7 +24,7 @@
namespace tint::wgsl {
-Program ApplySubstituteOverrides(Program&& program) {
+std::optional<Program> ApplySubstituteOverrides(const Program& program) {
ast::transform::SubstituteOverride::Config cfg;
inspector::Inspector inspector(program);
auto default_values = inspector.GetOverrideDefaultValues();
@@ -37,7 +37,7 @@
}
if (default_values.empty()) {
- return std::move(program);
+ return std::nullopt;
}
ast::transform::DataMap override_data;
diff --git a/src/tint/lang/wgsl/helpers/apply_substitute_overrides.h b/src/tint/lang/wgsl/helpers/apply_substitute_overrides.h
index 5278e9f..dd6da44 100644
--- a/src/tint/lang/wgsl/helpers/apply_substitute_overrides.h
+++ b/src/tint/lang/wgsl/helpers/apply_substitute_overrides.h
@@ -15,6 +15,8 @@
#ifndef SRC_TINT_LANG_WGSL_HELPERS_APPLY_SUBSTITUTE_OVERRIDES_H_
#define SRC_TINT_LANG_WGSL_HELPERS_APPLY_SUBSTITUTE_OVERRIDES_H_
+#include <optional>
+
// Forward declarations
namespace tint {
class Program;
@@ -22,9 +24,12 @@
namespace tint::wgsl {
-/// @returns a new program with all overrides subsituted with const variables
-/// @param program the input program
-Program ApplySubstituteOverrides(Program&& program);
+/// If needed, returns a new program with all `override` declarations substituted with `const`
+/// variables.
+/// @param program A valid program
+/// @return A new program with `override`s substituted, or std::nullopt if the program has no
+/// `override`s.
+std::optional<Program> ApplySubstituteOverrides(const Program& program);
} // namespace tint::wgsl