Commit Graph

350 Commits

Author SHA1 Message Date
Joe Groff
1dce36edd2 Make 'T.self is U.Type' work.
Fix up all of type-checking, SILGen, IRGen, and the runtime to support checked casts of metatypes. <rdar://problem/16847453>

Swift SVN r17719
2014-05-08 22:55:14 +00:00
Michael Gottesman
67cb75ea94 [irgen] When emitting code for the JIT, do not emit available external witness tables.
Currently we have in a hack that available_external entries are emitted
shared. This does not jive well in the JIT when one is attempting to
merge an external witness table with the linkonce_odr internal
available_external witness table.

We are not doing any optimization at the JIT level so there is no reason
to emit available_external witness tables at all.

So lets not do that.

Swift SVN r17423
2014-05-05 04:21:24 +00:00
Joe Groff
71678b4bdf IRGen/Runtime: Expose the 'isBitwiseTakable' bit in the value witness flags.
Set a bit for types that are non-bitwise-takable, and calculate it as part of runtime struct and enum layout. Include 'bitwise takable' as part of the runtime 'is inline' calculation to be consistent with the compile-time policy change in r17008.

Swift SVN r17036
2014-04-29 15:23:14 +00:00
Joe Groff
caff7b62d9 IRGen: Expose the array value witnesses as builtins.
Add Builtin.destroyArray, .copyArray, .takeArrayFrontToBack, and .takeArrayBackToFront, which perform bulk destroy/copy/take operations using memcpy/memmove, a loop, or a generic value witness.

Swift SVN r17009
2014-04-29 03:46:58 +00:00
Joe Groff
1f6af41dc3 IRGen: Store non-bitwise-takable types out of line in existential containers.
Give non-bitwise-takable types the Allocate FixedPacking kind so that they get allocated out of line in fixed buffers. Small value types with @weak references seem rare enough to me that it's overall better to let existential containers be bitwise-takable than to pessimize their take operations for the few value types that aren't bitwise-takable.

While we're here, add an assertion to FixedTypeInfo::initializeWithTake to ensure that all non-bitwise-takable types override the default implementation.

Swift SVN r17008
2014-04-29 03:46:48 +00:00
Joe Groff
7a18f7231d IRGen: Emit array value witnesses.
Implement codegen for the destroyArray, initializeArrayWithCopy, and initializeArrayWithTake value witnesses.

Swift SVN r16999
2014-04-28 22:30:28 +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
Joe Groff
809655d8d7 IRGen: Emit nontrivial initializeWithTake operations for types that aren't bitwise-takable.
Emit a real initializeWithTake value witness for types that aren't bitwise-takable. Drop the default 'initializeWithTake' implementation from NonFixedTypeInfo, so that leaf type infos are forced to properly override it for their own layout, and fill in the now-missing implementation in SequentialTypeInfo.

Swift SVN r16955
2014-04-27 23:45:28 +00:00
John McCall
285354fb5b Remove pointless code left over from a briefly
considered approach.

Swift SVN r16913
2014-04-27 04:55:12 +00:00
John McCall
7c742b4d32 Emit SILWitnessTables lazily if their linkage allows it.
Swift SVN r16911
2014-04-27 04:29:56 +00:00
Joe Groff
c0202d4fc2 IRGen: Push an 'isBitwiseTakable' bit through type infos.
In value witness table generation, and probably other places, we're inappropriately assuming that 'initializeWithTake' is equivalent to a memcpy in all cases, which isn't true for types that carry weak references or for potentially other types in the future. Add an 'isBitwiseTakable' property to TypeInfos that can be checked to see whether a type is bitwise-takable.

Swift SVN r16799
2014-04-25 03:06:46 +00:00
Joe Groff
f29a156e83 IRGen/Runtime: Add value witness slots for array witnesses.
Add value witnesses for destroyArray, initializeArrayWithCopy, and initializeArrayWithTake{FrontToBack,BackToFront}, and fill out the runtime value witness table implementations. Stub out the IRGen ones for now.

Swift SVN r16772
2014-04-24 22:25:26 +00:00
John McCall
b38a63950d Implement @unowned(unsafe).
This was part of the original weak design that
there was never any particular reason to rush the
implementation for.  It's convenient to do this now
so that we can use it to implement Unmanaged<T> for
importing CF types.

Swift SVN r16693
2014-04-23 08:51:23 +00:00
John McCall
8bd79535a1 Track spare bits in @unowned types.
Swift SVN r16692
2014-04-23 08:51:18 +00:00
Doug Gregor
09797f7f99 Introduce a new declaration node, ParamDecl, for function parameters.
Use this node to capture the argument name and its source location in
the AST. We're only building these in one place at the moment; the
rest will be updated soon.


Swift SVN r16581
2014-04-20 05:23:35 +00:00
Doug Gregor
36889a2b1a Introduce DeclIterator and DeclRange for iterating over decl members.
NFC. DeclRange is a range over DeclIterators, and is used rather than
ArrayRef<Decl*> to retrieve the members of a nominal type declaration
or extension thereof. The intent is to change the representation of
DeclRange next.


Swift SVN r16571
2014-04-19 18:53:20 +00:00
John McCall
53b872a751 Correctly handle class-bounded archetypes when initializing
opaque existentials.

rdar://16621578

Swift SVN r16382
2014-04-15 23:57:40 +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
862d50ac1c Change the layout of opaque existentials so that
the value buffer comes first.

The motivation for doing this is similar to the
motivation for moving it for class existentials:
it eliminates the need for an offset for the most
common accesses, which is particularly important
for the generic value witnesses.

Also try to hard-code that layout in fewer places,
or at least static_assert the places that have to
do so.

Swift SVN r16279
2014-04-13 07:43:08 +00:00
John McCall
46d35ed288 Change the layout of class existentials to put the instance
pointer first.

This most important effect of this is that accesses to that
field don't need to be dynamically offsetted past an arbitrary
number of value witnesses, which is pretty nice for the
generic value witnesses.

Swift SVN r16243
2014-04-12 02:13:16 +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
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
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
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
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
Michael Gottesman
3ad6f33202 Teach the generic specializer how to create SILWitnessTable declarations if a specialized conformance does not have a witness table.
This also teaches IRGen not to emit WitnessTable declarations. This
causes them to be left as unknown symbols in the resulting executable.

Swift SVN r15361
2014-03-22 05:05:47 +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
eec73c0919 IRGen: Don't try to collect witness table refs for conformances that don't need them.
Fixes <rdar://problem/16341261>.

Swift SVN r15191
2014-03-18 16:02:29 +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
John McCall
0a835c33db Don't abort when asking if a C function type has
polymorphic parameters.

Swift SVN r15041
2014-03-14 06:12:00 +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
Chris Lattner
bca9000809 silence some fallthrough warnings.
Swift SVN r15033
2014-03-14 05:50:38 +00:00
Joe Groff
205d286211 Knock off some bogus Substitution::Archetype uses.
Swift SVN r14967
2014-03-12 20:46:13 +00:00
Joe Groff
48e22cdfb6 IRGen: Don't emit polymorphic parameters for concrete-constrained associated types.
Fixes <rdar://problem/16273572>.

Swift SVN r14871
2014-03-10 16:44:26 +00:00
Joe Groff
9f12e2e4a4 Enable same-type concrete constraints, e.g. <T: P where T.Assoc == Int>
Let ArchetypeType nested types and PotentialArchetypes be bound to concrete types in addition to archetypes. Constraints to outer context archetypes still suffer type-checker issues, but constraints to true concrete types should work now.

Swift SVN r14832
2014-03-08 17:18:17 +00:00
Joe Groff
d12fb5a20b IRGen: Accept the existence of init requirements in protocols.
Make WitnessVisitor not freak out when it sees an init requirement, allowing 'init' requirements to be used in non-@objc protocols. Fixes <rdar://problem/13695680>.

Swift SVN r14744
2014-03-06 19:24:37 +00:00
Joe Groff
8fee3fdb9a IRGen: Don't expect AssociatedTypeProtocol references for @objc protocols.
@objc protocols don't have witness tables, so @objc protocol requirements on associated types don't require witness table entries in conformances to the parent protocol.

Swift SVN r14660
2014-03-04 23:04:49 +00:00
Joe Groff
88b6efcc43 Rename ArchetypeMethodInst -> WitnessMethodInst more thoroughly.
Swift SVN r14501
2014-02-28 06:41:18 +00:00
Joe Groff
59d2a169f6 SIL: Rename 'archetype_method' to 'witness_method'.
It has been generalized to get a witness out of an arbitrary protocol conformance, not just for archetypes.

Swift SVN r14497
2014-02-28 05:09:11 +00:00
Joe Pamer
f83f94d9d8 Support build and target configurations
These changes add support for build and target configurations in the compiler.
Build and target configurations, combined with the use of #if/#else/#endif allow
for conditional compilation within declaration and statement contexts.

Build configurations can be passed into the compiler via the new '-D' flag, or
set within the LangOptions class. Target configurations are implicit, and
currently only "os" and "arch" are supported.

Swift SVN r14305
2014-02-24 18:16:48 +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
Chris Lattner
fc42659613 Generalize witness table generation logic in silgen and irgen to handle properties.
We can now form witness tables for both properties and subscripts, but still can't
call them.  Also, only computed properties can fulfill a protocol requirement (which
is tracked by rdar://15912000).



Swift SVN r14137
2014-02-20 08:13:36 +00:00
John McCall
b0221e77db This should not fall through into the unreachable.
Swift SVN r14051
2014-02-18 22:00:09 +00:00
Chris Lattner
4a86056dff Progress towards putting subscript accessors into protocol witness tables.
This isn't testable yet, as it is blocked by at least two things:
 1. we can't put curried functions into witness tables (rdar://16079147),
    which is a problem given that subscript accessors are curried on their 
    index argument.
 2. accessors cannot silgen is curried form, we currently die in mangling.




Swift SVN r13947
2014-02-16 07:04:33 +00:00
Joe Groff
68db63b45d AST: Have GenericFunctionType use GenericSignature.
Change GenericFunctionType to reference a GenericSignature instead of containing its generic parameters and requirements in-line, and clean up some interface type APIs that awkwardly returned ArrayRef pairs to instead return GenericSignatures instead.

Swift SVN r13807
2014-02-12 03:44:28 +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