type::Manager: Simplify interface and use BlockAllocator

Internally use BlockAllocator to allocate the types.
When we optimize the allocation patterns of BlockAllocator, this will now benefit both AST nodes and types.

Remove Reset(). It was not used.

Remove type::Manager::Get(std::unique_ptr<type::Type>) - this was used (via Module::unique_type) in one place, which has easily been migrated to using the standard Module::create<>.

Replace all remaining uses of std::unique_ptr<> of types in tests with the standard create<> so we can guarantee uniqueness of the types.

Change-Id: Ib0e1fe94e492b31816450df5de0c839a0aefcb9e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38362
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2021-01-21 16:35:10 +00:00
committed by Commit Bot service account
parent 1e29f4beb0
commit 281b602f59
11 changed files with 138 additions and 172 deletions

View File

@@ -359,7 +359,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (!expect("struct declaration", Token::Type::kSemicolon))
return Failure::kErrored;
auto* type = module_.unique_type(std::move(str.value));
auto* type = str.value;
register_constructed(
module_.SymbolToName(type->As<type::Struct>()->symbol()), type);
module_.AddConstructedType(type);
@@ -1205,8 +1205,7 @@ Expect<ast::StorageClass> ParserImpl::expect_storage_class(
// struct_decl
// : struct_decoration_decl* STRUCT IDENT struct_body_decl
Maybe<std::unique_ptr<type::Struct>> ParserImpl::struct_decl(
ast::DecorationList& decos) {
Maybe<type::Struct*> ParserImpl::struct_decl(ast::DecorationList& decos) {
auto t = peek();
auto source = t.source();
@@ -1225,7 +1224,7 @@ Maybe<std::unique_ptr<type::Struct>> ParserImpl::struct_decl(
if (struct_decos.errored)
return Failure::kErrored;
return std::make_unique<type::Struct>(
return create<type::Struct>(
module_.RegisterSymbol(name.value),
create<ast::Struct>(source, std::move(body.value),
std::move(struct_decos.value)));

View File

@@ -397,7 +397,7 @@ class ParserImpl {
/// `struct_decoration_decl*` provided as `decos`.
/// @returns the struct type or nullptr on error
/// @param decos the list of decorations for the struct declaration.
Maybe<std::unique_ptr<type::Struct>> struct_decl(ast::DecorationList& decos);
Maybe<type::Struct*> struct_decl(ast::DecorationList& decos);
/// Parses a `struct_body_decl` grammar element, erroring on parse failure.
/// @returns the struct members
Expect<ast::StructMemberList> expect_struct_body_decl();