tint: ProgramBuilder: Rename Const() to Let()

These methods produce `let` declarations.
With creation-time expressions, we'll need to add `const` declarations.

Note that module-scope `let` declarations have been removed in the spec (for `const`). ProgramBuilder::GlobalConst() has not been renamed, although it still currently produces 'let' declarations.

Bug: tint:1504
Change-Id: I34f6d62236f0572163fc9c2d8fddfe4503817422
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/88305
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2022-04-28 14:35:04 +00:00 committed by Dawn LUCI CQ
parent 3e9077d04e
commit e85fe161cd
60 changed files with 502 additions and 518 deletions

View File

@ -1166,9 +1166,9 @@ TEST_F(InspectorGetStorageSizeTest, Simple_NonStruct) {
AddStorageBuffer("rosb_var", ty.i32(), ast::Access::kRead, 1, 1); AddStorageBuffer("rosb_var", ty.i32(), ast::Access::kRead, 1, 1);
Func("ep_func", {}, ty.void_(), Func("ep_func", {}, ty.void_(),
{ {
Decl(Const("ub", nullptr, Expr("ub_var"))), Decl(Let("ub", nullptr, Expr("ub_var"))),
Decl(Const("sb", nullptr, Expr("sb_var"))), Decl(Let("sb", nullptr, Expr("sb_var"))),
Decl(Const("rosb", nullptr, Expr("rosb_var"))), Decl(Let("rosb", nullptr, Expr("rosb_var"))),
}, },
{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)}); {Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)});
@ -1206,7 +1206,7 @@ TEST_F(InspectorGetStorageSizeTest, NonStructVec3) {
AddUniformBuffer("ub_var", ty.vec3<f32>(), 0, 0); AddUniformBuffer("ub_var", ty.vec3<f32>(), 0, 0);
Func("ep_func", {}, ty.void_(), Func("ep_func", {}, ty.void_(),
{ {
Decl(Const("ub", nullptr, Expr("ub_var"))), Decl(Let("ub", nullptr, Expr("ub_var"))),
}, },
{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)}); {Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)});
@ -1220,7 +1220,7 @@ TEST_F(InspectorGetStorageSizeTest, StructVec3) {
AddUniformBuffer("ub_var", ty.Of(ub_struct_type), 0, 0); AddUniformBuffer("ub_var", ty.Of(ub_struct_type), 0, 0);
Func("ep_func", {}, ty.void_(), Func("ep_func", {}, ty.void_(),
{ {
Decl(Const("ub", nullptr, Expr("ub_var"))), Decl(Let("ub", nullptr, Expr("ub_var"))),
}, },
{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)}); {Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)});

View File

@ -115,7 +115,7 @@ ProgramBuilder::TypesBuilder::TypesBuilder(ProgramBuilder* pb) : builder(pb) {}
const ast::Statement* ProgramBuilder::WrapInStatement( const ast::Statement* ProgramBuilder::WrapInStatement(
const ast::Expression* expr) { const ast::Expression* expr) {
// Create a temporary variable of inferred type from expr. // Create a temporary variable of inferred type from expr.
return Decl(Const(symbols_.New(), nullptr, expr)); return Decl(Let(symbols_.New(), nullptr, expr));
} }
const ast::VariableDeclStatement* ProgramBuilder::WrapInStatement( const ast::VariableDeclStatement* ProgramBuilder::WrapInStatement(

View File

@ -1368,12 +1368,12 @@ class ProgramBuilder {
/// @param type the variable type /// @param type the variable type
/// @param constructor constructor expression /// @param constructor constructor expression
/// @param attributes optional variable attributes /// @param attributes optional variable attributes
/// @returns a constant `ast::Variable` with the given name and type /// @returns an immutable `ast::Variable` with the given name and type
template <typename NAME> template <typename NAME>
const ast::Variable* Const(NAME&& name, const ast::Variable* Let(NAME&& name,
const ast::Type* type, const ast::Type* type,
const ast::Expression* constructor, const ast::Expression* constructor,
ast::AttributeList attributes = {}) { ast::AttributeList attributes = {}) {
return create<ast::Variable>( return create<ast::Variable>(
Sym(std::forward<NAME>(name)), ast::StorageClass::kNone, Sym(std::forward<NAME>(name)), ast::StorageClass::kNone,
ast::Access::kUndefined, type, true /* is_const */, ast::Access::kUndefined, type, true /* is_const */,
@ -1385,13 +1385,13 @@ class ProgramBuilder {
/// @param type the variable type /// @param type the variable type
/// @param constructor constructor expression /// @param constructor constructor expression
/// @param attributes optional variable attributes /// @param attributes optional variable attributes
/// @returns a constant `ast::Variable` with the given name and type /// @returns an immutable `ast::Variable` with the given name and type
template <typename NAME> template <typename NAME>
const ast::Variable* Const(const Source& source, const ast::Variable* Let(const Source& source,
NAME&& name, NAME&& name,
const ast::Type* type, const ast::Type* type,
const ast::Expression* constructor, const ast::Expression* constructor,
ast::AttributeList attributes = {}) { ast::AttributeList attributes = {}) {
return create<ast::Variable>( return create<ast::Variable>(
source, Sym(std::forward<NAME>(name)), ast::StorageClass::kNone, source, Sym(std::forward<NAME>(name)), ast::StorageClass::kNone,
ast::Access::kUndefined, type, true /* is_const */, ast::Access::kUndefined, type, true /* is_const */,
@ -1401,7 +1401,7 @@ class ProgramBuilder {
/// @param name the parameter name /// @param name the parameter name
/// @param type the parameter type /// @param type the parameter type
/// @param attributes optional parameter attributes /// @param attributes optional parameter attributes
/// @returns a constant `ast::Variable` with the given name and type /// @returns an immutable `ast::Variable` with the given name and type
template <typename NAME> template <typename NAME>
const ast::Variable* Param(NAME&& name, const ast::Variable* Param(NAME&& name,
const ast::Type* type, const ast::Type* type,
@ -1416,7 +1416,7 @@ class ProgramBuilder {
/// @param name the parameter name /// @param name the parameter name
/// @param type the parameter type /// @param type the parameter type
/// @param attributes optional parameter attributes /// @param attributes optional parameter attributes
/// @returns a constant `ast::Variable` with the given name and type /// @returns an immutable `ast::Variable` with the given name and type
template <typename NAME> template <typename NAME>
const ast::Variable* Param(const Source& source, const ast::Variable* Param(const Source& source,
NAME&& name, NAME&& name,
@ -1488,8 +1488,8 @@ class ProgramBuilder {
const ast::Type* type, const ast::Type* type,
const ast::Expression* constructor, const ast::Expression* constructor,
ast::AttributeList attributes = {}) { ast::AttributeList attributes = {}) {
auto* var = Const(std::forward<NAME>(name), type, constructor, auto* var =
std::move(attributes)); Let(std::forward<NAME>(name), type, constructor, std::move(attributes));
AST().AddGlobalVariable(var); AST().AddGlobalVariable(var);
return var; return var;
} }
@ -1508,8 +1508,8 @@ class ProgramBuilder {
const ast::Type* type, const ast::Type* type,
const ast::Expression* constructor, const ast::Expression* constructor,
ast::AttributeList attributes = {}) { ast::AttributeList attributes = {}) {
auto* var = Const(source, std::forward<NAME>(name), type, constructor, auto* var = Let(source, std::forward<NAME>(name), type, constructor,
std::move(attributes)); std::move(attributes));
AST().AddGlobalVariable(var); AST().AddGlobalVariable(var);
return var; return var;
} }

View File

@ -206,7 +206,7 @@ TEST_F(ResolverIndexAccessorTest, Array_Dynamic_I32) {
// let a : array<f32, 3> = 0; // let a : array<f32, 3> = 0;
// var idx : i32 = 0; // var idx : i32 = 0;
// var f : f32 = a[idx]; // var f : f32 = a[idx];
auto* a = Const("a", ty.array<f32, 3>(), array<f32, 3>()); auto* a = Let("a", ty.array<f32, 3>(), array<f32, 3>());
auto* idx = Var("idx", ty.i32(), Construct(ty.i32())); auto* idx = Var("idx", ty.i32(), Construct(ty.i32()));
auto* f = Var("f", ty.f32(), IndexAccessor("a", Expr(Source{{12, 34}}, idx))); auto* f = Var("f", ty.f32(), IndexAccessor("a", Expr(Source{{12, 34}}, idx)));
Func("my_func", ast::VariableList{}, ty.void_(), Func("my_func", ast::VariableList{}, ty.void_(),
@ -224,7 +224,7 @@ TEST_F(ResolverIndexAccessorTest, Array_Dynamic_I32) {
TEST_F(ResolverIndexAccessorTest, Array_Literal_F32) { TEST_F(ResolverIndexAccessorTest, Array_Literal_F32) {
// let a : array<f32, 3>; // let a : array<f32, 3>;
// var f : f32 = a[2.0f]; // var f : f32 = a[2.0f];
auto* a = Const("a", ty.array<f32, 3>(), array<f32, 3>()); auto* a = Let("a", ty.array<f32, 3>(), array<f32, 3>());
auto* f = auto* f =
Var("a_2", ty.f32(), IndexAccessor("a", Expr(Source{{12, 34}}, 2.0f))); Var("a_2", ty.f32(), IndexAccessor("a", Expr(Source{{12, 34}}, 2.0f)));
Func("my_func", ast::VariableList{}, ty.void_(), Func("my_func", ast::VariableList{}, ty.void_(),
@ -241,7 +241,7 @@ TEST_F(ResolverIndexAccessorTest, Array_Literal_F32) {
TEST_F(ResolverIndexAccessorTest, Array_Literal_I32) { TEST_F(ResolverIndexAccessorTest, Array_Literal_I32) {
// let a : array<f32, 3>; // let a : array<f32, 3>;
// var f : f32 = a[2]; // var f : f32 = a[2];
auto* a = Const("a", ty.array<f32, 3>(), array<f32, 3>()); auto* a = Let("a", ty.array<f32, 3>(), array<f32, 3>());
auto* f = Var("a_2", ty.f32(), IndexAccessor("a", 2)); auto* f = Var("a_2", ty.f32(), IndexAccessor("a", 2));
Func("my_func", ast::VariableList{}, ty.void_(), Func("my_func", ast::VariableList{}, ty.void_(),
{ {
@ -260,7 +260,7 @@ TEST_F(ResolverIndexAccessorTest, EXpr_Deref_FuncGoodParent) {
// } // }
auto* p = auto* p =
Param("p", ty.pointer(ty.vec4<f32>(), ast::StorageClass::kFunction)); Param("p", ty.pointer(ty.vec4<f32>(), ast::StorageClass::kFunction));
auto* idx = Const("idx", ty.u32(), Construct(ty.u32())); auto* idx = Let("idx", ty.u32(), Construct(ty.u32()));
auto* star_p = Deref(p); auto* star_p = Deref(p);
auto* accessor_expr = IndexAccessor(Source{{12, 34}}, star_p, idx); auto* accessor_expr = IndexAccessor(Source{{12, 34}}, star_p, idx);
auto* x = Var("x", ty.f32(), accessor_expr); auto* x = Var("x", ty.f32(), accessor_expr);
@ -277,7 +277,7 @@ TEST_F(ResolverIndexAccessorTest, EXpr_Deref_FuncBadParent) {
// } // }
auto* p = auto* p =
Param("p", ty.pointer(ty.vec4<f32>(), ast::StorageClass::kFunction)); Param("p", ty.pointer(ty.vec4<f32>(), ast::StorageClass::kFunction));
auto* idx = Const("idx", ty.u32(), Construct(ty.u32())); auto* idx = Let("idx", ty.u32(), Construct(ty.u32()));
auto* accessor_expr = IndexAccessor(Source{{12, 34}}, p, idx); auto* accessor_expr = IndexAccessor(Source{{12, 34}}, p, idx);
auto* star_p = Deref(accessor_expr); auto* star_p = Deref(accessor_expr);
auto* x = Var("x", ty.f32(), star_p); auto* x = Var("x", ty.f32(), star_p);

View File

@ -198,7 +198,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignThroughPointer_Pass) {
// *b = 2; // *b = 2;
const auto func = ast::StorageClass::kFunction; const auto func = ast::StorageClass::kFunction;
auto* var_a = Var("a", ty.i32(), func, Expr(2)); auto* var_a = Var("a", ty.i32(), func, Expr(2));
auto* var_b = Const("b", ty.pointer<int>(func), AddressOf(Expr("a"))); auto* var_b = Let("b", ty.pointer<int>(func), AddressOf(Expr("a")));
WrapInFunction(var_a, var_b, Assign(Source{{12, 34}}, Deref("b"), 2)); WrapInFunction(var_a, var_b, Assign(Source{{12, 34}}, Deref("b"), 2));
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -209,7 +209,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignToConstant_Fail) {
// let a : i32 = 2; // let a : i32 = 2;
// a = 2 // a = 2
// } // }
auto* var = Const("a", ty.i32(), Expr(2)); auto* var = Let("a", ty.i32(), Expr(2));
WrapInFunction(var, Assign(Expr(Source{{12, 34}}, "a"), 2)); WrapInFunction(var, Assign(Expr(Source{{12, 34}}, "a"), 2));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());

View File

@ -117,7 +117,7 @@ TEST_P(ResolverBitcastValidationTestInvalidSrcTy, Test) {
auto dst = std::get<1>(GetParam()); auto dst = std::get<1>(GetParam());
auto* cast = Bitcast(dst.ast(*this), Expr(Source{{12, 34}}, "src")); auto* cast = Bitcast(dst.ast(*this), Expr(Source{{12, 34}}, "src"));
WrapInFunction(Const("src", nullptr, src.expr(*this, 0)), cast); WrapInFunction(Let("src", nullptr, src.expr(*this, 0)), cast);
auto expected = "12:34 error: '" + src.sem(*this)->FriendlyName(Symbols()) + auto expected = "12:34 error: '" + src.sem(*this)->FriendlyName(Symbols()) +
"' cannot be bitcast"; "' cannot be bitcast";

View File

@ -101,7 +101,7 @@ TEST_F(ResolverCallValidationTest, PointerArgument_ConstIdentExpr) {
Func("foo", {param}, ty.void_(), {}); Func("foo", {param}, ty.void_(), {});
Func("main", {}, ty.void_(), Func("main", {}, ty.void_(),
{ {
Decl(Const("z", ty.i32(), Expr(1))), Decl(Let("z", ty.i32(), Expr(1))),
CallStmt(Call("foo", AddressOf(Expr(Source{{12, 34}}, "z")))), CallStmt(Call("foo", AddressOf(Expr(Source{{12, 34}}, "z")))),
}); });
@ -144,7 +144,7 @@ TEST_F(ResolverCallValidationTest, PointerArgument_AddressOfMemberAccessor) {
Func("foo", {param}, ty.void_(), {}); Func("foo", {param}, ty.void_(), {});
Func("main", {}, ty.void_(), Func("main", {}, ty.void_(),
{ {
Decl(Const("v", ty.Of(S), Construct(ty.Of(S)))), Decl(Let("v", ty.Of(S), Construct(ty.Of(S)))),
CallStmt(Call("foo", AddressOf(Expr(Source{{12, 34}}, CallStmt(Call("foo", AddressOf(Expr(Source{{12, 34}},
MemberAccessor("v", "m"))))), MemberAccessor("v", "m"))))),
}); });
@ -203,8 +203,8 @@ TEST_F(ResolverCallValidationTest, LetPointer) {
Func("x", {Param("p", ty.pointer<i32>(ast::StorageClass::kFunction))}, Func("x", {Param("p", ty.pointer<i32>(ast::StorageClass::kFunction))},
ty.void_(), {}); ty.void_(), {});
auto* v = Var("v", ty.i32()); auto* v = Var("v", ty.i32());
auto* p = Const("p", ty.pointer(ty.i32(), ast::StorageClass::kFunction), auto* p = Let("p", ty.pointer(ty.i32(), ast::StorageClass::kFunction),
AddressOf(v)); AddressOf(v));
auto* c = Var("c", ty.i32(), ast::StorageClass::kNone, auto* c = Var("c", ty.i32(), ast::StorageClass::kNone,
Call("x", Expr(Source{{12, 34}}, p))); Call("x", Expr(Source{{12, 34}}, p)));
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),
@ -233,8 +233,8 @@ TEST_F(ResolverCallValidationTest, LetPointerPrivate) {
Func("foo", {Param("p", ty.pointer<i32>(ast::StorageClass::kPrivate))}, Func("foo", {Param("p", ty.pointer<i32>(ast::StorageClass::kPrivate))},
ty.void_(), {}); ty.void_(), {});
auto* v = Global("v", ty.i32(), ast::StorageClass::kPrivate); auto* v = Global("v", ty.i32(), ast::StorageClass::kPrivate);
auto* p = Const("p", ty.pointer(ty.i32(), ast::StorageClass::kPrivate), auto* p =
AddressOf(v)); Let("p", ty.pointer(ty.i32(), ast::StorageClass::kPrivate), AddressOf(v));
auto* c = Var("c", ty.i32(), ast::StorageClass::kNone, auto* c = Var("c", ty.i32(), ast::StorageClass::kNone,
Call("foo", Expr(Source{{12, 34}}, p))); Call("foo", Expr(Source{{12, 34}}, p)));
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),

View File

@ -52,7 +52,7 @@ TEST_F(ResolverCompoundAssignmentValidationTest,
// *b += 2; // *b += 2;
const auto func = ast::StorageClass::kFunction; const auto func = ast::StorageClass::kFunction;
auto* var_a = Var("a", ty.i32(), func, Expr(2)); auto* var_a = Var("a", ty.i32(), func, Expr(2));
auto* var_b = Const("b", ty.pointer<int>(func), AddressOf(Expr("a"))); auto* var_b = Let("b", ty.pointer<int>(func), AddressOf(Expr("a")));
WrapInFunction( WrapInFunction(
var_a, var_b, var_a, var_b,
CompoundAssign(Source{{12, 34}}, Deref("b"), 2, ast::BinaryOp::kAdd)); CompoundAssign(Source{{12, 34}}, Deref("b"), 2, ast::BinaryOp::kAdd));
@ -262,7 +262,7 @@ TEST_F(ResolverCompoundAssignmentValidationTest, ReadOnlyBuffer) {
TEST_F(ResolverCompoundAssignmentValidationTest, LhsConstant) { TEST_F(ResolverCompoundAssignmentValidationTest, LhsConstant) {
// let a = 1; // let a = 1;
// a += 1; // a += 1;
auto* a = Const(Source{{12, 34}}, "a", nullptr, Expr(1)); auto* a = Let(Source{{12, 34}}, "a", nullptr, Expr(1));
WrapInFunction( WrapInFunction(
a, CompoundAssign(Expr(Source{{56, 78}}, "a"), 1, ast::BinaryOp::kAdd)); a, CompoundAssign(Expr(Source{{56, 78}}, "a"), 1, ast::BinaryOp::kAdd));

View File

@ -53,7 +53,7 @@ using ResolverDependencyGraphTest =
/// kinds of symbol declarations. /// kinds of symbol declarations.
enum class SymbolDeclKind { enum class SymbolDeclKind {
GlobalVar, GlobalVar,
GlobalLet, GlobalConst,
Alias, Alias,
Struct, Struct,
Function, Function,
@ -65,7 +65,7 @@ enum class SymbolDeclKind {
}; };
static constexpr SymbolDeclKind kAllSymbolDeclKinds[] = { static constexpr SymbolDeclKind kAllSymbolDeclKinds[] = {
SymbolDeclKind::GlobalVar, SymbolDeclKind::GlobalLet, SymbolDeclKind::GlobalVar, SymbolDeclKind::GlobalConst,
SymbolDeclKind::Alias, SymbolDeclKind::Struct, SymbolDeclKind::Alias, SymbolDeclKind::Struct,
SymbolDeclKind::Function, SymbolDeclKind::Parameter, SymbolDeclKind::Function, SymbolDeclKind::Parameter,
SymbolDeclKind::LocalVar, SymbolDeclKind::LocalLet, SymbolDeclKind::LocalVar, SymbolDeclKind::LocalLet,
@ -78,15 +78,16 @@ static constexpr SymbolDeclKind kTypeDeclKinds[] = {
}; };
static constexpr SymbolDeclKind kValueDeclKinds[] = { static constexpr SymbolDeclKind kValueDeclKinds[] = {
SymbolDeclKind::GlobalVar, SymbolDeclKind::GlobalLet, SymbolDeclKind::GlobalVar, SymbolDeclKind::GlobalConst,
SymbolDeclKind::Parameter, SymbolDeclKind::LocalVar, SymbolDeclKind::Parameter, SymbolDeclKind::LocalVar,
SymbolDeclKind::LocalLet, SymbolDeclKind::NestedLocalVar, SymbolDeclKind::LocalLet, SymbolDeclKind::NestedLocalVar,
SymbolDeclKind::NestedLocalLet, SymbolDeclKind::NestedLocalLet,
}; };
static constexpr SymbolDeclKind kGlobalDeclKinds[] = { static constexpr SymbolDeclKind kGlobalDeclKinds[] = {
SymbolDeclKind::GlobalVar, SymbolDeclKind::GlobalLet, SymbolDeclKind::Alias, SymbolDeclKind::GlobalVar, SymbolDeclKind::GlobalConst,
SymbolDeclKind::Struct, SymbolDeclKind::Function, SymbolDeclKind::Alias, SymbolDeclKind::Struct,
SymbolDeclKind::Function,
}; };
static constexpr SymbolDeclKind kLocalDeclKinds[] = { static constexpr SymbolDeclKind kLocalDeclKinds[] = {
@ -97,7 +98,7 @@ static constexpr SymbolDeclKind kLocalDeclKinds[] = {
static constexpr SymbolDeclKind kGlobalValueDeclKinds[] = { static constexpr SymbolDeclKind kGlobalValueDeclKinds[] = {
SymbolDeclKind::GlobalVar, SymbolDeclKind::GlobalVar,
SymbolDeclKind::GlobalLet, SymbolDeclKind::GlobalConst,
}; };
static constexpr SymbolDeclKind kFuncDeclKinds[] = { static constexpr SymbolDeclKind kFuncDeclKinds[] = {
@ -183,7 +184,7 @@ std::ostream& operator<<(std::ostream& out, SymbolDeclKind kind) {
switch (kind) { switch (kind) {
case SymbolDeclKind::GlobalVar: case SymbolDeclKind::GlobalVar:
return out << "global var"; return out << "global var";
case SymbolDeclKind::GlobalLet: case SymbolDeclKind::GlobalConst:
return out << "global let"; return out << "global let";
case SymbolDeclKind::Alias: case SymbolDeclKind::Alias:
return out << "alias"; return out << "alias";
@ -322,7 +323,7 @@ std::string DiagString(SymbolUseKind kind) {
int ScopeDepth(SymbolDeclKind kind) { int ScopeDepth(SymbolDeclKind kind) {
switch (kind) { switch (kind) {
case SymbolDeclKind::GlobalVar: case SymbolDeclKind::GlobalVar:
case SymbolDeclKind::GlobalLet: case SymbolDeclKind::GlobalConst:
case SymbolDeclKind::Alias: case SymbolDeclKind::Alias:
case SymbolDeclKind::Struct: case SymbolDeclKind::Struct:
case SymbolDeclKind::Function: case SymbolDeclKind::Function:
@ -430,7 +431,7 @@ const ast::Node* SymbolTestHelper::Add(SymbolDeclKind kind,
switch (kind) { switch (kind) {
case SymbolDeclKind::GlobalVar: case SymbolDeclKind::GlobalVar:
return b.Global(source, symbol, b.ty.i32(), ast::StorageClass::kPrivate); return b.Global(source, symbol, b.ty.i32(), ast::StorageClass::kPrivate);
case SymbolDeclKind::GlobalLet: case SymbolDeclKind::GlobalConst:
return b.GlobalConst(source, symbol, b.ty.i32(), b.Expr(1)); return b.GlobalConst(source, symbol, b.ty.i32(), b.Expr(1));
case SymbolDeclKind::Alias: case SymbolDeclKind::Alias:
return b.Alias(source, symbol, b.ty.i32()); return b.Alias(source, symbol, b.ty.i32());
@ -449,7 +450,7 @@ const ast::Node* SymbolTestHelper::Add(SymbolDeclKind kind,
return node; return node;
} }
case SymbolDeclKind::LocalLet: { case SymbolDeclKind::LocalLet: {
auto* node = b.Const(source, symbol, b.ty.i32(), b.Expr(1)); auto* node = b.Let(source, symbol, b.ty.i32(), b.Expr(1));
statements.emplace_back(b.Decl(node)); statements.emplace_back(b.Decl(node));
return node; return node;
} }
@ -459,7 +460,7 @@ const ast::Node* SymbolTestHelper::Add(SymbolDeclKind kind,
return node; return node;
} }
case SymbolDeclKind::NestedLocalLet: { case SymbolDeclKind::NestedLocalLet: {
auto* node = b.Const(source, symbol, b.ty.i32(), b.Expr(1)); auto* node = b.Let(source, symbol, b.ty.i32(), b.Expr(1));
nested_statements.emplace_back(b.Decl(node)); nested_statements.emplace_back(b.Decl(node));
return node; return node;
} }
@ -598,12 +599,12 @@ const ast::Node* SymbolTestHelper::Add(SymbolUseKind kind,
} }
case SymbolUseKind::LocalLetType: { case SymbolUseKind::LocalLetType: {
auto* node = b.ty.type_name(source, symbol); auto* node = b.ty.type_name(source, symbol);
statements.emplace_back(b.Decl(b.Const(b.Sym(), node, b.Expr(1)))); statements.emplace_back(b.Decl(b.Let(b.Sym(), node, b.Expr(1))));
return node; return node;
} }
case SymbolUseKind::LocalLetValue: { case SymbolUseKind::LocalLetValue: {
auto* node = b.Expr(source, symbol); auto* node = b.Expr(source, symbol);
statements.emplace_back(b.Decl(b.Const(b.Sym(), b.ty.i32(), node))); statements.emplace_back(b.Decl(b.Let(b.Sym(), b.ty.i32(), node)));
return node; return node;
} }
case SymbolUseKind::NestedLocalVarType: { case SymbolUseKind::NestedLocalVarType: {
@ -618,13 +619,12 @@ const ast::Node* SymbolTestHelper::Add(SymbolUseKind kind,
} }
case SymbolUseKind::NestedLocalLetType: { case SymbolUseKind::NestedLocalLetType: {
auto* node = b.ty.type_name(source, symbol); auto* node = b.ty.type_name(source, symbol);
nested_statements.emplace_back(b.Decl(b.Const(b.Sym(), node, b.Expr(1)))); nested_statements.emplace_back(b.Decl(b.Let(b.Sym(), node, b.Expr(1))));
return node; return node;
} }
case SymbolUseKind::NestedLocalLetValue: { case SymbolUseKind::NestedLocalLetValue: {
auto* node = b.Expr(source, symbol); auto* node = b.Expr(source, symbol);
nested_statements.emplace_back( nested_statements.emplace_back(b.Decl(b.Let(b.Sym(), b.ty.i32(), node)));
b.Decl(b.Const(b.Sym(), b.ty.i32(), node)));
return node; return node;
} }
case SymbolUseKind::WorkgroupSizeValue: { case SymbolUseKind::WorkgroupSizeValue: {
@ -788,7 +788,7 @@ TEST_F(ResolverDependencyGraphDeclSelfUse, GlobalVar) {
12:34 note: var 'SYMBOL' references var 'SYMBOL' here)"); 12:34 note: var 'SYMBOL' references var 'SYMBOL' here)");
} }
TEST_F(ResolverDependencyGraphDeclSelfUse, GlobalLet) { TEST_F(ResolverDependencyGraphDeclSelfUse, GlobalConst) {
const Symbol symbol = Sym("SYMBOL"); const Symbol symbol = Sym("SYMBOL");
GlobalConst(symbol, ty.i32(), Mul(Expr(Source{{12, 34}}, symbol), 123)); GlobalConst(symbol, ty.i32(), Mul(Expr(Source{{12, 34}}, symbol), 123));
Build(R"(error: cyclic dependency found: 'SYMBOL' -> 'SYMBOL' Build(R"(error: cyclic dependency found: 'SYMBOL' -> 'SYMBOL'
@ -805,7 +805,7 @@ TEST_F(ResolverDependencyGraphDeclSelfUse, LocalVar) {
TEST_F(ResolverDependencyGraphDeclSelfUse, LocalLet) { TEST_F(ResolverDependencyGraphDeclSelfUse, LocalLet) {
const Symbol symbol = Sym("SYMBOL"); const Symbol symbol = Sym("SYMBOL");
WrapInFunction( WrapInFunction(
Decl(Const(symbol, ty.i32(), Mul(Expr(Source{{12, 34}}, symbol), 123)))); Decl(Let(symbol, ty.i32(), Mul(Expr(Source{{12, 34}}, symbol), 123))));
Build("12:34 error: unknown identifier: 'SYMBOL'"); Build("12:34 error: unknown identifier: 'SYMBOL'");
} }
@ -1180,15 +1180,13 @@ TEST_P(ResolverDependencyShadowTest, Test) {
SymbolTestHelper helper(this); SymbolTestHelper helper(this);
auto* outer = helper.Add(outer_kind, symbol, Source{{12, 34}}); auto* outer = helper.Add(outer_kind, symbol, Source{{12, 34}});
helper.Add(inner_kind, symbol, Source{{56, 78}}); helper.Add(inner_kind, symbol, Source{{56, 78}});
auto* inner_var = helper.nested_statements.size() auto* inner_var =
? helper.nested_statements[0] helper.nested_statements.size() ? helper.nested_statements[0]
->As<ast::VariableDeclStatement>() ->As<ast::VariableDeclStatement>()
->variable ->variable
: helper.statements.size() : helper.statements.size()
? helper.statements[0] ? helper.statements[0]->As<ast::VariableDeclStatement>()->variable
->As<ast::VariableDeclStatement>() : helper.parameters[0];
->variable
: helper.parameters[0];
helper.Build(); helper.Build();
EXPECT_EQ(Build().shadows[inner_var], outer); EXPECT_EQ(Build().shadows[inner_var], outer);
@ -1255,7 +1253,7 @@ TEST_F(ResolverDependencyGraphTraversalTest, SymbolsReached) {
T, // Return type T, // Return type
{ {
Decl(Var(Sym(), T, V)), // Decl(Var(Sym(), T, V)), //
Decl(Const(Sym(), T, V)), // Decl(Let(Sym(), T, V)), //
CallStmt(Call(F, V)), // CallStmt(Call(F, V)), //
Block( // Block( //
Assign(V, V)), // Assign(V, V)), //
@ -1317,7 +1315,7 @@ TEST_F(ResolverDependencyGraphTraversalTest, InferredType) {
Global("a", nullptr, Expr(1)); Global("a", nullptr, Expr(1));
GlobalConst("b", nullptr, Expr(1)); GlobalConst("b", nullptr, Expr(1));
WrapInFunction(Var("c", nullptr, Expr(1)), // WrapInFunction(Var("c", nullptr, Expr(1)), //
Const("d", nullptr, Expr(1))); Let("d", nullptr, Expr(1)));
Build(); Build();
} }

View File

@ -49,7 +49,7 @@ TEST_F(ResolverFunctionValidationTest, LocalConflictsWithParameter) {
// let common_name = 1; // let common_name = 1;
// } // }
Func("func", {Param(Source{{12, 34}}, "common_name", ty.f32())}, ty.void_(), Func("func", {Param(Source{{12, 34}}, "common_name", ty.f32())}, ty.void_(),
{Decl(Const(Source{{56, 78}}, "common_name", nullptr, Expr(1)))}); {Decl(Let(Source{{56, 78}}, "common_name", nullptr, Expr(1)))});
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), R"(56:78 error: redeclaration of 'common_name' EXPECT_EQ(r()->error(), R"(56:78 error: redeclaration of 'common_name'
@ -63,7 +63,7 @@ TEST_F(ResolverFunctionValidationTest, NestedLocalMayShadowParameter) {
// } // }
// } // }
Func("func", {Param(Source{{12, 34}}, "common_name", ty.f32())}, ty.void_(), Func("func", {Param(Source{{12, 34}}, "common_name", ty.f32())}, ty.void_(),
{Block(Decl(Const(Source{{56, 78}}, "common_name", nullptr, Expr(1))))}); {Block(Decl(Let(Source{{56, 78}}, "common_name", nullptr, Expr(1))))});
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -419,7 +419,7 @@ TEST_F(ResolverFunctionValidationTest, FunctionConstInitWithParam) {
// } // }
auto* bar = Param("bar", ty.f32()); auto* bar = Param("bar", ty.f32());
auto* baz = Const("baz", ty.f32(), Expr("bar")); auto* baz = Let("baz", ty.f32(), Expr("bar"));
Func("foo", ast::VariableList{bar}, ty.void_(), ast::StatementList{Decl(baz)}, Func("foo", ast::VariableList{bar}, ty.void_(), ast::StatementList{Decl(baz)},
ast::AttributeList{}); ast::AttributeList{});

View File

@ -63,8 +63,8 @@ TEST_F(ResolverIncrementDecrementValidationTest, ThroughPointer) {
// let b : ptr<function,i32> = &a; // let b : ptr<function,i32> = &a;
// *b++; // *b++;
auto* var_a = Var("a", ty.i32(), ast::StorageClass::kFunction); auto* var_a = Var("a", ty.i32(), ast::StorageClass::kFunction);
auto* var_b = Const("b", ty.pointer<int>(ast::StorageClass::kFunction), auto* var_b = Let("b", ty.pointer<int>(ast::StorageClass::kFunction),
AddressOf(Expr("a"))); AddressOf(Expr("a")));
WrapInFunction(var_a, var_b, Increment(Source{{12, 34}}, Deref("b"))); WrapInFunction(var_a, var_b, Increment(Source{{12, 34}}, Deref("b")));
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -147,7 +147,7 @@ TEST_F(ResolverIncrementDecrementValidationTest, Literal) {
TEST_F(ResolverIncrementDecrementValidationTest, Constant) { TEST_F(ResolverIncrementDecrementValidationTest, Constant) {
// let a = 1; // let a = 1;
// a++; // a++;
auto* a = Const(Source{{12, 34}}, "a", nullptr, Expr(1)); auto* a = Let(Source{{12, 34}}, "a", nullptr, Expr(1));
WrapInFunction(a, Increment(Expr(Source{{56, 78}}, "a"))); WrapInFunction(a, Increment(Expr(Source{{56, 78}}, "a")));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());

View File

@ -112,7 +112,7 @@ TEST_P(ResolverInferredTypeParamTest, LocalLet_Pass) {
// let a = <type constructor>; // let a = <type constructor>;
auto* ctor_expr = params.create_value(*this, 0); auto* ctor_expr = params.create_value(*this, 0);
auto* var = Const("a", nullptr, ctor_expr); auto* var = Let("a", nullptr, ctor_expr);
WrapInFunction(var); WrapInFunction(var);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();

View File

@ -75,20 +75,20 @@ TEST_F(ResolverPtrRefTest, DefaultPtrStorageClass) {
}); });
auto* function_ptr = auto* function_ptr =
Const("f_ptr", ty.pointer(ty.i32(), ast::StorageClass::kFunction), Let("f_ptr", ty.pointer(ty.i32(), ast::StorageClass::kFunction),
AddressOf(function)); AddressOf(function));
auto* private_ptr = auto* private_ptr =
Const("p_ptr", ty.pointer(ty.i32(), ast::StorageClass::kPrivate), Let("p_ptr", ty.pointer(ty.i32(), ast::StorageClass::kPrivate),
AddressOf(private_)); AddressOf(private_));
auto* workgroup_ptr = auto* workgroup_ptr =
Const("w_ptr", ty.pointer(ty.i32(), ast::StorageClass::kWorkgroup), Let("w_ptr", ty.pointer(ty.i32(), ast::StorageClass::kWorkgroup),
AddressOf(workgroup)); AddressOf(workgroup));
auto* uniform_ptr = auto* uniform_ptr =
Const("ub_ptr", ty.pointer(ty.Of(buf), ast::StorageClass::kUniform), Let("ub_ptr", ty.pointer(ty.Of(buf), ast::StorageClass::kUniform),
AddressOf(uniform)); AddressOf(uniform));
auto* storage_ptr = auto* storage_ptr =
Const("sb_ptr", ty.pointer(ty.Of(buf), ast::StorageClass::kStorage), Let("sb_ptr", ty.pointer(ty.Of(buf), ast::StorageClass::kStorage),
AddressOf(storage)); AddressOf(storage));
WrapInFunction(function, function_ptr, private_ptr, workgroup_ptr, WrapInFunction(function, function_ptr, private_ptr, workgroup_ptr,
uniform_ptr, storage_ptr); uniform_ptr, storage_ptr);

View File

@ -40,7 +40,7 @@ TEST_F(ResolverPtrRefValidationTest, AddressOfLiteral) {
TEST_F(ResolverPtrRefValidationTest, AddressOfLet) { TEST_F(ResolverPtrRefValidationTest, AddressOfLet) {
// let l : i32 = 1; // let l : i32 = 1;
// &l // &l
auto* l = Const("l", ty.i32(), Expr(1)); auto* l = Let("l", ty.i32(), Expr(1));
auto* expr = AddressOf(Expr(Source{{12, 34}}, "l")); auto* expr = AddressOf(Expr(Source{{12, 34}}, "l"));
WrapInFunction(l, expr); WrapInFunction(l, expr);
@ -156,8 +156,8 @@ TEST_F(ResolverPtrRefValidationTest, InferredPtrAccessMismatch) {
auto* expr = auto* expr =
IndexAccessor(MemberAccessor(MemberAccessor(storage, "inner"), "arr"), 4); IndexAccessor(MemberAccessor(MemberAccessor(storage, "inner"), "arr"), 4);
auto* ptr = auto* ptr =
Const(Source{{12, 34}}, "p", ty.pointer<i32>(ast::StorageClass::kStorage), Let(Source{{12, 34}}, "p", ty.pointer<i32>(ast::StorageClass::kStorage),
AddressOf(expr)); AddressOf(expr));
WrapInFunction(ptr); WrapInFunction(ptr);

View File

@ -392,7 +392,7 @@ TEST_F(ResolverBehaviorTest, StmtIfTrue_ThenEmptyBlock_ElseCallFuncMayDiscard) {
} }
TEST_F(ResolverBehaviorTest, StmtLetDecl) { TEST_F(ResolverBehaviorTest, StmtLetDecl) {
auto* stmt = Decl(Const("v", ty.i32(), Expr(1))); auto* stmt = Decl(Let("v", ty.i32(), Expr(1)));
WrapInFunction(stmt); WrapInFunction(stmt);
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -402,7 +402,7 @@ TEST_F(ResolverBehaviorTest, StmtLetDecl) {
} }
TEST_F(ResolverBehaviorTest, StmtLetDecl_RHSDiscardOrNext) { TEST_F(ResolverBehaviorTest, StmtLetDecl_RHSDiscardOrNext) {
auto* stmt = Decl(Const("lhs", ty.i32(), Call("DiscardOrNext"))); auto* stmt = Decl(Let("lhs", ty.i32(), Call("DiscardOrNext")));
WrapInFunction(stmt); WrapInFunction(stmt);
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();

View File

@ -635,7 +635,7 @@ TEST_F(ResolverTest, Expr_Identifier_GlobalConstant) {
TEST_F(ResolverTest, Expr_Identifier_FunctionVariable_Const) { TEST_F(ResolverTest, Expr_Identifier_FunctionVariable_Const) {
auto* my_var_a = Expr("my_var"); auto* my_var_a = Expr("my_var");
auto* var = Const("my_var", ty.f32(), Construct(ty.f32())); auto* var = Let("my_var", ty.f32(), Construct(ty.f32()));
auto* decl = Decl(Var("b", ty.f32(), ast::StorageClass::kNone, my_var_a)); auto* decl = Decl(Var("b", ty.f32(), ast::StorageClass::kNone, my_var_a));
Func("my_func", ast::VariableList{}, ty.void_(), Func("my_func", ast::VariableList{}, ty.void_(),
@ -711,7 +711,7 @@ TEST_F(ResolverTest, Expr_Identifier_Function_Ptr) {
auto* p = Expr("p"); auto* p = Expr("p");
auto* v_decl = Decl(Var("v", ty.f32())); auto* v_decl = Decl(Var("v", ty.f32()));
auto* p_decl = Decl( auto* p_decl = Decl(
Const("p", ty.pointer<f32>(ast::StorageClass::kFunction), AddressOf(v))); Let("p", ty.pointer<f32>(ast::StorageClass::kFunction), AddressOf(v)));
auto* assign = Assign(Deref(p), 1.23f); auto* assign = Assign(Deref(p), 1.23f);
Func("my_func", ast::VariableList{}, ty.void_(), Func("my_func", ast::VariableList{}, ty.void_(),
{ {
@ -868,7 +868,7 @@ TEST_F(ResolverTest, Function_NotRegisterFunctionVariable) {
TEST_F(ResolverTest, Function_NotRegisterFunctionConstant) { TEST_F(ResolverTest, Function_NotRegisterFunctionConstant) {
auto* func = Func("my_func", ast::VariableList{}, ty.void_(), auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
{ {
Decl(Const("var", ty.f32(), Construct(ty.f32()))), Decl(Let("var", ty.f32(), Construct(ty.f32()))),
}); });
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -881,7 +881,7 @@ TEST_F(ResolverTest, Function_NotRegisterFunctionConstant) {
} }
TEST_F(ResolverTest, Function_NotRegisterFunctionParams) { TEST_F(ResolverTest, Function_NotRegisterFunctionParams) {
auto* func = Func("my_func", {Const("var", ty.f32(), Construct(ty.f32()))}, auto* func = Func("my_func", {Let("var", ty.f32(), Construct(ty.f32()))},
ty.void_(), {}); ty.void_(), {});
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -1782,7 +1782,7 @@ TEST_F(ResolverTest, StorageClass_SetForTexture) {
} }
TEST_F(ResolverTest, StorageClass_DoesNotSetOnConst) { TEST_F(ResolverTest, StorageClass_DoesNotSetOnConst) {
auto* var = Const("var", ty.i32(), Construct(ty.i32())); auto* var = Let("var", ty.i32(), Construct(ty.i32()));
auto* stmt = Decl(var); auto* stmt = Decl(var);
Func("func", ast::VariableList{}, ty.void_(), {stmt}, ast::AttributeList{}); Func("func", ast::VariableList{}, ty.void_(), {stmt}, ast::AttributeList{});

View File

@ -92,7 +92,7 @@ TEST_F(ResolverSourceVariableTest, GlobalOverride) {
EXPECT_EQ(Sem().Get(expr)->SourceVariable(), sem_a); EXPECT_EQ(Sem().Get(expr)->SourceVariable(), sem_a);
} }
TEST_F(ResolverSourceVariableTest, GlobalLet) { TEST_F(ResolverSourceVariableTest, GlobalConst) {
auto* a = GlobalConst("a", ty.f32(), Expr(1.f)); auto* a = GlobalConst("a", ty.f32(), Expr(1.f));
auto* expr = Expr(a); auto* expr = Expr(a);
WrapInFunction(expr); WrapInFunction(expr);
@ -115,7 +115,7 @@ TEST_F(ResolverSourceVariableTest, FunctionVar) {
} }
TEST_F(ResolverSourceVariableTest, FunctionLet) { TEST_F(ResolverSourceVariableTest, FunctionLet) {
auto* a = Const("a", ty.f32(), Expr(1.f)); auto* a = Let("a", ty.f32(), Expr(1.f));
auto* expr = Expr(a); auto* expr = Expr(a);
WrapInFunction(a, expr); WrapInFunction(a, expr);
@ -143,7 +143,7 @@ TEST_F(ResolverSourceVariableTest, PointerParameter) {
// } // }
auto* param = Param("a", ty.pointer(ty.f32(), ast::StorageClass::kFunction)); auto* param = Param("a", ty.pointer(ty.f32(), ast::StorageClass::kFunction));
auto* expr_param = Expr(param); auto* expr_param = Expr(param);
auto* let = Const("b", nullptr, expr_param); auto* let = Let("b", nullptr, expr_param);
auto* expr_let = Expr("b"); auto* expr_let = Expr("b");
Func("foo", {param}, ty.void_(), Func("foo", {param}, ty.void_(),
{WrapInStatement(let), WrapInStatement(expr_let)}); {WrapInStatement(let), WrapInStatement(expr_let)});
@ -181,7 +181,7 @@ TEST_F(ResolverSourceVariableTest, LetCopyVar) {
// } // }
auto* a = Var("a", ty.f32(), ast::StorageClass::kNone); auto* a = Var("a", ty.f32(), ast::StorageClass::kNone);
auto* expr_a = Expr(a); auto* expr_a = Expr(a);
auto* b = Const("b", ty.f32(), expr_a); auto* b = Let("b", ty.f32(), expr_a);
auto* expr_b = Expr(b); auto* expr_b = Expr(b);
WrapInFunction(a, b, expr_b); WrapInFunction(a, b, expr_b);
@ -235,10 +235,10 @@ TEST_F(ResolverSourceVariableTest, ThroughPointers) {
auto* address_of_1 = AddressOf(a); auto* address_of_1 = AddressOf(a);
auto* deref_1 = Deref(address_of_1); auto* deref_1 = Deref(address_of_1);
auto* address_of_2 = AddressOf(deref_1); auto* address_of_2 = AddressOf(deref_1);
auto* a_ptr1 = Const("a_ptr1", nullptr, address_of_2); auto* a_ptr1 = Let("a_ptr1", nullptr, address_of_2);
auto* deref_2 = Deref(a_ptr1); auto* deref_2 = Deref(a_ptr1);
auto* address_of_3 = AddressOf(deref_2); auto* address_of_3 = AddressOf(deref_2);
auto* a_ptr2 = Const("a_ptr2", nullptr, address_of_3); auto* a_ptr2 = Let("a_ptr2", nullptr, address_of_3);
WrapInFunction(a_ptr1, a_ptr2); WrapInFunction(a_ptr1, a_ptr2);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();

View File

@ -371,7 +371,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_FunctionConstant) {
// let size = 10; // let size = 10;
// var a : array<f32, size>; // var a : array<f32, size>;
// } // }
auto* size = Const("size", nullptr, Expr(10)); auto* size = Let("size", nullptr, Expr(10));
auto* a = Var("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size"))); auto* a = Var("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")));
WrapInFunction(Block(Decl(size), Decl(a))); WrapInFunction(Block(Decl(size), Decl(a)));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -382,7 +382,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_FunctionConstant) {
TEST_F(ResolverTypeValidationTest, ArraySize_InvalidExpr) { TEST_F(ResolverTypeValidationTest, ArraySize_InvalidExpr) {
// var a : array<f32, i32(4)>; // var a : array<f32, i32(4)>;
auto* size = Const("size", nullptr, Expr(10)); auto* size = Let("size", nullptr, Expr(10));
auto* a = auto* a =
Var("a", ty.array(ty.f32(), Construct(Source{{12, 34}}, ty.i32(), 4))); Var("a", ty.array(ty.f32(), Construct(Source{{12, 34}}, ty.i32(), 4)));
WrapInFunction(Block(Decl(size), Decl(a))); WrapInFunction(Block(Decl(size), Decl(a)));

View File

@ -1304,7 +1304,7 @@ TEST_F(ResolverTest, Expr_Constructor_Cast_Pointer) {
auto* c = auto* c =
Construct(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 = Let("ip", ty.pointer<i32>(ast::StorageClass::kFunction), c);
WrapInFunction(Decl(vf), Decl(ip)); WrapInFunction(Decl(vf), Decl(ip));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());

View File

@ -170,13 +170,13 @@ TEST_F(ResolverVarLetTest, LetDecl) {
auto* a_c = Construct(ty.Of(A), Expr(1)); auto* a_c = Construct(ty.Of(A), Expr(1));
auto* p_c = AddressOf(v); auto* p_c = AddressOf(v);
auto* i = Const("i", ty.i32(), i_c); auto* i = Let("i", ty.i32(), i_c);
auto* u = Const("u", ty.u32(), u_c); auto* u = Let("u", ty.u32(), u_c);
auto* f = Const("f", ty.f32(), f_c); auto* f = Let("f", ty.f32(), f_c);
auto* b = Const("b", ty.bool_(), b_c); auto* b = Let("b", ty.bool_(), b_c);
auto* s = Const("s", ty.Of(S), s_c); auto* s = Let("s", ty.Of(S), s_c);
auto* a = Const("a", ty.Of(A), a_c); auto* a = Let("a", ty.Of(A), a_c);
auto* p = Const("p", ty.pointer<i32>(ast::StorageClass::kFunction), p_c); auto* p = Let("p", ty.pointer<i32>(ast::StorageClass::kFunction), p_c);
Func("F", {}, ty.void_(), Func("F", {}, ty.void_(),
{ {
@ -299,7 +299,7 @@ TEST_F(ResolverVarLetTest, LetInheritsAccessFromOriginatingVariable) {
auto* expr = auto* expr =
IndexAccessor(MemberAccessor(MemberAccessor(storage, "inner"), "arr"), 4); IndexAccessor(MemberAccessor(MemberAccessor(storage, "inner"), "arr"), 4);
auto* ptr = Const("p", nullptr, AddressOf(expr)); auto* ptr = Let("p", nullptr, AddressOf(expr));
WrapInFunction(ptr); WrapInFunction(ptr);
@ -326,7 +326,7 @@ TEST_F(ResolverVarLetTest, LocalShadowsAlias) {
auto* t = Alias("a", ty.i32()); auto* t = Alias("a", ty.i32());
auto* v = Var("a", nullptr, Expr(false)); auto* v = Var("a", nullptr, Expr(false));
auto* l = Const("a", nullptr, Expr(false)); auto* l = Let("a", nullptr, Expr(false));
Func("X", {}, ty.void_(), {Decl(v)}); Func("X", {}, ty.void_(), {Decl(v)});
Func("Y", {}, ty.void_(), {Decl(l)}); Func("Y", {}, ty.void_(), {Decl(l)});
@ -358,7 +358,7 @@ TEST_F(ResolverVarLetTest, LocalShadowsStruct) {
auto* t = Structure("a", {Member("m", ty.i32())}); auto* t = Structure("a", {Member("m", ty.i32())});
auto* v = Var("a", nullptr, Expr(false)); auto* v = Var("a", nullptr, Expr(false));
auto* l = Const("a", nullptr, Expr(false)); auto* l = Let("a", nullptr, Expr(false));
Func("X", {}, ty.void_(), {Decl(v)}); Func("X", {}, ty.void_(), {Decl(v)});
Func("Y", {}, ty.void_(), {Decl(l)}); Func("Y", {}, ty.void_(), {Decl(l)});
@ -385,7 +385,7 @@ TEST_F(ResolverVarLetTest, LocalShadowsFunction) {
// } // }
auto* v = Var("a", nullptr, Expr(false)); auto* v = Var("a", nullptr, Expr(false));
auto* l = Const("b", nullptr, Expr(false)); auto* l = Let("b", nullptr, Expr(false));
auto* fa = Func("a", {}, ty.void_(), {Decl(v)}); auto* fa = Func("a", {}, ty.void_(), {Decl(v)});
auto* fb = Func("b", {}, ty.void_(), {Decl(l)}); auto* fb = Func("b", {}, ty.void_(), {Decl(l)});
@ -418,7 +418,7 @@ TEST_F(ResolverVarLetTest, LocalShadowsGlobalVar) {
auto* g = Global("a", ty.i32(), ast::StorageClass::kPrivate); auto* g = Global("a", ty.i32(), ast::StorageClass::kPrivate);
auto* v = Var("a", nullptr, Expr("a")); auto* v = Var("a", nullptr, Expr("a"));
auto* l = Const("a", nullptr, Expr("a")); auto* l = Let("a", nullptr, Expr("a"));
Func("X", {}, ty.void_(), {Decl(v)}); Func("X", {}, ty.void_(), {Decl(v)});
Func("Y", {}, ty.void_(), {Decl(l)}); Func("Y", {}, ty.void_(), {Decl(l)});
@ -459,7 +459,7 @@ TEST_F(ResolverVarLetTest, LocalShadowsGlobalLet) {
auto* g = GlobalConst("a", ty.i32(), Expr(1)); auto* g = GlobalConst("a", ty.i32(), Expr(1));
auto* v = Var("a", nullptr, Expr("a")); auto* v = Var("a", nullptr, Expr("a"));
auto* l = Const("a", nullptr, Expr("a")); auto* l = Let("a", nullptr, Expr("a"));
Func("X", {}, ty.void_(), {Decl(v)}); Func("X", {}, ty.void_(), {Decl(v)});
Func("Y", {}, ty.void_(), {Decl(l)}); Func("Y", {}, ty.void_(), {Decl(l)});
@ -500,7 +500,7 @@ TEST_F(ResolverVarLetTest, LocalShadowsLocalVar) {
auto* s = Var("a", ty.i32(), Expr(1)); auto* s = Var("a", ty.i32(), Expr(1));
auto* v = Var("a", nullptr, Expr("a")); auto* v = Var("a", nullptr, Expr("a"));
auto* l = Const("a", nullptr, Expr("a")); auto* l = Let("a", nullptr, Expr("a"));
Func("X", {}, ty.void_(), {Decl(s), Block(Decl(v)), Block(Decl(l))}); Func("X", {}, ty.void_(), {Decl(s), Block(Decl(v)), Block(Decl(l))});
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -539,9 +539,9 @@ TEST_F(ResolverVarLetTest, LocalShadowsLocalLet) {
// } // }
// } // }
auto* s = Const("a", ty.i32(), Expr(1)); auto* s = Let("a", ty.i32(), Expr(1));
auto* v = Var("a", nullptr, Expr("a")); auto* v = Var("a", nullptr, Expr("a"));
auto* l = Const("a", nullptr, Expr("a")); auto* l = Let("a", nullptr, Expr("a"));
Func("X", {}, ty.void_(), {Decl(s), Block(Decl(v)), Block(Decl(l))}); Func("X", {}, ty.void_(), {Decl(s), Block(Decl(v)), Block(Decl(l))});
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -581,7 +581,7 @@ TEST_F(ResolverVarLetTest, LocalShadowsParam) {
auto* p = Param("a", ty.i32()); auto* p = Param("a", ty.i32());
auto* v = Var("a", nullptr, Expr("a")); auto* v = Var("a", nullptr, Expr("a"));
auto* l = Const("a", nullptr, Expr("a")); auto* l = Let("a", nullptr, Expr("a"));
Func("X", {p}, ty.void_(), {Block(Decl(v)), Block(Decl(l))}); Func("X", {p}, ty.void_(), {Block(Decl(v)), Block(Decl(l))});
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();

View File

@ -25,7 +25,7 @@ struct ResolverVarLetValidationTest : public resolver::TestHelper,
TEST_F(ResolverVarLetValidationTest, LetNoInitializer) { TEST_F(ResolverVarLetValidationTest, LetNoInitializer) {
// let a : i32; // let a : i32;
WrapInFunction(Const(Source{{12, 34}}, "a", ty.i32(), nullptr)); WrapInFunction(Let(Source{{12, 34}}, "a", ty.i32(), nullptr));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -82,7 +82,7 @@ TEST_F(ResolverVarLetValidationTest, LetTypeNotConstructible) {
auto* t1 = auto* t1 =
Global("t1", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Global("t1", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()),
GroupAndBinding(0, 0)); GroupAndBinding(0, 0));
auto* t2 = Const(Source{{56, 78}}, "t2", nullptr, Expr(t1)); auto* t2 = Let(Source{{56, 78}}, "t2", nullptr, Expr(t1));
WrapInFunction(t2); WrapInFunction(t2);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -92,7 +92,7 @@ TEST_F(ResolverVarLetValidationTest, LetTypeNotConstructible) {
TEST_F(ResolverVarLetValidationTest, LetConstructorWrongType) { TEST_F(ResolverVarLetValidationTest, LetConstructorWrongType) {
// var v : i32 = 2u // var v : i32 = 2u
WrapInFunction(Const(Source{{3, 3}}, "v", ty.i32(), Expr(2u))); WrapInFunction(Let(Source{{3, 3}}, "v", ty.i32(), Expr(2u)));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ( EXPECT_EQ(
@ -113,7 +113,7 @@ TEST_F(ResolverVarLetValidationTest, VarConstructorWrongType) {
TEST_F(ResolverVarLetValidationTest, LetConstructorWrongTypeViaAlias) { TEST_F(ResolverVarLetValidationTest, LetConstructorWrongTypeViaAlias) {
auto* a = Alias("I32", ty.i32()); auto* a = Alias("I32", ty.i32());
WrapInFunction(Const(Source{{3, 3}}, "v", ty.Of(a), Expr(2u))); WrapInFunction(Let(Source{{3, 3}}, "v", ty.Of(a), Expr(2u)));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ( EXPECT_EQ(
@ -138,7 +138,7 @@ TEST_F(ResolverVarLetValidationTest, LetOfPtrConstructedWithRef) {
const auto priv = ast::StorageClass::kFunction; const auto priv = ast::StorageClass::kFunction;
auto* var_a = Var("a", ty.f32(), priv); auto* var_a = Var("a", ty.f32(), priv);
auto* var_b = auto* var_b =
Const(Source{{12, 34}}, "b", ty.pointer<float>(priv), Expr("a"), {}); Let(Source{{12, 34}}, "b", ty.pointer<float>(priv), Expr("a"), {});
WrapInFunction(var_a, var_b); WrapInFunction(var_a, var_b);
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -151,8 +151,8 @@ TEST_F(ResolverVarLetValidationTest, LetOfPtrConstructedWithRef) {
TEST_F(ResolverVarLetValidationTest, LocalLetRedeclared) { TEST_F(ResolverVarLetValidationTest, LocalLetRedeclared) {
// let l : f32 = 1.; // let l : f32 = 1.;
// let l : i32 = 0; // let l : i32 = 0;
auto* l1 = Const("l", ty.f32(), Expr(1.f)); auto* l1 = Let("l", ty.f32(), Expr(1.f));
auto* l2 = Const(Source{{12, 34}}, "l", ty.i32(), Expr(0)); auto* l2 = Let(Source{{12, 34}}, "l", ty.i32(), Expr(0));
WrapInFunction(l1, l2); WrapInFunction(l1, l2);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -235,10 +235,10 @@ TEST_F(ResolverVarLetValidationTest, InferredPtrStorageAccessMismatch) {
auto* expr = auto* expr =
IndexAccessor(MemberAccessor(MemberAccessor(storage, "inner"), "arr"), 4); IndexAccessor(MemberAccessor(MemberAccessor(storage, "inner"), "arr"), 4);
auto* ptr = Const( auto* ptr =
Source{{12, 34}}, "p", Let(Source{{12, 34}}, "p",
ty.pointer<i32>(ast::StorageClass::kStorage, ast::Access::kReadWrite), ty.pointer<i32>(ast::StorageClass::kStorage, ast::Access::kReadWrite),
AddressOf(expr)); AddressOf(expr));
WrapInFunction(ptr); WrapInFunction(ptr);
@ -309,8 +309,8 @@ TEST_F(ResolverVarLetValidationTest, InvalidStorageClassForInitializer) {
TEST_F(ResolverVarLetValidationTest, VectorLetNoType) { TEST_F(ResolverVarLetValidationTest, VectorLetNoType) {
// let a : mat3x3 = mat3x3<f32>(); // let a : mat3x3 = mat3x3<f32>();
WrapInFunction(Const("a", create<ast::Vector>(Source{{12, 34}}, nullptr, 3), WrapInFunction(
vec3<f32>())); Let("a", create<ast::Vector>(Source{{12, 34}}, nullptr, 3), vec3<f32>()));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: missing vector element type"); EXPECT_EQ(r()->error(), "12:34 error: missing vector element type");
@ -326,9 +326,8 @@ TEST_F(ResolverVarLetValidationTest, VectorVarNoType) {
TEST_F(ResolverVarLetValidationTest, MatrixLetNoType) { TEST_F(ResolverVarLetValidationTest, MatrixLetNoType) {
// let a : mat3x3 = mat3x3<f32>(); // let a : mat3x3 = mat3x3<f32>();
WrapInFunction(Const("a", WrapInFunction(Let("a", create<ast::Matrix>(Source{{12, 34}}, nullptr, 3, 3),
create<ast::Matrix>(Source{{12, 34}}, nullptr, 3, 3), mat3x3<f32>()));
mat3x3<f32>()));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: missing matrix element type"); EXPECT_EQ(r()->error(), "12:34 error: missing matrix element type");

View File

@ -59,48 +59,47 @@ struct BuiltinPolyfill::State {
auto V = [&](uint32_t value) -> const ast::Expression* { auto V = [&](uint32_t value) -> const ast::Expression* {
return ScalarOrVector(width, value); return ScalarOrVector(width, value);
}; };
b.Func( b.Func(name, {b.Param("v", T(ty))}, T(ty),
name, {b.Param("v", T(ty))}, T(ty), {
{ // var x = U(v);
// var x = U(v); b.Decl(b.Var("x", nullptr, b.Construct(U(), b.Expr("v")))),
b.Decl(b.Var("x", nullptr, b.Construct(U(), b.Expr("v")))), // let b16 = select(0, 16, x <= 0x0000ffff);
// let b16 = select(0, 16, x <= 0x0000ffff); b.Decl(b.Let("b16", nullptr,
b.Decl(b.Const("b16", nullptr, b.Call("select", V(0), V(16),
b.Call("select", V(0), V(16), b.LessThanEqual("x", V(0x0000ffff))))),
b.LessThanEqual("x", V(0x0000ffff))))), // x = x << b16;
// x = x << b16; b.Assign("x", b.Shl("x", "b16")),
b.Assign("x", b.Shl("x", "b16")), // let b8 = select(0, 8, x <= 0x00ffffff);
// let b8 = select(0, 8, x <= 0x00ffffff); b.Decl(b.Let("b8", nullptr,
b.Decl(b.Const("b8", nullptr, b.Call("select", V(0), V(8),
b.Call("select", V(0), V(8), b.LessThanEqual("x", V(0x00ffffff))))),
b.LessThanEqual("x", V(0x00ffffff))))), // x = x << b8;
// x = x << b8; b.Assign("x", b.Shl("x", "b8")),
b.Assign("x", b.Shl("x", "b8")), // let b4 = select(0, 4, x <= 0x0fffffff);
// let b4 = select(0, 4, x <= 0x0fffffff); b.Decl(b.Let("b4", nullptr,
b.Decl(b.Const("b4", nullptr, b.Call("select", V(0), V(4),
b.Call("select", V(0), V(4), b.LessThanEqual("x", V(0x0fffffff))))),
b.LessThanEqual("x", V(0x0fffffff))))), // x = x << b4;
// x = x << b4; b.Assign("x", b.Shl("x", "b4")),
b.Assign("x", b.Shl("x", "b4")), // let b2 = select(0, 2, x <= 0x3fffffff);
// let b2 = select(0, 2, x <= 0x3fffffff); b.Decl(b.Let("b2", nullptr,
b.Decl(b.Const("b2", nullptr, b.Call("select", V(0), V(2),
b.Call("select", V(0), V(2), b.LessThanEqual("x", V(0x3fffffff))))),
b.LessThanEqual("x", V(0x3fffffff))))), // x = x << b2;
// x = x << b2; b.Assign("x", b.Shl("x", "b2")),
b.Assign("x", b.Shl("x", "b2")), // let b1 = select(0, 1, x <= 0x7fffffff);
// let b1 = select(0, 1, x <= 0x7fffffff); b.Decl(b.Let("b1", nullptr,
b.Decl(b.Const("b1", nullptr, b.Call("select", V(0), V(1),
b.Call("select", V(0), V(1), b.LessThanEqual("x", V(0x7fffffff))))),
b.LessThanEqual("x", V(0x7fffffff))))), // let is_zero = select(0, 1, x == 0);
// let is_zero = select(0, 1, x == 0); b.Decl(b.Let("is_zero", nullptr,
b.Decl(b.Const("is_zero", nullptr, b.Call("select", V(0), V(1), b.Equal("x", V(0))))),
b.Call("select", V(0), V(1), b.Equal("x", V(0))))), // return R((b16 | b8 | b4 | b2 | b1) + zero);
// return R((b16 | b8 | b4 | b2 | b1) + zero); b.Return(b.Construct(
b.Return(b.Construct( T(ty),
T(ty), b.Add(b.Or(b.Or(b.Or(b.Or("b16", "b8"), "b4"), "b2"), "b1"),
b.Add(b.Or(b.Or(b.Or(b.Or("b16", "b8"), "b4"), "b2"), "b1"), "is_zero"))),
"is_zero"))), });
});
return name; return name;
} }
@ -127,48 +126,47 @@ struct BuiltinPolyfill::State {
} }
return b.Construct(b.ty.vec<bool>(width), value); return b.Construct(b.ty.vec<bool>(width), value);
}; };
b.Func( b.Func(name, {b.Param("v", T(ty))}, T(ty),
name, {b.Param("v", T(ty))}, T(ty), {
{ // var x = U(v);
// var x = U(v); b.Decl(b.Var("x", nullptr, b.Construct(U(), b.Expr("v")))),
b.Decl(b.Var("x", nullptr, b.Construct(U(), b.Expr("v")))), // let b16 = select(16, 0, bool(x & 0x0000ffff));
// let b16 = select(16, 0, bool(x & 0x0000ffff)); b.Decl(b.Let("b16", nullptr,
b.Decl(b.Const( b.Call("select", V(16), V(0),
"b16", nullptr, B(b.And("x", V(0x0000ffff)))))),
b.Call("select", V(16), V(0), B(b.And("x", V(0x0000ffff)))))), // x = x >> b16;
// x = x >> b16; b.Assign("x", b.Shr("x", "b16")),
b.Assign("x", b.Shr("x", "b16")), // let b8 = select(8, 0, bool(x & 0x000000ff));
// let b8 = select(8, 0, bool(x & 0x000000ff)); b.Decl(b.Let(
b.Decl(b.Const( "b8", nullptr,
"b8", nullptr, b.Call("select", V(8), V(0), B(b.And("x", V(0x000000ff)))))),
b.Call("select", V(8), V(0), B(b.And("x", V(0x000000ff)))))), // x = x >> b8;
// x = x >> b8; b.Assign("x", b.Shr("x", "b8")),
b.Assign("x", b.Shr("x", "b8")), // let b4 = select(4, 0, bool(x & 0x0000000f));
// let b4 = select(4, 0, bool(x & 0x0000000f)); b.Decl(b.Let(
b.Decl(b.Const( "b4", nullptr,
"b4", nullptr, b.Call("select", V(4), V(0), B(b.And("x", V(0x0000000f)))))),
b.Call("select", V(4), V(0), B(b.And("x", V(0x0000000f)))))), // x = x >> b4;
// x = x >> b4; b.Assign("x", b.Shr("x", "b4")),
b.Assign("x", b.Shr("x", "b4")), // let b2 = select(2, 0, bool(x & 0x00000003));
// let b2 = select(2, 0, bool(x & 0x00000003)); b.Decl(b.Let(
b.Decl(b.Const( "b2", nullptr,
"b2", nullptr, b.Call("select", V(2), V(0), B(b.And("x", V(0x00000003)))))),
b.Call("select", V(2), V(0), B(b.And("x", V(0x00000003)))))), // x = x >> b2;
// x = x >> b2; b.Assign("x", b.Shr("x", "b2")),
b.Assign("x", b.Shr("x", "b2")), // let b1 = select(1, 0, bool(x & 0x00000001));
// let b1 = select(1, 0, bool(x & 0x00000001)); b.Decl(b.Let(
b.Decl(b.Const( "b1", nullptr,
"b1", nullptr, b.Call("select", V(1), V(0), B(b.And("x", V(0x00000001)))))),
b.Call("select", V(1), V(0), B(b.And("x", V(0x00000001)))))), // let is_zero = select(0, 1, x == 0);
// let is_zero = select(0, 1, x == 0); b.Decl(b.Let("is_zero", nullptr,
b.Decl(b.Const("is_zero", nullptr, b.Call("select", V(0), V(1), b.Equal("x", V(0))))),
b.Call("select", V(0), V(1), b.Equal("x", V(0))))), // return R((b16 | b8 | b4 | b2 | b1) + zero);
// return R((b16 | b8 | b4 | b2 | b1) + zero); b.Return(b.Construct(
b.Return(b.Construct( T(ty),
T(ty), b.Add(b.Or(b.Or(b.Or(b.Or("b16", "b8"), "b4"), "b2"), "b1"),
b.Add(b.Or(b.Or(b.Or(b.Or("b16", "b8"), "b4"), "b2"), "b1"), "is_zero"))),
"is_zero"))), });
});
return name; return name;
} }
@ -190,14 +188,14 @@ struct BuiltinPolyfill::State {
}; };
ast::StatementList body = { ast::StatementList body = {
b.Decl(b.Const("s", nullptr, b.Call("min", "offset", W))), b.Decl(b.Let("s", nullptr, b.Call("min", "offset", W))),
b.Decl(b.Const("e", nullptr, b.Call("min", W, b.Add("s", "count")))), b.Decl(b.Let("e", nullptr, b.Call("min", W, b.Add("s", "count")))),
}; };
switch (polyfill.extract_bits) { switch (polyfill.extract_bits) {
case Level::kFull: case Level::kFull:
body.emplace_back(b.Decl(b.Const("shl", nullptr, b.Sub(W, "e")))); body.emplace_back(b.Decl(b.Let("shl", nullptr, b.Sub(W, "e"))));
body.emplace_back(b.Decl(b.Const("shr", nullptr, b.Add("shl", "s")))); body.emplace_back(b.Decl(b.Let("shr", nullptr, b.Add("shl", "s"))));
body.emplace_back(b.Return(b.Shr(b.Shl("v", vecN_u32(b.Expr("shl"))), body.emplace_back(b.Return(b.Shr(b.Shl("v", vecN_u32(b.Expr("shl"))),
vecN_u32(b.Expr("shr"))))); vecN_u32(b.Expr("shr")))));
break; break;
@ -264,37 +262,37 @@ struct BuiltinPolyfill::State {
// var x = select(U(v), ~U(v), v < 0); (signed) // var x = select(U(v), ~U(v), v < 0); (signed)
b.Decl(b.Var("x", nullptr, x)), b.Decl(b.Var("x", nullptr, x)),
// let b16 = select(0, 16, bool(x & 0xffff0000)); // let b16 = select(0, 16, bool(x & 0xffff0000));
b.Decl(b.Const("b16", nullptr, b.Decl(b.Let("b16", nullptr,
b.Call("select", V(0), V(16), b.Call("select", V(0), V(16),
B(b.And("x", V(0xffff0000)))))), B(b.And("x", V(0xffff0000)))))),
// x = x >> b16; // x = x >> b16;
b.Assign("x", b.Shr("x", "b16")), b.Assign("x", b.Shr("x", "b16")),
// let b8 = select(0, 8, bool(x & 0x0000ff00)); // let b8 = select(0, 8, bool(x & 0x0000ff00));
b.Decl(b.Const( b.Decl(b.Let(
"b8", nullptr, "b8", nullptr,
b.Call("select", V(0), V(8), B(b.And("x", V(0x0000ff00)))))), b.Call("select", V(0), V(8), B(b.And("x", V(0x0000ff00)))))),
// x = x >> b8; // x = x >> b8;
b.Assign("x", b.Shr("x", "b8")), b.Assign("x", b.Shr("x", "b8")),
// let b4 = select(0, 4, bool(x & 0x000000f0)); // let b4 = select(0, 4, bool(x & 0x000000f0));
b.Decl(b.Const( b.Decl(b.Let(
"b4", nullptr, "b4", nullptr,
b.Call("select", V(0), V(4), B(b.And("x", V(0x000000f0)))))), b.Call("select", V(0), V(4), B(b.And("x", V(0x000000f0)))))),
// x = x >> b4; // x = x >> b4;
b.Assign("x", b.Shr("x", "b4")), b.Assign("x", b.Shr("x", "b4")),
// let b2 = select(0, 2, bool(x & 0x0000000c)); // let b2 = select(0, 2, bool(x & 0x0000000c));
b.Decl(b.Const( b.Decl(b.Let(
"b2", nullptr, "b2", nullptr,
b.Call("select", V(0), V(2), B(b.And("x", V(0x0000000c)))))), b.Call("select", V(0), V(2), B(b.And("x", V(0x0000000c)))))),
// x = x >> b2; // x = x >> b2;
b.Assign("x", b.Shr("x", "b2")), b.Assign("x", b.Shr("x", "b2")),
// let b1 = select(0, 1, bool(x & 0x00000002)); // let b1 = select(0, 1, bool(x & 0x00000002));
b.Decl(b.Const( b.Decl(b.Let(
"b1", nullptr, "b1", nullptr,
b.Call("select", V(0), V(1), B(b.And("x", V(0x00000002)))))), b.Call("select", V(0), V(1), B(b.And("x", V(0x00000002)))))),
// let is_zero = select(0, 0xffffffff, x == 0); // let is_zero = select(0, 0xffffffff, x == 0);
b.Decl(b.Const("is_zero", nullptr, b.Decl(b.Let(
b.Call("select", V(0), V(0xffffffff), "is_zero", nullptr,
b.Equal("x", V(0))))), b.Call("select", V(0), V(0xffffffff), b.Equal("x", V(0))))),
// return R(b16 | b8 | b4 | b2 | b1 | zero); // return R(b16 | b8 | b4 | b2 | b1 | zero);
b.Return(b.Construct( b.Return(b.Construct(
T(ty), T(ty),
@ -332,37 +330,37 @@ struct BuiltinPolyfill::State {
// var x = U(v); // var x = U(v);
b.Decl(b.Var("x", nullptr, b.Construct(U(), b.Expr("v")))), b.Decl(b.Var("x", nullptr, b.Construct(U(), b.Expr("v")))),
// let b16 = select(16, 0, bool(x & 0x0000ffff)); // let b16 = select(16, 0, bool(x & 0x0000ffff));
b.Decl(b.Const("b16", nullptr, b.Decl(b.Let("b16", nullptr,
b.Call("select", V(16), V(0), b.Call("select", V(16), V(0),
B(b.And("x", V(0x0000ffff)))))), B(b.And("x", V(0x0000ffff)))))),
// x = x >> b16; // x = x >> b16;
b.Assign("x", b.Shr("x", "b16")), b.Assign("x", b.Shr("x", "b16")),
// let b8 = select(8, 0, bool(x & 0x000000ff)); // let b8 = select(8, 0, bool(x & 0x000000ff));
b.Decl(b.Const( b.Decl(b.Let(
"b8", nullptr, "b8", nullptr,
b.Call("select", V(8), V(0), B(b.And("x", V(0x000000ff)))))), b.Call("select", V(8), V(0), B(b.And("x", V(0x000000ff)))))),
// x = x >> b8; // x = x >> b8;
b.Assign("x", b.Shr("x", "b8")), b.Assign("x", b.Shr("x", "b8")),
// let b4 = select(4, 0, bool(x & 0x0000000f)); // let b4 = select(4, 0, bool(x & 0x0000000f));
b.Decl(b.Const( b.Decl(b.Let(
"b4", nullptr, "b4", nullptr,
b.Call("select", V(4), V(0), B(b.And("x", V(0x0000000f)))))), b.Call("select", V(4), V(0), B(b.And("x", V(0x0000000f)))))),
// x = x >> b4; // x = x >> b4;
b.Assign("x", b.Shr("x", "b4")), b.Assign("x", b.Shr("x", "b4")),
// let b2 = select(2, 0, bool(x & 0x00000003)); // let b2 = select(2, 0, bool(x & 0x00000003));
b.Decl(b.Const( b.Decl(b.Let(
"b2", nullptr, "b2", nullptr,
b.Call("select", V(2), V(0), B(b.And("x", V(0x00000003)))))), b.Call("select", V(2), V(0), B(b.And("x", V(0x00000003)))))),
// x = x >> b2; // x = x >> b2;
b.Assign("x", b.Shr("x", "b2")), b.Assign("x", b.Shr("x", "b2")),
// let b1 = select(1, 0, bool(x & 0x00000001)); // let b1 = select(1, 0, bool(x & 0x00000001));
b.Decl(b.Const( b.Decl(b.Let(
"b1", nullptr, "b1", nullptr,
b.Call("select", V(1), V(0), B(b.And("x", V(0x00000001)))))), b.Call("select", V(1), V(0), B(b.And("x", V(0x00000001)))))),
// let is_zero = select(0, 0xffffffff, x == 0); // let is_zero = select(0, 0xffffffff, x == 0);
b.Decl(b.Const("is_zero", nullptr, b.Decl(b.Let(
b.Call("select", V(0), V(0xffffffff), "is_zero", nullptr,
b.Equal("x", V(0))))), b.Call("select", V(0), V(0xffffffff), b.Equal("x", V(0))))),
// return R(b16 | b8 | b4 | b2 | b1 | is_zero); // return R(b16 | b8 | b4 | b2 | b1 | is_zero);
b.Return(b.Construct( b.Return(b.Construct(
T(ty), T(ty),
@ -399,14 +397,14 @@ struct BuiltinPolyfill::State {
}; };
ast::StatementList body = { ast::StatementList body = {
b.Decl(b.Const("s", nullptr, b.Call("min", "offset", W))), b.Decl(b.Let("s", nullptr, b.Call("min", "offset", W))),
b.Decl(b.Const("e", nullptr, b.Call("min", W, b.Add("s", "count")))), b.Decl(b.Let("e", nullptr, b.Call("min", W, b.Add("s", "count")))),
}; };
switch (polyfill.insert_bits) { switch (polyfill.insert_bits) {
case Level::kFull: case Level::kFull:
// let mask = ((1 << s) - 1) ^ ((1 << e) - 1) // let mask = ((1 << s) - 1) ^ ((1 << e) - 1)
body.emplace_back(b.Decl(b.Const( body.emplace_back(b.Decl(b.Let(
"mask", nullptr, "mask", nullptr,
b.Xor(b.Sub(b.Shl(1u, "s"), 1u), b.Sub(b.Shl(1u, "e"), 1u))))); b.Xor(b.Sub(b.Shl(1u, "s"), 1u), b.Sub(b.Shl(1u, "e"), 1u)))));
// return ((n << s) & mask) | (v & ~mask) // return ((n << s) & mask) | (v & ~mask)

View File

@ -215,8 +215,8 @@ void CalculateArrayLength::Run(CloneContext& ctx,
} }
uint32_t array_stride = array_type->Size(); uint32_t array_stride = array_type->Size();
auto* array_length_var = ctx.dst->Decl( auto* array_length_var = ctx.dst->Decl(
ctx.dst->Const(name, ctx.dst->ty.u32(), ctx.dst->Let(name, ctx.dst->ty.u32(),
ctx.dst->Div(total_size, array_stride))); ctx.dst->Div(total_size, array_stride)));
// Insert the array length calculations at the top of the block // Insert the array length calculations at the top of the block
ctx.InsertBefore(block->statements, block->statements[0], ctx.InsertBefore(block->statements, block->statements[0],

View File

@ -562,8 +562,8 @@ struct CanonicalizeEntryPointIO::State {
wrapper_body.push_back(ctx.dst->CallStmt(call_inner)); wrapper_body.push_back(ctx.dst->CallStmt(call_inner));
} else { } else {
// Capture the result of calling the original function. // Capture the result of calling the original function.
auto* inner_result = ctx.dst->Const( auto* inner_result = ctx.dst->Let(ctx.dst->Symbols().New("inner_result"),
ctx.dst->Symbols().New("inner_result"), nullptr, call_inner); nullptr, call_inner);
wrapper_body.push_back(ctx.dst->Decl(inner_result)); wrapper_body.push_back(ctx.dst->Decl(inner_result));
// Process the original return type to determine the outputs that the // Process the original return type to determine the outputs that the

View File

@ -80,8 +80,8 @@ TEST_F(DecomposeStridedArrayTest, PrivateDefaultStridedArray) {
b.Global("arr", b.ty.array<f32, 4>(4), ast::StorageClass::kPrivate); b.Global("arr", b.ty.array<f32, 4>(4), ast::StorageClass::kPrivate);
b.Func("f", {}, b.ty.void_(), b.Func("f", {}, b.ty.void_(),
{ {
b.Decl(b.Const("a", b.ty.array<f32, 4>(4), b.Expr("arr"))), b.Decl(b.Let("a", b.ty.array<f32, 4>(4), b.Expr("arr"))),
b.Decl(b.Const("b", b.ty.f32(), b.IndexAccessor("arr", 1))), b.Decl(b.Let("b", b.ty.f32(), b.IndexAccessor("arr", 1))),
}, },
{ {
b.Stage(ast::PipelineStage::kCompute), b.Stage(ast::PipelineStage::kCompute),
@ -117,8 +117,8 @@ TEST_F(DecomposeStridedArrayTest, PrivateStridedArray) {
b.Global("arr", b.ty.array<f32, 4>(32), ast::StorageClass::kPrivate); b.Global("arr", b.ty.array<f32, 4>(32), ast::StorageClass::kPrivate);
b.Func("f", {}, b.ty.void_(), b.Func("f", {}, b.ty.void_(),
{ {
b.Decl(b.Const("a", b.ty.array<f32, 4>(32), b.Expr("arr"))), b.Decl(b.Let("a", b.ty.array<f32, 4>(32), b.Expr("arr"))),
b.Decl(b.Const("b", b.ty.f32(), b.IndexAccessor("arr", 1))), b.Decl(b.Let("b", b.ty.f32(), b.IndexAccessor("arr", 1))),
}, },
{ {
b.Stage(ast::PipelineStage::kCompute), b.Stage(ast::PipelineStage::kCompute),
@ -163,10 +163,10 @@ TEST_F(DecomposeStridedArrayTest, ReadUniformStridedArray) {
b.GroupAndBinding(0, 0)); b.GroupAndBinding(0, 0));
b.Func("f", {}, b.ty.void_(), b.Func("f", {}, b.ty.void_(),
{ {
b.Decl(b.Const("a", b.ty.array<f32, 4>(32), b.Decl(b.Let("a", b.ty.array<f32, 4>(32),
b.MemberAccessor("s", "a"))), b.MemberAccessor("s", "a"))),
b.Decl(b.Const("b", b.ty.f32(), b.Decl(b.Let("b", b.ty.f32(),
b.IndexAccessor(b.MemberAccessor("s", "a"), 1))), b.IndexAccessor(b.MemberAccessor("s", "a"), 1))),
}, },
{ {
b.Stage(ast::PipelineStage::kCompute), b.Stage(ast::PipelineStage::kCompute),
@ -214,19 +214,19 @@ TEST_F(DecomposeStridedArrayTest, ReadUniformDefaultStridedArray) {
b.Structure("S", {b.Member("a", b.ty.array(b.ty.vec4<f32>(), 4, 16))}); b.Structure("S", {b.Member("a", b.ty.array(b.ty.vec4<f32>(), 4, 16))});
b.Global("s", b.ty.Of(S), ast::StorageClass::kUniform, b.Global("s", b.ty.Of(S), ast::StorageClass::kUniform,
b.GroupAndBinding(0, 0)); b.GroupAndBinding(0, 0));
b.Func("f", {}, b.ty.void_(), b.Func(
{ "f", {}, b.ty.void_(),
b.Decl(b.Const("a", b.ty.array(b.ty.vec4<f32>(), 4, 16), {
b.MemberAccessor("s", "a"))), b.Decl(b.Let("a", b.ty.array(b.ty.vec4<f32>(), 4, 16),
b.Decl(b.Const( b.MemberAccessor("s", "a"))),
"b", b.ty.f32(), b.Decl(b.Let("b", b.ty.f32(),
b.IndexAccessor(b.IndexAccessor(b.MemberAccessor("s", "a"), 1), b.IndexAccessor(
2))), b.IndexAccessor(b.MemberAccessor("s", "a"), 1), 2))),
}, },
{ {
b.Stage(ast::PipelineStage::kCompute), b.Stage(ast::PipelineStage::kCompute),
b.WorkgroupSize(1), b.WorkgroupSize(1),
}); });
auto* expect = auto* expect =
R"( R"(
@ -266,10 +266,10 @@ TEST_F(DecomposeStridedArrayTest, ReadStorageStridedArray) {
b.GroupAndBinding(0, 0)); b.GroupAndBinding(0, 0));
b.Func("f", {}, b.ty.void_(), b.Func("f", {}, b.ty.void_(),
{ {
b.Decl(b.Const("a", b.ty.array<f32, 4>(32), b.Decl(b.Let("a", b.ty.array<f32, 4>(32),
b.MemberAccessor("s", "a"))), b.MemberAccessor("s", "a"))),
b.Decl(b.Const("b", b.ty.f32(), b.Decl(b.Let("b", b.ty.f32(),
b.IndexAccessor(b.MemberAccessor("s", "a"), 1))), b.IndexAccessor(b.MemberAccessor("s", "a"), 1))),
}, },
{ {
b.Stage(ast::PipelineStage::kCompute), b.Stage(ast::PipelineStage::kCompute),
@ -316,17 +316,17 @@ TEST_F(DecomposeStridedArrayTest, ReadStorageDefaultStridedArray) {
auto* S = b.Structure("S", {b.Member("a", b.ty.array<f32, 4>(4))}); auto* S = b.Structure("S", {b.Member("a", b.ty.array<f32, 4>(4))});
b.Global("s", b.ty.Of(S), ast::StorageClass::kStorage, b.Global("s", b.ty.Of(S), ast::StorageClass::kStorage,
b.GroupAndBinding(0, 0)); b.GroupAndBinding(0, 0));
b.Func("f", {}, b.ty.void_(), b.Func(
{ "f", {}, b.ty.void_(),
b.Decl(b.Const("a", b.ty.array<f32, 4>(4), {
b.MemberAccessor("s", "a"))), b.Decl(b.Let("a", b.ty.array<f32, 4>(4), b.MemberAccessor("s", "a"))),
b.Decl(b.Const("b", b.ty.f32(), b.Decl(b.Let("b", b.ty.f32(),
b.IndexAccessor(b.MemberAccessor("s", "a"), 1))), b.IndexAccessor(b.MemberAccessor("s", "a"), 1))),
}, },
{ {
b.Stage(ast::PipelineStage::kCompute), b.Stage(ast::PipelineStage::kCompute),
b.WorkgroupSize(1), b.WorkgroupSize(1),
}); });
auto* expect = R"( auto* expect = R"(
struct S { struct S {
@ -476,22 +476,22 @@ TEST_F(DecomposeStridedArrayTest, ReadWriteViaPointerLets) {
auto* S = b.Structure("S", {b.Member("a", b.ty.array<f32, 4>(32))}); auto* S = b.Structure("S", {b.Member("a", b.ty.array<f32, 4>(32))});
b.Global("s", b.ty.Of(S), ast::StorageClass::kStorage, b.Global("s", b.ty.Of(S), ast::StorageClass::kStorage,
ast::Access::kReadWrite, b.GroupAndBinding(0, 0)); ast::Access::kReadWrite, b.GroupAndBinding(0, 0));
b.Func("f", {}, b.ty.void_(), b.Func(
{ "f", {}, b.ty.void_(),
b.Decl(b.Const("a", nullptr, {
b.AddressOf(b.MemberAccessor("s", "a")))), b.Decl(b.Let("a", nullptr, b.AddressOf(b.MemberAccessor("s", "a")))),
b.Decl(b.Const("b", nullptr, b.Decl(b.Let("b", nullptr,
b.AddressOf(b.Deref(b.AddressOf(b.Deref("a")))))), b.AddressOf(b.Deref(b.AddressOf(b.Deref("a")))))),
b.Decl(b.Const("c", nullptr, b.Deref("b"))), b.Decl(b.Let("c", nullptr, b.Deref("b"))),
b.Decl(b.Const("d", nullptr, b.IndexAccessor(b.Deref("b"), 1))), b.Decl(b.Let("d", nullptr, b.IndexAccessor(b.Deref("b"), 1))),
b.Assign(b.Deref("b"), b.Construct(b.ty.array<f32, 4>(32), 1.0f, b.Assign(b.Deref("b"),
2.0f, 3.0f, 4.0f)), b.Construct(b.ty.array<f32, 4>(32), 1.0f, 2.0f, 3.0f, 4.0f)),
b.Assign(b.IndexAccessor(b.Deref("b"), 1), 5.0f), b.Assign(b.IndexAccessor(b.Deref("b"), 1), 5.0f),
}, },
{ {
b.Stage(ast::PipelineStage::kCompute), b.Stage(ast::PipelineStage::kCompute),
b.WorkgroupSize(1), b.WorkgroupSize(1),
}); });
auto* expect = auto* expect =
R"( R"(
@ -544,10 +544,9 @@ TEST_F(DecomposeStridedArrayTest, PrivateAliasedStridedArray) {
b.Func( b.Func(
"f", {}, b.ty.void_(), "f", {}, b.ty.void_(),
{ {
b.Decl( b.Decl(b.Let("a", b.ty.type_name("ARR"), b.MemberAccessor("s", "a"))),
b.Const("a", b.ty.type_name("ARR"), b.MemberAccessor("s", "a"))), b.Decl(b.Let("b", b.ty.f32(),
b.Decl(b.Const("b", b.ty.f32(), b.IndexAccessor(b.MemberAccessor("s", "a"), 1))),
b.IndexAccessor(b.MemberAccessor("s", "a"), 1))),
b.Assign(b.MemberAccessor("s", "a"), b.Assign(b.MemberAccessor("s", "a"),
b.Construct(b.ty.type_name("ARR"))), b.Construct(b.ty.type_name("ARR"))),
b.Assign(b.MemberAccessor("s", "a"), b.Assign(b.MemberAccessor("s", "a"),
@ -618,26 +617,26 @@ TEST_F(DecomposeStridedArrayTest, PrivateNestedStridedArray) {
ast::Access::kReadWrite, b.GroupAndBinding(0, 0)); ast::Access::kReadWrite, b.GroupAndBinding(0, 0));
b.Func("f", {}, b.ty.void_(), b.Func("f", {}, b.ty.void_(),
{ {
b.Decl(b.Const("a", b.ty.type_name("ARR_B"), b.Decl(b.Let("a", b.ty.type_name("ARR_B"),
b.MemberAccessor("s", "a"))), b.MemberAccessor("s", "a"))),
b.Decl(b.Const("b", b.ty.array(b.ty.type_name("ARR_A"), 3, 16), b.Decl(b.Let("b", b.ty.array(b.ty.type_name("ARR_A"), 3, 16),
b.IndexAccessor( // b.IndexAccessor( //
b.MemberAccessor("s", "a"), // b.MemberAccessor("s", "a"), //
3))), 3))),
b.Decl(b.Const("c", b.ty.type_name("ARR_A"), b.Decl(b.Let("c", b.ty.type_name("ARR_A"),
b.IndexAccessor( // b.IndexAccessor( //
b.IndexAccessor( // b.IndexAccessor( //
b.MemberAccessor("s", "a"), // b.MemberAccessor("s", "a"), //
3), 3),
2))), 2))),
b.Decl(b.Const("d", b.ty.f32(), b.Decl(b.Let("d", b.ty.f32(),
b.IndexAccessor( // b.IndexAccessor( //
b.IndexAccessor( // b.IndexAccessor( //
b.IndexAccessor( // b.IndexAccessor( //
b.MemberAccessor("s", "a"), // b.MemberAccessor("s", "a"), //
3), 3),
2), 2),
1))), 1))),
b.Assign(b.MemberAccessor("s", "a"), b.Assign(b.MemberAccessor("s", "a"),
b.Construct(b.ty.type_name("ARR_B"))), b.Construct(b.ty.type_name("ARR_B"))),
b.Assign(b.IndexAccessor( // b.Assign(b.IndexAccessor( //

View File

@ -79,15 +79,14 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformMatrix) {
}); });
b.Global("s", b.ty.Of(S), ast::StorageClass::kUniform, b.Global("s", b.ty.Of(S), ast::StorageClass::kUniform,
b.GroupAndBinding(0, 0)); b.GroupAndBinding(0, 0));
b.Func( b.Func("f", {}, b.ty.void_(),
"f", {}, b.ty.void_(), {
{ b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
b.Decl(b.Const("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))), },
}, {
{ b.Stage(ast::PipelineStage::kCompute),
b.Stage(ast::PipelineStage::kCompute), b.WorkgroupSize(1),
b.WorkgroupSize(1), });
});
auto* expect = R"( auto* expect = R"(
struct S { struct S {
@ -142,8 +141,8 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformColumn) {
b.GroupAndBinding(0, 0)); b.GroupAndBinding(0, 0));
b.Func("f", {}, b.ty.void_(), b.Func("f", {}, b.ty.void_(),
{ {
b.Decl(b.Const("x", b.ty.vec2<f32>(), b.Decl(b.Let("x", b.ty.vec2<f32>(),
b.IndexAccessor(b.MemberAccessor("s", "m"), 1))), b.IndexAccessor(b.MemberAccessor("s", "m"), 1))),
}, },
{ {
b.Stage(ast::PipelineStage::kCompute), b.Stage(ast::PipelineStage::kCompute),
@ -197,15 +196,14 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformMatrix_DefaultStride) {
}); });
b.Global("s", b.ty.Of(S), ast::StorageClass::kUniform, b.Global("s", b.ty.Of(S), ast::StorageClass::kUniform,
b.GroupAndBinding(0, 0)); b.GroupAndBinding(0, 0));
b.Func( b.Func("f", {}, b.ty.void_(),
"f", {}, b.ty.void_(), {
{ b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
b.Decl(b.Const("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))), },
}, {
{ b.Stage(ast::PipelineStage::kCompute),
b.Stage(ast::PipelineStage::kCompute), b.WorkgroupSize(1),
b.WorkgroupSize(1), });
});
auto* expect = R"( auto* expect = R"(
struct S { struct S {
@ -255,15 +253,14 @@ TEST_F(DecomposeStridedMatrixTest, ReadStorageMatrix) {
}); });
b.Global("s", b.ty.Of(S), ast::StorageClass::kStorage, b.Global("s", b.ty.Of(S), ast::StorageClass::kStorage,
ast::Access::kReadWrite, b.GroupAndBinding(0, 0)); ast::Access::kReadWrite, b.GroupAndBinding(0, 0));
b.Func( b.Func("f", {}, b.ty.void_(),
"f", {}, b.ty.void_(), {
{ b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
b.Decl(b.Const("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))), },
}, {
{ b.Stage(ast::PipelineStage::kCompute),
b.Stage(ast::PipelineStage::kCompute), b.WorkgroupSize(1),
b.WorkgroupSize(1), });
});
auto* expect = R"( auto* expect = R"(
struct S { struct S {
@ -318,8 +315,8 @@ TEST_F(DecomposeStridedMatrixTest, ReadStorageColumn) {
ast::Access::kReadWrite, b.GroupAndBinding(0, 0)); ast::Access::kReadWrite, b.GroupAndBinding(0, 0));
b.Func("f", {}, b.ty.void_(), b.Func("f", {}, b.ty.void_(),
{ {
b.Decl(b.Const("x", b.ty.vec2<f32>(), b.Decl(b.Let("x", b.ty.vec2<f32>(),
b.IndexAccessor(b.MemberAccessor("s", "m"), 1))), b.IndexAccessor(b.MemberAccessor("s", "m"), 1))),
}, },
{ {
b.Stage(ast::PipelineStage::kCompute), b.Stage(ast::PipelineStage::kCompute),
@ -501,13 +498,12 @@ TEST_F(DecomposeStridedMatrixTest, ReadWriteViaPointerLets) {
b.Func( b.Func(
"f", {}, b.ty.void_(), "f", {}, b.ty.void_(),
{ {
b.Decl( b.Decl(b.Let("a", nullptr, b.AddressOf(b.MemberAccessor("s", "m")))),
b.Const("a", nullptr, b.AddressOf(b.MemberAccessor("s", "m")))), b.Decl(b.Let("b", nullptr,
b.Decl(b.Const("b", nullptr, b.AddressOf(b.Deref(b.AddressOf(b.Deref("a")))))),
b.AddressOf(b.Deref(b.AddressOf(b.Deref("a")))))), b.Decl(b.Let("x", nullptr, b.Deref("b"))),
b.Decl(b.Const("x", nullptr, b.Deref("b"))), b.Decl(b.Let("y", nullptr, b.IndexAccessor(b.Deref("b"), 1))),
b.Decl(b.Const("y", nullptr, b.IndexAccessor(b.Deref("b"), 1))), b.Decl(b.Let("z", nullptr, b.IndexAccessor("x", 1))),
b.Decl(b.Const("z", nullptr, b.IndexAccessor("x", 1))),
b.Assign(b.Deref("b"), b.mat2x2<f32>(b.vec2<f32>(1.0f, 2.0f), b.Assign(b.Deref("b"), b.mat2x2<f32>(b.vec2<f32>(1.0f, 2.0f),
b.vec2<f32>(3.0f, 4.0f))), b.vec2<f32>(3.0f, 4.0f))),
b.Assign(b.IndexAccessor(b.Deref("b"), 1), b.vec2<f32>(5.0f, 6.0f)), b.Assign(b.IndexAccessor(b.Deref("b"), 1), b.vec2<f32>(5.0f, 6.0f)),
@ -575,15 +571,14 @@ TEST_F(DecomposeStridedMatrixTest, ReadPrivateMatrix) {
}), }),
}); });
b.Global("s", b.ty.Of(S), ast::StorageClass::kPrivate); b.Global("s", b.ty.Of(S), ast::StorageClass::kPrivate);
b.Func( b.Func("f", {}, b.ty.void_(),
"f", {}, b.ty.void_(), {
{ b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
b.Decl(b.Const("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))), },
}, {
{ b.Stage(ast::PipelineStage::kCompute),
b.Stage(ast::PipelineStage::kCompute), b.WorkgroupSize(1),
b.WorkgroupSize(1), });
});
auto* expect = R"( auto* expect = R"(
struct S { struct S {

View File

@ -83,7 +83,7 @@ class State {
auto hoist_pointer_to = [&](const ast::Expression* expr) { auto hoist_pointer_to = [&](const ast::Expression* expr) {
auto name = b.Sym(); auto name = b.Sym();
auto* ptr = b.AddressOf(ctx.Clone(expr)); auto* ptr = b.AddressOf(ctx.Clone(expr));
auto* decl = b.Decl(b.Const(name, nullptr, ptr)); auto* decl = b.Decl(b.Let(name, nullptr, ptr));
hoist_to_decl_before.InsertBefore(ctx.src->Sem().Get(stmt), decl); hoist_to_decl_before.InsertBefore(ctx.src->Sem().Get(stmt), decl);
return name; return name;
}; };
@ -91,7 +91,7 @@ class State {
// Helper function to hoist `expr` to a let declaration. // Helper function to hoist `expr` to a let declaration.
auto hoist_expr_to_let = [&](const ast::Expression* expr) { auto hoist_expr_to_let = [&](const ast::Expression* expr) {
auto name = b.Sym(); auto name = b.Sym();
auto* decl = b.Decl(b.Const(name, nullptr, ctx.Clone(expr))); auto* decl = b.Decl(b.Let(name, nullptr, ctx.Clone(expr)));
hoist_to_decl_before.InsertBefore(ctx.src->Sem().Get(stmt), decl); hoist_to_decl_before.InsertBefore(ctx.src->Sem().Get(stmt), decl);
return name; return name;
}; };

View File

@ -162,7 +162,7 @@ class LocalizeStructArrayAssignment::State {
// the value twice e.g. let tint_symbol = &(s.a1); // the value twice e.g. let tint_symbol = &(s.a1);
auto mem_access_ptr = b.Sym(); auto mem_access_ptr = b.Sym();
s.insert_before_stmts.push_back( s.insert_before_stmts.push_back(
b.Decl(b.Const(mem_access_ptr, nullptr, b.AddressOf(mem_access)))); b.Decl(b.Let(mem_access_ptr, nullptr, b.AddressOf(mem_access))));
// Disable further transforms when cloning // Disable further transforms when cloning
TINT_SCOPED_ASSIGNMENT(s.process_nested_nodes, false); TINT_SCOPED_ASSIGNMENT(s.process_nested_nodes, false);

View File

@ -241,10 +241,10 @@ struct ModuleScopeVarToEntryPointParam::State {
auto* member_ptr = ctx.dst->AddressOf(ctx.dst->MemberAccessor( auto* member_ptr = ctx.dst->AddressOf(ctx.dst->MemberAccessor(
ctx.dst->Deref(workgroup_param()), member)); ctx.dst->Deref(workgroup_param()), member));
auto* local_var = auto* local_var =
ctx.dst->Const(new_var_symbol, ctx.dst->Let(new_var_symbol,
ctx.dst->ty.pointer( ctx.dst->ty.pointer(store_type(),
store_type(), ast::StorageClass::kWorkgroup), ast::StorageClass::kWorkgroup),
member_ptr); member_ptr);
ctx.InsertFront(func_ast->body->statements, ctx.InsertFront(func_ast->body->statements,
ctx.dst->Decl(local_var)); ctx.dst->Decl(local_var));
is_pointer = true; is_pointer = true;

View File

@ -441,7 +441,7 @@ class DecomposeSideEffects::DecomposeState : public StateBase {
[&](const ast::Expression* e) -> const ast::Expression* { [&](const ast::Expression* e) -> const ast::Expression* {
if (to_hoist.count(e)) { if (to_hoist.count(e)) {
auto name = b.Symbols().New(); auto name = b.Symbols().New();
auto* v = b.Const(name, nullptr, ctx.Clone(e)); auto* v = b.Let(name, nullptr, ctx.Clone(e));
auto* decl = b.Decl(v); auto* decl = b.Decl(v);
curr_stmts->push_back(decl); curr_stmts->push_back(decl);
return b.Expr(name); return b.Expr(name);

View File

@ -184,7 +184,7 @@ struct SimplifyPointers::State {
ctx.src->Symbols().NameFor(var->Declaration()->symbol) + ctx.src->Symbols().NameFor(var->Declaration()->symbol) +
"_save"); "_save");
auto* decl = ctx.dst->Decl( auto* decl = ctx.dst->Decl(
ctx.dst->Const(saved_name, nullptr, ctx.Clone(idx_expr))); ctx.dst->Let(saved_name, nullptr, ctx.Clone(idx_expr)));
saved.emplace_back(decl); saved.emplace_back(decl);
// Record the substitution of `idx_expr` to the saved variable // Record the substitution of `idx_expr` to the saved variable
// with the symbol `saved_name`. This will be used by the // with the symbol `saved_name`. This will be used by the

View File

@ -211,7 +211,7 @@ class HoistToDeclBefore::State {
auto name = b.Symbols().New(decl_name); auto name = b.Symbols().New(decl_name);
// Construct the let/var that holds the hoisted expr // Construct the let/var that holds the hoisted expr
auto* v = as_const ? b.Const(name, nullptr, ctx.Clone(expr)) auto* v = as_const ? b.Let(name, nullptr, ctx.Clone(expr))
: b.Var(name, nullptr, ctx.Clone(expr)); : b.Var(name, nullptr, ctx.Clone(expr));
auto* decl = b.Decl(v); auto* decl = b.Decl(v);

View File

@ -310,7 +310,7 @@ struct State {
// let pulling_offset_n = <attribute_offset> // let pulling_offset_n = <attribute_offset>
stmts.emplace_back(ctx.dst->Decl( stmts.emplace_back(ctx.dst->Decl(
ctx.dst->Const(buffer_array_base, nullptr, attribute_offset))); ctx.dst->Let(buffer_array_base, nullptr, attribute_offset)));
for (const VertexAttributeDescriptor& attribute_desc : for (const VertexAttributeDescriptor& attribute_desc :
buffer_layout.attributes) { buffer_layout.attributes) {

View File

@ -351,7 +351,7 @@ struct ZeroInitWorkgroupMemory::State {
ast::BinaryOp::kModulo, iteration(), b.Expr(index.modulo)) ast::BinaryOp::kModulo, iteration(), b.Expr(index.modulo))
: iteration(); : iteration();
auto* div = (index.division != 1u) ? b.Div(mod, index.division) : mod; auto* div = (index.division != 1u) ? b.Div(mod, index.division) : mod;
auto* decl = b.Decl(b.Const(name, b.ty.u32(), div)); auto* decl = b.Decl(b.Let(name, b.ty.u32(), div));
stmts.emplace_back(decl); stmts.emplace_back(decl);
} }
return stmts; return stmts;

View File

@ -206,9 +206,9 @@ TEST_F(GlslGeneratorImplTest_Function,
Func("frag_main", {Param("inputs", ty.Of(interface_struct))}, ty.void_(), Func("frag_main", {Param("inputs", ty.Of(interface_struct))}, ty.void_(),
{ {
Decl(Const("r", ty.f32(), MemberAccessor("inputs", "col1"))), Decl(Let("r", ty.f32(), MemberAccessor("inputs", "col1"))),
Decl(Const("g", ty.f32(), MemberAccessor("inputs", "col2"))), Decl(Let("g", ty.f32(), MemberAccessor("inputs", "col2"))),
Decl(Const("p", ty.vec4<f32>(), MemberAccessor("inputs", "pos"))), Decl(Let("p", ty.vec4<f32>(), MemberAccessor("inputs", "pos"))),
}, },
{Stage(ast::PipelineStage::kFragment)}); {Stage(ast::PipelineStage::kFragment)});

View File

@ -21,7 +21,7 @@ namespace {
using GlslGeneratorImplTest_ModuleConstant = TestHelper; using GlslGeneratorImplTest_ModuleConstant = TestHelper;
TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_ModuleConstant) { TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_ModuleConstant) {
auto* var = Const("pos", ty.array<f32, 3>(), array<f32, 3>(1.f, 2.f, 3.f)); auto* var = Let("pos", ty.array<f32, 3>(), array<f32, 3>(1.f, 2.f, 3.f));
WrapInFunction(Decl(var)); WrapInFunction(Decl(var));
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -115,8 +115,8 @@ TEST_F(GlslSanitizerTest, Call_ArrayLength_ViaLets) {
create<ast::GroupAttribute>(2), create<ast::GroupAttribute>(2),
}); });
auto* p = Const("p", nullptr, AddressOf("b")); auto* p = Let("p", nullptr, AddressOf("b"));
auto* p2 = Const("p2", nullptr, AddressOf(MemberAccessor(Deref(p), "a"))); auto* p2 = Let("p2", nullptr, AddressOf(MemberAccessor(Deref(p), "a")));
Func("a_func", ast::VariableList{}, ty.void_(), Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
@ -239,7 +239,7 @@ TEST_F(GlslSanitizerTest, InlinePtrLetsBasic) {
// let x : i32 = *p; // let x : i32 = *p;
auto* v = Var("v", ty.i32()); auto* v = Var("v", ty.i32());
auto* p = auto* p =
Const("p", ty.pointer<i32>(ast::StorageClass::kFunction), AddressOf(v)); Let("p", ty.pointer<i32>(ast::StorageClass::kFunction), AddressOf(v));
auto* x = Var("x", ty.i32(), ast::StorageClass::kNone, Deref(p)); auto* x = Var("x", ty.i32(), ast::StorageClass::kNone, Deref(p));
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),
@ -280,16 +280,15 @@ TEST_F(GlslSanitizerTest, InlinePtrLetsComplexChain) {
// let vp : ptr<function, vec4<f32>> = &(*mp)[2]; // let vp : ptr<function, vec4<f32>> = &(*mp)[2];
// let v : vec4<f32> = *vp; // let v : vec4<f32> = *vp;
auto* a = Var("a", ty.array(ty.mat4x4<f32>(), 4)); auto* a = Var("a", ty.array(ty.mat4x4<f32>(), 4));
auto* ap = Const( auto* ap = Let(
"ap", "ap",
ty.pointer(ty.array(ty.mat4x4<f32>(), 4), ast::StorageClass::kFunction), ty.pointer(ty.array(ty.mat4x4<f32>(), 4), ast::StorageClass::kFunction),
AddressOf(a)); AddressOf(a));
auto* mp = auto* mp =
Const("mp", ty.pointer(ty.mat4x4<f32>(), ast::StorageClass::kFunction), Let("mp", ty.pointer(ty.mat4x4<f32>(), ast::StorageClass::kFunction),
AddressOf(IndexAccessor(Deref(ap), 3))); AddressOf(IndexAccessor(Deref(ap), 3)));
auto* vp = auto* vp = Let("vp", ty.pointer(ty.vec4<f32>(), ast::StorageClass::kFunction),
Const("vp", ty.pointer(ty.vec4<f32>(), ast::StorageClass::kFunction), AddressOf(IndexAccessor(Deref(mp), 2)));
AddressOf(IndexAccessor(Deref(mp), 2)));
auto* v = Var("v", ty.vec4<f32>(), ast::StorageClass::kNone, Deref(vp)); auto* v = Var("v", ty.vec4<f32>(), ast::StorageClass::kNone, Deref(vp));
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),

View File

@ -47,9 +47,9 @@ TEST_F(GlslUnaryOpTest, Complement) {
TEST_F(GlslUnaryOpTest, Indirection) { TEST_F(GlslUnaryOpTest, Indirection) {
Global("G", ty.f32(), ast::StorageClass::kPrivate); Global("G", ty.f32(), ast::StorageClass::kPrivate);
auto* p = Const( auto* p =
"expr", nullptr, Let("expr", nullptr,
create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, Expr("G"))); create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, Expr("G")));
auto* op = auto* op =
create<ast::UnaryOpExpression>(ast::UnaryOp::kIndirection, Expr("expr")); create<ast::UnaryOpExpression>(ast::UnaryOp::kIndirection, Expr("expr"));
WrapInFunction(p, op); WrapInFunction(p, op);

View File

@ -37,7 +37,7 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) {
} }
TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) { TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) {
auto* var = Const("a", ty.f32(), Construct(ty.f32())); auto* var = Let("a", ty.f32(), Construct(ty.f32()));
auto* stmt = Decl(var); auto* stmt = Decl(var);
WrapInFunction(stmt); WrapInFunction(stmt);

View File

@ -44,7 +44,7 @@ TEST_F(HlslGeneratorImplTest_Assign, Emit_Vector_Assign_ConstantIndex) {
{ {
Decl(Var("lhs", ty.vec3<f32>())), Decl(Var("lhs", ty.vec3<f32>())),
Decl(Var("rhs", ty.f32())), Decl(Var("rhs", ty.f32())),
Decl(Const("index", ty.u32(), Expr(0u))), Decl(Let("index", ty.u32(), Expr(0u))),
Assign(IndexAccessor("lhs", "index"), "rhs"), Assign(IndexAccessor("lhs", "index"), "rhs"),
}); });
@ -92,7 +92,7 @@ TEST_F(HlslGeneratorImplTest_Assign, Emit_Matrix_Assign_Vector_ConstantIndex) {
{ {
Decl(Var("lhs", ty.mat4x2<f32>())), Decl(Var("lhs", ty.mat4x2<f32>())),
Decl(Var("rhs", ty.vec2<f32>())), Decl(Var("rhs", ty.vec2<f32>())),
Decl(Const("index", ty.u32(), Expr(0u))), Decl(Let("index", ty.u32(), Expr(0u))),
Assign(IndexAccessor("lhs", "index"), "rhs"), Assign(IndexAccessor("lhs", "index"), "rhs"),
}); });
@ -146,7 +146,7 @@ TEST_F(HlslGeneratorImplTest_Assign, Emit_Matrix_Assign_Scalar_ConstantIndex) {
{ {
Decl(Var("lhs", ty.mat4x2<f32>())), Decl(Var("lhs", ty.mat4x2<f32>())),
Decl(Var("rhs", ty.f32())), Decl(Var("rhs", ty.f32())),
Decl(Const("index", ty.u32(), Expr(0u))), Decl(Let("index", ty.u32(), Expr(0u))),
Assign(IndexAccessor(IndexAccessor("lhs", "index"), "index"), "rhs"), Assign(IndexAccessor(IndexAccessor("lhs", "index"), "index"), "rhs"),
}); });

View File

@ -555,7 +555,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByLiteralZero_i32) {
Func("fn", {}, ty.void_(), Func("fn", {}, ty.void_(),
{ {
Decl(Var("a", ty.i32())), Decl(Var("a", ty.i32())),
Decl(Const("r", nullptr, Op("a", 0))), Decl(Let("r", nullptr, Op("a", 0))),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -573,7 +573,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByLiteralZero_u32) {
Func("fn", {}, ty.void_(), Func("fn", {}, ty.void_(),
{ {
Decl(Var("a", ty.u32())), Decl(Var("a", ty.u32())),
Decl(Const("r", nullptr, Op("a", 0u))), Decl(Let("r", nullptr, Op("a", 0u))),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -591,7 +591,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByLiteralZero_vec_by_vec_i32) {
Func("fn", {}, ty.void_(), Func("fn", {}, ty.void_(),
{ {
Decl(Var("a", nullptr, vec4<i32>(100, 100, 100, 100))), Decl(Var("a", nullptr, vec4<i32>(100, 100, 100, 100))),
Decl(Const("r", nullptr, Op("a", vec4<i32>(50, 0, 25, 0)))), Decl(Let("r", nullptr, Op("a", vec4<i32>(50, 0, 25, 0)))),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -609,7 +609,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByLiteralZero_vec_by_scalar_i32) {
Func("fn", {}, ty.void_(), Func("fn", {}, ty.void_(),
{ {
Decl(Var("a", nullptr, vec4<i32>(100, 100, 100, 100))), Decl(Var("a", nullptr, vec4<i32>(100, 100, 100, 100))),
Decl(Const("r", nullptr, Op("a", 0))), Decl(Let("r", nullptr, Op("a", 0))),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -627,7 +627,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByIdentifier_i32) {
Func("fn", {Param("b", ty.i32())}, ty.void_(), Func("fn", {Param("b", ty.i32())}, ty.void_(),
{ {
Decl(Var("a", ty.i32())), Decl(Var("a", ty.i32())),
Decl(Const("r", nullptr, Op("a", "b"))), Decl(Let("r", nullptr, Op("a", "b"))),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -645,7 +645,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByIdentifier_u32) {
Func("fn", {Param("b", ty.u32())}, ty.void_(), Func("fn", {Param("b", ty.u32())}, ty.void_(),
{ {
Decl(Var("a", ty.u32())), Decl(Var("a", ty.u32())),
Decl(Const("r", nullptr, Op("a", "b"))), Decl(Let("r", nullptr, Op("a", "b"))),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -663,7 +663,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByIdentifier_vec_by_vec_i32) {
Func("fn", {Param("b", ty.vec3<i32>())}, ty.void_(), Func("fn", {Param("b", ty.vec3<i32>())}, ty.void_(),
{ {
Decl(Var("a", ty.vec3<i32>())), Decl(Var("a", ty.vec3<i32>())),
Decl(Const("r", nullptr, Op("a", "b"))), Decl(Let("r", nullptr, Op("a", "b"))),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -681,7 +681,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByIdentifier_vec_by_scalar_i32) {
Func("fn", {Param("b", ty.i32())}, ty.void_(), Func("fn", {Param("b", ty.i32())}, ty.void_(),
{ {
Decl(Var("a", ty.vec3<i32>())), Decl(Var("a", ty.vec3<i32>())),
Decl(Const("r", nullptr, Op("a", "b"))), Decl(Let("r", nullptr, Op("a", "b"))),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -704,7 +704,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByExpression_i32) {
Func("fn", {}, ty.void_(), Func("fn", {}, ty.void_(),
{ {
Decl(Var("a", ty.i32())), Decl(Var("a", ty.i32())),
Decl(Const("r", nullptr, Op("a", Call("zero")))), Decl(Let("r", nullptr, Op("a", Call("zero")))),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -735,7 +735,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByExpression_u32) {
Func("fn", {}, ty.void_(), Func("fn", {}, ty.void_(),
{ {
Decl(Var("a", ty.u32())), Decl(Var("a", ty.u32())),
Decl(Const("r", nullptr, Op("a", Call("zero")))), Decl(Let("r", nullptr, Op("a", Call("zero")))),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -766,7 +766,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByExpression_vec_by_vec_i32) {
Func("fn", {}, ty.void_(), Func("fn", {}, ty.void_(),
{ {
Decl(Var("a", ty.vec3<i32>())), Decl(Var("a", ty.vec3<i32>())),
Decl(Const("r", nullptr, Op("a", Call("zero")))), Decl(Let("r", nullptr, Op("a", Call("zero")))),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -797,7 +797,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByExpression_vec_by_scalar_i32) {
Func("fn", {}, ty.void_(), Func("fn", {}, ty.void_(),
{ {
Decl(Var("a", ty.vec3<i32>())), Decl(Var("a", ty.vec3<i32>())),
Decl(Const("r", nullptr, Op("a", Call("zero")))), Decl(Let("r", nullptr, Op("a", Call("zero")))),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -205,9 +205,9 @@ TEST_F(HlslGeneratorImplTest_Function,
Func("frag_main", {Param("inputs", ty.Of(interface_struct))}, ty.void_(), Func("frag_main", {Param("inputs", ty.Of(interface_struct))}, ty.void_(),
{ {
Decl(Const("r", ty.f32(), MemberAccessor("inputs", "col1"))), Decl(Let("r", ty.f32(), MemberAccessor("inputs", "col1"))),
Decl(Const("g", ty.f32(), MemberAccessor("inputs", "col2"))), Decl(Let("g", ty.f32(), MemberAccessor("inputs", "col2"))),
Decl(Const("p", ty.vec4<f32>(), MemberAccessor("inputs", "pos"))), Decl(Let("p", ty.vec4<f32>(), MemberAccessor("inputs", "pos"))),
}, },
{Stage(ast::PipelineStage::kFragment)}); {Stage(ast::PipelineStage::kFragment)});

View File

@ -21,7 +21,7 @@ namespace {
using HlslGeneratorImplTest_ModuleConstant = TestHelper; using HlslGeneratorImplTest_ModuleConstant = TestHelper;
TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_ModuleConstant) { TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_ModuleConstant) {
auto* var = Const("pos", ty.array<f32, 3>(), array<f32, 3>(1.f, 2.f, 3.f)); auto* var = Let("pos", ty.array<f32, 3>(), array<f32, 3>(1.f, 2.f, 3.f));
WrapInFunction(Decl(var)); WrapInFunction(Decl(var));
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -104,8 +104,8 @@ TEST_F(HlslSanitizerTest, Call_ArrayLength_ViaLets) {
create<ast::GroupAttribute>(2), create<ast::GroupAttribute>(2),
}); });
auto* p = Const("p", nullptr, AddressOf("b")); auto* p = Let("p", nullptr, AddressOf("b"));
auto* p2 = Const("p2", nullptr, AddressOf(MemberAccessor(Deref(p), "a"))); auto* p2 = Let("p2", nullptr, AddressOf(MemberAccessor(Deref(p), "a")));
Func("a_func", ast::VariableList{}, ty.void_(), Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
@ -259,7 +259,7 @@ TEST_F(HlslSanitizerTest, InlinePtrLetsBasic) {
// let x : i32 = *p; // let x : i32 = *p;
auto* v = Var("v", ty.i32()); auto* v = Var("v", ty.i32());
auto* p = auto* p =
Const("p", ty.pointer<i32>(ast::StorageClass::kFunction), AddressOf(v)); Let("p", ty.pointer<i32>(ast::StorageClass::kFunction), AddressOf(v));
auto* x = Var("x", ty.i32(), ast::StorageClass::kNone, Deref(p)); auto* x = Var("x", ty.i32(), ast::StorageClass::kNone, Deref(p));
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),
@ -293,16 +293,15 @@ TEST_F(HlslSanitizerTest, InlinePtrLetsComplexChain) {
// let vp : ptr<function, vec4<f32>> = &(*mp)[2]; // let vp : ptr<function, vec4<f32>> = &(*mp)[2];
// let v : vec4<f32> = *vp; // let v : vec4<f32> = *vp;
auto* a = Var("a", ty.array(ty.mat4x4<f32>(), 4)); auto* a = Var("a", ty.array(ty.mat4x4<f32>(), 4));
auto* ap = Const( auto* ap = Let(
"ap", "ap",
ty.pointer(ty.array(ty.mat4x4<f32>(), 4), ast::StorageClass::kFunction), ty.pointer(ty.array(ty.mat4x4<f32>(), 4), ast::StorageClass::kFunction),
AddressOf(a)); AddressOf(a));
auto* mp = auto* mp =
Const("mp", ty.pointer(ty.mat4x4<f32>(), ast::StorageClass::kFunction), Let("mp", ty.pointer(ty.mat4x4<f32>(), ast::StorageClass::kFunction),
AddressOf(IndexAccessor(Deref(ap), 3))); AddressOf(IndexAccessor(Deref(ap), 3)));
auto* vp = auto* vp = Let("vp", ty.pointer(ty.vec4<f32>(), ast::StorageClass::kFunction),
Const("vp", ty.pointer(ty.vec4<f32>(), ast::StorageClass::kFunction), AddressOf(IndexAccessor(Deref(mp), 2)));
AddressOf(IndexAccessor(Deref(mp), 2)));
auto* v = Var("v", ty.vec4<f32>(), ast::StorageClass::kNone, Deref(vp)); auto* v = Var("v", ty.vec4<f32>(), ast::StorageClass::kNone, Deref(vp));
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),

View File

@ -47,9 +47,9 @@ TEST_F(HlslUnaryOpTest, Complement) {
TEST_F(HlslUnaryOpTest, Indirection) { TEST_F(HlslUnaryOpTest, Indirection) {
Global("G", ty.f32(), ast::StorageClass::kPrivate); Global("G", ty.f32(), ast::StorageClass::kPrivate);
auto* p = Const( auto* p =
"expr", nullptr, Let("expr", nullptr,
create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, Expr("G"))); create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, Expr("G")));
auto* op = auto* op =
create<ast::UnaryOpExpression>(ast::UnaryOp::kIndirection, Expr("expr")); create<ast::UnaryOpExpression>(ast::UnaryOp::kIndirection, Expr("expr"));
WrapInFunction(p, op); WrapInFunction(p, op);

View File

@ -37,7 +37,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) {
} }
TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) { TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) {
auto* var = Const("a", ty.f32(), Construct(ty.f32())); auto* var = Let("a", ty.f32(), Construct(ty.f32()));
auto* stmt = Decl(var); auto* stmt = Decl(var);
WrapInFunction(stmt); WrapInFunction(stmt);

View File

@ -34,7 +34,7 @@ TEST_F(MslGeneratorImplTest, IndexAccessor) {
TEST_F(MslGeneratorImplTest, IndexAccessor_OfDref) { TEST_F(MslGeneratorImplTest, IndexAccessor_OfDref) {
Global("ary", ty.array<i32, 10>(), ast::StorageClass::kPrivate); Global("ary", ty.array<i32, 10>(), ast::StorageClass::kPrivate);
auto* p = Const("p", nullptr, AddressOf("ary")); auto* p = Let("p", nullptr, AddressOf("ary"));
auto* expr = IndexAccessor(Deref("p"), 5); auto* expr = IndexAccessor(Deref("p"), 5);
WrapInFunction(p, expr); WrapInFunction(p, expr);

View File

@ -185,14 +185,13 @@ TEST_F(MslGeneratorImplTest,
Construct(ty.vec4<f32>())))}, Construct(ty.vec4<f32>())))},
{Stage(ast::PipelineStage::kVertex)}); {Stage(ast::PipelineStage::kVertex)});
Func("frag_main", {Param("colors", ty.Of(interface_struct))}, ty.void_(), Func(
{ "frag_main", {Param("colors", ty.Of(interface_struct))}, ty.void_(),
WrapInStatement( {
Const("r", ty.f32(), MemberAccessor("colors", "col1"))), WrapInStatement(Let("r", ty.f32(), MemberAccessor("colors", "col1"))),
WrapInStatement( WrapInStatement(Let("g", ty.f32(), MemberAccessor("colors", "col2"))),
Const("g", ty.f32(), MemberAccessor("colors", "col2"))), },
}, {Stage(ast::PipelineStage::kFragment)});
{Stage(ast::PipelineStage::kFragment)});
GeneratorImpl& gen = SanitizeAndBuild(); GeneratorImpl& gen = SanitizeAndBuild();

View File

@ -122,8 +122,8 @@ TEST_F(MslSanitizerTest, Call_ArrayLength_ViaLets) {
create<ast::GroupAttribute>(2), create<ast::GroupAttribute>(2),
}); });
auto* p = Const("p", nullptr, AddressOf("b")); auto* p = Let("p", nullptr, AddressOf("b"));
auto* p2 = Const("p2", nullptr, AddressOf(MemberAccessor(Deref(p), "a"))); auto* p2 = Let("p2", nullptr, AddressOf(MemberAccessor(Deref(p), "a")));
Func("a_func", ast::VariableList{}, ty.void_(), Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{

View File

@ -138,7 +138,7 @@ vertex Out vert_main() {
TEST_F(MslGeneratorImplTest, WorkgroupMatrix) { TEST_F(MslGeneratorImplTest, WorkgroupMatrix) {
Global("m", ty.mat2x2<f32>(), ast::StorageClass::kWorkgroup); Global("m", ty.mat2x2<f32>(), ast::StorageClass::kWorkgroup);
Func("comp_main", ast::VariableList{}, ty.void_(), Func("comp_main", ast::VariableList{}, ty.void_(),
{Decl(Const("x", nullptr, Expr("m")))}, {Decl(Let("x", nullptr, Expr("m")))},
{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)}); {Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)});
GeneratorImpl& gen = SanitizeAndBuild(); GeneratorImpl& gen = SanitizeAndBuild();
@ -176,7 +176,7 @@ kernel void comp_main(threadgroup tint_symbol_3* tint_symbol_2 [[threadgroup(0)]
TEST_F(MslGeneratorImplTest, WorkgroupMatrixInArray) { TEST_F(MslGeneratorImplTest, WorkgroupMatrixInArray) {
Global("m", ty.array(ty.mat2x2<f32>(), 4), ast::StorageClass::kWorkgroup); Global("m", ty.array(ty.mat2x2<f32>(), 4), ast::StorageClass::kWorkgroup);
Func("comp_main", ast::VariableList{}, ty.void_(), Func("comp_main", ast::VariableList{}, ty.void_(),
{Decl(Const("x", nullptr, Expr("m")))}, {Decl(Let("x", nullptr, Expr("m")))},
{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)}); {Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)});
GeneratorImpl& gen = SanitizeAndBuild(); GeneratorImpl& gen = SanitizeAndBuild();
@ -226,7 +226,7 @@ TEST_F(MslGeneratorImplTest, WorkgroupMatrixInStruct) {
}); });
Global("s", ty.type_name("S2"), ast::StorageClass::kWorkgroup); Global("s", ty.type_name("S2"), ast::StorageClass::kWorkgroup);
Func("comp_main", ast::VariableList{}, ty.void_(), Func("comp_main", ast::VariableList{}, ty.void_(),
{Decl(Const("x", nullptr, Expr("s")))}, {Decl(Let("x", nullptr, Expr("s")))},
{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)}); {Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)});
GeneratorImpl& gen = SanitizeAndBuild(); GeneratorImpl& gen = SanitizeAndBuild();
@ -284,23 +284,23 @@ TEST_F(MslGeneratorImplTest, WorkgroupMatrix_Multiples) {
Global("m9", ty.mat4x4<f32>(), ast::StorageClass::kWorkgroup); Global("m9", ty.mat4x4<f32>(), ast::StorageClass::kWorkgroup);
Func("main1", ast::VariableList{}, ty.void_(), Func("main1", ast::VariableList{}, ty.void_(),
{ {
Decl(Const("a1", nullptr, Expr("m1"))), Decl(Let("a1", nullptr, Expr("m1"))),
Decl(Const("a2", nullptr, Expr("m2"))), Decl(Let("a2", nullptr, Expr("m2"))),
Decl(Const("a3", nullptr, Expr("m3"))), Decl(Let("a3", nullptr, Expr("m3"))),
}, },
{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)}); {Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)});
Func("main2", ast::VariableList{}, ty.void_(), Func("main2", ast::VariableList{}, ty.void_(),
{ {
Decl(Const("a1", nullptr, Expr("m4"))), Decl(Let("a1", nullptr, Expr("m4"))),
Decl(Const("a2", nullptr, Expr("m5"))), Decl(Let("a2", nullptr, Expr("m5"))),
Decl(Const("a3", nullptr, Expr("m6"))), Decl(Let("a3", nullptr, Expr("m6"))),
}, },
{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)}); {Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)});
Func("main3", ast::VariableList{}, ty.void_(), Func("main3", ast::VariableList{}, ty.void_(),
{ {
Decl(Const("a1", nullptr, Expr("m7"))), Decl(Let("a1", nullptr, Expr("m7"))),
Decl(Const("a2", nullptr, Expr("m8"))), Decl(Let("a2", nullptr, Expr("m8"))),
Decl(Const("a3", nullptr, Expr("m9"))), Decl(Let("a3", nullptr, Expr("m9"))),
}, },
{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)}); {Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)});
Func("main4_no_usages", ast::VariableList{}, ty.void_(), {}, Func("main4_no_usages", ast::VariableList{}, ty.void_(), {},

View File

@ -47,9 +47,9 @@ TEST_F(MslUnaryOpTest, Complement) {
TEST_F(MslUnaryOpTest, Indirection) { TEST_F(MslUnaryOpTest, Indirection) {
Global("G", ty.f32(), ast::StorageClass::kPrivate); Global("G", ty.f32(), ast::StorageClass::kPrivate);
auto* p = Const( auto* p =
"expr", nullptr, Let("expr", nullptr,
create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, Expr("G"))); create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, Expr("G")));
auto* op = auto* op =
create<ast::UnaryOpExpression>(ast::UnaryOp::kIndirection, Expr("expr")); create<ast::UnaryOpExpression>(ast::UnaryOp::kIndirection, Expr("expr"));
WrapInFunction(p, op); WrapInFunction(p, op);

View File

@ -37,7 +37,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) {
} }
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) { TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) {
auto* var = Const("a", ty.f32(), Construct(ty.f32())); auto* var = Let("a", ty.f32(), Construct(ty.f32()));
auto* stmt = Decl(var); auto* stmt = Decl(var);
WrapInFunction(stmt); WrapInFunction(stmt);

View File

@ -310,7 +310,7 @@ TEST_F(BuilderTest, MemberAccessor_NonPointer) {
Member("b", ty.f32()), Member("b", ty.f32()),
}); });
auto* var = Const("ident", ty.Of(s), Construct(ty.Of(s), 0.f, 0.f)); auto* var = Let("ident", ty.Of(s), Construct(ty.Of(s), 0.f, 0.f));
auto* expr = MemberAccessor("ident", "b"); auto* expr = MemberAccessor("ident", "b");
WrapInFunction(var, expr); WrapInFunction(var, expr);
@ -351,8 +351,8 @@ TEST_F(BuilderTest, MemberAccessor_Nested_NonPointer) {
auto* s_type = Structure("my_struct", {Member("inner", ty.Of(inner_struct))}); auto* s_type = Structure("my_struct", {Member("inner", ty.Of(inner_struct))});
auto* var = auto* var =
Const("ident", ty.Of(s_type), Let("ident", ty.Of(s_type),
Construct(ty.Of(s_type), Construct(ty.Of(inner_struct), 0.f, 0.f))); Construct(ty.Of(s_type), Construct(ty.Of(inner_struct), 0.f, 0.f)));
auto* expr = MemberAccessor(MemberAccessor("ident", "inner"), "b"); auto* expr = MemberAccessor(MemberAccessor("ident", "inner"), "b");
WrapInFunction(var, expr); WrapInFunction(var, expr);
@ -754,10 +754,9 @@ TEST_F(BuilderTest, IndexAccessor_Of_Vec) {
// vec2<f32>(0.5, -0.5)); // vec2<f32>(0.5, -0.5));
// pos[1] // pos[1]
auto* var = auto* var = Let("pos", ty.array(ty.vec2<f32>(), 3),
Const("pos", ty.array(ty.vec2<f32>(), 3), Construct(ty.array(ty.vec2<f32>(), 3), vec2<f32>(0.0f, 0.5f),
Construct(ty.array(ty.vec2<f32>(), 3), vec2<f32>(0.0f, 0.5f), vec2<f32>(-0.5f, -0.5f), vec2<f32>(0.5f, -0.5f)));
vec2<f32>(-0.5f, -0.5f), vec2<f32>(0.5f, -0.5f)));
auto* expr = IndexAccessor("pos", 1u); auto* expr = IndexAccessor("pos", 1u);
WrapInFunction(var, expr); WrapInFunction(var, expr);
@ -798,10 +797,9 @@ TEST_F(BuilderTest, IndexAccessor_Of_Array_Of_f32) {
// array<f32, 2>(0.5, -0.5)); // array<f32, 2>(0.5, -0.5));
// pos[2][1] // pos[2][1]
auto* var = auto* var = Let("pos", ty.array(ty.vec2<f32>(), 3),
Const("pos", ty.array(ty.vec2<f32>(), 3), Construct(ty.array(ty.vec2<f32>(), 3), vec2<f32>(0.0f, 0.5f),
Construct(ty.array(ty.vec2<f32>(), 3), vec2<f32>(0.0f, 0.5f), vec2<f32>(-0.5f, -0.5f), vec2<f32>(0.5f, -0.5f)));
vec2<f32>(-0.5f, -0.5f), vec2<f32>(0.5f, -0.5f)));
auto* expr = IndexAccessor(IndexAccessor("pos", 2u), 1u); auto* expr = IndexAccessor(IndexAccessor("pos", 2u), 1u);
WrapInFunction(var, expr); WrapInFunction(var, expr);
@ -841,7 +839,7 @@ TEST_F(BuilderTest, IndexAccessor_Vec_Literal) {
// let pos : vec2<f32> = vec2<f32>(0.0, 0.5); // let pos : vec2<f32> = vec2<f32>(0.0, 0.5);
// pos[1] // pos[1]
auto* var = Const("pos", ty.vec2<f32>(), vec2<f32>(0.0f, 0.5f)); auto* var = Let("pos", ty.vec2<f32>(), vec2<f32>(0.0f, 0.5f));
auto* expr = IndexAccessor("pos", 1u); auto* expr = IndexAccessor("pos", 1u);
WrapInFunction(var, expr); WrapInFunction(var, expr);
@ -871,7 +869,7 @@ TEST_F(BuilderTest, IndexAccessor_Vec_Dynamic) {
// idx : i32 // idx : i32
// pos[idx] // pos[idx]
auto* var = Const("pos", ty.vec2<f32>(), vec2<f32>(0.0f, 0.5f)); auto* var = Let("pos", ty.vec2<f32>(), vec2<f32>(0.0f, 0.5f));
auto* idx = Var("idx", ty.i32()); auto* idx = Var("idx", ty.i32());
auto* expr = IndexAccessor("pos", idx); auto* expr = IndexAccessor("pos", idx);
@ -906,8 +904,8 @@ TEST_F(BuilderTest, IndexAccessor_Array_Literal) {
// let a : array<f32, 3>; // let a : array<f32, 3>;
// a[2] // a[2]
auto* var = Const("a", ty.array<f32, 3>(), auto* var = Let("a", ty.array<f32, 3>(),
Construct(ty.array<f32, 3>(), 0.0f, 0.5f, 1.0f)); Construct(ty.array<f32, 3>(), 0.0f, 0.5f, 1.0f));
auto* expr = IndexAccessor("a", 2); auto* expr = IndexAccessor("a", 2);
WrapInFunction(var, expr); WrapInFunction(var, expr);
@ -942,8 +940,8 @@ TEST_F(BuilderTest, IndexAccessor_Array_Dynamic) {
// idx : i32 // idx : i32
// a[idx] // a[idx]
auto* var = Const("a", ty.array<f32, 3>(), auto* var = Let("a", ty.array<f32, 3>(),
Construct(ty.array<f32, 3>(), 0.0f, 0.5f, 1.0f)); Construct(ty.array<f32, 3>(), 0.0f, 0.5f, 1.0f));
auto* idx = Var("idx", ty.i32()); auto* idx = Var("idx", ty.i32());
auto* expr = IndexAccessor("a", idx); auto* expr = IndexAccessor("a", idx);
@ -992,9 +990,9 @@ TEST_F(BuilderTest, IndexAccessor_Matrix_Dynamic) {
// a[idx] // a[idx]
auto* var = auto* var =
Const("a", ty.mat2x2<f32>(), Let("a", ty.mat2x2<f32>(),
Construct(ty.mat2x2<f32>(), Construct(ty.vec2<f32>(), 1.f, 2.f), Construct(ty.mat2x2<f32>(), Construct(ty.vec2<f32>(), 1.f, 2.f),
Construct(ty.vec2<f32>(), 3.f, 4.f))); Construct(ty.vec2<f32>(), 3.f, 4.f)));
auto* idx = Var("idx", ty.i32()); auto* idx = Var("idx", ty.i32());
auto* expr = IndexAccessor("a", idx); auto* expr = IndexAccessor("a", idx);

View File

@ -1577,8 +1577,8 @@ TEST_F(BuiltinBuilderTest, Call_ArrayLength_ViaLets) {
create<ast::GroupAttribute>(2), create<ast::GroupAttribute>(2),
}); });
auto* p = Const("p", nullptr, AddressOf("b")); auto* p = Let("p", nullptr, AddressOf("b"));
auto* p2 = Const("p2", nullptr, AddressOf(MemberAccessor(Deref(p), "a"))); auto* p2 = Let("p2", nullptr, AddressOf(MemberAccessor(Deref(p), "a")));
auto* expr = Call("arrayLength", p2); auto* expr = Call("arrayLength", p2);
Func("a_func", {}, ty.void_(), Func("a_func", {}, ty.void_(),
@ -1637,9 +1637,9 @@ TEST_F(BuiltinBuilderTest, Call_ArrayLength_ViaLets_WithPtrNoise) {
create<ast::GroupAttribute>(2), create<ast::GroupAttribute>(2),
}); });
auto* p = Const("p", nullptr, AddressOf(Deref(AddressOf("b")))); auto* p = Let("p", nullptr, AddressOf(Deref(AddressOf("b"))));
auto* p2 = Const("p2", nullptr, AddressOf(Deref(p))); auto* p2 = Let("p2", nullptr, AddressOf(Deref(p)));
auto* p3 = Const("p3", nullptr, AddressOf(MemberAccessor(Deref(p2), "a"))); auto* p3 = Let("p3", nullptr, AddressOf(MemberAccessor(Deref(p2), "a")));
auto* expr = Call("arrayLength", AddressOf(Deref(p3))); auto* expr = Call("arrayLength", AddressOf(Deref(p3)));
Func("a_func", {}, ty.void_(), Func("a_func", {}, ty.void_(),
@ -1704,10 +1704,10 @@ TEST_F(BuiltinBuilderTest, Call_AtomicLoad) {
Func("a_func", {}, ty.void_(), Func("a_func", {}, ty.void_(),
ast::StatementList{ ast::StatementList{
Decl(Const("u", ty.u32(), Decl(Let("u", ty.u32(),
Call("atomicLoad", AddressOf(MemberAccessor("b", "u"))))), Call("atomicLoad", AddressOf(MemberAccessor("b", "u"))))),
Decl(Const("i", ty.i32(), Decl(Let("i", ty.i32(),
Call("atomicLoad", AddressOf(MemberAccessor("b", "i"))))), Call("atomicLoad", AddressOf(MemberAccessor("b", "i"))))),
}, },
ast::AttributeList{Stage(ast::PipelineStage::kFragment)}); ast::AttributeList{Stage(ast::PipelineStage::kFragment)});
@ -1845,9 +1845,9 @@ TEST_P(Builtin_Builtin_AtomicRMW_i32, Test) {
Func("a_func", {}, ty.void_(), Func("a_func", {}, ty.void_(),
ast::StatementList{ ast::StatementList{
Decl(Var("v", nullptr, Expr(10))), Decl(Var("v", nullptr, Expr(10))),
Decl(Const("x", ty.i32(), Decl(Let("x", ty.i32(),
Call(GetParam().name, AddressOf(MemberAccessor("b", "v")), Call(GetParam().name, AddressOf(MemberAccessor("b", "v")),
"v"))), "v"))),
}, },
ast::AttributeList{Stage(ast::PipelineStage::kFragment)}); ast::AttributeList{Stage(ast::PipelineStage::kFragment)});
@ -1920,9 +1920,9 @@ TEST_P(Builtin_Builtin_AtomicRMW_u32, Test) {
Func("a_func", {}, ty.void_(), Func("a_func", {}, ty.void_(),
ast::StatementList{ ast::StatementList{
Decl(Var("v", nullptr, Expr(10u))), Decl(Var("v", nullptr, Expr(10u))),
Decl(Const("x", ty.u32(), Decl(Let("x", ty.u32(),
Call(GetParam().name, AddressOf(MemberAccessor("b", "v")), Call(GetParam().name, AddressOf(MemberAccessor("b", "v")),
"v"))), "v"))),
}, },
ast::AttributeList{Stage(ast::PipelineStage::kFragment)}); ast::AttributeList{Stage(ast::PipelineStage::kFragment)});
@ -1998,12 +1998,12 @@ TEST_F(BuiltinBuilderTest, Call_AtomicExchange) {
ast::StatementList{ ast::StatementList{
Decl(Var("u", nullptr, Expr(10u))), Decl(Var("u", nullptr, Expr(10u))),
Decl(Var("i", nullptr, Expr(10))), Decl(Var("i", nullptr, Expr(10))),
Decl(Const("r", ty.u32(), Decl(Let("r", ty.u32(),
Call("atomicExchange", Call("atomicExchange", AddressOf(MemberAccessor("b", "u")),
AddressOf(MemberAccessor("b", "u")), "u"))), "u"))),
Decl(Const("s", ty.i32(), Decl(Let("s", ty.i32(),
Call("atomicExchange", Call("atomicExchange", AddressOf(MemberAccessor("b", "i")),
AddressOf(MemberAccessor("b", "i")), "i"))), "i"))),
}, },
ast::AttributeList{Stage(ast::PipelineStage::kFragment)}); ast::AttributeList{Stage(ast::PipelineStage::kFragment)});
@ -2074,12 +2074,12 @@ TEST_F(BuiltinBuilderTest, Call_AtomicCompareExchangeWeak) {
Func("a_func", {}, ty.void_(), Func("a_func", {}, ty.void_(),
ast::StatementList{ ast::StatementList{
Decl(Const("u", ty.vec2<u32>(), Decl(Let("u", ty.vec2<u32>(),
Call("atomicCompareExchangeWeak", Call("atomicCompareExchangeWeak",
AddressOf(MemberAccessor("b", "u")), 10u, 20u))), AddressOf(MemberAccessor("b", "u")), 10u, 20u))),
Decl(Const("i", ty.vec2<i32>(), Decl(Let("i", ty.vec2<i32>(),
Call("atomicCompareExchangeWeak", Call("atomicCompareExchangeWeak",
AddressOf(MemberAccessor("b", "i")), 10, 20))), AddressOf(MemberAccessor("b", "i")), 10, 20))),
}, },
ast::AttributeList{Stage(ast::PipelineStage::kFragment)}); ast::AttributeList{Stage(ast::PipelineStage::kFragment)});

View File

@ -174,7 +174,7 @@ OpStore %7 %6
TEST_F(BuilderTest, FunctionVar_Const) { TEST_F(BuilderTest, FunctionVar_Const) {
auto* init = vec3<f32>(1.f, 1.f, 3.f); auto* init = vec3<f32>(1.f, 1.f, 3.f);
auto* v = Const("var", ty.vec3<f32>(), init); auto* v = Let("var", ty.vec3<f32>(), init);
WrapInFunction(v); WrapInFunction(v);

View File

@ -67,7 +67,7 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalVar) {
TEST_F(BuilderTest, IdentifierExpression_FunctionConst) { TEST_F(BuilderTest, IdentifierExpression_FunctionConst) {
auto* init = vec3<f32>(1.f, 1.f, 3.f); auto* init = vec3<f32>(1.f, 1.f, 3.f);
auto* v = Const("var", ty.vec3<f32>(), init); auto* v = Let("var", ty.vec3<f32>(), init);
auto* expr = Expr("var"); auto* expr = Expr("var");
WrapInFunction(v, expr); WrapInFunction(v, expr);

View File

@ -34,7 +34,7 @@ TEST_F(WgslGeneratorImplTest, IndexAccessor) {
TEST_F(WgslGeneratorImplTest, IndexAccessor_OfDref) { TEST_F(WgslGeneratorImplTest, IndexAccessor_OfDref) {
Global("ary", ty.array<i32, 10>(), ast::StorageClass::kPrivate); Global("ary", ty.array<i32, 10>(), ast::StorageClass::kPrivate);
auto* p = Const("p", nullptr, AddressOf("ary")); auto* p = Let("p", nullptr, AddressOf("ary"));
auto* expr = IndexAccessor(Deref("p"), 5); auto* expr = IndexAccessor(Deref("p"), 5);
WrapInFunction(p, expr); WrapInFunction(p, expr);

View File

@ -37,7 +37,7 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_MemberAccessor_OfDref) {
auto* s = Structure("Data", {Member("mem", ty.f32())}); auto* s = Structure("Data", {Member("mem", ty.f32())});
Global("str", ty.Of(s), ast::StorageClass::kPrivate); Global("str", ty.Of(s), ast::StorageClass::kPrivate);
auto* p = Const("p", nullptr, AddressOf("str")); auto* p = Let("p", nullptr, AddressOf("str"));
auto* expr = MemberAccessor(Deref("p"), "mem"); auto* expr = MemberAccessor(Deref("p"), "mem");
WrapInFunction(p, expr); WrapInFunction(p, expr);

View File

@ -47,9 +47,9 @@ TEST_F(WgslUnaryOpTest, Complement) {
TEST_F(WgslUnaryOpTest, Indirection) { TEST_F(WgslUnaryOpTest, Indirection) {
Global("G", ty.f32(), ast::StorageClass::kPrivate); Global("G", ty.f32(), ast::StorageClass::kPrivate);
auto* p = Const( auto* p =
"expr", nullptr, Let("expr", nullptr,
create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, Expr("G"))); create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, Expr("G")));
auto* op = auto* op =
create<ast::UnaryOpExpression>(ast::UnaryOp::kIndirection, Expr("expr")); create<ast::UnaryOpExpression>(ast::UnaryOp::kIndirection, Expr("expr"));
WrapInFunction(p, op); WrapInFunction(p, op);

View File

@ -114,7 +114,7 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Constructor) {
} }
TEST_F(WgslGeneratorImplTest, EmitVariable_Const) { TEST_F(WgslGeneratorImplTest, EmitVariable_Const) {
auto* v = Const("a", ty.f32(), Expr(1.0f)); auto* v = Let("a", ty.f32(), Expr(1.0f));
WrapInFunction(Decl(v)); WrapInFunction(Decl(v));
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();