Files
carbon-lang/toolchain/sem_ir/inst_kind.def
T
Richard Smith d18584c6c2 Make representation of call to a generic class / interface more uniform. (#4050)
Model such calls as call operations, and compute the resulting type in
constant evaluation rather than in type-checking. This means we no
longer form non-constant `ClassType` or `InterfaceType` values, and that
we produce an `<error>` type in the case of bad argument lists rather
than a broken / meaningless `ClassType` / `InterfaceType` that doesn't
actually represent a type. This in turn suppresses some follow-on
diagnostics.
2024-06-13 21:24:36 +00:00

170 lines
9.2 KiB
Modula-2

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// This is an X-macro header. It does not use `#include` guards, and instead is
// designed to be `#include`ed after the x-macro is defined in order for its
// inclusion to expand to the desired output. Macro definitions are cleaned up
// at the end of this file.
//
// This macro should be defined before including this header:
// - CARBON_SEM_IR_INST_KIND(Name)
// Invoked for each kind of semantic instruction.
//
// The invocation of the above macro will be wrapped in one macro from each of
// the following sets, which by default expand to their argument:
//
// Whether the instruction can define a type:
// - CARBON_SEM_IR_INST_KIND_TYPE_ALWAYS(...)
// Invoked for each instruction that is always of type `type`, and might
// define a type constant.
// - CARBON_SEM_IR_INST_KIND_TYPE_MAYBE(...)
// Invoked for each instruction that is sometimes of type `type`, and might
// define a type constant.
// - CARBON_SEM_IR_INST_KIND_TYPE_NEVER(...)
// Invoked for each instruction that can never define a type constant. Note
// that such instructions can still have type `type`, but are not the
// canonical definition of any type.
//
// Whether the instruction can define a constant, see `InstConstantKind`:
// - CARBON_SEM_IR_INST_KIND_CONSTANT_NEVER(...)
// Invoked when `constant_kind()` is `InstConstantKind::Never`.
// - CARBON_SEM_IR_INST_KIND_CONSTANT_SYMBOLIC_ONLY(...)
// Invoked when `constant_kind()` is `InstConstantKind::SymbolicOnly`.
// - CARBON_SEM_IR_INST_KIND_CONSTANT_CONDITIONAL(...)
// Invoked when `constant_kind()` is `InstConstantKind::Conditional`.
// - CARBON_SEM_IR_INST_KIND_CONSTANT_ALWAYS(...)
// Invoked when `constant_kind()` is `InstConstantKind::Always`.
//
// Defining these is optional.
#ifndef CARBON_SEM_IR_INST_KIND
#error "Must define the x-macro to use this file."
#endif
#ifndef CARBON_SEM_IR_INST_KIND_TYPE_NEVER
#define CARBON_SEM_IR_INST_KIND_TYPE_NEVER(...) __VA_ARGS__
#endif
#ifndef CARBON_SEM_IR_INST_KIND_TYPE_MAYBE
#define CARBON_SEM_IR_INST_KIND_TYPE_MAYBE(...) __VA_ARGS__
#endif
#ifndef CARBON_SEM_IR_INST_KIND_TYPE_ALWAYS
#define CARBON_SEM_IR_INST_KIND_TYPE_ALWAYS(...) __VA_ARGS__
#endif
#ifndef CARBON_SEM_IR_INST_KIND_CONSTANT_NEVER
#define CARBON_SEM_IR_INST_KIND_CONSTANT_NEVER(...) __VA_ARGS__
#endif
#ifndef CARBON_SEM_IR_INST_KIND_CONSTANT_SYMBOLIC_ONLY
#define CARBON_SEM_IR_INST_KIND_CONSTANT_SYMBOLIC_ONLY(...) __VA_ARGS__
#endif
#ifndef CARBON_SEM_IR_INST_KIND_CONSTANT_CONDITIONAL
#define CARBON_SEM_IR_INST_KIND_CONSTANT_CONDITIONAL(...) __VA_ARGS__
#endif
#ifndef CARBON_SEM_IR_INST_KIND_CONSTANT_ALWAYS
#define CARBON_SEM_IR_INST_KIND_CONSTANT_ALWAYS(...) __VA_ARGS__
#endif
#define CARBON_SEM_IR_INST_KIND_IMPL(Name, IsType, IsConstant) \
CARBON_SEM_IR_INST_KIND_##IsType( \
CARBON_SEM_IR_INST_KIND_##IsConstant(CARBON_SEM_IR_INST_KIND(Name)))
// For each instruction kind declared here there is a matching definition in
// `typed_insts.h`.
CARBON_SEM_IR_INST_KIND_IMPL(AdaptDecl, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(AddrOf, TYPE_NEVER, CONSTANT_CONDITIONAL)
CARBON_SEM_IR_INST_KIND_IMPL(AddrPattern, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(ArrayIndex, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(ArrayInit, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(ArrayType, TYPE_ALWAYS, CONSTANT_CONDITIONAL)
CARBON_SEM_IR_INST_KIND_IMPL(AsCompatible, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(Assign, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(AssociatedConstantDecl, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(AssociatedEntity, TYPE_NEVER, CONSTANT_ALWAYS)
CARBON_SEM_IR_INST_KIND_IMPL(AssociatedEntityType, TYPE_ALWAYS,
CONSTANT_CONDITIONAL)
CARBON_SEM_IR_INST_KIND_IMPL(BaseDecl, TYPE_NEVER, CONSTANT_ALWAYS)
CARBON_SEM_IR_INST_KIND_IMPL(BindAlias, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(ExportDecl, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(BindName, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(BindSymbolicName, TYPE_MAYBE,
CONSTANT_SYMBOLIC_ONLY)
CARBON_SEM_IR_INST_KIND_IMPL(BindValue, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(BlockArg, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(BoolLiteral, TYPE_NEVER, CONSTANT_ALWAYS)
CARBON_SEM_IR_INST_KIND_IMPL(BoundMethod, TYPE_NEVER, CONSTANT_CONDITIONAL)
CARBON_SEM_IR_INST_KIND_IMPL(Branch, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(BranchIf, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(BranchWithArg, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(Builtin, TYPE_ALWAYS, CONSTANT_ALWAYS)
CARBON_SEM_IR_INST_KIND_IMPL(Call, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(ClassDecl, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(ClassElementAccess, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(ClassInit, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(ClassType, TYPE_ALWAYS, CONSTANT_ALWAYS)
CARBON_SEM_IR_INST_KIND_IMPL(ConstType, TYPE_ALWAYS, CONSTANT_CONDITIONAL)
CARBON_SEM_IR_INST_KIND_IMPL(Converted, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(Deref, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(FacetTypeAccess, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(FieldDecl, TYPE_NEVER, CONSTANT_ALWAYS)
CARBON_SEM_IR_INST_KIND_IMPL(FloatLiteral, TYPE_NEVER, CONSTANT_ALWAYS)
CARBON_SEM_IR_INST_KIND_IMPL(FloatType, TYPE_ALWAYS, CONSTANT_CONDITIONAL)
CARBON_SEM_IR_INST_KIND_IMPL(FunctionDecl, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(FunctionType, TYPE_ALWAYS, CONSTANT_CONDITIONAL)
CARBON_SEM_IR_INST_KIND_IMPL(GenericClassType, TYPE_ALWAYS,
CONSTANT_CONDITIONAL)
CARBON_SEM_IR_INST_KIND_IMPL(GenericInterfaceType, TYPE_ALWAYS,
CONSTANT_CONDITIONAL)
CARBON_SEM_IR_INST_KIND_IMPL(ImplDecl, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(ImportRefUnloaded, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(ImportRefLoaded, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(InitializeFrom, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(InterfaceDecl, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(InterfaceType, TYPE_ALWAYS, CONSTANT_ALWAYS)
CARBON_SEM_IR_INST_KIND_IMPL(InterfaceWitness, TYPE_NEVER, CONSTANT_CONDITIONAL)
CARBON_SEM_IR_INST_KIND_IMPL(InterfaceWitnessAccess, TYPE_MAYBE,
CONSTANT_SYMBOLIC_ONLY)
CARBON_SEM_IR_INST_KIND_IMPL(IntLiteral, TYPE_NEVER, CONSTANT_ALWAYS)
CARBON_SEM_IR_INST_KIND_IMPL(IntType, TYPE_ALWAYS, CONSTANT_CONDITIONAL)
CARBON_SEM_IR_INST_KIND_IMPL(NameRef, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(Namespace, TYPE_NEVER, CONSTANT_ALWAYS)
CARBON_SEM_IR_INST_KIND_IMPL(Param, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(PointerType, TYPE_ALWAYS, CONSTANT_CONDITIONAL)
CARBON_SEM_IR_INST_KIND_IMPL(RealLiteral, TYPE_NEVER, CONSTANT_ALWAYS)
CARBON_SEM_IR_INST_KIND_IMPL(ReturnExpr, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(Return, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(SpliceBlock, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(StringLiteral, TYPE_NEVER, CONSTANT_ALWAYS)
CARBON_SEM_IR_INST_KIND_IMPL(StructAccess, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(StructInit, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(StructLiteral, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(StructType, TYPE_ALWAYS, CONSTANT_CONDITIONAL)
CARBON_SEM_IR_INST_KIND_IMPL(StructTypeField, TYPE_NEVER, CONSTANT_CONDITIONAL)
CARBON_SEM_IR_INST_KIND_IMPL(StructValue, TYPE_NEVER, CONSTANT_CONDITIONAL)
CARBON_SEM_IR_INST_KIND_IMPL(TemporaryStorage, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(Temporary, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(TupleAccess, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(TupleIndex, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(TupleInit, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(TupleLiteral, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(TupleType, TYPE_ALWAYS, CONSTANT_CONDITIONAL)
CARBON_SEM_IR_INST_KIND_IMPL(TupleValue, TYPE_NEVER, CONSTANT_CONDITIONAL)
CARBON_SEM_IR_INST_KIND_IMPL(UnaryOperatorNot, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(UnboundElementType, TYPE_ALWAYS,
CONSTANT_CONDITIONAL)
CARBON_SEM_IR_INST_KIND_IMPL(ValueAsRef, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(ValueOfInitializer, TYPE_NEVER, CONSTANT_NEVER)
CARBON_SEM_IR_INST_KIND_IMPL(VarStorage, TYPE_NEVER, CONSTANT_NEVER)
#undef CARBON_SEM_IR_INST_KIND_TYPE_ALWAYS
#undef CARBON_SEM_IR_INST_KIND_TYPE_MAYBE
#undef CARBON_SEM_IR_INST_KIND_TYPE_NEVER
#undef CARBON_SEM_IR_INST_KIND_CONSTANT_NEVER
#undef CARBON_SEM_IR_INST_KIND_CONSTANT_SYMBOLIC_ONLY
#undef CARBON_SEM_IR_INST_KIND_CONSTANT_CONDITIONAL
#undef CARBON_SEM_IR_INST_KIND_CONSTANT_ALWAYS
#undef CARBON_SEM_IR_INST_KIND_IMPL
#undef CARBON_SEM_IR_INST_KIND