Commit Graph

80 Commits

Author SHA1 Message Date
Doug Gregor
7764f64cf8 Simplify assertion machinery in the standard library.
This change includes a number of simplifications that allow us to
eliminate the type checker hack that specifically tries
AssertString. Doing so provides a 25% speedup in the
test/stdlib/ArrayNew.swift test (which is type-checker bound).

The specific simplifications here:
  - User-level
  assert/precondition/preconditionalFailure/assertionFailer/fatalError
  always take an autoclosure producing a String, eliminating the need
  for the StaticString/AssertString dance.
  - Standard-library internal _precondition/_sanityCheck/etc. always
  take a StaticString. When we want to improve the diagnostics in the
  standard library, we can provide a separate overload or
  differently-named function.
  - Remove AssertString, AssertStringType, StaticStringType, which are
  no longer used or needed
  - Remove the AssertString hack from the compiler
  - Remove the "BooleanType" overloads of these functions, because
  their usefuless left when we stopped making optional types conform
  to BooleanType (sorry, should have been a separate patch).



Swift SVN r22139
2014-09-19 17:56:50 +00:00
Doug Gregor
82d7daf5fc Revert StringInterpolationConvertible back to class method requirements.
The initializer requirement is causing too much exponential behavior
in the constraint solver. We'll have to address that
first. Re-instating this change is tracked by rdar://problem/18381811.


Swift SVN r22080
2014-09-18 17:10:53 +00:00
Doug Gregor
f1e47a7b18 Switch string interpolation protocol over to initializer requirements.
With this, we're now using initializer requirements rather than
"convertFromXXX" requirements everywhere, addressing the rest of
rdar://problem/18154091.


Swift SVN r22078
2014-09-18 16:13:18 +00:00
Doug Gregor
3ebf5cb3da Switch the string literal protocols over to initializer requirements.
Swift SVN r22076
2014-09-18 15:48:42 +00:00
Dave Abrahams
69075bc61d [stdlib] Kill unintended argument label
Fixes <rdar://problem/18232095> Remove mandatory keyword from generic String init

Swift SVN r21801
2014-09-09 03:50:40 +00:00
Dmitri Hrybenko
4139fe129e stdlib: underscore-prefix private type Character.SmallUTF16
Swift SVN r21640
2014-09-02 14:26:51 +00:00
Dmitri Hrybenko
51a8becf1c stdlib/String: strength-reduce some String methods: prefer StringCore.append
over String.extend

Performance testsuite changes over 2% are as follows.  A lot of tests unrelated
to String have been affected because of measurement noise and because strings
are used in result verification.

                 Ary3     4.8%
          CaptureProp    10.3%
           Dictionary    -4.0%
         EditDistance     2.8%
               Forest    -4.0%
                 Hash     8.6%
        InsertionSort     6.7%
                 Life    -2.3%
               MatMul     2.6%
           NestedLoop     3.9%
        PopFrontArray     2.9%
             PrimeNum     3.6%
                Prims     2.2%
              SmallPT    -2.1%
               TwoSum     4.1%

Swift SVN r21629
2014-09-01 14:30:41 +00:00
Dmitri Hrybenko
985def47c9 stdlib: improve performance of string appending
CaptureProp ,  -21.8%
             HeapSort ,   12.7%
            ImageProc ,  -25.6%
               StrCat ,   92.6%
       StrComplexWalk ,   11.1%
             StrToInt ,   16.6%
  StringInterpolation ,   21.6%

Regression in CaptureProp is due to some interference of the harness.  When the
code is extracted into a separate file, there is no difference.

Regression in ImageProc is caused by unconditional construction of a string for
CheckResults()

rdar://18119872

Swift SVN r21535
2014-08-28 16:48:39 +00:00
Dmitri Hrybenko
4acc8a3e4b stdlib: remove redundant parens
Swift SVN r21529
2014-08-28 14:10:07 +00:00
Roman Levenstein
97014172b7 [sil-combine] String literal concatenation optimization. Constant-fold concatenation of string literals known at compile-time.
Addresses rdar://17033696.

Swift SVN r21526
2014-08-28 11:33:21 +00:00
Dave Abrahams
f3ac09497d Store ASCII string literals as UTF8
Fixes <rdar://problem/16740011> ASCII string literals produce UTF16
Strings

Swift SVN r21419
2014-08-22 19:05:15 +00:00
Dmitri Hrybenko
16604871b3 stdlib: disallow concatenating Characters with "+"
rdar://18026160


Swift SVN r21249
2014-08-18 10:13:36 +00:00
Dave Abrahams
980ccb7788 [stdlib] Fix reserve when extending String
I wish I knew how to code a regression test for this, but sadly I don't.

The only performance differences with magnitude > 7% show up in
-Ounchecked, and most of these look suspiciously like noise due to the
irrelevance of generic string append.  The only one I'd be remotely
concerned about is StrToInt, but it doesn't make any sense that it
should have gotten slower, so I think that's noise too.

Ackermann: -14.3%
Fibonacci: 33.3%
ImageProc: 9.0%
Phonebook: -7.1%
QuickSort: 15.6%
StrToInt: -14.3%

Swift SVN r21236
2014-08-15 16:44:10 +00:00
Dmitri Hrybenko
84abad0be4 stdlib: clarify a trap error message
Swift SVN r21205
2014-08-14 17:36:27 +00:00
Doug Gregor
7a80e1249e Minor standard library cleanups. NFC
Swift SVN r21203
2014-08-14 17:27:43 +00:00
Dmitri Hrybenko
938e7c2676 stdlib: introduce UnicodeScalarLiteralConvertible protocol
This allows UnicodeScalars to be constructed from an integer, rather
then from a string.  Not only this avoids an unnecessary memory
allocation (!) when creating a UnicodeScalar, this also allows the
compiler to statically check that the string contains a single scalar
value (in the same way the compiler checks that Character contains only
a single extended grapheme cluster).

rdar://17966622

Swift SVN r21198
2014-08-14 16:04:39 +00:00
Dmitri Hrybenko
2f80b28c5f stdlib: remove a bogus implementation of an unavailable function
Swift SVN r21193
2014-08-14 11:33:31 +00:00
Nadav Rotem
4cf6181785 Replace @semantics("readonly") with @effects(readonly).
Swift SVN r21088
2014-08-07 07:22:18 +00:00
Nadav Rotem
d96e940c36 Mark the concatination of two strings as @readonly.
Swift SVN r21061
2014-08-06 05:19:51 +00:00
Nadav Rotem
e67c274cbe Convert the toString overloads to GYB.
Swift SVN r21053
2014-08-05 23:48:43 +00:00
Nadav Rotem
744d1fb7b9 Remove the non-generic toString versions and create a single @readonly toString function that can be used by convertFromStringInterpolationSegment.
Swift SVN r21050
2014-08-05 22:59:13 +00:00
Nadav Rotem
ae52323dab toString() optimizations:
1. Remove incorrect @readonly semantics on two functions.
2. Overload toString for some of the popular types and add readonly semantics so that we can optimize them away.



Swift SVN r21045
2014-08-05 22:09:53 +00:00
Dmitri Hrybenko
b09698a6e6 stdlib: privatize lazyConcatenate() and related APIs
Swift SVN r21039
2014-08-05 14:55:09 +00:00
Dave Abrahams
7eacae411a [stdlib] Make String.extend/append overloads available
These will probably be faster than the generic versions, so why not
expose them?

Swift SVN r20998
2014-08-04 06:44:34 +00:00
Dave Abrahams
e70c19f021 [stdlib] Don't allow String() + Character("x")
Symmetry with what we did for Arrays says that Strings shoudl only
concatenate to Strings using "+".  We have append() for adding single
characters.

Swift SVN r20997
2014-08-04 06:44:34 +00:00
Dave Abrahams
70b388ba77 [stdlib] Add append() to ExtensibleCollectionType
If you can be grown by an arbitrary sequence of your element type, you
can be grown by a single element.

Swift SVN r20996
2014-08-04 06:44:33 +00:00
Dave Abrahams
1ec2b36fc1 [stdlib] Implement String.reserveCapacity
Fixes <rdar://problem/16970908>

Swift SVN r20989
2014-08-03 23:55:57 +00:00
Dave Abrahams
0c5cbd88ca [stdlib] String : RangeReplaceableCollectionType
Addresses <rdar://problem/17860946> Full Array mutation APIs for String and UnicodeScalarView

Swift SVN r20980
2014-08-03 22:02:42 +00:00
Dmitri Hrybenko
56473c34cd stdlib: change out-of-bounds subscripting traps on mirrors to be
_preconditionFailure()s.  Some of these checks are clearly redundant (for
example, the check of array subscript), but since we have no tests for
these traps (and reflection is not fast in general), I prefer to keep this
transformation as straightforward as possible.


Swift SVN r20971
2014-08-03 18:42:53 +00:00
Dmitri Hrybenko
5746e4e9ca stdlib: rename _fatalError to _sanityCheckFailure. Name similarity between
fatalError and _fatalError has caused some damage already, as some
memory-safety checks in Mirrors are _fatalErrors.


Swift SVN r20969
2014-08-03 15:20:37 +00:00
Nadav Rotem
08e5bff61b Mark some more conversion functions as @readonly.
On -Ounchecked we are now able to zap this expression (from Richards):
  UnicodeScalar(UInt32(2)+"0".value)

However, on -O we still check for overflow and actually need to construct the string.



Swift SVN r20856
2014-07-31 22:15:36 +00:00
Nadav Rotem
52ecfc8a27 Mark some more string builders as @readonly.
This accelerates Richards by 4X because we don't need to construct debug strings such as:

debug("TCB \(tcb!.id) state \(tcb!.state.bits)")



Swift SVN r20853
2014-07-31 21:55:29 +00:00
Dmitri Hrybenko
190db64c18 stdlib: document current plan of record for reserveCapacity() semantics
rdar://16970908


Swift SVN r20758
2014-07-30 14:42:24 +00:00
Doug Gregor
0b802ce6e9 String: add some unavailable subscript overloads for String with integer (or integer range) indices.
The compiler's QoI for these cases is horrible, and it's a common
pitfall, so be more direct about the fact that this cannot be done.


Swift SVN r20613
2014-07-28 03:50:26 +00:00
Dave Abrahams
31d6f95452 [stdlib] UnsafeBufferPointer: add ".count"
In answering a forum post I noiced that I wanted this and it was
missing.

Also, extensive comments

Also, rename the length: init parameter to count:.  When writing the
comments for the init function it became painfully clear why we use
"count" is better than "length" especially around pointers and memory:
the former is much less easy to mistake for "length in bytes".  Plus
it's consistent with the new ".count" property

Swift SVN r20609
2014-07-28 01:03:09 +00:00
Dmitri Hrybenko
ed855afb68 stdlib/String: use the Unicode collation algorithm in String's and Character's conformance to Comparable
rdar://17498444


Swift SVN r20554
2014-07-25 18:32:36 +00:00
Dmitri Hrybenko
089fd8d6ec stdlib/String: rename the function in one more place, follow-up for
r20543

Swift SVN r20544
2014-07-25 14:55:26 +00:00
Dmitri Hrybenko
c44b42c7aa stdlib/String: add a test that shows that equality comparison of strings
is performed according to the deterministic Unicode collation algorithm,
which allows us to use the hash of the NFD form.

rdar://17498444

Swift SVN r20543
2014-07-25 14:31:07 +00:00
Dmitri Hrybenko
27cbb5a9d5 stdlib/String: change == to perform string comparison after NFD
normalization

There is still some obscure bug with != on NSString, probably caused by
an ill-thought overload somewhere.

Part of rdar://17498444

Swift SVN r20518
2014-07-24 21:36:01 +00:00
Dmitri Hrybenko
c2adafc897 Revert "stdlib/String: change == to perform string comparison after NFD"
This breaks consistency between == comparison and hash value.

Swift SVN r20500
2014-07-24 17:28:40 +00:00
Dmitri Hrybenko
a3d5a8a0de stdlib/String: change == to perform string comparison after NFD
normalization

There is still some obscure bug with != on NSString, probably caused by
an ill-thought overload somewhere.

Part of rdar://17498444

Swift SVN r20495
2014-07-24 16:51:48 +00:00
Dmitri Hrybenko
766c9816de stdlib: underscore-prefix String.core
Swift SVN r20411
2014-07-23 16:28:57 +00:00
Dmitri Hrybenko
52f3ba25b4 stdlib: underscore a private String initializer
Swift SVN r20408
2014-07-23 16:15:17 +00:00
Dave Abrahams
e3f8d0e630 [stdlib] rename UnsafeArray => UnsafeBufferPointer
Also,

  UnsafeMutableArray => UnsafeMutableBufferPointer
  withUnsafeMutableStorage => withUnsafeMutableBufferPointer

Swift SVN r20340
2014-07-22 22:20:37 +00:00
Dave Abrahams
21669b3aee [stdlib] Add "Mutable" to [Autoreleasing]UnsafePointer
UnsafePointer becomes UnsafeMutablePointer
AutoreleasingUnsafePointer becomes AutoreleasingUnsafeMutablePointer

Swift SVN r20316
2014-07-22 16:56:23 +00:00
Jordan Rose
8f520414b7 [Accessibility] A private class cannot contain public methods.
There's no meaningful way in which these methods are public, since they
can't be accessed through any value of the type

<rdar://problem/17647878>

Swift SVN r20224
2014-07-20 17:26:24 +00:00
Dave Abrahams
c4f798e246 [stdlib] Make our BidirectionalIndexTypes Comparable
This will allow more error checking, resilient slicing, and occasionally
other useful capabilities.

Step 1 of <rdar://problem/11940897>

Swift SVN r20036
2014-07-16 20:43:42 +00:00
Chris Lattner
e0b0205cd7 Remove the @assignment attribute entirely. It doesn't do anything except
enforce its own little constraints.  The type checker isn't using it for
anything, and it is just clutter.

This resolves <rdar://problem/16656024> Remove @assignment from operator implementations



Swift SVN r19960
2014-07-14 22:44:25 +00:00
Dave Abrahams
6d1095f44e Protocol names end in "Type," "ible," or "able"
Mechanically add "Type" to the end of any protocol names that don't end
in "Type," "ible," or "able."  Also, drop "Type" from the end of any
associated type names, except for those of the *LiteralConvertible
protocols.

There are obvious improvements to make in some of these names, which can
be handled with separate commits.

Fixes <rdar://problem/17165920> Protocols `Integer` etc should get
uglier names.

Swift SVN r19883
2014-07-12 17:29:57 +00:00
Doug Gregor
8fb9a19542 Replace the "string" property of String.UnicodeScalarView with a String initializer.
Swift SVN r19695
2014-07-08 20:25:30 +00:00