Skip to content

Remove bypass of GetAddressOf when dealing with dynamic class types in variable materialization #1455

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

Conversation

augusto2112
Copy link

@augusto2112 augusto2112 force-pushed the remove-dynamic-class-type-check-materialization branch from 139ea41 to 5b66545 Compare July 14, 2020 19:39
@@ -489,19 +489,12 @@ class EntityVariable : public Materializer::Entity {
}
} else {
AddressType address_type = eAddressTypeInvalid;
const bool is_dynamic_class_type =
m_is_generic &&

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Is m_is_generic dead code after this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left scalar_is_load_address = m_is_generic since I though the changes should be independent, but after removing that m_is_generic is indeed dead code!

@adrian-prantl
Copy link

@swift-ci test

@adrian-prantl
Copy link

Just to clarify: This brings the code in sync with llvm.org again?

Copy link

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. The fewer swift-lldb-specific changes we need, the better!

@augusto2112
Copy link
Author

Just to clarify: This brings the code in sync with llvm.org again?

@adrian-prantl I didn't include the change of scalar_is_load_address in this PR (should I add that here?), but the changes of this and #1452 would leave the definition of scalar_is_load_address and addr_of_valobj the same as in llvm.org.

I'm not sure if you're asking if the code following that is the same as well, so here are the differences I found for the rest of the function:

  • There is a Swift-exclusive block of code:
      // BEGIN Swift.
      if (lldb::ProcessSP process_sp =
          map.GetBestExecutionContextScope()->CalculateProcess())
        if (auto runtime = process_sp->GetLanguageRuntime(
                valobj_type.GetMinimumLanguage())) {
          Status read_error;
          addr_of_valobj =
              runtime->FixupAddress(addr_of_valobj, valobj_type, read_error);
        }
      // END Swift.
  • There's also a Swift only check for empty structs when materialization fails:
          if (valobj_type.GetMinimumLanguage() == lldb::eLanguageTypeSwift) {
            llvm::Optional<uint64_t> size =
                valobj_type.GetByteSize(frame_sp.get());
            if (size && *size == 0) {
              // We don't need to materialize empty structs in Swift.
              return;
            }
          }
  • GetByteSize call is different:
    • Swift: if (data.GetByteSize() < m_variable_sp->GetType()->GetByteSize(scope))
    • LLVM: if (data.GetByteSize() < m_variable_sp->GetType()->GetByteSize())
  • Another call to GetByteSize:
    • Swift: m_variable_sp->GetType()->GetByteSize(map.GetBestExecutionContextScope()) .getValueOr(0)
    • LLVM: m_variable_sp->GetType()->GetByteSize().getValueOr(0)

@adrian-prantl
Copy link

Just to clarify: This brings the code in sync with llvm.org again?

@adrian-prantl I didn't include the change of scalar_is_load_address in this PR (should I add that here?), but the changes of this and #1452 would leave the definition of scalar_is_load_address and addr_of_valobj the same as in llvm.org.

I'm not sure if you're asking if the code following that is the same as well, so here are the differences I found for the rest of the function:

  • There is a Swift-exclusive block of code:
      // BEGIN Swift.
      if (lldb::ProcessSP process_sp =
          map.GetBestExecutionContextScope()->CalculateProcess())
        if (auto runtime = process_sp->GetLanguageRuntime(
                valobj_type.GetMinimumLanguage())) {
          Status read_error;
          addr_of_valobj =
              runtime->FixupAddress(addr_of_valobj, valobj_type, read_error);
        }
      // END Swift.

I think this one is strictly necessary. IIRC, it is to support global resilient values.

  • There's also a Swift only check for empty structs when materialization fails:
          if (valobj_type.GetMinimumLanguage() == lldb::eLanguageTypeSwift) {
            llvm::Optional<uint64_t> size =
                valobj_type.GetByteSize(frame_sp.get());
            if (size && *size == 0) {
              // We don't need to materialize empty structs in Swift.
              return;
            }
          }

I added support for zero-sized types to llvm.org's lldb ~1 year ago, maybe this is no longer necessary, or could be upstreamed.

  • GetByteSize call is different:

    • Swift: if (data.GetByteSize() < m_variable_sp->GetType()->GetByteSize(scope))
    • LLVM: if (data.GetByteSize() < m_variable_sp->GetType()->GetByteSize())
  • Another call to GetByteSize:

    • Swift: m_variable_sp->GetType()->GetByteSize(map.GetBestExecutionContextScope()) .getValueOr(0)
    • LLVM: m_variable_sp->GetType()->GetByteSize().getValueOr(0)

That is also necessary. In many cases we need to ask GetByteSize() to the Swift runtime, and we can only do that with an ExecutionContext. We should eventually upstream this change.

Thanks for the analysis!

@adrian-prantl adrian-prantl merged commit 393b271 into swiftlang:swift/master Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants