Commit Graph

9509 Commits

Author SHA1 Message Date
Karoy Lorentey 154c5598a5 Clarify rationale for using a per-capacity hash seed 2018-03-15 16:29:23 +00: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
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
Sho Ikeda a3f9a4c408 Fix a comment in MachError.swift 2018-03-14 13:57:00 +09: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
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
Paul Hudson 45b25b9b85 [Gardening] Changed lowercaseString to lowercased() in comments. 2018-03-13 09:55:33 -05:00
Slava Pestov 7415d35f3a Merge pull request #15194 from slavapestov/enable-resilience-again
Enable resilience again
2018-03-12 21:54:14 -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
swift-ci f764e685c2 Merge pull request #15177 from darquro/excise-iostream-from-metadata 2018-03-12 09:39:11 -07:00
Doug Gregor dd794f656e Merge pull request #15149 from ikesyo/remove-unnecessary-let
[gardening][SwiftOnoneSupport] Replace `let _` with `_`
2018-03-12 09:25:59 -07:00
Doug Gregor cc48aa41e4 Merge pull request #15151 from ikesyo/stdlib-public-operator-static-func
[SE-0091][gardening][stdlib/public] Move operators into types
2018-03-12 09:25:02 -07:00
Joe Groff 3fd2d2165e Merge pull request #15145 from jckarter/trimming-metadata
Trimming metadata
2018-03-12 06:55:59 -07:00
darquro 71e27406dd [stdlib] Excise #include <iostream> from Metadata.cpp. (SR-7164) 2018-03-12 20:29:27 +09:00
Sho Ikeda a08fef219e [gardening] Change static public to public static for consistency 2018-03-11 18:06:01 +09:00
Sho Ikeda 1fbc03005e [gardening][stdlib/public] Move operators into types 2018-03-11 12:14:56 +09:00
Sho Ikeda 077aa52cc5 [gardening][SwiftOnoneSupport] Replace let _ with _ 2018-03-11 11:20:39 +09:00
Michael Gottesman 763bbf971e Merge pull request #15114 from gottesmm/pr-ad4fc16a11b85ee79426be965870d165e866a298
[+0-all-args] Swift expects the returned object from bridgeErrorToNSE…
2018-03-10 10:19:25 -08:00
Joe Groff 98ee6a5d7d Runtime: Prefab metadata records for Any and AnyObject.
Metadata for these types gets demanded fairly frequently, and it's a decent code size savings not having to emit a runtime call to access them.
2018-03-10 10:15:42 -08:00
Joe Groff 57d6772d48 Runtime: Use type context descriptors to unique foreign metadata.
Now that every foreign type has a type context descriptor, we can use that for a uniquing key instead of a dedicated mangled string, saving some code size especially in code that makes heavy use of imported types. rdar://problem/37537241
2018-03-10 10:15:38 -08:00
Arnold Schwaighofer f01d84c4b9 Merge pull request #15132 from aschwaighofer/fix_linux_link_issue_attempt
Speculative fix for linux bot linker failure
2018-03-10 09:03:57 -08:00
swift-ci ca3acfd2b7 Merge pull request #15039 from gottesmm/pr-8840a7d3dda61ba61ad551cc6cece87b78fece99 2018-03-10 03:26:46 -08:00
Michael Gottesman eaafe33108 Merge pull request #15139 from gottesmm/pr-400a9ca07f4710ed248281e364eb49e11835d7de
Runtime: Do the bare minimum balancing for bridge casting at +0.
2018-03-10 02:53:54 -08:00
Joe Groff 0d7c42ce66 Runtime: Do the bare minimum balancing for bridge casting at +0.
The logic here is causing leaks in some situations, and it's likely we'll want
bridging calls to go back to +1 again anyway, so do the minimum adaptation to
the +0 convention for now.

rdar://34222540
2018-03-10 02:17:24 -08:00
Joe Groff 7f9e322d98 [+0-all-args] Knock out some inappropriate "unreachable"s in the runtime.
Future Swifts may add new metadata kinds, so it isn't appropriate to crash when
we see one. In the case of reflection, we can fall back to opaque behavior.

rdar://34222540
2018-03-09 22:44:04 -08:00
Arnold Schwaighofer e106161d8f Speculative fix for linux bot linker failure 2018-03-09 17:55:39 -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
Michael Gottesman bb8a273386 [+0-all-args] Swift expects the returned object from bridgeErrorToNSError to be at +1 even if the bridge is a no-op.
rdar://34222540
2018-03-09 10:53:08 -08:00
John McCall 9313aa04a1 Merge pull request #15071 from rjmccall/metadata-cache-entries
Rewrite MetadataCache to be a more natural extension of ConcurrentMap
2018-03-09 12:44:37 -05: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
Arnold Schwaighofer 1e4f55de8d Merge pull request #15046 from aschwaighofer/without_actually_escaping_verification
Implement withoutActuallyEscaping verification
2018-03-09 09:34:06 -08: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