[tint][core] Remove UnwrapRef() calls from intrinsic::Table.

The implicit loading doesn't belong here.
Move these unwraps to the WGSL resolver.

Change-Id: I113431cfe7a1f356648076c61e7f5f9f1dd836c7
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/168222
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Ben Clayton <bclayton@google.com>
diff --git a/src/tint/lang/core/intrinsic/table.cc b/src/tint/lang/core/intrinsic/table.cc
index 3677866..aa38b22 100644
--- a/src/tint/lang/core/intrinsic/table.cc
+++ b/src/tint/lang/core/intrinsic/table.cc
@@ -198,7 +198,7 @@
                 ss << ", ";
             }
             first = false;
-            ss << arg->UnwrapRef()->FriendlyName();
+            ss << arg->FriendlyName();
         }
     }
     ss << ")";
@@ -321,7 +321,7 @@
         auto* type_indices = context.data[parameter.type_matcher_indices];
         auto* number_indices = context.data[parameter.number_matcher_indices];
         if (!Match(context, templates, overload, type_indices, number_indices, earliest_eval_stage)
-                 .Type(args[p]->UnwrapRef())) {
+                 .Type(args[p])) {
             score += kMismatchedParamTypePenalty;
         }
     }
@@ -380,7 +380,7 @@
             auto* number_indices = context.data[parameter.number_matcher_indices];
             auto* ty = Match(context, templates, overload, type_indices, number_indices,
                              earliest_eval_stage)
-                           .Type(args[p]->UnwrapRef());
+                           .Type(args[p]);
             parameters.Emplace(ty, parameter.usage);
         }
     }
diff --git a/src/tint/lang/core/intrinsic/table_test.cc b/src/tint/lang/core/intrinsic/table_test.cc
index 6138555..d76c548 100644
--- a/src/tint/lang/core/intrinsic/table_test.cc
+++ b/src/tint/lang/core/intrinsic/table_test.cc
@@ -440,21 +440,6 @@
     ASSERT_THAT(Diagnostics().str(), HasSubstr("no matching call"));
 }
 
-TEST_F(IntrinsicTableTest, ImplicitLoadOnReference) {
-    auto* f32 = create<core::type::F32>();
-    auto result = table.Lookup(core::BuiltinFn::kCos,
-                               Vector{
-                                   create<core::type::Reference>(core::AddressSpace::kFunction, f32,
-                                                                 core::Access::kReadWrite),
-                               },
-                               EvaluationStage::kConstant, Source{});
-    ASSERT_EQ(result, Success) << Diagnostics();
-    ASSERT_EQ(Diagnostics().str(), "");
-    EXPECT_EQ(result->return_type, f32);
-    ASSERT_EQ(result->parameters.Length(), 1u);
-    EXPECT_EQ(result->parameters[0].type, f32);
-}
-
 TEST_F(IntrinsicTableTest, MatchTemplateType) {
     auto* f32 = create<core::type::F32>();
     auto result = table.Lookup(core::BuiltinFn::kClamp, Vector{f32, f32, f32},
@@ -540,9 +525,7 @@
 
 TEST_F(IntrinsicTableTest, MatchDifferentArgsElementType_Builtin_RuntimeEval) {
     auto* af = create<core::type::AbstractFloat>();
-    auto* bool_ref = create<core::type::Reference>(
-        core::AddressSpace::kFunction, create<core::type::Bool>(), core::Access::kReadWrite);
-    auto result = table.Lookup(core::BuiltinFn::kSelect, Vector{af, af, bool_ref},
+    auto result = table.Lookup(core::BuiltinFn::kSelect, Vector{af, af, create<core::type::Bool>()},
                                EvaluationStage::kRuntime, Source{});
     ASSERT_EQ(result, Success) << Diagnostics();
     ASSERT_EQ(Diagnostics().str(), "");
diff --git a/src/tint/lang/wgsl/resolver/resolver.cc b/src/tint/lang/wgsl/resolver/resolver.cc
index 95eeb5d..9bc73d6 100644
--- a/src/tint/lang/wgsl/resolver/resolver.cc
+++ b/src/tint/lang/wgsl/resolver/resolver.cc
@@ -2098,7 +2098,7 @@
     // sem::ValueConversion call for a CtorConvIntrinsic with an optional template argument type.
     auto ctor_or_conv = [&](CtorConvIntrinsic ty,
                             const core::type::Type* template_arg) -> sem::Call* {
-        auto arg_tys = tint::Transform(args, [](auto* arg) { return arg->Type(); });
+        auto arg_tys = tint::Transform(args, [](auto* arg) { return arg->Type()->UnwrapRef(); });
         auto match = intrinsic_table_.Lookup(ty, template_arg, arg_tys, args_stage, expr->source);
         if (match != Success) {
             return nullptr;
@@ -2370,7 +2370,7 @@
         arg_stage = core::EarliestStage(arg_stage, arg->Stage());
     }
 
-    auto arg_tys = tint::Transform(args, [](auto* arg) { return arg->Type(); });
+    auto arg_tys = tint::Transform(args, [](auto* arg) { return arg->Type()->UnwrapRef(); });
     auto overload = intrinsic_table_.Lookup(fn, arg_tys, arg_stage, expr->source);
     if (overload != Success) {
         return nullptr;
@@ -3545,8 +3545,8 @@
     }
 
     auto stage = core::EarliestStage(lhs->Stage(), rhs->Stage());
-    auto overload =
-        intrinsic_table_.Lookup(expr->op, lhs->Type(), rhs->Type(), stage, expr->source, false);
+    auto overload = intrinsic_table_.Lookup(expr->op, lhs->Type()->UnwrapRef(),
+                                            rhs->Type()->UnwrapRef(), stage, expr->source, false);
     if (overload != Success) {
         return nullptr;
     }
@@ -3667,7 +3667,8 @@
 
         default: {
             stage = expr->Stage();
-            auto overload = intrinsic_table_.Lookup(unary->op, expr_ty, stage, unary->source);
+            auto overload =
+                intrinsic_table_.Lookup(unary->op, expr_ty->UnwrapRef(), stage, unary->source);
             if (overload != Success) {
                 return nullptr;
             }