Resolver: Remove SetType() that takes ast::Type

This was calling Type() without actually checking that the resolve succeeded.
Have the caller resolve the AST type to the semantic type, so that there's a sensible place to handle errors.

Change-Id: I8fae91854377994f68a924fe8104a48a8afe150e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/53042
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2021-06-03 08:17:44 +00:00 committed by Tint LUCI CQ
parent 8324d227a1
commit 0e66b403a0
2 changed files with 16 additions and 15 deletions

View File

@ -1617,7 +1617,11 @@ bool Resolver::Bitcast(ast::BitcastExpression* expr) {
if (!Expression(expr->expr())) {
return false;
}
SetType(expr, expr->type());
auto* ty = Type(expr->type());
if (!ty) {
return false;
}
SetType(expr, ty, expr->type()->FriendlyName(builder_->Symbols()));
return true;
}
@ -1715,9 +1719,12 @@ bool Resolver::Constructor(ast::ConstructorExpression* expr) {
}
}
SetType(expr, type_ctor->type());
auto* type = Type(type_ctor->type());
if (!type) {
return false;
}
const sem::Type* type = TypeOf(expr);
SetType(expr, type, type_ctor->type()->FriendlyName(builder_->Symbols()));
// Now that the argument types have been determined, make sure that they
// obey the constructor type rules laid out in
@ -1731,7 +1738,11 @@ bool Resolver::Constructor(ast::ConstructorExpression* expr) {
// TODO(crbug.com/tint/634): Validate array constructor
} else if (auto* scalar_ctor = expr->As<ast::ScalarConstructorExpression>()) {
Mark(scalar_ctor->literal());
SetType(expr, TypeOf(scalar_ctor->literal()));
auto* type = TypeOf(scalar_ctor->literal());
if (!type) {
return false;
}
SetType(expr, type);
} else {
TINT_ICE(diagnostics_) << "unexpected constructor expression type";
}
@ -2436,10 +2447,6 @@ sem::Type* Resolver::TypeOf(const ast::Literal* lit) {
return nullptr;
}
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()));
}
@ -2634,7 +2641,7 @@ bool Resolver::DefaultAlignAndSize(const sem::Type* ty,
size = a->SizeInBytes();
return true;
}
TINT_UNREACHABLE(diagnostics_) << "Invalid type " << ty->TypeInfo().name;
TINT_UNREACHABLE(diagnostics_) << "invalid type " << ty->TypeInfo().name;
return false;
}

View File

@ -318,12 +318,6 @@ 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