tint: remove ConstEval::current_source member and pass down source through function calls
Bug: tint:1581
Bug: tint:1751
Change-Id: I4dea92d4b67d39559ce65f45144215e56b6a3e9a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/110724
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/tint/resolver/const_eval.cc b/src/tint/resolver/const_eval.cc
index 713ad36..306e9c9 100644
--- a/src/tint/resolver/const_eval.cc
+++ b/src/tint/resolver/const_eval.cc
@@ -39,7 +39,6 @@
#include "src/tint/utils/bitcast.h"
#include "src/tint/utils/compiler_macros.h"
#include "src/tint/utils/map.h"
-#include "src/tint/utils/scoped_assignment.h"
#include "src/tint/utils/transform.h"
using namespace tint::number_suffixes; // NOLINT
@@ -651,13 +650,13 @@
ConstEval::ConstEval(ProgramBuilder& b) : builder(b) {}
template <typename NumberT>
-utils::Result<NumberT> ConstEval::Add(NumberT a, NumberT b) {
+utils::Result<NumberT> ConstEval::Add(const Source& source, NumberT a, NumberT b) {
NumberT result;
if constexpr (IsAbstract<NumberT> || IsFloatingPoint<NumberT>) {
if (auto r = CheckedAdd(a, b)) {
result = r->value;
} else {
- AddError(OverflowErrorMessage(a, "+", b), *current_source);
+ AddError(OverflowErrorMessage(a, "+", b), source);
return utils::Failure;
}
} else {
@@ -677,13 +676,13 @@
}
template <typename NumberT>
-utils::Result<NumberT> ConstEval::Sub(NumberT a, NumberT b) {
+utils::Result<NumberT> ConstEval::Sub(const Source& source, NumberT a, NumberT b) {
NumberT result;
if constexpr (IsAbstract<NumberT> || IsFloatingPoint<NumberT>) {
if (auto r = CheckedSub(a, b)) {
result = r->value;
} else {
- AddError(OverflowErrorMessage(a, "-", b), *current_source);
+ AddError(OverflowErrorMessage(a, "-", b), source);
return utils::Failure;
}
} else {
@@ -703,7 +702,7 @@
}
template <typename NumberT>
-utils::Result<NumberT> ConstEval::Mul(NumberT a, NumberT b) {
+utils::Result<NumberT> ConstEval::Mul(const Source& source, NumberT a, NumberT b) {
using T = UnwrapNumber<NumberT>;
NumberT result;
if constexpr (IsAbstract<NumberT> || IsFloatingPoint<NumberT>) {
@@ -711,7 +710,7 @@
if (auto r = CheckedMul(a, b)) {
result = r->value;
} else {
- AddError(OverflowErrorMessage(a, "*", b), *current_source);
+ AddError(OverflowErrorMessage(a, "*", b), source);
return utils::Failure;
}
} else {
@@ -730,14 +729,14 @@
}
template <typename NumberT>
-utils::Result<NumberT> ConstEval::Div(NumberT a, NumberT b) {
+utils::Result<NumberT> ConstEval::Div(const Source& source, NumberT a, NumberT b) {
NumberT result;
if constexpr (IsAbstract<NumberT> || IsFloatingPoint<NumberT>) {
// Check for over/underflow for abstract values
if (auto r = CheckedDiv(a, b)) {
result = r->value;
} else {
- AddError(OverflowErrorMessage(a, "/", b), *current_source);
+ AddError(OverflowErrorMessage(a, "/", b), source);
return utils::Failure;
}
} else {
@@ -765,16 +764,20 @@
}
template <typename NumberT>
-utils::Result<NumberT> ConstEval::Dot2(NumberT a1, NumberT a2, NumberT b1, NumberT b2) {
- auto r1 = Mul(a1, b1);
+utils::Result<NumberT> ConstEval::Dot2(const Source& source,
+ NumberT a1,
+ NumberT a2,
+ NumberT b1,
+ NumberT b2) {
+ auto r1 = Mul(source, a1, b1);
if (!r1) {
return utils::Failure;
}
- auto r2 = Mul(a2, b2);
+ auto r2 = Mul(source, a2, b2);
if (!r2) {
return utils::Failure;
}
- auto r = Add(r1.Get(), r2.Get());
+ auto r = Add(source, r1.Get(), r2.Get());
if (!r) {
return utils::Failure;
}
@@ -782,29 +785,30 @@
}
template <typename NumberT>
-utils::Result<NumberT> ConstEval::Dot3(NumberT a1,
+utils::Result<NumberT> ConstEval::Dot3(const Source& source,
+ NumberT a1,
NumberT a2,
NumberT a3,
NumberT b1,
NumberT b2,
NumberT b3) {
- auto r1 = Mul(a1, b1);
+ auto r1 = Mul(source, a1, b1);
if (!r1) {
return utils::Failure;
}
- auto r2 = Mul(a2, b2);
+ auto r2 = Mul(source, a2, b2);
if (!r2) {
return utils::Failure;
}
- auto r3 = Mul(a3, b3);
+ auto r3 = Mul(source, a3, b3);
if (!r3) {
return utils::Failure;
}
- auto r = Add(r1.Get(), r2.Get());
+ auto r = Add(source, r1.Get(), r2.Get());
if (!r) {
return utils::Failure;
}
- r = Add(r.Get(), r3.Get());
+ r = Add(source, r.Get(), r3.Get());
if (!r) {
return utils::Failure;
}
@@ -812,7 +816,8 @@
}
template <typename NumberT>
-utils::Result<NumberT> ConstEval::Dot4(NumberT a1,
+utils::Result<NumberT> ConstEval::Dot4(const Source& source,
+ NumberT a1,
NumberT a2,
NumberT a3,
NumberT a4,
@@ -820,31 +825,31 @@
NumberT b2,
NumberT b3,
NumberT b4) {
- auto r1 = Mul(a1, b1);
+ auto r1 = Mul(source, a1, b1);
if (!r1) {
return utils::Failure;
}
- auto r2 = Mul(a2, b2);
+ auto r2 = Mul(source, a2, b2);
if (!r2) {
return utils::Failure;
}
- auto r3 = Mul(a3, b3);
+ auto r3 = Mul(source, a3, b3);
if (!r3) {
return utils::Failure;
}
- auto r4 = Mul(a4, b4);
+ auto r4 = Mul(source, a4, b4);
if (!r4) {
return utils::Failure;
}
- auto r = Add(r1.Get(), r2.Get());
+ auto r = Add(source, r1.Get(), r2.Get());
if (!r) {
return utils::Failure;
}
- r = Add(r.Get(), r3.Get());
+ r = Add(source, r.Get(), r3.Get());
if (!r) {
return utils::Failure;
}
- r = Add(r.Get(), r4.Get());
+ r = Add(source, r.Get(), r4.Get());
if (!r) {
return utils::Failure;
}
@@ -852,16 +857,20 @@
}
template <typename NumberT>
-utils::Result<NumberT> ConstEval::Det2(NumberT a1, NumberT a2, NumberT b1, NumberT b2) {
- auto r1 = Mul(a1, b2);
+utils::Result<NumberT> ConstEval::Det2(const Source& source,
+ NumberT a1,
+ NumberT a2,
+ NumberT b1,
+ NumberT b2) {
+ auto r1 = Mul(source, a1, b2);
if (!r1) {
return utils::Failure;
}
- auto r2 = Mul(b1, a2);
+ auto r2 = Mul(source, b1, a2);
if (!r2) {
return utils::Failure;
}
- auto r = Sub(r1.Get(), r2.Get());
+ auto r = Sub(source, r1.Get(), r2.Get());
if (!r) {
return utils::Failure;
}
@@ -869,86 +878,86 @@
}
template <typename NumberT>
-utils::Result<NumberT> ConstEval::Clamp(NumberT e, NumberT low, NumberT high) {
+utils::Result<NumberT> ConstEval::Clamp(const Source&, NumberT e, NumberT low, NumberT high) {
return NumberT{std::min(std::max(e, low), high)};
}
-auto ConstEval::ClampFunc(const sem::Type* elem_ty) {
+auto ConstEval::ClampFunc(const Source& source, const sem::Type* elem_ty) {
return [=](auto e, auto low, auto high) -> ImplResult {
- if (auto r = Clamp(e, low, high)) {
+ if (auto r = Clamp(source, e, low, high)) {
return CreateElement(builder, elem_ty, r.Get());
}
return utils::Failure;
};
}
-auto ConstEval::AddFunc(const sem::Type* elem_ty) {
+auto ConstEval::AddFunc(const Source& source, const sem::Type* elem_ty) {
return [=](auto a1, auto a2) -> ImplResult {
- if (auto r = Add(a1, a2)) {
+ if (auto r = Add(source, a1, a2)) {
return CreateElement(builder, elem_ty, r.Get());
}
return utils::Failure;
};
}
-auto ConstEval::SubFunc(const sem::Type* elem_ty) {
+auto ConstEval::SubFunc(const Source& source, const sem::Type* elem_ty) {
return [=](auto a1, auto a2) -> ImplResult {
- if (auto r = Sub(a1, a2)) {
+ if (auto r = Sub(source, a1, a2)) {
return CreateElement(builder, elem_ty, r.Get());
}
return utils::Failure;
};
}
-auto ConstEval::MulFunc(const sem::Type* elem_ty) {
+auto ConstEval::MulFunc(const Source& source, const sem::Type* elem_ty) {
return [=](auto a1, auto a2) -> ImplResult {
- if (auto r = Mul(a1, a2)) {
+ if (auto r = Mul(source, a1, a2)) {
return CreateElement(builder, elem_ty, r.Get());
}
return utils::Failure;
};
}
-auto ConstEval::DivFunc(const sem::Type* elem_ty) {
+auto ConstEval::DivFunc(const Source& source, const sem::Type* elem_ty) {
return [=](auto a1, auto a2) -> ImplResult {
- if (auto r = Div(a1, a2)) {
+ if (auto r = Div(source, a1, a2)) {
return CreateElement(builder, elem_ty, r.Get());
}
return utils::Failure;
};
}
-auto ConstEval::Dot2Func(const sem::Type* elem_ty) {
+auto ConstEval::Dot2Func(const Source& source, const sem::Type* elem_ty) {
return [=](auto a1, auto a2, auto b1, auto b2) -> ImplResult {
- if (auto r = Dot2(a1, a2, b1, b2)) {
+ if (auto r = Dot2(source, a1, a2, b1, b2)) {
return CreateElement(builder, elem_ty, r.Get());
}
return utils::Failure;
};
}
-auto ConstEval::Dot3Func(const sem::Type* elem_ty) {
+auto ConstEval::Dot3Func(const Source& source, const sem::Type* elem_ty) {
return [=](auto a1, auto a2, auto a3, auto b1, auto b2, auto b3) -> ImplResult {
- if (auto r = Dot3(a1, a2, a3, b1, b2, b3)) {
+ if (auto r = Dot3(source, a1, a2, a3, b1, b2, b3)) {
return CreateElement(builder, elem_ty, r.Get());
}
return utils::Failure;
};
}
-auto ConstEval::Dot4Func(const sem::Type* elem_ty) {
+auto ConstEval::Dot4Func(const Source& source, const sem::Type* elem_ty) {
return
[=](auto a1, auto a2, auto a3, auto a4, auto b1, auto b2, auto b3, auto b4) -> ImplResult {
- if (auto r = Dot4(a1, a2, a3, a4, b1, b2, b3, b4)) {
+ if (auto r = Dot4(source, a1, a2, a3, a4, b1, b2, b3, b4)) {
return CreateElement(builder, elem_ty, r.Get());
}
return utils::Failure;
};
}
-auto ConstEval::Det2Func(const sem::Type* elem_ty) {
+auto ConstEval::Det2Func(const Source& source, const sem::Type* elem_ty) {
return [=](auto a, auto b, auto c, auto d) -> ImplResult {
- if (auto r = Det2(a, b, c, d)) {
+ if (auto r = Det2(source, a, b, c, d)) {
return CreateElement(builder, elem_ty, r.Get());
}
return utils::Failure;
@@ -1205,9 +1214,8 @@
ConstEval::Result ConstEval::OpPlus(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source) {
- TINT_SCOPED_ASSIGNMENT(current_source, &source);
auto transform = [&](const sem::Constant* c0, const sem::Constant* c1) {
- return Dispatch_fia_fiu32_f16(AddFunc(c0->Type()), c0, c1);
+ return Dispatch_fia_fiu32_f16(AddFunc(source, c0->Type()), c0, c1);
};
return TransformBinaryElements(builder, ty, transform, args[0], args[1]);
@@ -1216,9 +1224,8 @@
ConstEval::Result ConstEval::OpMinus(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source) {
- TINT_SCOPED_ASSIGNMENT(current_source, &source);
auto transform = [&](const sem::Constant* c0, const sem::Constant* c1) {
- return Dispatch_fia_fiu32_f16(SubFunc(c0->Type()), c0, c1);
+ return Dispatch_fia_fiu32_f16(SubFunc(source, c0->Type()), c0, c1);
};
return TransformBinaryElements(builder, ty, transform, args[0], args[1]);
@@ -1227,9 +1234,8 @@
ConstEval::Result ConstEval::OpMultiply(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source) {
- TINT_SCOPED_ASSIGNMENT(current_source, &source);
auto transform = [&](const sem::Constant* c0, const sem::Constant* c1) {
- return Dispatch_fia_fiu32_f16(MulFunc(c0->Type()), c0, c1);
+ return Dispatch_fia_fiu32_f16(MulFunc(source, c0->Type()), c0, c1);
};
return TransformBinaryElements(builder, ty, transform, args[0], args[1]);
@@ -1238,7 +1244,6 @@
ConstEval::Result ConstEval::OpMultiplyMatVec(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source) {
- TINT_SCOPED_ASSIGNMENT(current_source, &source);
auto* mat_ty = args[0]->Type()->As<sem::Matrix>();
auto* vec_ty = args[1]->Type()->As<sem::Vector>();
auto* elem_ty = vec_ty->type();
@@ -1247,29 +1252,29 @@
ImplResult result;
switch (mat_ty->columns()) {
case 2:
- result = Dispatch_fa_f32_f16(Dot2Func(elem_ty), //
- m->Index(0)->Index(row), //
- m->Index(1)->Index(row), //
- v->Index(0), //
+ result = Dispatch_fa_f32_f16(Dot2Func(source, elem_ty), //
+ m->Index(0)->Index(row), //
+ m->Index(1)->Index(row), //
+ v->Index(0), //
v->Index(1));
break;
case 3:
- result = Dispatch_fa_f32_f16(Dot3Func(elem_ty), //
- m->Index(0)->Index(row), //
- m->Index(1)->Index(row), //
- m->Index(2)->Index(row), //
- v->Index(0), //
+ result = Dispatch_fa_f32_f16(Dot3Func(source, elem_ty), //
+ m->Index(0)->Index(row), //
+ m->Index(1)->Index(row), //
+ m->Index(2)->Index(row), //
+ v->Index(0), //
v->Index(1), v->Index(2));
break;
case 4:
- result = Dispatch_fa_f32_f16(Dot4Func(elem_ty), //
- m->Index(0)->Index(row), //
- m->Index(1)->Index(row), //
- m->Index(2)->Index(row), //
- m->Index(3)->Index(row), //
- v->Index(0), //
- v->Index(1), //
- v->Index(2), //
+ result = Dispatch_fa_f32_f16(Dot4Func(source, elem_ty), //
+ m->Index(0)->Index(row), //
+ m->Index(1)->Index(row), //
+ m->Index(2)->Index(row), //
+ m->Index(3)->Index(row), //
+ v->Index(0), //
+ v->Index(1), //
+ v->Index(2), //
v->Index(3));
break;
}
@@ -1289,7 +1294,6 @@
ConstEval::Result ConstEval::OpMultiplyVecMat(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source) {
- TINT_SCOPED_ASSIGNMENT(current_source, &source);
auto* vec_ty = args[0]->Type()->As<sem::Vector>();
auto* mat_ty = args[1]->Type()->As<sem::Matrix>();
auto* elem_ty = vec_ty->type();
@@ -1298,30 +1302,30 @@
ImplResult result;
switch (mat_ty->rows()) {
case 2:
- result = Dispatch_fa_f32_f16(Dot2Func(elem_ty), //
- m->Index(col)->Index(0), //
- m->Index(col)->Index(1), //
- v->Index(0), //
+ result = Dispatch_fa_f32_f16(Dot2Func(source, elem_ty), //
+ m->Index(col)->Index(0), //
+ m->Index(col)->Index(1), //
+ v->Index(0), //
v->Index(1));
break;
case 3:
- result = Dispatch_fa_f32_f16(Dot3Func(elem_ty), //
- m->Index(col)->Index(0), //
- m->Index(col)->Index(1), //
+ result = Dispatch_fa_f32_f16(Dot3Func(source, elem_ty), //
+ m->Index(col)->Index(0), //
+ m->Index(col)->Index(1), //
m->Index(col)->Index(2),
v->Index(0), //
v->Index(1), //
v->Index(2));
break;
case 4:
- result = Dispatch_fa_f32_f16(Dot4Func(elem_ty), //
- m->Index(col)->Index(0), //
- m->Index(col)->Index(1), //
- m->Index(col)->Index(2), //
- m->Index(col)->Index(3), //
- v->Index(0), //
- v->Index(1), //
- v->Index(2), //
+ result = Dispatch_fa_f32_f16(Dot4Func(source, elem_ty), //
+ m->Index(col)->Index(0), //
+ m->Index(col)->Index(1), //
+ m->Index(col)->Index(2), //
+ m->Index(col)->Index(3), //
+ v->Index(0), //
+ v->Index(1), //
+ v->Index(2), //
v->Index(3));
}
return result;
@@ -1341,7 +1345,6 @@
ConstEval::Result ConstEval::OpMultiplyMatMat(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source) {
- TINT_SCOPED_ASSIGNMENT(current_source, &source);
auto* mat1 = args[0];
auto* mat2 = args[1];
auto* mat1_ty = mat1->Type()->As<sem::Matrix>();
@@ -1355,30 +1358,30 @@
ImplResult result;
switch (mat1_ty->columns()) {
case 2:
- result = Dispatch_fa_f32_f16(Dot2Func(elem_ty), //
- m1e(row, 0), //
- m1e(row, 1), //
- m2e(0, col), //
+ result = Dispatch_fa_f32_f16(Dot2Func(source, elem_ty), //
+ m1e(row, 0), //
+ m1e(row, 1), //
+ m2e(0, col), //
m2e(1, col));
break;
case 3:
- result = Dispatch_fa_f32_f16(Dot3Func(elem_ty), //
- m1e(row, 0), //
- m1e(row, 1), //
- m1e(row, 2), //
- m2e(0, col), //
- m2e(1, col), //
+ result = Dispatch_fa_f32_f16(Dot3Func(source, elem_ty), //
+ m1e(row, 0), //
+ m1e(row, 1), //
+ m1e(row, 2), //
+ m2e(0, col), //
+ m2e(1, col), //
m2e(2, col));
break;
case 4:
- result = Dispatch_fa_f32_f16(Dot4Func(elem_ty), //
- m1e(row, 0), //
- m1e(row, 1), //
- m1e(row, 2), //
- m1e(row, 3), //
- m2e(0, col), //
- m2e(1, col), //
- m2e(2, col), //
+ result = Dispatch_fa_f32_f16(Dot4Func(source, elem_ty), //
+ m1e(row, 0), //
+ m1e(row, 1), //
+ m1e(row, 2), //
+ m1e(row, 3), //
+ m2e(0, col), //
+ m2e(1, col), //
+ m2e(2, col), //
m2e(3, col));
break;
}
@@ -1406,9 +1409,8 @@
ConstEval::Result ConstEval::OpDivide(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source) {
- TINT_SCOPED_ASSIGNMENT(current_source, &source);
auto transform = [&](const sem::Constant* c0, const sem::Constant* c1) {
- return Dispatch_fia_fiu32_f16(DivFunc(c0->Type()), c0, c1);
+ return Dispatch_fia_fiu32_f16(DivFunc(source, c0->Type()), c0, c1);
};
return TransformBinaryElements(builder, ty, transform, args[0], args[1]);
@@ -1803,10 +1805,10 @@
ConstEval::Result ConstEval::clamp(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
- const Source&) {
+ const Source& source) {
auto transform = [&](const sem::Constant* c0, const sem::Constant* c1,
const sem::Constant* c2) {
- return Dispatch_fia_fiu32_f16(ClampFunc(c0->Type()), c0, c1, c2);
+ return Dispatch_fia_fiu32_f16(ClampFunc(source, c0->Type()), c0, c1, c2);
};
return TransformElements(builder, ty, transform, args[0], args[1], args[2]);
}
@@ -1894,7 +1896,6 @@
ConstEval::Result ConstEval::cross(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source) {
- TINT_SCOPED_ASSIGNMENT(current_source, &source);
auto* u = args[0];
auto* v = args[1];
auto* elem_ty = u->Type()->As<sem::Vector>()->type();
@@ -1918,15 +1919,15 @@
auto* v1 = v->Index(1);
auto* v2 = v->Index(2);
- auto x = Dispatch_fa_f32_f16(Det2Func(elem_ty), u1, u2, v1, v2);
+ auto x = Dispatch_fa_f32_f16(Det2Func(source, elem_ty), u1, u2, v1, v2);
if (!x) {
return utils::Failure;
}
- auto y = Dispatch_fa_f32_f16(Det2Func(elem_ty), v0, v2, u0, u2);
+ auto y = Dispatch_fa_f32_f16(Det2Func(source, elem_ty), v0, v2, u0, u2);
if (!y) {
return utils::Failure;
}
- auto z = Dispatch_fa_f32_f16(Det2Func(elem_ty), u0, u1, v0, v1);
+ auto z = Dispatch_fa_f32_f16(Det2Func(source, elem_ty), u0, u1, v0, v1);
if (!z) {
return utils::Failure;
}
@@ -2178,9 +2179,9 @@
ConstEval::Result ConstEval::pack2x16snorm(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
- const Source&) {
+ const Source& source) {
auto calc = [&](f32 val) -> u32 {
- auto clamped = Clamp(val, f32(-1.0f), f32(1.0f)).Get();
+ auto clamped = Clamp(source, val, f32(-1.0f), f32(1.0f)).Get();
return u32(utils::Bitcast<uint16_t>(
static_cast<int16_t>(std::floor(0.5f + (32767.0f * clamped)))));
};
@@ -2195,9 +2196,9 @@
ConstEval::Result ConstEval::pack2x16unorm(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
- const Source&) {
+ const Source& source) {
auto calc = [&](f32 val) -> u32 {
- auto clamped = Clamp(val, f32(0.0f), f32(1.0f)).Get();
+ auto clamped = Clamp(source, val, f32(0.0f), f32(1.0f)).Get();
return u32{std::floor(0.5f + (65535.0f * clamped))};
};
@@ -2211,9 +2212,9 @@
ConstEval::Result ConstEval::pack4x8snorm(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
- const Source&) {
+ const Source& source) {
auto calc = [&](f32 val) -> u32 {
- auto clamped = Clamp(val, f32(-1.0f), f32(1.0f)).Get();
+ auto clamped = Clamp(source, val, f32(-1.0f), f32(1.0f)).Get();
return u32(
utils::Bitcast<uint8_t>(static_cast<int8_t>(std::floor(0.5f + (127.0f * clamped)))));
};
@@ -2231,9 +2232,9 @@
ConstEval::Result ConstEval::pack4x8unorm(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
- const Source&) {
+ const Source& source) {
auto calc = [&](f32 val) -> u32 {
- auto clamped = Clamp(val, f32(0.0f), f32(1.0f)).Get();
+ auto clamped = Clamp(source, val, f32(0.0f), f32(1.0f)).Get();
return u32{std::floor(0.5f + (255.0f * clamped))};
};
@@ -2405,8 +2406,6 @@
ConstEval::Result ConstEval::smoothstep(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source) {
- TINT_SCOPED_ASSIGNMENT(current_source, &source);
-
auto transform = [&](const sem::Constant* c0, const sem::Constant* c1,
const sem::Constant* c2) {
auto create = [&](auto low, auto high, auto x) -> ImplResult {
@@ -2418,33 +2417,33 @@
};
// t = clamp((x - low) / (high - low), 0.0, 1.0)
- auto x_minus_low = Sub(x, low);
- auto high_minus_low = Sub(high, low);
+ auto x_minus_low = Sub(source, x, low);
+ auto high_minus_low = Sub(source, high, low);
if (!x_minus_low || !high_minus_low) {
return err();
}
- auto div = Div(x_minus_low.Get(), high_minus_low.Get());
+ auto div = Div(source, x_minus_low.Get(), high_minus_low.Get());
if (!div) {
return err();
}
- auto clamp = Clamp(div.Get(), NumberT(0), NumberT(1));
+ auto clamp = Clamp(source, div.Get(), NumberT(0), NumberT(1));
auto t = clamp.Get();
// result = t * t * (3.0 - 2.0 * t)
- auto t_times_t = Mul(t, t);
- auto t_times_2 = Mul(NumberT(2), t);
+ auto t_times_t = Mul(source, t, t);
+ auto t_times_2 = Mul(source, NumberT(2), t);
if (!t_times_t || !t_times_2) {
return err();
}
- auto three_minus_t_times_2 = Sub(NumberT(3), t_times_2.Get());
+ auto three_minus_t_times_2 = Sub(source, NumberT(3), t_times_2.Get());
if (!three_minus_t_times_2) {
return err();
}
- auto result = Mul(t_times_t.Get(), three_minus_t_times_2.Get());
+ auto result = Mul(source, t_times_t.Get(), three_minus_t_times_2.Get());
if (!result) {
return err();
}
diff --git a/src/tint/resolver/const_eval.h b/src/tint/resolver/const_eval.h
index e2c5ed0..73274a1 100644
--- a/src/tint/resolver/const_eval.h
+++ b/src/tint/resolver/const_eval.h
@@ -105,7 +105,7 @@
/// Convert the `value` to `target_type`
/// @param ty the result type
/// @param value the value being converted
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the converted value, or null if the value cannot be calculated
Result Convert(const sem::Type* ty, const sem::Constant* value, const Source& source);
@@ -116,7 +116,7 @@
/// Type conversion
/// @param ty the result type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the converted value, or null if the value cannot be calculated
Result Conv(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -125,7 +125,7 @@
/// Zero value type initializer
/// @param ty the result type
/// @param args the input arguments (no arguments provided)
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the constructed value, or null if the value cannot be calculated
Result Zero(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -134,7 +134,7 @@
/// Identity value type initializer
/// @param ty the result type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the constructed value, or null if the value cannot be calculated
Result Identity(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -143,7 +143,7 @@
/// Vector splat initializer
/// @param ty the vector type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the constructed value, or null if the value cannot be calculated
Result VecSplat(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -152,7 +152,7 @@
/// Vector initializer using scalars
/// @param ty the vector type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the constructed value, or null if the value cannot be calculated
Result VecInitS(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -161,7 +161,7 @@
/// Vector initializer using a mix of scalars and smaller vectors
/// @param ty the vector type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the constructed value, or null if the value cannot be calculated
Result VecInitM(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -170,7 +170,7 @@
/// Matrix initializer using scalar values
/// @param ty the matrix type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the constructed value, or null if the value cannot be calculated
Result MatInitS(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -179,7 +179,7 @@
/// Matrix initializer using column vectors
/// @param ty the matrix type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the constructed value, or null if the value cannot be calculated
Result MatInitV(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -192,7 +192,7 @@
/// Complement operator '~'
/// @param ty the integer type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpComplement(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -201,7 +201,7 @@
/// Unary minus operator '-'
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpUnaryMinus(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -210,7 +210,7 @@
/// Unary not operator '!'
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpNot(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -223,7 +223,7 @@
/// Plus operator '+'
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpPlus(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -232,7 +232,7 @@
/// Minus operator '-'
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpMinus(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -241,7 +241,7 @@
/// Multiply operator '*' for the same type on the LHS and RHS
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpMultiply(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -250,7 +250,7 @@
/// Multiply operator '*' for matCxR<T> * vecC<T>
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpMultiplyMatVec(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -259,7 +259,7 @@
/// Multiply operator '*' for vecR<T> * matCxR<T>
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpMultiplyVecMat(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -268,7 +268,7 @@
/// Multiply operator '*' for matKxR<T> * matCxK<T>
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpMultiplyMatMat(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -277,7 +277,7 @@
/// Divide operator '/'
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpDivide(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -286,7 +286,7 @@
/// Equality operator '=='
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpEqual(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -295,7 +295,7 @@
/// Inequality operator '!='
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpNotEqual(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -304,7 +304,7 @@
/// Less than operator '<'
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpLessThan(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -313,7 +313,7 @@
/// Greater than operator '>'
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpGreaterThan(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -322,7 +322,7 @@
/// Less than or equal operator '<='
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpLessThanEqual(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -331,7 +331,7 @@
/// Greater than or equal operator '>='
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpGreaterThanEqual(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -340,7 +340,7 @@
/// Bitwise and operator '&'
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpAnd(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -349,7 +349,7 @@
/// Bitwise or operator '|'
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpOr(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -358,7 +358,7 @@
/// Bitwise xor operator '^'
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpXor(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -367,7 +367,7 @@
/// Bitwise shift left operator '<<'
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpShiftLeft(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -380,7 +380,7 @@
/// abs builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result abs(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -389,7 +389,7 @@
/// acos builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result acos(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -398,7 +398,7 @@
/// acosh builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result acosh(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -407,7 +407,7 @@
/// all builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result all(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -416,7 +416,7 @@
/// any builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result any(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -425,7 +425,7 @@
/// asin builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result asin(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -434,7 +434,7 @@
/// asinh builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result asinh(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -443,7 +443,7 @@
/// atan builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result atan(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -452,7 +452,7 @@
/// atanh builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result atanh(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -461,7 +461,7 @@
/// atan2 builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result atan2(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -470,7 +470,7 @@
/// ceil builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result ceil(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -479,7 +479,7 @@
/// clamp builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result clamp(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -488,7 +488,7 @@
/// cos builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result cos(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -497,7 +497,7 @@
/// cosh builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result cosh(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -506,7 +506,7 @@
/// countLeadingZeros builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result countLeadingZeros(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -515,7 +515,7 @@
/// countOneBits builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result countOneBits(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -524,7 +524,7 @@
/// countTrailingZeros builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result countTrailingZeros(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -533,7 +533,7 @@
/// cross builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result cross(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -542,7 +542,7 @@
/// extractBits builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result extractBits(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -551,7 +551,7 @@
/// firstLeadingBit builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result firstLeadingBit(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -560,7 +560,7 @@
/// firstTrailingBit builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result firstTrailingBit(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -569,7 +569,7 @@
/// floor builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result floor(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -578,7 +578,7 @@
/// insertBits builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result insertBits(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -587,7 +587,7 @@
/// max builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result max(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -596,7 +596,7 @@
/// min builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result min(const sem::Type* ty, // NOLINT(build/include_what_you_use) -- confused by min
utils::VectorRef<const sem::Constant*> args,
@@ -605,7 +605,7 @@
/// pack2x16float builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result pack2x16float(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -614,7 +614,7 @@
/// pack2x16snorm builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result pack2x16snorm(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -623,7 +623,7 @@
/// pack2x16unorm builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result pack2x16unorm(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -632,7 +632,7 @@
/// pack4x8snorm builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result pack4x8snorm(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -641,7 +641,7 @@
/// pack4x8unorm builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result pack4x8unorm(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -650,7 +650,7 @@
/// reverseBits builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result reverseBits(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -659,7 +659,7 @@
/// round builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result round(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -668,7 +668,7 @@
/// saturate builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result saturate(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -677,7 +677,7 @@
/// select builtin with single bool third arg
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result select_bool(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -686,7 +686,7 @@
/// select builtin with vector of bool third arg
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result select_boolvec(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -695,7 +695,7 @@
/// sign builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result sign(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -704,7 +704,7 @@
/// sin builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result sin(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -713,7 +713,7 @@
/// sinh builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result sinh(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -722,7 +722,7 @@
/// smoothstep builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result smoothstep(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -731,7 +731,7 @@
/// step builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result step(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -740,7 +740,7 @@
/// sqrt builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result sqrt(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -749,7 +749,7 @@
/// tan builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result tan(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -758,7 +758,7 @@
/// tanh builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result tanh(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -767,7 +767,7 @@
/// trunc builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result trunc(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -776,7 +776,7 @@
/// unpack2x16float builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result unpack2x16float(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -785,7 +785,7 @@
/// unpack2x16snorm builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result unpack2x16snorm(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -794,7 +794,7 @@
/// unpack2x16unorm builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result unpack2x16unorm(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -803,7 +803,7 @@
/// unpack4x8snorm builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result unpack4x8snorm(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -812,7 +812,7 @@
/// unpack4x8unorm builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result unpack4x8unorm(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -821,7 +821,7 @@
/// quantizeToF16 builtin
/// @param ty the expression type
/// @param args the input arguments
- /// @param source the source location of the conversion
+ /// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result quantizeToF16(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
@@ -838,43 +838,53 @@
void AddNote(const std::string& msg, const Source& source) const;
/// Adds two Number<T>s
+ /// @param source the source location
/// @param a the lhs number
/// @param b the rhs number
/// @returns the result number on success, or logs an error and returns Failure
template <typename NumberT>
- utils::Result<NumberT> Add(NumberT a, NumberT b);
+ utils::Result<NumberT> Add(const Source& source, NumberT a, NumberT b);
/// Subtracts two Number<T>s
+ /// @param source the source location
/// @param a the lhs number
/// @param b the rhs number
/// @returns the result number on success, or logs an error and returns Failure
template <typename NumberT>
- utils::Result<NumberT> Sub(NumberT a, NumberT b);
+ utils::Result<NumberT> Sub(const Source& source, NumberT a, NumberT b);
/// Multiplies two Number<T>s
+ /// @param source the source location
/// @param a the lhs number
/// @param b the rhs number
/// @returns the result number on success, or logs an error and returns Failure
template <typename NumberT>
- utils::Result<NumberT> Mul(NumberT a, NumberT b);
+ utils::Result<NumberT> Mul(const Source& source, NumberT a, NumberT b);
/// Divides two Number<T>s
+ /// @param source the source location
/// @param a the lhs number
/// @param b the rhs number
/// @returns the result number on success, or logs an error and returns Failure
template <typename NumberT>
- utils::Result<NumberT> Div(NumberT a, NumberT b);
+ utils::Result<NumberT> Div(const Source& source, NumberT a, NumberT b);
/// Returns the dot product of (a1,a2) with (b1,b2)
+ /// @param source the source location
/// @param a1 component 1 of lhs vector
/// @param a2 component 2 of lhs vector
/// @param b1 component 1 of rhs vector
/// @param b2 component 2 of rhs vector
/// @returns the result number on success, or logs an error and returns Failure
template <typename NumberT>
- utils::Result<NumberT> Dot2(NumberT a1, NumberT a2, NumberT b1, NumberT b2);
+ utils::Result<NumberT> Dot2(const Source& source,
+ NumberT a1,
+ NumberT a2,
+ NumberT b1,
+ NumberT b2);
/// Returns the dot product of (a1,a2,a3) with (b1,b2,b3)
+ /// @param source the source location
/// @param a1 component 1 of lhs vector
/// @param a2 component 2 of lhs vector
/// @param a3 component 3 of lhs vector
@@ -883,7 +893,8 @@
/// @param b3 component 3 of rhs vector
/// @returns the result number on success, or logs an error and returns Failure
template <typename NumberT>
- utils::Result<NumberT> Dot3(NumberT a1,
+ utils::Result<NumberT> Dot3(const Source& source,
+ NumberT a1,
NumberT a2,
NumberT a3,
NumberT b1,
@@ -891,6 +902,7 @@
NumberT b3);
/// Returns the dot product of (a1,b1,c1,d1) with (a2,b2,c2,d2)
+ /// @param source the source location
/// @param a1 component 1 of lhs vector
/// @param a2 component 2 of lhs vector
/// @param a3 component 3 of lhs vector
@@ -901,7 +913,8 @@
/// @param b4 component 4 of rhs vector
/// @returns the result number on success, or logs an error and returns Failure
template <typename NumberT>
- utils::Result<NumberT> Dot4(NumberT a1,
+ utils::Result<NumberT> Dot4(const Source& source,
+ NumberT a1,
NumberT a2,
NumberT a3,
NumberT a4,
@@ -911,77 +924,91 @@
NumberT b4);
/// Returns the determinant of the 2x2 matrix [(a1, a2), (b1, b2)]
+ /// @param source the source location
/// @param a1 component 1 of the first column vector
/// @param a2 component 2 of the first column vector
/// @param b1 component 1 of the second column vector
/// @param b2 component 2 of the second column vector
template <typename NumberT>
- utils::Result<NumberT> Det2(NumberT a1, NumberT a2, NumberT b1, NumberT b2);
+ utils::Result<NumberT> Det2(const Source& source,
+ NumberT a1,
+ NumberT a2,
+ NumberT b1,
+ NumberT b2);
/// Clamps e between low and high
+ /// @param source the source location
/// @param e the number to clamp
/// @param low the lower bound
/// @param high the upper bound
/// @returns the result number on success, or logs an error and returns Failure
template <typename NumberT>
- utils::Result<NumberT> Clamp(NumberT e, NumberT low, NumberT high);
+ utils::Result<NumberT> Clamp(const Source& source, NumberT e, NumberT low, NumberT high);
/// Returns a callable that calls Add, and creates a Constant with its result of type `elem_ty`
/// if successful, or returns Failure otherwise.
+ /// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
- auto AddFunc(const sem::Type* elem_ty);
+ auto AddFunc(const Source& source, const sem::Type* elem_ty);
/// Returns a callable that calls Sub, and creates a Constant with its result of type `elem_ty`
/// if successful, or returns Failure otherwise.
+ /// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
- auto SubFunc(const sem::Type* elem_ty);
+ auto SubFunc(const Source& source, const sem::Type* elem_ty);
/// Returns a callable that calls Mul, and creates a Constant with its result of type `elem_ty`
/// if successful, or returns Failure otherwise.
+ /// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
- auto MulFunc(const sem::Type* elem_ty);
+ auto MulFunc(const Source& source, const sem::Type* elem_ty);
/// Returns a callable that calls Div, and creates a Constant with its result of type `elem_ty`
/// if successful, or returns Failure otherwise.
+ /// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
- auto DivFunc(const sem::Type* elem_ty);
+ auto DivFunc(const Source& source, const sem::Type* elem_ty);
/// Returns a callable that calls Dot2, and creates a Constant with its result of type `elem_ty`
/// if successful, or returns Failure otherwise.
+ /// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
- auto Dot2Func(const sem::Type* elem_ty);
+ auto Dot2Func(const Source& source, const sem::Type* elem_ty);
/// Returns a callable that calls Dot3, and creates a Constant with its result of type `elem_ty`
/// if successful, or returns Failure otherwise.
+ /// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
- auto Dot3Func(const sem::Type* elem_ty);
+ auto Dot3Func(const Source& source, const sem::Type* elem_ty);
/// Returns a callable that calls Dot4, and creates a Constant with its result of type `elem_ty`
/// if successful, or returns Failure otherwise.
+ /// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
- auto Dot4Func(const sem::Type* elem_ty);
+ auto Dot4Func(const Source& source, const sem::Type* elem_ty);
/// Returns a callable that calls Det2, and creates a Constant with its result of type `elem_ty`
/// if successful, or returns Failure otherwise.
+ /// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
- auto Det2Func(const sem::Type* elem_ty);
+ auto Det2Func(const Source& source, const sem::Type* elem_ty);
/// Returns a callable that calls Clamp, and creates a Constant with its result of type
/// `elem_ty` if successful, or returns Failure otherwise.
+ /// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
- auto ClampFunc(const sem::Type* elem_ty);
+ auto ClampFunc(const Source& source, const sem::Type* elem_ty);
ProgramBuilder& builder;
- const Source* current_source = nullptr;
};
} // namespace tint::resolver