Commit Graph

405 Commits

Author SHA1 Message Date
Joe Groff
3aa75d0c38 SILGen: Fix broken value semantics in previous commit.
When we take advantage of AllowPlusZero, we shouldn't put a cleanup on the materialized temporary.

Swift SVN r21982
2014-09-16 21:44:49 +00:00
Joe Groff
d3702950af SILGen: Materialize class-constrained "self" parameters when passed to non-class-constrained protocol methods.
Fixes rdar://problem/17480006, rdar://problem/17557409, rdar://problem/17929884 and crash suite #019.

Swift SVN r21981
2014-09-16 21:12:40 +00:00
Doug Gregor
37ec99601a Don't try to copy-initialize an aggregate whose members have
Recent versions of Clang correctly reject this rdar://problem/18291554.

Swift SVN r21848
2014-09-10 19:14:25 +00:00
Doug Gregor
769ba83b28 Clean up "self" properly when delegating to a factory method.
Fixes the leak reported in rdar://problem/18141590.


Swift SVN r21739
2014-09-05 04:57:58 +00:00
Joe Groff
53bbefbe42 SILGen: Thread direct access through all uses of emitRValueForDecl.
Swift SVN r21715
2014-09-04 18:11:04 +00:00
Chris Lattner
44a1eb7715 Rework SILGen of optional methods to work with non-@objc situations:
- Split getSelfTypeForDynamicLookup into two pieces, and generalize it
    to work on non-loadable protocols.
  - Change dynamic_method_branch to take its argument as a protocol of any
    protocol type, instead of as something of UnownObject type.
  - Teach emitForcedDynamicMemberRef to only do its peephole optimization for
    @objc cases, since it is special behavior of objc_msgSend.
  - enhance emitDynamicPartialApply & emitDynamicMemberRefExpr to emit the
    proper project_existential instruction (not a _ref) when dealing with a
    non-classbound protocol.

Change the verifier to allow DynamicMethodBranchInst to work on non-@objc
protocol members.

This eliminates a bunch of pointless unchecked_ref_cast's in the generated
SIL for existing code, but this got squashed at IRGen time anyway, so no
real change for anything that sema permits.



Swift SVN r21519
2014-08-28 07:37:18 +00:00
Chris Lattner
dc7c565af8 further generalize dynamic_method and dynamic_method_br: instead of having them force
the subject to "Builtin.UnknownObject", just traffic in the protocol type directly.


Swift SVN r21516
2014-08-28 05:41:35 +00:00
Joe Groff
4b6556c987 Remove stale comment.
Swift SVN r21490
2014-08-27 20:19:08 +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
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
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
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
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
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
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
Joe Groff
36b2fd2d49 SILGen: Only dynamically dispatch 'dynamic' methods in extensions.
When 'dynamic' is honored, extension methods can only be dynamically dispatched if they'll be objc-dispatched, since they don't have native vtable entries.

Swift SVN r19999
2014-07-16 01:43:20 +00:00
Joe Groff
45eec9a2e9 Remove 'interface' from the method names of SILFunctionType.
SILFunctionTypes are always interface types now. NFC.

Swift SVN r19952
2014-07-14 22:03:46 +00:00
Joe Groff
eaf84f5f0e SILGen: Use the 'dynamic' attribute to decide whether to emit ObjC dispatches.
When -enable-dynamic is passed, only require ObjC dispatch for 'dynamic' methods and accessors instead of for all @objc entities.

Swift SVN r19839
2014-07-11 00:12:25 +00:00
Chris Lattner
5b49d59c57 Remove the @ from @final and @lazy, the last major piece of
rdar://17168115.

Also, reinstate the ARM driver change and testcase that I removed
in my last patch.


Swift SVN r19790
2014-07-10 06:23:27 +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
Joe Groff
0cd01ee148 SILGen: Correctly determine whether property accessors are dynamically dispatched.
We were getting this wrong for properties introduced in class extensions, for which we currently do not emit vtable entries and so are statically dispatched. Fixes <rdar://problem/17577579>. This also incidentally fixes references to properties of generic classes, which should be dynamically dispatched, but weren't because of getDeclaredTypeOf/InContext confusion.

Swift SVN r19641
2014-07-07 22:21:04 +00:00
Joe Groff
e37829e49b SILGen: Factor 'getMethodDispatch' out of SILGenApply.
We need to be able to ask whether a method requires dynamic dispatch in other places in SILGen. NFC yet, but a step on the way to fixing <rdar://problem/17577579>.

Swift SVN r19636
2014-07-07 21:24:29 +00:00
Chris Lattner
63b561aed1 fix <rdar://problem/17556858> delegating init that delegates to @transparent init fails
This is a nasty issue where inlining @transparent functions breaks DI, just disable transparent
inlining in this narrow case.



Swift SVN r19614
2014-07-07 16:25:41 +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
Joe Groff
8c1186cfc3 SILGen: Add support for address-only Builtin.reinterpretCast.
Lower to unchecked_addr_cast when one or both of the source or destination types are address-only.

Swift SVN r19082
2014-06-22 19:31:57 +00:00
Joe Groff
3fc9f8497f AST: Add Builtin.reinterpretCast.
SILGen lowers this to unchecked_trivial_bit_cast or unchecked_ref_bit_cast based on the semantics of the input and output types, raising an unsupported error if one of the types are address-only.

Swift SVN r19058
2014-06-21 00:23:46 +00:00
Joe Groff
18b4650f50 Sema/SILGen: Make default argument generators work for generic functions.
Tweak the AST representation and type-checking of default arguments to preserve a full ConcreteDeclRef with substitutions to the owner of the default arguments. In SILGen, emit default argument generators with the same genericity as the original function.

Swift SVN r18760
2014-06-09 22:16:57 +00:00
Doug Gregor
4dad2d13da Use the allocating constructor when delegating to a factory initializer.
This makes imported factory initializers (barely) usable from
Swift-defined convenience initializers, which is needed for
<rdar://problem/16509024>.

This is all an egregious hack, because factory initializers should
really be expressible in Swift and should only emit allocating
constructors. Doing this correctly is tracked by <rdar://problem/16884348>.




Swift SVN r17946
2014-05-12 18:29:03 +00:00
Ted Kremenek
a4f8afc3e6 Using an optional for 'SILDeclRef::Kind' value (-Wconditional-uninitialized).
This looks like this may always be initialized, but the logic is
a bit harder to follow and this simple extra checking doesn't
really cost us.

Swift SVN r17615
2014-05-07 07:34:50 +00:00
Joe Groff
bf858cc8a1 SILGen: Handle inner pointer returns through currying and dynamic lookup.
When we partially apply an inner-pointer method or property, the thunk or partial_apply that applies "self" needs to be the one that handles lifetime-extending "self". Verify that a partial_apply-ed inner pointer method is not inner pointer and implement lifetime extension in the partial apply thunk. Fixes <rdar://problem/16803701>.

Swift SVN r17321
2014-05-03 18:37:42 +00:00
Joe Groff
a3a54545e5 SIL: Fix up ownership and bridging when emitting dynamic method calls.
There were a bunch of things broken here--it's amazing this ever appeared to work.

- Retain 'self' before partial_applying it to the method, so we don't overrelease it.
- Correctly lower the ownership conventions of the dynamic method against the SILDeclRef, so we don't overrelease arguments or over-over-release self, and we handle ObjC methods with weird conventions correctly.
- Thunk when there are bridging type differences between the partially-applied ObjC method and a Swift method, so we don't crash if the method takes NSStrings or other bridged types.

Add verifier checks that the result of 'dynamic_method' and BB arg of 'dynamic_method_br' actually match the method they're dispatching.

Swift SVN r17198
2014-05-01 22:46:11 +00:00
John McCall
61ac868714 Fix the implementation of Builtin.release from being
a net +1 to being a net -1.

I'm pretty sure I just copy-and-pasted this and then
forgot to actually implement it.  Oops.  In my defense,
I was planning to actually audit/test correctness when
I actually started doing CF management.

Swift SVN r16924
2014-04-27 08:47:56 +00:00
Chris Lattner
371a9316f4 - Introduce a new 'nonmutating' context sensitive keyword, and use it instead of @!mutating.
- Change the parser to unconditionally reject @mutating and @!mutating with a fixit and 
  specific diagnostic to rewrite them into the [non]mutating keyword.
- Update tests.

This resolves <rdar://problem/16735619> introduce nonmutating CS keyword and remove the attribute form of mutating all together



Swift SVN r16892
2014-04-26 21:00:06 +00:00
John McCall
6a9ab031c6 Add Builtin.retain and Builtin.release, and
make Builtin.autorelease an unbalanced operation.

Swift SVN r16794
2014-04-25 02:16:02 +00:00
Joe Groff
68f942117a SIL: Squash 'ref_to_native_object' and 'native_object_to_ref' into one 'unchecked_ref_cast' insn.
An unsafe cast from a base to a derived class isn't really all that different from one from Builtin.NativeObject to an arbitrary class, so relax this pair of instructions to allow an arbitrary bitcast. This only combines the instructions; it doesn't attempt to simplify any codegen that was emitting round-trip casts before yet.

Swift SVN r16736
2014-04-24 03:10:53 +00:00
Joe Groff
a65a693ac9 Add an 'autorelease' builtin instead of @asmname-ing objc_autorelease.
Swift SVN r16643
2014-04-22 04:29:33 +00:00
Joe Groff
d90f9d46ae SILGen: Lifetime-extend the "self" parameters of inner-pointer methods.
Do this the lazy way, just autoreleasing "self" after the call. A future optimization pass may be able to eliminate this autorelease when it recognizes the lifetime of the derived value, but that's not immediately necessary.

Swift SVN r16635
2014-04-22 00:25:17 +00:00
John McCall
8681963bcb A couple of long-overdue renames.
Builtin.ObjectPointer -> Builtin.NativeObject
Builtin.ObjCPointer -> Builtin.UnknownObject

Swift SVN r16634
2014-04-22 00:17:08 +00:00
Joe Groff
c73acc67f2 SIL: Add an "UnownedInnerPointer" result convention.
This will represent the return convention of imported __attribute__((objc_returns_inner_pointer)) methods. Leave it unimplemented for now until we can autorelease things sanely.

Swift SVN r16628
2014-04-21 21:57:13 +00:00
Doug Gregor
8bc2ea4ea1 Use designated/convenience initializer terminology throughout. NFC
Introduce CtorInitializerKind to describe the kind of an enum, rather
than a bool, to make way for more initializer kinds in the future.

Swift SVN r16525
2014-04-18 15:10:13 +00:00
Chris Lattner
2b7f6b82b4 rename Builtin.move to Builtin.take. This matches the SIL naming better,
and avoids confusion with the C++'11 notion of "move".  'take' destroys 
source, where std::move leaves it destroyable.


Swift SVN r16316
2014-04-14 14:33:30 +00:00
Chris Lattner
6e90d343be At long last, land the implementation of <rdar://problem/16397000> Should be able to override stored properties
This means that we now synthesize getters and setters a lot more than we used to, so the
implementation work on this shook out a ton of bugs with them.

There is still one failure that I don't understand at all (test/stdlib/NewArray.swift.gyb), 
nor do I understand how to diagnose the problem, so I XFAILed it and filed rdar://16604980 to
track fixing it.



Swift SVN r16299
2014-04-14 04:48:54 +00:00
John McCall
8a85750c4c Plumb a lot of querying for different kinds of existential
type.

Swift SVN r16232
2014-04-11 22:30:14 +00:00
Joe Groff
8adaab0233 Fold ExtInfo::isThin and ::isBlock into a "Representation" enum.
These bits are orthogonal to each other, so combine them into one, and diagnose attempts to produce a type that's both. Spot-fix a bunch of places this revealed by inspection that we would have crashed in SILGen or IRGen if blocks were be handled.

Swift SVN r16088
2014-04-09 00:37:26 +00:00
Joe Groff
2189947cb0 Use report_fatal_error instead of exit(1) after unrecoverable problems in SILGen or IRGen.
Swift SVN r16059
2014-04-08 17:33:21 +00:00
Chris Lattner
d491f5121e Add parsing and SILGen support for @final methods and properties.
This is missing almost all semantic analysis and is missing various
optimization opportunities (e.g. final methods that are not overrides
don't need vtable entries), but this is enough to devirtualize class
stuff, which is important for our performance efforts.  I'll add this
to release notes when it is more fully fleshed out.



Swift SVN r15885
2014-04-03 17:53:52 +00:00
Chris Lattner
6540423613 rename CopyValueInst -> RetainValueInst. The .sil syntax
isn't changed yet.


Swift SVN r15775
2014-04-02 05:11:31 +00:00