Skip to content

Commit aadcf86

Browse files
committed
Always initialize 'Expansion' field in SILDeclRef.
Fixes nondeterminism in SIL serialization that fortunately seemed to not affect anything. Or maybe it did and some random crashes will go away now. Swift SVN r28577
1 parent 9ef66a3 commit aadcf86

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

include/swift/SIL/SILDeclRef.h

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -266,18 +266,14 @@ struct SILDeclRef {
266266
bool operator==(SILDeclRef rhs) const {
267267
return loc.getOpaqueValue() == rhs.loc.getOpaqueValue()
268268
&& kind == rhs.kind
269+
&& Expansion == rhs.Expansion
269270
&& uncurryLevel == rhs.uncurryLevel
270271
&& isForeign == rhs.isForeign
271272
&& isDirectReference == rhs.isDirectReference
272273
&& defaultArgIndex == rhs.defaultArgIndex;
273274
}
274275
bool operator!=(SILDeclRef rhs) const {
275-
return loc.getOpaqueValue() != rhs.loc.getOpaqueValue()
276-
|| kind != rhs.kind
277-
|| uncurryLevel != rhs.uncurryLevel
278-
|| isForeign != rhs.isForeign
279-
|| isDirectReference != rhs.isDirectReference
280-
|| defaultArgIndex != rhs.defaultArgIndex;
276+
return !(*this == rhs);
281277
}
282278

283279
void print(llvm::raw_ostream &os) const;
@@ -294,16 +290,16 @@ struct SILDeclRef {
294290
// Curry thunks are never foreign.
295291
bool willBeForeign = isForeign && !willBeCurried;
296292
bool willBeDirect = isDirectReference;
297-
return SILDeclRef(loc.getOpaqueValue(), kind, level,
293+
return SILDeclRef(loc.getOpaqueValue(), kind, Expansion, level,
298294
willBeCurried, willBeDirect, willBeForeign,
299295
defaultArgIndex);
300296
}
301297

302298
/// Returns the foreign (or native) entry point corresponding to the same
303299
/// decl.
304300
SILDeclRef asForeign(bool foreign = true) const {
305-
return SILDeclRef(loc.getOpaqueValue(), kind, uncurryLevel, isCurried,
306-
isDirectReference, foreign, defaultArgIndex);
301+
return SILDeclRef(loc.getOpaqueValue(), kind, Expansion, uncurryLevel,
302+
isCurried, isDirectReference, foreign, defaultArgIndex);
307303
}
308304

309305
SILDeclRef asDirectReference(bool direct = true) const {
@@ -321,22 +317,7 @@ struct SILDeclRef {
321317
/// True if the decl ref references a thunk from a natively Swift declaration
322318
/// to foreign C or ObjC calling convention.
323319
bool isNativeToForeignThunk() const;
324-
325-
/// Produces a SILDeclRef from an opaque value.
326-
explicit SILDeclRef(void *opaqueLoc,
327-
Kind kind,
328-
unsigned uncurryLevel,
329-
bool isCurried,
330-
bool isDirectReference,
331-
bool isForeign,
332-
unsigned defaultArgIndex)
333-
: loc(Loc::getFromOpaqueValue(opaqueLoc)),
334-
kind(kind), uncurryLevel(uncurryLevel),
335-
isCurried(isCurried),
336-
isForeign(isForeign), isDirectReference(isDirectReference),
337-
defaultArgIndex(defaultArgIndex)
338-
{}
339-
320+
340321
/// Return a SILDeclRef to the declaration overridden by this one, or
341322
/// a null SILDeclRef if there is no override.
342323
SILDeclRef getOverridden() const {
@@ -353,7 +334,25 @@ struct SILDeclRef {
353334
/// overrides. This may be different from "getOverridden" because some
354335
/// declarations do not always have vtable entries.
355336
SILDeclRef getOverriddenVTableEntry() const;
356-
337+
338+
private:
339+
friend struct llvm::DenseMapInfo<swift::SILDeclRef>;
340+
/// Produces a SILDeclRef from an opaque value.
341+
explicit SILDeclRef(void *opaqueLoc,
342+
Kind kind,
343+
unsigned rawExpansion,
344+
unsigned uncurryLevel,
345+
bool isCurried,
346+
bool isDirectReference,
347+
bool isForeign,
348+
unsigned defaultArgIndex)
349+
: loc(Loc::getFromOpaqueValue(opaqueLoc)),
350+
kind(kind), uncurryLevel(uncurryLevel), Expansion(rawExpansion),
351+
isCurried(isCurried),
352+
isForeign(isForeign), isDirectReference(isDirectReference),
353+
defaultArgIndex(defaultArgIndex)
354+
{}
355+
357356
};
358357

359358
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, SILDeclRef C) {
@@ -370,16 +369,17 @@ template<> struct DenseMapInfo<swift::SILDeclRef> {
370369
using SILDeclRef = swift::SILDeclRef;
371370
using Kind = SILDeclRef::Kind;
372371
using Loc = SILDeclRef::Loc;
372+
using ResilienceExpansion = swift::ResilienceExpansion;
373373
using PointerInfo = DenseMapInfo<void*>;
374374
using UnsignedInfo = DenseMapInfo<unsigned>;
375375

376376
static SILDeclRef getEmptyKey() {
377-
return SILDeclRef(PointerInfo::getEmptyKey(), Kind::Func, 0,
378-
false, false, false, 0);
377+
return SILDeclRef(PointerInfo::getEmptyKey(), Kind::Func,
378+
0, 0, false, false, false, 0);
379379
}
380380
static SILDeclRef getTombstoneKey() {
381-
return SILDeclRef(PointerInfo::getTombstoneKey(), Kind::Func, 0,
382-
false, false, false, 0);
381+
return SILDeclRef(PointerInfo::getTombstoneKey(), Kind::Func,
382+
0, 0, false, false, false, 0);
383383
}
384384
static unsigned getHashValue(swift::SILDeclRef Val) {
385385
unsigned h1 = PointerInfo::getHashValue(Val.loc.getOpaqueValue());

0 commit comments

Comments
 (0)