Commit Graph

1343 Commits

Author SHA1 Message Date
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
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
ac64ab7c60 IRGen: Emit an OBJC_CLASS symbol for @objc classes.
LLVM doesn't have interior symbols as a first-class concept, so generate module inline asm that defines the OBJC_CLASS symbol relative to the Swift metadata symbol. To prevent our system linkers from considering this symbol as the start of a new object and breaking apart class metadata objects, put the class metadata object into a no_dead_strip section.

This isn't quite enough to get the OBJC_CLASS symbol to be available--the symbol appears to show up in the .o as an undefined symbol and stripped out of the .dylib. John is investigating with the backend and linker teams as to why this is the case.

Swift SVN r14927
2014-03-11 21:44:31 +00:00
Doug Gregor
b1dfcd7085 Dynamically dispatch when delegating from a complete object initializer.
Inherited initializers are now functional: one can use an inherited
initializer to construct an object of a subclass type, and we properly
handle delegation to overridden complete object or subobject
initializers as appropriate. See the executable test.

This commit also contains various fixes for the IRGen side of vtable
emission and use. Proper IRGen tests still to come.

For now, we're still performing peer delegation from a subobject
initializer to another subobject initializer, hence the SILGen hack
for identifying when we're in a complete object vs. a subobject
initializer. We'll be banning delegation from subobject initializers,
so this hack---along with the peer_method instruction---will be going
away in the near future.



Swift SVN r14571
2014-03-02 08:19:11 +00:00
Doug Gregor
1d733d5646 IR generation for alloc_ref_dynamic.
Swift SVN r14561
2014-03-01 22:33:01 +00:00
Joe Groff
98d6fecc99 '.metatype' -> '.Type'
Also, reserve 'type' as a keyword for ensuing syntax changes.

Swift SVN r14375
2014-02-26 04:23:21 +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
Doug Gregor
b5af687b6d Emit and use vtable entries for abstract initializers.
Emit vtable entries for abstract initializers. When we're constructing
an object using an abstract initializer based on a metatype value that
is not statically derivable, use the vtable entry to call the
subclass's allocating constructor.

Most of the IRGen work here is hacking around the lossy SILDeclRef ->
(Code|Function)Ref -> SILDeclRef conversion. I'd feel bad about this
if John hadn't already agreed to clean this up at some point.



Swift SVN r14238
2014-02-21 23:15:46 +00:00
Doug Gregor
38cad0c284 Lower metatype and class_metatype to IR based on the requested representation.
Make IRGen just a little bit dumber: rather than inferring whether we
need the Swift or Objective-C metatype based on the uses of that
metatype, produce the metadata in the representation requested by the
'metatype' or 'class_metatype' instruction. SILGen will eventually
need to get smarter about asking for the representation it wants.


Swift SVN r14117
2014-02-20 00:31:24 +00:00
Doug Gregor
1e553187cb IRGen: A few more TypeMetadataPtrTy -> ObjCClassPtrTy cleanups.
Swift SVN r14113
2014-02-19 23:26:10 +00:00
Doug Gregor
27ae27bf04 Start using objc_class* to describe Objective-C class metatypes in IRGen.
Swift SVN r14099
2014-02-19 21:24:00 +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
Doug Gregor
a341300cb0 Switch ClassDecl::getSuperclass() and EnumDecl::getRawType() to interface types.
This has the nice "side effect" of making overrides of generic
functions work better, fixing the remaining type checker issues from
<rdar://problem/15836098>.

Also synthesize the types for derived RawRepresentable conformances
directly rather than going through the type checker, so we get the
interface types right. 



Swift SVN r14066
2014-02-19 00:54:04 +00:00
Chris Lattner
827acad533 Various inout improvements:
- purge @inout from comments in the compiler except for places talking about
   the SIL argument convention.
 - change diagnostics to not refer to @inout
 - Change the astprinter to print InoutType without the @, so it doesn't show
   up in diagnostics or in closure argument types in code completion.
 - Implement type parsing support for the new inout syntax (before we just 
   handled patterns).
 - Switch the last couple of uses in the stdlib (in types) to inout.
 - Various testcase updates (more to come).



Swift SVN r13564
2014-02-06 06:22:27 +00:00
Doug Gregor
030770a8c2 Make DynamicSelf into its own special type node.
Making DynamicSelf its own special type node makes it easier to opt-in
to the behavior we want rather than opting out of the behavior we
don't want. Some things already work better with this representation,
such as mangling and overriding; others are more broken, such as the
handling of DynamicSelf within generic classes and the lookup of the
DynamicSelf type.


Swift SVN r13141
2014-01-30 05:36:20 +00:00
Joe Groff
f7bf3bbb2c IRGen/Runtime: Tweak the hack to force generic class instantiations to be realized by ObjC.
Calling +class on our generic classes is not enough to reliably realize a generic class instantiation; if the method is already hot in the shared metaclass's cache, it will bypass the actual realization of the instance. Try another hack to force the runtime to realize the class by invoking class_getInstanceMethod on it, which appears to work more reliably. Factor the hack out into a runtime call so we can tweak it more easily in the future. This gets <rdar://problem/15898373> and <rdar://problem/15898701> working.

Thanks DTrace and John for helping puzzle out what was going on here.

Swift SVN r12934
2014-01-24 21:43:06 +00:00
Joe Groff
378f18c430 IRGen/Runtime: Provide getGenericMetadata[1-4] entry points.
This lets IRGen avoid emitting an alloca for common generic metadata instantiations. These entry points can also be marked "readnone", and the general getGenericMetadata entry point can be "readonly", giving LLVM's optimizer a fighting chance on unspecialized generic code.

Swift SVN r12789
2014-01-22 21:54:58 +00:00
Chris Lattner
f5b85341a1 Expand out the "isComputed" property in AbstractStorageDecl to be an enum
with two kinds, and some more specific predicates that clients can use.

The notion of 'computed or not' isn't specific enough for how properties
are accessed.  We already have problems with ObjC properties that are 
stored but usually accessed through getters and setters, and a bool here
isn't helping matters.

NFC.



Swift SVN r12593
2014-01-20 18:16:30 +00:00
John McCall
93d7bc4f0d Remove unnecessary Expr uses from IR-gen.
Swift SVN r12428
2014-01-16 22:32:35 +00:00