From 19d3205e15e0746dbfe7895793c7c1ca5ac8a379 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Thu, 20 May 2021 15:10:48 +0000 Subject: [PATCH] Remove typ::TypePair. You've helped us bridge two worlds. Good Night, Sweet Prince. Fixed: tint:724 Change-Id: I0b4ba960e9cf5dcff7df9d2f332ea36d6663c440 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/51667 Reviewed-by: Antonio Maiorano Commit-Queue: Antonio Maiorano Auto-Submit: Ben Clayton --- src/BUILD.gn | 1 - src/CMakeLists.txt | 1 - src/ast/bitcast_expression.h | 3 + src/ast/function.h | 1 - src/ast/intrinsic_texture_helper_test.cc | 2 +- src/ast/struct_member.h | 4 +- src/ast/type_constructor_expression.h | 3 + src/ast/variable.h | 2 + src/clone_context.h | 9 - src/inspector/inspector_test.cc | 57 ++-- src/program_builder.h | 167 +++++------ src/program_builder_test.cc | 4 +- src/reader/wgsl/parser_impl.h | 1 - src/reader/wgsl/parser_impl_detail.h | 12 - src/resolver/assignment_validation_test.cc | 4 +- src/resolver/intrinsic_test.cc | 14 +- src/resolver/resolver.cc | 18 +- src/resolver/resolver.h | 12 +- src/resolver/resolver_test.cc | 8 +- src/resolver/resolver_test_helper.h | 12 +- src/resolver/type_validation_test.cc | 26 +- src/resolver/validation_test.cc | 64 ++-- src/transform/external_texture_transform.cc | 4 +- src/typepair.h | 273 ------------------ .../generator_impl_member_accessor_test.cc | 40 ++- src/writer/hlsl/generator_impl_type_test.cc | 8 +- src/writer/msl/generator_impl.cc | 5 +- src/writer/msl/generator_impl.h | 2 +- src/writer/msl/generator_impl_type_test.cc | 2 +- .../spirv/builder_global_variable_test.cc | 8 +- src/writer/spirv/builder_intrinsic_test.cc | 4 +- src/writer/spirv/builder_type_test.cc | 28 +- .../wgsl/generator_impl_function_test.cc | 2 +- .../wgsl/generator_impl_global_decl_test.cc | 2 +- src/writer/wgsl/generator_impl_type_test.cc | 34 +-- 35 files changed, 277 insertions(+), 560 deletions(-) delete mode 100644 src/typepair.h diff --git a/src/BUILD.gn b/src/BUILD.gn index e7735a2e3f..517a3b1706 100644 --- a/src/BUILD.gn +++ b/src/BUILD.gn @@ -527,7 +527,6 @@ libtint_source_set("libtint_core_all_src") { "transform/var_for_dynamic_index.h", "transform/vertex_pulling.cc", "transform/vertex_pulling.h", - "typepair.h", "utils/get_or_create.h", "utils/hash.h", "utils/math.h", diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f4ff38d856..b42303ee9a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -262,7 +262,6 @@ set(TINT_LIB_SRCS symbol.cc symbol.h traits.h - typepair.h transform/binding_remapper.cc transform/binding_remapper.h transform/bound_array_accessors.cc diff --git a/src/ast/bitcast_expression.h b/src/ast/bitcast_expression.h index 6cce249c40..f901fec844 100644 --- a/src/ast/bitcast_expression.h +++ b/src/ast/bitcast_expression.h @@ -20,6 +20,9 @@ namespace tint { namespace ast { +// Forward declaration +class Type; + /// A bitcast expression class BitcastExpression : public Castable { public: diff --git a/src/ast/function.h b/src/ast/function.h index 397e1c4389..86e85bba59 100644 --- a/src/ast/function.h +++ b/src/ast/function.h @@ -28,7 +28,6 @@ #include "src/ast/location_decoration.h" #include "src/ast/pipeline_stage.h" #include "src/ast/variable.h" -#include "src/typepair.h" namespace tint { namespace ast { diff --git a/src/ast/intrinsic_texture_helper_test.cc b/src/ast/intrinsic_texture_helper_test.cc index f9430d4fa4..3cd12f61c8 100644 --- a/src/ast/intrinsic_texture_helper_test.cc +++ b/src/ast/intrinsic_texture_helper_test.cc @@ -171,7 +171,7 @@ ast::Variable* TextureOverloadCase::buildTextureVariable( ast::StorageClass::kNone, nullptr, decos); case ast::intrinsic::test::TextureKind::kStorage: { - auto st = b->ty.storage_texture(texture_dimension, image_format); + auto* st = b->ty.storage_texture(texture_dimension, image_format); auto* ac = b->ty.access(access_control, st); return b->Global("texture", ac, ast::StorageClass::kNone, nullptr, decos); } diff --git a/src/ast/struct_member.h b/src/ast/struct_member.h index 4ed141d6f9..8fae5ff613 100644 --- a/src/ast/struct_member.h +++ b/src/ast/struct_member.h @@ -19,11 +19,13 @@ #include #include "src/ast/decoration.h" -#include "src/typepair.h" namespace tint { namespace ast { +// Forward declaration +class Type; + /// A struct member statement. class StructMember : public Castable { public: diff --git a/src/ast/type_constructor_expression.h b/src/ast/type_constructor_expression.h index 19560a4702..8bd15a5e1e 100644 --- a/src/ast/type_constructor_expression.h +++ b/src/ast/type_constructor_expression.h @@ -22,6 +22,9 @@ namespace tint { namespace ast { +// Forward declaration +class Type; + /// A type specific constructor class TypeConstructorExpression : public Castable { diff --git a/src/ast/variable.h b/src/ast/variable.h index 0151d7404f..a345fcc131 100644 --- a/src/ast/variable.h +++ b/src/ast/variable.h @@ -25,9 +25,11 @@ namespace tint { namespace ast { +// Forward declarations class BindingDecoration; class GroupDecoration; class LocationDecoration; +class Type; /// A Variable statement. /// diff --git a/src/clone_context.h b/src/clone_context.h index c032877c3b..6e46f8f73d 100644 --- a/src/clone_context.h +++ b/src/clone_context.h @@ -26,7 +26,6 @@ #include "src/debug.h" #include "src/symbol.h" #include "src/traits.h" -#include "src/typepair.h" namespace tint { @@ -178,14 +177,6 @@ class CloneContext { return CheckedCast(c); } - /// Clones the AST node of the type pair - /// @param tp the type pair to clone - /// @return the cloned AST node wrapped in a type pair - template - typ::TypePair Clone(const typ::TypePair& tp) { - return Clone(const_cast(tp.ast)); - } - /// Clones the Source `s` into #dst /// TODO(bclayton) - Currently this 'clone' is a shallow copy. If/when /// `Source.File`s are owned by the Program this should make a copy of the diff --git a/src/inspector/inspector_test.cc b/src/inspector/inspector_test.cc index 2eebad195e..d8a3a35f0d 100644 --- a/src/inspector/inspector_test.cc +++ b/src/inspector/inspector_test.cc @@ -359,15 +359,15 @@ class InspectorHelper : public ProgramBuilder { /// @param dim the dimensions of the texture /// @param type the data type of the sampled texture /// @returns the generated SampleTextureType - typ::SampledTexture MakeSampledTextureType(ast::TextureDimension dim, - ast::Type* type) { + ast::SampledTexture* MakeSampledTextureType(ast::TextureDimension dim, + ast::Type* type) { return ty.sampled_texture(dim, type); } /// Generates a DepthTexture appropriate for the params /// @param dim the dimensions of the texture /// @returns the generated DepthTexture - typ::DepthTexture MakeDepthTextureType(ast::TextureDimension dim) { + ast::DepthTexture* MakeDepthTextureType(ast::TextureDimension dim) { return ty.depth_texture(dim); } @@ -375,7 +375,7 @@ class InspectorHelper : public ProgramBuilder { /// @param dim the dimensions of the texture /// @param type the data type of the sampled texture /// @returns the generated SampleTextureType - typ::MultisampledTexture MakeMultisampledTextureType( + ast::MultisampledTexture* MakeMultisampledTextureType( ast::TextureDimension dim, ast::Type* type) { return ty.multisampled_texture(dim, type); @@ -383,7 +383,7 @@ class InspectorHelper : public ProgramBuilder { /// Generates an ExternalTexture appropriate for the params /// @returns the generated ExternalTexture - typ::ExternalTexture MakeExternalTextureType() { + ast::ExternalTexture* MakeExternalTextureType() { return ty.external_texture(); } @@ -577,7 +577,7 @@ class InspectorHelper : public ProgramBuilder { bool read_only) { auto ac = read_only ? ast::AccessControl::kReadOnly : ast::AccessControl::kWriteOnly; - auto tex = ty.storage_texture(dim, format); + auto* tex = ty.storage_texture(dim, format); return ty.access(ac, tex); } @@ -588,7 +588,7 @@ class InspectorHelper : public ProgramBuilder { /// @param group the binding/group to use for the sampled texture /// @param binding the binding number to use for the sampled texture void AddStorageTexture(const std::string& name, - typ::Type type, + ast::Type* type, uint32_t group, uint32_t binding) { AddBinding(name, type, ast::StorageClass::kNone, group, binding); @@ -603,7 +603,7 @@ class InspectorHelper : public ProgramBuilder { ast::Function* MakeStorageTextureBodyFunction( const std::string& func_name, const std::string& st_name, - typ::Type dim_type, + ast::Type* dim_type, ast::DecorationList decorations) { ast::StatementList stmts; @@ -863,16 +863,16 @@ TEST_F(InspectorGetEntryPointTest, NoInOutVariables) { TEST_P(InspectorGetEntryPointTestWithComponentTypeParam, InOutVariables) { ComponentType inspector_type = GetParam(); - std::function tint_type; + std::function tint_type; switch (inspector_type) { case ComponentType::kFloat: - tint_type = [this]() -> typ::Type { return ty.f32(); }; + tint_type = [this]() -> ast::Type* { return ty.f32(); }; break; case ComponentType::kSInt: - tint_type = [this]() -> typ::Type { return ty.i32(); }; + tint_type = [this]() -> ast::Type* { return ty.i32(); }; break; case ComponentType::kUInt: - tint_type = [this]() -> typ::Type { return ty.u32(); }; + tint_type = [this]() -> ast::Type* { return ty.u32(); }; break; case ComponentType::kUnknown: return; @@ -1672,7 +1672,7 @@ TEST_F(InspectorGetResourceBindingsTest, Simple) { MakeStructVariableReferenceBodyFunction("rosb_func", "rosb_var", {{0, ty.i32()}}); - auto s_texture_type = + auto* s_texture_type = MakeSampledTextureType(ast::TextureDimension::k1d, ty.f32()); AddSampledTexture("s_texture", s_texture_type, 2, 0); AddSampler("s_var", 3, 0); @@ -1680,7 +1680,8 @@ TEST_F(InspectorGetResourceBindingsTest, Simple) { MakeSamplerReferenceBodyFunction("s_func", "s_texture", "s_var", "s_coords", ty.f32(), {}); - auto cs_depth_texture_type = MakeDepthTextureType(ast::TextureDimension::k2d); + auto* cs_depth_texture_type = + MakeDepthTextureType(ast::TextureDimension::k2d); AddDepthTexture("cs_texture", cs_depth_texture_type, 3, 1); AddComparisonSampler("cs_var", 3, 2); AddGlobalVariable("cs_coords", ty.vec2()); @@ -2327,7 +2328,7 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, SkipNonReadOnly) { } TEST_F(InspectorGetSamplerResourceBindingsTest, Simple) { - auto sampled_texture_type = + auto* sampled_texture_type = MakeSampledTextureType(ast::TextureDimension::k1d, ty.f32()); AddSampledTexture("foo_texture", sampled_texture_type, 0, 0); AddSampler("foo_sampler", 0, 1); @@ -2364,7 +2365,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, NoSampler) { } TEST_F(InspectorGetSamplerResourceBindingsTest, InFunction) { - auto sampled_texture_type = + auto* sampled_texture_type = MakeSampledTextureType(ast::TextureDimension::k1d, ty.f32()); AddSampledTexture("foo_texture", sampled_texture_type, 0, 0); AddSampler("foo_sampler", 0, 1); @@ -2390,7 +2391,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, InFunction) { } TEST_F(InspectorGetSamplerResourceBindingsTest, UnknownEntryPoint) { - auto sampled_texture_type = + auto* sampled_texture_type = MakeSampledTextureType(ast::TextureDimension::k1d, ty.f32()); AddSampledTexture("foo_texture", sampled_texture_type, 0, 0); AddSampler("foo_sampler", 0, 1); @@ -2409,7 +2410,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, UnknownEntryPoint) { } TEST_F(InspectorGetSamplerResourceBindingsTest, SkipsComparisonSamplers) { - auto depth_texture_type = MakeDepthTextureType(ast::TextureDimension::k2d); + auto* depth_texture_type = MakeDepthTextureType(ast::TextureDimension::k2d); AddDepthTexture("foo_texture", depth_texture_type, 0, 0); AddComparisonSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.vec2()); @@ -2430,7 +2431,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, SkipsComparisonSamplers) { } TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, Simple) { - auto depth_texture_type = MakeDepthTextureType(ast::TextureDimension::k2d); + auto* depth_texture_type = MakeDepthTextureType(ast::TextureDimension::k2d); AddDepthTexture("foo_texture", depth_texture_type, 0, 0); AddComparisonSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.vec2()); @@ -2468,7 +2469,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, NoSampler) { } TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, InFunction) { - auto depth_texture_type = MakeDepthTextureType(ast::TextureDimension::k2d); + auto* depth_texture_type = MakeDepthTextureType(ast::TextureDimension::k2d); AddDepthTexture("foo_texture", depth_texture_type, 0, 0); AddComparisonSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.vec2()); @@ -2496,7 +2497,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, InFunction) { } TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, UnknownEntryPoint) { - auto depth_texture_type = MakeDepthTextureType(ast::TextureDimension::k2d); + auto* depth_texture_type = MakeDepthTextureType(ast::TextureDimension::k2d); AddDepthTexture("foo_texture", depth_texture_type, 0, 0); AddComparisonSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.vec2()); @@ -2515,7 +2516,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, UnknownEntryPoint) { } TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, SkipsSamplers) { - auto sampled_texture_type = + auto* sampled_texture_type = MakeSampledTextureType(ast::TextureDimension::k1d, ty.f32()); AddSampledTexture("foo_texture", sampled_texture_type, 0, 0); AddSampler("foo_sampler", 0, 1); @@ -2549,7 +2550,7 @@ TEST_F(InspectorGetSampledTextureResourceBindingsTest, Empty) { } TEST_P(InspectorGetSampledTextureResourceBindingsTestWithParam, textureSample) { - auto sampled_texture_type = MakeSampledTextureType( + auto* sampled_texture_type = MakeSampledTextureType( GetParam().type_dim, GetBaseType(GetParam().sampled_kind)); AddSampledTexture("foo_texture", sampled_texture_type, 0, 0); AddSampler("foo_sampler", 0, 1); @@ -2607,7 +2608,7 @@ INSTANTIATE_TEST_SUITE_P( TEST_P(InspectorGetSampledArrayTextureResourceBindingsTestWithParam, textureSample) { - auto sampled_texture_type = MakeSampledTextureType( + auto* sampled_texture_type = MakeSampledTextureType( GetParam().type_dim, GetBaseType(GetParam().sampled_kind)); AddSampledTexture("foo_texture", sampled_texture_type, 0, 0); AddSampler("foo_sampler", 0, 1); @@ -2651,7 +2652,7 @@ INSTANTIATE_TEST_SUITE_P( TEST_P(InspectorGetMultisampledTextureResourceBindingsTestWithParam, textureLoad) { - auto multisampled_texture_type = MakeMultisampledTextureType( + auto* multisampled_texture_type = MakeMultisampledTextureType( GetParam().type_dim, GetBaseType(GetParam().sampled_kind)); AddMultisampledTexture("foo_texture", multisampled_texture_type, 0, 0); auto* coord_type = GetCoordsType(GetParam().type_dim, ty.i32()); @@ -2720,7 +2721,7 @@ TEST_F(InspectorGetMultisampledArrayTextureResourceBindingsTest, Empty) { TEST_P(InspectorGetMultisampledArrayTextureResourceBindingsTestWithParam, DISABLED_textureSample) { - auto multisampled_texture_type = MakeMultisampledTextureType( + auto* multisampled_texture_type = MakeMultisampledTextureType( GetParam().type_dim, GetBaseType(GetParam().sampled_kind)); AddMultisampledTexture("foo_texture", multisampled_texture_type, 0, 0); AddSampler("foo_sampler", 0, 1); @@ -2912,7 +2913,7 @@ INSTANTIATE_TEST_SUITE_P( TEST_P(InspectorGetDepthTextureResourceBindingsTestWithParam, textureDimensions) { - auto depth_texture_type = MakeDepthTextureType(GetParam().type_dim); + auto* depth_texture_type = MakeDepthTextureType(GetParam().type_dim); AddDepthTexture("dt", depth_texture_type, 0, 0); AddGlobalVariable("dt_level", ty.i32()); @@ -2956,7 +2957,7 @@ INSTANTIATE_TEST_SUITE_P( inspector::ResourceBinding::TextureDimension::kCubeArray})); TEST_F(InspectorGetExternalTextureResourceBindingsTest, Simple) { - auto external_texture_type = MakeExternalTextureType(); + auto* external_texture_type = MakeExternalTextureType(); AddExternalTexture("et", external_texture_type, 0, 0); Func("ep", ast::VariableList(), ty.void_(), diff --git a/src/program_builder.h b/src/program_builder.h index 47805bcb55..3a102ff09c 100644 --- a/src/program_builder.h +++ b/src/program_builder.h @@ -77,7 +77,6 @@ #include "src/sem/u32_type.h" #include "src/sem/vector_type.h" #include "src/sem/void_type.h" -#include "src/typepair.h" namespace tint { @@ -350,59 +349,59 @@ class ProgramBuilder { /// @return the tint AST type for the C type `T`. template - typ::Type Of() const { + ast::Type* Of() const { return CToAST::get(this); } /// @returns a boolean type - typ::Bool bool_() const { return builder->create(); } + ast::Bool* bool_() const { return builder->create(); } /// @param source the Source of the node /// @returns a boolean type - typ::Bool bool_(const Source& source) const { + ast::Bool* bool_(const Source& source) const { return builder->create(source); } /// @returns a f32 type - typ::F32 f32() const { return builder->create(); } + ast::F32* f32() const { return builder->create(); } /// @param source the Source of the node /// @returns a f32 type - typ::F32 f32(const Source& source) const { + ast::F32* f32(const Source& source) const { return builder->create(source); } /// @returns a i32 type - typ::I32 i32() const { return builder->create(); } + ast::I32* i32() const { return builder->create(); } /// @param source the Source of the node /// @returns a i32 type - typ::I32 i32(const Source& source) const { + ast::I32* i32(const Source& source) const { return builder->create(source); } /// @returns a u32 type - typ::U32 u32() const { return builder->create(); } + ast::U32* u32() const { return builder->create(); } /// @param source the Source of the node /// @returns a u32 type - typ::U32 u32(const Source& source) const { + ast::U32* u32(const Source& source) const { return builder->create(source); } /// @returns a void type - typ::Void void_() const { return builder->create(); } + ast::Void* void_() const { return builder->create(); } /// @param source the Source of the node /// @returns a void type - typ::Void void_(const Source& source) const { + ast::Void* void_(const Source& source) const { return builder->create(source); } /// @param type vector subtype /// @param n vector width in elements /// @return the tint AST type for a `n`-element vector of `type`. - typ::Vector vec(ast::Type* type, uint32_t n) const { + ast::Vector* vec(ast::Type* type, uint32_t n) const { type = MaybeCreateTypename(type); return builder->create(type, n); } @@ -411,45 +410,45 @@ class ProgramBuilder { /// @param type vector subtype /// @param n vector width in elements /// @return the tint AST type for a `n`-element vector of `type`. - typ::Vector vec(const Source& source, ast::Type* type, uint32_t n) const { + ast::Vector* vec(const Source& source, ast::Type* type, uint32_t n) const { type = MaybeCreateTypename(type); return builder->create(source, type, n); } /// @param type vector subtype /// @return the tint AST type for a 2-element vector of `type`. - typ::Vector vec2(ast::Type* type) const { return vec(type, 2u); } + ast::Vector* vec2(ast::Type* type) const { return vec(type, 2u); } /// @param type vector subtype /// @return the tint AST type for a 3-element vector of `type`. - typ::Vector vec3(ast::Type* type) const { return vec(type, 3u); } + ast::Vector* vec3(ast::Type* type) const { return vec(type, 3u); } /// @param type vector subtype /// @return the tint AST type for a 4-element vector of `type`. - typ::Vector vec4(ast::Type* type) const { return vec(type, 4u); } + ast::Vector* vec4(ast::Type* type) const { return vec(type, 4u); } /// @param n vector width in elements /// @return the tint AST type for a `n`-element vector of `type`. template - typ::Vector vec(uint32_t n) const { + ast::Vector* vec(uint32_t n) const { return vec(Of(), n); } /// @return the tint AST type for a 2-element vector of the C type `T`. template - typ::Vector vec2() const { + ast::Vector* vec2() const { return vec2(Of()); } /// @return the tint AST type for a 3-element vector of the C type `T`. template - typ::Vector vec3() const { + ast::Vector* vec3() const { return vec3(Of()); } /// @return the tint AST type for a 4-element vector of the C type `T`. template - typ::Vector vec4() const { + ast::Vector* vec4() const { return vec4(Of()); } @@ -457,7 +456,7 @@ class ProgramBuilder { /// @param columns number of columns for the matrix /// @param rows number of rows for the matrix /// @return the tint AST type for a matrix of `type` - typ::Matrix mat(ast::Type* type, uint32_t columns, uint32_t rows) const { + ast::Matrix* mat(ast::Type* type, uint32_t columns, uint32_t rows) const { type = MaybeCreateTypename(type); return builder->create(type, rows, columns); } @@ -467,108 +466,108 @@ class ProgramBuilder { /// @param columns number of columns for the matrix /// @param rows number of rows for the matrix /// @return the tint AST type for a matrix of `type` - typ::Matrix mat(const Source& source, - typ::Type type, - uint32_t columns, - uint32_t rows) const { + ast::Matrix* mat(const Source& source, + ast::Type* type, + uint32_t columns, + uint32_t rows) const { return builder->create(source, type, rows, columns); } /// @param type matrix subtype /// @return the tint AST type for a 2x3 matrix of `type`. - typ::Matrix mat2x2(ast::Type* type) const { return mat(type, 2u, 2u); } + ast::Matrix* mat2x2(ast::Type* type) const { return mat(type, 2u, 2u); } /// @param type matrix subtype /// @return the tint AST type for a 2x3 matrix of `type`. - typ::Matrix mat2x3(ast::Type* type) const { return mat(type, 2u, 3u); } + ast::Matrix* mat2x3(ast::Type* type) const { return mat(type, 2u, 3u); } /// @param type matrix subtype /// @return the tint AST type for a 2x4 matrix of `type`. - typ::Matrix mat2x4(ast::Type* type) const { return mat(type, 2u, 4u); } + ast::Matrix* mat2x4(ast::Type* type) const { return mat(type, 2u, 4u); } /// @param type matrix subtype /// @return the tint AST type for a 3x2 matrix of `type`. - typ::Matrix mat3x2(ast::Type* type) const { return mat(type, 3u, 2u); } + ast::Matrix* mat3x2(ast::Type* type) const { return mat(type, 3u, 2u); } /// @param type matrix subtype /// @return the tint AST type for a 3x3 matrix of `type`. - typ::Matrix mat3x3(ast::Type* type) const { return mat(type, 3u, 3u); } + ast::Matrix* mat3x3(ast::Type* type) const { return mat(type, 3u, 3u); } /// @param type matrix subtype /// @return the tint AST type for a 3x4 matrix of `type`. - typ::Matrix mat3x4(ast::Type* type) const { return mat(type, 3u, 4u); } + ast::Matrix* mat3x4(ast::Type* type) const { return mat(type, 3u, 4u); } /// @param type matrix subtype /// @return the tint AST type for a 4x2 matrix of `type`. - typ::Matrix mat4x2(ast::Type* type) const { return mat(type, 4u, 2u); } + ast::Matrix* mat4x2(ast::Type* type) const { return mat(type, 4u, 2u); } /// @param type matrix subtype /// @return the tint AST type for a 4x3 matrix of `type`. - typ::Matrix mat4x3(ast::Type* type) const { return mat(type, 4u, 3u); } + ast::Matrix* mat4x3(ast::Type* type) const { return mat(type, 4u, 3u); } /// @param type matrix subtype /// @return the tint AST type for a 4x4 matrix of `type`. - typ::Matrix mat4x4(ast::Type* type) const { return mat(type, 4u, 4u); } + ast::Matrix* mat4x4(ast::Type* type) const { return mat(type, 4u, 4u); } /// @param columns number of columns for the matrix /// @param rows number of rows for the matrix /// @return the tint AST type for a matrix of `type` template - typ::Matrix mat(uint32_t columns, uint32_t rows) const { + ast::Matrix* mat(uint32_t columns, uint32_t rows) const { return mat(Of(), columns, rows); } /// @return the tint AST type for a 2x3 matrix of the C type `T`. template - typ::Matrix mat2x2() const { + ast::Matrix* mat2x2() const { return mat2x2(Of()); } /// @return the tint AST type for a 2x3 matrix of the C type `T`. template - typ::Matrix mat2x3() const { + ast::Matrix* mat2x3() const { return mat2x3(Of()); } /// @return the tint AST type for a 2x4 matrix of the C type `T`. template - typ::Matrix mat2x4() const { + ast::Matrix* mat2x4() const { return mat2x4(Of()); } /// @return the tint AST type for a 3x2 matrix of the C type `T`. template - typ::Matrix mat3x2() const { + ast::Matrix* mat3x2() const { return mat3x2(Of()); } /// @return the tint AST type for a 3x3 matrix of the C type `T`. template - typ::Matrix mat3x3() const { + ast::Matrix* mat3x3() const { return mat3x3(Of()); } /// @return the tint AST type for a 3x4 matrix of the C type `T`. template - typ::Matrix mat3x4() const { + ast::Matrix* mat3x4() const { return mat3x4(Of()); } /// @return the tint AST type for a 4x2 matrix of the C type `T`. template - typ::Matrix mat4x2() const { + ast::Matrix* mat4x2() const { return mat4x2(Of()); } /// @return the tint AST type for a 4x3 matrix of the C type `T`. template - typ::Matrix mat4x3() const { + ast::Matrix* mat4x3() const { return mat4x3(Of()); } /// @return the tint AST type for a 4x4 matrix of the C type `T`. template - typ::Matrix mat4x4() const { + ast::Matrix* mat4x4() const { return mat4x4(Of()); } @@ -663,7 +662,7 @@ class ProgramBuilder { /// @param type the alias type /// @returns the alias pointer template - ast::Alias* alias(NAME&& name, typ::Type type) const { + ast::Alias* alias(NAME&& name, ast::Type* type) const { type = MaybeCreateTypename(type); auto sym = builder->Sym(std::forward(name)); return builder->create(sym, type); @@ -675,7 +674,9 @@ class ProgramBuilder { /// @param type the alias type /// @returns the alias pointer template - ast::Alias* alias(const Source& source, NAME&& name, typ::Type type) const { + ast::Alias* alias(const Source& source, + NAME&& name, + ast::Type* type) const { type = MaybeCreateTypename(type); auto sym = builder->Sym(std::forward(name)); return builder->create(source, sym, type); @@ -707,8 +708,8 @@ class ProgramBuilder { /// @param type the type of the pointer /// @param storage_class the storage class of the pointer /// @return the pointer to `type` with the given ast::StorageClass - typ::Pointer pointer(ast::Type* type, - ast::StorageClass storage_class) const { + ast::Pointer* pointer(ast::Type* type, + ast::StorageClass storage_class) const { type = MaybeCreateTypename(type); return builder->create(type, storage_class); } @@ -717,9 +718,9 @@ class ProgramBuilder { /// @param type the type of the pointer /// @param storage_class the storage class of the pointer /// @return the pointer to `type` with the given ast::StorageClass - typ::Pointer pointer(const Source& source, - typ::Type type, - ast::StorageClass storage_class) const { + ast::Pointer* pointer(const Source& source, + ast::Type* type, + ast::StorageClass storage_class) const { type = MaybeCreateTypename(type); return builder->create(source, type, storage_class); } @@ -727,42 +728,42 @@ class ProgramBuilder { /// @param storage_class the storage class of the pointer /// @return the pointer to type `T` with the given ast::StorageClass. template - typ::Pointer pointer(ast::StorageClass storage_class) const { + ast::Pointer* pointer(ast::StorageClass storage_class) const { return pointer(Of(), storage_class); } /// @param kind the kind of sampler /// @returns the sampler - typ::Sampler sampler(ast::SamplerKind kind) const { + ast::Sampler* sampler(ast::SamplerKind kind) const { return builder->create(kind); } /// @param source the Source of the node /// @param kind the kind of sampler /// @returns the sampler - typ::Sampler sampler(const Source& source, ast::SamplerKind kind) const { + ast::Sampler* sampler(const Source& source, ast::SamplerKind kind) const { return builder->create(source, kind); } /// @param dims the dimensionality of the texture /// @returns the depth texture - typ::DepthTexture depth_texture(ast::TextureDimension dims) const { + ast::DepthTexture* depth_texture(ast::TextureDimension dims) const { return builder->create(dims); } /// @param source the Source of the node /// @param dims the dimensionality of the texture /// @returns the depth texture - typ::DepthTexture depth_texture(const Source& source, - ast::TextureDimension dims) const { + ast::DepthTexture* depth_texture(const Source& source, + ast::TextureDimension dims) const { return builder->create(source, dims); } /// @param dims the dimensionality of the texture /// @param subtype the texture subtype. /// @returns the sampled texture - typ::SampledTexture sampled_texture(ast::TextureDimension dims, - ast::Type* subtype) const { + ast::SampledTexture* sampled_texture(ast::TextureDimension dims, + ast::Type* subtype) const { return builder->create(dims, subtype); } @@ -770,17 +771,17 @@ class ProgramBuilder { /// @param dims the dimensionality of the texture /// @param subtype the texture subtype. /// @returns the sampled texture - typ::SampledTexture sampled_texture(const Source& source, - ast::TextureDimension dims, - ast::Type* subtype) const { + ast::SampledTexture* sampled_texture(const Source& source, + ast::TextureDimension dims, + ast::Type* subtype) const { return builder->create(source, dims, subtype); } /// @param dims the dimensionality of the texture /// @param subtype the texture subtype. /// @returns the multisampled texture - typ::MultisampledTexture multisampled_texture(ast::TextureDimension dims, - ast::Type* subtype) const { + ast::MultisampledTexture* multisampled_texture(ast::TextureDimension dims, + ast::Type* subtype) const { return builder->create(dims, subtype); } @@ -788,17 +789,17 @@ class ProgramBuilder { /// @param dims the dimensionality of the texture /// @param subtype the texture subtype. /// @returns the multisampled texture - typ::MultisampledTexture multisampled_texture(const Source& source, - ast::TextureDimension dims, - ast::Type* subtype) const { + ast::MultisampledTexture* multisampled_texture(const Source& source, + ast::TextureDimension dims, + ast::Type* subtype) const { return builder->create(source, dims, subtype); } /// @param dims the dimensionality of the texture /// @param format the image format of the texture /// @returns the storage texture - typ::StorageTexture storage_texture(ast::TextureDimension dims, - ast::ImageFormat format) const { + ast::StorageTexture* storage_texture(ast::TextureDimension dims, + ast::ImageFormat format) const { auto* subtype = ast::StorageTexture::SubtypeFor(format, *builder); return builder->create(dims, format, subtype); } @@ -807,22 +808,22 @@ class ProgramBuilder { /// @param dims the dimensionality of the texture /// @param format the image format of the texture /// @returns the storage texture - typ::StorageTexture storage_texture(const Source& source, - ast::TextureDimension dims, - ast::ImageFormat format) const { + ast::StorageTexture* storage_texture(const Source& source, + ast::TextureDimension dims, + ast::ImageFormat format) const { auto* subtype = ast::StorageTexture::SubtypeFor(format, *builder); return builder->create(source, dims, format, subtype); } /// @returns the external texture - typ::ExternalTexture external_texture() const { + ast::ExternalTexture* external_texture() const { return builder->create(); } /// @param source the Source of the node /// @returns the external texture - typ::ExternalTexture external_texture(const Source& source) const { + ast::ExternalTexture* external_texture(const Source& source) const { return builder->create(source); } @@ -847,7 +848,7 @@ class ProgramBuilder { /// contains a single static `get()` method for obtaining the corresponding /// AST type for the C type `T`. /// `get()` has the signature: - /// `static typ::Type get(Types* t)` + /// `static ast::Type* get(Types* t)` template struct CToAST {}; }; @@ -1333,7 +1334,7 @@ class ProgramBuilder { /// variable with the ast::Module. template ast::Variable* GlobalConst(NAME&& name, - typ::Type type, + ast::Type* type, ast::Expression* constructor, ast::DecorationList decorations = {}) { auto* var = Const(std::forward(name), type, constructor, @@ -1353,7 +1354,7 @@ class ProgramBuilder { template ast::Variable* GlobalConst(const Source& source, NAME&& name, - typ::Type type, + ast::Type* type, ast::Expression* constructor, ast::DecorationList decorations = {}) { auto* var = Const(source, std::forward(name), type, constructor, @@ -2003,31 +2004,31 @@ class ProgramBuilder { // Various template specializations for ProgramBuilder::TypesBuilder::CToAST. template <> struct ProgramBuilder::TypesBuilder::CToAST { - static typ::Type get(const ProgramBuilder::TypesBuilder* t) { + static ast::Type* get(const ProgramBuilder::TypesBuilder* t) { return t->i32(); } }; template <> struct ProgramBuilder::TypesBuilder::CToAST { - static typ::Type get(const ProgramBuilder::TypesBuilder* t) { + static ast::Type* get(const ProgramBuilder::TypesBuilder* t) { return t->u32(); } }; template <> struct ProgramBuilder::TypesBuilder::CToAST { - static typ::Type get(const ProgramBuilder::TypesBuilder* t) { + static ast::Type* get(const ProgramBuilder::TypesBuilder* t) { return t->f32(); } }; template <> struct ProgramBuilder::TypesBuilder::CToAST { - static typ::Type get(const ProgramBuilder::TypesBuilder* t) { + static ast::Type* get(const ProgramBuilder::TypesBuilder* t) { return t->bool_(); } }; template <> struct ProgramBuilder::TypesBuilder::CToAST { - static typ::Type get(const ProgramBuilder::TypesBuilder* t) { + static ast::Type* get(const ProgramBuilder::TypesBuilder* t) { return t->void_(); } }; diff --git a/src/program_builder_test.cc b/src/program_builder_test.cc index f5a7394049..bfa9159f26 100644 --- a/src/program_builder_test.cc +++ b/src/program_builder_test.cc @@ -33,7 +33,7 @@ TEST_F(ProgramBuilderTest, IDsAreUnique) { TEST_F(ProgramBuilderTest, WrapDoesntAffectInner) { Program inner([] { ProgramBuilder builder; - auto ty = builder.ty.f32(); + auto* ty = builder.ty.f32(); builder.Func("a", {}, ty, {}, {}); return builder; }()); @@ -54,7 +54,7 @@ TEST_F(ProgramBuilderTest, WrapDoesntAffectInner) { EXPECT_FALSE(inner.Symbols().Get("b").IsValid()); EXPECT_FALSE(outer.Symbols().Get("b").IsValid()); - auto ty = outer.ty.f32(); + auto* ty = outer.ty.f32(); outer.Func("b", {}, ty, {}, {}); ASSERT_EQ(inner.AST().Functions().size(), 1u); diff --git a/src/reader/wgsl/parser_impl.h b/src/reader/wgsl/parser_impl.h index 513da69689..261d2c919f 100644 --- a/src/reader/wgsl/parser_impl.h +++ b/src/reader/wgsl/parser_impl.h @@ -27,7 +27,6 @@ #include "src/reader/wgsl/parser_impl_detail.h" #include "src/reader/wgsl/token.h" #include "src/sem/storage_texture_type.h" -#include "src/typepair.h" namespace tint { namespace ast { diff --git a/src/reader/wgsl/parser_impl_detail.h b/src/reader/wgsl/parser_impl_detail.h index 26f2813968..6d5d144438 100644 --- a/src/reader/wgsl/parser_impl_detail.h +++ b/src/reader/wgsl/parser_impl_detail.h @@ -16,7 +16,6 @@ #define SRC_READER_WGSL_PARSER_IMPL_DETAIL_H_ #include -#include "src/typepair.h" namespace tint { namespace reader { @@ -63,17 +62,6 @@ struct OperatorArrow { static inline T* ptr(T* val) { return val; } }; -/// OperatorArrow template specialization for TypePair. -template -struct OperatorArrow> { - /// type resolves to the same as input type to allow for operator-> chaining - using type = typ::TypePair; - /// @param val the value held by `ParserImpl::Expect` or - /// `ParserImpl::Maybe`. - /// @return `val`. - static inline type& ptr(type& val) { return val; } -}; - } // namespace detail } // namespace wgsl } // namespace reader diff --git a/src/resolver/assignment_validation_test.cc b/src/resolver/assignment_validation_test.cc index 86a92c23a7..3a4bc3f4c3 100644 --- a/src/resolver/assignment_validation_test.cc +++ b/src/resolver/assignment_validation_test.cc @@ -161,8 +161,8 @@ TEST_F(ResolverAssignmentValidationTest, AssignNonStorable_Fail) { // a = b; auto make_type = [&] { - auto tex_type = ty.storage_texture(ast::TextureDimension::k1d, - ast::ImageFormat::kRgba8Unorm); + auto* tex_type = ty.storage_texture(ast::TextureDimension::k1d, + ast::ImageFormat::kRgba8Unorm); return ty.access(ast::AccessControl::kReadOnly, tex_type); }; diff --git a/src/resolver/intrinsic_test.cc b/src/resolver/intrinsic_test.cc index 69a8001121..76452e8366 100644 --- a/src/resolver/intrinsic_test.cc +++ b/src/resolver/intrinsic_test.cc @@ -222,7 +222,7 @@ class ResolverIntrinsicTest_TextureOperation /// @param dim dimensionality of the texture being sampled /// @param scalar the scalar type /// @returns a pointer to a type appropriate for the coord param - typ::Type GetCoordsType(ast::TextureDimension dim, typ::Type scalar) { + ast::Type* GetCoordsType(ast::TextureDimension dim, ast::Type* scalar) { switch (dim) { case ast::TextureDimension::k1d: return scalar; @@ -255,7 +255,7 @@ class ResolverIntrinsicTest_TextureOperation call_params->push_back(Expr(name)); } - typ::Type subtype(Texture type) { + ast::Type* subtype(Texture type) { if (type == Texture::kF32) { return ty.f32(); } @@ -273,8 +273,8 @@ TEST_P(ResolverIntrinsicTest_StorageTextureOperation, TextureLoadRo) { auto type = GetParam().type; auto format = GetParam().format; - auto coords_type = GetCoordsType(dim, ty.i32()); - auto texture_type = ty.storage_texture(dim, format); + auto* coords_type = GetCoordsType(dim, ty.i32()); + auto* texture_type = ty.storage_texture(dim, format); auto* ro_texture_type = ty.access(ast::AccessControl::kReadOnly, texture_type); @@ -339,9 +339,9 @@ TEST_P(ResolverIntrinsicTest_SampledTextureOperation, TextureLoadSampled) { auto dim = GetParam().dim; auto type = GetParam().type; - auto s = subtype(type); - auto coords_type = GetCoordsType(dim, ty.i32()); - auto texture_type = ty.sampled_texture(dim, s); + auto* s = subtype(type); + auto* coords_type = GetCoordsType(dim, ty.i32()); + auto* texture_type = ty.sampled_texture(dim, s); ast::ExpressionList call_params; diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc index 246c2dafaf..dba06cefd1 100644 --- a/src/resolver/resolver.cc +++ b/src/resolver/resolver.cc @@ -2446,7 +2446,7 @@ bool Resolver::ValidateNamedType(const ast::NamedType* named_type) const { sem::Type* Resolver::TypeOf(const ast::Expression* expr) { auto it = expr_info_.find(expr); if (it != expr_info_.end()) { - return it->second.type; + return const_cast(it->second.type); } return nullptr; } @@ -2477,19 +2477,17 @@ sem::Type* Resolver::TypeOf(const ast::Literal* lit) { return nullptr; } -void Resolver::SetType(ast::Expression* expr, typ::Type type) { - SetType(expr, type, - type.sem ? type.sem->FriendlyName(builder_->Symbols()) - : type.ast->FriendlyName(builder_->Symbols())); +void Resolver::SetType(ast::Expression* expr, const ast::Type* type) { + SetType(expr, Type(type), type->FriendlyName(builder_->Symbols())); +} + +void Resolver::SetType(ast::Expression* expr, const sem::Type* type) { + SetType(expr, type, type->FriendlyName(builder_->Symbols())); } void Resolver::SetType(ast::Expression* expr, - typ::Type type, + const sem::Type* type, const std::string& type_name) { - if (!type.sem) { - type.sem = Type(type.ast); - TINT_ASSERT(type.sem); - } if (expr_info_.count(expr)) { TINT_ICE(diagnostics_) << "SetType() called twice for the same expression"; } diff --git a/src/resolver/resolver.h b/src/resolver/resolver.h index ac2bbf0f0c..2df47896fc 100644 --- a/src/resolver/resolver.h +++ b/src/resolver/resolver.h @@ -122,7 +122,7 @@ class Resolver { /// Structure holding semantic information about an expression. /// Used to build the sem::Expression nodes at the end of resolving. struct ExpressionInfo { - sem::Type* type; + sem::Type const* type; std::string const type_name; // Declared type name sem::Statement* statement; }; @@ -318,11 +318,17 @@ class Resolver { /// @param lit the literal sem::Type* TypeOf(const ast::Literal* lit); + /// Creates a sem::Expression node with the pre-resolved AST type `type`, and + /// assigns this semantic node to the expression `expr`. + /// @param expr the expression + /// @param type the AST type + void SetType(ast::Expression* expr, const ast::Type* type); + /// Creates a sem::Expression node with the resolved type `type`, and /// assigns this semantic node to the expression `expr`. /// @param expr the expression /// @param type the resolved type - void SetType(ast::Expression* expr, typ::Type type); + void SetType(ast::Expression* expr, const sem::Type* type); /// Creates a sem::Expression node with the resolved type `type`, the declared /// type name `type_name` and assigns this semantic node to the expression @@ -331,7 +337,7 @@ class Resolver { /// @param type the resolved type /// @param type_name the declared type name void SetType(ast::Expression* expr, - typ::Type type, + const sem::Type* type, const std::string& type_name); /// Resolve the value of a scalar const_expr. diff --git a/src/resolver/resolver_test.cc b/src/resolver/resolver_test.cc index 53fb0b7fc3..1645aaba1e 100644 --- a/src/resolver/resolver_test.cc +++ b/src/resolver/resolver_test.cc @@ -1579,8 +1579,8 @@ TEST_P(Expr_Binary_Test_Invalid_MatrixMatrixMultiply, All) { uint32_t rhs_mat_rows = std::get<2>(GetParam()); uint32_t rhs_mat_cols = std::get<3>(GetParam()); - auto lhs_type = ty.mat(lhs_mat_cols, lhs_mat_rows); - auto rhs_type = ty.mat(rhs_mat_cols, rhs_mat_rows); + auto* lhs_type = ty.mat(lhs_mat_cols, lhs_mat_rows); + auto* rhs_type = ty.mat(rhs_mat_cols, rhs_mat_rows); auto* f32 = create(); auto* col = create(f32, lhs_mat_rows); @@ -1650,7 +1650,7 @@ TEST_F(ResolverTest, StorageClass_SetsIfMissing) { } TEST_F(ResolverTest, StorageClass_SetForSampler) { - auto t = ty.sampler(ast::SamplerKind::kSampler); + auto* t = ty.sampler(ast::SamplerKind::kSampler); auto* var = Global("var", t, ast::StorageClass::kNone, nullptr, { create(0), @@ -1664,7 +1664,7 @@ TEST_F(ResolverTest, StorageClass_SetForSampler) { } TEST_F(ResolverTest, StorageClass_SetForTexture) { - auto t = ty.sampled_texture(ast::TextureDimension::k1d, ty.f32()); + auto* t = ty.sampled_texture(ast::TextureDimension::k1d, ty.f32()); auto* ac = ty.access(ast::AccessControl::kReadOnly, t); auto* var = Global("var", ac, ast::StorageClass::kNone, nullptr, { diff --git a/src/resolver/resolver_test_helper.h b/src/resolver/resolver_test_helper.h index a9dbb36c44..b82aec0172 100644 --- a/src/resolver/resolver_test_helper.h +++ b/src/resolver/resolver_test_helper.h @@ -99,9 +99,15 @@ class TestHelper : public ProgramBuilder { /// @param type a type /// @returns the name for `type` that closely resembles how it would be /// declared in WGSL. - std::string FriendlyName(typ::Type type) { - return type.ast ? type.ast->FriendlyName(Symbols()) - : type.sem->FriendlyName(Symbols()); + std::string FriendlyName(const ast::Type* type) { + return type->FriendlyName(Symbols()); + } + + /// @param type a type + /// @returns the name for `type` that closely resembles how it would be + /// declared in WGSL. + std::string FriendlyName(const sem::Type* type) { + return type->FriendlyName(Symbols()); } private: diff --git a/src/resolver/type_validation_test.cc b/src/resolver/type_validation_test.cc index de11bb9266..86481e954b 100644 --- a/src/resolver/type_validation_test.cc +++ b/src/resolver/type_validation_test.cc @@ -513,7 +513,7 @@ TEST_P(StorageTextureDimensionTest, All) { // var a : [[access(read)]] texture_storage_*; auto& params = GetParam(); - auto st = ty.storage_texture(params.dim, ast::ImageFormat::kR32Uint); + auto* st = ty.storage_texture(params.dim, ast::ImageFormat::kR32Uint); auto* ac = ty.access(ast::AccessControl::kReadOnly, st); Global("a", ac, ast::StorageClass::kNone, nullptr, @@ -586,7 +586,7 @@ TEST_P(StorageTextureFormatTest, All) { // [[group(0), binding(3)]] // var d : [[access(read)]] texture_storage_3d<*>; - auto st_a = ty.storage_texture(ast::TextureDimension::k1d, params.format); + auto* st_a = ty.storage_texture(ast::TextureDimension::k1d, params.format); auto* ac_a = ty.access(ast::AccessControl::kReadOnly, st_a); Global("a", ac_a, ast::StorageClass::kNone, nullptr, ast::DecorationList{ @@ -594,7 +594,7 @@ TEST_P(StorageTextureFormatTest, All) { create(0), }); - auto st_b = ty.storage_texture(ast::TextureDimension::k2d, params.format); + auto* st_b = ty.storage_texture(ast::TextureDimension::k2d, params.format); auto* ac_b = ty.access(ast::AccessControl::kReadOnly, st_b); Global("b", ac_b, ast::StorageClass::kNone, nullptr, ast::DecorationList{ @@ -602,7 +602,7 @@ TEST_P(StorageTextureFormatTest, All) { create(1), }); - auto st_c = + auto* st_c = ty.storage_texture(ast::TextureDimension::k2dArray, params.format); auto* ac_c = ty.access(ast::AccessControl::kReadOnly, st_c); Global("c", ac_c, ast::StorageClass::kNone, nullptr, @@ -611,7 +611,7 @@ TEST_P(StorageTextureFormatTest, All) { create(2), }); - auto st_d = ty.storage_texture(ast::TextureDimension::k3d, params.format); + auto* st_d = ty.storage_texture(ast::TextureDimension::k3d, params.format); auto* ac_d = ty.access(ast::AccessControl::kReadOnly, st_d); Global("d", ac_d, ast::StorageClass::kNone, nullptr, ast::DecorationList{ @@ -635,8 +635,8 @@ TEST_F(StorageTextureAccessControlTest, MissingAccessControl_Fail) { // [[group(0), binding(0)]] // var a : texture_storage_1d; - auto st = ty.storage_texture(ast::TextureDimension::k1d, - ast::ImageFormat::kR32Uint); + auto* st = ty.storage_texture(ast::TextureDimension::k1d, + ast::ImageFormat::kR32Uint); Global("a", st, ast::StorageClass::kNone, nullptr, ast::DecorationList{ @@ -651,8 +651,8 @@ TEST_F(StorageTextureAccessControlTest, RWAccessControl_Fail) { // [[group(0), binding(0)]] // var a : [[access(readwrite)]] texture_storage_1d; - auto st = ty.storage_texture(ast::TextureDimension::k1d, - ast::ImageFormat::kR32Uint); + auto* st = ty.storage_texture(ast::TextureDimension::k1d, + ast::ImageFormat::kR32Uint); Global("a", st, ast::StorageClass::kNone, nullptr, ast::DecorationList{ @@ -667,8 +667,8 @@ TEST_F(StorageTextureAccessControlTest, ReadOnlyAccessControl_Pass) { // [[group(0), binding(0)]] // var a : [[access(read)]] texture_storage_1d; - auto st = ty.storage_texture(ast::TextureDimension::k1d, - ast::ImageFormat::kR32Uint); + auto* st = ty.storage_texture(ast::TextureDimension::k1d, + ast::ImageFormat::kR32Uint); auto* ac = ty.access(ast::AccessControl::kReadOnly, st); Global("a", ac, ast::StorageClass::kNone, nullptr, @@ -684,8 +684,8 @@ TEST_F(StorageTextureAccessControlTest, WriteOnlyAccessControl_Pass) { // [[group(0), binding(0)]] // var a : [[access(write)]] texture_storage_1d; - auto st = ty.storage_texture(ast::TextureDimension::k1d, - ast::ImageFormat::kR32Uint); + auto* st = ty.storage_texture(ast::TextureDimension::k1d, + ast::ImageFormat::kR32Uint); auto* ac = ty.access(ast::AccessControl::kWriteOnly, st); Global("a", ac, ast::StorageClass::kNone, nullptr, diff --git a/src/resolver/validation_test.cc b/src/resolver/validation_test.cc index ed4d08992d..4b9731c7d9 100644 --- a/src/resolver/validation_test.cc +++ b/src/resolver/validation_test.cc @@ -343,7 +343,7 @@ TEST_F(ResolverValidationTest, StorageClass_NonFunctionClassError) { } TEST_F(ResolverValidationTest, StorageClass_SamplerExplicitStorageClass) { - auto t = ty.sampler(ast::SamplerKind::kSampler); + auto* t = ty.sampler(ast::SamplerKind::kSampler); Global(Source{{12, 34}}, "var", t, ast::StorageClass::kUniformConstant, nullptr, { @@ -359,7 +359,7 @@ TEST_F(ResolverValidationTest, StorageClass_SamplerExplicitStorageClass) { } TEST_F(ResolverValidationTest, StorageClass_TextureExplicitStorageClass) { - auto t = ty.sampled_texture(ast::TextureDimension::k1d, ty.f32()); + auto* t = ty.sampled_texture(ast::TextureDimension::k1d, ty.f32()); Global(Source{{12, 34}}, "var", t, ast::StorageClass::kUniformConstant, nullptr, { @@ -1729,7 +1729,7 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vector_ElementTypeAlias_Error) { AST().AddConstructedType(f32_alias); // vec2(1.0f, 1u) - auto vec_type = ty.vec(f32_alias, 2); + auto* vec_type = ty.vec(f32_alias, 2); auto* tc = create( Source{{12, 34}}, vec_type, ExprList(1.0f, create(Source{{12, 40}}, @@ -1748,7 +1748,7 @@ TEST_F(ResolverValidationTest, AST().AddConstructedType(f32_alias); // vec2(1.0f, 1.0f) - auto vec_type = ty.vec(f32_alias, 2); + auto* vec_type = ty.vec(f32_alias, 2); auto* tc = create(Source{{12, 34}}, vec_type, ExprList(1.0f, 1.0f)); WrapInFunction(tc); @@ -1762,7 +1762,7 @@ TEST_F(ResolverValidationTest, AST().AddConstructedType(f32_alias); // vec3(vec(), 1.0f) - auto vec_type = ty.vec(f32_alias, 2); + auto* vec_type = ty.vec(f32_alias, 2); auto* tc = vec3(create( Source{{12, 34}}, vec_type, ExprList()), 1.0f); @@ -1780,7 +1780,7 @@ TEST_F(ResolverValidationTest, AST().AddConstructedType(f32_alias); // vec3(vec(), 1.0f) - auto vec_type = ty.vec(f32_alias, 2); + auto* vec_type = ty.vec(f32_alias, 2); auto* tc = vec3(create( Source{{12, 34}}, vec_type, ExprList()), 1.0f); @@ -1813,12 +1813,12 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_Error_TooFewArguments) { ast::ExpressionList args; for (uint32_t i = 1; i <= param.columns - 1; i++) { - auto vec_type = ty.vec(param.rows); + auto* vec_type = ty.vec(param.rows); args.push_back(create( Source{{12, i}}, vec_type, ExprList())); } - auto matrix_type = ty.mat(param.columns, param.rows); + auto* matrix_type = ty.mat(param.columns, param.rows); auto* tc = create(Source{}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -1837,12 +1837,12 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_Error_TooManyArguments) { ast::ExpressionList args; for (uint32_t i = 1; i <= param.columns + 1; i++) { - auto vec_type = ty.vec(param.rows); + auto* vec_type = ty.vec(param.rows); args.push_back(create( Source{{12, i}}, vec_type, ExprList())); } - auto matrix_type = ty.mat(param.columns, param.rows); + auto* matrix_type = ty.mat(param.columns, param.rows); auto* tc = create(Source{}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -1865,7 +1865,7 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_Error_InvalidArgumentType) { Literal(1.0f))); } - auto matrix_type = ty.mat(param.columns, param.rows); + auto* matrix_type = ty.mat(param.columns, param.rows); auto* tc = create(Source{}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -1889,16 +1889,16 @@ TEST_P(MatrixConstructorTest, ast::ExpressionList args; for (uint32_t i = 1; i <= param.columns - 1; i++) { - auto valid_vec_type = ty.vec(param.rows); + auto* valid_vec_type = ty.vec(param.rows); args.push_back(create( Source{{12, i}}, valid_vec_type, ExprList())); } const size_t kInvalidLoc = 2 * (param.columns - 1); - auto invalid_vec_type = ty.vec(param.rows - 1); + auto* invalid_vec_type = ty.vec(param.rows - 1); args.push_back(create( Source{{12, kInvalidLoc}}, invalid_vec_type, ExprList())); - auto matrix_type = ty.mat(param.columns, param.rows); + auto* matrix_type = ty.mat(param.columns, param.rows); auto* tc = create(Source{}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -1924,16 +1924,16 @@ TEST_P(MatrixConstructorTest, ast::ExpressionList args; for (uint32_t i = 1; i <= param.columns - 1; i++) { - auto valid_vec_type = ty.vec(param.rows); + auto* valid_vec_type = ty.vec(param.rows); args.push_back(create( Source{{12, i}}, valid_vec_type, ExprList())); } const size_t kInvalidLoc = 2 * (param.columns - 1); - auto invalid_vec_type = ty.vec(param.rows + 1); + auto* invalid_vec_type = ty.vec(param.rows + 1); args.push_back(create( Source{{12, kInvalidLoc}}, invalid_vec_type, ExprList())); - auto matrix_type = ty.mat(param.columns, param.rows); + auto* matrix_type = ty.mat(param.columns, param.rows); auto* tc = create(Source{}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -1954,12 +1954,12 @@ TEST_P(MatrixConstructorTest, ast::ExpressionList args; for (uint32_t i = 1; i <= param.columns; i++) { - auto vec_type = ty.vec(param.rows); + auto* vec_type = ty.vec(param.rows); args.push_back(create( Source{{12, i}}, vec_type, ExprList())); } - auto matrix_type = ty.mat(param.columns, param.rows); + auto* matrix_type = ty.mat(param.columns, param.rows); auto* tc = create(Source{}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -1975,7 +1975,7 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ZeroValue_Success) { // matNxM(); const auto param = GetParam(); - auto matrix_type = ty.mat(param.columns, param.rows); + auto* matrix_type = ty.mat(param.columns, param.rows); auto* tc = create(Source{{12, 40}}, matrix_type, ExprList()); WrapInFunction(tc); @@ -1990,12 +1990,12 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_WithArguments_Success) { ast::ExpressionList args; for (uint32_t i = 1; i <= param.columns; i++) { - auto vec_type = ty.vec(param.rows); + auto* vec_type = ty.vec(param.rows); args.push_back(create( Source{{12, i}}, vec_type, ExprList())); } - auto matrix_type = ty.mat(param.columns, param.rows); + auto* matrix_type = ty.mat(param.columns, param.rows); auto* tc = create(Source{}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -2012,12 +2012,12 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ElementTypeAlias_Error) { ast::ExpressionList args; for (uint32_t i = 1; i <= param.columns; i++) { - auto vec_type = ty.vec(ty.u32(), param.rows); + auto* vec_type = ty.vec(ty.u32(), param.rows); args.push_back(create( Source{{12, i}}, vec_type, ExprList())); } - auto matrix_type = ty.mat(f32_alias, param.columns, param.rows); + auto* matrix_type = ty.mat(f32_alias, param.columns, param.rows); auto* tc = create(Source{}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -2038,12 +2038,12 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ElementTypeAlias_Success) { ast::ExpressionList args; for (uint32_t i = 1; i <= param.columns; i++) { - auto vec_type = ty.vec(param.rows); + auto* vec_type = ty.vec(param.rows); args.push_back(create( Source{{12, i}}, vec_type, ExprList())); } - auto matrix_type = ty.mat(f32_alias, param.columns, param.rows); + auto* matrix_type = ty.mat(f32_alias, param.columns, param.rows); auto* tc = create(Source{}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -2068,8 +2068,8 @@ TEST_F(ResolverValidationTest, Expr_MatrixConstructor_ArgumentTypeAlias_Error) { TEST_P(MatrixConstructorTest, Expr_Constructor_ArgumentTypeAlias_Success) { const auto param = GetParam(); - auto matrix_type = ty.mat(param.columns, param.rows); - auto vec_type = ty.vec(param.rows); + auto* matrix_type = ty.mat(param.columns, param.rows); + auto* vec_type = ty.vec(param.rows); auto* vec_alias = ty.alias("VectorFloat2", vec_type); AST().AddConstructedType(vec_alias); @@ -2088,13 +2088,13 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ArgumentTypeAlias_Success) { TEST_P(MatrixConstructorTest, Expr_Constructor_ArgumentElementTypeAlias_Error) { const auto param = GetParam(); - auto matrix_type = ty.mat(param.columns, param.rows); + auto* matrix_type = ty.mat(param.columns, param.rows); auto* f32_alias = ty.alias("UnsignedInt", ty.u32()); AST().AddConstructedType(f32_alias); ast::ExpressionList args; for (uint32_t i = 1; i <= param.columns; i++) { - auto vec_type = ty.vec(f32_alias, param.rows); + auto* vec_type = ty.vec(f32_alias, param.rows); args.push_back(create( Source{{12, i}}, vec_type, ExprList())); } @@ -2118,12 +2118,12 @@ TEST_P(MatrixConstructorTest, ast::ExpressionList args; for (uint32_t i = 1; i <= param.columns; i++) { - auto vec_type = ty.vec(f32_alias, param.rows); + auto* vec_type = ty.vec(f32_alias, param.rows); args.push_back(create( Source{{12, i}}, vec_type, ExprList())); } - auto matrix_type = ty.mat(param.columns, param.rows); + auto* matrix_type = ty.mat(param.columns, param.rows); auto* tc = create(Source{}, matrix_type, std::move(args)); WrapInFunction(tc); diff --git a/src/transform/external_texture_transform.cc b/src/transform/external_texture_transform.cc index c8fb07fe1e..036c296f0c 100644 --- a/src/transform/external_texture_transform.cc +++ b/src/transform/external_texture_transform.cc @@ -108,8 +108,8 @@ Output ExternalTextureTransform::Run(const Program* in, const DataMap&) { if (Is(var->type())) { // Replace a single-plane external texture with a 2D, f32 sampled // texture. - auto newType = ctx.dst->ty.sampled_texture(ast::TextureDimension::k2d, - ctx.dst->ty.f32()); + auto* newType = ctx.dst->ty.sampled_texture(ast::TextureDimension::k2d, + ctx.dst->ty.f32()); auto clonedSrc = ctx.Clone(var->source()); auto clonedSym = ctx.Clone(var->symbol()); auto* clonedConstructor = ctx.Clone(var->constructor()); diff --git a/src/typepair.h b/src/typepair.h deleted file mode 100644 index 78b6a68bdf..0000000000 --- a/src/typepair.h +++ /dev/null @@ -1,273 +0,0 @@ -// Copyright 2021 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// This file contains temporary code to help implement the new `ast::Type`s. -// Once complete, this file should be completely removed. -// Bug: crbug.com/tint/724 - -#ifndef SRC_TYPEPAIR_H_ -#define SRC_TYPEPAIR_H_ - -#include -#include -#include - -// X11 likes to #define Bool leading to confusing error messages. -// If its defined, undefine it. -#ifdef Bool -#undef Bool -#endif - -namespace tint { - -namespace ast { -class AccessControl; -class Array; -class Bool; -class DepthTexture; -class ExternalTexture; -class F32; -class I32; -class Matrix; -class MultisampledTexture; -class Pointer; -class Sampler; -class SampledTexture; -class StorageTexture; -class Struct; -class Texture; -class Type; -class U32; -class Vector; -class Void; -} // namespace ast - -namespace sem { -class AccessControl; -class Array; -class Bool; -class DepthTexture; -class ExternalTexture; -class F32; -class I32; -class Matrix; -class MultisampledTexture; -class Pointer; -class Sampler; -class SampledTexture; -class StorageTexture; -class Struct; -class Texture; -class Type; -class U32; -class Vector; -class Void; -} // namespace sem - -namespace typ { // type-pair - -/// A simple wrapper around a raw pointer. Used to prevent a whole bunch of -/// warnings about `auto` needing to be declared as `auto*` while we're -/// migrating code. -template -struct Ptr { - /// The raw pointer - T* const ptr; - - /// Constructor - Ptr() = default; - - /// Copy constructor - /// @param other the Ptr to copy - template - Ptr(const Ptr& other) : ptr(static_cast(other.ptr)) {} - - /// Constructor - /// @param p the pointer to wrap in a Ptr - template - Ptr(U* p) : ptr(p) {} // NOLINT: explicit - - /// @returns the pointer - operator T*() { return ptr; } - - /// @returns the pointer - operator const T*() const { return ptr; } - - /// @returns the pointer - T* operator->() { return ptr; } - - /// @returns the pointer - const T* operator->() const { return ptr; } -}; - -/// TypePair is a pair of ast::Type and sem::Type pointers used to simplify -/// migration to the new ast::Type nodes. -/// -/// Type attempts to behave as either an ast::Type or sem::Type: -/// * Type has constructors that take either an ast::Type and sem::Type pointer -/// pair, and single-parameter implicit constructors for either a single -/// ast::Type or sem::Type pointer. -/// * Type also has user-defined conversion functions for returning either an -/// ast::Type or sem::Type pointer. -/// * operator->() returns the sem::Type pointer. Later in the migration this -/// will switch to returning the ast::Type pointer. -template -struct TypePair { - /// Alias of the `AST` template type parameter - using AST_TYPE = AST; - /// Alias of the `SEM` template type parameter - using SEM_TYPE = SEM; - - /// The ast::Type pointer - AST const* ast = nullptr; - /// The sem::Type pointer - SEM const* sem = nullptr; - - /// Constructor - TypePair() = default; - /// Copy constructor - /// @param other the TypePair to copy - template - TypePair(const TypePair& other) - : ast(static_cast(other.ast)), - sem(static_cast(other.sem)) {} - /// Constructor - /// @param a the ast::Type pointer - TypePair(const AST* a) : ast(a) {} // NOLINT: explicit - /// Constructor - /// @param s the sem::Type pointer - TypePair(const SEM* s) : sem(s) {} // NOLINT: explicit - /// Constructor - /// @param a the ast::Type pointer - /// @param s the sem::Type pointer - TypePair(const AST* a, const SEM* s) : ast(a), sem(s) {} - /// Constructor - /// @param ptr the Ptr - template - TypePair(Ptr ptr) : TypePair(ptr.ptr) {} // NOLINT: explicit - /// Constructor - TypePair(std::nullptr_t) {} // NOLINT: explicit - - /// @returns the ast::Type pointer - operator AST*() const { return const_cast(ast); } - /// @returns the sem::Type pointer - operator SEM*() const { return const_cast(sem); } - /// @returns the sem::Type pointer - SEM* operator->() const { return const_cast(sem); } - - /// @returns true if sem is valid - explicit operator bool() const { return sem != nullptr; } - - /// @param ty the semantic type to compare against - /// @returns true if the semantic type is equal to `ty` - bool operator==(sem::Type* ty) const { return sem == ty; } - - /// @param ty the semantic type to compare against - /// @returns true if the semantic type is not equal to `ty` - bool operator!=(sem::Type* ty) const { return !((*this) == ty); } - - /// @param other the TypePair to compare against - /// @returns true if this TypePair is less than `other` - template - bool operator<(const TypePair& other) const { - if (sem < other.sem) { - return true; - } - if (sem > other.sem) { - return false; - } - return ast < other.ast; - } -}; - -/// @param lhs LHS value to compare -/// @param rhs RHS value to compare -/// @returns true if values compare equal -template -bool operator==(const TypePair& lhs, const TypePair& rhs) { - return lhs.sem == rhs.sem; -} - -/// @param lhs LHS value to compare -/// @param rhs RHS value to compare -/// @returns true if values compare not equal -template -bool operator!=(const TypePair& lhs, const TypePair& rhs) { - return !(lhs == rhs); -} - -/// @param lhs LHS value to compare -/// @returns true if `lhs` is nullptr -template -bool operator==(const TypePair& lhs, std::nullptr_t) { - return lhs.sem == nullptr; -} - -/// @param lhs LHS value to compare -/// @returns true if `lhs` is not nullptr -template -bool operator!=(const TypePair& lhs, std::nullptr_t) { - return !(lhs == nullptr); -} - -/// @param rhs RHS value to compare -/// @returns true if `rhs` is nullptr -template -bool operator==(std::nullptr_t, const TypePair& rhs) { - return nullptr == rhs.sem; -} - -/// @param rhs RHS value to compare -/// @returns true if `rhs` is not nullptr -template -bool operator!=(std::nullptr_t, const TypePair& rhs) { - return !(nullptr == rhs); -} - -using Type = TypePair; - - -using Bool = Ptr; -using U32 = Ptr; -using I32 = Ptr; -using F32 = Ptr; -using Void = Ptr; -using DepthTexture = Ptr; -using ExternalTexture = Ptr; -using MultisampledTexture = Ptr; -using SampledTexture = Ptr; -using StorageTexture = Ptr; -using Texture = Ptr; -using Sampler = Ptr; -using Matrix = Ptr; -using Vector = Ptr; -using Pointer = Ptr; -using Struct = Ptr; - -// Helpers - -/// Makes a type pair, deducing the return type from input args -/// @parm ast the ast node -/// @param sem the sem node -/// @returns a type pair -template -inline auto MakeTypePair(AST* ast, SEM* sem) { - return TypePair{ast, sem}; -} - -} // namespace typ - -} // namespace tint - -#endif // SRC_TYPEPAIR_H_ diff --git a/src/writer/hlsl/generator_impl_member_accessor_test.cc b/src/writer/hlsl/generator_impl_member_accessor_test.cc index 431912d923..e155281428 100644 --- a/src/writer/hlsl/generator_impl_member_accessor_test.cc +++ b/src/writer/hlsl/generator_impl_member_accessor_test.cc @@ -25,63 +25,63 @@ namespace { using ::testing::HasSubstr; using create_type_func_ptr = - typ::Type (*)(const ProgramBuilder::TypesBuilder& ty); + ast::Type* (*)(const ProgramBuilder::TypesBuilder& ty); -inline typ::Type ty_i32(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type* ty_i32(const ProgramBuilder::TypesBuilder& ty) { return ty.i32(); } -inline typ::Type ty_u32(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type* ty_u32(const ProgramBuilder::TypesBuilder& ty) { return ty.u32(); } -inline typ::Type ty_f32(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type* ty_f32(const ProgramBuilder::TypesBuilder& ty) { return ty.f32(); } template -inline typ::Type ty_vec2(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type* ty_vec2(const ProgramBuilder::TypesBuilder& ty) { return ty.vec2(); } template -inline typ::Type ty_vec3(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type* ty_vec3(const ProgramBuilder::TypesBuilder& ty) { return ty.vec3(); } template -inline typ::Type ty_vec4(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type* ty_vec4(const ProgramBuilder::TypesBuilder& ty) { return ty.vec4(); } template -inline typ::Type ty_mat2x2(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type* ty_mat2x2(const ProgramBuilder::TypesBuilder& ty) { return ty.mat2x2(); } template -inline typ::Type ty_mat2x3(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type* ty_mat2x3(const ProgramBuilder::TypesBuilder& ty) { return ty.mat2x3(); } template -inline typ::Type ty_mat2x4(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type* ty_mat2x4(const ProgramBuilder::TypesBuilder& ty) { return ty.mat2x4(); } template -inline typ::Type ty_mat3x2(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type* ty_mat3x2(const ProgramBuilder::TypesBuilder& ty) { return ty.mat3x2(); } template -inline typ::Type ty_mat3x3(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type* ty_mat3x3(const ProgramBuilder::TypesBuilder& ty) { return ty.mat3x3(); } template -inline typ::Type ty_mat3x4(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type* ty_mat3x4(const ProgramBuilder::TypesBuilder& ty) { return ty.mat3x4(); } template -inline typ::Type ty_mat4x2(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type* ty_mat4x2(const ProgramBuilder::TypesBuilder& ty) { return ty.mat4x2(); } template -inline typ::Type ty_mat4x3(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type* ty_mat4x3(const ProgramBuilder::TypesBuilder& ty) { return ty.mat4x3(); } template -inline typ::Type ty_mat4x4(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type* ty_mat4x4(const ProgramBuilder::TypesBuilder& ty) { return ty.mat4x4(); } @@ -154,12 +154,8 @@ struct TypeCase { }; inline std::ostream& operator<<(std::ostream& out, TypeCase c) { ProgramBuilder b; - auto ty = c.member_type(b.ty); - if (ty.sem) { - out << ty.sem->FriendlyName(b.Symbols()); - } else { - out << ty.ast->FriendlyName(b.Symbols()); - } + auto* ty = c.member_type(b.ty); + out << ty->FriendlyName(b.Symbols()); return out; } diff --git a/src/writer/hlsl/generator_impl_type_test.cc b/src/writer/hlsl/generator_impl_type_test.cc index 041804454d..a4c2b97034 100644 --- a/src/writer/hlsl/generator_impl_type_test.cc +++ b/src/writer/hlsl/generator_impl_type_test.cc @@ -352,7 +352,7 @@ using HlslDepthTexturesTest = TestParamHelper; TEST_P(HlslDepthTexturesTest, Emit) { auto params = GetParam(); - auto t = ty.depth_texture(params.dim); + auto* t = ty.depth_texture(params.dim); Global("tex", t, ast::StorageClass::kNone, nullptr, ast::DecorationList{ @@ -399,7 +399,7 @@ using HlslSampledTexturesTest = TestParamHelper; TEST_P(HlslSampledTexturesTest, Emit) { auto params = GetParam(); - typ::Type datatype; + ast::Type* datatype = nullptr; switch (params.datatype) { case TextureDataType::F32: datatype = ty.f32(); @@ -411,7 +411,7 @@ TEST_P(HlslSampledTexturesTest, Emit) { datatype = ty.i32(); break; } - auto t = ty.sampled_texture(params.dim, datatype); + auto* t = ty.sampled_texture(params.dim, datatype); Global("tex", t, ast::StorageClass::kNone, nullptr, ast::DecorationList{ @@ -552,7 +552,7 @@ using HlslStorageTexturesTest = TestParamHelper; TEST_P(HlslStorageTexturesTest, Emit) { auto params = GetParam(); - auto t = ty.storage_texture(params.dim, params.imgfmt); + auto* t = ty.storage_texture(params.dim, params.imgfmt); auto* ac = ty.access(params.ro ? ast::AccessControl::kReadOnly : ast::AccessControl::kWriteOnly, t); diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index f2928a9c01..9fd861afe6 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -920,10 +920,7 @@ bool GeneratorImpl::EmitTypeConstructor(ast::TypeConstructorExpression* expr) { return true; } -bool GeneratorImpl::EmitZeroValue(typ::Type type) { - if (!type.sem) { - type.sem = program_->Sem().Get(type.ast); - } +bool GeneratorImpl::EmitZeroValue(const sem::Type* type) { if (type->Is()) { out_ << "false"; } else if (type->Is()) { diff --git a/src/writer/msl/generator_impl.h b/src/writer/msl/generator_impl.h index f701dc274e..3608dc633e 100644 --- a/src/writer/msl/generator_impl.h +++ b/src/writer/msl/generator_impl.h @@ -227,7 +227,7 @@ class GeneratorImpl : public TextGenerator { /// Emits the zero value for the given type /// @param type the type to emit the value for /// @returns true if the zero value was successfully emitted. - bool EmitZeroValue(typ::Type type); + bool EmitZeroValue(const sem::Type* type); /// Determines if the function needs the input struct passed to it. /// @param func the function to check diff --git a/src/writer/msl/generator_impl_type_test.cc b/src/writer/msl/generator_impl_type_test.cc index cf3f14127b..8054ebdd47 100644 --- a/src/writer/msl/generator_impl_type_test.cc +++ b/src/writer/msl/generator_impl_type_test.cc @@ -765,7 +765,7 @@ using MslStorageTexturesTest = TestParamHelper; TEST_P(MslStorageTexturesTest, Emit) { auto params = GetParam(); - auto s = ty.storage_texture(params.dim, ast::ImageFormat::kR32Float); + auto* s = ty.storage_texture(params.dim, ast::ImageFormat::kR32Float); auto* ac = ty.access(params.ro ? ast::AccessControl::kReadOnly : ast::AccessControl::kWriteOnly, s); diff --git a/src/writer/spirv/builder_global_variable_test.cc b/src/writer/spirv/builder_global_variable_test.cc index fc1ee17cda..f084a403ea 100644 --- a/src/writer/spirv/builder_global_variable_test.cc +++ b/src/writer/spirv/builder_global_variable_test.cc @@ -570,8 +570,8 @@ OpName %5 "c" TEST_F(BuilderTest, GlobalVar_TextureStorageReadOnly) { // var a : [[access(read)]] texture_storage_2d; - auto type = ty.storage_texture(ast::TextureDimension::k2d, - ast::ImageFormat::kR32Uint); + auto* type = ty.storage_texture(ast::TextureDimension::k2d, + ast::ImageFormat::kR32Uint); auto* ac = ty.access(ast::AccessControl::kReadOnly, type); @@ -599,8 +599,8 @@ OpDecorate %1 DescriptorSet 0 TEST_F(BuilderTest, GlobalVar_TextureStorageWriteOnly) { // var a : [[access(write)]] texture_storage_2d; - auto type = ty.storage_texture(ast::TextureDimension::k2d, - ast::ImageFormat::kR32Uint); + auto* type = ty.storage_texture(ast::TextureDimension::k2d, + ast::ImageFormat::kR32Uint); auto* ac = ty.access(ast::AccessControl::kWriteOnly, type); diff --git a/src/writer/spirv/builder_intrinsic_test.cc b/src/writer/spirv/builder_intrinsic_test.cc index d6d8156807..3c40829063 100644 --- a/src/writer/spirv/builder_intrinsic_test.cc +++ b/src/writer/spirv/builder_intrinsic_test.cc @@ -370,8 +370,8 @@ TEST_F(IntrinsicBuilderTest, Call_Select) { // This tests that we do not push OpTypeSampledImage and float_0 type twice. TEST_F(IntrinsicBuilderTest, Call_TextureSampleCompare_Twice) { - auto s = ty.sampler(ast::SamplerKind::kComparisonSampler); - auto t = ty.depth_texture(ast::TextureDimension::k2d); + auto* s = ty.sampler(ast::SamplerKind::kComparisonSampler); + auto* t = ty.depth_texture(ast::TextureDimension::k2d); auto* tex = Global("texture", t, ast::StorageClass::kNone, nullptr, { diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc index 255f695dbb..fec6b39f04 100644 --- a/src/writer/spirv/builder_type_test.cc +++ b/src/writer/spirv/builder_type_test.cc @@ -830,8 +830,8 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_CubeArray) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_1d) { - auto s = ty.storage_texture(ast::TextureDimension::k1d, - ast::ImageFormat::kR32Float); + auto* s = ty.storage_texture(ast::TextureDimension::k1d, + ast::ImageFormat::kR32Float); auto* ac = ty.access(ast::AccessControl::kReadOnly, s); Global("test_var", ac, ast::StorageClass::kNone, nullptr, @@ -850,8 +850,8 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_1d) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) { - auto s = ty.storage_texture(ast::TextureDimension::k2d, - ast::ImageFormat::kR32Float); + auto* s = ty.storage_texture(ast::TextureDimension::k2d, + ast::ImageFormat::kR32Float); auto* ac = ty.access(ast::AccessControl::kReadOnly, s); Global("test_var", ac, ast::StorageClass::kNone, nullptr, @@ -870,8 +870,8 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) { - auto s = ty.storage_texture(ast::TextureDimension::k2dArray, - ast::ImageFormat::kR32Float); + auto* s = ty.storage_texture(ast::TextureDimension::k2dArray, + ast::ImageFormat::kR32Float); auto* ac = ty.access(ast::AccessControl::kReadOnly, s); Global("test_var", ac, ast::StorageClass::kNone, nullptr, @@ -890,8 +890,8 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) { - auto s = ty.storage_texture(ast::TextureDimension::k3d, - ast::ImageFormat::kR32Float); + auto* s = ty.storage_texture(ast::TextureDimension::k3d, + ast::ImageFormat::kR32Float); auto* ac = ty.access(ast::AccessControl::kReadOnly, s); Global("test_var", ac, ast::StorageClass::kNone, nullptr, @@ -911,8 +911,8 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) { TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeFloat_Format_r32float) { - auto s = ty.storage_texture(ast::TextureDimension::k2d, - ast::ImageFormat::kR32Float); + auto* s = ty.storage_texture(ast::TextureDimension::k2d, + ast::ImageFormat::kR32Float); auto* ac = ty.access(ast::AccessControl::kReadOnly, s); Global("test_var", ac, ast::StorageClass::kNone, nullptr, @@ -932,8 +932,8 @@ TEST_F(BuilderTest_Type, TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeSint_Format_r32sint) { - auto s = ty.storage_texture(ast::TextureDimension::k2d, - ast::ImageFormat::kR32Sint); + auto* s = ty.storage_texture(ast::TextureDimension::k2d, + ast::ImageFormat::kR32Sint); auto* ac = ty.access(ast::AccessControl::kReadOnly, s); Global("test_var", ac, ast::StorageClass::kNone, nullptr, @@ -953,8 +953,8 @@ TEST_F(BuilderTest_Type, TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeUint_Format_r32uint) { - auto s = ty.storage_texture(ast::TextureDimension::k2d, - ast::ImageFormat::kR32Uint); + auto* s = ty.storage_texture(ast::TextureDimension::k2d, + ast::ImageFormat::kR32Uint); auto* ac = ty.access(ast::AccessControl::kReadOnly, s); Global("test_var", ac, ast::StorageClass::kNone, nullptr, diff --git a/src/writer/wgsl/generator_impl_function_test.cc b/src/writer/wgsl/generator_impl_function_test.cc index 0e19f5a4ab..97bf435f7d 100644 --- a/src/writer/wgsl/generator_impl_function_test.cc +++ b/src/writer/wgsl/generator_impl_function_test.cc @@ -110,7 +110,7 @@ TEST_F(WgslGeneratorImplTest, } TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_Parameters) { - auto vec4 = ty.vec4(); + auto* vec4 = ty.vec4(); auto* coord = Param("coord", vec4, {Builtin(ast::Builtin::kPosition)}); auto* loc1 = Param("loc1", ty.f32(), {Location(1u)}); auto* func = Func("frag_main", ast::VariableList{coord, loc1}, ty.void_(), diff --git a/src/writer/wgsl/generator_impl_global_decl_test.cc b/src/writer/wgsl/generator_impl_global_decl_test.cc index db555b198c..76584d0118 100644 --- a/src/writer/wgsl/generator_impl_global_decl_test.cc +++ b/src/writer/wgsl/generator_impl_global_decl_test.cc @@ -113,7 +113,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Global_Sampler) { } TEST_F(WgslGeneratorImplTest, Emit_Global_Texture) { - auto st = ty.sampled_texture(ast::TextureDimension::k1d, ty.f32()); + auto* st = ty.sampled_texture(ast::TextureDimension::k1d, ty.f32()); Global("t", ty.access(ast::AccessControl::kReadOnly, st), ast::StorageClass::kNone, nullptr, {create(0), create(0)}); diff --git a/src/writer/wgsl/generator_impl_type_test.cc b/src/writer/wgsl/generator_impl_type_test.cc index cdd291e370..b15559d736 100644 --- a/src/writer/wgsl/generator_impl_type_test.cc +++ b/src/writer/wgsl/generator_impl_type_test.cc @@ -92,7 +92,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_RuntimeArray) { } TEST_F(WgslGeneratorImplTest, EmitType_Bool) { - auto bool_ = ty.bool_(); + auto* bool_ = ty.bool_(); AST().AddConstructedType(ty.alias("make_type_reachable", bool_)); GeneratorImpl& gen = Build(); @@ -102,7 +102,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Bool) { } TEST_F(WgslGeneratorImplTest, EmitType_F32) { - auto f32 = ty.f32(); + auto* f32 = ty.f32(); AST().AddConstructedType(ty.alias("make_type_reachable", f32)); GeneratorImpl& gen = Build(); @@ -112,7 +112,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_F32) { } TEST_F(WgslGeneratorImplTest, EmitType_I32) { - auto i32 = ty.i32(); + auto* i32 = ty.i32(); AST().AddConstructedType(ty.alias("make_type_reachable", i32)); GeneratorImpl& gen = Build(); @@ -122,7 +122,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_I32) { } TEST_F(WgslGeneratorImplTest, EmitType_Matrix) { - auto mat2x3 = ty.mat2x3(); + auto* mat2x3 = ty.mat2x3(); AST().AddConstructedType(ty.alias("make_type_reachable", mat2x3)); GeneratorImpl& gen = Build(); @@ -132,7 +132,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Matrix) { } TEST_F(WgslGeneratorImplTest, EmitType_Pointer) { - auto p = ty.pointer(ast::StorageClass::kWorkgroup); + auto* p = ty.pointer(ast::StorageClass::kWorkgroup); AST().AddConstructedType(ty.alias("make_type_reachable", p)); GeneratorImpl& gen = Build(); @@ -275,7 +275,7 @@ struct S { } TEST_F(WgslGeneratorImplTest, EmitType_U32) { - auto u32 = ty.u32(); + auto* u32 = ty.u32(); GeneratorImpl& gen = Build(); @@ -284,7 +284,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_U32) { } TEST_F(WgslGeneratorImplTest, EmitType_Vector) { - auto vec3 = ty.vec3(); + auto* vec3 = ty.vec3(); AST().AddConstructedType(ty.alias("make_type_reachable", vec3)); GeneratorImpl& gen = Build(); @@ -306,7 +306,7 @@ using WgslGenerator_DepthTextureTest = TestParamHelper; TEST_P(WgslGenerator_DepthTextureTest, EmitType_DepthTexture) { auto param = GetParam(); - auto d = ty.depth_texture(param.dim); + auto* d = ty.depth_texture(param.dim); AST().AddConstructedType(ty.alias("make_type_reachable", d)); GeneratorImpl& gen = Build(); @@ -328,7 +328,7 @@ using WgslGenerator_SampledTextureTest = TestParamHelper; TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_F32) { auto param = GetParam(); - auto t = ty.sampled_texture(param.dim, ty.f32()); + auto* t = ty.sampled_texture(param.dim, ty.f32()); AST().AddConstructedType(ty.alias("make_type_reachable", t)); GeneratorImpl& gen = Build(); @@ -340,7 +340,7 @@ TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_F32) { TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_I32) { auto param = GetParam(); - auto t = ty.sampled_texture(param.dim, ty.i32()); + auto* t = ty.sampled_texture(param.dim, ty.i32()); AST().AddConstructedType(ty.alias("make_type_reachable", t)); GeneratorImpl& gen = Build(); @@ -352,7 +352,7 @@ TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_I32) { TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_U32) { auto param = GetParam(); - auto t = ty.sampled_texture(param.dim, ty.u32()); + auto* t = ty.sampled_texture(param.dim, ty.u32()); AST().AddConstructedType(ty.alias("make_type_reachable", t)); GeneratorImpl& gen = Build(); @@ -375,7 +375,7 @@ using WgslGenerator_MultiampledTextureTest = TestParamHelper; TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_F32) { auto param = GetParam(); - auto t = ty.multisampled_texture(param.dim, ty.f32()); + auto* t = ty.multisampled_texture(param.dim, ty.f32()); AST().AddConstructedType(ty.alias("make_type_reachable", t)); GeneratorImpl& gen = Build(); @@ -387,7 +387,7 @@ TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_F32) { TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_I32) { auto param = GetParam(); - auto t = ty.multisampled_texture(param.dim, ty.i32()); + auto* t = ty.multisampled_texture(param.dim, ty.i32()); AST().AddConstructedType(ty.alias("make_type_reachable", t)); GeneratorImpl& gen = Build(); @@ -399,7 +399,7 @@ TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_I32) { TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_U32) { auto param = GetParam(); - auto t = ty.multisampled_texture(param.dim, ty.u32()); + auto* t = ty.multisampled_texture(param.dim, ty.u32()); AST().AddConstructedType(ty.alias("make_type_reachable", t)); GeneratorImpl& gen = Build(); @@ -427,7 +427,7 @@ using WgslGenerator_StorageTextureTest = TestParamHelper; TEST_P(WgslGenerator_StorageTextureTest, EmitType_StorageTexture) { auto param = GetParam(); - auto t = ty.storage_texture(param.dim, param.fmt); + auto* t = ty.storage_texture(param.dim, param.fmt); auto* ac = ty.access(param.access, t); GeneratorImpl& gen = Build(); @@ -531,7 +531,7 @@ INSTANTIATE_TEST_SUITE_P( ImageFormatData{ast::ImageFormat::kRgba32Float, "rgba32float"})); TEST_F(WgslGeneratorImplTest, EmitType_Sampler) { - auto sampler = ty.sampler(ast::SamplerKind::kSampler); + auto* sampler = ty.sampler(ast::SamplerKind::kSampler); AST().AddConstructedType(ty.alias("make_type_reachable", sampler)); GeneratorImpl& gen = Build(); @@ -541,7 +541,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Sampler) { } TEST_F(WgslGeneratorImplTest, EmitType_SamplerComparison) { - auto sampler = ty.sampler(ast::SamplerKind::kComparisonSampler); + auto* sampler = ty.sampler(ast::SamplerKind::kComparisonSampler); AST().AddConstructedType(ty.alias("make_type_reachable", sampler)); GeneratorImpl& gen = Build();