Use ProgramBuilder::Construct() where possible

Replace all calls to create<ast::TypeConstructorExpression>() with
Construct(). TypeConstructorExpression will be folded into
ast::CallExpression, but the Construct() call signature will remain
identical.

Bug: tint:888
Change-Id: Ifb28a90ccf5184c8090c2e32fa8c82f3996dfa33
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69108
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton 2021-11-12 13:53:49 +00:00
parent 5a40c6564c
commit 4cfa725fb3
7 changed files with 126 additions and 204 deletions

View File

@ -1350,8 +1350,8 @@ bool FunctionEmitter::EmitEntryPointAsWrapper() {
// Add the return-value statement. // Add the return-value statement.
stmts.push_back(create<ast::ReturnStatement>( stmts.push_back(create<ast::ReturnStatement>(
source, create<ast::TypeConstructorExpression>( source,
source, return_type, std::move(return_exprs)))); builder_.Construct(source, return_type, std::move(return_exprs))));
} }
} }
@ -3960,9 +3960,8 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue(
for (uint32_t iarg = 0; iarg < inst.NumInOperands(); ++iarg) { for (uint32_t iarg = 0; iarg < inst.NumInOperands(); ++iarg) {
operands.emplace_back(MakeOperand(inst, iarg).expr); operands.emplace_back(MakeOperand(inst, iarg).expr);
} }
return {ast_type, return {ast_type, builder_.Construct(Source{}, ast_type->Build(builder_),
create<ast::TypeConstructorExpression>( std::move(operands))};
Source{}, ast_type->Build(builder_), std::move(operands))};
} }
if (opcode == SpvOpCompositeExtract) { if (opcode == SpvOpCompositeExtract) {
@ -4646,8 +4645,8 @@ TypedExpression FunctionEmitter::MakeVectorShuffle(
return {}; return {};
} }
} }
return {result_type, create<ast::TypeConstructorExpression>( return {result_type,
source, result_type->Build(builder_), values)}; builder_.Construct(source, result_type->Build(builder_), values)};
} }
bool FunctionEmitter::RegisterSpecialBuiltInVariables() { bool FunctionEmitter::RegisterSpecialBuiltInVariables() {
@ -5018,10 +5017,10 @@ TypedExpression FunctionEmitter::MakeNumericConversion(
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(arg_expr.expr); params.push_back(arg_expr.expr);
TypedExpression result{expr_type, TypedExpression result{
create<ast::TypeConstructorExpression>( expr_type,
GetSourceForInst(inst), expr_type->Build(builder_), builder_.Construct(GetSourceForInst(inst), expr_type->Build(builder_),
std::move(params))}; std::move(params))};
if (requested_type == expr_type) { if (requested_type == expr_type) {
return result; return result;
@ -5468,7 +5467,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
// first component. // first component.
if (texture_type->IsAnyOf<DepthTexture, DepthMultisampledTexture>()) { if (texture_type->IsAnyOf<DepthTexture, DepthMultisampledTexture>()) {
if (is_non_dref_sample || (opcode == SpvOpImageFetch)) { if (is_non_dref_sample || (opcode == SpvOpImageFetch)) {
value = create<ast::TypeConstructorExpression>( value = builder_.Construct(
Source{}, Source{},
result_type->Build(builder_), // a vec4 result_type->Build(builder_), // a vec4
ast::ExpressionList{ ast::ExpressionList{
@ -5555,8 +5554,8 @@ bool FunctionEmitter::EmitImageQuery(const spvtools::opt::Instruction& inst) {
} }
auto* result_type = parser_impl_.ConvertType(inst.type_id()); auto* result_type = parser_impl_.ConvertType(inst.type_id());
TypedExpression expr = { TypedExpression expr = {
result_type, create<ast::TypeConstructorExpression>( result_type,
Source{}, result_type->Build(builder_), exprs)}; builder_.Construct(Source{}, result_type->Build(builder_), exprs)};
return EmitConstDefOrWriteToHoistedVar(inst, expr); return EmitConstDefOrWriteToHoistedVar(inst, expr);
} }
case SpvOpImageQueryLod: case SpvOpImageQueryLod:
@ -5577,9 +5576,8 @@ bool FunctionEmitter::EmitImageQuery(const spvtools::opt::Instruction& inst) {
// The SPIR-V result type must be integer scalar. The WGSL bulitin // The SPIR-V result type must be integer scalar. The WGSL bulitin
// returns i32. If they aren't the same then convert the result. // returns i32. If they aren't the same then convert the result.
if (!result_type->Is<I32>()) { if (!result_type->Is<I32>()) {
ast_expr = create<ast::TypeConstructorExpression>( ast_expr = builder_.Construct(Source{}, result_type->Build(builder_),
Source{}, result_type->Build(builder_), ast::ExpressionList{ast_expr});
ast::ExpressionList{ast_expr});
} }
TypedExpression expr{result_type, ast_expr}; TypedExpression expr{result_type, ast_expr};
return EmitConstDefOrWriteToHoistedVar(inst, expr); return EmitConstDefOrWriteToHoistedVar(inst, expr);
@ -5784,8 +5782,8 @@ const ast::Expression* FunctionEmitter::ConvertTexelForStorage(
for (auto i = src_count; i < dest_count; i++) { for (auto i = src_count; i < dest_count; i++) {
exprs.push_back(parser_impl_.MakeNullExpression(component_type).expr); exprs.push_back(parser_impl_.MakeNullExpression(component_type).expr);
} }
texel.expr = create<ast::TypeConstructorExpression>( texel.expr = builder_.Construct(Source{}, texel.type->Build(builder_),
Source{}, texel.type->Build(builder_), std::move(exprs)); std::move(exprs));
} }
return texel.expr; return texel.expr;
@ -5795,9 +5793,8 @@ TypedExpression FunctionEmitter::ToI32(TypedExpression value) {
if (!value || value.type->Is<I32>()) { if (!value || value.type->Is<I32>()) {
return value; return value;
} }
return {ty_.I32(), return {ty_.I32(), builder_.Construct(Source{}, builder_.ty.i32(),
create<ast::TypeConstructorExpression>( ast::ExpressionList{value.expr})};
Source{}, builder_.ty.i32(), ast::ExpressionList{value.expr})};
} }
TypedExpression FunctionEmitter::ToSignedIfUnsigned(TypedExpression value) { TypedExpression FunctionEmitter::ToSignedIfUnsigned(TypedExpression value) {
@ -5890,11 +5887,11 @@ TypedExpression FunctionEmitter::MakeOuterProduct(
Source{}, ast::BinaryOp::kMultiply, row_factor, column_factor); Source{}, ast::BinaryOp::kMultiply, row_factor, column_factor);
result_row.push_back(elem); result_row.push_back(elem);
} }
result_columns.push_back(create<ast::TypeConstructorExpression>( result_columns.push_back(
Source{}, col_ty->Build(builder_), result_row)); builder_.Construct(Source{}, col_ty->Build(builder_), result_row));
} }
return {result_ty, create<ast::TypeConstructorExpression>( return {result_ty, builder_.Construct(Source{}, result_ty->Build(builder_),
Source{}, result_ty->Build(builder_), result_columns)}; result_columns)};
} }
bool FunctionEmitter::MakeVectorInsertDynamic( bool FunctionEmitter::MakeVectorInsertDynamic(

View File

@ -1862,9 +1862,9 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
auto y = MakeConstantExpression(workgroup_size_builtin_.y_id); auto y = MakeConstantExpression(workgroup_size_builtin_.y_id);
auto z = MakeConstantExpression(workgroup_size_builtin_.z_id); auto z = MakeConstantExpression(workgroup_size_builtin_.z_id);
auto* ast_type = ty_.Vector(x.type, 3); auto* ast_type = ty_.Vector(x.type, 3);
return {ast_type, create<ast::TypeConstructorExpression>( return {ast_type,
Source{}, ast_type->Build(builder_), builder_.Construct(Source{}, ast_type->Build(builder_),
ast::ExpressionList{x.expr, y.expr, z.expr})}; ast::ExpressionList{x.expr, y.expr, z.expr})};
} else if (id == workgroup_size_builtin_.x_id) { } else if (id == workgroup_size_builtin_.x_id) {
return MakeConstantExpressionForScalarSpirvConstant( return MakeConstantExpressionForScalarSpirvConstant(
Source{}, ConvertType(workgroup_size_builtin_.component_type_id), Source{}, ConvertType(workgroup_size_builtin_.component_type_id),
@ -1933,9 +1933,9 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
// We've already emitted a diagnostic. // We've already emitted a diagnostic.
return {}; return {};
} }
return {original_ast_type, create<ast::TypeConstructorExpression>( return {original_ast_type,
source, original_ast_type->Build(builder_), builder_.Construct(source, original_ast_type->Build(builder_),
std::move(ast_components))}; std::move(ast_components))};
} }
default: default:
break; break;
@ -2005,16 +2005,16 @@ const ast::Expression* ParserImpl::MakeNullValue(const Type* type) {
if (type->Is<Alias>()) { if (type->Is<Alias>()) {
// TODO(amaiorano): No type constructor for TypeName (yet?) // TODO(amaiorano): No type constructor for TypeName (yet?)
ast::ExpressionList ast_components; ast::ExpressionList ast_components;
return create<ast::TypeConstructorExpression>( return builder_.Construct(Source{}, original_type->Build(builder_),
Source{}, original_type->Build(builder_), std::move(ast_components)); std::move(ast_components));
} }
if (auto* vec_ty = type->As<Vector>()) { if (auto* vec_ty = type->As<Vector>()) {
ast::ExpressionList ast_components; ast::ExpressionList ast_components;
for (size_t i = 0; i < vec_ty->size; ++i) { for (size_t i = 0; i < vec_ty->size; ++i) {
ast_components.emplace_back(MakeNullValue(vec_ty->type)); ast_components.emplace_back(MakeNullValue(vec_ty->type));
} }
return create<ast::TypeConstructorExpression>( return builder_.Construct(Source{}, type->Build(builder_),
Source{}, type->Build(builder_), std::move(ast_components)); std::move(ast_components));
} }
if (auto* mat_ty = type->As<Matrix>()) { if (auto* mat_ty = type->As<Matrix>()) {
// Matrix components are columns // Matrix components are columns
@ -2023,24 +2023,24 @@ const ast::Expression* ParserImpl::MakeNullValue(const Type* type) {
for (size_t i = 0; i < mat_ty->columns; ++i) { for (size_t i = 0; i < mat_ty->columns; ++i) {
ast_components.emplace_back(MakeNullValue(column_ty)); ast_components.emplace_back(MakeNullValue(column_ty));
} }
return create<ast::TypeConstructorExpression>( return builder_.Construct(Source{}, type->Build(builder_),
Source{}, type->Build(builder_), std::move(ast_components)); std::move(ast_components));
} }
if (auto* arr_ty = type->As<Array>()) { if (auto* arr_ty = type->As<Array>()) {
ast::ExpressionList ast_components; ast::ExpressionList ast_components;
for (size_t i = 0; i < arr_ty->size; ++i) { for (size_t i = 0; i < arr_ty->size; ++i) {
ast_components.emplace_back(MakeNullValue(arr_ty->type)); ast_components.emplace_back(MakeNullValue(arr_ty->type));
} }
return create<ast::TypeConstructorExpression>( return builder_.Construct(Source{}, original_type->Build(builder_),
Source{}, original_type->Build(builder_), std::move(ast_components)); std::move(ast_components));
} }
if (auto* struct_ty = type->As<Struct>()) { if (auto* struct_ty = type->As<Struct>()) {
ast::ExpressionList ast_components; ast::ExpressionList ast_components;
for (auto* member : struct_ty->members) { for (auto* member : struct_ty->members) {
ast_components.emplace_back(MakeNullValue(member)); ast_components.emplace_back(MakeNullValue(member));
} }
return create<ast::TypeConstructorExpression>( return builder_.Construct(Source{}, original_type->Build(builder_),
Source{}, original_type->Build(builder_), std::move(ast_components)); std::move(ast_components));
} }
Fail() << "can't make null value for type: " << type->TypeInfo().name; Fail() << "can't make null value for type: " << type->TypeInfo().name;
return nullptr; return nullptr;

View File

@ -2232,8 +2232,7 @@ Maybe<const ast::Expression*> ParserImpl::primary_expression() {
if (params.errored) if (params.errored)
return Failure::kErrored; return Failure::kErrored;
return create<ast::TypeConstructorExpression>(source, type.value, return builder_.Construct(source, type.value, std::move(params.value));
std::move(params.value));
} }
return Failure::kNoMatch; return Failure::kNoMatch;
@ -2917,8 +2916,7 @@ Expect<const ast::Expression*> ParserImpl::expect_const_expr() {
if (params.errored) if (params.errored)
return Failure::kErrored; return Failure::kErrored;
return create<ast::TypeConstructorExpression>(source, type.value, return builder_.Construct(source, type.value, params.value);
params.value);
} }
} }
return add_error(peek(), "unable to parse const_expr"); return add_error(peek(), "unable to parse const_expr");

View File

@ -471,8 +471,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Array_ScalarArgumentTypeMismatch_Vec2) { Expr_Constructor_Array_ScalarArgumentTypeMismatch_Vec2) {
// array<i32, 3>(1, vec2<i32>()); // array<i32, 3>(1, vec2<i32>());
auto* tc = auto* tc =
array<i32, 3>(Expr(1), create<ast::TypeConstructorExpression>( array<i32, 3>(Expr(1), Construct(Source{{12, 34}}, ty.vec2<i32>()));
Source{{12, 34}}, ty.vec2<i32>(), ExprList()));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -636,8 +635,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec2_Error_Vec3ArgumentCardinalityTooLarge) { Expr_Constructor_Vec2_Error_Vec3ArgumentCardinalityTooLarge) {
auto* tc = vec2<f32>(create<ast::TypeConstructorExpression>( auto* tc = vec2<f32>(Construct(Source{{12, 34}}, ty.vec3<f32>()));
Source{{12, 34}}, ty.vec3<f32>(), ExprList()));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -648,8 +646,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec2_Error_Vec4ArgumentCardinalityTooLarge) { Expr_Constructor_Vec2_Error_Vec4ArgumentCardinalityTooLarge) {
auto* tc = vec2<f32>(create<ast::TypeConstructorExpression>( auto* tc = vec2<f32>(Construct(Source{{12, 34}}, ty.vec4<f32>()));
Source{{12, 34}}, ty.vec4<f32>(), ExprList()));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -673,10 +670,8 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec2_Error_TooManyArgumentsVector) { Expr_Constructor_Vec2_Error_TooManyArgumentsVector) {
auto* tc = vec2<f32>(create<ast::TypeConstructorExpression>( auto* tc = vec2<f32>(Construct(Source{{12, 34}}, ty.vec2<f32>()),
Source{{12, 34}}, ty.vec2<f32>(), ExprList()), Construct(Source{{12, 40}}, ty.vec2<f32>()));
create<ast::TypeConstructorExpression>(
Source{{12, 40}}, ty.vec2<f32>(), ExprList()));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -687,8 +682,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec2_Error_TooManyArgumentsVectorAndScalar) { Expr_Constructor_Vec2_Error_TooManyArgumentsVectorAndScalar) {
auto* tc = vec2<f32>(create<ast::TypeConstructorExpression>( auto* tc = vec2<f32>(Construct(Source{{12, 34}}, ty.vec2<f32>()),
Source{{12, 34}}, ty.vec2<f32>(), ExprList()),
Expr(Source{{12, 40}}, 1.0f)); Expr(Source{{12, 40}}, 1.0f));
WrapInFunction(tc); WrapInFunction(tc);
@ -700,8 +694,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec2_Error_InvalidArgumentType) { Expr_Constructor_Vec2_Error_InvalidArgumentType) {
auto* tc = vec2<f32>(create<ast::TypeConstructorExpression>( auto* tc = vec2<f32>(Construct(Source{{12, 34}}, ty.mat2x2<f32>()));
Source{{12, 34}}, ty.mat2x2<f32>(), ExprList()));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -847,8 +840,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec3_Error_Vec4ArgumentCardinalityTooLarge) { Expr_Constructor_Vec3_Error_Vec4ArgumentCardinalityTooLarge) {
auto* tc = vec3<f32>(create<ast::TypeConstructorExpression>( auto* tc = vec3<f32>(Construct(Source{{12, 34}}, ty.vec4<f32>()));
Source{{12, 34}}, ty.vec4<f32>(), ExprList()));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -884,8 +876,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec3_Error_TooFewArgumentsVec2) { Expr_Constructor_Vec3_Error_TooFewArgumentsVec2) {
auto* tc = vec3<f32>(create<ast::TypeConstructorExpression>( auto* tc = vec3<f32>(Construct(Source{{12, 34}}, ty.vec2<f32>()));
Source{{12, 34}}, ty.vec2<f32>(), ExprList()));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -896,10 +887,8 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec3_Error_TooManyArgumentsVec2) { Expr_Constructor_Vec3_Error_TooManyArgumentsVec2) {
auto* tc = vec3<f32>(create<ast::TypeConstructorExpression>( auto* tc = vec3<f32>(Construct(Source{{12, 34}}, ty.vec2<f32>()),
Source{{12, 34}}, ty.vec2<f32>(), ExprList()), Construct(Source{{12, 40}}, ty.vec2<f32>()));
create<ast::TypeConstructorExpression>(
Source{{12, 40}}, ty.vec2<f32>(), ExprList()));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -911,8 +900,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec3_Error_TooManyArgumentsVec2AndScalar) { Expr_Constructor_Vec3_Error_TooManyArgumentsVec2AndScalar) {
auto* tc = auto* tc =
vec3<f32>(create<ast::TypeConstructorExpression>( vec3<f32>(Construct(Source{{12, 34}}, ty.vec2<f32>()),
Source{{12, 34}}, ty.vec2<f32>(), ExprList()),
Expr(Source{{12, 40}}, 1.0f), Expr(Source{{12, 46}}, 1.0f)); Expr(Source{{12, 40}}, 1.0f), Expr(Source{{12, 46}}, 1.0f));
WrapInFunction(tc); WrapInFunction(tc);
@ -924,8 +912,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec3_Error_TooManyArgumentsVec3) { Expr_Constructor_Vec3_Error_TooManyArgumentsVec3) {
auto* tc = vec3<f32>(create<ast::TypeConstructorExpression>( auto* tc = vec3<f32>(Construct(Source{{12, 34}}, ty.vec3<f32>()),
Source{{12, 34}}, ty.vec3<f32>(), ExprList()),
Expr(Source{{12, 40}}, 1.0f)); Expr(Source{{12, 40}}, 1.0f));
WrapInFunction(tc); WrapInFunction(tc);
@ -937,8 +924,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec3_Error_InvalidArgumentType) { Expr_Constructor_Vec3_Error_InvalidArgumentType) {
auto* tc = vec3<f32>(create<ast::TypeConstructorExpression>( auto* tc = vec3<f32>(Construct(Source{{12, 34}}, ty.mat2x2<f32>()));
Source{{12, 34}}, ty.mat2x2<f32>(), ExprList()));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1137,8 +1123,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec4_Error_TooFewArgumentsVec2AndScalar) { Expr_Constructor_Vec4_Error_TooFewArgumentsVec2AndScalar) {
auto* tc = vec4<f32>(create<ast::TypeConstructorExpression>( auto* tc = vec4<f32>(Construct(Source{{12, 34}}, ty.vec2<f32>()),
Source{{12, 34}}, ty.vec2<f32>(), ExprList()),
Expr(Source{{12, 40}}, 1.0f)); Expr(Source{{12, 40}}, 1.0f));
WrapInFunction(tc); WrapInFunction(tc);
@ -1150,11 +1135,9 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec4_Error_TooManyArgumentsVec2AndScalars) { Expr_Constructor_Vec4_Error_TooManyArgumentsVec2AndScalars) {
auto* tc = auto* tc = vec4<f32>(
vec4<f32>(create<ast::TypeConstructorExpression>( Construct(Source{{12, 34}}, ty.vec2<f32>()), Expr(Source{{12, 40}}, 1.0f),
Source{{12, 34}}, ty.vec2<f32>(), ExprList()), Expr(Source{{12, 46}}, 1.0f), Expr(Source{{12, 52}}, 1.0f));
Expr(Source{{12, 40}}, 1.0f), Expr(Source{{12, 46}}, 1.0f),
Expr(Source{{12, 52}}, 1.0f));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1165,10 +1148,8 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec4_Error_TooManyArgumentsVec2Vec2Scalar) { Expr_Constructor_Vec4_Error_TooManyArgumentsVec2Vec2Scalar) {
auto* tc = vec4<f32>(create<ast::TypeConstructorExpression>( auto* tc = vec4<f32>(Construct(Source{{12, 34}}, ty.vec2<f32>()),
Source{{12, 34}}, ty.vec2<f32>(), ExprList()), Construct(Source{{12, 40}}, ty.vec2<f32>()),
create<ast::TypeConstructorExpression>(
Source{{12, 40}}, ty.vec2<f32>(), ExprList()),
Expr(Source{{12, 46}}, 1.0f)); Expr(Source{{12, 46}}, 1.0f));
WrapInFunction(tc); WrapInFunction(tc);
@ -1180,12 +1161,9 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec4_Error_TooManyArgumentsVec2Vec2Vec2) { Expr_Constructor_Vec4_Error_TooManyArgumentsVec2Vec2Vec2) {
auto* tc = vec4<f32>(create<ast::TypeConstructorExpression>( auto* tc = vec4<f32>(Construct(Source{{12, 34}}, ty.vec2<f32>()),
Source{{12, 34}}, ty.vec2<f32>(), ExprList()), Construct(Source{{12, 40}}, ty.vec2<f32>()),
create<ast::TypeConstructorExpression>( Construct(Source{{12, 40}}, ty.vec2<f32>()));
Source{{12, 40}}, ty.vec2<f32>(), ExprList()),
create<ast::TypeConstructorExpression>(
Source{{12, 40}}, ty.vec2<f32>(), ExprList()));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1196,8 +1174,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec4_Error_TooFewArgumentsVec3) { Expr_Constructor_Vec4_Error_TooFewArgumentsVec3) {
auto* tc = vec4<f32>(create<ast::TypeConstructorExpression>( auto* tc = vec4<f32>(Construct(Source{{12, 34}}, ty.vec3<f32>()));
Source{{12, 34}}, ty.vec3<f32>(), ExprList()));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1209,8 +1186,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec4_Error_TooManyArgumentsVec3AndScalars) { Expr_Constructor_Vec4_Error_TooManyArgumentsVec3AndScalars) {
auto* tc = auto* tc =
vec4<f32>(create<ast::TypeConstructorExpression>( vec4<f32>(Construct(Source{{12, 34}}, ty.vec3<f32>()),
Source{{12, 34}}, ty.vec3<f32>(), ExprList()),
Expr(Source{{12, 40}}, 1.0f), Expr(Source{{12, 46}}, 1.0f)); Expr(Source{{12, 40}}, 1.0f), Expr(Source{{12, 46}}, 1.0f));
WrapInFunction(tc); WrapInFunction(tc);
@ -1222,10 +1198,8 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec4_Error_TooManyArgumentsVec3AndVec2) { Expr_Constructor_Vec4_Error_TooManyArgumentsVec3AndVec2) {
auto* tc = vec4<f32>(create<ast::TypeConstructorExpression>( auto* tc = vec4<f32>(Construct(Source{{12, 34}}, ty.vec3<f32>()),
Source{{12, 34}}, ty.vec3<f32>(), ExprList()), Construct(Source{{12, 40}}, ty.vec2<f32>()));
create<ast::TypeConstructorExpression>(
Source{{12, 40}}, ty.vec2<f32>(), ExprList()));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1236,10 +1210,8 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec4_Error_TooManyArgumentsVec2AndVec3) { Expr_Constructor_Vec4_Error_TooManyArgumentsVec2AndVec3) {
auto* tc = vec4<f32>(create<ast::TypeConstructorExpression>( auto* tc = vec4<f32>(Construct(Source{{12, 34}}, ty.vec2<f32>()),
Source{{12, 34}}, ty.vec2<f32>(), ExprList()), Construct(Source{{12, 40}}, ty.vec3<f32>()));
create<ast::TypeConstructorExpression>(
Source{{12, 40}}, ty.vec3<f32>(), ExprList()));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1250,10 +1222,8 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec4_Error_TooManyArgumentsVec3AndVec3) { Expr_Constructor_Vec4_Error_TooManyArgumentsVec3AndVec3) {
auto* tc = vec4<f32>(create<ast::TypeConstructorExpression>( auto* tc = vec4<f32>(Construct(Source{{12, 34}}, ty.vec3<f32>()),
Source{{12, 34}}, ty.vec3<f32>(), ExprList()), Construct(Source{{12, 40}}, ty.vec3<f32>()));
create<ast::TypeConstructorExpression>(
Source{{12, 40}}, ty.vec3<f32>(), ExprList()));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1264,8 +1234,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_Constructor_Vec4_Error_InvalidArgumentType) { Expr_Constructor_Vec4_Error_InvalidArgumentType) {
auto* tc = vec4<f32>(create<ast::TypeConstructorExpression>( auto* tc = vec4<f32>(Construct(Source{{12, 34}}, ty.mat2x2<f32>()));
Source{{12, 34}}, ty.mat2x2<f32>(), ExprList()));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1502,8 +1471,8 @@ TEST_F(ResolverTypeConstructorValidationTest,
// vec2<Float32>(1.0f, 1u) // vec2<Float32>(1.0f, 1u)
auto* vec_type = ty.vec(ty.Of(f32_alias), 2); auto* vec_type = ty.vec(ty.Of(f32_alias), 2);
auto* tc = create<ast::TypeConstructorExpression>( auto* tc =
Source{{12, 34}}, vec_type, ExprList(1.0f, Expr(Source{{12, 40}}, 1u))); Construct(Source{{12, 34}}, vec_type, 1.0f, Expr(Source{{12, 40}}, 1u));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1518,8 +1487,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
// vec2<Float32>(1.0f, 1.0f) // vec2<Float32>(1.0f, 1.0f)
auto* vec_type = ty.vec(ty.Of(f32_alias), 2); auto* vec_type = ty.vec(ty.Of(f32_alias), 2);
auto* tc = create<ast::TypeConstructorExpression>(Source{{12, 34}}, vec_type, auto* tc = Construct(Source{{12, 34}}, vec_type, 1.0f, 1.0f);
ExprList(1.0f, 1.0f));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -1531,9 +1499,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
// vec3<u32>(vec<Float32>(), 1.0f) // vec3<u32>(vec<Float32>(), 1.0f)
auto* vec_type = ty.vec(ty.Of(f32_alias), 2); auto* vec_type = ty.vec(ty.Of(f32_alias), 2);
auto* tc = vec3<u32>(create<ast::TypeConstructorExpression>( auto* tc = vec3<u32>(Construct(Source{{12, 34}}, vec_type), 1.0f);
Source{{12, 34}}, vec_type, ExprList()),
1.0f);
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1548,9 +1514,7 @@ TEST_F(ResolverTypeConstructorValidationTest,
// vec3<f32>(vec<Float32>(), 1.0f) // vec3<f32>(vec<Float32>(), 1.0f)
auto* vec_type = ty.vec(ty.Of(f32_alias), 2); auto* vec_type = ty.vec(ty.Of(f32_alias), 2);
auto* tc = vec3<f32>(create<ast::TypeConstructorExpression>( auto* tc = vec3<f32>(Construct(Source{{12, 34}}, vec_type), 1.0f);
Source{{12, 34}}, vec_type, ExprList()),
1.0f);
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -1579,13 +1543,11 @@ TEST_P(MatrixConstructorTest, Expr_ColumnConstructor_Error_TooFewArguments) {
ast::ExpressionList args; ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns - 1; i++) { for (uint32_t i = 1; i <= param.columns - 1; i++) {
auto* vec_type = ty.vec<f32>(param.rows); auto* vec_type = ty.vec<f32>(param.rows);
args.push_back(create<ast::TypeConstructorExpression>( args.push_back(Construct(Source{{12, i}}, vec_type));
Source{{12, i}}, vec_type, ExprList()));
} }
auto* matrix_type = ty.mat<f32>(param.columns, param.rows); auto* matrix_type = ty.mat<f32>(param.columns, param.rows);
auto* tc = create<ast::TypeConstructorExpression>(Source{}, matrix_type, auto* tc = Construct(Source{}, matrix_type, std::move(args));
std::move(args));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1601,13 +1563,11 @@ TEST_P(MatrixConstructorTest, Expr_ElementConstructor_Error_TooFewArguments) {
ast::ExpressionList args; ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns * param.rows - 1; i++) { for (uint32_t i = 1; i <= param.columns * param.rows - 1; i++) {
args.push_back(create<ast::TypeConstructorExpression>( args.push_back(Construct(Source{{12, i}}, ty.f32()));
Source{{12, i}}, ty.f32(), ExprList()));
} }
auto* matrix_type = ty.mat<f32>(param.columns, param.rows); auto* matrix_type = ty.mat<f32>(param.columns, param.rows);
auto* tc = create<ast::TypeConstructorExpression>(Source{}, matrix_type, auto* tc = Construct(Source{}, matrix_type, std::move(args));
std::move(args));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1624,13 +1584,11 @@ TEST_P(MatrixConstructorTest, Expr_ColumnConstructor_Error_TooManyArguments) {
ast::ExpressionList args; ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns + 1; i++) { for (uint32_t i = 1; i <= param.columns + 1; i++) {
auto* vec_type = ty.vec<f32>(param.rows); auto* vec_type = ty.vec<f32>(param.rows);
args.push_back(create<ast::TypeConstructorExpression>( args.push_back(Construct(Source{{12, i}}, vec_type));
Source{{12, i}}, vec_type, ExprList()));
} }
auto* matrix_type = ty.mat<f32>(param.columns, param.rows); auto* matrix_type = ty.mat<f32>(param.columns, param.rows);
auto* tc = create<ast::TypeConstructorExpression>(Source{}, matrix_type, auto* tc = Construct(Source{}, matrix_type, std::move(args));
std::move(args));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1646,13 +1604,11 @@ TEST_P(MatrixConstructorTest, Expr_ElementConstructor_Error_TooManyArguments) {
ast::ExpressionList args; ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns * param.rows + 1; i++) { for (uint32_t i = 1; i <= param.columns * param.rows + 1; i++) {
args.push_back(create<ast::TypeConstructorExpression>( args.push_back(Construct(Source{{12, i}}, ty.f32()));
Source{{12, i}}, ty.f32(), ExprList()));
} }
auto* matrix_type = ty.mat<f32>(param.columns, param.rows); auto* matrix_type = ty.mat<f32>(param.columns, param.rows);
auto* tc = create<ast::TypeConstructorExpression>(Source{}, matrix_type, auto* tc = Construct(Source{}, matrix_type, std::move(args));
std::move(args));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1670,13 +1626,11 @@ TEST_P(MatrixConstructorTest,
ast::ExpressionList args; ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns; i++) { for (uint32_t i = 1; i <= param.columns; i++) {
auto* vec_type = ty.vec<u32>(param.rows); auto* vec_type = ty.vec<u32>(param.rows);
args.push_back(create<ast::TypeConstructorExpression>( args.push_back(Construct(Source{{12, i}}, vec_type));
Source{{12, i}}, vec_type, ExprList()));
} }
auto* matrix_type = ty.mat<f32>(param.columns, param.rows); auto* matrix_type = ty.mat<f32>(param.columns, param.rows);
auto* tc = create<ast::TypeConstructorExpression>(Source{}, matrix_type, auto* tc = Construct(Source{}, matrix_type, std::move(args));
std::move(args));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1697,8 +1651,7 @@ TEST_P(MatrixConstructorTest,
} }
auto* matrix_type = ty.mat<f32>(param.columns, param.rows); auto* matrix_type = ty.mat<f32>(param.columns, param.rows);
auto* tc = create<ast::TypeConstructorExpression>(Source{}, matrix_type, auto* tc = Construct(Source{}, matrix_type, std::move(args));
std::move(args));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1721,17 +1674,14 @@ TEST_P(MatrixConstructorTest,
ast::ExpressionList args; ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns - 1; i++) { for (uint32_t i = 1; i <= param.columns - 1; i++) {
auto* valid_vec_type = ty.vec<f32>(param.rows); auto* valid_vec_type = ty.vec<f32>(param.rows);
args.push_back(create<ast::TypeConstructorExpression>( args.push_back(Construct(Source{{12, i}}, valid_vec_type));
Source{{12, i}}, valid_vec_type, ExprList()));
} }
const size_t kInvalidLoc = 2 * (param.columns - 1); const size_t kInvalidLoc = 2 * (param.columns - 1);
auto* invalid_vec_type = ty.vec<f32>(param.rows - 1); auto* invalid_vec_type = ty.vec<f32>(param.rows - 1);
args.push_back(create<ast::TypeConstructorExpression>( args.push_back(Construct(Source{{12, kInvalidLoc}}, invalid_vec_type));
Source{{12, kInvalidLoc}}, invalid_vec_type, ExprList()));
auto* matrix_type = ty.mat<f32>(param.columns, param.rows); auto* matrix_type = ty.mat<f32>(param.columns, param.rows);
auto* tc = create<ast::TypeConstructorExpression>(Source{}, matrix_type, auto* tc = Construct(Source{}, matrix_type, std::move(args));
std::move(args));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1754,17 +1704,14 @@ TEST_P(MatrixConstructorTest,
ast::ExpressionList args; ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns - 1; i++) { for (uint32_t i = 1; i <= param.columns - 1; i++) {
auto* valid_vec_type = ty.vec<f32>(param.rows); auto* valid_vec_type = ty.vec<f32>(param.rows);
args.push_back(create<ast::TypeConstructorExpression>( args.push_back(Construct(Source{{12, i}}, valid_vec_type));
Source{{12, i}}, valid_vec_type, ExprList()));
} }
const size_t kInvalidLoc = 2 * (param.columns - 1); const size_t kInvalidLoc = 2 * (param.columns - 1);
auto* invalid_vec_type = ty.vec<f32>(param.rows + 1); auto* invalid_vec_type = ty.vec<f32>(param.rows + 1);
args.push_back(create<ast::TypeConstructorExpression>( args.push_back(Construct(Source{{12, kInvalidLoc}}, invalid_vec_type));
Source{{12, kInvalidLoc}}, invalid_vec_type, ExprList()));
auto* matrix_type = ty.mat<f32>(param.columns, param.rows); auto* matrix_type = ty.mat<f32>(param.columns, param.rows);
auto* tc = create<ast::TypeConstructorExpression>(Source{}, matrix_type, auto* tc = Construct(Source{}, matrix_type, std::move(args));
std::move(args));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1778,8 +1725,7 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ZeroValue_Success) {
const auto param = GetParam(); const auto param = GetParam();
auto* matrix_type = ty.mat<f32>(param.columns, param.rows); auto* matrix_type = ty.mat<f32>(param.columns, param.rows);
auto* tc = create<ast::TypeConstructorExpression>(Source{{12, 40}}, auto* tc = Construct(Source{{12, 40}}, matrix_type);
matrix_type, ExprList());
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -1793,13 +1739,11 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_WithColumns_Success) {
ast::ExpressionList args; ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns; i++) { for (uint32_t i = 1; i <= param.columns; i++) {
auto* vec_type = ty.vec<f32>(param.rows); auto* vec_type = ty.vec<f32>(param.rows);
args.push_back(create<ast::TypeConstructorExpression>( args.push_back(Construct(Source{{12, i}}, vec_type));
Source{{12, i}}, vec_type, ExprList()));
} }
auto* matrix_type = ty.mat<f32>(param.columns, param.rows); auto* matrix_type = ty.mat<f32>(param.columns, param.rows);
auto* tc = create<ast::TypeConstructorExpression>(Source{}, matrix_type, auto* tc = Construct(Source{}, matrix_type, std::move(args));
std::move(args));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -1812,13 +1756,11 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_WithElements_Success) {
ast::ExpressionList args; ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns * param.rows; i++) { for (uint32_t i = 1; i <= param.columns * param.rows; i++) {
args.push_back(create<ast::TypeConstructorExpression>( args.push_back(Construct(Source{{12, i}}, ty.f32()));
Source{{12, i}}, ty.f32(), ExprList()));
} }
auto* matrix_type = ty.mat<f32>(param.columns, param.rows); auto* matrix_type = ty.mat<f32>(param.columns, param.rows);
auto* tc = create<ast::TypeConstructorExpression>(Source{}, matrix_type, auto* tc = Construct(Source{}, matrix_type, std::move(args));
std::move(args));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -1833,13 +1775,11 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ElementTypeAlias_Error) {
ast::ExpressionList args; ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns; i++) { for (uint32_t i = 1; i <= param.columns; i++) {
auto* vec_type = ty.vec(ty.u32(), param.rows); auto* vec_type = ty.vec(ty.u32(), param.rows);
args.push_back(create<ast::TypeConstructorExpression>( args.push_back(Construct(Source{{12, i}}, vec_type));
Source{{12, i}}, vec_type, ExprList()));
} }
auto* matrix_type = ty.mat(ty.Of(f32_alias), param.columns, param.rows); auto* matrix_type = ty.mat(ty.Of(f32_alias), param.columns, param.rows);
auto* tc = create<ast::TypeConstructorExpression>(Source{}, matrix_type, auto* tc = Construct(Source{}, matrix_type, std::move(args));
std::move(args));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1857,13 +1797,11 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ElementTypeAlias_Success) {
ast::ExpressionList args; ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns; i++) { for (uint32_t i = 1; i <= param.columns; i++) {
auto* vec_type = ty.vec<f32>(param.rows); auto* vec_type = ty.vec<f32>(param.rows);
args.push_back(create<ast::TypeConstructorExpression>( args.push_back(Construct(Source{{12, i}}, vec_type));
Source{{12, i}}, vec_type, ExprList()));
} }
auto* matrix_type = ty.mat(ty.Of(f32_alias), param.columns, param.rows); auto* matrix_type = ty.mat(ty.Of(f32_alias), param.columns, param.rows);
auto* tc = create<ast::TypeConstructorExpression>(Source{}, matrix_type, auto* tc = Construct(Source{}, matrix_type, std::move(args));
std::move(args));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -1872,9 +1810,8 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ElementTypeAlias_Success) {
TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest,
Expr_MatrixConstructor_ArgumentTypeAlias_Error) { Expr_MatrixConstructor_ArgumentTypeAlias_Error) {
auto* alias = Alias("VectorUnsigned2", ty.vec2<u32>()); auto* alias = Alias("VectorUnsigned2", ty.vec2<u32>());
auto* tc = mat2x2<f32>(create<ast::TypeConstructorExpression>( auto* tc =
Source{{12, 34}}, ty.Of(alias), ExprList()), mat2x2<f32>(Construct(Source{{12, 34}}, ty.Of(alias)), vec2<f32>());
vec2<f32>());
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1896,12 +1833,10 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ArgumentTypeAlias_Success) {
ast::ExpressionList args; ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns; i++) { for (uint32_t i = 1; i <= param.columns; i++) {
args.push_back(create<ast::TypeConstructorExpression>( args.push_back(Construct(Source{{12, i}}, ty.Of(vec_alias)));
Source{{12, i}}, ty.Of(vec_alias), ExprList()));
} }
auto* tc = create<ast::TypeConstructorExpression>(Source{}, matrix_type, auto* tc = Construct(Source{}, matrix_type, std::move(args));
std::move(args));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -1915,12 +1850,10 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ArgumentElementTypeAlias_Error) {
ast::ExpressionList args; ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns; i++) { for (uint32_t i = 1; i <= param.columns; i++) {
auto* vec_type = ty.vec(ty.Of(f32_alias), param.rows); auto* vec_type = ty.vec(ty.Of(f32_alias), param.rows);
args.push_back(create<ast::TypeConstructorExpression>( args.push_back(Construct(Source{{12, i}}, vec_type));
Source{{12, i}}, vec_type, ExprList()));
} }
auto* tc = create<ast::TypeConstructorExpression>(Source{}, matrix_type, auto* tc = Construct(Source{}, matrix_type, std::move(args));
std::move(args));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1937,13 +1870,11 @@ TEST_P(MatrixConstructorTest,
ast::ExpressionList args; ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns; i++) { for (uint32_t i = 1; i <= param.columns; i++) {
auto* vec_type = ty.vec(ty.Of(f32_alias), param.rows); auto* vec_type = ty.vec(ty.Of(f32_alias), param.rows);
args.push_back(create<ast::TypeConstructorExpression>( args.push_back(Construct(Source{{12, i}}, vec_type));
Source{{12, i}}, vec_type, ExprList()));
} }
auto* matrix_type = ty.mat<f32>(param.columns, param.rows); auto* matrix_type = ty.mat<f32>(param.columns, param.rows);
auto* tc = create<ast::TypeConstructorExpression>(Source{}, matrix_type, auto* tc = Construct(Source{}, matrix_type, std::move(args));
std::move(args));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -2010,8 +1941,7 @@ TEST_P(StructConstructorInputsTest, TooFew) {
} }
} }
auto* s = Structure("s", members); auto* s = Structure("s", members);
auto* tc = create<ast::TypeConstructorExpression>(Source{{12, 34}}, ty.Of(s), auto* tc = Construct(Source{{12, 34}}, ty.Of(s), values);
values);
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -2035,8 +1965,7 @@ TEST_P(StructConstructorInputsTest, TooMany) {
values.push_back(ctor_value_expr); values.push_back(ctor_value_expr);
} }
auto* s = Structure("s", members); auto* s = Structure("s", members);
auto* tc = create<ast::TypeConstructorExpression>(Source{{12, 34}}, ty.Of(s), auto* tc = Construct(Source{{12, 34}}, ty.Of(s), values);
values);
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -2075,7 +2004,7 @@ TEST_P(StructConstructorTypeTest, AllTypes) {
values.push_back(ctor_value_expr); values.push_back(ctor_value_expr);
} }
auto* s = Structure("s", members); auto* s = Structure("s", members);
auto* tc = create<ast::TypeConstructorExpression>(ty.Of(s), values); auto* tc = Construct(ty.Of(s), values);
WrapInFunction(tc); WrapInFunction(tc);
std::string found = FriendlyName(ctor_params.ast(*this)); std::string found = FriendlyName(ctor_params.ast(*this));
@ -2102,8 +2031,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Struct_Nested) {
auto* m2 = Member("m2", ty.i32()); auto* m2 = Member("m2", ty.i32());
auto* s = Structure("s", {m0, m1, m2}); auto* s = Structure("s", {m0, m1, m2});
auto* tc = create<ast::TypeConstructorExpression>(Source{{12, 34}}, ty.Of(s), auto* tc = Construct(Source{{12, 34}}, ty.Of(s), 1, 1, 1);
ExprList(1, 1, 1));
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -2114,8 +2042,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Struct_Nested) {
TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Struct) { TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Struct) {
auto* m = Member("m", ty.i32()); auto* m = Member("m", ty.i32());
auto* s = Structure("MyInputs", {m}); auto* s = Structure("MyInputs", {m});
auto* tc = create<ast::TypeConstructorExpression>(Source{{12, 34}}, ty.Of(s), auto* tc = Construct(Source{{12, 34}}, ty.Of(s));
ExprList());
WrapInFunction(tc); WrapInFunction(tc);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }

View File

@ -1035,9 +1035,9 @@ TEST_F(ResolverValidationTest, OffsetAndAlignAndSizeDecoration) {
TEST_F(ResolverTest, Expr_Constructor_Cast_Pointer) { TEST_F(ResolverTest, Expr_Constructor_Cast_Pointer) {
auto* vf = Var("vf", ty.f32()); auto* vf = Var("vf", ty.f32());
auto* c = create<ast::TypeConstructorExpression>( auto* c =
Source{{12, 34}}, ty.pointer<i32>(ast::StorageClass::kFunction), Construct(Source{{12, 34}}, ty.pointer<i32>(ast::StorageClass::kFunction),
ExprList(vf)); ExprList(vf));
auto* ip = Const("ip", ty.pointer<i32>(ast::StorageClass::kFunction), c); auto* ip = Const("ip", ty.pointer<i32>(ast::StorageClass::kFunction), c);
WrapInFunction(Decl(vf), Decl(ip)); WrapInFunction(Decl(vf), Decl(ip));

View File

@ -522,11 +522,11 @@ struct DecomposeMemoryAccess::State {
values.emplace_back(b.Call(load, "buffer", offset)); values.emplace_back(b.Call(load, "buffer", offset));
} }
} }
b.Func(name, params, CreateASTTypeFor(ctx, el_ty), b.Func(
{ name, params, CreateASTTypeFor(ctx, el_ty),
b.Return(b.create<ast::TypeConstructorExpression>( {
CreateASTTypeFor(ctx, el_ty), values)), b.Return(b.Construct(CreateASTTypeFor(ctx, el_ty), values)),
}); });
} }
return name; return name;
}); });

View File

@ -715,7 +715,7 @@ struct State {
LoadPrimitive(array_base, primitive_offset, buffer, base_format)); LoadPrimitive(array_base, primitive_offset, buffer, base_format));
} }
return ctx.dst->create<ast::TypeConstructorExpression>( return ctx.dst->Construct(
ctx.dst->create<ast::Vector>(base_type, count), std::move(expr_list)); ctx.dst->create<ast::Vector>(base_type, count), std::move(expr_list));
} }