Files
carbon-lang/toolchain/sem_ir/expr_info.h
T
Geoff RomerandRichard Smith e5b05a1fac ExprCategory for guaranteed-in-place initializing expressions (#6623)
The primary change in this PR is to split the `Initializing` expression
category into separate `ReprInitializing` and `InPlaceInitializing`
categories, depending on whether initialization uses the types
initializing representation, or is guaranteed to be in place. It also
rationalizes and documents the SemIR-level semantics of those categories
(including where #5545's "ephemeral entire reference" category will
fit), and introduces two new inst kinds to close gaps exposed in the
process.

Some additional secondary changes:
- Consistently format the storage arguments of initializers with `to`,
regardless of whether initialization is in-place, and document the `to`
notation.
- Rename some inst kinds and functions, and restructure some of the
code, for clarity and consistency with the new documentation.
- Resolve a TODO to handle more category conversions in
`CategoryConverter`, in order to make it easier to reason about category
conversions.

See #6588 and the review history of this PR for background.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2026-02-04 02:27:12 +00:00

45 lines
1.8 KiB
C++

// 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
#ifndef CARBON_TOOLCHAIN_SEM_IR_EXPR_INFO_H_
#define CARBON_TOOLCHAIN_SEM_IR_EXPR_INFO_H_
#include <cstdint>
#include "toolchain/sem_ir/file.h"
#include "toolchain/sem_ir/ids.h"
#include "toolchain/sem_ir/inst_kind.h"
namespace Carbon::SemIR {
// Returns the expression category for an instruction.
auto GetExprCategory(const File& file, InstId inst_id) -> ExprCategory;
// Returns whether the given expression category is for a reference expression.
inline auto IsRefCategory(ExprCategory cat) -> bool {
return cat == ExprCategory::DurableRef || cat == ExprCategory::EphemeralRef;
}
// Returns whether the given expression category is for an initializer
// (see inst_kind.h for background).
inline auto IsInitializerCategory(ExprCategory cat) -> bool {
return cat == ExprCategory::ReprInitializing ||
cat == ExprCategory::InPlaceInitializing;
}
// If `init_id` is an initializer, find the inst ID that specifies the storage
// to initialize, if any. If `allow_transitive` is true, the result may be an
// argument to some other inst whose outcome is forwarded by `init_id`;
// otherwise the result must be an argument to `init_id` itself. Returns `None`
// if there is no such storage argument. When `allow_transitive` is true, this
// can only return `None` if `init_id` is known not to perform in-place
// initialization; i.e. its type's initializing representation is not in-place,
// and its category is `Initializing`.
auto FindStorageArgForInitializer(const File& sem_ir, InstId init_id,
bool allow_transitive = true) -> InstId;
} // namespace Carbon::SemIR
#endif // CARBON_TOOLCHAIN_SEM_IR_EXPR_INFO_H_