Commit Graph

1397 Commits

Author SHA1 Message Date
Dave Abrahams
386146364b [stdlib] Refactor String.UTF8Index for conversion
The old design did not strictly keep track of the index in underlying
UTF16, which would have made converting between the different index
types too difficult.  It also made equality comparison between indices
broken, because

  UTF8Index(s.utf16.startIndex+1, within: s.utf8)

and

  UTF8Index(s.utf16.startIndex, within: s.utf8).successor()

would often have completely different UTF8 buffers and offsets within
the underlying UTF16.

For some reason this disturbed SILPasses/devirt_default_case.swift,
which is now XFAIL'd.  <rdar://problem/19298212>
SILPasses/devirt_default_case.swift is XFAIL'd

Swift SVN r24012
2014-12-18 20:47:37 +00:00
Dave Abrahams
3c9c3fa457 [stdlib] conversions to String.UTF8Index
Swift SVN r24011
2014-12-18 20:47:35 +00:00
Dave Abrahams
27983cf144 [stdlib] typealiases for String Indexes
Just a convenience

Swift SVN r24010
2014-12-18 20:47:34 +00:00
Dave Abrahams
e85a03663f [stdlib] String.UTF16View.Index speedups
Even though it doesn't conform to RandomAccessIndexType without
Foundation loaded, we can implement these internal operations to happen
in O(1), which, e.g., should speed up count(s.utf16) among others.

Swift SVN r24009
2014-12-18 20:47:33 +00:00
Andrew Trick
c2f3622ac3 Revert "Mark _copyCollectionToNativeArrayBuffer readonly."
This reverts commit 71eb477aa6d9354cbad7baebae4283936bb1831a.

Per Erik's review.
The correct fix is interprocedural analysis that has visibility
into specialized functions. Let's just wait for that.

Swift SVN r24007
2014-12-18 18:22:01 +00:00
Dmitri Hrybenko
555e0d2d2b stdlib/Hashing: add a comment explaining why the variable is defined in
C++ code

Swift SVN r23999
2014-12-18 00:24:54 +00:00
Maxwell Swadling
c2aa030c29 [stdlib] Specialized String's Generator
Specializing String's Generator yields a significant performance
improvement.

Swift SVN r23998
2014-12-18 00:12:32 +00:00
Maxwell Swadling
7cc8dfd59d [stdlib] made IndexingGenerator._elements a let
The elements of a collection can never be mutated by the Generator.

Swift SVN r23997
2014-12-18 00:12:30 +00:00
Dmitri Hrybenko
9177107940 stdlib/Hashing: move the hash seed variable to C++ code to avoid
dispatch_once calls on every load from it

Performance improvements, as reported by the perf testing buildbot:

Histogram       -18.81%
TwoSum          -17.42%
RGBHistogram    -9.65%

Regressions:

InsertionSort                5.59%
ArrayOfRef                   3.99%
SwiftStructuresInsertionSort 5.29%
PrimeNum                     6.09%

These regressions are bogus.  The tests that "regressed" don't do any
hashing at all.

Swift SVN r23995
2014-12-17 23:45:29 +00:00
Dmitri Hrybenko
e5c3b534fe stdlib/HashedCollections: don't save the NativeStorage in a local
variable

We were avoiding recomputing it because it used to be a slow operation.

Performance improvements, as reported by the perf testing buildbot:

Histogram                 -14.07%
StringUtilsUnderscoreCase -10.22%
Dictionary                -10.75%
LevenshteinDistance       -18.08%

Regressions:

* ArraySubscript 8.56%
  This is just bogus.  That test does not do any hashing.

* NSDictionaryCastToSwift 6.86%
  This test does not do any hashing.  It operates only on empty
  dictionaries.  I believe this is noise.

Swift SVN r23991
2014-12-17 22:17:59 +00:00
Dave Abrahams
ada079bb4d [stdlib] UTF16View: unavailable subscript with Int
There had been some discussion of making this available iff Foundation
is loaded, but it turns out that there are almost no Foundation APIs
that return NSUInteger indices into NSStrings without first packaging
them into NSRanges, and when <rdar://problem/19255291> is addressed,
these NSRanges will become Swift Range's, which have a different
interface.  So there's no seamless API transition to be had here, for
any substantial subset of code written against Cocoa.

Swift SVN r23949
2014-12-15 22:24:31 +00:00
Andrew Trick
361ceea369 Mark _copyCollectionToNativeArrayBuffer readonly.
This fixes one of the issues preventing optimization of RangeAssignment
when it isn't fully inlined. There is still another problem with this benchmark I haven't fixed:
<rdar://problem/19252374> We fail to fully optimize RangeAssignment. Forced inlining achieves 3-4x speedup.

This fix at least unblocks CopyForwarding, which perturbs inlining enough to expose the issue.

Swift SVN r23944
2014-12-15 21:20:03 +00:00
Dmitri Hrybenko
e87bcff79d stdlib: move String.{lowercaseString,uppercaseString} to the core
library

Swift SVN r23936
2014-12-15 09:47:03 +00:00
Dmitri Hrybenko
397d2fb8c3 stdlib: coding style: when colon specifies is-a relationship, we put
spaces on both sides of it

Swift SVN r23935
2014-12-15 06:55:30 +00:00
Dmitri Hrybenko
b169a102f7 stdlib: coding style: use "SPI(module)" annotation
Swift SVN r23931
2014-12-15 03:36:02 +00:00
Dave Abrahams
9550c02956 [stdlib] String.UTF16View.Index is bidirectional
Rather than expose random access on String.UTF16View to all Swift users,
expose it only when Foundation is loaded.  This effectively decouples
String from a UTF16 representation on non-Mac platforms.

Swift SVN r23929
2014-12-14 17:11:04 +00:00
Dave Abrahams
67ebc83674 [stdlib] String.UTF16View.Index is no longer Int
We don't want to be locked into a UTF-16 representation on all
platforms, and when we implement String index conversion we really don't
want to extend the interface of Int.

Swift SVN r23928
2014-12-14 17:11:03 +00:00
Maxwell Swadling
63462e64d0 [stdlib] Added ASCII fast path for string hashing
Swift SVN r23896
2014-12-12 22:22:58 +00:00
Erik Eckstein
14af3a57e8 Enable elimination of dead methods which are in classes of higher visibility.
The underlying problem is that e.g. even if a method is private but its class is public, the method can be referenced from another module - from the vtable of a derived class.
So far we handled this by setting the SILLinkage of such methods according to the visibility of the class. But this prevented dead method elimination.
Now I set the SILLinkage according to the visibility of the method. This enables dead method elimination, but it requires the following:
1) Still set the linkage in llvm so that it can be referenced from outside.
2) If the method is dead and eliminated, create a stub for it (which calls swift_reportMissingMethod).



Swift SVN r23889
2014-12-12 17:35:40 +00:00
Maxwell Swadling
3fd1eb23c4 [stdlib] Fixed typo in Character comment
Swift SVN r23847
2014-12-10 23:24:43 +00:00
Maxwell Swadling
4d1ebdbf1b [stdlib] fixed character ASCII fastpath
Swift SVN r23845
2014-12-10 19:13:25 +00:00
David Farler
324411a44b Don't trap when creating a Set from a literal with duplicate elements
rdar://problem/19178760

Swift SVN r23791
2014-12-08 23:09:04 +00:00
Joe Groff
dc4ada34ff Revert "Fix doc comment for ObjectIdentifier.uintValue"
This reverts commit r23742. Brain fart on my part.

Swift SVN r23746
2014-12-05 22:58:46 +00:00
Joe Groff
ee5adc1f6e Runtime: Provide reflection for metatypes.
Metatypes have no user-visible structure, but can at least summarize as their type names. This gives us reasonable ad-hoc Printable behavior (thought debugPrint is still wrong, since a type name isn't parsable without being .self'ed).

Swift SVN r23745
2014-12-05 22:58:44 +00:00
Joe Groff
1cf1b4172b Runtime: Use full demangled names when reflecting values.
Use the recursive demangled name generation I implemented in _typeName for metatypes in _stdlib_getDemangledType as well, so that we get fully-qualified generic names and other goodness.

Swift SVN r23743
2014-12-05 21:25:50 +00:00
Joe Groff
c744c5ec30 Fix doc comment for ObjectIdentifier.uintValue
Identifier equality is equivalent to identity, not value equality.

Swift SVN r23742
2014-12-05 21:25:49 +00:00
David Farler
16633eac05 Rename any/removeAny to first/removeFirst
Sticking with the original design.

Also added a trap test for removeFirst() since its precondition
is that the set be non-empty, similar to Array.

Swift SVN r23712
2014-12-05 01:42:45 +00:00
Maxwell Swadling
2eda5a2341 [stdlib] added ASCII fast path to Character
Swift SVN r23705
2014-12-05 00:24:37 +00:00
Maxwell Swadling
d749871b55 [stdlib] Added comment on incorrect unicode compare
Swift SVN r23703
2014-12-05 00:24:31 +00:00
David Farler
e7506e8eab Remove underscore from _Set<T>
rdar://problem/19132138

Make Set<T> visible by removing the underscore. Also, remove the pesky
${_Self} gyb variable that was for a temporary convenience in hiding Set.

Swift SVN r23699
2014-12-05 00:21:35 +00:00
David Farler
ad67a452dc Set.any should be a method
Although Set.any will always return the same element when not modifying
the set, that is an implementation detail. It should be a method.

Swift SVN r23697
2014-12-05 00:01:21 +00:00
David Farler
e1dd3bad59 Set: Rename removeFirst -> removeAny and first -> any
Rename in Set<T>:

func removeFirst() -> T
to
func removeAny() -> T?

var first: T?
to
var any: T?

- FWIW, `any` more closesly matches NSSet's `anyObject()` and constructs
  in other languages, so `first` seems to be a bit of a surprise.
- `first` implies an ordering of some kind, iterating over `Set` as a
  `SequenceType` does have a somewhat reliably "first" element, but it
  also has a linguistic tension with the fact that Set<T> is
  semantically unordered.
- `first` may be further confused if there ever is an OrderedSet<T>,
  which ought to be the first element in its semantic ordering.

Swift SVN r23696
2014-12-04 23:54:57 +00:00
David Farler
419afc489b Add performance FIXME for Set.intersect
Swift SVN r23675
2014-12-04 02:12:07 +00:00
David Farler
85f300609b Add exclusiveOr, exclusiveOrInPlace to Set<T>
rdar://problem/19124388

Swift SVN r23674
2014-12-04 02:06:19 +00:00
David Farler
76c5937b6c Build fix: Don't invalidate Set index during intersect
Intersect needs an intermediate set because we need to both traverse
and modify the left-hand side for the in-place operation, which can
invalidate the index.

Swift SVN r23666
2014-12-04 00:28:48 +00:00
David Farler
f9eb39cee3 Remove Comparable from Set<T>
Swift SVN r23663
2014-12-03 23:16:27 +00:00
David Farler
6757a7d7f6 Commit next revision of Set<T> public API
The public API is mostly solid at this point, with only a few minor
changes to naming and a couple of extra methods to bring it to parity
with Array.

Also removed the quick-and-dirty operators <, >, <=, and >= which were
used as a convenient shorthand for strict subset, strict superset,
subset, and superset respectively (< is retained for Comparable
conformance).

Swift SVN r23657
2014-12-03 22:22:24 +00:00
David Farler
7493240117 Add any() -> T? to Set
rdar://problem/19062929

Swift SVN r23599
2014-12-01 22:08:51 +00:00
Erik Eckstein
384d936850 Use assumeNonNegative for the array body count.
This should help to optimize the range check in isValidSubscript to a single unsigned integer comparison.
But this is not done yet, because it also needs an optimization in llvm, which I'm currently working on.

Together with the llvm change there will be an performance improvement for array benchmarks, where the
range check cannot be hoisted out of a loop. E.g. ~ +30% on QuickSort.



Swift SVN r23583
2014-11-26 09:58:37 +00:00
Erik Eckstein
54e1071da0 Add a builtin assumeNonNegative.
It returns the argument and specifies that the value is not negative.
It has only an effect if the argument is a load or call.

The effect of this builtin is that for the load/call argument a positive range metadata is created in llvm ir.

I also added a public function _assumeNonNegative(x: Int) -> Int in the stdlib.
To be on the save side, I prefixed it with an underscore. But maybe it makes sense to make it available for all users.



Swift SVN r23582
2014-11-26 09:53:14 +00:00
Graham Batty
e537c75d0c Revert "Disable existential metatype casting on non-objc."
This reverts commit 3e918838b3708bf2287e7caab437ccf72fe9a3f6.

Swift SVN r23579
2014-11-24 17:42:19 +00:00
Graham Batty
7ed843aab9 Revert "Implement String Comparable and Hashable conformances for non-objc"
This reverts commit 6d086ae7fe6725c74924ff410c562949a286e7d1.

Swift SVN r23576
2014-11-24 17:42:05 +00:00
Graham Batty
277891d8b5 Disable existential metatype casting on non-objc.
Swift SVN r23575
2014-11-24 17:40:44 +00:00
Graham Batty
396eca75b4 Implement String Comparable and Hashable conformances for non-objc
This is just a basic implementation of each, with some questions
lingering about whether to do unicode normalization (and if so how),
but it gets things going.

Swift SVN r23572
2014-11-24 17:40:24 +00:00
Dave Abrahams
d9c750eefd [stdlib] Remove ArrayBuffer indirection
The case where Array stores class instances no longer requires an
intermediate indirect buffer object.

Also fixes <rdar://problem/17348939>

These are the speed changes < 0.95x and > 1.05x, as I measured them.
Although I don't have great confidence in these numbers, some are
consistent with Arnold's measurements, FWIW.

-O:
0.93 ArrayLiteral
1.56 Ary
1.39 Ary2
1.06 CaptureProp
1.93 ClassArrayGetter
1.08 DeltaBlue
1.08 DollarChain
1.13 InsertionSort
1.08 PrimeNum
1.11 RC4
0.93 Rectangles
1.08 SwiftStructuresBubbleSort

-Onone:
1.06 ArrayLiteral
1.10 ArraySubscript
1.12 Ary
1.12 Ary2
1.10 Ary3
1.20 ClassArrayGetter
1.19 DeltaBlue
1.08 DollarChain
1.09 Hash
1.07 Havlak
1.10 HeapSort
1.11 ImageProc
1.17 InsertionSort
1.18 Memset
1.11 NBody
1.07 PrimeNum
1.11 QuickSort
1.12 RC4
1.08 Rectangles
1.07 SelectionSort
1.06 StringBuilder
1.12 SwiftStructuresBubbleSort
1.10 Walsh
1.12 XorLoop

-Ounchecked:
0.91 ArrayLiteral
1.74 Ary
1.53 Ary2
2.08 ClassArrayGetter
1.19 DeltaBlue
1.06 DollarChain
1.07 Havlak
1.09 ImageProc
1.22 InsertionSort
0.89 PopFrontArrayGeneric
1.11 PrimeNum
0.85 QuickSort
1.10 RC4
1.12 Rectangles
1.06 StrToInt
1.11 SwiftStructuresBubbleSort

Swift SVN r23551
2014-11-22 08:19:57 +00:00
Joe Groff
b60a30c84b stdlib: Make isUniquelyReferenced shims properly return bool.
rdar://problem/18573806 is fixed.

Swift SVN r23547
2014-11-22 05:36:38 +00:00
Dave Abrahams
5798cf9014 [stdlib] Fix a dumb omission
This should fix the build

Swift SVN r23509
2014-11-21 04:27:15 +00:00
Dave Abrahams
15e195943e [stdlib] BridgeStorage: uniqueness check fast path
When we know we've got a native object and no spare bits set, we can use
a faster check for uniqueness.

Swift SVN r23506
2014-11-21 01:39:55 +00:00
Dave Abrahams
bf233c5b46 [stdlib] BridgeStorage: rename a property
This name is more consistent with the convention used throughout the
runtime: use underscores to separate the preconditions of partial
functions from the rest of their names.

Swift SVN r23505
2014-11-21 01:39:55 +00:00
Dave Abrahams
de8967e2cd [stdlib] Copious force-inling
Just trying to remove possible overheads in the new Array
implementation.  It doesn't seem to affect performance, though.

Swift SVN r23504
2014-11-21 01:39:54 +00:00