Commit Graph

675 Commits

Author SHA1 Message Date
Joe Groff
cb48fbd24b Enable pointer conversions.
Swift SVN r19274
2014-06-26 23:26:31 +00:00
Joe Groff
d064fd7307 stdlib: Disable AutoreleasingUnsafePointer's inout conversion when building with intrinsic pointer conversions.
Swift SVN r19269
2014-06-26 22:37:26 +00:00
Joe Groff
7717b30d99 stdlib: Add a default initializer for AutoreleasingUnsafePointer.
Swift SVN r19268
2014-06-26 22:37:26 +00:00
Doug Gregor
bea1d3d9b3 Use dictionary type sugar in the standard library.
Swift SVN r19264
2014-06-26 22:26:58 +00:00
Chris Lattner
4ac0f31852 add an 'overflow' label to the second result of the "withoverflow" aritmetic operations,
as suggested by Dmitri



Swift SVN r19251
2014-06-26 21:00:32 +00:00
Chris Lattner
4dcd6cf4d1 implement <rdar://problem/17101613> standard library should provide a way to test for overflow
This just renames the existing "uncheckedAdd" (and related) functions to addWithOverflow.  These
were already "checked" and return the partial result + bool that we want.


Swift SVN r19246
2014-06-26 20:33:17 +00:00
Dave Abrahams
c1539b3e5d [stdlib] Put the "unsafe" in withUnsafeMutableStorage
This API exposes unmediated access to memory, and most users will never
see the UnsafeArray argument that's passed to the closure, so best to be
explicit.

Swift SVN r19243
2014-06-26 18:22:54 +00:00
Dmitri Hrybenko
108ab1a83e stdlib/Unicode: restore the comment that explains why the function is
@noinline; it might be useful for someone reading the code


Swift SVN r19233
2014-06-26 14:07:20 +00:00
Dmitri Hrybenko
0e8d76f13b stdlib/Unicode: add @noinline to a large error handling function
Swift SVN r19232
2014-06-26 14:04:37 +00:00
Dmitri Hrybenko
4671211ce3 stdlib/String: fix two bugs in UnicodeScalarView
If underlying NSString contained isolated surrogates, then we were crashing in
following ways:

- subscripting by index could crash;

- index pointing to the second code unit sequence was not moved backwards
  correctly.  Instead of moving it to pointing to the beginning of the view it
  could be moved to point to the code unit before the beginning of the view.



Swift SVN r19230
2014-06-26 13:47:00 +00:00
Dmitri Hrybenko
990960850f stdlib, tests: fix some more 'predecessor' names that should have been
changed to 'predicate' instead


Swift SVN r19229
2014-06-26 09:13:02 +00:00
Dave Abrahams
1fb11d623b [stdlib] Remove _buffer requirement from ArrayType
Until we get an optimizer pass to remove get/set pairs, passing a
property that is a protocol requirement as inout from generic code is
always going to cause an extra retain, causing many unintended Array
copies.

Because this dropped reference counts to 1 in some cases, it exercised
previously-untested code paths and uncovered bugs, particularly in the
handling of subrange replacement on Slice<T>.

There are still differences in speed for short arrays of CGPoint that bear
investigation, but at least as things scale up, the ratio of time goes
to 1.

Fixes <rdar://problem/17040913> append and += on an array have
completely different performance

Swift SVN r19228
2014-06-26 08:54:07 +00:00
Dave Abrahams
321d608935 [stdlib] 80-column / endline layout fix
Swift SVN r19227
2014-06-26 08:53:50 +00:00
Joe Groff
687e1c5174 stdlib: Migrate some stdlib convenience APIs to UnsafePointer.
Give UnsafePointer versions of CMutablePointer._setIfNonNil and _withBridgeObject/Value. Also provide a version of 'withUnsafePointer' as a staging aid so that UnsafePointer can be used in place of CMutablePointer.

Swift SVN r19215
2014-06-26 01:51:45 +00:00
Dave Abrahams
d1aa6fe2b8 [stdlib] Rename Array internals for clarity
Because _demandUniqueMutableBuffer returns nil if the buffer already
exists, rename to _createUniqueMutableBuffer.

Because _requestUniqueMutableBuffer may return native backing storage
for a slice whose bounds don't exactly match the backing storage, rename
to _requestUniqueMutableBackingBuffer

Swift SVN r19214
2014-06-26 01:49:54 +00:00
Dave Abrahams
f146b40401 [stdlib] 80-column fix
Swift SVN r19213
2014-06-26 01:49:53 +00:00
Enrico Granata
c696acfefb Add mirrors for Range and related objects. The format of the output is clearly not final; Also, test case
Swift SVN r19208
2014-06-26 01:15:32 +00:00
Joe Groff
e2f632589a stdlib: Add subscript and .null() interfaces to AutoreleasingUnsafePointer.
To make it more UnsafePointer-like.

Swift SVN r19206
2014-06-26 01:02:01 +00:00
Joe Groff
8eec49e50c stdlib: Introduce a staging typealias for the itemsPtr of fast enumeration states.
We (correctly) import this as AutoreleasingUnsafePointer instead of UnsafePointer in the new regime, but need to stage out the old regime fully before switching over.

Swift SVN r19200
2014-06-26 00:21:20 +00:00
Joe Groff
cd418a944c stdlib: Add explicit AutoreleasingUnsafePointer(*UnsafePointer) constructors.
Allow these explicit conversions by constructor, the same way we do between UnsafePointer and ConstUnsafePointer.

Swift SVN r19199
2014-06-26 00:21:20 +00:00
Manman Ren
0501da8f54 [stdlib] use noinline to get rid of closure.
Remove wrapping the callee in a closure to disable inlining, instead mark callee
as noinline.

No performance change is observed.


Swift SVN r19194
2014-06-25 23:50:14 +00:00
Doug Gregor
37df5c430c Update standard library to use [T] array syntax.
Swift SVN r19190
2014-06-25 23:39:20 +00:00
Enrico Granata
1860612161 Add reflection support for Swift.Character. Testing will follow
Swift SVN r19189
2014-06-25 23:36:52 +00:00
Dmitri Hrybenko
6b2c727850 stdlib/String: change UTF-16/UTF-16 transcoder in UTF16View to replace
ill-formed code unit sequences with U+FFFD

rdar://17451259


Swift SVN r19187
2014-06-25 22:28:33 +00:00
Manman Ren
544cd15eb9 [stdlib] add noinline on makeUnique.
Swift SVN r19174
2014-06-25 18:39:49 +00:00
Nadav Rotem
a3d2883887 Refactor the makeUnique parts of array subscript outside of the closure. We inline this closure with the new pass order.
Swift SVN r19164
2014-06-25 17:13:50 +00:00
Joe Groff
87dd6ed419 stdlib: Add #ifs to help stage in pointer conversions.
Hide the bridged C*Pointer types if the stdlib is built with -DENABLE_POINTER_CONVERSIONS as a temporary transition aid.

Swift SVN r19159
2014-06-25 16:37:25 +00:00
Dmitri Hrybenko
6bb6e1b0b4 stdlib/String: if we can not get a contiguous data buffer out of NSString,
don't call into CoreFoundation to perform UTF-8 transcoding.  CoreFoundation
can replace ill-formed sequences with a single byte, which is not good enough
to implement U+FFFD insertion.  Instead, use the same transcoding routine as
for contiguous buffer.

Pulled out the transcoding routine into a generic function that should be
specialized and simplified for the case when input is UnsafeArray; we should
not be losing efficiency here.

Fixes <rdar://problem/17297055> [unicode] println crashes when given string
with unpaired surrogate



Swift SVN r19157
2014-06-25 13:24:15 +00:00
Jordan Rose
ce4dcb7a5f [ClangImporter] Import C function types as CFunctionPointer<T>.
...where T is the equivalent Swift function type. This gives us proper type
safety (ish) for C function pointers while still not treating them the same
as Swift closures.

If the function type is not one we can represent in Swift, we fall back to
COpaquePointer. CFunctionPointer<T> and COpaquePointer can be explicitly
constructed from one another, but do not freely convert.

<rdar://problem/17215978>

Swift SVN r19154
2014-06-25 00:33:06 +00:00
Ted Kremenek
0ce574eb9e Correct mistake where some 'pred' arguments became 'predecessor' instead of 'predicate'.
Thanks to Dmitri and Joe for pointing this out.

Swift SVN r19151
2014-06-24 23:47:00 +00:00
Dmitri Hrybenko
9bd0b1e8d3 stdlib: fix some bugs in UTF-16/UTF-8 transcoder that is hidden inside String
implementation:

- don't crash on NSStrings that contain isolated surrogates (partial fix, there
  is a different code path that dispatches CoreFoundation and it still
  crashes);

- insert U+FFFD according to Unicode recommendation;

- fix decoding of surrogate pairs when the internal buffer is almost full
  (we used to drop characters in that case, rdar://16833733 + dups).


Swift SVN r19147
2014-06-24 21:59:19 +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
Joe Groff
0db8de1341 SILGen: Implement inout-to-pointer conversion.
For writeback through an AutoreleasingUnsafePointer, create an intrinsic AutoreleasingWritebackComponent we can append to lvalues.

Swift SVN r19134
2014-06-24 15:11:41 +00:00
Enrico Granata
2ab2e6c07b Change the very cryptic "don't ask" to something more informative
Fixes <rdar://problem/16922703>



Swift SVN r19123
2014-06-24 01:50:02 +00:00
Jordan Rose
678bbfe683 [stdlib] Remove posix_read/posix_write asmname stubs.
...and move them into the one prototype that uses them. Also modernize
the interfaces a bit.

Swift SVN r19120
2014-06-24 01:23:05 +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
3cdc901354 stdlib/Unicode: fix UTF-32 decoder not to crash on invalid code units
Also implemented U+FFFD insertion in UTF-32 decoder according to Unicode
reccomendation.


Swift SVN r19092
2014-06-23 15:40:22 +00:00
Dmitri Hrybenko
2103b1d995 stdlib/Unicode: fix UTF-16 decoder not to crash on invalid code unit sequences
Also implemented U+FFFD insertion in UTF-16 decoder according to Unicode
reccomendation.


Swift SVN r19091
2014-06-23 14:52:24 +00:00
Joe Groff
1a1683e813 stdlib: Add internal entry points that can be used by intrinsic pointer conversions.
Swift SVN r19084
2014-06-22 20:10:19 +00:00
Doug Gregor
22dc55058e Make bridgeFromObjectiveC return non-optional.
Now that we use bridgeFromObjectiveCConditional to perform conditional
bridging, make bridgeFromObjectiveC handle forced bridging. For the
latter, deferred checking is acceptable.

Almost all of <rdar://problem/17319154>.


Swift SVN r19046
2014-06-20 13:15:41 +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
Doug Gregor
fd62de4373 Use bridgeFromObjectiveCConditional where we want conditional bridging.
More of <rdar://problem/17319154>.


Swift SVN r19038
2014-06-20 07:41:50 +00:00
Michael Gottesman
8de060ff3f Revert "[stdlib] mask unused bits in uniqueness checks"
Revert "[stdlib] Use an enum for ArrayBuffer storage"

This reverts commit r18996.
This reverts commit r18954.

The optimizer is not ready yet to handle this change especially given
the time until Beta 3. After speaking with DaveA, we agreed to revert
this and take such large changes onto private branches until we are sure
that the optimizer is ready to handle them rather than risking
performance regressions due to hitting the "optimization cliff".

Swift SVN r19026
2014-06-20 01:41:04 +00:00
Dmitri Hrybenko
c4fd1c4092 stdlib: explain the trick used to achieve @noinline without @noinline
Swift SVN r19018
2014-06-19 23:53:09 +00:00
Jordan Rose
f60213e4e6 Update Joe's UnsafePointer changes to account for Chris's ..< changes.
Swift SVN r19010
2014-06-19 18:09:55 +00:00
Jordan Rose
fe5c879a1a Work around single-expression closure not returning Void.
Swift SVN r19009
2014-06-19 18:04:21 +00:00
Chris Lattner
63e34d727c fix doc comment.
Swift SVN r19007
2014-06-19 18:02:31 +00:00
Chris Lattner
444d835d00 implement <rdar://problem/17054014> map method should exist on ranges
Swift SVN r19006
2014-06-19 18:01:05 +00:00
Kuba Brecka
1da7379ff2 Changing putchar's prototype to match the C version (missing return type).
Swift SVN r19005
2014-06-19 17:32:30 +00:00