From fc53f856e1ea2c3f8c09b9d6a11fbf26328671d5 Mon Sep 17 00:00:00 2001 From: Geoffrey Romer Date: Thu, 1 May 2025 16:12:42 -0700 Subject: [PATCH] Alphabetize typed_insts.h As requested [here](https://github.com/carbon-language/carbon-lang/pull/5400#discussion_r2070631805) --- toolchain/sem_ir/typed_insts.h | 560 ++++++++++++++++----------------- 1 file changed, 280 insertions(+), 280 deletions(-) diff --git a/toolchain/sem_ir/typed_insts.h b/toolchain/sem_ir/typed_insts.h index ddedf6c959f15..8b1075662c447 100644 --- a/toolchain/sem_ir/typed_insts.h +++ b/toolchain/sem_ir/typed_insts.h @@ -76,17 +76,6 @@ struct AccessOptionalMemberAction { NameId name_id; }; -// Common representation for declarations describing the foundation type of a -// class -- either its adapted type or its base class. -struct AnyFoundationDecl { - static constexpr InstKind Kinds[] = {InstKind::AdaptDecl, InstKind::BaseDecl}; - - InstKind kind; - TypeInstId foundation_type_inst_id; - // Kind-specific data. - AnyRawId arg1; -}; - // An adapted type declaration in a class, of the form `adapt T;`. struct AdaptDecl { static constexpr auto Kind = InstKind::AdaptDecl.Define( @@ -125,19 +114,6 @@ struct AddrPattern { InstId inner_id; }; -// An array indexing operation, such as `array[index]`. -struct ArrayIndex { - // Parse node is usually Parse::IndexExprId. - static constexpr auto Kind = InstKind::ArrayIndex.Define( - {.ir_name = "array_index", - .is_type = InstIsType::Maybe, - .constant_kind = InstConstantKind::SymbolicOnly}); - - TypeId type_id; - InstId array_id; - InstId index_id; -}; - // Common representation for aggregate access nodes, which access a fixed // element of an aggregate. struct AnyAggregateAccess { @@ -173,6 +149,129 @@ struct AnyAggregateValue { InstBlockId elements_id; }; +// Common representation for various `*binding_pattern` nodes. +struct AnyBindingPattern { + // TODO: Also handle TemplateBindingPattern once it exists. + static constexpr InstKind Kinds[] = {InstKind::BindingPattern, + InstKind::SymbolicBindingPattern}; + + InstKind kind; + + // Always a PatternType whose scrutinee type is the declared type of the + // binding. + TypeId type_id; + + // The name declared by the binding pattern. `None` indicates that the + // pattern has `_` in the name position, and so does not truly declare + // a name. + EntityNameId entity_name_id; +}; + +// Common representation for various `bind*` nodes. +struct AnyBindName { + // TODO: Also handle BindTemplateName once it exists. + static constexpr InstKind Kinds[] = {InstKind::BindAlias, InstKind::BindName, + InstKind::BindSymbolicName}; + + InstKind kind; + TypeId type_id; + EntityNameId entity_name_id; + InstId value_id; +}; + +// Common representation for various `bind*` nodes, and `export name`. +struct AnyBindNameOrExportDecl { + // TODO: Also handle BindTemplateName once it exists. + static constexpr InstKind Kinds[] = {InstKind::BindAlias, InstKind::BindName, + InstKind::BindSymbolicName, + InstKind::ExportDecl}; + + InstKind kind; + TypeId type_id; + EntityNameId entity_name_id; + InstId value_id; +}; + +// Common representation for all kinds of `Branch*` node. +struct AnyBranch { + static constexpr InstKind Kinds[] = {InstKind::Branch, InstKind::BranchIf, + InstKind::BranchWithArg}; + + InstKind kind; + // Branches don't produce a value, so have no type. + LabelId target_id; + // Kind-specific data. + AnyRawId arg1; +}; + +// Common representation for declarations describing the foundation type of a +// class -- either its adapted type or its base class. +struct AnyFoundationDecl { + static constexpr InstKind Kinds[] = {InstKind::AdaptDecl, InstKind::BaseDecl}; + + InstKind kind; + TypeInstId foundation_type_inst_id; + // Kind-specific data. + AnyRawId arg1; +}; + +// Common representation for all kinds of `ImportRef*` node. +struct AnyImportRef { + static constexpr InstKind Kinds[] = {InstKind::ImportRefUnloaded, + InstKind::ImportRefLoaded}; + + InstKind kind; + ImportIRInstId import_ir_inst_id; + // A BindName is currently only set on directly imported names. It is not + // generically available. + EntityNameId entity_name_id; +}; + +// A `Call` parameter for a function or other parameterized block. +struct AnyParam { + static constexpr InstKind Kinds[] = {InstKind::OutParam, InstKind::RefParam, + InstKind::ValueParam}; + + InstKind kind; + TypeId type_id; + CallParamIndex index; + + // A name to associate with this Param in pretty-printed IR. This is not + // necessarily unique, and can even be `None`; it has no semantic + // significance. + NameId pretty_name_id; +}; + +// A pattern that represents a `Call` parameter. It delegates to subpattern_id +// in pattern matching. The sub-kinds differ only in the expression category +// of the corresponding parameter inst. +struct AnyParamPattern { + static constexpr InstKind Kinds[] = {InstKind::OutParamPattern, + InstKind::RefParamPattern, + InstKind::ValueParamPattern}; + + InstKind kind; + + // Always a PatternType that represents the same type as the type of + // `subpattern_id`. + TypeId type_id; + InstId subpattern_id; + CallParamIndex index; +}; + +// An array indexing operation, such as `array[index]`. +struct ArrayIndex { + // Parse node is usually Parse::IndexExprId. + static constexpr auto Kind = InstKind::ArrayIndex.Define( + {.ir_name = "array_index", + .is_type = InstIsType::Maybe, + .constant_kind = InstConstantKind::SymbolicOnly}); + + TypeId type_id; + InstId array_id; + InstId index_id; +}; + // Initializes an array from a tuple. `tuple_id` is the source tuple // expression. `inits_id` contains one initializer per array element. // `dest_id` is the destination array object for the initialization. @@ -294,31 +393,6 @@ struct BaseDecl { ElementIndex index; }; -// Common representation for various `bind*` nodes. -struct AnyBindName { - // TODO: Also handle BindTemplateName once it exists. - static constexpr InstKind Kinds[] = {InstKind::BindAlias, InstKind::BindName, - InstKind::BindSymbolicName}; - - InstKind kind; - TypeId type_id; - EntityNameId entity_name_id; - InstId value_id; -}; - -// Common representation for various `bind*` nodes, and `export name`. -struct AnyBindNameOrExportDecl { - // TODO: Also handle BindTemplateName once it exists. - static constexpr InstKind Kinds[] = {InstKind::BindAlias, InstKind::BindName, - InstKind::BindSymbolicName, - InstKind::ExportDecl}; - - InstKind kind; - TypeId type_id; - EntityNameId entity_name_id; - InstId value_id; -}; - // Binds a name as an alias. struct BindAlias { static constexpr auto Kind = @@ -364,24 +438,6 @@ struct BindValue { InstId value_id; }; -// Common representation for various `*binding_pattern` nodes. -struct AnyBindingPattern { - // TODO: Also handle TemplateBindingPattern once it exists. - static constexpr InstKind Kinds[] = {InstKind::BindingPattern, - InstKind::SymbolicBindingPattern}; - - InstKind kind; - - // Always a PatternType whose scrutinee type is the declared type of the - // binding. - TypeId type_id; - - // The name declared by the binding pattern. `None` indicates that the - // pattern has `_` in the name position, and so does not truly declare - // a name. - EntityNameId entity_name_id; -}; - // Represents a non-symbolic binding pattern. struct BindingPattern { static constexpr auto Kind = InstKind::BindingPattern.Define( @@ -393,19 +449,6 @@ struct BindingPattern { EntityNameId entity_name_id; }; -// Represents a symbolic binding pattern. -struct SymbolicBindingPattern { - static constexpr auto Kind = - InstKind::SymbolicBindingPattern.Define({ - .ir_name = "symbolic_binding_pattern", - .constant_kind = InstConstantKind::Unique, - .is_lowered = false, - }); - - TypeId type_id; - EntityNameId entity_name_id; -}; - // Reads an argument from `BranchWithArg`. struct BlockArg { static constexpr auto Kind = InstKind::BlockArg.Define( @@ -469,18 +512,6 @@ struct BoundMethodType { TypeId type_id; }; -// Common representation for all kinds of `Branch*` node. -struct AnyBranch { - static constexpr InstKind Kinds[] = {InstKind::Branch, InstKind::BranchIf, - InstKind::BranchWithArg}; - - InstKind kind; - // Branches don't produce a value, so have no type. - LabelId target_id; - // Kind-specific data. - AnyRawId arg1; -}; - // Control flow to branch to the target block. struct Branch { // TODO: Make Parse::NodeId more specific. @@ -621,6 +652,19 @@ struct ConstType { TypeInstId inner_id; }; +// Records that a type conversion `original as new_type` was done, producing the +// result. +struct Converted { + static constexpr auto Kind = + InstKind::Converted.Define({.ir_name = "converted"}); + + TypeId type_id; + // The operand prior to being converted. This is tracked only for tooling + // purposes and has no associated semantics. + AbsoluteInstId original_id; + InstId result_id; +}; + // An action that performs simple conversion to a value expression of a given // type. struct ConvertToValueAction { @@ -635,19 +679,6 @@ struct ConvertToValueAction { TypeInstId target_type_inst_id; }; -// Records that a type conversion `original as new_type` was done, producing the -// result. -struct Converted { - static constexpr auto Kind = - InstKind::Converted.Define({.ir_name = "converted"}); - - TypeId type_id; - // The operand prior to being converted. This is tracked only for tooling - // purposes and has no associated semantics. - AbsoluteInstId original_id; - InstId result_id; -}; - // The `*` dereference operator, as in `*pointer`. struct Deref { static constexpr auto Kind = @@ -769,22 +800,6 @@ struct FloatType { InstId bit_width_id; }; -// The legacy float type. This is currently used for real literals, and is -// treated as f64. It's separate from `FloatType`, and should change to mirror -// integers, likely replacing this with a `FloatLiteralType`. -struct LegacyFloatType { - static constexpr auto Kind = - InstKind::LegacyFloatType.Define( - {.ir_name = "f64", - .is_type = InstIsType::Always, - .constant_kind = InstConstantKind::Always}); - // This is a singleton instruction. However, it may still evolve into a more - // standard type and be removed. - static constexpr auto TypeInstId = MakeSingletonTypeInstId(); - - TypeId type_id; -}; - // A function declaration. struct FunctionDecl { static constexpr auto Kind = @@ -1012,18 +1027,6 @@ struct ImportDecl { NameId package_id; }; -// Common representation for all kinds of `ImportRef*` node. -struct AnyImportRef { - static constexpr InstKind Kinds[] = {InstKind::ImportRefUnloaded, - InstKind::ImportRefLoaded}; - - InstKind kind; - ImportIRInstId import_ir_inst_id; - // A BindName is currently only set on directly imported names. It is not - // generically available. - EntityNameId entity_name_id; -}; - // An imported entity that is not yet been loaded. struct ImportRefUnloaded { static constexpr auto Kind = @@ -1098,16 +1101,6 @@ struct InterfaceDecl { DeclInstBlockId decl_block_id; }; -// A literal integer value. -struct IntValue { - // TODO: Make Parse::NodeId more specific. - static constexpr auto Kind = InstKind::IntValue.Define( - {.ir_name = "int_value", .constant_kind = InstConstantKind::Always}); - - TypeId type_id; - IntId int_id; -}; - // An arbitrary-precision integer type, which is used as the type of integer // literals and as the parameter type of `Core.Int` and `Core.Float`. This type // only provides compile-time operations, and is represented as an empty type at @@ -1143,6 +1136,32 @@ struct IntType { InstId bit_width_id; }; +// A literal integer value. +struct IntValue { + // TODO: Make Parse::NodeId more specific. + static constexpr auto Kind = InstKind::IntValue.Define( + {.ir_name = "int_value", .constant_kind = InstConstantKind::Always}); + + TypeId type_id; + IntId int_id; +}; + +// The legacy float type. This is currently used for real literals, and is +// treated as f64. It's separate from `FloatType`, and should change to mirror +// integers, likely replacing this with a `FloatLiteralType`. +struct LegacyFloatType { + static constexpr auto Kind = + InstKind::LegacyFloatType.Define( + {.ir_name = "f64", + .is_type = InstIsType::Always, + .constant_kind = InstConstantKind::Always}); + // This is a singleton instruction. However, it may still evolve into a more + // standard type and be removed. + static constexpr auto TypeInstId = MakeSingletonTypeInstId(); + + TypeId type_id; +}; + // A symbolic instruction that takes the place of an `ImplWitness` when the // result is not fully known. When evaluated it does an impl lookup query, based // on the stored query arguments, that a type implements an interface. The query @@ -1225,21 +1244,6 @@ struct NamespaceType { TypeId type_id; }; -// A `Call` parameter for a function or other parameterized block. -struct AnyParam { - static constexpr InstKind Kinds[] = {InstKind::OutParam, InstKind::RefParam, - InstKind::ValueParam}; - - InstKind kind; - TypeId type_id; - CallParamIndex index; - - // A name to associate with this Param in pretty-printed IR. This is not - // necessarily unique, and can even be `None`; it has no semantic - // significance. - NameId pretty_name_id; -}; - // An output `Call` parameter. See AnyParam for member documentation. struct OutParam { // TODO: Make Parse::NodeId more specific. @@ -1251,45 +1255,6 @@ struct OutParam { NameId pretty_name_id; }; -// A by-reference `Call` parameter. See AnyParam for member documentation. -struct RefParam { - // TODO: Make Parse::NodeId more specific. - static constexpr auto Kind = InstKind::RefParam.Define( - {.ir_name = "ref_param", .constant_kind = InstConstantKind::Never}); - - TypeId type_id; - CallParamIndex index; - NameId pretty_name_id; -}; - -// A by-value `Call` parameter. See AnyParam for member documentation. -struct ValueParam { - // TODO: Make Parse::NodeId more specific. - static constexpr auto Kind = InstKind::ValueParam.Define( - {.ir_name = "value_param", .constant_kind = InstConstantKind::Never}); - - TypeId type_id; - CallParamIndex index; - NameId pretty_name_id; -}; - -// A pattern that represents a `Call` parameter. It delegates to subpattern_id -// in pattern matching. The sub-kinds differ only in the expression category -// of the corresponding parameter inst. -struct AnyParamPattern { - static constexpr InstKind Kinds[] = {InstKind::OutParamPattern, - InstKind::RefParamPattern, - InstKind::ValueParamPattern}; - - InstKind kind; - - // Always a PatternType that represents the same type as the type of - // `subpattern_id`. - TypeId type_id; - InstId subpattern_id; - CallParamIndex index; -}; - // A pattern that represents an output `Call` parameter. struct OutParamPattern { static constexpr auto Kind = @@ -1303,33 +1268,6 @@ struct OutParamPattern { CallParamIndex index; }; -// A pattern that represents a by-reference `Call` parameter. -struct RefParamPattern { - // TODO: Make Parse::NodeId more specific. - static constexpr auto Kind = InstKind::RefParamPattern.Define( - {.ir_name = "ref_param_pattern", - .constant_kind = InstConstantKind::Unique, - .is_lowered = false}); - - TypeId type_id; - InstId subpattern_id; - CallParamIndex index; -}; - -// A pattern that represents a by-value `Call` parameter. -struct ValueParamPattern { - // TODO: Make Parse::NodeId more specific. - static constexpr auto Kind = - InstKind::ValueParamPattern.Define( - {.ir_name = "value_param_pattern", - .constant_kind = InstConstantKind::Unique, - .is_lowered = false}); - - TypeId type_id; - InstId subpattern_id; - CallParamIndex index; -}; - // The type of a pattern that matches scrutinees of type // `scrutinee_type_inst_id`. struct PatternType { @@ -1370,6 +1308,30 @@ struct RefineTypeAction { TypeInstId inst_type_inst_id; }; +// A by-reference `Call` parameter. See AnyParam for member documentation. +struct RefParam { + // TODO: Make Parse::NodeId more specific. + static constexpr auto Kind = InstKind::RefParam.Define( + {.ir_name = "ref_param", .constant_kind = InstConstantKind::Never}); + + TypeId type_id; + CallParamIndex index; + NameId pretty_name_id; +}; + +// A pattern that represents a by-reference `Call` parameter. +struct RefParamPattern { + // TODO: Make Parse::NodeId more specific. + static constexpr auto Kind = InstKind::RefParamPattern.Define( + {.ir_name = "ref_param_pattern", + .constant_kind = InstConstantKind::Unique, + .is_lowered = false}); + + TypeId type_id; + InstId subpattern_id; + CallParamIndex index; +}; + // Requires a type to be complete. This is only created for generic types and // produces a witness that the type is complete. // @@ -1390,6 +1352,45 @@ struct RequireCompleteType { TypeInstId complete_type_inst_id; }; +// An `expr == expr` clause in a `where` expression or `require` declaration. +struct RequirementEquivalent { + static constexpr auto Kind = + InstKind::RequirementEquivalent.Define( + {.ir_name = "requirement_equivalent", + .constant_kind = InstConstantKind::Never, + .is_lowered = false}); + + // No type since not an expression + InstId lhs_id; + InstId rhs_id; +}; + +// An `expr impls expr` clause in a `where` expression or `require` declaration. +struct RequirementImpls { + static constexpr auto Kind = + InstKind::RequirementImpls.Define( + {.ir_name = "requirement_impls", + .constant_kind = InstConstantKind::Never, + .is_lowered = false}); + + // No type since not an expression + InstId lhs_id; + InstId rhs_id; +}; + +// A `.M = expr` clause in a `where` expression or `require` declaration. +struct RequirementRewrite { + static constexpr auto Kind = + InstKind::RequirementRewrite.Define( + {.ir_name = "requirement_rewrite", + .constant_kind = InstConstantKind::Never, + .is_lowered = false}); + + // No type since not an expression + InstId lhs_id; + InstId rhs_id; +}; + struct Return { static constexpr auto Kind = InstKind::Return.Define( - {.ir_name = "requirement_equivalent", - .constant_kind = InstConstantKind::Never, - .is_lowered = false}); - - // No type since not an expression - InstId lhs_id; - InstId rhs_id; -}; - -// An `expr impls expr` clause in a `where` expression or `require` declaration. -struct RequirementImpls { - static constexpr auto Kind = - InstKind::RequirementImpls.Define( - {.ir_name = "requirement_impls", - .constant_kind = InstConstantKind::Never, - .is_lowered = false}); - - // No type since not an expression - InstId lhs_id; - InstId rhs_id; -}; - -// A `.M = expr` clause in a `where` expression or `require` declaration. -struct RequirementRewrite { - static constexpr auto Kind = - InstKind::RequirementRewrite.Define( - {.ir_name = "requirement_rewrite", - .constant_kind = InstConstantKind::Never, - .is_lowered = false}); - - // No type since not an expression - InstId lhs_id; - InstId rhs_id; -}; - // Given an instruction with a constant value that depends on a generic // parameter, selects a version of that instruction with the constant value // corresponding to a particular specific. @@ -1680,6 +1642,19 @@ struct StructValue { InstBlockId elements_id; }; +// Represents a symbolic binding pattern. +struct SymbolicBindingPattern { + static constexpr auto Kind = + InstKind::SymbolicBindingPattern.Define({ + .ir_name = "symbolic_binding_pattern", + .constant_kind = InstConstantKind::Unique, + .is_lowered = false, + }); + + TypeId type_id; + EntityNameId entity_name_id; +}; + // A temporary value. struct Temporary { static constexpr auto Kind = @@ -1856,6 +1831,31 @@ struct ValueOfInitializer { InstId init_id; }; +// A by-value `Call` parameter. See AnyParam for member documentation. +struct ValueParam { + // TODO: Make Parse::NodeId more specific. + static constexpr auto Kind = InstKind::ValueParam.Define( + {.ir_name = "value_param", .constant_kind = InstConstantKind::Never}); + + TypeId type_id; + CallParamIndex index; + NameId pretty_name_id; +}; + +// A pattern that represents a by-value `Call` parameter. +struct ValueParamPattern { + // TODO: Make Parse::NodeId more specific. + static constexpr auto Kind = + InstKind::ValueParamPattern.Define( + {.ir_name = "value_param_pattern", + .constant_kind = InstConstantKind::Unique, + .is_lowered = false}); + + TypeId type_id; + InstId subpattern_id; + CallParamIndex index; +}; + // A `var` pattern. struct VarPattern { static constexpr auto Kind = @@ -1886,17 +1886,14 @@ struct VarStorage { NameId pretty_name_id; }; -// The type of virtual function tables. -struct VtableType { - static constexpr auto Kind = InstKind::VtableType.Define( - {.ir_name = "", - .is_type = InstIsType::Always, - .constant_kind = InstConstantKind::Always}); - // This is a singleton instruction. However, it may still evolve into a more - // standard type and be removed. - static constexpr auto TypeInstId = MakeSingletonTypeInstId(); - +// Definition of ABI-neutral vtable information for a dynamic class. +struct Vtable { + static constexpr auto Kind = InstKind::Vtable.Define( + {.ir_name = "vtable", + .constant_kind = InstConstantKind::Always, + .is_lowered = false}); TypeId type_id; + InstBlockId virtual_functions_id; }; // Initializer for virtual function table pointers in object initialization. @@ -1907,14 +1904,17 @@ struct VtablePtr { InstId vtable_id; }; -// Definition of ABI-neutral vtable information for a dynamic class. -struct Vtable { - static constexpr auto Kind = InstKind::Vtable.Define( - {.ir_name = "vtable", - .constant_kind = InstConstantKind::Always, - .is_lowered = false}); +// The type of virtual function tables. +struct VtableType { + static constexpr auto Kind = InstKind::VtableType.Define( + {.ir_name = "", + .is_type = InstIsType::Always, + .constant_kind = InstConstantKind::Always}); + // This is a singleton instruction. However, it may still evolve into a more + // standard type and be removed. + static constexpr auto TypeInstId = MakeSingletonTypeInstId(); + TypeId type_id; - InstBlockId virtual_functions_id; }; // An `expr where requirements` expression.