Skip to content

Implement TypeSystemSwiftTypeRef::GetPointerByteSize() (NFC) … #1497

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5282,10 +5282,6 @@ SwiftASTContext::GetAllocationStrategy(opaque_compiler_type_t type) {
// Type Completion
//----------------------------------------------------------------------

bool SwiftASTContext::GetCompleteType(opaque_compiler_type_t type) {
return true;
}

ConstString SwiftASTContext::GetTypeName(opaque_compiler_type_t type) {
std::string type_name;
if (type) {
Expand Down
4 changes: 0 additions & 4 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,6 @@ class SwiftASTContext : public TypeSystemSwift {
const CompilerType &type, NonTriviallyManagedReferenceStrategy &strategy,
CompilerType *underlying_type = nullptr);

// Type Completion

bool GetCompleteType(lldb::opaque_compiler_type_t type) override;

// AST related queries

uint32_t GetPointerByteSize() override;
Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ class TypeSystemSwift : public TypeSystem {
bool IsBeingDefined(lldb::opaque_compiler_type_t type) override {
return false;
}
bool GetCompleteType(lldb::opaque_compiler_type_t type) override {
return true;
}
bool CanPassInRegisters(const CompilerType &type) override {
// FIXME: Implement this. There was an abort() here to figure out which
// tests where hitting this code. At least TestSwiftReturns and
Expand Down
37 changes: 27 additions & 10 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,16 @@ template <> bool Equivalent<ConstString>(ConstString l, ConstString r) {

// This can be removed once the transition is complete.
#ifndef NDEBUG
#define VALIDATE_AND_RETURN_STATIC(IMPL, REFERENCE) \
do { \
auto result = IMPL(); \
if (!m_swift_ast_context) \
return result; \
assert((result == m_swift_ast_context->REFERENCE()) && \
"TypeSystemSwiftTypeRef diverges from SwiftASTContext"); \
return result; \
} while (0)

#define VALIDATE_AND_RETURN(IMPL, REFERENCE, TYPE, ARGS) \
do { \
auto result = IMPL(); \
Expand All @@ -1133,11 +1143,8 @@ template <> bool Equivalent<ConstString>(ConstString l, ConstString r) {
return result; \
} while (0)
#else
#define VALIDATE_AND_RETURN(IMPL, REFERENCE, TYPE, ARGS) \
do { \
auto result = IMPL(); \
return result; \
} while (0)
#define VALIDATE_AND_RETURN_STATIC(IMPL, REFERENCE) return IMPL()
#define VALIDATE_AND_RETURN(IMPL, REFERENCE, TYPE, ARGS) return IMPL()
#endif

CompilerType
Expand Down Expand Up @@ -1383,13 +1390,23 @@ bool TypeSystemSwiftTypeRef::IsVoidType(opaque_compiler_type_t type) {
};
VALIDATE_AND_RETURN(impl, IsVoidType, type, (ReconstructType(type)));
}
// Type Completion
bool TypeSystemSwiftTypeRef::GetCompleteType(opaque_compiler_type_t type) {
return m_swift_ast_context->GetCompleteType(ReconstructType(type));
}
// AST related queries
uint32_t TypeSystemSwiftTypeRef::GetPointerByteSize() {
return m_swift_ast_context->GetPointerByteSize();
auto impl = [&]() -> uint32_t {
if (auto *module = GetModule()) {
auto &triple = module->GetArchitecture().GetTriple();
if (triple.isArch64Bit())
return 8;
if (triple.isArch32Bit())
return 4;
if (triple.isArch16Bit())
return 2;
}
// An expression context has no module. Since it's for expression
// evaluation we might as well defer to the SwiftASTContext.
return m_swift_ast_context->GetPointerByteSize();
};
VALIDATE_AND_RETURN_STATIC(impl, GetPointerByteSize);
}
// Accessors
ConstString TypeSystemSwiftTypeRef::GetTypeName(opaque_compiler_type_t type) {
Expand Down
2 changes: 0 additions & 2 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
bool IsPointerType(lldb::opaque_compiler_type_t type,
CompilerType *pointee_type) override;
bool IsVoidType(lldb::opaque_compiler_type_t type) override;
// Type Completion
bool GetCompleteType(lldb::opaque_compiler_type_t type) override;
// AST related queries
uint32_t GetPointerByteSize() override;
// Accessors
Expand Down