This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Identify Swift-implemented ObjC classes
ClosedPublic

Authored by kastiglione on Jun 13 2023, 10:38 AM.

Details

Summary

Classes implemented in Swift can be exposed to ObjC. For those classes, the ObjC
metadata is incomplete (the types of the ivars are incomplete), but as one would expect
the Swift metadata is complete. In such cases, the Swift runtime should be consulted
first when determining the dynamic type of a value.

Diff Detail

Event Timeline

kastiglione created this revision.Jun 13 2023, 10:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 13 2023, 10:38 AM
kastiglione requested review of this revision.Jun 13 2023, 10:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 13 2023, 10:38 AM
bulbazord added inline comments.
lldb/source/Core/ValueObjectDynamicValue.cpp
10

Is there a way we can avoid using a plugin in non-plugin code?

kastiglione added inline comments.Jun 13 2023, 11:06 AM
lldb/source/Core/ValueObjectDynamicValue.cpp
118–122

@bulbazord this is where it's used, to work with ClassDescriptor which is part of the ObjCLanguageRuntime. I don't think it would make sense to lift that into the generic LangaugeRuntime. What other courses might there be?

aprantl added inline comments.Jun 13 2023, 11:07 AM
lldb/source/Core/ValueObjectDynamicValue.cpp
152

This is a bit of a layering violation. Could the ObjC language runtime perform this check in GetDynamicTypeAndAddress and dispatch to the Swift runtime there?

If you do this, we need to ensure we can't get into an infinite loop between the runtimes.

Alternatively, we could add a virtual GetPreferredLanguageRuntime() method to LanguageRuntime that we call here, maybe?

lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
90

Can you add a Doxygen commen?
/// Determine whether this class is implemented in Swift.

Refactor for better API layering

@bulbazord @augusto2112 hopefully this is a quick review.

My concerns have been addressed, LGTM.

augusto2112 accepted this revision.Jul 11 2023, 3:59 PM
This revision is now accepted and ready to land.Jul 11 2023, 3:59 PM

Change bool IsSwift() to LanguageType GetImplementationLanguage()

Redo ValueObjectDynamicValue::UpdateValue changes based on upstream testing

This revision was landed with ongoing or failed builds.Jul 20 2023, 7:32 PM
This revision was automatically updated to reflect the committed changes.