From 5894f26fb447e80e5eded63627d6d7e48c708eee Mon Sep 17 00:00:00 2001 From: Alex Langford Date: Tue, 20 Aug 2019 11:38:53 -0700 Subject: [PATCH] [Symbol] Remove swift from CompilerType I removed clang from CompilerType, so removing swift seems like the natural progression --- include/lldb/Symbol/CompilerType.h | 2 - .../Swift/SwiftASTManipulator.cpp | 17 +- .../Swift/SwiftExpressionVariable.h | 1 + .../Swift/SwiftREPLMaterializer.h | 1 + .../Language/Swift/SwiftFormatters.cpp | 4 +- .../Plugins/Language/Swift/SwiftLanguage.cpp | 9 +- .../SymbolFile/DWARF/DWARFASTParserSwift.cpp | 4 +- source/Symbol/CompilerType.cpp | 9 - source/Symbol/SwiftASTContext.cpp | 208 ++++++++++-------- source/Target/SwiftLanguageRuntime.cpp | 13 +- 10 files changed, 159 insertions(+), 109 deletions(-) diff --git a/include/lldb/Symbol/CompilerType.h b/include/lldb/Symbol/CompilerType.h index b048eee154e4..9b3a25d64200 100644 --- a/include/lldb/Symbol/CompilerType.h +++ b/include/lldb/Symbol/CompilerType.h @@ -13,7 +13,6 @@ #include #include -#include "lldb/Core/SwiftForward.h" #include "lldb/lldb-private.h" #include "llvm/ADT/APSInt.h" @@ -32,7 +31,6 @@ class CompilerType { public: // Constructors and Destructors CompilerType(TypeSystem *type_system, lldb::opaque_compiler_type_t type); - CompilerType(swift::Type qual_type); CompilerType(const CompilerType &rhs) : m_type(rhs.m_type), m_type_system(rhs.m_type_system) {} diff --git a/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp b/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp index b74681b31a43..3e2d8957ec3a 100644 --- a/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp +++ b/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp @@ -748,7 +748,9 @@ void SwiftASTManipulator::FindVariableDeclarations( auto type = var_decl->getDeclContext()->mapTypeIntoContext( var_decl->getInterfaceType()); persistent_info.m_name = name; - persistent_info.m_type = {type.getPointer()}; + persistent_info.m_type = CompilerType( + SwiftASTContext::GetSwiftASTContext(&type->getASTContext()), + type.getPointer()); persistent_info.m_decl = var_decl; m_variables.push_back(persistent_info); @@ -814,7 +816,8 @@ void SwiftASTManipulator::InsertResult( SwiftASTManipulator::ResultLocationInfo &result_info) { swift::ASTContext &ast_context = m_source_file.getASTContext(); - CompilerType return_ast_type(result_type.getPointer()); + CompilerType return_ast_type(SwiftASTContext::GetSwiftASTContext(&ast_context), + result_type.getPointer()); result_var->overwriteAccess(swift::AccessLevel::Public); result_var->overwriteSetterAccess(swift::AccessLevel::Public); @@ -855,7 +858,8 @@ void SwiftASTManipulator::InsertError(swift::VarDecl *error_var, swift::ASTContext &ast_context = m_source_file.getASTContext(); - CompilerType error_ast_type(error_type.getPointer()); + CompilerType error_ast_type(SwiftASTContext::GetSwiftASTContext(&ast_context), + error_type.getPointer()); error_var->overwriteAccess(swift::AccessLevel::Public); error_var->overwriteSetterAccess(swift::AccessLevel::Public); @@ -955,7 +959,8 @@ bool SwiftASTManipulator::FixupResultAfterTypeChecking(Status &error) { swift::ASTContext &ast_context = m_source_file.getASTContext(); - CompilerType return_ast_type(result_type.getPointer()); + CompilerType return_ast_type(SwiftASTContext::GetSwiftASTContext(&ast_context), + result_type.getPointer()); swift::Identifier result_var_name = ast_context.getIdentifier(GetResultName()); SwiftASTManipulatorBase::VariableMetadataSP metadata_sp( @@ -999,7 +1004,9 @@ bool SwiftASTManipulator::FixupResultAfterTypeChecking(Status &error) { continue; swift::Type error_type = var_decl->getInterfaceType(); - CompilerType error_ast_type(error_type.getPointer()); + CompilerType error_ast_type(SwiftASTContext::GetSwiftASTContext( + &error_type->getASTContext()), + error_type.getPointer()); SwiftASTManipulatorBase::VariableMetadataSP error_metadata_sp( new VariableMetadataError()); diff --git a/source/Plugins/ExpressionParser/Swift/SwiftExpressionVariable.h b/source/Plugins/ExpressionParser/Swift/SwiftExpressionVariable.h index c262f0de079b..afd30eb6a6e7 100644 --- a/source/Plugins/ExpressionParser/Swift/SwiftExpressionVariable.h +++ b/source/Plugins/ExpressionParser/Swift/SwiftExpressionVariable.h @@ -28,6 +28,7 @@ // Project includes #include "lldb/Core/ClangForward.h" +#include "lldb/Core/SwiftForward.h" #include "lldb/Core/Value.h" #include "lldb/Expression/ExpressionVariable.h" #include "lldb/Symbol/TaggedASTType.h" diff --git a/source/Plugins/ExpressionParser/Swift/SwiftREPLMaterializer.h b/source/Plugins/ExpressionParser/Swift/SwiftREPLMaterializer.h index 17c44ad4d728..512279a8bfd2 100644 --- a/source/Plugins/ExpressionParser/Swift/SwiftREPLMaterializer.h +++ b/source/Plugins/ExpressionParser/Swift/SwiftREPLMaterializer.h @@ -13,6 +13,7 @@ #ifndef liblldb_SwiftREPLMaterializer_h #define liblldb_SwiftREPLMaterializer_h +#include "lldb/Core/SwiftForward.h" #include "lldb/Expression/Materializer.h" namespace lldb_private { diff --git a/source/Plugins/Language/Swift/SwiftFormatters.cpp b/source/Plugins/Language/Swift/SwiftFormatters.cpp index fb6beec40c9e..6d1e8a31a8bf 100644 --- a/source/Plugins/Language/Swift/SwiftFormatters.cpp +++ b/source/Plugins/Language/Swift/SwiftFormatters.cpp @@ -1044,7 +1044,9 @@ bool lldb_private::formatters::swift::SIMDVector_SummaryProvider( if (generic_args.size() != 1) return false; auto swift_arg_type = generic_args[0]; - CompilerType arg_type(swift_arg_type); + CompilerType arg_type( + SwiftASTContext::GetSwiftASTContext(&swift_arg_type->getASTContext()), + swift_arg_type.getPointer()); llvm::Optional opt_arg_size = arg_type.GetByteSize(nullptr); if (!opt_arg_size) diff --git a/source/Plugins/Language/Swift/SwiftLanguage.cpp b/source/Plugins/Language/Swift/SwiftLanguage.cpp index 5dac9cb47ff6..eea9f04a0e95 100644 --- a/source/Plugins/Language/Swift/SwiftLanguage.cpp +++ b/source/Plugins/Language/Swift/SwiftLanguage.cpp @@ -1317,9 +1317,14 @@ std::unique_ptr SwiftLanguage::GetTypeScavenger() { results.insert(result); } else if (local_results.empty() && module && name_parts.size() == 1 && - name_parts.front() == module->getName().str()) + name_parts.front() == + module->getName().str()) { + auto module_type = swift::ModuleType::get(module); results.insert( - CompilerType(swift::ModuleType::get(module))); + CompilerType(SwiftASTContext::GetSwiftASTContext( + &module_type->getASTContext()), + module_type)); + } return true; }); diff --git a/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.cpp b/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.cpp index b4c6a257128d..2a53c074d506 100644 --- a/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.cpp +++ b/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.cpp @@ -189,7 +189,9 @@ lldb::TypeSP DWARFASTParserSwift::ParseTypeFromDWARF(const SymbolContext &sc, return {}; } preferred_name = name; - compiler_type = {swift_ast_ctx->TheRawPointerType}; + compiler_type = + CompilerType(SwiftASTContext::GetSwiftASTContext(swift_ast_ctx), + swift_ast_ctx->TheRawPointerType.getPointer()); } } diff --git a/source/Symbol/CompilerType.cpp b/source/Symbol/CompilerType.cpp index 85faf35982ab..129a63e0faa8 100644 --- a/source/Symbol/CompilerType.cpp +++ b/source/Symbol/CompilerType.cpp @@ -10,7 +10,6 @@ #include "lldb/Core/Debugger.h" #include "lldb/Core/StreamFile.h" -#include "lldb/Symbol/SwiftASTContext.h" #include "lldb/Symbol/Type.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/Process.h" @@ -24,9 +23,6 @@ #include #include -#include "swift/AST/Type.h" -#include "swift/AST/Types.h" - using namespace lldb; using namespace lldb_private; @@ -34,11 +30,6 @@ CompilerType::CompilerType(TypeSystem *type_system, lldb::opaque_compiler_type_t type) : m_type(type), m_type_system(type_system) {} -CompilerType::CompilerType(swift::Type qual_type) - : m_type(qual_type.getPointer()), - m_type_system( - SwiftASTContext::GetSwiftASTContext(&qual_type->getASTContext())) {} - CompilerType::~CompilerType() {} // Tests diff --git a/source/Symbol/SwiftASTContext.cpp b/source/Symbol/SwiftASTContext.cpp index 28ff644c4168..8b331d25b576 100644 --- a/source/Symbol/SwiftASTContext.cpp +++ b/source/Symbol/SwiftASTContext.cpp @@ -537,10 +537,11 @@ class SwiftAllPayloadEnumDescriptor : public SwiftEnumDescriptor { auto arg_type = case_decl->getArgumentInterfaceType(); CompilerType case_type; if (arg_type) { - case_type = { + case_type = CompilerType( + swift_ast_ctx, swift_can_type->getTypeOfMember(module_ctx, case_decl, arg_type) ->getCanonicalType() - .getPointer()}; + .getPointer()); } const bool is_indirect = @@ -777,7 +778,8 @@ SwiftEnumDescriptor *SwiftASTContext::GetCachedEnumInfo(void *type) { return pos->second.get(); swift::CanType swift_can_type(GetCanonicalSwiftType(type)); - if (!SwiftASTContext::IsFullyRealized({swift_can_type})) + if (!SwiftASTContext::IsFullyRealized( + CompilerType(this, swift_can_type.getPointer()))) return nullptr; SwiftEnumDescriptorSP enum_info_sp; @@ -4280,7 +4282,7 @@ SwiftASTContext::GetTypeFromMangledTypename(ConstString mangled_typename, LOG_PRINTF(LIBLLDB_LOG_TYPES, "(\"%s\") -- found in the positive cache", mangled_cstr); assert(&found_type->getASTContext() == ast_ctx); - return {found_type}; + return CompilerType(this, found_type); } if (m_negative_type_cache.Lookup(mangled_cstr)) { @@ -4300,7 +4302,7 @@ SwiftASTContext::GetTypeFromMangledTypename(ConstString mangled_typename, found_type = convertSILFunctionTypesToASTFunctionTypes(found_type).getPointer(); CacheDemangledType(mangled_typename, found_type); - CompilerType result_type(found_type); + CompilerType result_type(this, found_type); assert(&found_type->getASTContext() == ast_ctx); LOG_PRINTF(LIBLLDB_LOG_TYPES, "(\"%s\") -- found %s", mangled_cstr, result_type.GetTypeName().GetCString()); @@ -4316,8 +4318,7 @@ SwiftASTContext::GetTypeFromMangledTypename(ConstString mangled_typename, CompilerType SwiftASTContext::GetAnyObjectType() { VALID_OR_RETURN(CompilerType()); - swift::ASTContext *ast = GetASTContext(); - return {ast->getAnyObjectType()}; + return CompilerType(this, GetASTContext()->getAnyObjectType().getPointer()); } CompilerType SwiftASTContext::GetVoidFunctionType() { @@ -4326,7 +4327,8 @@ CompilerType SwiftASTContext::GetVoidFunctionType() { if (!m_void_function_type) { swift::ASTContext *ast = GetASTContext(); swift::Type empty_tuple_type(swift::TupleType::getEmpty(*ast)); - m_void_function_type = {swift::FunctionType::get({}, empty_tuple_type)}; + m_void_function_type = + CompilerType(this, swift::FunctionType::get({}, empty_tuple_type)); } return m_void_function_type; } @@ -4342,7 +4344,8 @@ static CompilerType ValueDeclToType(swift::ValueDecl *decl, swift::Type swift_type = swift::TypeAliasType::get( alias_decl, swift::Type(), swift::SubstitutionMap(), alias_decl->getUnderlyingTypeLoc().getType()); - return {swift_type.getPointer()}; + return CompilerType(SwiftASTContext::GetSwiftASTContext(ast), + swift_type.getPointer()); } break; } @@ -4355,7 +4358,8 @@ static CompilerType ValueDeclToType(swift::ValueDecl *decl, swift::cast(decl); if (nominal_decl->hasInterfaceType()) { swift::Type swift_type = nominal_decl->getDeclaredType(); - return {swift_type.getPointer()}; + return CompilerType(SwiftASTContext::GetSwiftASTContext(ast), + swift_type.getPointer()); } } break; @@ -4404,7 +4408,8 @@ static SwiftASTContext::TypeOrDecl DeclToTypeOrDecl(swift::ASTContext *ast, swift::Type swift_type = swift::TypeAliasType::get( alias_decl, swift::Type(), swift::SubstitutionMap(), alias_decl->getUnderlyingTypeLoc().getType()); - return CompilerType(swift_type.getPointer()); + return CompilerType(SwiftASTContext::GetSwiftASTContext(ast), + swift_type.getPointer()); } } break; case swift::DeclKind::Enum: @@ -4415,7 +4420,8 @@ static SwiftASTContext::TypeOrDecl DeclToTypeOrDecl(swift::ASTContext *ast, swift::cast(decl); if (nominal_decl->hasInterfaceType()) { swift::Type swift_type = nominal_decl->getDeclaredType(); - return CompilerType(swift_type.getPointer()); + return CompilerType(SwiftASTContext::GetSwiftASTContext(ast), + swift_type.getPointer()); } } break; @@ -4526,9 +4532,10 @@ size_t SwiftASTContext::FindTypes(const char *name, swift_type->getAs(); swift::ASTContext *ast = GetASTContext(); if (meta_type) - return {meta_type->getInstanceType().getPointer()}; + return CompilerType(this, + meta_type->getInstanceType().getPointer()); else - return {swift_type.getPointer()}; + return CompilerType(this, swift_type.getPointer()); } } return CompilerType(); @@ -4634,7 +4641,7 @@ CompilerType SwiftASTContext::ImportType(CompilerType &type, Status &error) { swift::TypeBase *our_type_base = m_mangled_name_to_type_map.lookup(mangled_name.GetCString()); if (our_type_base) - return {our_type_base}; + return CompilerType(swift_ast_ctx, our_type_base); else { Status error; @@ -4766,7 +4773,7 @@ SwiftASTContext::CreateTupleType(const std::vector &elements) { Status error; if (elements.size() == 0) - return {GetASTContext()->TheEmptyTupleType}; + return CompilerType(this, GetASTContext()->TheEmptyTupleType.getPointer()); else { std::vector tuple_elems; for (const TupleElement &element : elements) { @@ -4781,7 +4788,8 @@ SwiftASTContext::CreateTupleType(const std::vector &elements) { return {}; } llvm::ArrayRef fields(tuple_elems); - return {swift::TupleType::get(fields, *GetASTContext()).getPointer()}; + return CompilerType( + this, swift::TupleType::get(fields, *GetASTContext()).getPointer()); } } @@ -4796,7 +4804,7 @@ CompilerType SwiftASTContext::GetErrorType() { swift::NominalTypeDecl *error_type_decl = GetASTContext()->getErrorDecl(); if (error_type_decl) { auto error_type = error_type_decl->getDeclaredType().getPointer(); - return {error_type}; + return CompilerType(this, error_type); } } return {}; @@ -4812,7 +4820,7 @@ uint32_t SwiftASTContext::GetPointerByteSize() { if (m_pointer_byte_size == 0) m_pointer_byte_size = - CompilerType(GetASTContext()->TheRawPointerType.getPointer()) + CompilerType(this, GetASTContext()->TheRawPointerType.getPointer()) .GetByteSize(nullptr) .getValueOr(0); return m_pointer_byte_size; @@ -5049,7 +5057,7 @@ bool SwiftASTContext::IsArrayType(void *type, CompilerType *element_type_ptr, if (size) *size = 0; if (element_type_ptr) - *element_type_ptr = CompilerType(args[0].getPointer()); + *element_type_ptr = CompilerType(this, args[0].getPointer()); return true; } @@ -5331,7 +5339,7 @@ SwiftASTContext::GetReferentType(const CompilerType &compiler_type) { return compiler_type; auto ref_type = swift_type->getReferenceStorageReferent(); - return {ref_type}; + return CompilerType(compiler_type.GetTypeSystem(), ref_type.getPointer()); } return {}; @@ -5369,7 +5377,7 @@ bool SwiftASTContext::GetProtocolTypeInfo(const CompilerType &type, protocol_info.m_is_errortype = layout.isErrorExistential(); if (auto superclass = layout.explicitSuperclass) { - protocol_info.m_superclass = {superclass.getPointer()}; + protocol_info.m_superclass = CompilerType(ast, superclass.getPointer()); } unsigned num_witness_tables = 0; @@ -5462,21 +5470,21 @@ GetArchetypeNames(swift::Type type, swift::ASTContext &ast_ctx, const SymbolContext *sc) { llvm::DenseMap dict; - swift::Type swift_type(GetSwiftType(type)); - assert(&swift_type->getASTContext() == &ast_ctx); + assert(&type->getASTContext() == &ast_ctx); if (!sc) return dict; llvm::DenseMap, StringRef> names; SwiftLanguageRuntime::GetGenericParameterNamesForFunction(*sc, names); - swift_type.visit([&](swift::Type type) { - if (!type->isTypeParameter() || dict.count(type->getCanonicalType())) + type.visit([&](swift::Type swift_type) { + if (!swift_type->isTypeParameter() || + dict.count(swift_type->getCanonicalType())) return; - auto *param = type->getAs(); + auto *param = swift_type->getAs(); auto it = names.find({param->getDepth(), param->getIndex()}); if (it != names.end()) { swift::Identifier ident = ast_ctx.getIdentifier(it->second); - dict.insert({type->getCanonicalType(), ident}); + dict.insert({swift_type->getCanonicalType(), ident}); } }); return dict; @@ -5574,8 +5582,11 @@ SwiftASTContext::GetTypeInfo(void *type, case swift::TypeKind::UnmanagedStorage: case swift::TypeKind::UnownedStorage: case swift::TypeKind::WeakStorage: - swift_flags |= CompilerType(swift_can_type->getReferenceStorageReferent()) - .GetTypeInfo(pointee_or_element_clang_type); + swift_flags |= + CompilerType(SwiftASTContext::GetSwiftASTContext( + &swift_can_type->getASTContext()), + swift_can_type->getReferenceStorageReferent().getPointer()) + .GetTypeInfo(pointee_or_element_clang_type); break; case swift::TypeKind::BoundGenericEnum: swift_flags |= eTypeIsGeneric | eTypeIsBound; @@ -5686,7 +5697,10 @@ lldb::TypeClass SwiftASTContext::GetTypeClass(void *type) { case swift::TypeKind::UnmanagedStorage: case swift::TypeKind::UnownedStorage: case swift::TypeKind::WeakStorage: - return CompilerType(swift_can_type->getReferenceStorageReferent()) + return CompilerType( + SwiftASTContext::GetSwiftASTContext( + &swift_can_type->getASTContext()), + swift_can_type->getReferenceStorageReferent().getPointer()) .GetTypeClass(); case swift::TypeKind::GenericTypeParam: return lldb::eTypeClassOther; @@ -5783,7 +5797,7 @@ CompilerType SwiftASTContext::GetArrayElementType(void *type, 0 == strcmp(declname, "Array") || 0 == strcmp(declname, "ArraySlice")) { assert(GetASTContext() == &args[0].getPointer()->getASTContext()); - element_type = CompilerType(args[0].getPointer()); + element_type = CompilerType(this, args[0].getPointer()); } } } @@ -5794,9 +5808,13 @@ CompilerType SwiftASTContext::GetArrayElementType(void *type, CompilerType SwiftASTContext::GetCanonicalType(void *type) { VALID_OR_RETURN(CompilerType()); - if (type) - return {GetCanonicalSwiftType(type).getPointer()}; - return CompilerType(); + if (!type) + return CompilerType(); + + auto swift_can_type = GetCanonicalSwiftType(type); + return CompilerType( + SwiftASTContext::GetSwiftASTContext(&swift_can_type->getASTContext()), + swift_can_type.getPointer()); } CompilerType SwiftASTContext::GetInstanceType(void *type) { @@ -5810,15 +5828,15 @@ CompilerType SwiftASTContext::GetInstanceType(void *type) { "input type belongs to different SwiftASTContext"); auto metatype_type = swift::dyn_cast(swift_can_type); if (metatype_type) - return {metatype_type.getInstanceType().getPointer()}; + return CompilerType(this, metatype_type.getInstanceType().getPointer()); - return {GetSwiftType(type)}; + return CompilerType(this, GetSwiftType(type).getPointer()); } CompilerType SwiftASTContext::GetFullyUnqualifiedType(void *type) { VALID_OR_RETURN(CompilerType()); - return {GetSwiftType(type)}; + return CompilerType(this, GetSwiftType(type).getPointer()); } int SwiftASTContext::GetFunctionArgumentCount(void *type) { @@ -5837,7 +5855,7 @@ CompilerType SwiftASTContext::GetFunctionReturnType(void *type) { auto func = swift::dyn_cast(GetCanonicalSwiftType(type)); if (func) - return {func.getResult().getPointer()}; + return CompilerType(this, func.getResult().getPointer()); } return {}; } @@ -5921,7 +5939,7 @@ TypeMemberFunctionImpl SwiftASTContext::GetMemberFunctionAtIndex(void *type, } } result_type = CompilerType( - abstract_func_decl->getInterfaceType().getPointer()); + this, abstract_func_decl->getInterfaceType().getPointer()); } } else --idx; @@ -5944,7 +5962,7 @@ CompilerType SwiftASTContext::GetLValueReferenceType(void *type) { VALID_OR_RETURN(CompilerType()); if (type) - return {swift::LValueType::get(GetSwiftType(type))}; + return CompilerType(this, swift::LValueType::get(GetSwiftType(type))); return {}; } @@ -5958,7 +5976,7 @@ CompilerType SwiftASTContext::GetNonReferenceType(void *type) { swift::LValueType *lvalue = swift_can_type->getAs(); if (lvalue) - return {lvalue->getObjectType().getPointer()}; + return CompilerType(this, lvalue->getObjectType().getPointer()); } return {}; } @@ -5972,7 +5990,7 @@ CompilerType SwiftASTContext::GetPointerType(void *type) { swift::Type swift_type(::GetSwiftType(type)); const swift::TypeKind type_kind = swift_type->getKind(); if (type_kind == swift::TypeKind::BuiltinRawPointer) - return {swift_type}; + return CompilerType(this, swift_type.getPointer()); } return {}; } @@ -5985,7 +6003,7 @@ CompilerType SwiftASTContext::GetTypedefedType(void *type) { swift::TypeAliasType *name_alias_type = swift::dyn_cast(swift_type.getPointer()); if (name_alias_type) { - return {name_alias_type->getSinglyDesugaredType()}; + return CompilerType(this, name_alias_type->getSinglyDesugaredType()); } } @@ -6003,11 +6021,12 @@ SwiftASTContext::GetUnboundType(lldb::opaque_compiler_type_t type) { if (bound_generic_type) { swift::NominalTypeDecl *nominal_type_decl = bound_generic_type->getDecl(); if (nominal_type_decl) - return {nominal_type_decl->getDeclaredType()}; + return CompilerType(this, + nominal_type_decl->getDeclaredType().getPointer()); } } - return {GetSwiftType(type)}; + return CompilerType(this, GetSwiftType(type).getPointer()); } //---------------------------------------------------------------------- @@ -6198,7 +6217,8 @@ lldb::Encoding SwiftASTContext::GetEncoding(void *type, uint64_t &count) { case swift::TypeKind::UnmanagedStorage: case swift::TypeKind::UnownedStorage: case swift::TypeKind::WeakStorage: - return CompilerType(swift_can_type->getReferenceStorageReferent()) + return CompilerType( + this, swift_can_type->getReferenceStorageReferent().getPointer()) .GetEncoding(count); break; @@ -6287,7 +6307,8 @@ lldb::Format SwiftASTContext::GetFormat(void *type) { case swift::TypeKind::UnmanagedStorage: case swift::TypeKind::UnownedStorage: case swift::TypeKind::WeakStorage: - return CompilerType(swift_can_type->getReferenceStorageReferent()) + return CompilerType( + this, swift_can_type->getReferenceStorageReferent().getPointer()) .GetFormat(); break; @@ -6366,7 +6387,8 @@ uint32_t SwiftASTContext::GetNumChildren(void *type, case swift::TypeKind::UnmanagedStorage: case swift::TypeKind::UnownedStorage: case swift::TypeKind::WeakStorage: - return CompilerType(swift_can_type->getReferenceStorageReferent()) + return CompilerType( + this, swift_can_type->getReferenceStorageReferent().getPointer()) .GetNumChildren(omit_empty_base_classes, exe_ctx); case swift::TypeKind::GenericTypeParam: case swift::TypeKind::DependentMember: @@ -6393,7 +6415,8 @@ uint32_t SwiftASTContext::GetNumChildren(void *type, case swift::TypeKind::Protocol: case swift::TypeKind::ProtocolComposition: { ProtocolInfo protocol_info; - if (!GetProtocolTypeInfo(CompilerType(GetSwiftType(type)), protocol_info)) + if (!GetProtocolTypeInfo( + CompilerType(this, GetSwiftType(type).getPointer()), protocol_info)) break; return protocol_info.m_num_storage_words; @@ -6412,7 +6435,7 @@ uint32_t SwiftASTContext::GetNumChildren(void *type, swift::TypeBase *deref_type = lvalue_type->getObjectType().getPointer(); uint32_t num_pointee_children = - CompilerType(deref_type) + CompilerType(this, deref_type) .GetNumChildren(omit_empty_base_classes, exe_ctx); // If this type points to a simple type (or to a class), then it // has 1 child. @@ -6495,7 +6518,8 @@ uint32_t SwiftASTContext::GetNumFields(void *type) { case swift::TypeKind::UnmanagedStorage: case swift::TypeKind::UnownedStorage: case swift::TypeKind::WeakStorage: - return CompilerType(swift_can_type->getReferenceStorageReferent()) + return CompilerType( + this, swift_can_type->getReferenceStorageReferent().getPointer()) .GetNumFields(); case swift::TypeKind::GenericTypeParam: case swift::TypeKind::DependentMember: @@ -6570,7 +6594,7 @@ SwiftASTContext::GetDirectBaseClassAtIndex(void *opaque_type, size_t idx, if (class_decl) { swift::Type base_class_type = class_decl->getSuperclass(); if (base_class_type) - return {base_class_type.getPointer()}; + return CompilerType(this, base_class_type.getPointer()); } } return {}; @@ -6616,13 +6640,14 @@ GetExistentialTypeChild(swift::ASTContext *swift_ast_ctx, CompilerType type, assert(idx < protocol_info.m_num_storage_words && "caller is responsible for validating index"); + auto *ast = SwiftASTContext::GetSwiftASTContext(swift_ast_ctx); // A payload word for a non-class, non-error existential. if (idx < protocol_info.m_num_payload_words) { std::string name; llvm::raw_string_ostream(name) << "payload_data_" << idx; auto raw_pointer = swift_ast_ctx->TheRawPointerType; - return {CompilerType(raw_pointer.getPointer()), std::move(name)}; + return {CompilerType(ast, raw_pointer.getPointer()), std::move(name)}; } // The instance for a class-bound existential. @@ -6632,7 +6657,7 @@ GetExistentialTypeChild(swift::ASTContext *swift_ast_ctx, CompilerType type, class_type = protocol_info.m_superclass; } else { auto raw_pointer = swift_ast_ctx->TheRawPointerType; - class_type = CompilerType(raw_pointer.getPointer()); + class_type = CompilerType(ast, raw_pointer.getPointer()); } return {class_type, "instance"}; @@ -6641,7 +6666,7 @@ GetExistentialTypeChild(swift::ASTContext *swift_ast_ctx, CompilerType type, // The instance for an error existential. if (idx == 0 && protocol_info.m_is_errortype) { auto raw_pointer = swift_ast_ctx->TheRawPointerType; - return {CompilerType(raw_pointer.getPointer()), "error_instance"}; + return {CompilerType(ast, raw_pointer.getPointer()), "error_instance"}; } // The metatype for a non-class, non-error existential. @@ -6649,7 +6674,7 @@ GetExistentialTypeChild(swift::ASTContext *swift_ast_ctx, CompilerType type, // The metatype for a non-class, non-error existential. auto any_metatype = swift::ExistentialMetatypeType::get(swift_ast_ctx->TheAnyType); - return {CompilerType(any_metatype), "instance_type"}; + return {CompilerType(ast, any_metatype), "instance_type"}; } // A witness table. Figure out which protocol it corresponds to. @@ -6672,7 +6697,7 @@ GetExistentialTypeChild(swift::ASTContext *swift_ast_ctx, CompilerType type, } auto raw_pointer = swift_ast_ctx->TheRawPointerType; - return {CompilerType(raw_pointer.getPointer()), std::move(name)}; + return {CompilerType(ast, raw_pointer.getPointer()), std::move(name)}; } CompilerType SwiftASTContext::GetFieldAtIndex(void *type, size_t idx, @@ -6702,7 +6727,8 @@ CompilerType SwiftASTContext::GetFieldAtIndex(void *type, size_t idx, case swift::TypeKind::UnmanagedStorage: case swift::TypeKind::UnownedStorage: case swift::TypeKind::WeakStorage: - return CompilerType(swift_can_type->getReferenceStorageReferent()) + return CompilerType( + this, swift_can_type->getReferenceStorageReferent().getPointer()) .GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr); case swift::TypeKind::GenericTypeParam: @@ -6744,7 +6770,7 @@ CompilerType SwiftASTContext::GetFieldAtIndex(void *type, size_t idx, name = GetTupleElementName(tuple_type, idx); const auto &child = tuple_type->getElement(idx); - return CompilerType(child.getType().getPointer()); + return CompilerType(this, child.getType().getPointer()); } case swift::TypeKind::Class: @@ -6753,7 +6779,7 @@ CompilerType SwiftASTContext::GetFieldAtIndex(void *type, size_t idx, if (class_decl->hasSuperclass()) { if (idx == 0) { swift::Type superclass_swift_type = swift_can_type->getSuperclass(); - CompilerType superclass_type(superclass_swift_type.getPointer()); + CompilerType superclass_type(this, superclass_swift_type.getPointer()); name = GetSuperclassName(superclass_type); @@ -6797,19 +6823,20 @@ CompilerType SwiftASTContext::GetFieldAtIndex(void *type, size_t idx, swift::Type child_swift_type = swift_can_type->getTypeOfMember( nominal->getModuleContext(), property, nullptr); - return CompilerType(child_swift_type.getPointer()); + return CompilerType(this, child_swift_type.getPointer()); } case swift::TypeKind::Protocol: case swift::TypeKind::ProtocolComposition: { ProtocolInfo protocol_info; - if (!GetProtocolTypeInfo(CompilerType(GetSwiftType(type)), protocol_info)) + if (!GetProtocolTypeInfo( + CompilerType(this, GetSwiftType(type).getPointer()), protocol_info)) break; if (idx >= protocol_info.m_num_storage_words) break; - CompilerType compiler_type(GetSwiftType(type)); + CompilerType compiler_type(this, GetSwiftType(type).getPointer()); CompilerType child_type; std::tie(child_type, name) = GetExistentialTypeChild( GetASTContext(), compiler_type, protocol_info, idx); @@ -7031,21 +7058,21 @@ bool SwiftASTContext::IsNonTriviallyManagedReferenceType( strategy = NonTriviallyManagedReferenceStrategy::eUnmanaged; if (underlying_type) *underlying_type = CompilerType( - swift_can_type->getReferenceStorageReferent().getPointer()); + ast, swift_can_type->getReferenceStorageReferent().getPointer()); } return true; case swift::TypeKind::UnownedStorage: { strategy = NonTriviallyManagedReferenceStrategy::eUnowned; if (underlying_type) *underlying_type = CompilerType( - swift_can_type->getReferenceStorageReferent().getPointer()); + ast, swift_can_type->getReferenceStorageReferent().getPointer()); } return true; case swift::TypeKind::WeakStorage: { strategy = NonTriviallyManagedReferenceStrategy::eWeak; if (underlying_type) *underlying_type = CompilerType( - swift_can_type->getReferenceStorageReferent().getPointer()); + ast, swift_can_type->getReferenceStorageReferent().getPointer()); } return true; } @@ -7095,7 +7122,8 @@ CompilerType SwiftASTContext::GetChildCompilerTypeAtIndex( case swift::TypeKind::UnmanagedStorage: case swift::TypeKind::UnownedStorage: case swift::TypeKind::WeakStorage: - return CompilerType(swift_can_type->getReferenceStorageReferent()) + return CompilerType( + this, swift_can_type->getReferenceStorageReferent().getPointer()) .GetChildCompilerTypeAtIndex( exe_ctx, idx, transparent_pointers, omit_empty_base_classes, ignore_array_bounds, child_name, child_byte_size, child_byte_offset, @@ -7123,7 +7151,8 @@ CompilerType SwiftASTContext::GetChildCompilerTypeAtIndex( child_is_deref_of_parent = false; if (element_info->is_indirect) { language_flags |= LanguageFlags::eIsIndirectEnumCase; - return CompilerType(GetASTContext()->TheRawPointerType.getPointer()); + return CompilerType(this, + GetASTContext()->TheRawPointerType.getPointer()); } else return element_info->payload_type; } @@ -7141,13 +7170,13 @@ CompilerType SwiftASTContext::GetChildCompilerTypeAtIndex( llvm::raw_svector_ostream(printed_idx) << idx; child_name = GetTupleElementName(tuple_type, idx, printed_idx); - CompilerType child_type(child.getType().getPointer()); + CompilerType child_type(this, child.getType().getPointer()); if (!get_type_size(child_byte_size, child_type)) return {}; child_is_base_class = false; child_is_deref_of_parent = false; - CompilerType compiler_type(GetSwiftType(type)); + CompilerType compiler_type(this, GetSwiftType(type).getPointer()); llvm::Optional offset = GetInstanceVariableOffset( valobj, exe_ctx, compiler_type, printed_idx.c_str(), child_type); if (!offset) @@ -7167,7 +7196,7 @@ CompilerType SwiftASTContext::GetChildCompilerTypeAtIndex( if (class_decl->hasSuperclass()) { if (idx == 0) { swift::Type superclass_swift_type = swift_can_type->getSuperclass(); - CompilerType superclass_type(superclass_swift_type.getPointer()); + CompilerType superclass_type(this, superclass_swift_type.getPointer()); child_name = GetSuperclassName(superclass_type); if (!get_type_size(child_byte_size, superclass_type)) @@ -7201,14 +7230,14 @@ CompilerType SwiftASTContext::GetChildCompilerTypeAtIndex( swift::Type child_swift_type = swift_can_type->getTypeOfMember( nominal->getModuleContext(), property, nullptr); - CompilerType child_type(child_swift_type.getPointer()); + CompilerType child_type(this, child_swift_type.getPointer()); child_name = property->getBaseName().userFacingName(); if (!get_type_size(child_byte_size, child_type)) return {}; child_is_base_class = false; child_is_deref_of_parent = false; - CompilerType compiler_type(GetSwiftType(type)); + CompilerType compiler_type(this, GetSwiftType(type).getPointer()); llvm::Optional offset = GetInstanceVariableOffset( valobj, exe_ctx, compiler_type, child_name.c_str(), child_type); if (!offset) @@ -7223,13 +7252,14 @@ CompilerType SwiftASTContext::GetChildCompilerTypeAtIndex( case swift::TypeKind::Protocol: case swift::TypeKind::ProtocolComposition: { ProtocolInfo protocol_info; - if (!GetProtocolTypeInfo(CompilerType(GetSwiftType(type)), protocol_info)) + if (!GetProtocolTypeInfo( + CompilerType(this, GetSwiftType(type).getPointer()), protocol_info)) break; if (idx >= protocol_info.m_num_storage_words) break; - CompilerType compiler_type(GetSwiftType(type)); + CompilerType compiler_type(this, GetSwiftType(type).getPointer()); CompilerType child_type; std::tie(child_type, child_name) = GetExistentialTypeChild( GetASTContext(), compiler_type, protocol_info, idx); @@ -7361,7 +7391,9 @@ size_t SwiftASTContext::GetIndexOfChildMemberWithName( case swift::TypeKind::UnmanagedStorage: case swift::TypeKind::UnownedStorage: case swift::TypeKind::WeakStorage: - return CompilerType(swift_can_type->getReferenceStorageReferent()) + return CompilerType( + this, + swift_can_type->getReferenceStorageReferent().getPointer()) .GetIndexOfChildMemberWithName(name, omit_empty_base_classes, child_indexes); case swift::TypeKind::GenericTypeParam: @@ -7440,7 +7472,7 @@ size_t SwiftASTContext::GetIndexOfChildMemberWithName( // Look in the superclass. swift::Type superclass_swift_type = swift_can_type->getSuperclass(); - CompilerType superclass_type(superclass_swift_type.getPointer()); + CompilerType superclass_type(this, superclass_swift_type.getPointer()); if (superclass_type.GetIndexOfChildMemberWithName( name, omit_empty_base_classes, child_indexes)) return child_indexes.size(); @@ -7455,10 +7487,12 @@ size_t SwiftASTContext::GetIndexOfChildMemberWithName( case swift::TypeKind::Protocol: case swift::TypeKind::ProtocolComposition: { ProtocolInfo protocol_info; - if (!GetProtocolTypeInfo(CompilerType(GetSwiftType(type)), protocol_info)) + if (!GetProtocolTypeInfo( + CompilerType(this, GetSwiftType(type).getPointer()), + protocol_info)) break; - CompilerType compiler_type(GetSwiftType(type)); + CompilerType compiler_type(this, GetSwiftType(type).getPointer()); for (unsigned idx : swift::range(protocol_info.m_num_storage_words)) { CompilerType child_type; std::string child_name; @@ -7623,7 +7657,8 @@ CompilerType SwiftASTContext::GetBoundGenericType(void *type, size_t idx) { if (auto *bound_generic_type = swift_can_type->getAs()) if (idx < bound_generic_type->getGenericArgs().size()) - return {bound_generic_type->getGenericArgs()[idx].getPointer()}; + return CompilerType( + this, bound_generic_type->getGenericArgs()[idx].getPointer()); } return {}; } @@ -7640,8 +7675,8 @@ CompilerType SwiftASTContext::GetUnboundGenericType(void *type, size_t idx) { swift::GenericSignature *generic_sig = nominal_type_decl->getGenericSignature(); auto depTy = generic_sig->getGenericParams()[idx]; - return {nominal_type_decl->mapTypeIntoContext(depTy) - ->castTo()}; + return CompilerType(this, nominal_type_decl->mapTypeIntoContext(depTy) + ->castTo()); } } return {}; @@ -7667,7 +7702,7 @@ CompilerType SwiftASTContext::GetTypeForFormatters(void *type) { if (type) { swift::Type swift_type(GetSwiftType(type)); assert(&swift_type->getASTContext() == GetASTContext()); - return {swift_type}; + return CompilerType(this, swift_type.getPointer()); } return {}; } @@ -7841,7 +7876,8 @@ bool SwiftASTContext::DumpTypeValue( case swift::TypeKind::UnmanagedStorage: case swift::TypeKind::UnownedStorage: case swift::TypeKind::WeakStorage: - return CompilerType(swift_can_type->getReferenceStorageReferent()) + return CompilerType( + this, swift_can_type->getReferenceStorageReferent().getPointer()) .DumpTypeValue(s, format, data, byte_offset, byte_size, bitfield_bit_size, bitfield_bit_offset, exe_scope, is_base_class); @@ -8046,7 +8082,7 @@ void SwiftASTContext::DumpTypeDescription(void *type, Stream *s, llvm::dyn_cast_or_null(decl); if (type_decl) { CompilerType clang_type( - type_decl->getDeclaredInterfaceType().getPointer()); + this, type_decl->getDeclaredInterfaceType().getPointer()); if (clang_type) { Flags clang_type_flags(clang_type.GetTypeInfo()); DumpTypeDescription(clang_type.GetOpaqueQualType(), s, diff --git a/source/Target/SwiftLanguageRuntime.cpp b/source/Target/SwiftLanguageRuntime.cpp index 20b47186d342..bd5fb274f99e 100644 --- a/source/Target/SwiftLanguageRuntime.cpp +++ b/source/Target/SwiftLanguageRuntime.cpp @@ -1954,7 +1954,10 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Protocol( } auto type_and_address = result.getValue(); - class_type_or_name.SetCompilerType(type_and_address.InstanceType); + class_type_or_name.SetCompilerType( + CompilerType(SwiftASTContext::GetSwiftASTContext( + &type_and_address.InstanceType->getASTContext()), + type_and_address.InstanceType.getPointer())); address.SetRawAddress(type_and_address.PayloadAddress.getAddressData()); return true; } @@ -2113,7 +2116,9 @@ SwiftLanguageRuntime::DoArchetypeBindingForType(StackFrame &stack_frame, swift::SubstFlags::DesugarMemberTypes); assert(target_swift_type); - return {target_swift_type.getPointer()}; + return CompilerType(SwiftASTContext::GetSwiftASTContext( + &target_swift_type->getASTContext()), + target_swift_type.getPointer()); } return base_type; } @@ -2543,7 +2548,9 @@ lldb::addr_t SwiftLanguageRuntime::FixupAddress(lldb::addr_t addr, const swift::reflection::TypeInfo * SwiftLanguageRuntime::GetTypeInfo(CompilerType type) { swift::CanType swift_can_type(GetCanonicalSwiftType(type)); - CompilerType can_type(swift_can_type); + CompilerType can_type( + SwiftASTContext::GetSwiftASTContext(&swift_can_type->getASTContext()), + swift_can_type.getPointer()); ConstString mangled_name(can_type.GetMangledTypeName()); StringRef mangled_no_prefix = swift::Demangle::dropSwiftManglingPrefix(mangled_name.GetStringRef());