Commit Graph

421 Commits

Author SHA1 Message Date
Joe Groff
1c4e08a9c8 Fix up a tangle of issues related to reabstraction.
- A spot fix in SILGen for reabstracting the result of a downcast, which fixes checked casts to function types.
- Associate the layout information in type metadata records with the most abstract representation of the type. This is the correct thing to do in cases where we need the metadata as a tag for an opaque value--if we store a value in an Any, or pass it as an unconstrained generic parameter, we must maximally reabstract it. This fixes the value semantics of existentials containing trivial metatypes.
- To ensure that we get runtime layout of structs and enums correct when they contain reabstractable types, introduce a "metadata for layout" concept, which doesn't need to describe the canonical metadata for the type, but only needs to describe a type with equivalent layout and value semantics. This is a correctness fix that allows us to correctly lay out generic types containing dependent tuples and functions, and although we don't really take advantage of it here, it's also a potential runtime performance win down the road, because we could potentially produce direct metadata for a primitive type that's layout-equivalent with a runtime-instantiated type. To aid in type safety here, push SILType deeper into IRGen in places where we potentially care about specific representations of types.
- Finally, fix an inconsistency between the runtime and IRGen's concept of what spare bits unmanaged references and thick metatypes have.

Together, these fixes address rdar://problem/16406907, rdar://problem/17822208, rdar://problem/18189508, and likely many other related issues, and also fixes crash suite cases 012 and 024.

Swift SVN r21963
2014-09-16 01:44:34 +00:00
Doug Gregor
a7e42e9215 Don't use the destructor type to compute the @encoding of Objective-C ivar initializers/destroyers.
This was preventing generic subclasses of NSObject unnecessarily
rdar://problem/17417625, and there is no reason to compute the
encoding for each one: it will always be @?.


Swift SVN r21777
2014-09-08 17:34:59 +00:00
John McCall
0ddc7ee5b6 Resilience expansion is not an IR-generation concept.
If a type has to be passed or returned resiliently, it
will necessarily be passed indirectly, which is already
represented in SILFunctionType.  There is no need to
represent this as a separate channel of information.

NFC. Also fixes a problem where the signature cache
for ExtraData::Block was writing past the end of an
array (but into the storage for an adjacent array
which was fortunately never used).

ExtraData should also disappear as a concept, but we're
still relying on that for existential protocol witnesses.

Swift SVN r21548
2014-08-28 23:07:50 +00:00
John McCall
f7ebe89949 Set up the ARM retainAutoreleasedReturnValue markers
correctly in optimized builds.

rdar://17999904

Swift SVN r21323
2014-08-20 22:48:55 +00:00
John McCall
64aa0ea950 When instantiating a generic class, compensate for
unexpected forematter from the superclass.

This requires a pretty substantial shift in the
generic-metadata allocation/initialization dance
because (1) we can't allocate class metadata without
knowing what the superclass is and (2) the offset
from the metadata cache entry to the address point is
no longer determined solely by the metadata pattern.

While I'm making invasive changes to metadata, fix
two race conditions in metadata creation.  The first
is that we need to ensure that only one thread succeeds
at lazily creating a generic-metadata cache.  The second
is that we need to ensure that only one thread actually
attempts to create a particular metadata; any others
should block until the metadata is successfully built.

This commit finishes rdar://17776354.  LLDB will
need to adjust to the runtime-private metadata layout
changes.

Swift SVN r20537
2014-07-25 10:08:51 +00:00
Jordan Rose
b6818046a8 Eliminate optimization levels 0-3 in favor of -Onone/-O/-Ofast.
We were already effectively doing this everywhere /except/ when building
the standard library (which used -O2), so just use the model we want going
forward.

Swift SVN r20455
2014-07-24 01:12:59 +00:00
John McCall
807619b3c8 Force classes to be realized before forming a metadata
reference to them.

Fixes rdar://17776354.

Swift SVN r20384
2014-07-23 09:28:34 +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
55c7b72e94 IRGen: Use property-style ObjC encoding for property metadata.
Finish up <rdar://problem/17373368> now that Clang has an API to properly encode the property type.

Swift SVN r19708
2014-07-08 22:31:59 +00:00
Joe Groff
cd5a624bbc IRGen: Emit more accurate property metadata.
Instead of hacking together inaccurate metadata only for object-typed properties, make an effort to produce accurate metadata for all types of properties, and accurately capture the "copy", "dynamic", and "weak" semantics of some properties. This is necessary for Core Data to accurately synthesize property accessors for non-object properties; currently it will generate bogus object accessors over properties with non-object type. <rdar://problem/17373368>

This isn't fully accurate, since Clang hides property type encoding behind a 'getObjCEncodingForPropertyDecl' that only accepts an ObjCPropertyDecl. With some refactoring, it should be possible to expose this.

Swift SVN r19567
2014-07-04 15:58:18 +00:00
Joe Groff
0af4761d68 IRGen: Accurately convert SIL block types to Clang block types.
Although block types are invariant to ABI layout, they do need to be accurately encoded in method and block signatures for XPC to work correctly.

Swift SVN r19049
2014-06-20 20:00:27 +00:00
Jordan Rose
aaa147e1c9 Eliminate some uses of PolymorphicFunctionType.
No functionality change.

Swift SVN r18819
2014-06-12 01:29:48 +00:00
Joe Groff
8c974dfd5b SILGen: Emit @objc thunks with external linkage, even when local.
We do this hack for @objc methods at the top level, emitting them as external in SIL and making them private in IRGen, to prevent SIL optimizations from dropping the functions as unused (see <rdar://problem/17074598>), but we weren't doing so for @objc classes in local contexts, and they were getting dropped. Fixes <rdar://problem/16982281>.

Swift SVN r18668
2014-05-30 03:23:42 +00:00
John McCall
cc1d8b606f Look through reference storage types when generating
@encodings for property getter/setters.

rdar://16909436

Swift SVN r18399
2014-05-19 08:00:07 +00:00
John McCall
af92489d00 Cache the transformation of Swift types to Clang types.
Should fix <rdar://16830685>.

Swift SVN r18247
2014-05-17 08:52:34 +00:00
Joe Groff
7959032c46 IRGen: Work around an assertion compiling ObjC entry points for local classes.
This is still a kludge setting the visibility of ObjC thunks at IRGen rather than SILGen time, but resolves <rdar://problem/16906857>.

Swift SVN r18063
2014-05-14 05:22:06 +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
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
Doug Gregor
55a5709771 SILGen support for convenience factory and factory initializers.
These initializers are class methods, so provide them with the
metatype value rather than allocating an object. Moreover, they
generally return autoreleased, so we need to retain them out of the
autorelease pool before returning the produced 'self'.

Finishes the SILGen and IRGen portions of
<rdar://problem/16509024>. We still can't enable this in practice
because we're getting duplicate initializers, as predicated in the
hacky r16531.

Swift SVN r16555
2014-04-18 23:40:35 +00:00
Dmitri Hrybenko
e2e8db5f38 Migrate IB attributes to new decl attribute representation and fix a few bugs
along the way


Swift SVN r16542
2014-04-18 20:00:09 +00:00
Joe Groff
318aba81ef IRGen: Implement block header generation.
Implement the init_block_storage_header SIL instruction by teaching IRGen how to produce block descriptors, including copy/dispose helpers and block signatures.

Swift SVN r16478
2014-04-17 22:40:23 +00:00
John McCall
063552c4a1 Emit the assembly markers for objc_retainARV on ARM.
...I hope.  It is frustrating that testing this effectively
seems to require a massively different build environment.

More of rdar://16565958.

Swift SVN r16468
2014-04-17 21:42:32 +00:00
Doug Gregor
53b84c121e Switch ValueDecl::getObjCSelector() and friends over to ObjCSelector.
Formatting names into strings repeatedly, and using those for semantic
analysis, is generally considered poor form. Additionally, use the
camelCase utilities to perform the string manipulation we need, and
cache results on the ObjCAttr so we don't repeatedly do string
manipulation.

Swift SVN r16334
2014-04-14 22:02:51 +00:00
Joe Groff
42a942925b Enable block bridging.
Swift SVN r16248
2014-04-12 05:13:45 +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
def2f97944 IRGen: Generalize 'hasSwiftRefcount' into an enum of reference counting mechanisms.
Replace HeapTypeInfo::hasSwiftRefcount with a "getSwiftRefcounting" method, returning an enum indicating whether a heap object has native/ObjC/block/unknown refcounting semantics. Use _Block_copy and _Block_release for block refcounting.

Swift SVN r16041
2014-04-08 02:43:16 +00:00
Doug Gregor
f2578cb605 Use a named @objc to provide the name for methods, initializers, getters, and setters.
This is all of the functionality of <rdar://problem/16019773>, but
some cleanup remains.


Swift SVN r15641
2014-03-30 03:59:01 +00:00
John McCall
a070724719 Thick and ObjC metatypes have spare bits.
The important thing here is that we want optional
metatypes to be layout-compatible with metatypes
(of either thick representation).

Swift SVN r15625
2014-03-29 19:17:11 +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
Doug Gregor
9400e890d3 Emit @objc classes using namespaced names under a new flag -enable-objc-mangling.
Centralize the logic for figuring out what name to use for a class or
protocol in the Objective-C runtime. When the flag is enabled (it's
still disabled by default), use mangled names for all Swift-defined
classes, including those that are @objc. Note that the naming is
determined in the AST, because we're also going to use this logic when
printing an Objective-C header for Clang's consumption. The mangled
names will always start with _Tt, so they're easy to recognize and
demangle in various tools or, eventually, in the Objective-C runtime.

The new test (test/IRGen/objc_mangling.sil) is the only test of this
behavior at the moment. The other test changes are due to the
centralized logic tweaking the names of internal constants (_DATA_*,
_CATEGORY_*, etc.).

This is the majority of <rdar://problem/15506580>.



Swift SVN r15588
2014-03-28 23:00:08 +00:00
Fariborz Jahanian
6b5d484af1 [IRGen] Extended encoding of id<protocol-list>
in extended protocol meta-data. wip. Will have tests
when it is complete. // rdar://16308986
(note that you need the latest clang pulled or 
your compile will fail).


Swift SVN r15270
2014-03-20 17:54:04 +00:00
Fariborz Jahanian
b15d326bd8 Adds support for extended method signature for
methods declared in protocols. // rdar://16308986


Swift SVN r15239
2014-03-19 17:19:12 +00:00
John McCall
794360d312 Permit optional class types to be returned autoreleased.
Swift SVN r15042
2014-03-14 07:10:10 +00:00
John McCall
446a9bd4a7 Introduce CanType versions of the various "getXOrBoundGenericX"
accessors.

Optimize these accessors by making them check for
BoundGenericXType instead of BoundGenericType and dyn_cast'ing
the Decl.  (The latter used to be necessary before we split
BoundGenericType.)

Swift SVN r15037
2014-03-14 05:59:44 +00:00
Joe Groff
70f4f1db8d SILGen: Allow @objc_block properties to be @objc-dispatched.
Our guard against dispatching function properties should only apply to @objc_blocks. Fixes <rdar://problem/16223478>.

Swift SVN r14741
2014-03-06 18:35:39 +00:00
John McCall
79fad0cc87 Remove FunctionRef and CodeRef from IRGen in favor of SILDeclRef.
Swift SVN r14248
2014-02-22 01:45:44 +00:00
John McCall
3d5d8fdc03 Resilience expansion is really an aspect of a SILDeclRef.
We should also remove it from IRGen's Explosion API; IRGen
should always use maximal explosion, and SILGen will tell us
whether or not we need to put that in memory somewhere.
But that can be a later commit.

Swift SVN r14242
2014-02-21 23:28:43 +00:00
John McCall
32cf8b3bac Preserve SIL function order in the parser and IRGen.
We're mostly not that bad about this right now, but lazy
emission is going to wreak havoc.

Note that SILGen itself doesn't really make very good decisions
about the order in which to emit functions, but step one
towards fixing that is actually respecting it.

Swift SVN r14200
2014-02-21 02:22:03 +00:00
Doug Gregor
3182cd3910 Introduce thick/Objective-C metatype conversion instructions.
Introduce the SIL instructions thick_to_objc_metatype and
objc_to_thick_metatype to convert between the 'thick' and
'Objective-C' representations of a metatype. Most of this code is
trivial support code for these conversions: printing, parsing,
(de-)serialization, etc., for which testing will come online in
subsequent patches or is incidental in other tests.

Lower Objective-C metatype values down to objc_class* at the IR level
and implement IRGen support for these SIL instructions. SIL-only test
case at the moment because SILGen never creates these instructions.



Swift SVN r14087
2014-02-19 18:20:21 +00:00
Doug Gregor
c54f98fbc9 Convert thick/thin metatype bool to an enumeration. NFC
Swift SVN r14075
2014-02-19 06:05:48 +00:00
Chris Lattner
d88852e457 remove SILDeclRef::Getter/Setter and supporting code. NFC, but I think
the previous patches have defined away a few obscure bugs handling subscript 
accessors (from inspection).


Swift SVN r13885
2014-02-14 01:12:56 +00:00
Chris Lattner
12196c17ba Now that we always have funcdecls for getters and setters, we don't need
SILDeclRef::Getter/Setter and the complexity therein.  Switch the world
to make SILDeclRef::Func's instead of them.  NFC.


Swift SVN r13875
2014-02-13 23:11:29 +00:00
Chris Lattner
3f7d3877a4 Re-commit r13836 with more correctness this time:
Sink the getObjCGetterSelector/Setter methods from VarDecl/SubscriptDecl down to
AbstractStorageDecl.  NFC.



Swift SVN r13842
2014-02-12 22:49:47 +00:00
Mark Lacey
525c9323cc Revert "since the getObjCGetterSelector/Setter methods from VarDecl/SubscriptDecl down"
This reverts commit r13836, since it broke the build.

Swift SVN r13839
2014-02-12 20:59:24 +00:00
Chris Lattner
c23185d9ba since the getObjCGetterSelector/Setter methods from VarDecl/SubscriptDecl down
to AbstractStorageDecl, NFC.


Swift SVN r13836
2014-02-12 19:16:40 +00:00
Mark Lacey
70fa0dead0 Select ABI types for all arguments of a C/ObjC function together.
Updates to signature expansion, entrypoint lowering, and callsite
lowering so that each selects the ABI types for all arguments at once
rather than an argument at a time (as well as considering whether the
return value is returned indirectly). This is required to get the
correct behavior in cases where we run out of argument registers and
need to pass arguments as indirect byvals.

This is mostly just refactoring existing code to move loops inside inner
functions as well as dealing with return values at the same time as
arguments.

Swift SVN r13781
2014-02-11 06:45:53 +00:00
Joe Groff
b19cfb27ea Drop the context generic params from SILFunctionType.
SILFunctionType is now 100% context free!

Swift SVN r13775
2014-02-11 04:21:20 +00:00
Joe Groff
481fbb7b91 Drop the non-interface types from SILFunctionType.
There are some straggling references to the context generic param list, but nothing uses the non-interface param or result types anymore!

Swift SVN r13725
2014-02-09 22:39:01 +00:00
Fariborz Jahanian
99b74fb3b4 [IRGen] finishes off encoding of method and
prperty types and removes special case encoding
of property setter and getters since we now can
encode anything. // rdar://15541020


Swift SVN r13639
2014-02-07 18:33:43 +00:00
Chris Lattner
290a58494e Implement debug info for willset/didset, and teach dispatch to be non-virtual
to didset/will set since we don't drop these in the class vtable.


Swift SVN r13056
2014-01-28 06:33:31 +00:00