Skip to content

Commit ac5b1df

Browse files
committed
ASTMangler: Don't consider @_originallyDefinedIn when mangling local type discriminators
Local types are not ABI, and the only time we care about the mangling here is when we look them up using the DWARF mangling in debug info, which doesn't respect @_originallyDefinedIn either. Fixes #59773.
1 parent 1663b1d commit ac5b1df

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,11 @@ std::string ASTMangler::mangleLocalTypeDecl(const TypeDecl *type) {
822822
AllowNamelessEntities = true;
823823
OptimizeProtocolNames = false;
824824

825+
// Local types are not ABI anyway. To avoid problems with the ASTDemangler,
826+
// don't respect @_originallyDefinedIn here, since we don't respect it
827+
// when mangling DWARF types for debug info.
828+
RespectOriginallyDefinedIn = false;
829+
825830
if (auto GTD = dyn_cast<GenericTypeDecl>(type)) {
826831
appendAnyGenericType(GTD);
827832
} else {

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5858
/// describe what change you made. The content of this comment isn't important;
5959
/// it just ensures a conflict if two people change the module format.
6060
/// Don't worry about adhering to the 80-column limit for this line.
61-
const uint16_t SWIFTMODULE_VERSION_MINOR = 696; // `distributed thunk` bit on `AbstractFunctionDecl`
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 697; // change local type mangling
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@available(macOS 10, *)
2+
@_originallyDefinedIn(module: "Barn", macOS 10.1) public struct Horse {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/local_type_originally_defined_in_other.swiftmodule %S/Inputs/local_type_originally_defined_in_other.swift
3+
// RUN: %target-swift-frontend -I%t -g -emit-ir %s
4+
5+
import local_type_originally_defined_in_other
6+
7+
public func localTypeAliasTest(horse: Horse) {
8+
// The local type mangling for 'A' mentions 'Horse', which must
9+
// be mangled using it's current module name, and not the
10+
// original module name, for consistency with the debug info
11+
// mangling.
12+
typealias A = Int
13+
14+
let info = UnsafeMutablePointer<A>.allocate(capacity: 1)
15+
_ = info
16+
}

0 commit comments

Comments
 (0)