Commit Graph

562 Commits

Author SHA1 Message Date
Joe Groff
3cf9a13d68 IRGen: Fix some synchronization issues when skipping @objc protocols for witness emission.
We were stopping too early when binding witness tables for local archetypes, causing us to miss binding witness tables for native protocols if the number of total protocols was greater than the number of protocols with witness tables, and we failed to increment the local type data key to match the Archetype::getConformsTo() ordinal when binding polymorphic parameters. Together these fix rdar://problem/18232916 (though adding any methods to a class still crashes because of rdar://problem/17480006).

Swift SVN r21796
2014-09-09 03:22:49 +00:00
John McCall
590c25479d Use isa-masking to read the class object pointer from
instances of Swift subclasses of ObjC classes.

We were already doing this in the runtime.  This patch
unhides the runtime's mask word (swift_isaMask) and makes
IR-gen take advantage of it when it can.

Swift SVN r21592
2014-08-29 21:36:53 +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
c1b03784df Instead of passing type metadata to swift_initClassMetadata,
pass the size and alignment of each field.  Take advantage
of this to pass a constant size and alignment when
possible.

This avoids the need to recursively find type metadata for
every field type, allowing generic recursively-structured
classes to be built.  There are a number of more complicated
cases that this approach isn't good enough for, but this
is good enough for now to fix rdar://18067671.

Also make an effort to properly support generic subclasses
of Objective-C classes.

Swift SVN r21506
2014-08-28 01:27:53 +00:00
John McCall
77ea35ab46 Introduce a flag to mark classes with Swift-native
refcounting and take advantage of it.

Also, set the Swift1 flag in classes we generate.

Also, initialize a global cache of the non-pointer-isa
mask and use that instead of object_getClass, at least
within the runtime.

Also, centralize the runtime on a _swift_getSuperclass
function and make that use a direct access while we
await word from Greg on the desired ABI requirements.

Swift SVN r21077
2014-08-06 21:51:45 +00:00
Greg Parker
48ef4efb39 IRGen: Don't read an ObjC isa field directly when building a generic subclass
of a generic superclass.

A new generic class gets its metaclass's superclass pointer from the 
superclass's metaclass. On arm64 the superclass's metaclass may not be 
a pointer and must be fetched using object_getClass().

Three existing tests caught this bug but only when running on an iOS 8 
device. On iOS 7, the arclite implementation of objc_readClassPair() 
happened to rewrite the field before the runtime tripped over it.


Swift SVN r20811
2014-07-31 05:13:17 +00:00
John McCall
6165da998c Rename some of the emitTypeMetadataFor... routines to make
it clear that they're requesting a dynamic type.

Some conceptual functional change; practical functionality
change should be limited.

Swift SVN r20733
2014-07-30 04:40:51 +00:00
Joe Groff
48851bc8fc IRGen: Remove inaccurate assertion about extension methods.
@objc extension methods can override non-Clang-imported @objc methods in their superclass. Fixes <rdar://problem/17720365>.

Swift SVN r20687
2014-07-29 20:21:14 +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
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
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
John McCall
1ae1f750d0 Move most type metadata lookups into their own readnone
functions, and make those functions memoize the result.

This memoization can be both threadsafe and extremely
fast because of the memory ordering rules of the platforms
we're targeting: x86 is very permissive, and ARM has a
very convenient address-dependence rule which happens to
exactly match the semantics we need.

Swift SVN r20381
2014-07-23 07:38:26 +00:00
John McCall
ae0dfd4676 Change the layout of the extended class-object header: add
a flags field, add an instance address point field, and reserve
some additional space.

This change must be coordinated with a corresponding change
to ObjC runtime bits in libarclite; without this, dynamic
subclassing features like KVO will break.

The actual contents of the new fields can change without
bothering the ObjC runtime.

Swift SVN r20183
2014-07-18 21:39:43 +00:00
Joe Groff
03c9f871d2 IRGen/Runtime: Add a "primary generic parameters" count to generic parameter descriptors.
lldb needs this to be able to tell how many generic parameters are actually needed to instantiate a generic type. Fixes <rdar://problem/17425286>.

Swift SVN r19573
2014-07-04 19:34:11 +00:00
Joe Groff
a9a4601f22 IRGen: Update codegen for changes to cmpxchg LLVM instruction.
It now returns success as a separate i1 in the return struct.

Swift SVN r18883
2014-06-13 23:40:51 +00:00
Bob Wilson
fe63f7d35c GlobalAlias has been changing a fair amount lately upstream, but as of
r210062 they can point at arbitrary ConstantExprs again, and as of
r210734 our use of this can actually pass the IR verifier again.

Patch by Justin Bogner.

Swift SVN r18834
2014-06-12 19:48:41 +00:00
Chris Lattner
218859f7c2 Fix class metadata emission to properly strip ownership modifiers in a case
that it missed, fixing rdar://17220646.


Swift SVN r18738
2014-06-08 21:21:30 +00:00
Chris Lattner
2dc1df52d1 Implement <rdar://problem/16954464> Cannot make a strong IBOutlet
This adds support for the "strong" ownership modifier, and specifically 
make it override the "implicit weak" behavior of @IBOutlet.



Swift SVN r18737
2014-06-08 20:49:21 +00:00
Joe Groff
8c60c4af1f IRGen/Runtime: Emit distinct type metadata for block types.
Blocks need their own type metadata with value witnesses appropriate to the block representation. Fixes <rdar://problem/16918740> and <rdar://problem/16981126>.

Swift SVN r18508
2014-05-21 20:24:11 +00:00
Jordan Rose
99ae560530 [IRGen] Update for LLVM API change in r208983.
If you have not pulled this commit yet, it is safe to revert this locally.

Swift SVN r18207
2014-05-16 19:54:10 +00:00
John McCall
059ed4cd10 Propagate alignment arguments around through the
slow allocation/deallocation APIs.

Swift SVN r18160
2014-05-16 01:40:36 +00:00
Joe Groff
972ddc10d9 IRGen: Implement type metadata lookup for dynamic Self.
Fixes <rdar://problem/16925631>.

Swift SVN r18125
2014-05-15 20:44:59 +00:00
Joe Groff
202ee91549 IRGen/Runtime: Use objc_readClassPair to officially register generic classes with the ObjC runtime.
At long last, our generic classes are legal ObjC citizens. Note that you'll need to be either on OSX 10.10, or on OSX 10.9 with a recent enough Xcode 6.0 to have a not-broken arclite (6A207 worksforme) and building against a OSX 10.10 SDK, for this to work going forward.

Swift SVN r17916
2014-05-12 02:37:42 +00:00
Joe Groff
43cc4a28f2 IRGen: Instantiate ObjC metaclasses and rodata with generic classes.
If we officially register our classes with the ObjC runtime, we can't get away with generic class instances sharing a runtime name or a metaclass anymore, so pack the metaclass and rodata templates into the generic metadata template and add codegen to the fill function to wire up the references at instantiation time. Since we don't have a runtime mangler yet, create a stupid unique name for classes by tacking on the pointer value.

Swift SVN r17882
2014-05-11 19:42:38 +00:00
Ted Kremenek
3d3491b4c6 Initialize 'vwtableValue' to null (-Wconditional-uninitialized).
Swift SVN r17614
2014-05-07 07:34:49 +00:00
John McCall
bafeb84a56 Generate unique type metadata for foreign classes.
Swift SVN r17430
2014-05-05 06:45:42 +00:00
John McCall
b6831b0195 Extract a function to create a global string
constant for a type mangling.

Swift SVN r17429
2014-05-05 06:45:41 +00:00
John McCall
2b969c41a2 Track whether a class is "foreign" in the AST.
This basically just means "it's a CF class" for now,
but you could imagine applying this to all sorts of
class-like types from peer runtimes that we can't
support all possible language features for.

There are quite a few language features that require
fairly deep object-model integration to implement,
like subclassing and adding polymorphic methods.
Some of those features, like final classes, are useful
to generally support as attributes, but most of
them aren't.  At least in the short term, it makes
sense to have a big hammer we can hit things with.

Swift SVN r17428
2014-05-05 06:45:40 +00:00
Chris Lattner
a7012f23ef Remove swift::ArrayType. It is dead and vestigial code for supporting fixed size
arrays, which never got baked.  Remove it until we have time to do things right.


Swift SVN r16995
2014-04-28 21:18:27 +00:00
John McCall
63072df530 Add class size and address point fields to class metadata.
I've put these fields on the class object for now, just
so we can at least theoretically update them.  A superclass
that grew left rather than right could maybe even be made
to work with this schema, but probably not.

rdar://16705821

Swift SVN r16880
2014-04-26 10:57:50 +00:00
John McCall
f3d4513721 Turn some 64-bit metadata fields into 32-bit fields.
We really don't need to support individual objects
this large, much less more than 4 billion fields in
a single type.

Also rearrange the fields to bring the instance
size/alignment fields closer to the class header,
just for a minor locality win.

Swift SVN r16879
2014-04-26 09:43:39 +00:00
John McCall
cd8c2a47d4 Refactor metadata layout to allow non-pointer-sized
fields and reduce boilerplate.  NFC.

Swift SVN r16877
2014-04-26 07:00:55 +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
0cb9bb50c1 IRGen: Get 'isa' pointers via object_getClass for ObjC-heritage classes.
We can't know whether a mixed-heritage class has a non-pointer isa, so use object_getClass to get its isa pointer. Fixes <rdar://problem/16656489>.

Swift SVN r16549
2014-04-18 21:28:41 +00:00
Joe Groff
f7cf592777 Add a SIL-only '@block_storage T' type to represent on-stack storage for blocks.
Blocks need to be born on the stack, so we need a way to represent that on-stack storage. @block_storage T will represent the layout of a block that contains storage for a capture of type T.

Swift SVN r16355
2014-04-15 03:56:09 +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
Doug Gregor
724330514d Remove Dmitri's local hack
Swift SVN r16186
2014-04-10 23:41:46 +00:00
Dmitri Hrybenko
110f85bc16 Move @exported to use new attribute infrastructure
Swift SVN r16158
2014-04-10 13:35:35 +00:00
Joe Groff
cf539df249 IRGen: Crash on impossible type metadata cases instead of claiming them unimplemented.
We should never actually try to emit metadata for dependent types, lvalues, inouts, or SIL function types; these cases indicate upstream bugs in Sema or SILGen.

Swift SVN r16058
2014-04-08 17:33:20 +00:00
Joe Groff
d70136a046 IRGen: Don't eagerly emit protocol descriptors for imported protocols.
ObjC protocol descriptors are uniqued by the ObjC runtime and lazily emitted by Clang, so we shouldn't burn time eagerly emitting descriptors for every protocol in the universe. Addresses some of the performance issue in <rdar://problem/16520314>.

Swift SVN r15924
2014-04-04 04:42:39 +00:00
Joe Groff
f5816103e4 IRGen: Emit an OBJC_CLASS symbol for @objc classes.
Create a global alias into the metadata of @objc-visible classes at their address point, which should make these classes visible for linking from ObjC, fixing <rdar://problem/14449644>.

Swift SVN r15921
2014-04-04 04:05:05 +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
4ed1bbbe1f We know extra things about super-bounded archetypes the
same way we know them about class types.

Swift SVN r15667
2014-03-31 05:49:21 +00:00
John McCall
a43be126f3 Don't bother checking for incompatible overrides in IR-gen.
Eventually, SILGen will need to do something like this, and it
should go in the sil_vtable, and we should base the IR vtable
on that information.  For now, emitting multiple entries with
the same pointer in each is just bogus.

Swift SVN r15533
2014-03-26 22:25:51 +00:00
Joe Groff
99704ce69f IRGen: Build field type vector accessor functions.
As part of the nominal type descriptor for a struct or class, build a function that lazily generates the vector of type metadata for the fields of the nominal type given an instantiation of the type's metadata. To cache this for nongeneric types, produce a global variable we can stash the result in, or for generic types, reserve some space in the metadata template so that generic metadata instantiation naturally provides a space for every instance of the type.

Reapplying now that the missing Float80 builtin metadata is available.

Swift SVN r15260
2014-03-20 02:03:57 +00:00
Joe Groff
9b6a217bca Revert "IRGen: Build field type vector accessor functions."
This reverts commit r15256, which is producing phantom references to 'Float80'
that need investigating.

Swift SVN r15258
2014-03-20 01:41:38 +00:00
Joe Groff
891cdaf312 IRGen: Build field type vector accessor functions.
As part of the nominal type descriptor for a struct or class, build a function that lazily generates the vector of type metadata for the fields of the nominal type given an instantiation of the type's metadata. To cache this for nongeneric types, produce a global variable we can stash the result in, or for generic types, reserve some space in the metadata template so that generic metadata instantiation naturally provides a space for every instance of the type.

Swift SVN r15256
2014-03-20 00:41:00 +00:00
Joe Groff
809f91ec9e IRGen: Always emit field offset vectors for classes.
We need them for reflection, and we always emit them for structs, so for consistency, always emitting them for classes isn't the worst thing.

Swift SVN r15214
2014-03-19 00:19:56 +00:00
Joe Groff
c431509516 IRGen: Reserve a spot in the nominal type descriptor for the field type vector accessor.
Building the field type vector is potentially expensive and the vector isn't needed unless we do reflectiony things to a type, so let's use a lazy accessor. Make room for it, but don't populate it yet, so we can deal with fallout from the metadata layout change.

Swift SVN r15194
2014-03-18 17:30:31 +00:00
Joe Groff
365c2eac8e Revert "IRGen: Emit an OBJC_CLASS symbol for @objc classes."
This reverts commit r14927. The LLVM language design for this feature will
obviate the need for the inline asm approach.

Swift SVN r15171
2014-03-17 23:24:54 +00:00