Skip to content

Commit fdda925

Browse files
Merge pull request #7267 from adrian-prantl/113997661-fully-realized-5.9
Replace IsFullyRealized() with !IsMeaninglessWithoutDynamicResolution() (NFC)
2 parents 88deaff + c939393 commit fdda925

File tree

5 files changed

+32
-23
lines changed

5 files changed

+32
-23
lines changed

lldb/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,8 +1087,16 @@ bool SwiftASTManipulator::AddExternalVariables(
10871087

10881088
swift::VarDecl *redirected_var_decl =
10891089
GetVarDeclForVariableInFunction(variable, containing_function);
1090+
if (!redirected_var_decl) {
1091+
LLDB_LOG(log, "No var decl.");
1092+
continue;
1093+
}
10901094
swift::PatternBindingDecl *pattern_binding =
10911095
GetPatternBindingForVarDecl(redirected_var_decl, containing_function);
1096+
if (!pattern_binding) {
1097+
LLDB_LOG(log, "No pattern binding.");
1098+
continue;
1099+
}
10921100

10931101
// Push the var decl and pattern binding so we add them to the function
10941102
// later.

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,16 @@ CompilerType SwiftExpressionParser::ResolveVariable(
491491
if (!var_type.IsValid())
492492
return {};
493493

494+
auto swift_type_system =
495+
var_type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
496+
if (!swift_type_system)
497+
return {};
498+
494499
// If the type can't be realized and dynamic types are allowed, fall back to
495500
// the dynamic type. We can only do this when not binding generic types
496501
// though, as we don't bind the generic parameters in that case.
497-
if (!SwiftASTContext::IsFullyRealized(var_type) &&
502+
if (swift_type_system->IsMeaninglessWithoutDynamicResolution(
503+
var_type.GetOpaqueQualType()) &&
498504
bind_generic_types != lldb::eDontBind && use_dynamic_value) {
499505
var_type = GetSwiftTypeForVariableValueObject(
500506
valobj_sp->GetDynamicValue(use_dynamic), stack_frame_sp, runtime,

lldb/source/Plugins/ExpressionParser/Swift/SwiftUserExpression.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,19 @@ static bool AddVariableInfo(
330330
return true;
331331
}
332332

333+
// Report a fatal error if self can't be reconstructed as a Swift AST type.
334+
if (is_self && !GetSwiftType(target_type))
335+
return false;
336+
337+
auto ts = target_type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
338+
if (!ts)
339+
return false;
340+
333341
// If we couldn't fully realize the type, then we aren't going
334342
// to get very far making a local out of it, so discard it here.
335343
Log *log = GetLog(LLDBLog::Types | LLDBLog::Expressions);
336-
if (!is_unbound_pack && !SwiftASTContext::IsFullyRealized(target_type)) {
344+
if (!is_unbound_pack && ts->IsMeaninglessWithoutDynamicResolution(
345+
target_type.GetOpaqueQualType())) {
337346
if (log)
338347
log->Printf("Discarding local %s because we couldn't fully realize it, "
339348
"our best attempt was: %s.",

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -850,12 +850,11 @@ SwiftASTContext::GetCachedEnumInfo(opaque_compiler_type_t type) {
850850
if (pos != enum_info_cache->end())
851851
return pos->second.get();
852852

853-
swift::CanType swift_can_type(GetCanonicalSwiftType(type));
854-
if (!SwiftASTContext::IsFullyRealized(ToCompilerType({swift_can_type})))
853+
if (IsMeaninglessWithoutDynamicResolution(type))
855854
return nullptr;
856855

857856
SwiftEnumDescriptorSP enum_info_sp;
858-
857+
swift::CanType swift_can_type(GetCanonicalSwiftType(type));
859858
if (auto *enum_type = swift_can_type->getAs<swift::EnumType>()) {
860859
enum_info_sp.reset(GetEnumInfoFromEnumDecl(GetASTContext(), swift_can_type,
861860
enum_type->getDecl()));
@@ -5163,17 +5162,6 @@ SwiftASTContext::GetStaticSelfType(lldb::opaque_compiler_type_t type) {
51635162
return {weak_from_this(), type};
51645163
}
51655164

5166-
bool SwiftASTContext::IsFullyRealized(const CompilerType &compiler_type) {
5167-
if (swift::CanType swift_can_type = ::GetCanonicalSwiftType(compiler_type)) {
5168-
if (swift::isa<swift::MetatypeType>(swift_can_type))
5169-
return true;
5170-
return !swift_can_type->hasArchetype() &&
5171-
!swift_can_type->hasTypeParameter();
5172-
}
5173-
5174-
return false;
5175-
}
5176-
51775165
bool SwiftASTContext::GetProtocolTypeInfo(const CompilerType &type,
51785166
ProtocolInfo &protocol_info) {
51795167
LLDB_SCOPED_TIMER();

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,11 @@ class SwiftASTContext : public TypeSystemSwift {
411411
swift::CanType
412412
GetCanonicalSwiftType(lldb::opaque_compiler_type_t opaque_type);
413413

414-
// Imports the type from the passed in type into this SwiftASTContext. The
415-
// type must be a Swift type. If the type can be imported, returns the
416-
// CompilerType for the imported type.
417-
// If it cannot be, returns an invalid CompilerType, and sets the error to
418-
// indicate what went wrong.
414+
/// Imports the type from the passed in type into this SwiftASTContext. The
415+
/// type must be a Swift type. If the type can be imported, returns the
416+
/// CompilerType for the imported type.
417+
/// If it cannot be, returns an invalid CompilerType, and sets the error to
418+
/// indicate what went wrong.
419419
CompilerType ImportType(CompilerType &type, Status &error);
420420

421421
swift::ClangImporter *GetClangImporter();
@@ -582,8 +582,6 @@ class SwiftASTContext : public TypeSystemSwift {
582582
/// Whether this is the Swift error type.
583583
bool IsErrorType(lldb::opaque_compiler_type_t type);
584584

585-
static bool IsFullyRealized(const CompilerType &compiler_type);
586-
587585
struct ProtocolInfo {
588586
uint32_t m_num_protocols;
589587
uint32_t m_num_payload_words;

0 commit comments

Comments
 (0)