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 891d13f8515e..502381716b8b 100644 --- a/include/lldb/Symbol/SwiftASTContext.h +++ b/include/lldb/Symbol/SwiftASTContext.h @@ -738,6 +738,8 @@ class SwiftASTContext : public TypeSystem { lldb::StackFrameWP &stack_frame_wp, swift::SourceFile *source_file, Status &error); + static CompilerType GetCompilerType(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 c309be76b4dd..6cba289e23b0 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::GetCompilerType(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::GetCompilerType(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::GetCompilerType(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::GetCompilerType(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::GetCompilerType(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..1dbc314233de 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::GetCompilerType(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 796a89dad169..f4955c80f586 100644 --- a/source/Plugins/Language/Swift/SwiftLanguage.cpp +++ b/source/Plugins/Language/Swift/SwiftLanguage.cpp @@ -1315,8 +1315,8 @@ std::unique_ptr SwiftLanguage::GetTypeScavenger() { } else if (local_results.empty() && module && name_parts.size() == 1 && name_parts.front() == module->getName().str()) - results.insert( - CompilerType(swift::ModuleType::get(module))); + results.insert(SwiftASTContext::GetCompilerType( + swift::ModuleType::get(module))); } }; diff --git a/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.cpp b/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.cpp index a23608075647..63ea00282c5b 100644 --- a/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.cpp +++ b/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.cpp @@ -192,7 +192,8 @@ lldb::TypeSP DWARFASTParserSwift::ParseTypeFromDWARF(const SymbolContext &sc, return {}; } preferred_name = name; - compiler_type = {swift_ast_ctx->TheRawPointerType}; + compiler_type = + SwiftASTContext::GetCompilerType(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 3a1a1de5242d..3cf846d60e96 100644 --- a/source/Symbol/SwiftASTContext.cpp +++ b/source/Symbol/SwiftASTContext.cpp @@ -538,10 +538,10 @@ class SwiftAllPayloadEnumDescriptor : public SwiftEnumDescriptor { auto arg_type = case_decl->getArgumentInterfaceType(); CompilerType case_type; if (arg_type) { - case_type = { + case_type = SwiftASTContext::GetCompilerType( swift_can_type->getTypeOfMember(module_ctx, case_decl, arg_type) ->getCanonicalType() - .getPointer()}; + .getPointer()); } const bool is_indirect = @@ -778,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( + SwiftASTContext::GetCompilerType(swift_can_type))) return nullptr; SwiftEnumDescriptorSP enum_info_sp; @@ -4362,7 +4363,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::GetCompilerType(found_type); } if (m_negative_type_cache.Lookup(mangled_cstr)) { @@ -4382,7 +4383,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::GetCompilerType(found_type); assert(&found_type->getASTContext() == ast_ctx); LOG_PRINTF(LIBLLDB_LOG_TYPES, "(\"%s\") -- found %s", mangled_cstr, result_type.GetTypeName().GetCString()); @@ -4398,8 +4400,8 @@ SwiftASTContext::GetTypeFromMangledTypename(ConstString mangled_typename, CompilerType SwiftASTContext::GetAnyObjectType() { VALID_OR_RETURN(CompilerType()); - swift::ASTContext *ast = GetASTContext(); - return {ast->getAnyObjectType()}; + return SwiftASTContext::GetCompilerType( + GetASTContext()->getAnyObjectType()); } CompilerType SwiftASTContext::GetVoidFunctionType() { @@ -4408,7 +4410,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::GetCompilerType( + swift::FunctionType::get({}, empty_tuple_type)); } return m_void_function_type; } @@ -4424,7 +4427,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::GetCompilerType(swift_type); } break; } @@ -4437,7 +4440,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::GetCompilerType(swift_type); } } break; @@ -4486,7 +4489,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::GetCompilerType(swift_type); } } break; case swift::DeclKind::Enum: @@ -4497,7 +4500,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::GetCompilerType(swift_type); } } break; @@ -4608,9 +4611,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::GetCompilerType( + meta_type->getInstanceType()); else - return {swift_type.getPointer()}; + return SwiftASTContext::GetCompilerType(swift_type); } } return CompilerType(); @@ -4715,7 +4719,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::GetCompilerType(our_type_base); else { Status error; @@ -4857,7 +4861,8 @@ SwiftASTContext::CreateTupleType(const std::vector &elements) { Status error; if (elements.size() == 0) - return {GetASTContext()->TheEmptyTupleType}; + return SwiftASTContext::GetCompilerType( + GetASTContext()->TheEmptyTupleType); else { std::vector tuple_elems; for (const TupleElement &element : elements) { @@ -4872,7 +4877,8 @@ SwiftASTContext::CreateTupleType(const std::vector &elements) { return {}; } llvm::ArrayRef fields(tuple_elems); - return {swift::TupleType::get(fields, *GetASTContext()).getPointer()}; + return SwiftASTContext::GetCompilerType( + swift::TupleType::get(fields, *GetASTContext()).getPointer()); } } @@ -4887,7 +4893,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::GetCompilerType(error_type); } } return {}; @@ -4902,10 +4908,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::GetCompilerType( + GetASTContext()->TheRawPointerType.getPointer()) + .GetByteSize(nullptr) + .getValueOr(0); return m_pointer_byte_size; } @@ -5140,7 +5146,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::GetCompilerType(args[0].getPointer()); return true; } @@ -5422,7 +5429,7 @@ SwiftASTContext::GetReferentType(const CompilerType &compiler_type) { return compiler_type; auto ref_type = swift_type->getReferenceStorageReferent(); - return {ref_type}; + return SwiftASTContext::GetCompilerType(ref_type); } return {}; @@ -5460,7 +5467,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::GetCompilerType(superclass.getPointer()); } unsigned num_witness_tables = 0; @@ -5553,21 +5561,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; @@ -5665,7 +5673,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::GetCompilerType( + swift_can_type->getReferenceStorageReferent()) .GetTypeInfo(pointee_or_element_clang_type); break; case swift::TypeKind::BoundGenericEnum: @@ -5777,7 +5786,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::GetCompilerType( + swift_can_type->getReferenceStorageReferent()) .GetTypeClass(); case swift::TypeKind::GenericTypeParam: return lldb::eTypeClassOther; @@ -5874,7 +5884,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::GetCompilerType(args[0].getPointer()); } } } @@ -5885,9 +5896,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::GetCompilerType( + GetCanonicalSwiftType(type).getPointer()); } CompilerType SwiftASTContext::GetInstanceType(void *type) { @@ -5901,15 +5914,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::GetCompilerType( + metatype_type.getInstanceType().getPointer()); - return {GetSwiftType(type)}; + return SwiftASTContext::GetCompilerType(GetSwiftType(type)); } CompilerType SwiftASTContext::GetFullyUnqualifiedType(void *type) { VALID_OR_RETURN(CompilerType()); - return {GetSwiftType(type)}; + return SwiftASTContext::GetCompilerType(GetSwiftType(type)); } int SwiftASTContext::GetFunctionArgumentCount(void *type) { @@ -5928,7 +5942,8 @@ CompilerType SwiftASTContext::GetFunctionReturnType(void *type) { auto func = swift::dyn_cast(GetCanonicalSwiftType(type)); if (func) - return {func.getResult().getPointer()}; + return SwiftASTContext::GetCompilerType( + func.getResult().getPointer()); } return {}; } @@ -6011,7 +6026,7 @@ TypeMemberFunctionImpl SwiftASTContext::GetMemberFunctionAtIndex(void *type, } } } - result_type = CompilerType( + result_type = SwiftASTContext::GetCompilerType( abstract_func_decl->getInterfaceType().getPointer()); } } else @@ -6035,7 +6050,8 @@ CompilerType SwiftASTContext::GetLValueReferenceType(void *type) { VALID_OR_RETURN(CompilerType()); if (type) - return {swift::LValueType::get(GetSwiftType(type))}; + return SwiftASTContext::GetCompilerType( + swift::LValueType::get(GetSwiftType(type))); return {}; } @@ -6049,7 +6065,8 @@ CompilerType SwiftASTContext::GetNonReferenceType(void *type) { swift::LValueType *lvalue = swift_can_type->getAs(); if (lvalue) - return {lvalue->getObjectType().getPointer()}; + return SwiftASTContext::GetCompilerType( + lvalue->getObjectType().getPointer()); } return {}; } @@ -6063,7 +6080,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::GetCompilerType(swift_type); } return {}; } @@ -6076,7 +6093,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::GetCompilerType( + name_alias_type->getSinglyDesugaredType()); } } @@ -6094,11 +6112,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::GetCompilerType( + nominal_type_decl->getDeclaredType()); } } - return {GetSwiftType(type)}; + return SwiftASTContext::GetCompilerType(GetSwiftType(type)); } CompilerType SwiftASTContext::GetTypeForDecl(void *opaque_decl) { @@ -6301,7 +6320,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::GetCompilerType( + swift_can_type->getReferenceStorageReferent()) .GetEncoding(count); break; @@ -6390,7 +6410,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::GetCompilerType( + swift_can_type->getReferenceStorageReferent()) .GetFormat(); break; @@ -6469,7 +6490,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::GetCompilerType( + swift_can_type->getReferenceStorageReferent()) .GetNumChildren(omit_empty_base_classes, exe_ctx); case swift::TypeKind::GenericTypeParam: case swift::TypeKind::DependentMember: @@ -6496,7 +6518,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::GetCompilerType(GetSwiftType(type)), + protocol_info)) break; return protocol_info.m_num_storage_words; @@ -6515,7 +6539,7 @@ uint32_t SwiftASTContext::GetNumChildren(void *type, swift::TypeBase *deref_type = lvalue_type->getObjectType().getPointer(); uint32_t num_pointee_children = - CompilerType(deref_type) + SwiftASTContext::GetCompilerType(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. @@ -6598,7 +6622,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::GetCompilerType( + swift_can_type->getReferenceStorageReferent()) .GetNumFields(); case swift::TypeKind::GenericTypeParam: case swift::TypeKind::DependentMember: @@ -6673,7 +6698,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::GetCompilerType(base_class_type); } } return {}; @@ -6725,7 +6750,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::GetCompilerType(raw_pointer.getPointer()), + std::move(name)}; } // The instance for a class-bound existential. @@ -6735,7 +6761,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::GetCompilerType(raw_pointer.getPointer()); } return {class_type, "instance"}; @@ -6744,7 +6771,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::GetCompilerType(raw_pointer.getPointer()), + "error_instance"}; } // The metatype for a non-class, non-error existential. @@ -6752,7 +6780,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::GetCompilerType(any_metatype), + "instance_type"}; } // A witness table. Figure out which protocol it corresponds to. @@ -6775,7 +6804,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::GetCompilerType(raw_pointer.getPointer()), + std::move(name)}; } CompilerType SwiftASTContext::GetFieldAtIndex(void *type, size_t idx, @@ -6805,7 +6835,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::GetCompilerType( + swift_can_type->getReferenceStorageReferent()) .GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr); case swift::TypeKind::GenericTypeParam: @@ -6847,7 +6878,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::GetCompilerType(child.getType().getPointer()); } case swift::TypeKind::Class: @@ -6856,7 +6887,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::GetCompilerType( + superclass_swift_type.getPointer()); name = GetSuperclassName(superclass_type); @@ -6900,19 +6932,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::GetCompilerType(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::GetCompilerType(GetSwiftType(type)), + protocol_info)) break; if (idx >= protocol_info.m_num_storage_words) break; - CompilerType compiler_type(GetSwiftType(type)); + CompilerType compiler_type = + SwiftASTContext::GetCompilerType(GetSwiftType(type)); CompilerType child_type; std::tie(child_type, name) = GetExistentialTypeChild( GetASTContext(), compiler_type, protocol_info, idx); @@ -7105,21 +7140,21 @@ bool SwiftASTContext::IsNonTriviallyManagedReferenceType( case swift::TypeKind::UnmanagedStorage: { strategy = NonTriviallyManagedReferenceStrategy::eUnmanaged; if (underlying_type) - *underlying_type = CompilerType( + *underlying_type = SwiftASTContext::GetCompilerType( swift_can_type->getReferenceStorageReferent().getPointer()); } return true; case swift::TypeKind::UnownedStorage: { strategy = NonTriviallyManagedReferenceStrategy::eUnowned; if (underlying_type) - *underlying_type = CompilerType( + *underlying_type = SwiftASTContext::GetCompilerType( swift_can_type->getReferenceStorageReferent().getPointer()); } return true; case swift::TypeKind::WeakStorage: { strategy = NonTriviallyManagedReferenceStrategy::eWeak; if (underlying_type) - *underlying_type = CompilerType( + *underlying_type = SwiftASTContext::GetCompilerType( swift_can_type->getReferenceStorageReferent().getPointer()); } return true; @@ -7170,7 +7205,8 @@ CompilerType SwiftASTContext::GetChildCompilerTypeAtIndex( case swift::TypeKind::UnmanagedStorage: case swift::TypeKind::UnownedStorage: case swift::TypeKind::WeakStorage: - return CompilerType(swift_can_type->getReferenceStorageReferent()) + return SwiftASTContext::GetCompilerType( + 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, @@ -7198,7 +7234,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::GetCompilerType( + GetASTContext()->TheRawPointerType.getPointer()); } else return element_info->payload_type; } @@ -7216,13 +7253,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::GetCompilerType(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::GetCompilerType(GetSwiftType(type)); llvm::Optional offset = GetInstanceVariableOffset( valobj, exe_ctx, compiler_type, printed_idx.c_str(), child_type); if (!offset) @@ -7242,7 +7281,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::GetCompilerType( + superclass_swift_type.getPointer()); child_name = GetSuperclassName(superclass_type); if (!get_type_size(child_byte_size, superclass_type)) @@ -7276,14 +7316,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::GetCompilerType(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::GetCompilerType(GetSwiftType(type)); llvm::Optional offset = GetInstanceVariableOffset( valobj, exe_ctx, compiler_type, child_name.c_str(), child_type); if (!offset) @@ -7298,13 +7340,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::GetCompilerType(GetSwiftType(type)), + protocol_info)) break; if (idx >= protocol_info.m_num_storage_words) break; - CompilerType compiler_type(GetSwiftType(type)); + CompilerType compiler_type = + SwiftASTContext::GetCompilerType(GetSwiftType(type)); CompilerType child_type; std::tie(child_type, child_name) = GetExistentialTypeChild( GetASTContext(), compiler_type, protocol_info, idx); @@ -7436,7 +7481,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::GetCompilerType( + swift_can_type->getReferenceStorageReferent()) .GetIndexOfChildMemberWithName(name, omit_empty_base_classes, child_indexes); case swift::TypeKind::GenericTypeParam: @@ -7515,7 +7561,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::GetCompilerType( + superclass_swift_type.getPointer()); if (superclass_type.GetIndexOfChildMemberWithName( name, omit_empty_base_classes, child_indexes)) return child_indexes.size(); @@ -7530,10 +7577,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::GetCompilerType(GetSwiftType(type)), + protocol_info)) break; - CompilerType compiler_type(GetSwiftType(type)); + CompilerType compiler_type = + SwiftASTContext::GetCompilerType(GetSwiftType(type)); for (unsigned idx : swift::range(protocol_info.m_num_storage_words)) { CompilerType child_type; std::string child_name; @@ -7698,7 +7748,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::GetCompilerType( + bound_generic_type->getGenericArgs()[idx].getPointer()); } return {}; } @@ -7715,8 +7766,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::GetCompilerType( + nominal_type_decl->mapTypeIntoContext(depTy) + ->castTo()); } } return {}; @@ -7742,7 +7794,7 @@ CompilerType SwiftASTContext::GetTypeForFormatters(void *type) { if (type) { swift::Type swift_type(GetSwiftType(type)); assert(&swift_type->getASTContext() == GetASTContext()); - return {swift_type}; + return SwiftASTContext::GetCompilerType(swift_type); } return {}; } @@ -7916,7 +7968,8 @@ bool SwiftASTContext::DumpTypeValue( case swift::TypeKind::UnmanagedStorage: case swift::TypeKind::UnownedStorage: case swift::TypeKind::WeakStorage: - return CompilerType(swift_can_type->getReferenceStorageReferent()) + return SwiftASTContext::GetCompilerType( + swift_can_type->getReferenceStorageReferent()) .DumpTypeValue(s, format, data, byte_offset, byte_size, bitfield_bit_size, bitfield_bit_offset, exe_scope, is_base_class); @@ -8120,7 +8173,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::GetCompilerType( type_decl->getDeclaredInterfaceType().getPointer()); if (clang_type) { Flags clang_type_flags(clang_type.GetTypeInfo()); @@ -8542,3 +8595,9 @@ bool SwiftASTContext::PerformAutoImport(SwiftASTContext &swift_ast_context, source_file->addImports(additional_imports); return true; } + +CompilerType SwiftASTContext::GetCompilerType(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 da7b661b4836..3a8a42c7df4f 100644 --- a/source/Target/SwiftLanguageRuntime.cpp +++ b/source/Target/SwiftLanguageRuntime.cpp @@ -1698,7 +1698,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::GetCompilerType(type_and_address.InstanceType)); address.SetRawAddress(type_and_address.PayloadAddress.getAddressData()); return true; } @@ -1857,7 +1858,7 @@ SwiftLanguageRuntime::DoArchetypeBindingForType(StackFrame &stack_frame, swift::SubstFlags::DesugarMemberTypes); assert(target_swift_type); - return {target_swift_type.getPointer()}; + return SwiftASTContext::GetCompilerType(target_swift_type); } return base_type; } @@ -2375,7 +2376,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::GetCompilerType(swift_can_type); ConstString mangled_name(can_type.GetMangledTypeName()); StringRef mangled_no_prefix = swift::Demangle::dropSwiftManglingPrefix(mangled_name.GetStringRef());