tint: Deprecated module-scope 'let' for 'const'
Enable the parsing of 'const'.
Warn on use of module-scope 'let', and automatically replace with 'const'.
Fixed: tint:1580
Change-Id: I214aabca80686dc6b60ae21a7a57fbfb4898ea83
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93786
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/test/tint/const/global/global.wgsl b/test/tint/const/global/global.wgsl
new file mode 100644
index 0000000..12f56a8
--- /dev/null
+++ b/test/tint/const/global/global.wgsl
@@ -0,0 +1,27 @@
+type MyArray = array<f32, 10>;
+
+// Global consts
+const c1 = 1;
+const c2 = 1u;
+const c3 = 1.0;
+
+const c4 = vec3<i32>(1, 1, 1);
+const c5 = vec3<u32>(1u, 1u, 1u);
+const c6 = vec3<f32>(1.0, 1.0, 1.0);
+
+const c7 = mat3x3<f32>(vec3<f32>(1.0, 1.0, 1.0), vec3<f32>(1.0, 1.0, 1.0), vec3<f32>(1.0, 1.0, 1.0));
+
+const c9 = MyArray();
+
+@fragment
+fn main() -> @location(0) vec4<f32> {
+ var v1 = c1;
+ var v2 = c2;
+ var v3 = c3;
+ var v4 = c4;
+ var v5 = c5;
+ var v6 = c6;
+ var v7 = c7;
+ var v9 = c9;
+ return vec4<f32>(0.0,0.0,0.0,0.0);
+}
diff --git a/test/tint/const/global/global.wgsl.expected.glsl b/test/tint/const/global/global.wgsl.expected.glsl
new file mode 100644
index 0000000..54e642b
--- /dev/null
+++ b/test/tint/const/global/global.wgsl.expected.glsl
@@ -0,0 +1,21 @@
+#version 310 es
+precision mediump float;
+
+layout(location = 0) out vec4 value;
+vec4 tint_symbol() {
+ int v1 = 1;
+ uint v2 = 1u;
+ float v3 = 1.0f;
+ ivec3 v4 = ivec3(1);
+ uvec3 v5 = uvec3(1u);
+ vec3 v6 = vec3(1.0f);
+ mat3 v7 = mat3(vec3(1.0f), vec3(1.0f), vec3(1.0f));
+ float v9[10] = float[10](0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+ return vec4(0.0f);
+}
+
+void main() {
+ vec4 inner_result = tint_symbol();
+ value = inner_result;
+ return;
+}
diff --git a/test/tint/const/global/global.wgsl.expected.hlsl b/test/tint/const/global/global.wgsl.expected.hlsl
new file mode 100644
index 0000000..cc2c4c6
--- /dev/null
+++ b/test/tint/const/global/global.wgsl.expected.hlsl
@@ -0,0 +1,22 @@
+struct tint_symbol {
+ float4 value : SV_Target0;
+};
+
+float4 main_inner() {
+ int v1 = 1;
+ uint v2 = 1u;
+ float v3 = 1.0f;
+ int3 v4 = (1).xxx;
+ uint3 v5 = (1u).xxx;
+ float3 v6 = (1.0f).xxx;
+ float3x3 v7 = float3x3((1.0f).xxx, (1.0f).xxx, (1.0f).xxx);
+ float v9[10] = (float[10])0;
+ return (0.0f).xxxx;
+}
+
+tint_symbol main() {
+ const float4 inner_result = main_inner();
+ tint_symbol wrapper_result = (tint_symbol)0;
+ wrapper_result.value = inner_result;
+ return wrapper_result;
+}
diff --git a/test/tint/const/global/global.wgsl.expected.msl b/test/tint/const/global/global.wgsl.expected.msl
new file mode 100644
index 0000000..1807542
--- /dev/null
+++ b/test/tint/const/global/global.wgsl.expected.msl
@@ -0,0 +1,39 @@
+#include <metal_stdlib>
+
+using namespace metal;
+
+template<typename T, size_t N>
+struct tint_array {
+ const constant T& operator[](size_t i) const constant { return elements[i]; }
+ device T& operator[](size_t i) device { return elements[i]; }
+ const device T& operator[](size_t i) const device { return elements[i]; }
+ thread T& operator[](size_t i) thread { return elements[i]; }
+ const thread T& operator[](size_t i) const thread { return elements[i]; }
+ threadgroup T& operator[](size_t i) threadgroup { return elements[i]; }
+ const threadgroup T& operator[](size_t i) const threadgroup { return elements[i]; }
+ T elements[N];
+};
+
+struct tint_symbol_1 {
+ float4 value [[color(0)]];
+};
+
+float4 tint_symbol_inner() {
+ int v1 = 1;
+ uint v2 = 1u;
+ float v3 = 1.0f;
+ int3 v4 = int3(1);
+ uint3 v5 = uint3(1u);
+ float3 v6 = float3(1.0f);
+ float3x3 v7 = float3x3(float3(1.0f), float3(1.0f), float3(1.0f));
+ tint_array<float, 10> v9 = tint_array<float, 10>{};
+ return float4(0.0f);
+}
+
+fragment tint_symbol_1 tint_symbol() {
+ float4 const inner_result = tint_symbol_inner();
+ tint_symbol_1 wrapper_result = {};
+ wrapper_result.value = inner_result;
+ return wrapper_result;
+}
+
diff --git a/test/tint/const/global/global.wgsl.expected.spvasm b/test/tint/const/global/global.wgsl.expected.spvasm
new file mode 100644
index 0000000..d93b74d
--- /dev/null
+++ b/test/tint/const/global/global.wgsl.expected.spvasm
@@ -0,0 +1,87 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 53
+; Schema: 0
+ OpCapability Shader
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint Fragment %main "main" %value
+ OpExecutionMode %main OriginUpperLeft
+ OpName %value "value"
+ OpName %main_inner "main_inner"
+ OpName %v1 "v1"
+ OpName %v2 "v2"
+ OpName %v3 "v3"
+ OpName %v4 "v4"
+ OpName %v5 "v5"
+ OpName %v6 "v6"
+ OpName %v7 "v7"
+ OpName %v9 "v9"
+ OpName %main "main"
+ OpDecorate %value Location 0
+ OpDecorate %_arr_float_uint_10 ArrayStride 4
+ %float = OpTypeFloat 32
+ %v4float = OpTypeVector %float 4
+%_ptr_Output_v4float = OpTypePointer Output %v4float
+ %5 = OpConstantNull %v4float
+ %value = OpVariable %_ptr_Output_v4float Output %5
+ %6 = OpTypeFunction %v4float
+ %int = OpTypeInt 32 1
+ %int_1 = OpConstant %int 1
+%_ptr_Function_int = OpTypePointer Function %int
+ %13 = OpConstantNull %int
+ %uint = OpTypeInt 32 0
+ %uint_1 = OpConstant %uint 1
+%_ptr_Function_uint = OpTypePointer Function %uint
+ %18 = OpConstantNull %uint
+ %float_1 = OpConstant %float 1
+%_ptr_Function_float = OpTypePointer Function %float
+ %22 = OpConstantNull %float
+ %v3int = OpTypeVector %int 3
+ %24 = OpConstantComposite %v3int %int_1 %int_1 %int_1
+%_ptr_Function_v3int = OpTypePointer Function %v3int
+ %27 = OpConstantNull %v3int
+ %v3uint = OpTypeVector %uint 3
+ %29 = OpConstantComposite %v3uint %uint_1 %uint_1 %uint_1
+%_ptr_Function_v3uint = OpTypePointer Function %v3uint
+ %32 = OpConstantNull %v3uint
+ %v3float = OpTypeVector %float 3
+ %34 = OpConstantComposite %v3float %float_1 %float_1 %float_1
+%_ptr_Function_v3float = OpTypePointer Function %v3float
+ %37 = OpConstantNull %v3float
+%mat3v3float = OpTypeMatrix %v3float 3
+ %39 = OpConstantComposite %mat3v3float %34 %34 %34
+%_ptr_Function_mat3v3float = OpTypePointer Function %mat3v3float
+ %42 = OpConstantNull %mat3v3float
+ %uint_10 = OpConstant %uint 10
+%_arr_float_uint_10 = OpTypeArray %float %uint_10
+ %45 = OpConstantNull %_arr_float_uint_10
+%_ptr_Function__arr_float_uint_10 = OpTypePointer Function %_arr_float_uint_10
+ %void = OpTypeVoid
+ %48 = OpTypeFunction %void
+ %main_inner = OpFunction %v4float None %6
+ %8 = OpLabel
+ %v1 = OpVariable %_ptr_Function_int Function %13
+ %v2 = OpVariable %_ptr_Function_uint Function %18
+ %v3 = OpVariable %_ptr_Function_float Function %22
+ %v4 = OpVariable %_ptr_Function_v3int Function %27
+ %v5 = OpVariable %_ptr_Function_v3uint Function %32
+ %v6 = OpVariable %_ptr_Function_v3float Function %37
+ %v7 = OpVariable %_ptr_Function_mat3v3float Function %42
+ %v9 = OpVariable %_ptr_Function__arr_float_uint_10 Function %45
+ OpStore %v1 %int_1
+ OpStore %v2 %uint_1
+ OpStore %v3 %float_1
+ OpStore %v4 %24
+ OpStore %v5 %29
+ OpStore %v6 %34
+ OpStore %v7 %39
+ OpStore %v9 %45
+ OpReturnValue %5
+ OpFunctionEnd
+ %main = OpFunction %void None %48
+ %51 = OpLabel
+ %52 = OpFunctionCall %v4float %main_inner
+ OpStore %value %52
+ OpReturn
+ OpFunctionEnd
diff --git a/test/tint/const/global/global.wgsl.expected.wgsl b/test/tint/const/global/global.wgsl.expected.wgsl
new file mode 100644
index 0000000..8fc0106
--- /dev/null
+++ b/test/tint/const/global/global.wgsl.expected.wgsl
@@ -0,0 +1,30 @@
+type MyArray = array<f32, 10>;
+
+const c1 = 1;
+
+const c2 = 1u;
+
+const c3 = 1.0;
+
+const c4 = vec3<i32>(1, 1, 1);
+
+const c5 = vec3<u32>(1u, 1u, 1u);
+
+const c6 = vec3<f32>(1.0, 1.0, 1.0);
+
+const c7 = mat3x3<f32>(vec3<f32>(1.0, 1.0, 1.0), vec3<f32>(1.0, 1.0, 1.0), vec3<f32>(1.0, 1.0, 1.0));
+
+const c9 = MyArray();
+
+@fragment
+fn main() -> @location(0) vec4<f32> {
+ var v1 = c1;
+ var v2 = c2;
+ var v3 = c3;
+ var v4 = c4;
+ var v5 = c5;
+ var v6 = c6;
+ var v7 = c7;
+ var v9 = c9;
+ return vec4<f32>(0.0, 0.0, 0.0, 0.0);
+}
diff --git a/test/tint/const/inferred/function.wgsl b/test/tint/const/inferred/function.wgsl
new file mode 100644
index 0000000..cd8811b
--- /dev/null
+++ b/test/tint/const/inferred/function.wgsl
@@ -0,0 +1,21 @@
+type MyArray = array<f32, 10>;
+
+// Function-scope consts
+fn const_decls() {
+ const v1 = 1;
+ const v2 = 1u;
+ const v3 = 1.0;
+
+ const v4 = vec3<i32>(1, 1, 1);
+ const v5 = vec3<u32>(1u, 1u, 1u);
+ const v6 = vec3<f32>(1.0, 1.0, 1.0);
+
+ const v7 = mat3x3<f32>(v6, v6, v6);
+
+ const v8 = MyArray();
+}
+
+@fragment
+fn main() -> @location(0) vec4<f32> {
+ return vec4<f32>(0.0,0.0,0.0,0.0);
+}
diff --git a/test/tint/const/inferred/function.wgsl.expected.glsl b/test/tint/const/inferred/function.wgsl.expected.glsl
new file mode 100644
index 0000000..69a3a97
--- /dev/null
+++ b/test/tint/const/inferred/function.wgsl.expected.glsl
@@ -0,0 +1,13 @@
+#version 310 es
+precision mediump float;
+
+layout(location = 0) out vec4 value;
+vec4 tint_symbol() {
+ return vec4(0.0f);
+}
+
+void main() {
+ vec4 inner_result = tint_symbol();
+ value = inner_result;
+ return;
+}
diff --git a/test/tint/const/inferred/function.wgsl.expected.hlsl b/test/tint/const/inferred/function.wgsl.expected.hlsl
new file mode 100644
index 0000000..f60a041
--- /dev/null
+++ b/test/tint/const/inferred/function.wgsl.expected.hlsl
@@ -0,0 +1,17 @@
+void const_decls() {
+}
+
+struct tint_symbol {
+ float4 value : SV_Target0;
+};
+
+float4 main_inner() {
+ return (0.0f).xxxx;
+}
+
+tint_symbol main() {
+ const float4 inner_result = main_inner();
+ tint_symbol wrapper_result = (tint_symbol)0;
+ wrapper_result.value = inner_result;
+ return wrapper_result;
+}
diff --git a/test/tint/const/inferred/function.wgsl.expected.msl b/test/tint/const/inferred/function.wgsl.expected.msl
new file mode 100644
index 0000000..ad4f634
--- /dev/null
+++ b/test/tint/const/inferred/function.wgsl.expected.msl
@@ -0,0 +1,21 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void const_decls() {
+}
+
+struct tint_symbol_1 {
+ float4 value [[color(0)]];
+};
+
+float4 tint_symbol_inner() {
+ return float4(0.0f);
+}
+
+fragment tint_symbol_1 tint_symbol() {
+ float4 const inner_result = tint_symbol_inner();
+ tint_symbol_1 wrapper_result = {};
+ wrapper_result.value = inner_result;
+ return wrapper_result;
+}
+
diff --git a/test/tint/const/inferred/function.wgsl.expected.spvasm b/test/tint/const/inferred/function.wgsl.expected.spvasm
new file mode 100644
index 0000000..c24ee9e
--- /dev/null
+++ b/test/tint/const/inferred/function.wgsl.expected.spvasm
@@ -0,0 +1,36 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 16
+; Schema: 0
+ OpCapability Shader
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint Fragment %main "main" %value
+ OpExecutionMode %main OriginUpperLeft
+ OpName %value "value"
+ OpName %const_decls "const_decls"
+ OpName %main_inner "main_inner"
+ OpName %main "main"
+ OpDecorate %value Location 0
+ %float = OpTypeFloat 32
+ %v4float = OpTypeVector %float 4
+%_ptr_Output_v4float = OpTypePointer Output %v4float
+ %5 = OpConstantNull %v4float
+ %value = OpVariable %_ptr_Output_v4float Output %5
+ %void = OpTypeVoid
+ %6 = OpTypeFunction %void
+ %10 = OpTypeFunction %v4float
+%const_decls = OpFunction %void None %6
+ %9 = OpLabel
+ OpReturn
+ OpFunctionEnd
+ %main_inner = OpFunction %v4float None %10
+ %12 = OpLabel
+ OpReturnValue %5
+ OpFunctionEnd
+ %main = OpFunction %void None %6
+ %14 = OpLabel
+ %15 = OpFunctionCall %v4float %main_inner
+ OpStore %value %15
+ OpReturn
+ OpFunctionEnd
diff --git a/test/tint/const/inferred/function.wgsl.expected.wgsl b/test/tint/const/inferred/function.wgsl.expected.wgsl
new file mode 100644
index 0000000..94ff328
--- /dev/null
+++ b/test/tint/const/inferred/function.wgsl.expected.wgsl
@@ -0,0 +1,17 @@
+type MyArray = array<f32, 10>;
+
+fn const_decls() {
+ const v1 = 1;
+ const v2 = 1u;
+ const v3 = 1.0;
+ const v4 = vec3<i32>(1, 1, 1);
+ const v5 = vec3<u32>(1u, 1u, 1u);
+ const v6 = vec3<f32>(1.0, 1.0, 1.0);
+ const v7 = mat3x3<f32>(v6, v6, v6);
+ const v8 = MyArray();
+}
+
+@fragment
+fn main() -> @location(0) vec4<f32> {
+ return vec4<f32>(0.0, 0.0, 0.0, 0.0);
+}