Add a Core.Array class type, and make array refer to it. (#7892)

As described in proposal #4682, make `array(T, N)` be syntactic sugar
for the type `Core.Array` defined in the standard library. This provides
a home for impls that are specific to `Core.Array`.

Assisted-by: Gemini and Claude via Antigravity
This commit is contained in:
Richard Smith authored and GitHub committed 2026-10-06 17:23:49 +00:00
1 parent a50feb64ce
commit 947c1eb527
131 files changed
+9007 -8238

No files matched your search

+6 -6
View File
@@ -1444,8 +1444,9 @@ static auto MapReferenceType(Context& context, clang::QualType type,
return TypeExpr::ForUnsugared(context, pointer_type_id);
}
// Maps a C++ array type to a Carbon array type.
static auto MapArrayType(Context& context, const clang::ArrayType* array_type,
// Maps a C++ array type to a Carbon array type, `Core.Array(T, N)`.
static auto MapArrayType(Context& context, SemIR::LocId loc_id,
const clang::ArrayType* array_type,
TypeExpr element_type_expr) -> TypeExpr {
if (const auto* constant_array_type =
llvm::dyn_cast<clang::ConstantArrayType>(array_type)) {
@@ -1456,9 +1457,8 @@ static auto MapArrayType(Context& context, const clang::ArrayType* array_type,
.int_id = context.ints().AddUnsigned(
constant_array_type->getSize())});
auto bound_inst_id = context.constant_values().GetInstId(bound_const_id);
auto array_type_id =
GetArrayType(context, bound_inst_id, element_type_expr.inst_id);
return TypeExpr::ForUnsugared(context, array_type_id);
return MakeArrayType(context, loc_id, element_type_expr.inst_id,
bound_inst_id);
}
return TypeExpr::None;
@@ -1502,7 +1502,7 @@ static auto MapType(Context& context, SemIR::LocId loc_id, clang::QualType type)
} else if (wrapper->isReferenceType()) {
mapped = MapReferenceType(context, wrapper, mapped);
} else if (const auto* array_type = wrapper->getAsArrayTypeUnsafe()) {
mapped = MapArrayType(context, array_type, mapped);
mapped = MapArrayType(context, loc_id, array_type, mapped);
} else {
CARBON_FATAL("Unexpected wrapper type {0}", wrapper.getAsString());
}