tint/sem: Add abstract int and float types

Bug: tint:1504
Bug: tint:1516
Change-Id: I7dafaade903c85a6bd6ed095d0d7545de2f238a7
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/88309
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn
index 691b435..5a52e55 100644
--- a/src/tint/BUILD.gn
+++ b/src/tint/BUILD.gn
@@ -553,6 +553,12 @@
 
 libtint_source_set("libtint_sem_src") {
   sources = [
+    "sem/abstract_float.cc",
+    "sem/abstract_float.h",
+    "sem/abstract_int.cc",
+    "sem/abstract_int.h",
+    "sem/abstract_numeric.cc",
+    "sem/abstract_numeric.h",
     "sem/array.cc",
     "sem/array.h",
     "sem/atomic.cc",
diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt
index ac9723f..e5dcb14 100644
--- a/src/tint/CMakeLists.txt
+++ b/src/tint/CMakeLists.txt
@@ -262,6 +262,12 @@
   resolver/validator.cc
   resolver/validator.h
   scope_stack.h
+  sem/abstract_float.cc
+  sem/abstract_float.h
+  sem/abstract_int.cc
+  sem/abstract_int.h
+  sem/abstract_numeric.cc
+  sem/abstract_numeric.h
   sem/array.cc
   sem/array.h
   sem/atomic.cc
diff --git a/src/tint/sem/abstract_float.cc b/src/tint/sem/abstract_float.cc
new file mode 100644
index 0000000..e9282bf
--- /dev/null
+++ b/src/tint/sem/abstract_float.cc
@@ -0,0 +1,40 @@
+// Copyright 2022 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "src/tint/sem/abstract_float.h"
+
+#include "src/tint/program_builder.h"
+#include "src/tint/utils/hash.h"
+
+TINT_INSTANTIATE_TYPEINFO(tint::sem::AbstractFloat);
+
+namespace tint::sem {
+
+AbstractFloat::AbstractFloat() = default;
+AbstractFloat::AbstractFloat(AbstractFloat&&) = default;
+AbstractFloat::~AbstractFloat() = default;
+
+size_t AbstractFloat::Hash() const {
+  return utils::Hash(TypeInfo::Of<AbstractFloat>().full_hashcode);
+}
+
+bool AbstractFloat::Equals(const sem::Type& other) const {
+  return other.Is<AbstractFloat>();
+}
+
+std::string AbstractFloat::FriendlyName(const SymbolTable&) const {
+  return "AbstractFloat";
+}
+
+}  // namespace tint::sem
diff --git a/src/tint/sem/abstract_float.h b/src/tint/sem/abstract_float.h
new file mode 100644
index 0000000..8fb00fb
--- /dev/null
+++ b/src/tint/sem/abstract_float.h
@@ -0,0 +1,49 @@
+// Copyright 2022 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef SRC_TINT_SEM_ABSTRACT_FLOAT_H_
+#define SRC_TINT_SEM_ABSTRACT_FLOAT_H_
+
+#include <string>
+
+#include "src/tint/sem/abstract_numeric.h"
+
+namespace tint::sem {
+
+/// An abstract-float type.
+/// @see https://www.w3.org/TR/WGSL/#abstractFloat
+class AbstractFloat final : public Castable<AbstractFloat, AbstractNumeric> {
+ public:
+  /// Constructor
+  AbstractFloat();
+
+  /// Move constructor
+  AbstractFloat(AbstractFloat&&);
+  ~AbstractFloat() override;
+
+  /// @returns a hash of the type.
+  size_t Hash() const override;
+
+  /// @param other the other type to compare against
+  /// @returns true if this type is equal to the given type
+  bool Equals(const Type& other) const override;
+
+  /// @param symbols the program's symbol table
+  /// @returns the name for this type when printed in diagnostics.
+  std::string FriendlyName(const SymbolTable& symbols) const override;
+};
+
+}  // namespace tint::sem
+
+#endif  // SRC_TINT_SEM_ABSTRACT_FLOAT_H_
diff --git a/src/tint/sem/abstract_int.cc b/src/tint/sem/abstract_int.cc
new file mode 100644
index 0000000..31b242c
--- /dev/null
+++ b/src/tint/sem/abstract_int.cc
@@ -0,0 +1,40 @@
+// Copyright 2022 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "src/tint/sem/abstract_int.h"
+
+#include "src/tint/program_builder.h"
+#include "src/tint/utils/hash.h"
+
+TINT_INSTANTIATE_TYPEINFO(tint::sem::AbstractInt);
+
+namespace tint::sem {
+
+AbstractInt::AbstractInt() = default;
+AbstractInt::AbstractInt(AbstractInt&&) = default;
+AbstractInt::~AbstractInt() = default;
+
+size_t AbstractInt::Hash() const {
+  return utils::Hash(TypeInfo::Of<AbstractInt>().full_hashcode);
+}
+
+bool AbstractInt::Equals(const sem::Type& other) const {
+  return other.Is<AbstractInt>();
+}
+
+std::string AbstractInt::FriendlyName(const SymbolTable&) const {
+  return "AbstractInt";
+}
+
+}  // namespace tint::sem
diff --git a/src/tint/sem/abstract_int.h b/src/tint/sem/abstract_int.h
new file mode 100644
index 0000000..95ec461
--- /dev/null
+++ b/src/tint/sem/abstract_int.h
@@ -0,0 +1,49 @@
+// Copyright 2022 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef SRC_TINT_SEM_ABSTRACT_INT_H_
+#define SRC_TINT_SEM_ABSTRACT_INT_H_
+
+#include <string>
+
+#include "src/tint/sem/abstract_numeric.h"
+
+namespace tint::sem {
+
+/// An abstract-int type.
+/// @see https://www.w3.org/TR/WGSL/#abstractint
+class AbstractInt final : public Castable<AbstractInt, AbstractNumeric> {
+ public:
+  /// Constructor
+  AbstractInt();
+
+  /// Move constructor
+  AbstractInt(AbstractInt&&);
+  ~AbstractInt() override;
+
+  /// @returns a hash of the type.
+  size_t Hash() const override;
+
+  /// @param other the other type to compare against
+  /// @returns true if the this type is equal to the given type
+  bool Equals(const Type& other) const override;
+
+  /// @param symbols the program's symbol table
+  /// @returns the name for this type when printed in diagnostics.
+  std::string FriendlyName(const SymbolTable& symbols) const override;
+};
+
+}  // namespace tint::sem
+
+#endif  // SRC_TINT_SEM_ABSTRACT_INT_H_
diff --git a/src/tint/sem/abstract_numeric.cc b/src/tint/sem/abstract_numeric.cc
new file mode 100644
index 0000000..3429171
--- /dev/null
+++ b/src/tint/sem/abstract_numeric.cc
@@ -0,0 +1,37 @@
+// Copyright 2022 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "src/tint/sem/abstract_numeric.h"
+
+TINT_INSTANTIATE_TYPEINFO(tint::sem::AbstractNumeric);
+
+namespace tint::sem {
+
+AbstractNumeric::AbstractNumeric() = default;
+AbstractNumeric::AbstractNumeric(AbstractNumeric&&) = default;
+AbstractNumeric::~AbstractNumeric() = default;
+
+uint32_t AbstractNumeric::Size() const {
+  return 0;
+}
+
+uint32_t AbstractNumeric::Align() const {
+  return 0;
+}
+
+bool AbstractNumeric::IsConstructible() const {
+  return false;
+}
+
+}  // namespace tint::sem
diff --git a/src/tint/sem/abstract_numeric.h b/src/tint/sem/abstract_numeric.h
new file mode 100644
index 0000000..637d955
--- /dev/null
+++ b/src/tint/sem/abstract_numeric.h
@@ -0,0 +1,47 @@
+// Copyright 2022 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef SRC_TINT_SEM_ABSTRACT_NUMERIC_H_
+#define SRC_TINT_SEM_ABSTRACT_NUMERIC_H_
+
+#include <string>
+
+#include "src/tint/sem/type.h"
+
+namespace tint::sem {
+
+/// The base class for abstract-int and abstract-float types.
+/// @see https://www.w3.org/TR/WGSL/#types-for-creation-time-constants
+class AbstractNumeric : public Castable<AbstractNumeric, Type> {
+ public:
+  /// Constructor
+  AbstractNumeric();
+
+  /// Move constructor
+  AbstractNumeric(AbstractNumeric&&);
+  ~AbstractNumeric() override;
+
+  /// @returns 0, as the type is abstract.
+  uint32_t Size() const override;
+
+  /// @returns 0, as the type is abstract.
+  uint32_t Align() const override;
+
+  /// @returns 0, as the type is abstract.
+  bool IsConstructible() const override;
+};
+
+}  // namespace tint::sem
+
+#endif  // SRC_TINT_SEM_ABSTRACT_NUMERIC_H_
diff --git a/src/tint/sem/atomic.h b/src/tint/sem/atomic.h
index 0bc9808..cdfa562 100644
--- a/src/tint/sem/atomic.h
+++ b/src/tint/sem/atomic.h
@@ -54,7 +54,7 @@
   uint32_t Align() const override;
 
   /// @returns true if constructible as per
-  /// https://gpuweb.github.io/gpuweb/wgsl/#constructible-typesd
+  /// https://gpuweb.github.io/gpuweb/wgsl/#constructible-types
   bool IsConstructible() const override;
 
  private: