From 177cd3b78ab164e8f9a29c813d324bbd740e8ac0 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 - include/lldb/Symbol/SwiftASTContext.h | 2 + .../Swift/SwiftASTManipulator.cpp | 12 +- .../Swift/SwiftExpressionVariable.h | 1 + .../Swift/SwiftREPLMaterializer.h | 1 + .../Language/Swift/SwiftFormatters.cpp | 2 +- .../Plugins/Language/Swift/SwiftLanguage.cpp | 7 +- .../SymbolFile/DWARF/DWARFASTParserSwift.cpp | 3 +- source/Symbol/CompilerType.cpp | 9 - source/Symbol/SwiftASTContext.cpp | 235 +++++++++++------- source/Target/SwiftLanguageRuntime.cpp | 7 +- 11 files changed, 170 insertions(+), 111 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/include/lldb/Symbol/SwiftASTContext.h b/include/lldb/Symbol/SwiftASTContext.h index f192898e4f33..f53908e101a1 100644 --- a/include/lldb/Symbol/SwiftASTContext.h +++ b/include/lldb/Symbol/SwiftASTContext.h @@ -725,6 +725,8 @@ class SwiftASTContext : public TypeSystem { lldb::StackFrameWP &stack_frame_wp, swift::SourceFile *source_file, Status &error); + static CompilerType GetSwiftCompilerType(swift::Type swift_type); + protected: /// This map uses the string value of ConstStrings as the key, and the TypeBase /// * as the value. Since the ConstString strings are uniqued, we can use diff --git a/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp b/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp index b74681b31a43..d1d7c98b3063 100644 --- a/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp +++ b/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp @@ -748,7 +748,7 @@ 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 = SwiftASTContext::GetSwiftCompilerType(type); persistent_info.m_decl = var_decl; m_variables.push_back(persistent_info); @@ -814,7 +814,7 @@ 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::GetSwiftCompilerType(result_type); result_var->overwriteAccess(swift::AccessLevel::Public); result_var->overwriteSetterAccess(swift::AccessLevel::Public); @@ -855,7 +855,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::GetSwiftCompilerType(error_type); error_var->overwriteAccess(swift::AccessLevel::Public); error_var->overwriteSetterAccess(swift::AccessLevel::Public); @@ -955,7 +956,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::GetSwiftCompilerType(result_type); swift::Identifier result_var_name = ast_context.getIdentifier(GetResultName()); SwiftASTManipulatorBase::VariableMetadataSP metadata_sp( @@ -999,7 +1001,7 @@ 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::GetSwiftCompilerType(error_type); 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..74a46719caf1 100644 --- a/source/Plugins/Language/Swift/SwiftFormatters.cpp +++ b/source/Plugins/Language/Swift/SwiftFormatters.cpp @@ -1044,7 +1044,7 @@ 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::GetSwiftCompilerType(swift_arg_type); 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..d846319bd5bf 100644 --- a/source/Plugins/Language/Swift/SwiftLanguage.cpp +++ b/source/Plugins/Language/Swift/SwiftLanguage.cpp @@ -1317,9 +1317,12 @@ 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))); + SwiftASTContext::GetSwiftCompilerType(module_type)); + } return true; }); diff --git a/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.cpp b/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.cpp index b4c6a257128d..892328503e6a 100644 --- a/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.cpp +++ b/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.cpp @@ -189,7 +189,8 @@ lldb::TypeSP DWARFASTParserSwift::ParseTypeFromDWARF(const SymbolContext &sc, return {}; } preferred_name = name; - compiler_type = {swift_ast_ctx->TheRawPointerType}; + compiler_type = SwiftASTContext::GetSwiftCompilerType( + swift_ast_ctx->TheRawPointerType); } } 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..80191e8435c5 100644 --- a/source/Symbol/SwiftASTContext.cpp +++ b/source/Symbol/SwiftASTContext.cpp @@ -537,10 +537,10 @@ class SwiftAllPayloadEnumDescriptor : public SwiftEnumDescriptor { auto arg_type = case_decl->getArgumentInterfaceType(); CompilerType case_type; if (arg_type) { - case_type = { + case_type = SwiftASTContext::GetSwiftCompilerType( swift_can_type->getTypeOfMember(module_ctx, case_decl, arg_type) ->getCanonicalType() - .getPointer()}; + .getPointer()); } const bool is_indirect = @@ -777,7 +777,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( + SwiftASTContext::GetSwiftCompilerType(swift_can_type))) return nullptr; SwiftEnumDescriptorSP enum_info_sp; @@ -4280,7 +4281,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 SwiftASTContext::GetSwiftCompilerType(found_type); } if (m_negative_type_cache.Lookup(mangled_cstr)) { @@ -4300,7 +4301,8 @@ SwiftASTContext::GetTypeFromMangledTypename(ConstString mangled_typename, found_type = convertSILFunctionTypesToASTFunctionTypes(found_type).getPointer(); CacheDemangledType(mangled_typename, found_type); - CompilerType result_type(found_type); + CompilerType result_type = + SwiftASTContext::GetSwiftCompilerType(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,8 @@ SwiftASTContext::GetTypeFromMangledTypename(ConstString mangled_typename, CompilerType SwiftASTContext::GetAnyObjectType() { VALID_OR_RETURN(CompilerType()); - swift::ASTContext *ast = GetASTContext(); - return {ast->getAnyObjectType()}; + return SwiftASTContext::GetSwiftCompilerType( + GetASTContext()->getAnyObjectType()); } CompilerType SwiftASTContext::GetVoidFunctionType() { @@ -4326,7 +4328,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 = SwiftASTContext::GetSwiftCompilerType( + swift::FunctionType::get({}, empty_tuple_type)); } return m_void_function_type; } @@ -4342,7 +4345,7 @@ 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 SwiftASTContext::GetSwiftCompilerType(swift_type); } break; } @@ -4355,7 +4358,7 @@ 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 SwiftASTContext::GetSwiftCompilerType(swift_type); } } break; @@ -4404,7 +4407,7 @@ 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 SwiftASTContext::GetSwiftCompilerType(swift_type); } } break; case swift::DeclKind::Enum: @@ -4415,7 +4418,7 @@ 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 SwiftASTContext::GetSwiftCompilerType(swift_type); } } break; @@ -4526,9 +4529,10 @@ size_t SwiftASTContext::FindTypes(const char *name, swift_type->getAs(); swift::ASTContext *ast = GetASTContext(); if (meta_type) - return {meta_type->getInstanceType().getPointer()}; + return SwiftASTContext::GetSwiftCompilerType( + meta_type->getInstanceType()); else - return {swift_type.getPointer()}; + return SwiftASTContext::GetSwiftCompilerType(swift_type); } } return CompilerType(); @@ -4634,7 +4638,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 SwiftASTContext::GetSwiftCompilerType(our_type_base); else { Status error; @@ -4766,7 +4770,8 @@ SwiftASTContext::CreateTupleType(const std::vector &elements) { Status error; if (elements.size() == 0) - return {GetASTContext()->TheEmptyTupleType}; + return SwiftASTContext::GetSwiftCompilerType( + GetASTContext()->TheEmptyTupleType); else { std::vector tuple_elems; for (const TupleElement &element : elements) { @@ -4781,7 +4786,8 @@ SwiftASTContext::CreateTupleType(const std::vector &elements) { return {}; } llvm::ArrayRef fields(tuple_elems); - return {swift::TupleType::get(fields, *GetASTContext()).getPointer()}; + return SwiftASTContext::GetSwiftCompilerType( + swift::TupleType::get(fields, *GetASTContext()).getPointer()); } } @@ -4796,7 +4802,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 SwiftASTContext::GetSwiftCompilerType(error_type); } } return {}; @@ -4811,10 +4817,10 @@ uint32_t SwiftASTContext::GetPointerByteSize() { VALID_OR_RETURN(0); if (m_pointer_byte_size == 0) - m_pointer_byte_size = - CompilerType(GetASTContext()->TheRawPointerType.getPointer()) - .GetByteSize(nullptr) - .getValueOr(0); + m_pointer_byte_size = SwiftASTContext::GetSwiftCompilerType( + GetASTContext()->TheRawPointerType.getPointer()) + .GetByteSize(nullptr) + .getValueOr(0); return m_pointer_byte_size; } @@ -5049,7 +5055,8 @@ 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 = + SwiftASTContext::GetSwiftCompilerType(args[0].getPointer()); return true; } @@ -5331,7 +5338,7 @@ SwiftASTContext::GetReferentType(const CompilerType &compiler_type) { return compiler_type; auto ref_type = swift_type->getReferenceStorageReferent(); - return {ref_type}; + return SwiftASTContext::GetSwiftCompilerType(ref_type); } return {}; @@ -5369,7 +5376,8 @@ 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 = + SwiftASTContext::GetSwiftCompilerType(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,7 +5582,8 @@ SwiftASTContext::GetTypeInfo(void *type, case swift::TypeKind::UnmanagedStorage: case swift::TypeKind::UnownedStorage: case swift::TypeKind::WeakStorage: - swift_flags |= CompilerType(swift_can_type->getReferenceStorageReferent()) + swift_flags |= SwiftASTContext::GetSwiftCompilerType( + swift_can_type->getReferenceStorageReferent()) .GetTypeInfo(pointee_or_element_clang_type); break; case swift::TypeKind::BoundGenericEnum: @@ -5686,7 +5695,8 @@ 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 SwiftASTContext::GetSwiftCompilerType( + swift_can_type->getReferenceStorageReferent()) .GetTypeClass(); case swift::TypeKind::GenericTypeParam: return lldb::eTypeClassOther; @@ -5783,7 +5793,8 @@ 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 = + SwiftASTContext::GetSwiftCompilerType(args[0].getPointer()); } } } @@ -5794,9 +5805,11 @@ 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(); + + return SwiftASTContext::GetSwiftCompilerType( + GetCanonicalSwiftType(type).getPointer()); } CompilerType SwiftASTContext::GetInstanceType(void *type) { @@ -5810,15 +5823,16 @@ 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 SwiftASTContext::GetSwiftCompilerType( + metatype_type.getInstanceType().getPointer()); - return {GetSwiftType(type)}; + return SwiftASTContext::GetSwiftCompilerType(GetSwiftType(type)); } CompilerType SwiftASTContext::GetFullyUnqualifiedType(void *type) { VALID_OR_RETURN(CompilerType()); - return {GetSwiftType(type)}; + return SwiftASTContext::GetSwiftCompilerType(GetSwiftType(type)); } int SwiftASTContext::GetFunctionArgumentCount(void *type) { @@ -5837,7 +5851,8 @@ CompilerType SwiftASTContext::GetFunctionReturnType(void *type) { auto func = swift::dyn_cast(GetCanonicalSwiftType(type)); if (func) - return {func.getResult().getPointer()}; + return SwiftASTContext::GetSwiftCompilerType( + func.getResult().getPointer()); } return {}; } @@ -5920,7 +5935,7 @@ TypeMemberFunctionImpl SwiftASTContext::GetMemberFunctionAtIndex(void *type, } } } - result_type = CompilerType( + result_type = SwiftASTContext::GetSwiftCompilerType( abstract_func_decl->getInterfaceType().getPointer()); } } else @@ -5944,7 +5959,8 @@ CompilerType SwiftASTContext::GetLValueReferenceType(void *type) { VALID_OR_RETURN(CompilerType()); if (type) - return {swift::LValueType::get(GetSwiftType(type))}; + return SwiftASTContext::GetSwiftCompilerType( + swift::LValueType::get(GetSwiftType(type))); return {}; } @@ -5958,7 +5974,8 @@ CompilerType SwiftASTContext::GetNonReferenceType(void *type) { swift::LValueType *lvalue = swift_can_type->getAs(); if (lvalue) - return {lvalue->getObjectType().getPointer()}; + return SwiftASTContext::GetSwiftCompilerType( + lvalue->getObjectType().getPointer()); } return {}; } @@ -5972,7 +5989,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 SwiftASTContext::GetSwiftCompilerType(swift_type); } return {}; } @@ -5985,7 +6002,8 @@ 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 SwiftASTContext::GetSwiftCompilerType( + 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 SwiftASTContext::GetSwiftCompilerType( + nominal_type_decl->getDeclaredType()); } } - return {GetSwiftType(type)}; + return SwiftASTContext::GetSwiftCompilerType(GetSwiftType(type)); } //---------------------------------------------------------------------- @@ -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 SwiftASTContext::GetSwiftCompilerType( + swift_can_type->getReferenceStorageReferent()) .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 SwiftASTContext::GetSwiftCompilerType( + swift_can_type->getReferenceStorageReferent()) .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 SwiftASTContext::GetSwiftCompilerType( + swift_can_type->getReferenceStorageReferent()) .GetNumChildren(omit_empty_base_classes, exe_ctx); case swift::TypeKind::GenericTypeParam: case swift::TypeKind::DependentMember: @@ -6393,7 +6415,9 @@ 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( + SwiftASTContext::GetSwiftCompilerType(GetSwiftType(type)), + protocol_info)) break; return protocol_info.m_num_storage_words; @@ -6412,7 +6436,7 @@ uint32_t SwiftASTContext::GetNumChildren(void *type, swift::TypeBase *deref_type = lvalue_type->getObjectType().getPointer(); uint32_t num_pointee_children = - CompilerType(deref_type) + SwiftASTContext::GetSwiftCompilerType(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 +6519,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 SwiftASTContext::GetSwiftCompilerType( + swift_can_type->getReferenceStorageReferent()) .GetNumFields(); case swift::TypeKind::GenericTypeParam: case swift::TypeKind::DependentMember: @@ -6570,7 +6595,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 SwiftASTContext::GetSwiftCompilerType(base_class_type); } } return {}; @@ -6622,7 +6647,8 @@ GetExistentialTypeChild(swift::ASTContext *swift_ast_ctx, CompilerType type, llvm::raw_string_ostream(name) << "payload_data_" << idx; auto raw_pointer = swift_ast_ctx->TheRawPointerType; - return {CompilerType(raw_pointer.getPointer()), std::move(name)}; + return {SwiftASTContext::GetSwiftCompilerType(raw_pointer.getPointer()), + std::move(name)}; } // The instance for a class-bound existential. @@ -6632,7 +6658,8 @@ 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 = + SwiftASTContext::GetSwiftCompilerType(raw_pointer.getPointer()); } return {class_type, "instance"}; @@ -6641,7 +6668,8 @@ 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 {SwiftASTContext::GetSwiftCompilerType(raw_pointer.getPointer()), + "error_instance"}; } // The metatype for a non-class, non-error existential. @@ -6649,7 +6677,8 @@ 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 {SwiftASTContext::GetSwiftCompilerType(any_metatype), + "instance_type"}; } // A witness table. Figure out which protocol it corresponds to. @@ -6672,7 +6701,8 @@ GetExistentialTypeChild(swift::ASTContext *swift_ast_ctx, CompilerType type, } auto raw_pointer = swift_ast_ctx->TheRawPointerType; - return {CompilerType(raw_pointer.getPointer()), std::move(name)}; + return {SwiftASTContext::GetSwiftCompilerType(raw_pointer.getPointer()), + std::move(name)}; } CompilerType SwiftASTContext::GetFieldAtIndex(void *type, size_t idx, @@ -6702,7 +6732,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 SwiftASTContext::GetSwiftCompilerType( + swift_can_type->getReferenceStorageReferent()) .GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr); case swift::TypeKind::GenericTypeParam: @@ -6744,7 +6775,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 SwiftASTContext::GetSwiftCompilerType(child.getType().getPointer()); } case swift::TypeKind::Class: @@ -6753,7 +6784,8 @@ 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 = SwiftASTContext::GetSwiftCompilerType( + superclass_swift_type.getPointer()); name = GetSuperclassName(superclass_type); @@ -6797,19 +6829,22 @@ 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 SwiftASTContext::GetSwiftCompilerType(child_swift_type.getPointer()); } case swift::TypeKind::Protocol: case swift::TypeKind::ProtocolComposition: { ProtocolInfo protocol_info; - if (!GetProtocolTypeInfo(CompilerType(GetSwiftType(type)), protocol_info)) + if (!GetProtocolTypeInfo( + SwiftASTContext::GetSwiftCompilerType(GetSwiftType(type)), + protocol_info)) break; if (idx >= protocol_info.m_num_storage_words) break; - CompilerType compiler_type(GetSwiftType(type)); + CompilerType compiler_type = + SwiftASTContext::GetSwiftCompilerType(GetSwiftType(type)); CompilerType child_type; std::tie(child_type, name) = GetExistentialTypeChild( GetASTContext(), compiler_type, protocol_info, idx); @@ -7030,21 +7065,21 @@ bool SwiftASTContext::IsNonTriviallyManagedReferenceType( case swift::TypeKind::UnmanagedStorage: { strategy = NonTriviallyManagedReferenceStrategy::eUnmanaged; if (underlying_type) - *underlying_type = CompilerType( + *underlying_type = SwiftASTContext::GetSwiftCompilerType( swift_can_type->getReferenceStorageReferent().getPointer()); } return true; case swift::TypeKind::UnownedStorage: { strategy = NonTriviallyManagedReferenceStrategy::eUnowned; if (underlying_type) - *underlying_type = CompilerType( + *underlying_type = SwiftASTContext::GetSwiftCompilerType( swift_can_type->getReferenceStorageReferent().getPointer()); } return true; case swift::TypeKind::WeakStorage: { strategy = NonTriviallyManagedReferenceStrategy::eWeak; if (underlying_type) - *underlying_type = CompilerType( + *underlying_type = SwiftASTContext::GetSwiftCompilerType( swift_can_type->getReferenceStorageReferent().getPointer()); } return true; @@ -7095,7 +7130,8 @@ CompilerType SwiftASTContext::GetChildCompilerTypeAtIndex( case swift::TypeKind::UnmanagedStorage: case swift::TypeKind::UnownedStorage: case swift::TypeKind::WeakStorage: - return CompilerType(swift_can_type->getReferenceStorageReferent()) + return SwiftASTContext::GetSwiftCompilerType( + swift_can_type->getReferenceStorageReferent()) .GetChildCompilerTypeAtIndex( exe_ctx, idx, transparent_pointers, omit_empty_base_classes, ignore_array_bounds, child_name, child_byte_size, child_byte_offset, @@ -7123,7 +7159,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 SwiftASTContext::GetSwiftCompilerType( + GetASTContext()->TheRawPointerType.getPointer()); } else return element_info->payload_type; } @@ -7141,13 +7178,15 @@ 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 = + SwiftASTContext::GetSwiftCompilerType(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 = + SwiftASTContext::GetSwiftCompilerType(GetSwiftType(type)); llvm::Optional offset = GetInstanceVariableOffset( valobj, exe_ctx, compiler_type, printed_idx.c_str(), child_type); if (!offset) @@ -7167,7 +7206,8 @@ 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 = SwiftASTContext::GetSwiftCompilerType( + superclass_swift_type.getPointer()); child_name = GetSuperclassName(superclass_type); if (!get_type_size(child_byte_size, superclass_type)) @@ -7201,14 +7241,16 @@ 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 = + SwiftASTContext::GetSwiftCompilerType(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 = + SwiftASTContext::GetSwiftCompilerType(GetSwiftType(type)); llvm::Optional offset = GetInstanceVariableOffset( valobj, exe_ctx, compiler_type, child_name.c_str(), child_type); if (!offset) @@ -7223,13 +7265,16 @@ CompilerType SwiftASTContext::GetChildCompilerTypeAtIndex( case swift::TypeKind::Protocol: case swift::TypeKind::ProtocolComposition: { ProtocolInfo protocol_info; - if (!GetProtocolTypeInfo(CompilerType(GetSwiftType(type)), protocol_info)) + if (!GetProtocolTypeInfo( + SwiftASTContext::GetSwiftCompilerType(GetSwiftType(type)), + protocol_info)) break; if (idx >= protocol_info.m_num_storage_words) break; - CompilerType compiler_type(GetSwiftType(type)); + CompilerType compiler_type = + SwiftASTContext::GetSwiftCompilerType(GetSwiftType(type)); CompilerType child_type; std::tie(child_type, child_name) = GetExistentialTypeChild( GetASTContext(), compiler_type, protocol_info, idx); @@ -7361,7 +7406,8 @@ size_t SwiftASTContext::GetIndexOfChildMemberWithName( case swift::TypeKind::UnmanagedStorage: case swift::TypeKind::UnownedStorage: case swift::TypeKind::WeakStorage: - return CompilerType(swift_can_type->getReferenceStorageReferent()) + return SwiftASTContext::GetSwiftCompilerType( + swift_can_type->getReferenceStorageReferent()) .GetIndexOfChildMemberWithName(name, omit_empty_base_classes, child_indexes); case swift::TypeKind::GenericTypeParam: @@ -7440,7 +7486,8 @@ 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 = SwiftASTContext::GetSwiftCompilerType( + superclass_swift_type.getPointer()); if (superclass_type.GetIndexOfChildMemberWithName( name, omit_empty_base_classes, child_indexes)) return child_indexes.size(); @@ -7455,10 +7502,13 @@ size_t SwiftASTContext::GetIndexOfChildMemberWithName( case swift::TypeKind::Protocol: case swift::TypeKind::ProtocolComposition: { ProtocolInfo protocol_info; - if (!GetProtocolTypeInfo(CompilerType(GetSwiftType(type)), protocol_info)) + if (!GetProtocolTypeInfo( + SwiftASTContext::GetSwiftCompilerType(GetSwiftType(type)), + protocol_info)) break; - CompilerType compiler_type(GetSwiftType(type)); + CompilerType compiler_type = + SwiftASTContext::GetSwiftCompilerType(GetSwiftType(type)); for (unsigned idx : swift::range(protocol_info.m_num_storage_words)) { CompilerType child_type; std::string child_name; @@ -7623,7 +7673,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 SwiftASTContext::GetSwiftCompilerType( + bound_generic_type->getGenericArgs()[idx].getPointer()); } return {}; } @@ -7640,8 +7691,9 @@ 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 SwiftASTContext::GetSwiftCompilerType( + nominal_type_decl->mapTypeIntoContext(depTy) + ->castTo()); } } return {}; @@ -7667,7 +7719,7 @@ CompilerType SwiftASTContext::GetTypeForFormatters(void *type) { if (type) { swift::Type swift_type(GetSwiftType(type)); assert(&swift_type->getASTContext() == GetASTContext()); - return {swift_type}; + return SwiftASTContext::GetSwiftCompilerType(swift_type); } return {}; } @@ -7841,7 +7893,8 @@ bool SwiftASTContext::DumpTypeValue( case swift::TypeKind::UnmanagedStorage: case swift::TypeKind::UnownedStorage: case swift::TypeKind::WeakStorage: - return CompilerType(swift_can_type->getReferenceStorageReferent()) + return SwiftASTContext::GetSwiftCompilerType( + swift_can_type->getReferenceStorageReferent()) .DumpTypeValue(s, format, data, byte_offset, byte_size, bitfield_bit_size, bitfield_bit_offset, exe_scope, is_base_class); @@ -8045,7 +8098,7 @@ void SwiftASTContext::DumpTypeDescription(void *type, Stream *s, swift::TypeDecl *type_decl = llvm::dyn_cast_or_null(decl); if (type_decl) { - CompilerType clang_type( + CompilerType clang_type = SwiftASTContext::GetSwiftCompilerType( type_decl->getDeclaredInterfaceType().getPointer()); if (clang_type) { Flags clang_type_flags(clang_type.GetTypeInfo()); @@ -8467,3 +8520,9 @@ bool SwiftASTContext::PerformAutoImport(SwiftASTContext &swift_ast_context, source_file->addImports(additional_imports); return true; } + +CompilerType SwiftASTContext::GetSwiftCompilerType(swift::Type swift_type) { + return CompilerType( + SwiftASTContext::GetSwiftASTContext(&swift_type->getASTContext()), + swift_type.getPointer()); +} diff --git a/source/Target/SwiftLanguageRuntime.cpp b/source/Target/SwiftLanguageRuntime.cpp index 20b47186d342..367ab937b600 100644 --- a/source/Target/SwiftLanguageRuntime.cpp +++ b/source/Target/SwiftLanguageRuntime.cpp @@ -1954,7 +1954,8 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Protocol( } auto type_and_address = result.getValue(); - class_type_or_name.SetCompilerType(type_and_address.InstanceType); + class_type_or_name.SetCompilerType( + SwiftASTContext::GetSwiftCompilerType(type_and_address.InstanceType)); address.SetRawAddress(type_and_address.PayloadAddress.getAddressData()); return true; } @@ -2113,7 +2114,7 @@ SwiftLanguageRuntime::DoArchetypeBindingForType(StackFrame &stack_frame, swift::SubstFlags::DesugarMemberTypes); assert(target_swift_type); - return {target_swift_type.getPointer()}; + return SwiftASTContext::GetSwiftCompilerType(target_swift_type); } return base_type; } @@ -2543,7 +2544,7 @@ 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::GetSwiftCompilerType(swift_can_type); ConstString mangled_name(can_type.GetMangledTypeName()); StringRef mangled_no_prefix = swift::Demangle::dropSwiftManglingPrefix(mangled_name.GetStringRef());