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>
diff --git a/src/tint/transform/array_length_from_uniform.cc b/src/tint/transform/array_length_from_uniform.cc
index dc19c5c..86c4534 100644
--- a/src/tint/transform/array_length_from_uniform.cc
+++ b/src/tint/transform/array_length_from_uniform.cc
@@ -52,7 +52,7 @@
             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;
diff --git a/src/tint/transform/calculate_array_length.cc b/src/tint/transform/calculate_array_length.cc
index 42a212c..bdda1cd 100644
--- a/src/tint/transform/calculate_array_length.cc
+++ b/src/tint/transform/calculate_array_length.cc
@@ -123,7 +123,7 @@
     // 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
diff --git a/src/tint/transform/combine_samplers.cc b/src/tint/transform/combine_samplers.cc
index 66b5b937..c9d4913 100644
--- a/src/tint/transform/combine_samplers.cc
+++ b/src/tint/transform/combine_samplers.cc
@@ -220,7 +220,7 @@
         // 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>()) {
diff --git a/src/tint/transform/decompose_memory_access.cc b/src/tint/transform/decompose_memory_access.cc
index 66c6073..775cc05 100644
--- a/src/tint/transform/decompose_memory_access.cc
+++ b/src/tint/transform/decompose_memory_access.cc
@@ -882,7 +882,7 @@
         }
 
         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)
diff --git a/src/tint/transform/decompose_strided_array.cc b/src/tint/transform/decompose_strided_array.cc
index bf36c06..ba6252b 100644
--- a/src/tint/transform/decompose_strided_array.cc
+++ b/src/tint/transform/decompose_strided_array.cc
@@ -115,7 +115,7 @@
     //   `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
diff --git a/src/tint/transform/multiplanar_external_texture.cc b/src/tint/transform/multiplanar_external_texture.cc
index 0bc507e..2a9e20e 100644
--- a/src/tint/transform/multiplanar_external_texture.cc
+++ b/src/tint/transform/multiplanar_external_texture.cc
@@ -184,7 +184,8 @@
         // 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 @@
                     }
                 }
 
-            } 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
diff --git a/src/tint/transform/promote_initializers_to_const_var.cc b/src/tint/transform/promote_initializers_to_const_var.cc
index 81b5603..6e0ba55 100644
--- a/src/tint/transform/promote_initializers_to_const_var.cc
+++ b/src/tint/transform/promote_initializers_to_const_var.cc
@@ -33,7 +33,7 @@
     // 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;
         }
diff --git a/src/tint/transform/remove_phonies.cc b/src/tint/transform/remove_phonies.cc
index dc5c092..7ca1194 100644
--- a/src/tint/transform/remove_phonies.cc
+++ b/src/tint/transform/remove_phonies.cc
@@ -86,12 +86,19 @@
             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;
diff --git a/src/tint/transform/renamer.cc b/src/tint/transform/renamer.cc
index 50cd781..562a52f 100644
--- a/src/tint/transform/renamer.cc
+++ b/src/tint/transform/renamer.cc
@@ -1278,7 +1278,7 @@
                 }
             }
         } 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;
diff --git a/src/tint/transform/robustness.cc b/src/tint/transform/robustness.cc
index 46624b6..aab1e0c 100644
--- a/src/tint/transform/robustness.cc
+++ b/src/tint/transform/robustness.cc
@@ -206,7 +206,7 @@
     /// @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())) {
diff --git a/src/tint/transform/vectorize_scalar_matrix_constructors.cc b/src/tint/transform/vectorize_scalar_matrix_constructors.cc
index c22506e..9cd9757 100644
--- a/src/tint/transform/vectorize_scalar_matrix_constructors.cc
+++ b/src/tint/transform/vectorize_scalar_matrix_constructors.cc
@@ -49,7 +49,7 @@
     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;
diff --git a/src/tint/transform/wrap_arrays_in_structs.cc b/src/tint/transform/wrap_arrays_in_structs.cc
index b1dc5e8..eb133d7 100644
--- a/src/tint/transform/wrap_arrays_in_structs.cc
+++ b/src/tint/transform/wrap_arrays_in_structs.cc
@@ -83,7 +83,7 @@
 
     // 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)) {