Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ea1f273
[stdlib] Add alternative, streaming interface for hashing
lorentey Oct 18, 2017
6a0e200
[stdlib] Simplify SipHash13 and SipHash24 implementations
lorentey Oct 18, 2017
1d29dd9
[stdlib] Implement _hash(into:) in standard Hashable types.
lorentey Oct 18, 2017
f3c8ee9
[stdlib] Update Dictionary and Set to use hash(into:) rather than has…
lorentey Oct 18, 2017
c3be208
[WIP][SQUASH ME] Preparations for synthesizing Hashable with hashers
lorentey Oct 19, 2017
c433efd
[experiment] func _hash(into hasher: _Hasher) -> _Hasher
lorentey Feb 9, 2018
da02fe3
Add missing @_inlineable on default _hash(into:) implementation
lorentey Feb 9, 2018
da8063f
[stdlib] Switch to a faux-pure hasher interface
lorentey Feb 12, 2018
4ae8858
[benchmark] Update DictTest4 benchmark for new _hash(into:) variant
lorentey Feb 13, 2018
44b5da8
_UnsafeHasher.finalized(): Add @effects(readonly)
lorentey Feb 14, 2018
f0aca43
_defaultHashValue(for:) => _hashValue(for:)
lorentey Feb 16, 2018
543ee0c
Hide _Hasher entirely behind resilient function boundaries
lorentey Feb 16, 2018
fd9d7e1
Add _hash(into:) implementations for types conditionally conforming t…
lorentey Feb 15, 2018
2180c4b
Make _hashValue(for:) public.
lorentey Feb 16, 2018
0d3204d
Remove _hashValue(with:)
lorentey Feb 16, 2018
2785942
Add @effects(readonly) to non-inlineable version of _hashValue(for:).
lorentey Feb 16, 2018
157d2f1
First draft of synthesized Hashable conformance with _hash(into:)
lorentey Feb 16, 2018
7721e3b
Synthesize _hash(into:) instead of providing a default implementation.
lorentey Feb 19, 2018
8391e70
Cover all special cases of implicit Hashable conformance.
lorentey Feb 22, 2018
7b853e3
[benchmark] DictTest4: Remove obsolete _hash(into:) definition
lorentey Feb 16, 2018
d0228df
Review SipHash implementation and switch to SipHash13
lorentey Feb 23, 2018
275c0bd
Merge branch 'master' of https://github.com/apple/swift into smashing…
lorentey Feb 23, 2018
0940688
Merge branch 'master' into smashing-hashing
lorentey Feb 26, 2018
caa2cc7
FlattenCollection.Index.hashValue: Delegate to _hash(into:).
lorentey Feb 27, 2018
801004b
[stdlib] Move _UnsafeHasher and its posse to Hashing.swift.
lorentey Feb 27, 2018
c5a63c9
[stdlib] Update tests that assumed specific hash values or Dictionary…
lorentey Feb 27, 2018
b76ff8c
Update tests looking at Hashable members
lorentey Feb 27, 2018
729e587
[Foundation] _CFObject: Add _hash(into:) implementation.
lorentey Feb 27, 2018
c92a605
Remove test for _squeezeHashValue.
lorentey Feb 27, 2018
3da030e
Revert to having a default implementation of _hash(into:)
lorentey Feb 27, 2018
b013a52
Update tests looking at code completions in Hashable types.
lorentey Feb 27, 2018
9dbb3c9
StdlibUnittest: zero out the hash key in TestSuite.init.
lorentey Feb 27, 2018
9f08836
[DELETE] Temporarily disable SipHash tests.
lorentey Feb 27, 2018
908318c
[stdlib] SipHash: Fix 32-bit platform support
lorentey Feb 27, 2018
97435f4
Merge branch 'master' into smashing-hashing
lorentey Feb 28, 2018
fd590e4
[AST] Remove _combineHashValues and _mixInt from ASTContext
lorentey Feb 28, 2018
24856cf
[SQUASH] Fix typo
lorentey Feb 28, 2018
e14aba0
[stdlib] KeyPathComponent: Switch to new-style hashing
lorentey Feb 28, 2018
2170afc
[stdlib] Hash integers <= 32 bits as UInt32
lorentey Feb 28, 2018
35c9aa4
[stdlib] SipHash: Revive ability to hash byte sequences of arbitrary …
lorentey Feb 28, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ class ASTContext {
ProtocolDecl *getErrorDecl() const;
CanType getExceptionType() const;

#define KNOWN_STDLIB_TYPE_DECL(NAME, DECL_CLASS, NUM_GENERIC_PARAMS) \
/** Retrieve the declaration of Swift.NAME. */ \
#define KNOWN_STDLIB_TYPE_DECL_WITH_NAME(NAME, IDSTR, DECL_CLASS, NUM_GENERIC_PARAMS) \
/** Retrieve the declaration of Swift.IDSTR. */ \
DECL_CLASS *get##NAME##Decl() const;
#include "swift/AST/KnownStdlibTypes.def"

Expand Down Expand Up @@ -471,12 +471,8 @@ class ASTContext {
/// Retrieve the declaration of Swift.==(Int, Int) -> Bool.
FuncDecl *getEqualIntDecl() const;

/// Retrieve the declaration of
/// Swift._combineHashValues(Int, Int) -> Int.
FuncDecl *getCombineHashValuesDecl() const;

/// Retrieve the declaration of Swift._mixInt(Int) -> Int.
FuncDecl *getMixIntDecl() const;
/// Retrieve the declaration of Swift._hashValue<H>(for: H) -> Int.
FuncDecl *getHashValueForDecl() const;

/// Retrieve the declaration of Array.append(element:)
FuncDecl *getArrayAppendElementDecl() const;
Expand Down
5 changes: 5 additions & 0 deletions include/swift/AST/KnownIdentifiers.def
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ IDENTIFIER(alloc)
IDENTIFIER(allocWithZone)
IDENTIFIER(allZeros)
IDENTIFIER(Any)
IDENTIFIER(appending)
IDENTIFIER(ArrayLiteralElement)
IDENTIFIER(atIndexedSubscript)
IDENTIFIER_(bridgeToObjectiveC)
Expand Down Expand Up @@ -54,14 +55,18 @@ IDENTIFIER(encoder)
IDENTIFIER(error)
IDENTIFIER(forKeyedSubscript)
IDENTIFIER(Foundation)
IDENTIFIER(for)
IDENTIFIER(forKey)
IDENTIFIER(from)
IDENTIFIER(fromRaw)
IDENTIFIER_(hash)
IDENTIFIER(hasher)
IDENTIFIER(hashValue)
IDENTIFIER(init)
IDENTIFIER(initialize)
IDENTIFIER(initStorage)
IDENTIFIER(initialValue)
IDENTIFIER(into)
IDENTIFIER(intValue)
IDENTIFIER(Key)
IDENTIFIER(KeyedDecodingContainer)
Expand Down
11 changes: 8 additions & 3 deletions include/swift/AST/KnownStdlibTypes.def
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@
//
//===----------------------------------------------------------------------===//

#ifndef KNOWN_STDLIB_TYPE_DECL
/// KNOWN_STDLIB_TYPE_DECL(NAME, DECL_CLASS, NUM_GENERIC_PARAMS)
#ifndef KNOWN_STDLIB_TYPE_DECL_WITH_NAME
/// KNOWN_STDLIB_TYPE_DECL_WITH_NAME(NAME, IDSTR, DECL_CLASS, NUM_GENERIC_PARAMS)
///
/// The macro is expanded for each known standard library type. NAME is
/// bound to the unqualified name of the type. DECL_CLASS is bound to the
/// Decl subclass it is expected to be an instance of. NUM_GENERIC_PARAMS is
/// bound to the number of generic parameters the type is expected to have.
#define KNOWN_STDLIB_TYPE_DECL(NAME, DECL_CLASS, NUM_GENERIC_PARAMS)
#define KNOWN_STDLIB_TYPE_DECL_WITH_NAME(NAME, IDSTR, DECL_CLASS, NUM_GENERIC_PARAMS)
#endif

#define KNOWN_STDLIB_TYPE_DECL(NAME, DECL_CLASS, NUM_GENERIC_PARAMS) \
KNOWN_STDLIB_TYPE_DECL_WITH_NAME(NAME, #NAME, DECL_CLASS, NUM_GENERIC_PARAMS)

KNOWN_STDLIB_TYPE_DECL(Bool, NominalTypeDecl, 0)

KNOWN_STDLIB_TYPE_DECL(Int, NominalTypeDecl, 0)
Expand All @@ -50,6 +53,7 @@ KNOWN_STDLIB_TYPE_DECL(Sequence, NominalTypeDecl, 1)
KNOWN_STDLIB_TYPE_DECL(Dictionary, NominalTypeDecl, 2)
KNOWN_STDLIB_TYPE_DECL(AnyHashable, NominalTypeDecl, 0)
KNOWN_STDLIB_TYPE_DECL(MutableCollection, ProtocolDecl, 1)
KNOWN_STDLIB_TYPE_DECL_WITH_NAME(UnsafeHasher, "_UnsafeHasher", NominalTypeDecl, 0)

KNOWN_STDLIB_TYPE_DECL(AnyKeyPath, NominalTypeDecl, 0)
KNOWN_STDLIB_TYPE_DECL(PartialKeyPath, NominalTypeDecl, 1)
Expand Down Expand Up @@ -79,3 +83,4 @@ KNOWN_STDLIB_TYPE_DECL(KeyedDecodingContainer, NominalTypeDecl, 1)
KNOWN_STDLIB_TYPE_DECL(RangeReplaceableCollection, ProtocolDecl, 1)

#undef KNOWN_STDLIB_TYPE_DECL
#undef KNOWN_STDLIB_TYPE_DECL_WITH_NAME
72 changes: 27 additions & 45 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ struct ASTContext::Implementation {
/// The AnyObject type.
CanType AnyObjectType;

#define KNOWN_STDLIB_TYPE_DECL(NAME, DECL_CLASS, NUM_GENERIC_PARAMS) \
#define KNOWN_STDLIB_TYPE_DECL_WITH_NAME(NAME, IDSTR, DECL_CLASS, NUM_GENERIC_PARAMS) \
/** The declaration of Swift.NAME. */ \
DECL_CLASS *NAME##Decl = nullptr;
#include "swift/AST/KnownStdlibTypes.def"
Expand Down Expand Up @@ -189,12 +189,9 @@ FOR_KNOWN_FOUNDATION_TYPES(CACHE_FOUNDATION_DECL)
/// func ==(Int, Int) -> Bool
FuncDecl *EqualIntDecl = nullptr;

/// func _combineHashValues(Int, Int) -> Int
FuncDecl *CombineHashValuesDecl = nullptr;
/// func _hashValue<H: Hashable>(for: H) -> Int
FuncDecl *HashValueForDecl = nullptr;

/// func _mixInt(Int) -> Int
FuncDecl *MixIntDecl = nullptr;

/// func append(Element) -> void
FuncDecl *ArrayAppendElementDecl = nullptr;

Expand Down Expand Up @@ -616,11 +613,11 @@ FuncDecl *ASTContext::getPlusFunctionOnString() const {
return Impl.PlusFunctionOnString;
}

#define KNOWN_STDLIB_TYPE_DECL(NAME, DECL_CLASS, NUM_GENERIC_PARAMS) \
#define KNOWN_STDLIB_TYPE_DECL_WITH_NAME(NAME, IDSTR, DECL_CLASS, NUM_GENERIC_PARAMS) \
DECL_CLASS *ASTContext::get##NAME##Decl() const { \
if (!Impl.NAME##Decl) \
Impl.NAME##Decl = dyn_cast_or_null<DECL_CLASS>( \
findStdlibType(*this, #NAME, NUM_GENERIC_PARAMS)); \
findStdlibType(*this, IDSTR, NUM_GENERIC_PARAMS)); \
return Impl.NAME##Decl; \
}
#include "swift/AST/KnownStdlibTypes.def"
Expand Down Expand Up @@ -989,44 +986,29 @@ FuncDecl *ASTContext::getGetBoolDecl(LazyResolver *resolver) const {
return decl;
}

FuncDecl *ASTContext::getCombineHashValuesDecl() const {
if (Impl.CombineHashValuesDecl)
return Impl.CombineHashValuesDecl;

auto resolver = getLazyResolver();
auto intType = getIntDecl()->getDeclaredType();

auto callback = [&](Type inputType, Type resultType) {
// Look for the signature (Int, Int) -> Int
auto tupleType = dyn_cast<TupleType>(inputType.getPointer());
assert(tupleType);
return tupleType->getNumElements() == 2 &&
tupleType->getElementType(0)->isEqual(intType) &&
tupleType->getElementType(1)->isEqual(intType) &&
resultType->isEqual(intType);
};

auto decl = lookupLibraryIntrinsicFunc(
*this, "_combineHashValues", resolver, callback);
Impl.CombineHashValuesDecl = decl;
return decl;
}

FuncDecl *ASTContext::getMixIntDecl() const {
if (Impl.MixIntDecl)
return Impl.MixIntDecl;
FuncDecl *ASTContext::getHashValueForDecl() const {
if (Impl.HashValueForDecl)
return Impl.HashValueForDecl;

auto resolver = getLazyResolver();
auto intType = getIntDecl()->getDeclaredType();

auto callback = [&](Type inputType, Type resultType) {
// Look for the signature (Int) -> Int
return inputType->isEqual(intType) && resultType->isEqual(intType);
};

auto decl = lookupLibraryIntrinsicFunc(*this, "_mixInt", resolver, callback);
Impl.MixIntDecl = decl;
return decl;
SmallVector<ValueDecl *, 1> results;
lookupInSwiftModule("_hashValue", results);
for (auto result : results) {
auto *fd = dyn_cast<FuncDecl>(result);
if (!fd)
continue;
auto paramLists = fd->getParameterLists();
if (paramLists.size() != 1 || paramLists[0]->size() != 1)
continue;
auto paramDecl = paramLists[0]->get(0);
if (paramDecl->getArgumentName() != Id_for)
continue;
auto genericParams = fd->getGenericParams();
if (!genericParams || genericParams->size() != 1)
continue;
Impl.HashValueForDecl = fd;
return fd;
}
return nullptr;
}

FuncDecl *ASTContext::getArrayAppendElementDecl() const {
Expand Down
4 changes: 2 additions & 2 deletions lib/SILGen/SILGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3584,8 +3584,8 @@ getOrCreateKeyPathEqualsAndHash(SILGenFunction &SGF,

SILValue hashCode;

// TODO: Combine hashes of the indexes. There isn't a great hash combining
// interface in the standard library to do this yet.
// TODO: Combine hashes of the indexes using an _UnsafeHasher passed in as
// an extra parameter.
{
auto &index = indexes[0];

Expand Down
Loading