Move type_manager to type/ folder

This CL moves the type_manager from sem to type and updates the
namespace as needed.

Bug: tint:1718
Change-Id: I1fe0c2be08146221e68a9d2e7450283d102afdfa
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113280
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
dan sinclair 2022-12-08 12:03:53 +00:00 committed by Dawn LUCI CQ
parent 3e14a76425
commit c9949ac59e
11 changed files with 51 additions and 49 deletions

View File

@ -25,7 +25,6 @@
#include "src/tint/diagnostic/printer.h"
#include "src/tint/inspector/inspector.h"
#include "src/tint/reader/reader.h"
#include "src/tint/sem/type_manager.h"
#include "src/tint/transform/binding_remapper.h"
#include "src/tint/transform/first_index_offset.h"
#include "src/tint/transform/manager.h"
@ -35,6 +34,7 @@
#include "src/tint/transform/single_entry_point.h"
#include "src/tint/transform/substitute_override.h"
#include "src/tint/transform/vertex_pulling.h"
#include "src/tint/type/type_manager.h"
#include "src/tint/writer/flatten_bindings.h"
#include "src/tint/writer/writer.h"

View File

@ -460,7 +460,6 @@ libtint_source_set("libtint_core_all_src") {
"sem/texture.h",
"sem/type_conversion.h",
"sem/type_initializer.h",
"sem/type_manager.h",
"sem/type_mappings.h",
"sem/u32.h",
"sem/vector.h",
@ -579,6 +578,7 @@ libtint_source_set("libtint_core_all_src") {
"type/array_count.h",
"type/node.h",
"type/type.h",
"type/type_manager.h",
"utils/bitcast.h",
"utils/bitset.h",
"utils/block_allocator.h",
@ -722,8 +722,6 @@ libtint_source_set("libtint_sem_src") {
"sem/type_conversion.h",
"sem/type_initializer.cc",
"sem/type_initializer.h",
"sem/type_manager.cc",
"sem/type_manager.h",
"sem/type_mappings.h",
"sem/u32.cc",
"sem/u32.h",
@ -747,6 +745,8 @@ libtint_source_set("libtint_type_src") {
"type/node.h",
"type/type.cc",
"type/type.h",
"type/type_manager.cc",
"type/type_manager.h",
]
public_deps = [ ":libtint_core_all_src" ]
@ -1222,14 +1222,16 @@ if (tint_build_unittests) {
"sem/storage_texture_test.cc",
"sem/struct_test.cc",
"sem/texture_test.cc",
"sem/type_manager_test.cc",
"sem/u32_test.cc",
"sem/vector_test.cc",
]
}
tint_unittests_source_set("tint_unittests_type_src") {
sources = [ "type/type_test.cc" ]
sources = [
"type/type_manager_test.cc",
"type/type_test.cc",
]
}
tint_unittests_source_set("tint_unittests_text_src") {

View File

@ -379,8 +379,6 @@ list(APPEND TINT_LIB_SRCS
sem/type_initializer.h
sem/type_conversion.cc
sem/type_conversion.h
sem/type_manager.cc
sem/type_manager.h
sem/type_mappings.h
sem/u32.cc
sem/u32.h
@ -505,6 +503,8 @@ list(APPEND TINT_LIB_SRCS
type/node.h
type/type.cc
type/type.h
type/type_manager.cc
type/type_manager.h
utils/bitcast.h
utils/bitset.h
utils/block_allocator.h
@ -940,7 +940,6 @@ if(TINT_BUILD_TESTS)
sem/storage_texture_test.cc
sem/struct_test.cc
sem/texture_test.cc
sem/type_manager_test.cc
sem/u32_test.cc
sem/vector_test.cc
source_test.cc
@ -951,6 +950,7 @@ if(TINT_BUILD_TESTS)
traits_test.cc
transform/transform_test.cc
type/type_test.cc
type/type_manager_test.cc
utils/bitcast_test.cc
utils/bitset_test.cc
utils/block_allocator_test.cc

View File

@ -22,8 +22,8 @@
#include "src/tint/program_id.h"
#include "src/tint/sem/constant.h"
#include "src/tint/sem/info.h"
#include "src/tint/sem/type_manager.h"
#include "src/tint/symbol_table.h"
#include "src/tint/type/type_manager.h"
// Forward Declarations
namespace tint {
@ -73,7 +73,7 @@ class Program {
ast::NodeID HighestASTNodeID() const { return highest_node_id_; }
/// @returns a reference to the program's types
const sem::TypeManager& Types() const {
const type::TypeManager& Types() const {
AssertNotMoved();
return types_;
}
@ -180,7 +180,7 @@ class Program {
ProgramID id_;
ast::NodeID highest_node_id_;
sem::TypeManager types_;
type::TypeManager types_;
ASTNodeAllocator ast_nodes_;
SemNodeAllocator sem_nodes_;
ConstantAllocator constant_nodes_;

View File

@ -70,7 +70,7 @@ ProgramBuilder ProgramBuilder::Wrap(const Program* program) {
ProgramBuilder builder;
builder.id_ = program->ID();
builder.last_ast_node_id_ = program->HighestASTNodeID();
builder.types_ = sem::TypeManager::Wrap(program->Types());
builder.types_ = type::TypeManager::Wrap(program->Types());
builder.ast_ =
builder.create<ast::Module>(program->AST().source, program->AST().GlobalDeclarations());
builder.sem_ = sem::Info::Wrap(program->Sem());

View File

@ -299,13 +299,13 @@ class ProgramBuilder {
ProgramID ID() const { return id_; }
/// @returns a reference to the program's types
sem::TypeManager& Types() {
type::TypeManager& Types() {
AssertNotMoved();
return types_;
}
/// @returns a reference to the program's types
const sem::TypeManager& Types() const {
const type::TypeManager& Types() const {
AssertNotMoved();
return types_;
}
@ -3247,7 +3247,7 @@ class ProgramBuilder {
private:
ProgramID id_;
ast::NodeID last_ast_node_id_ = ast::NodeID{static_cast<decltype(ast::NodeID::value)>(0) - 1};
sem::TypeManager types_;
type::TypeManager types_;
ASTNodeAllocator ast_nodes_;
SemNodeAllocator sem_nodes_;
ConstantAllocator constant_nodes_;

View File

@ -48,7 +48,7 @@ std::string StorageTexture::FriendlyName(const SymbolTable&) const {
return out.str();
}
type::Type* StorageTexture::SubtypeFor(ast::TexelFormat format, sem::TypeManager& type_mgr) {
type::Type* StorageTexture::SubtypeFor(ast::TexelFormat format, type::TypeManager& type_mgr) {
switch (format) {
case ast::TexelFormat::kR32Uint:
case ast::TexelFormat::kRgba8Uint:

View File

@ -22,9 +22,9 @@
#include "src/tint/sem/texture.h"
// Forward declarations
namespace tint::sem {
namespace tint::type {
class TypeManager;
} // namespace tint::sem
} // namespace tint::type
namespace tint::sem {
@ -67,9 +67,9 @@ class StorageTexture final : public Castable<StorageTexture, Texture> {
std::string FriendlyName(const SymbolTable& symbols) const override;
/// @param format the storage texture image format
/// @param type_mgr the sem::TypeManager used to build the returned type
/// @param type_mgr the type::TypeManager used to build the returned type
/// @returns the storage texture subtype for the given TexelFormat
static type::Type* SubtypeFor(ast::TexelFormat format, sem::TypeManager& type_mgr);
static type::Type* SubtypeFor(ast::TexelFormat format, type::TypeManager& type_mgr);
private:
ast::TexelFormat const texel_format_;

View File

@ -1,4 +1,4 @@
// Copyright 2020 The Tint Authors.
// Copyright 2022 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.
@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/sem/type_manager.h"
#include "src/tint/type/type_manager.h"
namespace tint::sem {
namespace tint::type {
TypeManager::TypeManager() = default;
TypeManager::TypeManager(TypeManager&&) = default;
TypeManager& TypeManager::operator=(TypeManager&& rhs) = default;
TypeManager::~TypeManager() = default;
} // namespace tint::sem
} // namespace tint::type

View File

@ -1,4 +1,4 @@
// Copyright 2020 The Tint Authors.
// Copyright 2022 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.
@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_TINT_SEM_TYPE_MANAGER_H_
#define SRC_TINT_SEM_TYPE_MANAGER_H_
#ifndef SRC_TINT_TYPE_TYPE_MANAGER_H_
#define SRC_TINT_TYPE_TYPE_MANAGER_H_
#include <functional>
#include <string>
@ -26,7 +26,7 @@
#include "src/tint/type/type.h"
#include "src/tint/utils/unique_allocator.h"
namespace tint::sem {
namespace tint::type {
/// The type manager holds all the pointers to the known types.
class TypeManager final {
@ -107,7 +107,7 @@ class TypeManager final {
utils::UniqueAllocator<type::Node> nodes_;
};
} // namespace tint::sem
} // namespace tint::type
namespace std {
@ -149,4 +149,4 @@ struct equal_to<tint::type::Node> {
} // namespace std
#endif // SRC_TINT_SEM_TYPE_MANAGER_H_
#endif // SRC_TINT_TYPE_TYPE_MANAGER_H_

View File

@ -1,4 +1,4 @@
// Copyright 2020 The Tint Authors.
// Copyright 2022 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.
@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/sem/type_manager.h"
#include "src/tint/type/type_manager.h"
#include "gtest/gtest.h"
#include "src/tint/sem/i32.h"
#include "src/tint/sem/u32.h"
namespace tint::sem {
namespace tint::type {
namespace {
template <typename T>
@ -35,55 +35,55 @@ using TypeManagerTest = testing::Test;
TEST_F(TypeManagerTest, GetUnregistered) {
TypeManager tm;
auto* t = tm.Get<I32>();
auto* t = tm.Get<sem::I32>();
ASSERT_NE(t, nullptr);
EXPECT_TRUE(t->Is<I32>());
EXPECT_TRUE(t->Is<sem::I32>());
}
TEST_F(TypeManagerTest, GetSameTypeReturnsSamePtr) {
TypeManager tm;
auto* t = tm.Get<I32>();
auto* t = tm.Get<sem::I32>();
ASSERT_NE(t, nullptr);
EXPECT_TRUE(t->Is<I32>());
EXPECT_TRUE(t->Is<sem::I32>());
auto* t2 = tm.Get<I32>();
auto* t2 = tm.Get<sem::I32>();
EXPECT_EQ(t, t2);
}
TEST_F(TypeManagerTest, GetDifferentTypeReturnsDifferentPtr) {
TypeManager tm;
type::Type* t = tm.Get<I32>();
type::Type* t = tm.Get<sem::I32>();
ASSERT_NE(t, nullptr);
EXPECT_TRUE(t->Is<I32>());
EXPECT_TRUE(t->Is<sem::I32>());
type::Type* t2 = tm.Get<U32>();
type::Type* t2 = tm.Get<sem::U32>();
ASSERT_NE(t2, nullptr);
EXPECT_NE(t, t2);
EXPECT_TRUE(t2->Is<U32>());
EXPECT_TRUE(t2->Is<sem::U32>());
}
TEST_F(TypeManagerTest, Find) {
TypeManager tm;
auto* created = tm.Get<I32>();
auto* created = tm.Get<sem::I32>();
EXPECT_EQ(tm.Find<U32>(), nullptr);
EXPECT_EQ(tm.Find<I32>(), created);
EXPECT_EQ(tm.Find<sem::U32>(), nullptr);
EXPECT_EQ(tm.Find<sem::I32>(), created);
}
TEST_F(TypeManagerTest, WrapDoesntAffectInner) {
TypeManager inner;
TypeManager outer = TypeManager::Wrap(inner);
inner.Get<I32>();
inner.Get<sem::I32>();
EXPECT_EQ(count(inner), 1u);
EXPECT_EQ(count(outer), 0u);
outer.Get<U32>();
outer.Get<sem::U32>();
EXPECT_EQ(count(inner), 1u);
EXPECT_EQ(count(outer), 1u);
}
} // namespace
} // namespace tint::sem
} // namespace tint::type