Commit Graph

1292 Commits

Author SHA1 Message Date
John McCall
a1b469ed2f ExplosionKind -> ResilienceExpansion. NFC.
Swift SVN r12364
2014-01-16 00:25:29 +00:00
Doug Gregor
34113ffee4 Emit both Swift and Objective-C entry points for -dealloc.
The Swift entry point is required for the Swift metadata, while the
Objective-C entry point goes into the Objective-C metadata. As part of
this, stop emitting the destroying destructor for classes that use
Objective-C allocation: it won't work anyway.

Swift SVN r12199
2014-01-11 04:37:39 +00:00
Joe Groff
5e5f31d5e3 IRGen: Share TypeInfo among equivalent generic instantiations, take 2.
IRGen type conversion is invariant with respect to archetypes with the same set of constraints, so instead of redundantly generating a TypeInfo object and IR type for Optional<T> for every T everywhere, key TypeInfo objects using an "exemplar type" that we form using a folding set to collapse together archetypes with the same class-ness, superclass constraint, and protocol constraints.

This is a nice memory and IR size optimization, but will be essential for correctness when lowering interface types, because there is no unique context to ground a dependent type, and we need to lower the same generic parameter with the same context requirements to the same type whenever we instantiate it in order for the IR to type-check.

In this revision, we profile the nested archetypes of each recursively, which I neglected to take into account originally in r12112, causing failures when archetypes that differed by associated type constraints were incorrectly collapsed.

Swift SVN r12116
2014-01-10 05:25:45 +00:00
Joe Groff
97ff9e47a8 Revert "IRGen: Share TypeInfo among equivalent generic instantiations."
This reverts commit r12112. It gives the buildbot indigestion.

Swift SVN r12113
2014-01-10 03:22:53 +00:00
Joe Groff
57cacbfe38 IRGen: Share TypeInfo among equivalent generic instantiations.
IRGen type conversion is invariant with respect to archetypes with the same set of constraints, so instead of redundantly generating a TypeInfo object and IR type for Optional<T> for every T everywhere, key TypeInfo objects using an "exemplar type" that we form using a folding set to collapse together archetypes with the same class-ness, superclass constraint, and protocol constraints.

This is a nice memory and IR size optimization, but will be essential for correctness when lowering interface types, because there is no unique context to ground a dependent type, and we need to lower the same generic parameter with the same context requirements to the same type whenever we instantiate it in order for the IR to type-check.

Swift SVN r12112
2014-01-10 02:02:58 +00:00
John McCall
5da6defa1f Clean up the linkage model and the computation of linkage.
In general, this forces SILGen and IRGen code that's grabbing
a declaration to state whether it's doing so to define it.

Change SIL serialization to serialize the linkage of functions
and global variables, which means also serializing declarations.

Change the deserializer to use this stored linkage, even when
only deserializing a declaration, and to call a callback to
inform the client that it has deserialized a new entity.

Take advantage of that callback in the linking pass to alter
the deserialized linkage as appropriate for the fact that we
imported the declaration.  This computation should really take
advantage of the relationship between modules, but currently
it does not.

Swift SVN r12090
2014-01-09 08:58:07 +00:00
Chris Lattner
8d854f3e0b straighten out IRGen's @lvalue vs @inout handling. Since SILGen lowers all
@lvalue types, IRGen only needs to handle @inout.


Swift SVN r11799
2014-01-01 20:35:02 +00:00
Chris Lattner
9ae289de46 Drive the semantic wedge harder into lvalues. Now, instead of having one LValueType
with qualifiers on it, we have two distinct types:
 - LValueType(T) aka @lvalue T, which is used for mutable values on the LHS of an
   assignment in the typechecker.
 - InOutType(T) aka @inout T, which is used for @inout arguments, and the implicit
   @inout self argument of mutable methods on value types.  This type is also used
   at the SIL level for address types.

While I detangled a number of cases that were checking for LValueType (without checking
qualifiers) and only meant @inout or @lvalue, there is more to be done here.  Notably,
getRValueType() still strips @inout, which is totally and unbearably wrong.



Swift SVN r11727
2013-12-29 22:23:11 +00:00
Joe Groff
14362cd8e2 IRGen: Lower metatypes respecting SIL's 'thin' bit.
Use the 'thin' bit set by SIL to decide whether a metatype lowers to an empty type or not. In GenPoly we still need to accommodate unlowered metatypes to keep protocol witnesses limping along; hopefully that code can be killed soon. With this change we now lower @cc(witness_method) consistently for static methods.

Swift SVN r11535
2013-12-21 02:05:37 +00:00
Joe Groff
017440165e Fix the weird capitalization of MetaTypeType.
Swift SVN r11475
2013-12-19 18:43:08 +00:00
Joe Groff
402be77290 IRGen: Kludge instantiated generic classes into getting initialized as ObjC classes.
In the fun case where you create an object of a non-ObjC-derived generic Swift class and hand it off as a DynamicLookup or other class existential, the first ObjC-like thing that happens to that object is that it gets sent the "release" message in the context that only knows of it as an ObjC object. It turns out this is bad; magic happens when the first class method is sent to an ObjC class. In the normal case this is +alloc, but in our case, Swift's runtime has instantiated a class and allocated an object completely independent of the ObjC runtime. To fix this problem and avoid similar problems in the future, emit a useless call to +class in the generic metadata fill function for generic metadata patterns to force this initialization. We should be able to roll this back when we properly register generic class instances with the ObjC runtime (<rdar://problem/15306370>). In the meantime, this fixes <rdar://problem/15674812>.

Swift SVN r11407
2013-12-18 01:50:53 +00:00
Connor Wakamo
3e81830385 Move "include/swift/IRGen/Options.h" to "include/swift/AST/IRGenOptions.h".
This commit only moves the header file; updating the class so that it is no longer in the irgen namespace will be handled separately.

Swift SVN r11404
2013-12-18 01:17:09 +00:00
John McCall
20e58dcf93 Change the type of function values in SIL to SILFunctionType.
Perform major abstraction remappings in SILGen.  Introduce
thunking functions as necessary to map between abstraction
patterns.

Swift SVN r10562
2013-11-19 22:55:09 +00:00
John McCall
93dfaa6bf4 Make everything getting a TypeInfo declare whether it's
working with a SIL-lowered or SIL-unlowered type.

Swift SVN r10067
2013-11-09 01:41:16 +00:00
Joe Groff
22e32083b6 IRGen: Stop emitting static metadata for protocol types.
Metadata for protocols is now instantiated through the runtime.

Swift SVN r9876
2013-11-01 18:27:46 +00:00
Joe Groff
bbddf41693 IRGen: Instantiate existential metadata through the runtime.
When we need a reference to protocol or protocol composition type metadata, ask for it through the runtime, instead of referencing statically-emitted protocol metadata.

Swift SVN r9871
2013-11-01 17:13:49 +00:00
Joe Groff
a0c4486808 IRGen: Emit protocol descriptors.
Produce protocol descriptors when we see a protocol definition in the current module. If the protocol is @objc, go through the existing path for generating full Protocol* metadata for objc objects; otherwise, emit our layout-compatible but strong-external-linkage Swift protocol descriptor record.

Swift SVN r9867
2013-11-01 04:28:43 +00:00
Joe Groff
e31a1cf0a3 IRGen: Nominal type descriptors can be constant.
Swift SVN r9658
2013-10-24 21:52:03 +00:00
Joe Groff
3a8f81433f IRGen: Add a nominal type descriptor to class metadata.
Swift SVN r9503
2013-10-18 22:51:27 +00:00
Joe Groff
3d60786a30 IRGen: Add a requiresProtocolWitnessTable fn instead of peppering isObjC() everywhere.
Swift SVN r9497
2013-10-18 21:49:06 +00:00
Joe Groff
b8c75769b3 IRGen: Emit nominal type descriptors in struct and enum metadata.
Build a nominal type descriptor when we emit the metadata or generic metadata pattern for a nominal type, and put a reference into the formerly null slot in the struct or enum metadata. We need to make a place for them in class metadata; that'll come next.

Swift SVN r9492
2013-10-18 21:04:58 +00:00
Joe Groff
3c87c2f480 IRGen: Copy superclass generic parameters from superclass metadata.
Instead of trying to fill the superclass's generic parameter vector from the getGenericMetadata vector, which is broken, only populate the most-derived class's generic parameter vector from the getGenericMetadata vector, and copy the superclass vector from the superclass metadata.

Swift SVN r9301
2013-10-14 02:46:01 +00:00
Joe Groff
3478f6591b IRGen: Copy field offset vectors from super metadata.
In the fill function for a generic subclass metadata pattern, arrange to memcpy the field offset vectors from all of the ancestor classes into the newly-instantiated class metadata, before laying out the subclass's own fields.

Swift SVN r9299
2013-10-14 02:45:49 +00:00
Joe Groff
ab04ce9f34 IRGen: Populate fixed offsets in class metadata when we have them.
In particular, when a nongeneric class inherits a fragile generic class, we need to populate the field offsets for the instantiated base class because we can't rely on the runtime to populate it for us.

Swift SVN r9258
2013-10-12 14:56:47 +00:00
Joe Groff
280fc60ce9 IRGen, runtime: Poke generic size and alignment into class metadata.
This should get us actually allocating and deallocating generic root class instances.

Swift SVN r9251
2013-10-12 03:34:27 +00:00
Joe Groff
9ab5414609 IRGen: Load dependent class instance size and alignment from metadata.
When allocating and deallocating dependent generic class instances, load the instance size and alignment from the metadata instead of trying to use a static size from the compile-time class layout.

Swift SVN r9250
2013-10-12 02:57:41 +00:00
Joe Groff
4ff3c62ef6 IRGen: Include instance size and alignment mask in class metadata.
We need these for dependent-layout generic classes so we know the allocation/deallocation size and alignment. When I figure out ObjC interop with generic subclasses these should move to the rodata so they get handled resiliently by the ObjC runtime, but for generic class bringup this is convenient.

Swift SVN r9249
2013-10-12 01:51:18 +00:00
Joe Groff
77b1cdac68 IRGen: Emit runtime call to initialize generic class field offsets.
In the metadata template fill function for generic classes with dependent layout, include a call to a (not yet implemented) runtime initClassMetadata function to lay out the class fields and initialize the field offset vector.

Swift SVN r9233
2013-10-11 23:21:32 +00:00
Joe Groff
b724a6ea92 IRGen: Fix an off-by-one in class field access calculation.
The field's layout kind affects its own field access in addition to that of its following fields. This puts dependent fragile field accesses down the right code path. The NonFixedOffsets were inside us all along.

Swift SVN r9221
2013-10-11 21:38:35 +00:00
Joe Groff
7301ac3565 Don't interleave the vtable and field offset vectors in generic class metadata.
The field offset vector should be easily indexable by the NonFixedOffsets implementation.

Swift SVN r9213
2013-10-11 18:51:59 +00:00
Joe Groff
6d8942f436 IRGen: Put struct field offsets into struct metadata.
When we have fixed offsets available for fields, emit them into the metadata or metadata pattern. If we don't, emit zero and leave it for the pattern fill function to resolve at runtime.

Swift SVN r9114
2013-10-09 23:49:01 +00:00
Joe Groff
fe37b82a0b IRGen: Rename TypeInfo::initializeValueWitnessTable to initializeMetadata.
Its job will be a bit more broad for generic structs, where it needs to fill field offsets into the metadata in addition to storing the final size, stride, and alignment information to the value witness table.

Swift SVN r9104
2013-10-09 22:40:28 +00:00
John McCall
a38abec9fe Introduce (but don't yet use) SILFunctionType.
Swift SVN r9088
2013-10-09 20:55:42 +00:00
Doug Gregor
a012f60633 Make protocol methods generic over <Self>.
Pull the implicit 'Self' associated type out of the protocol and into
an implicitly-declared generic parameter list for the protocol. This
makes all of the methods of a protocol polymorphic, e.g., given

  protocol P {
    typealias Assoc
    func getAssoc() -> Assoc
  }

the type of P.getAssoc is:

  <Self : P> (self : @inout P) -> () -> Self.Assoc

This directly expresses the notion that protocol methods are
polymorphic, even though 'Self' is always implicitly bound. It can be
used to simplify IRgen and some parts of the type checker, as well as
laying more of the groundwork for default definitions within
protocols as well as sundry other improvements to the generics
system.

There are a number of moving parts that needed to be updated in tandem
for this. In no particular order:
  - Protocols always get an implicit generic parameter list, with a
  single generic parameter 'Self' that conforms to the protocol itself.
  - The 'Self' archetype type now knows which protocol it is
  associated with (since we can no longer point it at the Self
  associated type declaration).
  - Protocol methods now get interface types (i.e., canonicalizable
  dependent function types).
  - The "all archetypes" list for a polymorphic function type does not
  include the Self archetype nor its nested types, because they are
  handled implicitly. This avoids the need to rework IRGen's handling
  of archetypes for now.
  - When (de-)serializing a XREF for a function type that has an
  interface type, use the canonicalized interface type, which can be
  meaningfully compared during deserialization (unlike the
  PolymorphicFunctionType we'd otherwise be dealing with).
  - Added a SIL-specific type attribute @sil_self, which extracts the
  'Self' archetype of a protocol, because we can no longer refer to
  the associated type "P.Self". 




Swift SVN r9066
2013-10-09 17:27:58 +00:00
Doug Gregor
12e228c0f1 Introduce a new representation of polymorphic function types.
Introduces a new kind of function type, GenericFunctionType, that
represents a polymorphic function type with all of its generic
parameters and requirements stored in a more readily canonicalizable
form. It is meant to eventually replace PolymorphicFunctionType, but
for now we build it up in parallel so we can switch over to it
pieacemeal.

Note: this representation is built and then thrown away. We'll start
recording it soon.


Swift SVN r8881
2013-10-03 17:59:35 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Joe Groff
39ea0c930f Refactor MetadataScanner CRTP subclasses for structs and unions.
Share common FindValueTypeArgumentIndex and FindValueTypeWitnessTableIndex templates between the struct and union metadata versions of these scanners, templatized on the MetadataScanner they use. This makes witness table parameter lookup into generic union metadata work.

Swift SVN r8268
2013-09-15 03:00:16 +00:00
Doug Gregor
978eaab5c6 Introduce lazy computation of a BoundGenericType's substitutions.
Teach a BoundGenericType to compute its own substitutions, which
allows AST clients to create new bound generic types without the aid
of the type checker. 

This eliminates the TypeChecker::validateTypeSimple() abomination as
well as the need for the BoundGenericType AST validation step. There
is still more cleanup to do in this area.

Note that BoundGenericType::getSubstitutions() now accepts a module
parameter, which is the place from which we will look for
conformances. This is a baby step toward properly modeling the
conformances as part of the bound generic type, and is nowhere near
complete.


Swift SVN r8193
2013-09-13 14:25:36 +00:00
Doug Gregor
0e3aa19313 Factor the selector-loading logic into its own routine.
When loading a selector in the JIT, we need to call
sel_registerName(). This was manually coded in two places and missed
in a third, so factor it appropriately.


Swift SVN r8082
2013-09-10 22:42:45 +00:00
Joe Groff
d175076b2c IRGen: Add initializeValueWitnessTable to TypeInfo.
For dynamic generic types, this emits the sequence of operations to turn a value witness table template into a full, valid value witness table. For now, leave it stubbed out as empty, except for dynamic singleton unions, where we copy the size, flags, and stride from the lone element's table.

Swift SVN r8014
2013-09-06 23:53:17 +00:00
Joe Groff
ea61572b41 IRGen: Tail-emplace dependent vwtables into generic metadata patterns.
If a generic type has dynamic layout, the value witness table for its instances is dependent on its generic parameters for size and alignment. Instead of emitting a global symbol for the vwtable in these circumstances, embed the value witness table template in the generic metadata template so that both get instantiated in tandem by the runtime when the generic instance metadata is requested.

Swift SVN r7931
2013-09-05 00:33:38 +00:00
Joe Groff
3b8e8b6fb9 IRGen: Implement generic parameter metadata lookup for unions.
Factor out a UnionMetadataLayout and UnionMetadataScanner CRTP class, mirroring those for structs, and use UnionMetadataScanner to find generic parameters in union metadata.

Swift SVN r7918
2013-09-04 22:04:20 +00:00
Joe Groff
52283c01f2 IRGen: Bind archetype metadata for generic value witnesses.
Use EmitPolymorphicParameters to extract the metadata for generic type parameters from the "self" argument to value witnesses so that they're available to the value witness implementation. This makes it so that the compiler no longer crashes when emitting the value witness table for a generic struct with dynamic size.

This temporarily breaks generic unions since we didn't properly implement generic argument lookup for union metadata yet. Fix coming shortly.

Swift SVN r7910
2013-09-04 21:18:16 +00:00
Joe Groff
e6309152e5 IRGen: Kill the 'buildFakeType' abomination in GenericMetadataBuilder.
To instantiate the value witness table for generic types, we were instantiating the generic type at () for all of its parameters and hoping for the best. That's insane. Instead, let's use the DeclaredTypeInContext for the generic type so the archetypes actually get usefully bound inside the witnesses. This way, the witness implementations should be independent of generic parameters, so we can also mangle the unbound type into the witness symbols.

Swift SVN r7901
2013-09-04 17:50:12 +00:00
Joe Groff
82f1ea85c0 IRGen: Kill dead methods from GenericMetadataBuilderBase.
Swift SVN r7894
2013-09-04 02:24:52 +00:00
Joe Groff
33d2122ce9 IRGen/Runtime: Change generic metadata template to use a fill function.
Instead of hardcoding a walk of a list of fill ops, have generic metadata templates carry a pointer to a fill function for swift_getGenericMetadata to invoke to perform the fill operations. For types with dynamic layout, we will need to be able to perform more complex fill operations than a simple transfer of arguments into generic metadata slots.

Swift SVN r7893
2013-09-04 02:13:34 +00:00
Joe Groff
96a7c834de IRGen: Emit generic union metadata harder.
Missed a spot.

Swift SVN r7561
2013-08-25 19:05:56 +00:00
Joe Groff
b02fb06e58 IRGen: Emit generic union metadata templates.
At least, do so as poorly as we do for generic structs.

Swift SVN r7548
2013-08-24 00:18:29 +00:00
Joe Groff
46fd1c91b3 IRGen: Emit metadata and value witness tables for nongeneric unions.
And remove the hokey hardcoded metadata for Bool from the runtime.

Swift SVN r7541
2013-08-23 23:09:26 +00:00
Doug Gregor
7c84fd5926 Start detangling archetypes from the interface of generic functions.
This breaks the type-canonicalization link between a generic parameter
type and the archetype to which it maps. Generic type parameter types
are now separate entities (that can eventually be canonicalized) from
archetypes (rather than just being sugar).

Most of the front end still traffics in archetypes. As a step away
from this, allow us to type-check the generic parameter list's types
prior to wiring the generic type parameter declarations to archetypes,
using the new "dependent" member type to describe assocaited
types. The archetype builder understands dependent member types and
uses them to map down to associated types when building archetypes.

Once we have assigned archetypes, we revert the dependent identifier
types within the generic parameter list to an un-type-checked state
and do the type checking again in the presence of archetypes, so that
nothing beyond the generic-parameter-list checking code has to deal
with dependent types. We'll creep support out to other dependent types
elsewhere over time.



Swift SVN r7462
2013-08-22 18:07:40 +00:00