Commit Graph

6749 Commits

Author SHA1 Message Date
Joe Groff
c1456ff671 SILGen: Handle initializers that unconditionally fail.
A failable initializer that ended in an unconditional 'return nil' was leaving the exit basic block unemitted, since we exited early before writing out the unreachable epilog. Thanks Chris for catching this.

Swift SVN r21491
2014-08-27 20:19:09 +00:00
Joe Groff
4b6556c987 Remove stale comment.
Swift SVN r21490
2014-08-27 20:19:08 +00:00
Erik Eckstein
99cc7603be Add an @inline(__always) function attribute.
This will let the performance inliner inline a function even if the costs are too high.
This attribute is only a hint to the inliner.
If the inliner has other good reasons not to inline a function,
it will ignore this attribute. For example if it is a recursive function (which is
currently not supported by the inliner).

Note that setting the inline threshold to 0 does disable performance inlining at all and in
this case also the @inline(__always) has no effect.



Swift SVN r21452
2014-08-26 00:56:34 +00:00
Joe Groff
e9c7cefc94 SILGen: Return nil on the failure path from failable value initializers.
Since we preserve a single exit point in SIL, provide a join point with a BB argument to receive the success or failure result to return.

Swift SVN r21450
2014-08-26 00:49:35 +00:00
Doug Gregor
51c1433ddd Add magic "literal" __DSO_HANDLE__ to refer to the DSO handle.
__DSO_HANDLE__ can be used as a callee-side default
argument. Addresses rdar://problem/17878114.


Swift SVN r21440
2014-08-25 16:33:54 +00:00
Joe Groff
d63be086e0 SILGen: Forward failure from a delegated value constructor.
Swift SVN r21427
2014-08-23 00:14:56 +00:00
Doug Gregor
17716524c5 Handle CF <-> Objective-C toll-free-bridged conversions in the type checker.
Introduce an attribute that describes when a given CF type is
toll-free-bridged to an Objective-C class, and which class that
is. Use that information in the type checker to provide the CF <->
Objective-C toll-free-bridged conversions directly, rather than using
the user-defined conversion machinery.

Swift SVN r21376
2014-08-21 21:36:05 +00:00
Joe Groff
c23434a569 SILGen: Wrap the result of a failable value constructor in an optional.
Swift SVN r21370
2014-08-21 18:35:33 +00:00
Doug Gregor
7cae0cfc8e Remove -enable-dynamic and its language option; it's always on anyway.
Swift SVN r21354
2014-08-21 15:15:12 +00:00
Doug Gregor
67d0efd162 Use SILGenFunction::getMethodDispatch() to decide on delegating-initializer dispatch.
Fixes an attempt to perform vtable dispatch to an initializer that was
defined in an extension and is not @objc, which means it had no vtable
entry <rdar://problem/17909833>.

Swift SVN r21352
2014-08-21 14:05:16 +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
Joe Groff
fa75ee97c3 SILGen: Remove bogus "cannot handle specialized type references" assertion.
We can handle them just fine. Fixes <rdar://problem/17727332>.

Swift SVN r21322
2014-08-20 21:22:55 +00:00
Doug Gregor
344ecfd3f9 Add a new 'fail' statement to the AST for failing from an initializer.
The spelling of the 'fail' statement is simply 'return nil', but
distinguishing it in the AST clarifies intent for SILGen.

Swift SVN r21310
2014-08-20 17:22:36 +00:00
Chris Lattner
07d8963ba9 fix <rdar://problem/16554056> __FUNCTION__ in deinit for NSObject subclasses crashes the compiler
Swift SVN r21300
2014-08-20 00:28:01 +00:00
Arnold Schwaighofer
cd799f8e46 Revert "Add an inline(late) attribute"
This reverts commit r21286.

Discussions ongoing.

Swift SVN r21289
2014-08-19 18:15:25 +00:00
Arnold Schwaighofer
7aa62ce835 Add an inline(late) attribute
This disables inlining at the SIL level. LLVM inlining is still enabled. We can
use this to expose one function at the SIL level - which can participate in
dominance based optimizations but which is implemented in terms of a cheap check
and an expensive check (function call) that benefits from LLVM's inlining.

Example:

The inline(late) in the example below prevents inlining of the two checks. We
can now perform dominance based optimizations on isClassOrObjExistential.
Without blocking inlining the optimizations would apply to the sizeof check
only and we would have multiple expensive function calls.

@inline(late)
func isClassOrObjExistential(t: Type) -> Bool{
  return sizeof(t) == sizeof(AnyObject) &&
    swift_isClassOrObjExistential(t)
}

We do want inlining of this function to happen at the LLVM level because the
first check is constant folded away - IRGen replaces sizeof by constants.

rdar://17961249

Swift SVN r21286
2014-08-19 18:05:44 +00:00
Dmitri Hrybenko
938e7c2676 stdlib: introduce UnicodeScalarLiteralConvertible protocol
This allows UnicodeScalars to be constructed from an integer, rather
then from a string.  Not only this avoids an unnecessary memory
allocation (!) when creating a UnicodeScalar, this also allows the
compiler to statically check that the string contains a single scalar
value (in the same way the compiler checks that Character contains only
a single extended grapheme cluster).

rdar://17966622

Swift SVN r21198
2014-08-14 16:04:39 +00:00
Doug Gregor
f05cd00036 Handle reference storage types in the optional-injection workaround from r21176.
Swift SVN r21179
2014-08-13 18:57:30 +00:00
Doug Gregor
21dcd07846 Extend the optional-injection-of-erroneous-nil hack for more entities.
r21096 introduces an optimization barrier for failing initializers
that allows the pattern

  let x: NSFoo? = NSFoo()

be used to detect whether NSFoo() returned nil, even though the type
system says it cannot. Extend this check to Objective-C methods and
properties, where the non-optional annotation may be incorrect
<rdar://problem/17984530>.




Swift SVN r21176
2014-08-13 16:44:53 +00:00
Nadav Rotem
54458fb892 Enable access control based devirtualization.
Patch (mostly) by Jordan Rose.

rdar://17890078. 



Swift SVN r21139
2014-08-12 00:43:18 +00:00
Joe Groff
bde47cfe44 SILGen: Keep the 'let x: NSFoo? = NSFoo()' failing initializer hack from being optimized.
If we see that we're injecting the result of an @objc initializer into an optional, perform the T -> T? conversion using unchecked_ref_bit_cast, which is opaque to the optimizer, instead of doing a proper optional injection. This prevents the optimizer from defeating our workaround for failing initializers. <rdar://problem/17941601>

Swift SVN r21096
2014-08-07 17:40:38 +00:00
Nadav Rotem
8dd52d63cd Add the @effects(readonly/readnone/readwrite) attribute.
Swift SVN r21070
2014-08-06 18:48:20 +00:00
Chris Lattner
dd803a39f8 change LValue from holding its segments as a DiverseList to holding them
as a std::vector<std::unique_ptr<PathComponent>>.   DiverseList memcpy's
around its buffer on copy and move operations.  This seems safe with all
of the current implementations of Cleanup, but is absolutely not with the
LValue PathComponents.  These things hold std::vectors, RValue (which has
an std::vector in it), and a bunch of other probably non-trivial things.

While we're in here, disable the copy constructor, since it isn't safe.
This doesn't harm mainline, but was burning me on a patch I'm working on.

When/if someone cares about performance optimizing this code, a better
approach would be to use an ilist + bump pointer allocator.



Swift SVN r21057
2014-08-06 00:50:09 +00:00
Doug Gregor
f52c6789db Track the minimum deployment target and use it for 'unavailable' computations.
Swift SVN r20955
2014-08-02 18:05:45 +00:00
Joe Groff
6d2a3bb0fa SILGen: Load 'self' at +1 for class-constrained generic methods.
"self" for class-constrained witnesses is still passed at +1, so we can't load it using AllowPlusZero. Fixes <rdar://problem/17852846>.

Swift SVN r20868
2014-08-01 00:31:20 +00:00
Doug Gregor
79d5c69d5a Remove CheckedCastKind::ArrayDowncastBridged. Nobody F'ing Cares about it now.
Swift SVN r20730
2014-07-30 04:26:16 +00:00
Chris Lattner
2a9ba67b04 refactor some call emission logic w.r.t. inout arguments to expose the LValue for the inout
argument to SILGenApply.  NFC.


Swift SVN r20729
2014-07-30 00:37:09 +00:00
Chris Lattner
6d04cc4255 revert r20720: getting RValueSource's for self arguments is futile: we need
a concrete SILValue when emitting the Callee object so we can look things up
in method tables etc.  Without reengineering all of Callee, that isn't going 
to work.


Swift SVN r20727
2014-07-30 00:17:29 +00:00
Dave Abrahams
6e7f83fe98 Internalize old array casting entry-points
The core compiler now uses just two entry points for array casting

Swift SVN r20725
2014-07-29 23:56:51 +00:00
Chris Lattner
b89476336f push RValueSource down into the 'self' parameter emission logic in applications a bit farther, NFC.
Swift SVN r20720
2014-07-29 23:29:40 +00:00
Joe Groff
e8c79f3236 SILGen: Ignore the result of a "for" loop increment.
Fixes <rdar://problem/17236237>.

Swift SVN r20685
2014-07-29 19:42:09 +00:00
Chris Lattner
e466b4621b revert r20658, restoring us back to producing the "inout writeback to computed property"
error when detecting an inout writeback problem.


Swift SVN r20681
2014-07-29 18:12:51 +00:00
Chris Lattner
a730912d77 revert the non-debug-printing pieces of r20661.
Swift SVN r20680
2014-07-29 18:05:32 +00:00
Chris Lattner
7676259ecc Fix http://swiftwtf.tumblr.com/post/91934970718/xcode-6-beta-3 to compile into the
behaviorly correct code by CSE'sing subscripts that are identical.

Also, add a dump() method to PathComponent to help visualize / debug LValue structures.



Swift SVN r20661
2014-07-29 00:27:43 +00:00
Chris Lattner
4d03ef63f7 Rip out my previous work that produced perplexing "inout writeback to
computed property" errors when SILGen could determine that there was
an inout writeback alias, and have the code instead perform CSE of the
writebacks directly.

This means that we produce more efficient code, that a lot of things
now "just work" the way users would expect, and that the still erroneous
cases now get diagnosed with the "inout arguments are not allowed to 
alias each other" error, which people have a hope of understanding.

There is still more to do here in terms of detecting identical cases,
but that was true of the previous diagnostic as well.




Swift SVN r20658
2014-07-28 23:55:14 +00:00
Chris Lattner
1c80e6454f fix <rdar://problem/17828355> curried final method on a class crashes in irgen
getNextUncurryLevelRef was using it's own local test to determine whether a
FuncDecl is dynamically dispatched (which didn't check for "final"), change it 
to use SILGenFunction::getMethodDispatch instead.


Swift SVN r20623
2014-07-28 15:42:24 +00:00
Joe Groff
4bacaffaa7 SILGen: Implement lvalue BindOptionalExprs.
Factor out the code for emitting the "bind" branching logic, and share it to implement an LValueComponent for optional binds, which makes optional assignments work.

Swift SVN r20614
2014-07-28 04:05:28 +00:00
Chris Lattner
0db920b1c4 Reject obvious inout argument aliases with a good diagnostic, for example:
t2.swift:4:11: error: inout arguments are not allowed to alias each other
 swap(&x, &x)
          ^~
t2.swift:4:7: note: previous aliasing argument
 swap(&x, &x)
      ^~

This can (and arguably should) also be handled with a later diagnostic pass, but
handling it in SILGen gives us full range emission capability.



Swift SVN r20469
2014-07-24 05:11:28 +00:00
Chris Lattner
8ca43451b1 Simplify the highlighting in the subscript case of the inout writeback diagnostic to not
include the index which is confusing.  For example, in:

func testMultiArray(i : Int, j : Int, var array : [[Int]]) {
  swap(&array[i][j], &array[i][i])
}

we now highlight just "array[i]", instead of the subsequent "j" and "i"'s.



Swift SVN r20446
2014-07-23 23:40:19 +00:00
Doug Gregor
587d7e7dad Fix an assertion when a required initializer overrides a non-required one.
We were attempting to find the vtable slot for the allocating
initializer in the superclass, but of course it doesn't have one. Part
of <rdar://problem/17408284>.

Swift SVN r20429
2014-07-23 22:16:37 +00:00
Joe Groff
623aba1786 Encapsulate Substitution's state.
Expose Substitution's archetype, replacement, and conformances only through getters so we can actually assert invariants about them. To start, require  replacement types to be materializable in order to catch cases where the type-checker tries to bind type variables to lvalue or inout types, and require the conformance array to match the number of protocol conformances required by the archetype. This exposes some latent bugs in the test suite I've marked as failures for now:

- test/Constraints/overload.swift was quietly suffering from <rdar://problem/17507421>, but we didn't notice because we never tried to codegen it.
- test/SIL/Parser/array_roundtrip.swift doesn't correctly roundtrip substitutions, which I filed as <rdar://problem/17781140>.

Swift SVN r20418
2014-07-23 18:00:38 +00:00
Chris Lattner
5f06ae4fb6 Teach the inout aliasing diagnostic that a certainly narrow class of AST expression (which
lower to different SILValue's are actually identical.  These are the expression involved
in turning an integer literal into an expression.  This is totally a hack in that we assume
that all "convertFromIntegerLiteral" are side effect free, but is close enough to be useful
for this diagnostic.  The right answer is to implement real attributes to model this 
(rdar://15587352).

That said, this diagnostic is pretty useful as it is.  For example, the SwiftWTF blog post
(http://swiftwtf.tumblr.com/post/91934970718/xcode-6-beta-3) has two examples.  The first
one passes this diagnostic unscathed because there is no inout aliasing problem: "a" is a
physical lvalue, not a logical one and a[1] doesn't alias a[2].  

However, the second example is now rejected with an error message of:

t.swift:12:18: error: inout writeback through subscript occurs in multiple arguments to call, introducing invalid aliasing
swap(&aa[0][1], &aa[0][2])
                 ^~~~~ ~
t.swift:12:7: note: concurrent writeback occurred here
swap(&aa[0][1], &aa[0][2])
      ^~~~~ ~

This is a violation even though "aa" is physical lvalue, because "aa[0]" is a logical
lvalue and we can now detect that the two instances of "aa[0]" are identical (because
we can tell the two 0's are identical).  I'm still not thrilled with the diagnostic, but
I think this will help stem a common source of problems in practice.

As more lvalues become physical or get auto-CSE'd (either with better SILGen CSE, with 
physical i addressors, etc) this diagnostic will automatically track SILGen.



Swift SVN r20377
2014-07-23 05:57:10 +00:00
Chris Lattner
aac2a6c876 Start teaching the inout writeback diagnostic to handle subscripts. The first step is to
handle cases where the index lowers to exactly identical SILValue's.  This is presently 
pretty uncommon (except in the moderately common case of a direct reference to a "let Int"), 
but is a nice base case.

The diagnostic we now get is:

t.swift:5:23: error: inout writeback through subscript occurs in multiple arguments to call, introducing invalid aliasing
  swap(&array[i][j], &array[i][i])
                      ^~~~~~~~ ~
t.swift:5:9: note: concurrent writeback occurred here
  swap(&array[i][j], &array[i][i])
        ^~~~~~~~ ~

based on the fact that "i" lowers to the same SILValue.



Swift SVN r20376
2014-07-23 05:14:00 +00:00
Joe Groff
b5d5cf0c8d SILGen: Don't crash when peepholing a ForceValue of nested OptionalEvaluations.
The type checker produces nested optional evaluations for expressions of the form 'x.optionalProperty?.optionalProperty as NonOptionalType'. SILGen had a peephole for this case that was apparently never tested, because we tried to dereference a null failure BB. Fixes <rdar://problem/17576873> and at least half a dozen dupes. The codegen is still kind of ridiculous, but correct.

Swift SVN r20358
2014-07-23 01:34:02 +00:00
Dave Abrahams
1438d617cd [stdlib] Rename ConstUnsafePointer=>UnsafePointer
Swift SVN r20318
2014-07-22 17:10:54 +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
Chris Lattner
d473159814 Implement the start of a diagnostic to detect cases where inout aliasing violations are
introduced, as these are obvious miscompilations and clearly mystifying to our user base.

This is enough to emit diagnostics like this:

writeback_conflict_diagnostics.swift:58:70: error: inout writeback aliasing conflict detected on computed property 'c_local_struct_property'
  swap(&c_local_struct_property.stored_int, &c_local_struct_property.stored_int)
                                             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
writeback_conflict_diagnostics.swift:58:33: note: concurrent writeback occurred here
  swap(&c_local_struct_property.stored_int, &c_local_struct_property.stored_int)
        ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~

which isn't great, but is better than nothing (better wording is totally welcome!).

This doesn't handle subscripts (or many other kinds of logical lvalue) at all yet, so 
it doesn't handle the swift WTF case, but this is progress towards that.



Swift SVN r20297
2014-07-22 05:37:42 +00:00
Chris Lattner
710b35b396 enable SILGen diagnostic emitters to add fixits and source ranges. NFC.
Swift SVN r20294
2014-07-22 04:56:37 +00:00
Joe Groff
9b63a6d241 SILGen: Don't check requiresObjCDispatch for dynamic_method lookups.
They by definition always require ObjC dispatch. Will be tested when 'dynamic' is enabled.

Swift SVN r20284
2014-07-22 00:23:35 +00:00
Chris Lattner
247cc911cf add some assertions I forgot in r20281
Swift SVN r20282
2014-07-21 21:48:38 +00:00