Commit Graph

1052 Commits

Author SHA1 Message Date
John McCall
e3584068e8 Distinguish the allocation cases in IR-gen.
This gives us a more convenient type for allocateStack
and eliminates some unnecessary redundancy.

Swift SVN r6935
2013-08-06 07:31:36 +00:00
John McCall
b77c430848 Add SIL-gen and some missing runtime support for [unowned].
Swift SVN r6881
2013-08-03 08:46:54 +00:00
John McCall
00a940ac1b Rename weak_retain to unowned_retain and change it to
require the correct [unowned] type as an argument.

Swift SVN r6825
2013-08-02 00:02:09 +00:00
Jordan Rose
674a03b085 Replace "oneof" with "union"...everywhere.
We haven't fully updated references to union cases, and enums still are not
their own thing yet, but "oneof" is gone. Long live "union"!

Swift SVN r6783
2013-07-31 21:33:33 +00:00
Joe Groff
239f5aee8c IRGen: Include associated types in witness table layout.
Reserve slots in protocol witness table layout to drop in associated type metadata and witnesses. To actually populate these, we'll need to move the ABI to lazy conformance-instantiation functions.

Swift SVN r6702
2013-07-29 19:03:43 +00:00
Doug Gregor
1759210067 (De-)Serialize the protocols from which a protocol inherits.
Switch a few more clients from ::getInherited() to
::getProtocols(). The trajectory here is that ::getInherited() will
turn into something only populated when we've parsed the inheritance
clause, and that "the truth" will be getProtocols(). The former will
cease being serialized once this is the case.


Swift SVN r6661
2013-07-26 23:57:52 +00:00
Joe Groff
7a1009fc9f IRGen: Remove value witnesses from protocol witness tables.
The value witnesses are always available through type metadata (through an extra indirection). Saving that indirection costs 16 words (and growing!) in every witness table, and when we start instantiating conformances for generic instances, would require us to instantiate practically every generic witness table. Removing the value witnesses from the protocol witness table means we will only need to instantiate witness tables when associated types are dependent on the conforming type's type variables.

This is an ABI break, but should have no user-visible functional change.

Swift SVN r6651
2013-07-26 20:55:04 +00:00
Doug Gregor
532dd646dc Use "witness" rather than "value witness" to mean a non-type witness in the AST/type checker.
The term "value witness" has a very specific meaning in IR generation,
causing unnecessary confusion.


Swift SVN r6650
2013-07-26 18:34:06 +00:00
Doug Gregor
d0f60ab755 Introduce some encapsulation into ProtocolConformance.
Swift SVN r6648
2013-07-26 18:12:17 +00:00
Joe Groff
f866e5af25 Revert "IRGen: Pass existentials as generic parameters by unwrapping the container."
This reverts commit r6350. We don't imminently need this and intend to do it right soon.

Swift SVN r6605
2013-07-25 18:38:14 +00:00
Joe Groff
398cbba5be Rename SILConstant to SILDeclRef.
"SILConstant" doesn't really describe its role in SIL anymore, which is to provide a reference to a Swift declaration in a SIL instruction, such as a method or nominal type field.

Swift SVN r6559
2013-07-24 21:21:31 +00:00
John McCall
e668ff914f Add parsing and IR-gen for weak_retain and weak_release.
Swift SVN r6492
2013-07-23 06:28:51 +00:00
Joe Groff
2af2fe2f68 IRGen: Update calling convention for generic witnesses.
Have WitnessBuilder awkwardly ask SIL's TypeConverter to uncurry witness types, so that polymorphic arguments get emitted in the right order consistent with lowered SILFunctions, instead of doing the uncurrying itself directly from the Swift type. This is layer-violating as hell but gets generic witness codegen working. I have a feeling SILGen will want to take over witness thunk emission at some point.

Swift SVN r6401
2013-07-20 00:08:51 +00:00
Joe Groff
10f290a01d AST: Add slot for substitutions for generic witnesses.
If a protocol requirement is satisfied by a generic method, we'll need to save the substitutions necessary to call that method from the witness thunk. This patch adds the spot in the ProtocolConformance::Mapping to save the substitutions; for now, always leave it empty and update the code for the type change.

Swift SVN r6399
2013-07-20 00:08:43 +00:00
John McCall
69b64a09ce More canonical type preserving.
Swift SVN r6377
2013-07-19 07:08:38 +00:00
John McCall
4b4e7d0833 Eliminate SIL and IR-gen's TypeVisitor specializations in
favor of a new AST-level one, and exploit it.

Swift SVN r6376
2013-07-19 07:08:34 +00:00
John McCall
16063866ed Preserve type canonicality with isa/cast/dyn_cast.
Swift SVN r6362
2013-07-18 23:28:53 +00:00
Joe Groff
5fe164df07 IRGen: Pass existentials as generic parameters by unwrapping the container.
When an existential's contained type is used as a generic parameter, unwrap the existential container and save its metadata and witnesses to be used as polymorphic arguments.

Our AST representation can't quite express the distinction between a type parameter being satisfied by the existential type itself from being satisfied by the existential's contained yet. I use a goofy heuristic where I assume a protocol type bound to a type variable with no requirements is satisfied by the protocol type itself; this covers all of the existing <T> (Slice<T>, T) cases that come up in the library, while enabling the <T:Foo> (T) cases. This hopefully addresses <rdar://problem/14470097> well enough to unblock library work until we get a solid AST representation of this difference.

Swift SVN r6352
2013-07-18 19:09:19 +00:00
John McCall
0d0e0d1939 Abstract out sub-interfaces for [unowned] and [weak] TypeInfos.
Swift SVN r6325
2013-07-17 09:20:30 +00:00
John McCall
7b86817b3c Basic value structure for [weak] and [unowned] references.
Add a bunch of new entrypoints and give them terrible
implementations.

Swift SVN r6322
2013-07-17 09:20:20 +00:00
John McCall
0e63c4a0ed Extract a ReferenceTypeInfo subinterface for refcount operations.
Weak stuff will introduce a much broader set of required
operations.

Swift SVN r6143
2013-07-11 00:22:06 +00:00
John McCall
18a9290cbe Add ReferenceStorageType.
The idea for now is that this is a SIL-only type used for
representing the storage of a weak or unowned reference.
Having it be its own type is pretty vital for reasonable
behavior in SIL and IR-generation, and it's likely that
this will surface into runtime metadata as well (hence
the mangling).

I've implemented a bunch of things that technically I don't
think are necessary if this stays out of the typechecker,
but it's easier to implement half-a-dozen "recurse into
the child type" methods now that it would be to find them
all later if we change our minds.

Swift SVN r6091
2013-07-09 08:37:40 +00:00
Dave Abrahams
096ffc6eaf Silence warnings in the release build
Swift SVN r5950
2013-07-01 21:42:16 +00:00
Argyrios Kyrtzidis
e31bfa9859 Fix some -Wnon-virtual-dtor warnings.
Swift SVN r5938
2013-07-01 18:25:23 +00:00
Adrian Prantl
149ebb0ef3 Debug Info: Associate the remaining artificial functions with their debug scopes.
Swift SVN r5885
2013-06-28 22:27:25 +00:00
Adrian Prantl
ae9bd9397b Debug Info: Generate scope information for many more builtin/artificial functions.
Swift SVN r5876
2013-06-28 20:05:41 +00:00
Joe Groff
f072c48e45 Refactor cast representation in AST and SIL, and implement 'is'.
Improve our representations of casts in the AST and SIL so that 'as!' and 'is' (and eventually 'as?') can share almost all of the same type-checking, SILGen, and IRGen code.

In the AST, we now represent 'as!' and 'is' as UnconditionalCheckedCastExpr and IsaExpr, respectively, with the semantic variations of cast (downcast, super-to-archetype, archetype-to-concrete, etc.) discriminated by an enum field. This keeps the user-visible syntactic and type behavior differences of the two forms cleanly separated for AST consumers.

At the SIL level, we transpose the representation so that the different cast semantics get their own instructions and the conditional/unconditional cast behavior is indicated by an enum, making it easy for IRGen to discriminate the different code paths for the different semantics. We also add an 'IsNonnull' instruction to cover the conditional-cast-result-to-boolean conversion common to all the forms of 'is'.

The upshot of all this is that 'x is T' now works for all the new archetype and existential cast forms supported by 'as!'.

Swift SVN r5737
2013-06-21 05:54:03 +00:00
Joe Groff
470cb9eae0 IRGen: Implement opaque archetype/existential casts.
Use the new swift_dynamicCastIndirect runtime functions to implement casts from opaque archetype and existential types to concrete types.

Swift SVN r5684
2013-06-19 18:56:14 +00:00
Joe Groff
54898bf8fd IRGen: Leave inherited ObjC protocols out of protocol witness tables.
Don't generate parent witness tables for inherited ObjC protocols.

Swift SVN r5678
2013-06-19 04:51:57 +00:00
Joe Groff
4db5b84dde Oops, 'requiresClassExistential' -> 'isClassExistential'.
Clbuttic search-and-replace mistake.

Swift SVN r5675
2013-06-19 04:01:48 +00:00
Joe Groff
a55f246946 Remove the controversial "bounded" from "class-bounded".
Just refer to "class archetypes" and "class protocols". Change 'isClassBounded' methods to 'requiresClass', which is a character shorter.

Swift SVN r5674
2013-06-19 03:58:11 +00:00
Joe Groff
665cbf56c1 IRGen: Implement conversions between class protocol types.
Implement existential upcasts from a class-bounded protocol type to a more general one.

Swift SVN r5673
2013-06-19 02:46:29 +00:00
Joe Groff
f5101ddb97 Stop trusting the inliner to handle trivial 'size()' method calls.
Swift SVN r5671
2013-06-19 01:14:27 +00:00
Joe Groff
56a4220eeb IRGen: Use superclass repr and refcount for superclass archetypes.
If an archetype has a superclass bound, we can assume the superclass's
retain semantics for the type. We can also use the superclass's storage pointer type to cut down on some bitcast IR noise when calling superclass methods on the archetype value.

Swift SVN r5642
2013-06-18 03:42:27 +00:00
Joe Groff
70a9639057 IRGen: Fix off-by-one in class-bounded existential metadata size.
Swift SVN r5640
2013-06-18 02:06:34 +00:00
Joe Groff
dcc414026e IRGen: Lower SIL DeinitExistentialInst.
Provide a lowering for the DeinitExistential instruction to deallocate the buffer in an existential container with an uninitialized value, using its deallocateBuffer witness.

Swift SVN r5623
2013-06-17 19:57:48 +00:00
Joe Groff
4ff8cd27dd IRGen: Abstract out an "unknown refcounted" concept.
In the implementation of class-bounded archetypes and existentials, instead of referring to ObjC pointer types and retain/release operations directly, use an 'UnknownRefCountedPtrTy' and 'emitUnknownRetain/Release' functions.

Swift SVN r5619
2013-06-17 18:31:49 +00:00
Joe Groff
34dc94679d IRGen: Get objc protocol erasure working.
Don't try to emit witness tables for protocols that don't need them when emitting a protocol erasure. (We'll need to eventually ensure that ObjC method metadata gets generated for the conforming methods, but we don't yet, so this will only work for types that already have ObjC-dispatchable methods.)

Swift SVN r5610
2013-06-16 05:06:28 +00:00
Joe Groff
61292d7993 IRGen: Leave ObjC protocols out of existential type layout.
ObjC protocols don't require witness tables and so don't need to be included in protocol existential container layout.

Swift SVN r5602
2013-06-15 22:29:43 +00:00
Joe Groff
24acecc0d3 IRGen: Fix uninitialized "needs metatype" flag in WitnessTableBuilder.
Move the initialization of NeedsExtraMetatype before an early exit from the constructor that I missed. Oops.

Swift SVN r5597
2013-06-15 17:40:46 +00:00
Joe Groff
d4f9579eac IRGen: Class-bounded generics don't need extra metatype data.
Since the type metadata for the underlying method will be taken from the class instance, the witness entry point for a class-bounded protocol conformance doesn't need to pass on an extra metatype parameter for the 'This' archetype.

Swift SVN r5595
2013-06-15 16:10:04 +00:00
Joe Groff
b1aff68da9 Allow [class_protocol] protocols to be [objc].
Swift SVN r5591
2013-06-15 00:41:32 +00:00
Joe Groff
f678700dce IRGen: Implement class-bounded existential containers.
Provide TypeInfo for class-bounded existentials, which represents them as an explosion comprising one witness table per subscribed protocol and then the class instance pointer as an ObjC-refcounted pointer. Provide lowerings for the SIL instructions that manipulate class-bounded existentials (except for existential-to-existential erasures, which aren't critical to getting basic operations working and will need some abstraction remapping to deal with class-bounded-to-opaque upcasts aside from the representation change).

Swift SVN r5579
2013-06-14 14:52:47 +00:00
Joe Groff
5c8c9f9fb1 IRGen: Tweak witness 'This' binding to allow class-bounded archetypes.
Handle the case of a 'this' parameter of 'This' type not being an LValueType or MetaTypeType, which happens for class-bounded protocols. This gets witness emission working for class-bounded archetypes.

Some abstraction remapping still needs to be implemented when non-class-bounded methods are accessed from a class-bounded archetype with a mix of class-bounded and non-class-bounded protocol constraints, to remap the class-bounded archetype to its opaque representation.

Swift SVN r5573
2013-06-11 16:40:08 +00:00
Joe Groff
087803f5b0 IRGen: Implement type info for class-bounded archetypes.
Split ArchetypeTypeInfo into ClassBoundedArchetypeTypeInfo, for class-bounded archetypes, and OpaqueArchetypeTypeInfo, for fully generalized archetypes (the existing case). ClassBoundedArchetypeTypeInfo is represented using a single refcounted ObjCPointer. Implement abstraction remapping from class instances to class-bounded archetypes and back, and from class-bounded archetypes to non-class-bounded and back.

Witness tables are still generated only for opaque archetypes, so method calls on class-bounded archetypes won't work just yet.

Swift SVN r5569
2013-06-11 00:19:34 +00:00
Joe Groff
5e2779b51e SIL: Uncurry function types within the Swift type system.
Remove uncurry level as a property of SILType/SILFunctionTypeInfo. During SIL type lowering, map a (Type, UncurryLevel) pair to a Swift CanType with the uncurried arguments as a Swift tuple. For example, T -> (U, V) -> W at uncurry level 1 becomes ((U, V), T) -> W--in reverse order to match the low-level calling convention. Update SILGen and IRGen all over the place for this representation change.

SILFunctionTypeInfo is still used in the SILType representation, but it's no longer load-bearing. Everything remaining in it can be derived from a Swift type.

This is an ABI break. Be sure to rebuild clean!

Swift SVN r5296
2013-05-24 01:51:07 +00:00
Joe Groff
c4317411b6 IRGen: Use SILType in functions used for existential container insts.
Swift SVN r5191
2013-05-16 22:47:49 +00:00
Joe Groff
cdf95e6c5a IRGen: Use SILTypes when dispatching archetype/existential methods.
Swift SVN r5153
2013-05-10 22:26:24 +00:00
Joe Groff
667ef5d651 IRGen: Look up metatypes and class methods using SIL types.
Swift SVN r5150
2013-05-10 21:20:11 +00:00
Joe Groff
197c3e6d02 IRGen: Strip unneeded parameters from IRGenFunction constructor.
Swift SVN r5146
2013-05-10 18:18:14 +00:00