Compute type layouts in SemIR / Check (#7066)

Instead of allowing lower to pick whatever type layout it desires,
compute the layouts of types as part of completing the type, and make
lower build types that match that representation.

For now we assume that all pointers are 64-bit, since we don't have
access to target information. We allow tail padding reuse for structs
and tuple types (and by extension, for classes, since they use structs
as their object representation), but not for arrays.

In order to build matching LLVM types, we create LLVM packed structs
where necessary, and we insert inter-field padding on the end of the
previous field so that GEP indexes still always match Carbon's
ElementIndexes.

We don't yet use the computed alignment much in LLVM IR generation -- in
particular, `alloca`s, `load`s, and `store`s should probably use the
computed type alignment, but don't.

Assisted-by: Gemini via Antigravity
This commit is contained in:
Richard Smith
2026-04-16 22:37:48 +00:00
committed by GitHub
parent 896338d281
commit a6061d975c
33 changed files with 1456 additions and 190 deletions
+1
View File
@@ -276,6 +276,7 @@ auto FunctionContext::InitializeStorage(TypeInFile type, SemIR::InstId dest_id,
if (sem_ir().constant_values().Get(source_id).is_constant()) {
// When initializing from a constant, emission of the source doesn't
// initialize the destination. Copy the constant value instead.
// TODO: If the type is small, emit a store rather than a memcpy.
CopyValue(type, source_id, dest_id);
}
break;