Move type::AddressSpace to builtin/

This CL moves the AddressSpace enum from type:: to builtin::

Change-Id: Ie8d533be4dd42b34eef164b64e2c9e0843de5c3d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/120401
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
dan sinclair 2023-02-19 04:03:55 +00:00 committed by Dawn LUCI CQ
parent b6cc4cbf89
commit 2a65163c6d
208 changed files with 2049 additions and 1956 deletions

View File

@ -695,6 +695,8 @@ libtint_source_set("libtint_builtins_src") {
sources = [ sources = [
"builtin/access.cc", "builtin/access.cc",
"builtin/access.h", "builtin/access.h",
"builtin/address_space.cc",
"builtin/address_space.h",
"builtin/builtin_value.cc", "builtin/builtin_value.cc",
"builtin/builtin_value.h", "builtin/builtin_value.h",
"builtin/extension.cc", "builtin/extension.cc",
@ -711,8 +713,6 @@ libtint_source_set("libtint_type_src") {
"type/abstract_int.h", "type/abstract_int.h",
"type/abstract_numeric.cc", "type/abstract_numeric.cc",
"type/abstract_numeric.h", "type/abstract_numeric.h",
"type/address_space.cc",
"type/address_space.h",
"type/array.cc", "type/array.cc",
"type/array.h", "type/array.h",
"type/array_count.cc", "type/array_count.cc",
@ -1295,6 +1295,7 @@ if (tint_build_unittests) {
tint_unittests_source_set("tint_unittests_builtins_src") { tint_unittests_source_set("tint_unittests_builtins_src") {
sources = [ sources = [
"builtin/access_test.cc", "builtin/access_test.cc",
"builtin/address_space_test.cc",
"builtin/builtin_value_test.cc", "builtin/builtin_value_test.cc",
"builtin/extension_test.cc", "builtin/extension_test.cc",
] ]
@ -1413,7 +1414,6 @@ if (tint_build_unittests) {
tint_unittests_source_set("tint_unittests_type_src") { tint_unittests_source_set("tint_unittests_type_src") {
sources = [ sources = [
"type/address_space_test.cc",
"type/atomic_test.cc", "type/atomic_test.cc",
"type/bool_test.cc", "type/bool_test.cc",
"type/builtin_test.cc", "type/builtin_test.cc",
@ -1438,7 +1438,10 @@ if (tint_build_unittests) {
"type/u32_test.cc", "type/u32_test.cc",
"type/vector_test.cc", "type/vector_test.cc",
] ]
deps = [ ":libtint_base_src" ] deps = [
":libtint_base_src",
":libtint_builtins_src",
]
} }
tint_unittests_source_set("tint_unittests_text_src") { tint_unittests_source_set("tint_unittests_text_src") {

View File

@ -549,6 +549,7 @@ list(APPEND TINT_LIB_SRCS
) )
tint_generated(builtin/access BENCH TEST) tint_generated(builtin/access BENCH TEST)
tint_generated(builtin/address_space BENCH TEST)
tint_generated(builtin/builtin_value BENCH TEST) tint_generated(builtin/builtin_value BENCH TEST)
tint_generated(builtin/extension BENCH TEST) tint_generated(builtin/extension BENCH TEST)
tint_generated(ast/diagnostic_control BENCH TEST) tint_generated(ast/diagnostic_control BENCH TEST)
@ -556,7 +557,6 @@ tint_generated(ast/interpolate_attribute BENCH TEST)
tint_generated(resolver/init_conv_intrinsic) tint_generated(resolver/init_conv_intrinsic)
tint_generated(sem/builtin_type) tint_generated(sem/builtin_type)
tint_generated(sem/parameter_usage) tint_generated(sem/parameter_usage)
tint_generated(type/address_space BENCH TEST)
tint_generated(type/builtin BENCH TEST) tint_generated(type/builtin BENCH TEST)
tint_generated(type/texel_format BENCH TEST) tint_generated(type/texel_format BENCH TEST)

View File

@ -73,7 +73,7 @@ TEST_F(ModuleTest, Assert_DifferentProgramID_GlobalVariable) {
{ {
ProgramBuilder b1; ProgramBuilder b1;
ProgramBuilder b2; ProgramBuilder b2;
b1.AST().AddGlobalVariable(b2.Var("var", b2.ty.i32(), type::AddressSpace::kPrivate)); b1.AST().AddGlobalVariable(b2.Var("var", b2.ty.i32(), builtin::AddressSpace::kPrivate));
}, },
"internal compiler error"); "internal compiler error");
} }
@ -93,7 +93,7 @@ TEST_F(ModuleTest, CloneOrder) {
ProgramBuilder b; ProgramBuilder b;
b.Func("F", {}, b.ty.void_(), {}); b.Func("F", {}, b.ty.void_(), {});
b.Alias("A", b.ty.u32()); b.Alias("A", b.ty.u32());
b.GlobalVar("V", b.ty.i32(), type::AddressSpace::kPrivate); b.GlobalVar("V", b.ty.i32(), builtin::AddressSpace::kPrivate);
return Program(std::move(b)); return Program(std::move(b));
}(); }();

View File

@ -24,7 +24,7 @@
#include "src/tint/ast/group_attribute.h" #include "src/tint/ast/group_attribute.h"
#include "src/tint/ast/type.h" #include "src/tint/ast/type.h"
#include "src/tint/builtin/access.h" #include "src/tint/builtin/access.h"
#include "src/tint/type/address_space.h" #include "src/tint/builtin/address_space.h"
// Forward declarations // Forward declarations
namespace tint::ast { namespace tint::ast {

View File

@ -25,7 +25,7 @@ namespace {
using VariableTest = TestHelper; using VariableTest = TestHelper;
TEST_F(VariableTest, Creation) { TEST_F(VariableTest, Creation) {
auto* v = Var("my_var", ty.i32(), type::AddressSpace::kFunction); auto* v = Var("my_var", ty.i32(), builtin::AddressSpace::kFunction);
CheckIdentifier(Symbols(), v->name, "my_var"); CheckIdentifier(Symbols(), v->name, "my_var");
CheckIdentifier(Symbols(), v->declared_address_space, "function"); CheckIdentifier(Symbols(), v->declared_address_space, "function");
@ -39,7 +39,7 @@ TEST_F(VariableTest, Creation) {
TEST_F(VariableTest, CreationWithSource) { TEST_F(VariableTest, CreationWithSource) {
auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}}, "i", auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}}, "i",
ty.f32(), type::AddressSpace::kPrivate, utils::Empty); ty.f32(), builtin::AddressSpace::kPrivate, utils::Empty);
CheckIdentifier(Symbols(), v->name, "i"); CheckIdentifier(Symbols(), v->name, "i");
CheckIdentifier(Symbols(), v->declared_address_space, "private"); CheckIdentifier(Symbols(), v->declared_address_space, "private");
@ -52,7 +52,7 @@ TEST_F(VariableTest, CreationWithSource) {
TEST_F(VariableTest, CreationEmpty) { TEST_F(VariableTest, CreationEmpty) {
auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}}, "a_var", auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}}, "a_var",
ty.i32(), type::AddressSpace::kWorkgroup, utils::Empty); ty.i32(), builtin::AddressSpace::kWorkgroup, utils::Empty);
CheckIdentifier(Symbols(), v->name, "a_var"); CheckIdentifier(Symbols(), v->name, "a_var");
CheckIdentifier(Symbols(), v->declared_address_space, "workgroup"); CheckIdentifier(Symbols(), v->declared_address_space, "workgroup");
@ -93,7 +93,7 @@ TEST_F(VariableTest, Assert_DifferentProgramID_Initializer) {
} }
TEST_F(VariableTest, WithAttributes) { TEST_F(VariableTest, WithAttributes) {
auto* var = Var("my_var", ty.i32(), type::AddressSpace::kFunction, Location(1_u), auto* var = Var("my_var", ty.i32(), builtin::AddressSpace::kFunction, Location(1_u),
Builtin(builtin::BuiltinValue::kPosition), Id(1200_u)); Builtin(builtin::BuiltinValue::kPosition), Id(1200_u));
auto& attributes = var->attributes; auto& attributes = var->attributes;
@ -108,22 +108,22 @@ TEST_F(VariableTest, WithAttributes) {
} }
TEST_F(VariableTest, HasBindingPoint_BothProvided) { TEST_F(VariableTest, HasBindingPoint_BothProvided) {
auto* var = Var("my_var", ty.i32(), type::AddressSpace::kFunction, Binding(2_a), Group(1_a)); auto* var = Var("my_var", ty.i32(), builtin::AddressSpace::kFunction, Binding(2_a), Group(1_a));
EXPECT_TRUE(var->HasBindingPoint()); EXPECT_TRUE(var->HasBindingPoint());
} }
TEST_F(VariableTest, HasBindingPoint_NeitherProvided) { TEST_F(VariableTest, HasBindingPoint_NeitherProvided) {
auto* var = Var("my_var", ty.i32(), type::AddressSpace::kFunction, utils::Empty); auto* var = Var("my_var", ty.i32(), builtin::AddressSpace::kFunction, utils::Empty);
EXPECT_FALSE(var->HasBindingPoint()); EXPECT_FALSE(var->HasBindingPoint());
} }
TEST_F(VariableTest, HasBindingPoint_MissingGroupAttribute) { TEST_F(VariableTest, HasBindingPoint_MissingGroupAttribute) {
auto* var = Var("my_var", ty.i32(), type::AddressSpace::kFunction, Binding(2_a)); auto* var = Var("my_var", ty.i32(), builtin::AddressSpace::kFunction, Binding(2_a));
EXPECT_FALSE(var->HasBindingPoint()); EXPECT_FALSE(var->HasBindingPoint());
} }
TEST_F(VariableTest, HasBindingPoint_MissingBindingAttribute) { TEST_F(VariableTest, HasBindingPoint_MissingBindingAttribute) {
auto* var = Var("my_var", ty.i32(), type::AddressSpace::kFunction, Group(1_a)); auto* var = Var("my_var", ty.i32(), builtin::AddressSpace::kFunction, Group(1_a));
EXPECT_FALSE(var->HasBindingPoint()); EXPECT_FALSE(var->HasBindingPoint());
} }

View File

@ -15,14 +15,14 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen // File generated by tools/src/cmd/gen
// using the template: // using the template:
// src/tint/type/address_space.cc.tmpl // src/tint/builtin/address_space.cc.tmpl
// //
// Do not modify this file directly // Do not modify this file directly
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include "src/tint/type/address_space.h" #include "src/tint/builtin/address_space.h"
namespace tint::type { namespace tint::builtin {
/// ParseAddressSpace parses a AddressSpace from a string. /// ParseAddressSpace parses a AddressSpace from a string.
/// @param str the string to parse /// @param str the string to parse
@ -81,4 +81,4 @@ std::ostream& operator<<(std::ostream& out, AddressSpace value) {
return out << "<unknown>"; return out << "<unknown>";
} }
} // namespace tint::type } // namespace tint::builtin

View File

@ -14,12 +14,12 @@ See:
{{- Import "src/tint/templates/enums.tmpl.inc" -}} {{- Import "src/tint/templates/enums.tmpl.inc" -}}
{{- $enum := (Sem.Enum "address_space") -}} {{- $enum := (Sem.Enum "address_space") -}}
#include "src/tint/type/address_space.h" #include "src/tint/builtin/address_space.h"
namespace tint::type { namespace tint::builtin {
{{ Eval "ParseEnum" $enum}} {{ Eval "ParseEnum" $enum}}
{{ Eval "EnumOStream" $enum}} {{ Eval "EnumOStream" $enum}}
} // namespace tint::type } // namespace tint::builtin

View File

@ -15,17 +15,17 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen // File generated by tools/src/cmd/gen
// using the template: // using the template:
// src/tint/type/address_space.h.tmpl // src/tint/builtin/address_space.h.tmpl
// //
// Do not modify this file directly // Do not modify this file directly
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#ifndef SRC_TINT_TYPE_ADDRESS_SPACE_H_ #ifndef SRC_TINT_BUILTIN_ADDRESS_SPACE_H_
#define SRC_TINT_TYPE_ADDRESS_SPACE_H_ #define SRC_TINT_BUILTIN_ADDRESS_SPACE_H_
#include <ostream> #include <ostream>
namespace tint::type { namespace tint::builtin {
/// Address space of a given pointer. /// Address space of a given pointer.
enum class AddressSpace { enum class AddressSpace {
@ -63,6 +63,6 @@ inline bool IsHostShareable(AddressSpace address_space) {
address_space == AddressSpace::kPushConstant; address_space == AddressSpace::kPushConstant;
} }
} // namespace tint::type } // namespace tint::builtin
#endif // SRC_TINT_TYPE_ADDRESS_SPACE_H_ #endif // SRC_TINT_BUILTIN_ADDRESS_SPACE_H_

View File

@ -14,12 +14,12 @@ See:
{{- Import "src/tint/templates/enums.tmpl.inc" -}} {{- Import "src/tint/templates/enums.tmpl.inc" -}}
{{- $enum := (Sem.Enum "address_space") -}} {{- $enum := (Sem.Enum "address_space") -}}
#ifndef SRC_TINT_TYPE_ADDRESS_SPACE_H_ #ifndef SRC_TINT_BUILTIN_ADDRESS_SPACE_H_
#define SRC_TINT_TYPE_ADDRESS_SPACE_H_ #define SRC_TINT_BUILTIN_ADDRESS_SPACE_H_
#include <ostream> #include <ostream>
namespace tint::type { namespace tint::builtin {
/// Address space of a given pointer. /// Address space of a given pointer.
{{ Eval "DeclareEnum" $enum}} {{ Eval "DeclareEnum" $enum}}
@ -33,6 +33,6 @@ inline bool IsHostShareable(AddressSpace address_space) {
address_space == AddressSpace::kPushConstant; address_space == AddressSpace::kPushConstant;
} }
} // namespace tint::type } // namespace tint::builtin
#endif // SRC_TINT_TYPE_ADDRESS_SPACE_H_ #endif // SRC_TINT_BUILTIN_ADDRESS_SPACE_H_

View File

@ -15,18 +15,18 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen // File generated by tools/src/cmd/gen
// using the template: // using the template:
// src/tint/type/address_space_bench.cc.tmpl // src/tint/builtin/address_space_bench.cc.tmpl
// //
// Do not modify this file directly // Do not modify this file directly
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include "src/tint/type/address_space.h" #include "src/tint/builtin/address_space.h"
#include <array> #include <array>
#include "benchmark/benchmark.h" #include "benchmark/benchmark.h"
namespace tint::type { namespace tint::builtin {
namespace { namespace {
void AddressSpaceParser(::benchmark::State& state) { void AddressSpaceParser(::benchmark::State& state) {
@ -99,4 +99,4 @@ void AddressSpaceParser(::benchmark::State& state) {
BENCHMARK(AddressSpaceParser); BENCHMARK(AddressSpaceParser);
} // namespace } // namespace
} // namespace tint::type } // namespace tint::builtin

View File

@ -14,16 +14,16 @@ See:
{{- Import "src/tint/templates/enums.tmpl.inc" -}} {{- Import "src/tint/templates/enums.tmpl.inc" -}}
{{- $enum := (Sem.Enum "address_space") -}} {{- $enum := (Sem.Enum "address_space") -}}
#include "src/tint/type/address_space.h" #include "src/tint/builtin/address_space.h"
#include <array> #include <array>
#include "benchmark/benchmark.h" #include "benchmark/benchmark.h"
namespace tint::type { namespace tint::builtin {
namespace { namespace {
{{ Eval "BenchmarkParseEnum" $enum }} {{ Eval "BenchmarkParseEnum" $enum }}
} // namespace } // namespace
} // namespace tint::type } // namespace tint::builtin

View File

@ -15,19 +15,20 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen // File generated by tools/src/cmd/gen
// using the template: // using the template:
// src/tint/type/address_space_test.cc.tmpl // src/tint/builtin/address_space_test.cc.tmpl
// //
// Do not modify this file directly // Do not modify this file directly
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include "src/tint/type/address_space.h" #include "src/tint/builtin/address_space.h"
#include <gtest/gtest.h>
#include <string> #include <string>
#include "src/tint/type/test_helper.h"
#include "src/tint/utils/string.h" #include "src/tint/utils/string.h"
namespace tint::type { namespace tint::builtin {
namespace { namespace {
namespace parse_print_tests { namespace parse_print_tests {
@ -91,4 +92,4 @@ INSTANTIATE_TEST_SUITE_P(ValidCases, AddressSpacePrintTest, testing::ValuesIn(kV
} // namespace parse_print_tests } // namespace parse_print_tests
} // namespace } // namespace
} // namespace tint::type } // namespace tint::builtin

View File

@ -14,17 +14,18 @@ See:
{{- Import "src/tint/templates/enums.tmpl.inc" -}} {{- Import "src/tint/templates/enums.tmpl.inc" -}}
{{- $enum := (Sem.Enum "address_space") -}} {{- $enum := (Sem.Enum "address_space") -}}
#include "src/tint/type/address_space.h" #include "src/tint/builtin/address_space.h"
#include <gtest/gtest.h>
#include <string> #include <string>
#include "src/tint/type/test_helper.h"
#include "src/tint/utils/string.h" #include "src/tint/utils/string.h"
namespace tint::type { namespace tint::builtin {
namespace { namespace {
{{ Eval "TestParsePrintEnum" $enum}} {{ Eval "TestParsePrintEnum" $enum}}
} // namespace } // namespace
} // namespace tint::type } // namespace tint::builtin

View File

@ -587,7 +587,7 @@ uint32_t Inspector::GetWorkgroupStorageSize(const std::string& entry_point) {
uint32_t total_size = 0; uint32_t total_size = 0;
auto* func_sem = program_->Sem().Get(func); auto* func_sem = program_->Sem().Get(func);
for (const sem::Variable* var : func_sem->TransitivelyReferencedGlobals()) { for (const sem::Variable* var : func_sem->TransitivelyReferencedGlobals()) {
if (var->AddressSpace() == type::AddressSpace::kWorkgroup) { if (var->AddressSpace() == builtin::AddressSpace::kWorkgroup) {
auto* ty = var->Type()->UnwrapRef(); auto* ty = var->Type()->UnwrapRef();
uint32_t align = ty->Align(); uint32_t align = ty->Align();
uint32_t size = ty->Size(); uint32_t size = ty->Size();

View File

@ -743,7 +743,7 @@ TEST_F(InspectorGetEntryPointTest, OverrideReferencedIndirectly) {
TEST_F(InspectorGetEntryPointTest, OverrideReferencedIndirectly_ViaPrivateInitializer) { TEST_F(InspectorGetEntryPointTest, OverrideReferencedIndirectly_ViaPrivateInitializer) {
Override("foo", ty.f32()); Override("foo", ty.f32());
GlobalVar("bar", type::AddressSpace::kPrivate, ty.f32(), Mul(2_a, "foo")); GlobalVar("bar", builtin::AddressSpace::kPrivate, ty.f32(), Mul(2_a, "foo"));
MakePlainGlobalReferenceBodyFunction("ep_func", "bar", ty.f32(), MakePlainGlobalReferenceBodyFunction("ep_func", "bar", ty.f32(),
utils::Vector{ utils::Vector{
Stage(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
@ -834,7 +834,7 @@ TEST_F(InspectorGetEntryPointTest, OverrideReferencedByAttributeIndirectly) {
TEST_F(InspectorGetEntryPointTest, OverrideReferencedByArraySize) { TEST_F(InspectorGetEntryPointTest, OverrideReferencedByArraySize) {
Override("size", ty.u32()); Override("size", ty.u32());
GlobalVar("v", type::AddressSpace::kWorkgroup, ty.array(ty.f32(), "size")); GlobalVar("v", builtin::AddressSpace::kWorkgroup, ty.array(ty.f32(), "size"));
Func("ep", utils::Empty, ty.void_(), Func("ep", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
Assign(Phony(), IndexAccessor("v", 0_a)), Assign(Phony(), IndexAccessor("v", 0_a)),
@ -857,7 +857,7 @@ TEST_F(InspectorGetEntryPointTest, OverrideReferencedByArraySize) {
TEST_F(InspectorGetEntryPointTest, OverrideReferencedByArraySizeIndirectly) { TEST_F(InspectorGetEntryPointTest, OverrideReferencedByArraySizeIndirectly) {
Override("foo", ty.u32()); Override("foo", ty.u32());
Override("bar", ty.u32(), Mul(2_a, "foo")); Override("bar", ty.u32(), Mul(2_a, "foo"));
GlobalVar("v", type::AddressSpace::kWorkgroup, ty.array(ty.f32(), Mul(2_a, Expr("bar")))); GlobalVar("v", builtin::AddressSpace::kWorkgroup, ty.array(ty.f32(), Mul(2_a, Expr("bar"))));
Func("ep", utils::Empty, ty.void_(), Func("ep", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
Assign(Phony(), IndexAccessor("v", 0_a)), Assign(Phony(), IndexAccessor("v", 0_a)),
@ -885,7 +885,7 @@ TEST_F(InspectorGetEntryPointTest, OverrideReferencedByArraySizeViaAlias) {
Alias("MyArray", ty.array(ty.f32(), Mul(2_a, Expr("bar")))); Alias("MyArray", ty.array(ty.f32(), Mul(2_a, Expr("bar"))));
Override("zoo", ty.u32()); Override("zoo", ty.u32());
Alias("MyArrayUnused", ty.array(ty.f32(), Mul(2_a, Expr("zoo")))); Alias("MyArrayUnused", ty.array(ty.f32(), Mul(2_a, Expr("zoo"))));
GlobalVar("v", type::AddressSpace::kWorkgroup, ty("MyArray")); GlobalVar("v", builtin::AddressSpace::kWorkgroup, ty("MyArray"));
Func("ep", utils::Empty, ty.void_(), Func("ep", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
Assign(Phony(), IndexAccessor("v", 0_a)), Assign(Phony(), IndexAccessor("v", 0_a)),

View File

@ -125,11 +125,12 @@ void InspectorBuilder::AddUniformBuffer(const std::string& name,
ast::Type type, ast::Type type,
uint32_t group, uint32_t group,
uint32_t binding) { uint32_t binding) {
GlobalVar(name, type, type::AddressSpace::kUniform, Binding(AInt(binding)), Group(AInt(group))); GlobalVar(name, type, builtin::AddressSpace::kUniform, Binding(AInt(binding)),
Group(AInt(group)));
} }
void InspectorBuilder::AddWorkgroupStorage(const std::string& name, ast::Type type) { void InspectorBuilder::AddWorkgroupStorage(const std::string& name, ast::Type type) {
GlobalVar(name, type, type::AddressSpace::kWorkgroup); GlobalVar(name, type, builtin::AddressSpace::kWorkgroup);
} }
void InspectorBuilder::AddStorageBuffer(const std::string& name, void InspectorBuilder::AddStorageBuffer(const std::string& name,
@ -137,7 +138,7 @@ void InspectorBuilder::AddStorageBuffer(const std::string& name,
builtin::Access access, builtin::Access access,
uint32_t group, uint32_t group,
uint32_t binding) { uint32_t binding) {
GlobalVar(name, type, type::AddressSpace::kStorage, access, Binding(AInt(binding)), GlobalVar(name, type, builtin::AddressSpace::kStorage, access, Binding(AInt(binding)),
Group(AInt(group))); Group(AInt(group)));
} }
@ -189,7 +190,7 @@ void InspectorBuilder::AddResource(const std::string& name,
} }
void InspectorBuilder::AddGlobalVariable(const std::string& name, ast::Type type) { void InspectorBuilder::AddGlobalVariable(const std::string& name, ast::Type type) {
GlobalVar(name, type, type::AddressSpace::kPrivate); GlobalVar(name, type, builtin::AddressSpace::kPrivate);
} }
const ast::Function* InspectorBuilder::MakeSamplerReferenceBodyFunction( const ast::Function* InspectorBuilder::MakeSamplerReferenceBodyFunction(

View File

@ -1468,7 +1468,7 @@ FunctionEnd
TEST_F(IR_BuilderImplTest, EmitLiteral_Bool_True) { TEST_F(IR_BuilderImplTest, EmitLiteral_Bool_True) {
auto* expr = Expr(true); auto* expr = Expr(true);
GlobalVar("a", ty.bool_(), type::AddressSpace::kPrivate, expr); GlobalVar("a", ty.bool_(), builtin::AddressSpace::kPrivate, expr);
auto& b = CreateBuilder(); auto& b = CreateBuilder();
auto r = b.EmitLiteral(expr); auto r = b.EmitLiteral(expr);
@ -1482,7 +1482,7 @@ TEST_F(IR_BuilderImplTest, EmitLiteral_Bool_True) {
TEST_F(IR_BuilderImplTest, EmitLiteral_Bool_False) { TEST_F(IR_BuilderImplTest, EmitLiteral_Bool_False) {
auto* expr = Expr(false); auto* expr = Expr(false);
GlobalVar("a", ty.bool_(), type::AddressSpace::kPrivate, expr); GlobalVar("a", ty.bool_(), builtin::AddressSpace::kPrivate, expr);
auto& b = CreateBuilder(); auto& b = CreateBuilder();
auto r = b.EmitLiteral(expr); auto r = b.EmitLiteral(expr);
@ -1496,7 +1496,7 @@ TEST_F(IR_BuilderImplTest, EmitLiteral_Bool_False) {
TEST_F(IR_BuilderImplTest, EmitLiteral_F32) { TEST_F(IR_BuilderImplTest, EmitLiteral_F32) {
auto* expr = Expr(1.2_f); auto* expr = Expr(1.2_f);
GlobalVar("a", ty.f32(), type::AddressSpace::kPrivate, expr); GlobalVar("a", ty.f32(), builtin::AddressSpace::kPrivate, expr);
auto& b = CreateBuilder(); auto& b = CreateBuilder();
auto r = b.EmitLiteral(expr); auto r = b.EmitLiteral(expr);
@ -1511,7 +1511,7 @@ TEST_F(IR_BuilderImplTest, EmitLiteral_F32) {
TEST_F(IR_BuilderImplTest, EmitLiteral_F16) { TEST_F(IR_BuilderImplTest, EmitLiteral_F16) {
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
auto* expr = Expr(1.2_h); auto* expr = Expr(1.2_h);
GlobalVar("a", ty.f16(), type::AddressSpace::kPrivate, expr); GlobalVar("a", ty.f16(), builtin::AddressSpace::kPrivate, expr);
auto& b = CreateBuilder(); auto& b = CreateBuilder();
auto r = b.EmitLiteral(expr); auto r = b.EmitLiteral(expr);
@ -1525,7 +1525,7 @@ TEST_F(IR_BuilderImplTest, EmitLiteral_F16) {
TEST_F(IR_BuilderImplTest, EmitLiteral_I32) { TEST_F(IR_BuilderImplTest, EmitLiteral_I32) {
auto* expr = Expr(-2_i); auto* expr = Expr(-2_i);
GlobalVar("a", ty.i32(), type::AddressSpace::kPrivate, expr); GlobalVar("a", ty.i32(), builtin::AddressSpace::kPrivate, expr);
auto& b = CreateBuilder(); auto& b = CreateBuilder();
auto r = b.EmitLiteral(expr); auto r = b.EmitLiteral(expr);
@ -1539,7 +1539,7 @@ TEST_F(IR_BuilderImplTest, EmitLiteral_I32) {
TEST_F(IR_BuilderImplTest, EmitLiteral_U32) { TEST_F(IR_BuilderImplTest, EmitLiteral_U32) {
auto* expr = Expr(2_u); auto* expr = Expr(2_u);
GlobalVar("a", ty.u32(), type::AddressSpace::kPrivate, expr); GlobalVar("a", ty.u32(), builtin::AddressSpace::kPrivate, expr);
auto& b = CreateBuilder(); auto& b = CreateBuilder();
auto r = b.EmitLiteral(expr); auto r = b.EmitLiteral(expr);

View File

@ -232,8 +232,8 @@ class ProgramBuilder {
private: private:
void Set(ProgramBuilder&, ast::Type t) { type = t; } void Set(ProgramBuilder&, ast::Type t) { type = t; }
void Set(ProgramBuilder& b, type::AddressSpace addr_space) { void Set(ProgramBuilder& b, builtin::AddressSpace addr_space) {
if (addr_space != type::AddressSpace::kUndefined) { if (addr_space != builtin::AddressSpace::kUndefined) {
address_space = b.Expr(addr_space); address_space = b.Expr(addr_space);
} }
} }
@ -1199,9 +1199,9 @@ class ProgramBuilder {
/// @param type the type of the pointer /// @param type the type of the pointer
/// @param address_space the address space of the pointer /// @param address_space the address space of the pointer
/// @param access the optional access control of the pointer /// @param access the optional access control of the pointer
/// @return the pointer to `type` with the given type::AddressSpace /// @return the pointer to `type` with the given builtin::AddressSpace
ast::Type pointer(ast::Type type, ast::Type pointer(ast::Type type,
type::AddressSpace address_space, builtin::AddressSpace address_space,
builtin::Access access = builtin::Access::kUndefined) const { builtin::Access access = builtin::Access::kUndefined) const {
return pointer(builder->source_, type, address_space, access); return pointer(builder->source_, type, address_space, access);
} }
@ -1210,10 +1210,10 @@ class ProgramBuilder {
/// @param type the type of the pointer /// @param type the type of the pointer
/// @param address_space the address space of the pointer /// @param address_space the address space of the pointer
/// @param access the optional access control of the pointer /// @param access the optional access control of the pointer
/// @return the pointer to `type` with the given type::AddressSpace /// @return the pointer to `type` with the given builtin::AddressSpace
ast::Type pointer(const Source& source, ast::Type pointer(const Source& source,
ast::Type type, ast::Type type,
type::AddressSpace address_space, builtin::AddressSpace address_space,
builtin::Access access = builtin::Access::kUndefined) const { builtin::Access access = builtin::Access::kUndefined) const {
if (access != builtin::Access::kUndefined) { if (access != builtin::Access::kUndefined) {
return (*this)(source, "ptr", address_space, type, access); return (*this)(source, "ptr", address_space, type, access);
@ -1224,9 +1224,9 @@ class ProgramBuilder {
/// @param address_space the address space of the pointer /// @param address_space the address space of the pointer
/// @param access the optional access control of the pointer /// @param access the optional access control of the pointer
/// @return the pointer to type `T` with the given type::AddressSpace. /// @return the pointer to type `T` with the given builtin::AddressSpace.
template <typename T> template <typename T>
ast::Type pointer(type::AddressSpace address_space, ast::Type pointer(builtin::AddressSpace address_space,
builtin::Access access = builtin::Access::kUndefined) const { builtin::Access access = builtin::Access::kUndefined) const {
return pointer<T>(builder->source_, address_space, access); return pointer<T>(builder->source_, address_space, access);
} }
@ -1234,10 +1234,10 @@ class ProgramBuilder {
/// @param source the Source of the node /// @param source the Source of the node
/// @param address_space the address space of the pointer /// @param address_space the address space of the pointer
/// @param access the optional access control of the pointer /// @param access the optional access control of the pointer
/// @return the pointer to type `T` with the given type::AddressSpace. /// @return the pointer to type `T` with the given builtin::AddressSpace.
template <typename T> template <typename T>
ast::Type pointer(const Source& source, ast::Type pointer(const Source& source,
type::AddressSpace address_space, builtin::AddressSpace address_space,
builtin::Access access = builtin::Access::kUndefined) const { builtin::Access access = builtin::Access::kUndefined) const {
if (access != builtin::Access::kUndefined) { if (access != builtin::Access::kUndefined) {
return (*this)(source, "ptr", address_space, Of<T>(), access); return (*this)(source, "ptr", address_space, Of<T>(), access);
@ -2066,7 +2066,7 @@ class ProgramBuilder {
/// @param options the extra options passed to the ast::Var initializer /// @param options the extra options passed to the ast::Var initializer
/// Can be any of the following, in any order: /// Can be any of the following, in any order:
/// * ast::Type - specifies the variable's type /// * ast::Type - specifies the variable's type
/// * type::AddressSpace - specifies the variable's address space /// * builtin::AddressSpace - specifies the variable's address space
/// * builtin::Access - specifies the variable's access control /// * builtin::Access - specifies the variable's access control
/// * ast::Expression* - specifies the variable's initializer expression /// * ast::Expression* - specifies the variable's initializer expression
/// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector) /// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector)
@ -2083,7 +2083,7 @@ class ProgramBuilder {
/// @param options the extra options passed to the ast::Var initializer /// @param options the extra options passed to the ast::Var initializer
/// Can be any of the following, in any order: /// Can be any of the following, in any order:
/// * ast::Type - specifies the variable's type /// * ast::Type - specifies the variable's type
/// * type::AddressSpace - specifies the variable's address space /// * builtin::AddressSpace - specifies the variable's address space
/// * builtin::Access - specifies the variable's access control /// * builtin::Access - specifies the variable's access control
/// * ast::Expression* - specifies the variable's initializer expression /// * ast::Expression* - specifies the variable's initializer expression
/// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector) /// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector)
@ -2185,7 +2185,7 @@ class ProgramBuilder {
/// @param options the extra options passed to the ast::Var initializer /// @param options the extra options passed to the ast::Var initializer
/// Can be any of the following, in any order: /// Can be any of the following, in any order:
/// * ast::Type - specifies the variable's type /// * ast::Type - specifies the variable's type
/// * type::AddressSpace - specifies the variable address space /// * builtin::AddressSpace - specifies the variable address space
/// * builtin::Access - specifies the variable's access control /// * builtin::Access - specifies the variable's access control
/// * ast::Expression* - specifies the variable's initializer expression /// * ast::Expression* - specifies the variable's initializer expression
/// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector) /// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector)
@ -2202,7 +2202,7 @@ class ProgramBuilder {
/// @param options the extra options passed to the ast::Var initializer /// @param options the extra options passed to the ast::Var initializer
/// Can be any of the following, in any order: /// Can be any of the following, in any order:
/// * ast::Type - specifies the variable's type /// * ast::Type - specifies the variable's type
/// * type::AddressSpace - specifies the variable address space /// * builtin::AddressSpace - specifies the variable address space
/// * builtin::Access - specifies the variable's access control /// * builtin::Access - specifies the variable's access control
/// * ast::Expression* - specifies the variable's initializer expression /// * ast::Expression* - specifies the variable's initializer expression
/// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector) /// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector)

View File

@ -46,7 +46,7 @@ TEST_F(ProgramTest, IDsAreUnique) {
} }
TEST_F(ProgramTest, Assert_GlobalVariable) { TEST_F(ProgramTest, Assert_GlobalVariable) {
GlobalVar("var", ty.f32(), type::AddressSpace::kPrivate); GlobalVar("var", ty.f32(), builtin::AddressSpace::kPrivate);
Program program(std::move(*this)); Program program(std::move(*this));
EXPECT_TRUE(program.IsValid()); EXPECT_TRUE(program.IsValid());

View File

@ -38,30 +38,30 @@ ast::PipelineStage EnumConverter::ToPipelineStage(spv::ExecutionModel model) {
return ast::PipelineStage::kNone; return ast::PipelineStage::kNone;
} }
type::AddressSpace EnumConverter::ToAddressSpace(const spv::StorageClass sc) { builtin::AddressSpace EnumConverter::ToAddressSpace(const spv::StorageClass sc) {
switch (sc) { switch (sc) {
case spv::StorageClass::Input: case spv::StorageClass::Input:
return type::AddressSpace::kIn; return builtin::AddressSpace::kIn;
case spv::StorageClass::Output: case spv::StorageClass::Output:
return type::AddressSpace::kOut; return builtin::AddressSpace::kOut;
case spv::StorageClass::Uniform: case spv::StorageClass::Uniform:
return type::AddressSpace::kUniform; return builtin::AddressSpace::kUniform;
case spv::StorageClass::Workgroup: case spv::StorageClass::Workgroup:
return type::AddressSpace::kWorkgroup; return builtin::AddressSpace::kWorkgroup;
case spv::StorageClass::UniformConstant: case spv::StorageClass::UniformConstant:
return type::AddressSpace::kUndefined; return builtin::AddressSpace::kUndefined;
case spv::StorageClass::StorageBuffer: case spv::StorageClass::StorageBuffer:
return type::AddressSpace::kStorage; return builtin::AddressSpace::kStorage;
case spv::StorageClass::Private: case spv::StorageClass::Private:
return type::AddressSpace::kPrivate; return builtin::AddressSpace::kPrivate;
case spv::StorageClass::Function: case spv::StorageClass::Function:
return type::AddressSpace::kFunction; return builtin::AddressSpace::kFunction;
default: default:
break; break;
} }
Fail() << "unknown SPIR-V storage class: " << uint32_t(sc); Fail() << "unknown SPIR-V storage class: " << uint32_t(sc);
return type::AddressSpace::kUndefined; return builtin::AddressSpace::kUndefined;
} }
builtin::BuiltinValue EnumConverter::ToBuiltin(spv::BuiltIn b) { builtin::BuiltinValue EnumConverter::ToBuiltin(spv::BuiltIn b) {

View File

@ -18,9 +18,9 @@
#include "spirv/unified1/spirv.h" #include "spirv/unified1/spirv.h"
#include "spirv/unified1/spirv.hpp11" #include "spirv/unified1/spirv.hpp11"
#include "src/tint/ast/pipeline_stage.h" #include "src/tint/ast/pipeline_stage.h"
#include "src/tint/builtin/address_space.h"
#include "src/tint/builtin/builtin_value.h" #include "src/tint/builtin/builtin_value.h"
#include "src/tint/reader/spirv/fail_stream.h" #include "src/tint/reader/spirv/fail_stream.h"
#include "src/tint/type/address_space.h"
#include "src/tint/type/storage_texture.h" #include "src/tint/type/storage_texture.h"
#include "src/tint/type/texture_dimension.h" #include "src/tint/type/texture_dimension.h"
@ -45,7 +45,7 @@ class EnumConverter {
/// On failure, logs an error and returns kNone /// On failure, logs an error and returns kNone
/// @param sc the SPIR-V storage class /// @param sc the SPIR-V storage class
/// @returns a Tint AST address space /// @returns a Tint AST address space
type::AddressSpace ToAddressSpace(const spv::StorageClass sc); builtin::AddressSpace ToAddressSpace(const spv::StorageClass sc);
/// Converts a SPIR-V Builtin value a Tint Builtin. /// Converts a SPIR-V Builtin value a Tint Builtin.
/// On failure, logs an error and returns kNone /// On failure, logs an error and returns kNone

View File

@ -85,7 +85,7 @@ INSTANTIATE_TEST_SUITE_P(EnumConverterBad,
struct StorageClassCase { struct StorageClassCase {
spv::StorageClass sc; spv::StorageClass sc;
bool expect_success; bool expect_success;
type::AddressSpace expected; builtin::AddressSpace expected;
}; };
inline std::ostream& operator<<(std::ostream& out, StorageClassCase scc) { inline std::ostream& operator<<(std::ostream& out, StorageClassCase scc) {
out << "StorageClassCase{ spv::StorageClass:::" << int(scc.sc) out << "StorageClassCase{ spv::StorageClass:::" << int(scc.sc)
@ -126,19 +126,21 @@ INSTANTIATE_TEST_SUITE_P(
EnumConverterGood, EnumConverterGood,
SpvStorageClassTest, SpvStorageClassTest,
testing::Values( testing::Values(
StorageClassCase{spv::StorageClass::Input, true, type::AddressSpace::kIn}, StorageClassCase{spv::StorageClass::Input, true, builtin::AddressSpace::kIn},
StorageClassCase{spv::StorageClass::Output, true, type::AddressSpace::kOut}, StorageClassCase{spv::StorageClass::Output, true, builtin::AddressSpace::kOut},
StorageClassCase{spv::StorageClass::Uniform, true, type::AddressSpace::kUniform}, StorageClassCase{spv::StorageClass::Uniform, true, builtin::AddressSpace::kUniform},
StorageClassCase{spv::StorageClass::Workgroup, true, type::AddressSpace::kWorkgroup}, StorageClassCase{spv::StorageClass::Workgroup, true, builtin::AddressSpace::kWorkgroup},
StorageClassCase{spv::StorageClass::UniformConstant, true, type::AddressSpace::kUndefined}, StorageClassCase{spv::StorageClass::UniformConstant, true,
StorageClassCase{spv::StorageClass::StorageBuffer, true, type::AddressSpace::kStorage}, builtin::AddressSpace::kUndefined},
StorageClassCase{spv::StorageClass::Private, true, type::AddressSpace::kPrivate}, StorageClassCase{spv::StorageClass::StorageBuffer, true, builtin::AddressSpace::kStorage},
StorageClassCase{spv::StorageClass::Function, true, type::AddressSpace::kFunction})); StorageClassCase{spv::StorageClass::Private, true, builtin::AddressSpace::kPrivate},
StorageClassCase{spv::StorageClass::Function, true, builtin::AddressSpace::kFunction}));
INSTANTIATE_TEST_SUITE_P(EnumConverterBad, INSTANTIATE_TEST_SUITE_P(EnumConverterBad,
SpvStorageClassTest, SpvStorageClassTest,
testing::Values(StorageClassCase{static_cast<spv::StorageClass>(9999), testing::Values(StorageClassCase{static_cast<spv::StorageClass>(9999),
false, type::AddressSpace::kUndefined})); false,
builtin::AddressSpace::kUndefined}));
// Builtin // Builtin

View File

@ -2521,12 +2521,12 @@ bool FunctionEmitter::EmitFunctionVariables() {
return false; return false;
} }
} }
auto* var = parser_impl_.MakeVar(inst.result_id(), type::AddressSpace::kUndefined, auto* var = parser_impl_.MakeVar(inst.result_id(), builtin::AddressSpace::kUndefined,
builtin::Access::kUndefined, var_store_type, initializer, builtin::Access::kUndefined, var_store_type, initializer,
AttributeList{}); AttributeList{});
auto* var_decl_stmt = create<ast::VariableDeclStatement>(Source{}, var); auto* var_decl_stmt = create<ast::VariableDeclStatement>(Source{}, var);
AddStatement(var_decl_stmt); AddStatement(var_decl_stmt);
auto* var_type = ty_.Reference(var_store_type, type::AddressSpace::kUndefined); auto* var_type = ty_.Reference(var_store_type, builtin::AddressSpace::kUndefined);
identifier_types_.emplace(inst.result_id(), var_type); identifier_types_.emplace(inst.result_id(), var_type);
} }
return success(); return success();
@ -3369,9 +3369,9 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
auto* store_type = parser_impl_.ConvertType(def_inst->type_id()); auto* store_type = parser_impl_.ConvertType(def_inst->type_id());
AddStatement(create<ast::VariableDeclStatement>( AddStatement(create<ast::VariableDeclStatement>(
Source{}, Source{},
parser_impl_.MakeVar(id, type::AddressSpace::kUndefined, builtin::Access::kUndefined, parser_impl_.MakeVar(id, builtin::AddressSpace::kUndefined, builtin::Access::kUndefined,
store_type, nullptr, AttributeList{}))); store_type, nullptr, AttributeList{})));
auto* type = ty_.Reference(store_type, type::AddressSpace::kUndefined); auto* type = ty_.Reference(store_type, builtin::AddressSpace::kUndefined);
identifier_types_.emplace(id, type); identifier_types_.emplace(id, type);
} }
@ -4842,7 +4842,8 @@ DefInfo::Pointer FunctionEmitter::GetPointerInfo(uint32_t id) {
} }
// Local variables are always Function storage class, with default // Local variables are always Function storage class, with default
// access mode. // access mode.
return DefInfo::Pointer{type::AddressSpace::kFunction, builtin::Access::kUndefined}; return DefInfo::Pointer{builtin::AddressSpace::kFunction,
builtin::Access::kUndefined};
} }
case spv::Op::OpFunctionParameter: { case spv::Op::OpFunctionParameter: {
const auto* type = As<Pointer>(parser_impl_.ConvertType(inst.type_id())); const auto* type = As<Pointer>(parser_impl_.ConvertType(inst.type_id()));
@ -5082,7 +5083,7 @@ void FunctionEmitter::FindValuesNeedingNamedOrHoistedDefinition() {
// Avoid moving combinatorial values across constructs. This is a // Avoid moving combinatorial values across constructs. This is a
// simple heuristic to avoid changing the cost of an operation // simple heuristic to avoid changing the cost of an operation
// by moving it into or out of a loop, for example. // by moving it into or out of a loop, for example.
if ((def_info->pointer.address_space == type::AddressSpace::kUndefined) && if ((def_info->pointer.address_space == builtin::AddressSpace::kUndefined) &&
local_def.used_in_another_construct) { local_def.used_in_another_construct) {
should_hoist_to_let = true; should_hoist_to_let = true;
} }
@ -6192,7 +6193,7 @@ bool FunctionEmitter::MakeVectorInsertDynamic(const spvtools::opt::Instruction&
var_name = namer_.MakeDerivedName(original_value_name); var_name = namer_.MakeDerivedName(original_value_name);
auto* temp_var = builder_.Var(var_name, type->Build(builder_), auto* temp_var = builder_.Var(var_name, type->Build(builder_),
type::AddressSpace::kUndefined, src_vector.expr); builtin::AddressSpace::kUndefined, src_vector.expr);
AddStatement(builder_.Decl({}, temp_var)); AddStatement(builder_.Decl({}, temp_var));
} }
@ -6262,7 +6263,7 @@ bool FunctionEmitter::MakeCompositeInsert(const spvtools::opt::Instruction& inst
// API in parser_impl_. // API in parser_impl_.
var_name = namer_.MakeDerivedName(original_value_name); var_name = namer_.MakeDerivedName(original_value_name);
auto* temp_var = builder_.Var(var_name, type->Build(builder_), auto* temp_var = builder_.Var(var_name, type->Build(builder_),
type::AddressSpace::kUndefined, src_composite.expr); builtin::AddressSpace::kUndefined, src_composite.expr);
AddStatement(builder_.Decl({}, temp_var)); AddStatement(builder_.Decl({}, temp_var));
} }

View File

@ -331,7 +331,7 @@ struct DefInfo {
/// buffer expressed in the old style (with Uniform address space) /// buffer expressed in the old style (with Uniform address space)
/// that needs to be remapped to StorageBuffer address space. /// that needs to be remapped to StorageBuffer address space.
/// This is kInvalid for non-pointers. /// This is kInvalid for non-pointers.
type::AddressSpace address_space = type::AddressSpace::kUndefined; builtin::AddressSpace address_space = builtin::AddressSpace::kUndefined;
/// The declared access mode. /// The declared access mode.
builtin::Access access = builtin::Access::kUndefined; builtin::Access access = builtin::Access::kUndefined;
@ -368,7 +368,7 @@ inline std::ostream& operator<<(std::ostream& o, const DefInfo& di) {
} }
o << " requires_named_let_def: " << (di.requires_named_let_def ? "true" : "false") o << " requires_named_let_def: " << (di.requires_named_let_def ? "true" : "false")
<< " requires_hoisted_var_def: " << (di.requires_hoisted_var_def ? "true" : "false"); << " requires_hoisted_var_def: " << (di.requires_hoisted_var_def ? "true" : "false");
if (di.pointer.address_space != type::AddressSpace::kUndefined) { if (di.pointer.address_space != builtin::AddressSpace::kUndefined) {
o << " sc:" << int(di.pointer.address_space); o << " sc:" << int(di.pointer.address_space);
} }
switch (di.skip) { switch (di.skip) {

View File

@ -1222,16 +1222,16 @@ const Type* ParserImpl::ConvertType(uint32_t type_id,
} }
auto ast_address_space = enum_converter_.ToAddressSpace(storage_class); auto ast_address_space = enum_converter_.ToAddressSpace(storage_class);
if (ast_address_space == type::AddressSpace::kUniform && if (ast_address_space == builtin::AddressSpace::kUniform &&
remap_buffer_block_type_.count(pointee_type_id)) { remap_buffer_block_type_.count(pointee_type_id)) {
ast_address_space = type::AddressSpace::kStorage; ast_address_space = builtin::AddressSpace::kStorage;
remap_buffer_block_type_.insert(type_id); remap_buffer_block_type_.insert(type_id);
} }
// Pipeline input and output variables map to private variables. // Pipeline input and output variables map to private variables.
if (ast_address_space == type::AddressSpace::kIn || if (ast_address_space == builtin::AddressSpace::kIn ||
ast_address_space == type::AddressSpace::kOut) { ast_address_space == builtin::AddressSpace::kOut) {
ast_address_space = type::AddressSpace::kPrivate; ast_address_space = builtin::AddressSpace::kPrivate;
} }
switch (ptr_as) { switch (ptr_as) {
case PtrAs::Ref: case PtrAs::Ref:
@ -1454,14 +1454,14 @@ bool ParserImpl::EmitModuleScopeVariables() {
continue; continue;
} }
switch (enum_converter_.ToAddressSpace(spirv_storage_class)) { switch (enum_converter_.ToAddressSpace(spirv_storage_class)) {
case type::AddressSpace::kUndefined: case builtin::AddressSpace::kUndefined:
case type::AddressSpace::kIn: case builtin::AddressSpace::kIn:
case type::AddressSpace::kOut: case builtin::AddressSpace::kOut:
case type::AddressSpace::kUniform: case builtin::AddressSpace::kUniform:
case type::AddressSpace::kHandle: case builtin::AddressSpace::kHandle:
case type::AddressSpace::kStorage: case builtin::AddressSpace::kStorage:
case type::AddressSpace::kWorkgroup: case builtin::AddressSpace::kWorkgroup:
case type::AddressSpace::kPrivate: case builtin::AddressSpace::kPrivate:
break; break;
default: default:
return Fail() << "invalid SPIR-V storage class " << int(spirv_storage_class) return Fail() << "invalid SPIR-V storage class " << int(spirv_storage_class)
@ -1471,7 +1471,7 @@ bool ParserImpl::EmitModuleScopeVariables() {
return false; return false;
} }
const Type* ast_store_type = nullptr; const Type* ast_store_type = nullptr;
type::AddressSpace ast_address_space = type::AddressSpace::kUndefined; builtin::AddressSpace ast_address_space = builtin::AddressSpace::kUndefined;
if (spirv_storage_class == spv::StorageClass::UniformConstant) { if (spirv_storage_class == spv::StorageClass::UniformConstant) {
// These are opaque handles: samplers or textures // These are opaque handles: samplers or textures
ast_store_type = GetHandleTypeForSpirvHandle(var); ast_store_type = GetHandleTypeForSpirvHandle(var);
@ -1576,8 +1576,9 @@ const spvtools::opt::analysis::IntConstant* ParserImpl::GetArraySize(uint32_t va
return size->AsIntConstant(); return size->AsIntConstant();
} }
builtin::Access ParserImpl::VarAccess(const Type* storage_type, type::AddressSpace address_space) { builtin::Access ParserImpl::VarAccess(const Type* storage_type,
if (address_space != type::AddressSpace::kStorage) { builtin::AddressSpace address_space) {
if (address_space != builtin::AddressSpace::kStorage) {
return builtin::Access::kUndefined; return builtin::Access::kUndefined;
} }
@ -1591,7 +1592,7 @@ builtin::Access ParserImpl::VarAccess(const Type* storage_type, type::AddressSpa
} }
const ast::Var* ParserImpl::MakeVar(uint32_t id, const ast::Var* ParserImpl::MakeVar(uint32_t id,
type::AddressSpace address_space, builtin::AddressSpace address_space,
builtin::Access access, builtin::Access access,
const Type* storage_type, const Type* storage_type,
const ast::Expression* initializer, const ast::Expression* initializer,
@ -1603,12 +1604,12 @@ const ast::Var* ParserImpl::MakeVar(uint32_t id,
// Handle variables (textures and samplers) are always in the handle // Handle variables (textures and samplers) are always in the handle
// address space, so we don't mention the address space. // address space, so we don't mention the address space.
if (address_space == type::AddressSpace::kHandle) { if (address_space == builtin::AddressSpace::kHandle) {
address_space = type::AddressSpace::kUndefined; address_space = builtin::AddressSpace::kUndefined;
} }
if (!ConvertDecorationsForVariable(id, &storage_type, &decorations, if (!ConvertDecorationsForVariable(id, &storage_type, &decorations,
address_space != type::AddressSpace::kPrivate)) { address_space != builtin::AddressSpace::kPrivate)) {
return nullptr; return nullptr;
} }

View File

@ -424,12 +424,12 @@ class ParserImpl : Reader {
/// @param address_space the 'var' address space /// @param address_space the 'var' address space
/// @returns the access mode for a 'var' declaration with the given storage type and address /// @returns the access mode for a 'var' declaration with the given storage type and address
/// space. /// space.
builtin::Access VarAccess(const Type* storage_type, type::AddressSpace address_space); builtin::Access VarAccess(const Type* storage_type, builtin::AddressSpace address_space);
/// Creates an AST 'var' node for a SPIR-V ID, including any attached decorations, unless it's /// Creates an AST 'var' node for a SPIR-V ID, including any attached decorations, unless it's
/// an ignorable builtin variable. /// an ignorable builtin variable.
/// @param id the SPIR-V result ID /// @param id the SPIR-V result ID
/// @param address_space the address space, which cannot be type::AddressSpace::kUndefined /// @param address_space the address space, which cannot be builtin::AddressSpace::kUndefined
/// @param access the access /// @param access the access
/// @param storage_type the storage type of the variable /// @param storage_type the storage type of the variable
/// @param initializer the variable initializer /// @param initializer the variable initializer
@ -437,7 +437,7 @@ class ParserImpl : Reader {
/// @returns a new Variable node, or null in the ignorable variable case and /// @returns a new Variable node, or null in the ignorable variable case and
/// in the error case /// in the error case
const ast::Var* MakeVar(uint32_t id, const ast::Var* MakeVar(uint32_t id,
type::AddressSpace address_space, builtin::AddressSpace address_space,
builtin::Access access, builtin::Access access,
const Type* storage_type, const Type* storage_type,
const ast::Expression* initializer, const ast::Expression* initializer,
@ -672,7 +672,7 @@ class ParserImpl : Reader {
/// The AST variable node. /// The AST variable node.
const ast::Var* var = nullptr; const ast::Var* var = nullptr;
/// The address space of the var /// The address space of the var
type::AddressSpace address_space = type::AddressSpace::kUndefined; builtin::AddressSpace address_space = builtin::AddressSpace::kUndefined;
/// The access mode of the var /// The access mode of the var
builtin::Access access = builtin::Access::kUndefined; builtin::Access access = builtin::Access::kUndefined;
}; };

View File

@ -731,7 +731,7 @@ TEST_F(SpvParserTest, ConvertType_PointerInput) {
auto* ptr_ty = type->As<Pointer>(); auto* ptr_ty = type->As<Pointer>();
EXPECT_NE(ptr_ty, nullptr); EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type->Is<F32>()); EXPECT_TRUE(ptr_ty->type->Is<F32>());
EXPECT_EQ(ptr_ty->address_space, type::AddressSpace::kPrivate); EXPECT_EQ(ptr_ty->address_space, builtin::AddressSpace::kPrivate);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -747,7 +747,7 @@ TEST_F(SpvParserTest, ConvertType_PointerOutput) {
auto* ptr_ty = type->As<Pointer>(); auto* ptr_ty = type->As<Pointer>();
EXPECT_NE(ptr_ty, nullptr); EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type->Is<F32>()); EXPECT_TRUE(ptr_ty->type->Is<F32>());
EXPECT_EQ(ptr_ty->address_space, type::AddressSpace::kPrivate); EXPECT_EQ(ptr_ty->address_space, builtin::AddressSpace::kPrivate);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -763,7 +763,7 @@ TEST_F(SpvParserTest, ConvertType_PointerUniform) {
auto* ptr_ty = type->As<Pointer>(); auto* ptr_ty = type->As<Pointer>();
EXPECT_NE(ptr_ty, nullptr); EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type->Is<F32>()); EXPECT_TRUE(ptr_ty->type->Is<F32>());
EXPECT_EQ(ptr_ty->address_space, type::AddressSpace::kUniform); EXPECT_EQ(ptr_ty->address_space, builtin::AddressSpace::kUniform);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -779,7 +779,7 @@ TEST_F(SpvParserTest, ConvertType_PointerWorkgroup) {
auto* ptr_ty = type->As<Pointer>(); auto* ptr_ty = type->As<Pointer>();
EXPECT_NE(ptr_ty, nullptr); EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type->Is<F32>()); EXPECT_TRUE(ptr_ty->type->Is<F32>());
EXPECT_EQ(ptr_ty->address_space, type::AddressSpace::kWorkgroup); EXPECT_EQ(ptr_ty->address_space, builtin::AddressSpace::kWorkgroup);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -795,7 +795,7 @@ TEST_F(SpvParserTest, ConvertType_PointerStorageBuffer) {
auto* ptr_ty = type->As<Pointer>(); auto* ptr_ty = type->As<Pointer>();
EXPECT_NE(ptr_ty, nullptr); EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type->Is<F32>()); EXPECT_TRUE(ptr_ty->type->Is<F32>());
EXPECT_EQ(ptr_ty->address_space, type::AddressSpace::kStorage); EXPECT_EQ(ptr_ty->address_space, builtin::AddressSpace::kStorage);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -811,7 +811,7 @@ TEST_F(SpvParserTest, ConvertType_PointerPrivate) {
auto* ptr_ty = type->As<Pointer>(); auto* ptr_ty = type->As<Pointer>();
EXPECT_NE(ptr_ty, nullptr); EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type->Is<F32>()); EXPECT_TRUE(ptr_ty->type->Is<F32>());
EXPECT_EQ(ptr_ty->address_space, type::AddressSpace::kPrivate); EXPECT_EQ(ptr_ty->address_space, builtin::AddressSpace::kPrivate);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -827,7 +827,7 @@ TEST_F(SpvParserTest, ConvertType_PointerFunction) {
auto* ptr_ty = type->As<Pointer>(); auto* ptr_ty = type->As<Pointer>();
EXPECT_NE(ptr_ty, nullptr); EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type->Is<F32>()); EXPECT_TRUE(ptr_ty->type->Is<F32>());
EXPECT_EQ(ptr_ty->address_space, type::AddressSpace::kFunction); EXPECT_EQ(ptr_ty->address_space, builtin::AddressSpace::kFunction);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -846,12 +846,12 @@ TEST_F(SpvParserTest, ConvertType_PointerToPointer) {
auto* ptr_ty = type->As<Pointer>(); auto* ptr_ty = type->As<Pointer>();
EXPECT_NE(ptr_ty, nullptr); EXPECT_NE(ptr_ty, nullptr);
EXPECT_EQ(ptr_ty->address_space, type::AddressSpace::kPrivate); EXPECT_EQ(ptr_ty->address_space, builtin::AddressSpace::kPrivate);
EXPECT_TRUE(ptr_ty->type->Is<Pointer>()); EXPECT_TRUE(ptr_ty->type->Is<Pointer>());
auto* ptr_ptr_ty = ptr_ty->type->As<Pointer>(); auto* ptr_ptr_ty = ptr_ty->type->As<Pointer>();
EXPECT_NE(ptr_ptr_ty, nullptr); EXPECT_NE(ptr_ptr_ty, nullptr);
EXPECT_EQ(ptr_ptr_ty->address_space, type::AddressSpace::kPrivate); EXPECT_EQ(ptr_ptr_ty->address_space, builtin::AddressSpace::kPrivate);
EXPECT_TRUE(ptr_ptr_ty->type->Is<F32>()); EXPECT_TRUE(ptr_ptr_ty->type->Is<F32>());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());

View File

@ -175,7 +175,7 @@ Type::~Type() = default;
Texture::~Texture() = default; Texture::~Texture() = default;
Pointer::Pointer(const Type* t, type::AddressSpace s, builtin::Access a) Pointer::Pointer(const Type* t, builtin::AddressSpace s, builtin::Access a)
: type(t), address_space(s), access(a) {} : type(t), address_space(s), access(a) {}
Pointer::Pointer(const Pointer&) = default; Pointer::Pointer(const Pointer&) = default;
@ -189,7 +189,7 @@ ast::Type Pointer::Build(ProgramBuilder& b) const {
return b.ty.pointer(type->Build(b), address_space, access); return b.ty.pointer(type->Build(b), address_space, access);
} }
Reference::Reference(const Type* t, type::AddressSpace s, builtin::Access a) Reference::Reference(const Type* t, builtin::AddressSpace s, builtin::Access a)
: type(t), address_space(s), access(a) {} : type(t), address_space(s), access(a) {}
Reference::Reference(const Reference&) = default; Reference::Reference(const Reference&) = default;
@ -474,13 +474,13 @@ const Type* TypeManager::AsUnsigned(const Type* ty) {
} }
const spirv::Pointer* TypeManager::Pointer(const Type* el, const spirv::Pointer* TypeManager::Pointer(const Type* el,
type::AddressSpace address_space, builtin::AddressSpace address_space,
builtin::Access access) { builtin::Access access) {
return state->pointers_.Get(el, address_space, access); return state->pointers_.Get(el, address_space, access);
} }
const spirv::Reference* TypeManager::Reference(const Type* el, const spirv::Reference* TypeManager::Reference(const Type* el,
type::AddressSpace address_space, builtin::AddressSpace address_space,
builtin::Access access) { builtin::Access access) {
return state->references_.Get(el, address_space, access); return state->references_.Get(el, address_space, access);
} }

View File

@ -21,9 +21,9 @@
#include "src/tint/ast/type.h" #include "src/tint/ast/type.h"
#include "src/tint/builtin/access.h" #include "src/tint/builtin/access.h"
#include "src/tint/builtin/address_space.h"
#include "src/tint/castable.h" #include "src/tint/castable.h"
#include "src/tint/symbol.h" #include "src/tint/symbol.h"
#include "src/tint/type/address_space.h"
#include "src/tint/type/sampler_kind.h" #include "src/tint/type/sampler_kind.h"
#include "src/tint/type/texel_format.h" #include "src/tint/type/texel_format.h"
#include "src/tint/type/texture_dimension.h" #include "src/tint/type/texture_dimension.h"
@ -162,7 +162,7 @@ struct Pointer final : public Castable<Pointer, Type> {
/// @param ty the store type /// @param ty the store type
/// @param sc the pointer address space /// @param sc the pointer address space
/// @param access the declared access mode /// @param access the declared access mode
Pointer(const Type* ty, type::AddressSpace sc, builtin::Access access); Pointer(const Type* ty, builtin::AddressSpace sc, builtin::Access access);
/// Copy constructor /// Copy constructor
/// @param other the other type to copy /// @param other the other type to copy
@ -180,7 +180,7 @@ struct Pointer final : public Castable<Pointer, Type> {
/// the store type /// the store type
Type const* const type; Type const* const type;
/// the pointer address space /// the pointer address space
type::AddressSpace const address_space; builtin::AddressSpace const address_space;
/// the pointer declared access mode /// the pointer declared access mode
builtin::Access const access; builtin::Access const access;
}; };
@ -193,7 +193,7 @@ struct Reference final : public Castable<Reference, Type> {
/// @param ty the referenced type /// @param ty the referenced type
/// @param sc the reference address space /// @param sc the reference address space
/// @param access the reference declared access mode /// @param access the reference declared access mode
Reference(const Type* ty, type::AddressSpace sc, builtin::Access access); Reference(const Type* ty, builtin::AddressSpace sc, builtin::Access access);
/// Copy constructor /// Copy constructor
/// @param other the other type to copy /// @param other the other type to copy
@ -211,7 +211,7 @@ struct Reference final : public Castable<Reference, Type> {
/// the store type /// the store type
Type const* const type; Type const* const type;
/// the pointer address space /// the pointer address space
type::AddressSpace const address_space; builtin::AddressSpace const address_space;
/// the pointer declared access mode /// the pointer declared access mode
builtin::Access const access; builtin::Access const access;
}; };
@ -549,7 +549,7 @@ class TypeManager {
/// @return a Pointer type. Repeated calls with the same arguments will return /// @return a Pointer type. Repeated calls with the same arguments will return
/// the same pointer. /// the same pointer.
const spirv::Pointer* Pointer(const Type* ty, const spirv::Pointer* Pointer(const Type* ty,
type::AddressSpace address_space, builtin::AddressSpace address_space,
builtin::Access access = builtin::Access::kUndefined); builtin::Access access = builtin::Access::kUndefined);
/// @param ty the referenced type /// @param ty the referenced type
/// @param address_space the reference address space /// @param address_space the reference address space
@ -557,7 +557,7 @@ class TypeManager {
/// @return a Reference type. Repeated calls with the same arguments will /// @return a Reference type. Repeated calls with the same arguments will
/// return the same pointer. /// return the same pointer.
const spirv::Reference* Reference(const Type* ty, const spirv::Reference* Reference(const Type* ty,
type::AddressSpace address_space, builtin::AddressSpace address_space,
builtin::Access access = builtin::Access::kUndefined); builtin::Access access = builtin::Access::kUndefined);
/// @param ty the element type /// @param ty the element type
/// @param sz the number of elements in the vector /// @param sz the number of elements in the vector

View File

@ -29,8 +29,8 @@ TEST(SpvParserTypeTest, SameArgumentsGivesSamePointer) {
EXPECT_EQ(ty.U32(), ty.U32()); EXPECT_EQ(ty.U32(), ty.U32());
EXPECT_EQ(ty.F32(), ty.F32()); EXPECT_EQ(ty.F32(), ty.F32());
EXPECT_EQ(ty.I32(), ty.I32()); EXPECT_EQ(ty.I32(), ty.I32());
EXPECT_EQ(ty.Pointer(ty.I32(), type::AddressSpace::kUndefined), EXPECT_EQ(ty.Pointer(ty.I32(), builtin::AddressSpace::kUndefined),
ty.Pointer(ty.I32(), type::AddressSpace::kUndefined)); ty.Pointer(ty.I32(), builtin::AddressSpace::kUndefined));
EXPECT_EQ(ty.Vector(ty.I32(), 3), ty.Vector(ty.I32(), 3)); EXPECT_EQ(ty.Vector(ty.I32(), 3), ty.Vector(ty.I32(), 3));
EXPECT_EQ(ty.Matrix(ty.I32(), 3, 2), ty.Matrix(ty.I32(), 3, 2)); EXPECT_EQ(ty.Matrix(ty.I32(), 3, 2), ty.Matrix(ty.I32(), 3, 2));
EXPECT_EQ(ty.Array(ty.I32(), 3, 2), ty.Array(ty.I32(), 3, 2)); EXPECT_EQ(ty.Array(ty.I32(), 3, 2), ty.Array(ty.I32(), 3, 2));
@ -54,10 +54,10 @@ TEST(SpvParserTypeTest, DifferentArgumentsGivesDifferentPointer) {
Symbol sym_b(Symbol(2, {})); Symbol sym_b(Symbol(2, {}));
TypeManager ty; TypeManager ty;
EXPECT_NE(ty.Pointer(ty.I32(), type::AddressSpace::kUndefined), EXPECT_NE(ty.Pointer(ty.I32(), builtin::AddressSpace::kUndefined),
ty.Pointer(ty.U32(), type::AddressSpace::kUndefined)); ty.Pointer(ty.U32(), builtin::AddressSpace::kUndefined));
EXPECT_NE(ty.Pointer(ty.I32(), type::AddressSpace::kUndefined), EXPECT_NE(ty.Pointer(ty.I32(), builtin::AddressSpace::kUndefined),
ty.Pointer(ty.I32(), type::AddressSpace::kIn)); ty.Pointer(ty.I32(), builtin::AddressSpace::kIn));
EXPECT_NE(ty.Vector(ty.I32(), 3), ty.Vector(ty.U32(), 3)); EXPECT_NE(ty.Vector(ty.I32(), 3), ty.Vector(ty.U32(), 3));
EXPECT_NE(ty.Vector(ty.I32(), 3), ty.Vector(ty.I32(), 2)); EXPECT_NE(ty.Vector(ty.I32(), 3), ty.Vector(ty.I32(), 2));
EXPECT_NE(ty.Matrix(ty.I32(), 3, 2), ty.Matrix(ty.U32(), 3, 2)); EXPECT_NE(ty.Matrix(ty.I32(), 3, 2), ty.Matrix(ty.U32(), 3, 2));

View File

@ -20,7 +20,7 @@ namespace {
struct VariableStorageData { struct VariableStorageData {
const char* input; const char* input;
type::AddressSpace address_space; builtin::AddressSpace address_space;
builtin::Access access; builtin::Access access;
}; };
inline std::ostream& operator<<(std::ostream& out, VariableStorageData data) { inline std::ostream& operator<<(std::ostream& out, VariableStorageData data) {
@ -38,7 +38,7 @@ TEST_P(VariableQualifierTest, ParsesAddressSpace) {
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
EXPECT_FALSE(sc.errored); EXPECT_FALSE(sc.errored);
EXPECT_TRUE(sc.matched); EXPECT_TRUE(sc.matched);
if (params.address_space != type::AddressSpace::kUndefined) { if (params.address_space != builtin::AddressSpace::kUndefined) {
ast::CheckIdentifier(p->builder().Symbols(), sc->address_space, ast::CheckIdentifier(p->builder().Symbols(), sc->address_space,
utils::ToString(params.address_space)); utils::ToString(params.address_space));
} else { } else {
@ -56,18 +56,22 @@ TEST_P(VariableQualifierTest, ParsesAddressSpace) {
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
ParserImplTest, ParserImplTest,
VariableQualifierTest, VariableQualifierTest,
testing::Values( testing::Values(VariableStorageData{"uniform", builtin::AddressSpace::kUniform,
VariableStorageData{"uniform", type::AddressSpace::kUniform, builtin::Access::kUndefined}, builtin::Access::kUndefined},
VariableStorageData{"workgroup", type::AddressSpace::kWorkgroup, VariableStorageData{"workgroup", builtin::AddressSpace::kWorkgroup,
builtin::Access::kUndefined}, builtin::Access::kUndefined},
VariableStorageData{"storage", type::AddressSpace::kStorage, builtin::Access::kUndefined}, VariableStorageData{"storage", builtin::AddressSpace::kStorage,
VariableStorageData{"private", type::AddressSpace::kPrivate, builtin::Access::kUndefined}, builtin::Access::kUndefined},
VariableStorageData{"function", type::AddressSpace::kFunction, builtin::Access::kUndefined}, VariableStorageData{"private", builtin::AddressSpace::kPrivate,
VariableStorageData{"storage, read", type::AddressSpace::kStorage, builtin::Access::kRead}, builtin::Access::kUndefined},
VariableStorageData{"storage, write", type::AddressSpace::kStorage, VariableStorageData{"function", builtin::AddressSpace::kFunction,
builtin::Access::kWrite}, builtin::Access::kUndefined},
VariableStorageData{"storage, read_write", type::AddressSpace::kStorage, VariableStorageData{"storage, read", builtin::AddressSpace::kStorage,
builtin::Access::kReadWrite})); builtin::Access::kRead},
VariableStorageData{"storage, write", builtin::AddressSpace::kStorage,
builtin::Access::kWrite},
VariableStorageData{"storage, read_write", builtin::AddressSpace::kStorage,
builtin::Access::kReadWrite}));
TEST_F(ParserImplTest, VariableQualifier_Empty) { TEST_F(ParserImplTest, VariableQualifier_Empty) {
auto p = parser("var<> name"); auto p = parser("var<> name");

View File

@ -39,7 +39,7 @@ TEST_F(ResolverAddressSpaceLayoutValidationTest, StorageBuffer_UnalignedMember)
Member(Source{{34, 56}}, "b", ty.f32(), utils::Vector{MemberAlign(1_i)}), Member(Source{{34, 56}}, "b", ty.f32(), utils::Vector{MemberAlign(1_i)}),
}); });
GlobalVar(Source{{78, 90}}, "a", ty("S"), type::AddressSpace::kStorage, Group(0_a), GlobalVar(Source{{78, 90}}, "a", ty("S"), builtin::AddressSpace::kStorage, Group(0_a),
Binding(0_a)); Binding(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -69,7 +69,7 @@ TEST_F(ResolverAddressSpaceLayoutValidationTest, StorageBuffer_UnalignedMember_S
Member(Source{{34, 56}}, "b", ty.f32(), utils::Vector{MemberAlign(4_i)}), Member(Source{{34, 56}}, "b", ty.f32(), utils::Vector{MemberAlign(4_i)}),
}); });
GlobalVar(Source{{78, 90}}, "a", ty("S"), type::AddressSpace::kStorage, Group(0_a), GlobalVar(Source{{78, 90}}, "a", ty("S"), builtin::AddressSpace::kStorage, Group(0_a),
Binding(0_a)); Binding(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -100,7 +100,7 @@ TEST_F(ResolverAddressSpaceLayoutValidationTest, UniformBuffer_UnalignedMember_S
Member(Source{{56, 78}}, "inner", ty("Inner")), Member(Source{{56, 78}}, "inner", ty("Inner")),
}); });
GlobalVar(Source{{78, 90}}, "a", ty("Outer"), type::AddressSpace::kUniform, Group(0_a), GlobalVar(Source{{78, 90}}, "a", ty("Outer"), builtin::AddressSpace::kUniform, Group(0_a),
Binding(0_a)); Binding(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -144,7 +144,7 @@ TEST_F(ResolverAddressSpaceLayoutValidationTest,
Member(Source{{56, 78}}, "inner", ty("Inner"), utils::Vector{MemberAlign(16_i)}), Member(Source{{56, 78}}, "inner", ty("Inner"), utils::Vector{MemberAlign(16_i)}),
}); });
GlobalVar(Source{{78, 90}}, "a", ty("Outer"), type::AddressSpace::kUniform, Group(0_a), GlobalVar(Source{{78, 90}}, "a", ty("Outer"), builtin::AddressSpace::kUniform, Group(0_a),
Binding(0_a)); Binding(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -169,7 +169,7 @@ TEST_F(ResolverAddressSpaceLayoutValidationTest, UniformBuffer_UnalignedMember_A
Member(Source{{56, 78}}, "inner", ty("Inner")), Member(Source{{56, 78}}, "inner", ty("Inner")),
}); });
GlobalVar(Source{{78, 90}}, "a", ty("Outer"), type::AddressSpace::kUniform, Group(0_a), GlobalVar(Source{{78, 90}}, "a", ty("Outer"), builtin::AddressSpace::kUniform, Group(0_a),
Binding(0_a)); Binding(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -202,7 +202,7 @@ TEST_F(ResolverAddressSpaceLayoutValidationTest, UniformBuffer_UnalignedMember_A
Member(Source{{34, 56}}, "inner", ty("Inner"), utils::Vector{MemberAlign(16_i)}), Member(Source{{34, 56}}, "inner", ty("Inner"), utils::Vector{MemberAlign(16_i)}),
}); });
GlobalVar(Source{{78, 90}}, "a", ty("Outer"), type::AddressSpace::kUniform, Group(0_a), GlobalVar(Source{{78, 90}}, "a", ty("Outer"), builtin::AddressSpace::kUniform, Group(0_a),
Binding(0_a)); Binding(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -234,7 +234,7 @@ TEST_F(ResolverAddressSpaceLayoutValidationTest, UniformBuffer_MembersOffsetNotM
Member(Source{{78, 90}}, "scalar", ty.i32()), Member(Source{{78, 90}}, "scalar", ty.i32()),
}); });
GlobalVar(Source{{22, 24}}, "a", ty("Outer"), type::AddressSpace::kUniform, Group(0_a), GlobalVar(Source{{22, 24}}, "a", ty("Outer"), builtin::AddressSpace::kUniform, Group(0_a),
Binding(0_a)); Binding(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -286,7 +286,7 @@ TEST_F(ResolverAddressSpaceLayoutValidationTest,
Member(Source{{78, 90}}, "scalar", ty.i32()), Member(Source{{78, 90}}, "scalar", ty.i32()),
}); });
GlobalVar(Source{{22, 24}}, "a", ty("Outer"), type::AddressSpace::kUniform, Group(0_a), GlobalVar(Source{{22, 24}}, "a", ty("Outer"), builtin::AddressSpace::kUniform, Group(0_a),
Binding(0_a)); Binding(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -334,7 +334,7 @@ TEST_F(ResolverAddressSpaceLayoutValidationTest,
Member(Source{{78, 90}}, "scalar", ty.i32(), utils::Vector{MemberAlign(16_i)}), Member(Source{{78, 90}}, "scalar", ty.i32(), utils::Vector{MemberAlign(16_i)}),
}); });
GlobalVar(Source{{22, 34}}, "a", ty("Outer"), type::AddressSpace::kUniform, Group(0_a), GlobalVar(Source{{22, 34}}, "a", ty("Outer"), builtin::AddressSpace::kUniform, Group(0_a),
Binding(0_a)); Binding(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -355,7 +355,7 @@ TEST_F(ResolverAddressSpaceLayoutValidationTest, UniformBuffer_Vec3MemberOffset_
Member("s", ty.f32()), Member("s", ty.f32()),
}); });
GlobalVar(Source{{78, 90}}, "a", ty("ScalarPackedAtEndOfVec3"), type::AddressSpace::kUniform, GlobalVar(Source{{78, 90}}, "a", ty("ScalarPackedAtEndOfVec3"), builtin::AddressSpace::kUniform,
Group(0_a), Binding(0_a)); Group(0_a), Binding(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -378,7 +378,7 @@ TEST_F(ResolverAddressSpaceLayoutValidationTest, UniformBuffer_Vec3F16MemberOffs
Member("s", ty.f16()), Member("s", ty.f16()),
}); });
GlobalVar(Source{{78, 90}}, "a", ty("ScalarPackedAtEndOfVec3"), type::AddressSpace::kUniform, GlobalVar(Source{{78, 90}}, "a", ty("ScalarPackedAtEndOfVec3"), builtin::AddressSpace::kUniform,
Group(0_a), Binding(0_a)); Group(0_a), Binding(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -404,7 +404,7 @@ TEST_F(ResolverAddressSpaceLayoutValidationTest, UniformBuffer_InvalidArrayStrid
Member("scalar", ty.i32()), Member("scalar", ty.i32()),
}); });
GlobalVar(Source{{78, 90}}, "a", ty("Outer"), type::AddressSpace::kUniform, Group(0_a), GlobalVar(Source{{78, 90}}, "a", ty("Outer"), builtin::AddressSpace::kUniform, Group(0_a),
Binding(0_a)); Binding(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -438,7 +438,7 @@ TEST_F(ResolverAddressSpaceLayoutValidationTest, UniformBuffer_InvalidArrayStrid
Member("scalar", ty.i32()), Member("scalar", ty.i32()),
}); });
GlobalVar(Source{{78, 90}}, "a", ty("Outer"), type::AddressSpace::kUniform, Group(0_a), GlobalVar(Source{{78, 90}}, "a", ty("Outer"), builtin::AddressSpace::kUniform, Group(0_a),
Binding(0_a)); Binding(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -481,7 +481,7 @@ TEST_F(ResolverAddressSpaceLayoutValidationTest, UniformBuffer_InvalidArrayStrid
Member("scalar", ty.i32()), Member("scalar", ty.i32()),
}); });
GlobalVar(Source{{78, 90}}, "a", ty("Outer"), type::AddressSpace::kUniform, Group(0_a), GlobalVar(Source{{78, 90}}, "a", ty("Outer"), builtin::AddressSpace::kUniform, Group(0_a),
Binding(0_a)); Binding(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -500,7 +500,7 @@ TEST_F(ResolverAddressSpaceLayoutValidationTest, UniformBuffer_InvalidArrayStrid
// @group(0) @binding(0) // @group(0) @binding(0)
// var<uniform> a : array<f32, 4u>; // var<uniform> a : array<f32, 4u>;
GlobalVar(Source{{78, 90}}, "a", ty.array(Source{{34, 56}}, ty.f32(), 4_u), GlobalVar(Source{{78, 90}}, "a", ty.array(Source{{34, 56}}, ty.f32(), 4_u),
type::AddressSpace::kUniform, Group(0_a), Binding(0_a)); builtin::AddressSpace::kUniform, Group(0_a), Binding(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
EXPECT_EQ( EXPECT_EQ(
@ -521,7 +521,7 @@ TEST_F(ResolverAddressSpaceLayoutValidationTest, UniformBuffer_InvalidArrayStrid
Member("inner", ty.array(Source{{34, 56}}, ty.array<f32, 4>(), 4_u)), Member("inner", ty.array(Source{{34, 56}}, ty.array<f32, 4>(), 4_u)),
}); });
GlobalVar(Source{{78, 90}}, "a", ty("Outer"), type::AddressSpace::kUniform, Group(0_a), GlobalVar(Source{{78, 90}}, "a", ty("Outer"), builtin::AddressSpace::kUniform, Group(0_a),
Binding(0_a)); Binding(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -554,7 +554,7 @@ TEST_F(ResolverAddressSpaceLayoutValidationTest, UniformBuffer_InvalidArrayStrid
Member("scalar", ty.i32()), Member("scalar", ty.i32()),
}); });
GlobalVar(Source{{78, 90}}, "a", ty("Outer"), type::AddressSpace::kUniform, Group(0_a), GlobalVar(Source{{78, 90}}, "a", ty("Outer"), builtin::AddressSpace::kUniform, Group(0_a),
Binding(0_a)); Binding(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -573,7 +573,7 @@ TEST_F(ResolverAddressSpaceLayoutValidationTest, PushConstant_UnalignedMember) {
Source{{12, 34}}, "S", Source{{12, 34}}, "S",
utils::Vector{Member("a", ty.f32(), utils::Vector{MemberSize(5_a)}), utils::Vector{Member("a", ty.f32(), utils::Vector{MemberSize(5_a)}),
Member(Source{{34, 56}}, "b", ty.f32(), utils::Vector{MemberAlign(1_i)})}); Member(Source{{34, 56}}, "b", ty.f32(), utils::Vector{MemberAlign(1_i)})});
GlobalVar(Source{{78, 90}}, "a", ty("S"), type::AddressSpace::kPushConstant); GlobalVar(Source{{78, 90}}, "a", ty("S"), builtin::AddressSpace::kPushConstant);
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
EXPECT_EQ( EXPECT_EQ(
@ -598,7 +598,7 @@ TEST_F(ResolverAddressSpaceLayoutValidationTest, PushConstant_Aligned) {
Enable(builtin::Extension::kChromiumExperimentalPushConstant); Enable(builtin::Extension::kChromiumExperimentalPushConstant);
Structure("S", utils::Vector{Member("a", ty.f32(), utils::Vector{MemberSize(5_a)}), Structure("S", utils::Vector{Member("a", ty.f32(), utils::Vector{MemberSize(5_a)}),
Member("b", ty.f32(), utils::Vector{MemberAlign(4_i)})}); Member("b", ty.f32(), utils::Vector{MemberAlign(4_i)})});
GlobalVar("a", ty("S"), type::AddressSpace::kPushConstant); GlobalVar("a", ty("S"), builtin::AddressSpace::kPushConstant);
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }

View File

@ -47,7 +47,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_NoAddressSpace_Fail) {
TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_FunctionAddressSpace_Fail) { TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_FunctionAddressSpace_Fail) {
// var<private> g : f32; // var<private> g : f32;
GlobalVar(Source{{12, 34}}, "g", ty.f32(), type::AddressSpace::kFunction); GlobalVar(Source{{12, 34}}, "g", ty.f32(), builtin::AddressSpace::kFunction);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -57,7 +57,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_FunctionAddressSpace_F
TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Private_RuntimeArray) { TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Private_RuntimeArray) {
// var<private> v : array<i32>; // var<private> v : array<i32>;
GlobalVar(Source{{56, 78}}, "v", ty.array(Source{{12, 34}}, ty.i32()), GlobalVar(Source{{56, 78}}, "v", ty.array(Source{{12, 34}}, ty.i32()),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -68,7 +68,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Private_RuntimeArray)
TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Private_RuntimeArray) { TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Private_RuntimeArray) {
// type t : ptr<private, array<i32>>; // type t : ptr<private, array<i32>>;
Alias("t", ty.pointer(Source{{56, 78}}, ty.array(Source{{12, 34}}, ty.i32()), Alias("t", ty.pointer(Source{{56, 78}}, ty.array(Source{{12, 34}}, ty.i32()),
type::AddressSpace::kPrivate)); builtin::AddressSpace::kPrivate));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -80,7 +80,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Private_RuntimeArrayIn
// struct S { m : array<i32> }; // struct S { m : array<i32> };
// var<private> v : S; // var<private> v : S;
Structure("S", utils::Vector{Member(Source{{12, 34}}, "m", ty.array(ty.i32()))}); Structure("S", utils::Vector{Member(Source{{12, 34}}, "m", ty.array(ty.i32()))});
GlobalVar(Source{{56, 78}}, "v", ty("S"), type::AddressSpace::kPrivate); GlobalVar(Source{{56, 78}}, "v", ty("S"), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -93,7 +93,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Private_RuntimeArrayInSt
// struct S { m : array<i32> }; // struct S { m : array<i32> };
// type t = ptr<private, S>; // type t = ptr<private, S>;
Structure("S", utils::Vector{Member(Source{{12, 34}}, "m", ty.array(ty.i32()))}); Structure("S", utils::Vector{Member(Source{{12, 34}}, "m", ty.array(ty.i32()))});
Alias("t", ty.pointer(ty("S"), type::AddressSpace::kPrivate)); Alias("t", ty.pointer(ty("S"), builtin::AddressSpace::kPrivate));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -105,7 +105,7 @@ note: while instantiating ptr<private, S, read_write>)");
TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Workgroup_RuntimeArray) { TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Workgroup_RuntimeArray) {
// var<workgroup> v : array<i32>; // var<workgroup> v : array<i32>;
GlobalVar(Source{{56, 78}}, "v", ty.array(Source{{12, 34}}, ty.i32()), GlobalVar(Source{{56, 78}}, "v", ty.array(Source{{12, 34}}, ty.i32()),
type::AddressSpace::kWorkgroup); builtin::AddressSpace::kWorkgroup);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -115,7 +115,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Workgroup_RuntimeArray
TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Workgroup_RuntimeArray) { TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Workgroup_RuntimeArray) {
// type t = ptr<workgroup, array<i32>>; // type t = ptr<workgroup, array<i32>>;
Alias("t", ty.pointer(ty.array(Source{{12, 34}}, ty.i32()), type::AddressSpace::kWorkgroup)); Alias("t", ty.pointer(ty.array(Source{{12, 34}}, ty.i32()), builtin::AddressSpace::kWorkgroup));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -127,7 +127,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Workgroup_RuntimeArray
// struct S { m : array<i32> }; // struct S { m : array<i32> };
// var<workgroup> v : S; // var<workgroup> v : S;
Structure("S", utils::Vector{Member(Source{{12, 34}}, "m", ty.array(ty.i32()))}); Structure("S", utils::Vector{Member(Source{{12, 34}}, "m", ty.array(ty.i32()))});
GlobalVar(Source{{56, 78}}, "v", ty("S"), type::AddressSpace::kWorkgroup); GlobalVar(Source{{56, 78}}, "v", ty("S"), builtin::AddressSpace::kWorkgroup);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -140,7 +140,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Workgroup_RuntimeArrayIn
// struct S { m : array<i32> }; // struct S { m : array<i32> };
// type t = ptr<workgroup, S>; // type t = ptr<workgroup, S>;
Structure("S", utils::Vector{Member(Source{{12, 34}}, "m", ty.array(ty.i32()))}); Structure("S", utils::Vector{Member(Source{{12, 34}}, "m", ty.array(ty.i32()))});
Alias(Source{{56, 78}}, "t", ty.pointer(ty("S"), type::AddressSpace::kWorkgroup)); Alias(Source{{56, 78}}, "t", ty.pointer(ty("S"), builtin::AddressSpace::kWorkgroup));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -151,7 +151,7 @@ note: while instantiating ptr<workgroup, S, read_write>)");
TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_Bool) { TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_Bool) {
// var<storage> g : bool; // var<storage> g : bool;
GlobalVar(Source{{56, 78}}, "g", ty.bool_(Source{{12, 34}}), type::AddressSpace::kStorage, GlobalVar(Source{{56, 78}}, "g", ty.bool_(Source{{12, 34}}), builtin::AddressSpace::kStorage,
Binding(0_a), Group(0_a)); Binding(0_a), Group(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -165,7 +165,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_Bool) {
TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_Bool) { TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_Bool) {
// type t = ptr<storage, bool>; // type t = ptr<storage, bool>;
Alias(Source{{56, 78}}, "t", Alias(Source{{56, 78}}, "t",
ty.pointer(ty.bool_(Source{{12, 34}}), type::AddressSpace::kStorage)); ty.pointer(ty.bool_(Source{{12, 34}}), builtin::AddressSpace::kStorage));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -179,7 +179,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_BoolAlias) {
// type a = bool; // type a = bool;
// @binding(0) @group(0) var<storage, read> g : a; // @binding(0) @group(0) var<storage, read> g : a;
Alias("a", ty.bool_()); Alias("a", ty.bool_());
GlobalVar(Source{{56, 78}}, "g", ty(Source{{12, 34}}, "a"), type::AddressSpace::kStorage, GlobalVar(Source{{56, 78}}, "g", ty(Source{{12, 34}}, "a"), builtin::AddressSpace::kStorage,
Binding(0_a), Group(0_a)); Binding(0_a), Group(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -195,7 +195,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_BoolAlias) {
// type t = ptr<storage, a>; // type t = ptr<storage, a>;
Alias("a", ty.bool_()); Alias("a", ty.bool_());
Alias(Source{{56, 78}}, "t", Alias(Source{{56, 78}}, "t",
ty.pointer(ty(Source{{12, 34}}, "a"), type::AddressSpace::kStorage)); ty.pointer(ty(Source{{12, 34}}, "a"), builtin::AddressSpace::kStorage));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -208,8 +208,8 @@ note: while instantiating ptr<storage, bool, read>)");
TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_Pointer) { TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_Pointer) {
// var<storage> g : ptr<private, f32>; // var<storage> g : ptr<private, f32>;
GlobalVar(Source{{56, 78}}, "g", GlobalVar(Source{{56, 78}}, "g",
ty.pointer(Source{{12, 34}}, ty.f32(), type::AddressSpace::kPrivate), ty.pointer(Source{{12, 34}}, ty.f32(), builtin::AddressSpace::kPrivate),
type::AddressSpace::kStorage, Binding(0_a), Group(0_a)); builtin::AddressSpace::kStorage, Binding(0_a), Group(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -222,8 +222,8 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_Pointer) {
TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_Pointer) { TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_Pointer) {
// type t = ptr<storage, ptr<private, f32>>; // type t = ptr<storage, ptr<private, f32>>;
Alias("t", ty.pointer(Source{{56, 78}}, Alias("t", ty.pointer(Source{{56, 78}},
ty.pointer(Source{{12, 34}}, ty.f32(), type::AddressSpace::kPrivate), ty.pointer(Source{{12, 34}}, ty.f32(), builtin::AddressSpace::kPrivate),
type::AddressSpace::kStorage)); builtin::AddressSpace::kStorage));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -235,14 +235,14 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_Pointer) {
TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_IntScalar) { TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_IntScalar) {
// var<storage> g : i32; // var<storage> g : i32;
GlobalVar("g", ty.i32(), type::AddressSpace::kStorage, Binding(0_a), Group(0_a)); GlobalVar("g", ty.i32(), builtin::AddressSpace::kStorage, Binding(0_a), Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_IntScalar) { TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_IntScalar) {
// type t = ptr<storage, i32; // type t = ptr<storage, i32;
Alias("t", ty.pointer(ty.i32(), type::AddressSpace::kStorage)); Alias("t", ty.pointer(ty.i32(), builtin::AddressSpace::kStorage));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -252,7 +252,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_F16) {
// var<storage> g : f16; // var<storage> g : f16;
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
GlobalVar("g", ty.f16(), type::AddressSpace::kStorage, Binding(0_a), Group(0_a)); GlobalVar("g", ty.f16(), builtin::AddressSpace::kStorage, Binding(0_a), Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -262,7 +262,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_F16) {
// type t = ptr<storage, f16>; // type t = ptr<storage, f16>;
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
Alias("t", ty.pointer(ty.f16(), type::AddressSpace::kStorage)); Alias("t", ty.pointer(ty.f16(), builtin::AddressSpace::kStorage));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -274,7 +274,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_F16Alias) {
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
Alias("a", ty.f16()); Alias("a", ty.f16());
GlobalVar("g", ty("a"), type::AddressSpace::kStorage, Binding(0_a), Group(0_a)); GlobalVar("g", ty("a"), builtin::AddressSpace::kStorage, Binding(0_a), Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -286,21 +286,21 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_F16Alias) {
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
Alias("a", ty.f16()); Alias("a", ty.f16());
Alias("t", ty.pointer(ty("a"), type::AddressSpace::kStorage)); Alias("t", ty.pointer(ty("a"), builtin::AddressSpace::kStorage));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_VectorF32) { TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_VectorF32) {
// var<storage> g : vec4<f32>; // var<storage> g : vec4<f32>;
GlobalVar("g", ty.vec4<f32>(), type::AddressSpace::kStorage, Binding(0_a), Group(0_a)); GlobalVar("g", ty.vec4<f32>(), builtin::AddressSpace::kStorage, Binding(0_a), Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_VectorF32) { TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_VectorF32) {
// type t = ptr<storage, vec4<f32>>; // type t = ptr<storage, vec4<f32>>;
Alias("t", ty.pointer(ty.vec4<f32>(), type::AddressSpace::kStorage)); Alias("t", ty.pointer(ty.vec4<f32>(), builtin::AddressSpace::kStorage));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -308,7 +308,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_VectorF32) {
TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_VectorF16) { TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_VectorF16) {
// var<storage> g : vec4<f16>; // var<storage> g : vec4<f16>;
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
GlobalVar("g", ty.vec(ty.f16(), 4u), type::AddressSpace::kStorage, Binding(0_a), Group(0_a)); GlobalVar("g", ty.vec(ty.f16(), 4u), builtin::AddressSpace::kStorage, Binding(0_a), Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -316,7 +316,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_VectorF16) {
TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_VectorF16) { TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_VectorF16) {
// type t = ptr<storage, vec4<f16>>; // type t = ptr<storage, vec4<f16>>;
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
Alias("t", ty.pointer(ty.vec(ty.f16(), 4u), type::AddressSpace::kStorage)); Alias("t", ty.pointer(ty.vec(ty.f16(), 4u), builtin::AddressSpace::kStorage));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -325,7 +325,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_ArrayF32) {
// struct S{ a : f32 }; // struct S{ a : f32 };
// var<storage, read> g : array<S, 3u>; // var<storage, read> g : array<S, 3u>;
Structure("S", utils::Vector{Member("a", ty.f32())}); Structure("S", utils::Vector{Member("a", ty.f32())});
GlobalVar("g", ty.array(ty("S"), 3_u), type::AddressSpace::kStorage, builtin::Access::kRead, GlobalVar("g", ty.array(ty("S"), 3_u), builtin::AddressSpace::kStorage, builtin::Access::kRead,
Binding(0_a), Group(0_a)); Binding(0_a), Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -335,7 +335,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_ArrayF32) {
// struct S{ a : f32 }; // struct S{ a : f32 };
// type t = ptr<storage, array<S, 3u>>; // type t = ptr<storage, array<S, 3u>>;
Structure("S", utils::Vector{Member("a", ty.f32())}); Structure("S", utils::Vector{Member("a", ty.f32())});
Alias("t", ty.pointer(ty.array(ty("S"), 3_u), type::AddressSpace::kStorage)); Alias("t", ty.pointer(ty.array(ty("S"), 3_u), builtin::AddressSpace::kStorage));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -347,7 +347,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_ArrayF16) {
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
Structure("S", utils::Vector{Member("a", ty.f16())}); Structure("S", utils::Vector{Member("a", ty.f16())});
GlobalVar("g", ty.array(ty("S"), 3_u), type::AddressSpace::kStorage, builtin::Access::kRead, GlobalVar("g", ty.array(ty("S"), 3_u), builtin::AddressSpace::kStorage, builtin::Access::kRead,
Binding(0_a), Group(0_a)); Binding(0_a), Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -360,8 +360,8 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_ArrayF16) {
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
Structure("S", utils::Vector{Member("a", ty.f16())}); Structure("S", utils::Vector{Member("a", ty.f16())});
Alias("t", Alias("t", ty.pointer(ty.array(ty("S"), 3_u), builtin::AddressSpace::kStorage,
ty.pointer(ty.array(ty("S"), 3_u), type::AddressSpace::kStorage, builtin::Access::kRead)); builtin::Access::kRead));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -370,7 +370,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_StructI32) {
// struct S { x : i32 }; // struct S { x : i32 };
// var<storage, read> g : S; // var<storage, read> g : S;
Structure("S", utils::Vector{Member("x", ty.i32())}); Structure("S", utils::Vector{Member("x", ty.i32())});
GlobalVar("g", ty("S"), type::AddressSpace::kStorage, builtin::Access::kRead, Binding(0_a), GlobalVar("g", ty("S"), builtin::AddressSpace::kStorage, builtin::Access::kRead, Binding(0_a),
Group(0_a)); Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -380,7 +380,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_StructI32) {
// struct S { x : i32 }; // struct S { x : i32 };
// type t = ptr<storage, read, S>; // type t = ptr<storage, read, S>;
Structure("S", utils::Vector{Member("x", ty.i32())}); Structure("S", utils::Vector{Member("x", ty.i32())});
Alias("t", ty.pointer(ty("S"), type::AddressSpace::kStorage, builtin::Access::kRead)); Alias("t", ty.pointer(ty("S"), builtin::AddressSpace::kStorage, builtin::Access::kRead));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -392,7 +392,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_StructI32Alias
Structure("S", utils::Vector{Member("x", ty.i32())}); Structure("S", utils::Vector{Member("x", ty.i32())});
Alias("a1", ty("S")); Alias("a1", ty("S"));
Alias("a2", ty("a1")); Alias("a2", ty("a1"));
GlobalVar("g", ty("a2"), type::AddressSpace::kStorage, builtin::Access::kRead, Binding(0_a), GlobalVar("g", ty("a2"), builtin::AddressSpace::kStorage, builtin::Access::kRead, Binding(0_a),
Group(0_a)); Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -405,7 +405,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_StructI32Aliases
Structure("S", utils::Vector{Member("x", ty.i32())}); Structure("S", utils::Vector{Member("x", ty.i32())});
Alias("a1", ty("S")); Alias("a1", ty("S"));
Alias("a2", ty("a1")); Alias("a2", ty("a1"));
Alias("t", ty.pointer(ty("a2"), type::AddressSpace::kStorage, builtin::Access::kRead)); Alias("t", ty.pointer(ty("a2"), builtin::AddressSpace::kStorage, builtin::Access::kRead));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -416,7 +416,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_StructF16) {
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
Structure("S", utils::Vector{Member("x", ty.f16())}); Structure("S", utils::Vector{Member("x", ty.f16())});
GlobalVar("g", ty("S"), type::AddressSpace::kStorage, builtin::Access::kRead, Binding(0_a), GlobalVar("g", ty("S"), builtin::AddressSpace::kStorage, builtin::Access::kRead, Binding(0_a),
Group(0_a)); Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -428,7 +428,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_StructF16) {
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
Structure("S", utils::Vector{Member("x", ty.f16())}); Structure("S", utils::Vector{Member("x", ty.f16())});
Alias("t", ty.pointer(ty("S"), type::AddressSpace::kStorage, builtin::Access::kRead)); Alias("t", ty.pointer(ty("S"), builtin::AddressSpace::kStorage, builtin::Access::kRead));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -442,7 +442,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_StructF16Alias
Structure("S", utils::Vector{Member("x", ty.f16())}); Structure("S", utils::Vector{Member("x", ty.f16())});
Alias("a1", ty("S")); Alias("a1", ty("S"));
Alias("a2", ty("a1")); Alias("a2", ty("a1"));
GlobalVar("g", ty("a2"), type::AddressSpace::kStorage, builtin::Access::kRead, Binding(0_a), GlobalVar("g", ty("a2"), builtin::AddressSpace::kStorage, builtin::Access::kRead, Binding(0_a),
Group(0_a)); Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -457,14 +457,14 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_StructF16Aliases
Structure("S", utils::Vector{Member("x", ty.f16())}); Structure("S", utils::Vector{Member("x", ty.f16())});
Alias("a1", ty("S")); Alias("a1", ty("S"));
Alias("a2", ty("a1")); Alias("a2", ty("a1"));
Alias("g", ty.pointer(ty("a2"), type::AddressSpace::kStorage, builtin::Access::kRead)); Alias("g", ty.pointer(ty("a2"), builtin::AddressSpace::kStorage, builtin::Access::kRead));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_NotStorage_AccessMode) { TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_NotStorage_AccessMode) {
// var<private, read> g : a; // var<private, read> g : a;
GlobalVar(Source{{12, 34}}, "g", ty.i32(), type::AddressSpace::kPrivate, GlobalVar(Source{{12, 34}}, "g", ty.i32(), builtin::AddressSpace::kPrivate,
builtin::Access::kRead); builtin::Access::kRead);
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -476,7 +476,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_NotStorage_AccessMode)
TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_NotStorage_AccessMode) { TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_NotStorage_AccessMode) {
// type t = ptr<private, i32, read>; // type t = ptr<private, i32, read>;
Alias("t", ty.pointer(Source{{12, 34}}, ty.i32(), type::AddressSpace::kPrivate, Alias("t", ty.pointer(Source{{12, 34}}, ty.i32(), builtin::AddressSpace::kPrivate,
builtin::Access::kRead)); builtin::Access::kRead));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -488,7 +488,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_NotStorage_AccessMode) {
TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_ReadAccessMode) { TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_ReadAccessMode) {
// @group(0) @binding(0) var<storage, read> a : i32; // @group(0) @binding(0) var<storage, read> a : i32;
GlobalVar("a", ty.i32(), type::AddressSpace::kStorage, builtin::Access::kRead, Group(0_a), GlobalVar("a", ty.i32(), builtin::AddressSpace::kStorage, builtin::Access::kRead, Group(0_a),
Binding(0_a)); Binding(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -496,29 +496,29 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_ReadAccessMode
TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_ReadAccessMode) { TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_ReadAccessMode) {
// type t = ptr<storage, read, i32>; // type t = ptr<storage, read, i32>;
Alias("t", ty.pointer(ty.i32(), type::AddressSpace::kStorage, builtin::Access::kRead)); Alias("t", ty.pointer(ty.i32(), builtin::AddressSpace::kStorage, builtin::Access::kRead));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_ReadWriteAccessMode) { TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_ReadWriteAccessMode) {
// @group(0) @binding(0) var<storage, read_write> a : i32; // @group(0) @binding(0) var<storage, read_write> a : i32;
GlobalVar("a", ty.i32(), type::AddressSpace::kStorage, builtin::Access::kReadWrite, Group(0_a), GlobalVar("a", ty.i32(), builtin::AddressSpace::kStorage, builtin::Access::kReadWrite,
Binding(0_a)); Group(0_a), Binding(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_ReadWriteAccessMode) { TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_ReadWriteAccessMode) {
// type t = ptr<storage, read_write, i32>; // type t = ptr<storage, read_write, i32>;
Alias("t", ty.pointer(ty.i32(), type::AddressSpace::kStorage, builtin::Access::kReadWrite)); Alias("t", ty.pointer(ty.i32(), builtin::AddressSpace::kStorage, builtin::Access::kReadWrite));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_WriteAccessMode) { TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_WriteAccessMode) {
// @group(0) @binding(0) var<storage, read_write> a : i32; // @group(0) @binding(0) var<storage, read_write> a : i32;
GlobalVar(Source{{12, 34}}, "a", ty.i32(), type::AddressSpace::kStorage, GlobalVar(Source{{12, 34}}, "a", ty.i32(), builtin::AddressSpace::kStorage,
builtin::Access::kWrite, Group(0_a), Binding(0_a)); builtin::Access::kWrite, Group(0_a), Binding(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -529,7 +529,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_Storage_WriteAccessMod
TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_WriteAccessMode) { TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_Storage_WriteAccessMode) {
// type t = ptr<storage, read_write, i32>; // type t = ptr<storage, read_write, i32>;
Alias("t", ty.pointer(Source{{12, 34}}, ty.i32(), type::AddressSpace::kStorage, Alias("t", ty.pointer(Source{{12, 34}}, ty.i32(), builtin::AddressSpace::kStorage,
builtin::Access::kWrite)); builtin::Access::kWrite));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -545,7 +545,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformBuffer_Struct_R
Structure("S", Structure("S",
utils::Vector{Member(Source{{56, 78}}, "m", ty.array(Source{{12, 34}}, ty.i32()))}); utils::Vector{Member(Source{{56, 78}}, "m", ty.array(Source{{12, 34}}, ty.i32()))});
GlobalVar(Source{{90, 12}}, "svar", ty("S"), type::AddressSpace::kUniform, Binding(0_a), GlobalVar(Source{{90, 12}}, "svar", ty("S"), builtin::AddressSpace::kUniform, Binding(0_a),
Group(0_a)); Group(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -562,7 +562,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformBuffer_Struct_Run
Structure("S", Structure("S",
utils::Vector{Member(Source{{56, 78}}, "m", ty.array(Source{{12, 34}}, ty.i32()))}); utils::Vector{Member(Source{{56, 78}}, "m", ty.array(Source{{12, 34}}, ty.i32()))});
Alias("t", ty.pointer(Source{{90, 12}}, ty("S"), type::AddressSpace::kUniform)); Alias("t", ty.pointer(Source{{90, 12}}, ty("S"), builtin::AddressSpace::kUniform));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
EXPECT_EQ( EXPECT_EQ(
@ -577,7 +577,7 @@ note: see layout of struct:
TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformBufferBool) { TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformBufferBool) {
// var<uniform> g : bool; // var<uniform> g : bool;
GlobalVar(Source{{56, 78}}, "g", ty.bool_(Source{{12, 34}}), type::AddressSpace::kUniform, GlobalVar(Source{{56, 78}}, "g", ty.bool_(Source{{12, 34}}), builtin::AddressSpace::kUniform,
Binding(0_a), Group(0_a)); Binding(0_a), Group(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -590,8 +590,8 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformBufferBool) {
TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformBufferBool) { TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformBufferBool) {
// type t = ptr<uniform, bool>; // type t = ptr<uniform, bool>;
Alias("t", Alias("t", ty.pointer(Source{{56, 78}}, ty.bool_(Source{{12, 34}}),
ty.pointer(Source{{56, 78}}, ty.bool_(Source{{12, 34}}), type::AddressSpace::kUniform)); builtin::AddressSpace::kUniform));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -605,7 +605,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformBufferBoolAlias
// type a = bool; // type a = bool;
// var<uniform> g : a; // var<uniform> g : a;
Alias("a", ty.bool_()); Alias("a", ty.bool_());
GlobalVar(Source{{56, 78}}, "g", ty(Source{{12, 34}}, "a"), type::AddressSpace::kUniform, GlobalVar(Source{{56, 78}}, "g", ty(Source{{12, 34}}, "a"), builtin::AddressSpace::kUniform,
Binding(0_a), Group(0_a)); Binding(0_a), Group(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -621,7 +621,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformBufferBoolAlias)
// type t = ptr<uniform, a>; // type t = ptr<uniform, a>;
Alias("a", ty.bool_()); Alias("a", ty.bool_());
Alias("t", Alias("t",
ty.pointer(Source{{56, 78}}, ty(Source{{12, 34}}, "a"), type::AddressSpace::kUniform)); ty.pointer(Source{{56, 78}}, ty(Source{{12, 34}}, "a"), builtin::AddressSpace::kUniform));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -634,8 +634,8 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformBufferBoolAlias)
TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformPointer) { TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformPointer) {
// var<uniform> g : ptr<private, f32>; // var<uniform> g : ptr<private, f32>;
GlobalVar(Source{{56, 78}}, "g", GlobalVar(Source{{56, 78}}, "g",
ty.pointer(Source{{12, 34}}, ty.f32(), type::AddressSpace::kPrivate), ty.pointer(Source{{12, 34}}, ty.f32(), builtin::AddressSpace::kPrivate),
type::AddressSpace::kUniform, Binding(0_a), Group(0_a)); builtin::AddressSpace::kUniform, Binding(0_a), Group(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -648,8 +648,8 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformPointer) {
TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformPointer) { TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformPointer) {
// type t = ptr<uniform, ptr<private, f32>>; // type t = ptr<uniform, ptr<private, f32>>;
Alias("t", ty.pointer(Source{{56, 78}}, Alias("t", ty.pointer(Source{{56, 78}},
ty.pointer(Source{{12, 34}}, ty.f32(), type::AddressSpace::kPrivate), ty.pointer(Source{{12, 34}}, ty.f32(), builtin::AddressSpace::kPrivate),
type::AddressSpace::kUniform)); builtin::AddressSpace::kUniform));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -661,7 +661,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformPointer) {
TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformBufferIntScalar) { TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformBufferIntScalar) {
// var<uniform> g : i32; // var<uniform> g : i32;
GlobalVar(Source{{56, 78}}, "g", ty.i32(), type::AddressSpace::kUniform, Binding(0_a), GlobalVar(Source{{56, 78}}, "g", ty.i32(), builtin::AddressSpace::kUniform, Binding(0_a),
Group(0_a)); Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -669,7 +669,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformBufferIntScalar
TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformBufferIntScalar) { TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformBufferIntScalar) {
// type t = ptr<uniform, i32>; // type t = ptr<uniform, i32>;
Alias("t", ty.pointer(ty.i32(), type::AddressSpace::kUniform)); Alias("t", ty.pointer(ty.i32(), builtin::AddressSpace::kUniform));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -679,7 +679,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformBufferF16) {
// var<uniform> g : f16; // var<uniform> g : f16;
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
GlobalVar("g", ty.f16(), type::AddressSpace::kUniform, Binding(0_a), Group(0_a)); GlobalVar("g", ty.f16(), builtin::AddressSpace::kUniform, Binding(0_a), Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -689,21 +689,21 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformBufferF16) {
// type t = ptr<uniform, f16>; // type t = ptr<uniform, f16>;
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
Alias("t", ty.pointer(ty.f16(), type::AddressSpace::kUniform)); Alias("t", ty.pointer(ty.f16(), builtin::AddressSpace::kUniform));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformBufferVectorF32) { TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformBufferVectorF32) {
// var<uniform> g : vec4<f32>; // var<uniform> g : vec4<f32>;
GlobalVar("g", ty.vec4<f32>(), type::AddressSpace::kUniform, Binding(0_a), Group(0_a)); GlobalVar("g", ty.vec4<f32>(), builtin::AddressSpace::kUniform, Binding(0_a), Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformBufferVectorF32) { TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformBufferVectorF32) {
// type t = ptr<uniform, vec4<f32>>; // type t = ptr<uniform, vec4<f32>>;
Alias("t", ty.pointer(ty.vec4<f32>(), type::AddressSpace::kUniform)); Alias("t", ty.pointer(ty.vec4<f32>(), builtin::AddressSpace::kUniform));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -713,7 +713,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformBufferVectorF16
// var<uniform> g : vec4<f16>; // var<uniform> g : vec4<f16>;
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
GlobalVar("g", ty.vec4<f16>(), type::AddressSpace::kUniform, Binding(0_a), Group(0_a)); GlobalVar("g", ty.vec4<f16>(), builtin::AddressSpace::kUniform, Binding(0_a), Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -723,7 +723,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformBufferVectorF16)
// type t = ptr<uniform, vec4<f16>>; // type t = ptr<uniform, vec4<f16>>;
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
Alias("t", ty.pointer(ty.vec4<f16>(), type::AddressSpace::kUniform)); Alias("t", ty.pointer(ty.vec4<f16>(), builtin::AddressSpace::kUniform));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -734,7 +734,8 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformBufferArrayF32)
// } // }
// var<uniform> g : array<S, 3u>; // var<uniform> g : array<S, 3u>;
Structure("S", utils::Vector{Member("a", ty.f32(), utils::Vector{MemberSize(16_a)})}); Structure("S", utils::Vector{Member("a", ty.f32(), utils::Vector{MemberSize(16_a)})});
GlobalVar("g", ty.array(ty("S"), 3_u), type::AddressSpace::kUniform, Binding(0_a), Group(0_a)); GlobalVar("g", ty.array(ty("S"), 3_u), builtin::AddressSpace::kUniform, Binding(0_a),
Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -745,7 +746,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformBufferArrayF32) {
// } // }
// type t = ptr<uniform, array<S, 3u>>; // type t = ptr<uniform, array<S, 3u>>;
Structure("S", utils::Vector{Member("a", ty.f32(), utils::Vector{MemberSize(16_a)})}); Structure("S", utils::Vector{Member("a", ty.f32(), utils::Vector{MemberSize(16_a)})});
Alias("t", ty.pointer(ty.array(ty("S"), 3_u), type::AddressSpace::kUniform)); Alias("t", ty.pointer(ty.array(ty("S"), 3_u), builtin::AddressSpace::kUniform));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -759,7 +760,8 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformBufferArrayF16)
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
Structure("S", utils::Vector{Member("a", ty.f16(), utils::Vector{MemberSize(16_a)})}); Structure("S", utils::Vector{Member("a", ty.f16(), utils::Vector{MemberSize(16_a)})});
GlobalVar("g", ty.array(ty("S"), 3_u), type::AddressSpace::kUniform, Binding(0_a), Group(0_a)); GlobalVar("g", ty.array(ty("S"), 3_u), builtin::AddressSpace::kUniform, Binding(0_a),
Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -773,7 +775,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformBufferArrayF16) {
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
Structure("S", utils::Vector{Member("a", ty.f16(), utils::Vector{MemberSize(16_a)})}); Structure("S", utils::Vector{Member("a", ty.f16(), utils::Vector{MemberSize(16_a)})});
Alias("t", ty.pointer(ty.array(ty("S"), 3_u), type::AddressSpace::kUniform)); Alias("t", ty.pointer(ty.array(ty("S"), 3_u), builtin::AddressSpace::kUniform));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -782,7 +784,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformBufferStructI32
// struct S { x : i32 }; // struct S { x : i32 };
// var<uniform> g : S; // var<uniform> g : S;
Structure("S", utils::Vector{Member("x", ty.i32())}); Structure("S", utils::Vector{Member("x", ty.i32())});
GlobalVar("g", ty("S"), type::AddressSpace::kUniform, Binding(0_a), Group(0_a)); GlobalVar("g", ty("S"), builtin::AddressSpace::kUniform, Binding(0_a), Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -791,7 +793,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformBufferStructI32)
// struct S { x : i32 }; // struct S { x : i32 };
// type t = ptr<uniform, S>; // type t = ptr<uniform, S>;
Structure("S", utils::Vector{Member("x", ty.i32())}); Structure("S", utils::Vector{Member("x", ty.i32())});
Alias("t", ty.pointer(ty("S"), type::AddressSpace::kUniform)); Alias("t", ty.pointer(ty("S"), builtin::AddressSpace::kUniform));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -802,7 +804,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformBufferStructI32
// var<uniform> g : a1; // var<uniform> g : a1;
Structure("S", utils::Vector{Member("x", ty.i32())}); Structure("S", utils::Vector{Member("x", ty.i32())});
Alias("a1", ty("S")); Alias("a1", ty("S"));
GlobalVar("g", ty("a1"), type::AddressSpace::kUniform, Binding(0_a), Group(0_a)); GlobalVar("g", ty("a1"), builtin::AddressSpace::kUniform, Binding(0_a), Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -813,7 +815,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformBufferStructI32Al
// type t = ptr<uniform, a1>; // type t = ptr<uniform, a1>;
Structure("S", utils::Vector{Member("x", ty.i32())}); Structure("S", utils::Vector{Member("x", ty.i32())});
Alias("a1", ty("S")); Alias("a1", ty("S"));
Alias("t", ty.pointer(ty("a1"), type::AddressSpace::kUniform)); Alias("t", ty.pointer(ty("a1"), builtin::AddressSpace::kUniform));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -825,7 +827,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformBufferStructF16
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
Structure("S", utils::Vector{Member("x", ty.f16())}); Structure("S", utils::Vector{Member("x", ty.f16())});
GlobalVar("g", ty("S"), type::AddressSpace::kUniform, Binding(0_a), Group(0_a)); GlobalVar("g", ty("S"), builtin::AddressSpace::kUniform, Binding(0_a), Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -837,7 +839,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformBufferStructF16)
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
Structure("S", utils::Vector{Member("x", ty.f16())}); Structure("S", utils::Vector{Member("x", ty.f16())});
Alias("t", ty.pointer(ty("S"), type::AddressSpace::kUniform)); Alias("t", ty.pointer(ty("S"), builtin::AddressSpace::kUniform));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -851,7 +853,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_UniformBufferStructF16
Structure("S", utils::Vector{Member("x", ty.f16())}); Structure("S", utils::Vector{Member("x", ty.f16())});
Alias("a1", ty("S")); Alias("a1", ty("S"));
GlobalVar("g", ty("a1"), type::AddressSpace::kUniform, Binding(0_a), Group(0_a)); GlobalVar("g", ty("a1"), builtin::AddressSpace::kUniform, Binding(0_a), Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -865,7 +867,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_UniformBufferStructF16Al
Structure("S", utils::Vector{Member("x", ty.f16())}); Structure("S", utils::Vector{Member("x", ty.f16())});
Alias("a1", ty("S")); Alias("a1", ty("S"));
Alias("t", ty.pointer(ty("a1"), type::AddressSpace::kUniform)); Alias("t", ty.pointer(ty("a1"), builtin::AddressSpace::kUniform));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -874,7 +876,8 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_PushConstantBool) {
// enable chromium_experimental_push_constant; // enable chromium_experimental_push_constant;
// var<push_constant> g : bool; // var<push_constant> g : bool;
Enable(builtin::Extension::kChromiumExperimentalPushConstant); Enable(builtin::Extension::kChromiumExperimentalPushConstant);
GlobalVar(Source{{56, 78}}, "g", ty.bool_(Source{{12, 34}}), type::AddressSpace::kPushConstant); GlobalVar(Source{{56, 78}}, "g", ty.bool_(Source{{12, 34}}),
builtin::AddressSpace::kPushConstant);
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
EXPECT_EQ( EXPECT_EQ(
@ -888,7 +891,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_PushConstantBool) {
// type t = ptr<push_constant, bool>; // type t = ptr<push_constant, bool>;
Enable(builtin::Extension::kChromiumExperimentalPushConstant); Enable(builtin::Extension::kChromiumExperimentalPushConstant);
Alias(Source{{56, 78}}, "t", Alias(Source{{56, 78}}, "t",
ty.pointer(ty.bool_(Source{{12, 34}}), type::AddressSpace::kPushConstant)); ty.pointer(ty.bool_(Source{{12, 34}}), builtin::AddressSpace::kPushConstant));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
EXPECT_EQ( EXPECT_EQ(
@ -903,7 +906,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_PushConstantF16) {
// var<push_constant> g : f16; // var<push_constant> g : f16;
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
Enable(builtin::Extension::kChromiumExperimentalPushConstant); Enable(builtin::Extension::kChromiumExperimentalPushConstant);
GlobalVar("g", ty.f16(Source{{56, 78}}), type::AddressSpace::kPushConstant); GlobalVar("g", ty.f16(Source{{56, 78}}), builtin::AddressSpace::kPushConstant);
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -916,7 +919,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_PushConstantF16) {
// type t = ptr<push_constant, f16>; // type t = ptr<push_constant, f16>;
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
Enable(builtin::Extension::kChromiumExperimentalPushConstant); Enable(builtin::Extension::kChromiumExperimentalPushConstant);
Alias("t", ty.pointer(ty.f16(Source{{56, 78}}), type::AddressSpace::kPushConstant)); Alias("t", ty.pointer(ty.f16(Source{{56, 78}}), builtin::AddressSpace::kPushConstant));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -928,8 +931,8 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_PushConstantPointer) {
// var<push_constant> g : ptr<private, f32>; // var<push_constant> g : ptr<private, f32>;
Enable(builtin::Extension::kChromiumExperimentalPushConstant); Enable(builtin::Extension::kChromiumExperimentalPushConstant);
GlobalVar(Source{{56, 78}}, "g", GlobalVar(Source{{56, 78}}, "g",
ty.pointer(Source{{12, 34}}, ty.f32(), type::AddressSpace::kPrivate), ty.pointer(Source{{12, 34}}, ty.f32(), builtin::AddressSpace::kPrivate),
type::AddressSpace::kPushConstant); builtin::AddressSpace::kPushConstant);
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
EXPECT_EQ( EXPECT_EQ(
@ -943,8 +946,8 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_PushConstantPointer) {
// type t = ptr<push_constant, ptr<private, f32>>; // type t = ptr<push_constant, ptr<private, f32>>;
Enable(builtin::Extension::kChromiumExperimentalPushConstant); Enable(builtin::Extension::kChromiumExperimentalPushConstant);
Alias(Source{{56, 78}}, "t", Alias(Source{{56, 78}}, "t",
ty.pointer(ty.pointer(Source{{12, 34}}, ty.f32(), type::AddressSpace::kPrivate), ty.pointer(ty.pointer(Source{{12, 34}}, ty.f32(), builtin::AddressSpace::kPrivate),
type::AddressSpace::kPushConstant)); builtin::AddressSpace::kPushConstant));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
EXPECT_EQ( EXPECT_EQ(
@ -957,7 +960,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_PushConstantIntScalar)
// enable chromium_experimental_push_constant; // enable chromium_experimental_push_constant;
// var<push_constant> g : i32; // var<push_constant> g : i32;
Enable(builtin::Extension::kChromiumExperimentalPushConstant); Enable(builtin::Extension::kChromiumExperimentalPushConstant);
GlobalVar("g", ty.i32(), type::AddressSpace::kPushConstant); GlobalVar("g", ty.i32(), builtin::AddressSpace::kPushConstant);
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -966,7 +969,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_PushConstantIntScalar) {
// enable chromium_experimental_push_constant; // enable chromium_experimental_push_constant;
// type t = ptr<push_constant, i32>; // type t = ptr<push_constant, i32>;
Enable(builtin::Extension::kChromiumExperimentalPushConstant); Enable(builtin::Extension::kChromiumExperimentalPushConstant);
Alias("t", ty.pointer(ty.i32(), type::AddressSpace::kPushConstant)); Alias("t", ty.pointer(ty.i32(), builtin::AddressSpace::kPushConstant));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -975,7 +978,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_PushConstantVectorF32)
// enable chromium_experimental_push_constant; // enable chromium_experimental_push_constant;
// var<push_constant> g : vec4<f32>; // var<push_constant> g : vec4<f32>;
Enable(builtin::Extension::kChromiumExperimentalPushConstant); Enable(builtin::Extension::kChromiumExperimentalPushConstant);
GlobalVar("g", ty.vec4<f32>(), type::AddressSpace::kPushConstant); GlobalVar("g", ty.vec4<f32>(), builtin::AddressSpace::kPushConstant);
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -984,7 +987,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_PushConstantVectorF32) {
// enable chromium_experimental_push_constant; // enable chromium_experimental_push_constant;
// var<push_constant> g : vec4<f32>; // var<push_constant> g : vec4<f32>;
Enable(builtin::Extension::kChromiumExperimentalPushConstant); Enable(builtin::Extension::kChromiumExperimentalPushConstant);
Alias("t", ty.pointer(ty.vec4<f32>(), type::AddressSpace::kPushConstant)); Alias("t", ty.pointer(ty.vec4<f32>(), builtin::AddressSpace::kPushConstant));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -995,7 +998,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_PushConstantArrayF32)
// var<push_constant> g : array<S, 3u>; // var<push_constant> g : array<S, 3u>;
Enable(builtin::Extension::kChromiumExperimentalPushConstant); Enable(builtin::Extension::kChromiumExperimentalPushConstant);
Structure("S", utils::Vector{Member("a", ty.f32())}); Structure("S", utils::Vector{Member("a", ty.f32())});
GlobalVar("g", ty.array(ty("S"), 3_u), type::AddressSpace::kPushConstant); GlobalVar("g", ty.array(ty("S"), 3_u), builtin::AddressSpace::kPushConstant);
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }
@ -1006,7 +1009,7 @@ TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_PushConstantArrayF32) {
// type t = ptr<push_constant, array<S, 3u>>; // type t = ptr<push_constant, array<S, 3u>>;
Enable(builtin::Extension::kChromiumExperimentalPushConstant); Enable(builtin::Extension::kChromiumExperimentalPushConstant);
Structure("S", utils::Vector{Member("a", ty.f32())}); Structure("S", utils::Vector{Member("a", ty.f32())});
Alias("t", ty.pointer(ty.array(ty("S"), 3_u), type::AddressSpace::kPushConstant)); Alias("t", ty.pointer(ty.array(ty("S"), 3_u), builtin::AddressSpace::kPushConstant));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }

View File

@ -35,19 +35,19 @@ struct ResolverAliasAnalysisTest : public resolver::TestHelper, public testing::
// target(&v1, aliased ? &v1 : &v2); // target(&v1, aliased ? &v1 : &v2);
// } // }
struct TwoPointerConfig { struct TwoPointerConfig {
type::AddressSpace address_space; // The address space for the pointers. builtin::AddressSpace address_space; // The address space for the pointers.
bool aliased; // Whether the pointers alias or not. bool aliased; // Whether the pointers alias or not.
}; };
class TwoPointers : public ResolverTestWithParam<TwoPointerConfig> { class TwoPointers : public ResolverTestWithParam<TwoPointerConfig> {
protected: protected:
void SetUp() override { void SetUp() override {
utils::Vector<const ast::Statement*, 4> body; utils::Vector<const ast::Statement*, 4> body;
if (GetParam().address_space == type::AddressSpace::kFunction) { if (GetParam().address_space == builtin::AddressSpace::kFunction) {
body.Push(Decl(Var("v1", ty.i32()))); body.Push(Decl(Var("v1", ty.i32())));
body.Push(Decl(Var("v2", ty.i32()))); body.Push(Decl(Var("v2", ty.i32())));
} else { } else {
GlobalVar("v1", type::AddressSpace::kPrivate, ty.i32()); GlobalVar("v1", builtin::AddressSpace::kPrivate, ty.i32());
GlobalVar("v2", type::AddressSpace::kPrivate, ty.i32()); GlobalVar("v2", builtin::AddressSpace::kPrivate, ty.i32());
} }
body.Push(CallStmt(Call("target", AddressOf(Source{{12, 34}}, "v1"), body.Push(CallStmt(Call("target", AddressOf(Source{{12, 34}}, "v1"),
AddressOf(Source{{56, 78}}, GetParam().aliased ? "v1" : "v2")))); AddressOf(Source{{56, 78}}, GetParam().aliased ? "v1" : "v2"))));
@ -190,10 +190,11 @@ TEST_P(TwoPointers, ReadWriteAcrossDifferentFunctions) {
INSTANTIATE_TEST_SUITE_P(ResolverAliasAnalysisTest, INSTANTIATE_TEST_SUITE_P(ResolverAliasAnalysisTest,
TwoPointers, TwoPointers,
::testing::Values(TwoPointerConfig{type::AddressSpace::kFunction, false}, ::testing::Values(TwoPointerConfig{builtin::AddressSpace::kFunction,
TwoPointerConfig{type::AddressSpace::kFunction, true}, false},
TwoPointerConfig{type::AddressSpace::kPrivate, false}, TwoPointerConfig{builtin::AddressSpace::kFunction, true},
TwoPointerConfig{type::AddressSpace::kPrivate, true}), TwoPointerConfig{builtin::AddressSpace::kPrivate, false},
TwoPointerConfig{builtin::AddressSpace::kPrivate, true}),
[](const ::testing::TestParamInfo<TwoPointers::ParamType>& p) { [](const ::testing::TestParamInfo<TwoPointers::ParamType>& p) {
std::stringstream ss; std::stringstream ss;
ss << (p.param.aliased ? "Aliased" : "Unaliased") << "_" ss << (p.param.aliased ? "Aliased" : "Unaliased") << "_"
@ -214,8 +215,8 @@ INSTANTIATE_TEST_SUITE_P(ResolverAliasAnalysisTest,
class OnePointerOneModuleScope : public ResolverTestWithParam<bool> { class OnePointerOneModuleScope : public ResolverTestWithParam<bool> {
protected: protected:
void SetUp() override { void SetUp() override {
GlobalVar("global_1", type::AddressSpace::kPrivate, ty.i32()); GlobalVar("global_1", builtin::AddressSpace::kPrivate, ty.i32());
GlobalVar("global_2", type::AddressSpace::kPrivate, ty.i32()); GlobalVar("global_2", builtin::AddressSpace::kPrivate, ty.i32());
Func("caller", utils::Empty, ty.void_(), Func("caller", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
CallStmt(Call("target", CallStmt(Call("target",
@ -226,7 +227,7 @@ class OnePointerOneModuleScope : public ResolverTestWithParam<bool> {
void Run(utils::Vector<const ast::Statement*, 4>&& body, const char* err = nullptr) { void Run(utils::Vector<const ast::Statement*, 4>&& body, const char* err = nullptr) {
Func("target", Func("target",
utils::Vector<const ast::Parameter*, 4>{ utils::Vector<const ast::Parameter*, 4>{
Param("p1", ty.pointer<i32>(type::AddressSpace::kPrivate)), Param("p1", ty.pointer<i32>(builtin::AddressSpace::kPrivate)),
}, },
ty.void_(), std::move(body)); ty.void_(), std::move(body));
if (GetParam() && err) { if (GetParam() && err) {
@ -295,7 +296,7 @@ TEST_P(OnePointerOneModuleScope, ReadWriteThroughChain_GlobalViaArg) {
// f1(p1); // f1(p1);
Func("f2", Func("f2",
utils::Vector<const ast::Parameter*, 4>{ utils::Vector<const ast::Parameter*, 4>{
Param("p1", ty.pointer<i32>(type::AddressSpace::kPrivate)), Param("p1", ty.pointer<i32>(builtin::AddressSpace::kPrivate)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{
@ -303,7 +304,7 @@ TEST_P(OnePointerOneModuleScope, ReadWriteThroughChain_GlobalViaArg) {
}); });
Func("f1", Func("f1",
utils::Vector<const ast::Parameter*, 4>{ utils::Vector<const ast::Parameter*, 4>{
Param("p1", ty.pointer<i32>(type::AddressSpace::kPrivate)), Param("p1", ty.pointer<i32>(builtin::AddressSpace::kPrivate)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{
@ -330,7 +331,7 @@ TEST_P(OnePointerOneModuleScope, ReadWriteThroughChain_Both) {
// f1(p1); // f1(p1);
Func("f2", Func("f2",
utils::Vector<const ast::Parameter*, 4>{ utils::Vector<const ast::Parameter*, 4>{
Param("p1", ty.pointer<i32>(type::AddressSpace::kPrivate)), Param("p1", ty.pointer<i32>(builtin::AddressSpace::kPrivate)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{
@ -339,7 +340,7 @@ TEST_P(OnePointerOneModuleScope, ReadWriteThroughChain_Both) {
}); });
Func("f1", Func("f1",
utils::Vector<const ast::Parameter*, 4>{ utils::Vector<const ast::Parameter*, 4>{
Param("p1", ty.pointer<i32>(type::AddressSpace::kPrivate)), Param("p1", ty.pointer<i32>(builtin::AddressSpace::kPrivate)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{
@ -365,7 +366,7 @@ TEST_P(OnePointerOneModuleScope, WriteReadThroughChain_GlobalViaArg) {
// f1(p1); // f1(p1);
Func("f2", Func("f2",
utils::Vector<const ast::Parameter*, 4>{ utils::Vector<const ast::Parameter*, 4>{
Param("p1", ty.pointer<i32>(type::AddressSpace::kPrivate)), Param("p1", ty.pointer<i32>(builtin::AddressSpace::kPrivate)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{
@ -373,7 +374,7 @@ TEST_P(OnePointerOneModuleScope, WriteReadThroughChain_GlobalViaArg) {
}); });
Func("f1", Func("f1",
utils::Vector<const ast::Parameter*, 4>{ utils::Vector<const ast::Parameter*, 4>{
Param("p1", ty.pointer<i32>(type::AddressSpace::kPrivate)), Param("p1", ty.pointer<i32>(builtin::AddressSpace::kPrivate)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{
@ -400,7 +401,7 @@ TEST_P(OnePointerOneModuleScope, WriteReadThroughChain_Both) {
// f1(p1); // f1(p1);
Func("f2", Func("f2",
utils::Vector{ utils::Vector{
Param("p1", ty.pointer<i32>(type::AddressSpace::kPrivate)), Param("p1", ty.pointer<i32>(builtin::AddressSpace::kPrivate)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{
@ -409,7 +410,7 @@ TEST_P(OnePointerOneModuleScope, WriteReadThroughChain_Both) {
}); });
Func("f1", Func("f1",
utils::Vector{ utils::Vector{
Param("p1", ty.pointer<i32>(type::AddressSpace::kPrivate)), Param("p1", ty.pointer<i32>(builtin::AddressSpace::kPrivate)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{
@ -435,7 +436,7 @@ TEST_P(OnePointerOneModuleScope, ReadWriteAcrossDifferentFunctions) {
// f2(); // f2();
Func("f1", Func("f1",
utils::Vector{ utils::Vector{
Param("p1", ty.pointer<i32>(type::AddressSpace::kPrivate)), Param("p1", ty.pointer<i32>(builtin::AddressSpace::kPrivate)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{
@ -487,8 +488,8 @@ class Use : public ResolverTestWithParam<bool> {
void Run(const ast::Statement* stmt, const char* err = nullptr) { void Run(const ast::Statement* stmt, const char* err = nullptr) {
Func("target", Func("target",
utils::Vector{ utils::Vector{
Param("p1", ty.pointer<i32>(type::AddressSpace::kFunction)), Param("p1", ty.pointer<i32>(builtin::AddressSpace::kFunction)),
Param("p2", ty.pointer<i32>(type::AddressSpace::kFunction)), Param("p2", ty.pointer<i32>(builtin::AddressSpace::kFunction)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{
@ -531,7 +532,7 @@ TEST_P(Use, Write_CompoundAssignment_LHS) {
TEST_P(Use, Read_CompoundAssignment_RHS) { TEST_P(Use, Read_CompoundAssignment_RHS) {
// var<private> global : i32; // var<private> global : i32;
// global += *p2; // global += *p2;
GlobalVar("global", type::AddressSpace::kPrivate, ty.i32()); GlobalVar("global", builtin::AddressSpace::kPrivate, ty.i32());
Run(CompoundAssign("global", Deref("p2"), ast::BinaryOp::kAdd), Run(CompoundAssign("global", Deref("p2"), ast::BinaryOp::kAdd),
R"(56:78 error: invalid aliased pointer argument R"(56:78 error: invalid aliased pointer argument
12:34 note: aliases with another argument passed here)"); 12:34 note: aliases with another argument passed here)");
@ -578,7 +579,7 @@ TEST_P(Use, Read_Convert) {
TEST_P(Use, Read_IndexAccessor) { TEST_P(Use, Read_IndexAccessor) {
// var<private> data : array<f32, 4>; // var<private> data : array<f32, 4>;
// _ = data[*p2]; // _ = data[*p2];
GlobalVar("data", type::AddressSpace::kPrivate, ty.array<f32, 4>()); GlobalVar("data", builtin::AddressSpace::kPrivate, ty.array<f32, 4>());
Run(Assign(Phony(), IndexAccessor("data", Deref("p2"))), Run(Assign(Phony(), IndexAccessor("data", Deref("p2"))),
R"(56:78 error: invalid aliased pointer argument R"(56:78 error: invalid aliased pointer argument
12:34 note: aliases with another argument passed here)"); 12:34 note: aliases with another argument passed here)");
@ -592,7 +593,7 @@ TEST_P(Use, Read_LetInitializer) {
TEST_P(Use, Read_VarInitializer) { TEST_P(Use, Read_VarInitializer) {
// var x = *p2; // var x = *p2;
Run(Decl(Var("x", type::AddressSpace::kFunction, Deref("p2"))), Run(Decl(Var("x", builtin::AddressSpace::kFunction, Deref("p2"))),
R"(56:78 error: invalid aliased pointer argument R"(56:78 error: invalid aliased pointer argument
12:34 note: aliases with another argument passed here)"); 12:34 note: aliases with another argument passed here)");
} }
@ -602,7 +603,7 @@ TEST_P(Use, Read_ReturnValue) {
// foo(p2); // foo(p2);
Func("foo", Func("foo",
utils::Vector{ utils::Vector{
Param("p", ty.pointer<i32>(type::AddressSpace::kFunction)), Param("p", ty.pointer<i32>(builtin::AddressSpace::kFunction)),
}, },
ty.i32(), ty.i32(),
utils::Vector{ utils::Vector{
@ -659,8 +660,8 @@ class UseBool : public ResolverTestWithParam<bool> {
void Run(const ast::Statement* stmt, const char* err = nullptr) { void Run(const ast::Statement* stmt, const char* err = nullptr) {
Func("target", Func("target",
utils::Vector{ utils::Vector{
Param("p1", ty.pointer<bool>(type::AddressSpace::kFunction)), Param("p1", ty.pointer<bool>(builtin::AddressSpace::kFunction)),
Param("p2", ty.pointer<bool>(type::AddressSpace::kFunction)), Param("p2", ty.pointer<bool>(builtin::AddressSpace::kFunction)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{
@ -724,8 +725,8 @@ TEST_F(ResolverAliasAnalysisTest, NoAccess_MemberAccessor) {
Structure("S", utils::Vector{Member("a", ty.i32())}); Structure("S", utils::Vector{Member("a", ty.i32())});
Func("f2", Func("f2",
utils::Vector{ utils::Vector{
Param("p1", ty.pointer(ty("S"), type::AddressSpace::kFunction)), Param("p1", ty.pointer(ty("S"), builtin::AddressSpace::kFunction)),
Param("p2", ty.pointer(ty("S"), type::AddressSpace::kFunction)), Param("p2", ty.pointer(ty("S"), builtin::AddressSpace::kFunction)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{
@ -753,8 +754,8 @@ TEST_F(ResolverAliasAnalysisTest, Read_MemberAccessor) {
Structure("S", utils::Vector{Member("a", ty.i32())}); Structure("S", utils::Vector{Member("a", ty.i32())});
Func("f2", Func("f2",
utils::Vector{ utils::Vector{
Param("p1", ty.pointer(ty("S"), type::AddressSpace::kFunction)), Param("p1", ty.pointer(ty("S"), builtin::AddressSpace::kFunction)),
Param("p2", ty.pointer(ty("S"), type::AddressSpace::kFunction)), Param("p2", ty.pointer(ty("S"), builtin::AddressSpace::kFunction)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{
@ -785,8 +786,8 @@ TEST_F(ResolverAliasAnalysisTest, Write_MemberAccessor) {
Structure("S", utils::Vector{Member("a", ty.i32())}); Structure("S", utils::Vector{Member("a", ty.i32())});
Func("f2", Func("f2",
utils::Vector{ utils::Vector{
Param("p1", ty.pointer(ty("S"), type::AddressSpace::kFunction)), Param("p1", ty.pointer(ty("S"), builtin::AddressSpace::kFunction)),
Param("p2", ty.pointer(ty("S"), type::AddressSpace::kFunction)), Param("p2", ty.pointer(ty("S"), builtin::AddressSpace::kFunction)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{
@ -816,8 +817,8 @@ TEST_F(ResolverAliasAnalysisTest, Read_MultiComponentSwizzle) {
Structure("S", utils::Vector{Member("a", ty.i32())}); Structure("S", utils::Vector{Member("a", ty.i32())});
Func("f2", Func("f2",
utils::Vector{ utils::Vector{
Param("p1", ty.pointer(ty.vec4<f32>(), type::AddressSpace::kFunction)), Param("p1", ty.pointer(ty.vec4<f32>(), builtin::AddressSpace::kFunction)),
Param("p2", ty.pointer(ty.vec4<f32>(), type::AddressSpace::kFunction)), Param("p2", ty.pointer(ty.vec4<f32>(), builtin::AddressSpace::kFunction)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{
@ -848,7 +849,7 @@ TEST_F(ResolverAliasAnalysisTest, SinglePointerReadWrite) {
// } // }
Func("f1", Func("f1",
utils::Vector{ utils::Vector{
Param("p", ty.pointer<i32>(type::AddressSpace::kFunction)), Param("p", ty.pointer<i32>(builtin::AddressSpace::kFunction)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{
@ -901,7 +902,7 @@ TEST_F(ResolverAliasAnalysisTest, NonOverlappingCalls) {
// } // }
Func("f2", Func("f2",
utils::Vector{ utils::Vector{
Param("p", ty.pointer<i32>(type::AddressSpace::kFunction)), Param("p", ty.pointer<i32>(builtin::AddressSpace::kFunction)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{
@ -909,7 +910,7 @@ TEST_F(ResolverAliasAnalysisTest, NonOverlappingCalls) {
}); });
Func("f3", Func("f3",
utils::Vector{ utils::Vector{
Param("p", ty.pointer<i32>(type::AddressSpace::kFunction)), Param("p", ty.pointer<i32>(builtin::AddressSpace::kFunction)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{

View File

@ -27,7 +27,7 @@ namespace {
using ResolverIndexAccessorTest = ResolverTest; using ResolverIndexAccessorTest = ResolverTest;
TEST_F(ResolverIndexAccessorTest, Matrix_Dynamic_F32) { TEST_F(ResolverIndexAccessorTest, Matrix_Dynamic_F32) {
GlobalVar("my_var", ty.mat2x3<f32>(), type::AddressSpace::kPrivate); GlobalVar("my_var", ty.mat2x3<f32>(), builtin::AddressSpace::kPrivate);
auto* acc = IndexAccessor("my_var", Expr(Source{{12, 34}}, 1_f)); auto* acc = IndexAccessor("my_var", Expr(Source{{12, 34}}, 1_f));
WrapInFunction(acc); WrapInFunction(acc);
@ -36,7 +36,7 @@ TEST_F(ResolverIndexAccessorTest, Matrix_Dynamic_F32) {
} }
TEST_F(ResolverIndexAccessorTest, Matrix_Dynamic_Ref) { TEST_F(ResolverIndexAccessorTest, Matrix_Dynamic_Ref) {
GlobalVar("my_var", ty.mat2x3<f32>(), type::AddressSpace::kPrivate); GlobalVar("my_var", ty.mat2x3<f32>(), builtin::AddressSpace::kPrivate);
auto* idx = Var("idx", ty.i32(), Call<i32>()); auto* idx = Var("idx", ty.i32(), Call<i32>());
auto* acc = IndexAccessor("my_var", idx); auto* acc = IndexAccessor("my_var", idx);
WrapInFunction(Decl(idx), acc); WrapInFunction(Decl(idx), acc);
@ -50,7 +50,7 @@ TEST_F(ResolverIndexAccessorTest, Matrix_Dynamic_Ref) {
} }
TEST_F(ResolverIndexAccessorTest, Matrix_BothDimensions_Dynamic_Ref) { TEST_F(ResolverIndexAccessorTest, Matrix_BothDimensions_Dynamic_Ref) {
GlobalVar("my_var", ty.mat4x4<f32>(), type::AddressSpace::kPrivate); GlobalVar("my_var", ty.mat4x4<f32>(), builtin::AddressSpace::kPrivate);
auto* idx = Var("idx", ty.u32(), Expr(3_u)); auto* idx = Var("idx", ty.u32(), Expr(3_u));
auto* idy = Var("idy", ty.u32(), Expr(2_u)); auto* idy = Var("idy", ty.u32(), Expr(2_u));
auto* acc = IndexAccessor(IndexAccessor("my_var", idx), idy); auto* acc = IndexAccessor(IndexAccessor("my_var", idx), idy);
@ -100,7 +100,7 @@ TEST_F(ResolverIndexAccessorTest, Matrix_BothDimension_Dynamic) {
} }
TEST_F(ResolverIndexAccessorTest, Matrix) { TEST_F(ResolverIndexAccessorTest, Matrix) {
GlobalVar("my_var", ty.mat2x3<f32>(), type::AddressSpace::kPrivate); GlobalVar("my_var", ty.mat2x3<f32>(), builtin::AddressSpace::kPrivate);
auto* acc = IndexAccessor("my_var", 1_i); auto* acc = IndexAccessor("my_var", 1_i);
WrapInFunction(acc); WrapInFunction(acc);
@ -118,7 +118,7 @@ TEST_F(ResolverIndexAccessorTest, Matrix) {
} }
TEST_F(ResolverIndexAccessorTest, Matrix_BothDimensions) { TEST_F(ResolverIndexAccessorTest, Matrix_BothDimensions) {
GlobalVar("my_var", ty.mat2x3<f32>(), type::AddressSpace::kPrivate); GlobalVar("my_var", ty.mat2x3<f32>(), builtin::AddressSpace::kPrivate);
auto* acc = IndexAccessor(IndexAccessor("my_var", 0_i), 1_i); auto* acc = IndexAccessor(IndexAccessor("my_var", 0_i), 1_i);
WrapInFunction(acc); WrapInFunction(acc);
@ -135,7 +135,7 @@ TEST_F(ResolverIndexAccessorTest, Matrix_BothDimensions) {
} }
TEST_F(ResolverIndexAccessorTest, Vector_F32) { TEST_F(ResolverIndexAccessorTest, Vector_F32) {
GlobalVar("my_var", ty.vec3<f32>(), type::AddressSpace::kPrivate); GlobalVar("my_var", ty.vec3<f32>(), builtin::AddressSpace::kPrivate);
auto* acc = IndexAccessor("my_var", Expr(Source{{12, 34}}, 2_f)); auto* acc = IndexAccessor("my_var", Expr(Source{{12, 34}}, 2_f));
WrapInFunction(acc); WrapInFunction(acc);
@ -144,7 +144,7 @@ TEST_F(ResolverIndexAccessorTest, Vector_F32) {
} }
TEST_F(ResolverIndexAccessorTest, Vector_Dynamic_Ref) { TEST_F(ResolverIndexAccessorTest, Vector_Dynamic_Ref) {
GlobalVar("my_var", ty.vec3<f32>(), type::AddressSpace::kPrivate); GlobalVar("my_var", ty.vec3<f32>(), builtin::AddressSpace::kPrivate);
auto* idx = Var("idx", ty.i32(), Expr(2_i)); auto* idx = Var("idx", ty.i32(), Expr(2_i));
auto* acc = IndexAccessor("my_var", idx); auto* acc = IndexAccessor("my_var", idx);
WrapInFunction(Decl(idx), acc); WrapInFunction(Decl(idx), acc);
@ -167,7 +167,7 @@ TEST_F(ResolverIndexAccessorTest, Vector_Dynamic) {
} }
TEST_F(ResolverIndexAccessorTest, Vector) { TEST_F(ResolverIndexAccessorTest, Vector) {
GlobalVar("my_var", ty.vec3<f32>(), type::AddressSpace::kPrivate); GlobalVar("my_var", ty.vec3<f32>(), builtin::AddressSpace::kPrivate);
auto* acc = IndexAccessor("my_var", 2_i); auto* acc = IndexAccessor("my_var", 2_i);
WrapInFunction(acc); WrapInFunction(acc);
@ -184,7 +184,7 @@ TEST_F(ResolverIndexAccessorTest, Vector) {
} }
TEST_F(ResolverIndexAccessorTest, Array_Literal_i32) { TEST_F(ResolverIndexAccessorTest, Array_Literal_i32) {
GlobalVar("my_var", ty.array<f32, 3>(), type::AddressSpace::kPrivate); GlobalVar("my_var", ty.array<f32, 3>(), builtin::AddressSpace::kPrivate);
auto* acc = IndexAccessor("my_var", 2_i); auto* acc = IndexAccessor("my_var", 2_i);
WrapInFunction(acc); WrapInFunction(acc);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -197,7 +197,7 @@ TEST_F(ResolverIndexAccessorTest, Array_Literal_i32) {
} }
TEST_F(ResolverIndexAccessorTest, Array_Literal_u32) { TEST_F(ResolverIndexAccessorTest, Array_Literal_u32) {
GlobalVar("my_var", ty.array<f32, 3>(), type::AddressSpace::kPrivate); GlobalVar("my_var", ty.array<f32, 3>(), builtin::AddressSpace::kPrivate);
auto* acc = IndexAccessor("my_var", 2_u); auto* acc = IndexAccessor("my_var", 2_u);
WrapInFunction(acc); WrapInFunction(acc);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -210,7 +210,7 @@ TEST_F(ResolverIndexAccessorTest, Array_Literal_u32) {
} }
TEST_F(ResolverIndexAccessorTest, Array_Literal_AInt) { TEST_F(ResolverIndexAccessorTest, Array_Literal_AInt) {
GlobalVar("my_var", ty.array<f32, 3>(), type::AddressSpace::kPrivate); GlobalVar("my_var", ty.array<f32, 3>(), builtin::AddressSpace::kPrivate);
auto* acc = IndexAccessor("my_var", 2_a); auto* acc = IndexAccessor("my_var", 2_a);
WrapInFunction(acc); WrapInFunction(acc);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -225,7 +225,7 @@ TEST_F(ResolverIndexAccessorTest, Array_Literal_AInt) {
TEST_F(ResolverIndexAccessorTest, Alias_Array) { TEST_F(ResolverIndexAccessorTest, Alias_Array) {
auto* aary = Alias("myarrty", ty.array<f32, 3>()); auto* aary = Alias("myarrty", ty.array<f32, 3>());
GlobalVar("my_var", ty.Of(aary), type::AddressSpace::kPrivate); GlobalVar("my_var", ty.Of(aary), builtin::AddressSpace::kPrivate);
auto* acc = IndexAccessor("my_var", 2_i); auto* acc = IndexAccessor("my_var", 2_i);
WrapInFunction(acc); WrapInFunction(acc);
@ -316,7 +316,7 @@ TEST_F(ResolverIndexAccessorTest, Expr_Deref_FuncGoodParent) {
// let x: f32 = (*p)[idx]; // let x: f32 = (*p)[idx];
// return x; // return x;
// } // }
auto* p = Param("p", ty.pointer(ty.vec4<f32>(), type::AddressSpace::kFunction)); auto* p = Param("p", ty.pointer(ty.vec4<f32>(), builtin::AddressSpace::kFunction));
auto* idx = Let("idx", ty.u32(), Call<u32>()); auto* idx = Let("idx", ty.u32(), Call<u32>());
auto* star_p = Deref(p); auto* star_p = Deref(p);
auto* acc = IndexAccessor(Source{{12, 34}}, star_p, idx); auto* acc = IndexAccessor(Source{{12, 34}}, star_p, idx);
@ -337,7 +337,7 @@ TEST_F(ResolverIndexAccessorTest, Expr_Deref_FuncBadParent) {
// let x: f32 = *p[idx]; // let x: f32 = *p[idx];
// return x; // return x;
// } // }
auto* p = Param("p", ty.pointer(ty.vec4<f32>(), type::AddressSpace::kFunction)); auto* p = Param("p", ty.pointer(ty.vec4<f32>(), builtin::AddressSpace::kFunction));
auto* idx = Let("idx", ty.u32(), Call<u32>()); auto* idx = Let("idx", ty.u32(), Call<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);

View File

@ -33,8 +33,8 @@ TEST_F(ResolverAssignmentValidationTest, ReadOnlyBuffer) {
auto* s = Structure("S", utils::Vector{ auto* s = Structure("S", utils::Vector{
Member("m", ty.i32()), Member("m", ty.i32()),
}); });
GlobalVar(Source{{12, 34}}, "a", ty.Of(s), type::AddressSpace::kStorage, builtin::Access::kRead, GlobalVar(Source{{12, 34}}, "a", ty.Of(s), builtin::AddressSpace::kStorage,
Binding(0_a), Group(0_a)); builtin::Access::kRead, Binding(0_a), Group(0_a));
WrapInFunction(Assign(Source{{56, 78}}, MemberAccessor("a", "m"), 1_i)); WrapInFunction(Assign(Source{{56, 78}}, MemberAccessor("a", "m"), 1_i));
@ -193,7 +193,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignThroughPointer_Pass) {
// var a : i32; // var a : i32;
// let b : ptr<function,i32> = &a; // let b : ptr<function,i32> = &a;
// *b = 2i; // *b = 2i;
const auto func = type::AddressSpace::kFunction; const auto func = builtin::AddressSpace::kFunction;
WrapInFunction(Var("a", ty.i32(), func, Expr(2_i)), // WrapInFunction(Var("a", ty.i32(), func, Expr(2_i)), //
Let("b", ty.pointer<i32>(func), AddressOf(Expr("a"))), // Let("b", ty.pointer<i32>(func), AddressOf(Expr("a"))), //
Assign(Deref("b"), 2_i)); Assign(Deref("b"), 2_i));
@ -205,7 +205,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignMaterializedThroughPointer_Pass)
// var a : i32; // var a : i32;
// let b : ptr<function,i32> = &a; // let b : ptr<function,i32> = &a;
// *b = 2; // *b = 2;
const auto func = type::AddressSpace::kFunction; const auto func = builtin::AddressSpace::kFunction;
auto* var_a = Var("a", ty.i32(), func, Expr(2_i)); auto* var_a = Var("a", ty.i32(), func, Expr(2_i));
auto* var_b = Let("b", ty.pointer<i32>(func), AddressOf(Expr("a"))); auto* var_b = Let("b", ty.pointer<i32>(func), AddressOf(Expr("a")));
WrapInFunction(var_a, var_b, Assign(Deref("b"), 2_a)); WrapInFunction(var_a, var_b, Assign(Deref("b"), 2_a));
@ -252,7 +252,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignNonConstructible_Atomic) {
auto* s = Structure("S", utils::Vector{ auto* s = Structure("S", utils::Vector{
Member("a", ty.atomic(ty.i32())), Member("a", ty.atomic(ty.i32())),
}); });
GlobalVar(Source{{12, 34}}, "v", ty.Of(s), type::AddressSpace::kStorage, GlobalVar(Source{{12, 34}}, "v", ty.Of(s), builtin::AddressSpace::kStorage,
builtin::Access::kReadWrite, Binding(0_a), Group(0_a)); builtin::Access::kReadWrite, Binding(0_a), Group(0_a));
WrapInFunction(Assign(Source{{56, 78}}, MemberAccessor("v", "a"), MemberAccessor("v", "a"))); WrapInFunction(Assign(Source{{56, 78}}, MemberAccessor("v", "a"), MemberAccessor("v", "a")));
@ -269,7 +269,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignNonConstructible_RuntimeArray) {
auto* s = Structure("S", utils::Vector{ auto* s = Structure("S", utils::Vector{
Member("a", ty.array(ty.f32())), Member("a", ty.array(ty.f32())),
}); });
GlobalVar(Source{{12, 34}}, "v", ty.Of(s), type::AddressSpace::kStorage, GlobalVar(Source{{12, 34}}, "v", ty.Of(s), builtin::AddressSpace::kStorage,
builtin::Access::kReadWrite, Binding(0_a), Group(0_a)); builtin::Access::kReadWrite, Binding(0_a), Group(0_a));
WrapInFunction(Assign(Source{{56, 78}}, MemberAccessor("v", "a"), MemberAccessor("v", "a"))); WrapInFunction(Assign(Source{{56, 78}}, MemberAccessor("v", "a"), MemberAccessor("v", "a")));
@ -289,7 +289,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignToPhony_NonConstructibleStruct_Fa
auto* s = Structure("S", utils::Vector{ auto* s = Structure("S", utils::Vector{
Member("arr", ty.array<i32>()), Member("arr", ty.array<i32>()),
}); });
GlobalVar("s", ty.Of(s), type::AddressSpace::kStorage, Group(0_a), Binding(0_a)); GlobalVar("s", ty.Of(s), builtin::AddressSpace::kStorage, Group(0_a), Binding(0_a));
WrapInFunction(Assign(Phony(), Expr(Source{{12, 34}}, "s"))); WrapInFunction(Assign(Phony(), Expr(Source{{12, 34}}, "s")));
@ -311,7 +311,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignToPhony_DynamicArray_Fail) {
auto* s = Structure("S", utils::Vector{ auto* s = Structure("S", utils::Vector{
Member("arr", ty.array<i32>()), Member("arr", ty.array<i32>()),
}); });
GlobalVar("s", ty.Of(s), type::AddressSpace::kStorage, Group(0_a), Binding(0_a)); GlobalVar("s", ty.Of(s), builtin::AddressSpace::kStorage, Group(0_a), Binding(0_a));
WrapInFunction(Assign(Phony(), MemberAccessor(Source{{12, 34}}, "s", "arr"))); WrapInFunction(Assign(Phony(), MemberAccessor(Source{{12, 34}}, "s", "arr")));
@ -364,9 +364,9 @@ TEST_F(ResolverAssignmentValidationTest, AssignToPhony_Pass) {
GlobalVar("tex", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Group(0_a), GlobalVar("tex", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Group(0_a),
Binding(0_a)); Binding(0_a));
GlobalVar("smp", ty.sampler(type::SamplerKind::kSampler), Group(0_a), Binding(1_a)); GlobalVar("smp", ty.sampler(type::SamplerKind::kSampler), Group(0_a), Binding(1_a));
GlobalVar("u", ty.Of(U), type::AddressSpace::kUniform, Group(0_a), Binding(2_a)); GlobalVar("u", ty.Of(U), builtin::AddressSpace::kUniform, Group(0_a), Binding(2_a));
GlobalVar("s", ty.Of(S), type::AddressSpace::kStorage, Group(0_a), Binding(3_a)); GlobalVar("s", ty.Of(S), builtin::AddressSpace::kStorage, Group(0_a), Binding(3_a));
GlobalVar("wg", ty.array<f32, 10>(), type::AddressSpace::kWorkgroup); GlobalVar("wg", ty.array<f32, 10>(), builtin::AddressSpace::kWorkgroup);
WrapInFunction(Assign(Phony(), 1_i), // WrapInFunction(Assign(Phony(), 1_i), //
Assign(Phony(), 2_u), // Assign(Phony(), 2_u), //

View File

@ -27,7 +27,8 @@ using namespace tint::number_suffixes; // NOLINT
struct ResolverAtomicTest : public resolver::TestHelper, public testing::Test {}; struct ResolverAtomicTest : public resolver::TestHelper, public testing::Test {};
TEST_F(ResolverAtomicTest, GlobalWorkgroupI32) { TEST_F(ResolverAtomicTest, GlobalWorkgroupI32) {
auto* g = GlobalVar("a", ty.atomic(Source{{12, 34}}, ty.i32()), type::AddressSpace::kWorkgroup); auto* g =
GlobalVar("a", ty.atomic(Source{{12, 34}}, ty.i32()), builtin::AddressSpace::kWorkgroup);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_TRUE(TypeOf(g)->Is<type::Reference>()); ASSERT_TRUE(TypeOf(g)->Is<type::Reference>());
@ -37,7 +38,8 @@ TEST_F(ResolverAtomicTest, GlobalWorkgroupI32) {
} }
TEST_F(ResolverAtomicTest, GlobalWorkgroupU32) { TEST_F(ResolverAtomicTest, GlobalWorkgroupU32) {
auto* g = GlobalVar("a", ty.atomic(Source{{12, 34}}, ty.u32()), type::AddressSpace::kWorkgroup); auto* g =
GlobalVar("a", ty.atomic(Source{{12, 34}}, ty.u32()), builtin::AddressSpace::kWorkgroup);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_TRUE(TypeOf(g)->Is<type::Reference>()); ASSERT_TRUE(TypeOf(g)->Is<type::Reference>());
@ -48,7 +50,7 @@ TEST_F(ResolverAtomicTest, GlobalWorkgroupU32) {
TEST_F(ResolverAtomicTest, GlobalStorageStruct) { TEST_F(ResolverAtomicTest, GlobalStorageStruct) {
auto* s = Structure("s", utils::Vector{Member("a", ty.atomic(Source{{12, 34}}, ty.i32()))}); auto* s = Structure("s", utils::Vector{Member("a", ty.atomic(Source{{12, 34}}, ty.i32()))});
auto* g = GlobalVar("g", ty.Of(s), type::AddressSpace::kStorage, builtin::Access::kReadWrite, auto* g = GlobalVar("g", ty.Of(s), builtin::AddressSpace::kStorage, builtin::Access::kReadWrite,
Binding(0_a), Group(0_a)); Binding(0_a), Group(0_a));
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();

View File

@ -27,13 +27,13 @@ namespace {
struct ResolverAtomicValidationTest : public resolver::TestHelper, public testing::Test {}; struct ResolverAtomicValidationTest : public resolver::TestHelper, public testing::Test {};
TEST_F(ResolverAtomicValidationTest, AddressSpace_WorkGroup) { TEST_F(ResolverAtomicValidationTest, AddressSpace_WorkGroup) {
GlobalVar("a", ty.atomic(Source{{12, 34}}, ty.i32()), type::AddressSpace::kWorkgroup); GlobalVar("a", ty.atomic(Source{{12, 34}}, ty.i32()), builtin::AddressSpace::kWorkgroup);
EXPECT_TRUE(r()->Resolve()); EXPECT_TRUE(r()->Resolve());
} }
TEST_F(ResolverAtomicValidationTest, AddressSpace_Storage) { TEST_F(ResolverAtomicValidationTest, AddressSpace_Storage) {
GlobalVar("g", ty.atomic(Source{{12, 34}}, ty.i32()), type::AddressSpace::kStorage, GlobalVar("g", ty.atomic(Source{{12, 34}}, ty.i32()), builtin::AddressSpace::kStorage,
builtin::Access::kReadWrite, Group(0_a), Binding(0_a)); builtin::Access::kReadWrite, Group(0_a), Binding(0_a));
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -41,21 +41,21 @@ TEST_F(ResolverAtomicValidationTest, AddressSpace_Storage) {
TEST_F(ResolverAtomicValidationTest, AddressSpace_Storage_Struct) { TEST_F(ResolverAtomicValidationTest, AddressSpace_Storage_Struct) {
auto* s = Structure("s", utils::Vector{Member(Source{{12, 34}}, "a", ty.atomic(ty.i32()))}); auto* s = Structure("s", utils::Vector{Member(Source{{12, 34}}, "a", ty.atomic(ty.i32()))});
GlobalVar("g", ty.Of(s), type::AddressSpace::kStorage, builtin::Access::kReadWrite, Group(0_a), GlobalVar("g", ty.Of(s), builtin::AddressSpace::kStorage, builtin::Access::kReadWrite,
Binding(0_a)); Group(0_a), Binding(0_a));
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverAtomicValidationTest, InvalidType) { TEST_F(ResolverAtomicValidationTest, InvalidType) {
GlobalVar("a", ty.atomic(ty.f32(Source{{12, 34}})), type::AddressSpace::kWorkgroup); GlobalVar("a", ty.atomic(ty.f32(Source{{12, 34}})), builtin::AddressSpace::kWorkgroup);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: atomic only supports i32 or u32 types"); EXPECT_EQ(r()->error(), "12:34 error: atomic only supports i32 or u32 types");
} }
TEST_F(ResolverAtomicValidationTest, InvalidAddressSpace_Simple) { TEST_F(ResolverAtomicValidationTest, InvalidAddressSpace_Simple) {
GlobalVar(Source{{12, 34}}, "a", ty.atomic(ty.i32()), type::AddressSpace::kPrivate); GlobalVar(Source{{12, 34}}, "a", ty.atomic(ty.i32()), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -63,7 +63,7 @@ TEST_F(ResolverAtomicValidationTest, InvalidAddressSpace_Simple) {
} }
TEST_F(ResolverAtomicValidationTest, InvalidAddressSpace_Array) { TEST_F(ResolverAtomicValidationTest, InvalidAddressSpace_Array) {
GlobalVar(Source{{12, 34}}, "a", ty.atomic(ty.i32()), type::AddressSpace::kPrivate); GlobalVar(Source{{12, 34}}, "a", ty.atomic(ty.i32()), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -72,7 +72,7 @@ TEST_F(ResolverAtomicValidationTest, InvalidAddressSpace_Array) {
TEST_F(ResolverAtomicValidationTest, InvalidAddressSpace_Struct) { TEST_F(ResolverAtomicValidationTest, InvalidAddressSpace_Struct) {
auto* s = Structure("s", utils::Vector{Member("a", ty.atomic(ty.i32()))}); auto* s = Structure("s", utils::Vector{Member("a", ty.atomic(ty.i32()))});
GlobalVar(Source{{56, 78}}, "g", ty.Of(s), type::AddressSpace::kPrivate); GlobalVar(Source{{56, 78}}, "g", ty.Of(s), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -88,7 +88,7 @@ TEST_F(ResolverAtomicValidationTest, InvalidAddressSpace_StructOfStruct) {
auto* Inner = auto* Inner =
Structure("Inner", utils::Vector{Member("m", ty.atomic(Source{{12, 34}}, ty.i32()))}); Structure("Inner", utils::Vector{Member("m", ty.atomic(Source{{12, 34}}, ty.i32()))});
auto* Outer = Structure("Outer", utils::Vector{Member("m", ty.Of(Inner))}); auto* Outer = Structure("Outer", utils::Vector{Member("m", ty.Of(Inner))});
GlobalVar(Source{{56, 78}}, "g", ty.Of(Outer), type::AddressSpace::kPrivate); GlobalVar(Source{{56, 78}}, "g", ty.Of(Outer), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -104,7 +104,7 @@ TEST_F(ResolverAtomicValidationTest, InvalidAddressSpace_StructOfStructOfArray)
auto* Inner = auto* Inner =
Structure("Inner", utils::Vector{Member(Source{{12, 34}}, "m", ty.atomic(ty.i32()))}); Structure("Inner", utils::Vector{Member(Source{{12, 34}}, "m", ty.atomic(ty.i32()))});
auto* Outer = Structure("Outer", utils::Vector{Member("m", ty.Of(Inner))}); auto* Outer = Structure("Outer", utils::Vector{Member("m", ty.Of(Inner))});
GlobalVar(Source{{56, 78}}, "g", ty.Of(Outer), type::AddressSpace::kPrivate); GlobalVar(Source{{56, 78}}, "g", ty.Of(Outer), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -118,7 +118,7 @@ TEST_F(ResolverAtomicValidationTest, InvalidAddressSpace_ArrayOfArray) {
auto* atomic_array = auto* atomic_array =
Alias(Source{{12, 34}}, "AtomicArray", ty.atomic(Source{{12, 34}}, ty.i32())); Alias(Source{{12, 34}}, "AtomicArray", ty.atomic(Source{{12, 34}}, ty.i32()));
GlobalVar(Source{{56, 78}}, "v", ty.Of(atomic_array), type::AddressSpace::kPrivate); GlobalVar(Source{{56, 78}}, "v", ty.Of(atomic_array), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -132,7 +132,7 @@ TEST_F(ResolverAtomicValidationTest, InvalidAddressSpace_ArrayOfStruct) {
// var<private> v: array<S, 5u>; // var<private> v: array<S, 5u>;
auto* s = Structure("S", utils::Vector{Member(Source{{12, 34}}, "m", ty.atomic<u32>())}); auto* s = Structure("S", utils::Vector{Member(Source{{12, 34}}, "m", ty.atomic<u32>())});
GlobalVar(Source{{56, 78}}, "v", ty.array(ty.Of(s), 5_u), type::AddressSpace::kPrivate); GlobalVar(Source{{56, 78}}, "v", ty.array(ty.Of(s), 5_u), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -149,7 +149,7 @@ TEST_F(ResolverAtomicValidationTest, InvalidAddressSpace_ArrayOfStructOfArray) {
auto* atomic_array = Alias("AtomicArray", ty.atomic(ty.i32())); auto* atomic_array = Alias("AtomicArray", ty.atomic(ty.i32()));
auto* s = Structure("S", utils::Vector{Member(Source{{12, 34}}, "m", ty.Of(atomic_array))}); auto* s = Structure("S", utils::Vector{Member(Source{{12, 34}}, "m", ty.Of(atomic_array))});
GlobalVar(Source{{56, 78}}, "v", ty.array(ty.Of(s), 5_u), type::AddressSpace::kPrivate); GlobalVar(Source{{56, 78}}, "v", ty.array(ty.Of(s), 5_u), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -188,7 +188,7 @@ TEST_F(ResolverAtomicValidationTest, InvalidAddressSpace_Complex) {
auto* s2 = Structure("S2", utils::Vector{Member("x", ty.Of(s3))}); auto* s2 = Structure("S2", utils::Vector{Member("x", ty.Of(s3))});
auto* s1 = Structure("S1", utils::Vector{Member("x", ty.Of(s2))}); auto* s1 = Structure("S1", utils::Vector{Member("x", ty.Of(s2))});
auto* s0 = Structure("S0", utils::Vector{Member("x", ty.Of(s1))}); auto* s0 = Structure("S0", utils::Vector{Member("x", ty.Of(s1))});
GlobalVar(Source{{56, 78}}, "g", ty.Of(s0), type::AddressSpace::kPrivate); GlobalVar(Source{{56, 78}}, "g", ty.Of(s0), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -198,8 +198,8 @@ TEST_F(ResolverAtomicValidationTest, InvalidAddressSpace_Complex) {
TEST_F(ResolverAtomicValidationTest, Struct_AccessMode_Read) { TEST_F(ResolverAtomicValidationTest, Struct_AccessMode_Read) {
auto* s = Structure("s", utils::Vector{Member(Source{{12, 34}}, "a", ty.atomic(ty.i32()))}); auto* s = Structure("s", utils::Vector{Member(Source{{12, 34}}, "a", ty.atomic(ty.i32()))});
GlobalVar(Source{{56, 78}}, "g", ty.Of(s), type::AddressSpace::kStorage, builtin::Access::kRead, GlobalVar(Source{{56, 78}}, "g", ty.Of(s), builtin::AddressSpace::kStorage,
Group(0_a), Binding(0_a)); builtin::Access::kRead, Group(0_a), Binding(0_a));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ( EXPECT_EQ(
@ -210,8 +210,8 @@ TEST_F(ResolverAtomicValidationTest, Struct_AccessMode_Read) {
TEST_F(ResolverAtomicValidationTest, InvalidAccessMode_Struct) { TEST_F(ResolverAtomicValidationTest, InvalidAccessMode_Struct) {
auto* s = Structure("s", utils::Vector{Member(Source{{12, 34}}, "a", ty.atomic(ty.i32()))}); auto* s = Structure("s", utils::Vector{Member(Source{{12, 34}}, "a", ty.atomic(ty.i32()))});
GlobalVar(Source{{56, 78}}, "g", ty.Of(s), type::AddressSpace::kStorage, builtin::Access::kRead, GlobalVar(Source{{56, 78}}, "g", ty.Of(s), builtin::AddressSpace::kStorage,
Group(0_a), Binding(0_a)); builtin::Access::kRead, Group(0_a), Binding(0_a));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ( EXPECT_EQ(
@ -228,7 +228,7 @@ TEST_F(ResolverAtomicValidationTest, InvalidAccessMode_StructOfStruct) {
auto* Inner = auto* Inner =
Structure("Inner", utils::Vector{Member(Source{{12, 34}}, "m", ty.atomic(ty.i32()))}); Structure("Inner", utils::Vector{Member(Source{{12, 34}}, "m", ty.atomic(ty.i32()))});
auto* Outer = Structure("Outer", utils::Vector{Member("m", ty.Of(Inner))}); auto* Outer = Structure("Outer", utils::Vector{Member("m", ty.Of(Inner))});
GlobalVar(Source{{56, 78}}, "g", ty.Of(Outer), type::AddressSpace::kStorage, GlobalVar(Source{{56, 78}}, "g", ty.Of(Outer), builtin::AddressSpace::kStorage,
builtin::Access::kRead, Group(0_a), Binding(0_a)); builtin::Access::kRead, Group(0_a), Binding(0_a));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -246,7 +246,7 @@ TEST_F(ResolverAtomicValidationTest, InvalidAccessMode_StructOfStructOfArray) {
auto* Inner = auto* Inner =
Structure("Inner", utils::Vector{Member(Source{{12, 34}}, "m", ty.atomic(ty.i32()))}); Structure("Inner", utils::Vector{Member(Source{{12, 34}}, "m", ty.atomic(ty.i32()))});
auto* Outer = Structure("Outer", utils::Vector{Member("m", ty.Of(Inner))}); auto* Outer = Structure("Outer", utils::Vector{Member("m", ty.Of(Inner))});
GlobalVar(Source{{56, 78}}, "g", ty.Of(Outer), type::AddressSpace::kStorage, GlobalVar(Source{{56, 78}}, "g", ty.Of(Outer), builtin::AddressSpace::kStorage,
builtin::Access::kRead, Group(0_a), Binding(0_a)); builtin::Access::kRead, Group(0_a), Binding(0_a));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -287,7 +287,7 @@ TEST_F(ResolverAtomicValidationTest, InvalidAccessMode_Complex) {
auto* s2 = Structure("S2", utils::Vector{Member("x", ty.Of(s3))}); auto* s2 = Structure("S2", utils::Vector{Member("x", ty.Of(s3))});
auto* s1 = Structure("S1", utils::Vector{Member("x", ty.Of(s2))}); auto* s1 = Structure("S1", utils::Vector{Member("x", ty.Of(s2))});
auto* s0 = Structure("S0", utils::Vector{Member("x", ty.Of(s1))}); auto* s0 = Structure("S0", utils::Vector{Member("x", ty.Of(s1))});
GlobalVar(Source{{12, 34}}, "g", ty.Of(s0), type::AddressSpace::kStorage, GlobalVar(Source{{12, 34}}, "g", ty.Of(s0), builtin::AddressSpace::kStorage,
builtin::Access::kRead, Group(0_a), Binding(0_a)); builtin::Access::kRead, Group(0_a), Binding(0_a));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());

View File

@ -734,7 +734,7 @@ TEST_F(StructMemberAttributeTest, Align_Attribute_ConstAFloat) {
} }
TEST_F(StructMemberAttributeTest, Align_Attribute_Var) { TEST_F(StructMemberAttributeTest, Align_Attribute_Var) {
GlobalVar(Source{{1, 2}}, "val", ty.f32(), type::AddressSpace::kPrivate, GlobalVar(Source{{1, 2}}, "val", ty.f32(), builtin::AddressSpace::kPrivate,
builtin::Access::kUndefined, Expr(1.23_f)); builtin::Access::kUndefined, Expr(1.23_f));
Structure(Source{{6, 4}}, "mystruct", Structure(Source{{6, 4}}, "mystruct",
@ -808,7 +808,7 @@ TEST_F(StructMemberAttributeTest, Size_Attribute_ConstAFloat) {
} }
TEST_F(StructMemberAttributeTest, Size_Attribute_Var) { TEST_F(StructMemberAttributeTest, Size_Attribute_Var) {
GlobalVar(Source{{1, 2}}, "val", ty.f32(), type::AddressSpace::kPrivate, GlobalVar(Source{{1, 2}}, "val", ty.f32(), builtin::AddressSpace::kPrivate,
builtin::Access::kUndefined, Expr(1.23_f)); builtin::Access::kUndefined, Expr(1.23_f));
Structure(Source{{6, 4}}, "mystruct", Structure(Source{{6, 4}}, "mystruct",
@ -888,7 +888,7 @@ TEST_P(VariableAttributeTest, IsValid) {
if (IsBindingAttribute(params.kind)) { if (IsBindingAttribute(params.kind)) {
GlobalVar("a", ty.sampler(type::SamplerKind::kSampler), attrs); GlobalVar("a", ty.sampler(type::SamplerKind::kSampler), attrs);
} else { } else {
GlobalVar("a", ty.f32(), type::AddressSpace::kPrivate, attrs); GlobalVar("a", ty.f32(), builtin::AddressSpace::kPrivate, attrs);
} }
if (params.should_pass) { if (params.should_pass) {
@ -1157,7 +1157,7 @@ TEST_P(ArrayStrideTest, All) {
create<ast::StrideAttribute>(Source{{12, 34}}, params.stride), create<ast::StrideAttribute>(Source{{12, 34}}, params.stride),
}); });
GlobalVar("myarray", arr, type::AddressSpace::kPrivate); GlobalVar("myarray", arr, builtin::AddressSpace::kPrivate);
if (params.should_pass) { if (params.should_pass) {
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -1240,7 +1240,7 @@ TEST_F(ArrayStrideTest, DuplicateAttribute) {
create<ast::StrideAttribute>(Source{{56, 78}}, 4u), create<ast::StrideAttribute>(Source{{56, 78}}, 4u),
}); });
GlobalVar("myarray", arr, type::AddressSpace::kPrivate); GlobalVar("myarray", arr, builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -1259,7 +1259,7 @@ TEST_F(ResourceAttributeTest, UniformBufferMissingBinding) {
auto* s = Structure("S", utils::Vector{ auto* s = Structure("S", utils::Vector{
Member("x", ty.i32()), Member("x", ty.i32()),
}); });
GlobalVar(Source{{12, 34}}, "G", ty.Of(s), type::AddressSpace::kUniform); GlobalVar(Source{{12, 34}}, "G", ty.Of(s), builtin::AddressSpace::kUniform);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -1270,7 +1270,7 @@ TEST_F(ResourceAttributeTest, StorageBufferMissingBinding) {
auto* s = Structure("S", utils::Vector{ auto* s = Structure("S", utils::Vector{
Member("x", ty.i32()), Member("x", ty.i32()),
}); });
GlobalVar(Source{{12, 34}}, "G", ty.Of(s), type::AddressSpace::kStorage, GlobalVar(Source{{12, 34}}, "G", ty.Of(s), builtin::AddressSpace::kStorage,
builtin::Access::kRead); builtin::Access::kRead);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1357,7 +1357,7 @@ TEST_F(ResourceAttributeTest, BindingPointUsedTwiceByDifferentEntryPoints) {
} }
TEST_F(ResourceAttributeTest, BindingPointOnNonResource) { TEST_F(ResourceAttributeTest, BindingPointOnNonResource) {
GlobalVar(Source{{12, 34}}, "G", ty.f32(), type::AddressSpace::kPrivate, Binding(1_a), GlobalVar(Source{{12, 34}}, "G", ty.f32(), builtin::AddressSpace::kPrivate, Binding(1_a),
Group(2_a)); Group(2_a));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());

View File

@ -81,7 +81,7 @@ using ResolverBuiltinTest_BoolMethod = ResolverTestWithParam<std::string>;
TEST_P(ResolverBuiltinTest_BoolMethod, Scalar) { TEST_P(ResolverBuiltinTest_BoolMethod, Scalar) {
auto name = GetParam(); auto name = GetParam();
GlobalVar("my_var", ty.bool_(), type::AddressSpace::kPrivate); GlobalVar("my_var", ty.bool_(), builtin::AddressSpace::kPrivate);
auto* expr = Call(name, "my_var"); auto* expr = Call(name, "my_var");
WrapInFunction(expr); WrapInFunction(expr);
@ -94,7 +94,7 @@ TEST_P(ResolverBuiltinTest_BoolMethod, Scalar) {
TEST_P(ResolverBuiltinTest_BoolMethod, Vector) { TEST_P(ResolverBuiltinTest_BoolMethod, Vector) {
auto name = GetParam(); auto name = GetParam();
GlobalVar("my_var", ty.vec3<bool>(), type::AddressSpace::kPrivate); GlobalVar("my_var", ty.vec3<bool>(), builtin::AddressSpace::kPrivate);
auto* expr = Call(name, "my_var"); auto* expr = Call(name, "my_var");
WrapInFunction(expr); WrapInFunction(expr);
@ -109,9 +109,9 @@ INSTANTIATE_TEST_SUITE_P(ResolverTest,
testing::Values("any", "all")); testing::Values("any", "all"));
TEST_F(ResolverBuiltinTest, Select) { TEST_F(ResolverBuiltinTest, Select) {
GlobalVar("my_var", ty.vec3<f32>(), type::AddressSpace::kPrivate); GlobalVar("my_var", ty.vec3<f32>(), builtin::AddressSpace::kPrivate);
GlobalVar("bool_var", ty.vec3<bool>(), type::AddressSpace::kPrivate); GlobalVar("bool_var", ty.vec3<bool>(), builtin::AddressSpace::kPrivate);
auto* expr = Call("select", "my_var", "my_var", "bool_var"); auto* expr = Call("select", "my_var", "my_var", "bool_var");
WrapInFunction(expr); WrapInFunction(expr);
@ -215,8 +215,8 @@ using ResolverBuiltinArrayTest = ResolverTest;
TEST_F(ResolverBuiltinArrayTest, ArrayLength_Vector) { TEST_F(ResolverBuiltinArrayTest, ArrayLength_Vector) {
auto ary = ty.array<i32>(); auto ary = ty.array<i32>();
auto* str = Structure("S", utils::Vector{Member("x", ary)}); auto* str = Structure("S", utils::Vector{Member("x", ary)});
GlobalVar("a", ty.Of(str), type::AddressSpace::kStorage, builtin::Access::kRead, Binding(0_a), GlobalVar("a", ty.Of(str), builtin::AddressSpace::kStorage, builtin::Access::kRead,
Group(0_a)); Binding(0_a), Group(0_a));
auto* call = Call("arrayLength", AddressOf(MemberAccessor("a", "x"))); auto* call = Call("arrayLength", AddressOf(MemberAccessor("a", "x")));
WrapInFunction(call); WrapInFunction(call);
@ -228,7 +228,7 @@ TEST_F(ResolverBuiltinArrayTest, ArrayLength_Vector) {
} }
TEST_F(ResolverBuiltinArrayTest, ArrayLength_Error_ArraySized) { TEST_F(ResolverBuiltinArrayTest, ArrayLength_Error_ArraySized) {
GlobalVar("arr", ty.array<i32, 4>(), type::AddressSpace::kPrivate); GlobalVar("arr", ty.array<i32, 4>(), builtin::AddressSpace::kPrivate);
auto* call = Call("arrayLength", AddressOf("arr")); auto* call = Call("arrayLength", AddressOf("arr"));
WrapInFunction(call); WrapInFunction(call);
@ -1048,7 +1048,7 @@ TEST_F(ResolverBuiltinFloatTest, FrexpVector_f16) {
} }
TEST_F(ResolverBuiltinFloatTest, Frexp_Error_FirstParamInt) { TEST_F(ResolverBuiltinFloatTest, Frexp_Error_FirstParamInt) {
GlobalVar("v", ty.i32(), type::AddressSpace::kWorkgroup); GlobalVar("v", ty.i32(), builtin::AddressSpace::kWorkgroup);
auto* call = Call("frexp", 1_i, AddressOf("v")); auto* call = Call("frexp", 1_i, AddressOf("v"));
WrapInFunction(call); WrapInFunction(call);
@ -1297,7 +1297,7 @@ TEST_F(ResolverBuiltinFloatTest, ModfVector_f16) {
} }
TEST_F(ResolverBuiltinFloatTest, Modf_Error_FirstParamInt) { TEST_F(ResolverBuiltinFloatTest, Modf_Error_FirstParamInt) {
GlobalVar("whole", ty.f32(), type::AddressSpace::kWorkgroup); GlobalVar("whole", ty.f32(), builtin::AddressSpace::kWorkgroup);
auto* call = Call("modf", 1_i, AddressOf("whole")); auto* call = Call("modf", 1_i, AddressOf("whole"));
WrapInFunction(call); WrapInFunction(call);
@ -1313,7 +1313,7 @@ TEST_F(ResolverBuiltinFloatTest, Modf_Error_FirstParamInt) {
} }
TEST_F(ResolverBuiltinFloatTest, Modf_Error_SecondParamIntPtr) { TEST_F(ResolverBuiltinFloatTest, Modf_Error_SecondParamIntPtr) {
GlobalVar("whole", ty.i32(), type::AddressSpace::kWorkgroup); GlobalVar("whole", ty.i32(), builtin::AddressSpace::kWorkgroup);
auto* call = Call("modf", 1_f, AddressOf("whole")); auto* call = Call("modf", 1_f, AddressOf("whole"));
WrapInFunction(call); WrapInFunction(call);
@ -1343,7 +1343,7 @@ TEST_F(ResolverBuiltinFloatTest, Modf_Error_SecondParamNotAPointer) {
} }
TEST_F(ResolverBuiltinFloatTest, Modf_Error_VectorSizesDontMatch) { TEST_F(ResolverBuiltinFloatTest, Modf_Error_VectorSizesDontMatch) {
GlobalVar("whole", ty.vec4<f32>(), type::AddressSpace::kWorkgroup); GlobalVar("whole", ty.vec4<f32>(), builtin::AddressSpace::kWorkgroup);
auto* call = Call("modf", vec2<f32>(1_f, 2_f), AddressOf("whole")); auto* call = Call("modf", vec2<f32>(1_f, 2_f), AddressOf("whole"));
WrapInFunction(call); WrapInFunction(call);
@ -1823,7 +1823,7 @@ INSTANTIATE_TEST_SUITE_P(
namespace matrix_builtin_tests { namespace matrix_builtin_tests {
TEST_F(ResolverBuiltinTest, Determinant_2x2_f32) { TEST_F(ResolverBuiltinTest, Determinant_2x2_f32) {
GlobalVar("var", ty.mat2x2<f32>(), type::AddressSpace::kPrivate); GlobalVar("var", ty.mat2x2<f32>(), builtin::AddressSpace::kPrivate);
auto* call = Call("determinant", "var"); auto* call = Call("determinant", "var");
WrapInFunction(call); WrapInFunction(call);
@ -1837,7 +1837,7 @@ TEST_F(ResolverBuiltinTest, Determinant_2x2_f32) {
TEST_F(ResolverBuiltinTest, Determinant_2x2_f16) { TEST_F(ResolverBuiltinTest, Determinant_2x2_f16) {
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
GlobalVar("var", ty.mat2x2<f16>(), type::AddressSpace::kPrivate); GlobalVar("var", ty.mat2x2<f16>(), builtin::AddressSpace::kPrivate);
auto* call = Call("determinant", "var"); auto* call = Call("determinant", "var");
WrapInFunction(call); WrapInFunction(call);
@ -1849,7 +1849,7 @@ TEST_F(ResolverBuiltinTest, Determinant_2x2_f16) {
} }
TEST_F(ResolverBuiltinTest, Determinant_3x3_f32) { TEST_F(ResolverBuiltinTest, Determinant_3x3_f32) {
GlobalVar("var", ty.mat3x3<f32>(), type::AddressSpace::kPrivate); GlobalVar("var", ty.mat3x3<f32>(), builtin::AddressSpace::kPrivate);
auto* call = Call("determinant", "var"); auto* call = Call("determinant", "var");
WrapInFunction(call); WrapInFunction(call);
@ -1863,7 +1863,7 @@ TEST_F(ResolverBuiltinTest, Determinant_3x3_f32) {
TEST_F(ResolverBuiltinTest, Determinant_3x3_f16) { TEST_F(ResolverBuiltinTest, Determinant_3x3_f16) {
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
GlobalVar("var", ty.mat3x3<f16>(), type::AddressSpace::kPrivate); GlobalVar("var", ty.mat3x3<f16>(), builtin::AddressSpace::kPrivate);
auto* call = Call("determinant", "var"); auto* call = Call("determinant", "var");
WrapInFunction(call); WrapInFunction(call);
@ -1875,7 +1875,7 @@ TEST_F(ResolverBuiltinTest, Determinant_3x3_f16) {
} }
TEST_F(ResolverBuiltinTest, Determinant_4x4_f32) { TEST_F(ResolverBuiltinTest, Determinant_4x4_f32) {
GlobalVar("var", ty.mat4x4<f32>(), type::AddressSpace::kPrivate); GlobalVar("var", ty.mat4x4<f32>(), builtin::AddressSpace::kPrivate);
auto* call = Call("determinant", "var"); auto* call = Call("determinant", "var");
WrapInFunction(call); WrapInFunction(call);
@ -1889,7 +1889,7 @@ TEST_F(ResolverBuiltinTest, Determinant_4x4_f32) {
TEST_F(ResolverBuiltinTest, Determinant_4x4_f16) { TEST_F(ResolverBuiltinTest, Determinant_4x4_f16) {
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
GlobalVar("var", ty.mat4x4<f16>(), type::AddressSpace::kPrivate); GlobalVar("var", ty.mat4x4<f16>(), builtin::AddressSpace::kPrivate);
auto* call = Call("determinant", "var"); auto* call = Call("determinant", "var");
WrapInFunction(call); WrapInFunction(call);
@ -1901,7 +1901,7 @@ TEST_F(ResolverBuiltinTest, Determinant_4x4_f16) {
} }
TEST_F(ResolverBuiltinTest, Determinant_NotSquare) { TEST_F(ResolverBuiltinTest, Determinant_NotSquare) {
GlobalVar("var", ty.mat2x3<f32>(), type::AddressSpace::kPrivate); GlobalVar("var", ty.mat2x3<f32>(), builtin::AddressSpace::kPrivate);
auto* call = Call("determinant", "var"); auto* call = Call("determinant", "var");
WrapInFunction(call); WrapInFunction(call);
@ -1916,7 +1916,7 @@ TEST_F(ResolverBuiltinTest, Determinant_NotSquare) {
} }
TEST_F(ResolverBuiltinTest, Determinant_NotMatrix) { TEST_F(ResolverBuiltinTest, Determinant_NotMatrix) {
GlobalVar("var", ty.f32(), type::AddressSpace::kPrivate); GlobalVar("var", ty.f32(), builtin::AddressSpace::kPrivate);
auto* call = Call("determinant", "var"); auto* call = Call("determinant", "var");
WrapInFunction(call); WrapInFunction(call);
@ -1936,7 +1936,7 @@ TEST_F(ResolverBuiltinTest, Determinant_NotMatrix) {
namespace vector_builtin_tests { namespace vector_builtin_tests {
TEST_F(ResolverBuiltinTest, Dot_Vec2_f32) { TEST_F(ResolverBuiltinTest, Dot_Vec2_f32) {
GlobalVar("my_var", ty.vec2<f32>(), type::AddressSpace::kPrivate); GlobalVar("my_var", ty.vec2<f32>(), builtin::AddressSpace::kPrivate);
auto* expr = Call("dot", "my_var", "my_var"); auto* expr = Call("dot", "my_var", "my_var");
WrapInFunction(expr); WrapInFunction(expr);
@ -1950,7 +1950,7 @@ TEST_F(ResolverBuiltinTest, Dot_Vec2_f32) {
TEST_F(ResolverBuiltinTest, Dot_Vec2_f16) { TEST_F(ResolverBuiltinTest, Dot_Vec2_f16) {
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
GlobalVar("my_var", ty.vec2<f16>(), type::AddressSpace::kPrivate); GlobalVar("my_var", ty.vec2<f16>(), builtin::AddressSpace::kPrivate);
auto* expr = Call("dot", "my_var", "my_var"); auto* expr = Call("dot", "my_var", "my_var");
WrapInFunction(expr); WrapInFunction(expr);
@ -1962,7 +1962,7 @@ TEST_F(ResolverBuiltinTest, Dot_Vec2_f16) {
} }
TEST_F(ResolverBuiltinTest, Dot_Vec3_i32) { TEST_F(ResolverBuiltinTest, Dot_Vec3_i32) {
GlobalVar("my_var", ty.vec3<i32>(), type::AddressSpace::kPrivate); GlobalVar("my_var", ty.vec3<i32>(), builtin::AddressSpace::kPrivate);
auto* expr = Call("dot", "my_var", "my_var"); auto* expr = Call("dot", "my_var", "my_var");
WrapInFunction(expr); WrapInFunction(expr);
@ -1974,7 +1974,7 @@ TEST_F(ResolverBuiltinTest, Dot_Vec3_i32) {
} }
TEST_F(ResolverBuiltinTest, Dot_Vec4_u32) { TEST_F(ResolverBuiltinTest, Dot_Vec4_u32) {
GlobalVar("my_var", ty.vec4<u32>(), type::AddressSpace::kPrivate); GlobalVar("my_var", ty.vec4<u32>(), builtin::AddressSpace::kPrivate);
auto* expr = Call("dot", "my_var", "my_var"); auto* expr = Call("dot", "my_var", "my_var");
WrapInFunction(expr); WrapInFunction(expr);
@ -2009,7 +2009,7 @@ using ResolverBuiltinDerivativeTest = ResolverTestWithParam<std::string>;
TEST_P(ResolverBuiltinDerivativeTest, Scalar) { TEST_P(ResolverBuiltinDerivativeTest, Scalar) {
auto name = GetParam(); auto name = GetParam();
GlobalVar("ident", ty.f32(), type::AddressSpace::kPrivate); GlobalVar("ident", ty.f32(), builtin::AddressSpace::kPrivate);
auto* expr = Call(name, "ident"); auto* expr = Call(name, "ident");
Func("func", utils::Empty, ty.void_(), utils::Vector{Ignore(expr)}, Func("func", utils::Empty, ty.void_(), utils::Vector{Ignore(expr)},
@ -2023,7 +2023,7 @@ TEST_P(ResolverBuiltinDerivativeTest, Scalar) {
TEST_P(ResolverBuiltinDerivativeTest, Vector) { TEST_P(ResolverBuiltinDerivativeTest, Vector) {
auto name = GetParam(); auto name = GetParam();
GlobalVar("ident", ty.vec4<f32>(), type::AddressSpace::kPrivate); GlobalVar("ident", ty.vec4<f32>(), builtin::AddressSpace::kPrivate);
auto* expr = Call(name, "ident"); auto* expr = Call(name, "ident");
Func("func", utils::Empty, ty.void_(), utils::Vector{Ignore(expr)}, Func("func", utils::Empty, ty.void_(), utils::Vector{Ignore(expr)},
@ -2119,7 +2119,7 @@ class ResolverBuiltinTest_TextureOperation : public ResolverTestWithParam<Textur
if (utils::HasPrefix(type_name, "texture") || utils::HasPrefix(type_name, "sampler")) { if (utils::HasPrefix(type_name, "texture") || utils::HasPrefix(type_name, "sampler")) {
GlobalVar(name, type, Binding(0_a), Group(0_a)); GlobalVar(name, type, Binding(0_a), Group(0_a));
} else { } else {
GlobalVar(name, type, type::AddressSpace::kPrivate); GlobalVar(name, type, builtin::AddressSpace::kPrivate);
} }
call_params->Push(Expr(name)); call_params->Push(Expr(name));

View File

@ -132,7 +132,7 @@ TEST_F(ResolverBuiltinValidationTest, BuiltinRedeclaredAsGlobalConstUsedAsVariab
TEST_F(ResolverBuiltinValidationTest, BuiltinRedeclaredAsGlobalVarUsedAsVariable) { TEST_F(ResolverBuiltinValidationTest, BuiltinRedeclaredAsGlobalVarUsedAsVariable) {
auto* mix = auto* mix =
GlobalVar(Source{{12, 34}}, "mix", ty.i32(), Expr(1_i), type::AddressSpace::kPrivate); GlobalVar(Source{{12, 34}}, "mix", ty.i32(), Expr(1_i), builtin::AddressSpace::kPrivate);
auto* use = Expr("mix"); auto* use = Expr("mix");
WrapInFunction(Decl(Var("v", use))); WrapInFunction(Decl(Var("v", use)));
@ -410,7 +410,7 @@ TEST_P(BuiltinTextureConstExprArgValidationTest, GlobalVar) {
overload.BuildSamplerVariable(this); overload.BuildSamplerVariable(this);
// Build the module-scope var 'G' with the offset value // Build the module-scope var 'G' with the offset value
GlobalVar("G", expr({}, *this), type::AddressSpace::kPrivate); GlobalVar("G", expr({}, *this), builtin::AddressSpace::kPrivate);
auto args = overload.args(this); auto args = overload.args(this);
auto*& arg_to_replace = (param.position == Position::kFirst) ? args.Front() : args.Back(); auto*& arg_to_replace = (param.position == Position::kFirst) ? args.Front() : args.Back();
@ -581,7 +581,7 @@ TEST_F(ResolverBuiltinValidationTest, WorkgroupUniformLoad_WrongAddressSpace) {
// fn foo() { // fn foo() {
// workgroupUniformLoad(&v); // workgroupUniformLoad(&v);
// } // }
GlobalVar("v", ty.i32(), type::AddressSpace::kStorage, builtin::Access::kReadWrite, GlobalVar("v", ty.i32(), builtin::AddressSpace::kStorage, builtin::Access::kReadWrite,
utils::Vector{Group(0_a), Binding(0_a)}); utils::Vector{Group(0_a), Binding(0_a)});
WrapInFunction(CallStmt(Call("workgroupUniformLoad", AddressOf(Source{{12, 34}}, "v")))); WrapInFunction(CallStmt(Call("workgroupUniformLoad", AddressOf(Source{{12, 34}}, "v"))));
@ -599,7 +599,7 @@ TEST_F(ResolverBuiltinValidationTest, WorkgroupUniformLoad_Atomic) {
// fn foo() { // fn foo() {
// workgroupUniformLoad(&v); // workgroupUniformLoad(&v);
// } // }
GlobalVar("v", ty.atomic<i32>(), type::AddressSpace::kWorkgroup); GlobalVar("v", ty.atomic<i32>(), builtin::AddressSpace::kWorkgroup);
WrapInFunction(CallStmt(Call("workgroupUniformLoad", AddressOf(Source{{12, 34}}, "v")))); WrapInFunction(CallStmt(Call("workgroupUniformLoad", AddressOf(Source{{12, 34}}, "v"))));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -613,7 +613,7 @@ TEST_F(ResolverBuiltinValidationTest, WorkgroupUniformLoad_AtomicInArray) {
// fn foo() { // fn foo() {
// workgroupUniformLoad(&v); // workgroupUniformLoad(&v);
// } // }
GlobalVar("v", ty.array(ty.atomic<i32>(), 4_a), type::AddressSpace::kWorkgroup); GlobalVar("v", ty.array(ty.atomic<i32>(), 4_a), builtin::AddressSpace::kWorkgroup);
WrapInFunction(CallStmt(Call("workgroupUniformLoad", AddressOf(Source{{12, 34}}, "v")))); WrapInFunction(CallStmt(Call("workgroupUniformLoad", AddressOf(Source{{12, 34}}, "v"))));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -631,7 +631,7 @@ TEST_F(ResolverBuiltinValidationTest, WorkgroupUniformLoad_AtomicInStruct) {
// } // }
Structure("Inner", utils::Vector{Member("a", ty.array(ty.atomic<i32>(), 4_a))}); Structure("Inner", utils::Vector{Member("a", ty.array(ty.atomic<i32>(), 4_a))});
Structure("S", utils::Vector{Member("i", ty("Inner"))}); Structure("S", utils::Vector{Member("i", ty("Inner"))});
GlobalVar(Source{{12, 34}}, "v", ty.array(ty("S"), 4_a), type::AddressSpace::kWorkgroup); GlobalVar(Source{{12, 34}}, "v", ty.array(ty("S"), 4_a), builtin::AddressSpace::kWorkgroup);
WrapInFunction(CallStmt(Call("workgroupUniformLoad", AddressOf("v")))); WrapInFunction(CallStmt(Call("workgroupUniformLoad", AddressOf("v"))));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());

View File

@ -112,7 +112,7 @@ using ResolverBuiltinsStageTest = ResolverTestWithParam<Params>;
TEST_P(ResolverBuiltinsStageTest, All_input) { TEST_P(ResolverBuiltinsStageTest, All_input) {
const Params& params = GetParam(); const Params& params = GetParam();
auto* p = GlobalVar("p", ty.vec4<f32>(), type::AddressSpace::kPrivate); auto* p = GlobalVar("p", ty.vec4<f32>(), builtin::AddressSpace::kPrivate);
auto* input = Param("input", params.type(*this), auto* input = Param("input", params.type(*this),
utils::Vector{Builtin(Source{{12, 34}}, params.builtin)}); utils::Vector{Builtin(Source{{12, 34}}, params.builtin)});
switch (params.stage) { switch (params.stage) {

View File

@ -103,7 +103,7 @@ TEST_F(ResolverCallValidationTest, PointerArgument_VariableIdentExpr) {
// var z: i32 = 1i; // var z: i32 = 1i;
// foo(&z); // foo(&z);
// } // }
auto* param = Param("p", ty.pointer<i32>(type::AddressSpace::kFunction)); auto* param = Param("p", ty.pointer<i32>(builtin::AddressSpace::kFunction));
Func("foo", utils::Vector{param}, ty.void_(), utils::Empty); Func("foo", utils::Vector{param}, ty.void_(), utils::Empty);
Func("main", utils::Empty, ty.void_(), Func("main", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
@ -120,7 +120,7 @@ TEST_F(ResolverCallValidationTest, PointerArgument_LetIdentExpr) {
// let z: i32 = 1i; // let z: i32 = 1i;
// foo(&z); // foo(&z);
// } // }
auto* param = Param("p", ty.pointer<i32>(type::AddressSpace::kFunction)); auto* param = Param("p", ty.pointer<i32>(builtin::AddressSpace::kFunction));
Func("foo", utils::Vector{param}, ty.void_(), utils::Empty); Func("foo", utils::Vector{param}, ty.void_(), utils::Empty);
Func("main", utils::Empty, ty.void_(), Func("main", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
@ -142,7 +142,7 @@ TEST_F(ResolverCallValidationTest, PointerArgument_AddressOfFunctionMember) {
auto* S = Structure("S", utils::Vector{ auto* S = Structure("S", utils::Vector{
Member("m", ty.i32()), Member("m", ty.i32()),
}); });
auto* param = Param("p", ty.pointer<i32>(type::AddressSpace::kFunction)); auto* param = Param("p", ty.pointer<i32>(builtin::AddressSpace::kFunction));
Func("foo", utils::Vector{param}, ty.void_(), utils::Empty); Func("foo", utils::Vector{param}, ty.void_(), utils::Empty);
Func("main", utils::Empty, ty.void_(), Func("main", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
@ -169,7 +169,7 @@ TEST_F(ResolverCallValidationTest,
auto* S = Structure("S", utils::Vector{ auto* S = Structure("S", utils::Vector{
Member("m", ty.i32()), Member("m", ty.i32()),
}); });
auto* param = Param("p", ty.pointer<i32>(type::AddressSpace::kFunction)); auto* param = Param("p", ty.pointer<i32>(builtin::AddressSpace::kFunction));
Func("foo", utils::Vector{param}, ty.void_(), utils::Empty); Func("foo", utils::Vector{param}, ty.void_(), utils::Empty);
Func("main", utils::Empty, ty.void_(), Func("main", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
@ -189,7 +189,7 @@ TEST_F(ResolverCallValidationTest, PointerArgument_AddressOfLetMember) {
auto* S = Structure("S", utils::Vector{ auto* S = Structure("S", utils::Vector{
Member("m", ty.i32()), Member("m", ty.i32()),
}); });
auto* param = Param("p", ty.pointer<i32>(type::AddressSpace::kFunction)); auto* param = Param("p", ty.pointer<i32>(builtin::AddressSpace::kFunction));
Func("foo", utils::Vector{param}, ty.void_(), utils::Empty); Func("foo", utils::Vector{param}, ty.void_(), utils::Empty);
Func("main", utils::Empty, ty.void_(), Func("main", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
@ -208,12 +208,12 @@ TEST_F(ResolverCallValidationTest, PointerArgument_FunctionParam) {
// } // }
Func("foo", Func("foo",
utils::Vector{ utils::Vector{
Param("p", ty.pointer<i32>(type::AddressSpace::kFunction)), Param("p", ty.pointer<i32>(builtin::AddressSpace::kFunction)),
}, },
ty.void_(), utils::Empty); ty.void_(), utils::Empty);
Func("bar", Func("bar",
utils::Vector{ utils::Vector{
Param("p", ty.pointer<i32>(type::AddressSpace::kFunction)), Param("p", ty.pointer<i32>(builtin::AddressSpace::kFunction)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{
@ -235,12 +235,12 @@ TEST_F(ResolverCallValidationTest, PointerArgument_FunctionParamWithMain) {
// } // }
Func("foo", Func("foo",
utils::Vector{ utils::Vector{
Param("p", ty.pointer<i32>(type::AddressSpace::kFunction)), Param("p", ty.pointer<i32>(builtin::AddressSpace::kFunction)),
}, },
ty.void_(), utils::Empty); ty.void_(), utils::Empty);
Func("bar", Func("bar",
utils::Vector{ utils::Vector{
Param("p", ty.pointer<i32>(type::AddressSpace::kFunction)), Param("p", ty.pointer<i32>(builtin::AddressSpace::kFunction)),
}, },
ty.void_(), ty.void_(),
utils::Vector{ utils::Vector{
@ -268,13 +268,13 @@ TEST_F(ResolverCallValidationTest, LetPointer) {
// } // }
Func("x", Func("x",
utils::Vector{ utils::Vector{
Param("p", ty.pointer<i32>(type::AddressSpace::kFunction)), Param("p", ty.pointer<i32>(builtin::AddressSpace::kFunction)),
}, },
ty.void_(), utils::Empty); ty.void_(), utils::Empty);
Func("main", utils::Empty, ty.void_(), Func("main", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
Decl(Var("v", ty.i32())), Decl(Var("v", ty.i32())),
Decl(Let("p", ty.pointer(ty.i32(), type::AddressSpace::kFunction), AddressOf("v"))), Decl(Let("p", ty.pointer(ty.i32(), builtin::AddressSpace::kFunction), AddressOf("v"))),
CallStmt(Call("x", "p")), CallStmt(Call("x", "p")),
}, },
utils::Vector{ utils::Vector{
@ -293,13 +293,13 @@ TEST_F(ResolverCallValidationTest, LetPointerPrivate) {
// } // }
Func("foo", Func("foo",
utils::Vector{ utils::Vector{
Param("p", ty.pointer<i32>(type::AddressSpace::kPrivate)), Param("p", ty.pointer<i32>(builtin::AddressSpace::kPrivate)),
}, },
ty.void_(), utils::Empty); ty.void_(), utils::Empty);
GlobalVar("v", ty.i32(), type::AddressSpace::kPrivate); GlobalVar("v", ty.i32(), builtin::AddressSpace::kPrivate);
Func("main", utils::Empty, ty.void_(), Func("main", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
Decl(Let("p", ty.pointer(ty.i32(), type::AddressSpace::kPrivate), AddressOf("v"))), Decl(Let("p", ty.pointer(ty.i32(), builtin::AddressSpace::kPrivate), AddressOf("v"))),
CallStmt(Call("foo", Expr(Source{{12, 34}}, "p"))), CallStmt(Call("foo", Expr(Source{{12, 34}}, "p"))),
}, },
utils::Vector{ utils::Vector{
@ -318,13 +318,13 @@ TEST_F(ResolverCallValidationTest, LetPointer_NotWholeVar) {
// } // }
Func("foo", Func("foo",
utils::Vector{ utils::Vector{
Param("p", ty.pointer<i32>(type::AddressSpace::kFunction)), Param("p", ty.pointer<i32>(builtin::AddressSpace::kFunction)),
}, },
ty.void_(), utils::Empty); ty.void_(), utils::Empty);
Func("main", utils::Empty, ty.void_(), Func("main", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
Decl(Var("v", ty.array<i32, 4>())), Decl(Var("v", ty.array<i32, 4>())),
Decl(Let("p", ty.pointer(ty.i32(), type::AddressSpace::kFunction), Decl(Let("p", ty.pointer(ty.i32(), builtin::AddressSpace::kFunction),
AddressOf(IndexAccessor("v", 0_a)))), AddressOf(IndexAccessor("v", 0_a)))),
CallStmt(Call("foo", Expr(Source{{12, 34}}, "p"))), CallStmt(Call("foo", Expr(Source{{12, 34}}, "p"))),
}, },
@ -349,13 +349,13 @@ TEST_F(ResolverCallValidationTest, LetPointer_NotWholeVar_WithFullPtrParametersE
Enable(builtin::Extension::kChromiumExperimentalFullPtrParameters); Enable(builtin::Extension::kChromiumExperimentalFullPtrParameters);
Func("foo", Func("foo",
utils::Vector{ utils::Vector{
Param("p", ty.pointer<i32>(type::AddressSpace::kFunction)), Param("p", ty.pointer<i32>(builtin::AddressSpace::kFunction)),
}, },
ty.void_(), utils::Empty); ty.void_(), utils::Empty);
Func("main", utils::Empty, ty.void_(), Func("main", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
Decl(Var("v", ty.array<i32, 4>())), Decl(Var("v", ty.array<i32, 4>())),
Decl(Let("p", ty.pointer(ty.i32(), type::AddressSpace::kFunction), Decl(Let("p", ty.pointer(ty.i32(), builtin::AddressSpace::kFunction),
AddressOf(IndexAccessor("v", 0_a)))), AddressOf(IndexAccessor("v", 0_a)))),
CallStmt(Call("foo", Expr(Source{{12, 34}}, "p"))), CallStmt(Call("foo", Expr(Source{{12, 34}}, "p"))),
}, },
@ -377,7 +377,7 @@ TEST_F(ResolverCallValidationTest, ComplexPointerChain) {
// } // }
Func("foo", Func("foo",
utils::Vector{ utils::Vector{
Param("p", ty.pointer(ty.array<i32, 4>(), type::AddressSpace::kFunction)), Param("p", ty.pointer(ty.array<i32, 4>(), builtin::AddressSpace::kFunction)),
}, },
ty.void_(), utils::Empty); ty.void_(), utils::Empty);
Func("main", utils::Empty, ty.void_(), Func("main", utils::Empty, ty.void_(),
@ -406,7 +406,7 @@ TEST_F(ResolverCallValidationTest, ComplexPointerChain_NotWholeVar) {
// } // }
Func("foo", Func("foo",
utils::Vector{ utils::Vector{
Param("p", ty.pointer<i32>(type::AddressSpace::kFunction)), Param("p", ty.pointer<i32>(builtin::AddressSpace::kFunction)),
}, },
ty.void_(), utils::Empty); ty.void_(), utils::Empty);
Func("main", utils::Empty, ty.void_(), Func("main", utils::Empty, ty.void_(),
@ -440,7 +440,7 @@ TEST_F(ResolverCallValidationTest, ComplexPointerChain_NotWholeVar_WithFullPtrPa
Enable(builtin::Extension::kChromiumExperimentalFullPtrParameters); Enable(builtin::Extension::kChromiumExperimentalFullPtrParameters);
Func("foo", Func("foo",
utils::Vector{ utils::Vector{
Param("p", ty.pointer<i32>(type::AddressSpace::kFunction)), Param("p", ty.pointer<i32>(builtin::AddressSpace::kFunction)),
}, },
ty.void_(), utils::Empty); ty.void_(), utils::Empty);
Func("main", utils::Empty, ty.void_(), Func("main", utils::Empty, ty.void_(),

View File

@ -51,7 +51,7 @@ TEST_F(ResolverCompoundAssignmentValidationTest, CompatibleTypesAssignThroughPoi
// var a : i32; // var a : i32;
// let b : ptr<function,i32> = &a; // let b : ptr<function,i32> = &a;
// *b += 2; // *b += 2;
const auto func = type::AddressSpace::kFunction; const auto func = builtin::AddressSpace::kFunction;
auto* var_a = Var("a", ty.i32(), func, Expr(2_i)); auto* var_a = Var("a", ty.i32(), func, Expr(2_i));
auto* var_b = Let("b", ty.pointer<i32>(func), AddressOf(Expr("a"))); auto* var_b = Let("b", ty.pointer<i32>(func), AddressOf(Expr("a")));
WrapInFunction(var_a, var_b, WrapInFunction(var_a, var_b,
@ -233,8 +233,8 @@ TEST_F(ResolverCompoundAssignmentValidationTest, ReadOnlyBuffer) {
// { // {
// a += 1i; // a += 1i;
// } // }
GlobalVar(Source{{12, 34}}, "a", ty.i32(), type::AddressSpace::kStorage, builtin::Access::kRead, GlobalVar(Source{{12, 34}}, "a", ty.i32(), builtin::AddressSpace::kStorage,
Group(0_a), Binding(0_a)); builtin::Access::kRead, Group(0_a), Binding(0_a));
WrapInFunction(CompoundAssign(Source{{56, 78}}, "a", 1_i, ast::BinaryOp::kAdd)); WrapInFunction(CompoundAssign(Source{{56, 78}}, "a", 1_i, ast::BinaryOp::kAdd));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -264,7 +264,7 @@ TEST_F(ResolverCompoundAssignmentValidationTest, LhsLiteral) {
TEST_F(ResolverCompoundAssignmentValidationTest, LhsAtomic) { TEST_F(ResolverCompoundAssignmentValidationTest, LhsAtomic) {
// var<workgroup> a : atomic<i32>; // var<workgroup> a : atomic<i32>;
// a += a; // a += a;
GlobalVar(Source{{12, 34}}, "a", ty.atomic(ty.i32()), type::AddressSpace::kWorkgroup); GlobalVar(Source{{12, 34}}, "a", ty.atomic(ty.i32()), builtin::AddressSpace::kWorkgroup);
WrapInFunction(CompoundAssign(Source{{56, 78}}, "a", "a", ast::BinaryOp::kAdd)); WrapInFunction(CompoundAssign(Source{{56, 78}}, "a", "a", ast::BinaryOp::kAdd));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());

View File

@ -84,7 +84,7 @@ TEST_F(ResolverConstAssertTest, Local_Const_Fail) {
} }
TEST_F(ResolverConstAssertTest, Local_NonConst) { TEST_F(ResolverConstAssertTest, Local_NonConst) {
GlobalVar("V", ty.bool_(), Expr(true), type::AddressSpace::kPrivate); GlobalVar("V", ty.bool_(), Expr(true), builtin::AddressSpace::kPrivate);
WrapInFunction(ConstAssert(Expr(Source{{12, 34}}, "V"))); WrapInFunction(ConstAssert(Expr(Source{{12, 34}}, "V")));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),

View File

@ -279,7 +279,7 @@ TEST_F(ResolverConstEvalTest, Array_vec3_f32_Index_OOB_Low) {
TEST_F(ResolverConstEvalTest, RuntimeArray_vec3_f32_Index_OOB_Low) { TEST_F(ResolverConstEvalTest, RuntimeArray_vec3_f32_Index_OOB_Low) {
auto* sb = GlobalVar("sb", ty.array(ty.vec3<f32>()), Group(0_a), Binding(0_a), auto* sb = GlobalVar("sb", ty.array(ty.vec3<f32>()), Group(0_a), Binding(0_a),
type::AddressSpace::kStorage); builtin::AddressSpace::kStorage);
auto* expr = IndexAccessor(sb, Expr(Source{{12, 34}}, -2_i)); auto* expr = IndexAccessor(sb, Expr(Source{{12, 34}}, -2_i));
WrapInFunction(expr); WrapInFunction(expr);

View File

@ -479,7 +479,8 @@ class DependencyScanner {
graph_.resolved_identifiers.Add(from, ResolvedIdentifier(builtin_ty)); graph_.resolved_identifiers.Add(from, ResolvedIdentifier(builtin_ty));
return; return;
} }
if (auto addr = type::ParseAddressSpace(s); addr != type::AddressSpace::kUndefined) { if (auto addr = builtin::ParseAddressSpace(s);
addr != builtin::AddressSpace::kUndefined) {
graph_.resolved_identifiers.Add(from, ResolvedIdentifier(addr)); graph_.resolved_identifiers.Add(from, ResolvedIdentifier(addr));
return; return;
} }
@ -864,7 +865,7 @@ std::string ResolvedIdentifier::String(const SymbolTable& symbols, diag::List& d
if (auto access = Access(); access != builtin::Access::kUndefined) { if (auto access = Access(); access != builtin::Access::kUndefined) {
return "access '" + utils::ToString(access) + "'"; return "access '" + utils::ToString(access) + "'";
} }
if (auto addr = AddressSpace(); addr != type::AddressSpace::kUndefined) { if (auto addr = AddressSpace(); addr != builtin::AddressSpace::kUndefined) {
return "address space '" + utils::ToString(addr) + "'"; return "address space '" + utils::ToString(addr) + "'";
} }
if (auto fmt = TexelFormat(); fmt != type::TexelFormat::kUndefined) { if (auto fmt = TexelFormat(); fmt != type::TexelFormat::kUndefined) {

View File

@ -36,7 +36,7 @@ namespace tint::resolver {
/// - const ast::Function* (as const ast::Node*) /// - const ast::Function* (as const ast::Node*)
/// - sem::BuiltinType /// - sem::BuiltinType
/// - builtin::Access /// - builtin::Access
/// - type::AddressSpace /// - builtin::AddressSpace
/// - type::Builtin /// - type::Builtin
/// - type::TexelFormat /// - type::TexelFormat
class ResolvedIdentifier { class ResolvedIdentifier {
@ -77,13 +77,13 @@ class ResolvedIdentifier {
return builtin::Access::kUndefined; return builtin::Access::kUndefined;
} }
/// @return the address space if the ResolvedIdentifier holds type::AddressSpace, otherwise /// @return the address space if the ResolvedIdentifier holds builtin::AddressSpace, otherwise
/// type::AddressSpace::kUndefined /// builtin::AddressSpace::kUndefined
type::AddressSpace AddressSpace() const { builtin::AddressSpace AddressSpace() const {
if (auto n = std::get_if<type::AddressSpace>(&value_)) { if (auto n = std::get_if<builtin::AddressSpace>(&value_)) {
return *n; return *n;
} }
return type::AddressSpace::kUndefined; return builtin::AddressSpace::kUndefined;
} }
/// @return the builtin type if the ResolvedIdentifier holds type::Builtin, otherwise /// @return the builtin type if the ResolvedIdentifier holds type::Builtin, otherwise
@ -131,7 +131,7 @@ class ResolvedIdentifier {
const ast::Node*, const ast::Node*,
sem::BuiltinType, sem::BuiltinType,
builtin::Access, builtin::Access,
type::AddressSpace, builtin::AddressSpace,
type::Builtin, type::Builtin,
type::TexelFormat> type::TexelFormat>
value_; value_;

View File

@ -17,6 +17,7 @@
#include <utility> #include <utility>
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "src/tint/builtin/address_space.h"
#include "src/tint/resolver/dependency_graph.h" #include "src/tint/resolver/dependency_graph.h"
#include "src/tint/resolver/resolver_test_helper.h" #include "src/tint/resolver/resolver_test_helper.h"
#include "src/tint/type/texture_dimension.h" #include "src/tint/type/texture_dimension.h"
@ -425,7 +426,7 @@ const ast::Node* SymbolTestHelper::Add(SymbolDeclKind kind, Symbol symbol, Sourc
auto& b = *builder; auto& b = *builder;
switch (kind) { switch (kind) {
case SymbolDeclKind::GlobalVar: case SymbolDeclKind::GlobalVar:
return b.GlobalVar(source, symbol, b.ty.i32(), type::AddressSpace::kPrivate); return b.GlobalVar(source, symbol, b.ty.i32(), builtin::AddressSpace::kPrivate);
case SymbolDeclKind::GlobalConst: case SymbolDeclKind::GlobalConst:
return b.GlobalConst(source, symbol, b.ty.i32(), b.Expr(1_i)); return b.GlobalConst(source, symbol, b.ty.i32(), b.Expr(1_i));
case SymbolDeclKind::Alias: case SymbolDeclKind::Alias:
@ -470,27 +471,27 @@ const ast::Identifier* SymbolTestHelper::Add(SymbolUseKind kind,
switch (kind) { switch (kind) {
case SymbolUseKind::GlobalVarType: { case SymbolUseKind::GlobalVarType: {
auto node = b.ty(source, symbol); auto node = b.ty(source, symbol);
b.GlobalVar(b.Sym(), node, type::AddressSpace::kPrivate); b.GlobalVar(b.Sym(), node, builtin::AddressSpace::kPrivate);
return node->identifier; return node->identifier;
} }
case SymbolUseKind::GlobalVarArrayElemType: { case SymbolUseKind::GlobalVarArrayElemType: {
auto node = b.ty(source, symbol); auto node = b.ty(source, symbol);
b.GlobalVar(b.Sym(), b.ty.array(node, 4_i), type::AddressSpace::kPrivate); b.GlobalVar(b.Sym(), b.ty.array(node, 4_i), builtin::AddressSpace::kPrivate);
return node->identifier; return node->identifier;
} }
case SymbolUseKind::GlobalVarArraySizeValue: { case SymbolUseKind::GlobalVarArraySizeValue: {
auto* node = b.Expr(source, symbol); auto* node = b.Expr(source, symbol);
b.GlobalVar(b.Sym(), b.ty.array(b.ty.i32(), node), type::AddressSpace::kPrivate); b.GlobalVar(b.Sym(), b.ty.array(b.ty.i32(), node), builtin::AddressSpace::kPrivate);
return node->identifier; return node->identifier;
} }
case SymbolUseKind::GlobalVarVectorElemType: { case SymbolUseKind::GlobalVarVectorElemType: {
auto node = b.ty(source, symbol); auto node = b.ty(source, symbol);
b.GlobalVar(b.Sym(), b.ty.vec3(node), type::AddressSpace::kPrivate); b.GlobalVar(b.Sym(), b.ty.vec3(node), builtin::AddressSpace::kPrivate);
return node->identifier; return node->identifier;
} }
case SymbolUseKind::GlobalVarMatrixElemType: { case SymbolUseKind::GlobalVarMatrixElemType: {
ast::Type node = b.ty(source, symbol); ast::Type node = b.ty(source, symbol);
b.GlobalVar(b.Sym(), b.ty.mat3x4(node), type::AddressSpace::kPrivate); b.GlobalVar(b.Sym(), b.ty.mat3x4(node), builtin::AddressSpace::kPrivate);
return node->identifier; return node->identifier;
} }
case SymbolUseKind::GlobalVarSampledTexElemType: { case SymbolUseKind::GlobalVarSampledTexElemType: {
@ -505,7 +506,7 @@ const ast::Identifier* SymbolTestHelper::Add(SymbolUseKind kind,
} }
case SymbolUseKind::GlobalVarValue: { case SymbolUseKind::GlobalVarValue: {
auto* node = b.Expr(source, symbol); auto* node = b.Expr(source, symbol);
b.GlobalVar(b.Sym(), b.ty.i32(), type::AddressSpace::kPrivate, node); b.GlobalVar(b.Sym(), b.ty.i32(), builtin::AddressSpace::kPrivate, node);
return node->identifier; return node->identifier;
} }
case SymbolUseKind::GlobalConstType: { case SymbolUseKind::GlobalConstType: {
@ -726,7 +727,7 @@ TEST_F(ResolverDependencyGraphUsedBeforeDeclTest, VarUsed) {
Block(Assign(Expr(Source{{12, 34}}, "G"), 3.14_f)), Block(Assign(Expr(Source{{12, 34}}, "G"), 3.14_f)),
}); });
GlobalVar(Source{{56, 78}}, "G", ty.f32(), type::AddressSpace::kPrivate, Expr(2.1_f)); GlobalVar(Source{{56, 78}}, "G", ty.f32(), builtin::AddressSpace::kPrivate, Expr(2.1_f));
Build(); Build();
} }
@ -1268,7 +1269,7 @@ TEST_P(ResolverDependencyGraphResolveToBuiltinType, ShadowedByGlobalVar) {
const auto symbol = Symbols().New(name); const auto symbol = Symbols().New(name);
auto* decl = auto* decl =
GlobalVar(symbol, name == "i32" ? ty.u32() : ty.i32(), type::AddressSpace::kPrivate); GlobalVar(symbol, name == "i32" ? ty.u32() : ty.i32(), builtin::AddressSpace::kPrivate);
SymbolTestHelper helper(this); SymbolTestHelper helper(this);
auto* ident = helper.Add(use, symbol); auto* ident = helper.Add(use, symbol);
@ -1415,7 +1416,7 @@ INSTANTIATE_TEST_SUITE_P(Functions,
} // namespace resolve_to_access } // namespace resolve_to_access
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Resolve to type::AddressSpace tests // Resolve to builtin::AddressSpace tests
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
namespace resolve_to_address_space { namespace resolve_to_address_space {
@ -1433,7 +1434,7 @@ TEST_P(ResolverDependencyGraphResolveToAddressSpace, Resolve) {
auto resolved = Build().resolved_identifiers.Get(ident); auto resolved = Build().resolved_identifiers.Get(ident);
ASSERT_TRUE(resolved); ASSERT_TRUE(resolved);
EXPECT_EQ(resolved->AddressSpace(), type::ParseAddressSpace(name)) EXPECT_EQ(resolved->AddressSpace(), builtin::ParseAddressSpace(name))
<< resolved->String(Symbols(), Diagnostics()); << resolved->String(Symbols(), Diagnostics());
} }
@ -1485,17 +1486,17 @@ TEST_P(ResolverDependencyGraphResolveToAddressSpace, ShadowedByFunc) {
INSTANTIATE_TEST_SUITE_P(Types, INSTANTIATE_TEST_SUITE_P(Types,
ResolverDependencyGraphResolveToAddressSpace, ResolverDependencyGraphResolveToAddressSpace,
testing::Combine(testing::ValuesIn(kTypeUseKinds), testing::Combine(testing::ValuesIn(kTypeUseKinds),
testing::ValuesIn(type::kAddressSpaceStrings))); testing::ValuesIn(builtin::kAddressSpaceStrings)));
INSTANTIATE_TEST_SUITE_P(Values, INSTANTIATE_TEST_SUITE_P(Values,
ResolverDependencyGraphResolveToAddressSpace, ResolverDependencyGraphResolveToAddressSpace,
testing::Combine(testing::ValuesIn(kValueUseKinds), testing::Combine(testing::ValuesIn(kValueUseKinds),
testing::ValuesIn(type::kAddressSpaceStrings))); testing::ValuesIn(builtin::kAddressSpaceStrings)));
INSTANTIATE_TEST_SUITE_P(Functions, INSTANTIATE_TEST_SUITE_P(Functions,
ResolverDependencyGraphResolveToAddressSpace, ResolverDependencyGraphResolveToAddressSpace,
testing::Combine(testing::ValuesIn(kFuncUseKinds), testing::Combine(testing::ValuesIn(kFuncUseKinds),
testing::ValuesIn(type::kAddressSpaceStrings))); testing::ValuesIn(builtin::kAddressSpaceStrings)));
} // namespace resolve_to_address_space } // namespace resolve_to_address_space
@ -1649,7 +1650,7 @@ TEST_F(ResolverDependencyGraphTraversalTest, SymbolsReached) {
const auto type_sym = Sym("TYPE"); const auto type_sym = Sym("TYPE");
const auto func_sym = Sym("FUNC"); const auto func_sym = Sym("FUNC");
const auto* value_decl = GlobalVar(value_sym, ty.i32(), type::AddressSpace::kPrivate); const auto* value_decl = GlobalVar(value_sym, ty.i32(), builtin::AddressSpace::kPrivate);
const auto* type_decl = Alias(type_sym, ty.i32()); const auto* type_decl = Alias(type_sym, ty.i32());
const auto* func_decl = Func(func_sym, utils::Empty, ty.void_(), utils::Empty); const auto* func_decl = Func(func_sym, utils::Empty, ty.void_(), utils::Empty);
@ -1728,7 +1729,7 @@ TEST_F(ResolverDependencyGraphTraversalTest, SymbolsReached) {
GlobalVar(Sym(), ty.array(T, V)); GlobalVar(Sym(), ty.array(T, V));
GlobalVar(Sym(), ty.vec3(T)); GlobalVar(Sym(), ty.vec3(T));
GlobalVar(Sym(), ty.mat3x2(T)); GlobalVar(Sym(), ty.mat3x2(T));
GlobalVar(Sym(), ty.pointer(T, type::AddressSpace::kPrivate)); GlobalVar(Sym(), ty.pointer(T, builtin::AddressSpace::kPrivate));
GlobalVar(Sym(), ty.sampled_texture(type::TextureDimension::k2d, T)); GlobalVar(Sym(), ty.sampled_texture(type::TextureDimension::k2d, T));
GlobalVar(Sym(), ty.depth_texture(type::TextureDimension::k2d)); GlobalVar(Sym(), ty.depth_texture(type::TextureDimension::k2d));
GlobalVar(Sym(), ty.depth_multisampled_texture(type::TextureDimension::k2d)); GlobalVar(Sym(), ty.depth_multisampled_texture(type::TextureDimension::k2d));

View File

@ -456,14 +456,14 @@ TEST_F(ResolverEntryPointValidationTest, PushConstantAllowedWithEnable) {
// enable chromium_experimental_push_constant; // enable chromium_experimental_push_constant;
// var<push_constant> a : u32; // var<push_constant> a : u32;
Enable(builtin::Extension::kChromiumExperimentalPushConstant); Enable(builtin::Extension::kChromiumExperimentalPushConstant);
GlobalVar("a", ty.u32(), type::AddressSpace::kPushConstant); GlobalVar("a", ty.u32(), builtin::AddressSpace::kPushConstant);
EXPECT_TRUE(r()->Resolve()); EXPECT_TRUE(r()->Resolve());
} }
TEST_F(ResolverEntryPointValidationTest, PushConstantDisallowedWithoutEnable) { TEST_F(ResolverEntryPointValidationTest, PushConstantDisallowedWithoutEnable) {
// var<push_constant> a : u32; // var<push_constant> a : u32;
GlobalVar(Source{{1, 2}}, "a", ty.u32(), type::AddressSpace::kPushConstant); GlobalVar(Source{{1, 2}}, "a", ty.u32(), builtin::AddressSpace::kPushConstant);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -473,7 +473,7 @@ TEST_F(ResolverEntryPointValidationTest, PushConstantDisallowedWithoutEnable) {
TEST_F(ResolverEntryPointValidationTest, PushConstantAllowedWithIgnoreAddressSpaceAttribute) { TEST_F(ResolverEntryPointValidationTest, PushConstantAllowedWithIgnoreAddressSpaceAttribute) {
// var<push_constant> a : u32; // With ast::DisabledValidation::kIgnoreAddressSpace // var<push_constant> a : u32; // With ast::DisabledValidation::kIgnoreAddressSpace
GlobalVar("a", ty.u32(), type::AddressSpace::kPushConstant, GlobalVar("a", ty.u32(), builtin::AddressSpace::kPushConstant,
utils::Vector{Disable(ast::DisabledValidation::kIgnoreAddressSpace)}); utils::Vector{Disable(ast::DisabledValidation::kIgnoreAddressSpace)});
EXPECT_TRUE(r()->Resolve()); EXPECT_TRUE(r()->Resolve());
@ -486,7 +486,7 @@ TEST_F(ResolverEntryPointValidationTest, PushConstantOneVariableUsedInEntryPoint
// _ = a; // _ = a;
// } // }
Enable(builtin::Extension::kChromiumExperimentalPushConstant); Enable(builtin::Extension::kChromiumExperimentalPushConstant);
GlobalVar("a", ty.u32(), type::AddressSpace::kPushConstant); GlobalVar("a", ty.u32(), builtin::AddressSpace::kPushConstant);
Func("main", {}, ty.void_(), utils::Vector{Assign(Phony(), "a")}, Func("main", {}, ty.void_(), utils::Vector{Assign(Phony(), "a")},
utils::Vector{Stage(ast::PipelineStage::kCompute), utils::Vector{Stage(ast::PipelineStage::kCompute),
@ -504,8 +504,8 @@ TEST_F(ResolverEntryPointValidationTest, PushConstantTwoVariablesUsedInEntryPoin
// _ = b; // _ = b;
// } // }
Enable(builtin::Extension::kChromiumExperimentalPushConstant); Enable(builtin::Extension::kChromiumExperimentalPushConstant);
GlobalVar(Source{{1, 2}}, "a", ty.u32(), type::AddressSpace::kPushConstant); GlobalVar(Source{{1, 2}}, "a", ty.u32(), builtin::AddressSpace::kPushConstant);
GlobalVar(Source{{3, 4}}, "b", ty.u32(), type::AddressSpace::kPushConstant); GlobalVar(Source{{3, 4}}, "b", ty.u32(), builtin::AddressSpace::kPushConstant);
Func(Source{{5, 6}}, "main", {}, ty.void_(), Func(Source{{5, 6}}, "main", {}, ty.void_(),
utils::Vector{Assign(Phony(), "a"), Assign(Phony(), "b")}, utils::Vector{Assign(Phony(), "a"), Assign(Phony(), "b")},
@ -535,8 +535,8 @@ TEST_F(ResolverEntryPointValidationTest,
// uses_b(); // uses_b();
// } // }
Enable(builtin::Extension::kChromiumExperimentalPushConstant); Enable(builtin::Extension::kChromiumExperimentalPushConstant);
GlobalVar(Source{{1, 2}}, "a", ty.u32(), type::AddressSpace::kPushConstant); GlobalVar(Source{{1, 2}}, "a", ty.u32(), builtin::AddressSpace::kPushConstant);
GlobalVar(Source{{3, 4}}, "b", ty.u32(), type::AddressSpace::kPushConstant); GlobalVar(Source{{3, 4}}, "b", ty.u32(), builtin::AddressSpace::kPushConstant);
Func(Source{{5, 6}}, "uses_a", {}, ty.void_(), utils::Vector{Assign(Phony(), "a")}); Func(Source{{5, 6}}, "uses_a", {}, ty.void_(), utils::Vector{Assign(Phony(), "a")});
Func(Source{{7, 8}}, "uses_b", {}, ty.void_(), utils::Vector{Assign(Phony(), "b")}); Func(Source{{7, 8}}, "uses_b", {}, ty.void_(), utils::Vector{Assign(Phony(), "b")});
@ -568,8 +568,8 @@ TEST_F(ResolverEntryPointValidationTest, PushConstantTwoVariablesUsedInDifferent
// _ = a; // _ = a;
// } // }
Enable(builtin::Extension::kChromiumExperimentalPushConstant); Enable(builtin::Extension::kChromiumExperimentalPushConstant);
GlobalVar("a", ty.u32(), type::AddressSpace::kPushConstant); GlobalVar("a", ty.u32(), builtin::AddressSpace::kPushConstant);
GlobalVar("b", ty.u32(), type::AddressSpace::kPushConstant); GlobalVar("b", ty.u32(), builtin::AddressSpace::kPushConstant);
Func("uses_a", {}, ty.void_(), utils::Vector{Assign(Phony(), "a")}, Func("uses_a", {}, ty.void_(), utils::Vector{Assign(Phony(), "a")},
utils::Vector{Stage(ast::PipelineStage::kCompute), utils::Vector{Stage(ast::PipelineStage::kCompute),

View File

@ -135,9 +135,9 @@ TEST_P(ResolverExpressionKindTest, Test) {
sym = Sym("workgroup"); sym = Sym("workgroup");
check_expr = [](const sem::Expression* expr) { check_expr = [](const sem::Expression* expr) {
ASSERT_NE(expr, nullptr); ASSERT_NE(expr, nullptr);
auto* enum_expr = expr->As<sem::BuiltinEnumExpression<type::AddressSpace>>(); auto* enum_expr = expr->As<sem::BuiltinEnumExpression<builtin::AddressSpace>>();
ASSERT_NE(enum_expr, nullptr); ASSERT_NE(enum_expr, nullptr);
EXPECT_EQ(enum_expr->Value(), type::AddressSpace::kWorkgroup); EXPECT_EQ(enum_expr->Value(), builtin::AddressSpace::kWorkgroup);
}; };
break; break;
} }
@ -231,7 +231,7 @@ TEST_P(ResolverExpressionKindTest, Test) {
Func("f", utils::Empty, ty.void_(), CallStmt(Call(expr))); Func("f", utils::Empty, ty.void_(), CallStmt(Call(expr)));
break; break;
case Use::kBinaryOp: case Use::kBinaryOp:
GlobalVar("v", type::AddressSpace::kPrivate, Mul(1_a, expr)); GlobalVar("v", builtin::AddressSpace::kPrivate, Mul(1_a, expr));
break; break;
case Use::kFunctionReturnType: case Use::kFunctionReturnType:
Func("f", utils::Empty, ty(expr), Return(Call(sym))); Func("f", utils::Empty, ty(expr), Return(Call(sym)));
@ -243,13 +243,13 @@ TEST_P(ResolverExpressionKindTest, Test) {
GlobalVar("v", ty("texture_storage_2d", ty(expr), "write"), Group(0_u), Binding(0_u)); GlobalVar("v", ty("texture_storage_2d", ty(expr), "write"), Group(0_u), Binding(0_u));
break; break;
case Use::kValueExpression: case Use::kValueExpression:
GlobalVar("v", type::AddressSpace::kPrivate, expr); GlobalVar("v", builtin::AddressSpace::kPrivate, expr);
break; break;
case Use::kVariableType: case Use::kVariableType:
GlobalVar("v", type::AddressSpace::kPrivate, ty(expr)); GlobalVar("v", builtin::AddressSpace::kPrivate, ty(expr));
break; break;
case Use::kUnaryOp: case Use::kUnaryOp:
GlobalVar("v", type::AddressSpace::kPrivate, Negation(expr)); GlobalVar("v", builtin::AddressSpace::kPrivate, Negation(expr));
break; break;
} }

View File

@ -29,14 +29,14 @@ TEST_F(ResolverF16ExtensionTest, TypeUsedWithExtension) {
// var<private> v : f16; // var<private> v : f16;
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
GlobalVar("v", ty.f16(), type::AddressSpace::kPrivate); GlobalVar("v", ty.f16(), builtin::AddressSpace::kPrivate);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverF16ExtensionTest, TypeUsedWithoutExtension) { TEST_F(ResolverF16ExtensionTest, TypeUsedWithoutExtension) {
// var<private> v : f16; // var<private> v : f16;
GlobalVar("v", ty.f16(Source{{12, 34}}), type::AddressSpace::kPrivate); GlobalVar("v", ty.f16(Source{{12, 34}}), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: f16 type used without 'f16' extension enabled"); EXPECT_EQ(r()->error(), "12:34 error: f16 type used without 'f16' extension enabled");
@ -47,14 +47,14 @@ TEST_F(ResolverF16ExtensionTest, Vec2TypeUsedWithExtension) {
// var<private> v : vec2<f16>; // var<private> v : vec2<f16>;
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
GlobalVar("v", ty.vec2<f16>(), type::AddressSpace::kPrivate); GlobalVar("v", ty.vec2<f16>(), builtin::AddressSpace::kPrivate);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverF16ExtensionTest, Vec2TypeUsedWithoutExtension) { TEST_F(ResolverF16ExtensionTest, Vec2TypeUsedWithoutExtension) {
// var<private> v : vec2<f16>; // var<private> v : vec2<f16>;
GlobalVar("v", ty.vec2(ty.f16(Source{{12, 34}})), type::AddressSpace::kPrivate); GlobalVar("v", ty.vec2(ty.f16(Source{{12, 34}})), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: f16 type used without 'f16' extension enabled"); EXPECT_EQ(r()->error(), "12:34 error: f16 type used without 'f16' extension enabled");
@ -65,14 +65,14 @@ TEST_F(ResolverF16ExtensionTest, Vec2TypeInitUsedWithExtension) {
// var<private> v = vec2<f16>(); // var<private> v = vec2<f16>();
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
GlobalVar("v", vec2<f16>(), type::AddressSpace::kPrivate); GlobalVar("v", vec2<f16>(), builtin::AddressSpace::kPrivate);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverF16ExtensionTest, Vec2TypeInitUsedWithoutExtension) { TEST_F(ResolverF16ExtensionTest, Vec2TypeInitUsedWithoutExtension) {
// var<private> v = vec2<f16>(); // var<private> v = vec2<f16>();
GlobalVar("v", Call(ty.vec2(ty.f16(Source{{12, 34}}))), type::AddressSpace::kPrivate); GlobalVar("v", Call(ty.vec2(ty.f16(Source{{12, 34}}))), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: f16 type used without 'f16' extension enabled"); EXPECT_EQ(r()->error(), "12:34 error: f16 type used without 'f16' extension enabled");
@ -83,14 +83,14 @@ TEST_F(ResolverF16ExtensionTest, Vec2TypeConvUsedWithExtension) {
// var<private> v = vec2<f16>(vec2<f32>()); // var<private> v = vec2<f16>(vec2<f32>());
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
GlobalVar("v", vec2<f16>(vec2<f32>()), type::AddressSpace::kPrivate); GlobalVar("v", vec2<f16>(vec2<f32>()), builtin::AddressSpace::kPrivate);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverF16ExtensionTest, Vec2TypeConvUsedWithoutExtension) { TEST_F(ResolverF16ExtensionTest, Vec2TypeConvUsedWithoutExtension) {
// var<private> v = vec2<f16>(vec2<f32>()); // var<private> v = vec2<f16>(vec2<f32>());
GlobalVar("v", vec2(ty.f16(Source{{12, 34}}), vec2<f32>()), type::AddressSpace::kPrivate); GlobalVar("v", vec2(ty.f16(Source{{12, 34}}), vec2<f32>()), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: f16 type used without 'f16' extension enabled"); EXPECT_EQ(r()->error(), "12:34 error: f16 type used without 'f16' extension enabled");
@ -101,14 +101,14 @@ TEST_F(ResolverF16ExtensionTest, F16LiteralUsedWithExtension) {
// var<private> v = 16h; // var<private> v = 16h;
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
GlobalVar("v", Expr(16_h), type::AddressSpace::kPrivate); GlobalVar("v", Expr(16_h), builtin::AddressSpace::kPrivate);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverF16ExtensionTest, F16LiteralUsedWithoutExtension) { TEST_F(ResolverF16ExtensionTest, F16LiteralUsedWithoutExtension) {
// var<private> v = 16h; // var<private> v = 16h;
GlobalVar("v", Expr(Source{{12, 34}}, 16_h), type::AddressSpace::kPrivate); GlobalVar("v", Expr(Source{{12, 34}}, 16_h), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: f16 type used without 'f16' extension enabled"); EXPECT_EQ(r()->error(), "12:34 error: f16 type used without 'f16' extension enabled");
@ -121,14 +121,14 @@ TEST_P(ResolverF16ExtensionBuiltinTypeAliasTest, Vec2hTypeUsedWithExtension) {
// var<private> v : vec2h; // var<private> v : vec2h;
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
GlobalVar("v", ty(Source{{12, 34}}, GetParam()), type::AddressSpace::kPrivate); GlobalVar("v", ty(Source{{12, 34}}, GetParam()), builtin::AddressSpace::kPrivate);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_P(ResolverF16ExtensionBuiltinTypeAliasTest, Vec2hTypeUsedWithoutExtension) { TEST_P(ResolverF16ExtensionBuiltinTypeAliasTest, Vec2hTypeUsedWithoutExtension) {
// var<private> v : vec2h; // var<private> v : vec2h;
GlobalVar("v", ty(Source{{12, 34}}, GetParam()), type::AddressSpace::kPrivate); GlobalVar("v", ty(Source{{12, 34}}, GetParam()), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: f16 type used without 'f16' extension enabled"); EXPECT_EQ(r()->error(), "12:34 error: f16 type used without 'f16' extension enabled");

View File

@ -39,7 +39,7 @@ TEST_F(ResolverFunctionValidationTest, DuplicateParameterName) {
TEST_F(ResolverFunctionValidationTest, ParameterMayShadowGlobal) { TEST_F(ResolverFunctionValidationTest, ParameterMayShadowGlobal) {
// var<private> common_name : f32; // var<private> common_name : f32;
// fn func(common_name : f32) { } // fn func(common_name : f32) { }
GlobalVar("common_name", ty.f32(), type::AddressSpace::kPrivate); GlobalVar("common_name", ty.f32(), builtin::AddressSpace::kPrivate);
Func("func", utils::Vector{Param("common_name", ty.f32())}, ty.void_(), utils::Empty); Func("func", utils::Vector{Param("common_name", ty.f32())}, ty.void_(), utils::Empty);
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -420,7 +420,7 @@ TEST_F(ResolverFunctionValidationTest, CannotCallFunctionAtModuleScope) {
utils::Vector{ utils::Vector{
Return(1_i), Return(1_i),
}); });
GlobalVar("x", Call(Source{{12, 34}}, "F"), type::AddressSpace::kPrivate); GlobalVar("x", Call(Source{{12, 34}}, "F"), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), R"(12:34 error: functions cannot be called at module-scope)"); EXPECT_EQ(r()->error(), R"(12:34 error: functions cannot be called at module-scope)");
@ -874,7 +874,7 @@ TEST_F(ResolverFunctionValidationTest, WorkgroupSize_NonConst) {
// var<private> x = 64i; // var<private> x = 64i;
// @compute @workgroup_size(x) // @compute @workgroup_size(x)
// fn main() {} // fn main() {}
GlobalVar("x", ty.i32(), type::AddressSpace::kPrivate, Expr(64_i)); GlobalVar("x", ty.i32(), builtin::AddressSpace::kPrivate, Expr(64_i));
Func("main", utils::Empty, ty.void_(), utils::Empty, Func("main", utils::Empty, ty.void_(), utils::Empty,
utils::Vector{ utils::Vector{
Stage(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
@ -890,7 +890,7 @@ TEST_F(ResolverFunctionValidationTest, WorkgroupSize_NonConst) {
TEST_F(ResolverFunctionValidationTest, WorkgroupSize_InvalidExpr_x) { TEST_F(ResolverFunctionValidationTest, WorkgroupSize_InvalidExpr_x) {
// @compute @workgroup_size(1 << 2 + 4) // @compute @workgroup_size(1 << 2 + 4)
// fn main() {} // fn main() {}
GlobalVar("x", ty.i32(), type::AddressSpace::kPrivate, Expr(0_i)); GlobalVar("x", ty.i32(), builtin::AddressSpace::kPrivate, Expr(0_i));
Func("main", utils::Empty, ty.void_(), utils::Empty, Func("main", utils::Empty, ty.void_(), utils::Empty,
utils::Vector{ utils::Vector{
Stage(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
@ -906,7 +906,7 @@ TEST_F(ResolverFunctionValidationTest, WorkgroupSize_InvalidExpr_x) {
TEST_F(ResolverFunctionValidationTest, WorkgroupSize_InvalidExpr_y) { TEST_F(ResolverFunctionValidationTest, WorkgroupSize_InvalidExpr_y) {
// @compute @workgroup_size(1, 1 << 2 + 4) // @compute @workgroup_size(1, 1 << 2 + 4)
// fn main() {} // fn main() {}
GlobalVar("x", ty.i32(), type::AddressSpace::kPrivate, Expr(0_i)); GlobalVar("x", ty.i32(), builtin::AddressSpace::kPrivate, Expr(0_i));
Func("main", utils::Empty, ty.void_(), utils::Empty, Func("main", utils::Empty, ty.void_(), utils::Empty,
utils::Vector{ utils::Vector{
Stage(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
@ -922,7 +922,7 @@ TEST_F(ResolverFunctionValidationTest, WorkgroupSize_InvalidExpr_y) {
TEST_F(ResolverFunctionValidationTest, WorkgroupSize_InvalidExpr_z) { TEST_F(ResolverFunctionValidationTest, WorkgroupSize_InvalidExpr_z) {
// @compute @workgroup_size(1, 1, 1 << 2 + 4) // @compute @workgroup_size(1, 1, 1 << 2 + 4)
// fn main() {} // fn main() {}
GlobalVar("x", ty.i32(), type::AddressSpace::kPrivate, Expr(0_i)); GlobalVar("x", ty.i32(), builtin::AddressSpace::kPrivate, Expr(0_i));
Func("main", utils::Empty, ty.void_(), utils::Empty, Func("main", utils::Empty, ty.void_(), utils::Empty,
utils::Vector{ utils::Vector{
Stage(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
@ -936,7 +936,7 @@ TEST_F(ResolverFunctionValidationTest, WorkgroupSize_InvalidExpr_z) {
} }
TEST_F(ResolverFunctionValidationTest, ReturnIsConstructible_NonPlain) { TEST_F(ResolverFunctionValidationTest, ReturnIsConstructible_NonPlain) {
auto ret_type = ty.pointer(Source{{12, 34}}, ty.i32(), type::AddressSpace::kFunction); auto ret_type = ty.pointer(Source{{12, 34}}, ty.i32(), builtin::AddressSpace::kFunction);
Func("f", utils::Empty, ret_type, utils::Empty); Func("f", utils::Empty, ret_type, utils::Empty);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1049,7 +1049,7 @@ enum class Expectation {
kInvalid, kInvalid,
}; };
struct TestParams { struct TestParams {
type::AddressSpace address_space; builtin::AddressSpace address_space;
Expectation expectation; Expectation expectation;
}; };
@ -1102,16 +1102,18 @@ TEST_P(ResolverFunctionParameterValidationTest, AddressSpaceWithExtension) {
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
ResolverTest, ResolverTest,
ResolverFunctionParameterValidationTest, ResolverFunctionParameterValidationTest,
testing::Values( testing::Values(TestParams{builtin::AddressSpace::kUndefined, Expectation::kInvalid},
TestParams{type::AddressSpace::kUndefined, Expectation::kInvalid}, TestParams{builtin::AddressSpace::kIn, Expectation::kAlwaysFail},
TestParams{type::AddressSpace::kIn, Expectation::kAlwaysFail}, TestParams{builtin::AddressSpace::kOut, Expectation::kAlwaysFail},
TestParams{type::AddressSpace::kOut, Expectation::kAlwaysFail}, TestParams{builtin::AddressSpace::kUniform,
TestParams{type::AddressSpace::kUniform, Expectation::kPassWithFullPtrParameterExtension}, Expectation::kPassWithFullPtrParameterExtension},
TestParams{type::AddressSpace::kWorkgroup, Expectation::kPassWithFullPtrParameterExtension}, TestParams{builtin::AddressSpace::kWorkgroup,
TestParams{type::AddressSpace::kHandle, Expectation::kInvalid}, Expectation::kPassWithFullPtrParameterExtension},
TestParams{type::AddressSpace::kStorage, Expectation::kPassWithFullPtrParameterExtension}, TestParams{builtin::AddressSpace::kHandle, Expectation::kInvalid},
TestParams{type::AddressSpace::kPrivate, Expectation::kAlwaysPass}, TestParams{builtin::AddressSpace::kStorage,
TestParams{type::AddressSpace::kFunction, Expectation::kAlwaysPass})); Expectation::kPassWithFullPtrParameterExtension},
TestParams{builtin::AddressSpace::kPrivate, Expectation::kAlwaysPass},
TestParams{builtin::AddressSpace::kFunction, Expectation::kAlwaysPass}));
} // namespace } // namespace
} // namespace tint::resolver } // namespace tint::resolver

View File

@ -29,8 +29,8 @@ TEST_F(ResolverHostShareableValidationTest, BoolMember) {
auto* s = auto* s =
Structure("S", utils::Vector{Member(Source{{56, 78}}, "x", ty.bool_(Source{{12, 34}}))}); Structure("S", utils::Vector{Member(Source{{56, 78}}, "x", ty.bool_(Source{{12, 34}}))});
GlobalVar(Source{{90, 12}}, "g", ty.Of(s), type::AddressSpace::kStorage, builtin::Access::kRead, GlobalVar(Source{{90, 12}}, "g", ty.Of(s), builtin::AddressSpace::kStorage,
Binding(0_a), Group(0_a)); builtin::Access::kRead, Binding(0_a), Group(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -45,8 +45,8 @@ TEST_F(ResolverHostShareableValidationTest, BoolVectorMember) {
auto* s = Structure( auto* s = Structure(
"S", utils::Vector{Member(Source{{56, 78}}, "x", ty.vec3<bool>(Source{{12, 34}}))}); "S", utils::Vector{Member(Source{{56, 78}}, "x", ty.vec3<bool>(Source{{12, 34}}))});
GlobalVar(Source{{90, 12}}, "g", ty.Of(s), type::AddressSpace::kStorage, builtin::Access::kRead, GlobalVar(Source{{90, 12}}, "g", ty.Of(s), builtin::AddressSpace::kStorage,
Binding(0_a), Group(0_a)); builtin::Access::kRead, Binding(0_a), Group(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -62,7 +62,7 @@ TEST_F(ResolverHostShareableValidationTest, Aliases) {
auto* s = auto* s =
Structure("S", utils::Vector{Member(Source{{56, 78}}, "x", ty(Source{{12, 34}}, "a1"))}); Structure("S", utils::Vector{Member(Source{{56, 78}}, "x", ty(Source{{12, 34}}, "a1"))});
auto* a2 = Alias("a2", ty.Of(s)); auto* a2 = Alias("a2", ty.Of(s));
GlobalVar(Source{{90, 12}}, "g", ty.Of(a2), type::AddressSpace::kStorage, GlobalVar(Source{{90, 12}}, "g", ty.Of(a2), builtin::AddressSpace::kStorage,
builtin::Access::kRead, Binding(0_a), Group(0_a)); builtin::Access::kRead, Binding(0_a), Group(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -81,8 +81,8 @@ TEST_F(ResolverHostShareableValidationTest, NestedStructures) {
auto* s = Structure("S", utils::Vector{Member(Source{{7, 8}}, "m", ty.Of(i3))}); auto* s = Structure("S", utils::Vector{Member(Source{{7, 8}}, "m", ty.Of(i3))});
GlobalVar(Source{{9, 10}}, "g", ty.Of(s), type::AddressSpace::kStorage, builtin::Access::kRead, GlobalVar(Source{{9, 10}}, "g", ty.Of(s), builtin::AddressSpace::kStorage,
Binding(0_a), Group(0_a)); builtin::Access::kRead, Binding(0_a), Group(0_a));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -120,8 +120,8 @@ TEST_F(ResolverHostShareableValidationTest, NoError) {
auto* s = Structure("S", utils::Vector{Member(Source{{7, 8}}, "m", ty.Of(i3))}); auto* s = Structure("S", utils::Vector{Member(Source{{7, 8}}, "m", ty.Of(i3))});
GlobalVar(Source{{9, 10}}, "g", ty.Of(s), type::AddressSpace::kStorage, builtin::Access::kRead, GlobalVar(Source{{9, 10}}, "g", ty.Of(s), builtin::AddressSpace::kStorage,
Binding(0_a), Group(0_a)); builtin::Access::kRead, Binding(0_a), Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
} }

View File

@ -64,8 +64,8 @@ TEST_F(ResolverIncrementDecrementValidationTest, ThroughPointer) {
// var a : i32; // var a : i32;
// let b : ptr<function,i32> = &a; // let b : ptr<function,i32> = &a;
// *b++; // *b++;
auto* var_a = Var("a", ty.i32(), type::AddressSpace::kFunction); auto* var_a = Var("a", ty.i32(), builtin::AddressSpace::kFunction);
auto* var_b = Let("b", ty.pointer<i32>(type::AddressSpace::kFunction), AddressOf(Expr("a"))); auto* var_b = Let("b", ty.pointer<i32>(builtin::AddressSpace::kFunction), 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();
@ -127,7 +127,7 @@ TEST_F(ResolverIncrementDecrementValidationTest, Vector) {
TEST_F(ResolverIncrementDecrementValidationTest, Atomic) { TEST_F(ResolverIncrementDecrementValidationTest, Atomic) {
// var<workgroup> a : atomic<i32>; // var<workgroup> a : atomic<i32>;
// a++; // a++;
GlobalVar(Source{{12, 34}}, "a", ty.atomic(ty.i32()), type::AddressSpace::kWorkgroup); GlobalVar(Source{{12, 34}}, "a", ty.atomic(ty.i32()), builtin::AddressSpace::kWorkgroup);
WrapInFunction(Increment(Expr(Source{{56, 78}}, "a"))); WrapInFunction(Increment(Expr(Source{{56, 78}}, "a")));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -193,8 +193,8 @@ TEST_F(ResolverIncrementDecrementValidationTest, ReadOnlyBuffer) {
// { // {
// a++; // a++;
// } // }
GlobalVar(Source{{12, 34}}, "a", ty.i32(), type::AddressSpace::kStorage, builtin::Access::kRead, GlobalVar(Source{{12, 34}}, "a", ty.i32(), builtin::AddressSpace::kStorage,
Group(0_a), Binding(0_a)); builtin::Access::kRead, Group(0_a), Binding(0_a));
WrapInFunction(Increment(Source{{56, 78}}, "a")); WrapInFunction(Increment(Source{{56, 78}}, "a"));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());

View File

@ -97,7 +97,7 @@ TEST_P(ResolverInferredTypeParamTest, GlobalVar_Pass) {
// var a = <type initializer>; // var a = <type initializer>;
auto* ctor_expr = params.create_value(*this, 0); auto* ctor_expr = params.create_value(*this, 0);
auto* var = GlobalVar("a", type::AddressSpace::kPrivate, ctor_expr); auto* var = GlobalVar("a", builtin::AddressSpace::kPrivate, ctor_expr);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_EQ(TypeOf(var)->UnwrapRef(), expected_type); EXPECT_EQ(TypeOf(var)->UnwrapRef(), expected_type);
@ -124,7 +124,7 @@ TEST_P(ResolverInferredTypeParamTest, LocalVar_Pass) {
// var a = <type initializer>; // var a = <type initializer>;
auto* ctor_expr = params.create_value(*this, 0); auto* ctor_expr = params.create_value(*this, 0);
auto* var = Var("a", type::AddressSpace::kFunction, ctor_expr); auto* var = Var("a", builtin::AddressSpace::kFunction, ctor_expr);
WrapInFunction(var); WrapInFunction(var);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -139,7 +139,7 @@ TEST_F(ResolverInferredTypeTest, InferArray_Pass) {
create<type::U32>(), create<type::ConstantArrayCount>(10u), 4u, 4u * 10u, 4u, 4u); create<type::U32>(), create<type::ConstantArrayCount>(10u), 4u, 4u * 10u, 4u, 4u);
auto* ctor_expr = Call(type); auto* ctor_expr = Call(type);
auto* var = Var("a", type::AddressSpace::kFunction, ctor_expr); auto* var = Var("a", builtin::AddressSpace::kFunction, ctor_expr);
WrapInFunction(var); WrapInFunction(var);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -158,7 +158,7 @@ TEST_F(ResolverInferredTypeTest, InferStruct_Pass) {
auto* ctor_expr = Call(ty.Of(str)); auto* ctor_expr = Call(ty.Of(str));
auto* var = Var("a", type::AddressSpace::kFunction, ctor_expr); auto* var = Var("a", builtin::AddressSpace::kFunction, ctor_expr);
WrapInFunction(var); WrapInFunction(var);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();

View File

@ -330,7 +330,7 @@ class TemplateNumberMatcher : public NumberMatcher {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
using TexelFormat = type::TexelFormat; using TexelFormat = type::TexelFormat;
using Access = builtin::Access; using Access = builtin::Access;
using AddressSpace = type::AddressSpace; using AddressSpace = builtin::AddressSpace;
using ParameterUsage = sem::ParameterUsage; using ParameterUsage = sem::ParameterUsage;
using PipelineStage = ast::PipelineStage; using PipelineStage = ast::PipelineStage;
@ -560,7 +560,7 @@ bool match_ptr(MatchState&, const type::Type* ty, Number& S, const type::Type*&
} }
const type::Pointer* build_ptr(MatchState& state, Number S, const type::Type* T, Number& A) { const type::Pointer* build_ptr(MatchState& state, Number S, const type::Type* T, Number& A) {
return state.builder.create<type::Pointer>(T, static_cast<type::AddressSpace>(S.Value()), return state.builder.create<type::Pointer>(T, static_cast<builtin::AddressSpace>(S.Value()),
static_cast<builtin::Access>(A.Value())); static_cast<builtin::Access>(A.Value()));
} }
@ -1276,7 +1276,7 @@ Impl::Builtin Impl::Lookup(sem::BuiltinType builtin_type,
for (auto& p : match.parameters) { for (auto& p : match.parameters) {
params.Push(builder.create<sem::Parameter>( params.Push(builder.create<sem::Parameter>(
nullptr, static_cast<uint32_t>(params.Length()), p.type, nullptr, static_cast<uint32_t>(params.Length()), p.type,
type::AddressSpace::kUndefined, builtin::Access::kUndefined, p.usage)); builtin::AddressSpace::kUndefined, builtin::Access::kUndefined, p.usage));
} }
sem::PipelineStageSet supported_stages; sem::PipelineStageSet supported_stages;
if (match.overload->flags.Contains(OverloadFlag::kSupportsVertexPipeline)) { if (match.overload->flags.Contains(OverloadFlag::kSupportsVertexPipeline)) {
@ -1477,7 +1477,7 @@ IntrinsicTable::InitOrConv Impl::Lookup(InitConvIntrinsic type,
for (auto& p : match.parameters) { for (auto& p : match.parameters) {
params.Push(builder.create<sem::Parameter>( params.Push(builder.create<sem::Parameter>(
nullptr, static_cast<uint32_t>(params.Length()), p.type, nullptr, static_cast<uint32_t>(params.Length()), p.type,
type::AddressSpace::kUndefined, builtin::Access::kUndefined, p.usage)); builtin::AddressSpace::kUndefined, builtin::Access::kUndefined, p.usage));
} }
auto eval_stage = match.overload->const_eval_fn ? sem::EvaluationStage::kConstant auto eval_stage = match.overload->const_eval_fn ? sem::EvaluationStage::kConstant
: sem::EvaluationStage::kRuntime; : sem::EvaluationStage::kRuntime;
@ -1491,7 +1491,7 @@ IntrinsicTable::InitOrConv Impl::Lookup(InitConvIntrinsic type,
// Conversion. // Conversion.
auto* target = converters.GetOrCreate(match, [&]() { auto* target = converters.GetOrCreate(match, [&]() {
auto param = builder.create<sem::Parameter>( auto param = builder.create<sem::Parameter>(
nullptr, 0u, match.parameters[0].type, type::AddressSpace::kUndefined, nullptr, 0u, match.parameters[0].type, builtin::AddressSpace::kUndefined,
builtin::Access::kUndefined, match.parameters[0].usage); builtin::Access::kUndefined, match.parameters[0].usage);
auto eval_stage = match.overload->const_eval_fn ? sem::EvaluationStage::kConstant auto eval_stage = match.overload->const_eval_fn ? sem::EvaluationStage::kConstant
: sem::EvaluationStage::kRuntime; : sem::EvaluationStage::kRuntime;

View File

@ -231,7 +231,7 @@ TEST_F(IntrinsicTableTest, MismatchBool) {
TEST_F(IntrinsicTableTest, MatchPointer) { TEST_F(IntrinsicTableTest, MatchPointer) {
auto* i32 = create<type::I32>(); auto* i32 = create<type::I32>();
auto* atomicI32 = create<type::Atomic>(i32); auto* atomicI32 = create<type::Atomic>(i32);
auto* ptr = create<type::Pointer>(atomicI32, type::AddressSpace::kWorkgroup, auto* ptr = create<type::Pointer>(atomicI32, builtin::AddressSpace::kWorkgroup,
builtin::Access::kReadWrite); builtin::Access::kReadWrite);
auto result = table->Lookup(BuiltinType::kAtomicLoad, utils::Vector{ptr}, auto result = table->Lookup(BuiltinType::kAtomicLoad, utils::Vector{ptr},
sem::EvaluationStage::kConstant, Source{}); sem::EvaluationStage::kConstant, Source{});
@ -256,7 +256,7 @@ TEST_F(IntrinsicTableTest, MatchArray) {
auto* arr = auto* arr =
create<type::Array>(create<type::U32>(), create<type::RuntimeArrayCount>(), 4u, 4u, 4u, 4u); create<type::Array>(create<type::U32>(), create<type::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
auto* arr_ptr = auto* arr_ptr =
create<type::Pointer>(arr, type::AddressSpace::kStorage, builtin::Access::kReadWrite); create<type::Pointer>(arr, builtin::AddressSpace::kStorage, builtin::Access::kReadWrite);
auto result = table->Lookup(BuiltinType::kArrayLength, utils::Vector{arr_ptr}, auto result = table->Lookup(BuiltinType::kArrayLength, utils::Vector{arr_ptr},
sem::EvaluationStage::kConstant, Source{}); sem::EvaluationStage::kConstant, Source{});
ASSERT_NE(result.sem, nullptr) << Diagnostics().str(); ASSERT_NE(result.sem, nullptr) << Diagnostics().str();
@ -448,7 +448,7 @@ TEST_F(IntrinsicTableTest, ImplicitLoadOnReference) {
auto* f32 = create<type::F32>(); auto* f32 = create<type::F32>();
auto result = table->Lookup(BuiltinType::kCos, auto result = table->Lookup(BuiltinType::kCos,
utils::Vector{ utils::Vector{
create<type::Reference>(f32, type::AddressSpace::kFunction, create<type::Reference>(f32, builtin::AddressSpace::kFunction,
builtin::Access::kReadWrite), builtin::Access::kReadWrite),
}, },
sem::EvaluationStage::kConstant, Source{}); sem::EvaluationStage::kConstant, Source{});
@ -549,7 +549,7 @@ TEST_F(IntrinsicTableTest, MatchDifferentArgsElementType_Builtin_ConstantEval) {
TEST_F(IntrinsicTableTest, MatchDifferentArgsElementType_Builtin_RuntimeEval) { TEST_F(IntrinsicTableTest, MatchDifferentArgsElementType_Builtin_RuntimeEval) {
auto* af = create<type::AbstractFloat>(); auto* af = create<type::AbstractFloat>();
auto* bool_ref = create<type::Reference>(create<type::Bool>(), type::AddressSpace::kFunction, auto* bool_ref = create<type::Reference>(create<type::Bool>(), builtin::AddressSpace::kFunction,
builtin::Access::kReadWrite); builtin::Access::kReadWrite);
auto result = table->Lookup(BuiltinType::kSelect, utils::Vector{af, af, bool_ref}, auto result = table->Lookup(BuiltinType::kSelect, utils::Vector{af, af, bool_ref},
sem::EvaluationStage::kRuntime, Source{}); sem::EvaluationStage::kRuntime, Source{});

View File

@ -95,7 +95,7 @@ TEST_F(ResolverIsHostShareable, Matrix) {
} }
TEST_F(ResolverIsHostShareable, Pointer) { TEST_F(ResolverIsHostShareable, Pointer) {
auto* ptr = create<type::Pointer>(create<type::I32>(), type::AddressSpace::kPrivate, auto* ptr = create<type::Pointer>(create<type::I32>(), builtin::AddressSpace::kPrivate,
builtin::Access::kReadWrite); builtin::Access::kReadWrite);
EXPECT_FALSE(r()->IsHostShareable(ptr)); EXPECT_FALSE(r()->IsHostShareable(ptr));
} }

View File

@ -78,7 +78,7 @@ TEST_F(ResolverIsStorableTest, Matrix) {
} }
TEST_F(ResolverIsStorableTest, Pointer) { TEST_F(ResolverIsStorableTest, Pointer) {
auto* ptr = create<type::Pointer>(create<type::I32>(), type::AddressSpace::kPrivate, auto* ptr = create<type::Pointer>(create<type::I32>(), builtin::AddressSpace::kPrivate,
builtin::Access::kReadWrite); builtin::Access::kReadWrite);
EXPECT_FALSE(r()->IsStorable(ptr)); EXPECT_FALSE(r()->IsStorable(ptr));
} }
@ -112,7 +112,7 @@ TEST_F(ResolverIsStorableTest, Struct_AllMembersStorable) {
TEST_F(ResolverIsStorableTest, Struct_SomeMembersNonStorable) { TEST_F(ResolverIsStorableTest, Struct_SomeMembersNonStorable) {
Structure("S", utils::Vector{ Structure("S", utils::Vector{
Member("a", ty.i32()), Member("a", ty.i32()),
Member("b", ty.pointer<i32>(type::AddressSpace::kPrivate)), Member("b", ty.pointer<i32>(builtin::AddressSpace::kPrivate)),
}); });
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -138,7 +138,7 @@ TEST_F(ResolverIsStorableTest, Struct_NestedNonStorable) {
auto* non_storable = auto* non_storable =
Structure("nonstorable", utils::Vector{ Structure("nonstorable", utils::Vector{
Member("a", ty.i32()), Member("a", ty.i32()),
Member("b", ty.pointer<i32>(type::AddressSpace::kPrivate)), Member("b", ty.pointer<i32>(builtin::AddressSpace::kPrivate)),
}); });
Structure("S", utils::Vector{ Structure("S", utils::Vector{
Member("a", ty.i32()), Member("a", ty.i32()),

View File

@ -929,7 +929,7 @@ TEST_P(MaterializeAbstractNumericToDefaultType, Test) {
break; break;
} }
case Method::kIndex: { case Method::kIndex: {
GlobalVar("arr", ty.array<i32, 4>(), type::AddressSpace::kPrivate); GlobalVar("arr", ty.array<i32, 4>(), builtin::AddressSpace::kPrivate);
WrapInFunction(IndexAccessor("arr", abstract_expr())); WrapInFunction(IndexAccessor("arr", abstract_expr()));
break; break;
} }

View File

@ -159,7 +159,7 @@ TEST_F(ResolverOverrideTest, TransitiveReferences_ViaOverrideInit) {
TEST_F(ResolverOverrideTest, TransitiveReferences_ViaPrivateInit) { TEST_F(ResolverOverrideTest, TransitiveReferences_ViaPrivateInit) {
auto* a = Override("a", ty.f32()); auto* a = Override("a", ty.f32());
auto* b = GlobalVar("b", type::AddressSpace::kPrivate, ty.f32(), Mul(2_a, "a")); auto* b = GlobalVar("b", builtin::AddressSpace::kPrivate, ty.f32(), Mul(2_a, "a"));
Override("unused", ty.f32(), Expr(1_f)); Override("unused", ty.f32(), Expr(1_f));
auto* func = Func("foo", utils::Empty, ty.void_(), auto* func = Func("foo", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
@ -208,7 +208,8 @@ TEST_F(ResolverOverrideTest, TransitiveReferences_ViaAttribute) {
TEST_F(ResolverOverrideTest, TransitiveReferences_ViaArraySize) { TEST_F(ResolverOverrideTest, TransitiveReferences_ViaArraySize) {
auto* a = Override("a", ty.i32()); auto* a = Override("a", ty.i32());
auto* b = Override("b", ty.i32(), Mul(2_a, "a")); auto* b = Override("b", ty.i32(), Mul(2_a, "a"));
auto* arr = GlobalVar("arr", type::AddressSpace::kWorkgroup, ty.array(ty.i32(), Mul(2_a, "b"))); auto* arr =
GlobalVar("arr", builtin::AddressSpace::kWorkgroup, ty.array(ty.i32(), Mul(2_a, "b")));
auto arr_ty = arr->type; auto arr_ty = arr->type;
Override("unused", ty.i32(), Expr(1_a)); Override("unused", ty.i32(), Expr(1_a));
auto* func = Func("foo", utils::Empty, ty.void_(), auto* func = Func("foo", utils::Empty, ty.void_(),
@ -249,7 +250,7 @@ TEST_F(ResolverOverrideTest, TransitiveReferences_ViaArraySize_Alias) {
auto* a = Override("a", ty.i32()); auto* a = Override("a", ty.i32());
auto* b = Override("b", ty.i32(), Mul(2_a, "a")); auto* b = Override("b", ty.i32(), Mul(2_a, "a"));
Alias("arr_ty", ty.array(ty.i32(), Mul(2_a, "b"))); Alias("arr_ty", ty.array(ty.i32(), Mul(2_a, "b")));
auto* arr = GlobalVar("arr", type::AddressSpace::kWorkgroup, ty("arr_ty")); auto* arr = GlobalVar("arr", builtin::AddressSpace::kWorkgroup, ty("arr_ty"));
auto arr_ty = arr->type; auto arr_ty = arr->type;
Override("unused", ty.i32(), Expr(1_a)); Override("unused", ty.i32(), Expr(1_a));
auto* func = Func("foo", utils::Empty, ty.void_(), auto* func = Func("foo", utils::Empty, ty.void_(),
@ -295,8 +296,8 @@ TEST_F(ResolverOverrideTest, TransitiveReferences_MultipleEntryPoints) {
auto* d = Override("d", ty.i32()); auto* d = Override("d", ty.i32());
Alias("arr_ty1", ty.array(ty.i32(), Mul("b1", "c1"))); Alias("arr_ty1", ty.array(ty.i32(), Mul("b1", "c1")));
Alias("arr_ty2", ty.array(ty.i32(), Mul("b2", "c2"))); Alias("arr_ty2", ty.array(ty.i32(), Mul("b2", "c2")));
auto* arr1 = GlobalVar("arr1", type::AddressSpace::kWorkgroup, ty("arr_ty1")); auto* arr1 = GlobalVar("arr1", builtin::AddressSpace::kWorkgroup, ty("arr_ty1"));
auto* arr2 = GlobalVar("arr2", type::AddressSpace::kWorkgroup, ty("arr_ty2")); auto* arr2 = GlobalVar("arr2", builtin::AddressSpace::kWorkgroup, ty("arr_ty2"));
Override("unused", ty.i32(), Expr(1_a)); Override("unused", ty.i32(), Expr(1_a));
auto* func1 = Func("foo1", utils::Empty, ty.void_(), auto* func1 = Func("foo1", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{

View File

@ -39,7 +39,7 @@ TEST_F(ResolverPtrRefTest, AddressOf) {
ASSERT_TRUE(TypeOf(expr)->Is<type::Pointer>()); ASSERT_TRUE(TypeOf(expr)->Is<type::Pointer>());
EXPECT_TRUE(TypeOf(expr)->As<type::Pointer>()->StoreType()->Is<type::I32>()); EXPECT_TRUE(TypeOf(expr)->As<type::Pointer>()->StoreType()->Is<type::I32>());
EXPECT_EQ(TypeOf(expr)->As<type::Pointer>()->AddressSpace(), type::AddressSpace::kFunction); EXPECT_EQ(TypeOf(expr)->As<type::Pointer>()->AddressSpace(), builtin::AddressSpace::kFunction);
} }
TEST_F(ResolverPtrRefTest, AddressOfThenDeref) { TEST_F(ResolverPtrRefTest, AddressOfThenDeref) {
@ -68,23 +68,23 @@ TEST_F(ResolverPtrRefTest, DefaultPtrAddressSpace) {
auto* buf = Structure("S", utils::Vector{Member("m", ty.i32())}); auto* buf = Structure("S", utils::Vector{Member("m", ty.i32())});
auto* function = Var("f", ty.i32()); auto* function = Var("f", ty.i32());
auto* private_ = GlobalVar("p", ty.i32(), type::AddressSpace::kPrivate); auto* private_ = GlobalVar("p", ty.i32(), builtin::AddressSpace::kPrivate);
auto* workgroup = GlobalVar("w", ty.i32(), type::AddressSpace::kWorkgroup); auto* workgroup = GlobalVar("w", ty.i32(), builtin::AddressSpace::kWorkgroup);
auto* uniform = auto* uniform =
GlobalVar("ub", ty.Of(buf), type::AddressSpace::kUniform, Binding(0_a), Group(0_a)); GlobalVar("ub", ty.Of(buf), builtin::AddressSpace::kUniform, Binding(0_a), Group(0_a));
auto* storage = auto* storage =
GlobalVar("sb", ty.Of(buf), type::AddressSpace::kStorage, Binding(1_a), Group(0_a)); GlobalVar("sb", ty.Of(buf), builtin::AddressSpace::kStorage, Binding(1_a), Group(0_a));
auto* function_ptr = auto* function_ptr =
Let("f_ptr", ty.pointer(ty.i32(), type::AddressSpace::kFunction), AddressOf(function)); Let("f_ptr", ty.pointer(ty.i32(), builtin::AddressSpace::kFunction), AddressOf(function));
auto* private_ptr = auto* private_ptr =
Let("p_ptr", ty.pointer(ty.i32(), type::AddressSpace::kPrivate), AddressOf(private_)); Let("p_ptr", ty.pointer(ty.i32(), builtin::AddressSpace::kPrivate), AddressOf(private_));
auto* workgroup_ptr = auto* workgroup_ptr =
Let("w_ptr", ty.pointer(ty.i32(), type::AddressSpace::kWorkgroup), AddressOf(workgroup)); Let("w_ptr", ty.pointer(ty.i32(), builtin::AddressSpace::kWorkgroup), AddressOf(workgroup));
auto* uniform_ptr = auto* uniform_ptr =
Let("ub_ptr", ty.pointer(ty.Of(buf), type::AddressSpace::kUniform), AddressOf(uniform)); Let("ub_ptr", ty.pointer(ty.Of(buf), builtin::AddressSpace::kUniform), AddressOf(uniform));
auto* storage_ptr = auto* storage_ptr =
Let("sb_ptr", ty.pointer(ty.Of(buf), type::AddressSpace::kStorage), AddressOf(storage)); Let("sb_ptr", ty.pointer(ty.Of(buf), builtin::AddressSpace::kStorage), AddressOf(storage));
WrapInFunction(function, function_ptr, private_ptr, workgroup_ptr, uniform_ptr, storage_ptr); WrapInFunction(function, function_ptr, private_ptr, workgroup_ptr, uniform_ptr, storage_ptr);

View File

@ -143,12 +143,12 @@ TEST_F(ResolverPtrRefValidationTest, InferredPtrAccessMismatch) {
// } // }
auto* inner = Structure("Inner", utils::Vector{Member("arr", ty.array<i32, 4>())}); auto* inner = Structure("Inner", utils::Vector{Member("arr", ty.array<i32, 4>())});
auto* buf = Structure("S", utils::Vector{Member("inner", ty.Of(inner))}); auto* buf = Structure("S", utils::Vector{Member("inner", ty.Of(inner))});
auto* storage = GlobalVar("s", ty.Of(buf), type::AddressSpace::kStorage, auto* storage = GlobalVar("s", ty.Of(buf), builtin::AddressSpace::kStorage,
builtin::Access::kReadWrite, Binding(0_a), Group(0_a)); builtin::Access::kReadWrite, Binding(0_a), Group(0_a));
auto* expr = IndexAccessor(MemberAccessor(MemberAccessor(storage, "inner"), "arr"), 2_i); auto* expr = IndexAccessor(MemberAccessor(MemberAccessor(storage, "inner"), "arr"), 2_i);
auto* ptr = auto* ptr = Let(Source{{12, 34}}, "p", ty.pointer<i32>(builtin::AddressSpace::kStorage),
Let(Source{{12, 34}}, "p", ty.pointer<i32>(type::AddressSpace::kStorage), AddressOf(expr)); AddressOf(expr));
WrapInFunction(ptr); WrapInFunction(ptr);

View File

@ -88,7 +88,7 @@
#include "src/tint/utils/vector.h" #include "src/tint/utils/vector.h"
TINT_INSTANTIATE_TYPEINFO(tint::sem::BuiltinEnumExpression<tint::builtin::Access>); TINT_INSTANTIATE_TYPEINFO(tint::sem::BuiltinEnumExpression<tint::builtin::Access>);
TINT_INSTANTIATE_TYPEINFO(tint::sem::BuiltinEnumExpression<tint::type::AddressSpace>); TINT_INSTANTIATE_TYPEINFO(tint::sem::BuiltinEnumExpression<tint::builtin::AddressSpace>);
TINT_INSTANTIATE_TYPEINFO(tint::sem::BuiltinEnumExpression<tint::type::TexelFormat>); TINT_INSTANTIATE_TYPEINFO(tint::sem::BuiltinEnumExpression<tint::type::TexelFormat>);
namespace tint::resolver { namespace tint::resolver {
@ -255,12 +255,12 @@ sem::Variable* Resolver::Let(const ast::Let* v, bool is_global) {
ty = rhs->Type()->UnwrapRef(); // Implicit load of RHS ty = rhs->Type()->UnwrapRef(); // Implicit load of RHS
} }
if (rhs && !validator_.VariableInitializer(v, type::AddressSpace::kUndefined, ty, rhs)) { if (rhs && !validator_.VariableInitializer(v, builtin::AddressSpace::kUndefined, ty, rhs)) {
return nullptr; return nullptr;
} }
if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kUndefined, const_cast<type::Type*>(ty), if (!ApplyAddressSpaceUsageToType(builtin::AddressSpace::kUndefined,
v->source)) { const_cast<type::Type*>(ty), v->source)) {
AddNote("while instantiating 'let' " + builder_->Symbols().NameFor(v->name->symbol), AddNote("while instantiating 'let' " + builder_->Symbols().NameFor(v->name->symbol),
v->source); v->source);
return nullptr; return nullptr;
@ -269,12 +269,12 @@ sem::Variable* Resolver::Let(const ast::Let* v, bool is_global) {
sem::Variable* sem = nullptr; sem::Variable* sem = nullptr;
if (is_global) { if (is_global) {
sem = builder_->create<sem::GlobalVariable>( sem = builder_->create<sem::GlobalVariable>(
v, ty, sem::EvaluationStage::kRuntime, type::AddressSpace::kUndefined, v, ty, sem::EvaluationStage::kRuntime, builtin::AddressSpace::kUndefined,
builtin::Access::kUndefined, builtin::Access::kUndefined,
/* constant_value */ nullptr, sem::BindingPoint{}, std::nullopt); /* constant_value */ nullptr, sem::BindingPoint{}, std::nullopt);
} else { } else {
sem = builder_->create<sem::LocalVariable>(v, ty, sem::EvaluationStage::kRuntime, sem = builder_->create<sem::LocalVariable>(v, ty, sem::EvaluationStage::kRuntime,
type::AddressSpace::kUndefined, builtin::AddressSpace::kUndefined,
builtin::Access::kUndefined, current_statement_, builtin::Access::kUndefined, current_statement_,
/* constant_value */ nullptr); /* constant_value */ nullptr);
} }
@ -318,19 +318,19 @@ sem::Variable* Resolver::Override(const ast::Override* v) {
return nullptr; return nullptr;
} }
if (rhs && !validator_.VariableInitializer(v, type::AddressSpace::kUndefined, ty, rhs)) { if (rhs && !validator_.VariableInitializer(v, builtin::AddressSpace::kUndefined, ty, rhs)) {
return nullptr; return nullptr;
} }
if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kUndefined, const_cast<type::Type*>(ty), if (!ApplyAddressSpaceUsageToType(builtin::AddressSpace::kUndefined,
v->source)) { const_cast<type::Type*>(ty), v->source)) {
AddNote("while instantiating 'override' " + builder_->Symbols().NameFor(v->name->symbol), AddNote("while instantiating 'override' " + builder_->Symbols().NameFor(v->name->symbol),
v->source); v->source);
return nullptr; return nullptr;
} }
auto* sem = builder_->create<sem::GlobalVariable>( auto* sem = builder_->create<sem::GlobalVariable>(
v, ty, sem::EvaluationStage::kOverride, type::AddressSpace::kUndefined, v, ty, sem::EvaluationStage::kOverride, builtin::AddressSpace::kUndefined,
builtin::Access::kUndefined, builtin::Access::kUndefined,
/* constant_value */ nullptr, sem::BindingPoint{}, std::nullopt); /* constant_value */ nullptr, sem::BindingPoint{}, std::nullopt);
sem->SetInitializer(rhs); sem->SetInitializer(rhs);
@ -412,12 +412,12 @@ sem::Variable* Resolver::Const(const ast::Const* c, bool is_global) {
ty = rhs->Type(); ty = rhs->Type();
} }
if (!validator_.VariableInitializer(c, type::AddressSpace::kUndefined, ty, rhs)) { if (!validator_.VariableInitializer(c, builtin::AddressSpace::kUndefined, ty, rhs)) {
return nullptr; return nullptr;
} }
if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kUndefined, const_cast<type::Type*>(ty), if (!ApplyAddressSpaceUsageToType(builtin::AddressSpace::kUndefined,
c->source)) { const_cast<type::Type*>(ty), c->source)) {
AddNote("while instantiating 'const' " + builder_->Symbols().NameFor(c->name->symbol), AddNote("while instantiating 'const' " + builder_->Symbols().NameFor(c->name->symbol),
c->source); c->source);
return nullptr; return nullptr;
@ -426,10 +426,10 @@ sem::Variable* Resolver::Const(const ast::Const* c, bool is_global) {
const auto value = rhs->ConstantValue(); const auto value = rhs->ConstantValue();
auto* sem = is_global auto* sem = is_global
? static_cast<sem::Variable*>(builder_->create<sem::GlobalVariable>( ? static_cast<sem::Variable*>(builder_->create<sem::GlobalVariable>(
c, ty, sem::EvaluationStage::kConstant, type::AddressSpace::kUndefined, c, ty, sem::EvaluationStage::kConstant, builtin::AddressSpace::kUndefined,
builtin::Access::kUndefined, value, sem::BindingPoint{}, std::nullopt)) builtin::Access::kUndefined, value, sem::BindingPoint{}, std::nullopt))
: static_cast<sem::Variable*>(builder_->create<sem::LocalVariable>( : static_cast<sem::Variable*>(builder_->create<sem::LocalVariable>(
c, ty, sem::EvaluationStage::kConstant, type::AddressSpace::kUndefined, c, ty, sem::EvaluationStage::kConstant, builtin::AddressSpace::kUndefined,
builtin::Access::kUndefined, current_statement_, value)); builtin::Access::kUndefined, current_statement_, value));
sem->SetInitializer(rhs); sem->SetInitializer(rhs);
@ -473,7 +473,7 @@ sem::Variable* Resolver::Var(const ast::Var* var, bool is_global) {
return nullptr; return nullptr;
} }
auto address_space = type::AddressSpace::kUndefined; auto address_space = builtin::AddressSpace::kUndefined;
if (var->declared_address_space) { if (var->declared_address_space) {
auto expr = AddressSpaceExpression(var->declared_address_space); auto expr = AddressSpaceExpression(var->declared_address_space);
if (!expr) { if (!expr) {
@ -483,17 +483,17 @@ sem::Variable* Resolver::Var(const ast::Var* var, bool is_global) {
} else { } else {
// No declared address space. Infer from usage / type. // No declared address space. Infer from usage / type.
if (!is_global) { if (!is_global) {
address_space = type::AddressSpace::kFunction; address_space = builtin::AddressSpace::kFunction;
} else if (storage_ty->UnwrapRef()->is_handle()) { } else if (storage_ty->UnwrapRef()->is_handle()) {
// https://gpuweb.github.io/gpuweb/wgsl/#module-scope-variables // https://gpuweb.github.io/gpuweb/wgsl/#module-scope-variables
// If the store type is a texture type or a sampler type, then the // If the store type is a texture type or a sampler type, then the
// variable declaration must not have a address space attribute. The // variable declaration must not have a address space attribute. The
// address space will always be handle. // address space will always be handle.
address_space = type::AddressSpace::kHandle; address_space = builtin::AddressSpace::kHandle;
} }
} }
if (!is_global && address_space != type::AddressSpace::kFunction && if (!is_global && address_space != builtin::AddressSpace::kFunction &&
validator_.IsValidationEnabled(var->attributes, validator_.IsValidationEnabled(var->attributes,
ast::DisabledValidation::kIgnoreAddressSpace)) { ast::DisabledValidation::kIgnoreAddressSpace)) {
AddError("function-scope 'var' declaration must use 'function' address space", var->source); AddError("function-scope 'var' declaration must use 'function' address space", var->source);
@ -622,7 +622,7 @@ sem::Parameter* Resolver::Parameter(const ast::Parameter* param, uint32_t index)
return nullptr; return nullptr;
} }
if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kUndefined, ty, param->type->source)) { if (!ApplyAddressSpaceUsageToType(builtin::AddressSpace::kUndefined, ty, param->type->source)) {
add_note(); add_note();
return nullptr; return nullptr;
} }
@ -673,7 +673,7 @@ sem::Parameter* Resolver::Parameter(const ast::Parameter* param, uint32_t index)
} }
auto* sem = builder_->create<sem::Parameter>( auto* sem = builder_->create<sem::Parameter>(
param, index, ty, type::AddressSpace::kUndefined, builtin::Access::kUndefined, param, index, ty, builtin::AddressSpace::kUndefined, builtin::Access::kUndefined,
sem::ParameterUsage::kNone, binding_point, location); sem::ParameterUsage::kNone, binding_point, location);
builder_->Sem().Add(param, sem); builder_->Sem().Add(param, sem);
return sem; return sem;
@ -703,12 +703,12 @@ utils::Result<uint32_t> Resolver::LocationAttribute(const ast::LocationAttribute
return static_cast<uint32_t>(value); return static_cast<uint32_t>(value);
} }
builtin::Access Resolver::DefaultAccessForAddressSpace(type::AddressSpace address_space) { builtin::Access Resolver::DefaultAccessForAddressSpace(builtin::AddressSpace address_space) {
// https://gpuweb.github.io/gpuweb/wgsl/#storage-class // https://gpuweb.github.io/gpuweb/wgsl/#storage-class
switch (address_space) { switch (address_space) {
case type::AddressSpace::kStorage: case builtin::AddressSpace::kStorage:
case type::AddressSpace::kUniform: case builtin::AddressSpace::kUniform:
case type::AddressSpace::kHandle: case builtin::AddressSpace::kHandle:
return builtin::Access::kRead; return builtin::Access::kRead;
default: default:
break; break;
@ -933,7 +933,7 @@ sem::Function* Resolver::Function(const ast::Function* decl) {
} }
if (auto* str = return_type->As<sem::Struct>()) { if (auto* str = return_type->As<sem::Struct>()) {
if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kUndefined, str, decl->source)) { if (!ApplyAddressSpaceUsageToType(builtin::AddressSpace::kUndefined, str, decl->source)) {
AddNote("while instantiating return type for " + AddNote("while instantiating return type for " +
builder_->Symbols().NameFor(decl->name->symbol), builder_->Symbols().NameFor(decl->name->symbol),
decl->source); decl->source);
@ -1497,7 +1497,7 @@ type::Type* Resolver::Type(const ast::Expression* ast) {
return const_cast<type::Type*>(type_expr->Type()); return const_cast<type::Type*>(type_expr->Type());
} }
sem::BuiltinEnumExpression<type::AddressSpace>* Resolver::AddressSpaceExpression( sem::BuiltinEnumExpression<builtin::AddressSpace>* Resolver::AddressSpaceExpression(
const ast::Expression* expr) { const ast::Expression* expr) {
return sem_.AsAddressSpace(Expression(expr)); return sem_.AsAddressSpace(Expression(expr));
} }
@ -2024,10 +2024,10 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
[&]() -> sem::TypeInitializer* { [&]() -> sem::TypeInitializer* {
auto params = utils::Transform(args, [&](auto, size_t i) { auto params = utils::Transform(args, [&](auto, size_t i) {
return builder_->create<sem::Parameter>( return builder_->create<sem::Parameter>(
nullptr, // declaration nullptr, // declaration
static_cast<uint32_t>(i), // index static_cast<uint32_t>(i), // index
arr->ElemType(), // type arr->ElemType(), // type
type::AddressSpace::kUndefined, // address_space builtin::AddressSpace::kUndefined, // address_space
builtin::Access::kUndefined); builtin::Access::kUndefined);
}); });
return builder_->create<sem::TypeInitializer>(arr, std::move(params), return builder_->create<sem::TypeInitializer>(arr, std::move(params),
@ -2053,11 +2053,11 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
params.Resize(std::min(args.Length(), str->Members().Length())); params.Resize(std::min(args.Length(), str->Members().Length()));
for (size_t i = 0, n = params.Length(); i < n; i++) { for (size_t i = 0, n = params.Length(); i < n; i++) {
params[i] = builder_->create<sem::Parameter>( params[i] = builder_->create<sem::Parameter>(
nullptr, // declaration nullptr, // declaration
static_cast<uint32_t>(i), // index static_cast<uint32_t>(i), // index
str->Members()[i]->Type(), // type str->Members()[i]->Type(), // type
type::AddressSpace::kUndefined, // address_space builtin::AddressSpace::kUndefined, // address_space
builtin::Access::kUndefined); // access builtin::Access::kUndefined); // access
} }
return builder_->create<sem::TypeInitializer>(str, std::move(params), return builder_->create<sem::TypeInitializer>(str, std::move(params),
args_stage); args_stage);
@ -2982,8 +2982,8 @@ sem::Expression* Resolver::Identifier(const ast::IdentifierExpression* expr) {
expr, current_statement_, access); expr, current_statement_, access);
} }
if (auto addr = resolved->AddressSpace(); addr != type::AddressSpace::kUndefined) { if (auto addr = resolved->AddressSpace(); addr != builtin::AddressSpace::kUndefined) {
return builder_->create<sem::BuiltinEnumExpression<type::AddressSpace>>( return builder_->create<sem::BuiltinEnumExpression<builtin::AddressSpace>>(
expr, current_statement_, addr); expr, current_statement_, addr);
} }
@ -3980,7 +3980,7 @@ sem::Statement* Resolver::IncrementDecrementStatement(
}); });
} }
bool Resolver::ApplyAddressSpaceUsageToType(type::AddressSpace address_space, bool Resolver::ApplyAddressSpaceUsageToType(builtin::AddressSpace address_space,
type::Type* ty, type::Type* ty,
const Source& usage) { const Source& usage) {
ty = const_cast<type::Type*>(ty->UnwrapRef()); ty = const_cast<type::Type*>(ty->UnwrapRef());
@ -4008,7 +4008,7 @@ bool Resolver::ApplyAddressSpaceUsageToType(type::AddressSpace address_space,
} }
if (auto* arr = ty->As<type::Array>()) { if (auto* arr = ty->As<type::Array>()) {
if (address_space != type::AddressSpace::kStorage) { if (address_space != builtin::AddressSpace::kStorage) {
if (arr->Count()->Is<type::RuntimeArrayCount>()) { if (arr->Count()->Is<type::RuntimeArrayCount>()) {
AddError("runtime-sized arrays can only be used in the <storage> address space", AddError("runtime-sized arrays can only be used in the <storage> address space",
usage); usage);
@ -4027,7 +4027,7 @@ bool Resolver::ApplyAddressSpaceUsageToType(type::AddressSpace address_space,
usage); usage);
} }
if (type::IsHostShareable(address_space) && !validator_.IsHostShareable(ty)) { if (builtin::IsHostShareable(address_space) && !validator_.IsHostShareable(ty)) {
std::stringstream err; std::stringstream err;
err << "Type '" << sem_.TypeNameOf(ty) << "' cannot be used in address space '" err << "Type '" << sem_.TypeNameOf(ty) << "' cannot be used in address space '"
<< address_space << "' as it is non-host-shareable"; << address_space << "' as it is non-host-shareable";

View File

@ -138,10 +138,11 @@ class Resolver {
/// @returns the resolved type from an expression, or nullptr on error /// @returns the resolved type from an expression, or nullptr on error
type::Type* Type(const ast::Expression* ast); type::Type* Type(const ast::Expression* ast);
/// @returns the call of Expression() cast to a sem::BuiltinEnumExpression<type::AddressSpace>. /// @returns the call of Expression() cast to a
/// If the sem::Expression is not a sem::BuiltinEnumExpression<type::AddressSpace>, then an /// sem::BuiltinEnumExpression<builtin::AddressSpace>. If the sem::Expression is not a
/// error diagnostic is raised and nullptr is returned. /// sem::BuiltinEnumExpression<builtin::AddressSpace>, then an error diagnostic is raised and
sem::BuiltinEnumExpression<type::AddressSpace>* AddressSpaceExpression( /// nullptr is returned.
sem::BuiltinEnumExpression<builtin::AddressSpace>* AddressSpaceExpression(
const ast::Expression* expr); const ast::Expression* expr);
/// @returns the call of Expression() cast to a sem::BuiltinEnumExpression<type::TexelFormat>. /// @returns the call of Expression() cast to a sem::BuiltinEnumExpression<type::TexelFormat>.
@ -401,11 +402,13 @@ class Resolver {
/// given type and address space. Used for generating sensible error /// given type and address space. Used for generating sensible error
/// messages. /// messages.
/// @returns true on success, false on error /// @returns true on success, false on error
bool ApplyAddressSpaceUsageToType(type::AddressSpace sc, type::Type* ty, const Source& usage); bool ApplyAddressSpaceUsageToType(builtin::AddressSpace sc,
type::Type* ty,
const Source& usage);
/// @param address_space the address space /// @param address_space the address space
/// @returns the default access control for the given address space /// @returns the default access control for the given address space
builtin::Access DefaultAccessForAddressSpace(type::AddressSpace address_space); builtin::Access DefaultAccessForAddressSpace(builtin::AddressSpace address_space);
/// Allocate constant IDs for pipeline-overridable constants. /// Allocate constant IDs for pipeline-overridable constants.
/// @returns true on success, false on error /// @returns true on success, false on error

View File

@ -325,7 +325,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl_Alias) {
TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScope) { TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScope) {
auto* init = Expr(2_i); auto* init = Expr(2_i);
GlobalVar("my_var", ty.i32(), type::AddressSpace::kPrivate, init); GlobalVar("my_var", ty.i32(), builtin::AddressSpace::kPrivate, init);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -405,7 +405,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScopeAfterFunctionScope) {
Func("func_i32", utils::Empty, ty.void_(), utils::Vector{fn_i32_decl}); Func("func_i32", utils::Empty, ty.void_(), utils::Vector{fn_i32_decl});
// Declare f32 "foo" at module scope // Declare f32 "foo" at module scope
auto* mod_f32 = Var("foo", ty.f32(), type::AddressSpace::kPrivate, Expr(2_f)); auto* mod_f32 = Var("foo", ty.f32(), builtin::AddressSpace::kPrivate, Expr(2_f));
auto* mod_init = mod_f32->initializer; auto* mod_init = mod_f32->initializer;
AST().AddGlobalVariable(mod_f32); AST().AddGlobalVariable(mod_f32);
@ -433,7 +433,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScopeAfterFunctionScope) {
TEST_F(ResolverTest, ArraySize_UnsignedLiteral) { TEST_F(ResolverTest, ArraySize_UnsignedLiteral) {
// var<private> a : array<f32, 10u>; // var<private> a : array<f32, 10u>;
auto* a = GlobalVar("a", ty.array(ty.f32(), Expr(10_u)), type::AddressSpace::kPrivate); auto* a = GlobalVar("a", ty.array(ty.f32(), Expr(10_u)), builtin::AddressSpace::kPrivate);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -446,7 +446,7 @@ TEST_F(ResolverTest, ArraySize_UnsignedLiteral) {
TEST_F(ResolverTest, ArraySize_SignedLiteral) { TEST_F(ResolverTest, ArraySize_SignedLiteral) {
// var<private> a : array<f32, 10i>; // var<private> a : array<f32, 10i>;
auto* a = GlobalVar("a", ty.array(ty.f32(), Expr(10_i)), type::AddressSpace::kPrivate); auto* a = GlobalVar("a", ty.array(ty.f32(), Expr(10_i)), builtin::AddressSpace::kPrivate);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -461,7 +461,7 @@ TEST_F(ResolverTest, ArraySize_UnsignedConst) {
// const size = 10u; // const size = 10u;
// var<private> a : array<f32, size>; // var<private> a : array<f32, size>;
GlobalConst("size", Expr(10_u)); GlobalConst("size", Expr(10_u));
auto* a = GlobalVar("a", ty.array(ty.f32(), Expr("size")), type::AddressSpace::kPrivate); auto* a = GlobalVar("a", ty.array(ty.f32(), Expr("size")), builtin::AddressSpace::kPrivate);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -476,7 +476,7 @@ TEST_F(ResolverTest, ArraySize_SignedConst) {
// const size = 0; // const size = 0;
// var<private> a : array<f32, size>; // var<private> a : array<f32, size>;
GlobalConst("size", Expr(10_i)); GlobalConst("size", Expr(10_i));
auto* a = GlobalVar("a", ty.array(ty.f32(), Expr("size")), type::AddressSpace::kPrivate); auto* a = GlobalVar("a", ty.array(ty.f32(), Expr("size")), builtin::AddressSpace::kPrivate);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -491,7 +491,7 @@ TEST_F(ResolverTest, ArraySize_NamedOverride) {
// override size = 10i; // override size = 10i;
// var<workgroup> a : array<f32, size>; // var<workgroup> a : array<f32, size>;
auto* override = Override("size", Expr(10_i)); auto* override = Override("size", Expr(10_i));
auto* a = GlobalVar("a", ty.array(ty.f32(), Expr("size")), type::AddressSpace::kWorkgroup); auto* a = GlobalVar("a", ty.array(ty.f32(), Expr("size")), builtin::AddressSpace::kWorkgroup);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -509,8 +509,8 @@ TEST_F(ResolverTest, ArraySize_NamedOverride_Equivalence) {
// var<workgroup> a : array<f32, size>; // var<workgroup> a : array<f32, size>;
// var<workgroup> b : array<f32, size>; // var<workgroup> b : array<f32, size>;
auto* override = Override("size", Expr(10_i)); auto* override = Override("size", Expr(10_i));
auto* a = GlobalVar("a", ty.array(ty.f32(), Expr("size")), type::AddressSpace::kWorkgroup); auto* a = GlobalVar("a", ty.array(ty.f32(), Expr("size")), builtin::AddressSpace::kWorkgroup);
auto* b = GlobalVar("b", ty.array(ty.f32(), Expr("size")), type::AddressSpace::kWorkgroup); auto* b = GlobalVar("b", ty.array(ty.f32(), Expr("size")), builtin::AddressSpace::kWorkgroup);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -536,7 +536,7 @@ TEST_F(ResolverTest, ArraySize_UnnamedOverride) {
// var<workgroup> a : array<f32, size*2>; // var<workgroup> a : array<f32, size*2>;
auto* override = Override("size", Expr(10_i)); auto* override = Override("size", Expr(10_i));
auto* cnt = Mul("size", 2_a); auto* cnt = Mul("size", 2_a);
auto* a = GlobalVar("a", ty.array(ty.f32(), cnt), type::AddressSpace::kWorkgroup); auto* a = GlobalVar("a", ty.array(ty.f32(), cnt), builtin::AddressSpace::kWorkgroup);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -556,8 +556,8 @@ TEST_F(ResolverTest, ArraySize_UnamedOverride_Equivalence) {
auto* override = Override("size", Expr(10_i)); auto* override = Override("size", Expr(10_i));
auto* a_cnt = Mul("size", 2_a); auto* a_cnt = Mul("size", 2_a);
auto* b_cnt = Mul("size", 2_a); auto* b_cnt = Mul("size", 2_a);
auto* a = GlobalVar("a", ty.array(ty.f32(), a_cnt), type::AddressSpace::kWorkgroup); auto* a = GlobalVar("a", ty.array(ty.f32(), a_cnt), builtin::AddressSpace::kWorkgroup);
auto* b = GlobalVar("b", ty.array(ty.f32(), b_cnt), type::AddressSpace::kWorkgroup); auto* b = GlobalVar("b", ty.array(ty.f32(), b_cnt), builtin::AddressSpace::kWorkgroup);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -579,7 +579,7 @@ TEST_F(ResolverTest, ArraySize_UnamedOverride_Equivalence) {
} }
TEST_F(ResolverTest, Expr_Bitcast) { TEST_F(ResolverTest, Expr_Bitcast) {
GlobalVar("name", ty.f32(), type::AddressSpace::kPrivate); GlobalVar("name", ty.f32(), builtin::AddressSpace::kPrivate);
auto* bitcast = Bitcast<f32>(Expr("name")); auto* bitcast = Bitcast<f32>(Expr("name"));
WrapInFunction(bitcast); WrapInFunction(bitcast);
@ -642,7 +642,7 @@ TEST_F(ResolverTest, Expr_Call_Builtin) {
} }
TEST_F(ResolverTest, Expr_Cast) { TEST_F(ResolverTest, Expr_Cast) {
GlobalVar("name", ty.f32(), type::AddressSpace::kPrivate); GlobalVar("name", ty.f32(), builtin::AddressSpace::kPrivate);
auto* cast = Call<f32>("name"); auto* cast = Call<f32>("name");
WrapInFunction(cast); WrapInFunction(cast);
@ -700,7 +700,7 @@ TEST_F(ResolverTest, Expr_Initializer_Type_Vec4) {
} }
TEST_F(ResolverTest, Expr_Identifier_GlobalVariable) { TEST_F(ResolverTest, Expr_Identifier_GlobalVariable) {
auto* my_var = GlobalVar("my_var", ty.f32(), type::AddressSpace::kPrivate); auto* my_var = GlobalVar("my_var", ty.f32(), builtin::AddressSpace::kPrivate);
auto* ident = Expr("my_var"); auto* ident = Expr("my_var");
WrapInFunction(ident); WrapInFunction(ident);
@ -801,7 +801,7 @@ TEST_F(ResolverTest, Expr_Identifier_Function_Ptr) {
auto* v = Expr("v"); auto* v = Expr("v");
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(Let("p", ty.pointer<f32>(type::AddressSpace::kFunction), AddressOf(v))); auto* p_decl = Decl(Let("p", ty.pointer<f32>(builtin::AddressSpace::kFunction), AddressOf(v)));
auto* assign = Assign(Deref(p), 1.23_f); auto* assign = Assign(Deref(p), 1.23_f);
Func("my_func", utils::Empty, ty.void_(), Func("my_func", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
@ -877,7 +877,7 @@ TEST_F(ResolverTest, Function_Parameters_Locations) {
Param("b", ty.u32(), utils::Vector{Builtin(builtin::BuiltinValue::kVertexIndex)}); Param("b", ty.u32(), utils::Vector{Builtin(builtin::BuiltinValue::kVertexIndex)});
auto* param_c = Param("c", ty.u32(), utils::Vector{Location(1_a)}); auto* param_c = Param("c", ty.u32(), utils::Vector{Location(1_a)});
GlobalVar("my_vec", ty.vec4<f32>(), type::AddressSpace::kPrivate); GlobalVar("my_vec", ty.vec4<f32>(), builtin::AddressSpace::kPrivate);
auto* func = Func("my_func", auto* func = Func("my_func",
utils::Vector{ utils::Vector{
param_a, param_a,
@ -907,7 +907,7 @@ TEST_F(ResolverTest, Function_Parameters_Locations) {
TEST_F(ResolverTest, Function_GlobalVariable_Location) { TEST_F(ResolverTest, Function_GlobalVariable_Location) {
auto* var = GlobalVar( auto* var = GlobalVar(
"my_vec", ty.vec4<f32>(), type::AddressSpace::kIn, "my_vec", ty.vec4<f32>(), builtin::AddressSpace::kIn,
utils::Vector{Location(3_a), Disable(ast::DisabledValidation::kIgnoreAddressSpace)}); utils::Vector{Location(3_a), Disable(ast::DisabledValidation::kIgnoreAddressSpace)});
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -920,10 +920,10 @@ TEST_F(ResolverTest, Function_GlobalVariable_Location) {
TEST_F(ResolverTest, Function_RegisterInputOutputVariables) { TEST_F(ResolverTest, Function_RegisterInputOutputVariables) {
auto* s = Structure("S", utils::Vector{Member("m", ty.u32())}); auto* s = Structure("S", utils::Vector{Member("m", ty.u32())});
auto* sb_var = GlobalVar("sb_var", ty.Of(s), type::AddressSpace::kStorage, auto* sb_var = GlobalVar("sb_var", ty.Of(s), builtin::AddressSpace::kStorage,
builtin::Access::kReadWrite, Binding(0_a), Group(0_a)); builtin::Access::kReadWrite, Binding(0_a), Group(0_a));
auto* wg_var = GlobalVar("wg_var", ty.f32(), type::AddressSpace::kWorkgroup); auto* wg_var = GlobalVar("wg_var", ty.f32(), builtin::AddressSpace::kWorkgroup);
auto* priv_var = GlobalVar("priv_var", ty.f32(), type::AddressSpace::kPrivate); auto* priv_var = GlobalVar("priv_var", ty.f32(), builtin::AddressSpace::kPrivate);
auto* func = Func("my_func", utils::Empty, ty.void_(), auto* func = Func("my_func", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
@ -966,7 +966,7 @@ TEST_F(ResolverTest, Function_ReturnType_Location) {
} }
TEST_F(ResolverTest, Function_ReturnType_NoLocation) { TEST_F(ResolverTest, Function_ReturnType_NoLocation) {
GlobalVar("my_vec", ty.vec4<f32>(), type::AddressSpace::kPrivate); GlobalVar("my_vec", ty.vec4<f32>(), builtin::AddressSpace::kPrivate);
auto* func = Func("my_func", utils::Empty, ty.vec4<f32>(), auto* func = Func("my_func", utils::Empty, ty.vec4<f32>(),
utils::Vector{ utils::Vector{
Return("my_vec"), Return("my_vec"),
@ -988,10 +988,10 @@ TEST_F(ResolverTest, Function_ReturnType_NoLocation) {
TEST_F(ResolverTest, Function_RegisterInputOutputVariables_SubFunction) { TEST_F(ResolverTest, Function_RegisterInputOutputVariables_SubFunction) {
auto* s = Structure("S", utils::Vector{Member("m", ty.u32())}); auto* s = Structure("S", utils::Vector{Member("m", ty.u32())});
auto* sb_var = GlobalVar("sb_var", ty.Of(s), type::AddressSpace::kStorage, auto* sb_var = GlobalVar("sb_var", ty.Of(s), builtin::AddressSpace::kStorage,
builtin::Access::kReadWrite, Binding(0_a), Group(0_a)); builtin::Access::kReadWrite, Binding(0_a), Group(0_a));
auto* wg_var = GlobalVar("wg_var", ty.f32(), type::AddressSpace::kWorkgroup); auto* wg_var = GlobalVar("wg_var", ty.f32(), builtin::AddressSpace::kWorkgroup);
auto* priv_var = GlobalVar("priv_var", ty.f32(), type::AddressSpace::kPrivate); auto* priv_var = GlobalVar("priv_var", ty.f32(), builtin::AddressSpace::kPrivate);
Func("my_func", utils::Empty, ty.f32(), Func("my_func", utils::Empty, ty.f32(),
utils::Vector{Assign("wg_var", "wg_var"), Assign("sb_var", "sb_var"), utils::Vector{Assign("wg_var", "wg_var"), Assign("sb_var", "sb_var"),
@ -1240,7 +1240,7 @@ TEST_F(ResolverTest, Function_WorkgroupSize_Mixed) {
TEST_F(ResolverTest, Expr_MemberAccessor_Struct) { TEST_F(ResolverTest, Expr_MemberAccessor_Struct) {
auto* st = Structure( auto* st = Structure(
"S", utils::Vector{Member("first_member", ty.i32()), Member("second_member", ty.f32())}); "S", utils::Vector{Member("first_member", ty.i32()), Member("second_member", ty.f32())});
GlobalVar("my_struct", ty.Of(st), type::AddressSpace::kPrivate); GlobalVar("my_struct", ty.Of(st), builtin::AddressSpace::kPrivate);
auto* mem = MemberAccessor("my_struct", "second_member"); auto* mem = MemberAccessor("my_struct", "second_member");
WrapInFunction(mem); WrapInFunction(mem);
@ -1261,7 +1261,7 @@ TEST_F(ResolverTest, Expr_MemberAccessor_Struct_Alias) {
auto* st = Structure( auto* st = Structure(
"S", utils::Vector{Member("first_member", ty.i32()), Member("second_member", ty.f32())}); "S", utils::Vector{Member("first_member", ty.i32()), Member("second_member", ty.f32())});
auto* alias = Alias("alias", ty.Of(st)); auto* alias = Alias("alias", ty.Of(st));
GlobalVar("my_struct", ty.Of(alias), type::AddressSpace::kPrivate); GlobalVar("my_struct", ty.Of(alias), builtin::AddressSpace::kPrivate);
auto* mem = MemberAccessor("my_struct", "second_member"); auto* mem = MemberAccessor("my_struct", "second_member");
WrapInFunction(mem); WrapInFunction(mem);
@ -1278,7 +1278,7 @@ TEST_F(ResolverTest, Expr_MemberAccessor_Struct_Alias) {
} }
TEST_F(ResolverTest, Expr_MemberAccessor_VectorSwizzle) { TEST_F(ResolverTest, Expr_MemberAccessor_VectorSwizzle) {
GlobalVar("my_vec", ty.vec4<f32>(), type::AddressSpace::kPrivate); GlobalVar("my_vec", ty.vec4<f32>(), builtin::AddressSpace::kPrivate);
auto* mem = MemberAccessor("my_vec", "xzyw"); auto* mem = MemberAccessor("my_vec", "xzyw");
WrapInFunction(mem); WrapInFunction(mem);
@ -1296,7 +1296,7 @@ TEST_F(ResolverTest, Expr_MemberAccessor_VectorSwizzle) {
} }
TEST_F(ResolverTest, Expr_MemberAccessor_VectorSwizzle_SingleElement) { TEST_F(ResolverTest, Expr_MemberAccessor_VectorSwizzle_SingleElement) {
GlobalVar("my_vec", ty.vec3<f32>(), type::AddressSpace::kPrivate); GlobalVar("my_vec", ty.vec3<f32>(), builtin::AddressSpace::kPrivate);
auto* mem = MemberAccessor("my_vec", "b"); auto* mem = MemberAccessor("my_vec", "b");
WrapInFunction(mem); WrapInFunction(mem);
@ -1329,7 +1329,7 @@ TEST_F(ResolverTest, Expr_Accessor_MultiLevel) {
auto* stB = Structure("B", utils::Vector{Member("foo", ty.vec4<f32>())}); auto* stB = Structure("B", utils::Vector{Member("foo", ty.vec4<f32>())});
auto* stA = Structure("A", utils::Vector{Member("mem", ty.array(ty.Of(stB), 3_i))}); auto* stA = Structure("A", utils::Vector{Member("mem", ty.array(ty.Of(stB), 3_i))});
GlobalVar("c", ty.Of(stA), type::AddressSpace::kPrivate); GlobalVar("c", ty.Of(stA), builtin::AddressSpace::kPrivate);
auto* mem = auto* mem =
MemberAccessor(MemberAccessor(IndexAccessor(MemberAccessor("c", "mem"), 0_i), "foo"), "yx"); MemberAccessor(MemberAccessor(IndexAccessor(MemberAccessor("c", "mem"), 0_i), "foo"), "yx");
@ -1347,7 +1347,7 @@ TEST_F(ResolverTest, Expr_Accessor_MultiLevel) {
TEST_F(ResolverTest, Expr_MemberAccessor_InBinaryOp) { TEST_F(ResolverTest, Expr_MemberAccessor_InBinaryOp) {
auto* st = Structure( auto* st = Structure(
"S", utils::Vector{Member("first_member", ty.f32()), Member("second_member", ty.f32())}); "S", utils::Vector{Member("first_member", ty.f32()), Member("second_member", ty.f32())});
GlobalVar("my_struct", ty.Of(st), type::AddressSpace::kPrivate); GlobalVar("my_struct", ty.Of(st), builtin::AddressSpace::kPrivate);
auto* expr = Add(MemberAccessor("my_struct", "first_member"), auto* expr = Add(MemberAccessor("my_struct", "first_member"),
MemberAccessor("my_struct", "second_member")); MemberAccessor("my_struct", "second_member"));
@ -1650,8 +1650,8 @@ TEST_P(Expr_Binary_Test_Valid, All) {
ss << FriendlyName(lhs_type) << " " << params.op << " " << FriendlyName(rhs_type); ss << FriendlyName(lhs_type) << " " << params.op << " " << FriendlyName(rhs_type);
SCOPED_TRACE(ss.str()); SCOPED_TRACE(ss.str());
GlobalVar("lhs", lhs_type, type::AddressSpace::kPrivate); GlobalVar("lhs", lhs_type, builtin::AddressSpace::kPrivate);
GlobalVar("rhs", rhs_type, type::AddressSpace::kPrivate); GlobalVar("rhs", rhs_type, builtin::AddressSpace::kPrivate);
auto* expr = create<ast::BinaryExpression>(params.op, Expr("lhs"), Expr("rhs")); auto* expr = create<ast::BinaryExpression>(params.op, Expr("lhs"), Expr("rhs"));
WrapInFunction(expr); WrapInFunction(expr);
@ -1685,8 +1685,8 @@ TEST_P(Expr_Binary_Test_WithAlias_Valid, All) {
<< FriendlyName(rhs_type); << FriendlyName(rhs_type);
SCOPED_TRACE(ss.str()); SCOPED_TRACE(ss.str());
GlobalVar("lhs", lhs_type, type::AddressSpace::kPrivate); GlobalVar("lhs", lhs_type, builtin::AddressSpace::kPrivate);
GlobalVar("rhs", rhs_type, type::AddressSpace::kPrivate); GlobalVar("rhs", rhs_type, builtin::AddressSpace::kPrivate);
auto* expr = create<ast::BinaryExpression>(params.op, Expr("lhs"), Expr("rhs")); auto* expr = create<ast::BinaryExpression>(params.op, Expr("lhs"), Expr("rhs"));
WrapInFunction(expr); WrapInFunction(expr);
@ -1731,8 +1731,8 @@ TEST_P(Expr_Binary_Test_Invalid, All) {
ss << FriendlyName(lhs_type) << " " << op << " " << FriendlyName(rhs_type); ss << FriendlyName(lhs_type) << " " << op << " " << FriendlyName(rhs_type);
SCOPED_TRACE(ss.str()); SCOPED_TRACE(ss.str());
GlobalVar("lhs", lhs_type, type::AddressSpace::kPrivate); GlobalVar("lhs", lhs_type, builtin::AddressSpace::kPrivate);
GlobalVar("rhs", rhs_type, type::AddressSpace::kPrivate); GlobalVar("rhs", rhs_type, builtin::AddressSpace::kPrivate);
auto* expr = create<ast::BinaryExpression>(Source{{12, 34}}, op, Expr("lhs"), Expr("rhs")); auto* expr = create<ast::BinaryExpression>(Source{{12, 34}}, op, Expr("lhs"), Expr("rhs"));
WrapInFunction(expr); WrapInFunction(expr);
@ -1771,8 +1771,8 @@ TEST_P(Expr_Binary_Test_Invalid_VectorMatrixMultiply, All) {
is_valid_expr = vec_size == mat_cols; is_valid_expr = vec_size == mat_cols;
} }
GlobalVar("lhs", lhs_type, type::AddressSpace::kPrivate); GlobalVar("lhs", lhs_type, builtin::AddressSpace::kPrivate);
GlobalVar("rhs", rhs_type, type::AddressSpace::kPrivate); GlobalVar("rhs", rhs_type, builtin::AddressSpace::kPrivate);
auto* expr = Mul(Source{{12, 34}}, Expr("lhs"), Expr("rhs")); auto* expr = Mul(Source{{12, 34}}, Expr("lhs"), Expr("rhs"));
WrapInFunction(expr); WrapInFunction(expr);
@ -1808,8 +1808,8 @@ TEST_P(Expr_Binary_Test_Invalid_MatrixMatrixMultiply, All) {
auto* col = create<type::Vector>(f32, lhs_mat_rows); auto* col = create<type::Vector>(f32, lhs_mat_rows);
auto* result_type = create<type::Matrix>(col, rhs_mat_cols); auto* result_type = create<type::Matrix>(col, rhs_mat_cols);
GlobalVar("lhs", lhs_type, type::AddressSpace::kPrivate); GlobalVar("lhs", lhs_type, builtin::AddressSpace::kPrivate);
GlobalVar("rhs", rhs_type, type::AddressSpace::kPrivate); GlobalVar("rhs", rhs_type, builtin::AddressSpace::kPrivate);
auto* expr = Mul(Source{{12, 34}}, Expr("lhs"), Expr("rhs")); auto* expr = Mul(Source{{12, 34}}, Expr("lhs"), Expr("rhs"));
WrapInFunction(expr); WrapInFunction(expr);
@ -1837,11 +1837,11 @@ TEST_P(UnaryOpExpressionTest, Expr_UnaryOp) {
auto op = GetParam(); auto op = GetParam();
if (op == ast::UnaryOp::kNot) { if (op == ast::UnaryOp::kNot) {
GlobalVar("ident", ty.vec4<bool>(), type::AddressSpace::kPrivate); GlobalVar("ident", ty.vec4<bool>(), builtin::AddressSpace::kPrivate);
} else if (op == ast::UnaryOp::kNegation || op == ast::UnaryOp::kComplement) { } else if (op == ast::UnaryOp::kNegation || op == ast::UnaryOp::kComplement) {
GlobalVar("ident", ty.vec4<i32>(), type::AddressSpace::kPrivate); GlobalVar("ident", ty.vec4<i32>(), builtin::AddressSpace::kPrivate);
} else { } else {
GlobalVar("ident", ty.vec4<f32>(), type::AddressSpace::kPrivate); GlobalVar("ident", ty.vec4<f32>(), builtin::AddressSpace::kPrivate);
} }
auto* der = create<ast::UnaryOpExpression>(op, Expr("ident")); auto* der = create<ast::UnaryOpExpression>(op, Expr("ident"));
WrapInFunction(der); WrapInFunction(der);
@ -1873,7 +1873,7 @@ TEST_F(ResolverTest, AddressSpace_SetsIfMissing) {
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_EQ(Sem().Get(var)->AddressSpace(), type::AddressSpace::kFunction); EXPECT_EQ(Sem().Get(var)->AddressSpace(), builtin::AddressSpace::kFunction);
} }
TEST_F(ResolverTest, AddressSpace_SetForSampler) { TEST_F(ResolverTest, AddressSpace_SetForSampler) {
@ -1882,7 +1882,7 @@ TEST_F(ResolverTest, AddressSpace_SetForSampler) {
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_EQ(Sem().Get(var)->AddressSpace(), type::AddressSpace::kHandle); EXPECT_EQ(Sem().Get(var)->AddressSpace(), builtin::AddressSpace::kHandle);
} }
TEST_F(ResolverTest, AddressSpace_SetForTexture) { TEST_F(ResolverTest, AddressSpace_SetForTexture) {
@ -1891,7 +1891,7 @@ TEST_F(ResolverTest, AddressSpace_SetForTexture) {
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_EQ(Sem().Get(var)->AddressSpace(), type::AddressSpace::kHandle); EXPECT_EQ(Sem().Get(var)->AddressSpace(), builtin::AddressSpace::kHandle);
} }
TEST_F(ResolverTest, AddressSpace_DoesNotSetOnConst) { TEST_F(ResolverTest, AddressSpace_DoesNotSetOnConst) {
@ -1901,14 +1901,14 @@ TEST_F(ResolverTest, AddressSpace_DoesNotSetOnConst) {
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_EQ(Sem().Get(var)->AddressSpace(), type::AddressSpace::kUndefined); EXPECT_EQ(Sem().Get(var)->AddressSpace(), builtin::AddressSpace::kUndefined);
} }
TEST_F(ResolverTest, Access_SetForStorageBuffer) { TEST_F(ResolverTest, Access_SetForStorageBuffer) {
// struct S { x : i32 }; // struct S { x : i32 };
// var<storage> g : S; // var<storage> g : S;
auto* s = Structure("S", utils::Vector{Member(Source{{12, 34}}, "x", ty.i32())}); auto* s = Structure("S", utils::Vector{Member(Source{{12, 34}}, "x", ty.i32())});
auto* var = GlobalVar(Source{{56, 78}}, "g", ty.Of(s), type::AddressSpace::kStorage, auto* var = GlobalVar(Source{{56, 78}}, "g", ty.Of(s), builtin::AddressSpace::kStorage,
Binding(0_a), Group(0_a)); Binding(0_a), Group(0_a));
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -1941,11 +1941,11 @@ TEST_F(ResolverTest, Function_EntryPoints_StageAttribute) {
// ep_1 -> {} // ep_1 -> {}
// ep_2 -> {} // ep_2 -> {}
GlobalVar("first", ty.f32(), type::AddressSpace::kPrivate); GlobalVar("first", ty.f32(), builtin::AddressSpace::kPrivate);
GlobalVar("second", ty.f32(), type::AddressSpace::kPrivate); GlobalVar("second", ty.f32(), builtin::AddressSpace::kPrivate);
GlobalVar("call_a", ty.f32(), type::AddressSpace::kPrivate); GlobalVar("call_a", ty.f32(), builtin::AddressSpace::kPrivate);
GlobalVar("call_b", ty.f32(), type::AddressSpace::kPrivate); GlobalVar("call_b", ty.f32(), builtin::AddressSpace::kPrivate);
GlobalVar("call_c", ty.f32(), type::AddressSpace::kPrivate); GlobalVar("call_c", ty.f32(), builtin::AddressSpace::kPrivate);
auto* func_b = Func("b", utils::Empty, ty.f32(), auto* func_b = Func("b", utils::Empty, ty.f32(),
utils::Vector{ utils::Vector{
@ -2085,8 +2085,8 @@ TEST_F(ResolverTest, ASTNodeReachedTwice) {
{ {
ProgramBuilder b; ProgramBuilder b;
auto* expr = b.Expr(1_i); auto* expr = b.Expr(1_i);
b.GlobalVar("a", b.ty.i32(), type::AddressSpace::kPrivate, expr); b.GlobalVar("a", b.ty.i32(), builtin::AddressSpace::kPrivate, expr);
b.GlobalVar("b", b.ty.i32(), type::AddressSpace::kPrivate, expr); b.GlobalVar("b", b.ty.i32(), builtin::AddressSpace::kPrivate, expr);
Resolver(&b).Resolve(); Resolver(&b).Resolve();
}, },
"internal compiler error: AST node 'tint::ast::IntLiteralExpression' was encountered twice " "internal compiler error: AST node 'tint::ast::IntLiteralExpression' was encountered twice "
@ -2094,7 +2094,7 @@ TEST_F(ResolverTest, ASTNodeReachedTwice) {
} }
TEST_F(ResolverTest, UnaryOp_Not) { TEST_F(ResolverTest, UnaryOp_Not) {
GlobalVar("ident", ty.vec4<f32>(), type::AddressSpace::kPrivate); GlobalVar("ident", ty.vec4<f32>(), builtin::AddressSpace::kPrivate);
auto* der = create<ast::UnaryOpExpression>(ast::UnaryOp::kNot, Expr(Source{{12, 34}}, "ident")); auto* der = create<ast::UnaryOpExpression>(ast::UnaryOp::kNot, Expr(Source{{12, 34}}, "ident"));
WrapInFunction(der); WrapInFunction(der);
@ -2103,7 +2103,7 @@ TEST_F(ResolverTest, UnaryOp_Not) {
} }
TEST_F(ResolverTest, UnaryOp_Complement) { TEST_F(ResolverTest, UnaryOp_Complement) {
GlobalVar("ident", ty.vec4<f32>(), type::AddressSpace::kPrivate); GlobalVar("ident", ty.vec4<f32>(), builtin::AddressSpace::kPrivate);
auto* der = auto* der =
create<ast::UnaryOpExpression>(ast::UnaryOp::kComplement, Expr(Source{{12, 34}}, "ident")); create<ast::UnaryOpExpression>(ast::UnaryOp::kComplement, Expr(Source{{12, 34}}, "ident"));
WrapInFunction(der); WrapInFunction(der);
@ -2113,7 +2113,7 @@ TEST_F(ResolverTest, UnaryOp_Complement) {
} }
TEST_F(ResolverTest, UnaryOp_Negation) { TEST_F(ResolverTest, UnaryOp_Negation) {
GlobalVar("ident", ty.u32(), type::AddressSpace::kPrivate); GlobalVar("ident", ty.u32(), builtin::AddressSpace::kPrivate);
auto* der = auto* der =
create<ast::UnaryOpExpression>(ast::UnaryOp::kNegation, Expr(Source{{12, 34}}, "ident")); create<ast::UnaryOpExpression>(ast::UnaryOp::kNegation, Expr(Source{{12, 34}}, "ident"));
WrapInFunction(der); WrapInFunction(der);
@ -2272,7 +2272,7 @@ TEST_F(ResolverTest, TextureSampler_Bug1715) { // crbug.com/tint/1715
GlobalVar("s", ty.sampler(type::SamplerKind::kSampler), Group(0_a), Binding(0_a)); GlobalVar("s", ty.sampler(type::SamplerKind::kSampler), Group(0_a), Binding(0_a));
GlobalVar("t", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Group(0_a), GlobalVar("t", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Group(0_a),
Binding(1_a)); Binding(1_a));
GlobalVar("c", ty.vec2<f32>(), type::AddressSpace::kUniform, Group(0_a), Binding(2_a)); GlobalVar("c", ty.vec2<f32>(), builtin::AddressSpace::kUniform, Group(0_a), Binding(2_a));
Func("main", utils::Empty, ty.vec4<f32>(), Func("main", utils::Empty, ty.vec4<f32>(),
utils::Vector{ utils::Vector{
@ -2288,9 +2288,9 @@ TEST_F(ResolverTest, TextureSampler_Bug1715) { // crbug.com/tint/1715
Func("helper", Func("helper",
utils::Vector{ utils::Vector{
Param("sl", ty.pointer(ty.sampler(type::SamplerKind::kSampler), Param("sl", ty.pointer(ty.sampler(type::SamplerKind::kSampler),
type::AddressSpace::kFunction)), builtin::AddressSpace::kFunction)),
Param("tl", ty.pointer(ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Param("tl", ty.pointer(ty.sampled_texture(type::TextureDimension::k2d, ty.f32()),
type::AddressSpace::kFunction)), builtin::AddressSpace::kFunction)),
}, },
ty.vec4<f32>(), ty.vec4<f32>(),
utils::Vector{ utils::Vector{
@ -2303,15 +2303,15 @@ TEST_F(ResolverTest, TextureSampler_Bug1715) { // crbug.com/tint/1715
TEST_F(ResolverTest, ModuleDependencyOrderedDeclarations) { TEST_F(ResolverTest, ModuleDependencyOrderedDeclarations) {
auto* f0 = Func("f0", utils::Empty, ty.void_(), utils::Empty); auto* f0 = Func("f0", utils::Empty, ty.void_(), utils::Empty);
auto* v0 = GlobalVar("v0", ty.i32(), type::AddressSpace::kPrivate); auto* v0 = GlobalVar("v0", ty.i32(), builtin::AddressSpace::kPrivate);
auto* a0 = Alias("a0", ty.i32()); auto* a0 = Alias("a0", ty.i32());
auto* s0 = Structure("s0", utils::Vector{Member("m", ty.i32())}); auto* s0 = Structure("s0", utils::Vector{Member("m", ty.i32())});
auto* f1 = Func("f1", utils::Empty, ty.void_(), utils::Empty); auto* f1 = Func("f1", utils::Empty, ty.void_(), utils::Empty);
auto* v1 = GlobalVar("v1", ty.i32(), type::AddressSpace::kPrivate); auto* v1 = GlobalVar("v1", ty.i32(), builtin::AddressSpace::kPrivate);
auto* a1 = Alias("a1", ty.i32()); auto* a1 = Alias("a1", ty.i32());
auto* s1 = Structure("s1", utils::Vector{Member("m", ty.i32())}); auto* s1 = Structure("s1", utils::Vector{Member("m", ty.i32())});
auto* f2 = Func("f2", utils::Empty, ty.void_(), utils::Empty); auto* f2 = Func("f2", utils::Empty, ty.void_(), utils::Empty);
auto* v2 = GlobalVar("v2", ty.i32(), type::AddressSpace::kPrivate); auto* v2 = GlobalVar("v2", ty.i32(), builtin::AddressSpace::kPrivate);
auto* a2 = Alias("a2", ty.i32()); auto* a2 = Alias("a2", ty.i32());
auto* s2 = Structure("s2", utils::Vector{Member("m", ty.i32())}); auto* s2 = Structure("s2", utils::Vector{Member("m", ty.i32())});

View File

@ -628,13 +628,13 @@ struct DataType<ptr<T>> {
/// @param b the ProgramBuilder /// @param b the ProgramBuilder
/// @return a new AST alias type /// @return a new AST alias type
static inline ast::Type AST(ProgramBuilder& b) { static inline ast::Type AST(ProgramBuilder& b) {
return b.ty.pointer(DataType<T>::AST(b), type::AddressSpace::kPrivate, return b.ty.pointer(DataType<T>::AST(b), builtin::AddressSpace::kPrivate,
builtin::Access::kUndefined); builtin::Access::kUndefined);
} }
/// @param b the ProgramBuilder /// @param b the ProgramBuilder
/// @return the semantic aliased type /// @return the semantic aliased type
static inline const type::Type* Sem(ProgramBuilder& b) { static inline const type::Type* Sem(ProgramBuilder& b) {
return b.create<type::Pointer>(DataType<T>::Sem(b), type::AddressSpace::kPrivate, return b.create<type::Pointer>(DataType<T>::Sem(b), builtin::AddressSpace::kPrivate,
builtin::Access::kReadWrite); builtin::Access::kReadWrite);
} }
@ -643,7 +643,7 @@ struct DataType<ptr<T>> {
static inline const ast::Expression* Expr(ProgramBuilder& b, static inline const ast::Expression* Expr(ProgramBuilder& b,
utils::VectorRef<Scalar> /*unused*/) { utils::VectorRef<Scalar> /*unused*/) {
auto sym = b.Symbols().New("global_for_ptr"); auto sym = b.Symbols().New("global_for_ptr");
b.GlobalVar(sym, DataType<T>::AST(b), type::AddressSpace::kPrivate); b.GlobalVar(sym, DataType<T>::AST(b), builtin::AddressSpace::kPrivate);
return b.AddressOf(sym); return b.AddressOf(sym);
} }

View File

@ -27,7 +27,7 @@ namespace {
class ResolverRootIdentifierTest : public ResolverTest {}; class ResolverRootIdentifierTest : public ResolverTest {};
TEST_F(ResolverRootIdentifierTest, GlobalPrivateVar) { TEST_F(ResolverRootIdentifierTest, GlobalPrivateVar) {
auto* a = GlobalVar("a", ty.f32(), type::AddressSpace::kPrivate); auto* a = GlobalVar("a", ty.f32(), builtin::AddressSpace::kPrivate);
auto* expr = Expr(a); auto* expr = Expr(a);
WrapInFunction(expr); WrapInFunction(expr);
@ -38,7 +38,7 @@ TEST_F(ResolverRootIdentifierTest, GlobalPrivateVar) {
} }
TEST_F(ResolverRootIdentifierTest, GlobalWorkgroupVar) { TEST_F(ResolverRootIdentifierTest, GlobalWorkgroupVar) {
auto* a = GlobalVar("a", ty.f32(), type::AddressSpace::kWorkgroup); auto* a = GlobalVar("a", ty.f32(), builtin::AddressSpace::kWorkgroup);
auto* expr = Expr(a); auto* expr = Expr(a);
WrapInFunction(expr); WrapInFunction(expr);
@ -49,7 +49,7 @@ TEST_F(ResolverRootIdentifierTest, GlobalWorkgroupVar) {
} }
TEST_F(ResolverRootIdentifierTest, GlobalStorageVar) { TEST_F(ResolverRootIdentifierTest, GlobalStorageVar) {
auto* a = GlobalVar("a", ty.f32(), type::AddressSpace::kStorage, Group(0_a), Binding(0_a)); auto* a = GlobalVar("a", ty.f32(), builtin::AddressSpace::kStorage, Group(0_a), Binding(0_a));
auto* expr = Expr(a); auto* expr = Expr(a);
WrapInFunction(expr); WrapInFunction(expr);
@ -60,7 +60,7 @@ TEST_F(ResolverRootIdentifierTest, GlobalStorageVar) {
} }
TEST_F(ResolverRootIdentifierTest, GlobalUniformVar) { TEST_F(ResolverRootIdentifierTest, GlobalUniformVar) {
auto* a = GlobalVar("a", ty.f32(), type::AddressSpace::kUniform, Group(0_a), Binding(0_a)); auto* a = GlobalVar("a", ty.f32(), builtin::AddressSpace::kUniform, Group(0_a), Binding(0_a));
auto* expr = Expr(a); auto* expr = Expr(a);
WrapInFunction(expr); WrapInFunction(expr);
@ -72,7 +72,7 @@ TEST_F(ResolverRootIdentifierTest, GlobalUniformVar) {
TEST_F(ResolverRootIdentifierTest, GlobalTextureVar) { TEST_F(ResolverRootIdentifierTest, GlobalTextureVar) {
auto* a = GlobalVar("a", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), auto* a = GlobalVar("a", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()),
type::AddressSpace::kUndefined, Group(0_a), Binding(0_a)); builtin::AddressSpace::kUndefined, Group(0_a), Binding(0_a));
auto* expr = Expr(a); auto* expr = Expr(a);
WrapInFunction(Call("textureDimensions", expr)); WrapInFunction(Call("textureDimensions", expr));
@ -142,7 +142,7 @@ TEST_F(ResolverRootIdentifierTest, PointerParameter) {
// { // {
// let b = a; // let b = a;
// } // }
auto* param = Param("a", ty.pointer(ty.f32(), type::AddressSpace::kFunction)); auto* param = Param("a", ty.pointer(ty.f32(), builtin::AddressSpace::kFunction));
auto* expr_param = Expr(param); auto* expr_param = Expr(param);
auto* let = Let("b", expr_param); auto* let = Let("b", expr_param);
auto* expr_let = Expr("b"); auto* expr_let = Expr("b");
@ -199,7 +199,7 @@ TEST_F(ResolverRootIdentifierTest, ThroughIndexAccessor) {
// { // {
// a[2i] // a[2i]
// } // }
auto* a = GlobalVar("a", ty.array<f32, 4>(), type::AddressSpace::kPrivate); auto* a = GlobalVar("a", ty.array<f32, 4>(), builtin::AddressSpace::kPrivate);
auto* expr = IndexAccessor(a, 2_i); auto* expr = IndexAccessor(a, 2_i);
WrapInFunction(expr); WrapInFunction(expr);
@ -216,7 +216,7 @@ TEST_F(ResolverRootIdentifierTest, ThroughMemberAccessor) {
// a.f // a.f
// } // }
auto* S = Structure("S", utils::Vector{Member("f", ty.f32())}); auto* S = Structure("S", utils::Vector{Member("f", ty.f32())});
auto* a = GlobalVar("a", ty.Of(S), type::AddressSpace::kPrivate); auto* a = GlobalVar("a", ty.Of(S), builtin::AddressSpace::kPrivate);
auto* expr = MemberAccessor(a, "f"); auto* expr = MemberAccessor(a, "f");
WrapInFunction(expr); WrapInFunction(expr);
@ -232,7 +232,7 @@ TEST_F(ResolverRootIdentifierTest, ThroughPointers) {
// let a_ptr1 = &*&a; // let a_ptr1 = &*&a;
// let a_ptr2 = &*a_ptr1; // let a_ptr2 = &*a_ptr1;
// } // }
auto* a = GlobalVar("a", ty.f32(), type::AddressSpace::kPrivate); auto* a = GlobalVar("a", ty.f32(), builtin::AddressSpace::kPrivate);
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);

View File

@ -79,7 +79,7 @@ void SemHelper::ErrorUnexpectedExprKind(const sem::Expression* expr,
std::string(wanted), std::string(wanted),
access->Declaration()->source); access->Declaration()->source);
}, },
[&](const sem::BuiltinEnumExpression<type::AddressSpace>* addr) { [&](const sem::BuiltinEnumExpression<builtin::AddressSpace>* addr) {
AddError("cannot use address space '" + utils::ToString(addr->Value()) + "' as " + AddError("cannot use address space '" + utils::ToString(addr->Value()) + "' as " +
std::string(wanted), std::string(wanted),
addr->Declaration()->source); addr->Declaration()->source);

View File

@ -105,11 +105,11 @@ class SemHelper {
/// @param expr the semantic node /// @param expr the semantic node
/// @returns nullptr if @p expr is nullptr, or @p expr cast to /// @returns nullptr if @p expr is nullptr, or @p expr cast to
/// sem::BuiltinEnumExpression<type::AddressSpace> if the cast is successful, otherwise an error /// sem::BuiltinEnumExpression<builtin::AddressSpace> if the cast is successful, otherwise an
/// diagnostic is raised. /// error diagnostic is raised.
sem::BuiltinEnumExpression<type::AddressSpace>* AsAddressSpace(sem::Expression* expr) const { sem::BuiltinEnumExpression<builtin::AddressSpace>* AsAddressSpace(sem::Expression* expr) const {
if (TINT_LIKELY(expr)) { if (TINT_LIKELY(expr)) {
auto* enum_expr = expr->As<sem::BuiltinEnumExpression<type::AddressSpace>>(); auto* enum_expr = expr->As<sem::BuiltinEnumExpression<builtin::AddressSpace>>();
if (TINT_LIKELY(enum_expr)) { if (TINT_LIKELY(enum_expr)) {
return enum_expr; return enum_expr;
} }

View File

@ -15,6 +15,7 @@
#include "src/tint/resolver/resolver.h" #include "src/tint/resolver/resolver.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/tint/builtin/address_space.h"
#include "src/tint/builtin/extension.h" #include "src/tint/builtin/extension.h"
#include "src/tint/resolver/resolver_test_helper.h" #include "src/tint/resolver/resolver_test_helper.h"
#include "src/tint/sem/index_accessor_expression.h" #include "src/tint/sem/index_accessor_expression.h"
@ -32,7 +33,7 @@ struct SideEffectsTest : ResolverTest {
template <typename T> template <typename T>
void MakeSideEffectFunc(const char* name) { void MakeSideEffectFunc(const char* name) {
auto global = Sym(); auto global = Sym();
GlobalVar(global, ty.Of<T>(), type::AddressSpace::kPrivate); GlobalVar(global, ty.Of<T>(), builtin::AddressSpace::kPrivate);
auto local = Sym(); auto local = Sym();
Func(name, utils::Empty, ty.Of<T>(), Func(name, utils::Empty, ty.Of<T>(),
utils::Vector{ utils::Vector{
@ -45,7 +46,7 @@ struct SideEffectsTest : ResolverTest {
template <typename MAKE_TYPE_FUNC> template <typename MAKE_TYPE_FUNC>
void MakeSideEffectFunc(const char* name, MAKE_TYPE_FUNC make_type) { void MakeSideEffectFunc(const char* name, MAKE_TYPE_FUNC make_type) {
auto global = Sym(); auto global = Sym();
GlobalVar(global, make_type(), type::AddressSpace::kPrivate); GlobalVar(global, make_type(), builtin::AddressSpace::kPrivate);
auto local = Sym(); auto local = Sym();
Func(name, utils::Empty, make_type(), Func(name, utils::Empty, make_type(),
utils::Vector{ utils::Vector{
@ -90,7 +91,7 @@ TEST_F(SideEffectsTest, VariableUser) {
} }
TEST_F(SideEffectsTest, Call_Builtin_NoSE) { TEST_F(SideEffectsTest, Call_Builtin_NoSE) {
GlobalVar("a", ty.f32(), type::AddressSpace::kPrivate); GlobalVar("a", ty.f32(), builtin::AddressSpace::kPrivate);
auto* expr = Call("dpdx", "a"); auto* expr = Call("dpdx", "a");
Func("f", utils::Empty, ty.void_(), utils::Vector{Ignore(expr)}, Func("f", utils::Empty, ty.void_(), utils::Vector{Ignore(expr)},
utils::Vector{create<ast::StageAttribute>(ast::PipelineStage::kFragment)}); utils::Vector{create<ast::StageAttribute>(ast::PipelineStage::kFragment)});
@ -116,7 +117,7 @@ TEST_F(SideEffectsTest, Call_Builtin_NoSE_WithSEArg) {
} }
TEST_F(SideEffectsTest, Call_Builtin_SE) { TEST_F(SideEffectsTest, Call_Builtin_SE) {
GlobalVar("a", ty.atomic(ty.i32()), type::AddressSpace::kWorkgroup); GlobalVar("a", ty.atomic(ty.i32()), builtin::AddressSpace::kWorkgroup);
auto* expr = Call("atomicAdd", AddressOf("a"), 1_i); auto* expr = Call("atomicAdd", AddressOf("a"), 1_i);
WrapInFunction(expr); WrapInFunction(expr);
@ -165,21 +166,21 @@ TEST_P(SideEffectsBuiltinTest, Test) {
auto& c = GetParam(); auto& c = GetParam();
uint32_t next_binding = 0; uint32_t next_binding = 0;
GlobalVar("f", ty.f32(), type::AddressSpace::kPrivate); GlobalVar("f", ty.f32(), tint::builtin::AddressSpace::kPrivate);
GlobalVar("i", ty.i32(), type::AddressSpace::kPrivate); GlobalVar("i", ty.i32(), tint::builtin::AddressSpace::kPrivate);
GlobalVar("u", ty.u32(), type::AddressSpace::kPrivate); GlobalVar("u", ty.u32(), tint::builtin::AddressSpace::kPrivate);
GlobalVar("b", ty.bool_(), type::AddressSpace::kPrivate); GlobalVar("b", ty.bool_(), tint::builtin::AddressSpace::kPrivate);
GlobalVar("vf", ty.vec3<f32>(), type::AddressSpace::kPrivate); GlobalVar("vf", ty.vec3<f32>(), tint::builtin::AddressSpace::kPrivate);
GlobalVar("vf2", ty.vec2<f32>(), type::AddressSpace::kPrivate); GlobalVar("vf2", ty.vec2<f32>(), tint::builtin::AddressSpace::kPrivate);
GlobalVar("vi2", ty.vec2<i32>(), type::AddressSpace::kPrivate); GlobalVar("vi2", ty.vec2<i32>(), tint::builtin::AddressSpace::kPrivate);
GlobalVar("vf4", ty.vec4<f32>(), type::AddressSpace::kPrivate); GlobalVar("vf4", ty.vec4<f32>(), tint::builtin::AddressSpace::kPrivate);
GlobalVar("vb", ty.vec3<bool>(), type::AddressSpace::kPrivate); GlobalVar("vb", ty.vec3<bool>(), tint::builtin::AddressSpace::kPrivate);
GlobalVar("m", ty.mat3x3<f32>(), type::AddressSpace::kPrivate); GlobalVar("m", ty.mat3x3<f32>(), tint::builtin::AddressSpace::kPrivate);
GlobalVar("arr", ty.array<f32, 10>(), type::AddressSpace::kPrivate); GlobalVar("arr", ty.array<f32, 10>(), tint::builtin::AddressSpace::kPrivate);
GlobalVar("storage_arr", ty.array<f32>(), type::AddressSpace::kStorage, Group(0_a), GlobalVar("storage_arr", ty.array<f32>(), tint::builtin::AddressSpace::kStorage, Group(0_a),
Binding(AInt(next_binding++))); Binding(AInt(next_binding++)));
GlobalVar("workgroup_arr", ty.array<f32, 4>(), type::AddressSpace::kWorkgroup); GlobalVar("workgroup_arr", ty.array<f32, 4>(), tint::builtin::AddressSpace::kWorkgroup);
GlobalVar("a", ty.atomic(ty.i32()), type::AddressSpace::kStorage, GlobalVar("a", ty.atomic(ty.i32()), tint::builtin::AddressSpace::kStorage,
tint::builtin::Access::kReadWrite, Group(0_a), Binding(AInt(next_binding++))); tint::builtin::Access::kReadWrite, Group(0_a), Binding(AInt(next_binding++)));
if (c.pipeline_stage != ast::PipelineStage::kCompute) { if (c.pipeline_stage != ast::PipelineStage::kCompute) {
GlobalVar("t2d", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Group(0_a), GlobalVar("t2d", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Group(0_a),

View File

@ -46,7 +46,7 @@ TEST_F(ResolverAddressSpaceUseTest, StructReachableFromParameter) {
auto* sem = TypeOf(s)->As<sem::Struct>(); auto* sem = TypeOf(s)->As<sem::Struct>();
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(type::AddressSpace::kUndefined)); EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(builtin::AddressSpace::kUndefined));
} }
TEST_F(ResolverAddressSpaceUseTest, StructReachableFromReturnType) { TEST_F(ResolverAddressSpaceUseTest, StructReachableFromReturnType) {
@ -58,55 +58,55 @@ TEST_F(ResolverAddressSpaceUseTest, StructReachableFromReturnType) {
auto* sem = TypeOf(s)->As<sem::Struct>(); auto* sem = TypeOf(s)->As<sem::Struct>();
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(type::AddressSpace::kUndefined)); EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(builtin::AddressSpace::kUndefined));
} }
TEST_F(ResolverAddressSpaceUseTest, StructReachableFromGlobal) { TEST_F(ResolverAddressSpaceUseTest, StructReachableFromGlobal) {
auto* s = Structure("S", utils::Vector{Member("a", ty.f32())}); auto* s = Structure("S", utils::Vector{Member("a", ty.f32())});
GlobalVar("g", ty.Of(s), type::AddressSpace::kPrivate); GlobalVar("g", ty.Of(s), builtin::AddressSpace::kPrivate);
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = TypeOf(s)->As<sem::Struct>(); auto* sem = TypeOf(s)->As<sem::Struct>();
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(type::AddressSpace::kPrivate)); EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(builtin::AddressSpace::kPrivate));
} }
TEST_F(ResolverAddressSpaceUseTest, StructReachableViaGlobalAlias) { TEST_F(ResolverAddressSpaceUseTest, StructReachableViaGlobalAlias) {
auto* s = Structure("S", utils::Vector{Member("a", ty.f32())}); auto* s = Structure("S", utils::Vector{Member("a", ty.f32())});
auto* a = Alias("A", ty.Of(s)); auto* a = Alias("A", ty.Of(s));
GlobalVar("g", ty.Of(a), type::AddressSpace::kPrivate); GlobalVar("g", ty.Of(a), builtin::AddressSpace::kPrivate);
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = TypeOf(s)->As<sem::Struct>(); auto* sem = TypeOf(s)->As<sem::Struct>();
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(type::AddressSpace::kPrivate)); EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(builtin::AddressSpace::kPrivate));
} }
TEST_F(ResolverAddressSpaceUseTest, StructReachableViaGlobalStruct) { TEST_F(ResolverAddressSpaceUseTest, StructReachableViaGlobalStruct) {
auto* s = Structure("S", utils::Vector{Member("a", ty.f32())}); auto* s = Structure("S", utils::Vector{Member("a", ty.f32())});
auto* o = Structure("O", utils::Vector{Member("a", ty.Of(s))}); auto* o = Structure("O", utils::Vector{Member("a", ty.Of(s))});
GlobalVar("g", ty.Of(o), type::AddressSpace::kPrivate); GlobalVar("g", ty.Of(o), builtin::AddressSpace::kPrivate);
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = TypeOf(s)->As<sem::Struct>(); auto* sem = TypeOf(s)->As<sem::Struct>();
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(type::AddressSpace::kPrivate)); EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(builtin::AddressSpace::kPrivate));
} }
TEST_F(ResolverAddressSpaceUseTest, StructReachableViaGlobalArray) { TEST_F(ResolverAddressSpaceUseTest, StructReachableViaGlobalArray) {
auto* s = Structure("S", utils::Vector{Member("a", ty.f32())}); auto* s = Structure("S", utils::Vector{Member("a", ty.f32())});
auto a = ty.array(ty.Of(s), 3_u); auto a = ty.array(ty.Of(s), 3_u);
GlobalVar("g", a, type::AddressSpace::kPrivate); GlobalVar("g", a, builtin::AddressSpace::kPrivate);
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = TypeOf(s)->As<sem::Struct>(); auto* sem = TypeOf(s)->As<sem::Struct>();
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(type::AddressSpace::kPrivate)); EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(builtin::AddressSpace::kPrivate));
} }
TEST_F(ResolverAddressSpaceUseTest, StructReachableFromLocal) { TEST_F(ResolverAddressSpaceUseTest, StructReachableFromLocal) {
@ -118,7 +118,7 @@ TEST_F(ResolverAddressSpaceUseTest, StructReachableFromLocal) {
auto* sem = TypeOf(s)->As<sem::Struct>(); auto* sem = TypeOf(s)->As<sem::Struct>();
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(type::AddressSpace::kFunction)); EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(builtin::AddressSpace::kFunction));
} }
TEST_F(ResolverAddressSpaceUseTest, StructReachableViaLocalAlias) { TEST_F(ResolverAddressSpaceUseTest, StructReachableViaLocalAlias) {
@ -130,7 +130,7 @@ TEST_F(ResolverAddressSpaceUseTest, StructReachableViaLocalAlias) {
auto* sem = TypeOf(s)->As<sem::Struct>(); auto* sem = TypeOf(s)->As<sem::Struct>();
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(type::AddressSpace::kFunction)); EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(builtin::AddressSpace::kFunction));
} }
TEST_F(ResolverAddressSpaceUseTest, StructReachableViaLocalStruct) { TEST_F(ResolverAddressSpaceUseTest, StructReachableViaLocalStruct) {
@ -142,7 +142,7 @@ TEST_F(ResolverAddressSpaceUseTest, StructReachableViaLocalStruct) {
auto* sem = TypeOf(s)->As<sem::Struct>(); auto* sem = TypeOf(s)->As<sem::Struct>();
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(type::AddressSpace::kFunction)); EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(builtin::AddressSpace::kFunction));
} }
TEST_F(ResolverAddressSpaceUseTest, StructReachableViaLocalArray) { TEST_F(ResolverAddressSpaceUseTest, StructReachableViaLocalArray) {
@ -154,13 +154,13 @@ TEST_F(ResolverAddressSpaceUseTest, StructReachableViaLocalArray) {
auto* sem = TypeOf(s)->As<sem::Struct>(); auto* sem = TypeOf(s)->As<sem::Struct>();
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(type::AddressSpace::kFunction)); EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(builtin::AddressSpace::kFunction));
} }
TEST_F(ResolverAddressSpaceUseTest, StructMultipleAddressSpaceUses) { TEST_F(ResolverAddressSpaceUseTest, StructMultipleAddressSpaceUses) {
auto* s = Structure("S", utils::Vector{Member("a", ty.f32())}); auto* s = Structure("S", utils::Vector{Member("a", ty.f32())});
GlobalVar("x", ty.Of(s), type::AddressSpace::kUniform, Binding(0_a), Group(0_a)); GlobalVar("x", ty.Of(s), builtin::AddressSpace::kUniform, Binding(0_a), Group(0_a));
GlobalVar("y", ty.Of(s), type::AddressSpace::kStorage, builtin::Access::kRead, Binding(1_a), GlobalVar("y", ty.Of(s), builtin::AddressSpace::kStorage, builtin::Access::kRead, Binding(1_a),
Group(0_a)); Group(0_a));
WrapInFunction(Var("g", ty.Of(s))); WrapInFunction(Var("g", ty.Of(s)));
@ -168,9 +168,9 @@ TEST_F(ResolverAddressSpaceUseTest, StructMultipleAddressSpaceUses) {
auto* sem = TypeOf(s)->As<sem::Struct>(); auto* sem = TypeOf(s)->As<sem::Struct>();
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
EXPECT_THAT(sem->AddressSpaceUsage(), EXPECT_THAT(sem->AddressSpaceUsage(), UnorderedElementsAre(builtin::AddressSpace::kUniform,
UnorderedElementsAre(type::AddressSpace::kUniform, type::AddressSpace::kStorage, builtin::AddressSpace::kStorage,
type::AddressSpace::kFunction)); builtin::AddressSpace::kFunction));
} }
} // namespace } // namespace

View File

@ -70,11 +70,11 @@ TEST_F(ResolverTypeInitializerValidationTest, InferTypeTest_Simple) {
ASSERT_TRUE(TypeOf(a_ident)->Is<type::Reference>()); ASSERT_TRUE(TypeOf(a_ident)->Is<type::Reference>());
EXPECT_TRUE(TypeOf(a_ident)->As<type::Reference>()->StoreType()->Is<type::I32>()); EXPECT_TRUE(TypeOf(a_ident)->As<type::Reference>()->StoreType()->Is<type::I32>());
EXPECT_EQ(TypeOf(a_ident)->As<type::Reference>()->AddressSpace(), EXPECT_EQ(TypeOf(a_ident)->As<type::Reference>()->AddressSpace(),
type::AddressSpace::kFunction); builtin::AddressSpace::kFunction);
ASSERT_TRUE(TypeOf(b_ident)->Is<type::Reference>()); ASSERT_TRUE(TypeOf(b_ident)->Is<type::Reference>());
EXPECT_TRUE(TypeOf(b_ident)->As<type::Reference>()->StoreType()->Is<type::I32>()); EXPECT_TRUE(TypeOf(b_ident)->As<type::Reference>()->StoreType()->Is<type::I32>());
EXPECT_EQ(TypeOf(b_ident)->As<type::Reference>()->AddressSpace(), EXPECT_EQ(TypeOf(b_ident)->As<type::Reference>()->AddressSpace(),
type::AddressSpace::kFunction); builtin::AddressSpace::kFunction);
} }
using InferTypeTest_FromInitializerExpression = ResolverTestWithParam<Params>; using InferTypeTest_FromInitializerExpression = ResolverTestWithParam<Params>;
@ -98,7 +98,7 @@ TEST_P(InferTypeTest_FromInitializerExpression, All) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* got = TypeOf(a_ident); auto* got = TypeOf(a_ident);
auto* expected = auto* expected =
create<type::Reference>(params.create_rhs_sem_type(*this), type::AddressSpace::kFunction, create<type::Reference>(params.create_rhs_sem_type(*this), builtin::AddressSpace::kFunction,
builtin::Access::kReadWrite); builtin::Access::kReadWrite);
ASSERT_EQ(got, expected) << "got: " << FriendlyName(got) << "\n" ASSERT_EQ(got, expected) << "got: " << FriendlyName(got) << "\n"
<< "expected: " << FriendlyName(expected) << "\n"; << "expected: " << FriendlyName(expected) << "\n";
@ -153,7 +153,7 @@ TEST_P(InferTypeTest_FromArithmeticExpression, All) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* got = TypeOf(a_ident); auto* got = TypeOf(a_ident);
auto* expected = auto* expected =
create<type::Reference>(params.create_rhs_sem_type(*this), type::AddressSpace::kFunction, create<type::Reference>(params.create_rhs_sem_type(*this), builtin::AddressSpace::kFunction,
builtin::Access::kReadWrite); builtin::Access::kReadWrite);
ASSERT_EQ(got, expected) << "got: " << FriendlyName(got) << "\n" ASSERT_EQ(got, expected) << "got: " << FriendlyName(got) << "\n"
<< "expected: " << FriendlyName(expected) << "\n"; << "expected: " << FriendlyName(expected) << "\n";
@ -202,7 +202,7 @@ TEST_P(InferTypeTest_FromCallExpression, All) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* got = TypeOf(a_ident); auto* got = TypeOf(a_ident);
auto* expected = auto* expected =
create<type::Reference>(params.create_rhs_sem_type(*this), type::AddressSpace::kFunction, create<type::Reference>(params.create_rhs_sem_type(*this), builtin::AddressSpace::kFunction,
builtin::Access::kReadWrite); builtin::Access::kReadWrite);
ASSERT_EQ(got, expected) << "got: " << FriendlyName(got) << "\n" ASSERT_EQ(got, expected) << "got: " << FriendlyName(got) << "\n"
<< "expected: " << FriendlyName(expected) << "\n"; << "expected: " << FriendlyName(expected) << "\n";
@ -1971,7 +1971,7 @@ TEST_F(ResolverTypeInitializerValidationTest, NestedVectorInitializers_Success)
TEST_F(ResolverTypeInitializerValidationTest, Vector_Alias_Argument_Error) { TEST_F(ResolverTypeInitializerValidationTest, Vector_Alias_Argument_Error) {
auto* alias = Alias("UnsignedInt", ty.u32()); auto* alias = Alias("UnsignedInt", ty.u32());
GlobalVar("uint_var", ty.Of(alias), type::AddressSpace::kPrivate); GlobalVar("uint_var", ty.Of(alias), builtin::AddressSpace::kPrivate);
auto* tc = vec2<f32>(Source{{12, 34}}, "uint_var"); auto* tc = vec2<f32>(Source{{12, 34}}, "uint_var");
WrapInFunction(tc); WrapInFunction(tc);
@ -1983,8 +1983,8 @@ TEST_F(ResolverTypeInitializerValidationTest, Vector_Alias_Argument_Error) {
TEST_F(ResolverTypeInitializerValidationTest, Vector_Alias_Argument_Success) { TEST_F(ResolverTypeInitializerValidationTest, Vector_Alias_Argument_Success) {
auto* f32_alias = Alias("Float32", ty.f32()); auto* f32_alias = Alias("Float32", ty.f32());
auto* vec2_alias = Alias("VectorFloat2", ty.vec2<f32>()); auto* vec2_alias = Alias("VectorFloat2", ty.vec2<f32>());
GlobalVar("my_f32", ty.Of(f32_alias), type::AddressSpace::kPrivate); GlobalVar("my_f32", ty.Of(f32_alias), builtin::AddressSpace::kPrivate);
GlobalVar("my_vec2", ty.Of(vec2_alias), type::AddressSpace::kPrivate); GlobalVar("my_vec2", ty.Of(vec2_alias), builtin::AddressSpace::kPrivate);
auto* tc = vec3<f32>("my_vec2", "my_f32"); auto* tc = vec3<f32>("my_vec2", "my_f32");
WrapInFunction(tc); WrapInFunction(tc);

View File

@ -95,7 +95,7 @@ TEST_F(ResolverTypeValidationTest, GlobalOverrideNoInitializer_Pass) {
TEST_F(ResolverTypeValidationTest, GlobalVariableWithAddressSpace_Pass) { TEST_F(ResolverTypeValidationTest, GlobalVariableWithAddressSpace_Pass) {
// var<private> global_var: f32; // var<private> global_var: f32;
GlobalVar(Source{{12, 34}}, "global_var", ty.f32(), type::AddressSpace::kPrivate); GlobalVar(Source{{12, 34}}, "global_var", ty.f32(), builtin::AddressSpace::kPrivate);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
@ -111,9 +111,10 @@ TEST_F(ResolverTypeValidationTest, GlobalVariableUnique_Pass) {
// var global_var0 : f32 = 0.1; // var global_var0 : f32 = 0.1;
// var global_var1 : i32 = 0; // var global_var1 : i32 = 0;
GlobalVar("global_var0", ty.f32(), type::AddressSpace::kPrivate, Expr(0.1_f)); GlobalVar("global_var0", ty.f32(), builtin::AddressSpace::kPrivate, Expr(0.1_f));
GlobalVar(Source{{12, 34}}, "global_var1", ty.f32(), type::AddressSpace::kPrivate, Expr(1_f)); GlobalVar(Source{{12, 34}}, "global_var1", ty.f32(), builtin::AddressSpace::kPrivate,
Expr(1_f));
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
@ -129,7 +130,7 @@ TEST_F(ResolverTypeValidationTest, GlobalVariableFunctionVariableNotUnique_Pass)
Decl(Var("a", ty.f32(), Expr(2_f))), Decl(Var("a", ty.f32(), Expr(2_f))),
}); });
GlobalVar("a", ty.f32(), type::AddressSpace::kPrivate, Expr(2.1_f)); GlobalVar("a", ty.f32(), builtin::AddressSpace::kPrivate, Expr(2.1_f));
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
@ -193,19 +194,22 @@ TEST_F(ResolverTypeValidationTest, RedeclaredIdentifierDifferentFunctions_Pass)
TEST_F(ResolverTypeValidationTest, ArraySize_AIntLiteral_Pass) { TEST_F(ResolverTypeValidationTest, ArraySize_AIntLiteral_Pass) {
// var<private> a : array<f32, 4>; // var<private> a : array<f32, 4>;
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 4_a)), type::AddressSpace::kPrivate); GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 4_a)),
builtin::AddressSpace::kPrivate);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverTypeValidationTest, ArraySize_UnsignedLiteral_Pass) { TEST_F(ResolverTypeValidationTest, ArraySize_UnsignedLiteral_Pass) {
// var<private> a : array<f32, 4u>; // var<private> a : array<f32, 4u>;
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 4_u)), type::AddressSpace::kPrivate); GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 4_u)),
builtin::AddressSpace::kPrivate);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverTypeValidationTest, ArraySize_SignedLiteral_Pass) { TEST_F(ResolverTypeValidationTest, ArraySize_SignedLiteral_Pass) {
// var<private> a : array<f32, 4i>; // var<private> a : array<f32, 4i>;
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 4_i)), type::AddressSpace::kPrivate); GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 4_i)),
builtin::AddressSpace::kPrivate);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
@ -214,7 +218,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_UnsignedConst_Pass) {
// var<private> a : array<f32, size>; // var<private> a : array<f32, size>;
GlobalConst("size", Expr(4_u)); GlobalConst("size", Expr(4_u));
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")), GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
@ -223,34 +227,38 @@ TEST_F(ResolverTypeValidationTest, ArraySize_SignedConst_Pass) {
// var<private> a : array<f32, size>; // var<private> a : array<f32, size>;
GlobalConst("size", Expr(4_i)); GlobalConst("size", Expr(4_i));
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")), GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverTypeValidationTest, ArraySize_AIntLiteral_Zero) { TEST_F(ResolverTypeValidationTest, ArraySize_AIntLiteral_Zero) {
// var<private> a : array<f32, 0>; // var<private> a : array<f32, 0>;
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 0_a)), type::AddressSpace::kPrivate); GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 0_a)),
builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: array count (0) must be greater than 0"); EXPECT_EQ(r()->error(), "12:34 error: array count (0) must be greater than 0");
} }
TEST_F(ResolverTypeValidationTest, ArraySize_UnsignedLiteral_Zero) { TEST_F(ResolverTypeValidationTest, ArraySize_UnsignedLiteral_Zero) {
// var<private> a : array<f32, 0u>; // var<private> a : array<f32, 0u>;
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 0_u)), type::AddressSpace::kPrivate); GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 0_u)),
builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: array count (0) must be greater than 0"); EXPECT_EQ(r()->error(), "12:34 error: array count (0) must be greater than 0");
} }
TEST_F(ResolverTypeValidationTest, ArraySize_SignedLiteral_Zero) { TEST_F(ResolverTypeValidationTest, ArraySize_SignedLiteral_Zero) {
// var<private> a : array<f32, 0i>; // var<private> a : array<f32, 0i>;
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 0_i)), type::AddressSpace::kPrivate); GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 0_i)),
builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: array count (0) must be greater than 0"); EXPECT_EQ(r()->error(), "12:34 error: array count (0) must be greater than 0");
} }
TEST_F(ResolverTypeValidationTest, ArraySize_SignedLiteral_Negative) { TEST_F(ResolverTypeValidationTest, ArraySize_SignedLiteral_Negative) {
// var<private> a : array<f32, -10i>; // var<private> a : array<f32, -10i>;
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, -10_i)), type::AddressSpace::kPrivate); GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, -10_i)),
builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: array count (-10) must be greater than 0"); EXPECT_EQ(r()->error(), "12:34 error: array count (-10) must be greater than 0");
} }
@ -260,7 +268,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_UnsignedConst_Zero) {
// var<private> a : array<f32, size>; // var<private> a : array<f32, size>;
GlobalConst("size", Expr(0_u)); GlobalConst("size", Expr(0_u));
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")), GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: array count (0) must be greater than 0"); EXPECT_EQ(r()->error(), "12:34 error: array count (0) must be greater than 0");
} }
@ -270,7 +278,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_SignedConst_Zero) {
// var<private> a : array<f32, size>; // var<private> a : array<f32, size>;
GlobalConst("size", Expr(0_i)); GlobalConst("size", Expr(0_i));
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")), GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: array count (0) must be greater than 0"); EXPECT_EQ(r()->error(), "12:34 error: array count (0) must be greater than 0");
} }
@ -280,14 +288,15 @@ TEST_F(ResolverTypeValidationTest, ArraySize_SignedConst_Negative) {
// var<private> a : array<f32, size>; // var<private> a : array<f32, size>;
GlobalConst("size", Expr(-10_i)); GlobalConst("size", Expr(-10_i));
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")), GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: array count (-10) must be greater than 0"); EXPECT_EQ(r()->error(), "12:34 error: array count (-10) must be greater than 0");
} }
TEST_F(ResolverTypeValidationTest, ArraySize_FloatLiteral) { TEST_F(ResolverTypeValidationTest, ArraySize_FloatLiteral) {
// var<private> a : array<f32, 10.0>; // var<private> a : array<f32, 10.0>;
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 10_f)), type::AddressSpace::kPrivate); GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 10_f)),
builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ( EXPECT_EQ(
r()->error(), r()->error(),
@ -298,7 +307,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_FloatLiteral) {
TEST_F(ResolverTypeValidationTest, ArraySize_IVecLiteral) { TEST_F(ResolverTypeValidationTest, ArraySize_IVecLiteral) {
// var<private> a : array<f32, vec2<i32>(10, 10)>; // var<private> a : array<f32, vec2<i32>(10, 10)>;
GlobalVar("a", ty.array(ty.f32(), Call(Source{{12, 34}}, ty.vec2<i32>(), 10_i, 10_i)), GlobalVar("a", ty.array(ty.f32(), Call(Source{{12, 34}}, ty.vec2<i32>(), 10_i, 10_i)),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ( EXPECT_EQ(
r()->error(), r()->error(),
@ -311,7 +320,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_FloatConst) {
// var<private> a : array<f32, size>; // var<private> a : array<f32, size>;
GlobalConst("size", Expr(10_f)); GlobalConst("size", Expr(10_f));
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")), GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ( EXPECT_EQ(
r()->error(), r()->error(),
@ -324,7 +333,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_IVecConst) {
// var<private> a : array<f32, size>; // var<private> a : array<f32, size>;
GlobalConst("size", Call(ty.vec2<i32>(), 100_i, 100_i)); GlobalConst("size", Call(ty.vec2<i32>(), 100_i, 100_i));
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")), GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ( EXPECT_EQ(
r()->error(), r()->error(),
@ -335,14 +344,14 @@ TEST_F(ResolverTypeValidationTest, ArraySize_IVecConst) {
TEST_F(ResolverTypeValidationTest, ArraySize_UnderElementCountLimit) { TEST_F(ResolverTypeValidationTest, ArraySize_UnderElementCountLimit) {
// var<private> a : array<f32, 65535>; // var<private> a : array<f32, 65535>;
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 65535_a)), GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 65535_a)),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverTypeValidationTest, ArraySize_OverElementCountLimit) { TEST_F(ResolverTypeValidationTest, ArraySize_OverElementCountLimit) {
// var<private> a : array<f32, 65536>; // var<private> a : array<f32, 65536>;
GlobalVar(Source{{56, 78}}, "a", ty.array(Source{{12, 34}}, ty.f32(), Expr(65536_a)), GlobalVar(Source{{56, 78}}, "a", ty.array(Source{{12, 34}}, ty.f32(), Expr(65536_a)),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), R"(12:34 error: array count (65536) must be less than 65536 EXPECT_EQ(r()->error(), R"(12:34 error: array count (65536) must be less than 65536
56:78 note: while instantiating 'var' a)"); 56:78 note: while instantiating 'var' a)");
@ -351,7 +360,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_OverElementCountLimit) {
TEST_F(ResolverTypeValidationTest, ArraySize_StorageBufferLargeArray) { TEST_F(ResolverTypeValidationTest, ArraySize_StorageBufferLargeArray) {
// var<storage> a : array<f32, 65536>; // var<storage> a : array<f32, 65536>;
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 65536_a)), GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, 65536_a)),
type::AddressSpace::kStorage, utils::Vector{Binding(0_u), Group(0_u)}); builtin::AddressSpace::kStorage, utils::Vector{Binding(0_u), Group(0_u)});
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
@ -362,7 +371,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_NestedStorageBufferLargeArray) {
// var<storage> a : S; // var<storage> a : S;
Structure("S", utils::Vector{Member(Source{{12, 34}}, "a", Structure("S", utils::Vector{Member(Source{{12, 34}}, "a",
ty.array(Source{{12, 20}}, ty.f32(), 65536_a))}); ty.array(Source{{12, 20}}, ty.f32(), 65536_a))});
GlobalVar("a", ty(Source{{12, 30}}, "S"), type::AddressSpace::kStorage, GlobalVar("a", ty(Source{{12, 30}}, "S"), builtin::AddressSpace::kStorage,
utils::Vector{Binding(0_u), Group(0_u)}); utils::Vector{Binding(0_u), Group(0_u)});
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
@ -375,7 +384,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_TooBig_ImplicitStride) {
Structure("S", utils::Vector{Member(Source{{12, 34}}, "a", ty.f32(), Structure("S", utils::Vector{Member(Source{{12, 34}}, "a", ty.f32(),
utils::Vector{MemberOffset(800000_a)})}); utils::Vector{MemberOffset(800000_a)})});
GlobalVar("a", ty.array(ty(Source{{12, 30}}, "S"), Expr(Source{{12, 34}}, 65535_a)), GlobalVar("a", ty.array(ty(Source{{12, 30}}, "S"), Expr(Source{{12, 34}}, 65535_a)),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
"12:34 error: array byte size (0xc34f7cafc) must not exceed 0xffffffff bytes"); "12:34 error: array byte size (0xc34f7cafc) must not exceed 0xffffffff bytes");
@ -385,7 +394,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_TooBig_ExplicitStride) {
// var<private> a : @stride(8000000) array<f32, 65535>; // var<private> a : @stride(8000000) array<f32, 65535>;
GlobalVar("a", GlobalVar("a",
ty.array(ty.f32(), Expr(Source{{12, 34}}, 65535_a), utils::Vector{Stride(8000000)}), ty.array(ty.f32(), Expr(Source{{12, 34}}, 65535_a), utils::Vector{Stride(8000000)}),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
"12:34 error: array byte size (0x7a1185ee00) must not exceed 0xffffffff bytes"); "12:34 error: array byte size (0x7a1185ee00) must not exceed 0xffffffff bytes");
@ -395,7 +404,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_NamedOverride_PrivateVar) {
// override size = 10i; // override size = 10i;
// var<private> a : array<f32, size>; // var<private> a : array<f32, size>;
Override("size", Expr(10_i)); Override("size", Expr(10_i));
GlobalVar("a", ty.array(Source{{12, 34}}, ty.f32(), "size"), type::AddressSpace::kPrivate); GlobalVar("a", ty.array(Source{{12, 34}}, ty.f32(), "size"), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
"12:34 error: array with an 'override' element count can only be used as the store " "12:34 error: array with an 'override' element count can only be used as the store "
@ -407,7 +416,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_NamedOverride_InArray) {
// var<workgroup> a : array<array<f32, size>, 4>; // var<workgroup> a : array<array<f32, size>, 4>;
Override("size", Expr(10_i)); Override("size", Expr(10_i));
GlobalVar("a", ty.array(ty.array(Source{{12, 34}}, ty.f32(), "size"), 4_a), GlobalVar("a", ty.array(ty.array(Source{{12, 34}}, ty.f32(), "size"), 4_a),
type::AddressSpace::kWorkgroup); builtin::AddressSpace::kWorkgroup);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
"12:34 error: array with an 'override' element count can only be used as the store " "12:34 error: array with an 'override' element count can only be used as the store "
@ -466,7 +475,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_NamedOverride_FunctionVar_Implicit)
// var a = w; // var a = w;
// } // }
Override("size", Expr(10_i)); Override("size", Expr(10_i));
GlobalVar("w", ty.array(ty.f32(), "size"), type::AddressSpace::kWorkgroup); GlobalVar("w", ty.array(ty.f32(), "size"), builtin::AddressSpace::kWorkgroup);
Func("f", utils::Empty, ty.void_(), Func("f", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
Decl(Var("a", Expr(Source{{12, 34}}, "w"))), Decl(Var("a", Expr(Source{{12, 34}}, "w"))),
@ -484,7 +493,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_NamedOverride_FunctionLet_Implicit)
// let a = w; // let a = w;
// } // }
Override("size", Expr(10_i)); Override("size", Expr(10_i));
GlobalVar("w", ty.array(ty.f32(), "size"), type::AddressSpace::kWorkgroup); GlobalVar("w", ty.array(ty.f32(), "size"), builtin::AddressSpace::kWorkgroup);
Func("f", utils::Empty, ty.void_(), Func("f", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
Decl(Let("a", Expr(Source{{12, 34}}, "w"))), Decl(Let("a", Expr(Source{{12, 34}}, "w"))),
@ -503,8 +512,8 @@ TEST_F(ResolverTypeValidationTest, ArraySize_UnnamedOverride_Equivalence) {
// a = b; // a = b;
// } // }
Override("size", Expr(10_i)); Override("size", Expr(10_i));
GlobalVar("a", ty.array(ty.f32(), Add("size", 1_i)), type::AddressSpace::kWorkgroup); GlobalVar("a", ty.array(ty.f32(), Add("size", 1_i)), builtin::AddressSpace::kWorkgroup);
GlobalVar("b", ty.array(ty.f32(), Add("size", 1_i)), type::AddressSpace::kWorkgroup); GlobalVar("b", ty.array(ty.f32(), Add("size", 1_i)), builtin::AddressSpace::kWorkgroup);
WrapInFunction(Assign(Source{{12, 34}}, "a", "b")); WrapInFunction(Assign(Source{{12, 34}}, "a", "b"));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -538,16 +547,16 @@ TEST_F(ResolverTypeValidationTest, ArraySize_Workgroup_Overridable) {
// var<workgroup> a : array<f32, size>; // var<workgroup> a : array<f32, size>;
Override("size", Expr(10_i)); Override("size", Expr(10_i));
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")), GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")),
type::AddressSpace::kWorkgroup); builtin::AddressSpace::kWorkgroup);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
TEST_F(ResolverTypeValidationTest, ArraySize_ModuleVar) { TEST_F(ResolverTypeValidationTest, ArraySize_ModuleVar) {
// var<private> size : i32 = 10i; // var<private> size : i32 = 10i;
// var<private> a : array<f32, size>; // var<private> a : array<f32, size>;
GlobalVar("size", ty.i32(), Expr(10_i), type::AddressSpace::kPrivate); GlobalVar("size", ty.i32(), Expr(10_i), builtin::AddressSpace::kPrivate);
GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")), GlobalVar("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
R"(12:34 error: var 'size' cannot be referenced at module-scope R"(12:34 error: var 'size' cannot be referenced at module-scope
@ -704,7 +713,7 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayInStructInArray) {
// var<private> a : array<Foo, 4>; // var<private> a : array<Foo, 4>;
Structure("Foo", utils::Vector{Member("rt", ty.array<f32>())}); Structure("Foo", utils::Vector{Member("rt", ty.array<f32>())});
GlobalVar("v", ty.array(ty(Source{{12, 34}}, "Foo"), 4_u), type::AddressSpace::kPrivate); GlobalVar("v", ty.array(ty(Source{{12, 34}}, "Foo"), 4_u), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()) << r()->error(); EXPECT_FALSE(r()->Resolve()) << r()->error();
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -750,7 +759,7 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayIsNotLast_Fail) {
TEST_F(ResolverTypeValidationTest, RuntimeArrayAsGlobalVariable) { TEST_F(ResolverTypeValidationTest, RuntimeArrayAsGlobalVariable) {
GlobalVar(Source{{56, 78}}, "g", ty.array(Source{{12, 34}}, ty.i32()), GlobalVar(Source{{56, 78}}, "g", ty.array(Source{{12, 34}}, ty.i32()),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -799,7 +808,7 @@ TEST_F(ResolverTypeValidationTest, PtrToRuntimeArrayAsPointerParameter_Fail) {
// fn func(a : ptr<workgroup, array<u32>>) {} // fn func(a : ptr<workgroup, array<u32>>) {}
auto* param = Param("a", ty.pointer(Source{{56, 78}}, ty.array(Source{{12, 34}}, ty.i32()), auto* param = Param("a", ty.pointer(Source{{56, 78}}, ty.array(Source{{12, 34}}, ty.i32()),
type::AddressSpace::kWorkgroup)); builtin::AddressSpace::kWorkgroup));
Func("func", utils::Vector{param}, ty.void_(), Func("func", utils::Vector{param}, ty.void_(),
utils::Vector{ utils::Vector{
@ -864,7 +873,7 @@ TEST_F(ResolverTypeValidationTest, AliasRuntimeArrayIsLast_Pass) {
TEST_F(ResolverTypeValidationTest, ArrayOfNonStorableType) { TEST_F(ResolverTypeValidationTest, ArrayOfNonStorableType) {
auto tex_ty = ty.sampled_texture(Source{{12, 34}}, type::TextureDimension::k2d, ty.f32()); auto tex_ty = ty.sampled_texture(Source{{12, 34}}, type::TextureDimension::k2d, ty.f32());
GlobalVar("arr", ty.array(tex_ty, 4_i), type::AddressSpace::kPrivate); GlobalVar("arr", ty.array(tex_ty, 4_i), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -872,9 +881,9 @@ TEST_F(ResolverTypeValidationTest, ArrayOfNonStorableType) {
} }
TEST_F(ResolverTypeValidationTest, ArrayOfNonStorableTypeWithStride) { TEST_F(ResolverTypeValidationTest, ArrayOfNonStorableTypeWithStride) {
auto ptr_ty = ty.pointer<u32>(Source{{12, 34}}, type::AddressSpace::kUniform); auto ptr_ty = ty.pointer<u32>(Source{{12, 34}}, builtin::AddressSpace::kUniform);
GlobalVar("arr", ty.array(ptr_ty, 4_i, utils::Vector{Stride(16)}), GlobalVar("arr", ty.array(ptr_ty, 4_i, utils::Vector{Stride(16)}),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -1235,7 +1244,7 @@ TEST_P(ValidMatrixTypes, Okay) {
ast::Type el_ty = params.elem_ty(*this); ast::Type el_ty = params.elem_ty(*this);
GlobalVar("a", ty.mat(el_ty, params.columns, params.rows), type::AddressSpace::kPrivate); GlobalVar("a", ty.mat(el_ty, params.columns, params.rows), builtin::AddressSpace::kPrivate);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest, INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest,
@ -1276,7 +1285,7 @@ TEST_P(InvalidMatrixElementTypes, InvalidElementType) {
ast::Type el_ty = params.elem_ty(*this); ast::Type el_ty = params.elem_ty(*this);
GlobalVar("a", ty.mat(Source{{12, 34}}, el_ty, params.columns, params.rows), GlobalVar("a", ty.mat(Source{{12, 34}}, el_ty, params.columns, params.rows),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: matrix element type must be 'f32' or 'f16'"); EXPECT_EQ(r()->error(), "12:34 error: matrix element type must be 'f32' or 'f16'");
} }
@ -1318,7 +1327,7 @@ TEST_P(ValidVectorTypes, Okay) {
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
GlobalVar("a", ty.vec(params.elem_ty(*this), params.width), type::AddressSpace::kPrivate); GlobalVar("a", ty.vec(params.elem_ty(*this), params.width), builtin::AddressSpace::kPrivate);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
} }
INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest, INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest,
@ -1353,7 +1362,7 @@ TEST_P(InvalidVectorElementTypes, InvalidElementType) {
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
GlobalVar("a", ty.vec(Source{{12, 34}}, params.elem_ty(*this), params.width), GlobalVar("a", ty.vec(Source{{12, 34}}, params.elem_ty(*this), params.width),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
"12:34 error: vector element type must be 'bool', 'f32', 'f16', 'i32' " "12:34 error: vector element type must be 'bool', 'f32', 'f16', 'i32' "
@ -1450,7 +1459,7 @@ TEST_P(ResolverUntemplatedTypeUsedWithTemplateArgs, Builtin_UseWithTemplateArgs)
// var<private> v : f32<true>; // var<private> v : f32<true>;
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
GlobalVar("v", type::AddressSpace::kPrivate, ty(Source{{12, 34}}, GetParam(), true)); GlobalVar("v", builtin::AddressSpace::kPrivate, ty(Source{{12, 34}}, GetParam(), true));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: type '" + std::string(GetParam()) + EXPECT_EQ(r()->error(), "12:34 error: type '" + std::string(GetParam()) +
@ -1464,7 +1473,7 @@ TEST_P(ResolverUntemplatedTypeUsedWithTemplateArgs, BuiltinAlias_UseWithTemplate
Enable(builtin::Extension::kF16); Enable(builtin::Extension::kF16);
Alias(Source{{56, 78}}, "A", ty(GetParam())); Alias(Source{{56, 78}}, "A", ty(GetParam()));
GlobalVar("v", type::AddressSpace::kPrivate, ty(Source{{12, 34}}, "A", true)); GlobalVar("v", builtin::AddressSpace::kPrivate, ty(Source{{12, 34}}, "A", true));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -1517,7 +1526,7 @@ TEST_F(ResolverUntemplatedTypeUsedWithTemplateArgs, Struct_UseWithTemplateArgs)
// var<private> v : S<true>; // var<private> v : S<true>;
Structure(Source{{56, 78}}, "S", utils::Vector{Member("i", ty.i32())}); Structure(Source{{56, 78}}, "S", utils::Vector{Member("i", ty.i32())});
GlobalVar("v", type::AddressSpace::kPrivate, ty(Source{{12, 34}}, "S", true)); GlobalVar("v", builtin::AddressSpace::kPrivate, ty(Source{{12, 34}}, "S", true));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),

View File

@ -1749,11 +1749,11 @@ class UniformityGraph {
auto var_type = [&](const sem::Variable* var) { auto var_type = [&](const sem::Variable* var) {
switch (var->AddressSpace()) { switch (var->AddressSpace()) {
case type::AddressSpace::kStorage: case builtin::AddressSpace::kStorage:
return "read_write storage buffer "; return "read_write storage buffer ";
case type::AddressSpace::kWorkgroup: case builtin::AddressSpace::kWorkgroup:
return "workgroup storage variable "; return "workgroup storage variable ";
case type::AddressSpace::kPrivate: case builtin::AddressSpace::kPrivate:
return "module-scope private variable "; return "module-scope private variable ";
default: default:
return ""; return "";

View File

@ -5301,8 +5301,8 @@ TEST_F(UniformityAnalysisTest, MaximumNumberOfPointerParameters) {
} }
foo_body.Push(b.Decl(b.Let("rhs", rhs_init))); foo_body.Push(b.Decl(b.Let("rhs", rhs_init)));
for (int i = 0; i < 255; i++) { for (int i = 0; i < 255; i++) {
params.Push( params.Push(b.Param("p" + std::to_string(i),
b.Param("p" + std::to_string(i), ty.pointer(ty.i32(), type::AddressSpace::kFunction))); ty.pointer(ty.i32(), builtin::AddressSpace::kFunction)));
if (i > 0) { if (i > 0) {
foo_body.Push(b.Assign(b.Deref("p" + std::to_string(i)), "rhs")); foo_body.Push(b.Assign(b.Deref("p" + std::to_string(i)), "rhs"));
} }
@ -5321,7 +5321,7 @@ TEST_F(UniformityAnalysisTest, MaximumNumberOfPointerParameters) {
// workgroupBarrier(); // workgroupBarrier();
// } // }
// } // }
b.GlobalVar("non_uniform_global", ty.i32(), type::AddressSpace::kPrivate); b.GlobalVar("non_uniform_global", ty.i32(), builtin::AddressSpace::kPrivate);
utils::Vector<const ast::Statement*, 8> main_body; utils::Vector<const ast::Statement*, 8> main_body;
utils::Vector<const ast::Expression*, 8> args; utils::Vector<const ast::Expression*, 8> args;
for (int i = 0; i < 255; i++) { for (int i = 0; i < 255; i++) {
@ -7847,7 +7847,7 @@ TEST_F(UniformityAnalysisTest, StressGraphTraversalDepth) {
// workgroupBarrier(); // workgroupBarrier();
// } // }
// } // }
b.GlobalVar("v0", ty.i32(), type::AddressSpace::kPrivate, b.Expr(0_i)); b.GlobalVar("v0", ty.i32(), builtin::AddressSpace::kPrivate, b.Expr(0_i));
utils::Vector<const ast::Statement*, 8> foo_body; utils::Vector<const ast::Statement*, 8> foo_body;
std::string v_last = "v0"; std::string v_last = "v0";
for (int i = 1; i < 100000; i++) { for (int i = 1; i < 100000; i++) {

View File

@ -62,8 +62,8 @@ class FakeExpr final : public Castable<FakeExpr, ast::Expression> {
}; };
TEST_F(ResolverValidationTest, WorkgroupMemoryUsedInVertexStage) { TEST_F(ResolverValidationTest, WorkgroupMemoryUsedInVertexStage) {
GlobalVar(Source{{1, 2}}, "wg", ty.vec4<f32>(), type::AddressSpace::kWorkgroup); GlobalVar(Source{{1, 2}}, "wg", ty.vec4<f32>(), builtin::AddressSpace::kWorkgroup);
GlobalVar("dst", ty.vec4<f32>(), type::AddressSpace::kPrivate); GlobalVar("dst", ty.vec4<f32>(), builtin::AddressSpace::kPrivate);
auto* stmt = Assign(Expr("dst"), Expr(Source{{3, 4}}, "wg")); auto* stmt = Assign(Expr("dst"), Expr(Source{{3, 4}}, "wg"));
Func(Source{{9, 10}}, "f0", utils::Empty, ty.vec4<f32>(), Func(Source{{9, 10}}, "f0", utils::Empty, ty.vec4<f32>(),
@ -94,8 +94,8 @@ TEST_F(ResolverValidationTest, WorkgroupMemoryUsedInFragmentStage) {
// f1(); // f1();
//} //}
GlobalVar(Source{{1, 2}}, "wg", ty.vec4<f32>(), type::AddressSpace::kWorkgroup); GlobalVar(Source{{1, 2}}, "wg", ty.vec4<f32>(), builtin::AddressSpace::kWorkgroup);
GlobalVar("dst", ty.vec4<f32>(), type::AddressSpace::kPrivate); GlobalVar("dst", ty.vec4<f32>(), builtin::AddressSpace::kPrivate);
auto* stmt = Assign(Expr("dst"), Expr(Source{{3, 4}}, "wg")); auto* stmt = Assign(Expr("dst"), Expr(Source{{3, 4}}, "wg"));
Func(Source{{5, 6}}, "f2", utils::Empty, ty.void_(), utils::Vector{stmt}); Func(Source{{5, 6}}, "f2", utils::Empty, ty.void_(), utils::Vector{stmt});
@ -192,7 +192,7 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableGlobalVariable_Pass) {
// return; // return;
// } // }
GlobalVar("global_var", ty.f32(), type::AddressSpace::kPrivate, Expr(2.1_f)); GlobalVar("global_var", ty.f32(), builtin::AddressSpace::kPrivate, Expr(2.1_f));
Func("my_func", utils::Empty, ty.void_(), Func("my_func", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
@ -266,7 +266,7 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableDifferentScope_Fail) {
} }
TEST_F(ResolverValidationTest, AddressSpace_FunctionVariableWorkgroupClass) { TEST_F(ResolverValidationTest, AddressSpace_FunctionVariableWorkgroupClass) {
auto* var = Var("var", ty.i32(), type::AddressSpace::kWorkgroup); auto* var = Var("var", ty.i32(), builtin::AddressSpace::kWorkgroup);
Func("func", utils::Empty, ty.void_(), Func("func", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
@ -280,7 +280,7 @@ TEST_F(ResolverValidationTest, AddressSpace_FunctionVariableWorkgroupClass) {
} }
TEST_F(ResolverValidationTest, AddressSpace_FunctionVariableI32) { TEST_F(ResolverValidationTest, AddressSpace_FunctionVariableI32) {
auto* var = Var("s", ty.i32(), type::AddressSpace::kPrivate); auto* var = Var("s", ty.i32(), builtin::AddressSpace::kPrivate);
Func("func", utils::Empty, ty.void_(), Func("func", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
@ -295,7 +295,8 @@ TEST_F(ResolverValidationTest, AddressSpace_FunctionVariableI32) {
TEST_F(ResolverValidationTest, AddressSpace_SamplerExplicitAddressSpace) { TEST_F(ResolverValidationTest, AddressSpace_SamplerExplicitAddressSpace) {
auto t = ty.sampler(type::SamplerKind::kSampler); auto t = ty.sampler(type::SamplerKind::kSampler);
GlobalVar(Source{{12, 34}}, "var", t, type::AddressSpace::kPrivate, Binding(0_a), Group(0_a)); GlobalVar(Source{{12, 34}}, "var", t, builtin::AddressSpace::kPrivate, Binding(0_a),
Group(0_a));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -305,7 +306,8 @@ TEST_F(ResolverValidationTest, AddressSpace_SamplerExplicitAddressSpace) {
TEST_F(ResolverValidationTest, AddressSpace_TextureExplicitAddressSpace) { TEST_F(ResolverValidationTest, AddressSpace_TextureExplicitAddressSpace) {
auto t = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); auto t = ty.sampled_texture(type::TextureDimension::k1d, ty.f32());
GlobalVar(Source{{12, 34}}, "var", t, type::AddressSpace::kFunction, Binding(0_a), Group(0_a)); GlobalVar(Source{{12, 34}}, "var", t, builtin::AddressSpace::kFunction, Binding(0_a),
Group(0_a));
EXPECT_FALSE(r()->Resolve()) << r()->error(); EXPECT_FALSE(r()->Resolve()) << r()->error();
@ -315,7 +317,7 @@ TEST_F(ResolverValidationTest, AddressSpace_TextureExplicitAddressSpace) {
} }
TEST_F(ResolverValidationTest, Expr_MemberAccessor_VectorSwizzle_BadChar) { TEST_F(ResolverValidationTest, Expr_MemberAccessor_VectorSwizzle_BadChar) {
GlobalVar("my_vec", ty.vec3<f32>(), type::AddressSpace::kPrivate); GlobalVar("my_vec", ty.vec3<f32>(), builtin::AddressSpace::kPrivate);
auto* mem = MemberAccessor("my_vec", Ident(Source{{{3, 3}, {3, 7}}}, "xyqz")); auto* mem = MemberAccessor("my_vec", Ident(Source{{{3, 3}, {3, 7}}}, "xyqz"));
WrapInFunction(mem); WrapInFunction(mem);
@ -325,7 +327,7 @@ TEST_F(ResolverValidationTest, Expr_MemberAccessor_VectorSwizzle_BadChar) {
} }
TEST_F(ResolverValidationTest, Expr_MemberAccessor_VectorSwizzle_MixedChars) { TEST_F(ResolverValidationTest, Expr_MemberAccessor_VectorSwizzle_MixedChars) {
GlobalVar("my_vec", ty.vec4<f32>(), type::AddressSpace::kPrivate); GlobalVar("my_vec", ty.vec4<f32>(), builtin::AddressSpace::kPrivate);
auto* mem = MemberAccessor("my_vec", Ident(Source{{{3, 3}, {3, 7}}}, "rgyw")); auto* mem = MemberAccessor("my_vec", Ident(Source{{{3, 3}, {3, 7}}}, "rgyw"));
WrapInFunction(mem); WrapInFunction(mem);
@ -336,7 +338,7 @@ TEST_F(ResolverValidationTest, Expr_MemberAccessor_VectorSwizzle_MixedChars) {
} }
TEST_F(ResolverValidationTest, Expr_MemberAccessor_VectorSwizzle_BadLength) { TEST_F(ResolverValidationTest, Expr_MemberAccessor_VectorSwizzle_BadLength) {
GlobalVar("my_vec", ty.vec3<f32>(), type::AddressSpace::kPrivate); GlobalVar("my_vec", ty.vec3<f32>(), builtin::AddressSpace::kPrivate);
auto* mem = MemberAccessor("my_vec", Ident(Source{{{3, 3}, {3, 8}}}, "zzzzz")); auto* mem = MemberAccessor("my_vec", Ident(Source{{{3, 3}, {3, 8}}}, "zzzzz"));
WrapInFunction(mem); WrapInFunction(mem);
@ -346,7 +348,7 @@ TEST_F(ResolverValidationTest, Expr_MemberAccessor_VectorSwizzle_BadLength) {
} }
TEST_F(ResolverValidationTest, Expr_MemberAccessor_VectorSwizzle_BadIndex) { TEST_F(ResolverValidationTest, Expr_MemberAccessor_VectorSwizzle_BadIndex) {
GlobalVar("my_vec", ty.vec2<f32>(), type::AddressSpace::kPrivate); GlobalVar("my_vec", ty.vec2<f32>(), builtin::AddressSpace::kPrivate);
auto* mem = MemberAccessor("my_vec", Ident(Source{{3, 3}}, "z")); auto* mem = MemberAccessor("my_vec", Ident(Source{{3, 3}}, "z"));
WrapInFunction(mem); WrapInFunction(mem);
@ -377,7 +379,7 @@ TEST_F(ResolverValidationTest, EXpr_MemberAccessor_FuncGoodParent) {
// let x: f32 = (*p).z; // let x: f32 = (*p).z;
// return x; // return x;
// } // }
auto* p = Param("p", ty.pointer(ty.vec4<f32>(), type::AddressSpace::kFunction)); auto* p = Param("p", ty.pointer(ty.vec4<f32>(), builtin::AddressSpace::kFunction));
auto* star_p = Deref(p); auto* star_p = Deref(p);
auto* accessor_expr = MemberAccessor(star_p, "z"); auto* accessor_expr = MemberAccessor(star_p, "z");
auto* x = Var("x", ty.f32(), accessor_expr); auto* x = Var("x", ty.f32(), accessor_expr);
@ -394,7 +396,7 @@ TEST_F(ResolverValidationTest, EXpr_MemberAccessor_FuncBadParent) {
// let x: f32 = *p.z; // let x: f32 = *p.z;
// return x; // return x;
// } // }
auto* p = Param("p", ty.pointer(ty.vec4<f32>(), type::AddressSpace::kFunction)); auto* p = Param("p", ty.pointer(ty.vec4<f32>(), builtin::AddressSpace::kFunction));
auto* accessor_expr = MemberAccessor(p, Ident(Source{{12, 34}}, "z")); auto* accessor_expr = MemberAccessor(p, Ident(Source{{12, 34}}, "z"));
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);
@ -1231,8 +1233,9 @@ TEST_F(ResolverValidationTest, OffsetAndAlignAndSizeAttribute) {
TEST_F(ResolverTest, Expr_Initializer_Cast_Pointer) { TEST_F(ResolverTest, Expr_Initializer_Cast_Pointer) {
auto* vf = Var("vf", ty.f32()); auto* vf = Var("vf", ty.f32());
auto* c = Call(Source{{12, 34}}, ty.pointer<i32>(type::AddressSpace::kFunction), ExprList(vf)); auto* c =
auto* ip = Let("ip", ty.pointer<i32>(type::AddressSpace::kFunction), c); Call(Source{{12, 34}}, ty.pointer<i32>(builtin::AddressSpace::kFunction), ExprList(vf));
auto* ip = Let("ip", ty.pointer<i32>(builtin::AddressSpace::kFunction), c);
WrapInFunction(Decl(vf), Decl(ip)); WrapInFunction(Decl(vf), Decl(ip));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -1240,21 +1243,22 @@ TEST_F(ResolverTest, Expr_Initializer_Cast_Pointer) {
} }
TEST_F(ResolverTest, I32_Overflow) { TEST_F(ResolverTest, I32_Overflow) {
GlobalVar("v", ty.i32(), type::AddressSpace::kPrivate, Expr(Source{{12, 24}}, 2147483648_a)); GlobalVar("v", ty.i32(), builtin::AddressSpace::kPrivate, Expr(Source{{12, 24}}, 2147483648_a));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), R"(12:24 error: value 2147483648 cannot be represented as 'i32')"); EXPECT_EQ(r()->error(), R"(12:24 error: value 2147483648 cannot be represented as 'i32')");
} }
TEST_F(ResolverTest, I32_Underflow) { TEST_F(ResolverTest, I32_Underflow) {
GlobalVar("v", ty.i32(), type::AddressSpace::kPrivate, Expr(Source{{12, 24}}, -2147483649_a)); GlobalVar("v", ty.i32(), builtin::AddressSpace::kPrivate,
Expr(Source{{12, 24}}, -2147483649_a));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), R"(12:24 error: value -2147483649 cannot be represented as 'i32')"); EXPECT_EQ(r()->error(), R"(12:24 error: value -2147483649 cannot be represented as 'i32')");
} }
TEST_F(ResolverTest, U32_Overflow) { TEST_F(ResolverTest, U32_Overflow) {
GlobalVar("v", ty.u32(), type::AddressSpace::kPrivate, Expr(Source{{12, 24}}, 4294967296_a)); GlobalVar("v", ty.u32(), builtin::AddressSpace::kPrivate, Expr(Source{{12, 24}}, 4294967296_a));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), R"(12:24 error: value 4294967296 cannot be represented as 'u32')"); EXPECT_EQ(r()->error(), R"(12:24 error: value 4294967296 cannot be represented as 'u32')");

View File

@ -288,7 +288,7 @@ bool Validator::Atomic(const ast::TemplatedIdentifier* a, const type::Atomic* s)
} }
bool Validator::Pointer(const ast::TemplatedIdentifier* a, const type::Pointer* s) const { bool Validator::Pointer(const ast::TemplatedIdentifier* a, const type::Pointer* s) const {
if (s->AddressSpace() == type::AddressSpace::kUndefined) { if (s->AddressSpace() == builtin::AddressSpace::kUndefined) {
AddError("ptr missing address space", a->source); AddError("ptr missing address space", a->source);
return false; return false;
} }
@ -298,7 +298,7 @@ bool Validator::Pointer(const ast::TemplatedIdentifier* a, const type::Pointer*
// When writing a variable declaration or a pointer type in WGSL source: // When writing a variable declaration or a pointer type in WGSL source:
// * For the storage address space, the access mode is optional, and defaults to read. // * For the storage address space, the access mode is optional, and defaults to read.
// * For other address spaces, the access mode must not be written. // * For other address spaces, the access mode must not be written.
if (s->AddressSpace() != type::AddressSpace::kStorage) { if (s->AddressSpace() != builtin::AddressSpace::kStorage) {
AddError("only pointers in <storage> address space may specify an access mode", AddError("only pointers in <storage> address space may specify an access mode",
a->source); a->source);
return false; return false;
@ -373,7 +373,7 @@ bool Validator::Materialize(const type::Type* to,
} }
bool Validator::VariableInitializer(const ast::Variable* v, bool Validator::VariableInitializer(const ast::Variable* v,
type::AddressSpace address_space, builtin::AddressSpace address_space,
const type::Type* storage_ty, const type::Type* storage_ty,
const sem::ValueExpression* initializer) const { const sem::ValueExpression* initializer) const {
auto* initializer_ty = initializer->Type(); auto* initializer_ty = initializer->Type();
@ -390,8 +390,8 @@ bool Validator::VariableInitializer(const ast::Variable* v,
if (v->Is<ast::Var>()) { if (v->Is<ast::Var>()) {
switch (address_space) { switch (address_space) {
case type::AddressSpace::kPrivate: case builtin::AddressSpace::kPrivate:
case type::AddressSpace::kFunction: case builtin::AddressSpace::kFunction:
break; // Allowed an initializer break; // Allowed an initializer
default: default:
// https://gpuweb.github.io/gpuweb/wgsl/#var-and-let // https://gpuweb.github.io/gpuweb/wgsl/#var-and-let
@ -409,17 +409,17 @@ bool Validator::VariableInitializer(const ast::Variable* v,
} }
bool Validator::AddressSpaceLayout(const type::Type* store_ty, bool Validator::AddressSpaceLayout(const type::Type* store_ty,
type::AddressSpace address_space, builtin::AddressSpace address_space,
Source source) const { Source source) const {
// https://gpuweb.github.io/gpuweb/wgsl/#storage-class-layout-constraints // https://gpuweb.github.io/gpuweb/wgsl/#storage-class-layout-constraints
auto is_uniform_struct_or_array = [address_space](const type::Type* ty) { auto is_uniform_struct_or_array = [address_space](const type::Type* ty) {
return address_space == type::AddressSpace::kUniform && return address_space == builtin::AddressSpace::kUniform &&
ty->IsAnyOf<type::Array, sem::Struct>(); ty->IsAnyOf<type::Array, sem::Struct>();
}; };
auto is_uniform_struct = [address_space](const type::Type* ty) { auto is_uniform_struct = [address_space](const type::Type* ty) {
return address_space == type::AddressSpace::kUniform && ty->Is<sem::Struct>(); return address_space == builtin::AddressSpace::kUniform && ty->Is<sem::Struct>();
}; };
auto required_alignment_of = [&](const type::Type* ty) { auto required_alignment_of = [&](const type::Type* ty) {
@ -440,7 +440,7 @@ bool Validator::AddressSpaceLayout(const type::Type* store_ty,
return true; return true;
} }
if (!type::IsHostShareable(address_space)) { if (!builtin::IsHostShareable(address_space)) {
return true; return true;
} }
@ -453,7 +453,7 @@ bool Validator::AddressSpaceLayout(const type::Type* store_ty,
// Among three host-shareable address spaces, f16 is supported in "uniform" and // Among three host-shareable address spaces, f16 is supported in "uniform" and
// "storage" address space, but not "push_constant" address space yet. // "storage" address space, but not "push_constant" address space yet.
if (Is<type::F16>(type::Type::DeepestElementOf(store_ty)) && if (Is<type::F16>(type::Type::DeepestElementOf(store_ty)) &&
address_space == type::AddressSpace::kPushConstant) { address_space == builtin::AddressSpace::kPushConstant) {
AddError("using f16 types in 'push_constant' address space is not implemented yet", source); AddError("using f16 types in 'push_constant' address space is not implemented yet", source);
return false; return false;
} }
@ -530,7 +530,7 @@ bool Validator::AddressSpaceLayout(const type::Type* store_ty,
return false; return false;
} }
if (address_space == type::AddressSpace::kUniform) { if (address_space == builtin::AddressSpace::kUniform) {
// We already validated that this array member is itself aligned to 16 bytes above, so // We already validated that this array member is itself aligned to 16 bytes above, so
// we only need to validate that stride is a multiple of 16 bytes. // we only need to validate that stride is a multiple of 16 bytes.
if (arr->Stride() % 16 != 0) { if (arr->Stride() % 16 != 0) {
@ -596,7 +596,7 @@ bool Validator::GlobalVariable(
const sem::GlobalVariable* global, const sem::GlobalVariable* global,
const utils::Hashmap<OverrideId, const sem::Variable*, 8>& override_ids) const { const utils::Hashmap<OverrideId, const sem::Variable*, 8>& override_ids) const {
auto* decl = global->Declaration(); auto* decl = global->Declaration();
if (global->AddressSpace() != type::AddressSpace::kWorkgroup && if (global->AddressSpace() != builtin::AddressSpace::kWorkgroup &&
IsArrayWithOverrideCount(global->Type())) { IsArrayWithOverrideCount(global->Type())) {
RaiseArrayWithOverrideCountError(decl->type ? decl->type->source RaiseArrayWithOverrideCountError(decl->type ? decl->type->source
: decl->initializer->source); : decl->initializer->source);
@ -624,8 +624,8 @@ bool Validator::GlobalVariable(
bool is_shader_io_attribute = bool is_shader_io_attribute =
attr->IsAnyOf<ast::BuiltinAttribute, ast::InterpolateAttribute, attr->IsAnyOf<ast::BuiltinAttribute, ast::InterpolateAttribute,
ast::InvariantAttribute, ast::LocationAttribute>(); ast::InvariantAttribute, ast::LocationAttribute>();
bool has_io_address_space = global->AddressSpace() == type::AddressSpace::kIn || bool has_io_address_space = global->AddressSpace() == builtin::AddressSpace::kIn ||
global->AddressSpace() == type::AddressSpace::kOut; global->AddressSpace() == builtin::AddressSpace::kOut;
if (!attr->IsAnyOf<ast::BindingAttribute, ast::GroupAttribute, if (!attr->IsAnyOf<ast::BindingAttribute, ast::GroupAttribute,
ast::InternalAttribute>() && ast::InternalAttribute>() &&
(!is_shader_io_attribute || !has_io_address_space)) { (!is_shader_io_attribute || !has_io_address_space)) {
@ -657,15 +657,15 @@ bool Validator::GlobalVariable(
return false; return false;
} }
if (global->AddressSpace() == type::AddressSpace::kFunction) { if (global->AddressSpace() == builtin::AddressSpace::kFunction) {
AddError("module-scope 'var' must not use address space 'function'", decl->source); AddError("module-scope 'var' must not use address space 'function'", decl->source);
return false; return false;
} }
switch (global->AddressSpace()) { switch (global->AddressSpace()) {
case type::AddressSpace::kUniform: case builtin::AddressSpace::kUniform:
case type::AddressSpace::kStorage: case builtin::AddressSpace::kStorage:
case type::AddressSpace::kHandle: { case builtin::AddressSpace::kHandle: {
// https://gpuweb.github.io/gpuweb/wgsl/#resource-interface // https://gpuweb.github.io/gpuweb/wgsl/#resource-interface
// Each resource variable must be declared with both group and binding attributes. // Each resource variable must be declared with both group and binding attributes.
if (!decl->HasBindingPoint()) { if (!decl->HasBindingPoint()) {
@ -714,7 +714,7 @@ bool Validator::Var(const sem::Variable* v) const {
// When writing a variable declaration or a pointer type in WGSL source: // When writing a variable declaration or a pointer type in WGSL source:
// * For the storage address space, the access mode is optional, and defaults to read. // * For the storage address space, the access mode is optional, and defaults to read.
// * For other address spaces, the access mode must not be written. // * For other address spaces, the access mode must not be written.
if (v->AddressSpace() != type::AddressSpace::kStorage) { if (v->AddressSpace() != builtin::AddressSpace::kStorage) {
AddError("only variables in <storage> address space may specify an access mode", AddError("only variables in <storage> address space may specify an access mode",
var->source); var->source);
return false; return false;
@ -727,8 +727,8 @@ bool Validator::Var(const sem::Variable* v) const {
} }
if (IsValidationEnabled(var->attributes, ast::DisabledValidation::kIgnoreAddressSpace) && if (IsValidationEnabled(var->attributes, ast::DisabledValidation::kIgnoreAddressSpace) &&
(v->AddressSpace() == type::AddressSpace::kIn || (v->AddressSpace() == builtin::AddressSpace::kIn ||
v->AddressSpace() == type::AddressSpace::kOut)) { v->AddressSpace() == builtin::AddressSpace::kOut)) {
AddError("invalid use of input/output address space", var->source); AddError("invalid use of input/output address space", var->source);
return false; return false;
} }
@ -822,13 +822,13 @@ bool Validator::Parameter(const ast::Function* func, const sem::Variable* var) c
auto sc = ref->AddressSpace(); auto sc = ref->AddressSpace();
switch (sc) { switch (sc) {
case type::AddressSpace::kFunction: case builtin::AddressSpace::kFunction:
case type::AddressSpace::kPrivate: case builtin::AddressSpace::kPrivate:
ok = true; ok = true;
break; break;
case type::AddressSpace::kStorage: case builtin::AddressSpace::kStorage:
case type::AddressSpace::kUniform: case builtin::AddressSpace::kUniform:
case type::AddressSpace::kWorkgroup: case builtin::AddressSpace::kWorkgroup:
ok = enabled_extensions_.Contains( ok = enabled_extensions_.Contains(
builtin::Extension::kChromiumExperimentalFullPtrParameters); builtin::Extension::kChromiumExperimentalFullPtrParameters);
break; break;
@ -1883,7 +1883,7 @@ bool Validator::PipelineStages(utils::VectorRef<sem::Function*> entry_points) co
auto stage = entry_point->Declaration()->PipelineStage(); auto stage = entry_point->Declaration()->PipelineStage();
if (stage != ast::PipelineStage::kCompute) { if (stage != ast::PipelineStage::kCompute) {
for (auto* var : func->DirectlyReferencedGlobals()) { for (auto* var : func->DirectlyReferencedGlobals()) {
if (var->AddressSpace() == type::AddressSpace::kWorkgroup) { if (var->AddressSpace() == builtin::AddressSpace::kWorkgroup) {
std::stringstream stage_name; std::stringstream stage_name;
stage_name << stage; stage_name << stage;
for (auto* user : var->Users()) { for (auto* user : var->Users()) {
@ -1969,7 +1969,7 @@ bool Validator::PushConstants(utils::VectorRef<sem::Function*> entry_points) con
auto check_push_constant = [&](const sem::Function* func, const sem::Function* ep) { auto check_push_constant = [&](const sem::Function* func, const sem::Function* ep) {
for (auto* var : func->DirectlyReferencedGlobals()) { for (auto* var : func->DirectlyReferencedGlobals()) {
if (var->AddressSpace() != type::AddressSpace::kPushConstant || if (var->AddressSpace() != builtin::AddressSpace::kPushConstant ||
var == push_constant_var) { var == push_constant_var) {
continue; continue;
} }
@ -2506,14 +2506,14 @@ std::string Validator::VectorPretty(uint32_t size, const type::Type* element_typ
bool Validator::CheckTypeAccessAddressSpace( bool Validator::CheckTypeAccessAddressSpace(
const type::Type* store_ty, const type::Type* store_ty,
builtin::Access access, builtin::Access access,
type::AddressSpace address_space, builtin::AddressSpace address_space,
utils::VectorRef<const tint::ast::Attribute*> attributes, utils::VectorRef<const tint::ast::Attribute*> attributes,
const Source& source) const { const Source& source) const {
if (!AddressSpaceLayout(store_ty, address_space, source)) { if (!AddressSpaceLayout(store_ty, address_space, source)) {
return false; return false;
} }
if (address_space == type::AddressSpace::kPushConstant && if (address_space == builtin::AddressSpace::kPushConstant &&
!enabled_extensions_.Contains(builtin::Extension::kChromiumExperimentalPushConstant) && !enabled_extensions_.Contains(builtin::Extension::kChromiumExperimentalPushConstant) &&
IsValidationEnabled(attributes, ast::DisabledValidation::kIgnoreAddressSpace)) { IsValidationEnabled(attributes, ast::DisabledValidation::kIgnoreAddressSpace)) {
AddError( AddError(
@ -2523,7 +2523,7 @@ bool Validator::CheckTypeAccessAddressSpace(
return false; return false;
} }
if (address_space == type::AddressSpace::kStorage && access == builtin::Access::kWrite) { if (address_space == builtin::AddressSpace::kStorage && access == builtin::Access::kWrite) {
// The access mode for the storage address space can only be 'read' or // The access mode for the storage address space can only be 'read' or
// 'read_write'. // 'read_write'.
AddError("access mode 'write' is not valid for the 'storage' address space", source); AddError("access mode 'write' is not valid for the 'storage' address space", source);
@ -2531,11 +2531,11 @@ bool Validator::CheckTypeAccessAddressSpace(
} }
auto atomic_error = [&]() -> const char* { auto atomic_error = [&]() -> const char* {
if (address_space != type::AddressSpace::kStorage && if (address_space != builtin::AddressSpace::kStorage &&
address_space != type::AddressSpace::kWorkgroup) { address_space != builtin::AddressSpace::kWorkgroup) {
return "atomic variables must have <storage> or <workgroup> address space"; return "atomic variables must have <storage> or <workgroup> address space";
} }
if (address_space == type::AddressSpace::kStorage && if (address_space == builtin::AddressSpace::kStorage &&
access != builtin::Access::kReadWrite) { access != builtin::Access::kReadWrite) {
return "atomic variables in <storage> address space must have read_write access " return "atomic variables in <storage> address space must have read_write access "
"mode"; "mode";

View File

@ -75,7 +75,7 @@ struct TypeAndAddressSpace {
/// The type /// The type
const type::Type* type; const type::Type* type;
/// The address space /// The address space
type::AddressSpace address_space; builtin::AddressSpace address_space;
/// Equality operator /// Equality operator
/// @param other the other TypeAndAddressSpace to compare this TypeAndAddressSpace to /// @param other the other TypeAndAddressSpace to compare this TypeAndAddressSpace to
@ -435,7 +435,7 @@ class Validator {
/// @param initializer the RHS initializer expression /// @param initializer the RHS initializer expression
/// @returns true on succes, false otherwise /// @returns true on succes, false otherwise
bool VariableInitializer(const ast::Variable* v, bool VariableInitializer(const ast::Variable* v,
type::AddressSpace address_space, builtin::AddressSpace address_space,
const type::Type* storage_type, const type::Type* storage_type,
const sem::ValueExpression* initializer) const; const sem::ValueExpression* initializer) const;
@ -488,7 +488,7 @@ class Validator {
/// @param sc the address space /// @param sc the address space
/// @param source the source of the type /// @param source the source of the type
/// @returns true on success, false otherwise /// @returns true on success, false otherwise
bool AddressSpaceLayout(const type::Type* type, type::AddressSpace sc, Source source) const; bool AddressSpaceLayout(const type::Type* type, builtin::AddressSpace sc, Source source) const;
/// @returns true if the attribute list contains a /// @returns true if the attribute list contains a
/// ast::DisableValidationAttribute with the validation mode equal to /// ast::DisableValidationAttribute with the validation mode equal to
@ -543,7 +543,7 @@ class Validator {
/// @returns true on success, false if an error was raised. /// @returns true on success, false if an error was raised.
bool CheckTypeAccessAddressSpace(const type::Type* store_ty, bool CheckTypeAccessAddressSpace(const type::Type* store_ty,
builtin::Access access, builtin::Access access,
type::AddressSpace address_space, builtin::AddressSpace address_space,
utils::VectorRef<const tint::ast::Attribute*> attributes, utils::VectorRef<const tint::ast::Attribute*> attributes,
const Source& source) const; const Source& source) const;
SymbolTable& symbols_; SymbolTable& symbols_;

View File

@ -78,7 +78,7 @@ TEST_F(ValidatorIsStorableTest, Matrix) {
} }
TEST_F(ValidatorIsStorableTest, Pointer) { TEST_F(ValidatorIsStorableTest, Pointer) {
auto* ptr = create<type::Pointer>(create<type::I32>(), type::AddressSpace::kPrivate, auto* ptr = create<type::Pointer>(create<type::I32>(), builtin::AddressSpace::kPrivate,
builtin::Access::kReadWrite); builtin::Access::kReadWrite);
EXPECT_FALSE(v()->IsStorable(ptr)); EXPECT_FALSE(v()->IsStorable(ptr));
} }

View File

@ -238,7 +238,7 @@ TEST_F(ResolverVariableTest, LocalVar_ShadowsGlobalVar) {
// var a = a; // var a = a;
// } // }
auto* g = GlobalVar("a", ty.i32(), type::AddressSpace::kPrivate); auto* g = GlobalVar("a", ty.i32(), builtin::AddressSpace::kPrivate);
auto* v = Var("a", Expr("a")); auto* v = Var("a", Expr("a"));
Func("F", utils::Empty, ty.void_(), utils::Vector{Decl(v)}); Func("F", utils::Empty, ty.void_(), utils::Vector{Decl(v)});
@ -421,7 +421,7 @@ TEST_F(ResolverVariableTest, LocalLet) {
auto* b = Let("b", ty.bool_(), b_c); auto* b = Let("b", ty.bool_(), b_c);
auto* s = Let("s", ty.Of(S), s_c); auto* s = Let("s", ty.Of(S), s_c);
auto* a = Let("a", ty.Of(A), a_c); auto* a = Let("a", ty.Of(A), a_c);
auto* p = Let("p", ty.pointer<i32>(type::AddressSpace::kFunction), p_c); auto* p = Let("p", ty.pointer<i32>(builtin::AddressSpace::kFunction), p_c);
Func("F", utils::Empty, ty.void_(), Func("F", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
@ -472,7 +472,7 @@ TEST_F(ResolverVariableTest, LocalLet_InheritsAccessFromOriginatingVariable) {
// } // }
auto* inner = Structure("Inner", utils::Vector{Member("arr", ty.array<i32, 4>())}); auto* inner = Structure("Inner", utils::Vector{Member("arr", ty.array<i32, 4>())});
auto* buf = Structure("S", utils::Vector{Member("inner", ty.Of(inner))}); auto* buf = Structure("S", utils::Vector{Member("inner", ty.Of(inner))});
auto* storage = GlobalVar("s", ty.Of(buf), type::AddressSpace::kStorage, auto* storage = GlobalVar("s", ty.Of(buf), builtin::AddressSpace::kStorage,
builtin::Access::kReadWrite, Binding(0_a), Group(0_a)); builtin::Access::kReadWrite, Binding(0_a), Group(0_a));
auto* expr = IndexAccessor(MemberAccessor(MemberAccessor(storage, "inner"), "arr"), 3_i); auto* expr = IndexAccessor(MemberAccessor(MemberAccessor(storage, "inner"), "arr"), 3_i);
@ -554,7 +554,7 @@ TEST_F(ResolverVariableTest, LocalLet_ShadowsGlobalVar) {
// let a = a; // let a = a;
// } // }
auto* g = GlobalVar("a", ty.i32(), type::AddressSpace::kPrivate); auto* g = GlobalVar("a", ty.i32(), builtin::AddressSpace::kPrivate);
auto* l = Let("a", Expr("a")); auto* l = Let("a", Expr("a"));
Func("F", utils::Empty, ty.void_(), utils::Vector{Decl(l)}); Func("F", utils::Empty, ty.void_(), utils::Vector{Decl(l)});
@ -766,7 +766,7 @@ TEST_F(ResolverVariableTest, LocalConst_ShadowsGlobalVar) {
// const a = 1i; // const a = 1i;
// } // }
auto* g = GlobalVar("a", ty.i32(), type::AddressSpace::kPrivate); auto* g = GlobalVar("a", ty.i32(), builtin::AddressSpace::kPrivate);
auto* c = Const("a", Expr(1_i)); auto* c = Const("a", Expr(1_i));
Func("F", utils::Empty, ty.void_(), utils::Vector{Decl(c)}); Func("F", utils::Empty, ty.void_(), utils::Vector{Decl(c)});
@ -1037,12 +1037,12 @@ TEST_F(ResolverVariableTest, GlobalVar_AddressSpace) {
// https://gpuweb.github.io/gpuweb/wgsl/#storage-class // https://gpuweb.github.io/gpuweb/wgsl/#storage-class
auto* buf = Structure("S", utils::Vector{Member("m", ty.i32())}); auto* buf = Structure("S", utils::Vector{Member("m", ty.i32())});
auto* private_ = GlobalVar("p", ty.i32(), type::AddressSpace::kPrivate); auto* private_ = GlobalVar("p", ty.i32(), builtin::AddressSpace::kPrivate);
auto* workgroup = GlobalVar("w", ty.i32(), type::AddressSpace::kWorkgroup); auto* workgroup = GlobalVar("w", ty.i32(), builtin::AddressSpace::kWorkgroup);
auto* uniform = auto* uniform =
GlobalVar("ub", ty.Of(buf), type::AddressSpace::kUniform, Binding(0_a), Group(0_a)); GlobalVar("ub", ty.Of(buf), builtin::AddressSpace::kUniform, Binding(0_a), Group(0_a));
auto* storage = auto* storage =
GlobalVar("sb", ty.Of(buf), type::AddressSpace::kStorage, Binding(1_a), Group(0_a)); GlobalVar("sb", ty.Of(buf), builtin::AddressSpace::kStorage, Binding(1_a), Group(0_a));
auto* handle = auto* handle =
GlobalVar("h", ty.depth_texture(type::TextureDimension::k2d), Binding(2_a), Group(0_a)); GlobalVar("h", ty.depth_texture(type::TextureDimension::k2d), Binding(2_a), Group(0_a));
@ -1065,7 +1065,7 @@ TEST_F(ResolverVariableTest, GlobalVar_ExplicitAddressSpace) {
// https://gpuweb.github.io/gpuweb/wgsl/#storage-class // https://gpuweb.github.io/gpuweb/wgsl/#storage-class
auto* buf = Structure("S", utils::Vector{Member("m", ty.i32())}); auto* buf = Structure("S", utils::Vector{Member("m", ty.i32())});
auto* storage = GlobalVar("sb", ty.Of(buf), type::AddressSpace::kStorage, auto* storage = GlobalVar("sb", ty.Of(buf), builtin::AddressSpace::kStorage,
builtin::Access::kReadWrite, Binding(1_a), Group(0_a)); builtin::Access::kReadWrite, Binding(1_a), Group(0_a));
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -1222,7 +1222,7 @@ TEST_F(ResolverVariableTest, Param_ShadowsGlobalVar) {
// fn F(a : bool) { // fn F(a : bool) {
// } // }
auto* g = GlobalVar("a", ty.i32(), type::AddressSpace::kPrivate); auto* g = GlobalVar("a", ty.i32(), builtin::AddressSpace::kPrivate);
auto* p = Param("a", ty.bool_()); auto* p = Param("a", ty.bool_());
Func("F", utils::Vector{p}, ty.void_(), utils::Empty); Func("F", utils::Vector{p}, ty.void_(), utils::Empty);

View File

@ -61,8 +61,8 @@ TEST_F(ResolverVariableValidationTest, GlobalVarInitializerNoReturnValueBuiltin)
TEST_F(ResolverVariableValidationTest, GlobalVarUsedAtModuleScope) { TEST_F(ResolverVariableValidationTest, GlobalVarUsedAtModuleScope) {
// var<private> a : i32; // var<private> a : i32;
// var<private> b : i32 = a; // var<private> b : i32 = a;
GlobalVar(Source{{12, 34}}, "a", ty.i32(), type::AddressSpace::kPrivate); GlobalVar(Source{{12, 34}}, "a", ty.i32(), builtin::AddressSpace::kPrivate);
GlobalVar("b", ty.i32(), type::AddressSpace::kPrivate, Expr(Source{{56, 78}}, "a")); GlobalVar("b", ty.i32(), builtin::AddressSpace::kPrivate, Expr(Source{{56, 78}}, "a"));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), R"(56:78 error: var 'a' cannot be referenced at module-scope EXPECT_EQ(r()->error(), R"(56:78 error: var 'a' cannot be referenced at module-scope
@ -112,8 +112,8 @@ TEST_F(ResolverVariableValidationTest, VarTypeNotConstructible) {
// var i : i32; // var i : i32;
// var p : pointer<function, i32> = &v; // var p : pointer<function, i32> = &v;
auto* i = Var("i", ty.i32()); auto* i = Var("i", ty.i32());
auto* p = Var("a", ty.pointer<i32>(Source{{56, 78}}, type::AddressSpace::kFunction), auto* p = Var("a", ty.pointer<i32>(Source{{56, 78}}, builtin::AddressSpace::kFunction),
type::AddressSpace::kUndefined, AddressOf(Source{{12, 34}}, "i")); builtin::AddressSpace::kUndefined, AddressOf(Source{{12, 34}}, "i"));
WrapInFunction(i, p); WrapInFunction(i, p);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -205,7 +205,7 @@ TEST_F(ResolverVariableValidationTest, VarInitializerWrongTypeViaAlias) {
TEST_F(ResolverVariableValidationTest, LetOfPtrConstructedWithRef) { TEST_F(ResolverVariableValidationTest, LetOfPtrConstructedWithRef) {
// var a : f32; // var a : f32;
// let b : ptr<function,f32> = a; // let b : ptr<function,f32> = a;
const auto priv = type::AddressSpace::kFunction; const auto priv = builtin::AddressSpace::kFunction;
auto* var_a = Var("a", ty.f32(), priv); auto* var_a = Var("a", ty.f32(), priv);
auto* var_b = Let(Source{{12, 34}}, "b", ty.pointer<f32>(priv), Expr("a")); auto* var_b = Let(Source{{12, 34}}, "b", ty.pointer<f32>(priv), Expr("a"));
WrapInFunction(var_a, var_b); WrapInFunction(var_a, var_b);
@ -236,7 +236,7 @@ TEST_F(ResolverVariableValidationTest, GlobalVarRedeclaredAsLocal) {
// return 0; // return 0;
// } // }
GlobalVar("v", ty.f32(), type::AddressSpace::kPrivate, Expr(2.1_f)); GlobalVar("v", ty.f32(), builtin::AddressSpace::kPrivate, Expr(2.1_f));
WrapInFunction(Var(Source{{12, 34}}, "v", ty.f32(), Expr(2_f))); WrapInFunction(Var(Source{{12, 34}}, "v", ty.f32(), Expr(2_f)));
@ -295,11 +295,11 @@ TEST_F(ResolverVariableValidationTest, InferredPtrStorageAccessMismatch) {
Member("inner", ty.Of(inner)), Member("inner", ty.Of(inner)),
}); });
auto* storage = auto* storage =
GlobalVar("s", ty.Of(buf), type::AddressSpace::kStorage, Binding(0_a), Group(0_a)); GlobalVar("s", ty.Of(buf), builtin::AddressSpace::kStorage, Binding(0_a), Group(0_a));
auto* expr = IndexAccessor(MemberAccessor(MemberAccessor(storage, "inner"), "arr"), 2_i); auto* expr = IndexAccessor(MemberAccessor(MemberAccessor(storage, "inner"), "arr"), 2_i);
auto* ptr = Let(Source{{12, 34}}, "p", auto* ptr = Let(Source{{12, 34}}, "p",
ty.pointer<i32>(type::AddressSpace::kStorage, builtin::Access::kReadWrite), ty.pointer<i32>(builtin::AddressSpace::kStorage, builtin::Access::kReadWrite),
AddressOf(expr)); AddressOf(expr));
WrapInFunction(ptr); WrapInFunction(ptr);
@ -359,7 +359,7 @@ TEST_F(ResolverVariableValidationTest, NonConstructibleType_InferredType) {
TEST_F(ResolverVariableValidationTest, InvalidAddressSpaceForInitializer) { TEST_F(ResolverVariableValidationTest, InvalidAddressSpaceForInitializer) {
// var<workgroup> v : f32 = 1.23; // var<workgroup> v : f32 = 1.23;
GlobalVar(Source{{12, 34}}, "v", ty.f32(), type::AddressSpace::kWorkgroup, Expr(1.23_f)); GlobalVar(Source{{12, 34}}, "v", ty.f32(), builtin::AddressSpace::kWorkgroup, Expr(1.23_f));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
@ -489,7 +489,7 @@ TEST_F(ResolverVariableValidationTest, GlobalVariable_PushConstantWithInitialize
// enable chromium_experimental_push_constant; // enable chromium_experimental_push_constant;
// var<push_constant> a : u32 = 0u; // var<push_constant> a : u32 = 0u;
Enable(builtin::Extension::kChromiumExperimentalPushConstant); Enable(builtin::Extension::kChromiumExperimentalPushConstant);
GlobalVar(Source{{1u, 2u}}, "a", ty.u32(), type::AddressSpace::kPushConstant, GlobalVar(Source{{1u, 2u}}, "a", ty.u32(), builtin::AddressSpace::kPushConstant,
Expr(Source{{3u, 4u}}, u32(0))); Expr(Source{{3u, 4u}}, u32(0)));
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());

View File

@ -69,7 +69,7 @@ Function::VariableBindings Function::TransitivelyReferencedUniformVariables() co
VariableBindings ret; VariableBindings ret;
for (auto* global : TransitivelyReferencedGlobals()) { for (auto* global : TransitivelyReferencedGlobals()) {
if (global->AddressSpace() != type::AddressSpace::kUniform) { if (global->AddressSpace() != builtin::AddressSpace::kUniform) {
continue; continue;
} }
@ -84,7 +84,7 @@ Function::VariableBindings Function::TransitivelyReferencedStorageBufferVariable
VariableBindings ret; VariableBindings ret;
for (auto* global : TransitivelyReferencedGlobals()) { for (auto* global : TransitivelyReferencedGlobals()) {
if (global->AddressSpace() != type::AddressSpace::kStorage) { if (global->AddressSpace() != builtin::AddressSpace::kStorage) {
continue; continue;
} }

View File

@ -18,8 +18,8 @@
#include <optional> #include <optional>
#include "src/tint/ast/struct.h" #include "src/tint/ast/struct.h"
#include "src/tint/builtin/address_space.h"
#include "src/tint/symbol.h" #include "src/tint/symbol.h"
#include "src/tint/type/address_space.h"
#include "src/tint/type/struct.h" #include "src/tint/type/struct.h"
#include "src/tint/type/type.h" #include "src/tint/type/type.h"
#include "src/tint/utils/vector.h" #include "src/tint/utils/vector.h"

View File

@ -31,7 +31,7 @@ namespace tint::sem {
Variable::Variable(const ast::Variable* declaration, Variable::Variable(const ast::Variable* declaration,
const type::Type* type, const type::Type* type,
EvaluationStage stage, EvaluationStage stage,
type::AddressSpace address_space, builtin::AddressSpace address_space,
builtin::Access access, builtin::Access access,
const constant::Value* constant_value) const constant::Value* constant_value)
: declaration_(declaration), : declaration_(declaration),
@ -46,7 +46,7 @@ Variable::~Variable() = default;
LocalVariable::LocalVariable(const ast::Variable* declaration, LocalVariable::LocalVariable(const ast::Variable* declaration,
const type::Type* type, const type::Type* type,
EvaluationStage stage, EvaluationStage stage,
type::AddressSpace address_space, builtin::AddressSpace address_space,
builtin::Access access, builtin::Access access,
const sem::Statement* statement, const sem::Statement* statement,
const constant::Value* constant_value) const constant::Value* constant_value)
@ -58,7 +58,7 @@ LocalVariable::~LocalVariable() = default;
GlobalVariable::GlobalVariable(const ast::Variable* declaration, GlobalVariable::GlobalVariable(const ast::Variable* declaration,
const type::Type* type, const type::Type* type,
EvaluationStage stage, EvaluationStage stage,
type::AddressSpace address_space, builtin::AddressSpace address_space,
builtin::Access access, builtin::Access access,
const constant::Value* constant_value, const constant::Value* constant_value,
sem::BindingPoint binding_point, sem::BindingPoint binding_point,
@ -72,7 +72,7 @@ GlobalVariable::~GlobalVariable() = default;
Parameter::Parameter(const ast::Parameter* declaration, Parameter::Parameter(const ast::Parameter* declaration,
uint32_t index, uint32_t index,
const type::Type* type, const type::Type* type,
type::AddressSpace address_space, builtin::AddressSpace address_space,
builtin::Access access, builtin::Access access,
const ParameterUsage usage /* = ParameterUsage::kNone */, const ParameterUsage usage /* = ParameterUsage::kNone */,
sem::BindingPoint binding_point /* = {} */, sem::BindingPoint binding_point /* = {} */,

View File

@ -23,10 +23,10 @@
#include "src/tint/ast/parameter.h" #include "src/tint/ast/parameter.h"
#include "src/tint/builtin/access.h" #include "src/tint/builtin/access.h"
#include "src/tint/builtin/address_space.h"
#include "src/tint/sem/binding_point.h" #include "src/tint/sem/binding_point.h"
#include "src/tint/sem/parameter_usage.h" #include "src/tint/sem/parameter_usage.h"
#include "src/tint/sem/value_expression.h" #include "src/tint/sem/value_expression.h"
#include "src/tint/type/address_space.h"
#include "src/tint/type/type.h" #include "src/tint/type/type.h"
#include "src/tint/utils/unique_vector.h" #include "src/tint/utils/unique_vector.h"
@ -57,7 +57,7 @@ class Variable : public Castable<Variable, Node> {
Variable(const ast::Variable* declaration, Variable(const ast::Variable* declaration,
const type::Type* type, const type::Type* type,
EvaluationStage stage, EvaluationStage stage,
type::AddressSpace address_space, builtin::AddressSpace address_space,
builtin::Access access, builtin::Access access,
const constant::Value* constant_value); const constant::Value* constant_value);
@ -74,7 +74,7 @@ class Variable : public Castable<Variable, Node> {
EvaluationStage Stage() const { return stage_; } EvaluationStage Stage() const { return stage_; }
/// @returns the address space for the variable /// @returns the address space for the variable
type::AddressSpace AddressSpace() const { return address_space_; } builtin::AddressSpace AddressSpace() const { return address_space_; }
/// @returns the access control for the variable /// @returns the access control for the variable
builtin::Access Access() const { return access_; } builtin::Access Access() const { return access_; }
@ -100,7 +100,7 @@ class Variable : public Castable<Variable, Node> {
const ast::Variable* const declaration_; const ast::Variable* const declaration_;
const type::Type* const type_; const type::Type* const type_;
const EvaluationStage stage_; const EvaluationStage stage_;
const type::AddressSpace address_space_; const builtin::AddressSpace address_space_;
const builtin::Access access_; const builtin::Access access_;
const constant::Value* constant_value_; const constant::Value* constant_value_;
const ValueExpression* initializer_ = nullptr; const ValueExpression* initializer_ = nullptr;
@ -121,7 +121,7 @@ class LocalVariable final : public Castable<LocalVariable, Variable> {
LocalVariable(const ast::Variable* declaration, LocalVariable(const ast::Variable* declaration,
const type::Type* type, const type::Type* type,
EvaluationStage stage, EvaluationStage stage,
type::AddressSpace address_space, builtin::AddressSpace address_space,
builtin::Access access, builtin::Access access,
const sem::Statement* statement, const sem::Statement* statement,
const constant::Value* constant_value); const constant::Value* constant_value);
@ -162,7 +162,7 @@ class GlobalVariable final : public Castable<GlobalVariable, Variable> {
GlobalVariable(const ast::Variable* declaration, GlobalVariable(const ast::Variable* declaration,
const type::Type* type, const type::Type* type,
EvaluationStage stage, EvaluationStage stage,
type::AddressSpace address_space, builtin::AddressSpace address_space,
builtin::Access access, builtin::Access access,
const constant::Value* constant_value, const constant::Value* constant_value,
sem::BindingPoint binding_point = {}, sem::BindingPoint binding_point = {},
@ -205,7 +205,7 @@ class Parameter final : public Castable<Parameter, Variable> {
Parameter(const ast::Parameter* declaration, Parameter(const ast::Parameter* declaration,
uint32_t index, uint32_t index,
const type::Type* type, const type::Type* type,
type::AddressSpace address_space, builtin::AddressSpace address_space,
builtin::Access access, builtin::Access access,
const ParameterUsage usage = ParameterUsage::kNone, const ParameterUsage usage = ParameterUsage::kNone,
sem::BindingPoint binding_point = {}, sem::BindingPoint binding_point = {},

View File

@ -47,7 +47,7 @@ Transform::ApplyResult AddBlockAttribute::Apply(const Program* src,
bool made_changes = false; bool made_changes = false;
for (auto* global : src->AST().GlobalVariables()) { for (auto* global : src->AST().GlobalVariables()) {
auto* var = sem.Get(global); auto* var = sem.Get(global);
if (!type::IsHostShareable(var->AddressSpace())) { if (!builtin::IsHostShareable(var->AddressSpace())) {
// Not declared in a host-sharable address space // Not declared in a host-sharable address space
continue; continue;
} }

View File

@ -106,10 +106,10 @@ struct ArrayLengthFromUniform::State {
b.ty.array(b.ty.vec4(b.ty.u32()), b.ty.array(b.ty.vec4(b.ty.u32()),
u32((max_buffer_size_index / 4) + 1))), u32((max_buffer_size_index / 4) + 1))),
}); });
buffer_size_ubo = buffer_size_ubo = b.GlobalVar(b.Sym(), b.ty.Of(buffer_size_struct),
b.GlobalVar(b.Sym(), b.ty.Of(buffer_size_struct), type::AddressSpace::kUniform, builtin::AddressSpace::kUniform,
b.Group(AInt(cfg->ubo_binding.group)), b.Group(AInt(cfg->ubo_binding.group)),
b.Binding(AInt(cfg->ubo_binding.binding))); b.Binding(AInt(cfg->ubo_binding.binding)));
} }
return buffer_size_ubo; return buffer_size_ubo;
}; };

View File

@ -131,7 +131,7 @@ Transform::ApplyResult BindingRemapper::Apply(const Program* src,
return Program(std::move(b)); return Program(std::move(b));
} }
auto* sem = src->Sem().Get(var); auto* sem = src->Sem().Get(var);
if (sem->AddressSpace() != type::AddressSpace::kStorage) { if (sem->AddressSpace() != builtin::AddressSpace::kStorage) {
b.Diagnostics().add_error( b.Diagnostics().add_error(
diag::System::Transform, diag::System::Transform,
"cannot apply access control to variable with address space " + "cannot apply access control to variable with address space " +

View File

@ -679,7 +679,7 @@ struct BuiltinPolyfill::State {
auto name = b.Symbols().New("tint_workgroupUniformLoad"); auto name = b.Symbols().New("tint_workgroupUniformLoad");
b.Func(name, b.Func(name,
utils::Vector{ utils::Vector{
b.Param("p", b.ty.pointer(T(type), type::AddressSpace::kWorkgroup)), b.Param("p", b.ty.pointer(T(type), builtin::AddressSpace::kWorkgroup)),
}, },
T(type), T(type),
utils::Vector{ utils::Vector{

View File

@ -112,7 +112,7 @@ Transform::ApplyResult CalculateArrayLength::Apply(const Program* src,
b.Param("buffer", b.Param("buffer",
b.ty.pointer(type, buffer_type->AddressSpace(), buffer_type->Access()), b.ty.pointer(type, buffer_type->AddressSpace(), buffer_type->Access()),
utils::Vector{disable_validation}), utils::Vector{disable_validation}),
b.Param("result", b.ty.pointer(b.ty.u32(), type::AddressSpace::kFunction)), b.Param("result", b.ty.pointer(b.ty.u32(), builtin::AddressSpace::kFunction)),
}, },
b.ty.void_(), nullptr, b.ty.void_(), nullptr,
utils::Vector{ utils::Vector{

View File

@ -234,7 +234,7 @@ struct CanonicalizeEntryPointIO::State {
auto* builtin = ast::GetAttribute<ast::BuiltinAttribute>(attributes); auto* builtin = ast::GetAttribute<ast::BuiltinAttribute>(attributes);
if (cfg.shader_style == ShaderStyle::kGlsl && builtin) { if (cfg.shader_style == ShaderStyle::kGlsl && builtin) {
name = GLSLBuiltinToString(builtin->builtin, func_ast->PipelineStage(), name = GLSLBuiltinToString(builtin->builtin, func_ast->PipelineStage(),
type::AddressSpace::kIn); builtin::AddressSpace::kIn);
} }
auto symbol = ctx.dst->Symbols().New(name); auto symbol = ctx.dst->Symbols().New(name);
@ -251,7 +251,7 @@ struct CanonicalizeEntryPointIO::State {
value = ctx.dst->IndexAccessor(value, 0_i); value = ctx.dst->IndexAccessor(value, 0_i);
} }
} }
ctx.dst->GlobalVar(symbol, ast_type, type::AddressSpace::kIn, std::move(attributes)); ctx.dst->GlobalVar(symbol, ast_type, builtin::AddressSpace::kIn, std::move(attributes));
return value; return value;
} else if (cfg.shader_style == ShaderStyle::kMsl && } else if (cfg.shader_style == ShaderStyle::kMsl &&
ast::HasAttribute<ast::BuiltinAttribute>(attributes)) { ast::HasAttribute<ast::BuiltinAttribute>(attributes)) {
@ -300,7 +300,7 @@ struct CanonicalizeEntryPointIO::State {
if (cfg.shader_style == ShaderStyle::kGlsl) { if (cfg.shader_style == ShaderStyle::kGlsl) {
if (auto* b = ast::GetAttribute<ast::BuiltinAttribute>(attributes)) { if (auto* b = ast::GetAttribute<ast::BuiltinAttribute>(attributes)) {
name = GLSLBuiltinToString(b->builtin, func_ast->PipelineStage(), name = GLSLBuiltinToString(b->builtin, func_ast->PipelineStage(),
type::AddressSpace::kOut); builtin::AddressSpace::kOut);
value = ToGLSLBuiltin(b->builtin, value, type); value = ToGLSLBuiltin(b->builtin, value, type);
} }
} }
@ -532,7 +532,7 @@ struct CanonicalizeEntryPointIO::State {
type = ctx.dst->ty.array(type, 1_u); type = ctx.dst->ty.array(type, 1_u);
lhs = ctx.dst->IndexAccessor(lhs, 0_i); lhs = ctx.dst->IndexAccessor(lhs, 0_i);
} }
ctx.dst->GlobalVar(name, type, type::AddressSpace::kOut, std::move(attributes)); ctx.dst->GlobalVar(name, type, builtin::AddressSpace::kOut, std::move(attributes));
wrapper_body.Push(ctx.dst->Assign(lhs, outval.value)); wrapper_body.Push(ctx.dst->Assign(lhs, outval.value));
} }
} }
@ -677,7 +677,7 @@ struct CanonicalizeEntryPointIO::State {
/// @returns the gl_ string corresponding to that builtin /// @returns the gl_ string corresponding to that builtin
const char* GLSLBuiltinToString(builtin::BuiltinValue builtin, const char* GLSLBuiltinToString(builtin::BuiltinValue builtin,
ast::PipelineStage stage, ast::PipelineStage stage,
type::AddressSpace address_space) { builtin::AddressSpace address_space) {
switch (builtin) { switch (builtin) {
case builtin::BuiltinValue::kPosition: case builtin::BuiltinValue::kPosition:
switch (stage) { switch (stage) {
@ -709,7 +709,7 @@ struct CanonicalizeEntryPointIO::State {
case builtin::BuiltinValue::kSampleIndex: case builtin::BuiltinValue::kSampleIndex:
return "gl_SampleID"; return "gl_SampleID";
case builtin::BuiltinValue::kSampleMask: case builtin::BuiltinValue::kSampleMask:
if (address_space == type::AddressSpace::kIn) { if (address_space == builtin::AddressSpace::kIn) {
return "gl_SampleMaskIn"; return "gl_SampleMaskIn";
} else { } else {
return "gl_SampleMask"; return "gl_SampleMask";

View File

@ -89,7 +89,7 @@ Transform::ApplyResult ClampFragDepth::Apply(const Program* src, const DataMap&,
for (auto* global : src->AST().GlobalVariables()) { for (auto* global : src->AST().GlobalVariables()) {
if (auto* var = global->As<ast::Var>()) { if (auto* var = global->As<ast::Var>()) {
auto* v = src->Sem().Get(var); auto* v = src->Sem().Get(var);
if (TINT_UNLIKELY(v->AddressSpace() == type::AddressSpace::kPushConstant)) { if (TINT_UNLIKELY(v->AddressSpace() == builtin::AddressSpace::kPushConstant)) {
TINT_ICE(Transform, b.Diagnostics()) TINT_ICE(Transform, b.Diagnostics())
<< "ClampFragDepth doesn't know how to handle module that already use push " << "ClampFragDepth doesn't know how to handle module that already use push "
"constants"; "constants";
@ -124,7 +124,7 @@ Transform::ApplyResult ClampFragDepth::Apply(const Program* src, const DataMap&,
utils::Vector{b.Member("min", b.ty.f32()), b.Member("max", b.ty.f32())}); utils::Vector{b.Member("min", b.ty.f32()), b.Member("max", b.ty.f32())});
auto args_sym = b.Symbols().New("frag_depth_clamp_args"); auto args_sym = b.Symbols().New("frag_depth_clamp_args");
b.GlobalVar(args_sym, b.ty("FragDepthClampArgs"), type::AddressSpace::kPushConstant); b.GlobalVar(args_sym, b.ty("FragDepthClampArgs"), builtin::AddressSpace::kPushConstant);
auto base_fn_sym = b.Symbols().New("clamp_frag_depth"); auto base_fn_sym = b.Symbols().New("clamp_frag_depth");
b.Func(base_fn_sym, utils::Vector{b.Param("v", b.ty.f32())}, b.ty.f32(), b.Func(base_fn_sym, utils::Vector{b.Param("v", b.ty.f32())}, b.ty.f32(),

View File

@ -49,8 +49,8 @@ namespace {
bool ShouldRun(const Program* program) { bool ShouldRun(const Program* program) {
for (auto* decl : program->AST().GlobalDeclarations()) { for (auto* decl : program->AST().GlobalDeclarations()) {
if (auto* var = program->Sem().Get<sem::Variable>(decl)) { if (auto* var = program->Sem().Get<sem::Variable>(decl)) {
if (var->AddressSpace() == type::AddressSpace::kStorage || if (var->AddressSpace() == builtin::AddressSpace::kStorage ||
var->AddressSpace() == type::AddressSpace::kUniform) { var->AddressSpace() == builtin::AddressSpace::kUniform) {
return true; return true;
} }
} }
@ -108,10 +108,10 @@ struct OffsetBinOp : Offset {
/// LoadStoreKey is the unordered map key to a load or store intrinsic. /// LoadStoreKey is the unordered map key to a load or store intrinsic.
struct LoadStoreKey { struct LoadStoreKey {
type::AddressSpace const address_space; // buffer address space builtin::AddressSpace const address_space; // buffer address space
builtin::Access const access; // buffer access builtin::Access const access; // buffer access
type::Type const* buf_ty = nullptr; // buffer type type::Type const* buf_ty = nullptr; // buffer type
type::Type const* el_ty = nullptr; // element type type::Type const* el_ty = nullptr; // element type
bool operator==(const LoadStoreKey& rhs) const { bool operator==(const LoadStoreKey& rhs) const {
return address_space == rhs.address_space && access == rhs.access && buf_ty == rhs.buf_ty && return address_space == rhs.address_space && access == rhs.access && buf_ty == rhs.buf_ty &&
el_ty == rhs.el_ty; el_ty == rhs.el_ty;
@ -222,7 +222,7 @@ bool IntrinsicDataTypeFor(const type::Type* ty, DecomposeMemoryAccess::Intrinsic
/// @returns a DecomposeMemoryAccess::Intrinsic attribute that can be applied /// @returns a DecomposeMemoryAccess::Intrinsic attribute that can be applied
/// to a stub function to load the type `ty`. /// to a stub function to load the type `ty`.
DecomposeMemoryAccess::Intrinsic* IntrinsicLoadFor(ProgramBuilder* builder, DecomposeMemoryAccess::Intrinsic* IntrinsicLoadFor(ProgramBuilder* builder,
type::AddressSpace address_space, builtin::AddressSpace address_space,
const type::Type* ty) { const type::Type* ty) {
DecomposeMemoryAccess::Intrinsic::DataType type; DecomposeMemoryAccess::Intrinsic::DataType type;
if (!IntrinsicDataTypeFor(ty, type)) { if (!IntrinsicDataTypeFor(ty, type)) {
@ -236,7 +236,7 @@ DecomposeMemoryAccess::Intrinsic* IntrinsicLoadFor(ProgramBuilder* builder,
/// @returns a DecomposeMemoryAccess::Intrinsic attribute that can be applied /// @returns a DecomposeMemoryAccess::Intrinsic attribute that can be applied
/// to a stub function to store the type `ty`. /// to a stub function to store the type `ty`.
DecomposeMemoryAccess::Intrinsic* IntrinsicStoreFor(ProgramBuilder* builder, DecomposeMemoryAccess::Intrinsic* IntrinsicStoreFor(ProgramBuilder* builder,
type::AddressSpace address_space, builtin::AddressSpace address_space,
const type::Type* ty) { const type::Type* ty) {
DecomposeMemoryAccess::Intrinsic::DataType type; DecomposeMemoryAccess::Intrinsic::DataType type;
if (!IntrinsicDataTypeFor(ty, type)) { if (!IntrinsicDataTypeFor(ty, type)) {
@ -299,7 +299,7 @@ DecomposeMemoryAccess::Intrinsic* IntrinsicAtomicFor(ProgramBuilder* builder,
return nullptr; return nullptr;
} }
return builder->ASTNodes().Create<DecomposeMemoryAccess::Intrinsic>( return builder->ASTNodes().Create<DecomposeMemoryAccess::Intrinsic>(
builder->ID(), builder->AllocateNodeID(), op, type::AddressSpace::kStorage, type); builder->ID(), builder->AllocateNodeID(), op, builtin::AddressSpace::kStorage, type);
} }
/// BufferAccess describes a single storage or uniform buffer access /// BufferAccess describes a single storage or uniform buffer access
@ -465,7 +465,7 @@ struct DecomposeMemoryAccess::State {
const sem::VariableUser* var_user) { const sem::VariableUser* var_user) {
auto address_space = var_user->Variable()->AddressSpace(); auto address_space = var_user->Variable()->AddressSpace();
auto access = var_user->Variable()->Access(); auto access = var_user->Variable()->Access();
if (address_space != type::AddressSpace::kStorage) { if (address_space != builtin::AddressSpace::kStorage) {
access = builtin::Access::kUndefined; access = builtin::Access::kUndefined;
} }
return utils::GetOrCreate( return utils::GetOrCreate(
@ -561,7 +561,7 @@ struct DecomposeMemoryAccess::State {
const sem::VariableUser* var_user) { const sem::VariableUser* var_user) {
auto address_space = var_user->Variable()->AddressSpace(); auto address_space = var_user->Variable()->AddressSpace();
auto access = var_user->Variable()->Access(); auto access = var_user->Variable()->Access();
if (address_space != type::AddressSpace::kStorage) { if (address_space != builtin::AddressSpace::kStorage) {
access = builtin::Access::kUndefined; access = builtin::Access::kUndefined;
} }
return utils::GetOrCreate( return utils::GetOrCreate(
@ -671,7 +671,7 @@ struct DecomposeMemoryAccess::State {
auto op = intrinsic->Type(); auto op = intrinsic->Type();
auto address_space = var_user->Variable()->AddressSpace(); auto address_space = var_user->Variable()->AddressSpace();
auto access = var_user->Variable()->Access(); auto access = var_user->Variable()->Access();
if (address_space != type::AddressSpace::kStorage) { if (address_space != builtin::AddressSpace::kStorage) {
access = builtin::Access::kUndefined; access = builtin::Access::kUndefined;
} }
return utils::GetOrCreate(atomic_funcs, AtomicKey{access, buf_ty, el_ty, op}, [&] { return utils::GetOrCreate(atomic_funcs, AtomicKey{access, buf_ty, el_ty, op}, [&] {
@ -679,7 +679,7 @@ struct DecomposeMemoryAccess::State {
// atomic. This is replaced with two parameters: the buffer and offset. // atomic. This is replaced with two parameters: the buffer and offset.
utils::Vector params{ utils::Vector params{
b.Param("buffer", b.Param("buffer",
b.ty.pointer(CreateASTTypeFor(ctx, buf_ty), type::AddressSpace::kStorage, b.ty.pointer(CreateASTTypeFor(ctx, buf_ty), builtin::AddressSpace::kStorage,
access), access),
utils::Vector{b.Disable(ast::DisabledValidation::kFunctionParameter)}), utils::Vector{b.Disable(ast::DisabledValidation::kFunctionParameter)}),
b.Param("offset", b.ty.u32()), b.Param("offset", b.ty.u32()),
@ -734,7 +734,7 @@ struct DecomposeMemoryAccess::State {
DecomposeMemoryAccess::Intrinsic::Intrinsic(ProgramID pid, DecomposeMemoryAccess::Intrinsic::Intrinsic(ProgramID pid,
ast::NodeID nid, ast::NodeID nid,
Op o, Op o,
type::AddressSpace sc, builtin::AddressSpace sc,
DataType ty) DataType ty)
: Base(pid, nid), op(o), address_space(sc), type(ty) {} : Base(pid, nid), op(o), address_space(sc), type(ty) {}
DecomposeMemoryAccess::Intrinsic::~Intrinsic() = default; DecomposeMemoryAccess::Intrinsic::~Intrinsic() = default;
@ -873,8 +873,8 @@ Transform::ApplyResult DecomposeMemoryAccess::Apply(const Program* src,
// X // X
if (auto* sem_ident = sem.GetVal(ident)) { if (auto* sem_ident = sem.GetVal(ident)) {
if (auto* var = sem_ident->UnwrapLoad()->As<sem::VariableUser>()) { if (auto* var = sem_ident->UnwrapLoad()->As<sem::VariableUser>()) {
if (var->Variable()->AddressSpace() == type::AddressSpace::kStorage || if (var->Variable()->AddressSpace() == builtin::AddressSpace::kStorage ||
var->Variable()->AddressSpace() == type::AddressSpace::kUniform) { var->Variable()->AddressSpace() == builtin::AddressSpace::kUniform) {
// Variable to a storage or uniform buffer // Variable to a storage or uniform buffer
state.AddAccess(ident, { state.AddAccess(ident, {
var, var,

View File

@ -81,7 +81,7 @@ class DecomposeMemoryAccess final : public Castable<DecomposeMemoryAccess, Trans
/// @param o the op of the intrinsic /// @param o the op of the intrinsic
/// @param sc the address space of the buffer /// @param sc the address space of the buffer
/// @param ty the data type of the intrinsic /// @param ty the data type of the intrinsic
Intrinsic(ProgramID pid, ast::NodeID nid, Op o, type::AddressSpace sc, DataType ty); Intrinsic(ProgramID pid, ast::NodeID nid, Op o, builtin::AddressSpace sc, DataType ty);
/// Destructor /// Destructor
~Intrinsic() override; ~Intrinsic() override;
@ -101,7 +101,7 @@ class DecomposeMemoryAccess final : public Castable<DecomposeMemoryAccess, Trans
const Op op; const Op op;
/// The address space of the buffer this intrinsic operates on /// The address space of the buffer this intrinsic operates on
type::AddressSpace const address_space; builtin::AddressSpace const address_space;
/// The type of the intrinsic /// The type of the intrinsic
const DataType type; const DataType type;

View File

@ -39,7 +39,7 @@ TEST_F(DecomposeStridedArrayTest, ShouldRunNonStridedArray) {
// var<private> arr : array<f32, 4u> // var<private> arr : array<f32, 4u>
ProgramBuilder b; ProgramBuilder b;
b.GlobalVar("arr", b.ty.array<f32, 4u>(), type::AddressSpace::kPrivate); b.GlobalVar("arr", b.ty.array<f32, 4u>(), builtin::AddressSpace::kPrivate);
EXPECT_FALSE(ShouldRun<DecomposeStridedArray>(Program(std::move(b)))); EXPECT_FALSE(ShouldRun<DecomposeStridedArray>(Program(std::move(b))));
} }
@ -51,7 +51,7 @@ TEST_F(DecomposeStridedArrayTest, ShouldRunDefaultStridedArray) {
b.ty.array<f32, 4u>(utils::Vector{ b.ty.array<f32, 4u>(utils::Vector{
b.Stride(4), b.Stride(4),
}), }),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
EXPECT_TRUE(ShouldRun<DecomposeStridedArray>(Program(std::move(b)))); EXPECT_TRUE(ShouldRun<DecomposeStridedArray>(Program(std::move(b))));
} }
@ -63,7 +63,7 @@ TEST_F(DecomposeStridedArrayTest, ShouldRunExplicitStridedArray) {
b.ty.array<f32, 4u>(utils::Vector{ b.ty.array<f32, 4u>(utils::Vector{
b.Stride(16), b.Stride(16),
}), }),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
EXPECT_TRUE(ShouldRun<DecomposeStridedArray>(Program(std::move(b)))); EXPECT_TRUE(ShouldRun<DecomposeStridedArray>(Program(std::move(b))));
} }
@ -90,7 +90,7 @@ TEST_F(DecomposeStridedArrayTest, PrivateDefaultStridedArray) {
b.ty.array<f32, 4u>(utils::Vector{ b.ty.array<f32, 4u>(utils::Vector{
b.Stride(4), b.Stride(4),
}), }),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
b.Func("f", utils::Empty, b.ty.void_(), b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{
b.Decl(b.Let("a", b.Decl(b.Let("a",
@ -134,7 +134,7 @@ TEST_F(DecomposeStridedArrayTest, PrivateStridedArray) {
b.ty.array<f32, 4u>(utils::Vector{ b.ty.array<f32, 4u>(utils::Vector{
b.Stride(32), b.Stride(32),
}), }),
type::AddressSpace::kPrivate); builtin::AddressSpace::kPrivate);
b.Func("f", utils::Empty, b.ty.void_(), b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{
b.Decl(b.Let("a", b.Decl(b.Let("a",
@ -184,7 +184,7 @@ TEST_F(DecomposeStridedArrayTest, ReadUniformStridedArray) {
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array<f32, 4u>(utils::Vector{ auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array<f32, 4u>(utils::Vector{
b.Stride(32), b.Stride(32),
}))}); }))});
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kUniform, b.Group(0_a), b.Binding(0_a)); b.GlobalVar("s", b.ty.Of(S), builtin::AddressSpace::kUniform, b.Group(0_a), b.Binding(0_a));
b.Func("f", utils::Empty, b.ty.void_(), b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{
b.Decl(b.Let("a", b.Decl(b.Let("a",
@ -239,7 +239,7 @@ TEST_F(DecomposeStridedArrayTest, ReadUniformDefaultStridedArray) {
utils::Vector{ utils::Vector{
b.Stride(16), b.Stride(16),
}))}); }))});
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kUniform, b.Group(0_a), b.Binding(0_a)); b.GlobalVar("s", b.ty.Of(S), builtin::AddressSpace::kUniform, b.Group(0_a), b.Binding(0_a));
b.Func( b.Func(
"f", utils::Empty, b.ty.void_(), "f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{
@ -292,7 +292,7 @@ TEST_F(DecomposeStridedArrayTest, ReadStorageStridedArray) {
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array<f32, 4u>(utils::Vector{ auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array<f32, 4u>(utils::Vector{
b.Stride(32), b.Stride(32),
}))}); }))});
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kStorage, b.Group(0_a), b.Binding(0_a)); b.GlobalVar("s", b.ty.Of(S), builtin::AddressSpace::kStorage, b.Group(0_a), b.Binding(0_a));
b.Func("f", utils::Empty, b.ty.void_(), b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{
b.Decl(b.Let("a", b.Decl(b.Let("a",
@ -346,7 +346,7 @@ TEST_F(DecomposeStridedArrayTest, ReadStorageDefaultStridedArray) {
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array<f32, 4u>(utils::Vector{ auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array<f32, 4u>(utils::Vector{
b.Stride(4), b.Stride(4),
}))}); }))});
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kStorage, b.Group(0_a), b.Binding(0_a)); b.GlobalVar("s", b.ty.Of(S), builtin::AddressSpace::kStorage, b.Group(0_a), b.Binding(0_a));
b.Func("f", utils::Empty, b.ty.void_(), b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{
b.Decl(b.Let("a", b.Decl(b.Let("a",
@ -396,7 +396,7 @@ TEST_F(DecomposeStridedArrayTest, WriteStorageStridedArray) {
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array<f32, 4u>(utils::Vector{ auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array<f32, 4u>(utils::Vector{
b.Stride(32), b.Stride(32),
}))}); }))});
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kStorage, builtin::Access::kReadWrite, b.GlobalVar("s", b.ty.Of(S), builtin::AddressSpace::kStorage, builtin::Access::kReadWrite,
b.Group(0_a), b.Binding(0_a)); b.Group(0_a), b.Binding(0_a));
b.Func("f", utils::Empty, b.ty.void_(), b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{
@ -458,7 +458,7 @@ TEST_F(DecomposeStridedArrayTest, WriteStorageDefaultStridedArray) {
b.Stride(4), b.Stride(4),
})), })),
}); });
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kStorage, builtin::Access::kReadWrite, b.GlobalVar("s", b.ty.Of(S), builtin::AddressSpace::kStorage, builtin::Access::kReadWrite,
b.Group(0_a), b.Binding(0_a)); b.Group(0_a), b.Binding(0_a));
b.Func("f", utils::Empty, b.ty.void_(), b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{
@ -516,7 +516,7 @@ TEST_F(DecomposeStridedArrayTest, ReadWriteViaPointerLets) {
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array<f32, 4u>(utils::Vector{ auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array<f32, 4u>(utils::Vector{
b.Stride(32), b.Stride(32),
}))}); }))});
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kStorage, builtin::Access::kReadWrite, b.GlobalVar("s", b.ty.Of(S), builtin::AddressSpace::kStorage, builtin::Access::kReadWrite,
b.Group(0_a), b.Binding(0_a)); b.Group(0_a), b.Binding(0_a));
b.Func("f", utils::Empty, b.ty.void_(), b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{
@ -582,7 +582,7 @@ TEST_F(DecomposeStridedArrayTest, PrivateAliasedStridedArray) {
b.Stride(32), b.Stride(32),
})); }));
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty("ARR"))}); auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty("ARR"))});
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kStorage, builtin::Access::kReadWrite, b.GlobalVar("s", b.ty.Of(S), builtin::AddressSpace::kStorage, builtin::Access::kReadWrite,
b.Group(0_a), b.Binding(0_a)); b.Group(0_a), b.Binding(0_a));
b.Func("f", utils::Empty, b.ty.void_(), b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{
@ -658,7 +658,7 @@ TEST_F(DecomposeStridedArrayTest, PrivateNestedStridedArray) {
b.Stride(128), b.Stride(128),
})); }));
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty("ARR_B"))}); auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty("ARR_B"))});
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kStorage, builtin::Access::kReadWrite, b.GlobalVar("s", b.ty.Of(S), builtin::AddressSpace::kStorage, builtin::Access::kReadWrite,
b.Group(0_a), b.Binding(0_a)); b.Group(0_a), b.Binding(0_a));
b.Func("f", utils::Empty, b.ty.void_(), b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{

View File

@ -74,8 +74,8 @@ Transform::ApplyResult DecomposeStridedMatrix::Apply(const Program* src,
for (auto* node : src->ASTNodes().Objects()) { for (auto* node : src->ASTNodes().Objects()) {
if (auto* str = node->As<ast::Struct>()) { if (auto* str = node->As<ast::Struct>()) {
auto* str_ty = src->Sem().Get(str); auto* str_ty = src->Sem().Get(str);
if (!str_ty->UsedAs(type::AddressSpace::kUniform) && if (!str_ty->UsedAs(builtin::AddressSpace::kUniform) &&
!str_ty->UsedAs(type::AddressSpace::kStorage)) { !str_ty->UsedAs(builtin::AddressSpace::kStorage)) {
continue; continue;
} }
for (auto* member : str_ty->Members()) { for (auto* member : str_ty->Members()) {

View File

@ -76,7 +76,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformMatrix) {
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute), b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}), }),
}); });
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kUniform, b.Group(0_a), b.Binding(0_a)); b.GlobalVar("s", b.ty.Of(S), builtin::AddressSpace::kUniform, b.Group(0_a), b.Binding(0_a));
b.Func("f", utils::Empty, b.ty.void_(), b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{
b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))), b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
@ -133,7 +133,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformColumn) {
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute), b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}), }),
}); });
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kUniform, b.Group(0_a), b.Binding(0_a)); b.GlobalVar("s", b.ty.Of(S), builtin::AddressSpace::kUniform, b.Group(0_a), b.Binding(0_a));
b.Func( b.Func(
"f", utils::Empty, b.ty.void_(), "f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{
@ -187,7 +187,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformMatrix_DefaultStride) {
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute), b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}), }),
}); });
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kUniform, b.Group(0_a), b.Binding(0_a)); b.GlobalVar("s", b.ty.Of(S), builtin::AddressSpace::kUniform, b.Group(0_a), b.Binding(0_a));
b.Func("f", utils::Empty, b.ty.void_(), b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{
b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))), b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
@ -241,7 +241,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadStorageMatrix) {
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute), b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}), }),
}); });
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kStorage, builtin::Access::kReadWrite, b.GlobalVar("s", b.ty.Of(S), builtin::AddressSpace::kStorage, builtin::Access::kReadWrite,
b.Group(0_a), b.Binding(0_a)); b.Group(0_a), b.Binding(0_a));
b.Func("f", utils::Empty, b.ty.void_(), b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{
@ -299,7 +299,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadStorageColumn) {
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute), b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}), }),
}); });
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kStorage, builtin::Access::kReadWrite, b.GlobalVar("s", b.ty.Of(S), builtin::AddressSpace::kStorage, builtin::Access::kReadWrite,
b.Group(0_a), b.Binding(0_a)); b.Group(0_a), b.Binding(0_a));
b.Func( b.Func(
"f", utils::Empty, b.ty.void_(), "f", utils::Empty, b.ty.void_(),
@ -354,7 +354,7 @@ TEST_F(DecomposeStridedMatrixTest, WriteStorageMatrix) {
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute), b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}), }),
}); });
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kStorage, builtin::Access::kReadWrite, b.GlobalVar("s", b.ty.Of(S), builtin::AddressSpace::kStorage, builtin::Access::kReadWrite,
b.Group(0_a), b.Binding(0_a)); b.Group(0_a), b.Binding(0_a));
b.Func("f", utils::Empty, b.ty.void_(), b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{
@ -413,7 +413,7 @@ TEST_F(DecomposeStridedMatrixTest, WriteStorageColumn) {
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute), b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}), }),
}); });
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kStorage, builtin::Access::kReadWrite, b.GlobalVar("s", b.ty.Of(S), builtin::AddressSpace::kStorage, builtin::Access::kReadWrite,
b.Group(0_a), b.Binding(0_a)); b.Group(0_a), b.Binding(0_a));
b.Func("f", utils::Empty, b.ty.void_(), b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{
@ -473,7 +473,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadWriteViaPointerLets) {
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute), b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}), }),
}); });
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kStorage, builtin::Access::kReadWrite, b.GlobalVar("s", b.ty.Of(S), builtin::AddressSpace::kStorage, builtin::Access::kReadWrite,
b.Group(0_a), b.Binding(0_a)); b.Group(0_a), b.Binding(0_a));
b.Func("f", utils::Empty, b.ty.void_(), b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{
@ -545,7 +545,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadPrivateMatrix) {
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute), b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}), }),
}); });
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kPrivate); b.GlobalVar("s", b.ty.Of(S), builtin::AddressSpace::kPrivate);
b.Func("f", utils::Empty, b.ty.void_(), b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{
b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))), b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
@ -599,7 +599,7 @@ TEST_F(DecomposeStridedMatrixTest, WritePrivateMatrix) {
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute), b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}), }),
}); });
b.GlobalVar("s", b.ty.Of(S), type::AddressSpace::kPrivate); b.GlobalVar("s", b.ty.Of(S), builtin::AddressSpace::kPrivate);
b.Func("f", utils::Empty, b.ty.void_(), b.Func("f", utils::Empty, b.ty.void_(),
utils::Vector{ utils::Vector{
b.Assign(b.MemberAccessor("s", "m"), b.Assign(b.MemberAccessor("s", "m"),

View File

@ -81,7 +81,7 @@ Transform::ApplyResult DemoteToHelper::Apply(const Program* src, const DataMap&,
// Create a module-scope flag that indicates whether the current invocation has been discarded. // Create a module-scope flag that indicates whether the current invocation has been discarded.
auto flag = b.Symbols().New("tint_discarded"); auto flag = b.Symbols().New("tint_discarded");
b.GlobalVar(flag, type::AddressSpace::kPrivate, b.Expr(false)); b.GlobalVar(flag, builtin::AddressSpace::kPrivate, b.Expr(false));
// Replace all discard statements with a statement that marks the invocation as discarded. // Replace all discard statements with a statement that marks the invocation as discarded.
ctx.ReplaceAll([&](const ast::DiscardStatement*) -> const ast::Statement* { ctx.ReplaceAll([&](const ast::DiscardStatement*) -> const ast::Statement* {
@ -125,12 +125,12 @@ Transform::ApplyResult DemoteToHelper::Apply(const Program* src, const DataMap&,
// Skip writes to invocation-private address spaces. // Skip writes to invocation-private address spaces.
auto* ref = sem.GetVal(assign->lhs)->Type()->As<type::Reference>(); auto* ref = sem.GetVal(assign->lhs)->Type()->As<type::Reference>();
switch (ref->AddressSpace()) { switch (ref->AddressSpace()) {
case type::AddressSpace::kStorage: case builtin::AddressSpace::kStorage:
// Need to mask these. // Need to mask these.
break; break;
case type::AddressSpace::kFunction: case builtin::AddressSpace::kFunction:
case type::AddressSpace::kPrivate: case builtin::AddressSpace::kPrivate:
case type::AddressSpace::kOut: case builtin::AddressSpace::kOut:
// Skip these. // Skip these.
return; return;
default: default:

Some files were not shown because too many files have changed in this diff Show More