Commit Graph

6754 Commits

Author SHA1 Message Date
Joe Groff
e8f71c12a2 Rename ObjCMutablePointer to AutoreleasingUnsafePointer.
This relates its interface and behavior to that of UnsafePointer, and draws an analogy to '__autoreleasing *' in ARC.

Swift SVN r18236
2014-05-17 04:44:44 +00:00
Joe Groff
793fe06a34 SILGen: Emit an artificial toplevel for files with @UIApplicationMain classes.
If a source file contains the main class for its module, then implicitly emit a top_level_code that invokes UIApplicationMain with the name of the marked class.

Swift SVN r18088
2014-05-15 00:53:38 +00:00
Doug Gregor
1e9f16038c Remove my accidental commit in r18010.
Swift SVN r18018
2014-05-13 20:03:24 +00:00
Nadav Rotem
185edf0492 Fix what looks like a typo to fix the buildbots.
Swift SVN r18012
2014-05-13 17:16:14 +00:00
Doug Gregor
d5a9c2ab94 Only supersede initializers with other imported initializers when the types match.
This fixes a case where the Swift-variadic and C-varargs versions of
various initializers were superseding each other
<rdar://problem/16801456>.

It also uncovered some more cases where we weren't getting quite the
right semantics for factory-methods-as-initializers, which are also
fixed here.

Swift SVN r18010
2014-05-13 16:49:39 +00:00
Joe Pamer
1e5b9116d4 More array casting work:
- Continue adding support for checked downcasts of array types (rdar://problem/16535104)
- Fix non-bridged array conversions post-r17868
- Fix rdar://problem/16773693
- Add tests for NSArray coercions to and from Array<T>

Swift SVN r17957
2014-05-12 20:49:42 +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
Joe Groff
02fb8b3451 SILGen: Don't overrelease arrays and dictionaries after bridging.
The bridging function takes the original value at +1, so it needs to be consumed so it isn't released in the caller. Fixes <rdar://problem/16877676>.

Swift SVN r17944
2014-05-12 18:04:31 +00:00
Chris Lattner
feddbc1844 fix <rdar://problem/16880044> unowned let properties don't work as struct and class members
Swift SVN r17934
2014-05-12 15:42:12 +00:00
Doug Gregor
f369a22a0a Remove the isConvenienceInit hack from SILGen
Swift SVN r17932
2014-05-12 15:13:53 +00:00
Chris Lattner
e2e36f2832 rework OwnershipComponent: instead of being the root of an lvalue, make it be
an interior node that remaps the weak/unowned storage representation to its
strong rvalue representation.  This allows it to chain on top of ValueComponent
and other memory-addressing things.  NFC.


Swift SVN r17931
2014-05-12 15:07:10 +00:00
Chris Lattner
38a16df992 fix <rdar://problem/16880240> SILGen crash assigning to _
Swift SVN r17913
2014-05-12 01:50:57 +00:00
Doug Gregor
5159201aed Bridge T[] to NSArray when T is bridged to Objective-C.
Generalize the bridging of AnyObject[] to NSArray into bridging T[] to
NSArray, following what we already have for dictionaries. Use some new
Foundation-level entry points for the bridging, which could use an
audit from someone who understands Array better than I do.

Part of <rdar://problem/16535097>.


Swift SVN r17869
2014-05-11 06:12:34 +00:00
Chris Lattner
527da39f32 now that unowned pointers basically work with closures in general, wire us SILGen support
for capture lists and add testcases for stuff that works.

Still more to come, weak pointers need work and one unowned pointer case doesn't work.


Swift SVN r17860
2014-05-11 00:16:19 +00:00
Chris Lattner
761c627b38 Rework SILGenFunction::emitInitializationForVarDecl to make sure that
weak/unowned global variables get emitted with a
ReferenceStorageInitialization.  This fixes test/DebugInfo/attributes.swift



Swift SVN r17856
2014-05-10 23:54:20 +00:00
Chris Lattner
512d5ea05d Fix: <rdar://problem/16877510> capturing an unowned let crashes in silgen
There were two problems here: emitRValueForDecl wasn't doing a semantic 
conversion to an RValue when loading from let vardecls of reference storage
type, and we were trying to capture the rvalue type (not the storage type)
when forming the capture.



Swift SVN r17854
2014-05-10 23:09:24 +00:00
Chris Lattner
368fdd67b5 rearrange the order in which we set up initializations, so that
'unowned let' initializations don't drop their ReferenceStorageInitialization
transformation.  This defines away another class of problems related to weak and
unowned pointers, and allows us to remove a hack added to paper over rdar://16681656.


Swift SVN r17846
2014-05-10 21:09:54 +00:00
Chris Lattner
f8ce2a3a87 Fix <rdar://problem/16871284> silgen crashes on weak capture
This reworks handling of weak/unowned values to represent them as logical 
lvalues instead of as physical lvalues.  Representing them as physical
lvalues breaks a lot of assumptions throughout silgen because (while they
have the same in-memory representation) weak pointers and optional have
different dynamic behavior.

This will hopefully make weak pointers generally more reliable than they
have been.  One causualty of this is that the "copy_addr" peephole is defeated
for the case that you copy a weak lvalue to another weak lvalue, but correctness
needs to win, and this can be added back later when it becomes a priority.



Swift SVN r17842
2014-05-10 20:31:01 +00:00
Joe Groff
3dda4c9cf5 SILGen: Reference ObjC initializers and factories through foreign-to-native thunks.
Eliminate the duplicate half-broken bridging logic in emitClassConstructorAllocator by referencing foreign initializers through their foreign-to-native thunks, which SILGen knows how to emit already. Do the same thing for factory initializers by suppressing their normal allocating initializer codegen and just referencing the usual foreign-to-native thunk for them. This fixes <rdar://problem/16853205> because we get the ownership thunking right now.

Swift SVN r17840
2014-05-10 20:18:53 +00:00
Doug Gregor
104cf17d5d SILGen: Bridge Dictionary<K, V> <-> NSDictionary in Objective-C thunks.
Implements the majority of Dictionary bridging in SILGen
<rdar://problem/16870626>.

Swift SVN r17838
2014-05-10 19:51:00 +00:00
Doug Gregor
335c605d58 Allow one to disable verification of a bridging function's parameter/result types.
This should be used sparingly , for cases where forming the parameter/result types is tricky due to generics. If we could form those types without too much pain, it'd be better to remove this hack. However, it enables bridging in cases where we need generic bridging.

Swift SVN r17837
2014-05-10 19:50:59 +00:00
Chris Lattner
8aa65c027e teach the AST walker to walk into the capture list of closure exprs, teach the
type checker to type check them, tweak the ast dumper to dump out something nicer.



Swift SVN r17832
2014-05-10 19:17:13 +00:00
Argyrios Kyrtzidis
19aeaf94fc Fully embrace ParamDecls instead of AnyPattern at function creation time, thus removing the need to create param decls at SILGen or Sema.
Swift SVN r17829
2014-05-10 18:23:50 +00:00
Joe Groff
0695e0e4e4 SILGen: Scope bridging temporaries in allocating inits until after the initializer method has been called.
This keeps us from prematurely releasing values before they're needed by the underlying initializer, which caused a crash if you tried to pass a Swift array into NSArray(objects:count:) via pointer bridging. <rdar://problem/16738050>

Swift SVN r17812
2014-05-09 23:27:09 +00:00
Joe Groff
d6957d0328 Make existential-to-concrete metatype casts work.
This mostly falls out from the metatype cast infrastructure, but we need to generalize some Sema and SILGen code to accept AnyMetatypeType. Concrete-to-existential metatypes will need more runtime checking that isn't implemented, so raise a 'not implemented' error on those for now.

Swift SVN r17798
2014-05-09 20:57:55 +00:00
Joe Groff
0e0e151680 SILGen: Reabstract metatypes to thick representation when checked-casting them.
Fixes a crash when a concrete non-polymorphic type like 'Int.self' is used as the source of a metatype cast.

Swift SVN r17778
2014-05-09 16:10:05 +00:00
Joe Groff
692ef04b72 SILGen: Always dispatch Swift class witnesses natively even when @objc.
Maybe we should wrap the @objc dispatch in another thunk in order to account for ObjC dynamic magic, but this is the shortest path to getting proper class dispatch behavior for witnesses in all cases and close <rdar://problem/14620454>.

Swift SVN r17757
2014-05-09 03:28:31 +00:00
Joe Groff
fcd0816179 SILGen: Emit witness function refs through 'emitGlobalFunctionRef'.
This ensures that if the witness is a foreign-to-native, curry, or other lazily-generated thunk, that the thunk gets generated. This fixes natively-ObjC witnesses to Swift protocols.

Swift SVN r17739
2014-05-09 00:14:43 +00:00
Joe Pamer
709da29301 Implement checks for conditionally bridged types when performing a bridged conversion between array types. (rdar://problem/16540403)
Swift SVN r17660
2014-05-08 00:58:30 +00:00
Joe Groff
4bc0a8b964 SILGen: Change the signature of _convertStringToNSString and _convertNSStringToString not to use inouts.
This was an artifact of their long-dead C++-based implementations that was way past due to clean up. It's also a convenient workaround for <rdar://problem/16835447>, since we no longer have to look up constructor members for String at SILGen time and potentially lazily instantiate Clang-imported types during SILGen. This totally isn't a real solution to that problem, but it puts out the fire for now.

Swift SVN r17643
2014-05-07 21:50:03 +00:00
Joe Pamer
2eedc06d66 Begin adding plumbing for the type checker to accept "forward" bridged array conversions. (rdar://problem/16540403)
Swift SVN r17640
2014-05-07 19:45:37 +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 Pamer
edb4946f66 Begin updating type checking of array upcasts to conform with the new spec.
Also, call through DaveA's new entry point for upcasts on Array<T>.

Swift SVN r17564
2014-05-06 21:32:22 +00:00
Doug Gregor
eb7a9144a8 Bring keyword arguments to subscripts.
Subscript declarations were still encoding the names of index
variables in the subscript type, which unintentionally made them
keyword arguments. Bring subscript declarations into the modern day,
using compound names to encode the subscript argument names, which
provides consistency for the keyword-argument world
<rdar://problem/14462349>. Note that arguments in subscripts default
to not being keyword arguments, which seems like the right default.

We now get keyword arguments for subscripts, so one can overload
subscripts on the names of the indices, and distinguish at the call
site. Under -strict-keyword-arguments, we require strictness here as well.

The IRGen/IDE/SILGen test updates are because the mangling of common
subscripts changed from accidentally having keyword arguments to not
having keyword arguments.

Swift SVN r17393
2014-05-04 19:31:09 +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
Michael Gottesman
a7bb61265c [deserialization] Tighten up deserialization of witness tables.
We now enforce via an assert that each witness table is unique and that
every protocol conformance that is referenceable from SIL must have a
witness table matched to it.

Also, I taught the linker that it should deserialize witness tables for
InitExistentialRefInst instructions, something that was missed before.

Swift SVN r17283
2014-05-02 22:28:13 +00:00
Joe Groff
dd9ee77b5e Trim stale comment.
Swift SVN r17279
2014-05-02 22:04:40 +00:00
Ted Kremenek
050fd53af7 Rename UncheckedOptional to ImplicitlyUnwrappedOptional.
Swift SVN r17232
2014-05-02 06:13:57 +00:00
Doug Gregor
b46e6cc5b7 Suppress Swift vtable entries for getters/setters of @NSManaged properties.
This finishes up the functional behavior of
<rdar://problem/16736676>. Some QoI remains.


Swift SVN r17209
2014-05-01 23:30:04 +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
Doug Gregor
af1f5b7baf Don't emit @objc thunks for @NSManaged properties.
Another part of <rdar://problem/16736676>.

Swift SVN r17197
2014-05-01 22:42:55 +00:00
Doug Gregor
f2e331f6ed Don't emit @objc thunks for @NSManaged properties.
Another part of <rdar://problem/16736676>.

Swift SVN r17194
2014-05-01 22:24:32 +00:00
Doug Gregor
3d3ff6811a Add a pile of missing #includes exposed by pruning includes in top-of-tree LLVM.
Swift SVN r17157
2014-05-01 14:26:34 +00:00
Joe Groff
aeb607ad5b Fix latent SIL verification errors.
r15824 overrode SILVerifier::visitSILBasicBlock without calling up to the super definition, causing us to never actually verify any instructions for the past three weeks. Awesome. Patch up the latent bugs that have crept in, except for three devirtualizer tests that fail. This doesn't reenable the verifier because I don't want to cause crashes until all the regressions have been cleared up.

Swift SVN r17121
2014-04-30 22:33:46 +00:00
Joe Groff
164870c0c3 SILGen: Reenable partial application of ObjC methods.
Make ObjC method partial applications go through a native-to-foreign thunk so that we properly handle bridging conversions in the resulting function value. Partial applications through dynamic lookup are still broken because they apparently go through a different path.

Swift SVN r17108
2014-04-30 19:57:44 +00:00
Chris Lattner
53a8a06b9d ongoing progress on TypeExpr rollout, this makes it handle existential metatypes
better and cleans up some interfaces.  They aren't used enough to make much of a
difference yet.



Swift SVN r16957
2014-04-28 02:22:25 +00:00
Joe Groff
78d8fbdb67 SILGen: Don't emit into reference storage buffers.
Trying to use a @weak slot as an in-place initialization buffer for an Optional is never going to end well, so refuse to offer reference storage slots as buffers for expr results. Fixes <rdar://problem/16681656>.

Swift SVN r16956
2014-04-28 00:32:43 +00:00
Joe Groff
31e761ca3e SILGen: Don't overrelease the for-each iteration value when break-ing.
We don't ever need to destroy_addr the iteration value buffer, because either the for loop exited normally because it's nil, or it exited by 'break' and it contains a stale 'Some' value that was consumed by the loop body. Fixes <rdar://problem/16687672>.

Swift SVN r16942
2014-04-27 21:39:03 +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
Ted Kremenek
49f393920a Rename bridging "convert" functions to start with '_'.
This is part of our poor-man's internal compiler SPI hiding
in the standard library.  We don't want these functions showing
up in code completion, etc.

Swift SVN r16916
2014-04-27 05:13:19 +00:00