Skip to content

Commit 8a4d61f

Browse files
committed
Remove FIXME in TypeExpansionAnalysis: It's cache needed to be keyed by the type expansion context
1 parent 2ea1c5c commit 8a4d61f

File tree

4 files changed

+41
-37
lines changed

4 files changed

+41
-37
lines changed

include/swift/AST/TypeExpansionContext.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
#define SWIFT_TYPEEXPANSIONCONTEXT_H
1919

2020
#include "swift/AST/ResilienceExpansion.h"
21+
#include "llvm/ADT/DenseMap.h"
2122

2223
namespace swift {
2324
class DeclContext;
25+
class SILFunction;
2426

2527
/// Describes the context in which SIL types should eventually be expanded.
2628
/// Required for lowering resilient types and deciding whether to look through
@@ -111,4 +113,33 @@ class TypeExpansionContext {
111113

112114
} // namespace swift
113115

116+
namespace llvm {
117+
template <> struct DenseMapInfo<swift::TypeExpansionContext> {
118+
using TypeExpansionContext = swift::TypeExpansionContext;
119+
120+
static TypeExpansionContext getEmptyKey() {
121+
return TypeExpansionContext(
122+
swift::ResilienceExpansion::Minimal,
123+
reinterpret_cast<swift::DeclContext *>(
124+
DenseMapInfo<swift::DeclContext *>::getEmptyKey()),
125+
false);
126+
}
127+
static TypeExpansionContext getTombstoneKey() {
128+
return TypeExpansionContext(
129+
swift::ResilienceExpansion::Minimal,
130+
reinterpret_cast<swift::DeclContext *>(
131+
DenseMapInfo<swift::DeclContext *>::getTombstoneKey()),
132+
false);
133+
}
134+
135+
static unsigned getHashValue(TypeExpansionContext val) {
136+
return DenseMapInfo<uintptr_t>::getHashValue(val.getHashKey());
137+
}
138+
139+
static bool isEqual(TypeExpansionContext LHS, TypeExpansionContext RHS) {
140+
return LHS == RHS;
141+
}
142+
};
143+
} // namespace llvm
144+
114145
#endif

include/swift/SIL/TypeLowering.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,6 @@ namespace clang {
3030
class Type;
3131
}
3232

33-
namespace llvm {
34-
template <> struct DenseMapInfo<swift::TypeExpansionContext> {
35-
using TypeExpansionContext = swift::TypeExpansionContext;
36-
37-
static TypeExpansionContext getEmptyKey() {
38-
return TypeExpansionContext(
39-
swift::ResilienceExpansion::Minimal,
40-
reinterpret_cast<swift::ModuleDecl *>(
41-
DenseMapInfo<swift::ModuleDecl *>::getEmptyKey()),
42-
false);
43-
}
44-
static TypeExpansionContext getTombstoneKey() {
45-
return TypeExpansionContext(
46-
swift::ResilienceExpansion::Minimal,
47-
reinterpret_cast<swift::ModuleDecl *>(
48-
DenseMapInfo<swift::ModuleDecl *>::getTombstoneKey()),
49-
false);
50-
}
51-
52-
static unsigned getHashValue(TypeExpansionContext val) {
53-
return DenseMapInfo<uintptr_t>::getHashValue(val.getHashKey());
54-
}
55-
56-
static bool isEqual(TypeExpansionContext LHS, TypeExpansionContext RHS) {
57-
return LHS == RHS;
58-
}
59-
};
60-
}
61-
6233
namespace swift {
6334
class AnyFunctionRef;
6435
enum class Bridgeability : unsigned;

include/swift/SILOptimizer/Analysis/TypeExpansionAnalysis.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#ifndef SWIFT_SILOPTIMIZER_ANALYSIS_TYPEEXPANSIONANALYSIS_H
1313
#define SWIFT_SILOPTIMIZER_ANALYSIS_TYPEEXPANSIONANALYSIS_H
1414

15+
#include "swift/AST/TypeExpansionContext.h"
1516
#include "swift/SIL/Projection.h"
1617
#include "swift/SIL/SILType.h"
1718
#include "swift/SIL/SILValue.h"
@@ -22,7 +23,9 @@ namespace swift {
2223

2324
/// This analysis determines memory effects during destruction.
2425
class TypeExpansionAnalysis : public SILAnalysis {
25-
llvm::DenseMap<SILType, ProjectionPathList> ExpansionCache;
26+
llvm::DenseMap<std::pair<SILType, TypeExpansionContext>, ProjectionPathList>
27+
ExpansionCache;
28+
2629
public:
2730
TypeExpansionAnalysis(SILModule *M)
2831
: SILAnalysis(SILAnalysisKind::TypeExpansion) {}

lib/SILOptimizer/Analysis/TypeExpansionAnalysis.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ const ProjectionPathList &
2828
TypeExpansionAnalysis::getTypeExpansion(SILType B, SILModule *Mod,
2929
TypeExpansionContext context) {
3030
// Check whether we have the type expansion.
31-
auto Iter = ExpansionCache.find(B);
32-
// TODO: FIXME: ExpansionCache.find((B,context))
33-
//
31+
auto key = std::make_pair(B, context);
32+
auto Iter = ExpansionCache.find(key);
3433
//
3534
if (Iter != ExpansionCache.end()) {
3635
return Iter->second;
@@ -40,8 +39,8 @@ TypeExpansionAnalysis::getTypeExpansion(SILType B, SILModule *Mod,
4039
if (!shouldExpand(*Mod, B)) {
4140
// Push the empty projection path.
4241
ProjectionPath P(B);
43-
ExpansionCache[B].push_back(P);
44-
return ExpansionCache[B];
42+
ExpansionCache[key].push_back(P);
43+
return ExpansionCache[key];
4544
}
4645

4746
// Flush the cache if the size of the cache is too large.
@@ -51,8 +50,8 @@ TypeExpansionAnalysis::getTypeExpansion(SILType B, SILModule *Mod,
5150

5251
// Build the type expansion for the leaf nodes.
5352
ProjectionPath::expandTypeIntoLeafProjectionPaths(B, Mod, context,
54-
ExpansionCache[B]);
55-
return ExpansionCache[B];
53+
ExpansionCache[key]);
54+
return ExpansionCache[key];
5655
}
5756

5857
SILAnalysis *swift::createTypeExpansionAnalysis(SILModule *M) {

0 commit comments

Comments
 (0)