[DebugInfo] Add new DW_AT_APPLE_enum_kind to encode enum_extensibility #9956
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When creating
EnumDecl
s from DWARF for Objective-CNS_ENUM
s, the Swift compiler tries to figure out if it should perform "swiftification" of that enum (which involves renaming the enumerator cases, etc.). The heuristics by which it determines whether we want to swiftify an enum is by checking theenum_extensibility
attribute (because that's whatNS_ENUM
pretty much are). Currently LLDB fails to attach theEnumExtensibilityAttr
toEnumDecl
s it creates (because there's not enough info in DWARF to derive it), which means we have to fall back to re-building Swift modules on-the-fly, slowing down expression evaluation substantially. This happens around https://github.com/swiftlang/swift/blob/4b3931c8ce437b3f13f245e6423f95c94a5876ac/lib/ClangImporter/ImportEnumInfo.cpp#L37-L59To speed up Swift exression evaluation, this patch proposes encoding the C/C++/Objective-C
enum_extensibility
attribute in DWARF via a newDW_AT_APPLE_ENUM_KIND
. This would currently be only used from the LLDB Swift plugin. But may be of interest to other language plugins as well (though I haven't come up with a concrete use-case for it outside of Swift).I'm open to naming suggestions of the various new attributes/attribute constants proposed here. I tried to be as generic as possible if we wanted to extend it to other kinds of enum properties (e.g., flag enums).
The new attribute would look as follows:
Absence of the attribute means the extensibility of the enum is unknown and abides by whatever the language rules of that CU dictate.
Alternatives considered:
DW_TAG_enumeration_type
could have aDW_AT_count
orDW_AT_upper_bound
indicating the number of enumerators, which could imply closed-ness. I felt like a dedicated attribute (which could be generalized further) seemed more applicable. But I'm open to re-using existing attributes.DW_TAG_LLVM_annotation ("enum_extensibility((open))")
) on theDW_TAG_enumeration_type
. Then in LLDB somehow parse that out into aEnumExtensibilityAttr
. I haven't found a great API in Clang to parse arbitrary strings into AST nodes (the ones I've found required fully formed C++ constructs). Though if someone knows of a good way to do this, happy to consider that too.