Skip to content

Commit 365f0c7

Browse files
authored
Merge pull request swiftlang#30861 from slavapestov/outdated-fixme
IRGen: Type reconstruction supports opaque result types now
2 parents d02c140 + 0724c47 commit 365f0c7

File tree

9 files changed

+33
-8
lines changed

9 files changed

+33
-8
lines changed

include/swift/AST/ASTMangler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ class ASTMangler : public Mangler {
236236

237237
std::string mangleLocalTypeDecl(const TypeDecl *type);
238238

239+
std::string mangleOpaqueTypeDecl(const OpaqueTypeDecl *decl);
240+
239241
enum SpecialContext {
240242
ObjCContext,
241243
ClangImporterContext,

lib/AST/ASTMangler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "swift/AST/ProtocolConformance.h"
3030
#include "swift/AST/ProtocolConformanceRef.h"
3131
#include "swift/Basic/Defer.h"
32+
#include "swift/Demangling/ManglingMacros.h"
3233
#include "swift/Demangling/ManglingUtils.h"
3334
#include "swift/Demangling/Demangler.h"
3435
#include "swift/Strings.h"
@@ -691,6 +692,12 @@ std::string ASTMangler::mangleLocalTypeDecl(const TypeDecl *type) {
691692
return finalize();
692693
}
693694

695+
std::string ASTMangler::mangleOpaqueTypeDecl(const OpaqueTypeDecl *decl) {
696+
DWARFMangling = true;
697+
OptimizeProtocolNames = false;
698+
return mangleDeclAsUSR(decl->getNamingDecl(), MANGLING_PREFIX_STR);
699+
}
700+
694701
void ASTMangler::appendSymbolKind(SymbolKind SKind) {
695702
switch (SKind) {
696703
case SymbolKind::Default: return;

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7088,7 +7088,7 @@ Identifier OpaqueTypeDecl::getOpaqueReturnTypeIdentifier() const {
70887088
{
70897089
llvm::raw_svector_ostream os(mangleBuf);
70907090
Mangle::ASTMangler mangler;
7091-
os << mangler.mangleDeclAsUSR(getNamingDecl(), MANGLING_PREFIX_STR);
7091+
os << mangler.mangleOpaqueTypeDecl(this);
70927092
}
70937093

70947094
OpaqueReturnTypeIdentifier = getASTContext().getIdentifier(mangleBuf);

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -798,9 +798,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
798798
std::string Result = Mangler.mangleTypeForDebugger(
799799
Ty, nullptr);
800800

801-
if (!Opts.DisableRoundTripDebugTypes
802-
// FIXME: implement type reconstruction for opaque types
803-
&& !Ty->hasOpaqueArchetype()) {
801+
if (!Opts.DisableRoundTripDebugTypes) {
804802
// Make sure we can reconstruct mangled types for the debugger.
805803
#ifndef NDEBUG
806804
auto &Ctx = Ty->getASTContext();

lib/IRGen/IRGenRequests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void swift::simple_display(llvm::raw_ostream &out,
4040
} else {
4141
assert(SF);
4242
out << "IR Generation for file ";
43-
out << '\"' << cast<LoadedFile>(SF)->getFilename() << '\"';
43+
out << '\"' << SF->getFilename() << '\"';
4444
}
4545
}
4646

lib/Serialization/ModuleFile.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,10 @@ class ModuleFile::LocalDeclTableInfo {
597597
return ID;
598598
}
599599

600+
external_key_type GetExternalKey(internal_key_type ID) {
601+
return ID;
602+
}
603+
600604
hash_value_type ComputeHash(internal_key_type key) {
601605
return llvm::djbHash(key, SWIFTMODULE_HASH_SEED);
602606
}

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5555
/// describe what change you made. The content of this comment isn't important;
5656
/// it just ensures a conflict if two people change the module format.
5757
/// Don't worry about adhering to the 80-column limit for this line.
58-
const uint16_t SWIFTMODULE_VERSION_MINOR = 552; // simple didSet
58+
const uint16_t SWIFTMODULE_VERSION_MINOR = 553; // change to USR mangling
5959

6060
/// A standard hash seed used for all string hashes in a serialized module.
6161
///

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5067,8 +5067,7 @@ void Serializer::writeAST(ModuleOrSourceFile DC) {
50675067
for (auto OTD : opaqueReturnTypeDecls) {
50685068
hasOpaqueReturnTypes = true;
50695069
Mangle::ASTMangler Mangler;
5070-
auto MangledName = Mangler.mangleDeclAsUSR(OTD->getNamingDecl(),
5071-
MANGLING_PREFIX_STR);
5070+
auto MangledName = Mangler.mangleOpaqueTypeDecl(OTD);
50725071
opaqueReturnTypeGenerator.insert(MangledName, addDeclRef(OTD));
50735072
}
50745073
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-swift-frontend -emit-ir -g %s -disable-availability-checking
2+
3+
public protocol P {
4+
associatedtype Horse
5+
}
6+
7+
public protocol Feed {}
8+
9+
public struct Hay : Feed {}
10+
11+
public func hasOpaqueResult<T : P>(_: T.Type, _: T.Horse) -> some Feed {
12+
return Hay()
13+
}
14+
15+

0 commit comments

Comments
 (0)