[llvm] [DebugInfo] Add num_extra_inhabitants to debug info (PR #112590)

Augusto Noronha via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 16 15:06:45 PDT 2024


augusto2112 wrote:

> What would it do with this information? 

This information is used to calculate the layout of types. For example, since Bool has extra inhabitants, the debugger needs that information to calculate that Optional<Bool> will only use 1 byte.

Since Swift generics are not monomorphized, by using dynamic libraries you can have generic types whose size, alignment, etc, are known only at runtime (which is why this feature is needed).

> How would it know what the actual invalid bit patterns are? For example, an enum with two enumerators with values equal to 0 and 5 would have exactly the same number of "extra inhabitants" as bool.

This is part of the ABI of the language (which is why I added the attribute as an Apple extension). You are correct that if you have an enum with two enumerators equal to 0 and 5 you can't know which bit patterns are extra inhabitants. But for enums that don't specify what the integer representation is, two enumerators means that all bit patterns outside 0 and 1 are extra inhabitants.

https://github.com/llvm/llvm-project/pull/112590


More information about the llvm-commits mailing list