Skip to content

Commit 7678e43

Browse files
committed
[TBDGen] Include materializeForSet closures.
This is a hack around IRGen's inadequacies, for the moment.
1 parent a560ea1 commit 7678e43

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===- SILGenMaterializeForSet.h - SILGen for materializeForSet -*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include <string>
14+
15+
namespace swift {
16+
class ProtocolConformance;
17+
class FuncDecl;
18+
19+
namespace Lowering {
20+
/// \brief Compute the name of the callback inside an auto-generated
21+
/// materializeForSet accessor.
22+
///
23+
/// FIXME: this should just be a static function inside
24+
/// SILGenMaterializeForSet.cpp, but currently these closures end up public,
25+
/// so TBDGen wants to emit them.
26+
std::string getMaterializeForSetCallbackName(ProtocolConformance *conformance,
27+
FuncDecl *requirement);
28+
}
29+
}

lib/SILGen/SILGenMaterializeForSet.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,15 @@
171171
#include "swift/SIL/SILArgument.h"
172172
#include "swift/SIL/SILUndef.h"
173173
#include "swift/SIL/TypeLowering.h"
174+
#include "swift/SILGen/SILGenMaterializeForSet.h"
174175
#include "llvm/Support/raw_ostream.h"
175176
#include "ASTVisitor.h"
176177
using namespace swift;
177178
using namespace Lowering;
178179

179-
namespace {
180-
181-
static std::string
182-
getMaterializeForSetCallbackName(ProtocolConformance *conformance,
183-
FuncDecl *requirement) {
180+
std::string
181+
Lowering::getMaterializeForSetCallbackName(ProtocolConformance *conformance,
182+
FuncDecl *requirement) {
184183

185184
DeclContext *dc = requirement;
186185
ClosureExpr closure(/*patterns*/ nullptr,
@@ -209,6 +208,8 @@ getMaterializeForSetCallbackName(ProtocolConformance *conformance,
209208
Mangle::ASTMangler::SymbolKind::Default);
210209
}
211210

211+
namespace {
212+
212213
/// A helper class for emitting materializeForSet.
213214
///
214215
/// The formal type of materializeForSet is:

lib/TBDGen/TBDGen.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "swift/SIL/SILDeclRef.h"
2727
#include "swift/SIL/SILWitnessTable.h"
2828
#include "swift/SIL/TypeLowering.h"
29+
#include "swift/SILGen/SILGenMaterializeForSet.h"
2930
#include "llvm/ADT/StringSet.h"
3031

3132
using namespace swift;
@@ -285,6 +286,15 @@ void TBDGenVisitor::visitAbstractStorageDecl(AbstractStorageDecl *ASD) {
285286
InsideAbstractStorageDecl = true;
286287
visitMembers(ASD);
287288
InsideAbstractStorageDecl = false;
289+
290+
// IRGen currently promotes serialized private functions to public, which
291+
// includes the closures inside materializeForSets of computed properties.
292+
if (auto MFS = ASD->getMaterializeForSetFunc()) {
293+
if (!isPrivateDecl(MFS)) {
294+
addSymbol(Lowering::getMaterializeForSetCallbackName(
295+
/*conformance=*/nullptr, MFS));
296+
}
297+
}
288298
}
289299
void TBDGenVisitor::visitVarDecl(VarDecl *VD) {
290300
// statically/globally stored variables have some special handling.

0 commit comments

Comments
 (0)