Commit Graph

5263 Commits

Author SHA1 Message Date
Michael Ilseman
4e573f47f8 [stdlib] Split StringProtocol out from String.swift; NFC 2018-03-13 15:34:35 -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
swift-ci
3359f02d97 Merge remote-tracking branch 'origin/master' into master-next 2018-03-13 15:11:29 -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
swift-ci
2ad44b2f35 Merge remote-tracking branch 'origin/master' into master-next 2018-03-13 12:49:01 -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
879e4f9ce5 [runtime][stdlib] Better support for random hash seeds
- Hash seed randomization can now be disabled by defining the SWIFT_DETERMINISTIC_HASHING environment value with a value of "1".
- The random hash seed is now generated using arc4random, where available. On platforms where it isn't, don't construct std::random_device twice.
- _Hasher._secretKey is renamed _Hashing._seed, with no setter.
- _Hasher._isDeterministic is a new property exposing whether we're running with non-random hashes. (Set/Dictionary will need this information to decide if they're allowed to use per-instance seeding.)
2018-03-13 16:15:09 +00:00
swift-ci
4db36b61f0 Merge remote-tracking branch 'origin/master' into master-next 2018-03-13 08:09:31 -07:00
Paul Hudson
45b25b9b85 [Gardening] Changed lowercaseString to lowercased() in comments. 2018-03-13 09:55:33 -05:00
swift-ci
bb20a3fdbb Merge remote-tracking branch 'origin/master' into master-next 2018-03-12 22:09:53 -07:00
Slava Pestov
7415d35f3a Merge pull request #15194 from slavapestov/enable-resilience-again
Enable resilience again
2018-03-12 21:54:14 -07:00
swift-ci
5c9270210b Merge remote-tracking branch 'origin/master' into master-next 2018-03-12 17:49:53 -07:00
Ben Cohen
f9b3e14137 [stdlib] Use Swift-native Character iteration for hasPrefix/Suffix (#14390)
* Use Swift-native Character iteration for hasPrefix/Suffix

* Remove old tests for removed C shims
2018-03-12 17:41:55 -07:00
Slava Pestov
0223daec0f stdlib: ClosedRange.Index should be fixed-layout 2018-03-12 15:22:47 -07:00
Sho Ikeda
415ee8d703 [gardening] Change static internal to internal static for consistency
Before the changes:

- `git grep "internal static " | wc -l`: 161
- `git grep "static internal " | wc -l`: 10
2018-03-13 02:29:56 +09:00
swift-ci
ced131dec8 Merge remote-tracking branch 'origin/master' into master-next 2018-03-11 15:09:00 -07:00
Sho Ikeda
a08fef219e [gardening] Change static public to public static for consistency 2018-03-11 18:06:01 +09:00
bruno-rocha-movile
3b074205ad [stdlib] Revert overflow operators implementation change and improve their documentation 2018-03-10 17:25:16 -03:00
bruno-rocha-movile
9750689210 [stdlib][SR-4818] Add overflow assignment operators 2018-03-10 13:55:45 -03:00
swift-ci
8e0cd417eb Merge remote-tracking branch 'origin/master' into master-next 2018-03-09 12:09:24 -08:00
Karoy Lorentey
ab0c74b85c Merge pull request #14913 from lorentey/resilient-hashing
Switch to a resilient hashing interface, currently implementing SipHash-1-3.
Compiler-synthesized Hashable conformances still use the old _combineHashValues interface for now.
2018-03-09 19:57:03 +00:00
swift-ci
ecd7a48bb2 Merge remote-tracking branch 'origin/master' into master-next 2018-03-09 09:49:07 -08:00
Robert Widmann
72e4224dc9 Merge pull request #13655 from CodaFi/ace-attorney
[SE-0194] Implement deriving collections of enum cases
2018-03-09 12:43:13 -05:00
Karoy Lorentey
8cf5bc8bdc [stdlib] Switch to using SipHash-1-3 as the standard hash function
Beyond switching hashing algorithms, this also enables per-execution hash seeds, fulfilling a long-standing prophecy in Hashable’s documentation.

To reduce the possibility of random test failures, StdlibUnittest’s TestSuite overrides the random hash seed on initialization.

rdar://problem/24109692
rdar://problem/35052153
2018-03-09 14:48:59 +00:00
Karoy Lorentey
f8ce96273e [stdlib] Implement _hash(into:) for standard Hashable types. 2018-03-09 14:35:22 +00:00
Karoy Lorentey
42cab58554 [stdlib] Dictionary, Set: Use resilient hashing
This switches the primary hashing interface from hashValue to _hash(into:).
2018-03-09 14:35:19 +00:00
Karoy Lorentey
54b857ed0b [stdlib] Hashable: Add support for resilient hashing
Introduce _Hasher, representing an opaque hash compression function.

Add the method _hash(into:) as a Hashable requirement, decoupling the choice of hash function from Hashable's implementation. The default implementation of _hash(into:) has a default implementation that simply feeds hashValue to the hasher.

Add _hash(into:) implementations for the default integer types. Note that Int.hashValue does not return self anymore.

Add struct _LegacyHasher, emulating Swift 4.1 hashes in the new interface.
2018-03-09 14:34:57 +00:00
swift-ci
3c9d3877f7 Merge remote-tracking branch 'origin/master' into master-next 2018-03-09 03:29:18 -08:00
Robert Widmann
dac06898e9 [SE-0194] Deriving Collections of Enum Cases
Implements the minimum specified by the SE-proposal.

* Add the CaseIterable protocol with AllCases associatedtype and
allCases requirement
* Automatic synthesis occurs for "simple" enums
    - Caveat: Availability attributes suppress synthesis.  This can be
              lifted in the future
    - Caveat: Conformance must be stated on the original type
              declaration (just like synthesizing Equatable/Hashable)
    - Caveat: Synthesis generates an [T].  A more efficient collection
              - possibly even a lazy one - should be put here.
2018-03-09 00:22:55 -05:00
Sho Ikeda
e5223e4826 [stdlib/public][gardening] Prefer os(macOS) over os(OSX) 2018-03-09 09:10:35 +09:00
swift-ci
5b5a0ba466 Merge remote-tracking branch 'origin/master' into master-next 2018-03-08 05:49:22 -08:00
swift-ci
9bda1e5c55 Merge pull request #13340 from glessard/umbp-failearlyrangecheck 2018-03-08 05:38:39 -08:00
swift-ci
e5fdf1b121 Merge remote-tracking branch 'origin/master' into master-next 2018-03-07 20:09:18 -08:00
Xiaodi Wu
dee3cef347 Revert "Revert "[stdlib] Add faster 32-bit and 64-bit binade, nextUp, ulp"" 2018-03-07 19:54:20 -06:00
Bob Wilson
1dce60b2a6 Merge remote-tracking branch 'origin/master' into master-next 2018-03-07 17:02:53 -08:00
Stephen Canon
f8a9e56957 Importer support for float80 (#14971)
* First pass at implementing support for mapping between long double and Float80.

* Only define CLongDouble on platforms where I know what it is.

* remove some hacks that are no longer necessary.
2018-03-07 16:49:21 -05:00
swift-ci
9218c296f6 Merge remote-tracking branch 'origin/master' into master-next 2018-03-07 13:48:50 -08:00
Mike Ash
e38ea2d60d Merge pull request #15044 from mikeash/remove-objcmirrors
[Runtime] Remove ObjCMirrors.swift
2018-03-07 16:48:30 -05:00
swift-ci
23003b41a7 Merge remote-tracking branch 'origin/master' into master-next 2018-03-07 12:49:12 -08:00