Skip to content

SwiftASTContext::GetMinimumLanguage() into TypeSystemSwift (NFC) … #1502

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 4 commits into from
Jul 20, 2020
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
14 changes: 1 addition & 13 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ swift::Type SwiftASTContext::GetSwiftType(opaque_compiler_type_t opaque_type) {

swift::CanType
SwiftASTContext::GetCanonicalSwiftType(opaque_compiler_type_t opaque_type) {
assert(opaque_type && *reinterpret_cast<const char *>(opaque_type) != '$' &&
assert(!opaque_type || *reinterpret_cast<const char *>(opaque_type) != '$' &&
"wrong type system");
return lldb_private::GetCanonicalSwiftType(CompilerType(this, opaque_type));
}
Expand Down 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 Expand Up @@ -5501,14 +5497,6 @@ SwiftASTContext::GetTypeInfo(opaque_compiler_type_t type,
return swift_flags;
}

lldb::LanguageType
SwiftASTContext::GetMinimumLanguage(opaque_compiler_type_t type) {
if (!type)
return lldb::eLanguageTypeC;

return lldb::eLanguageTypeSwift;
}

lldb::TypeClass SwiftASTContext::GetTypeClass(opaque_compiler_type_t type) {
VALID_OR_RETURN(lldb::eTypeClassInvalid);

Expand Down
7 changes: 0 additions & 7 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 All @@ -529,9 +525,6 @@ class SwiftASTContext : public TypeSystemSwift {
uint32_t GetTypeInfo(lldb::opaque_compiler_type_t type,
CompilerType *pointee_or_element_clang_type) override;

lldb::LanguageType
GetMinimumLanguage(lldb::opaque_compiler_type_t type) override;

lldb::TypeClass GetTypeClass(lldb::opaque_compiler_type_t type) override;

// Creating related types
Expand Down
7 changes: 7 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,19 @@ 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
// TestSwiftStepping were failing because of this Darwin.
return false;
}
lldb::LanguageType
GetMinimumLanguage(lldb::opaque_compiler_type_t type) override {
return lldb::eLanguageTypeSwift;
}
unsigned GetTypeQualifiers(lldb::opaque_compiler_type_t type) override {
return 0;
}
Expand Down
41 changes: 27 additions & 14 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 Expand Up @@ -1440,10 +1457,6 @@ uint32_t TypeSystemSwiftTypeRef::GetTypeInfo(
VALIDATE_AND_RETURN(impl, GetTypeInfo, type,
(ReconstructType(type), nullptr));
}
lldb::LanguageType
TypeSystemSwiftTypeRef::GetMinimumLanguage(opaque_compiler_type_t type) {
return m_swift_ast_context->GetMinimumLanguage(ReconstructType(type));
}
lldb::TypeClass
TypeSystemSwiftTypeRef::GetTypeClass(opaque_compiler_type_t type) {
return m_swift_ast_context->GetTypeClass(ReconstructType(type));
Expand Down
4 changes: 0 additions & 4 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 All @@ -112,8 +110,6 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
ConstString GetMangledTypeName(lldb::opaque_compiler_type_t type) override;
uint32_t GetTypeInfo(lldb::opaque_compiler_type_t type,
CompilerType *pointee_or_element_clang_type) override;
lldb::LanguageType
GetMinimumLanguage(lldb::opaque_compiler_type_t type) override;
lldb::TypeClass GetTypeClass(lldb::opaque_compiler_type_t type) override;

// Creating related types
Expand Down
11 changes: 11 additions & 0 deletions lldb/unittests/Symbol/TestTypeSystemSwiftTypeRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,14 @@ TEST_F(TestTypeSystemSwiftTypeRef, ScalarAddress) {
ASSERT_TRUE(c.ShouldTreatScalarValueAsAddress());
}
}

TEST_F(TestTypeSystemSwiftTypeRef, LanguageVersion) {
using namespace swift::Demangle;
Demangler dem;
NodeBuilder b(dem);
{
NodePointer int_node = b.GlobalTypeMangling(b.IntType());
CompilerType int_type = GetCompilerType(b.Mangle(int_node));
ASSERT_EQ(int_type.GetMinimumLanguage(), lldb::eLanguageTypeSwift);
}
}