wgsl-reader: treat function formal params as const

They should only be singly-assigned.

This is required because consts can hold pointers, but
var's cannot.  And we need to support pointer arguments.

Bug: tint:275
Change-Id: I00a58734725bd08d40df71c736854a93c364a33c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/30923
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc
index 33a487f..09f5348 100644
--- a/src/reader/wgsl/parser_impl.cc
+++ b/src/reader/wgsl/parser_impl.cc
@@ -1991,8 +1991,14 @@
     return {};
 
   for (;;) {
-    ret.push_back(std::make_unique<ast::Variable>(
-        source, name, ast::StorageClass::kNone, type));
+    auto var = std::make_unique<ast::Variable>(source, name,
+                                               ast::StorageClass::kNone, type);
+    // Formal parameters are treated like a const declaration where the
+    // initializer value is provided by the call's argument.  The key point is
+    // that it's not updatable after intially set.  This is unlike C or GLSL
+    // which treat formal parameters like local variables that can be updated.
+    var->set_is_const(true);
+    ret.push_back(std::move(var));
 
     t = peek();
     if (!t.IsComma())
diff --git a/src/reader/wgsl/parser_impl_param_list_test.cc b/src/reader/wgsl/parser_impl_param_list_test.cc
index ca8c38e..1d0b12a 100644
--- a/src/reader/wgsl/parser_impl_param_list_test.cc
+++ b/src/reader/wgsl/parser_impl_param_list_test.cc
@@ -38,6 +38,7 @@
 
   EXPECT_EQ(e[0]->name(), "a");
   EXPECT_EQ(e[0]->type(), i32);
+  EXPECT_TRUE(e[0]->is_const());
 }
 
 TEST_F(ParserImplTest, ParamList_Multiple) {
@@ -52,12 +53,15 @@
 
   EXPECT_EQ(e[0]->name(), "a");
   EXPECT_EQ(e[0]->type(), i32);
+  EXPECT_TRUE(e[0]->is_const());
 
   EXPECT_EQ(e[1]->name(), "b");
   EXPECT_EQ(e[1]->type(), f32);
+  EXPECT_TRUE(e[1]->is_const());
 
   EXPECT_EQ(e[2]->name(), "c");
   EXPECT_EQ(e[2]->type(), vec2);
+  EXPECT_TRUE(e[1]->is_const());
 }
 
 TEST_F(ParserImplTest, ParamList_Empty) {