tint/resolver: Propagate constant values between 'const's
Required for 'const' values that use other 'const' values in their expressions. Bug: tint:1580 Change-Id: I1d86281bec19340fdc0c60dc5b22eb3d6dc04cf5 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94606 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: David Neto <dneto@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
e3834c4760
commit
410a3bd19a
|
@ -210,6 +210,8 @@ class Resolver {
|
||||||
/// nodes are guaranteed to have been already resolved and any constant values calculated.
|
/// nodes are guaranteed to have been already resolved and any constant values calculated.
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
sem::Constant EvaluateConstantValue(const ast::Expression* expr, const sem::Type* type);
|
sem::Constant EvaluateConstantValue(const ast::Expression* expr, const sem::Type* type);
|
||||||
|
sem::Constant EvaluateConstantValue(const ast::IdentifierExpression* ident,
|
||||||
|
const sem::Type* type);
|
||||||
sem::Constant EvaluateConstantValue(const ast::LiteralExpression* literal,
|
sem::Constant EvaluateConstantValue(const ast::LiteralExpression* literal,
|
||||||
const sem::Type* type);
|
const sem::Type* type);
|
||||||
sem::Constant EvaluateConstantValue(const ast::CallExpression* call, const sem::Type* type);
|
sem::Constant EvaluateConstantValue(const ast::CallExpression* call, const sem::Type* type);
|
||||||
|
|
|
@ -154,11 +154,20 @@ utils::Result<sem::Constant::Elements> MaterializeElements(const sem::Constant::
|
||||||
sem::Constant Resolver::EvaluateConstantValue(const ast::Expression* expr, const sem::Type* type) {
|
sem::Constant Resolver::EvaluateConstantValue(const ast::Expression* expr, const sem::Type* type) {
|
||||||
return Switch(
|
return Switch(
|
||||||
expr, //
|
expr, //
|
||||||
|
[&](const ast::IdentifierExpression* e) { return EvaluateConstantValue(e, type); },
|
||||||
[&](const ast::LiteralExpression* e) { return EvaluateConstantValue(e, type); },
|
[&](const ast::LiteralExpression* e) { return EvaluateConstantValue(e, type); },
|
||||||
[&](const ast::CallExpression* e) { return EvaluateConstantValue(e, type); },
|
[&](const ast::CallExpression* e) { return EvaluateConstantValue(e, type); },
|
||||||
[&](const ast::IndexAccessorExpression* e) { return EvaluateConstantValue(e, type); });
|
[&](const ast::IndexAccessorExpression* e) { return EvaluateConstantValue(e, type); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sem::Constant Resolver::EvaluateConstantValue(const ast::IdentifierExpression* ident,
|
||||||
|
const sem::Type*) {
|
||||||
|
if (auto* sem = builder_->Sem().Get(ident)) {
|
||||||
|
return sem->ConstantValue();
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
sem::Constant Resolver::EvaluateConstantValue(const ast::LiteralExpression* literal,
|
sem::Constant Resolver::EvaluateConstantValue(const ast::LiteralExpression* literal,
|
||||||
const sem::Type* type) {
|
const sem::Type* type) {
|
||||||
return Switch(
|
return Switch(
|
||||||
|
|
|
@ -1052,8 +1052,7 @@ TEST_F(ResolverVariableTest, LocalConst_ImplicitType_Decls) {
|
||||||
EXPECT_EQ(Sem().Get(c_maf32)->ConstantValue().ElementCount(), 9u);
|
EXPECT_EQ(Sem().Get(c_maf32)->ConstantValue().ElementCount(), 9u);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable when constants propagate between 'const' variables
|
TEST_F(ResolverVariableTest, LocalConst_PropagateConstValue) {
|
||||||
TEST_F(ResolverVariableTest, DISABLED_LocalConst_PropagateConstValue) {
|
|
||||||
auto* a = Const("a", nullptr, Expr(42_i));
|
auto* a = Const("a", nullptr, Expr(42_i));
|
||||||
auto* b = Const("b", nullptr, Expr("a"));
|
auto* b = Const("b", nullptr, Expr("a"));
|
||||||
auto* c = Const("c", nullptr, Expr("b"));
|
auto* c = Const("c", nullptr, Expr("b"));
|
||||||
|
@ -1256,8 +1255,7 @@ TEST_F(ResolverVariableTest, GlobalConst_ImplicitType_Decls) {
|
||||||
EXPECT_EQ(Sem().Get(c_maf32)->ConstantValue().ElementCount(), 9u);
|
EXPECT_EQ(Sem().Get(c_maf32)->ConstantValue().ElementCount(), 9u);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable when constants propagate between 'const' variables
|
TEST_F(ResolverVariableTest, GlobalConst_PropagateConstValue) {
|
||||||
TEST_F(ResolverVariableTest, DISABLED_GlobalConst_PropagateConstValue) {
|
|
||||||
GlobalConst("b", nullptr, Expr("a"));
|
GlobalConst("b", nullptr, Expr("a"));
|
||||||
auto* c = GlobalConst("c", nullptr, Expr("b"));
|
auto* c = GlobalConst("c", nullptr, Expr("b"));
|
||||||
GlobalConst("a", nullptr, Expr(42_i));
|
GlobalConst("a", nullptr, Expr(42_i));
|
||||||
|
|
Loading…
Reference in New Issue