From a71bd22de1263cbf5e7774e0abad9653b77cec42 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 24 May 2023 23:07:36 +0000 Subject: [PATCH] [tint][constant] Make Value::Clone() return a const pointer Once constants are de-duplicated, they must be fully immutable. Bug: tint:1935 Change-Id: Iba1f85079f2ada1f44ba44d1da9b8a65d1abf2ad Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/134361 Kokoro: Kokoro Reviewed-by: James Price Reviewed-by: Dan Sinclair --- src/tint/constant/composite.cc | 2 +- src/tint/constant/composite.h | 2 +- src/tint/constant/scalar.h | 2 +- src/tint/constant/splat.cc | 2 +- src/tint/constant/splat.h | 2 +- src/tint/constant/value.h | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/tint/constant/composite.cc b/src/tint/constant/composite.cc index 5b004e0998..fee4baf186 100644 --- a/src/tint/constant/composite.cc +++ b/src/tint/constant/composite.cc @@ -28,7 +28,7 @@ Composite::Composite(const type::Type* t, Composite::~Composite() = default; -Composite* Composite::Clone(CloneContext& ctx) const { +const Composite* Composite::Clone(CloneContext& ctx) const { auto* ty = type->Clone(ctx.type_ctx); utils::Vector els; for (const auto* el : elements) { diff --git a/src/tint/constant/composite.h b/src/tint/constant/composite.h index 7a50640d7d..23367a594a 100644 --- a/src/tint/constant/composite.h +++ b/src/tint/constant/composite.h @@ -61,7 +61,7 @@ class Composite : public utils::Castable { /// Clones the constant into the provided context /// @param ctx the clone context /// @returns the cloned node - Composite* Clone(CloneContext& ctx) const override; + const Composite* Clone(CloneContext& ctx) const override; /// The composite type type::Type const* const type; diff --git a/src/tint/constant/scalar.h b/src/tint/constant/scalar.h index ab5f8528ac..5a40cdf457 100644 --- a/src/tint/constant/scalar.h +++ b/src/tint/constant/scalar.h @@ -61,7 +61,7 @@ class Scalar : public utils::Castable, Value> { /// Clones the constant into the provided context /// @param ctx the clone context /// @returns the cloned node - Scalar* Clone(CloneContext& ctx) const override { + const Scalar* Clone(CloneContext& ctx) const override { auto* ty = type->Clone(ctx.type_ctx); return ctx.dst.constants->Create>(ty, value); } diff --git a/src/tint/constant/splat.cc b/src/tint/constant/splat.cc index 4ebfe5f5f8..e1c9a90fea 100644 --- a/src/tint/constant/splat.cc +++ b/src/tint/constant/splat.cc @@ -22,7 +22,7 @@ Splat::Splat(const type::Type* t, const constant::Value* e, size_t n) : type(t), Splat::~Splat() = default; -Splat* Splat::Clone(CloneContext& ctx) const { +const Splat* Splat::Clone(CloneContext& ctx) const { auto* ty = type->Clone(ctx.type_ctx); auto* element = el->Clone(ctx); return ctx.dst.constants->Create(ty, element, count); diff --git a/src/tint/constant/splat.h b/src/tint/constant/splat.h index d8e55a6764..2bf82ddbc5 100644 --- a/src/tint/constant/splat.h +++ b/src/tint/constant/splat.h @@ -57,7 +57,7 @@ class Splat : public utils::Castable { /// Clones the constant into the provided context /// @param ctx the clone context /// @returns the cloned node - Splat* Clone(CloneContext& ctx) const override; + const Splat* Clone(CloneContext& ctx) const override; /// The type of the splat element type::Type const* const type; diff --git a/src/tint/constant/value.h b/src/tint/constant/value.h index fe1f78a83c..baf1171a3d 100644 --- a/src/tint/constant/value.h +++ b/src/tint/constant/value.h @@ -80,7 +80,7 @@ class Value : public utils::Castable { /// Clones the constant into the provided context /// @param ctx the clone context /// @returns the cloned node - virtual Value* Clone(CloneContext& ctx) const = 0; + virtual const Value* Clone(CloneContext& ctx) const = 0; protected: /// @returns the value, if this is of a scalar value or abstract numeric, otherwise