sem: Rename `Vector::size()` to `Vector::Width()`

`Size()` will be added which is the size of the type in bytes.

Change-Id: If997820d7859cd9d1bb0631d1b72150378e6a24b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/59300
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ben Clayton 2021-07-22 18:31:34 +00:00 committed by Tint LUCI CQ
parent 4261466a84
commit f5ed2ba906
23 changed files with 147 additions and 146 deletions

View File

@ -66,33 +66,33 @@ std::tuple<ComponentType, CompositionType> CalculateComponentAndComposition(
return {ComponentType::kFloat, CompositionType::kScalar};
} else if (type->is_float_vector()) {
auto* vec = type->As<sem::Vector>();
if (vec->size() == 2) {
if (vec->Width() == 2) {
return {ComponentType::kFloat, CompositionType::kVec2};
} else if (vec->size() == 3) {
} else if (vec->Width() == 3) {
return {ComponentType::kFloat, CompositionType::kVec3};
} else if (vec->size() == 4) {
} else if (vec->Width() == 4) {
return {ComponentType::kFloat, CompositionType::kVec4};
}
} else if (type->is_unsigned_integer_scalar()) {
return {ComponentType::kUInt, CompositionType::kScalar};
} else if (type->is_unsigned_integer_vector()) {
auto* vec = type->As<sem::Vector>();
if (vec->size() == 2) {
if (vec->Width() == 2) {
return {ComponentType::kUInt, CompositionType::kVec2};
} else if (vec->size() == 3) {
} else if (vec->Width() == 3) {
return {ComponentType::kUInt, CompositionType::kVec3};
} else if (vec->size() == 4) {
} else if (vec->Width() == 4) {
return {ComponentType::kUInt, CompositionType::kVec4};
}
} else if (type->is_signed_integer_scalar()) {
return {ComponentType::kSInt, CompositionType::kScalar};
} else if (type->is_signed_integer_vector()) {
auto* vec = type->As<sem::Vector>();
if (vec->size() == 2) {
if (vec->Width() == 2) {
return {ComponentType::kSInt, CompositionType::kVec2};
} else if (vec->size() == 3) {
} else if (vec->Width() == 3) {
return {ComponentType::kSInt, CompositionType::kVec3};
} else if (vec->size() == 4) {
} else if (vec->Width() == 4) {
return {ComponentType::kSInt, CompositionType::kVec4};
}
}

View File

@ -335,7 +335,7 @@ bool match_vec(const sem::Type* ty, Number& N, const sem::Type*& T) {
}
if (auto* v = ty->As<sem::Vector>()) {
N = v->size();
N = v->Width();
T = v->type();
return true;
}
@ -354,7 +354,7 @@ bool match_vec(const sem::Type* ty, const sem::Type*& T) {
}
if (auto* v = ty->As<sem::Vector>()) {
if (v->size() == N) {
if (v->Width() == N) {
T = v->type();
return true;
}
@ -395,7 +395,7 @@ bool match_mat(const sem::Type* ty, Number& M, Number& N, const sem::Type*& T) {
}
if (auto* m = ty->As<sem::Matrix>()) {
M = m->columns();
N = m->ColumnType()->size();
N = m->ColumnType()->Width();
T = m->type();
return true;
}

View File

@ -77,7 +77,7 @@ TEST_P(ResolverIntrinsicDerivativeTest, Vector) {
ASSERT_NE(TypeOf(expr), nullptr);
ASSERT_TRUE(TypeOf(expr)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(expr)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(expr)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(expr)->As<sem::Vector>()->Width(), 4u);
}
TEST_P(ResolverIntrinsicDerivativeTest, MissingParam) {
@ -139,7 +139,7 @@ TEST_P(ResolverIntrinsicTest_FloatMethod, Vector) {
ASSERT_NE(TypeOf(expr), nullptr);
ASSERT_TRUE(TypeOf(expr)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(expr)->As<sem::Vector>()->type()->Is<sem::Bool>());
EXPECT_EQ(TypeOf(expr)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(expr)->As<sem::Vector>()->Width(), 3u);
}
TEST_P(ResolverIntrinsicTest_FloatMethod, Scalar) {
@ -301,7 +301,7 @@ TEST_P(ResolverIntrinsicTest_StorageTextureOperation, TextureLoadRo) {
} else {
EXPECT_TRUE(TypeOf(expr)->As<sem::Vector>()->type()->Is<sem::U32>());
}
EXPECT_EQ(TypeOf(expr)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(expr)->As<sem::Vector>()->Width(), 4u);
}
INSTANTIATE_TEST_SUITE_P(
@ -366,7 +366,7 @@ TEST_P(ResolverIntrinsicTest_SampledTextureOperation, TextureLoadSampled) {
} else {
EXPECT_TRUE(TypeOf(expr)->As<sem::Vector>()->type()->Is<sem::U32>());
}
EXPECT_EQ(TypeOf(expr)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(expr)->As<sem::Vector>()->Width(), 4u);
}
INSTANTIATE_TEST_SUITE_P(
@ -455,7 +455,7 @@ TEST_F(ResolverIntrinsicTest, Select) {
ASSERT_NE(TypeOf(expr), nullptr);
EXPECT_TRUE(TypeOf(expr)->Is<sem::Vector>());
EXPECT_EQ(TypeOf(expr)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(expr)->As<sem::Vector>()->Width(), 3u);
EXPECT_TRUE(TypeOf(expr)->As<sem::Vector>()->type()->Is<sem::F32>());
}
@ -668,9 +668,9 @@ TEST_P(ResolverIntrinsicTest_DataUnpacking, InferType) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
if (pack4) {
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->Width(), 4u);
} else {
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 2u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->Width(), 2u);
}
}
@ -707,7 +707,7 @@ TEST_P(ResolverIntrinsicTest_SingleParam, Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->Width(), 3u);
}
TEST_P(ResolverIntrinsicTest_SingleParam, Error_NoParams) {
@ -812,7 +812,7 @@ TEST_F(ResolverIntrinsicDataTest, Normalize_Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->Width(), 3u);
}
TEST_F(ResolverIntrinsicDataTest, Normalize_Error_NoParams) {
@ -1028,7 +1028,7 @@ TEST_P(ResolverIntrinsicTest_SingleParam_FloatOrInt, Float_Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->Width(), 3u);
}
TEST_P(ResolverIntrinsicTest_SingleParam_FloatOrInt, Sint_Scalar) {
@ -1053,7 +1053,7 @@ TEST_P(ResolverIntrinsicTest_SingleParam_FloatOrInt, Sint_Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_signed_integer_vector());
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->Width(), 3u);
}
TEST_P(ResolverIntrinsicTest_SingleParam_FloatOrInt, Uint_Scalar) {
@ -1078,7 +1078,7 @@ TEST_P(ResolverIntrinsicTest_SingleParam_FloatOrInt, Uint_Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_unsigned_integer_vector());
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->Width(), 3u);
}
TEST_P(ResolverIntrinsicTest_SingleParam_FloatOrInt, Error_NoParams) {
@ -1148,7 +1148,7 @@ TEST_P(ResolverIntrinsicTest_TwoParam, Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->Width(), 3u);
}
TEST_P(ResolverIntrinsicTest_TwoParam, Error_NoTooManyParams) {
@ -1222,7 +1222,7 @@ TEST_F(ResolverIntrinsicTest, Cross) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->Width(), 3u);
}
TEST_F(ResolverIntrinsicTest, Cross_Error_NoArgs) {
@ -1304,7 +1304,7 @@ TEST_F(ResolverIntrinsicTest, Normalize) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->Width(), 3u);
}
TEST_F(ResolverIntrinsicTest, Normalize_NoArgs) {
@ -1344,7 +1344,7 @@ TEST_P(ResolverIntrinsicTest_ThreeParam, Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->Width(), 3u);
}
TEST_P(ResolverIntrinsicTest_ThreeParam, Error_NoParams) {
auto param = GetParam();
@ -1395,7 +1395,7 @@ TEST_P(ResolverIntrinsicTest_ThreeParam_FloatOrInt, Float_Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->Width(), 3u);
}
TEST_P(ResolverIntrinsicTest_ThreeParam_FloatOrInt, Sint_Scalar) {
@ -1421,7 +1421,7 @@ TEST_P(ResolverIntrinsicTest_ThreeParam_FloatOrInt, Sint_Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_signed_integer_vector());
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->Width(), 3u);
}
TEST_P(ResolverIntrinsicTest_ThreeParam_FloatOrInt, Uint_Scalar) {
@ -1447,7 +1447,7 @@ TEST_P(ResolverIntrinsicTest_ThreeParam_FloatOrInt, Uint_Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_unsigned_integer_vector());
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->Width(), 3u);
}
TEST_P(ResolverIntrinsicTest_ThreeParam_FloatOrInt, Error_NoParams) {
@ -1498,7 +1498,7 @@ TEST_P(ResolverIntrinsicTest_Int_SingleParam, Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_signed_integer_vector());
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->Width(), 3u);
}
TEST_P(ResolverIntrinsicTest_Int_SingleParam, Error_NoParams) {
@ -1573,7 +1573,7 @@ TEST_P(ResolverIntrinsicTest_FloatOrInt_TwoParam, Vector_Signed) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_signed_integer_vector());
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->Width(), 3u);
}
TEST_P(ResolverIntrinsicTest_FloatOrInt_TwoParam, Vector_Unsigned) {
@ -1586,7 +1586,7 @@ TEST_P(ResolverIntrinsicTest_FloatOrInt_TwoParam, Vector_Unsigned) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_unsigned_integer_vector());
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->Width(), 3u);
}
TEST_P(ResolverIntrinsicTest_FloatOrInt_TwoParam, Vector_Float) {
@ -1600,7 +1600,7 @@ TEST_P(ResolverIntrinsicTest_FloatOrInt_TwoParam, Vector_Float) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->Width(), 3u);
}
TEST_P(ResolverIntrinsicTest_FloatOrInt_TwoParam, Error_NoParams) {
@ -1977,14 +1977,14 @@ TEST_P(ResolverIntrinsicTest_Texture, Call) {
case ast::TextureDimension::kCubeArray: {
auto* vec = As<sem::Vector>(TypeOf(call));
ASSERT_NE(vec, nullptr);
EXPECT_EQ(vec->size(), 2u);
EXPECT_EQ(vec->Width(), 2u);
EXPECT_TRUE(vec->type()->Is<sem::I32>());
break;
}
case ast::TextureDimension::k3d: {
auto* vec = As<sem::Vector>(TypeOf(call));
ASSERT_NE(vec, nullptr);
EXPECT_EQ(vec->size(), 3u);
EXPECT_EQ(vec->Width(), 3u);
EXPECT_TRUE(vec->type()->Is<sem::I32>());
break;
}

View File

@ -1218,7 +1218,7 @@ bool Resolver::ValidateBuiltinDecoration(const ast::BuiltinDecoration* deco,
stage_name.str() + " pipeline stage",
deco->source());
}
if (!(type->is_float_vector() && type->As<sem::Vector>()->size() == 4)) {
if (!(type->is_float_vector() && type->As<sem::Vector>()->Width() == 4)) {
AddError("store type of " + deco_to_str(deco) + " must be 'vec4<f32>'",
deco->source());
return false;
@ -1232,7 +1232,7 @@ bool Resolver::ValidateBuiltinDecoration(const ast::BuiltinDecoration* deco,
is_stage_mismatch = true;
}
if (!(type->is_unsigned_integer_vector() &&
type->As<sem::Vector>()->size() == 3)) {
type->As<sem::Vector>()->Width() == 3)) {
AddError("store type of " + deco_to_str(deco) + " must be 'vec3<u32>'",
deco->source());
return false;
@ -2794,7 +2794,7 @@ bool Resolver::ValidateVectorConstructor(
return false;
}
value_cardinality_sum += value_vec->size();
value_cardinality_sum += value_vec->Width();
} else {
// A vector constructor can only accept vectors and scalars.
AddError("expected vector or scalar type in vector constructor; found: " +
@ -2807,7 +2807,7 @@ bool Resolver::ValidateVectorConstructor(
// A correct vector constructor must either be a zero-value expression,
// a single-value initializer (splat) expression, or the number of components
// of all constructor arguments must add up to the vector cardinality.
if (value_cardinality_sum > 1 && value_cardinality_sum != vec_type->size()) {
if (value_cardinality_sum > 1 && value_cardinality_sum != vec_type->Width()) {
if (values.empty()) {
TINT_ICE(Resolver, diagnostics_)
<< "constructor arguments expected to be non-empty!";
@ -2869,7 +2869,7 @@ bool Resolver::ValidateMatrixConstructor(
auto* value_type = TypeOf(value)->UnwrapRef();
auto* value_vec = value_type->As<sem::Vector>();
if (!value_vec || value_vec->size() != matrix_type->rows() ||
if (!value_vec || value_vec->Width() != matrix_type->rows() ||
elem_type != value_vec->type()) {
AddError("expected argument type '" +
VectorPretty(matrix_type->rows(), elem_type) + "' in '" +
@ -3050,7 +3050,7 @@ bool Resolver::MemberAccessor(ast::MemberAccessorExpression* expr) {
return false;
}
if (swizzle.back() >= vec->size()) {
if (swizzle.back() >= vec->Width()) {
AddError("invalid vector swizzle member", expr->member()->source());
return false;
}
@ -3130,7 +3130,7 @@ bool Resolver::Binary(ast::BinaryExpression* expr) {
const bool matching_vec_elem_types =
lhs_vec_elem_type && rhs_vec_elem_type &&
(lhs_vec_elem_type == rhs_vec_elem_type) &&
(lhs_vec->size() == rhs_vec->size());
(lhs_vec->Width() == rhs_vec->Width());
const bool matching_types = matching_vec_elem_types || (lhs_type == rhs_type);
@ -3222,7 +3222,7 @@ bool Resolver::Binary(ast::BinaryExpression* expr) {
// Vector times matrix
if (lhs_vec_elem_type && lhs_vec_elem_type->Is<F32>() &&
rhs_mat_elem_type && rhs_mat_elem_type->Is<F32>() &&
(lhs_vec->size() == rhs_mat->rows())) {
(lhs_vec->Width() == rhs_mat->rows())) {
SetExprInfo(expr, builder_->create<sem::Vector>(lhs_vec->type(),
rhs_mat->columns()));
return true;
@ -3231,7 +3231,7 @@ bool Resolver::Binary(ast::BinaryExpression* expr) {
// Matrix times vector
if (lhs_mat_elem_type && lhs_mat_elem_type->Is<F32>() &&
rhs_vec_elem_type && rhs_vec_elem_type->Is<F32>() &&
(lhs_mat->columns() == rhs_vec->size())) {
(lhs_mat->columns() == rhs_vec->Width())) {
SetExprInfo(expr, builder_->create<sem::Vector>(rhs_vec->type(),
lhs_mat->rows()));
return true;
@ -3270,13 +3270,13 @@ bool Resolver::Binary(ast::BinaryExpression* expr) {
if (lhs_vec_elem_type->Is<Bool>() &&
(expr->IsEqual() || expr->IsNotEqual())) {
SetExprInfo(expr, builder_->create<sem::Vector>(
builder_->create<sem::Bool>(), lhs_vec->size()));
builder_->create<sem::Bool>(), lhs_vec->Width()));
return true;
}
if (lhs_vec_elem_type->is_numeric_scalar()) {
SetExprInfo(expr, builder_->create<sem::Vector>(
builder_->create<sem::Bool>(), lhs_vec->size()));
builder_->create<sem::Bool>(), lhs_vec->Width()));
return true;
}
}

View File

@ -109,7 +109,7 @@ sem::Constant Resolver::EvaluateConstantValue(
}
auto* elem_type = vec ? vec->type() : type;
int result_size = vec ? static_cast<int>(vec->size()) : 1;
int result_size = vec ? static_cast<int>(vec->Width()) : 1;
// For zero value init, return 0s
if (ctor_values.empty()) {

View File

@ -96,7 +96,7 @@ TEST_F(ResolverConstantsTest, Vec3_ZeroInit_i32) {
EXPECT_NE(sem, nullptr);
ASSERT_TRUE(sem->Type()->Is<sem::Vector>());
EXPECT_TRUE(sem->Type()->As<sem::Vector>()->type()->Is<sem::I32>());
EXPECT_EQ(sem->Type()->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(sem->Type()->As<sem::Vector>()->Width(), 3u);
EXPECT_EQ(sem->ConstantValue().Type(), sem->Type());
EXPECT_TRUE(sem->ConstantValue().ElementType()->Is<sem::I32>());
ASSERT_EQ(sem->ConstantValue().Elements().size(), 3u);
@ -115,7 +115,7 @@ TEST_F(ResolverConstantsTest, Vec3_ZeroInit_u32) {
EXPECT_NE(sem, nullptr);
ASSERT_TRUE(sem->Type()->Is<sem::Vector>());
EXPECT_TRUE(sem->Type()->As<sem::Vector>()->type()->Is<sem::U32>());
EXPECT_EQ(sem->Type()->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(sem->Type()->As<sem::Vector>()->Width(), 3u);
EXPECT_EQ(sem->ConstantValue().Type(), sem->Type());
EXPECT_TRUE(sem->ConstantValue().ElementType()->Is<sem::U32>());
ASSERT_EQ(sem->ConstantValue().Elements().size(), 3u);
@ -134,7 +134,7 @@ TEST_F(ResolverConstantsTest, Vec3_ZeroInit_f32) {
EXPECT_NE(sem, nullptr);
ASSERT_TRUE(sem->Type()->Is<sem::Vector>());
EXPECT_TRUE(sem->Type()->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(sem->Type()->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(sem->Type()->As<sem::Vector>()->Width(), 3u);
EXPECT_EQ(sem->ConstantValue().Type(), sem->Type());
EXPECT_TRUE(sem->ConstantValue().ElementType()->Is<sem::F32>());
ASSERT_EQ(sem->ConstantValue().Elements().size(), 3u);
@ -153,7 +153,7 @@ TEST_F(ResolverConstantsTest, Vec3_ZeroInit_bool) {
EXPECT_NE(sem, nullptr);
ASSERT_TRUE(sem->Type()->Is<sem::Vector>());
EXPECT_TRUE(sem->Type()->As<sem::Vector>()->type()->Is<sem::Bool>());
EXPECT_EQ(sem->Type()->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(sem->Type()->As<sem::Vector>()->Width(), 3u);
EXPECT_EQ(sem->ConstantValue().Type(), sem->Type());
EXPECT_TRUE(sem->ConstantValue().ElementType()->Is<sem::Bool>());
ASSERT_EQ(sem->ConstantValue().Elements().size(), 3u);
@ -172,7 +172,7 @@ TEST_F(ResolverConstantsTest, Vec3_Splat_i32) {
EXPECT_NE(sem, nullptr);
ASSERT_TRUE(sem->Type()->Is<sem::Vector>());
EXPECT_TRUE(sem->Type()->As<sem::Vector>()->type()->Is<sem::I32>());
EXPECT_EQ(sem->Type()->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(sem->Type()->As<sem::Vector>()->Width(), 3u);
EXPECT_EQ(sem->ConstantValue().Type(), sem->Type());
EXPECT_TRUE(sem->ConstantValue().ElementType()->Is<sem::I32>());
ASSERT_EQ(sem->ConstantValue().Elements().size(), 3u);
@ -191,7 +191,7 @@ TEST_F(ResolverConstantsTest, Vec3_Splat_u32) {
EXPECT_NE(sem, nullptr);
ASSERT_TRUE(sem->Type()->Is<sem::Vector>());
EXPECT_TRUE(sem->Type()->As<sem::Vector>()->type()->Is<sem::U32>());
EXPECT_EQ(sem->Type()->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(sem->Type()->As<sem::Vector>()->Width(), 3u);
EXPECT_EQ(sem->ConstantValue().Type(), sem->Type());
EXPECT_TRUE(sem->ConstantValue().ElementType()->Is<sem::U32>());
ASSERT_EQ(sem->ConstantValue().Elements().size(), 3u);
@ -210,7 +210,7 @@ TEST_F(ResolverConstantsTest, Vec3_Splat_f32) {
EXPECT_NE(sem, nullptr);
ASSERT_TRUE(sem->Type()->Is<sem::Vector>());
EXPECT_TRUE(sem->Type()->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(sem->Type()->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(sem->Type()->As<sem::Vector>()->Width(), 3u);
EXPECT_EQ(sem->ConstantValue().Type(), sem->Type());
EXPECT_TRUE(sem->ConstantValue().ElementType()->Is<sem::F32>());
ASSERT_EQ(sem->ConstantValue().Elements().size(), 3u);
@ -229,7 +229,7 @@ TEST_F(ResolverConstantsTest, Vec3_Splat_bool) {
EXPECT_NE(sem, nullptr);
ASSERT_TRUE(sem->Type()->Is<sem::Vector>());
EXPECT_TRUE(sem->Type()->As<sem::Vector>()->type()->Is<sem::Bool>());
EXPECT_EQ(sem->Type()->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(sem->Type()->As<sem::Vector>()->Width(), 3u);
EXPECT_EQ(sem->ConstantValue().Type(), sem->Type());
EXPECT_TRUE(sem->ConstantValue().ElementType()->Is<sem::Bool>());
ASSERT_EQ(sem->ConstantValue().Elements().size(), 3u);
@ -248,7 +248,7 @@ TEST_F(ResolverConstantsTest, Vec3_FullConstruct_i32) {
EXPECT_NE(sem, nullptr);
ASSERT_TRUE(sem->Type()->Is<sem::Vector>());
EXPECT_TRUE(sem->Type()->As<sem::Vector>()->type()->Is<sem::I32>());
EXPECT_EQ(sem->Type()->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(sem->Type()->As<sem::Vector>()->Width(), 3u);
EXPECT_EQ(sem->ConstantValue().Type(), sem->Type());
EXPECT_TRUE(sem->ConstantValue().ElementType()->Is<sem::I32>());
ASSERT_EQ(sem->ConstantValue().Elements().size(), 3u);
@ -267,7 +267,7 @@ TEST_F(ResolverConstantsTest, Vec3_FullConstruct_u32) {
EXPECT_NE(sem, nullptr);
ASSERT_TRUE(sem->Type()->Is<sem::Vector>());
EXPECT_TRUE(sem->Type()->As<sem::Vector>()->type()->Is<sem::U32>());
EXPECT_EQ(sem->Type()->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(sem->Type()->As<sem::Vector>()->Width(), 3u);
EXPECT_EQ(sem->ConstantValue().Type(), sem->Type());
EXPECT_TRUE(sem->ConstantValue().ElementType()->Is<sem::U32>());
ASSERT_EQ(sem->ConstantValue().Elements().size(), 3u);
@ -286,7 +286,7 @@ TEST_F(ResolverConstantsTest, Vec3_FullConstruct_f32) {
EXPECT_NE(sem, nullptr);
ASSERT_TRUE(sem->Type()->Is<sem::Vector>());
EXPECT_TRUE(sem->Type()->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(sem->Type()->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(sem->Type()->As<sem::Vector>()->Width(), 3u);
EXPECT_EQ(sem->ConstantValue().Type(), sem->Type());
EXPECT_TRUE(sem->ConstantValue().ElementType()->Is<sem::F32>());
ASSERT_EQ(sem->ConstantValue().Elements().size(), 3u);
@ -305,7 +305,7 @@ TEST_F(ResolverConstantsTest, Vec3_FullConstruct_bool) {
EXPECT_NE(sem, nullptr);
ASSERT_TRUE(sem->Type()->Is<sem::Vector>());
EXPECT_TRUE(sem->Type()->As<sem::Vector>()->type()->Is<sem::Bool>());
EXPECT_EQ(sem->Type()->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(sem->Type()->As<sem::Vector>()->Width(), 3u);
EXPECT_EQ(sem->ConstantValue().Type(), sem->Type());
EXPECT_TRUE(sem->ConstantValue().ElementType()->Is<sem::Bool>());
ASSERT_EQ(sem->ConstantValue().Elements().size(), 3u);
@ -324,7 +324,7 @@ TEST_F(ResolverConstantsTest, Vec3_MixConstruct_i32) {
EXPECT_NE(sem, nullptr);
ASSERT_TRUE(sem->Type()->Is<sem::Vector>());
EXPECT_TRUE(sem->Type()->As<sem::Vector>()->type()->Is<sem::I32>());
EXPECT_EQ(sem->Type()->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(sem->Type()->As<sem::Vector>()->Width(), 3u);
EXPECT_EQ(sem->ConstantValue().Type(), sem->Type());
EXPECT_TRUE(sem->ConstantValue().ElementType()->Is<sem::I32>());
ASSERT_EQ(sem->ConstantValue().Elements().size(), 3u);
@ -343,7 +343,7 @@ TEST_F(ResolverConstantsTest, Vec3_MixConstruct_u32) {
EXPECT_NE(sem, nullptr);
ASSERT_TRUE(sem->Type()->Is<sem::Vector>());
EXPECT_TRUE(sem->Type()->As<sem::Vector>()->type()->Is<sem::U32>());
EXPECT_EQ(sem->Type()->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(sem->Type()->As<sem::Vector>()->Width(), 3u);
EXPECT_EQ(sem->ConstantValue().Type(), sem->Type());
EXPECT_TRUE(sem->ConstantValue().ElementType()->Is<sem::U32>());
ASSERT_EQ(sem->ConstantValue().Elements().size(), 3u);
@ -362,7 +362,7 @@ TEST_F(ResolverConstantsTest, Vec3_MixConstruct_f32) {
EXPECT_NE(sem, nullptr);
ASSERT_TRUE(sem->Type()->Is<sem::Vector>());
EXPECT_TRUE(sem->Type()->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(sem->Type()->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(sem->Type()->As<sem::Vector>()->Width(), 3u);
EXPECT_EQ(sem->ConstantValue().Type(), sem->Type());
EXPECT_TRUE(sem->ConstantValue().ElementType()->Is<sem::F32>());
ASSERT_EQ(sem->ConstantValue().Elements().size(), 3u);
@ -381,7 +381,7 @@ TEST_F(ResolverConstantsTest, Vec3_MixConstruct_bool) {
EXPECT_NE(sem, nullptr);
ASSERT_TRUE(sem->Type()->Is<sem::Vector>());
EXPECT_TRUE(sem->Type()->As<sem::Vector>()->type()->Is<sem::Bool>());
EXPECT_EQ(sem->Type()->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(sem->Type()->As<sem::Vector>()->Width(), 3u);
EXPECT_EQ(sem->ConstantValue().Type(), sem->Type());
EXPECT_TRUE(sem->ConstantValue().ElementType()->Is<sem::Bool>());
ASSERT_EQ(sem->ConstantValue().Elements().size(), 3u);
@ -400,7 +400,7 @@ TEST_F(ResolverConstantsTest, Vec3_Cast_f32_to_32) {
EXPECT_NE(sem, nullptr);
ASSERT_TRUE(sem->Type()->Is<sem::Vector>());
EXPECT_TRUE(sem->Type()->As<sem::Vector>()->type()->Is<sem::I32>());
EXPECT_EQ(sem->Type()->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(sem->Type()->As<sem::Vector>()->Width(), 3u);
EXPECT_EQ(sem->ConstantValue().Type(), sem->Type());
EXPECT_TRUE(sem->ConstantValue().ElementType()->Is<sem::I32>());
ASSERT_EQ(sem->ConstantValue().Elements().size(), 3u);
@ -419,7 +419,7 @@ TEST_F(ResolverConstantsTest, Vec3_Cast_u32_to_f32) {
EXPECT_NE(sem, nullptr);
ASSERT_TRUE(sem->Type()->Is<sem::Vector>());
EXPECT_TRUE(sem->Type()->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(sem->Type()->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(sem->Type()->As<sem::Vector>()->Width(), 3u);
EXPECT_EQ(sem->ConstantValue().Type(), sem->Type());
EXPECT_TRUE(sem->ConstantValue().ElementType()->Is<sem::F32>());
ASSERT_EQ(sem->ConstantValue().Elements().size(), 3u);

View File

@ -552,7 +552,7 @@ TEST_F(ResolverTest, Expr_ArrayAccessor_Matrix) {
auto* ref = TypeOf(acc)->As<sem::Reference>();
ASSERT_TRUE(ref->StoreType()->Is<sem::Vector>());
EXPECT_EQ(ref->StoreType()->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(ref->StoreType()->As<sem::Vector>()->Width(), 3u);
}
TEST_F(ResolverTest, Expr_ArrayAccessor_Matrix_BothDimensions) {
@ -709,7 +709,7 @@ TEST_F(ResolverTest, Expr_Constructor_Type_Vec2) {
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 2u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 2u);
}
TEST_F(ResolverTest, Expr_Constructor_Type_Vec3) {
@ -721,7 +721,7 @@ TEST_F(ResolverTest, Expr_Constructor_Type_Vec3) {
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 3u);
}
TEST_F(ResolverTest, Expr_Constructor_Type_Vec4) {
@ -733,7 +733,7 @@ TEST_F(ResolverTest, Expr_Constructor_Type_Vec4) {
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 4u);
}
TEST_F(ResolverTest, Expr_Identifier_GlobalVariable) {
@ -1328,7 +1328,7 @@ TEST_F(ResolverTest, Expr_MemberAccessor_VectorSwizzle) {
ASSERT_NE(TypeOf(mem), nullptr);
ASSERT_TRUE(TypeOf(mem)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(mem)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(mem)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(mem)->As<sem::Vector>()->Width(), 4u);
ASSERT_TRUE(Sem().Get(mem)->Is<sem::Swizzle>());
EXPECT_THAT(Sem().Get(mem)->As<sem::Swizzle>()->Indices(),
ElementsAre(0, 2, 1, 3));
@ -1381,7 +1381,7 @@ TEST_F(ResolverTest, Expr_Accessor_MultiLevel) {
ASSERT_NE(TypeOf(mem), nullptr);
ASSERT_TRUE(TypeOf(mem)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(mem)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(mem)->As<sem::Vector>()->size(), 2u);
EXPECT_EQ(TypeOf(mem)->As<sem::Vector>()->Width(), 2u);
ASSERT_TRUE(Sem().Get(mem)->Is<sem::Swizzle>());
}
@ -1928,7 +1928,7 @@ TEST_P(UnaryOpExpressionTest, Expr_UnaryOp) {
} else {
EXPECT_TRUE(TypeOf(der)->As<sem::Vector>()->type()->Is<sem::F32>());
}
EXPECT_EQ(TypeOf(der)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(der)->As<sem::Vector>()->Width(), 4u);
}
INSTANTIATE_TEST_SUITE_P(ResolverTest,
UnaryOpExpressionTest,

View File

@ -746,7 +746,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 2u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 2u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -759,7 +759,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 2u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 2u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -772,7 +772,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::U32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 2u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 2u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -785,7 +785,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::I32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 2u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 2u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -798,7 +798,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::Bool>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 2u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 2u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -811,7 +811,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 2u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 2u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -824,7 +824,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 2u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 2u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1002,7 +1002,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 3u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1015,7 +1015,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 3u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1028,7 +1028,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::U32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 3u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1041,7 +1041,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::I32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 3u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1054,7 +1054,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::Bool>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 3u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1067,7 +1067,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 3u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1080,7 +1080,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 3u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1093,7 +1093,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 3u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1106,7 +1106,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 3u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1352,7 +1352,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 4u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1365,7 +1365,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 4u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1378,7 +1378,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::U32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 4u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1391,7 +1391,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::I32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 4u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1404,7 +1404,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::Bool>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 4u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1417,7 +1417,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 4u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1430,7 +1430,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 4u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1443,7 +1443,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 4u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1456,7 +1456,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 4u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1469,7 +1469,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 4u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1482,7 +1482,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 4u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1495,7 +1495,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 4u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1508,7 +1508,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 4u);
}
TEST_F(ResolverTypeConstructorValidationTest,
@ -1535,7 +1535,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 4u);
}
TEST_F(ResolverTypeConstructorValidationTest,

View File

@ -36,7 +36,7 @@ const Type* ElemType(const Type* ty, size_t num_elements) {
return ty;
}
if (auto* vec = ty->As<Vector>()) {
if (num_elements != vec->size()) {
if (num_elements != vec->Width()) {
TINT_ICE(Semantic, diag)
<< "sem::Constant() type <-> num_element mismatch. type: '"
<< ty->type_name() << "' num_elements: " << num_elements;

View File

@ -25,7 +25,7 @@ namespace sem {
Matrix::Matrix(Vector* column_type, uint32_t columns)
: subtype_(column_type->type()),
column_type_(column_type),
rows_(column_type->size()),
rows_(column_type->Width()),
columns_(columns) {
TINT_ASSERT(AST, rows_ > 1);
TINT_ASSERT(AST, rows_ < 5);

View File

@ -82,9 +82,9 @@ void Type::GetDefaultAlignAndSize(uint32_t& align, uint32_t& size) const {
return;
}
if (auto* vec = As<Vector>()) {
TINT_ASSERT(Semantic, vec->size() >= 2 && vec->size() <= 4);
align = vector_align[vec->size()];
size = vector_size[vec->size()];
TINT_ASSERT(Semantic, vec->Width() >= 2 && vec->Width() <= 4);
align = vector_align[vec->Width()];
size = vector_size[vec->Width()];
return;
}
if (auto* mat = As<Matrix>()) {

View File

@ -21,10 +21,10 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::Vector);
namespace tint {
namespace sem {
Vector::Vector(Type const* subtype, uint32_t size)
: subtype_(subtype), size_(size) {
TINT_ASSERT(Semantic, size_ > 1);
TINT_ASSERT(Semantic, size_ < 5);
Vector::Vector(Type const* subtype, uint32_t width)
: subtype_(subtype), width_(width) {
TINT_ASSERT(Semantic, width_ > 1);
TINT_ASSERT(Semantic, width_ < 5);
}
Vector::Vector(Vector&&) = default;
@ -32,12 +32,12 @@ Vector::Vector(Vector&&) = default;
Vector::~Vector() = default;
std::string Vector::type_name() const {
return "__vec_" + std::to_string(size_) + subtype_->type_name();
return "__vec_" + std::to_string(width_) + subtype_->type_name();
}
std::string Vector::FriendlyName(const SymbolTable& symbols) const {
std::ostringstream out;
out << "vec" << size_ << "<" << subtype_->FriendlyName(symbols) << ">";
out << "vec" << width_ << "<" << subtype_->FriendlyName(symbols) << ">";
return out.str();
}

View File

@ -35,12 +35,13 @@ class Vector : public Castable<Vector, Type> {
/// @returns the type of the vector elements
Type* type() const { return const_cast<Type*>(subtype_); }
/// @returns the size of the vector
uint32_t size() const { return size_; }
/// @returns the name for th type
std::string type_name() const override;
/// @returns the width of the vector
uint32_t Width() const { return width_; }
/// @param symbols the program's symbol table
/// @returns the name for this type that closely resembles how it would be
/// declared in WGSL.
@ -52,7 +53,7 @@ class Vector : public Castable<Vector, Type> {
private:
Type const* const subtype_;
uint32_t const size_;
uint32_t const width_;
};
} // namespace sem

View File

@ -25,7 +25,7 @@ TEST_F(VectorTest, Creation) {
I32 i32;
Vector v{&i32, 2};
EXPECT_EQ(v.type(), &i32);
EXPECT_EQ(v.size(), 2u);
EXPECT_EQ(v.Width(), 2u);
}
TEST_F(VectorTest, TypeName) {

View File

@ -153,7 +153,7 @@ bool IntrinsicDataTypeFor(const sem::Type* ty,
return true;
}
if (auto* vec = ty->As<sem::Vector>()) {
switch (vec->size()) {
switch (vec->Width()) {
case 2:
if (vec->type()->Is<sem::I32>()) {
out = DecomposeMemoryAccess::Intrinsic::DataType::kVec2I32;

View File

@ -56,7 +56,7 @@ void FoldConstants::Run(CloneContext& ctx, const DataMap&, DataMap&) {
}
if (auto* vec = ty->As<sem::Vector>()) {
uint32_t vec_size = static_cast<uint32_t>(vec->size());
uint32_t vec_size = static_cast<uint32_t>(vec->Width());
// We'd like to construct the new vector with the same number of
// constructor args that the original node had, but after folding

View File

@ -63,7 +63,7 @@ struct Robustness::State {
Value size; // size of the array, vector or matrix
size.is_signed = false; // size is always unsigned
if (auto* vec = ret_type->As<sem::Vector>()) {
size.u32 = vec->size();
size.u32 = vec->Width();
} else if (auto* arr = ret_type->As<sem::Array>()) {
size.u32 = arr->Count();

View File

@ -124,7 +124,7 @@ ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const sem::Type* ty) {
}
if (auto* v = ty->As<sem::Vector>()) {
auto* el = CreateASTTypeFor(ctx, v->type());
return ctx.dst->create<ast::Vector>(el, v->size());
return ctx.dst->create<ast::Vector>(el, v->Width());
}
if (auto* a = ty->As<sem::Array>()) {
auto* el = CreateASTTypeFor(ctx, a->ElemType());

View File

@ -148,7 +148,7 @@ DataType DataTypeOf(sem::Type* ty) {
return {BaseType::kF32, 1};
}
if (auto* vec = ty->As<sem::Vector>()) {
return {DataTypeOf(vec->type()).base_type, vec->size()};
return {DataTypeOf(vec->type()).base_type, vec->Width()};
}
return {BaseType::kInvalid, 0};
}

View File

@ -43,7 +43,7 @@ ast::TypeConstructorExpression* AppendVector(ProgramBuilder* b,
auto* vector_sem = b->Sem().Get(vector);
auto* vector_ty = vector_sem->Type()->UnwrapRef();
if (auto* vec = vector_ty->As<sem::Vector>()) {
packed_size = vec->size() + 1;
packed_size = vec->Width() + 1;
packed_el_sem_ty = vec->type();
} else {
packed_size = 2;

View File

@ -205,7 +205,7 @@ bool GeneratorImpl::EmitDynamicVectorAssignment(
{
ScopedIndent si(&helpers_);
auto out = line(&helpers_);
switch (vec->size()) {
switch (vec->Width()) {
case 2:
out << "vec = (idx.xx == int2(0, 1)) ? val.xx : vec;";
break;
@ -217,7 +217,7 @@ bool GeneratorImpl::EmitDynamicVectorAssignment(
break;
default:
TINT_UNREACHABLE(Writer, builder_.Diagnostics())
<< "invalid vector size " << vec->size();
<< "invalid vector size " << vec->Width();
break;
}
}
@ -1285,7 +1285,7 @@ bool GeneratorImpl::EmitFrexpCall(std::ostream& out,
std::string width;
if (auto* vec = significand_ty->As<sem::Vector>()) {
width = std::to_string(vec->size());
width = std::to_string(vec->Width());
}
// Exponent is an integer, which HLSL does not have an overload for.
@ -1318,7 +1318,7 @@ bool GeneratorImpl::EmitIsNormalCall(std::ostream& out,
std::string width;
if (auto* vec = input_ty->As<sem::Vector>()) {
width = std::to_string(vec->size());
width = std::to_string(vec->Width());
}
constexpr auto* kExponentMask = "0x7f80000";
@ -1816,7 +1816,7 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
// number of components.
uint32_t wgsl_ret_width = 1;
if (auto* vec = intrinsic->ReturnType()->As<sem::Vector>()) {
wgsl_ret_width = vec->size();
wgsl_ret_width = vec->Width();
}
if (wgsl_ret_width < hlsl_ret_width) {
out << ".";
@ -2022,7 +2022,7 @@ bool GeneratorImpl::EmitTypeConstructor(std::ostream& out,
}
if (is_single_value_vector_init) {
out << ")." << std::string(type->As<sem::Vector>()->size(), 'x');
out << ")." << std::string(type->As<sem::Vector>()->Width(), 'x');
}
out << (brackets ? "}" : ")");
@ -2537,7 +2537,7 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, const sem::Type* type) {
return false;
}
ScopedParen sp(out);
for (uint32_t i = 0; i < vec->size(); i++) {
for (uint32_t i = 0; i < vec->Width(); i++) {
if (i != 0) {
out << ", ";
}
@ -2970,7 +2970,7 @@ bool GeneratorImpl::EmitType(std::ostream& out,
} else if (type->Is<sem::U32>()) {
out << "uint";
} else if (auto* vec = type->As<sem::Vector>()) {
auto size = vec->size();
auto size = vec->Width();
if (vec->type()->Is<sem::F32>() && size >= 1 && size <= 4) {
out << "float" << size;
} else if (vec->type()->Is<sem::I32>() && size >= 1 && size <= 4) {

View File

@ -2017,7 +2017,7 @@ bool GeneratorImpl::EmitType(std::ostream& out,
if (!EmitType(out, vec->type(), "")) {
return false;
}
out << vec->size();
out << vec->Width();
return true;
}
@ -2062,7 +2062,7 @@ bool GeneratorImpl::EmitPackedType(std::ostream& out,
if (!EmitType(out, vec->type(), "")) {
return false;
}
out << vec->size();
out << vec->Width();
return true;
}
@ -2349,7 +2349,7 @@ GeneratorImpl::SizeAndAlign GeneratorImpl::MslPackedTypeSizeAndAlign(
if (auto* vec = ty->As<sem::Vector>()) {
// https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf
// 2.2.3 Packed Vector Types
auto num_els = vec->size();
auto num_els = vec->Width();
auto* el_ty = vec->type();
if (el_ty->IsAnyOf<sem::U32, sem::I32, sem::F32>()) {
return SizeAndAlign{num_els * 4, 4};

View File

@ -1337,7 +1337,7 @@ uint32_t Builder::GenerateTypeConstructorExpression(
auto* value_type = TypeOf(values[0])->UnwrapRef();
if (auto* val_vec = value_type->As<sem::Vector>()) {
if (val_vec->type()->is_scalar()) {
can_cast_or_copy = res_vec->size() == val_vec->size();
can_cast_or_copy = res_vec->Width() == val_vec->Width();
}
}
}
@ -1413,7 +1413,7 @@ uint32_t Builder::GenerateTypeConstructorExpression(
return 0;
}
for (uint32_t i = 0; i < vec->size(); ++i) {
for (uint32_t i = 0; i < vec->Width(); ++i) {
auto extract = result_op();
auto extract_id = extract.to_i();
@ -1455,7 +1455,7 @@ uint32_t Builder::GenerateTypeConstructorExpression(
auto* const init_result_type = TypeOf(init)->UnwrapRef();
if (values.size() == 1 && init_result_type->is_scalar_vector() &&
TypeOf(values[0])->UnwrapRef()->is_scalar()) {
size_t vec_size = init_result_type->As<sem::Vector>()->size();
size_t vec_size = init_result_type->As<sem::Vector>()->Width();
for (size_t i = 0; i < (vec_size - 1); ++i) {
ops.push_back(ops[0]);
}
@ -1772,7 +1772,7 @@ uint32_t Builder::GenerateConstantVectorSplatIfNeeded(const sem::Vector* type,
return 0;
}
uint64_t key = (static_cast<uint64_t>(type->size()) << 32) + value_id;
uint64_t key = (static_cast<uint64_t>(type->Width()) << 32) + value_id;
return utils::GetOrCreate(const_splat_to_id_, key, [&] {
auto result = result_op();
auto result_id = result.to_i();
@ -1780,7 +1780,7 @@ uint32_t Builder::GenerateConstantVectorSplatIfNeeded(const sem::Vector* type,
OperandList ops;
ops.push_back(Operand::Int(type_id));
ops.push_back(result);
for (uint32_t i = 0; i < type->size(); i++) {
for (uint32_t i = 0; i < type->Width(); i++) {
ops.push_back(Operand::Int(value_id));
}
push_type(spv::Op::OpConstantComposite, ops);
@ -1882,7 +1882,7 @@ uint32_t Builder::GenerateSplat(uint32_t scalar_id, const sem::Type* vec_type) {
OperandList ops;
ops.push_back(Operand::Int(GenerateTypeIfNeeded(vec_type)));
ops.push_back(splat_result);
for (size_t i = 0; i < vec_type->As<sem::Vector>()->size(); ++i) {
for (size_t i = 0; i < vec_type->As<sem::Vector>()->Width(); ++i) {
ops.push_back(Operand::Int(scalar_id));
}
if (!push_function_inst(spv::Op::OpCompositeConstruct, ops)) {
@ -2467,12 +2467,12 @@ uint32_t Builder::GenerateIntrinsic(ast::CallExpression* call,
// same size, and create vector constants by replicating the scalars.
// I expect backend compilers to fold these into unique constants, so
// there is no loss of efficiency.
sem::Vector uvec_ty(&u32, fvec_ty->size());
sem::Vector uvec_ty(&u32, fvec_ty->Width());
unsigned_id = GenerateTypeIfNeeded(&uvec_ty);
auto splat = [&](uint32_t scalar_id) -> uint32_t {
auto splat_result = result_op();
OperandList splat_params{Operand::Int(unsigned_id), splat_result};
for (size_t i = 0; i < fvec_ty->size(); i++) {
for (size_t i = 0; i < fvec_ty->Width(); i++) {
splat_params.emplace_back(Operand::Int(scalar_id));
}
if (!push_function_inst(spv::Op::OpCompositeConstruct,
@ -2531,7 +2531,7 @@ uint32_t Builder::GenerateIntrinsic(ast::CallExpression* call,
if (result_vector_type &&
intrinsic->Parameters()[2]->Type()->is_scalar()) {
sem::Bool bool_type;
sem::Vector bool_vec_type(&bool_type, result_vector_type->size());
sem::Vector bool_vec_type(&bool_type, result_vector_type->Width());
if (!GenerateTypeIfNeeded(&bool_vec_type)) {
return 0;
}
@ -4015,7 +4015,7 @@ bool Builder::GenerateVectorType(const sem::Vector* vec,
}
push_type(spv::Op::OpTypeVector,
{result, Operand::Int(type_id), Operand::Int(vec->size())});
{result, Operand::Int(type_id), Operand::Int(vec->Width())});
return true;
}