chromium/third_party/dawn/src/tint/lang/wgsl/resolver/resolver.cc

// Copyright 2020 The Dawn & Tint Authors
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
//    list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation
//    and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
//    contributors may be used to endorse or promote products derived from
//    this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "src/tint/lang/wgsl/resolver/resolver.h"
#include <iostream>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string_view>
#include <utility>

#include "src/tint/lang/core/builtin_type.h"
#include "src/tint/lang/core/constant/scalar.h"
#include "src/tint/lang/core/fluent_types.h"
#include "src/tint/lang/core/texel_format.h"
#include "src/tint/lang/core/type/abstract_float.h"
#include "src/tint/lang/core/type/abstract_int.h"
#include "src/tint/lang/core/type/array.h"
#include "src/tint/lang/core/type/atomic.h"
#include "src/tint/lang/core/type/builtin_structs.h"
#include "src/tint/lang/core/type/depth_multisampled_texture.h"
#include "src/tint/lang/core/type/depth_texture.h"
#include "src/tint/lang/core/type/external_texture.h"
#include "src/tint/lang/core/type/input_attachment.h"
#include "src/tint/lang/core/type/memory_view.h"
#include "src/tint/lang/core/type/multisampled_texture.h"
#include "src/tint/lang/core/type/pointer.h"
#include "src/tint/lang/core/type/reference.h"
#include "src/tint/lang/core/type/sampled_texture.h"
#include "src/tint/lang/core/type/sampler.h"
#include "src/tint/lang/core/type/storage_texture.h"
#include "src/tint/lang/wgsl/ast/alias.h"
#include "src/tint/lang/wgsl/ast/assignment_statement.h"
#include "src/tint/lang/wgsl/ast/attribute.h"
#include "src/tint/lang/wgsl/ast/break_statement.h"
#include "src/tint/lang/wgsl/ast/call_statement.h"
#include "src/tint/lang/wgsl/ast/continue_statement.h"
#include "src/tint/lang/wgsl/ast/disable_validation_attribute.h"
#include "src/tint/lang/wgsl/ast/discard_statement.h"
#include "src/tint/lang/wgsl/ast/for_loop_statement.h"
#include "src/tint/lang/wgsl/ast/id_attribute.h"
#include "src/tint/lang/wgsl/ast/if_statement.h"
#include "src/tint/lang/wgsl/ast/input_attachment_index_attribute.h"
#include "src/tint/lang/wgsl/ast/internal_attribute.h"
#include "src/tint/lang/wgsl/ast/interpolate_attribute.h"
#include "src/tint/lang/wgsl/ast/loop_statement.h"
#include "src/tint/lang/wgsl/ast/return_statement.h"
#include "src/tint/lang/wgsl/ast/switch_statement.h"
#include "src/tint/lang/wgsl/ast/traverse_expressions.h"
#include "src/tint/lang/wgsl/ast/unary_op_expression.h"
#include "src/tint/lang/wgsl/ast/variable_decl_statement.h"
#include "src/tint/lang/wgsl/ast/while_statement.h"
#include "src/tint/lang/wgsl/ast/workgroup_attribute.h"
#include "src/tint/lang/wgsl/intrinsic/ctor_conv.h"
#include "src/tint/lang/wgsl/intrinsic/dialect.h"
#include "src/tint/lang/wgsl/resolver/incomplete_type.h"
#include "src/tint/lang/wgsl/resolver/uniformity.h"
#include "src/tint/lang/wgsl/resolver/unresolved_identifier.h"
#include "src/tint/lang/wgsl/sem/array.h"
#include "src/tint/lang/wgsl/sem/break_if_statement.h"
#include "src/tint/lang/wgsl/sem/builtin_enum_expression.h"
#include "src/tint/lang/wgsl/sem/call.h"
#include "src/tint/lang/wgsl/sem/for_loop_statement.h"
#include "src/tint/lang/wgsl/sem/function.h"
#include "src/tint/lang/wgsl/sem/function_expression.h"
#include "src/tint/lang/wgsl/sem/if_statement.h"
#include "src/tint/lang/wgsl/sem/index_accessor_expression.h"
#include "src/tint/lang/wgsl/sem/load.h"
#include "src/tint/lang/wgsl/sem/loop_statement.h"
#include "src/tint/lang/wgsl/sem/materialize.h"
#include "src/tint/lang/wgsl/sem/member_accessor_expression.h"
#include "src/tint/lang/wgsl/sem/module.h"
#include "src/tint/lang/wgsl/sem/statement.h"
#include "src/tint/lang/wgsl/sem/struct.h"
#include "src/tint/lang/wgsl/sem/switch_statement.h"
#include "src/tint/lang/wgsl/sem/type_expression.h"
#include "src/tint/lang/wgsl/sem/value_constructor.h"
#include "src/tint/lang/wgsl/sem/value_conversion.h"
#include "src/tint/lang/wgsl/sem/variable.h"
#include "src/tint/lang/wgsl/sem/while_statement.h"
#include "src/tint/utils/containers/reverse.h"
#include "src/tint/utils/containers/transform.h"
#include "src/tint/utils/containers/vector.h"
#include "src/tint/utils/macros/compiler.h"
#include "src/tint/utils/macros/defer.h"
#include "src/tint/utils/macros/scoped_assignment.h"
#include "src/tint/utils/math/math.h"
#include "src/tint/utils/text/string.h"
#include "src/tint/utils/text/string_stream.h"
#include "src/tint/utils/text/styled_text.h"
#include "src/tint/utils/text/text_style.h"

usingnamespacetint::core::fluent_types;  // NOLINT

namespace tint::resolver {
namespace {

/// ICE() is a wrapper around TINT_ICE() that includes a prefixed source location
#define ICE(SOURCE)

CtorConvIntrinsic;
OverloadFlag;

constexpr int64_t kMaxArrayElementCount =;
constexpr uint32_t kMaxStatementDepth =;
constexpr size_t kMaxNestDepthOfCompositeType =;

}  // namespace

Resolver::Resolver(ProgramBuilder* builder,
                   const wgsl::AllowedFeatures& allowed_features,
                   wgsl::ValidationMode mode)
    :{}

Resolver::~Resolver() = default;

bool Resolver::Resolve() {}

bool Resolver::ResolveInternal() {}

sem::Variable* Resolver::Variable(const ast::Variable* v, bool is_global) {}

sem::Variable* Resolver::Let(const ast::Let* v) {}

sem::Variable* Resolver::Override(const ast::Override* v) {}

sem::Variable* Resolver::Const(const ast::Const* c, bool is_global) {}

sem::Variable* Resolver::Var(const ast::Var* var, bool is_global) {}

sem::Parameter* Resolver::Parameter(const ast::Parameter* param,
                                    const ast::Function* func,
                                    uint32_t index) {}

core::Access Resolver::DefaultAccessForAddressSpace(core::AddressSpace address_space) {}

bool Resolver::AllocateOverridableConstantIds() {}

void Resolver::SetShadows() {}

sem::GlobalVariable* Resolver::GlobalVariable(const ast::Variable* v) {}

sem::Statement* Resolver::ConstAssert(const ast::ConstAssert* assertion) {}

sem::Function* Resolver::Function(const ast::Function* decl) {}

bool Resolver::Statements(VectorRef<const ast::Statement*> stmts) {}

sem::Statement* Resolver::Statement(const ast::Statement* stmt) {}

sem::CaseStatement* Resolver::CaseStatement(const ast::CaseStatement* stmt,
                                            const core::type::Type* ty) {}

sem::IfStatement* Resolver::IfStatement(const ast::IfStatement* stmt) {}

sem::BlockStatement* Resolver::BlockStatement(const ast::BlockStatement* stmt) {}

sem::LoopStatement* Resolver::LoopStatement(const ast::LoopStatement* stmt) {}

sem::ForLoopStatement* Resolver::ForLoopStatement(const ast::ForLoopStatement* stmt) {}

sem::WhileStatement* Resolver::WhileStatement(const ast::WhileStatement* stmt) {}

sem::Expression* Resolver::Expression(const ast::Expression* root) {}

sem::ValueExpression* Resolver::ValueExpression(const ast::Expression* expr) {}

sem::TypeExpression* Resolver::TypeExpression(const ast::Expression* expr) {}

sem::FunctionExpression* Resolver::FunctionExpression(const ast::Expression* expr) {}

core::type::Type* Resolver::Type(const ast::Expression* ast) {}

sem::BuiltinEnumExpression<core::AddressSpace>* Resolver::AddressSpaceExpression(
    const ast::Expression* expr) {}

sem::BuiltinEnumExpression<core::TexelFormat>* Resolver::TexelFormatExpression(
    const ast::Expression* expr) {}

sem::BuiltinEnumExpression<core::Access>* Resolver::AccessExpression(const ast::Expression* expr) {}

void Resolver::RegisterStore(const sem::ValueExpression* expr) {}

void Resolver::RegisterLoad(const sem::ValueExpression* expr) {}

bool Resolver::AliasAnalysis(const sem::Call* call) {}

const core::type::Type* Resolver::ConcreteType(const core::type::Type* ty,
                                               const core::type::Type* target_ty,
                                               const Source& source) {}

const sem::ValueExpression* Resolver::Load(const sem::ValueExpression* expr) {}

const sem::ValueExpression* Resolver::Materialize(
    const sem::ValueExpression* expr,
    const core::type::Type* target_type /* = nullptr */) {}

template <size_t N>
bool Resolver::MaybeMaterializeAndLoadArguments(Vector<const sem::ValueExpression*, N>& args,
                                                const sem::CallTarget* target) {}

bool Resolver::ShouldMaterializeArgument(const core::type::Type* parameter_ty) const {}

bool Resolver::Convert(const core::constant::Value*& c,
                       const core::type::Type* target_ty,
                       const Source& source) {}

template <size_t N>
tint::Result<Vector<const core::constant::Value*, N>> Resolver::ConvertArguments(
    const Vector<const sem::ValueExpression*, N>& args,
    const sem::CallTarget* target) {}

template <size_t N>
const core::constant::Value* Resolver::ConvertConstArgument(
    const Vector<const sem::ValueExpression*, N>& args,
    const sem::CallTarget* target,
    unsigned i) {}

sem::ValueExpression* Resolver::IndexAccessor(const ast::IndexAccessorExpression* expr) {}

sem::Call* Resolver::Call(const ast::CallExpression* expr) {}

template <size_t N>
sem::Call* Resolver::BuiltinCall(const ast::CallExpression* expr,
                                 wgsl::BuiltinFn fn,
                                 Vector<const sem::ValueExpression*, N>& args) {}

core::type::Type* Resolver::BuiltinType(core::BuiltinType builtin_ty,
                                        const ast::Identifier* ident) {}

core::type::AbstractFloat* Resolver::AF() {}

core::type::F32* Resolver::F32() {}

core::type::I32* Resolver::I32() {}

core::type::U32* Resolver::U32() {}

core::type::F16* Resolver::F16(const ast::Identifier* ident) {}

core::type::Vector* Resolver::Vec(const ast::Identifier* ident, core::type::Type* el, uint32_t n) {}

core::type::Type* Resolver::VecT(const ast::Identifier* ident,
                                 core::BuiltinType builtin,
                                 uint32_t n) {}

core::type::Matrix* Resolver::Mat(const ast::Identifier* ident,
                                  core::type::Type* el,
                                  uint32_t num_columns,
                                  uint32_t num_rows) {}

core::type::Type* Resolver::MatT(const ast::Identifier* ident,
                                 core::BuiltinType builtin,
                                 uint32_t num_columns,
                                 uint32_t num_rows) {}

core::type::Type* Resolver::Array(const ast::Identifier* ident) {}

core::type::Atomic* Resolver::Atomic(const ast::Identifier* ident) {}

core::type::Pointer* Resolver::Ptr(const ast::Identifier* ident) {}

core::type::SampledTexture* Resolver::SampledTexture(const ast::Identifier* ident,
                                                     core::type::TextureDimension dim) {}

core::type::MultisampledTexture* Resolver::MultisampledTexture(const ast::Identifier* ident,
                                                               core::type::TextureDimension dim) {}

core::type::StorageTexture* Resolver::StorageTexture(const ast::Identifier* ident,
                                                     core::type::TextureDimension dim) {}

core::type::InputAttachment* Resolver::InputAttachment(const ast::Identifier* ident) {}

core::type::Vector* Resolver::PackedVec3T(const ast::Identifier* ident) {}

const ast::TemplatedIdentifier* Resolver::TemplatedIdentifier(const ast::Identifier* ident,
                                                              size_t min_args,
                                                              size_t max_args /* = use min 0 */) {}

bool Resolver::CheckTemplatedIdentifierArgs(const ast::TemplatedIdentifier* ident,
                                            size_t min_args,
                                            size_t max_args /* = use min 0 */) {}

size_t Resolver::NestDepth(const core::type::Type* ty) const {}

void Resolver::CollectTextureSamplerPairs(const sem::BuiltinFn* builtin,
                                          VectorRef<const sem::ValueExpression*> args) const {}

sem::Call* Resolver::FunctionCall(const ast::CallExpression* expr,
                                  sem::Function* target,
                                  VectorRef<const sem::ValueExpression*> args_in,
                                  sem::Behaviors arg_behaviors) {}

void Resolver::CollectTextureSamplerPairs(sem::Function* func,
                                          VectorRef<const sem::ValueExpression*> args) const {}

sem::ValueExpression* Resolver::Literal(const ast::LiteralExpression* literal) {}

sem::Expression* Resolver::Identifier(const ast::IdentifierExpression* expr) {}

sem::ValueExpression* Resolver::MemberAccessor(const ast::MemberAccessorExpression* expr) {}

sem::ValueExpression* Resolver::Binary(const ast::BinaryExpression* expr) {}

sem::ValueExpression* Resolver::UnaryOp(const ast::UnaryOpExpression* unary) {}

tint::Result<uint32_t> Resolver::LocationAttribute(const ast::LocationAttribute* attr) {}

tint::Result<uint32_t> Resolver::ColorAttribute(const ast::ColorAttribute* attr) {}
tint::Result<uint32_t> Resolver::BlendSrcAttribute(const ast::BlendSrcAttribute* attr) {}

tint::Result<uint32_t> Resolver::BindingAttribute(const ast::BindingAttribute* attr) {}

tint::Result<uint32_t> Resolver::GroupAttribute(const ast::GroupAttribute* attr) {}

tint::Result<uint32_t> Resolver::InputAttachmentIndexAttribute(
    const ast::InputAttachmentIndexAttribute* attr) {}

tint::Result<sem::WorkgroupSize> Resolver::WorkgroupAttribute(const ast::WorkgroupAttribute* attr) {}

bool Resolver::DiagnosticAttribute(const ast::DiagnosticAttribute* attr) {}

bool Resolver::StageAttribute(const ast::StageAttribute*) {}

bool Resolver::MustUseAttribute(const ast::MustUseAttribute*) {}

bool Resolver::InvariantAttribute(const ast::InvariantAttribute*) {}

bool Resolver::StrideAttribute(const ast::StrideAttribute*) {}

bool Resolver::InternalAttribute(const ast::InternalAttribute* attr) {}

bool Resolver::DiagnosticControl(const ast::DiagnosticControl& control) {}

bool Resolver::Enable(const ast::Enable* enable) {}

bool Resolver::Requires(const ast::Requires* req) {}

core::type::Type* Resolver::TypeDecl(const ast::TypeDecl* named_type) {}

const core::type::ArrayCount* Resolver::ArrayCount(const ast::Expression* count_expr) {}

bool Resolver::ArrayAttributes(VectorRef<const ast::Attribute*> attributes,
                               const core::type::Type* el_ty,
                               uint32_t& explicit_stride) {}

sem::Array* Resolver::Array(const Source& array_source,
                            const Source& el_source,
                            const Source& count_source,
                            const core::type::Type* el_ty,
                            const core::type::ArrayCount* el_count,
                            uint32_t explicit_stride) {}

core::type::Type* Resolver::Alias(const ast::Alias* alias) {}

sem::Struct* Resolver::Structure(const ast::Struct* str) {}

sem::Statement* Resolver::ReturnStatement(const ast::ReturnStatement* stmt) {}

sem::SwitchStatement* Resolver::SwitchStatement(const ast::SwitchStatement* stmt) {}

sem::Statement* Resolver::VariableDeclStatement(const ast::VariableDeclStatement* stmt) {}

sem::Statement* Resolver::AssignmentStatement(const ast::AssignmentStatement* stmt) {}

sem::Statement* Resolver::BreakStatement(const ast::BreakStatement* stmt) {}

sem::Statement* Resolver::BreakIfStatement(const ast::BreakIfStatement* stmt) {}

sem::Statement* Resolver::CallStatement(const ast::CallStatement* stmt) {}

sem::Statement* Resolver::CompoundAssignmentStatement(
    const ast::CompoundAssignmentStatement* stmt) {}

sem::Statement* Resolver::ContinueStatement(const ast::ContinueStatement* stmt) {}

sem::Statement* Resolver::DiscardStatement(const ast::DiscardStatement* stmt) {}

sem::Statement* Resolver::IncrementDecrementStatement(
    const ast::IncrementDecrementStatement* stmt) {}

bool Resolver::ApplyAddressSpaceUsageToType(core::AddressSpace address_space,
                                            core::type::Type* ty,
                                            const Source& usage) {}

template <typename SEM, typename F>
SEM* Resolver::StatementScope(const ast::Statement* ast, SEM* sem, F&& callback) {}

bool Resolver::Mark(const ast::Node* node) {}

template <typename NODE>
void Resolver::ApplyDiagnosticSeverities(NODE* node) {}

bool Resolver::CheckNotTemplated(const char* use, const ast::Identifier* ident) {}

void Resolver::ErrorInvalidAttribute(const ast::Attribute* attr, StyledText use) {}

diag::Diagnostic& Resolver::AddError(const Source& source) const {}

diag::Diagnostic& Resolver::AddWarning(const Source& source) const {}

diag::Diagnostic& Resolver::AddNote(const Source& source) const {}

}  // namespace tint::resolver