tint: Remove ast::CallExpression -> sem::Call implicit mapping

With abstract materialization, any ast::Expression may map to the new
sem::Materialize node. Because of this, we can't assume that an
ast::CallExpression maps to a sem::Call, as it might be wrapped by a
sem::Materialize.

Remove the mapping, and fix up all the code that was relying on this.

Fixes are done by either:
• Calling `UnwrapMaterialize()->As<sem::Call>()` on the semantic
  expression. This is done when the logic may assume it's possible for
  the expression to be a Materialize node.
• Using the explicit sem::Info::Get<sem::Call>() template argument to
  cast the semantic type to sem::Call. This is done when the logic
  either knows it is impossible for the expression to be a Materialize.

The backends have been stubbed, as we'll want to emit the constant value
for these nodes. It's likely that we'll just use the FoldConstants
transform to strip all Materialize nodes from the tree. For now, be
defensive.

Bug: tint:1504
Change-Id: If9231b300fc30c7fe886c17a804ead8ee2988285
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/90533
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton 2022-05-19 21:50:59 +00:00 committed by Dawn LUCI CQ
parent 7b921fb4c7
commit e5a67ac891
28 changed files with 120 additions and 75 deletions

View File

@ -777,7 +777,7 @@ void Inspector::GenerateSamplerTargets() {
continue;
}
auto* call = sem.Get(c);
auto* call = sem.Get(c)->UnwrapMaterialize()->As<sem::Call>();
if (!call) {
continue;
}

View File

@ -69,7 +69,7 @@ TEST_F(SpvParserTest, WorkgroupBarrier) {
auto* call = helper->body->statements[0]->As<ast::CallStatement>();
ASSERT_NE(call, nullptr);
EXPECT_EQ(call->expr->args.size(), 0u);
auto* sem_call = program.Sem().Get(call->expr);
auto* sem_call = program.Sem().Get<sem::Call>(call->expr);
ASSERT_NE(sem_call, nullptr);
auto* builtin = sem_call->Target()->As<sem::Builtin>();
ASSERT_NE(builtin, nullptr);
@ -102,7 +102,7 @@ TEST_F(SpvParserTest, StorageBarrier) {
auto* call = helper->body->statements[0]->As<ast::CallStatement>();
ASSERT_NE(call, nullptr);
EXPECT_EQ(call->expr->args.size(), 0u);
auto* sem_call = program.Sem().Get(call->expr);
auto* sem_call = program.Sem().Get<sem::Call>(call->expr);
ASSERT_NE(sem_call, nullptr);
auto* builtin = sem_call->Target()->As<sem::Builtin>();
ASSERT_NE(builtin, nullptr);

View File

@ -1924,7 +1924,7 @@ TEST_P(ResolverBuiltinTest_Texture, Call) {
}
}
auto* call_sem = Sem().Get(call);
auto* call_sem = Sem().Get<sem::Call>(call);
ASSERT_NE(call_sem, nullptr);
auto* target = call_sem->Target();
ASSERT_NE(target, nullptr);

View File

@ -94,7 +94,7 @@ TEST_F(ResolverCallTest, Valid) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
auto* call = Sem().Get(call_expr);
auto* call = Sem().Get<sem::Call>(call_expr);
EXPECT_NE(call, nullptr);
EXPECT_EQ(call->Target(), Sem().Get(func));
}
@ -106,7 +106,7 @@ TEST_F(ResolverCallTest, OutOfOrder) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
auto* call = Sem().Get(call_expr);
auto* call = Sem().Get<sem::Call>(call_expr);
EXPECT_NE(call, nullptr);
EXPECT_EQ(call->Target(), Sem().Get(b));
}

View File

@ -318,7 +318,7 @@ TEST_P(ConversionConstructorValidTest, All) {
ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* call = Sem().Get(tc);
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
switch (params.kind) {
case Kind::Construct: {
@ -440,7 +440,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Array_ZeroValue_P
ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* call = Sem().Get(tc);
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
EXPECT_TRUE(call->Type()->Is<sem::Array>());
auto* ctor = call->Target()->As<sem::TypeConstructor>();
@ -456,7 +456,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Array_type_match)
ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* call = Sem().Get(tc);
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
EXPECT_TRUE(call->Type()->Is<sem::Array>());
auto* ctor = call->Target()->As<sem::TypeConstructor>();
@ -629,7 +629,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Construct_i32_Success) {
ASSERT_NE(TypeOf(expr), nullptr);
ASSERT_TRUE(TypeOf(expr)->Is<sem::I32>());
auto* call = Sem().Get(expr);
auto* call = Sem().Get<sem::Call>(expr);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConstructor>();
ASSERT_NE(ctor, nullptr);
@ -647,7 +647,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Construct_u32_Success) {
ASSERT_NE(TypeOf(expr), nullptr);
ASSERT_TRUE(TypeOf(expr)->Is<sem::U32>());
auto* call = Sem().Get(expr);
auto* call = Sem().Get<sem::Call>(expr);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConstructor>();
ASSERT_NE(ctor, nullptr);
@ -665,7 +665,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Construct_f32_Success) {
ASSERT_NE(TypeOf(expr), nullptr);
ASSERT_TRUE(TypeOf(expr)->Is<sem::F32>());
auto* call = Sem().Get(expr);
auto* call = Sem().Get<sem::Call>(expr);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConstructor>();
ASSERT_NE(ctor, nullptr);
@ -683,7 +683,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Convert_f32_to_i32_Success) {
ASSERT_NE(TypeOf(expr), nullptr);
ASSERT_TRUE(TypeOf(expr)->Is<sem::I32>());
auto* call = Sem().Get(expr);
auto* call = Sem().Get<sem::Call>(expr);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConversion>();
ASSERT_NE(ctor, nullptr);
@ -701,7 +701,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Convert_i32_to_u32_Success) {
ASSERT_NE(TypeOf(expr), nullptr);
ASSERT_TRUE(TypeOf(expr)->Is<sem::U32>());
auto* call = Sem().Get(expr);
auto* call = Sem().Get<sem::Call>(expr);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConversion>();
ASSERT_NE(ctor, nullptr);
@ -719,7 +719,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Convert_u32_to_f32_Success) {
ASSERT_NE(TypeOf(expr), nullptr);
ASSERT_TRUE(TypeOf(expr)->Is<sem::F32>());
auto* call = Sem().Get(expr);
auto* call = Sem().Get<sem::Call>(expr);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConversion>();
ASSERT_NE(ctor, nullptr);
@ -831,7 +831,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec2_Success_Zero
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 2u);
auto* call = Sem().Get(tc);
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConstructor>();
ASSERT_NE(ctor, nullptr);
@ -850,7 +850,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec2F32_Success_S
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 2u);
auto* call = Sem().Get(tc);
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConstructor>();
ASSERT_NE(ctor, nullptr);
@ -871,7 +871,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec2U32_Success_S
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::U32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 2u);
auto* call = Sem().Get(tc);
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConstructor>();
ASSERT_NE(ctor, nullptr);
@ -892,7 +892,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec2I32_Success_S
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::I32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 2u);
auto* call = Sem().Get(tc);
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConstructor>();
ASSERT_NE(ctor, nullptr);
@ -913,7 +913,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec2Bool_Success_
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::Bool>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 2u);
auto* call = Sem().Get(tc);
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConstructor>();
ASSERT_NE(ctor, nullptr);
@ -934,7 +934,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec2_Success_Iden
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 2u);
auto* call = Sem().Get(tc);
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConstructor>();
ASSERT_NE(ctor, nullptr);
@ -954,7 +954,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec2_Success_Vec2
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 2u);
auto* call = Sem().Get(tc);
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConversion>();
ASSERT_NE(ctor, nullptr);
@ -1079,7 +1079,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec3_Success_Zero
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 3u);
auto* call = Sem().Get(tc);
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConstructor>();
ASSERT_NE(ctor, nullptr);
@ -1098,7 +1098,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec3F32_Success_S
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 3u);
auto* call = Sem().Get(tc);
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConstructor>();
ASSERT_NE(ctor, nullptr);
@ -1120,7 +1120,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec3U32_Success_S
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::U32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 3u);
auto* call = Sem().Get(tc);
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConstructor>();
ASSERT_NE(ctor, nullptr);
@ -1142,7 +1142,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec3I32_Success_S
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::I32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 3u);
auto* call = Sem().Get(tc);
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConstructor>();
ASSERT_NE(ctor, nullptr);
@ -1164,7 +1164,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec3Bool_Success_
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::Bool>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 3u);
auto* call = Sem().Get(tc);
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConstructor>();
ASSERT_NE(ctor, nullptr);
@ -1186,7 +1186,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec3_Success_Vec2
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 3u);
auto* call = Sem().Get(tc);
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConstructor>();
ASSERT_NE(ctor, nullptr);
@ -1207,7 +1207,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec3_Success_Scal
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 3u);
auto* call = Sem().Get(tc);
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConstructor>();
ASSERT_NE(ctor, nullptr);
@ -1228,7 +1228,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec3_Success_Iden
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 3u);
auto* call = Sem().Get(tc);
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConstructor>();
ASSERT_NE(ctor, nullptr);
@ -1248,7 +1248,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec3_Success_Vec3
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->Width(), 3u);
auto* call = Sem().Get(tc);
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
auto* ctor = call->Target()->As<sem::TypeConversion>();
ASSERT_NE(ctor, nullptr);

View File

@ -1162,7 +1162,7 @@ class UniformityGraph {
// Get tags for the callee.
CallSiteTag callsite_tag = CallSiteNoRestriction;
FunctionTag function_tag = NoRestriction;
auto* sem = sem_.Get(call);
auto* sem = SemCall(call);
const FunctionInfo* func_info = nullptr;
Switch(
sem->Target(),
@ -1313,7 +1313,7 @@ class UniformityGraph {
/// Recursively descend through the function called by `call` and the functions that it calls in
/// order to find a call to a builtin function that requires uniformity.
const ast::CallExpression* FindBuiltinThatRequiresUniformity(const ast::CallExpression* call) {
auto* target = sem_.Get(call)->Target();
auto* target = SemCall(call)->Target();
if (target->Is<sem::Builtin>()) {
// This is a call to a builtin, so we must be done.
return call;
@ -1362,7 +1362,7 @@ class UniformityGraph {
call->args[idx]->source);
// Recurse into the target function.
if (auto* user = sem_.Get(call)->Target()->As<sem::Function>()) {
if (auto* user = SemCall(call)->Target()->As<sem::Function>()) {
auto& callee = functions_.at(user->Declaration());
ShowCauseOfNonUniformity(callee, callee.cf_return,
callee.parameters[idx].init_value);
@ -1427,7 +1427,7 @@ class UniformityGraph {
c->source);
// Recurse into the target function.
if (auto* user = sem_.Get(c)->Target()->As<sem::Function>()) {
if (auto* user = SemCall(c)->Target()->As<sem::Function>()) {
auto& callee = functions_.at(user->Declaration());
ShowCauseOfNonUniformity(callee, callee.cf_return,
callee.may_be_non_uniform);
@ -1489,7 +1489,7 @@ class UniformityGraph {
// The node will always have a corresponding call expression.
auto* call = cause->ast->As<ast::CallExpression>();
TINT_ASSERT(Resolver, call);
auto* target = sem_.Get(call)->Target();
auto* target = SemCall(call)->Target();
std::string func_name;
if (auto* builtin = target->As<sem::Builtin>()) {
@ -1521,14 +1521,17 @@ class UniformityGraph {
// causes the uniformity requirement.
auto* innermost_call = FindBuiltinThatRequiresUniformity(call);
if (innermost_call != call) {
auto* sem_call = SemCall(call);
auto* sem_innermost_call = SemCall(innermost_call);
// Determine whether the builtin is being called directly or indirectly.
bool indirect = false;
if (sem_.Get(call)->Target()->As<sem::Function>() !=
sem_.Get(innermost_call)->Stmt()->Function()) {
if (sem_call->Target()->As<sem::Function>() !=
sem_innermost_call->Stmt()->Function()) {
indirect = true;
}
auto* builtin = sem_.Get(innermost_call)->Target()->As<sem::Builtin>();
auto* builtin = sem_innermost_call->Target()->As<sem::Builtin>();
diagnostics_.add_note(diag::System::Resolver,
"'" + func_name + "' requires uniformity because it " +
(indirect ? "indirectly " : "") + "calls " +
@ -1543,6 +1546,11 @@ class UniformityGraph {
function.may_be_non_uniform);
}
}
// Helper for obtaining the sem::Call node for the ast::CallExpression
const sem::Call* SemCall(const ast::CallExpression* expr) const {
return sem_.Get(expr)->UnwrapMaterialize()->As<sem::Call>();
}
};
} // namespace

View File

@ -59,7 +59,6 @@ namespace tint::sem {
struct TypeMappings {
//! @cond Doxygen_Suppress
Array* operator()(ast::Array*);
Call* operator()(ast::CallExpression*);
Expression* operator()(ast::Expression*);
ForLoopStatement* operator()(ast::ForLoopStatement*);
Function* operator()(ast::Function*);

View File

@ -52,7 +52,7 @@ static void IterateArrayLengthOnStorageVar(CloneContext& ctx, F&& functor) {
continue;
}
auto* call = sem.Get(call_expr);
auto* call = sem.Get(call_expr)->UnwrapMaterialize()->As<sem::Call>();
auto* builtin = call->Target()->As<sem::Builtin>();
if (!builtin || builtin->Type() != sem::BuiltinType::kArrayLength) {
continue;

View File

@ -123,7 +123,7 @@ void CalculateArrayLength::Run(CloneContext& ctx, const DataMap&, DataMap&) cons
// Find all the arrayLength() calls...
for (auto* node : ctx.src->ASTNodes().Objects()) {
if (auto* call_expr = node->As<ast::CallExpression>()) {
auto* call = sem.Get(call_expr);
auto* call = sem.Get(call_expr)->UnwrapMaterialize()->As<sem::Call>();
if (auto* builtin = call->Target()->As<sem::Builtin>()) {
if (builtin->Type() == sem::BuiltinType::kArrayLength) {
// We're dealing with an arrayLength() call

View File

@ -220,7 +220,7 @@ struct CombineSamplers::State {
// sampler parameters to use the current function's combined samplers or
// the combined global samplers, as appropriate.
ctx.ReplaceAll([&](const ast::CallExpression* expr) -> const ast::Expression* {
if (auto* call = sem.Get(expr)) {
if (auto* call = sem.Get(expr)->UnwrapMaterialize()->As<sem::Call>()) {
ast::ExpressionList args;
// Replace all texture builtin calls.
if (auto* builtin = call->Target()->As<sem::Builtin>()) {

View File

@ -882,7 +882,7 @@ void DecomposeMemoryAccess::Run(CloneContext& ctx, const DataMap&, DataMap&) con
}
if (auto* call_expr = node->As<ast::CallExpression>()) {
auto* call = sem.Get(call_expr);
auto* call = sem.Get(call_expr)->UnwrapMaterialize()->As<sem::Call>();
if (auto* builtin = call->Target()->As<sem::Builtin>()) {
if (builtin->Type() == sem::BuiltinType::kArrayLength) {
// arrayLength(X)

View File

@ -115,7 +115,7 @@ void DecomposeStridedArray::Run(CloneContext& ctx, const DataMap&, DataMap&) con
// `array<strided_arr, 3>(strided_arr(1), strided_arr(2), strided_arr(3))`
ctx.ReplaceAll([&](const ast::CallExpression* expr) -> const ast::Expression* {
if (!expr->args.empty()) {
if (auto* call = sem.Get(expr)) {
if (auto* call = sem.Get(expr)->UnwrapMaterialize()->As<sem::Call>()) {
if (auto* ctor = call->Target()->As<sem::TypeConstructor>()) {
if (auto* arr = ctor->ReturnType()->As<sem::Array>()) {
// Begin by cloning the array constructor type or name

View File

@ -184,7 +184,8 @@ struct MultiplanarExternalTexture::State {
// Transform the original textureLoad and textureSampleLevel calls into
// textureLoadExternal and textureSampleExternal calls.
ctx.ReplaceAll([&](const ast::CallExpression* expr) -> const ast::CallExpression* {
auto* builtin = sem.Get(expr)->Target()->As<sem::Builtin>();
auto* call = sem.Get(expr)->UnwrapMaterialize()->As<sem::Call>();
auto* builtin = call->Target()->As<sem::Builtin>();
if (builtin && !builtin->Parameters().empty() &&
builtin->Parameters()[0]->Type()->Is<sem::ExternalTexture>() &&
@ -209,7 +210,7 @@ struct MultiplanarExternalTexture::State {
}
}
} else if (sem.Get(expr)->Target()->Is<sem::Function>()) {
} else if (call->Target()->Is<sem::Function>()) {
// The call expression may be to a user-defined function that
// contains a texture_external parameter. These need to be expanded
// out to multiple plane textures and the texture parameters

View File

@ -33,7 +33,7 @@ void PromoteInitializersToConstVar::Run(CloneContext& ctx, const DataMap&, DataM
// Hoists array and structure initializers to a constant variable, declared
// just before the statement of usage.
auto type_ctor_to_let = [&](const ast::CallExpression* expr) {
auto* ctor = ctx.src->Sem().Get(expr);
auto* ctor = ctx.src->Sem().Get(expr)->UnwrapMaterialize()->As<sem::Call>();
if (!ctor->Target()->Is<sem::TypeConstructor>()) {
return true;
}

View File

@ -86,12 +86,19 @@ void RemovePhonies::Run(CloneContext& ctx, const DataMap&, DataMap&) const {
if (stmt->lhs->Is<ast::PhonyExpression>()) {
std::vector<const ast::Expression*> side_effects;
if (!ast::TraverseExpressions(
stmt->rhs, ctx.dst->Diagnostics(), [&](const ast::CallExpression* call) {
stmt->rhs, ctx.dst->Diagnostics(), [&](const ast::CallExpression* expr) {
// ast::CallExpression may map to a function or builtin call
// (both may have side-effects), or a type constructor or
// type conversion (both do not have side effects).
if (sem.Get(call)->Target()->IsAnyOf<sem::Function, sem::Builtin>()) {
side_effects.push_back(call);
auto* call = sem.Get<sem::Call>(expr);
if (!call) {
// Semantic node must be a Materialize, in which case the expression
// was creation-time (compile time), so could not have side effects.
// Just skip.
return ast::TraverseAction::Skip;
}
if (call->Target()->IsAnyOf<sem::Function, sem::Builtin>()) {
side_effects.push_back(expr);
return ast::TraverseAction::Skip;
}
return ast::TraverseAction::Descend;

View File

@ -1278,7 +1278,7 @@ Output Renamer::Run(const Program* in, const DataMap& inputs) const {
}
}
} else if (auto* call = node->As<ast::CallExpression>()) {
auto* sem = in->Sem().Get(call);
auto* sem = in->Sem().Get(call)->UnwrapMaterialize()->As<sem::Call>();
if (!sem) {
TINT_ICE(Transform, out.Diagnostics()) << "CallExpression has no semantic info";
continue;

View File

@ -206,7 +206,7 @@ struct Robustness::State {
/// @return the clamped replacement call expression, or nullptr if `expr`
/// should be cloned without changes.
const ast::CallExpression* Transform(const ast::CallExpression* expr) {
auto* call = ctx.src->Sem().Get(expr);
auto* call = ctx.src->Sem().Get(expr)->UnwrapMaterialize()->As<sem::Call>();
auto* call_target = call->Target();
auto* builtin = call_target->As<sem::Builtin>();
if (!builtin || !TextureBuiltinNeedsClamping(builtin->Type())) {

View File

@ -49,7 +49,7 @@ void VectorizeScalarMatrixConstructors::Run(CloneContext& ctx, const DataMap&, D
std::unordered_map<const sem::Matrix*, Symbol> scalar_ctors;
ctx.ReplaceAll([&](const ast::CallExpression* expr) -> const ast::CallExpression* {
auto* call = ctx.src->Sem().Get(expr);
auto* call = ctx.src->Sem().Get(expr)->UnwrapMaterialize()->As<sem::Call>();
auto* ty_ctor = call->Target()->As<sem::TypeConstructor>();
if (!ty_ctor) {
return nullptr;

View File

@ -83,7 +83,7 @@ void WrapArraysInStructs::Run(CloneContext& ctx, const DataMap&, DataMap&) const
// Fix up array constructors so `A(1,2)` becomes `tint_array_wrapper(A(1,2))`
ctx.ReplaceAll([&](const ast::CallExpression* expr) -> const ast::Expression* {
if (auto* call = sem.Get(expr)) {
if (auto* call = sem.Get(expr)->UnwrapMaterialize()->As<sem::Call>()) {
if (auto* ctor = call->Target()->As<sem::TypeConstructor>()) {
if (auto* array = ctor->ReturnType()->As<sem::Array>()) {
if (auto w = wrapper(array)) {

View File

@ -46,7 +46,7 @@ TEST_F(AppendVectorTest, Vec2i32_i32) {
EXPECT_EQ(vec_123->args[1], scalar_2);
EXPECT_EQ(vec_123->args[2], scalar_3);
auto* call = Sem().Get(vec_123);
auto* call = Sem().Get<sem::Call>(vec_123);
ASSERT_NE(call, nullptr);
ASSERT_EQ(call->Arguments().size(), 3u);
EXPECT_EQ(call->Arguments()[0], Sem().Get(scalar_1));
@ -90,7 +90,7 @@ TEST_F(AppendVectorTest, Vec2i32_u32) {
ASSERT_EQ(u32_to_i32->args.size(), 1u);
EXPECT_EQ(u32_to_i32->args[0], scalar_3);
auto* call = Sem().Get(vec_123);
auto* call = Sem().Get<sem::Call>(vec_123);
ASSERT_NE(call, nullptr);
ASSERT_EQ(call->Arguments().size(), 3u);
EXPECT_EQ(call->Arguments()[0], Sem().Get(scalar_1));
@ -142,7 +142,7 @@ TEST_F(AppendVectorTest, Vec2i32FromVec2u32_u32) {
ASSERT_EQ(u32_to_i32->args.size(), 1u);
EXPECT_EQ(u32_to_i32->args[0], scalar_3);
auto* call = Sem().Get(vec_123);
auto* call = Sem().Get<sem::Call>(vec_123);
ASSERT_NE(call, nullptr);
ASSERT_EQ(call->Arguments().size(), 2u);
EXPECT_EQ(call->Arguments()[0], Sem().Get(vec_12));
@ -184,7 +184,7 @@ TEST_F(AppendVectorTest, Vec2i32_f32) {
ASSERT_EQ(f32_to_i32->args.size(), 1u);
EXPECT_EQ(f32_to_i32->args[0], scalar_3);
auto* call = Sem().Get(vec_123);
auto* call = Sem().Get<sem::Call>(vec_123);
ASSERT_NE(call, nullptr);
ASSERT_EQ(call->Arguments().size(), 3u);
EXPECT_EQ(call->Arguments()[0], Sem().Get(scalar_1));
@ -226,7 +226,7 @@ TEST_F(AppendVectorTest, Vec3i32_i32) {
EXPECT_EQ(vec_1234->args[2], scalar_3);
EXPECT_EQ(vec_1234->args[3], scalar_4);
auto* call = Sem().Get(vec_1234);
auto* call = Sem().Get<sem::Call>(vec_1234);
ASSERT_NE(call, nullptr);
ASSERT_EQ(call->Arguments().size(), 4u);
EXPECT_EQ(call->Arguments()[0], Sem().Get(scalar_1));
@ -266,7 +266,7 @@ TEST_F(AppendVectorTest, Vec2i32Var_i32) {
EXPECT_EQ(vec_123->args[0], vec_12);
EXPECT_EQ(vec_123->args[1], scalar_3);
auto* call = Sem().Get(vec_123);
auto* call = Sem().Get<sem::Call>(vec_123);
ASSERT_NE(call, nullptr);
ASSERT_EQ(call->Arguments().size(), 2u);
EXPECT_EQ(call->Arguments()[0], Sem().Get(vec_12));
@ -305,7 +305,7 @@ TEST_F(AppendVectorTest, Vec2i32_i32Var) {
EXPECT_EQ(vec_123->args[1], scalar_2);
EXPECT_EQ(vec_123->args[2], scalar_3);
auto* call = Sem().Get(vec_123);
auto* call = Sem().Get<sem::Call>(vec_123);
ASSERT_NE(call, nullptr);
ASSERT_EQ(call->Arguments().size(), 3u);
EXPECT_EQ(call->Arguments()[0], Sem().Get(scalar_1));
@ -344,7 +344,7 @@ TEST_F(AppendVectorTest, Vec2i32Var_i32Var) {
EXPECT_EQ(vec_123->args[0], vec_12);
EXPECT_EQ(vec_123->args[1], scalar_3);
auto* call = Sem().Get(vec_123);
auto* call = Sem().Get<sem::Call>(vec_123);
ASSERT_NE(call, nullptr);
ASSERT_EQ(call->Arguments().size(), 2u);
EXPECT_EQ(call->Arguments()[0], Sem().Get(vec_12));
@ -385,7 +385,7 @@ TEST_F(AppendVectorTest, Vec2i32Var_f32Var) {
ASSERT_EQ(f32_to_i32->args.size(), 1u);
EXPECT_EQ(f32_to_i32->args[0], scalar_3);
auto* call = Sem().Get(vec_123);
auto* call = Sem().Get<sem::Call>(vec_123);
ASSERT_NE(call, nullptr);
ASSERT_EQ(call->Arguments().size(), 2u);
EXPECT_EQ(call->Arguments()[0], Sem().Get(vec_12));
@ -422,7 +422,7 @@ TEST_F(AppendVectorTest, Vec2boolVar_boolVar) {
EXPECT_EQ(vec_123->args[0], vec_12);
EXPECT_EQ(vec_123->args[1], scalar_3);
auto* call = Sem().Get(vec_123);
auto* call = Sem().Get<sem::Call>(vec_123);
ASSERT_NE(call, nullptr);
ASSERT_EQ(call->Arguments().size(), 2u);
EXPECT_EQ(call->Arguments()[0], Sem().Get(vec_12));
@ -461,7 +461,7 @@ TEST_F(AppendVectorTest, ZeroVec3i32_i32) {
}
EXPECT_EQ(vec_0004->args[3], scalar);
auto* call = Sem().Get(vec_0004);
auto* call = Sem().Get<sem::Call>(vec_0004);
ASSERT_NE(call, nullptr);
ASSERT_EQ(call->Arguments().size(), 4u);
EXPECT_EQ(call->Arguments()[0], Sem().Get(vec_0004->args[0]));

View File

@ -35,6 +35,7 @@
#include "src/tint/sem/depth_multisampled_texture.h"
#include "src/tint/sem/depth_texture.h"
#include "src/tint/sem/function.h"
#include "src/tint/sem/materialize.h"
#include "src/tint/sem/member_accessor_expression.h"
#include "src/tint/sem/module.h"
#include "src/tint/sem/multisampled_texture.h"
@ -690,7 +691,12 @@ bool GeneratorImpl::EmitBreak(const ast::BreakStatement*) {
}
bool GeneratorImpl::EmitCall(std::ostream& out, const ast::CallExpression* expr) {
auto* call = builder_.Sem().Get(expr);
auto* sem = builder_.Sem().Get(expr);
if (auto* m = sem->As<sem::Materialize>()) {
// TODO(crbug.com/tint/1504): Just emit the constant value.
sem = m->Expr();
}
auto* call = sem->As<sem::Call>();
auto* target = call->Target();
if (target->Is<sem::Function>()) {

View File

@ -169,7 +169,7 @@ TEST_P(GlslBuiltinTest, Emit) {
GeneratorImpl& gen = Build();
auto* sem = program->Sem().Get(call);
auto* sem = program->Sem().Get<sem::Call>(call);
ASSERT_NE(sem, nullptr);
auto* target = sem->Target();
ASSERT_NE(target, nullptr);

View File

@ -36,6 +36,7 @@
#include "src/tint/sem/depth_multisampled_texture.h"
#include "src/tint/sem/depth_texture.h"
#include "src/tint/sem/function.h"
#include "src/tint/sem/materialize.h"
#include "src/tint/sem/member_accessor_expression.h"
#include "src/tint/sem/module.h"
#include "src/tint/sem/multisampled_texture.h"
@ -924,7 +925,12 @@ bool GeneratorImpl::EmitBreak(const ast::BreakStatement*) {
}
bool GeneratorImpl::EmitCall(std::ostream& out, const ast::CallExpression* expr) {
auto* call = builder_.Sem().Get(expr);
auto* sem = builder_.Sem().Get(expr);
if (auto* m = sem->As<sem::Materialize>()) {
// TODO(crbug.com/tint/1504): Just emit the constant value.
sem = m->Expr();
}
auto* call = sem->As<sem::Call>();
auto* target = call->Target();
return Switch(
target, [&](const sem::Function* func) { return EmitFunctionCall(out, call, func); },

View File

@ -168,7 +168,7 @@ TEST_P(HlslBuiltinTest, Emit) {
GeneratorImpl& gen = Build();
auto* sem = program->Sem().Get(call);
auto* sem = program->Sem().Get<sem::Call>(call);
ASSERT_NE(sem, nullptr);
auto* target = sem->Target();
ASSERT_NE(target, nullptr);

View File

@ -41,6 +41,7 @@
#include "src/tint/sem/f32.h"
#include "src/tint/sem/function.h"
#include "src/tint/sem/i32.h"
#include "src/tint/sem/materialize.h"
#include "src/tint/sem/matrix.h"
#include "src/tint/sem/member_accessor_expression.h"
#include "src/tint/sem/module.h"
@ -550,7 +551,12 @@ bool GeneratorImpl::EmitBreak(const ast::BreakStatement*) {
}
bool GeneratorImpl::EmitCall(std::ostream& out, const ast::CallExpression* expr) {
auto* call = program_->Sem().Get(expr);
auto* sem = program_->Sem().Get(expr);
if (auto* m = sem->As<sem::Materialize>()) {
// TODO(crbug.com/tint/1504): Just emit the constant value.
sem = m->Expr();
}
auto* call = sem->As<sem::Call>();
auto* target = call->Target();
return Switch(
target, [&](const sem::Function* func) { return EmitFunctionCall(out, call, func); },

View File

@ -189,7 +189,7 @@ TEST_P(MslBuiltinTest, Emit) {
GeneratorImpl& gen = Build();
auto* sem = program->Sem().Get(call);
auto* sem = program->Sem().Get<sem::Call>(call);
ASSERT_NE(sem, nullptr);
auto* target = sem->Target();
ASSERT_NE(target, nullptr);

View File

@ -40,7 +40,7 @@ TEST_P(MslImportData_SingleParamTest, FloatScalar) {
GeneratorImpl& gen = Build();
auto* sem = program->Sem().Get(call);
auto* sem = program->Sem().Get<sem::Call>(call);
ASSERT_NE(sem, nullptr);
auto* target = sem->Target();
ASSERT_NE(target, nullptr);

View File

@ -30,6 +30,7 @@
#include "src/tint/sem/depth_multisampled_texture.h"
#include "src/tint/sem/depth_texture.h"
#include "src/tint/sem/function.h"
#include "src/tint/sem/materialize.h"
#include "src/tint/sem/member_accessor_expression.h"
#include "src/tint/sem/module.h"
#include "src/tint/sem/multisampled_texture.h"
@ -1273,7 +1274,13 @@ bool Builder::IsConstructorConst(const ast::Expression* expr) {
return ast::TraverseAction::Descend;
}
if (auto* ce = e->As<ast::CallExpression>()) {
auto* call = builder_.Sem().Get(ce);
auto* sem = builder_.Sem().Get(ce);
if (sem->Is<sem::Materialize>()) {
// Materialize can only occur on compile time expressions, so this sub-tree must be
// constant.
return ast::TraverseAction::Skip;
}
auto* call = sem->As<sem::Call>();
if (call->Target()->Is<sem::TypeConstructor>()) {
return ast::TraverseAction::Descend;
}
@ -2154,7 +2161,12 @@ bool Builder::GenerateBlockStatementWithoutScoping(const ast::BlockStatement* st
}
uint32_t Builder::GenerateCallExpression(const ast::CallExpression* expr) {
auto* call = builder_.Sem().Get(expr);
auto* sem = builder_.Sem().Get(expr);
if (auto* m = sem->As<sem::Materialize>()) {
// TODO(crbug.com/tint/1504): Just emit the constant value.
sem = m->Expr();
}
auto* call = sem->As<sem::Call>();
auto* target = call->Target();
return Switch(
target, [&](const sem::Function* func) { return GenerateFunctionCall(call, func); },