-
Notifications
You must be signed in to change notification settings - Fork 344
[lldb] Wire-up TypeSystemSwiftTypeRef::GetNumChildren #2200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lldb] Wire-up TypeSystemSwiftTypeRef::GetNumChildren #2200
Conversation
lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp
Outdated
Show resolved
Hide resolved
EDIT: Resolved by 79f7869. When running the The issue is the |
@swift-ci test |
lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp
Outdated
Show resolved
Hide resolved
TODO:
|
With the fallback to 1. Possible Bugs in SwiftASTContextIt seems that for these types,
2. Function Types "false positive"These cases are function types.
3. Protocol Type implementation differencesI don't have any insight to these. Both values seem weird to me. For example
4. TBD
|
@swift-ci test |
Running tests to see if CI has different results from my local run. |
Great summary!
That looks great. In previous cases, I've amended the
what are the "children" of a function type? I'm curious what path we go down that reports children and if that is indicative of a bug. If that code looks reasonable, then special-casing function types sounds right.
I agree, these are both suspicious. We could ignore them in the comparison and file a bug to investigate later.
This one is scary, because it is a Foundation value type! Is that just an unimplemented case, or do we have a deeper problem?
|
Since there was only the one failure, I was optimistic it wouldn't be too much of any issue. The problem was specific to |
@swift-ci test |
That makes sense. Without a process, we don't have a language runtime. In GetChildCompilerTypeAtIndex() I partially worked around this by still resolving Clang types statically, but in this particular case that wouldn't work. I think we have to drop support for |
Ah it turns out one of the cases is quite relevant. One case of these assertions is coming from the |
Awesome! |
For protocol types, the difference in child count is 3 in each case (5 vs 2, 4 vs 1). Looking at one test that asserts, the raw output for the protocol includes payload, metadata, and witness table. Example:
For Seems then the way to proceed to is to stick with current behavior? Have @adrian-prantl I can check, but do you know off the top of your head how |
If you look at the code, these (payload_data,...) are actually hardcoded in LLDB and their usefulness is questionable if you look at the dataformatters. |
🤦 Yeah, they're not that used. I'll keep compatibility, we can visit their existence later. |
@swift-ci test |
lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp
Outdated
Show resolved
Hide resolved
@swift-ci test |
@@ -82,7 +82,7 @@ def cleanup(): | |||
# This test is deliberately checking what the user will see, rather than | |||
# the structure provided by the Python API, in order to test the recovery. | |||
self.expect("fr var", substrs=[ | |||
"(SomeLibrary.ContainsTwoInts) container = (other = 10)", | |||
"(SomeLibrary.ContainsTwoInts) container = {", "other = 10", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is perhaps indicative of issues that need to be solved in this PR, or in follow ups.
ContainsTwoInts
is defined as:
public struct ContainsTwoInts {
internal var wrapped: TwoInts
public var other: Int
}
This was previously formatted as container = (other = 10)
but with these changes it's formatted as:
container = {
other = 10
}
The same data is printed, but the difference is (presumably) that ShouldPrintAsOneLiner
is no longer true. Note that despite there being two children in the type, lldb prints only one, the public property other
.
Based on my debugging of other discrepancies, my guess is that GetNumChildren
now returns 2 instead of 1, which then causes ShouldPrintAsOneLiner
to return false.
What I think should be possible now, is for lldb to print both properties, wrapped
and other
. I'll take a look tomorrow to see if the TypeRef
implementation of GetChildCompilerTypeAtIndex
is excluding wrapped
to mirror the behavior of SwiftASTContext
. If that is the case, it seems like something we should fix, showing private properties too would be an improvement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds great! Thanks for the thoughtful analysis.
All tests pass, ready for review. |
uint32_t | ||
TypeSystemSwiftTypeRef::GetNumChildren(opaque_compiler_type_t type, | ||
bool omit_empty_base_classes, | ||
const ExecutionContext *exe_ctx) { | ||
return m_swift_ast_context->GetNumChildren(ReconstructType(type), | ||
omit_empty_base_classes, exe_ctx); | ||
if (IsFunctionType(type, nullptr)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for my curiosity: What are the children of a function type that the runtime reports?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant to find that out too, I'll reply with the answer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My guess is implicit self, and/or a capture context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fields are function
, whose mangled symbol is a ThinFunctionType
, and context
whose mangled symbol is Builtin.NativeObject
. The type info is a RecordKind::ThickFunction
.
Since RecordKind::OpaqueExistential
is handled in SwiftLanguageRuntimeImpl
, I'm thinking it's reasonable and maybe good to handle RecordKind::ThickFunction
there too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved function handling: a5d4945
@swift-ci test |
Make
TypeSystemSwiftTypeRef::GetNumChildren
use reflection viaSwiftLanguageRuntimeImpl
instead of usingSwiftASTContext
.This required changes to
SwiftLanguageRuntimeImpl::GetNumChildren
, to handleEnumTypeInfo
andOpaqueExistential
.Other notes:
Equivalent
helper was tweaked to allowGetNumChildren
to use>=
when validating. This is becauseTypeRef
s can, in some cases, expose more children thanSwiftASTContext
(for example when using library evolution and.swiftinterface
files)SwiftASTContext
(and makes sense).TypeRef
s for function types can contain a non-zero number of children.rdar://68171335