Commit Graph

1309 Commits

Author SHA1 Message Date
Dmitri Hrybenko
2b5d0166c5 stdlib: underscore-prefix MaxBuiltinIntegerType and MaxBuiltinFloatType
Swift SVN r20388
2014-07-23 11:40:45 +00:00
Dmitri Hrybenko
37cd51b76a stdlib: don't use 'private' in stdlib
In this case, internal is as good as private.


Swift SVN r20387
2014-07-23 11:07:50 +00:00
Dmitri Hrybenko
09561ae6fa stdlib/Printing: when printing objects without Printable conformances, print
demangled names

rdar://16929868


Swift SVN r20386
2014-07-23 11:01:51 +00:00
Pete Cooper
e0add45e63 Add isInBounds to stdlib and use this for bounds checking on array subscript.
Ultimately this gets to HeapBuffer which checks the index is in range by separately checking whether the storage is nil, then the index is less than the count

Swift SVN r20363
2014-07-23 02:53:45 +00:00
Dave Abrahams
df33434197 Revert "[stdlib] Remove protocol availability annotations"
I think I did this too early; it's supposed to be after Beta5.
This reverts r20348

Swift SVN r20350
2014-07-22 23:44:00 +00:00
Dave Abrahams
d6eaa1b156 [stdlib] Remove protocol availability annotations
These were for the transition from Beta 3 to Beta 4.  Now that we've
shipped Beta 4, they're obsolete.  Fixes <rdar://problem/17672088>

Swift SVN r20348
2014-07-22 23:42:28 +00:00
Dave Abrahams
478c41fa3c [stdlib] Drop withUnsafe[Mutable]PointerToElements
Now that arrays have withUnsafe[Mutable]BufferPointer, and the buffer
pointers have a baseAddress property, this API is obsolete.

Swift SVN r20347
2014-07-22 23:04:45 +00:00
Joe Pamer
e783ab1c0d Support equality comparisons between 'nil' and non-equatable optional types (rdar://problem/17489239)
To facilitate the removal of the BooleanType conformance from Optional<T>, we'll first need to support
equality comparisons between the 'nil' literal and optionals with non-equatable element types.

We can accomplish this via three changes:
- New overloads for "==" and "!=" that we can resolve against non-equatable optionals
- A tweak to our overload resolution algorithm that, when all other aspects of two overloads are
  considered equal, would favor the overload with a more "constrained" type parameter. This allows
  us to avoid ambiguities between generic overloads that are distinct, but whose parameters do not
  share a pairwise subtype relationship.
- A gross hack to favor overloads that do not require bindings to 'nil' when presented with an
  otherwise ambiguous set of solutions. (Essentially, in the face of a potential ambiguity, favor solutions
  that do not require bindings to _OptionalNilComparisonType over those that do.)

The third change is only necessary because we currently lack the ability to specify "negative" or
otherwise more expressive constraints, so we'll want to rethink the hack post-1.0. (I've filed
rdar://problem/17769974 to cover its removal.)

Swift SVN r20346
2014-07-22 22:59:07 +00:00
Dave Abrahams
00f9ca5eda [stdlib] Rename [_]elementStorage=>[_]baseAddress
Swift SVN r20342
2014-07-22 22:29:03 +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
e570866bf6 [stdlib] On-demand unique contiguous Array storage
Lift the precondition that contiguous storage already exist on the use
of Array.withUnsafe[Mutable]PointerToElements.  Automatically guarantee
that storage is unique when using the mutable variants of these methods.

Also, fix some---essentially---inout aliasing violations in
test/stdlib/Unicode.swift that were revealed by the new careful
implementation of these methods.

Swift SVN r20339
2014-07-22 21:34:57 +00:00
Dave Abrahams
dfe2ba4d8d [stdlib] const-correct withUnsafePointer APIs
Fixes <rdar://problem/17364737>

Swift SVN r20329
2014-07-22 20:39:59 +00:00
Dave Abrahams
1a6c80a93d [stdlib] .first and .last are var:T?, not func->T
The global first() and last() algorithms return T?, nil when empty

All .first() and .last() methods became T? vars that are nil when the
Collection is empty

Swift SVN r20326
2014-07-22 19:30:42 +00:00
Dmitri Hrybenko
1c2cd46094 stdlib/Printing: fix pointer printing on 32-bit platforms
Swift SVN r20325
2014-07-22 19:03:04 +00:00
Dave Abrahams
1438d617cd [stdlib] Rename ConstUnsafePointer=>UnsafePointer
Swift SVN r20318
2014-07-22 17:10:54 +00:00
Dave Abrahams
03dca56669 Add merges missed in r20316
Swift SVN r20317
2014-07-22 17:02:12 +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
80748a5883 stdlib/Printing: add DebugPrintable conformances to unsafe pointer types
rdar://16896025 rdar://16896013

Swift SVN r20312
2014-07-22 16:06:47 +00:00
Dmitri Hrybenko
d5e7ffb2a1 stdlib/Unicode: remove a stale comment
Swift SVN r20310
2014-07-22 15:28:07 +00:00
Dmitri Hrybenko
d14f17beef Change 'getLogicValue()' into a property 'boolValue'; change
'getArrayBoundValue()' into a property 'arrayBoundValue'.

rdar://17156123


Swift SVN r20304
2014-07-22 12:08:10 +00:00
Joe Groff
54fb27b9a2 Mark assignment operators in the stdlib as 'assignment'.
Swift SVN r20296
2014-07-22 05:16:04 +00:00
Dave Abrahams
2c3ab47cf2 [stdlib] O(1) Array<non-verbatim> round-tripping
Arrays of non-verbatim-bridged types (such as Int, and today's String)
are converted to Objective-C lazily, with the objects created due to
element conversion being autoreleased when necessary.

Fixes <rdar://problem/17360154>

Note: test/SIL/Parser/array_roundtrip.swift was XFAIL'd;
see <rdar://problem/17758203>

Swift SVN r20293
2014-07-22 04:42:47 +00:00
Dave Abrahams
079b5e57ef [stdlib] += no longer appends array elements
+= only extends arrays with another sequence of the same element type.

Fixes <rdar://problem/17151420> The use of the overloaded += operator in
Swift is inconsistent and confusing with Arrays.

Note that this commits generated 3 new radars against the type checker:

  <rdar://problem/17751308>
  <rdar://problem/17750582>
  <rdar://problem/17751359>

Swift SVN r20274
2014-07-21 20:07:13 +00:00
Chris Lattner
bc481f0fe1 implement <rdar://problem/16859927> remove the underscore in "auto_closure"
autoclosure is one work, not two.



Swift SVN r20253
2014-07-21 15:23:50 +00:00
Dmitri Hrybenko
2af9bc954a stdlib/Dictionary: underscore-prefix implementation details (even not
marked as public)

Swift SVN r20245
2014-07-21 08:31:32 +00:00
Dmitri Hrybenko
e6d2194b22 stdlib/String: trap when attempting to increment or index using
String.UTF8View.endIndex

rdar://17539993

Swift SVN r20244
2014-07-21 08:31:30 +00:00
Dave Abrahams
3731a0d1d2 [stdlib] Deal with various zero-division scenarios
Primarily, this means becoming resilient to Builtin.strideof(x) == 0.
Pretty much the only way to get pointers and arrays to make sense is to
treat zero-sized elements as having a stride of 1, so we do that in our
wrapper for Builtin.strideof.  Other points include precondition checks
for radixes in number formatting.

Fixes <rdar://problem/17097768>

Swift SVN r20242
2014-07-21 05:21:22 +00:00
Dave Abrahams
8e853fd0d4 [stdlib] Add isEmpty first() and last() to lazy collections
<rdar://problem/16953693> part 3 of 3

Swift SVN r20239
2014-07-21 03:27:17 +00:00
Dave Abrahams
c9e55b48c4 [stdlib] Add first() and last() to Array types
Also, tests for the isEmpty property

<rdar://problem/16953693> part 2 of 3

Swift SVN r20238
2014-07-21 03:27:17 +00:00
Dave Abrahams
a1c1d09c6c [stdlib] Add first, last, and isEmpty algorithms
<rdar://problem/16953693> part 1 of 3

Swift SVN r20237
2014-07-21 03:27:15 +00:00
Chris Lattner
56dbab6421 move prefix+ up to being next to prefix-, NFC.
Swift SVN r20235
2014-07-20 22:18:35 +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
de368b9070 [stdlib] Make algorithms safe with illegal predicates
Even if the user supplies an ordering predicate that isn't a strict-weak
ordering, algorithms should not index beyond their bounds.  Otherwise, a
use of withUnsafeMutableStorage for optimization purposes could easily
do an unsafe memory access.

This commit comments and tests our algorithms that require strict weak
orderings, and fixes safety problems in partition().  Most benchmarks
are unaffected, but the rewrite of partition produces a 27% speedup in
the Phonebook benchmark at -O3 and a 22% speedup at -Ofast.

Also, at -Ofast, QuickSort lost 6% and RC4 gained 6%.  These benchmarks
were not noticeably affected at -O3

====================`PrecommitBench_O3`====================
````benchmark`,`baserun0`,`baserun1`,`baserun2`,``optrun0`,``optrun1`,``optrun2`,``delta`,`speedup`
````Phonebook`,``1608.00`,``1676.00`,``1651.00`,``1265.00`,``1278.00`,``1281.00`,`343.00`,```27.1%`
````QuickSort`,```430.00`,```448.00`,```429.00`,```428.00`,```431.00`,```428.00`,```1.00`,````0.2%`
``````````RC4`,```925.00`,```924.00`,```922.00`,```916.00`,```919.00`,```917.00`,```6.00`,````0.7%`
====================`PrecommitBench_Ofast`====================
````benchmark`,`baserun0`,`baserun1`,`baserun2`,``optrun0`,``optrun1`,``optrun2`,``delta`,`speedup`
````Phonebook`,``1521.00`,``1546.00`,``1591.00`,``1252.00`,``1255.00`,``1256.00`,`269.00`,```21.5%`
````QuickSort`,```478.00`,```477.00`,```476.00`,```506.00`,```510.00`,```513.00`,``30.00`,```-5.9%`
``````````RC4`,``1033.00`,``1874.00`,``1030.00`,```974.00`,```982.00`,```975.00`,``56.00`,````5.7%`

Swift SVN r20202
2014-07-19 01:51:03 +00:00
Dave Abrahams
6bbbf052a3 [stdlib] _partition doesn't need to be public!
Thanks, Jordan

Swift SVN r20194
2014-07-19 00:38:48 +00:00
Dave Abrahams
ec8b29cdf1 [stdlib] Fix the public interface of partition
It should not take the predicate as inout!

Swift SVN r20193
2014-07-19 00:35:45 +00:00
Joe Groff
c556d92ccd SILGen: Implement codegen for lvalue ForceValueExprs.
Add a set of _preconditionOptionalHasValue intrinsics that merely test that an optional has a case. Emit an lvalue ForceValueExpr as a physical lvalue, first asserting the precondition then projecting out the Some payload.

Swift SVN r20188
2014-07-18 22:49:49 +00:00
Dave Abrahams
71913ae085 [stdlib] Rename @semantics for array bounds checks
There are two kinds of bounds check: valid for subscripting, and valid
as an index.  Rename the semantics accordingly.

Swift SVN r20181
2014-07-18 20:54:26 +00:00
Enrico Granata
e4cfd3ae0a Reflect ranges in the half-open format - it's not always consistent with what the user typed, but at least it resembles language syntax, and is more consistent with what LLDB already does too. Last chunk of work for rdar://16117421
Swift SVN r20168
2014-07-18 18:26:17 +00:00
Dave Abrahams
3a90aaf8a3 [stdlib] Ensure full bounds checking for Array
Swift SVN r20132
2014-07-18 02:40:24 +00:00
Dave Abrahams
4d704c3574 Revert "[stdlib] Array resilient slicing"
We've decided resilience is wrong for Swift given current constraints;
see rdar://problem/11940897 for more detail.

This reverts commit r20052

Swift SVN r20127
2014-07-18 00:21:22 +00:00
Dave Abrahams
a84f46ca26 [stdlib] Add prefix/suffix functions on Sliceable
Also, improve comments in Collection.swift

Swift SVN r20125
2014-07-18 00:11:44 +00:00
Dave Abrahams
4e54fafb35 [stdlib] Fix symmetry of bounded advance()
It wasn't properly handling the cases where the bound was in the
opposite direction from the amount, when advancing random access
indices.

Swift SVN r20123
2014-07-18 00:11:43 +00:00
Dmitri Hrybenko
c4138bd192 stdlib/Dictionary: coding style, remove unneeded line breaks
Swift SVN r20080
2014-07-17 09:54:40 +00:00
Dmitri Hrybenko
4c4f83fb52 stdlib: underscore-prefix requirements of _BridgedToObjectiveCType and
_ConditionallyBridgedToObjectiveCType protocols

rdar://17283639


Swift SVN r20079
2014-07-17 09:42:19 +00:00
Dave Abrahams
e2d9f6f6a5 [stdlib] Fix clamp parameter name
Thanks, Jordan!

Swift SVN r20053
2014-07-16 22:33:01 +00:00
Dave Abrahams
304f27218b [stdlib] Array resilient slicing
Partially addresses <rdar://problem/11940897> #Seed 4: Slicing should
limit to valid slices

Swift SVN r20052
2014-07-16 22:27:09 +00:00
Dave Abrahams
3d61398376 [stdlib] Add clamp method to Interval
Swift SVN r20051
2014-07-16 22:16:26 +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
Dmitri Hrybenko
d125ac1e24 stdlib/runtime: stdlib casts to existentials: correctly project the buffer as
required

rdar://17628745


Swift SVN r20024
2014-07-16 15:17:46 +00:00
Mark Lacey
41643d0ef3 Revert "Remove @transparent from a few functions in the stdlib."
This reverts commit r19996.

I'll either fix <rdar://problem/17687851>, or work around it in a
different way.

Swift SVN r20020
2014-07-16 08:09:56 +00:00