Commit Graph

5263 Commits

Author SHA1 Message Date
David Farler
8f2fbdc93a Make function parameters and refutable patterns always immutable
All refutable patterns and function parameters marked with 'var'
is now an error.

- Using explicit 'let' keyword on function parameters causes a warning.
- Don't suggest making function parameters mutable
- Remove uses in the standard library
- Update tests

rdar://problem/23378003
2015-11-09 16:56:13 -08:00
Erik Eckstein
971a680199 Support for stack promotion of array buffers in the stdlib.
The basic idea is to move the allocation of the buffer out of @_semantics("array.uninitialized") so that it can be inlined without inlining the semantics function (on high-level SIL).

This change in the stdlib also requires an adaption of the dead area elimination in DeadObjectElimination.
Otherwise it would just remove the semantics function but not the allocation and we would leak memory.
2015-11-05 16:52:59 -08:00
Maxwell Swadling
5d52666132 Improved the performance of _dictionaryBridgeFromObjectiveCConditional by specifying the minimumCapacity up front. NFC 2015-11-05 12:01:30 -08:00
Maxwell Swadling
933c973551 Revert "Improved the performance of _dictionaryBridgeFromObjectiveCConditional by only allocating a _NativeDictionaryStorage once all the items are bridged. NFC"
This reverts commit e001efc741.

A faster approach is to reserve the memory with minimumCapacity.
2015-11-05 12:01:30 -08:00
Maxwell Swadling
e001efc741 Improved the performance of _dictionaryBridgeFromObjectiveCConditional by only allocating a _NativeDictionaryStorage once all the items are bridged. NFC 2015-11-04 14:30:31 -08:00
Joe Groff
4fb68c8a1a stdlib & Runtime: Replace atomic RMW stubs with builtins.
Swift SVN r32954
2015-10-28 23:47:40 +00:00
Joe Groff
527221ff4d stdlib & Runtime: Replace atomicStore/Load stubs with builtins.
Swift SVN r32953
2015-10-28 23:04:35 +00:00
Joe Groff
eb330480cb stdlib & Runtime: Replace _swift_stdlib_atomicCompareExchangeStrong* stubs with Builtin calls.
NFC intended.

Swift SVN r32934
2015-10-28 01:58:52 +00:00
Dmitri Hrybenko
8df3dd331e Remove standard library hooks for AppKit apps in the integrated REPL
The REPL code can be simplified now.

Swift SVN r32882
2015-10-25 08:27:42 +00:00
Dmitri Hrybenko
2e51d23875 Un-ifdef object literals
Swift SVN r32880
2015-10-25 07:50:53 +00:00
Dmitri Hrybenko
9383927356 stdlib: trap correctly in floating-point to unsigned integer conversion
Uncovered by Dave's fixes to gyb.

<rdar://problem/23247773>

Swift SVN r32879
2015-10-25 04:53:37 +00:00
Dave Abrahams
98f612aef3 [stdlib] warning suppression
Swift SVN r32874
2015-10-24 16:51:36 +00:00
Dave Abrahams
a795fcd12c Remove stray debug print
Left this in by mistake

Swift SVN r32872
2015-10-24 14:48:13 +00:00
Dave Abrahams
b3ca7eed40 gyb parsing fixes
Fixes <rdar://problem/18900352> gyb miscompiles nested loops

Swift SVN r32863
2015-10-24 04:47:57 +00:00
David Farler
3434f9642b Disallow 'var' pattern bindings in if, while, and guard statements
Make the following patterns illegal:

  if var x = ... {
    ...
  }

  guard var x = ... else {
    ...
  }

  while var x = ... {
    ...
  }

And provide a replacement fixit 'var' -> 'let'.

rdar://problem/23172698

Swift SVN r32855
2015-10-24 01:46:30 +00:00
Andrew Trick
60d23310c1 For unsafeReferenceCast rely on type checks in the runtime.
<slight revision of yesterday's reverted commit>

The debugAsserts were nicely self-documenting, but generate an obscene
amount of useless SIL code that is inlined everywhere and sticks around
when we compile the stdlib. The old asserts would need to be fixed to
support Optionals but that makes the situation much worse.

Why is it ok to remove the asserts?
_unsafeReferenceCast remains an internal API.
If the src/dest types are not loadable reference types, the cast will
not be promoted to a value bitcast.
The remanining cases will be dynamically checked by swift_dynamicCast.

Swift SVN r32828
2015-10-22 18:19:24 +00:00
Arnold Schwaighofer
7fa673c6bc Revert "stdlib: Replace unsafeBitCast calls with unsafeCastReference."
Revert "For unsafeReferenceCast rely on static verifier checks."

This reverts commit r32796.
This reverts commit r32795.

They very likely broke a buildbot.

Swift SVN r32813
2015-10-21 22:06:01 +00:00
Andrew Trick
b1b07ef0fa stdlib: Replace unsafeBitCast calls with unsafeCastReference.
unsafeBitCast should only be used when we actually need to lie to the type system (as opposed to just having an unchecked downcast).

Theses are the places where unsafeReferenceCast makes sense:
(In general it makes sense whenever the source & dest are class or class existential types)

- ArrayBuffer.getElement.

  The deferred downcast case cannot be benchmarked. It is never on the critical path.

  The ObjC array case cannot conceivably matter either, however, it is touched by
  DollarChain, JSONHelperDeserialize, and StrSplitter.
  These benchmarks do not regress at -O.

- arrayForceCast

  No regressions at -O based on microbenchmarks.

None of these remaining cases affect PerfTestSuite at -O:

- General ObjC bridging

- Set/Dictionary bridging

- String bridging

- AutoreleasingUnsafeMutablePointer

These are confirmed speedups but I did not investigate the cause:

|.Chars...................|.32.1%.|
|.Sim2DArray..............|.15.4%.|
|.Calculator..............|.13.0%.|
|.RecursiveOwnedParameter.|..7.9%.|

Swift SVN r32796
2015-10-21 19:41:57 +00:00
Andrew Trick
98d17a5236 For unsafeReferenceCast rely on static verifier checks.
The debugAsserts were nicely self-documenting, but generate an obscene
amount of useless SIL code that is inlined everywhere and sticks around
when we compile the stdlib. The old asserts would need to be fixed to
support Optionals but that makes the situation much worse.

Why is it ok to remove the asserts?
_unsafeReferenceCast remains an internal API. The invariants are checked
statically whenever the routine is specialized, and dynamically checked
by the runtime cast.

Swift SVN r32795
2015-10-21 19:41:54 +00:00
Dave Abrahams
912a00cfad [stdlib] More Array Refactoring
w/Dmitri and Arnold, making incremental progress towards comprehensible
code.

Swift SVN r32716
2015-10-16 00:08:03 +00:00
Dmitri Hrybenko
57d296772f stdlib: remove _Strideable
Swift SVN r32675
2015-10-14 03:37:19 +00:00
Dmitri Hrybenko
371e189608 stdlib: tighten constraints on MutableCollectionType.SubSequence
Swift SVN r32674
2015-10-14 01:38:12 +00:00
Dave Abrahams
fd4a9cd658 [stdlib] Fix typo in doc comment
Swift SVN r32667
2015-10-13 20:56:57 +00:00
Andrew Trick
f3e5b1d5af Convert unsafeDownCast to use Builtin.castReference.
Generally avoid casting to a raw pointer unless a raw pointer is needed.
Builtin.castReference is now the canonical way to cast reference types.
Canonical generally = better optimizer. In practice this will reduce to
the same SIL since the stdlib code will be optimized.

There are enough unit tests for unsafeDowncast and Builtin.castReference.

I measured no performance regressions.

Swift SVN r32646
2015-10-13 01:07:54 +00:00
Andrew Trick
8007dc8cfa Add Builtin.castReference and internal API _unsafeCastReference.
_unsafeCastReference allows casting of any references types, regardless
of whether they are references to objects or class existentials. The
implementation is responsible for converting between representations.

_unsafeCastReference provides a dynamic check to ensure that the source
and dest are both actually references. If not, the implementation will
trap at runtime. Generally, the optimizer can prove that the source
and dest are references, and promote this cast to an
unchecked_ref_cast bitcast. There is no dynamic check that the
references types are compatible.

This differs from unsafeDownCast in two ways:

(1) The source and dest types are not statically typed
AnyObjects. Therefore, unsafeCastReference can be used when the
surrounding code dynamically handles both reference and nonreference
types.

(2) The source and dest also need not dynamically conform to AnyObject.
Either side of the cast may be a class existential. The primary
requirement is that the source and dest refer to the same reference
counted object.

Swift SVN r32588
2015-10-10 03:39:34 +00:00
Dmitri Hrybenko
6536edd68c stdlib: fix coding style
Swift SVN r32425
2015-10-03 21:13:15 +00:00
Dmitri Hrybenko
f7005d520f stdlib: clean up code: arrays of functions work now
Swift SVN r32424
2015-10-03 21:13:07 +00:00
Dave Abrahams
06e32293a4 [stdlib] Attempt to fix linux build
An Array's buffer is a ContiguousArrayBuffer on Linux.

Swift SVN r32323
2015-09-29 23:52:24 +00:00
Dave Abrahams
243b528fac [stdlib] Array refactoring: simplify all array subscript checking
Swift SVN r32314
2015-09-29 22:38:59 +00:00
Dave Abrahams
ee60b5f0e2 [stdlib] Array refactoring: rewrite ArrayBuffer._isValidSubscript
Swift SVN r32313
2015-09-29 22:38:58 +00:00
Dave Abrahams
cfe877bc0a [stdlib] Array refactoring: s/hoistedIs/was/
Swift SVN r32312
2015-09-29 22:38:57 +00:00
Dave Abrahams
b1e98fe3e1 [stdlib] Array refactoring: s/NoTypeCheck/TypeChecked/
First in a long series of commits to clean up the array implementation
and make it maintainable by the stdlib team.

Swift SVN r32311
2015-09-29 22:38:56 +00:00
Dave Abrahams
5cf32911fb Array: Improve function, parameter names and add documentation
NFC.

Swift SVN r32310
2015-09-29 22:38:53 +00:00
Andrew Trick
08bc41849e Remove from unsafeBitCast argument--it doesn't need an address.
Swift SVN r32300
2015-09-29 15:42:38 +00:00
Arnold Schwaighofer
599a438015 Don't force to grow the buffer everytime we make it unique
rdar://22873620

Swift SVN r32280
2015-09-28 20:47:23 +00:00
Andrew Trick
21e7b06e77 Migrate the unsafeBitCast API to use Builtin.reinterpretCast.
This avoids unnecessary address-taking. Instead use the builtin that directly
supports unsafe casts. The optimizer now follows clear rules for
Builtin.reinterpretCast (so it's safe to use) and knows how to optimize it.

Swift SVN r32268
2015-09-28 01:58:30 +00:00
Andrew Trick
9055b274ee Use bridgeToRawPointer instead of unsafeBitCast.
Swift SVN r32264
2015-09-27 00:55:37 +00:00
Arnold Schwaighofer
66275a3ad8 Replace handrolled max by max.
Swift SVN r32250
2015-09-25 23:37:29 +00:00
Arnold Schwaighofer
9ec0c2391d Nuke the CollectionType implementation from _BitMap.
It is dead code.

Swift SVN r32249
2015-09-25 23:37:23 +00:00
Arnold Schwaighofer
fd00a80029 HashedCollections: Fix code only executed if compiled with internal checks enabled
Swift SVN r32247
2015-09-25 22:47:33 +00:00
Arnold Schwaighofer
6c88b414cd Fix _BitMap's endIndex function
Swift SVN r32246
2015-09-25 22:19:14 +00:00
Arnold Schwaighofer
a5e75311af stdlib: Implement Dictionary using a structs of arrays strategy
Instead of Optional entries use a third bitmap array to mark whether an entry is
valid. This representation saves space (because individual entries don't have a
alignment padding slack) and simplifies ARC's job leading to better performance.

Speedup measured (before/after) at -O:

DictionaryHashableClass`````````3.1
DollarFilter````````````````````1.3
DollarMap```````````````````````1.3
DollarReduce````````````````````1.4
JSONHelperDeserialize```````````1.4
NSDictionaryImplicitConversion``1.4
NSXMLParser`````````````````````1.3

Speedup measured (before/after) at -Onone:

DictOfArraysToArrayOfDicts``````1.3
Dictionary``````````````````````3.5
Dictionary2`````````````````````3.2
Dictionary3`````````````````````3.2
DictionaryHashableClass`````````1.9
DictionaryHashableStruct````````2.4
DictionaryRemove````````````````3.3
DictionarySwap``````````````````2.5
DollarFilter````````````````````1.2
DollarMap```````````````````````1.2
DollarReduce````````````````````1.3
Forest``````````````````````````1.8
Histogram```````````````````````1.6
JSONHelperDeserialize```````````1.6
NSDictionaryImplicitConversion``1.3
Prims```````````````````````````2.9
RGBHistogram````````````````````1.4

rdar://22173734

Swift SVN r32244
2015-09-25 22:05:15 +00:00
Arnold Schwaighofer
6e51e15a59 Add _sizeInBytes to fixed point types.
Swift SVN r32243
2015-09-25 22:05:15 +00:00
Arnold Schwaighofer
cc4e41cb3e Add a ispod builtin and _isPOD function to the stdlib
The builtin returns true if the argument type is a POD type: needs no special
handling for copy and destruct operations.

Swift SVN r32242
2015-09-25 22:05:14 +00:00
Dmitri Hrybenko
f57947a7e0 stdlib: fix capitalization issues in documentation comments
Patch by Nate Cook.

rdar://22054901

Swift SVN r32226
2015-09-25 17:13:54 +00:00
Dmitri Hrybenko
153d95efc6 SwiftShims: don't redeclare libc functions
Clang importer thinks that SwiftShims is the primary module where they
live, and this confuses code completion.

rdar://22488333

Swift SVN r32218
2015-09-25 03:33:50 +00:00
Dmitri Hrybenko
9da0b57178 stdlib: Add an initializer to RangeReplaceableCollectionType from SequenceType
rdar://19815116

Swift SVN r32213
2015-09-24 23:20:13 +00:00
Dmitri Hrybenko
1c0bb69a32 stdlib: add removeFirst() and removeLast() functions to slices
It is an oversight that we didn't add these when we were converting to
protocol extensions.

Swift SVN r32144
2015-09-22 02:50:33 +00:00
Dmitri Hrybenko
f7612273cf stdlib: simplify AnyGenerator API
Change the non-final class into a struct, and migrate global functions
into initializers.

rdar://21878289

Swift SVN r32137
2015-09-22 00:23:10 +00:00
Dmitri Hrybenko
384ec05ae4 stdlib: stop using Builtin types in UnicodeScalar
There is no reason for that now, and using Swift types simplifies code.

Swift SVN r32109
2015-09-21 01:33:10 +00:00