Skip to content

Commit fa43d48

Browse files
authored
Merge pull request #40851 from slavapestov/originally-defined-in-opaque-result-type-5.6
ASTMangler: Respect @_originallyDefinedIn in mangleOpaqueTypeDecl() [5.6]
2 parents e7c73a3 + 9356874 commit fa43d48

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,9 +831,11 @@ std::string ASTMangler::mangleOpaqueTypeDecl(const OpaqueTypeDecl *decl) {
831831
}
832832

833833
std::string ASTMangler::mangleOpaqueTypeDecl(const ValueDecl *decl) {
834-
DWARFMangling = true;
835834
OptimizeProtocolNames = false;
836-
return mangleDeclAsUSR(decl, MANGLING_PREFIX_STR);
835+
836+
beginMangling();
837+
appendEntity(decl);
838+
return finalize();
837839
}
838840

839841
std::string ASTMangler::mangleGenericSignature(const GenericSignature sig) {

lib/AST/Decl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2939,7 +2939,9 @@ TypeRepr *ValueDecl::getOpaqueResultTypeRepr() const {
29392939

29402940
OpaqueTypeDecl *ValueDecl::getOpaqueResultTypeDecl() const {
29412941
if (getOpaqueResultTypeRepr() == nullptr) {
2942-
if (isa<ModuleDecl>(this))
2942+
if (!isa<VarDecl>(this) &&
2943+
!isa<FuncDecl>(this) &&
2944+
!isa<SubscriptDecl>(this))
29432945
return nullptr;
29442946
auto file = cast<FileUnit>(getDeclContext()->getModuleScopeContext());
29452947
// Don't look up when the decl is from source, otherwise a cycle will happen.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@available(macOS 10.8, *)
2+
@_originallyDefinedIn(module: "CoreSoup", macOS 10.10)
3+
public struct Vegetable {
4+
public init() {}
5+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// 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
4+
// 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
5+
6+
// RUN: %FileCheck %s < %t/CoreChef.swiftinterface
7+
8+
// REQUIRES: OS=macosx
9+
import CoreVegetable
10+
11+
public protocol Soup {}
12+
13+
public struct VegetableSoup : Soup {}
14+
15+
public protocol Chef {
16+
associatedtype Food
17+
18+
func cookSoup(_: Vegetable) -> Food
19+
}
20+
21+
public struct SoupChef : Chef {
22+
public func cookSoup(_: Vegetable) -> some Soup { VegetableSoup() }
23+
}
24+
25+
// CHECK-LABEL: public typealias Food = @_opaqueReturnTypeOf("$s8CoreChef04SoupB0V04cookC0yQr0aC09VegetableVF", 0) __

0 commit comments

Comments
 (0)