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

@@ -41,7 +41,7 @@ Transform::ApplyResult AddBlockAttribute::Apply(const Program* src,
// A map from a type in the source program to a block-decorated wrapper that contains it in the
// destination program.
utils::Hashmap<const sem::Type*, const ast::Struct*, 8> wrapper_structs;
utils::Hashmap<const type::Type*, const ast::Struct*, 8> wrapper_structs;
// Process global 'var' declarations that are buffers.
bool made_changes = false;

View File

@@ -32,7 +32,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::transform::BuiltinPolyfill::Config);
namespace tint::transform {
/// BinaryOpSignature is tuple of a binary op, LHS type and RHS type
using BinaryOpSignature = std::tuple<ast::BinaryOp, const sem::Type*, const sem::Type*>;
using BinaryOpSignature = std::tuple<ast::BinaryOp, const type::Type*, const type::Type*>;
/// PIMPL state for the transform
struct BuiltinPolyfill::State {
@@ -48,7 +48,7 @@ struct BuiltinPolyfill::State {
/// Builds the polyfill function for the `acosh` builtin
/// @param ty the parameter and return type for the function
/// @return the polyfill function name
Symbol acosh(const sem::Type* ty) {
Symbol acosh(const type::Type* ty) {
auto name = b.Symbols().New("tint_acosh");
uint32_t width = WidthOf(ty);
@@ -87,7 +87,7 @@ struct BuiltinPolyfill::State {
/// Builds the polyfill function for the `asinh` builtin
/// @param ty the parameter and return type for the function
/// @return the polyfill function name
Symbol asinh(const sem::Type* ty) {
Symbol asinh(const type::Type* ty) {
auto name = b.Symbols().New("tint_sinh");
// return log(x + sqrt(x*x + 1));
@@ -102,7 +102,7 @@ struct BuiltinPolyfill::State {
/// Builds the polyfill function for the `atanh` builtin
/// @param ty the parameter and return type for the function
/// @return the polyfill function name
Symbol atanh(const sem::Type* ty) {
Symbol atanh(const type::Type* ty) {
auto name = b.Symbols().New("tint_atanh");
uint32_t width = WidthOf(ty);
@@ -141,7 +141,7 @@ struct BuiltinPolyfill::State {
/// (scalar or vector)
/// @param ty the parameter and return type for the function
/// @return the polyfill function name
Symbol clampInteger(const sem::Type* ty) {
Symbol clampInteger(const type::Type* ty) {
auto name = b.Symbols().New("tint_clamp");
b.Func(name,
@@ -161,7 +161,7 @@ struct BuiltinPolyfill::State {
/// Builds the polyfill function for the `countLeadingZeros` builtin
/// @param ty the parameter and return type for the function
/// @return the polyfill function name
Symbol countLeadingZeros(const sem::Type* ty) {
Symbol countLeadingZeros(const type::Type* ty) {
auto name = b.Symbols().New("tint_count_leading_zeros");
uint32_t width = WidthOf(ty);
@@ -219,7 +219,7 @@ struct BuiltinPolyfill::State {
/// Builds the polyfill function for the `countTrailingZeros` builtin
/// @param ty the parameter and return type for the function
/// @return the polyfill function name
Symbol countTrailingZeros(const sem::Type* ty) {
Symbol countTrailingZeros(const type::Type* ty) {
auto name = b.Symbols().New("tint_count_trailing_zeros");
uint32_t width = WidthOf(ty);
@@ -279,7 +279,7 @@ struct BuiltinPolyfill::State {
/// Builds the polyfill function for the `extractBits` builtin
/// @param ty the parameter and return type for the function
/// @return the polyfill function name
Symbol extractBits(const sem::Type* ty) {
Symbol extractBits(const type::Type* ty) {
auto name = b.Symbols().New("tint_extract_bits");
uint32_t width = WidthOf(ty);
@@ -337,7 +337,7 @@ struct BuiltinPolyfill::State {
/// Builds the polyfill function for the `firstLeadingBit` builtin
/// @param ty the parameter and return type for the function
/// @return the polyfill function name
Symbol firstLeadingBit(const sem::Type* ty) {
Symbol firstLeadingBit(const type::Type* ty) {
auto name = b.Symbols().New("tint_first_leading_bit");
uint32_t width = WidthOf(ty);
@@ -409,7 +409,7 @@ struct BuiltinPolyfill::State {
/// Builds the polyfill function for the `firstTrailingBit` builtin
/// @param ty the parameter and return type for the function
/// @return the polyfill function name
Symbol firstTrailingBit(const sem::Type* ty) {
Symbol firstTrailingBit(const type::Type* ty) {
auto name = b.Symbols().New("tint_first_trailing_bit");
uint32_t width = WidthOf(ty);
@@ -468,12 +468,12 @@ struct BuiltinPolyfill::State {
/// Builds the polyfill function for the `insertBits` builtin
/// @param ty the parameter and return type for the function
/// @return the polyfill function name
Symbol insertBits(const sem::Type* ty) {
Symbol insertBits(const type::Type* ty) {
auto name = b.Symbols().New("tint_insert_bits");
uint32_t width = WidthOf(ty);
// Currently in WGSL parameters of insertBits must be i32, u32, vecN<i32> or vecN<u32>
if (!sem::Type::DeepestElementOf(ty)->IsAnyOf<sem::I32, sem::U32>()) {
if (!type::Type::DeepestElementOf(ty)->IsAnyOf<sem::I32, sem::U32>()) {
TINT_ICE(Transform, b.Diagnostics())
<< "insertBits polyfill only support i32, u32, and vector of i32 or u32, got "
<< b.FriendlyName(ty);
@@ -576,7 +576,7 @@ struct BuiltinPolyfill::State {
/// Builds the polyfill function for the `saturate` builtin
/// @param ty the parameter and return type for the function
/// @return the polyfill function name
Symbol saturate(const sem::Type* ty) {
Symbol saturate(const type::Type* ty) {
auto name = b.Symbols().New("tint_saturate");
auto body = utils::Vector{
b.Return(b.Call("clamp", "v", b.Construct(T(ty), 0_a), b.Construct(T(ty), 1_a))),
@@ -593,7 +593,7 @@ struct BuiltinPolyfill::State {
/// Builds the polyfill function for the `sign` builtin when the element type is integer
/// @param ty the parameter and return type for the function
/// @return the polyfill function name
Symbol sign_int(const sem::Type* ty) {
Symbol sign_int(const type::Type* ty) {
const uint32_t width = WidthOf(ty);
auto zero = [&] { return ScalarOrVector(width, 0_a); };
@@ -671,7 +671,7 @@ struct BuiltinPolyfill::State {
const ast::Expression* BitshiftModulo(const ast::BinaryExpression* bin_op) {
auto* lhs_ty = ctx.src->TypeOf(bin_op->lhs)->UnwrapRef();
auto* rhs_ty = ctx.src->TypeOf(bin_op->rhs)->UnwrapRef();
auto* lhs_el_ty = sem::Type::DeepestElementOf(lhs_ty);
auto* lhs_el_ty = type::Type::DeepestElementOf(lhs_ty);
const ast::Expression* mask = b.Expr(AInt(lhs_el_ty->Size() * 8 - 1));
if (rhs_ty->Is<sem::Vector>()) {
mask = b.Construct(CreateASTTypeFor(ctx, rhs_ty), mask);
@@ -694,8 +694,8 @@ struct BuiltinPolyfill::State {
uint32_t lhs_width = 1;
uint32_t rhs_width = 1;
const auto* lhs_el_ty = sem::Type::ElementOf(lhs_ty, &lhs_width);
const auto* rhs_el_ty = sem::Type::ElementOf(rhs_ty, &rhs_width);
const auto* lhs_el_ty = type::Type::ElementOf(lhs_ty, &lhs_width);
const auto* rhs_el_ty = type::Type::ElementOf(rhs_ty, &rhs_width);
const uint32_t width = std::max(lhs_width, rhs_width);
@@ -757,10 +757,10 @@ struct BuiltinPolyfill::State {
utils::Hashmap<BinaryOpSignature, Symbol, 8> binary_op_polyfills;
/// @returns the AST type for the given sem type
const ast::Type* T(const sem::Type* ty) const { return CreateASTTypeFor(ctx, ty); }
const ast::Type* T(const type::Type* ty) const { return CreateASTTypeFor(ctx, ty); }
/// @returns 1 if `ty` is not a vector, otherwise the vector width
uint32_t WidthOf(const sem::Type* ty) const {
uint32_t WidthOf(const type::Type* ty) const {
if (auto* v = ty->As<sem::Vector>()) {
return v->Width();
}

View File

@@ -207,7 +207,7 @@ struct CanonicalizeEntryPointIO::State {
/// @param attributes the attributes to apply to the shader input
/// @returns an expression which evaluates to the value of the shader input
const ast::Expression* AddInput(std::string name,
const sem::Type* type,
const type::Type* type,
std::optional<uint32_t> location,
utils::Vector<const ast::Attribute*, 8> attributes) {
auto* ast_type = CreateASTTypeFor(ctx, type);
@@ -278,7 +278,7 @@ struct CanonicalizeEntryPointIO::State {
/// @param attributes the attributes to apply to the shader output
/// @param value the value of the shader output
void AddOutput(std::string name,
const sem::Type* type,
const type::Type* type,
std::optional<uint32_t> location,
utils::Vector<const ast::Attribute*, 8> attributes,
const ast::Expression* value) {
@@ -378,7 +378,7 @@ struct CanonicalizeEntryPointIO::State {
/// function.
/// @param inner_ret_type the original function return type
/// @param original_result the result object produced by the original function
void ProcessReturnType(const sem::Type* inner_ret_type, Symbol original_result) {
void ProcessReturnType(const type::Type* inner_ret_type, Symbol original_result) {
// Do not add interpolation attributes on fragment output
bool do_interpolate = func_ast->PipelineStage() != ast::PipelineStage::kFragment;
if (auto* str = inner_ret_type->As<sem::Struct>()) {
@@ -754,7 +754,7 @@ struct CanonicalizeEntryPointIO::State {
/// @returns the converted value which can be assigned to the GLSL builtin
const ast::Expression* ToGLSLBuiltin(ast::BuiltinValue builtin,
const ast::Expression* value,
const sem::Type*& type) {
const type::Type*& type) {
switch (builtin) {
case ast::BuiltinValue::kVertexIndex:
case ast::BuiltinValue::kInstanceIndex:

View File

@@ -140,7 +140,7 @@ struct CombineSamplers::State {
/// @returns the newly-created type
const ast::Type* CreateCombinedASTTypeFor(const sem::Variable* texture,
const sem::Variable* sampler) {
const sem::Type* texture_type = texture->Type()->UnwrapRef();
const type::Type* texture_type = texture->Type()->UnwrapRef();
const sem::DepthTexture* depth = texture_type->As<sem::DepthTexture>();
if (depth && !sampler) {
return ctx.dst->create<ast::SampledTexture>(depth->dim(), ctx.dst->create<ast::F32>());

View File

@@ -111,8 +111,8 @@ struct OffsetBinOp : Offset {
struct LoadStoreKey {
ast::AddressSpace const address_space; // buffer address space
ast::Access const access; // buffer access
sem::Type const* buf_ty = nullptr; // buffer type
sem::Type const* el_ty = nullptr; // element type
type::Type const* buf_ty = nullptr; // buffer type
type::Type const* el_ty = nullptr; // element type
bool operator==(const LoadStoreKey& rhs) const {
return address_space == rhs.address_space && access == rhs.access && buf_ty == rhs.buf_ty &&
el_ty == rhs.el_ty;
@@ -127,8 +127,8 @@ struct LoadStoreKey {
/// AtomicKey is the unordered map key to an atomic intrinsic.
struct AtomicKey {
ast::Access const access; // buffer access
sem::Type const* buf_ty = nullptr; // buffer type
sem::Type const* el_ty = nullptr; // element type
type::Type const* buf_ty = nullptr; // buffer type
type::Type const* el_ty = nullptr; // element type
sem::BuiltinType const op; // atomic op
bool operator==(const AtomicKey& rhs) const {
return access == rhs.access && buf_ty == rhs.buf_ty && el_ty == rhs.el_ty && op == rhs.op;
@@ -140,7 +140,7 @@ struct AtomicKey {
};
};
bool IntrinsicDataTypeFor(const sem::Type* ty, DecomposeMemoryAccess::Intrinsic::DataType& out) {
bool IntrinsicDataTypeFor(const type::Type* ty, DecomposeMemoryAccess::Intrinsic::DataType& out) {
if (ty->Is<sem::I32>()) {
out = DecomposeMemoryAccess::Intrinsic::DataType::kI32;
return true;
@@ -224,7 +224,7 @@ bool IntrinsicDataTypeFor(const sem::Type* ty, DecomposeMemoryAccess::Intrinsic:
/// to a stub function to load the type `ty`.
DecomposeMemoryAccess::Intrinsic* IntrinsicLoadFor(ProgramBuilder* builder,
ast::AddressSpace address_space,
const sem::Type* ty) {
const type::Type* ty) {
DecomposeMemoryAccess::Intrinsic::DataType type;
if (!IntrinsicDataTypeFor(ty, type)) {
return nullptr;
@@ -238,7 +238,7 @@ DecomposeMemoryAccess::Intrinsic* IntrinsicLoadFor(ProgramBuilder* builder,
/// to a stub function to store the type `ty`.
DecomposeMemoryAccess::Intrinsic* IntrinsicStoreFor(ProgramBuilder* builder,
ast::AddressSpace address_space,
const sem::Type* ty) {
const type::Type* ty) {
DecomposeMemoryAccess::Intrinsic::DataType type;
if (!IntrinsicDataTypeFor(ty, type)) {
return nullptr;
@@ -252,7 +252,7 @@ DecomposeMemoryAccess::Intrinsic* IntrinsicStoreFor(ProgramBuilder* builder,
/// to a stub function for the atomic op and the type `ty`.
DecomposeMemoryAccess::Intrinsic* IntrinsicAtomicFor(ProgramBuilder* builder,
sem::BuiltinType ity,
const sem::Type* ty) {
const type::Type* ty) {
auto op = DecomposeMemoryAccess::Intrinsic::Op::kAtomicLoad;
switch (ity) {
case sem::BuiltinType::kAtomicLoad:
@@ -307,7 +307,7 @@ DecomposeMemoryAccess::Intrinsic* IntrinsicAtomicFor(ProgramBuilder* builder,
struct BufferAccess {
sem::Expression const* var = nullptr; // Storage buffer variable
Offset const* offset = nullptr; // The byte offset on var
sem::Type const* type = nullptr; // The type of the access
type::Type const* type = nullptr; // The type of the access
operator bool() const { return var; } // Returns true if valid
};
@@ -461,8 +461,8 @@ struct DecomposeMemoryAccess::State {
/// @param el_ty the storage or uniform buffer element type
/// @param var_user the variable user
/// @return the name of the function that performs the load
Symbol LoadFunc(const sem::Type* buf_ty,
const sem::Type* el_ty,
Symbol LoadFunc(const type::Type* buf_ty,
const type::Type* el_ty,
const sem::VariableUser* var_user) {
auto address_space = var_user->Variable()->AddressSpace();
auto access = var_user->Variable()->Access();
@@ -560,8 +560,8 @@ struct DecomposeMemoryAccess::State {
/// @param el_ty the storage buffer element type
/// @param var_user the variable user
/// @return the name of the function that performs the store
Symbol StoreFunc(const sem::Type* buf_ty,
const sem::Type* el_ty,
Symbol StoreFunc(const type::Type* buf_ty,
const type::Type* el_ty,
const sem::VariableUser* var_user) {
auto address_space = var_user->Variable()->AddressSpace();
auto access = var_user->Variable()->Access();
@@ -671,8 +671,8 @@ struct DecomposeMemoryAccess::State {
/// @param intrinsic the atomic intrinsic
/// @param var_user the variable user
/// @return the name of the function that performs the load
Symbol AtomicFunc(const sem::Type* buf_ty,
const sem::Type* el_ty,
Symbol AtomicFunc(const type::Type* buf_ty,
const type::Type* el_ty,
const sem::Builtin* intrinsic,
const sem::VariableUser* var_user) {
auto op = intrinsic->Type();

View File

@@ -104,7 +104,7 @@ Transform::ApplyResult DemoteToHelper::Apply(const Program* src, const DataMap&,
// Mask all writes to host-visible memory using the discarded flag.
// We also insert a discard statement before all return statements in entry points for shaders
// that discard.
std::unordered_map<const sem::Type*, Symbol> atomic_cmpxchg_result_types;
std::unordered_map<const type::Type*, Symbol> atomic_cmpxchg_result_types;
for (auto* node : src->ASTNodes().Objects()) {
Switch(
node,

View File

@@ -45,7 +45,7 @@ struct AccessRoot {
/// The pointer-unwrapped type of the *transformed* variable.
/// This may be different for pointers in 'private' and 'function' address space, as the pointer
/// parameter type is to the *base object* instead of the input pointer type.
tint::sem::Type const* type = nullptr;
tint::type::Type const* type = nullptr;
/// The originating module-scope variable ('private', 'storage', 'uniform', 'workgroup'),
/// function-scope variable ('function'), or pointer parameter in the source program.
tint::sem::Variable const* variable = nullptr;

View File

@@ -172,7 +172,7 @@ struct LocalizeStructArrayAssignment::State {
// Returns the type and address space of the originating variable of the lhs
// of the assignment statement.
// See https://www.w3.org/TR/WGSL/#originating-variable-section
std::pair<const sem::Type*, ast::AddressSpace> GetOriginatingTypeAndAddressSpace(
std::pair<const type::Type*, ast::AddressSpace> GetOriginatingTypeAndAddressSpace(
const ast::AssignmentStatement* assign_stmt) {
auto* root_ident = src->Sem().Get(assign_stmt->lhs)->RootIdentifier();
if (!root_ident) {

View File

@@ -48,7 +48,7 @@ bool ShouldRun(const Program* program) {
}
// Returns `true` if `type` is or contains a matrix type.
bool ContainsMatrix(const sem::Type* type) {
bool ContainsMatrix(const type::Type* type) {
type = type->UnwrapRef();
if (type->Is<sem::Matrix>()) {
return true;
@@ -78,7 +78,7 @@ struct ModuleScopeVarToEntryPointParam::State {
/// and add it to the global declarations now, so that they precede new global
/// declarations that need to reference them.
/// @param ty the type to clone
void CloneStructTypes(const sem::Type* ty) {
void CloneStructTypes(const type::Type* ty) {
if (auto* str = ty->As<sem::Struct>()) {
if (!cloned_structs_.emplace(str).second) {
// The struct has already been cloned.
@@ -147,7 +147,7 @@ struct ModuleScopeVarToEntryPointParam::State {
auto* param_type = store_type();
if (auto* arr = ty->As<sem::Array>();
arr && arr->Count()->Is<sem::RuntimeArrayCount>()) {
arr && arr->Count()->Is<type::RuntimeArrayCount>()) {
// Wrap runtime-sized arrays in structures, so that we can declare pointers to
// them. Ideally we'd just emit the array itself as a pointer, but this is not
// representable in Tint's AST.

View File

@@ -84,7 +84,7 @@ Transform::ApplyResult PadStructs::Apply(const Program* src, const DataMap&, Dat
// std140 structs should be padded out to 16 bytes.
size = utils::RoundUp(16u, size);
} else if (auto* array_ty = ty->As<sem::Array>()) {
if (array_ty->Count()->Is<sem::RuntimeArrayCount>()) {
if (array_ty->Count()->Is<type::RuntimeArrayCount>()) {
has_runtime_sized_array = true;
}
}

View File

@@ -94,7 +94,7 @@ struct PreservePadding::State {
/// @param lhs the lhs expression (in the destination program)
/// @param rhs the rhs expression (in the destination program)
/// @returns the statement that performs the assignment
const ast::Statement* MakeAssignment(const sem::Type* ty,
const ast::Statement* MakeAssignment(const type::Type* ty,
const ast::Expression* lhs,
const ast::Expression* rhs) {
if (!HasPadding(ty)) {
@@ -168,7 +168,7 @@ struct PreservePadding::State {
/// Checks if a type contains padding bytes.
/// @param ty the type to check
/// @returns true if `ty` (or any of its contained types) have padding bytes
bool HasPadding(const sem::Type* ty) {
bool HasPadding(const type::Type* ty) {
return Switch(
ty, //
[&](const sem::Array* arr) {
@@ -214,7 +214,7 @@ struct PreservePadding::State {
/// Flag to track whether we have already enabled the full pointer parameters extension.
bool ext_enabled = false;
/// Map of semantic types to their assignment helper functions.
utils::Hashmap<const sem::Type*, Symbol, 8> helpers;
utils::Hashmap<const type::Type*, Symbol, 8> helpers;
};
Transform::ApplyResult PreservePadding::Apply(const Program* program,

View File

@@ -33,7 +33,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::transform::RemovePhonies);
namespace tint::transform {
namespace {
using SinkSignature = std::vector<const sem::Type*>;
using SinkSignature = std::vector<const type::Type*>;
} // namespace

View File

@@ -106,7 +106,7 @@ struct Robustness::State {
},
[&](const sem::Array* arr) -> const ast::Expression* {
const ast::Expression* max = nullptr;
if (arr->Count()->Is<sem::RuntimeArrayCount>()) {
if (arr->Count()->Is<type::RuntimeArrayCount>()) {
// Size is unknown until runtime.
// Must clamp, even if the index is constant.
auto* arr_ptr = b.AddressOf(ctx.Clone(expr->object));
@@ -176,7 +176,7 @@ struct Robustness::State {
auto* coords_arg = expr->args[static_cast<size_t>(coords_idx)];
auto* coords_ty = builtin->Parameters()[static_cast<size_t>(coords_idx)]->Type();
auto width_of = [&](const sem::Type* ty) {
auto width_of = [&](const type::Type* ty) {
if (auto* vec = ty->As<sem::Vector>()) {
return vec->Width();
}

View File

@@ -198,14 +198,14 @@ struct SpirvAtomic::State {
}
}
const ast::Type* AtomicTypeFor(const sem::Type* ty) {
const ast::Type* AtomicTypeFor(const type::Type* ty) {
return Switch(
ty, //
[&](const sem::I32*) { return b.ty.atomic(CreateASTTypeFor(ctx, ty)); },
[&](const sem::U32*) { return b.ty.atomic(CreateASTTypeFor(ctx, ty)); },
[&](const sem::Struct* str) { return b.ty.type_name(Fork(str->Declaration()).name); },
[&](const sem::Array* arr) -> const ast::Type* {
if (arr->Count()->Is<sem::RuntimeArrayCount>()) {
if (arr->Count()->Is<type::RuntimeArrayCount>()) {
return b.ty.array(AtomicTypeFor(arr->ElemType()));
}
auto count = arr->ConstantCount();

View File

@@ -128,7 +128,7 @@ struct Std140::State {
/// @returns true if this transform should be run for the given program
bool ShouldRun() const {
// Returns true if the type needs to be forked for std140 usage.
auto needs_fork = [&](const sem::Type* ty) {
auto needs_fork = [&](const type::Type* ty) {
while (auto* arr = ty->As<sem::Array>()) {
ty = arr->ElemType();
}
@@ -218,7 +218,7 @@ struct Std140::State {
utils::Hashmap<LoadFnKey, Symbol, 8, LoadFnKey::Hasher> load_fns;
/// Map of std140-forked type to converter function name
utils::Hashmap<const sem::Type*, Symbol, 8> conv_fns;
utils::Hashmap<const type::Type*, Symbol, 8> conv_fns;
// Uniform variables that have been modified to use a std140 type
utils::Hashset<const sem::Variable*, 8> std140_uniforms;
@@ -397,7 +397,7 @@ struct Std140::State {
/// If the semantic type is not split for std140-layout, then nullptr is returned.
/// @note will construct new std140 structures to hold decomposed matrices, populating
/// #std140_mats.
const ast::Type* Std140Type(const sem::Type* ty) {
const ast::Type* Std140Type(const type::Type* ty) {
return Switch(
ty, //
[&](const sem::Struct* str) -> const ast::Type* {
@@ -625,7 +625,7 @@ struct Std140::State {
/// @returns a name suffix for a std140 -> non-std140 conversion function based on the type
/// being converted.
const std::string ConvertSuffix(const sem::Type* ty) {
const std::string ConvertSuffix(const type::Type* ty) {
return Switch(
ty, //
[&](const sem::Struct* str) { return sym.NameFor(str->Name()); },
@@ -659,7 +659,7 @@ struct Std140::State {
/// @param chain the access chain from a uniform buffer to the value to load.
const ast::Expression* LoadWithConvert(const AccessChain& chain) {
const ast::Expression* expr = nullptr;
const sem::Type* ty = nullptr;
const type::Type* ty = nullptr;
auto dynamic_index = [&](size_t idx) {
return ctx.Clone(chain.dynamic_indices[idx]->Declaration());
};
@@ -675,7 +675,7 @@ struct Std140::State {
/// std140-forked type to the type @p ty. If @p expr is not a std140-forked type, then Convert()
/// will simply return @p expr.
/// @returns the converted value expression.
const ast::Expression* Convert(const sem::Type* ty, const ast::Expression* expr) {
const ast::Expression* Convert(const type::Type* ty, const ast::Expression* expr) {
// Get an existing, or create a new function for converting the std140 type to ty.
auto fn = conv_fns.GetOrCreate(ty, [&] {
auto std140_ty = Std140Type(ty);
@@ -815,7 +815,7 @@ struct Std140::State {
};
const ast::Expression* expr = nullptr;
const sem::Type* ty = nullptr;
const type::Type* ty = nullptr;
// Build the expression up to, but not including the matrix member
auto std140_mat_idx = *chain.std140_mat_idx;
@@ -889,13 +889,13 @@ struct Std140::State {
utils::Vector<const ast::CaseStatement*, 4> cases;
// The function return type.
const sem::Type* ret_ty = nullptr;
const type::Type* ret_ty = nullptr;
// Build switch() cases for each column of the matrix
auto num_columns = chain.std140_mat_ty->columns();
for (uint32_t column_idx = 0; column_idx < num_columns; column_idx++) {
const ast::Expression* expr = nullptr;
const sem::Type* ty = nullptr;
const type::Type* ty = nullptr;
// Build the expression up to, but not including the matrix
for (size_t i = 0; i < std140_mat_idx; i++) {
@@ -985,7 +985,7 @@ struct Std140::State {
auto dynamic_index = [&](size_t idx) { return b.Expr(dynamic_index_params[idx]->symbol); };
const ast::Expression* expr = nullptr;
const sem::Type* ty = nullptr;
const type::Type* ty = nullptr;
std::string name = "load";
// Build the expression up to, but not including the matrix member
@@ -1048,7 +1048,7 @@ struct Std140::State {
/// The new, post-access expression
const ast::Expression* expr;
/// The type of #expr
const sem::Type* type;
const type::Type* type;
/// A name segment which can be used to build sensible names for helper functions
std::string name;
};
@@ -1061,7 +1061,7 @@ struct Std140::State {
/// @returns a ExprTypeName which holds the new expression, new type and a name segment which
/// can be used for creating helper function names.
ExprTypeName BuildAccessExpr(const ast::Expression* lhs,
const sem::Type* ty,
const type::Type* ty,
const AccessChain& chain,
size_t index,
std::function<const ast::Expression*(size_t)> dynamic_index) {

View File

@@ -73,7 +73,7 @@ void Transform::RemoveStatement(CloneContext& ctx, const ast::Statement* stmt) {
<< "unable to remove statement from parent of type " << sem->TypeInfo().name;
}
const ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const sem::Type* ty) {
const ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const type::Type* ty) {
if (ty->Is<sem::Void>()) {
return ctx.dst->create<ast::Void>();
}
@@ -106,7 +106,7 @@ const ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const sem::Type*
if (!a->IsStrideImplicit()) {
attrs.Push(ctx.dst->create<ast::StrideAttribute>(a->Stride()));
}
if (a->Count()->Is<sem::RuntimeArrayCount>()) {
if (a->Count()->Is<type::RuntimeArrayCount>()) {
return ctx.dst->ty.array(el, nullptr, std::move(attrs));
}
if (auto* override = a->Count()->As<sem::NamedOverrideArrayCount>()) {

View File

@@ -195,7 +195,7 @@ class Transform : public Castable<Transform> {
/// @param ty the semantic type to reconstruct
/// @returns a ast::Type that when resolved, will produce the semantic type
/// `ty`.
static const ast::Type* CreateASTTypeFor(CloneContext& ctx, const sem::Type* ty);
static const ast::Type* CreateASTTypeFor(CloneContext& ctx, const type::Type* ty);
};
} // namespace tint::transform

View File

@@ -29,7 +29,7 @@ struct CreateASTTypeForTest : public testing::Test, public Transform {
return SkipTransform;
}
const ast::Type* create(std::function<sem::Type*(ProgramBuilder&)> create_sem_type) {
const ast::Type* create(std::function<type::Type*(ProgramBuilder&)> create_sem_type) {
ProgramBuilder sem_type_builder;
auto* sem_type = create_sem_type(sem_type_builder);
Program program(std::move(sem_type_builder));
@@ -69,8 +69,8 @@ TEST_F(CreateASTTypeForTest, Vector) {
TEST_F(CreateASTTypeForTest, ArrayImplicitStride) {
auto* arr = create([](ProgramBuilder& b) {
return b.create<sem::Array>(b.create<sem::F32>(), b.create<sem::ConstantArrayCount>(2u), 4u,
4u, 32u, 32u);
return b.create<sem::Array>(b.create<sem::F32>(), b.create<type::ConstantArrayCount>(2u),
4u, 4u, 32u, 32u);
});
ASSERT_TRUE(arr->Is<ast::Array>());
ASSERT_TRUE(arr->As<ast::Array>()->type->Is<ast::F32>());
@@ -83,8 +83,8 @@ TEST_F(CreateASTTypeForTest, ArrayImplicitStride) {
TEST_F(CreateASTTypeForTest, ArrayNonImplicitStride) {
auto* arr = create([](ProgramBuilder& b) {
return b.create<sem::Array>(b.create<sem::F32>(), b.create<sem::ConstantArrayCount>(2u), 4u,
4u, 64u, 32u);
return b.create<sem::Array>(b.create<sem::F32>(), b.create<type::ConstantArrayCount>(2u),
4u, 4u, 64u, 32u);
});
ASSERT_TRUE(arr->Is<ast::Array>());
ASSERT_TRUE(arr->As<ast::Array>()->type->Is<ast::F32>());

View File

@@ -150,7 +150,7 @@ bool IsTypeCompatible(AttributeWGSLType wgslType, VertexFormatType vertexFormatT
}
}
AttributeWGSLType WGSLTypeOf(const sem::Type* ty) {
AttributeWGSLType WGSLTypeOf(const type::Type* ty) {
return Switch(
ty,
[](const sem::I32*) -> AttributeWGSLType {
@@ -273,7 +273,7 @@ struct VertexPulling::State {
/// A builder that builds the expression that resolves to the (transformed) input location
std::function<const ast::Expression*()> expr;
/// The store type of the location variable
const sem::Type* type;
const type::Type* type;
};
/// The source program

View File

@@ -290,7 +290,7 @@ struct ZeroInitWorkgroupMemory::State {
/// @param ty the expression type
/// @param get_expr a function that builds the AST nodes for the expression.
/// @returns true on success, false on failure
[[nodiscard]] bool BuildZeroingStatements(const sem::Type* ty,
[[nodiscard]] bool BuildZeroingStatements(const type::Type* ty,
const BuildZeroingExpr& get_expr) {
if (CanTriviallyZero(ty)) {
auto var = get_expr(1u);
@@ -438,7 +438,7 @@ struct ZeroInitWorkgroupMemory::State {
/// initialized by decomposing the initialization into multiple
/// sub-initializations.
/// @param ty the type to inspect
bool CanTriviallyZero(const sem::Type* ty) {
bool CanTriviallyZero(const type::Type* ty) {
if (ty->Is<sem::Atomic>()) {
return false;
}