Files
carbon-lang/explorer/ast/value_kinds.def
T
Adrien Leravat d02366f881 Explorer: Prevent copies when initializing a let binding from reference expression (#2946)
Prevent copies when initializing value expression from reference
expression. This is based on
https://github.com/carbon-language/carbon-lang/pull/2006, which
introduces expression categories, and how it is possible to convert
to/from those different categories. Continuation of
https://github.com/carbon-language/carbon-lang/pull/2907

## Functional changes

* Initializing a value expression from a reference expression takes its
value without a copy
* Reading from the value expression causes an error if the value changed
from the time it was initialized
* In this situation, prevents a copy both for variable definitions, and
call parameter bindings

## Main implementation changes

* Add new `ExpressionCategoryAction`, which evaluates an expression and
returns an `ExpressionValue` containing its category and address (if
any), in addition to the resulting `Value*`
* `ExpressionAction`s now invokes `ExpressionCategoryAction` and unwraps
the returned `ExpressionValue`
* `RuntimeScope::BindAndPin` method, and corresponding when attempting
to read a `value_node`.

## Next work

* Avoid unnecessary copies from value expression to value expression,
after ensuring that even value expression temporaries are registered for
destruction (https://github.com/Pixep/carbon-lang/pull/9)
2023-07-17 23:26:01 +00:00

60 lines
2.0 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 .def file expands the CARBON_VALUE_KIND macro once for each kind of
// Value. The macro should be defined as taking a single argument, which is the
// name of the Value type.
#ifndef CARBON_VALUE_KIND
#error #define CARBON_VALUE_KIND(kind) before including this header
#endif
CARBON_VALUE_KIND(IntValue)
CARBON_VALUE_KIND(FunctionValue)
CARBON_VALUE_KIND(DestructorValue)
CARBON_VALUE_KIND(BoundMethodValue)
CARBON_VALUE_KIND(PointerValue)
CARBON_VALUE_KIND(LocationValue)
CARBON_VALUE_KIND(ReferenceExpressionValue)
CARBON_VALUE_KIND(BoolValue)
CARBON_VALUE_KIND(StructValue)
CARBON_VALUE_KIND(NominalClassValue)
CARBON_VALUE_KIND(AlternativeValue)
CARBON_VALUE_KIND(TupleValue)
CARBON_VALUE_KIND(UninitializedValue)
CARBON_VALUE_KIND(ImplWitness)
CARBON_VALUE_KIND(BindingWitness)
CARBON_VALUE_KIND(ConstraintWitness)
CARBON_VALUE_KIND(ConstraintImplWitness)
CARBON_VALUE_KIND(IntType)
CARBON_VALUE_KIND(BoolType)
CARBON_VALUE_KIND(TypeType)
CARBON_VALUE_KIND(FunctionType)
CARBON_VALUE_KIND(PointerType)
CARBON_VALUE_KIND(AutoType)
CARBON_VALUE_KIND(StructType)
CARBON_VALUE_KIND(NominalClassType)
CARBON_VALUE_KIND(TupleType)
CARBON_VALUE_KIND(MixinPseudoType)
CARBON_VALUE_KIND(InterfaceType)
CARBON_VALUE_KIND(NamedConstraintType)
CARBON_VALUE_KIND(ConstraintType)
CARBON_VALUE_KIND(ChoiceType)
CARBON_VALUE_KIND(VariableType)
CARBON_VALUE_KIND(AssociatedConstant)
CARBON_VALUE_KIND(ParameterizedEntityName)
CARBON_VALUE_KIND(MemberName)
CARBON_VALUE_KIND(BindingPlaceholderValue)
CARBON_VALUE_KIND(AddrValue)
CARBON_VALUE_KIND(AlternativeConstructorValue)
CARBON_VALUE_KIND(StringType)
CARBON_VALUE_KIND(StringValue)
CARBON_VALUE_KIND(TypeOfMixinPseudoType)
CARBON_VALUE_KIND(TypeOfParameterizedEntityName)
CARBON_VALUE_KIND(TypeOfMemberName)
CARBON_VALUE_KIND(TypeOfNamespaceName)
CARBON_VALUE_KIND(StaticArrayType)
#undef CARBON_VALUE_KIND