Resolver: compute canonical types and store them as semantic::Variable::Type

We define the canonical type as a type stripped of all aliases. For
example, Canonical(alias<alias<vec3<alias<f32>>>>) is vec3<f32>. This
change adds Resolver::Canonical(Type*) which caches and returns the
resulting canonical type. We use this throughout the Resolver instead of
UnwrapAliasIfNeeded(), and we store the result in semantic::Variable,
returned from it's Type() member function.

Also:

* Wrote unit tests for Resolver::Canonical()

* Added semantic::Variable::DeclaredType() as a convenience to
retrieve the AST variable's type.

* Updated post-resolve code (transforms) to make use of Type and
DeclaredType appropriately, removing unnecessary calls to
UnwrapAliasIfNeeded.

* Added IntrinsicTableTest.MatchWithNestedAliasUnwrapping to ensure we
don't need to pass canonical parameter types for instrinsic table
lookups.

* ProgramBuilder: added vecN and matMxN overloads that take a Type* arg
to create them with alias types.

Bug: tint:705
Change-Id: I58a3b62538356b8dad2b1161a19b38bcefdd5d62
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47360
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Antonio Maiorano
2021-04-13 13:32:33 +00:00
committed by Commit Bot service account
parent 2f25ecf8ba
commit 2543686412
14 changed files with 269 additions and 76 deletions

View File

@@ -15,6 +15,7 @@
#include "src/semantic/variable.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/variable.h"
TINT_INSTANTIATE_TYPEINFO(tint::semantic::Variable);
TINT_INSTANTIATE_TYPEINFO(tint::semantic::VariableUser);
@@ -29,6 +30,10 @@ Variable::Variable(const ast::Variable* declaration,
Variable::~Variable() = default;
type::Type* Variable::DeclaredType() const {
return declaration_->declared_type();
}
VariableUser::VariableUser(ast::IdentifierExpression* declaration,
type::Type* type,
Statement* statement,

View File

@@ -52,9 +52,12 @@ class Variable : public Castable<Variable, Node> {
/// @returns the AST declaration node
const ast::Variable* Declaration() const { return declaration_; }
/// @returns the type for the variable
/// @returns the canonical type for the variable
type::Type* Type() const { return type_; }
/// @returns the AST node's type. May be nullptr.
type::Type* DeclaredType() const;
/// @returns the storage class for the variable
ast::StorageClass StorageClass() const { return storage_class_; }