Commit Graph

1232 Commits

Author SHA1 Message Date
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
Joe Groff
ba34976f87 SILGen: Implement lowering for writeback conversion.
Lower LValueConversionExprs to LValueConversionComponents of SILGen's LValues, which add the conversion pair as a logical component of a writeback chain.

Swift SVN r15771
2014-04-02 03:15:12 +00:00
John McCall
f1180f5e6d in order to work correctly for non-@objc protocols.
Language features like erasing concrete metatype
values are also left for the future.  Still, baby steps.

The singleton ordinary metatype for existential types
is still potentially useful; we allow it to be written
as P.Protocol.

I've been somewhat cavalier in making code accept
AnyMetatypeType instead of a more specific type, and
it's likely that a number of these places can and
should be more restrictive.
When T is an existential type, parse T.Type as an
ExistentialMetatypeType instead of a MetatypeType.

An existential metatype is the formal type
 \exists t:P . (t.Type)
whereas the ordinary metatype is the formal type
 (\exists t:P . t).Type
which is singleton.  Our inability to express that
difference was leading to an ever-increasing cascade
of hacks where information is shadily passed behind
the scenes in order to make various operations with
static members of protocols work correctly.

This patch takes the first step towards fixing that
by splitting out existential metatypes and giving
them a pointer representation.  Eventually, we will
need them to be able to carry protocol witness tables

Swift SVN r15716
2014-04-01 00:38:28 +00:00
John McCall
1923cf510a existential_metatype returns a thick metatype, but
dynamic_method really expects an ObjC metatype.

Swift SVN r15666
2014-03-31 05:49:20 +00:00
John McCall
6e03b1423c Always coerce the operand of an optional force to
Optional type,

The attempt to coerce the operand to UncheckedOptional for
dynamic member accesses leads to an inconsistency when
applying the constraint solution because we haven't figured
out how to convert to UncheckedOptional<T> --- all the
conversion restrictions are to optional type.

The test case will be part of the standard test suite when
applying the UncheckedOptional import patch.

In order to continue to work around weaknesses in SILGen's
function conversion code, peephole optional conversion in
the function application path.

Swift SVN r15651
2014-03-30 19:15:18 +00:00
Joe Groff
584009d27e SIL: Remove copy_value's result.
We won't have any types where copying has an effect on the bit pattern (except for blocks, which need special handling anyway), and copy_value having a result makes optimizations more complex, so remove it.

Swift SVN r15640
2014-03-30 03:40:45 +00:00
Joe Groff
71404091d4 Add Builtin.fixLifetime as a way for library code to fix object lifetimes.
Lowers directly to the SIL fix_lifetime instruction.

Swift SVN r15637
2014-03-29 22:59:24 +00:00
Joe Groff
9f7dab725c Make the ASTContext parameter to MetatypeType::get optional for type-checked types.
We can just get it from the instance type, if the instance type has been fully initialized, which is the case except during parsing of type decls when the decls' own types are being formed.

Swift SVN r15598
2014-03-29 02:50:30 +00:00
Joe Pamer
56e2b28b76 Remove more unnecessary semicolons.
Swift SVN r15489
2014-03-26 06:07:06 +00:00
Joe Groff
f2ed6dd49b Reflection: Add additional dispositions and an 'AttributedString' QuickLookObject case.
<rdar://problem/16412965> and <rdar://problem/16413366>.

Swift SVN r15438
2014-03-25 02:55:20 +00:00
Joe Groff
b8b4f4efbe SILGen: Don't throw away the cleanup on accessor base args.
Getters and setters don't always take self at +1, in particular @objc accessors, so we can't just take the base object as an unmanaged thing. Fixes <rdar://problem/16398756>.

Swift SVN r15372
2014-03-22 22:12:32 +00:00
Chris Lattner
cecfcc38ff Fix rdar://16381392 - Super property references in non-objc classes should be direct,
a blocker for other property work.



Swift SVN r15274
2014-03-20 18:50:20 +00:00
Nadav Rotem
791d8ee6a5 a small cleanup.
Swift SVN r15217
2014-03-19 00:39:22 +00:00
Nadav Rotem
cdb1db8e8a Strip in-out qualifiers when inspecting closure arguments.
Swift SVN r15195
2014-03-18 17:36:40 +00:00
Chris Lattner
ce7bc53f50 implement <rdar://problem/16310561> Property vtables not set up correctly
This switches property/subscript dispatch to use virtual dispatch instead of static
dispatch.  This currently only works for computed properties (and subscripts of 
course), not stored ones yet.

Long story short, this:

class Base {
  subscript() -> Int {
    return 42
  }
}

class Derived : Base {
  @override
  subscript() -> Int {
    return 9
  }
}

var a : Base = Derived()
print(a[])

now prints 9 instead of 42.



Swift SVN r15142
2014-03-17 16:37:37 +00:00
Chris Lattner
4782017753 revert r15135, the missing IRGen piece breaks swiftFoundation, I can't stage it.
Swift SVN r15136
2014-03-17 15:54:31 +00:00
Chris Lattner
e99774329f switch properties and subscripts to be virtually dispatched when on any class,
not just @objc classes.  This is continued progress towards resolving rdar://16310561


Swift SVN r15135
2014-03-17 15:34:45 +00:00
Doug Gregor
3cc834714c SILGen for initialization using an existential metatype value.
Loosen the restrictions on open_existential_ref to also allow it to
refer to an existential metatype. When it does, open_existential_ref
returns the metatype for the opened archetype.



Swift SVN r15113
2014-03-16 20:52:54 +00:00
Doug Gregor
0c02a45745 Implement dispatch to @objc initializers through non-statically-derived metatypes.
Swift SVN r15097
2014-03-15 00:48:09 +00:00
John McCall
8a6dd6e124 Give CanType a getAnyOptionalObjectType accessor.
Swift SVN r15079
2014-03-14 22:00:06 +00:00
Joe Groff
cdd2ec38d2 SILGen: Add missing WitnessMarker to the synthesized generic signature of trait builtins.
Swift SVN r14946
2014-03-12 00:50:44 +00:00
Chris Lattner
d758e0dfe3 Eliminate more "DynamicLookup" in favor of "AnyObject", this is the
bulk of finishing rdar://13327098.


Swift SVN r14653
2014-03-04 22:15:46 +00:00
Doug Gregor
15be2159a2 Rename "abstract initializers" to "required initializers".
It's better than what we have.

Swift SVN r14620
2014-03-03 23:12:40 +00:00
Doug Gregor
82c1ba2e29 Remove peer_method instruction; we're no longer using it.
Swift SVN r14599
2014-03-03 17:13:06 +00:00