Move type base classes into type/ folder.

This CL moves sem/type and copies sem/node into the type/ folder. The
type subclasses are moved over to using type::Type while remaining in
the sem:: namespace. They will be moved over in followup CLs.

Bug: tint:1718
Change-Id: I3f3495328d734f88e4fc2dfbc6705343f1198dc5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113180
Reviewed-by: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair
2022-12-08 00:32:27 +00:00
committed by Dawn LUCI CQ
parent ad71dc1ab2
commit 5f764d8527
148 changed files with 1895 additions and 1657 deletions

View File

@@ -34,8 +34,8 @@
#include "src/tint/sem/member_accessor_expression.h"
#include "src/tint/sem/sampled_texture.h"
#include "src/tint/sem/statement.h"
#include "src/tint/sem/test_helper.h"
#include "src/tint/sem/variable.h"
#include "src/tint/type/test_helper.h"
using ::testing::ElementsAre;
using ::testing::HasSubstr;

File diff suppressed because it is too large Load Diff

View File

@@ -18,6 +18,7 @@
#include <stddef.h>
#include <string>
#include "src/tint/type/type.h"
#include "src/tint/utils/result.h"
#include "src/tint/utils/vector.h"
@@ -33,7 +34,6 @@ namespace tint::sem {
class Constant;
class Expression;
class StructMember;
class Type;
} // namespace tint::sem
namespace tint::resolver {
@@ -56,7 +56,7 @@ class ConstEval {
using Result = utils::Result<const sem::Constant*>;
/// Typedef for a constant evaluation function
using Function = Result (ConstEval::*)(const sem::Type* result_ty,
using Function = Result (ConstEval::*)(const type::Type* result_ty,
utils::VectorRef<const sem::Constant*>,
const Source&);
@@ -71,13 +71,13 @@ class ConstEval {
/// @param ty the target type - must be an array or initializer
/// @param args the input arguments
/// @return the constructed value, or null if the value cannot be calculated
Result ArrayOrStructInit(const sem::Type* ty, utils::VectorRef<const sem::Expression*> args);
Result ArrayOrStructInit(const type::Type* ty, utils::VectorRef<const sem::Expression*> args);
/// @param ty the target type
/// @param expr the input expression
/// @return the bit-cast of the given expression to the given type, or null if the value cannot
/// be calculated
Result Bitcast(const sem::Type* ty, const sem::Expression* expr);
Result Bitcast(const type::Type* ty, const sem::Expression* expr);
/// @param obj the object being indexed
/// @param idx the index expression
@@ -87,7 +87,7 @@ class ConstEval {
/// @param ty the result type
/// @param lit the literal AST node
/// @return the constant value of the literal
Result Literal(const sem::Type* ty, const ast::LiteralExpression* lit);
Result Literal(const type::Type* ty, const ast::LiteralExpression* lit);
/// @param obj the object being accessed
/// @param member the member
@@ -98,7 +98,7 @@ class ConstEval {
/// @param vector the vector being swizzled
/// @param indices the swizzle indices
/// @return the result of the swizzle, or null if the value cannot be calculated
Result Swizzle(const sem::Type* ty,
Result Swizzle(const type::Type* ty,
const sem::Expression* vector,
utils::VectorRef<uint32_t> indices);
@@ -107,7 +107,7 @@ class ConstEval {
/// @param value the value being converted
/// @param source the source location
/// @return the converted value, or null if the value cannot be calculated
Result Convert(const sem::Type* ty, const sem::Constant* value, const Source& source);
Result Convert(const type::Type* ty, const sem::Constant* value, const Source& source);
////////////////////////////////////////////////////////////////////////////////////////////////
// Constant value evaluation methods, to be indirectly called via the intrinsic table
@@ -118,7 +118,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the converted value, or null if the value cannot be calculated
Result Conv(const sem::Type* ty,
Result Conv(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -127,7 +127,7 @@ class ConstEval {
/// @param args the input arguments (no arguments provided)
/// @param source the source location
/// @return the constructed value, or null if the value cannot be calculated
Result Zero(const sem::Type* ty,
Result Zero(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -136,7 +136,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the constructed value, or null if the value cannot be calculated
Result Identity(const sem::Type* ty,
Result Identity(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -145,7 +145,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the constructed value, or null if the value cannot be calculated
Result VecSplat(const sem::Type* ty,
Result VecSplat(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -154,7 +154,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the constructed value, or null if the value cannot be calculated
Result VecInitS(const sem::Type* ty,
Result VecInitS(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -163,7 +163,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the constructed value, or null if the value cannot be calculated
Result VecInitM(const sem::Type* ty,
Result VecInitM(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -172,7 +172,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the constructed value, or null if the value cannot be calculated
Result MatInitS(const sem::Type* ty,
Result MatInitS(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -181,7 +181,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the constructed value, or null if the value cannot be calculated
Result MatInitV(const sem::Type* ty,
Result MatInitV(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -194,7 +194,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpComplement(const sem::Type* ty,
Result OpComplement(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -203,7 +203,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpUnaryMinus(const sem::Type* ty,
Result OpUnaryMinus(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -212,7 +212,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpNot(const sem::Type* ty,
Result OpNot(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -225,7 +225,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpPlus(const sem::Type* ty,
Result OpPlus(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -234,7 +234,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpMinus(const sem::Type* ty,
Result OpMinus(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -243,7 +243,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpMultiply(const sem::Type* ty,
Result OpMultiply(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -252,7 +252,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpMultiplyMatVec(const sem::Type* ty,
Result OpMultiplyMatVec(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -261,7 +261,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpMultiplyVecMat(const sem::Type* ty,
Result OpMultiplyVecMat(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -270,7 +270,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpMultiplyMatMat(const sem::Type* ty,
Result OpMultiplyMatMat(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -279,7 +279,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpDivide(const sem::Type* ty,
Result OpDivide(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -288,7 +288,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpModulo(const sem::Type* ty,
Result OpModulo(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -297,7 +297,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpEqual(const sem::Type* ty,
Result OpEqual(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -306,7 +306,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpNotEqual(const sem::Type* ty,
Result OpNotEqual(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -315,7 +315,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpLessThan(const sem::Type* ty,
Result OpLessThan(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -324,7 +324,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpGreaterThan(const sem::Type* ty,
Result OpGreaterThan(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -333,7 +333,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpLessThanEqual(const sem::Type* ty,
Result OpLessThanEqual(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -342,7 +342,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpGreaterThanEqual(const sem::Type* ty,
Result OpGreaterThanEqual(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -351,7 +351,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpLogicalAnd(const sem::Type* ty,
Result OpLogicalAnd(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -360,7 +360,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpLogicalOr(const sem::Type* ty,
Result OpLogicalOr(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -369,7 +369,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpAnd(const sem::Type* ty,
Result OpAnd(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -378,7 +378,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpOr(const sem::Type* ty,
Result OpOr(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -387,7 +387,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpXor(const sem::Type* ty,
Result OpXor(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -396,7 +396,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpShiftLeft(const sem::Type* ty,
Result OpShiftLeft(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -405,7 +405,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result OpShiftRight(const sem::Type* ty,
Result OpShiftRight(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -418,7 +418,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result abs(const sem::Type* ty,
Result abs(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -427,7 +427,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result acos(const sem::Type* ty,
Result acos(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -436,7 +436,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result acosh(const sem::Type* ty,
Result acosh(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -445,7 +445,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result all(const sem::Type* ty,
Result all(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -454,7 +454,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result any(const sem::Type* ty,
Result any(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -463,7 +463,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result asin(const sem::Type* ty,
Result asin(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -472,7 +472,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result asinh(const sem::Type* ty,
Result asinh(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -481,7 +481,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result atan(const sem::Type* ty,
Result atan(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -490,7 +490,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result atanh(const sem::Type* ty,
Result atanh(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -499,7 +499,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result atan2(const sem::Type* ty,
Result atan2(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -508,7 +508,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result ceil(const sem::Type* ty,
Result ceil(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -517,7 +517,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result clamp(const sem::Type* ty,
Result clamp(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -526,7 +526,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result cos(const sem::Type* ty,
Result cos(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -535,7 +535,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result cosh(const sem::Type* ty,
Result cosh(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -544,7 +544,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result countLeadingZeros(const sem::Type* ty,
Result countLeadingZeros(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -553,7 +553,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result countOneBits(const sem::Type* ty,
Result countOneBits(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -562,7 +562,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result countTrailingZeros(const sem::Type* ty,
Result countTrailingZeros(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -571,7 +571,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result cross(const sem::Type* ty,
Result cross(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -580,7 +580,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location of the conversion
/// @return the result value, or null if the value cannot be calculated
Result degrees(const sem::Type* ty,
Result degrees(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -589,7 +589,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location of the conversion
/// @return the result value, or null if the value cannot be calculated
Result determinant(const sem::Type* ty,
Result determinant(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -598,7 +598,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location of the conversion
/// @return the result value, or null if the value cannot be calculated
Result distance(const sem::Type* ty,
Result distance(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -607,7 +607,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result dot(const sem::Type* ty,
Result dot(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -616,7 +616,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result exp(const sem::Type* ty,
Result exp(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -625,7 +625,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result exp2(const sem::Type* ty,
Result exp2(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -634,7 +634,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result extractBits(const sem::Type* ty,
Result extractBits(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -643,7 +643,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result faceForward(const sem::Type* ty,
Result faceForward(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -652,7 +652,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result firstLeadingBit(const sem::Type* ty,
Result firstLeadingBit(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -661,7 +661,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result firstTrailingBit(const sem::Type* ty,
Result firstTrailingBit(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -670,7 +670,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result floor(const sem::Type* ty,
Result floor(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -679,7 +679,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result fma(const sem::Type* ty,
Result fma(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -688,7 +688,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result frexp(const sem::Type* ty,
Result frexp(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -697,7 +697,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result insertBits(const sem::Type* ty,
Result insertBits(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -706,7 +706,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result inverseSqrt(const sem::Type* ty,
Result inverseSqrt(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -715,7 +715,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result length(const sem::Type* ty,
Result length(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -724,7 +724,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result log(const sem::Type* ty,
Result log(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -733,7 +733,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result log2(const sem::Type* ty,
Result log2(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -742,7 +742,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result max(const sem::Type* ty,
Result max(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -751,7 +751,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result min(const sem::Type* ty, // NOLINT(build/include_what_you_use) -- confused by min
Result min(const type::Type* ty, // NOLINT(build/include_what_you_use) -- confused by min
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -760,7 +760,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result modf(const sem::Type* ty,
Result modf(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -769,7 +769,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result normalize(const sem::Type* ty,
Result normalize(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -778,7 +778,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result pack2x16float(const sem::Type* ty,
Result pack2x16float(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -787,7 +787,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result pack2x16snorm(const sem::Type* ty,
Result pack2x16snorm(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -796,7 +796,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result pack2x16unorm(const sem::Type* ty,
Result pack2x16unorm(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -805,7 +805,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result pack4x8snorm(const sem::Type* ty,
Result pack4x8snorm(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -814,7 +814,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result pack4x8unorm(const sem::Type* ty,
Result pack4x8unorm(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -823,7 +823,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location of the conversion
/// @return the result value, or null if the value cannot be calculated
Result radians(const sem::Type* ty,
Result radians(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -832,7 +832,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location of the conversion
/// @return the result value, or null if the value cannot be calculated
Result reflect(const sem::Type* ty,
Result reflect(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -841,7 +841,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location of the conversion
/// @return the result value, or null if the value cannot be calculated
Result refract(const sem::Type* ty,
Result refract(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -850,7 +850,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result reverseBits(const sem::Type* ty,
Result reverseBits(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -859,7 +859,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result round(const sem::Type* ty,
Result round(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -868,7 +868,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result saturate(const sem::Type* ty,
Result saturate(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -877,7 +877,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result select_bool(const sem::Type* ty,
Result select_bool(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -886,7 +886,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result select_boolvec(const sem::Type* ty,
Result select_boolvec(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -895,7 +895,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result sign(const sem::Type* ty,
Result sign(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -904,7 +904,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result sin(const sem::Type* ty,
Result sin(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -913,7 +913,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result sinh(const sem::Type* ty,
Result sinh(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -922,7 +922,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result smoothstep(const sem::Type* ty,
Result smoothstep(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -931,7 +931,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result step(const sem::Type* ty,
Result step(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -940,7 +940,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result sqrt(const sem::Type* ty,
Result sqrt(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -949,7 +949,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result tan(const sem::Type* ty,
Result tan(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -958,7 +958,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result tanh(const sem::Type* ty,
Result tanh(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -967,7 +967,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result transpose(const sem::Type* ty,
Result transpose(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -976,7 +976,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result trunc(const sem::Type* ty,
Result trunc(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -985,7 +985,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result unpack2x16float(const sem::Type* ty,
Result unpack2x16float(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -994,7 +994,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result unpack2x16snorm(const sem::Type* ty,
Result unpack2x16snorm(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -1003,7 +1003,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result unpack2x16unorm(const sem::Type* ty,
Result unpack2x16unorm(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -1012,7 +1012,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result unpack4x8snorm(const sem::Type* ty,
Result unpack4x8snorm(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -1021,7 +1021,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result unpack4x8unorm(const sem::Type* ty,
Result unpack4x8unorm(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -1030,7 +1030,7 @@ class ConstEval {
/// @param args the input arguments
/// @param source the source location
/// @return the result value, or null if the value cannot be calculated
Result quantizeToF16(const sem::Type* ty,
Result quantizeToF16(const type::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
@@ -1237,91 +1237,91 @@ class ConstEval {
/// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
auto AddFunc(const Source& source, const sem::Type* elem_ty);
auto AddFunc(const Source& source, const type::Type* elem_ty);
/// Returns a callable that calls Sub, and creates a Constant with its result of type `elem_ty`
/// if successful, or returns Failure otherwise.
/// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
auto SubFunc(const Source& source, const sem::Type* elem_ty);
auto SubFunc(const Source& source, const type::Type* elem_ty);
/// Returns a callable that calls Mul, and creates a Constant with its result of type `elem_ty`
/// if successful, or returns Failure otherwise.
/// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
auto MulFunc(const Source& source, const sem::Type* elem_ty);
auto MulFunc(const Source& source, const type::Type* elem_ty);
/// Returns a callable that calls Div, and creates a Constant with its result of type `elem_ty`
/// if successful, or returns Failure otherwise.
/// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
auto DivFunc(const Source& source, const sem::Type* elem_ty);
auto DivFunc(const Source& source, const type::Type* elem_ty);
/// Returns a callable that calls Mod, and creates a Constant with its result of type `elem_ty`
/// if successful, or returns Failure otherwise.
/// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
auto ModFunc(const Source& source, const sem::Type* elem_ty);
auto ModFunc(const Source& source, const type::Type* elem_ty);
/// Returns a callable that calls Dot2, and creates a Constant with its result of type `elem_ty`
/// if successful, or returns Failure otherwise.
/// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
auto Dot2Func(const Source& source, const sem::Type* elem_ty);
auto Dot2Func(const Source& source, const type::Type* elem_ty);
/// Returns a callable that calls Dot3, and creates a Constant with its result of type `elem_ty`
/// if successful, or returns Failure otherwise.
/// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
auto Dot3Func(const Source& source, const sem::Type* elem_ty);
auto Dot3Func(const Source& source, const type::Type* elem_ty);
/// Returns a callable that calls Dot4, and creates a Constant with its result of type `elem_ty`
/// if successful, or returns Failure otherwise.
/// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
auto Dot4Func(const Source& source, const sem::Type* elem_ty);
auto Dot4Func(const Source& source, const type::Type* elem_ty);
/// Returns a callable that calls Det2, and creates a Constant with its result of type `elem_ty`
/// if successful, or returns Failure otherwise.
/// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
auto Det2Func(const Source& source, const sem::Type* elem_ty);
auto Det2Func(const Source& source, const type::Type* elem_ty);
/// Returns a callable that calls Det3, and creates a Constant with its result of type `elem_ty`
/// if successful, or returns Failure otherwise.
/// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
auto Det3Func(const Source& source, const sem::Type* elem_ty);
auto Det3Func(const Source& source, const type::Type* elem_ty);
/// Returns a callable that calls Det4, and creates a Constant with its result of type `elem_ty`
/// if successful, or returns Failure otherwise.
/// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
auto Det4Func(const Source& source, const sem::Type* elem_ty);
auto Det4Func(const Source& source, const type::Type* elem_ty);
/// Returns a callable that calls Clamp, and creates a Constant with its result of type
/// `elem_ty` if successful, or returns Failure otherwise.
/// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
auto ClampFunc(const Source& source, const sem::Type* elem_ty);
auto ClampFunc(const Source& source, const type::Type* elem_ty);
/// Returns a callable that calls SqrtFunc, and creates a Constant with its
/// result of type `elem_ty` if successful, or returns Failure otherwise.
/// @param source the source location
/// @param elem_ty the element type of the Constant to create on success
/// @returns the callable function
auto SqrtFunc(const Source& source, const sem::Type* elem_ty);
auto SqrtFunc(const Source& source, const type::Type* elem_ty);
/// Returns the dot product of v1 and v2.
/// @param source the source location
@@ -1335,7 +1335,7 @@ class ConstEval {
/// @param ty the return type
/// @param c0 the constant to calculate the length of
/// @returns the length of c0
Result Length(const Source& source, const sem::Type* ty, const sem::Constant* c0);
Result Length(const Source& source, const type::Type* ty, const sem::Constant* c0);
/// Returns the product of v1 and v2
/// @param source the source location
@@ -1344,7 +1344,7 @@ class ConstEval {
/// @param v2 rhs value
/// @returns the product of v1 and v2
Result Mul(const Source& source,
const sem::Type* ty,
const type::Type* ty,
const sem::Constant* v1,
const sem::Constant* v2);
@@ -1355,7 +1355,7 @@ class ConstEval {
/// @param v2 rhs value
/// @returns the difference between v2 and v1
Result Sub(const Source& source,
const sem::Type* ty,
const type::Type* ty,
const sem::Constant* v1,
const sem::Constant* v2);

View File

@@ -23,7 +23,7 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "src/tint/resolver/resolver_test_helper.h"
#include "src/tint/sem/test_helper.h"
#include "src/tint/type/test_helper.h"
namespace tint::resolver {

View File

@@ -136,7 +136,7 @@ INSTANTIATE_TEST_SUITE_P(ResolverTest, ResolverInferredTypeParamTest, testing::V
TEST_F(ResolverInferredTypeTest, InferArray_Pass) {
auto* type = ty.array(ty.u32(), 10_u);
auto* expected_type = create<sem::Array>(
create<sem::U32>(), create<sem::ConstantArrayCount>(10u), 4u, 4u * 10u, 4u, 4u);
create<sem::U32>(), create<type::ConstantArrayCount>(10u), 4u, 4u * 10u, 4u, 4u);
auto* ctor_expr = Construct(type);
auto* var = Var("a", ast::AddressSpace::kFunction, ctor_expr);

View File

@@ -55,14 +55,14 @@ constexpr static const size_t kNumFixedParams = 8;
constexpr static const size_t kNumFixedCandidates = 8;
/// A special type that matches all TypeMatchers
class Any final : public Castable<Any, sem::Type> {
class Any final : public Castable<Any, type::Type> {
public:
Any() : Base(sem::TypeFlags{}) {}
Any() : Base(type::TypeFlags{}) {}
~Any() override = default;
// Stub implementations for sem::Type conformance.
// Stub implementations for type::Type conformance.
size_t Hash() const override { return 0; }
bool Equals(const sem::Type&) const override { return false; }
bool Equals(const type::Type&) const override { return false; }
std::string FriendlyName(const SymbolTable&) const override { return "<any>"; }
};
@@ -122,7 +122,7 @@ class TemplateState {
/// template type is replaced with `ty`, and `ty` is returned.
/// If none of the above applies, then `ty` is a type mismatch for the template type, and
/// nullptr is returned.
const sem::Type* Type(size_t idx, const sem::Type* ty) {
const type::Type* Type(size_t idx, const type::Type* ty) {
if (idx >= types_.Length()) {
types_.Resize(idx + 1);
}
@@ -131,7 +131,7 @@ class TemplateState {
t = ty;
return ty;
}
ty = sem::Type::Common(utils::Vector{t, ty});
ty = type::Type::Common(utils::Vector{t, ty});
if (ty) {
t = ty;
}
@@ -154,7 +154,7 @@ class TemplateState {
}
/// Type returns the template type with index `idx`, or nullptr if the type was not defined.
const sem::Type* Type(size_t idx) const {
const type::Type* Type(size_t idx) const {
if (idx >= types_.Length()) {
return nullptr;
}
@@ -162,7 +162,7 @@ class TemplateState {
}
/// SetType replaces the template type with index `idx` with type `ty`.
void SetType(size_t idx, const sem::Type* ty) {
void SetType(size_t idx, const type::Type* ty) {
if (idx >= types_.Length()) {
types_.Resize(idx + 1);
}
@@ -178,7 +178,7 @@ class TemplateState {
}
private:
utils::Vector<const sem::Type*, 4> types_;
utils::Vector<const type::Type*, 4> types_;
utils::Vector<Number, 2> numbers_;
};
@@ -219,7 +219,7 @@ class MatchState {
/// `ty`. If the type matches, the canonical expected type is returned. If the
/// type `ty` does not match, then nullptr is returned.
/// @note: The matcher indices are progressed on calling.
const sem::Type* Type(const sem::Type* ty);
const type::Type* Type(const type::Type* ty);
/// Num uses the next NumMatcher from the matcher indices to match the number
/// `num`. If the number matches, the canonical expected number is returned.
@@ -253,7 +253,7 @@ class TypeMatcher {
/// Match may define and refine the template types and numbers in state.
/// @param type the type to match
/// @returns the canonicalized type on match, otherwise nullptr
virtual const sem::Type* Match(MatchState& state, const sem::Type* type) const = 0;
virtual const type::Type* Match(MatchState& state, const type::Type* type) const = 0;
/// @return a string representation of the matcher. Used for printing error
/// messages when no overload is found.
@@ -286,7 +286,7 @@ class TemplateTypeMatcher : public TypeMatcher {
/// Constructor
explicit TemplateTypeMatcher(size_t index) : index_(index) {}
const sem::Type* Match(MatchState& state, const sem::Type* type) const override {
const type::Type* Match(MatchState& state, const type::Type* type) const override {
if (type->Is<Any>()) {
return state.templates.Type(index_);
}
@@ -348,7 +348,7 @@ enum class OverloadFlag {
// An enum set of OverloadFlag, used by OperatorInfo
using OverloadFlags = utils::EnumSet<OverloadFlag>;
bool match_bool(MatchState&, const sem::Type* ty) {
bool match_bool(MatchState&, const type::Type* ty) {
return ty->IsAnyOf<Any, sem::Bool>();
}
@@ -356,7 +356,7 @@ const sem::AbstractFloat* build_fa(MatchState& state) {
return state.builder.create<sem::AbstractFloat>();
}
bool match_fa(MatchState& state, const sem::Type* ty) {
bool match_fa(MatchState& state, const type::Type* ty) {
return (state.earliest_eval_stage == sem::EvaluationStage::kConstant) &&
ty->IsAnyOf<Any, sem::AbstractNumeric>();
}
@@ -365,7 +365,7 @@ const sem::AbstractInt* build_ia(MatchState& state) {
return state.builder.create<sem::AbstractInt>();
}
bool match_ia(MatchState& state, const sem::Type* ty) {
bool match_ia(MatchState& state, const type::Type* ty) {
return (state.earliest_eval_stage == sem::EvaluationStage::kConstant) &&
ty->IsAnyOf<Any, sem::AbstractInt>();
}
@@ -378,7 +378,7 @@ const sem::F16* build_f16(MatchState& state) {
return state.builder.create<sem::F16>();
}
bool match_f16(MatchState&, const sem::Type* ty) {
bool match_f16(MatchState&, const type::Type* ty) {
return ty->IsAnyOf<Any, sem::F16, sem::AbstractNumeric>();
}
@@ -386,7 +386,7 @@ const sem::F32* build_f32(MatchState& state) {
return state.builder.create<sem::F32>();
}
bool match_f32(MatchState&, const sem::Type* ty) {
bool match_f32(MatchState&, const type::Type* ty) {
return ty->IsAnyOf<Any, sem::F32, sem::AbstractNumeric>();
}
@@ -394,7 +394,7 @@ const sem::I32* build_i32(MatchState& state) {
return state.builder.create<sem::I32>();
}
bool match_i32(MatchState&, const sem::Type* ty) {
bool match_i32(MatchState&, const type::Type* ty) {
return ty->IsAnyOf<Any, sem::I32, sem::AbstractInt>();
}
@@ -402,11 +402,11 @@ const sem::U32* build_u32(MatchState& state) {
return state.builder.create<sem::U32>();
}
bool match_u32(MatchState&, const sem::Type* ty) {
bool match_u32(MatchState&, const type::Type* ty) {
return ty->IsAnyOf<Any, sem::U32, sem::AbstractInt>();
}
bool match_vec(MatchState&, const sem::Type* ty, Number& N, const sem::Type*& T) {
bool match_vec(MatchState&, const type::Type* ty, Number& N, const type::Type*& T) {
if (ty->Is<Any>()) {
N = Number::any;
T = ty;
@@ -422,7 +422,7 @@ bool match_vec(MatchState&, const sem::Type* ty, Number& N, const sem::Type*& T)
}
template <uint32_t N>
bool match_vec(MatchState&, const sem::Type* ty, const sem::Type*& T) {
bool match_vec(MatchState&, const type::Type* ty, const type::Type*& T) {
if (ty->Is<Any>()) {
T = ty;
return true;
@@ -437,12 +437,12 @@ bool match_vec(MatchState&, const sem::Type* ty, const sem::Type*& T) {
return false;
}
const sem::Vector* build_vec(MatchState& state, Number N, const sem::Type* el) {
const sem::Vector* build_vec(MatchState& state, Number N, const type::Type* el) {
return state.builder.create<sem::Vector>(el, N.Value());
}
template <uint32_t N>
const sem::Vector* build_vec(MatchState& state, const sem::Type* el) {
const sem::Vector* build_vec(MatchState& state, const type::Type* el) {
return state.builder.create<sem::Vector>(el, N);
}
@@ -454,7 +454,7 @@ constexpr auto build_vec2 = build_vec<2>;
constexpr auto build_vec3 = build_vec<3>;
constexpr auto build_vec4 = build_vec<4>;
bool match_mat(MatchState&, const sem::Type* ty, Number& M, Number& N, const sem::Type*& T) {
bool match_mat(MatchState&, const type::Type* ty, Number& M, Number& N, const type::Type*& T) {
if (ty->Is<Any>()) {
M = Number::any;
N = Number::any;
@@ -471,7 +471,7 @@ bool match_mat(MatchState&, const sem::Type* ty, Number& M, Number& N, const sem
}
template <uint32_t C, uint32_t R>
bool match_mat(MatchState&, const sem::Type* ty, const sem::Type*& T) {
bool match_mat(MatchState&, const type::Type* ty, const type::Type*& T) {
if (ty->Is<Any>()) {
T = ty;
return true;
@@ -485,13 +485,13 @@ bool match_mat(MatchState&, const sem::Type* ty, const sem::Type*& T) {
return false;
}
const sem::Matrix* build_mat(MatchState& state, Number C, Number R, const sem::Type* T) {
const sem::Matrix* build_mat(MatchState& state, Number C, Number R, const type::Type* T) {
auto* column_type = state.builder.create<sem::Vector>(T, R.Value());
return state.builder.create<sem::Matrix>(column_type, C.Value());
}
template <uint32_t C, uint32_t R>
const sem::Matrix* build_mat(MatchState& state, const sem::Type* T) {
const sem::Matrix* build_mat(MatchState& state, const type::Type* T) {
auto* column_type = state.builder.create<sem::Vector>(T, R);
return state.builder.create<sem::Matrix>(column_type, C);
}
@@ -516,14 +516,14 @@ constexpr auto match_mat4x2 = match_mat<4, 2>;
constexpr auto match_mat4x3 = match_mat<4, 3>;
constexpr auto match_mat4x4 = match_mat<4, 4>;
bool match_array(MatchState&, const sem::Type* ty, const sem::Type*& T) {
bool match_array(MatchState&, const type::Type* ty, const type::Type*& T) {
if (ty->Is<Any>()) {
T = ty;
return true;
}
if (auto* a = ty->As<sem::Array>()) {
if (a->Count()->Is<sem::RuntimeArrayCount>()) {
if (a->Count()->Is<type::RuntimeArrayCount>()) {
T = a->ElemType();
return true;
}
@@ -531,17 +531,17 @@ bool match_array(MatchState&, const sem::Type* ty, const sem::Type*& T) {
return false;
}
const sem::Array* build_array(MatchState& state, const sem::Type* el) {
const sem::Array* build_array(MatchState& state, const type::Type* el) {
return state.builder.create<sem::Array>(
el,
/* count */ state.builder.create<sem::RuntimeArrayCount>(),
/* count */ state.builder.create<type::RuntimeArrayCount>(),
/* align */ 0u,
/* size */ 0u,
/* stride */ 0u,
/* stride_implicit */ 0u);
}
bool match_ptr(MatchState&, const sem::Type* ty, Number& S, const sem::Type*& T, Number& A) {
bool match_ptr(MatchState&, const type::Type* ty, Number& S, const type::Type*& T, Number& A) {
if (ty->Is<Any>()) {
S = Number::any;
T = ty;
@@ -558,12 +558,12 @@ bool match_ptr(MatchState&, const sem::Type* ty, Number& S, const sem::Type*& T,
return false;
}
const sem::Pointer* build_ptr(MatchState& state, Number S, const sem::Type* T, Number& A) {
const sem::Pointer* build_ptr(MatchState& state, Number S, const type::Type* T, Number& A) {
return state.builder.create<sem::Pointer>(T, static_cast<ast::AddressSpace>(S.Value()),
static_cast<ast::Access>(A.Value()));
}
bool match_atomic(MatchState&, const sem::Type* ty, const sem::Type*& T) {
bool match_atomic(MatchState&, const type::Type* ty, const type::Type*& T) {
if (ty->Is<Any>()) {
T = ty;
return true;
@@ -576,11 +576,11 @@ bool match_atomic(MatchState&, const sem::Type* ty, const sem::Type*& T) {
return false;
}
const sem::Atomic* build_atomic(MatchState& state, const sem::Type* T) {
const sem::Atomic* build_atomic(MatchState& state, const type::Type* T) {
return state.builder.create<sem::Atomic>(T);
}
bool match_sampler(MatchState&, const sem::Type* ty) {
bool match_sampler(MatchState&, const type::Type* ty) {
if (ty->Is<Any>()) {
return true;
}
@@ -591,7 +591,7 @@ const sem::Sampler* build_sampler(MatchState& state) {
return state.builder.create<sem::Sampler>(ast::SamplerKind::kSampler);
}
bool match_sampler_comparison(MatchState&, const sem::Type* ty) {
bool match_sampler_comparison(MatchState&, const type::Type* ty) {
if (ty->Is<Any>()) {
return true;
}
@@ -604,9 +604,9 @@ const sem::Sampler* build_sampler_comparison(MatchState& state) {
}
bool match_texture(MatchState&,
const sem::Type* ty,
const type::Type* ty,
ast::TextureDimension dim,
const sem::Type*& T) {
const type::Type*& T) {
if (ty->Is<Any>()) {
T = ty;
return true;
@@ -622,14 +622,14 @@ bool match_texture(MatchState&,
#define JOIN(a, b) a##b
#define DECLARE_SAMPLED_TEXTURE(suffix, dim) \
bool JOIN(match_texture_, suffix)(MatchState & state, const sem::Type* ty, \
const sem::Type*& T) { \
return match_texture(state, ty, dim, T); \
} \
const sem::SampledTexture* JOIN(build_texture_, suffix)(MatchState & state, \
const sem::Type* T) { \
return state.builder.create<sem::SampledTexture>(dim, T); \
#define DECLARE_SAMPLED_TEXTURE(suffix, dim) \
bool JOIN(match_texture_, suffix)(MatchState & state, const type::Type* ty, \
const type::Type*& T) { \
return match_texture(state, ty, dim, T); \
} \
const sem::SampledTexture* JOIN(build_texture_, suffix)(MatchState & state, \
const type::Type* T) { \
return state.builder.create<sem::SampledTexture>(dim, T); \
}
DECLARE_SAMPLED_TEXTURE(1d, ast::TextureDimension::k1d)
@@ -641,9 +641,9 @@ DECLARE_SAMPLED_TEXTURE(cube_array, ast::TextureDimension::kCubeArray)
#undef DECLARE_SAMPLED_TEXTURE
bool match_texture_multisampled(MatchState&,
const sem::Type* ty,
const type::Type* ty,
ast::TextureDimension dim,
const sem::Type*& T) {
const type::Type*& T) {
if (ty->Is<Any>()) {
T = ty;
return true;
@@ -657,32 +657,32 @@ bool match_texture_multisampled(MatchState&,
return false;
}
#define DECLARE_MULTISAMPLED_TEXTURE(suffix, dim) \
bool JOIN(match_texture_multisampled_, suffix)(MatchState & state, const sem::Type* ty, \
const sem::Type*& T) { \
return match_texture_multisampled(state, ty, dim, T); \
} \
const sem::MultisampledTexture* JOIN(build_texture_multisampled_, suffix)( \
MatchState & state, const sem::Type* T) { \
return state.builder.create<sem::MultisampledTexture>(dim, T); \
#define DECLARE_MULTISAMPLED_TEXTURE(suffix, dim) \
bool JOIN(match_texture_multisampled_, suffix)(MatchState & state, const type::Type* ty, \
const type::Type*& T) { \
return match_texture_multisampled(state, ty, dim, T); \
} \
const sem::MultisampledTexture* JOIN(build_texture_multisampled_, suffix)( \
MatchState & state, const type::Type* T) { \
return state.builder.create<sem::MultisampledTexture>(dim, T); \
}
DECLARE_MULTISAMPLED_TEXTURE(2d, ast::TextureDimension::k2d)
#undef DECLARE_MULTISAMPLED_TEXTURE
bool match_texture_depth(MatchState&, const sem::Type* ty, ast::TextureDimension dim) {
bool match_texture_depth(MatchState&, const type::Type* ty, ast::TextureDimension dim) {
if (ty->Is<Any>()) {
return true;
}
return ty->Is([&](const sem::DepthTexture* t) { return t->dim() == dim; });
}
#define DECLARE_DEPTH_TEXTURE(suffix, dim) \
bool JOIN(match_texture_depth_, suffix)(MatchState & state, const sem::Type* ty) { \
return match_texture_depth(state, ty, dim); \
} \
const sem::DepthTexture* JOIN(build_texture_depth_, suffix)(MatchState & state) { \
return state.builder.create<sem::DepthTexture>(dim); \
#define DECLARE_DEPTH_TEXTURE(suffix, dim) \
bool JOIN(match_texture_depth_, suffix)(MatchState & state, const type::Type* ty) { \
return match_texture_depth(state, ty, dim); \
} \
const sem::DepthTexture* JOIN(build_texture_depth_, suffix)(MatchState & state) { \
return state.builder.create<sem::DepthTexture>(dim); \
}
DECLARE_DEPTH_TEXTURE(2d, ast::TextureDimension::k2d)
@@ -691,7 +691,7 @@ DECLARE_DEPTH_TEXTURE(cube, ast::TextureDimension::kCube)
DECLARE_DEPTH_TEXTURE(cube_array, ast::TextureDimension::kCubeArray)
#undef DECLARE_DEPTH_TEXTURE
bool match_texture_depth_multisampled_2d(MatchState&, const sem::Type* ty) {
bool match_texture_depth_multisampled_2d(MatchState&, const type::Type* ty) {
if (ty->Is<Any>()) {
return true;
}
@@ -705,7 +705,7 @@ sem::DepthMultisampledTexture* build_texture_depth_multisampled_2d(MatchState& s
}
bool match_texture_storage(MatchState&,
const sem::Type* ty,
const type::Type* ty,
ast::TextureDimension dim,
Number& F,
Number& A) {
@@ -724,17 +724,17 @@ bool match_texture_storage(MatchState&,
return false;
}
#define DECLARE_STORAGE_TEXTURE(suffix, dim) \
bool JOIN(match_texture_storage_, suffix)(MatchState & state, const sem::Type* ty, Number& F, \
Number& A) { \
return match_texture_storage(state, ty, dim, F, A); \
} \
const sem::StorageTexture* JOIN(build_texture_storage_, suffix)(MatchState & state, Number F, \
Number A) { \
auto format = static_cast<TexelFormat>(F.Value()); \
auto access = static_cast<Access>(A.Value()); \
auto* T = sem::StorageTexture::SubtypeFor(format, state.builder.Types()); \
return state.builder.create<sem::StorageTexture>(dim, format, access, T); \
#define DECLARE_STORAGE_TEXTURE(suffix, dim) \
bool JOIN(match_texture_storage_, suffix)(MatchState & state, const type::Type* ty, Number& F, \
Number& A) { \
return match_texture_storage(state, ty, dim, F, A); \
} \
const sem::StorageTexture* JOIN(build_texture_storage_, suffix)(MatchState & state, Number F, \
Number A) { \
auto format = static_cast<TexelFormat>(F.Value()); \
auto access = static_cast<Access>(A.Value()); \
auto* T = sem::StorageTexture::SubtypeFor(format, state.builder.Types()); \
return state.builder.create<sem::StorageTexture>(dim, format, access, T); \
}
DECLARE_STORAGE_TEXTURE(1d, ast::TextureDimension::k1d)
@@ -743,7 +743,7 @@ DECLARE_STORAGE_TEXTURE(2d_array, ast::TextureDimension::k2dArray)
DECLARE_STORAGE_TEXTURE(3d, ast::TextureDimension::k3d)
#undef DECLARE_STORAGE_TEXTURE
bool match_texture_external(MatchState&, const sem::Type* ty) {
bool match_texture_external(MatchState&, const type::Type* ty) {
return ty->IsAnyOf<Any, sem::ExternalTexture>();
}
@@ -754,14 +754,14 @@ const sem::ExternalTexture* build_texture_external(MatchState& state) {
// Builtin types starting with a _ prefix cannot be declared in WGSL, so they
// can only be used as return types. Because of this, they must only match Any,
// which is used as the return type matcher.
bool match_modf_result(MatchState&, const sem::Type* ty, const sem::Type*& T) {
bool match_modf_result(MatchState&, const type::Type* ty, const type::Type*& T) {
if (!ty->Is<Any>()) {
return false;
}
T = ty;
return true;
}
bool match_modf_result_vec(MatchState&, const sem::Type* ty, Number& N, const sem::Type*& T) {
bool match_modf_result_vec(MatchState&, const type::Type* ty, Number& N, const type::Type*& T) {
if (!ty->Is<Any>()) {
return false;
}
@@ -769,14 +769,14 @@ bool match_modf_result_vec(MatchState&, const sem::Type* ty, Number& N, const se
T = ty;
return true;
}
bool match_frexp_result(MatchState&, const sem::Type* ty, const sem::Type*& T) {
bool match_frexp_result(MatchState&, const type::Type* ty, const type::Type*& T) {
if (!ty->Is<Any>()) {
return false;
}
T = ty;
return true;
}
bool match_frexp_result_vec(MatchState&, const sem::Type* ty, Number& N, const sem::Type*& T) {
bool match_frexp_result_vec(MatchState&, const type::Type* ty, Number& N, const type::Type*& T) {
if (!ty->Is<Any>()) {
return false;
}
@@ -785,7 +785,7 @@ bool match_frexp_result_vec(MatchState&, const sem::Type* ty, Number& N, const s
return true;
}
bool match_atomic_compare_exchange_result(MatchState&, const sem::Type* ty, const sem::Type*& T) {
bool match_atomic_compare_exchange_result(MatchState&, const type::Type* ty, const type::Type*& T) {
if (ty->Is<Any>()) {
T = ty;
return true;
@@ -795,7 +795,7 @@ bool match_atomic_compare_exchange_result(MatchState&, const sem::Type* ty, cons
struct NameAndType {
std::string name;
const sem::Type* type;
const type::Type* type;
};
sem::Struct* build_struct(ProgramBuilder& b,
std::string name,
@@ -832,7 +832,7 @@ sem::Struct* build_struct(ProgramBuilder& b,
/* size_no_padding */ size_without_padding);
}
const sem::Struct* build_modf_result(MatchState& state, const sem::Type* el) {
const sem::Struct* build_modf_result(MatchState& state, const type::Type* el) {
auto build_f32 = [&] {
auto* ty = state.builder.create<sem::F32>();
return build_struct(state.builder, "__modf_result_f32", {{"fract", ty}, {"whole", ty}});
@@ -859,7 +859,7 @@ const sem::Struct* build_modf_result(MatchState& state, const sem::Type* el) {
});
}
const sem::Struct* build_modf_result_vec(MatchState& state, Number& n, const sem::Type* el) {
const sem::Struct* build_modf_result_vec(MatchState& state, Number& n, const type::Type* el) {
auto prefix = "__modf_result_vec" + std::to_string(n.Value());
auto build_f32 = [&] {
auto* vec = state.builder.create<sem::Vector>(state.builder.create<sem::F32>(), n.Value());
@@ -888,7 +888,7 @@ const sem::Struct* build_modf_result_vec(MatchState& state, Number& n, const sem
});
}
const sem::Struct* build_frexp_result(MatchState& state, const sem::Type* el) {
const sem::Struct* build_frexp_result(MatchState& state, const type::Type* el) {
auto build_f32 = [&] {
auto* f = state.builder.create<sem::F32>();
auto* i = state.builder.create<sem::I32>();
@@ -918,7 +918,7 @@ const sem::Struct* build_frexp_result(MatchState& state, const sem::Type* el) {
});
}
const sem::Struct* build_frexp_result_vec(MatchState& state, Number& n, const sem::Type* el) {
const sem::Struct* build_frexp_result_vec(MatchState& state, Number& n, const type::Type* el) {
auto prefix = "__frexp_result_vec" + std::to_string(n.Value());
auto build_f32 = [&] {
auto* f = state.builder.create<sem::Vector>(state.builder.create<sem::F32>(), n.Value());
@@ -951,11 +951,11 @@ const sem::Struct* build_frexp_result_vec(MatchState& state, Number& n, const se
});
}
const sem::Struct* build_atomic_compare_exchange_result(MatchState& state, const sem::Type* ty) {
const sem::Struct* build_atomic_compare_exchange_result(MatchState& state, const type::Type* ty) {
return build_struct(
state.builder,
"__atomic_compare_exchange_result" + ty->FriendlyName(state.builder.Symbols()),
{{"old_value", const_cast<sem::Type*>(ty)},
{{"old_value", const_cast<type::Type*>(ty)},
{"exchanged", state.builder.create<sem::Bool>()}});
}
@@ -1028,7 +1028,7 @@ struct IntrinsicPrototype {
/// Parameter describes a single parameter
struct Parameter {
/// Parameter type
const sem::Type* const type;
const type::Type* const type;
/// Parameter usage
ParameterUsage const usage = ParameterUsage::kNone;
};
@@ -1047,7 +1047,7 @@ struct IntrinsicPrototype {
};
const OverloadInfo* overload = nullptr;
sem::Type const* return_type = nullptr;
type::Type const* return_type = nullptr;
utils::Vector<Parameter, kNumFixedParams> parameters;
};
@@ -1073,25 +1073,25 @@ class Impl : public IntrinsicTable {
explicit Impl(ProgramBuilder& builder);
Builtin Lookup(sem::BuiltinType builtin_type,
utils::VectorRef<const sem::Type*> args,
utils::VectorRef<const type::Type*> args,
sem::EvaluationStage earliest_eval_stage,
const Source& source) override;
UnaryOperator Lookup(ast::UnaryOp op,
const sem::Type* arg,
const type::Type* arg,
sem::EvaluationStage earliest_eval_stage,
const Source& source) override;
BinaryOperator Lookup(ast::BinaryOp op,
const sem::Type* lhs,
const sem::Type* rhs,
const type::Type* lhs,
const type::Type* rhs,
sem::EvaluationStage earliest_eval_stage,
const Source& source,
bool is_compound) override;
InitOrConv Lookup(InitConvIntrinsic type,
const sem::Type* template_arg,
utils::VectorRef<const sem::Type*> args,
const type::Type* template_arg,
utils::VectorRef<const type::Type*> args,
sem::EvaluationStage earliest_eval_stage,
const Source& source) override;
@@ -1137,7 +1137,7 @@ class Impl : public IntrinsicTable {
/// IntrinsicPrototype::return_type.
IntrinsicPrototype MatchIntrinsic(const IntrinsicInfo& intrinsic,
const char* intrinsic_name,
utils::VectorRef<const sem::Type*> args,
utils::VectorRef<const type::Type*> args,
sem::EvaluationStage earliest_eval_stage,
TemplateState templates,
OnNoMatch on_no_match) const;
@@ -1150,7 +1150,7 @@ class Impl : public IntrinsicTable {
/// template as `f32`.
/// @returns the evaluated Candidate information.
Candidate ScoreOverload(const OverloadInfo* overload,
utils::VectorRef<const sem::Type*> args,
utils::VectorRef<const type::Type*> args,
sem::EvaluationStage earliest_eval_stage,
TemplateState templates) const;
@@ -1166,7 +1166,7 @@ class Impl : public IntrinsicTable {
/// @returns the resolved Candidate.
Candidate ResolveCandidate(Candidates&& candidates,
const char* intrinsic_name,
utils::VectorRef<const sem::Type*> args,
utils::VectorRef<const type::Type*> args,
TemplateState templates) const;
/// Match constructs a new MatchState
@@ -1190,7 +1190,7 @@ class Impl : public IntrinsicTable {
/// Raises an error when no overload is a clear winner of overload resolution
void ErrAmbiguousOverload(const char* intrinsic_name,
utils::VectorRef<const sem::Type*> args,
utils::VectorRef<const type::Type*> args,
TemplateState templates,
utils::VectorRef<Candidate> candidates) const;
@@ -1207,8 +1207,8 @@ class Impl : public IntrinsicTable {
/// types.
std::string CallSignature(ProgramBuilder& builder,
const char* intrinsic_name,
utils::VectorRef<const sem::Type*> args,
const sem::Type* template_arg = nullptr) {
utils::VectorRef<const type::Type*> args,
const type::Type* template_arg = nullptr) {
std::stringstream ss;
ss << intrinsic_name;
if (template_arg) {
@@ -1241,7 +1241,7 @@ std::string TemplateNumberMatcher::String(MatchState* state) const {
Impl::Impl(ProgramBuilder& b) : builder(b) {}
Impl::Builtin Impl::Lookup(sem::BuiltinType builtin_type,
utils::VectorRef<const sem::Type*> args,
utils::VectorRef<const type::Type*> args,
sem::EvaluationStage earliest_eval_stage,
const Source& source) {
const char* intrinsic_name = sem::str(builtin_type);
@@ -1295,7 +1295,7 @@ Impl::Builtin Impl::Lookup(sem::BuiltinType builtin_type,
}
IntrinsicTable::UnaryOperator Impl::Lookup(ast::UnaryOp op,
const sem::Type* arg,
const type::Type* arg,
sem::EvaluationStage earliest_eval_stage,
const Source& source) {
auto [intrinsic_index, intrinsic_name] = [&]() -> std::pair<size_t, const char*> {
@@ -1341,8 +1341,8 @@ IntrinsicTable::UnaryOperator Impl::Lookup(ast::UnaryOp op,
}
IntrinsicTable::BinaryOperator Impl::Lookup(ast::BinaryOp op,
const sem::Type* lhs,
const sem::Type* rhs,
const type::Type* lhs,
const type::Type* rhs,
sem::EvaluationStage earliest_eval_stage,
const Source& source,
bool is_compound) {
@@ -1420,8 +1420,8 @@ IntrinsicTable::BinaryOperator Impl::Lookup(ast::BinaryOp op,
}
IntrinsicTable::InitOrConv Impl::Lookup(InitConvIntrinsic type,
const sem::Type* template_arg,
utils::VectorRef<const sem::Type*> args,
const type::Type* template_arg,
utils::VectorRef<const type::Type*> args,
sem::EvaluationStage earliest_eval_stage,
const Source& source) {
auto name = str(type);
@@ -1499,7 +1499,7 @@ IntrinsicTable::InitOrConv Impl::Lookup(InitConvIntrinsic type,
IntrinsicPrototype Impl::MatchIntrinsic(const IntrinsicInfo& intrinsic,
const char* intrinsic_name,
utils::VectorRef<const sem::Type*> args,
utils::VectorRef<const type::Type*> args,
sem::EvaluationStage earliest_eval_stage,
TemplateState templates,
OnNoMatch on_no_match) const {
@@ -1539,7 +1539,7 @@ IntrinsicPrototype Impl::MatchIntrinsic(const IntrinsicInfo& intrinsic,
}
// Build the return type
const sem::Type* return_type = nullptr;
const type::Type* return_type = nullptr;
if (auto* indices = match.overload->return_matcher_indices) {
Any any;
return_type =
@@ -1556,7 +1556,7 @@ IntrinsicPrototype Impl::MatchIntrinsic(const IntrinsicInfo& intrinsic,
}
Impl::Candidate Impl::ScoreOverload(const OverloadInfo* overload,
utils::VectorRef<const sem::Type*> args,
utils::VectorRef<const type::Type*> args,
sem::EvaluationStage earliest_eval_stage,
TemplateState templates) const {
// Penalty weights for overload mismatching.
@@ -1656,7 +1656,7 @@ Impl::Candidate Impl::ScoreOverload(const OverloadInfo* overload,
Impl::Candidate Impl::ResolveCandidate(Impl::Candidates&& candidates,
const char* intrinsic_name,
utils::VectorRef<const sem::Type*> args,
utils::VectorRef<const type::Type*> args,
TemplateState templates) const {
utils::Vector<uint32_t, kNumFixedParams> best_ranks;
best_ranks.Resize(args.Length(), 0xffffffff);
@@ -1669,7 +1669,7 @@ Impl::Candidate Impl::ResolveCandidate(Impl::Candidates&& candidates,
bool some_won = false; // An argument ranked less than the 'best' overload's argument
bool some_lost = false; // An argument ranked more than the 'best' overload's argument
for (size_t i = 0; i < args.Length(); i++) {
auto rank = sem::Type::ConversionRank(args[i], candidate.parameters[i].type);
auto rank = type::Type::ConversionRank(args[i], candidate.parameters[i].type);
if (best_ranks[i] > rank) {
best_ranks[i] = rank;
some_won = true;
@@ -1808,7 +1808,7 @@ void Impl::PrintCandidates(std::ostream& ss,
}
}
const sem::Type* MatchState::Type(const sem::Type* ty) {
const type::Type* MatchState::Type(const type::Type* ty) {
MatcherIndex matcher_index = *matcher_indices_++;
auto* matcher = matchers.type[matcher_index];
return matcher->Match(*this, ty);
@@ -1833,7 +1833,7 @@ std::string MatchState::NumName() {
}
void Impl::ErrAmbiguousOverload(const char* intrinsic_name,
utils::VectorRef<const sem::Type*> args,
utils::VectorRef<const type::Type*> args,
TemplateState templates,
utils::VectorRef<Candidate> candidates) const {
std::stringstream ss;

View File

@@ -53,9 +53,9 @@ class IntrinsicTable {
/// UnaryOperator describes a resolved unary operator
struct UnaryOperator {
/// The result type of the unary operator
const sem::Type* result = nullptr;
const type::Type* result = nullptr;
/// The type of the parameter of the unary operator
const sem::Type* parameter = nullptr;
const type::Type* parameter = nullptr;
/// The constant evaluation function
ConstEval::Function const_eval_fn = nullptr;
};
@@ -63,11 +63,11 @@ class IntrinsicTable {
/// BinaryOperator describes a resolved binary operator
struct BinaryOperator {
/// The result type of the binary operator
const sem::Type* result = nullptr;
const type::Type* result = nullptr;
/// The type of LHS parameter of the binary operator
const sem::Type* lhs = nullptr;
const type::Type* lhs = nullptr;
/// The type of RHS parameter of the binary operator
const sem::Type* rhs = nullptr;
const type::Type* rhs = nullptr;
/// The constant evaluation function
ConstEval::Function const_eval_fn = nullptr;
};
@@ -93,7 +93,7 @@ class IntrinsicTable {
/// @param source the source of the builtin call
/// @return the semantic builtin if found, otherwise nullptr
virtual Builtin Lookup(sem::BuiltinType type,
utils::VectorRef<const sem::Type*> args,
utils::VectorRef<const type::Type*> args,
sem::EvaluationStage earliest_eval_stage,
const Source& source) = 0;
@@ -111,7 +111,7 @@ class IntrinsicTable {
/// @return the operator call target signature. If the operator was not found
/// UnaryOperator::result will be nullptr.
virtual UnaryOperator Lookup(ast::UnaryOp op,
const sem::Type* arg,
const type::Type* arg,
sem::EvaluationStage earliest_eval_stage,
const Source& source) = 0;
@@ -131,8 +131,8 @@ class IntrinsicTable {
/// @return the operator call target signature. If the operator was not found
/// BinaryOperator::result will be nullptr.
virtual BinaryOperator Lookup(ast::BinaryOp op,
const sem::Type* lhs,
const sem::Type* rhs,
const type::Type* lhs,
const type::Type* rhs,
sem::EvaluationStage earliest_eval_stage,
const Source& source,
bool is_compound) = 0;
@@ -151,8 +151,8 @@ class IntrinsicTable {
/// @param source the source of the call
/// @return a sem::TypeInitializer, sem::TypeConversion or nullptr if nothing matched
virtual InitOrConv Lookup(InitConvIntrinsic type,
const sem::Type* template_arg,
utils::VectorRef<const sem::Type*> args,
const type::Type* template_arg,
utils::VectorRef<const type::Type*> args,
sem::EvaluationStage earliest_eval_stage,
const Source& source) = 0;
};

File diff suppressed because it is too large Load Diff

View File

@@ -190,14 +190,14 @@ class {{$class}} : public TypeMatcher {
/// @param state the MatchState
/// @param type the type to match
/// @returns the canonicalized type on match, otherwise nullptr
const sem::Type* Match(MatchState& state,
const sem::Type* type) const override;
const type::Type* Match(MatchState& state,
const type::Type* type) const override;
/// @param state the MatchState
/// @return a string representation of the matcher.
std::string String(MatchState* state) const override;
};
const sem::Type* {{$class}}::Match(MatchState& state, const sem::Type* ty) const {
const type::Type* {{$class}}::Match(MatchState& state, const type::Type* ty) const {
{{- range .TemplateParams }}
{{- template "DeclareLocalTemplateParam" . }}
{{- end }}
@@ -245,14 +245,14 @@ class {{$class}} : public TypeMatcher {
/// @param state the MatchState
/// @param type the type to match
/// @returns the canonicalized type on match, otherwise nullptr
const sem::Type* Match(MatchState& state,
const sem::Type* type) const override;
const type::Type* Match(MatchState& state,
const type::Type* type) const override;
/// @param state the MatchState
/// @return a string representation of the matcher.
std::string String(MatchState* state) const override;
};
const sem::Type* {{$class}}::Match(MatchState& state, const sem::Type* ty) const {
const type::Type* {{$class}}::Match(MatchState& state, const type::Type* ty) const {
{{- range .PrecedenceSortedTypes }}
if (match_{{.Name}}(state, ty)) {
return build_{{.Name}}(state);
@@ -400,7 +400,7 @@ Matchers::~Matchers() = default;
{{- define "DeclareLocalTemplateParam" -}}
{{- /* ------------------------------------------------------------------ */ -}}
{{- if IsTemplateTypeParam . }}
const sem::Type* {{.Name}} = nullptr;
const type::Type* {{.Name}} = nullptr;
{{- else if IsTemplateNumberParam . }}
Number {{.Name}} = Number::invalid;
{{- else if IsTemplateEnumParam . }}

View File

@@ -27,9 +27,9 @@
#include "src/tint/sem/reference.h"
#include "src/tint/sem/sampled_texture.h"
#include "src/tint/sem/storage_texture.h"
#include "src/tint/sem/test_helper.h"
#include "src/tint/sem/type_conversion.h"
#include "src/tint/sem/type_initializer.h"
#include "src/tint/type/test_helper.h"
namespace tint::resolver {
namespace {
@@ -253,7 +253,7 @@ TEST_F(IntrinsicTableTest, MismatchPointer) {
TEST_F(IntrinsicTableTest, MatchArray) {
auto* arr =
create<sem::Array>(create<sem::U32>(), create<sem::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
create<sem::Array>(create<sem::U32>(), create<type::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
auto* arr_ptr = create<sem::Pointer>(arr, ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto result = table->Lookup(BuiltinType::kArrayLength, utils::Vector{arr_ptr},
sem::EvaluationStage::kConstant, Source{});
@@ -957,7 +957,7 @@ TEST_F(IntrinsicTableTest, MatchTypeConversion) {
TEST_F(IntrinsicTableTest, MismatchTypeConversion) {
auto* arr =
create<sem::Array>(create<sem::U32>(), create<sem::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
create<sem::Array>(create<sem::U32>(), create<type::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
auto* f32 = create<sem::F32>();
auto result = table->Lookup(InitConvIntrinsic::kVec3, f32, utils::Vector{arr},
sem::EvaluationStage::kConstant, Source{{12, 34}});
@@ -1017,7 +1017,7 @@ TEST_F(IntrinsicTableTest, MatchTypeConversion_RuntimeEval) {
TEST_F(IntrinsicTableTest, Err257Arguments) { // crbug.com/1323605
auto* f32 = create<sem::F32>();
utils::Vector<const sem::Type*, 0> arg_tys;
utils::Vector<const type::Type*, 0> arg_tys;
arg_tys.Resize(257, f32);
auto result = table->Lookup(BuiltinType::kAbs, std::move(arg_tys),
sem::EvaluationStage::kConstant, Source{});

View File

@@ -106,14 +106,14 @@ TEST_F(ResolverIsHostShareable, Atomic) {
}
TEST_F(ResolverIsHostShareable, ArraySizedOfHostShareable) {
auto* arr = create<sem::Array>(create<sem::I32>(), create<sem::ConstantArrayCount>(5u), 4u, 20u,
4u, 4u);
auto* arr = create<sem::Array>(create<sem::I32>(), create<type::ConstantArrayCount>(5u), 4u,
20u, 4u, 4u);
EXPECT_TRUE(r()->IsHostShareable(arr));
}
TEST_F(ResolverIsHostShareable, ArrayUnsizedOfHostShareable) {
auto* arr =
create<sem::Array>(create<sem::I32>(), create<sem::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
create<sem::Array>(create<sem::I32>(), create<type::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
EXPECT_TRUE(r()->IsHostShareable(arr));
}

View File

@@ -89,14 +89,14 @@ TEST_F(ResolverIsStorableTest, Atomic) {
}
TEST_F(ResolverIsStorableTest, ArraySizedOfStorable) {
auto* arr = create<sem::Array>(create<sem::I32>(), create<sem::ConstantArrayCount>(5u), 4u, 20u,
4u, 4u);
auto* arr = create<sem::Array>(create<sem::I32>(), create<type::ConstantArrayCount>(5u), 4u,
20u, 4u, 4u);
EXPECT_TRUE(r()->IsStorable(arr));
}
TEST_F(ResolverIsStorableTest, ArrayUnsizedOfStorable) {
auto* arr =
create<sem::Array>(create<sem::I32>(), create<sem::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
create<sem::Array>(create<sem::I32>(), create<type::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
EXPECT_TRUE(r()->IsStorable(arr));
}

View File

@@ -16,7 +16,7 @@
#include "src/tint/resolver/resolver.h"
#include "src/tint/resolver/resolver_test_helper.h"
#include "src/tint/sem/test_helper.h"
#include "src/tint/type/test_helper.h"
#include "gmock/gmock.h"
@@ -77,7 +77,7 @@ class MaterializeTest : public resolver::ResolverTestWithParam<CASE> {
using ProgramBuilder::FriendlyName;
void CheckTypesAndValues(const sem::Expression* expr,
const tint::sem::Type* expected_sem_ty,
const tint::type::Type* expected_sem_ty,
const std::variant<AInt, AFloat>& expected_value) {
std::visit([&](auto v) { CheckTypesAndValuesImpl(expr, expected_sem_ty, v); },
expected_value);
@@ -86,7 +86,7 @@ class MaterializeTest : public resolver::ResolverTestWithParam<CASE> {
private:
template <typename T>
void CheckTypesAndValuesImpl(const sem::Expression* expr,
const tint::sem::Type* expected_sem_ty,
const tint::type::Type* expected_sem_ty,
T expected_value) {
EXPECT_TYPE(expr->Type(), expected_sem_ty);

View File

@@ -199,7 +199,7 @@ bool Resolver::ResolveInternal() {
return result;
}
sem::Type* Resolver::Type(const ast::Type* ty) {
type::Type* Resolver::Type(const ast::Type* ty) {
Mark(ty);
auto* s = Switch(
ty, //
@@ -317,7 +317,7 @@ sem::Type* Resolver::Type(const ast::Type* ty) {
auto* resolved = sem_.ResolvedSymbol(ty);
return Switch(
resolved, //
[&](sem::Type* type) { return type; },
[&](type::Type* type) { return type; },
[&](sem::Variable* var) {
auto name = builder_->Symbols().NameFor(var->Declaration()->symbol);
AddError("cannot use variable '" + name + "' as type", ty->source);
@@ -330,7 +330,7 @@ sem::Type* Resolver::Type(const ast::Type* ty) {
AddNote("'" + name + "' declared here", func->Declaration()->source);
return nullptr;
},
[&](Default) -> sem::Type* {
[&](Default) -> type::Type* {
if (auto* tn = ty->As<ast::TypeName>()) {
if (IsBuiltin(tn->name)) {
auto name = builder_->Symbols().NameFor(tn->name);
@@ -371,7 +371,7 @@ sem::Variable* Resolver::Variable(const ast::Variable* v, bool is_global) {
}
sem::Variable* Resolver::Let(const ast::Let* v, bool is_global) {
const sem::Type* ty = nullptr;
const type::Type* ty = nullptr;
// If the variable has a declared type, resolve it.
if (v->type) {
@@ -402,7 +402,7 @@ sem::Variable* Resolver::Let(const ast::Let* v, bool is_global) {
return nullptr;
}
if (!ApplyAddressSpaceUsageToType(ast::AddressSpace::kNone, const_cast<sem::Type*>(ty),
if (!ApplyAddressSpaceUsageToType(ast::AddressSpace::kNone, const_cast<type::Type*>(ty),
v->source)) {
AddNote("while instantiating 'let' " + builder_->Symbols().NameFor(v->symbol), v->source);
return nullptr;
@@ -427,7 +427,7 @@ sem::Variable* Resolver::Let(const ast::Let* v, bool is_global) {
}
sem::Variable* Resolver::Override(const ast::Override* v) {
const sem::Type* ty = nullptr;
const type::Type* ty = nullptr;
// If the variable has a declared type, resolve it.
if (v->type) {
@@ -461,7 +461,7 @@ sem::Variable* Resolver::Override(const ast::Override* v) {
return nullptr;
}
if (!ApplyAddressSpaceUsageToType(ast::AddressSpace::kNone, const_cast<sem::Type*>(ty),
if (!ApplyAddressSpaceUsageToType(ast::AddressSpace::kNone, const_cast<type::Type*>(ty),
v->source)) {
AddNote("while instantiating 'override' " + builder_->Symbols().NameFor(v->symbol),
v->source);
@@ -511,7 +511,7 @@ sem::Variable* Resolver::Override(const ast::Override* v) {
}
sem::Variable* Resolver::Const(const ast::Const* c, bool is_global) {
const sem::Type* ty = nullptr;
const type::Type* ty = nullptr;
// If the variable has a declared type, resolve it.
if (c->type) {
@@ -551,7 +551,7 @@ sem::Variable* Resolver::Const(const ast::Const* c, bool is_global) {
return nullptr;
}
if (!ApplyAddressSpaceUsageToType(ast::AddressSpace::kNone, const_cast<sem::Type*>(ty),
if (!ApplyAddressSpaceUsageToType(ast::AddressSpace::kNone, const_cast<type::Type*>(ty),
c->source)) {
AddNote("while instantiating 'const' " + builder_->Symbols().NameFor(c->symbol), c->source);
return nullptr;
@@ -571,7 +571,7 @@ sem::Variable* Resolver::Const(const ast::Const* c, bool is_global) {
}
sem::Variable* Resolver::Var(const ast::Var* var, bool is_global) {
const sem::Type* storage_ty = nullptr;
const type::Type* storage_ty = nullptr;
// If the variable has a declared type, resolve it.
if (auto* ty = var->type) {
@@ -738,7 +738,7 @@ sem::Parameter* Resolver::Parameter(const ast::Parameter* param, uint32_t index)
return nullptr;
}
sem::Type* ty = Type(param->type);
type::Type* ty = Type(param->type);
if (!ty) {
return nullptr;
}
@@ -752,7 +752,7 @@ sem::Parameter* Resolver::Parameter(const ast::Parameter* param, uint32_t index)
// For MSL, we push module-scope variables into the entry point as pointer
// parameters, so we also need to handle their store type.
if (!ApplyAddressSpaceUsageToType(
ptr->AddressSpace(), const_cast<sem::Type*>(ptr->StoreType()), param->source)) {
ptr->AddressSpace(), const_cast<type::Type*>(ptr->StoreType()), param->source)) {
add_note();
return nullptr;
}
@@ -887,10 +887,18 @@ bool Resolver::AllocateOverridableConstantIds() {
void Resolver::SetShadows() {
for (auto it : dependencies_.shadows) {
CastableBase* b = sem_.Get(it.value);
if (!b) {
TINT_ICE(Resolver, builder_->Diagnostics())
<< "AST node '" << it.value->TypeInfo().name << "' had no semantic info\n"
<< "At: " << it.value->source << "\n"
<< "Pointer: " << it.value;
}
Switch(
sem_.Get(it.key), //
[&](sem::LocalVariable* local) { local->SetShadows(sem_.Get(it.value)); },
[&](sem::Parameter* param) { param->SetShadows(sem_.Get(it.value)); });
[&](sem::LocalVariable* local) { local->SetShadows(b); },
[&](sem::Parameter* param) { param->SetShadows(b); });
}
}
@@ -984,7 +992,7 @@ sem::Function* Resolver::Function(const ast::Function* decl) {
parameters.Push(p);
auto* p_ty = const_cast<sem::Type*>(p->Type());
auto* p_ty = const_cast<type::Type*>(p->Type());
if (auto* str = p_ty->As<sem::Struct>()) {
switch (decl->PipelineStage()) {
case ast::PipelineStage::kVertex:
@@ -1003,7 +1011,7 @@ sem::Function* Resolver::Function(const ast::Function* decl) {
}
// Resolve the return type
sem::Type* return_type = nullptr;
type::Type* return_type = nullptr;
if (auto* ty = decl->return_type) {
return_type = Type(ty);
if (!return_type) {
@@ -1129,7 +1137,7 @@ bool Resolver::WorkgroupSize(const ast::Function* func) {
auto values = attr->Values();
utils::Vector<const sem::Expression*, 3> args;
utils::Vector<const sem::Type*, 3> arg_tys;
utils::Vector<const type::Type*, 3> arg_tys;
constexpr const char* kErrBadExpr =
"workgroup_size argument must be a constant or override-expression of type "
@@ -1162,7 +1170,7 @@ bool Resolver::WorkgroupSize(const ast::Function* func) {
arg_tys.Push(ty);
}
auto* common_ty = sem::Type::Common(arg_tys);
auto* common_ty = type::Type::Common(arg_tys);
if (!common_ty) {
AddError("workgroup_size arguments must be of the same type, either i32 or u32",
attr->source);
@@ -1266,7 +1274,7 @@ sem::Statement* Resolver::Statement(const ast::Statement* stmt) {
});
}
sem::CaseStatement* Resolver::CaseStatement(const ast::CaseStatement* stmt, const sem::Type* ty) {
sem::CaseStatement* Resolver::CaseStatement(const ast::CaseStatement* stmt, const type::Type* ty) {
auto* sem =
builder_->create<sem::CaseStatement>(stmt, current_compound_statement_, current_function_);
return StatementScope(stmt, sem, [&] {
@@ -1705,9 +1713,9 @@ bool Resolver::AliasAnalysis(const sem::Call* call) {
return true;
}
const sem::Type* Resolver::ConcreteType(const sem::Type* ty,
const sem::Type* target_ty,
const Source& source) {
const type::Type* Resolver::ConcreteType(const type::Type* ty,
const type::Type* target_ty,
const Source& source) {
auto i32 = [&] { return builder_->create<sem::I32>(); };
auto f32 = [&] { return builder_->create<sem::F32>(); };
auto i32v = [&](uint32_t width) { return builder_->create<sem::Vector>(i32(), width); };
@@ -1734,8 +1742,8 @@ const sem::Type* Resolver::ConcreteType(const sem::Type* ty,
return target_ty ? target_ty : f32m(m->columns(), m->rows());
});
},
[&](const sem::Array* a) -> const sem::Type* {
const sem::Type* target_el_ty = nullptr;
[&](const sem::Array* a) -> const type::Type* {
const type::Type* target_el_ty = nullptr;
if (auto* target_arr_ty = As<sem::Array>(target_ty)) {
target_el_ty = target_arr_ty->ElemType();
}
@@ -1744,7 +1752,7 @@ const sem::Type* Resolver::ConcreteType(const sem::Type* ty,
}
return nullptr;
},
[&](const sem::Struct* s) -> const sem::Type* {
[&](const sem::Struct* s) -> const type::Type* {
if (auto tys = s->ConcreteTypes(); !tys.IsEmpty()) {
return target_ty ? target_ty : tys[0];
}
@@ -1753,7 +1761,7 @@ const sem::Type* Resolver::ConcreteType(const sem::Type* ty,
}
const sem::Expression* Resolver::Materialize(const sem::Expression* expr,
const sem::Type* target_type /* = nullptr */) {
const type::Type* target_type /* = nullptr */) {
if (!expr) {
// Allow for Materialize(Expression(blah)), where failures pass through Materialize()
return nullptr;
@@ -1813,12 +1821,12 @@ bool Resolver::MaybeMaterializeArguments(utils::Vector<const sem::Expression*, N
return true;
}
bool Resolver::ShouldMaterializeArgument(const sem::Type* parameter_ty) const {
const auto* param_el_ty = sem::Type::DeepestElementOf(parameter_ty);
bool Resolver::ShouldMaterializeArgument(const type::Type* parameter_ty) const {
const auto* param_el_ty = type::Type::DeepestElementOf(parameter_ty);
return param_el_ty && !param_el_ty->Is<sem::AbstractNumeric>();
}
bool Resolver::Convert(const sem::Constant*& c, const sem::Type* target_ty, const Source& source) {
bool Resolver::Convert(const sem::Constant*& c, const type::Type* target_ty, const Source& source) {
auto r = const_eval_.Convert(target_ty, c, source);
if (!r) {
return false;
@@ -1963,7 +1971,7 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
// ct_init_or_conv is a helper for building either a sem::TypeInitializer or
// sem::TypeConversion call for a InitConvIntrinsic with an optional template argument type.
auto ct_init_or_conv = [&](InitConvIntrinsic ty, const sem::Type* template_arg) -> sem::Call* {
auto ct_init_or_conv = [&](InitConvIntrinsic ty, const type::Type* template_arg) -> sem::Call* {
auto arg_tys = utils::Transform(args, [](auto* arg) { return arg->Type(); });
auto ctor_or_conv =
intrinsic_table_->Lookup(ty, template_arg, arg_tys, args_stage, expr->source);
@@ -1993,7 +2001,7 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
// arr_or_str_init is a helper for building a sem::TypeInitializer for an array or structure
// initializer call target.
auto arr_or_str_init = [&](const sem::Type* ty,
auto arr_or_str_init = [&](const type::Type* ty,
const sem::CallTarget* call_target) -> sem::Call* {
if (!MaybeMaterializeArguments(args, call_target)) {
return nullptr;
@@ -2023,7 +2031,7 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
// ty_init_or_conv is a helper for building either a sem::TypeInitializer or
// sem::TypeConversion call for the given semantic type.
auto ty_init_or_conv = [&](const sem::Type* ty) {
auto ty_init_or_conv = [&](const type::Type* ty) {
return Switch(
ty, //
[&](const sem::Vector* v) {
@@ -2110,7 +2118,7 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
[&](const ast::Vector* v) -> sem::Call* {
Mark(v);
// vector element type must be inferred if it was not specified.
sem::Type* template_arg = nullptr;
type::Type* template_arg = nullptr;
if (v->type) {
template_arg = Type(v->type);
if (!template_arg) {
@@ -2126,7 +2134,7 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
[&](const ast::Matrix* m) -> sem::Call* {
Mark(m);
// matrix element type must be inferred if it was not specified.
sem::Type* template_arg = nullptr;
type::Type* template_arg = nullptr;
if (m->type) {
template_arg = Type(m->type);
if (!template_arg) {
@@ -2143,8 +2151,8 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
[&](const ast::Array* a) -> sem::Call* {
Mark(a);
// array element type must be inferred if it was not specified.
const sem::ArrayCount* el_count = nullptr;
const sem::Type* el_ty = nullptr;
const type::ArrayCount* el_count = nullptr;
const type::Type* el_ty = nullptr;
if (a->type) {
el_ty = Type(a->type);
if (!el_ty) {
@@ -2161,16 +2169,16 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
// Note: validation later will detect any mismatches between explicit array
// size and number of initializer expressions.
} else {
el_count = builder_->create<sem::ConstantArrayCount>(
el_count = builder_->create<type::ConstantArrayCount>(
static_cast<uint32_t>(args.Length()));
auto arg_tys =
utils::Transform(args, [](auto* arg) { return arg->Type()->UnwrapRef(); });
el_ty = sem::Type::Common(arg_tys);
el_ty = type::Type::Common(arg_tys);
if (!el_ty) {
AddError(
"cannot infer common array element type from initializer arguments",
expr->source);
utils::Hashset<const sem::Type*, 8> types;
utils::Hashset<const type::Type*, 8> types;
for (size_t i = 0; i < args.Length(); i++) {
if (types.Add(args[i]->Type())) {
AddNote("argument " + std::to_string(i) + " is of type '" +
@@ -2216,16 +2224,17 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
// conversion.
auto* ident = expr->target.name;
Mark(ident);
auto* resolved = sem_.ResolvedSymbol(ident);
if (auto* resolved = sem_.ResolvedSymbol<type::Type>(ident)) {
// A type initializer or conversions.
// Note: Unlike the code path where we're resolving the call target from an
// ast::Type, all types must already have the element type explicitly specified,
// so there's no need to infer element types.
return ty_init_or_conv(resolved);
}
auto* resolved = sem_.ResolvedSymbol<sem::Node>(ident);
call = Switch<sem::Call*>(
resolved, //
[&](sem::Type* ty) {
// A type initializer or conversions.
// Note: Unlike the code path where we're resolving the call target from an
// ast::Type, all types must already have the element type explicitly specified,
// so there's no need to infer element types.
return ty_init_or_conv(ty);
},
[&](sem::Function* func) { return FunctionCall(expr, func, args, arg_behaviors); },
[&](sem::Variable* var) {
auto name = builder_->Symbols().NameFor(var->Declaration()->symbol);
@@ -2337,7 +2346,7 @@ sem::Call* Resolver::BuiltinCall(const ast::CallExpression* expr,
return call;
}
sem::Type* Resolver::BuiltinTypeAlias(Symbol sym) const {
type::Type* Resolver::BuiltinTypeAlias(Symbol sym) const {
auto name = builder_->Symbols().NameFor(sym);
auto& b = *builder_;
switch (ParseTypeAlias(name)) {
@@ -2471,7 +2480,7 @@ void Resolver::CollectTextureSamplerPairs(sem::Function* func,
sem::Expression* Resolver::Literal(const ast::LiteralExpression* literal) {
auto* ty = Switch(
literal,
[&](const ast::IntLiteralExpression* i) -> sem::Type* {
[&](const ast::IntLiteralExpression* i) -> type::Type* {
switch (i->suffix) {
case ast::IntLiteralExpression::Suffix::kNone:
return builder_->create<sem::AbstractInt>();
@@ -2482,7 +2491,7 @@ sem::Expression* Resolver::Literal(const ast::LiteralExpression* literal) {
}
return nullptr;
},
[&](const ast::FloatLiteralExpression* f) -> sem::Type* {
[&](const ast::FloatLiteralExpression* f) -> type::Type* {
switch (f->suffix) {
case ast::FloatLiteralExpression::Suffix::kNone:
return builder_->create<sem::AbstractFloat>();
@@ -2520,8 +2529,8 @@ sem::Expression* Resolver::Literal(const ast::LiteralExpression* literal) {
sem::Expression* Resolver::Identifier(const ast::IdentifierExpression* expr) {
auto symbol = expr->symbol;
auto* resolved = sem_.ResolvedSymbol(expr);
if (auto* variable = As<sem::Variable>(resolved)) {
auto* sem_resolved = sem_.ResolvedSymbol<sem::Node>(expr);
if (auto* variable = As<sem::Variable>(sem_resolved)) {
auto* user = builder_->create<sem::VariableUser>(expr, current_statement_, variable);
if (current_statement_) {
@@ -2589,7 +2598,7 @@ sem::Expression* Resolver::Identifier(const ast::IdentifierExpression* expr) {
return user;
}
if (Is<sem::Function>(resolved)) {
if (Is<sem::Function>(sem_resolved)) {
AddError("missing '(' for function call", expr->source.End());
return nullptr;
}
@@ -2599,14 +2608,14 @@ sem::Expression* Resolver::Identifier(const ast::IdentifierExpression* expr) {
return nullptr;
}
if (resolved->Is<sem::Type>() || BuiltinTypeAlias(symbol)) {
if (sem_.ResolvedSymbol<type::Type>(expr)) {
AddError("missing '(' for type initializer or cast", expr->source.End());
return nullptr;
}
TINT_ICE(Resolver, diagnostics_)
<< expr->source << " unresolved identifier:\n"
<< "resolved: " << (resolved ? resolved->TypeInfo().name : "<null>") << "\n"
<< "resolved: " << (sem_resolved ? sem_resolved->TypeInfo().name : "<null>") << "\n"
<< "name: " << builder_->Symbols().NameFor(symbol);
return nullptr;
}
@@ -2617,7 +2626,7 @@ sem::Expression* Resolver::MemberAccessor(const ast::MemberAccessorExpression* e
auto* object = sem_.Get(expr->structure);
auto* root_ident = object->RootIdentifier();
const sem::Type* ty = nullptr;
const type::Type* ty = nullptr;
// Object may be a side-effecting expression (e.g. function call).
bool has_side_effects = object && object->HasSideEffects();
@@ -2812,7 +2821,7 @@ sem::Expression* Resolver::UnaryOp(const ast::UnaryOpExpression* unary) {
return nullptr;
}
const sem::Type* ty = nullptr;
const type::Type* ty = nullptr;
const sem::Variable* root_ident = nullptr;
const sem::Constant* value = nullptr;
auto stage = sem::EvaluationStage::kRuntime;
@@ -2898,8 +2907,8 @@ bool Resolver::Enable(const ast::Enable* enable) {
return true;
}
sem::Type* Resolver::TypeDecl(const ast::TypeDecl* named_type) {
sem::Type* result = nullptr;
type::Type* Resolver::TypeDecl(const ast::TypeDecl* named_type) {
type::Type* result = nullptr;
if (auto* alias = named_type->As<ast::Alias>()) {
result = Alias(alias);
} else if (auto* str = named_type->As<ast::Struct>()) {
@@ -2936,7 +2945,7 @@ sem::Array* Resolver::Array(const ast::Array* arr) {
return nullptr;
}
const sem::ArrayCount* el_count = nullptr;
const type::ArrayCount* el_count = nullptr;
// Evaluate the constant array count expression.
if (auto* count_expr = arr->count) {
@@ -2945,7 +2954,7 @@ sem::Array* Resolver::Array(const ast::Array* arr) {
return nullptr;
}
} else {
el_count = builder_->create<sem::RuntimeArrayCount>();
el_count = builder_->create<type::RuntimeArrayCount>();
}
auto* out = Array(arr->type->source, //
@@ -2972,7 +2981,7 @@ sem::Array* Resolver::Array(const ast::Array* arr) {
return out;
}
const sem::ArrayCount* Resolver::ArrayCount(const ast::Expression* count_expr) {
const type::ArrayCount* Resolver::ArrayCount(const ast::Expression* count_expr) {
// Evaluate the constant array count expression.
const auto* count_sem = Materialize(Expression(count_expr));
if (!count_sem) {
@@ -3011,11 +3020,11 @@ const sem::ArrayCount* Resolver::ArrayCount(const ast::Expression* count_expr) {
return nullptr;
}
return builder_->create<sem::ConstantArrayCount>(static_cast<uint32_t>(count));
return builder_->create<type::ConstantArrayCount>(static_cast<uint32_t>(count));
}
bool Resolver::ArrayAttributes(utils::VectorRef<const ast::Attribute*> attributes,
const sem::Type* el_ty,
const type::Type* el_ty,
uint32_t& explicit_stride) {
if (!validator_.NoDuplicateAttributes(attributes)) {
return false;
@@ -3046,8 +3055,8 @@ bool Resolver::ArrayAttributes(utils::VectorRef<const ast::Attribute*> attribute
sem::Array* Resolver::Array(const Source& el_source,
const Source& count_source,
const sem::Type* el_ty,
const sem::ArrayCount* el_count,
const type::Type* el_ty,
const type::ArrayCount* el_count,
uint32_t explicit_stride) {
uint32_t el_align = el_ty->Align();
uint32_t el_size = el_ty->Size();
@@ -3055,7 +3064,7 @@ sem::Array* Resolver::Array(const Source& el_source,
uint64_t stride = explicit_stride ? explicit_stride : implicit_stride;
uint64_t size = 0;
if (auto const_count = el_count->As<sem::ConstantArrayCount>()) {
if (auto const_count = el_count->As<type::ConstantArrayCount>()) {
size = const_count->value * stride;
if (size > std::numeric_limits<uint32_t>::max()) {
std::stringstream msg;
@@ -3064,7 +3073,7 @@ sem::Array* Resolver::Array(const Source& el_source,
AddError(msg.str(), count_source);
return nullptr;
}
} else if (el_count->Is<sem::RuntimeArrayCount>()) {
} else if (el_count->Is<type::RuntimeArrayCount>()) {
size = stride;
}
auto* out = builder_->create<sem::Array>(el_ty, el_count, el_align, static_cast<uint32_t>(size),
@@ -3078,7 +3087,7 @@ sem::Array* Resolver::Array(const Source& el_source,
return out;
}
sem::Type* Resolver::Alias(const ast::Alias* alias) {
type::Type* Resolver::Alias(const ast::Alias* alias) {
auto* ty = Type(alias->type);
if (!ty) {
return nullptr;
@@ -3329,7 +3338,7 @@ sem::Statement* Resolver::ReturnStatement(const ast::ReturnStatement* stmt) {
auto& behaviors = current_statement_->Behaviors();
behaviors = sem::Behavior::kReturn;
const sem::Type* value_ty = nullptr;
const type::Type* value_ty = nullptr;
if (auto* value = stmt->value) {
const auto* expr = Expression(value);
if (!expr) {
@@ -3374,7 +3383,7 @@ sem::SwitchStatement* Resolver::SwitchStatement(const ast::SwitchStatement* stmt
// Determine the common type across all selectors and the switch expression
// This must materialize to an integer scalar (non-abstract).
utils::Vector<const sem::Type*, 8> types;
utils::Vector<const type::Type*, 8> types;
types.Push(cond_ty);
for (auto* case_stmt : stmt->body) {
for (auto* sel : case_stmt->selectors) {
@@ -3388,7 +3397,7 @@ sem::SwitchStatement* Resolver::SwitchStatement(const ast::SwitchStatement* stmt
types.Push(sem_expr->Type()->UnwrapRef());
}
}
auto* common_ty = sem::Type::Common(types);
auto* common_ty = type::Type::Common(types);
if (!common_ty || !common_ty->is_integer_scalar()) {
// No common type found or the common type was abstract.
// Pick i32 and let validation deal with any mismatches.
@@ -3607,9 +3616,9 @@ sem::Statement* Resolver::IncrementDecrementStatement(
}
bool Resolver::ApplyAddressSpaceUsageToType(ast::AddressSpace address_space,
sem::Type* ty,
type::Type* ty,
const Source& usage) {
ty = const_cast<sem::Type*>(ty->UnwrapRef());
ty = const_cast<type::Type*>(ty->UnwrapRef());
if (auto* str = ty->As<sem::Struct>()) {
if (str->AddressSpaceUsage().count(address_space)) {
@@ -3621,8 +3630,8 @@ bool Resolver::ApplyAddressSpaceUsageToType(ast::AddressSpace address_space,
for (auto* member : str->Members()) {
auto decl = member->Declaration();
if (decl &&
!ApplyAddressSpaceUsageToType(address_space, const_cast<sem::Type*>(member->Type()),
decl->type->source)) {
!ApplyAddressSpaceUsageToType(
address_space, const_cast<type::Type*>(member->Type()), decl->type->source)) {
std::stringstream err;
err << "while analyzing structure member " << sem_.TypeNameOf(str) << "."
<< builder_->Symbols().NameFor(member->Name());
@@ -3635,7 +3644,7 @@ bool Resolver::ApplyAddressSpaceUsageToType(ast::AddressSpace address_space,
if (auto* arr = ty->As<sem::Array>()) {
if (address_space != ast::AddressSpace::kStorage) {
if (arr->Count()->Is<sem::RuntimeArrayCount>()) {
if (arr->Count()->Is<type::RuntimeArrayCount>()) {
AddError("runtime-sized arrays can only be used in the <storage> address space",
usage);
return false;
@@ -3649,7 +3658,7 @@ bool Resolver::ApplyAddressSpaceUsageToType(ast::AddressSpace address_space,
return false;
}
}
return ApplyAddressSpaceUsageToType(address_space, const_cast<sem::Type*>(arr->ElemType()),
return ApplyAddressSpaceUsageToType(address_space, const_cast<type::Type*>(arr->ElemType()),
usage);
}

View File

@@ -93,19 +93,21 @@ class Resolver {
/// @param type the given type
/// @returns true if the given type is a plain type
bool IsPlain(const sem::Type* type) const { return validator_.IsPlain(type); }
bool IsPlain(const type::Type* type) const { return validator_.IsPlain(type); }
/// @param type the given type
/// @returns true if the given type is a fixed-footprint type
bool IsFixedFootprint(const sem::Type* type) const { return validator_.IsFixedFootprint(type); }
bool IsFixedFootprint(const type::Type* type) const {
return validator_.IsFixedFootprint(type);
}
/// @param type the given type
/// @returns true if the given type is storable
bool IsStorable(const sem::Type* type) const { return validator_.IsStorable(type); }
bool IsStorable(const type::Type* type) const { return validator_.IsStorable(type); }
/// @param type the given type
/// @returns true if the given type is host-shareable
bool IsHostShareable(const sem::Type* type) const { return validator_.IsHostShareable(type); }
bool IsHostShareable(const type::Type* type) const { return validator_.IsHostShareable(type); }
/// @returns the validator for testing
const Validator* GetValidatorForTesting() const { return &validator_; }
@@ -179,7 +181,7 @@ class Resolver {
/// materialized type.
/// If `expr` is nullptr, then Materialize() will also return nullptr.
const sem::Expression* Materialize(const sem::Expression* expr,
const sem::Type* target_type = nullptr);
const type::Type* target_type = nullptr);
/// Materializes all the arguments in `args` to the parameter types of `target`.
/// @returns true on success, false on failure.
@@ -189,11 +191,11 @@ class Resolver {
/// @returns true if an argument of an abstract numeric type, passed to a parameter of type
/// `parameter_ty` should be materialized.
bool ShouldMaterializeArgument(const sem::Type* parameter_ty) const;
bool ShouldMaterializeArgument(const type::Type* parameter_ty) const;
/// Converts `c` to `target_ty`
/// @returns true on success, false on failure.
bool Convert(const sem::Constant*& c, const sem::Type* target_ty, const Source& source);
bool Convert(const sem::Constant*& c, const type::Type* target_ty, const Source& source);
/// Transforms `args` to a vector of constants, and converts each constant to the call target's
/// parameter type.
@@ -209,9 +211,9 @@ class Resolver {
/// @param source the source of the expression requiring materialization
/// @returns the concrete (materialized) type for the given type, or nullptr if the type is
/// already concrete.
const sem::Type* ConcreteType(const sem::Type* ty,
const sem::Type* target_ty,
const Source& source);
const type::Type* ConcreteType(const type::Type* ty,
const type::Type* target_ty,
const Source& source);
// Statement resolving methods
// Each return true on success, false on failure.
@@ -220,7 +222,7 @@ class Resolver {
sem::Statement* BreakStatement(const ast::BreakStatement*);
sem::Statement* BreakIfStatement(const ast::BreakIfStatement*);
sem::Statement* CallStatement(const ast::CallStatement*);
sem::CaseStatement* CaseStatement(const ast::CaseStatement*, const sem::Type*);
sem::CaseStatement* CaseStatement(const ast::CaseStatement*, const type::Type*);
sem::Statement* CompoundAssignmentStatement(const ast::CompoundAssignmentStatement*);
sem::Statement* ContinueStatement(const ast::ContinueStatement*);
sem::Statement* DiscardStatement(const ast::DiscardStatement*);
@@ -249,11 +251,11 @@ class Resolver {
/// current_function_
bool WorkgroupSize(const ast::Function*);
/// @returns the sem::Type for the ast::Type `ty`, building it if it
/// @returns the type::Type for the ast::Type `ty`, building it if it
/// hasn't been constructed already. If an error is raised, nullptr is
/// returned.
/// @param ty the ast::Type
sem::Type* Type(const ast::Type* ty);
type::Type* Type(const ast::Type* ty);
/// @param enable the enable declaration
/// @returns the resolved extension
@@ -261,7 +263,7 @@ class Resolver {
/// @param named_type the named type to resolve
/// @returns the resolved semantic type
sem::Type* TypeDecl(const ast::TypeDecl* named_type);
type::Type* TypeDecl(const ast::TypeDecl* named_type);
/// Builds and returns the semantic information for the AST array `arr`.
/// This method does not mark the ast::Array node, nor attach the generated semantic information
@@ -273,7 +275,7 @@ class Resolver {
/// Resolves and validates the expression used as the count parameter of an array.
/// @param count_expr the expression used as the second template parameter to an array<>.
/// @returns the number of elements in the array.
const sem::ArrayCount* ArrayCount(const ast::Expression* count_expr);
const type::ArrayCount* ArrayCount(const ast::Expression* count_expr);
/// Resolves and validates the attributes on an array.
/// @param attributes the attributes on the array type.
@@ -281,7 +283,7 @@ class Resolver {
/// @param explicit_stride assigned the specified stride of the array in bytes.
/// @returns true on success, false on failure
bool ArrayAttributes(utils::VectorRef<const ast::Attribute*> attributes,
const sem::Type* el_ty,
const type::Type* el_ty,
uint32_t& explicit_stride);
/// Builds and returns the semantic information for an array.
@@ -295,15 +297,15 @@ class Resolver {
/// @param explicit_stride the explicit byte stride of the array. Zero means implicit stride.
sem::Array* Array(const Source& el_source,
const Source& count_source,
const sem::Type* el_ty,
const sem::ArrayCount* el_count,
const type::Type* el_ty,
const type::ArrayCount* el_count,
uint32_t explicit_stride);
/// Builds and returns the semantic information for the alias `alias`.
/// This method does not mark the ast::Alias node, nor attach the generated
/// semantic information to the AST node.
/// @returns the aliased type, or nullptr if an error is raised.
sem::Type* Alias(const ast::Alias* alias);
type::Type* Alias(const ast::Alias* alias);
/// Builds and returns the semantic information for the structure `str`.
/// This method does not mark the ast::Struct node, nor attach the generated
@@ -371,7 +373,7 @@ class Resolver {
/// given type and address space. Used for generating sensible error
/// messages.
/// @returns true on success, false on error
bool ApplyAddressSpaceUsageToType(ast::AddressSpace sc, sem::Type* ty, const Source& usage);
bool ApplyAddressSpaceUsageToType(ast::AddressSpace sc, type::Type* ty, const Source& usage);
/// @param address_space the address space
/// @returns the default access control for the given address space
@@ -417,7 +419,7 @@ class Resolver {
bool IsBuiltin(Symbol) const;
/// @returns the builtin type alias for the given symbol
sem::Type* BuiltinTypeAlias(Symbol) const;
type::Type* BuiltinTypeAlias(Symbol) const;
// ArrayInitializerSig represents a unique array initializer signature.
// It is a tuple of the array type, number of arguments provided and earliest evaluation stage.
@@ -461,7 +463,7 @@ class Resolver {
Validator validator_;
ast::Extensions enabled_extensions_;
utils::Vector<sem::Function*, 8> entry_points_;
utils::Hashmap<const sem::Type*, const Source*, 8> atomic_composite_info_;
utils::Hashmap<const type::Type*, const Source*, 8> atomic_composite_info_;
utils::Bitset<0> marked_;
ExprEvalStageConstraint expr_eval_stage_constraint_;
std::unordered_map<const sem::Function*, AliasAnalysisInfo> alias_analysis_infos_;

View File

@@ -440,7 +440,7 @@ TEST_F(ResolverTest, ArraySize_UnsignedLiteral) {
auto* ref = TypeOf(a)->As<sem::Reference>();
ASSERT_NE(ref, nullptr);
auto* ary = ref->StoreType()->As<sem::Array>();
EXPECT_EQ(ary->Count(), create<sem::ConstantArrayCount>(10u));
EXPECT_EQ(ary->Count(), create<type::ConstantArrayCount>(10u));
}
TEST_F(ResolverTest, ArraySize_SignedLiteral) {
@@ -453,7 +453,7 @@ TEST_F(ResolverTest, ArraySize_SignedLiteral) {
auto* ref = TypeOf(a)->As<sem::Reference>();
ASSERT_NE(ref, nullptr);
auto* ary = ref->StoreType()->As<sem::Array>();
EXPECT_EQ(ary->Count(), create<sem::ConstantArrayCount>(10u));
EXPECT_EQ(ary->Count(), create<type::ConstantArrayCount>(10u));
}
TEST_F(ResolverTest, ArraySize_UnsignedConst) {
@@ -468,7 +468,7 @@ TEST_F(ResolverTest, ArraySize_UnsignedConst) {
auto* ref = TypeOf(a)->As<sem::Reference>();
ASSERT_NE(ref, nullptr);
auto* ary = ref->StoreType()->As<sem::Array>();
EXPECT_EQ(ary->Count(), create<sem::ConstantArrayCount>(10u));
EXPECT_EQ(ary->Count(), create<type::ConstantArrayCount>(10u));
}
TEST_F(ResolverTest, ArraySize_SignedConst) {
@@ -483,7 +483,7 @@ TEST_F(ResolverTest, ArraySize_SignedConst) {
auto* ref = TypeOf(a)->As<sem::Reference>();
ASSERT_NE(ref, nullptr);
auto* ary = ref->StoreType()->As<sem::Array>();
EXPECT_EQ(ary->Count(), create<sem::ConstantArrayCount>(10u));
EXPECT_EQ(ary->Count(), create<type::ConstantArrayCount>(10u));
}
TEST_F(ResolverTest, ArraySize_NamedOverride) {
@@ -1767,7 +1767,7 @@ TEST_P(Expr_Binary_Test_Invalid_VectorMatrixMultiply, All) {
const ast::Type* lhs_type = nullptr;
const ast::Type* rhs_type = nullptr;
const sem::Type* result_type = nullptr;
const type::Type* result_type = nullptr;
bool is_valid_expr;
if (vec_by_mat) {

View File

@@ -114,7 +114,7 @@ class TestHelper : public ProgramBuilder {
/// @param type a type
/// @returns the name for `type` that closely resembles how it would be
/// declared in WGSL.
std::string FriendlyName(const sem::Type* type) { return type->FriendlyName(Symbols()); }
std::string FriendlyName(const type::Type* type) { return type->FriendlyName(Symbols()); }
private:
std::unique_ptr<Resolver> resolver_;
@@ -194,7 +194,7 @@ using ast_type_func_ptr = const ast::Type* (*)(ProgramBuilder& b);
using ast_expr_func_ptr = const ast::Expression* (*)(ProgramBuilder& b,
utils::VectorRef<Scalar> args);
using ast_expr_from_double_func_ptr = const ast::Expression* (*)(ProgramBuilder& b, double v);
using sem_type_func_ptr = const sem::Type* (*)(ProgramBuilder& b);
using sem_type_func_ptr = const type::Type* (*)(ProgramBuilder& b);
using type_name_func_ptr = std::string (*)();
struct UnspecializedElementType {};
@@ -215,7 +215,7 @@ struct DataType<void> {
/// @return nullptr
static inline const ast::Type* AST(ProgramBuilder&) { return nullptr; }
/// @return nullptr
static inline const sem::Type* Sem(ProgramBuilder&) { return nullptr; }
static inline const type::Type* Sem(ProgramBuilder&) { return nullptr; }
};
/// Helper for building bool types and expressions
@@ -232,7 +232,7 @@ struct DataType<bool> {
static inline const ast::Type* AST(ProgramBuilder& b) { return b.ty.bool_(); }
/// @param b the ProgramBuilder
/// @return the semantic bool type
static inline const sem::Type* Sem(ProgramBuilder& b) { return b.create<sem::Bool>(); }
static inline const type::Type* Sem(ProgramBuilder& b) { return b.create<sem::Bool>(); }
/// @param b the ProgramBuilder
/// @param args args of size 1 with the boolean value to init with
/// @return a new AST expression of the bool type
@@ -263,7 +263,7 @@ struct DataType<i32> {
static inline const ast::Type* AST(ProgramBuilder& b) { return b.ty.i32(); }
/// @param b the ProgramBuilder
/// @return the semantic i32 type
static inline const sem::Type* Sem(ProgramBuilder& b) { return b.create<sem::I32>(); }
static inline const type::Type* Sem(ProgramBuilder& b) { return b.create<sem::I32>(); }
/// @param b the ProgramBuilder
/// @param args args of size 1 with the i32 value to init with
/// @return a new AST i32 literal value expression
@@ -294,7 +294,7 @@ struct DataType<u32> {
static inline const ast::Type* AST(ProgramBuilder& b) { return b.ty.u32(); }
/// @param b the ProgramBuilder
/// @return the semantic u32 type
static inline const sem::Type* Sem(ProgramBuilder& b) { return b.create<sem::U32>(); }
static inline const type::Type* Sem(ProgramBuilder& b) { return b.create<sem::U32>(); }
/// @param b the ProgramBuilder
/// @param args args of size 1 with the u32 value to init with
/// @return a new AST u32 literal value expression
@@ -325,7 +325,7 @@ struct DataType<f32> {
static inline const ast::Type* AST(ProgramBuilder& b) { return b.ty.f32(); }
/// @param b the ProgramBuilder
/// @return the semantic f32 type
static inline const sem::Type* Sem(ProgramBuilder& b) { return b.create<sem::F32>(); }
static inline const type::Type* Sem(ProgramBuilder& b) { return b.create<sem::F32>(); }
/// @param b the ProgramBuilder
/// @param args args of size 1 with the f32 value to init with
/// @return a new AST f32 literal value expression
@@ -356,7 +356,7 @@ struct DataType<f16> {
static inline const ast::Type* AST(ProgramBuilder& b) { return b.ty.f16(); }
/// @param b the ProgramBuilder
/// @return the semantic f16 type
static inline const sem::Type* Sem(ProgramBuilder& b) { return b.create<sem::F16>(); }
static inline const type::Type* Sem(ProgramBuilder& b) { return b.create<sem::F16>(); }
/// @param b the ProgramBuilder
/// @param args args of size 1 with the f16 value to init with
/// @return a new AST f16 literal value expression
@@ -386,7 +386,9 @@ struct DataType<AFloat> {
static inline const ast::Type* AST(ProgramBuilder&) { return nullptr; }
/// @param b the ProgramBuilder
/// @return the semantic abstract-float type
static inline const sem::Type* Sem(ProgramBuilder& b) { return b.create<sem::AbstractFloat>(); }
static inline const type::Type* Sem(ProgramBuilder& b) {
return b.create<sem::AbstractFloat>();
}
/// @param b the ProgramBuilder
/// @param args args of size 1 with the abstract-float value to init with
/// @return a new AST abstract-float literal value expression
@@ -416,7 +418,7 @@ struct DataType<AInt> {
static inline const ast::Type* AST(ProgramBuilder&) { return nullptr; }
/// @param b the ProgramBuilder
/// @return the semantic abstract-int type
static inline const sem::Type* Sem(ProgramBuilder& b) { return b.create<sem::AbstractInt>(); }
static inline const type::Type* Sem(ProgramBuilder& b) { return b.create<sem::AbstractInt>(); }
/// @param b the ProgramBuilder
/// @param args args of size 1 with the abstract-int value to init with
/// @return a new AST abstract-int literal value expression
@@ -449,7 +451,7 @@ struct DataType<vec<N, T>> {
}
/// @param b the ProgramBuilder
/// @return the semantic vector type
static inline const sem::Type* Sem(ProgramBuilder& b) {
static inline const type::Type* Sem(ProgramBuilder& b) {
return b.create<sem::Vector>(DataType<T>::Sem(b), N);
}
/// @param b the ProgramBuilder
@@ -497,7 +499,7 @@ struct DataType<mat<N, M, T>> {
}
/// @param b the ProgramBuilder
/// @return the semantic matrix type
static inline const sem::Type* Sem(ProgramBuilder& b) {
static inline const type::Type* Sem(ProgramBuilder& b) {
auto* column_type = b.create<sem::Vector>(DataType<T>::Sem(b), M);
return b.create<sem::Matrix>(column_type, N);
}
@@ -561,7 +563,7 @@ struct DataType<alias<T, ID>> {
}
/// @param b the ProgramBuilder
/// @return the semantic aliased type
static inline const sem::Type* Sem(ProgramBuilder& b) { return DataType<T>::Sem(b); }
static inline const type::Type* Sem(ProgramBuilder& b) { return DataType<T>::Sem(b); }
/// @param b the ProgramBuilder
/// @param args the value nested elements will be initialized with
@@ -613,7 +615,7 @@ struct DataType<ptr<T>> {
}
/// @param b the ProgramBuilder
/// @return the semantic aliased type
static inline const sem::Type* Sem(ProgramBuilder& b) {
static inline const type::Type* Sem(ProgramBuilder& b) {
return b.create<sem::Pointer>(DataType<T>::Sem(b), ast::AddressSpace::kPrivate,
ast::Access::kReadWrite);
}
@@ -657,13 +659,13 @@ struct DataType<array<N, T>> {
}
/// @param b the ProgramBuilder
/// @return the semantic array type
static inline const sem::Type* Sem(ProgramBuilder& b) {
static inline const type::Type* Sem(ProgramBuilder& b) {
auto* el = DataType<T>::Sem(b);
const sem::ArrayCount* count = nullptr;
const type::ArrayCount* count = nullptr;
if (N == 0) {
count = b.create<sem::RuntimeArrayCount>();
count = b.create<type::RuntimeArrayCount>();
} else {
count = b.create<sem::ConstantArrayCount>(N);
count = b.create<type::ConstantArrayCount>(N);
}
return b.create<sem::Array>(
/* element */ el,

View File

@@ -23,17 +23,17 @@ SemHelper::SemHelper(ProgramBuilder* builder, DependencyGraph& dependencies)
SemHelper::~SemHelper() = default;
std::string SemHelper::TypeNameOf(const sem::Type* ty) const {
std::string SemHelper::TypeNameOf(const type::Type* ty) const {
return RawTypeNameOf(ty->UnwrapRef());
}
std::string SemHelper::RawTypeNameOf(const sem::Type* ty) const {
std::string SemHelper::RawTypeNameOf(const type::Type* ty) const {
return ty->FriendlyName(builder_->Symbols());
}
sem::Type* SemHelper::TypeOf(const ast::Expression* expr) const {
type::Type* SemHelper::TypeOf(const ast::Expression* expr) const {
auto* sem = Get(expr);
return sem ? const_cast<sem::Type*>(sem->Type()) : nullptr;
return sem ? const_cast<type::Type*>(sem->Type()) : nullptr;
}
} // namespace tint::resolver

View File

@@ -49,10 +49,10 @@ class SemHelper {
return const_cast<T*>(As<T>(sem));
}
/// @returns the resolved symbol (function, type or variable) for the given
/// ast::Identifier or ast::TypeName cast to the given semantic type.
/// @returns the resolved symbol (function, type or variable) for the given ast::Identifier or
/// ast::TypeName cast to the given semantic type.
/// @param node the node to retrieve
template <typename SEM = sem::Node>
template <typename SEM = CastableBase>
SEM* ResolvedSymbol(const ast::Node* node) const {
auto resolved = dependencies_.resolved_symbols.Find(node);
return resolved ? const_cast<SEM*>(builder_->Sem().Get<SEM>(*resolved)) : nullptr;
@@ -60,17 +60,17 @@ class SemHelper {
/// @returns the resolved type of the ast::Expression `expr`
/// @param expr the expression
sem::Type* TypeOf(const ast::Expression* expr) const;
type::Type* TypeOf(const ast::Expression* expr) const;
/// @returns the type name of the given semantic type, unwrapping
/// references.
/// @param ty the type to look up
std::string TypeNameOf(const sem::Type* ty) const;
std::string TypeNameOf(const type::Type* ty) const;
/// @returns the type name of the given semantic type, without unwrapping
/// references.
/// @param ty the type to look up
std::string RawTypeNameOf(const sem::Type* ty) const;
std::string RawTypeNameOf(const type::Type* ty) const;
private:
ProgramBuilder* builder_;

View File

@@ -157,7 +157,7 @@ Validator::Validator(
ProgramBuilder* builder,
SemHelper& sem,
const ast::Extensions& enabled_extensions,
const utils::Hashmap<const sem::Type*, const Source*, 8>& atomic_composite_info,
const utils::Hashmap<const type::Type*, const Source*, 8>& atomic_composite_info,
utils::Hashset<TypeAndAddressSpace, 8>& valid_type_storage_layouts)
: symbols_(builder->Symbols()),
diagnostics_(builder->Diagnostics()),
@@ -181,20 +181,21 @@ void Validator::AddNote(const std::string& msg, const Source& source) const {
}
// https://gpuweb.github.io/gpuweb/wgsl/#plain-types-section
bool Validator::IsPlain(const sem::Type* type) const {
bool Validator::IsPlain(const type::Type* type) const {
return type->is_scalar() ||
type->IsAnyOf<sem::Atomic, sem::Vector, sem::Matrix, sem::Array, sem::Struct>();
}
// https://gpuweb.github.io/gpuweb/wgsl/#fixed-footprint-types
bool Validator::IsFixedFootprint(const sem::Type* type) const {
bool Validator::IsFixedFootprint(const type::Type* type) const {
return Switch(
type, //
[&](const sem::Vector*) { return true; }, //
[&](const sem::Matrix*) { return true; }, //
[&](const sem::Atomic*) { return true; },
[&](const sem::Array* arr) {
return !arr->Count()->Is<sem::RuntimeArrayCount>() && IsFixedFootprint(arr->ElemType());
return !arr->Count()->Is<type::RuntimeArrayCount>() &&
IsFixedFootprint(arr->ElemType());
},
[&](const sem::Struct* str) {
for (auto* member : str->Members()) {
@@ -208,7 +209,7 @@ bool Validator::IsFixedFootprint(const sem::Type* type) const {
}
// https://gpuweb.github.io/gpuweb/wgsl.html#host-shareable-types
bool Validator::IsHostShareable(const sem::Type* type) const {
bool Validator::IsHostShareable(const type::Type* type) const {
if (type->IsAnyOf<sem::I32, sem::U32, sem::F32, sem::F16>()) {
return true;
}
@@ -229,7 +230,7 @@ bool Validator::IsHostShareable(const sem::Type* type) const {
}
// https://gpuweb.github.io/gpuweb/wgsl.html#storable-types
bool Validator::IsStorable(const sem::Type* type) const {
bool Validator::IsStorable(const type::Type* type) const {
return IsPlain(type) || type->IsAnyOf<sem::Texture, sem::Sampler>();
}
@@ -341,10 +342,10 @@ bool Validator::MultisampledTexture(const sem::MultisampledTexture* t, const Sou
return true;
}
bool Validator::Materialize(const sem::Type* to,
const sem::Type* from,
bool Validator::Materialize(const type::Type* to,
const type::Type* from,
const Source& source) const {
if (sem::Type::ConversionRank(from, to) == sem::Type::kNoConversion) {
if (type::Type::ConversionRank(from, to) == type::Type::kNoConversion) {
AddError("cannot convert value of type '" + sem_.TypeNameOf(from) + "' to type '" +
sem_.TypeNameOf(to) + "'",
source);
@@ -355,7 +356,7 @@ bool Validator::Materialize(const sem::Type* to,
bool Validator::VariableInitializer(const ast::Variable* v,
ast::AddressSpace address_space,
const sem::Type* storage_ty,
const type::Type* storage_ty,
const sem::Expression* initializer) const {
auto* initializer_ty = initializer->Type();
auto* value_type = initializer_ty->UnwrapRef(); // Implicit load of RHS
@@ -389,21 +390,21 @@ bool Validator::VariableInitializer(const ast::Variable* v,
return true;
}
bool Validator::AddressSpaceLayout(const sem::Type* store_ty,
bool Validator::AddressSpaceLayout(const type::Type* store_ty,
ast::AddressSpace address_space,
Source source) const {
// https://gpuweb.github.io/gpuweb/wgsl/#storage-class-layout-constraints
auto is_uniform_struct_or_array = [address_space](const sem::Type* ty) {
auto is_uniform_struct_or_array = [address_space](const type::Type* ty) {
return address_space == ast::AddressSpace::kUniform &&
ty->IsAnyOf<sem::Array, sem::Struct>();
};
auto is_uniform_struct = [address_space](const sem::Type* ty) {
auto is_uniform_struct = [address_space](const type::Type* ty) {
return address_space == ast::AddressSpace::kUniform && ty->Is<sem::Struct>();
};
auto required_alignment_of = [&](const sem::Type* ty) {
auto required_alignment_of = [&](const type::Type* ty) {
uint32_t actual_align = ty->Align();
uint32_t required_align = actual_align;
if (is_uniform_struct_or_array(ty)) {
@@ -433,7 +434,7 @@ bool Validator::AddressSpaceLayout(const sem::Type* store_ty,
// Among three host-shareable address spaces, f16 is supported in "uniform" and
// "storage" address space, but not "push_constant" address space yet.
if (Is<sem::F16>(sem::Type::DeepestElementOf(store_ty)) &&
if (Is<sem::F16>(type::Type::DeepestElementOf(store_ty)) &&
address_space == ast::AddressSpace::kPushConstant) {
AddError("using f16 types in 'push_constant' address space is not implemented yet", source);
return false;
@@ -840,7 +841,7 @@ bool Validator::Parameter(const ast::Function* func, const sem::Variable* var) c
}
bool Validator::BuiltinAttribute(const ast::BuiltinAttribute* attr,
const sem::Type* storage_ty,
const type::Type* storage_ty,
ast::PipelineStage stage,
const bool is_input) const {
auto* type = storage_ty->UnwrapRef();
@@ -950,7 +951,7 @@ bool Validator::BuiltinAttribute(const ast::BuiltinAttribute* attr,
}
bool Validator::InterpolateAttribute(const ast::InterpolateAttribute* attr,
const sem::Type* storage_ty) const {
const type::Type* storage_ty) const {
auto* type = storage_ty->UnwrapRef();
if (type->is_integer_scalar_or_vector() && attr->type != ast::InterpolationType::kFlat) {
@@ -1064,7 +1065,7 @@ bool Validator::EntryPoint(const sem::Function* func, ast::PipelineStage stage)
// Inner lambda that is applied to a type and all of its members.
auto validate_entry_point_attributes_inner = [&](utils::VectorRef<const ast::Attribute*> attrs,
const sem::Type* ty, Source source,
const type::Type* ty, Source source,
ParamOrRetType param_or_ret,
bool is_struct_member,
std::optional<uint32_t> location) {
@@ -1207,7 +1208,7 @@ bool Validator::EntryPoint(const sem::Function* func, ast::PipelineStage stage)
// Outer lambda for validating the entry point attributes for a type.
auto validate_entry_point_attributes = [&](utils::VectorRef<const ast::Attribute*> attrs,
const sem::Type* ty, Source source,
const type::Type* ty, Source source,
ParamOrRetType param_or_ret,
std::optional<uint32_t> location) {
if (!validate_entry_point_attributes_inner(attrs, ty, source, param_or_ret,
@@ -1357,7 +1358,7 @@ bool Validator::Statements(utils::VectorRef<const ast::Statement*> stmts) const
return true;
}
bool Validator::Bitcast(const ast::BitcastExpression* cast, const sem::Type* to) const {
bool Validator::Bitcast(const ast::BitcastExpression* cast, const type::Type* to) const {
auto* from = sem_.TypeOf(cast->expr)->UnwrapRef();
if (!from->is_numeric_scalar_or_vector()) {
AddError("'" + sem_.TypeNameOf(from) + "' cannot be bitcast", cast->expr->source);
@@ -1368,7 +1369,7 @@ bool Validator::Bitcast(const ast::BitcastExpression* cast, const sem::Type* to)
return false;
}
auto width = [&](const sem::Type* ty) {
auto width = [&](const type::Type* ty) {
if (auto* vec = ty->As<sem::Vector>()) {
return vec->Width();
}
@@ -1672,7 +1673,7 @@ bool Validator::FunctionCall(const sem::Call* call, sem::Statement* current_stat
auto* root_ptr_ty = root->Type()->As<sem::Pointer>();
auto* root_ref_ty = root->Type()->As<sem::Reference>();
TINT_ASSERT(Resolver, root_ptr_ty || root_ref_ty);
const sem::Type* root_store_type;
const type::Type* root_store_type;
if (root_ptr_ty) {
root_store_type = root_ptr_ty->StoreType();
} else {
@@ -1747,7 +1748,7 @@ bool Validator::ArrayInitializer(const ast::CallExpression* ctor,
auto* elem_ty = array_type->ElemType();
for (auto* value : values) {
auto* value_ty = sem_.TypeOf(value)->UnwrapRef();
if (sem::Type::ConversionRank(value_ty, elem_ty) == sem::Type::kNoConversion) {
if (type::Type::ConversionRank(value_ty, elem_ty) == type::Type::kNoConversion) {
AddError("'" + sem_.TypeNameOf(value_ty) +
"' cannot be used to construct an array of '" + sem_.TypeNameOf(elem_ty) +
"'",
@@ -1757,7 +1758,7 @@ bool Validator::ArrayInitializer(const ast::CallExpression* ctor,
}
auto* c = array_type->Count();
if (c->Is<sem::RuntimeArrayCount>()) {
if (c->Is<type::RuntimeArrayCount>()) {
AddError("cannot construct a runtime-sized array", ctor->source);
return false;
}
@@ -1772,12 +1773,12 @@ bool Validator::ArrayInitializer(const ast::CallExpression* ctor,
return false;
}
if (!c->Is<sem::ConstantArrayCount>()) {
if (!c->Is<type::ConstantArrayCount>()) {
TINT_ICE(Resolver, diagnostics_) << "Invalid ArrayCount found";
return false;
}
const auto count = c->As<sem::ConstantArrayCount>()->value;
const auto count = c->As<type::ConstantArrayCount>()->value;
if (!values.IsEmpty() && (values.Length() != count)) {
std::string fm = values.Length() < count ? "few" : "many";
AddError("array initializer has too " + fm + " elements: expected " +
@@ -2020,7 +2021,7 @@ bool Validator::Structure(const sem::Struct* str, ast::PipelineStage stage) cons
utils::Hashset<uint32_t, 8> locations;
for (auto* member : str->Members()) {
if (auto* r = member->Type()->As<sem::Array>()) {
if (r->Count()->Is<sem::RuntimeArrayCount>()) {
if (r->Count()->Is<type::RuntimeArrayCount>()) {
if (member != str->Members().Back()) {
AddError("runtime arrays may only appear as the last member of a struct",
member->Source());
@@ -2134,7 +2135,7 @@ bool Validator::Structure(const sem::Struct* str, ast::PipelineStage stage) cons
bool Validator::LocationAttribute(const ast::LocationAttribute* loc_attr,
uint32_t location,
const sem::Type* type,
const type::Type* type,
utils::Hashset<uint32_t, 8>& locations,
ast::PipelineStage stage,
const Source& source,
@@ -2166,8 +2167,8 @@ bool Validator::LocationAttribute(const ast::LocationAttribute* loc_attr,
}
bool Validator::Return(const ast::ReturnStatement* ret,
const sem::Type* func_type,
const sem::Type* ret_type,
const type::Type* func_type,
const type::Type* ret_type,
sem::Statement* current_statement) const {
if (func_type->UnwrapRef() != ret_type) {
AddError("return statement type must match its function return type, returned '" +
@@ -2246,7 +2247,7 @@ bool Validator::SwitchStatement(const ast::SwitchStatement* s) {
return true;
}
bool Validator::Assignment(const ast::Statement* a, const sem::Type* rhs_ty) const {
bool Validator::Assignment(const ast::Statement* a, const type::Type* rhs_ty) const {
const ast::Expression* lhs;
const ast::Expression* rhs;
if (auto* assign = a->As<ast::AssignmentStatement>()) {
@@ -2390,7 +2391,7 @@ bool Validator::IsValidationEnabled(utils::VectorRef<const ast::Attribute*> attr
return !IsValidationDisabled(attributes, validation);
}
bool Validator::IsArrayWithOverrideCount(const sem::Type* ty) const {
bool Validator::IsArrayWithOverrideCount(const type::Type* ty) const {
if (auto* arr = ty->UnwrapRef()->As<sem::Array>()) {
if (arr->Count()->IsAnyOf<sem::NamedOverrideArrayCount, sem::UnnamedOverrideArrayCount>()) {
return true;
@@ -2406,13 +2407,13 @@ void Validator::RaiseArrayWithOverrideCountError(const Source& source) const {
source);
}
std::string Validator::VectorPretty(uint32_t size, const sem::Type* element_type) const {
std::string Validator::VectorPretty(uint32_t size, const type::Type* element_type) const {
sem::Vector vec_type(element_type, size);
return vec_type.FriendlyName(symbols_);
}
bool Validator::CheckTypeAccessAddressSpace(
const sem::Type* store_ty,
const type::Type* store_ty,
ast::Access access,
ast::AddressSpace address_space,
utils::VectorRef<const tint::ast::Attribute*> attributes,

View File

@@ -70,7 +70,7 @@ namespace tint::resolver {
/// TypeAndAddressSpace is a pair of type and address space
struct TypeAndAddressSpace {
/// The type
const sem::Type* type;
const type::Type* type;
/// The address space
ast::AddressSpace address_space;
@@ -97,7 +97,7 @@ class Validator {
Validator(ProgramBuilder* builder,
SemHelper& helper,
const ast::Extensions& enabled_extensions,
const utils::Hashmap<const sem::Type*, const Source*, 8>& atomic_composite_info,
const utils::Hashmap<const type::Type*, const Source*, 8>& atomic_composite_info,
utils::Hashset<TypeAndAddressSpace, 8>& valid_type_storage_layouts);
~Validator();
@@ -118,19 +118,19 @@ class Validator {
/// @param type the given type
/// @returns true if the given type is a plain type
bool IsPlain(const sem::Type* type) const;
bool IsPlain(const type::Type* type) const;
/// @param type the given type
/// @returns true if the given type is a fixed-footprint type
bool IsFixedFootprint(const sem::Type* type) const;
bool IsFixedFootprint(const type::Type* type) const;
/// @param type the given type
/// @returns true if the given type is storable
bool IsStorable(const sem::Type* type) const;
bool IsStorable(const type::Type* type) const;
/// @param type the given type
/// @returns true if the given type is host-shareable
bool IsHostShareable(const sem::Type* type) const;
bool IsHostShareable(const type::Type* type) const;
/// Validates pipeline stages
/// @param entry_points the entry points to the module
@@ -179,13 +179,13 @@ class Validator {
/// @param a the assignment statement
/// @param rhs_ty the type of the right hand side
/// @returns true on success, false otherwise.
bool Assignment(const ast::Statement* a, const sem::Type* rhs_ty) const;
bool Assignment(const ast::Statement* a, const type::Type* rhs_ty) const;
/// Validates a bitcase
/// @param cast the bitcast expression
/// @param to the destination type
/// @returns true on success, false otherwise
bool Bitcast(const ast::BitcastExpression* cast, const sem::Type* to) const;
bool Bitcast(const ast::BitcastExpression* cast, const type::Type* to) const;
/// Validates a break statement
/// @param stmt the break statement to validate
@@ -200,7 +200,7 @@ class Validator {
/// @param is_input true if this is an input attribute
/// @returns true on success, false otherwise.
bool BuiltinAttribute(const ast::BuiltinAttribute* attr,
const sem::Type* storage_type,
const type::Type* storage_type,
ast::PipelineStage stage,
const bool is_input) const;
@@ -283,7 +283,7 @@ class Validator {
/// @param storage_type the storage type of the attached variable
/// @returns true on succes, false otherwise
bool InterpolateAttribute(const ast::InterpolateAttribute* attr,
const sem::Type* storage_type) const;
const type::Type* storage_type) const;
/// Validates a builtin call
/// @param call the builtin call to validate
@@ -306,7 +306,7 @@ class Validator {
/// @returns true on success, false otherwise.
bool LocationAttribute(const ast::LocationAttribute* loc_attr,
uint32_t location,
const sem::Type* type,
const type::Type* type,
utils::Hashset<uint32_t, 8>& locations,
ast::PipelineStage stage,
const Source& source,
@@ -322,7 +322,7 @@ class Validator {
/// @param from the abstract numeric type
/// @param source the source of the materialization
/// @returns true on success, false otherwise
bool Materialize(const sem::Type* to, const sem::Type* from, const Source& source) const;
bool Materialize(const type::Type* to, const type::Type* from, const Source& source) const;
/// Validates a matrix
/// @param ty the matrix to validate
@@ -343,8 +343,8 @@ class Validator {
/// @param current_statement the current statement being resolved
/// @returns true on success, false otherwise
bool Return(const ast::ReturnStatement* ret,
const sem::Type* func_type,
const sem::Type* ret_type,
const type::Type* func_type,
const type::Type* ret_type,
sem::Statement* current_statement) const;
/// Validates a list of statements
@@ -417,7 +417,7 @@ class Validator {
/// @returns true on succes, false otherwise
bool VariableInitializer(const ast::Variable* v,
ast::AddressSpace address_space,
const sem::Type* storage_type,
const type::Type* storage_type,
const sem::Expression* initializer) const;
/// Validates a vector
@@ -452,7 +452,7 @@ class Validator {
/// @param sc the address space
/// @param source the source of the type
/// @returns true on success, false otherwise
bool AddressSpaceLayout(const sem::Type* type, ast::AddressSpace sc, Source source) const;
bool AddressSpaceLayout(const type::Type* type, ast::AddressSpace sc, Source source) const;
/// @returns true if the attribute list contains a
/// ast::DisableValidationAttribute with the validation mode equal to
@@ -474,7 +474,7 @@ class Validator {
/// @param ty the type to check
/// @returns true if @p ty is an array with an `override` expression element count, otherwise
/// false.
bool IsArrayWithOverrideCount(const sem::Type* ty) const;
bool IsArrayWithOverrideCount(const type::Type* ty) const;
/// Raises an error about an array type using an `override` expression element count, outside
/// the single allowed use of a `var<workgroup>`.
@@ -496,7 +496,7 @@ class Validator {
/// @param size the vector dimension
/// @param element_type scalar vector sub-element type
/// @return pretty string representation
std::string VectorPretty(uint32_t size, const sem::Type* element_type) const;
std::string VectorPretty(uint32_t size, const type::Type* element_type) const;
/// Raises an error if combination of @p store_ty, @p access and @p address_space are not valid
/// for a `var` or `ptr` declaration.
@@ -505,7 +505,7 @@ class Validator {
/// @param address_space the var or pointer address space
/// @param source the source for the error
/// @returns true on success, false if an error was raised.
bool CheckTypeAccessAddressSpace(const sem::Type* store_ty,
bool CheckTypeAccessAddressSpace(const type::Type* store_ty,
ast::Access access,
ast::AddressSpace address_space,
utils::VectorRef<const tint::ast::Attribute*> attributes,
@@ -514,7 +514,7 @@ class Validator {
diag::List& diagnostics_;
SemHelper& sem_;
const ast::Extensions& enabled_extensions_;
const utils::Hashmap<const sem::Type*, const Source*, 8>& atomic_composite_info_;
const utils::Hashmap<const type::Type*, const Source*, 8>& atomic_composite_info_;
utils::Hashset<TypeAndAddressSpace, 8>& valid_type_storage_layouts_;
};

View File

@@ -89,14 +89,14 @@ TEST_F(ValidatorIsStorableTest, Atomic) {
}
TEST_F(ValidatorIsStorableTest, ArraySizedOfStorable) {
auto* arr = create<sem::Array>(create<sem::I32>(), create<sem::ConstantArrayCount>(5u), 4u, 20u,
4u, 4u);
auto* arr = create<sem::Array>(create<sem::I32>(), create<type::ConstantArrayCount>(5u), 4u,
20u, 4u, 4u);
EXPECT_TRUE(v()->IsStorable(arr));
}
TEST_F(ValidatorIsStorableTest, ArrayUnsizedOfStorable) {
auto* arr =
create<sem::Array>(create<sem::I32>(), create<sem::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
create<sem::Array>(create<sem::I32>(), create<type::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
EXPECT_TRUE(v()->IsStorable(arr));
}