Skip to content

ASTMangler: Respect @_originallyDefinedIn in mangleOpaqueTypeDecl() [5.6] #40851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,9 +831,11 @@ std::string ASTMangler::mangleOpaqueTypeDecl(const OpaqueTypeDecl *decl) {
}

std::string ASTMangler::mangleOpaqueTypeDecl(const ValueDecl *decl) {
DWARFMangling = true;
OptimizeProtocolNames = false;
return mangleDeclAsUSR(decl, MANGLING_PREFIX_STR);

beginMangling();
appendEntity(decl);
return finalize();
}

std::string ASTMangler::mangleGenericSignature(const GenericSignature sig) {
Expand Down
4 changes: 3 additions & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2939,7 +2939,9 @@ TypeRepr *ValueDecl::getOpaqueResultTypeRepr() const {

OpaqueTypeDecl *ValueDecl::getOpaqueResultTypeDecl() const {
if (getOpaqueResultTypeRepr() == nullptr) {
if (isa<ModuleDecl>(this))
if (!isa<VarDecl>(this) &&
!isa<FuncDecl>(this) &&
!isa<SubscriptDecl>(this))
return nullptr;
auto file = cast<FileUnit>(getDeclContext()->getModuleScopeContext());
// Don't look up when the decl is from source, otherwise a cycle will happen.
Expand Down
5 changes: 5 additions & 0 deletions test/ModuleInterface/Inputs/CoreVegetable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@available(macOS 10.8, *)
@_originallyDefinedIn(module: "CoreSoup", macOS 10.10)
public struct Vegetable {
public init() {}
}
25 changes: 25 additions & 0 deletions test/ModuleInterface/originally-defined-attr-opaque-result.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %empty-directory(%t)

// RUN: %target-swift-frontend -typecheck -emit-module-interface-path %t/CoreVegetable.swiftinterface %S/Inputs/CoreVegetable.swift -disable-availability-checking -enable-library-evolution -swift-version 5
// RUN: %target-swift-frontend -typecheck -emit-module-interface-path %t/CoreChef.swiftinterface -module-name CoreChef %s -I %t -disable-availability-checking -enable-library-evolution -swift-version 5 -DLIB

// RUN: %FileCheck %s < %t/CoreChef.swiftinterface

// REQUIRES: OS=macosx
import CoreVegetable

public protocol Soup {}

public struct VegetableSoup : Soup {}

public protocol Chef {
associatedtype Food

func cookSoup(_: Vegetable) -> Food
}

public struct SoupChef : Chef {
public func cookSoup(_: Vegetable) -> some Soup { VegetableSoup() }
}

// CHECK-LABEL: public typealias Food = @_opaqueReturnTypeOf("$s8CoreChef04SoupB0V04cookC0yQr0aC09VegetableVF", 0) __