Commit Graph

9748 Commits

Author SHA1 Message Date
Lance Parker
cbf157f924 [stdlib]Unify String hashing implementation (#14921)
* Add partial range subscripts to _UnmanagedOpaqueString

* Use SipHash13+_NormalizedCodeUnitIterator for String hashes on all platforms

* Remove unecessary collation algorithm shims

* Pass the buffer to the SipHasher for ASCII

* Hash the ascii parts of UTF16 strings the same way we hash pure ascii strings

* De-dupe some code that can be shared between _UnmanagedOpaqueString and _UnmanagedString<UInt16>

* ASCII strings now hash consistently for in hashASCII() and hashUTF16()

* Fix zalgo comparison regression

* Use hasher

* Fix crash when appending to an empty _FixedArray

* Compact ASCII characters into a single UInt64 for hashing

* String: Switch to _hash(into:)-based hashing

This should speed up String hashing quite a bit, as doing it through hashValue involves two rounds of SipHash nested in each other.

* Remove obsolete workaround for ARC traffic

* Ditch _FixedArray<UInt8> in favor of _UIntBuffer<UInt64, UInt8>

* Bad rebase remnants

* Fix failing benchmarks

* michael's feedback

* clarify the comment about nul-terminated string hashes
2018-03-17 22:13:37 -07:00
swift-ci
6a9e1f2b3e Merge pull request #15305 from rjmccall/metadata-cycle-caching 2018-03-17 10:41:11 -07:00
Sho Ikeda
ba3a62b725 [gardening][Data] Prefer !isEmpty over count > 0 2018-03-18 00:58:57 +09:00
John McCall
1d4fc1933b Let the runtime copy generic arguments into place. 2018-03-17 11:40:31 -04:00
John McCall
aa0658decf Allow value witness tables to advertise themselves as incomplete
and use that when evaluating how complete an incomplete metadata is.
2018-03-17 11:40:30 -04:00
John McCall
3d5d643b9e Substantially simplify the synchronization scheme for metadata caches.
I was trying to make the entry-delegation thing do *way* too much.
Just give the entry access to the lock/queue and introduce subclasses
which simplify most of the work.

Also, fix some bad reasoning around the attempts to avoid acquiring
locks in the absence of waiters.  It really is always necessary to
acquire the lock when notifying; waiters cannot atomically set the
has-waiters flag and wait, so we have to protect against the
possibility that we notify before they can wait.
2018-03-17 11:40:30 -04:00
John McCall
3cf9a6f91a Add the caching machinery for arbitrary metadata dependencies.
We aren't taking advantage of this yet.
2018-03-17 11:40:30 -04:00
Stephen Canon
ddf70fa199 Cleanup tgmath wrappers. (#15304)
* Cleanup tgmath wrappers.

- Remove special-case gyb logic for lgamma on Darwin; the symbols we need are always present, even if not visible in the headers, so we only need a prototype.
- Add some deprecations for symbols that have direct stdlib analogues.
- Make some operations generic on [Binary]FloatingPoint, where they can map to the protocols instead of calling libm.
- Mark ldexp(Float/Double) renamed to scalbn; for binary formats these are identical functions, and we don't really want to use these names for hypothetical future Decimal support, as they're not Swifty.
2018-03-17 10:32:13 -04:00
Joe Shajrawi
4761ae7885 Merge pull request #15298 from shajrawi/fixedlayout_hasher
Temporarily add fixed layout to _Hasher
2018-03-16 17:41:18 -07:00
Kuba (Brecka) Mracek
84e71b8d7a Change the RemoteMirror API to have extensible data layout callback (#15291)
* Change the RemoteMirror API to have extensible data layout callback

* Use DLQ_Get prefix on DataLayoutQueryType enum values

* Simplify MemoryReaderImpl and synthesize minimalDataLayoutQueryFunction
2018-03-16 14:54:04 -07:00
Mike Ash
979b75699a Merge branch 'master' into remotemirror-hide-reflection-sections 2018-03-16 16:24:57 -04:00
Joe Shajrawi
b4ac6249b1 Temporarily add fixed layout to _Hasher.
This should be removed / reverted once we have resolved the performance issues.
2018-03-16 10:45:51 -07:00
Doug Gregor
eae03cb09a Merge pull request #15292 from ikesyo/dispatch-macos-over-osx
[gardening][Dispatch] Prefer macOS over OSX for `@available`
2018-03-16 10:21:49 -07:00
Chris Eidhof
86fb3faaee [wip] Bool toggle implementation (#14586)
* Bool toggle implementation

* Made it public
2018-03-16 09:17:54 -07:00
Sho Ikeda
70ab828d9f [gardening][Dispatch] Prefer macOS over OSX for @available 2018-03-16 13:30:01 +09:00
Andrew Trick
afbcbfdfa7 Merge pull request #13071 from glessard/umbp-nonmutating-swapat
nonmutating swapAt implementations for UnsafeMutable(Raw)BufferPointer
2018-03-15 16:35:47 -07:00
Jordan Rose
520d6b9b91 Make NS_TYPED_ENUMS ObjectiveCBridgeable when they wrap an object (#15270)
This allows them to be used in generic arguments for NSArray et al.
We already do this for the ones that wrap bridged values (like
NSString/String), but failed to do it for objects that /weren't/
bridged to Swift values (class instances and protocol compositions),
or for Error-which-is-special.

In addition to this being a sensible thing to do, /not/ doing this led
to IRGen getting very confused (i.e. crashing) when we imported a
Objective-C protocol that actually used an NS_TYPED_ENUM in this way.

(We actually shouldn't be using Swift's IRGen logic to emit protocol
descriptors for imported protocols at all, because it's possible we
weren't able to import all the requirements. But that's a separate
issue.)

https://bugs.swift.org/browse/SR-6844
2018-03-15 16:17:38 -07:00
Jordan Rose
0671848fa1 Merge pull request #15213 from jrose-apple/avail-yourself-of-this-patch
Allow @available(swift, ...) nested within @available(macOS, ...)

rdar://problem/32632327
2018-03-15 16:10:23 -07:00
Karoy Lorentey
8e4c2168ed Merge pull request #15236 from lorentey/seedless-hashes2
[runtime] Collapse hashing parameters into a single struct
2018-03-15 21:03:04 +00:00
Karoy Lorentey
154c5598a5 Clarify rationale for using a per-capacity hash seed 2018-03-15 16:29:23 +00:00
Jordan Rose
74a4adc54c [stdlib] Remove ignored platform-agnostic '@available' from extensions
It looks like we exposed a bunch of Metal APIs to Swift 3 that we
didn't mean to; at this point it would be a source-breaking change to
hide them. Oops.
2018-03-14 16:37:40 -07:00
Arnold Schwaighofer
69975aae93 Merge pull request #15235 from aschwaighofer/swift4_section_rename
Mark swift sections as swift4 for Swift 4.2
2018-03-14 15:32:20 -07:00
Karoy Lorentey
f783f361eb [stdlib] Set, Dictionary: Always use capacity-based seeding
Per-instance seeding would break COW, unless we stored the seed within the storage class.
2018-03-14 21:44:27 +00:00
Nate Cook
2b8ff1d354 Merge pull request #15047 from natecook1000/nc-fixes-82-2
[stdlib] Revise playground quicklook docs.
2018-03-14 16:34:17 -05:00
Karoy Lorentey
b08a5c2eb6 [stdlib] Set, Dictionary: Enable per-instance hash seeding
This is done by xoring the base address of the hash table storage to the hash seed.

In deterministic mode, we perturb the seed by the bucket count instead, so that we ordering within hashed collections remains repeatable (as long as the capacity doesn't change).

Fixes https://bugs.swift.org/browse/SR-3268
2018-03-14 17:54:30 +00:00
Karoy Lorentey
2cf0e4daa1 [runtime] Collapse hashing parameters into a single struct
Having a single initializer function lets us not set a randomized seed in deterministic mode, slightly simplifying the stdlib.

Set related stdlib properties to be always inlined.
2018-03-14 17:44:13 +00:00
Arnold Schwaighofer
0c11e1a0a3 Mark swift sections as swift4 for Swift 4.2
rdar://36363251
2018-03-14 10:27:28 -07:00
Robert Widmann
4b851b6874 Merge pull request #15182 from ikesyo/internal-static
[gardening][stdlib/public] Change `static internal` to `internal static` for consistency
2018-03-14 12:13:20 -04:00
Doug Gregor
00bc32d582 Merge pull request #15230 from ikesyo/macos-over-osx
[gardening][Overlay] Prefer macOS over OSX for `#available`
2018-03-14 08:39:37 -07:00
Arnold Schwaighofer
156a4dc880 Merge pull request #15226 from Coeur/patch-1
Hi ho, Typo!
2018-03-14 05:16:13 -07:00
Sho Ikeda
f956609312 [gardening][Overlay] Prefer macOS over OSX for #available 2018-03-14 14:06:31 +09:00
Sho Ikeda
a3f9a4c408 Fix a comment in MachError.swift 2018-03-14 13:57:00 +09:00
Antoine Cœur
3362b23f2a typo 2018-03-14 12:07:19 +08:00
Michael Ilseman
4e573f47f8 [stdlib] Split StringProtocol out from String.swift; NFC 2018-03-13 15:34:35 -07:00
Michael Ilseman
b572bfe2f4 [stubs] Add CFString*Bytes stubs, drop some dead ones.
NFC, just stubs and plumbing.
2018-03-13 15:32:20 -07:00
Michael Ilseman
8082ae4c0a [string] Restore StringStorage by-hand visit pattern.
StringStorage tried to adopt the visitor pattern, but it regressed
benchmarks too much. We'd like to come up with a mutation story
anyways, and StringStorage was sort of cheating that by being a class.

Restores perf-regressions of Join etc.
2018-03-13 15:32:20 -07:00
Michael Ilseman
6970238635 [gardening] code formatting; NFC 2018-03-13 15:32:20 -07:00
Michael Ilseman
189bc4dd91 [string] Un-break Linux due to duplicate def 2018-03-13 15:32:20 -07:00
Michael Ilseman
63ed19122b [string] Finally, un-version _asOpaque 2018-03-13 15:32:20 -07:00
Michael Ilseman
e7c418b0fa [comments] Annotate places we don't use _StringGuts visitor. NFC
Adds some comments for sections of code that doesn't adopt the
visitation pattern, or have inefficiencies discovered as part of this
work. Additionally, mutating methods generally do not use the visitor
scheme.
2018-03-13 15:32:19 -07:00
Michael Ilseman
1229af8e0f [string] Adopt _StringGuts visitor pattern.
Use the visitor pattern in most of the opaque-by-hand call
sites. Inspecting the compiler output does not show excessive and
unanticipated ARC, but there may need to be further tweaks.

One downside of the visitor pattern as written is that there's extra
shuffling around of registers for the closure CC. Hopefully this will
also be fixed soon.
2018-03-13 15:32:19 -07:00
Michael Ilseman
9ba2f4c771 [string] Introduce the StringGuts visitor
Add a visitor-like function which will inspect the bitpattern of
_StringGuts and dispatch to the appropriate mechanism. This allows us
to keep the core usage pattern in one spot, and tweak the branching
scheme as the ABI finalizes.

It also reduces the bug surface area by allowing us to maintain
resilience in the visitor, instead of by-hand at every use site. It
also prevents expression-drift, which the by-hand opaque pattern is
susceptible to.

Current implementation is very carefully written to avoid excess
ARC. Uses need to be very careful about not capturing, or else there
will be non-trivial closure contexts and performance will blow
up. Both of these aspects will hopefully be fixed soon.
2018-03-13 15:32:19 -07:00
Michael Ilseman
12fe85fad1 [string] Establish opaque branching pattern.
Stop inlining _asOpaque into user code. Inlining it bloats user code
as there's a bit-test-and-branch to a block containing the _asOpaque
call, followed up some operations to e.g. manipulate the range or
re-align the calling convention, etc., followed by a final branch to
opaque stdlib code.

Instead, branch directly into opaque stdlib code. In theory, this
means that supporting all opaque patterns can be done with minimal
bloat. On ARM, this is a single tbnz instruction.
2018-03-13 15:32:19 -07:00
Michael Ilseman
884356fc0a [string] Bifurcate StringGuts inits for large strings.
In preparation for small strings optimizations, bifurcate StringGuts's
inits to denote when the caller is choosing to skip any checks for is
small. In the majority of cases, the caller has more local information
to guide the decision.

Adds todos and comments as well:

  * TODO(SSO) denotes any task that should be done simultaneously with
    the introduction of small strings.

  * TODO(TODO: JIRA) denotes tasks that should eventually happen
    later (and will have corresponding JIRAs filed for).

  * TODO(Comparison) denotes tasks when the new string comparison
    lands.
2018-03-13 15:32:19 -07:00
Michael Ilseman
a6e79efbbe [string] Minor simplifications 2018-03-13 15:32:19 -07:00
Michael Ilseman
444796a66b [gardening] Strip trailing whitespace; NFC 2018-03-13 15:32:19 -07:00
Slava Pestov
aa4ca22b1b stdlib: Add FIXME(resilience) to @_fixed_layout declarations not added by stdlib team 2018-03-13 13:23:14 -07:00
Slava Pestov
9aae3b7b1c stdlib: Declare _UnmanagedOpaqueString.UnicodeScalarIterator fixed layout 2018-03-13 13:22:28 -07:00
Karoy Lorentey
b0108336f7 Merge pull request #15207 from lorentey/seedless-hashes
[runtime] Add better control over the random hashing seed
2018-03-13 19:46:51 +00:00
Karoy Lorentey
3e90284883 [test] Disable hash randomization using environment variables
The hash seed is not settable at runtime anymore; update lit config to set the SWIFT_DETERMINISTIC_HASHING environment variable instead.
2018-03-13 16:15:09 +00:00