Commit Graph

58 Commits

Author SHA1 Message Date
Maxwell Swadling
55f3289054 Added additional tests and comments to String
Swift SVN r23490
2014-11-20 22:33:13 +00:00
Graham Batty
dc6a776d10 stdlib: Use config directives to work without objective-c.
Swift SVN r23211
2014-11-10 20:06:25 +00:00
Graham Batty
373414864d Revert "Use config directives to carve out a 'portable' kernel stdlib."
This reverts commit r23202 pending further discussion.

Swift SVN r23205
2014-11-10 18:46:42 +00:00
Graham Batty
dfa260fab1 Use config directives to carve out a 'portable' kernel stdlib.
Swift SVN r23202
2014-11-10 18:03:09 +00:00
Dave Abrahams
56c4cb2d42 [stdlib] Kill off _isUniquelyReferenced
It was doing an unsafeBitCast and possibly not managing lifetimes;
replace it with more-typesafe and memory-safe calls where possible.

Swift SVN r22779
2014-10-15 22:25:12 +00:00
Dave Abrahams
156020de19 [stdlib] Rename 'countElements' => 'count'
The name was not only long and unwieldy, but inconsistent with our
conscious decision to avoid the use of "elements" in APIs as mostly
redundant.

Swift SVN r22408
2014-09-30 22:00:26 +00:00
Dmitri Hrybenko
a04ee3a463 stdlib/Unicode: allow transcode() to operate on mutable value-typed
sinks

Swift SVN r22302
2014-09-26 17:28:00 +00:00
Dave Abrahams
66d2ba43c6 [stdlib] underscore APIs made visible by r22212
That commit made a protocol public.  The protocol was underscored but
some of its APIs were not, and those became unintentionally publicly
visible.  This commit corrects that problem.  Since Builtin.RawPointer
properties were being renamed from "value" to "_rawValue" for clarity,
COpaquePointer got that treatment too, even though it wasn't strictly
necessary, for consistency.

Swift SVN r22252
2014-09-24 02:50:43 +00:00
Dave Abrahams
6bb89ae255 [stdlib] Propagate RangeReplaceableCollectionType docs
240 undocumented public non-operator APIs remain in core

Swift SVN r22235
2014-09-23 22:48:15 +00:00
Dave Abrahams
f5c80b115b [stdlib] Propagate ExtensibleCollectionType docs
184 undocumented public non-operator APIs remain in core

Swift SVN r22231
2014-09-23 21:13:45 +00:00
Dave Abrahams
1e9e7734f0 Revert "[stdlib] any/all algorithms, keyword for contains"
This reverts r21810 and r21811 due to lack of design consensus

Swift SVN r21880
2014-09-11 17:42:32 +00:00
Dave Abrahams
c467825bc2 [stdlib] any/all algorithms, keyword for contains
Expose any, all on Array and all the Lazy sequence adapters.  Make the
'contains' algorithm that takes a predecate unavailable in favor of
'any', which does the same thing.

Fixes <rdar://problem/18190149> [algorithm] `contains` syntax is ambiguous

Swift SVN r21810
2014-09-09 20:39:39 +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
Dave Abrahams
082c396cfe [stdlib] String.replaceRange: fix value semantics
Fixes <rdar://problem/18114265> Swift Compiler Optimizations for Strings causing incorrect behaviour

Swift SVN r21487
2014-08-27 19:24:55 +00:00
Dave Abrahams
6c07fb4ad1 [stdlib] Revert UnsafePointer casting change
The syntax being reverted added busywork and noise to the common case
where you want to say "I have the right address, but the wrong type,"
without adding any real safety.

Also it eliminated the ability to write UnsafePointer<T>(otherPointer),
without adding ".self" to T.  Overall, it was not a win.

This reverts commits r21324 and r21342

Swift SVN r21424
2014-08-22 21:53:12 +00:00
Dave Abrahams
1fb0f889d7 [stdlib] Make UnsafePointer conversions explicit
Previously, it was possible to write Unsafe[Mutable]Pointer(x) and have
Swift deduce the pointee type based on context.  Since reinterpreting
memory is a fundamentally type-unsafe operation, it's better to be
explicit about conversions from Unsafe[Mutable]Pointer<T> to
Unsafe[Mutable]Pointer<U>.  This change is consistent with the move from
reinterpretCast(x) to unsafeBitCast(x, T.self).

Also, we've encoded the operations of explicitly adding or removing
mutability as properties, so that adding mutability can be separated
from wild reinterpretCast'ing, a much more severe form of unsafety.

Swift SVN r21324
2014-08-20 23:15:56 +00:00
Dmitri Hrybenko
532ca776ca stdlib/String: fix a memory safety issue with using foreign indexes
(indexes obtained from a different object)

rdar://18037790

Swift SVN r21244
2014-08-15 23:56:30 +00:00
Dmitri Hrybenko
a75c7a427a stdlib/NSString APIs on String: add more tests and fix a crash in
_countFormatSpecifiers() that was triggered by non-BMP characters in the format
string


Swift SVN r21014
2014-08-04 15:37:58 +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
a7e485d601 [stdlib] _StringCore.replaceRange precondition checks
Swift SVN r20949
2014-08-02 06:01:12 +00:00
Dave Abrahams
f270a5b6f3 [stdlib] _StringCore : RangeReplaceable
Swift SVN r20947
2014-08-02 05:44:40 +00:00
Dave Abrahams
921045c7f8 [stdlib] Enable commented test part
As I was reducing a test case for a typechecker bug, I ended up
commenting out important test code in the regression suite.  This
restores it (and makes it work).

Swift SVN r20925
2014-08-01 23:01:02 +00:00
Dave Abrahams
1f8ec23ebe [stdlib] Correct/test _StringCore.reserveCapacity
The old one could never have worked.

Swift SVN r20916
2014-08-01 21:35:15 +00:00
Dave Abrahams
5f02ce8f03 [stdlib] Use Range<UnsafePointer> in _StringBuffer.grow()
Swift SVN r20876
2014-08-01 01:47:50 +00:00
Dave Abrahams
ea21309150 [stdlib] _StringCore: ExtensibleCollectionType
Swift SVN r20825
2014-07-31 14:57:42 +00:00
Dmitri Hrybenko
ec4f8d37f7 stdlib: fix a heap overflow that colud happen when appending to a string
slice

rdar://17855908

Swift SVN r20762
2014-07-30 18:04:36 +00:00
Joe Pamer
94dac129d4 Remove the BooleanType conformance from optional types (rdar://problem/17110911)
To limit user confusion when using conditional expressions of type Bool?, we've decided to remove the BooleanType (aka "LogicValue") conformance from optional types. (If users would like to use an expression of type Bool? as a conditional, they'll need to check against nil.)

Note: This change effectively regresses the "case is" pattern over types, since it currently demands a BooleanType conformance. I've filed rdar://problem/17791533 to track reinstating it if necessary.

Swift SVN r20637
2014-07-28 19:20:39 +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
Dave Abrahams
d00e888d95 [stdlib] Rename reinterpretCast => unsafeBitCast
Also give unsafeBitCast an explicit type parameter.  So

  let x: T = reinterpretCast(y)

becomes

  let x = unsafeBitCast(y, T.self)

Swift SVN r20487
2014-07-24 13:17:36 +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
Dmitri Hrybenko
b53ed944b0 stdlib: replace masking arithmetic with less complex code
Swift SVN r19899
2014-07-13 15:42:51 +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
Nadav Rotem
bb3ad55201 Document the use of the non overflowing arithmetic when multiplying sizeof() by 8.
Swift SVN r19856
2014-07-11 18:35:23 +00:00
Nadav Rotem
98ab6d8286 Perform unsafe arithmetic on sizeof() calculations. This calculation is unlikely to overflow. I did not see a noticable performance change to the string benchmarks.
Swift SVN r19836
2014-07-10 23:43:15 +00:00
Andrew Trick
7ed7be9c14 Put cocoa on the slow path of String.subscript.
Swift SVN r19700
2014-07-08 21:43:16 +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
Doug Gregor
d8de1a9ef9 Remove two more implicit conversions used only within the standard library.
Swift SVN r19624
2014-07-07 18:57:36 +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
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
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
Jordan Rose
7d649e0a16 Use "_" instead of "c_" for primitive functions accessed through asmname.
No functionality change.

Swift SVN r19119
2014-06-24 01:23:04 +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
Dave Abrahams
89fb9c8bea [stdlib] Factor out Array growth calculation
This enables testing of other growth factors, per
<rdar://problem/17230502>.  See the radar for basic performance test
results confirming (to the degree practical) that 2x growth is better
than 1.5x in our current system.

Swift SVN r18990
2014-06-18 23:17:06 +00:00
Dave Abrahams
bf10db2834 [stdlib] Add an UnsafeMutableArray
Will be useful in optimizing bulk array mutations such as sort()

Also stopped making UnsafeArray a generator; in general making a
collection a generator seems somewhat muddled and dangerous, especially
when it comes to adapters that may have reference semantics.

Swift SVN r18924
2014-06-16 14:04:53 +00:00
Manman Ren
aec78d0693 [stdlib] revert r18764.
Swift SVN r18765
2014-06-10 00:13:41 +00:00
Manman Ren
cc90c81239 [stdlib] add two-operand version of max and use max2 in stdlib when appropriate.
This helps array append's performance by ~ 2x. The generic max with a variadic
argument creates a temporary array then iterates over the array.

rdar://17140639 rdar://17073827


Swift SVN r18764
2014-06-09 23:56:40 +00:00
Ted Kremenek
074150571f Rename isNull() to _isNull() (making them private), and make pointers
conform to LogicValue.

This approach was taken to keep _isNull because I first tried
to just use comparisons to nil instead of isNull().  Apparently
that led to some circular definitions, so it was easier to just
stage it this way.

Swift SVN r18301
2014-05-18 03:42:40 +00:00