diff --git a/src/tint/constant/composite.cc b/src/tint/constant/composite.cc index 40bcc3c60c..a0f0c9f601 100644 --- a/src/tint/constant/composite.cc +++ b/src/tint/constant/composite.cc @@ -16,9 +16,9 @@ #include -TINT_INSTANTIATE_TYPEINFO(tint::resolver::Composite); +TINT_INSTANTIATE_TYPEINFO(tint::constant::Composite); -namespace tint::resolver { +namespace tint::constant { Composite::Composite(const type::Type* t, utils::VectorRef els, @@ -28,4 +28,4 @@ Composite::Composite(const type::Type* t, Composite::~Composite() = default; -} // namespace tint::resolver +} // namespace tint::constant diff --git a/src/tint/constant/composite.h b/src/tint/constant/composite.h index 5facc56c58..98bf93a1c7 100644 --- a/src/tint/constant/composite.h +++ b/src/tint/constant/composite.h @@ -22,7 +22,7 @@ #include "src/tint/utils/hash.h" #include "src/tint/utils/vector.h" -namespace tint::resolver { +namespace tint::constant { /// Composite holds a number of mixed child Constant values. /// Composite may be of a vector, matrix or array type. @@ -75,6 +75,6 @@ class Composite : public Castable { } }; -} // namespace tint::resolver +} // namespace tint::constant #endif // SRC_TINT_CONSTANT_COMPOSITE_H_ diff --git a/src/tint/constant/scalar.cc b/src/tint/constant/scalar.cc index 2f7de7fc62..b77cb3b0f6 100644 --- a/src/tint/constant/scalar.cc +++ b/src/tint/constant/scalar.cc @@ -14,10 +14,10 @@ #include "src/tint/constant/scalar.h" -TINT_INSTANTIATE_TYPEINFO(tint::resolver::Scalar); -TINT_INSTANTIATE_TYPEINFO(tint::resolver::Scalar); -TINT_INSTANTIATE_TYPEINFO(tint::resolver::Scalar); -TINT_INSTANTIATE_TYPEINFO(tint::resolver::Scalar); -TINT_INSTANTIATE_TYPEINFO(tint::resolver::Scalar); -TINT_INSTANTIATE_TYPEINFO(tint::resolver::Scalar); -TINT_INSTANTIATE_TYPEINFO(tint::resolver::Scalar); +TINT_INSTANTIATE_TYPEINFO(tint::constant::Scalar); +TINT_INSTANTIATE_TYPEINFO(tint::constant::Scalar); +TINT_INSTANTIATE_TYPEINFO(tint::constant::Scalar); +TINT_INSTANTIATE_TYPEINFO(tint::constant::Scalar); +TINT_INSTANTIATE_TYPEINFO(tint::constant::Scalar); +TINT_INSTANTIATE_TYPEINFO(tint::constant::Scalar); +TINT_INSTANTIATE_TYPEINFO(tint::constant::Scalar); diff --git a/src/tint/constant/scalar.h b/src/tint/constant/scalar.h index b159563465..bba4fbba86 100644 --- a/src/tint/constant/scalar.h +++ b/src/tint/constant/scalar.h @@ -21,7 +21,7 @@ #include "src/tint/type/type.h" #include "src/tint/utils/hash.h" -namespace tint::resolver { +namespace tint::constant { /// Scalar holds a single scalar or abstract-numeric value. /// Scalar implements the Constant interface. @@ -36,7 +36,7 @@ class Scalar : public Castable, constant::Constant> { /// @param v the scalar value Scalar(const type::Type* t, T v) : type(t), value(v) { if constexpr (IsFloatingPoint) { - TINT_ASSERT(Resolver, std::isfinite(v.value)); + TINT_ASSERT(Constant, std::isfinite(v.value)); } } ~Scalar() override = default; @@ -79,6 +79,6 @@ class Scalar : public Castable, constant::Constant> { const T value; }; -} // namespace tint::resolver +} // namespace tint::constant #endif // SRC_TINT_CONSTANT_SCALAR_H_ diff --git a/src/tint/constant/splat.cc b/src/tint/constant/splat.cc index 04ae2495db..2b0766e273 100644 --- a/src/tint/constant/splat.cc +++ b/src/tint/constant/splat.cc @@ -14,13 +14,13 @@ #include "src/tint/constant/splat.h" -TINT_INSTANTIATE_TYPEINFO(tint::resolver::Splat); +TINT_INSTANTIATE_TYPEINFO(tint::constant::Splat); -namespace tint::resolver { +namespace tint::constant { Splat::Splat(const type::Type* t, const constant::Constant* e, size_t n) : type(t), el(e), count(n) {} Splat::~Splat() = default; -} // namespace tint::resolver +} // namespace tint::constant diff --git a/src/tint/constant/splat.h b/src/tint/constant/splat.h index 1b7c9993d5..5393927f4d 100644 --- a/src/tint/constant/splat.h +++ b/src/tint/constant/splat.h @@ -20,7 +20,7 @@ #include "src/tint/type/type.h" #include "src/tint/utils/vector.h" -namespace tint::resolver { +namespace tint::constant { /// Splat holds a single Constant value, duplicated as all children. /// Splat is used for zero-initializers, 'splat' initializers, or initializers where each element is @@ -64,6 +64,6 @@ class Splat : public Castable { const size_t count; }; -} // namespace tint::resolver +} // namespace tint::constant #endif // SRC_TINT_CONSTANT_SPLAT_H_ diff --git a/src/tint/diagnostic/diagnostic.h b/src/tint/diagnostic/diagnostic.h index f66cb62110..82b9eb9ab9 100644 --- a/src/tint/diagnostic/diagnostic.h +++ b/src/tint/diagnostic/diagnostic.h @@ -37,6 +37,7 @@ inline bool operator>=(Severity a, Severity b) { enum class System { AST, Clone, + Constant, Inspector, IR, Program, diff --git a/src/tint/resolver/const_eval.cc b/src/tint/resolver/const_eval.cc index 295b00ae18..27d2592efa 100644 --- a/src/tint/resolver/const_eval.cc +++ b/src/tint/resolver/const_eval.cc @@ -241,7 +241,7 @@ const constant::Constant* CreateComposite(ProgramBuilder& builder, utils::VectorRef elements); template -ImplResult ScalarConvert(const Scalar* scalar, +ImplResult ScalarConvert(const constant::Scalar* scalar, ProgramBuilder& builder, const type::Type* target_ty, const Source& source) { @@ -258,13 +258,13 @@ ImplResult ScalarConvert(const Scalar* scalar, using FROM = T; if constexpr (std::is_same_v) { // [x -> bool] - return builder.create>(target_ty, !scalar->IsPositiveZero()); + return builder.create>(target_ty, !scalar->IsPositiveZero()); } else if constexpr (std::is_same_v) { // [bool -> x] - return builder.create>(target_ty, TO(scalar->value ? 1 : 0)); + return builder.create>(target_ty, TO(scalar->value ? 1 : 0)); } else if (auto conv = CheckedConvert(scalar->value)) { // Conversion success - return builder.create>(target_ty, conv.Get()); + return builder.create>(target_ty, conv.Get()); // --- Below this point are the failure cases --- } else if constexpr (IsAbstract) { // [abstract-numeric -> x] - materialization failure @@ -284,14 +284,14 @@ ImplResult ScalarConvert(const Scalar* scalar, // https://www.w3.org/TR/WGSL/#floating-point-conversion switch (conv.Failure()) { case ConversionFailure::kExceedsNegativeLimit: - return builder.create>(target_ty, TO::Lowest()); + return builder.create>(target_ty, TO::Lowest()); case ConversionFailure::kExceedsPositiveLimit: - return builder.create>(target_ty, TO::Highest()); + return builder.create>(target_ty, TO::Highest()); } } else if constexpr (IsIntegral) { // [integer -> integer] - number not exactly representable // Static cast - return builder.create>(target_ty, static_cast(scalar->value)); + return builder.create>(target_ty, static_cast(scalar->value)); } return nullptr; // Expression is not constant. }); @@ -304,7 +304,7 @@ ImplResult ConvertInternal(const constant::Constant* c, const type::Type* target_ty, const Source& source); -ImplResult SplatConvert(const Splat* splat, +ImplResult SplatConvert(const constant::Splat* splat, ProgramBuilder& builder, const type::Type* target_ty, const Source& source) { @@ -316,10 +316,10 @@ ImplResult SplatConvert(const Splat* splat, if (!conv_el.Get()) { return nullptr; } - return builder.create(target_ty, conv_el.Get(), splat->count); + return builder.create(target_ty, conv_el.Get(), splat->count); } -ImplResult CompositeConvert(const Composite* composite, +ImplResult CompositeConvert(const constant::Composite* composite, ProgramBuilder& builder, const type::Type* target_ty, const Source& source) { @@ -359,30 +359,34 @@ ImplResult ConvertInternal(const constant::Constant* c, const Source& source) { return Switch( c, - [&](const Scalar* val) { + [&](const constant::Scalar* val) { return ScalarConvert(val, builder, target_ty, source); }, - [&](const Scalar* val) { + [&](const constant::Scalar* val) { return ScalarConvert(val, builder, target_ty, source); }, - [&](const Scalar* val) { + [&](const constant::Scalar* val) { return ScalarConvert(val, builder, target_ty, source); }, - [&](const Scalar* val) { + [&](const constant::Scalar* val) { return ScalarConvert(val, builder, target_ty, source); }, - [&](const Scalar* val) { + [&](const constant::Scalar* val) { return ScalarConvert(val, builder, target_ty, source); }, - [&](const Scalar* val) { + [&](const constant::Scalar* val) { return ScalarConvert(val, builder, target_ty, source); }, - [&](const Scalar* val) { return ScalarConvert(val, builder, target_ty, source); }, - [&](const Splat* val) { return SplatConvert(val, builder, target_ty, source); }, - [&](const Composite* val) { return CompositeConvert(val, builder, target_ty, source); }); + [&](const constant::Scalar* val) { + return ScalarConvert(val, builder, target_ty, source); + }, + [&](const constant::Splat* val) { return SplatConvert(val, builder, target_ty, source); }, + [&](const constant::Composite* val) { + return CompositeConvert(val, builder, target_ty, source); + }); } -/// CreateScalar constructs and returns an Scalar. +/// CreateScalar constructs and returns an constant::Scalar. template ImplResult CreateScalar(ProgramBuilder& builder, const Source& source, const type::Type* t, T v) { static_assert(IsNumber || std::is_same_v, "T must be a Number or bool"); @@ -395,7 +399,7 @@ ImplResult CreateScalar(ProgramBuilder& builder, const Source& source, const typ return utils::Failure; } } - return builder.create>(t, v); + return builder.create>(t, v); } /// ZeroValue returns a Constant for the zero-value of the type `type`. @@ -404,16 +408,16 @@ const constant::Constant* ZeroValue(ProgramBuilder& builder, const type::Type* t type, // [&](const type::Vector* v) -> const constant::Constant* { auto* zero_el = ZeroValue(builder, v->type()); - return builder.create(type, zero_el, v->Width()); + return builder.create(type, zero_el, v->Width()); }, [&](const type::Matrix* m) -> const constant::Constant* { auto* zero_el = ZeroValue(builder, m->ColumnType()); - return builder.create(type, zero_el, m->columns()); + return builder.create(type, zero_el, m->columns()); }, [&](const type::Array* a) -> const constant::Constant* { if (auto n = a->ConstantCount()) { if (auto* zero_el = ZeroValue(builder, a->ElemType())) { - return builder.create(type, zero_el, n.value()); + return builder.create(type, zero_el, n.value()); } } return nullptr; @@ -432,7 +436,7 @@ const constant::Constant* ZeroValue(ProgramBuilder& builder, const type::Type* t } if (zero_by_type.Count() == 1) { // All members were of the same type, so the zero value is the same for all members. - return builder.create(type, zeros[0], s->Members().Length()); + return builder.create(type, zeros[0], s->Members().Length()); } return CreateComposite(builder, s, std::move(zeros)); }, @@ -531,9 +535,9 @@ const constant::Constant* CreateComposite(ProgramBuilder& builder, } } if (all_equal) { - return builder.create(type, elements[0], elements.Length()); + return builder.create(type, elements[0], elements.Length()); } else { - return builder.create(type, std::move(elements), all_zero, any_zero); + return builder.create(type, std::move(elements), all_zero, any_zero); } } @@ -1298,7 +1302,8 @@ ConstEval::Result ConstEval::VecSplat(const type::Type* ty, utils::VectorRef args, const Source&) { if (auto* arg = args[0]) { - return builder.create(ty, arg, static_cast(ty)->Width()); + return builder.create(ty, arg, + static_cast(ty)->Width()); } return nullptr; }