Commit Graph

7655 Commits

Author SHA1 Message Date
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
Dmitri Hrybenko
4375a463a7 stdlib: rename Int**.value and Float**.value to _value per naming convention
rdar://21357661

Swift SVN r32096
2015-09-20 00:01:13 +00:00
Dmitri Hrybenko
a2e1dc5fb7 stdlib: remove some workarounds for compiler bugs from ExistentialCollection
Swift SVN r32066
2015-09-18 03:37:03 +00:00
Dmitri Hrybenko
4f114006ab stdlib: fix the comment on removeFirst() to not refer to the 'n' parameter
Swift SVN r31954
2015-09-15 00:51:06 +00:00
Dmitri Hrybenko
cf19c6c532 stdlib: format a code snippet as a code block
rdar://22422749

Swift SVN r31922
2015-09-14 06:29:25 +00:00
Dmitri Hrybenko
2ff89aa40e stdlib: fix comment on ArraySlice.startIndex
ArraySlice.startIndex is not necessarily zero anymore.

rdar://22633052

Swift SVN r31921
2015-09-14 05:40:14 +00:00
Dmitri Hrybenko
67944589d6 stdlib: improve index invalidation guarantees for removeFirst()
Slice types that are RangeReplaceable (like ArraySlice) now slice
themselves in removeFirst().  Previously, these types were picking up
the wrong default implementation, and they were going through
replaceRange(), which caused all indices to be invalidated.  The new
implementation preserves all indices.

rdar://22536664

Swift SVN r31918
2015-09-12 04:35:51 +00:00
Dave Abrahams
07c47326cb [stdlib] Integer Prototype: get most signifcant bit
Swift SVN r31898
2015-09-11 18:40:47 +00:00
Argyrios Kyrtzidis
742f65c66b [stdlib] Fix comment of _ColorLiteralConvertible, NFC.
Swift SVN r31847
2015-09-10 02:03:16 +00:00