Commit Graph

59 Commits

Author SHA1 Message Date
Erik Eckstein
54e1071da0 Add a builtin assumeNonNegative.
It returns the argument and specifies that the value is not negative.
It has only an effect if the argument is a load or call.

The effect of this builtin is that for the load/call argument a positive range metadata is created in llvm ir.

I also added a public function _assumeNonNegative(x: Int) -> Int in the stdlib.
To be on the save side, I prefixed it with an underscore. But maybe it makes sense to make it available for all users.



Swift SVN r23582
2014-11-26 09:53:14 +00:00
Graham Batty
e537c75d0c Revert "Disable existential metatype casting on non-objc."
This reverts commit 3e918838b3708bf2287e7caab437ccf72fe9a3f6.

Swift SVN r23579
2014-11-24 17:42:19 +00:00
Graham Batty
277891d8b5 Disable existential metatype casting on non-objc.
Swift SVN r23575
2014-11-24 17:40:44 +00:00
Joe Groff
b60a30c84b stdlib: Make isUniquelyReferenced shims properly return bool.
rdar://problem/18573806 is fixed.

Swift SVN r23547
2014-11-22 05:36:38 +00:00
Dave Abrahams
de8967e2cd [stdlib] Copious force-inling
Just trying to remove possible overheads in the new Array
implementation.  It doesn't seem to affect performance, though.

Swift SVN r23504
2014-11-21 01:39:54 +00:00
Dave Abrahams
0c1e5265c4 [stdlib] Degenericize some BridgeObject primitives
There's really no reason to make the compiler and optimizer work hard,
here.

Also, make some sanity checks more informative

Swift SVN r23503
2014-11-21 01:39:54 +00:00
Dave Abrahams
1ed31fa31a [stdlib] Fix BridgeStorage!
Fix the test so it actually runs, then fix all the bugs it finds, then
extend the test to cover the no-bits-fast-path functionality.

Swift SVN r23466
2014-11-20 03:41:10 +00:00
Mark Lacey
d344976d3d Remove @inline(__always) on a var decl.
@inline(__always) can only be used on functions and constructors.

Swift SVN r23462
2014-11-20 03:01:43 +00:00
Dave Abrahams
e78ad13b7f [stdlib] Force-inline some bitmask constants
Swift SVN r23454
2014-11-19 22:57:44 +00:00
Dave Abrahams
e581216d28 [stdlib] Fix a comment
Swift SVN r23453
2014-11-19 22:57:44 +00:00
Dave Abrahams
2f29db9bfa [stdlib] Finish incomplete comment
Swift SVN r23432
2014-11-19 06:21:49 +00:00
Dave Abrahams
d4e06bd174 [stdlib] Clean up a sanity check
Swift SVN r23431
2014-11-19 06:21:01 +00:00
Dave Abrahams
68fbea2988 BridgeObject: native object with no spare bits set
Naturally, the fast path for things like Array<Int> has to be that no
masking is required to get at the buffer.  Therefore, the state with no
spare bits set needs to be reserved for native objects.  After the
change, an ObjC non-tagged pointer is stored with all spare bits set, and
native objects are stored with 0..<N bits set, where N is the number of
spare bits.  ObjC tagged pointers are still stored verbatim.

Swift SVN r23430
2014-11-19 06:07:19 +00:00
Dave Abrahams
4111b94d1f [stdlib] _BridgeStorage: use Builtin.BridgeObject
Swift SVN r23348
2014-11-15 01:54:53 +00:00
Graham Batty
04f8efbdf5 Correctly calculate non-objc instance size and rename to reflect.
Renames swift_class_getInstanceSize to
swift_class_getInstancePositiveExtentSize to reflect that it is
the size of the object after the instance address point.

Swift SVN r23333
2014-11-14 22:09:20 +00:00
Michael Gottesman
9a691a55b2 [playgrounds] Implement _swift_isClass(x: Any) -> Bool.
This is acting as a temporary work around until the more general
getTypeKind() is finalized from an API perspective.

The reason that removing this now instead of waiting makes sense is:

1. The previous way playgrounds was performing this check was using the runtime
c++ implementation of swift_isClassOrObjCExistential via @asmname. We
want to move away from the @asmname approach in general since it is
brittle since it leads to loose cupling of dependencies.

2. The @asmname version in playgrounds caused the deserializer to assert since
the c++ version of swift_isClassOrObjCExistential() does not match the signature
of the swift declaration of swift_isClassOrObjCExistential().

This allows us to avoid the aforementioned issues and make forward
progress on re-enabling the playground logger with optimization.

rdar://18841292

Swift SVN r23307
2014-11-13 19:35:59 +00:00
Graham Batty
dc6a776d10 stdlib: Use config directives to work without objective-c.
Swift SVN r23211
2014-11-10 20:06:25 +00:00
Graham Batty
9524ca20b3 stdlib: Move _nilRawPointer to Builtin.swift
Swift SVN r23209
2014-11-10 20:05:26 +00:00
Graham Batty
373414864d Revert "Use config directives to carve out a 'portable' kernel stdlib."
This reverts commit r23202 pending further discussion.

Swift SVN r23205
2014-11-10 18:46:42 +00:00
Graham Batty
dfa260fab1 Use config directives to carve out a 'portable' kernel stdlib.
Swift SVN r23202
2014-11-10 18:03:09 +00:00
Dmitri Hrybenko
8d68624c87 stdlib: fix doc comment syntax and coding style
Swift SVN r22684
2014-10-11 01:33:05 +00:00
Dave Abrahams
5c33278e63 [stdlib] Add ManagedBufferPointer
A revamped version of HeapBuffer that doesn't allow null buffer
references.  Something like this is needed for killing the null array
state.

Swift SVN r22683
2014-10-11 01:10:38 +00:00
Dave Abrahams
e4d8ea49e4 [stdlib] Add a FIXME
Swift SVN r22579
2014-10-07 22:15:09 +00:00
Dave Abrahams
d669b8fd56 [stdlib] Always inline _isClassOrObjCExistential
Swift SVN r22543
2014-10-06 18:40:05 +00:00
Erik Eckstein
a4c7d89671 fix coding style in stdlib: move non-attribute keywords in same line as function declaration
Swift SVN r22275
2014-09-25 08:43:55 +00:00
Dave Abrahams
a00085e6ce [stdlib] Document public non-protocol API thru 'B'
Swift SVN r22186
2014-09-22 21:51:38 +00:00
Dmitri Hrybenko
96d00d70b5 StdlibUnittest: add infrastructure for race tests (see examples)
This will be used to test rdar://18191358

Swift SVN r21836
2014-09-10 11:58:45 +00:00
Dave Abrahams
c16987cc8b [stdlib] Add/use unsafeDowncast
now that <rdar://problem/18184883> is fixed, this factoring can be done

Swift SVN r21647
2014-09-02 17:26:03 +00:00
Dave Abrahams
42a2f263fd [stdlib] Add/use unsafeAddressOf
Turning a class into an UnsafePointer should be available to users, and
both safer and more optimizable than using unsafeBitCast.

Swift SVN r21593
2014-08-29 22:33:13 +00:00
Arnold Schwaighofer
9a7b869faf Revert "Add @effects(readnone) to _swift_isClassOrObjCExistential"
We have not defined whether readnone would potentially allow it to be
speculatively executed which is not desired semantics for
_swift_isClassOrObjCExistential because the metadata might not have been loaded
at the speculative point. Since we don't need the readnone property on this
function after the Builtin.canBeClass change for performance remove it for now.

This reverts commit r21330.

Swift SVN r21422
2014-08-22 21:34:33 +00:00
Arnold Schwaighofer
16e41ada77 Make Builtin.canBeClass return a tri-state
Replace the true/maybe state that Builtin.canBeClass was returning by a
tri-state (yes, no, maybe) allowing the optimizer to use the definite no
answer.  This removes the need of the sizeof check that we had in
isClassOrObjCExistential. It also removes the need to CSE this function since
in most cases we will be able to instantiate canBeClass to yes or no (vs maybe)
at compile time.

benchmark``````````````,``baserun0``,``optrun2``,``delta,``speedup
ClassArrayGetter```````,``988.00````,``337.00```,``644.00``,````````191.7%
DeltaBlue``````````````,``2429.00```,``1927.00``,``460.00``,````````23.9%
Dictionary`````````````,``1374.00```,``1231.00``,``129.00``,````````10.9%
Havlak`````````````````,``1079.00```,``911.00```,``124.00``,````````13.7%
Rectangles`````````````,``924.00````,``541.00```,``379.00``,````````70.1%

radar://16823238

Swift SVN r21331
2014-08-21 00:55:40 +00:00
Arnold Schwaighofer
411ad98fba Add @effects(readnone) to _swift_isClassOrObjCExistential
rdar://17961249

Swift SVN r21330
2014-08-21 00:55:36 +00:00
Arnold Schwaighofer
f1ffbf0e0e Revert "stdlib: Add a _isClassOrObjCExistentialAndSizeofAnyObject function"
This reverts commit r21287.

Discussions ongoing.

Swift SVN r21288
2014-08-19 18:15:24 +00:00
Arnold Schwaighofer
87fe2bf736 stdlib: Add a _isClassOrObjCExistentialAndSizeofAnyObject function
The function _isClassOrObjCExistentialAndSizeofAnyObject encapsulates the
"sizeof(x) == sizeof(AnyObject)" check and the call to
swift_isClassOrObjCExistential. The sizeof(x) check cannot be eliminated at the
SIL level and creates extra control flow such that the call to
swift_isClassOrObjCExistential does not dominate. Encapsulating both checks
results in one function call that does dominate allowing us to CSE calls when we
add the attributes inline(late) and effects(readnone).

benchmark``````````````,``baserun0``,``optrun2``,``delta,``speedup
ClassArrayGetter```````,``977.00````,``571.00```,``409.00``,````````72.0%
DeltaBlue``````````````,``2594.00```,``2086.00``,``311.00``,````````14.9%
Rectangles`````````````,``921.00````,``605.00```,``314.00``,````````52.0%

rdar://17961249

Swift SVN r21287
2014-08-19 18:05:44 +00:00
Dmitri Hrybenko
3a04e0809f stdlib: add a function to squeeze a number in a given range from a hash value
This function mixes the bits in the hash value, which improves Dictionary
performance for keys with bad hashes.

PrecommitBenchmark changes with greater than 7% difference:

``````````Dictionary2`,```1456.00`,```1508.00`,```1502.00`,````624.00`,````607.00`,````592.00`,`864.00`,``145.9%
``````````Dictionary3`,```1379.00`,```1439.00`,```1408.00`,````585.00`,````567.00`,````552.00`,`827.00`,``149.8%
````````````Histogram`,````850.00`,````849.00`,````851.00`,```1053.00`,```1049.00`,```1048.00`,`199.00`,``-19.0%
````````````````Prims`,```1999.00`,```2005.00`,```2018.00`,```1734.00`,```1689.00`,```1701.00`,`310.00`,```18.4%
``````````StrSplitter`,```2365.00`,```2334.00`,```2316.00`,```1979.00`,```1997.00`,```2000.00`,`337.00`,```17.0%
```````````````TwoSum`,```1551.00`,```1568.00`,```1556.00`,```1771.00`,```1741.00`,```1716.00`,`165.00`,```-9.6%

Regressions are in benchmarks that use `Int` as dictionary key: we are just
doing more work than previously (hashing an `Int` was an identity function).

rdar://17962402


Swift SVN r21142
2014-08-12 12:02:26 +00:00
Pete Cooper
16f6c73db9 Use unchecked arithmetic for offsets to HeapBuffer values and elements. If these were able to overflow then we'd have already failed in the initializer of the HeapBuffer
Performance numbers are being noisy, but overall there are some good wins.  The losses are the noisy ones unfortunately.

2Sum           ,        1273.00   ,                1292.00   ,        19.00   ,                -1.5%
Ackermann      ,        1423.00   ,                1663.00   ,        240.00  ,                -14.4%
ArrayLiteral   ,        913.00    ,                869.00    ,        44.00   ,                5.1%
Ary            ,        1278.00   ,                1278.00   ,        0.00    ,                0.0%
Ary2           ,        1667.00   ,                1656.00   ,        11.00   ,                0.7%
Ary3           ,        1418.00   ,                1380.00   ,        38.00   ,                2.8%
DeltaBlue      ,        2480.00   ,                2437.00   ,        43.00   ,                1.8%
Dictionary     ,        606.00    ,                594.00    ,        12.00   ,                2.0%
Dictionary2    ,        879.00    ,                862.00    ,        17.00   ,                2.0%
Dictionary3    ,        878.00    ,                871.00    ,        7.00    ,                0.8%
EditDistance   ,        1427.00   ,                1404.00   ,        23.00   ,                1.6%
Fibonacci      ,        1351.00   ,                1335.00   ,        16.00   ,                1.2%
ForLoops       ,        1978.00   ,                1976.00   ,        2.00    ,                0.1%
Forest         ,        1091.00   ,                1076.00   ,        15.00   ,                1.4%
GlobalClass    ,        1714.00   ,                1619.00   ,        95.00   ,                5.9%
Hash           ,        971.00    ,                915.00    ,        56.00   ,                6.1%
HeapSort       ,        1321.00   ,                1261.00   ,        60.00   ,                4.8%
Histogram      ,        1085.00   ,                1079.00   ,        6.00    ,                0.6%
Life           ,        67.00     ,                63.00     ,        4.00    ,                6.3%
LinkedList     ,        1586.00   ,                1535.00   ,        51.00   ,                3.3%
MatMul         ,        239.00    ,                240.00    ,        1.00    ,                -0.4%
Memset         ,        53.00     ,                53.00     ,        0.00    ,                0.0%
MonteCarloE    ,        1243.00   ,                1242.00   ,        1.00    ,                0.1%
MonteCarloPi   ,        993.00    ,                1010.00   ,        17.00   ,                -1.7%
NBody          ,        44.00     ,                43.00     ,        1.00    ,                2.3%
Phonebook      ,        1416.00   ,                1402.00   ,        14.00   ,                1.0%
PrimeNum       ,        347.00    ,                351.00    ,        4.00    ,                -1.1%
Prims          ,        1556.00   ,                1523.00   ,        33.00   ,                2.2%
QuickSort      ,        103.00    ,                101.00    ,        2.00    ,                2.0%
R17315246      ,        1080.00   ,                1076.00   ,        4.00    ,                0.4%
RC4            ,        26.00     ,                25.00     ,        1.00    ,                4.0%
RIPEMD         ,        798.00    ,                767.00    ,        31.00   ,                4.0%
Rectangles     ,        1008.00   ,                972.00    ,        36.00   ,                3.7%
SmallPT        ,        1004.00   ,                1040.00   ,        36.00   ,                -3.5%
StrToInt       ,        795.00    ,                815.00    ,        20.00   ,                -2.5%
StringBuilder  ,        795.00    ,                858.00    ,        63.00   ,                -7.3%
StringWalk     ,        1233.00   ,                1322.00   ,        89.00   ,                -6.7%
Totals         ,        38274.00  ,                38145.00  ,        129.00  ,                0.3%
Walsh          ,        135.00    ,                140.00    ,        5.00    ,                -3.6%

Swift SVN r20569
2014-07-25 22:49:24 +00:00
Pete Cooper
b68de9d4c0 Update strideof in stdlib to call new strideof_nonzero.
This hides the call to max in the compiler and removes the control flow
associated with max.  The resulting -O3 performance is

2Sum           ,  1303.00   ,  1286.00   ,  17.00     ,        1.3%
Ackermann      ,  4077.00   ,  4498.00   ,  421.00    ,        -9.4%
DeltaBlue      ,  19473.00  ,  17265.00  ,  2208.00   ,        12.8%
Dictionary     ,  882.00    ,  817.00    ,  65.00     ,        8.0%
EditDistance   ,  1467.00   ,  1416.00   ,  51.00     ,        3.6%
ForLoops       ,  1998.00   ,  2014.00   ,  16.00     ,        -0.8%
Forest         ,  1125.00   ,  1055.00   ,  70.00     ,        6.6%
GlobalClass    ,  1633.00   ,  1640.00   ,  7.00      ,        -0.4%
Hash           ,  1634.00   ,  945.00    ,  689.00    ,        72.9%
Histogram      ,  1196.00   ,  1054.00   ,  142.00    ,        13.5%
Life           ,  71.00     ,  64.00     ,  7.00      ,        10.9%
LinkedList     ,  1573.00   ,  1573.00   ,  0.00      ,        0.0%
Memset         ,  5987.00   ,  273.00    ,  5714.00   ,        2093.0%
NBody          ,  208.00    ,  44.00     ,  164.00    ,        372.7%
Phonebook      ,  2193.00   ,  1486.00   ,  707.00    ,        47.6%
PrimeNum       ,  1093.00   ,  393.00    ,  700.00    ,        178.1%
Prims          ,  1710.00   ,  1712.00   ,  2.00      ,        -0.1%
QuickSort      ,  121.00    ,  112.00    ,  9.00      ,        8.0%
R17315246      ,  1109.00   ,  1273.00   ,  164.00    ,        -12.9%
RC4            ,  745.00    ,  63.00     ,  682.00    ,        1082.5%
Rectangles     ,  947.00    ,  1015.00   ,  68.00     ,        -6.7%
SmallPT        ,  1071.00   ,  1088.00   ,  17.00     ,        -1.6%
StringBuilder  ,  928.00    ,  799.00    ,  129.00    ,        16.1%
StringWalk     ,  1221.00   ,  1264.00   ,  43.00     ,        -3.4%
Totals         ,  54980.00  ,  43284.00  ,  11696.00  ,        27.0%
Walsh          ,  1215.00   ,  135.00    ,  1080.00   ,        800.0%

Swift SVN r20509
2014-07-24 18:44:42 +00:00
Pete Cooper
3590f4a896 Alignof can never return 0, so don't max against 1
Swift SVN r20507
2014-07-24 18:44:41 +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
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
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
cbcf9aba21 s/LogicValueType/BooleanType/
We're moving toward using that protocol for straight-up Bool types

Swift SVN r19884
2014-07-12 18:58:18 +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
Chris Lattner
02999cac51 Reinstate the @ on the @objc attribute. This is largely a revert of r19555 with a few tweaks.
Swift SVN r19706
2014-07-08 21:50:34 +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
Dmitri Hrybenko
7f351643d9 stdlib: hide roundUpToAlignment
rdar://17315534


Swift SVN r19566
2014-07-04 15:57:47 +00:00
Chris Lattner
7a56499d61 Start making @objc not start with an @ sign:
- Change the parser to accept "objc" without an @ sign as a contextual
   keyword, including the dance to handle the general parenthesized case.
 - Update all comments to refer to "objc" instead of "@objc".
 - Update all diagnostics accordingly.
 - Update all tests that fail due to the diagnostics change.
 - Switch the stdlib to use the new syntax.

This does not switch all tests to use the new syntax, nor does it warn about
the old syntax yet.  That will be forthcoming.  Also, this needs a bit of 
refactoring, which will be coming up.



Swift SVN r19555
2014-07-04 05:57:57 +00:00
Andrew Trick
8122715df7 Teach the ColdBlocks SIL analysis to recognize the branch hint semantic model.
We're temporarily using @semantics until we have mandatory inlining of branch hints.

We now have @noinline, which helps a lot, but:
- @noinline and "cold/slow" are not the same thing.

- Some functions may need to be inlined into hot paths, but that
  doesn't mean we should also inline them into cold paths.

- It is easier to find cold blocks than to look for blocks that
  contain calls to @noinline functions. And that doesn't necessarilly
  mean the blocks are cold anyway.

Swift SVN r19455
2014-07-02 06:35:09 +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