Commit Graph

48 Commits

Author SHA1 Message Date
Dave Abrahams
cb27b7d821 [stdlib] Excise unsafeBitCasts from SliceBuffer
Swift SVN r23192
2014-11-09 04:53:35 +00:00
Dave Abrahams
2794fe3a13 [stdlib] Restore a combination of 11 commits
...but remove all new uses of closures, to make things easier on the
optimizer.

Swift SVN r23183
2014-11-08 20:04:29 +00:00
Dave Abrahams
c77d7e353c Revert a combination of 11 commits
These commits are suspected of causing performance regressions:

r22995, "[stdlib] Array nil state elimination, part trois"
r22994, "[stdlib] Array nil-state elimination II"
r22993, "[stdlib] Array nil-state elimination I"
r22992, "[stdlib] Still more nil buffer elimination"
r22991, "[stdlib] Nix an unneeded typealias"
r22988, "[stdlib] Nix _ContiguousArrayBuffer._base, part deux"
r22986, "[stdlib] Kill _ContiguousArrayBuffer._base, part I"
r22985, "[stdlib] destroy redundant property"
r22975, "[stdlib] More array nil-state destruction"
r22974, "[stdlib] Construct HeapBuffer without AnyObject"
r22959, "[stdlib] non-nil ContiguousArray"

Swift SVN r23001
2014-10-29 02:57:45 +00:00
Dave Abrahams
f7bf9bf16d [stdlib] Still more nil buffer elimination
Swift SVN r22992
2014-10-28 18:00:55 +00:00
Dave Abrahams
7c8364fb52 [stdlib] More array nil-state destruction
Baby steps.

Swift SVN r22975
2014-10-27 22:36:24 +00:00
Dave Abrahams
1a9f96e1c7 [stdlib] Drop unneeded protocol requirement
Conversion to cocoa is not a common requirement for all models of
_ArrayBufferType

Swift SVN r22947
2014-10-26 18:29:42 +00:00
Dave Abrahams
69194280a7 [stdlib] Nix an unused protocol and rename another
Swift SVN r22791
2014-10-16 03:46:34 +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
4bdb9462c7 [stdlib] ArrayBufferType: identity is base address
Buffer identity is only used by tests.  The switch to an identity
representation that accounts for the buffer length was actually
incorrect for the way many tests used it.

Swift SVN r22771
2014-10-15 20:27:57 +00:00
Dave Abrahams
ab69e26656 [stdlib] Actually run the ArrayCore test
Fixes rdar://problem/18646425

Running the test uncovered avoidable inefficiencies in Array copying, so
dispatch of _copyToNativeArrayBuffer was revamped.  It's reasonable to
expect some speedups from this.

Also, the internal Array API requestNativeBuffer was highly error prone
when the source was a Slice, because it could return an array buffer
that represented more than the entire slice.  That capability was
probably used for optimization once, but is no longer, and the error
prone API probably caused bugs, so it was reformed.

Swift SVN r22746
2014-10-15 03:24:47 +00:00
Dave Abrahams
eac8ca27f9 [stdlib] Use a universal empty array buffer
NFC, and no significant performance change expected.  This is part one
of a move to eliminate nil checks from the array implementation.

Swift SVN r22526
2014-10-05 17:55:11 +00:00
Dave Abrahams
b740ad0df9 Revert "[stdlib] Use a universal empty array buffer"
This reverts commit r22495, because it wroke havoc with SIL and the perf
test suite somehow.

Swift SVN r22499
2014-10-03 18:52:11 +00:00
Dave Abrahams
f2f068c3dc [stdlib] Use a universal empty array buffer
NFC, and no significant performance change expected.  This is part one
of a move to eliminate nil checks from the array implementation.

Swift SVN r22495
2014-10-03 16:01:50 +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
Dave Abrahams
f4a7812065 [stdlib] Propagate SequenceType docs to models
235 undocumented public APIs remain in core

Swift SVN r22210
2014-09-23 10:40:37 +00:00
Dave Abrahams
1dd7272fe9 [stdlib] Propagate CollectionType docs to models
266 undocumented public APIs remain in core

Swift SVN r22206
2014-09-23 08:19:23 +00:00
Dmitri Hrybenko
e6e17ac7d4 stdlib: replace _CocoaArrayType with _SwiftNSArrayRequiredOverridesType
Swift SVN r21972
2014-09-16 12:53:00 +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
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
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
Dave Abrahams
00f9ca5eda [stdlib] Rename [_]elementStorage=>[_]baseAddress
Swift SVN r20342
2014-07-22 22:29:03 +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
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
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
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
Dmitri Hrybenko
86f58123f9 stdlib/Array: hide some Array implementation details:
ArrayBuffer
ArrayBufferType
ContiguousArrayBuffer
ContiguousArrayStorage
IndirectArrayBuffer
SliceBuffer

Unfortunately, can not remove 'public' from them since they are used by
Foundation overlay in bridging code.


Swift SVN r19810
2014-07-10 14:30:54 +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
Jordan Rose
faa4004b42 [Accessibility] Public types/functions cannot have private generic parameters.
Or rather, they cannot have constraints on their generic parameters that use
private types.

Swift SVN r19644
2014-07-07 22:52:29 +00:00
Dmitri Hrybenko
1911aaed9f stdlib: hide isUniquelyReferenced
Swift SVN r19598
2014-07-07 10:01:48 +00:00
Dmitri Hrybenko
62c772ad6a stdlib: hide Objective-C bridging implementation details
Swift SVN r19595
2014-07-07 09:46:07 +00:00
Jordan Rose
f746b8c6dd [Accessibility] Public variables cannot have private types.
This does not yet handle variables with inferred types, since those don't
have TypePatterns.

There is some nasty propagation of @public into the stdlib because of this
one, mainly because Foundation needs access to some of the implementation
details of Array and Dictionary. We may want to try to improve this later
(or just build Foundation with -disable-access-control if it comes to that).

Swift SVN r19432
2014-07-01 22:30:53 +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
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
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
Dave Abrahams
85533dd7d3 [stdlib] Restore Array value semantics
'nuff said.

Swift SVN r18923
2014-06-16 13:56:15 +00:00
Argyrios Kyrtzidis
b1914701e9 [stdlib] In ContiguousArrayBuffer<T>, vars 'storage' and 'base' where under the 'private' section
so I took the liberty to 'privatize' them with a leading underscore.

This also completely removes '_ArrayBody' from the public interface.
Should be NFC, apart from the public interface change.

Swift SVN r18625
2014-05-25 04:31:13 +00:00
Doug Gregor
67ca1c9ea1 Implement the new casting syntaxes "as" and "as?".
There's a bit of a reshuffle of the ExplicitCastExpr subclasses:
  - The existing ConditionalCheckedCastExpr expression node now represents
"as?". 
  - A new ForcedCheckedCastExpr node represents "as" when it is a
  downcast.
  - CoerceExpr represents "as" when it is a coercion.
  - A new UnresolvedCheckedCastExpr node describes "as" before it has
  been type-checked down to ForcedCheckedCastExpr or CoerceExpr. This
  wasn't a strictly necessary change, but it helps us detangle what's
  going on.

There are a few new diagnostics to help users avoid getting bitten by
as/as? mistakes:
  - Custom errors when a forced downcast (as) is used as the operand
  of postfix '!' or '?', with Fix-Its to remove the '!' or make the
  downcast conditional (with as?), respectively.
  - A warning when a forced downcast is injected into an optional,
  with a suggestion to use a conditional downcast.
  - A new error when the postfix '!' is used for a contextual
  downcast, with a Fix-It to replace it with "as T" with the
  contextual type T.

Lots of test updates, none of which felt like regressions. The new
tests are in test/expr/cast/optionals.swift. 

Addresses <rdar://problem/17000058>


Swift SVN r18556
2014-05-22 06:15:29 +00:00
Dmitri Hrybenko
2fc5297171 stdlib/Slice: relax assertion to allow Slice<T> to be constructed from a native
empty buffer without storage

rdar://16971593 rdar://16388632


Swift SVN r18489
2014-05-21 11:01:55 +00:00
Ted Kremenek
16dea15a24 Hide CocoaArray ('_' to mark as private API).
Swift SVN r18302
2014-05-18 04:03:32 +00:00
Doug Gregor
bed81488c1 Revert r18232, r18220: we're not doing T* now.
Swift SVN r18250
2014-05-17 16:36:02 +00:00
Dave Abrahams
46388dd5e2 [stdlib] Unwrap some lines shrunken by T*
Concision FTW!

Swift SVN r18232
2014-05-17 00:27:43 +00:00
Doug Gregor
73f02d1a69 Switch a bunch of UnsafePointer<T>'s over to T*
Swift SVN r18220
2014-05-16 22:32:01 +00:00
Arnold Schwaighofer
da6d9152b6 Differentiate between user assertion and preconditions and the like
assert() and fatalError()
These functions are meant to be used in user code. They are enabled in debug
mode and disabled in release or fast mode.

_precondition() and _preconditionFailure()
These functions are meant to be used in library code to check preconditions at
the api boundry. They are enabled in debug mode (with a verbose message) and
release mode (trap). In fast mode they are disabled.

_debugPrecondition() and _debugPreconditionFailure()
These functions are meant to be used in library code to check preconditions that
are not neccesarily comprehensive for safety (UnsafePointer can be null or an
invalid pointer but we can't check both). They are enabled only in debug mode.

_sanityCheck() and _fatalError()
These are meant to be used for internal consistency checks. They are only
enabled when the library is build with -DSWIFT_STDLIB_INTERNAL_CHECKS=ON.

I modified the code in the standard library to the best of my judgement.

rdar://16477198

Swift SVN r18212
2014-05-16 20:49:54 +00:00
Dave Abrahams
b666651e3f [stdlib] Rename NativeArray => ContiguousArray
Per API review feedback.

Swift SVN r18140
2014-05-15 23:24:09 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Dave Abrahams
004998e63e [stdlib] Move SliceBuffer into its own file
Swift SVN r15766
2014-04-02 02:47:34 +00:00