Interop support for initialization via std::initializer_list. (#6672)

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
This commit is contained in:
Richard Smith
2026-01-30 22:24:18 +00:00
committed by GitHub
parent 20a5c43e95
commit c0b24047dd
27 changed files with 2137 additions and 525 deletions
+5
View File
@@ -240,6 +240,11 @@ auto GetFacetType(Context& context, const SemIR::FacetTypeInfo& info)
context.facet_types().Add(info));
}
auto GetFacetAccessType(Context& context, SemIR::InstId facet_value_inst_id)
-> SemIR::TypeId {
return GetTypeImpl<SemIR::FacetAccessType>(context, facet_value_inst_id);
}
auto GetPointerType(Context& context, SemIR::TypeInstId pointee_type_id)
-> SemIR::TypeId {
return GetCompleteTypeImpl<SemIR::PointerType>(context, pointee_type_id);