Skip to content

Commit 94d9d6a

Browse files
committed
[ClangImporter] Shrink EffectiveClangContext on 32-bit platforms.
No intended functionality change.
1 parent 280dace commit 94d9d6a

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

lib/ClangImporter/SwiftLookupTable.h

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ namespace swift {
5656
/// Swift name, this will be recorded as
5757
class EffectiveClangContext {
5858
public:
59-
enum Kind {
59+
enum Kind : uint8_t {
6060
DeclContext,
6161
TypedefContext,
62-
UnresolvedContext,
62+
UnresolvedContext, // must be last
6363
};
6464

6565
private:
@@ -70,15 +70,19 @@ class EffectiveClangContext {
7070
const char *Data;
7171
} Unresolved;
7272
};
73-
Kind TheKind;
74-
unsigned UnresolvedLength;
75-
73+
74+
/// If KindOrBiasedLength < Kind::UnresolvedContext, this represents a Kind.
75+
/// Otherwise it's (uintptr_t)Kind::UnresolvedContext plus the length of
76+
/// Unresolved.Data.
77+
uintptr_t KindOrBiasedLength;
78+
7679
public:
77-
EffectiveClangContext() : TheKind(DeclContext) {
80+
EffectiveClangContext() : KindOrBiasedLength(DeclContext) {
7881
DC = nullptr;
7982
}
8083

81-
EffectiveClangContext(const clang::DeclContext *dc) : TheKind(DeclContext) {
84+
EffectiveClangContext(const clang::DeclContext *dc)
85+
: KindOrBiasedLength(DeclContext) {
8286
assert(dc != nullptr && "use null constructor instead");
8387
if (auto tagDecl = dyn_cast<clang::TagDecl>(dc)) {
8488
DC = tagDecl->getCanonicalDecl();
@@ -99,14 +103,13 @@ class EffectiveClangContext {
99103
}
100104

101105
EffectiveClangContext(const clang::TypedefNameDecl *typedefName)
102-
: TheKind(TypedefContext)
103-
{
106+
: KindOrBiasedLength(TypedefContext) {
104107
Typedef = typedefName->getCanonicalDecl();
105108
}
106109

107-
EffectiveClangContext(StringRef unresolved) : TheKind(UnresolvedContext) {
110+
EffectiveClangContext(StringRef unresolved)
111+
: KindOrBiasedLength(UnresolvedContext + unresolved.size()) {
108112
Unresolved.Data = unresolved.data();
109-
UnresolvedLength = unresolved.size();
110113
}
111114

112115
/// Determine whether this effective Clang context was set.
@@ -115,7 +118,12 @@ class EffectiveClangContext {
115118
}
116119

117120
/// Determine the kind of effective Clang context.
118-
Kind getKind() const { return TheKind; }
121+
Kind getKind() const {
122+
if (KindOrBiasedLength >= UnresolvedContext)
123+
return UnresolvedContext;
124+
return static_cast<Kind>(KindOrBiasedLength);
125+
126+
}
119127

120128
/// Retrieve the declaration context.
121129
const clang::DeclContext *getAsDeclContext() const {
@@ -131,7 +139,7 @@ class EffectiveClangContext {
131139
/// Retrieve the unresolved context name.
132140
StringRef getUnresolvedName() const {
133141
assert(getKind() == UnresolvedContext);
134-
return StringRef(Unresolved.Data, UnresolvedLength);
142+
return StringRef(Unresolved.Data, KindOrBiasedLength - UnresolvedContext);
135143
}
136144

137145
/// Compares two EffectiveClangContexts without resolving unresolved names.
@@ -149,13 +157,8 @@ class EffectiveClangContext {
149157
}
150158
};
151159

152-
#if LLVM_PTR_SIZE == 4
153-
static_assert(sizeof(EffectiveClangContext) <= 4 * sizeof(void *),
154-
"should fit in four pointers");
155-
#else
156160
static_assert(sizeof(EffectiveClangContext) <= 2 * sizeof(void *),
157-
"should fit in a couple pointers");
158-
#endif
161+
"should be small");
159162

160163
class SwiftLookupTableReader;
161164
class SwiftLookupTableWriter;

0 commit comments

Comments
 (0)