Commit Graph

56 Commits

Author SHA1 Message Date
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
Doug Gregor
973caddc24 Replace String.UnicodeScalarView's user conversion to String with a "string" property
Swift SVN r19691
2014-07-08 20:01:50 +00:00
Nadav Rotem
bdecfe75a6 Mark the string builder as @readonly to allow us to remove unused strings.
Swift SVN r19679
2014-07-08 04:52:48 +00:00
Jordan Rose
5427102268 Remove stray @ from 'public' and 'internal' missed in r19672.
Swift SVN r19675
2014-07-08 03:00:42 +00:00
Jordan Rose
da29f099f0 Update stdlib for accessibility modifiers becoming context-sensitive keywords.
Swift SVN r19672
2014-07-08 02:17:46 +00:00
Enrico Granata
b6ca5f3a77 Add Mirror support for String.Index
The chosen display mode is using the integer UTF16-based position as the thing to display
This is what would also be displayed by default, except it would show up as {{_position 0},{...}}
Now we avoid exposing the internals, and just essentially coalesce the Index with its numeric value



Swift SVN r19670
2014-07-08 02:13:38 +00:00
Jordan Rose
cdd8532f33 Remove @private from the stdlib.
@private can't safely be used with inlineable code at this time, which
unfortunately covers the entire standard library.

Swift SVN r19550
2014-07-04 01:53:52 +00:00
Dmitri Hrybenko
57df21cefe stdlib/comments: UTF-8 and UTF-16 are spelled with a dash
Swift SVN r19466
2014-07-02 15:45:38 +00:00
Dmitri Hrybenko
27abfcb271 stdlib/String: add a performance FIXME
Swift SVN r19394
2014-07-01 13:18:18 +00:00
Dmitri Hrybenko
124eb2ae83 stdlib: reword trap messages in response to review from Dave
Swift SVN r19393
2014-07-01 13:18:16 +00:00
Jordan Rose
748efed913 [Accessibility] Protocol witnesses must be as accessible as the protocol.
...unless the type has less accessibility than the protocol, in which case
they must be as accessible as the type.

This restriction applies even with access control checking disabled, but
shouldn't affect any decls not already marked with access control modifiers.

Swift SVN r19382
2014-06-30 23:38:35 +00:00
Jordan Rose
5e59d30c6f Update stdlib for memberwise access control.
As before, there may be more things marked @public than we actually want
public. Judicious use of the frontend option -disable-access-control may
help reduce the public surface area of the stdlib.

Swift SVN r19353
2014-06-30 18:50:50 +00:00
Dmitri Hrybenko
4814e00fda stdlib/String: implement Unicode extended grapheme cluster segmentation
algorithm

The implementation uses a specialized trie that has not been tuned to the table
data.  I tried guessing parameter values that should work well, but did not do
any performance measurements.

There is no efficient way to initialize arrays with static data in Swift.  The
required tables are being generated as C++ code in the runtime library.

rdar://16013860


Swift SVN r19340
2014-06-30 14:38:53 +00:00
Dmitri Hrybenko
50a5b303a1 stdlib/String.UnicodeScalarView: rename _base to _core
NFC; improves readability of future commits.

Swift SVN r19337
2014-06-30 12:02:36 +00:00
Jordan Rose
cca27d02a0 Tag everything in the standard library with accessibility attributes.
Keep calm: remember that the standard library has many more public exports
than the average target, and that this contains ALL of them at once.
I also deliberately tried to tag nearly every top-level decl, even if that
was just to explicitly mark things @internal, to make sure I didn't miss
something.

This does export more than we might want to, mostly for protocol conformance
reasons, along with our simple-but-limiting typealias rule. I tried to also
mark things private where possible, but it's really going to be up to the
standard library owners to get this right. This is also only validated
against top-level access control; I haven't fully tested against member-level
access control yet, and none of our semantic restrictions are in place.

Along the way I also noticed bits of stdlib cruft; to keep this patch
understandable, I didn't change any of them.

Swift SVN r19145
2014-06-24 21:32:18 +00:00
Ted Kremenek
58558fcca3 Rename 'succ' and 'pred' to 'successor' and 'predecessor' respectively.
This is motivated by <rdar://problem/17051606>.

This ends up renaming variables as well, which seems right for
consistency since we use "predicate" as variable name.

Swift SVN r19135
2014-06-24 19:27:19 +00:00
Dmitri Hrybenko
f370ca0746 stdlib: fix a bunch of various Unicode issues, primarily in UTF-8 decoding
In UTF-8 decoder:
- implement U+FFFD insertion according to the recommendation given in the
  Unicode spec.  This required changing the decoder to become stateful, which
  significantly increased complexity due to the need to maintain an internal
  buffer.
- reject invalid code unit sequences properly instead of crashing rdar://16767868
- reject overlong sequences rdar://16767911

In stdlib:
- change APIs that assume that UTF decoding can never fail to account for
  possibility of errors
- fix a bug in UnicodeScalarView that could cause a crash during backward
  iteration if U+8000 is present in the string
- allow noncharacters in UnicodeScalar.  They are explicitly allowed in the
  definition of "Unicode scalar" in the specification.  Disallowing noncharacters
  in UnicodeScalar prevents actually using these scalar values as internal
  special values during string processing, which is exactly the reason why they
  are reserved in the first place.
- fix a crash in String.fromCString() that could happen if it was passed a null
  pointer

In Lexer:
- allow noncharacters in string literals.  These Unicode scalar values are not
  allowed to be exchanged externally, but it is totally reasonable to have them
  in literals as long as they don't escape the program.  For example, using
  U+FFFF as a delimiter and then calling str.split("\uffff") is completely
  reasonable.

This is a lot of changes in a single commit; the primary reason why they are
lumped together is the need to change stdlib APIs to account for the
possibility of UTF decoding failure, and this has long-reaching effects
throughout stdlib where these APIs are used.


Swift SVN r19045
2014-06-20 13:07:40 +00:00
Chris Lattner
62cad3dce8 add a "..<" operator, which is an alias for ".." and switch the stdlib to use it.
Until I have a chance to update the testsuite, we'll accept both.



Swift SVN r18998
2014-06-19 05:42:29 +00:00
Chris Lattner
60fc0e6cd2 Implement <rdar://problem/16951729> nil should be a literal type
This is all goodness, and eliminates a major source of implicit conversions.
One thing this regresses on though, is that we now reject "x == nil" where
x is an option type and the element of the optional is not Equtatable.  If
this is important, there are ways to enable this, but directly testing it as
a logic value is more straight-forward.

This does not include support for pattern matching against nil, that will be
a follow on patch.



Swift SVN r18918
2014-06-15 22:59:03 +00:00
Dmitri Hrybenko
ce14332bb6 stdlib: make UnicodeScalar.escape() independent of current locale
Swift SVN r18595
2014-05-23 15:40:47 +00:00
Dave Abrahams
0f9edadc41 [stdlib] String API Review: NSString API
Many changes in how we're presenting the NSString APIs on String, most
notably that we now traffic in String.Index and Range<String.Index>
rather than Int and NSRange.  Also we present NSString initializers that
can fail only as factory functions, and factory functions that can't
fail only as init functions.

About 25% of the API changes here have been reviewd by the Foundation
guys, and testing is, as it has always been, admittedly spotty.  Dmitri
is going to be writing some more comprehensive tests.

Swift SVN r18553
2014-05-22 04:21:55 +00:00
Dmitri Hrybenko
9a4004ab61 stdlib/Join: add forwarding join() instance functions to array and string types
rdar://16388632


Swift SVN r18493
2014-05-21 13:15:30 +00:00
Ted Kremenek
dce90aed78 Change remaining standard library cases of isEmpty() to a property isEmpty.
Swift SVN r18266
2014-05-17 20:01:17 +00:00
Dmitri Hrybenko
a4d9dcf1a7 stdlib: extinguish \brief and \c
Swift SVN r18261
2014-05-17 18:10:51 +00:00
Dmitri Hrybenko
011584a0b6 stdlib/pritning: untie string interpolation from string initializers
String interpolation invokes convertFromStringInterpolationSegment() function
now.  There is no need to add extensions to String to allow custom types to
participate in string interpolation.  Just implementing Printable will do the
right thing.


Swift SVN r18104
2014-05-15 09:56:02 +00:00