Support array types with dependent bounds. (#4751)

Given `N:! i32`, the type `[T; N]` is a valid but dependent array type.
This commit is contained in:
Richard Smith
2025-01-09 22:46:22 +00:00
committed by GitHub
parent 3a6fd0306e
commit d31fc9ad02
12 changed files with 816 additions and 469 deletions
+8 -6
View File
@@ -1527,13 +1527,15 @@ static auto TryEvalInstInContext(EvalContext& eval_context,
eval_context, inst,
[&](SemIR::ArrayType result) {
auto bound_id = array_type.bound_id;
auto int_bound =
eval_context.insts().TryGetAs<SemIR::IntValue>(result.bound_id);
auto bound_inst = eval_context.insts().Get(result.bound_id);
auto int_bound = bound_inst.TryAs<SemIR::IntValue>();
if (!int_bound) {
// TODO: Permit symbolic array bounds. This will require fixing
// callers of `GetArrayBoundValue`.
eval_context.context().TODO(bound_id, "symbolic array bound");
return false;
CARBON_CHECK(eval_context.constant_values()
.Get(result.bound_id)
.is_symbolic(),
"Unexpected inst {0} for template constant int",
bound_inst);
return true;
}
// TODO: We should check that the size of the resulting array type
// fits in 64 bits, not just that the bound does. Should we use a