Commit Graph

27 Commits

Author SHA1 Message Date
Robert Widmann
0149ccd0ca Add arm64_32 support for Swift
Commit the platform definition and build script work necessary to
cross-compile for arm64_32.

arm64_32 is a variant of AARCH64 that supports an ILP32 architecture.
2021-04-20 14:59:04 -07:00
Max Desiatov
67297904ac [WebAssembly] Add ifdefs for the WASI target 2020-02-08 07:37:10 +00:00
Ben Cohen
e9d4687e31 De-underscore @frozen, apply it to structs (#24185)
* De-underscore @frozen for enums

* Add @frozen for structs, deprecate @_fixed_layout for them

* Switch usage from _fixed_layout to frozen
2019-05-30 17:55:37 -07:00
Ben Cohen
1673c12d78 [stdlib] Replace "sanityCheck" with "internalInvariant" (#20616)
* Replace "sanityCheck" with "internalInvariant"
2018-11-15 20:50:22 -08:00
Karoy Lorentey
43f3431d9f [stdlib] Fix 32-bit oversight 2018-11-07 14:53:22 +00:00
Karoy Lorentey
50bd37b49a [stdlib] Eliminate _HasherCore protocol 2018-11-07 13:45:56 +00:00
Karoy Lorentey
3ae170c1c1 [stdlib] Remove SipHash from ABI-visible names
Also, eliminate the (unused) SipHash24 implementation and nest most of Hasher’s internals under Hasher itself.
2018-11-01 00:45:40 +00:00
Karoy Lorentey
6d81663716 [stdlib] Make Hashable._rawHashValue(seed:) safer and more convenient
- Don’t expose the raw execution seed to _rawHashValue.
- Change the type of _rawHashValue’s seed from (UInt64,UInt64) to a single Int. Working with a pair of UInt64s is unwieldy, and overkill in practice. Int as a seed also integrates nicely with Int as a hash value.
- Remove _HasherCore._generateSeed(). Instead, simply call finalize() on a copy of the hasher to get a seed suitable for _rawHashValue.
- Update Set and Dictionary to store a single Int as the seed value.

Note that this doesn’t affect the core hasher, which still mixes in the actual 128-bit execution seed during its initialization. To reduce the potential of confusion, use the name “rawSeed” to refer to an actual 128-bit seed value.
2018-09-24 13:30:05 +01:00
Karoy Lorentey
376753e3a0 [stdlib] Hasher._Seed: Add internal typealias
This is intended to improve readability.
2018-09-22 02:04:05 +01:00
Jordan Rose
55eaa7ffcf [stdlib] Add some missing '@usableFromInline's
Caught by the rule I'm about to add in the next commit: a fixed-layout
struct must only contain public/@usableFromInline members.
2018-09-17 17:18:30 -07:00
Doug Gregor
6ffcbc5eff [Standard library] Faster formulation for the _HasherTailBuffer sanity check 2018-07-27 15:37:59 -07:00
Doug Gregor
fa9a24538f [Standard library] Ascribe types to some literals to improve typecheck time.
One expression in the new hashing implementation is going exponential,
accounting for a huge amount of type-checking type. Add (admittedly ugly)
“as UInt64” annotations to greatly reduce the time to type-check this
expression.

*Ahem* type-checking time for the standard library goes from 24s->14s with
this change. Added a type-checker “slow” performance test and captured
the problem in rdar://problem/42672946.
2018-07-27 14:10:49 -07:00
Nate Cook
2536277362 [stdlib] Various documentation improvements (#18013)
- Revise Bool.toggle() discussion and fix attribute placement
- Revise to Hasher abstracts and discussions
- Correct the name of the remainder operator
- Clean up deprecations and paste-os w/in UnsafePointer
2018-07-18 12:41:22 -05:00
Karoy Lorentey
ff91f36a9d [stdlib] Fix AnyHashable's Equatable/Hashable conformance
AnyHashable has numerous edge cases where two AnyHashable values compare equal but produce different hashes. This breaks Set and Dictionary invariants and can cause unexpected behavior and/or traps. This change overhauls AnyHashable's implementation to fix these edge cases, hopefully without introducing new issues.

- Fix transitivity of ==. Previously, comparisons involving AnyHashable values with Objective-C provenance were handled specially, breaking Equatable:

    let a = (42 as Int as AnyHashable)
    let b = (42 as NSNumber as AnyHashable)
    let c = (42 as Double as AnyHashable)
    a == b // true
    b == c // true
    a == c // was false(!), now true

    let d = ("foo" as AnyHashable)
    let e = ("foo" as NSString as AnyHashable)
    let f = ("foo" as NSString as NSAttributedStringKey as AnyHashable)
    d == e // true
    e == f // true
    d == f // was false(!), now true

- Fix Hashable conformance for numeric types boxed into AnyHashable:

    b == c // true
    b.hashValue == c.hashValue // was false(!), now true

  Fixing this required adding a custom AnyHashable box for all standard integer and floating point types. The custom box was needed to ensure that two AnyHashables containing the same number compare equal and hash the same way, no matter what their original type was. (This behavior is required to ensure consistency with NSNumber, which has not been preserving types since SE-0170.

- Add custom AnyHashable representations for Arrays, Sets and Dictionaries, so that when they contain numeric types, they hash correctly under the new rules above.

- Remove AnyHashable._usedCustomRepresentation. The provenance of a value should not affect its behavior.

- Allow AnyHashable values to be downcasted into compatible types more often.

- Forward _rawHashValue(seed:) to AnyHashable box. This fixes AnyHashable hashing for types that customize single-shot hashing.

https://bugs.swift.org/browse/SR-7496
rdar://problem/39648819
2018-06-25 20:14:01 +01:00
Erik Little
863f3a19ff Rename @effects to @_effects
@effects is too low a level, and not meant for general usage outside
the standard library. Therefore it deserves to be underscored like
other such attributes.
2018-06-06 12:53:03 -04:00
Nate Cook
7a4e0a32f6 [stdlib] Revise documentation
This includes various revisions to the APIs landing in Swift 4.2, including:
- Random and other randomness APIs
- Hashable changes
- MemoryLayout.offset(of:)
2018-05-18 11:31:54 -05:00
Karoy Lorentey
b1a64e8303 Merge pull request #16177 from lorentey/hashable-docs
[SE-0206] Update Hashable docs for hash(into:)
2018-05-02 13:19:29 +01:00
Karoy Lorentey
3a162d225a [stdlib] Hashable, Hasher: Add non-public top-level hashing interface
The new _rawHashValue(seed:) requirement allows stdlib types to specialize their hashing when they’re hashed on their own (i.e., not as a component of some composite type).

This makes it possible to get rid of discriminator/terminator values and to eliminate most of Hasher’s resiliency overhead, leading to a measurable speedup, especially for tiny keys.
2018-04-30 15:16:47 +01:00
Karoy Lorentey
5d259cf082 [SE-0206] Update Hashable docs for hash(into:)
Also, repeat warning about hash values not being stable in the docs of Hasher.finalize().
2018-04-26 16:38:03 +01:00
Karoy Lorentey
0fb3e88110 [SE-0206][stdlib] De-underscore Hashable.hash(into:) 2018-04-24 17:42:42 +01:00
Karoy Lorentey
08d8804da9 [SE-0206][stdlib] Clarify Hasher.finalize() documentation 2018-04-24 17:42:42 +01:00
Karoy Lorentey
97ec2967e0 [SE-0206][stdlib] Hasher, SipHash: Make non-public declarations internal
Newly internal declarations include Hasher._seed and the integer overloads of Hasher._combine(_:), as well as _SipHash13 and _SipHash24.

Unify the interfaces of these SipHash testing structs with Hasher. Update SipHash test to cover Hasher, too.

Add @usableFromInline to all newly internal stuff. In addition to its normal use, it also enables white box testing; compile tests that need to use these declarations with -disable-access-control.
2018-04-24 17:42:42 +01:00
Karoy Lorentey
87685aaef9 [SE-0206][stdlib] Make Hasher.finalize() nonmutating but __consuming
As noted in the proposal’s revision, this allows us to get rid of finalization checks, improves API robustness, and paves the way for making Hasher move-only in the future.
2018-04-24 17:42:42 +01:00
Karoy Lorentey
de66338475 [SE-0206][stdlib] Document Hasher 2018-04-24 17:42:42 +01:00
Karoy Lorentey
45cb8b7123 [SE-0206][stdlib] De-underscore Hasher 2018-04-24 17:42:42 +01:00
Karoy Lorentey
ebf290a598 [stdlib] Optimize ASCII String hashing
- String hashing is not inlinable, so it can use _Hasher._core operations directly. Remove custom buffering.
- Speed up ASCII hashing by as much as 5.5x by feeding the storage buffer directly into hasher in a single go.
- For other strings, just feed the UTF-8 encoding of the normalized string to the hasher; don't switch to UTF-16 at the first non-ASCII scalar. (Doing that would make the hash encoding of some string sequences ambiguous, leading to artificial collisions.)
- Add a single unconditional terminator byte, 0xFF. It's not a valid UTF-8 code unit, so it won't ever occur within a normalized string encoding.
2018-04-19 11:49:51 +01:00
Karoy Lorentey
7e66a38af8 [stdlib] De-gyb SipHash; implement full Hasher API 2018-04-18 17:33:24 +01:00