diff --git a/lib/AST/ASTMangler.cpp b/lib/AST/ASTMangler.cpp index 1b5c03833ec19..0b51385c646c4 100644 --- a/lib/AST/ASTMangler.cpp +++ b/lib/AST/ASTMangler.cpp @@ -2591,15 +2591,9 @@ void ASTMangler::appendModule(const ModuleDecl *module, StringRef ModName = module->getRealName().str(); // If RespectOriginallyDefinedIn is not set, ignore the ABI name only for - // _Concurrency and swift-syntax (which adds "Compiler" as a prefix when - // building swift-syntax as part of the compiler). - // TODO: Mangling for the debugger should respect originally defined in, but - // as of right now there is not enough information in the mangled name to - // reconstruct AST types from mangled names when using that attribute. + // _Concurrency. if ((RespectOriginallyDefinedIn || - (module->getName().str() != SWIFT_CONCURRENCY_NAME && - !module->getABIName().str().starts_with( - SWIFT_MODULE_ABI_NAME_PREFIX))) && + module->getName().str() != SWIFT_CONCURRENCY_NAME) && module->getABIName() != module->getName()) ModName = module->getABIName().str(); diff --git a/lib/IRGen/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp index f624cf3049e1d..d974f863d9806 100644 --- a/lib/IRGen/IRGenDebugInfo.cpp +++ b/lib/IRGen/IRGenDebugInfo.cpp @@ -25,6 +25,7 @@ #include "swift/AST/ASTMangler.h" #include "swift/AST/Attr.h" #include "swift/AST/Decl.h" +#include "swift/AST/DeclContext.h" #include "swift/AST/Expr.h" #include "swift/AST/GenericEnvironment.h" #include "swift/AST/IRGenOptions.h" @@ -34,6 +35,7 @@ #include "swift/AST/Pattern.h" #include "swift/AST/TypeDifferenceVisitor.h" #include "swift/AST/TypeWalker.h" +#include "swift/AST/Types.h" #include "swift/Basic/Assertions.h" #include "swift/Basic/Compiler.h" #include "swift/Basic/SourceManager.h" @@ -65,6 +67,7 @@ #include "llvm/IR/DebugInfo.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Module.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/FileSystem.h" @@ -2343,18 +2346,21 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type, if (visitedOriginallyDefinedIn) return TypeWalker::Action::Stop; - // A typealias inside a function used that function's signature as part of + DeclContext *D = nullptr; + if (auto *TAT = llvm::dyn_cast(T)) + D = TAT->getDecl()->getDeclContext(); + else if (auto *NT = llvm::dyn_cast(T)) + D = NT->getDecl()->getDeclContext(); + + // A type inside a function uses that function's signature as part of // its mangling, so check if any types in the generic signature are // annotated with @_originallyDefinedIn. - if (auto *TAT = llvm::dyn_cast(T)) { - auto D = TAT->getDecl()->getDeclContext(); - if (auto AFD = llvm::dyn_cast(D)) { - OriginallyDefinedInFinder InnerWalker; - AFD->getInterfaceType().walk(InnerWalker); - if (InnerWalker.visitedOriginallyDefinedIn) { - visitedOriginallyDefinedIn = true; - return TypeWalker::Action::Stop; - } + if (auto AFD = llvm::dyn_cast_or_null(D)) { + OriginallyDefinedInFinder InnerWalker; + AFD->getInterfaceType().walk(InnerWalker); + if (InnerWalker.visitedOriginallyDefinedIn) { + visitedOriginallyDefinedIn = true; + return TypeWalker::Action::Stop; } } diff --git a/test/DebugInfo/local_type_originally_defined_in.swift b/test/DebugInfo/local_type_originally_defined_in.swift index 3f58ca032e59d..4887a31fefadf 100644 --- a/test/DebugInfo/local_type_originally_defined_in.swift +++ b/test/DebugInfo/local_type_originally_defined_in.swift @@ -21,6 +21,19 @@ public func localTypeAliasTest(horse: Horse) { // CHECK: DIDerivedType(tag: DW_TAG_typedef, name: "$s32local_type_originally_defined_in0A13TypeAliasTest5horsey4Barn5HorseV_tF1AL_aD" } + +public func localTypeTest(horse: Horse) { + // The local type mangling for 'A' mentions 'Horse', which must + // be mangled using it's current module name, and not the + // original module name, for consistency with the debug info + // mangling. + struct LocalStruct {} + + let info = UnsafeMutablePointer.allocate(capacity: 1) + _ = info + // CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "$s32local_type_originally_defined_in0A8TypeTest5horsey4Barn5HorseV_tF11LocalStructL_VD" +} + public func localTypeAliasTest() -> Horse { typealias B = Int