mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 20:20:10 +01:00
Add a new builtin function `cpp.std.initializer_list.make` that takes an array and returns a `std::initializer_list`, initialized to refer to that array. When C++ initialization wants to perform a `std::initializer_list`-from-array construction, synthesize a declaration of a matching builtin function and use that to perform the initialization. Ideally we would specify this conversion as an impl of `ImplicitAs` in the prelude instead of hardcoding it in the interop layer, but unfortunately that's not currently possible, for various reasons -- we can't make the conversion form-generic, we can't deduce the array length from the initializer, and we can't deduce against the arguments of imported C++ class templates yet -- so for now synthesizing a builtin function on demand is the best we can do. Assisted-by: Gemini 3 Pro via Antigravity
37 lines
1.5 KiB
C++
37 lines
1.5 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_LOWER_AGGREGATE_H_
|
|
#define CARBON_TOOLCHAIN_LOWER_AGGREGATE_H_
|
|
|
|
#include "llvm/ADT/Twine.h"
|
|
#include "llvm/IR/Value.h"
|
|
#include "toolchain/lower/function_context.h"
|
|
#include "toolchain/sem_ir/ids.h"
|
|
|
|
namespace Carbon::Lower {
|
|
|
|
// Extracts an element of an aggregate, such as a struct, tuple, or class, by
|
|
// index. Depending on the expression category and value representation of the
|
|
// aggregate input, this will either produce a value or a reference.
|
|
auto GetAggregateElement(FunctionContext& context, SemIR::InstId aggr_inst_id,
|
|
SemIR::ElementIndex idx, SemIR::InstId result_inst_id,
|
|
llvm::Twine name) -> llvm::Value*;
|
|
|
|
// Emits the value representation for a struct or tuple whose elements are the
|
|
// contents of `refs_id`.
|
|
auto EmitAggregateValueRepr(FunctionContext& context,
|
|
SemIR::InstId value_inst_id,
|
|
SemIR::InstBlockId refs_id) -> llvm::Value*;
|
|
|
|
// Emits the initialization for a struct or tuple.
|
|
auto EmitAggregateInitializer(FunctionContext& context,
|
|
SemIR::InstId init_inst_id,
|
|
SemIR::InstBlockId refs_id, llvm::Twine name)
|
|
-> llvm::Value*;
|
|
|
|
} // namespace Carbon::Lower
|
|
|
|
#endif // CARBON_TOOLCHAIN_LOWER_AGGREGATE_H_
|