Commit Graph

540 Commits

Author SHA1 Message Date
Joe Groff
44c10213f1 IRGen: Use the 'Self' argument to value witnesses as metadata for the type.
Avoid a pointless getGenericMetadata call in nearly every generic value witness.

Swift SVN r12851
2014-01-23 06:06:22 +00:00
Dave Zarzycki
17eb84d9c6 Zap accumlated warnings in non-assert builds
Swift SVN r12850
2014-01-23 05:45:24 +00:00
Joe Groff
4c6ef04d02 IRGen: Expand function signatures from SILFunctionType's interface types.
Now that we unique equivalent archetypes and lower interface types from the AST, we can convert IRGen over to using the interface types of the SILFunctionType when expanding out an LLVM function signature.

Swift SVN r12566
2014-01-19 17:14:09 +00:00
Joe Groff
0776c4b6b8 SIL: Reorient function type lowering toward interface types.
Lower types for SILDeclRefs from the interface types of their referents, dragging the old type along for the ride so we can still offer the context to clients that haven't been weaned off of it. Make SILFunctionType's interface types and generic signature independent arguments of its  Derive the context types of SILFunctionType from the interface types, instead of the other way around. Do a bunch of annoying inseparable work in the AST and IRGen to accommodate the switchover.

Swift SVN r12536
2014-01-18 19:42:02 +00:00
Joe Groff
bf1fdcdb3d IRGen: Class existentials are single-unknown-retainable if they need no witness tables.
This would enable the mask-and-retain optimization for the 'Owner' enum of ContiguousString, except that that causes heap corruption issues as noted in r12465.

Swift SVN r12466
2014-01-17 05:49:42 +00:00
Joe Groff
0c20833d5f IRGen: Optimize copy/destroy of ObjC tagged or nullable enums too.
Rename TypeInfo::isSingleRetainablePointer to TypeInfo::isSingleSwiftRetainablePointer, and add an isSingleUnknownRetainablePointer entry point to ask whether a type has any single-refcounted representation, native or not. Use that to provide the same nullable-pointer and pointer-with-tag optimizations for copying and destroying enums with ObjC payloads as we do for Swift class payloads.

Swift SVN r12410
2014-01-16 19:08:01 +00:00
John McCall
a1b469ed2f ExplosionKind -> ResilienceExpansion. NFC.
Swift SVN r12364
2014-01-16 00:25:29 +00:00
Joe Groff
7c7787f86f IRGen: Class existentials have spare bits.
And we really want to take advantage of them in String's Owner enum so we don't waste space (<rdar://problem/15787975>). This gets the size of ContiguousUTF16Slice down to 24 bytes from 32.

Swift SVN r12119
2014-01-10 06:22:47 +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
Joe Groff
44fb729830 SIL: Use only interface types in the verifier.
Treat the interface types of SILFunctionTypes as the canonical representation in the verifier. Do a bunch of supporting and annoyingly irreducible work to enable this:

- Stop trying to uncurry generic parameter lists during type lowering and preserve the structure of AST GenericParamLists. This makes mapping dependent types into contexts easier.
- Properly walk generic parameter lists at all depths when grooming substitution vectors for use with substGenericArgs interfaces.
- Reseat the generic parameter lists created for protocol_method results so that we don't expect the outer Self archetype to be unbound; it's provided by the extra data of the result.
- Hack SILFunctionType serialization never to use a decl reference when serializing its generic param list. When this happens, we get incorrect archetypes. This is a gross hack, but when we're able to jump all the way to interface types, it can go away.

Putting these ducks in a row nicely un-XFAILs TextFormatting.swift.

Swift SVN r11989
2014-01-07 06:50:20 +00:00
Doug Gregor
bbc4b2ddb5 Use Objective-C protocol name directly, without looking at the "Proto" suffix.
Swift SVN r11853
2014-01-03 06:21:55 +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
e06ee37dca Enable SIL protocol witnesses.
We should be able to cut out another layer of IRGen grime now.

This does XFAIL one test, test/Prototypes/TextFormatting.swift, which fails because of a weird archetype ordering in a nested substitution list. This should get sorted out by switching to interface types, so I'm going to let it go until then.

Swift SVN r11618
2013-12-24 04:36:03 +00:00
Joe Groff
96d52d3bdf IRGen: Make 'ConformanceInfo' a class hierarchy.
Split out the old path, where we directly referenced internal constants, from the new one, where we define global symbols, and may need to replaceAllUsesWith a definition when we visit one, so a direct reference to the llvm::Constant* is not robust.

Swift SVN r11612
2013-12-24 00:28:41 +00:00
Joe Groff
3381ae8529 IRGen: Ignore 'var' requirements for now in the WitnessBuilder.
I thought we already ignored these, but it turns out we just never actually instantiated witness tables for the stdlib protocols that declare property requirements. When we eagerly generate witness tables this crashed. Ignore them at the IRGen level for now, so we don't need to regress the stdlib.

Swift SVN r11611
2013-12-24 00:28:39 +00:00
Joe Groff
1690f5265c IRGen: Emit witness tables as exported symbols in -emit-sil-protocol-witness-tables mode.
SILGen eagerly produces witness tables for all of the conformances defined in the module, which is what we want in order to make them runtime-unique. Have IRGen follow suit. This should address a ton of radars about breakage with non-unique conformances once SIL witnesses are turned on. We will need some runtime machinery to handle witness tables with dependent fields, but since we currently ignore the associated type fields of witnesses, we can get away with emitting direct references to all witness tables for now.

Swift SVN r11608
2013-12-23 20:31:49 +00:00
Joe Groff
ee71669a52 IRGen: Handle @objc protocols in the -emit-sil-protocol-witness-tables regime.
These still can't ever take any extra polymorphic params without breaking the calling convention, so protocol_method still needs to produce a thin value in SIL, and we have to ensure we don't add any extra polymorphic params in the IR signature.

Swift SVN r11594
2013-12-23 03:57:38 +00:00
Joe Groff
07a6fd7e21 IRGen: Don't produce polymorphic witness table arguments for @objc protocols.
They don't need them.

Swift SVN r11593
2013-12-23 03:57:36 +00:00
Joe Groff
8c7659451d IRGen: Populate witness tables using SILWitnessTables.
In -emit-sil-protocol-witness-tables mode, bypass IRGen's thunk generation and consult the SILWitnessTable for the functions to use as witnesses. To minimize the shock to the system, we still produce the witness tables themselves using the broken old lazy generation system; we only use the SILWitnessTable to feed it witnesses.

Swift SVN r11577
2013-12-22 22:37:57 +00:00
Joe Groff
2f66cfed70 IRGen: Lower protocol_method in -emit-sil-protocol-witness-tables mode.
We still abuse the 'ExtraData' concept to carry the existential self type metadata from the protocol_method to the application, so we let that argument come from ExtraData when expanding the signature and consume it when binding arguments.

Swift SVN r11565
2013-12-22 04:44:41 +00:00
Joe Groff
548ea3ae3d IRGen: Lower archetype_method calls in -emit-sil-protocol-witness-methods mode.
archetype_method results no longer need to be thick; we can get the Self binding from the substitution in the apply instruction. When considering the 'self' argument of a witness_method, consider an archetype self type as fulfilling itself; we'll inject the metadata for it when we emit the polymorphic source.

Swift SVN r11564
2013-12-22 04:11:07 +00:00
Joe Groff
bd0690be5c IRGen: Unwrap metatype of static method when considering the Self type for a polymorphic convention.
We use the substInputType to create an artificial polymorphic parameter from whole cloth for witnesses, and we don't want to pass the metadata for the metatype.

Swift SVN r11558
2013-12-21 21:56:20 +00:00
Joe Groff
a2f86c42a3 IRGen: Fix bad fallthrough in lowering witness polymorphic source.
Swift SVN r11540
2013-12-21 16:15:07 +00:00
Mark Lacey
9b81800432 Choose correct IR types for @objc return values.
This change updates signature generation as well as IR generation for
calls and returns so that the correct ABI types are generated for the
results of @objc functions.

Swift SVN r11527
2013-12-20 23:31:01 +00:00
Chris Lattner
b29748a6be remove the ASTContext argument from Type::transform,
(various) FunctionType::get's, ArrayType::get,
ArraySliceType::get, OptionalType::get, and a few
other places.

There is more to be done here, but this is all I plan to do
for now.


Swift SVN r11497
2013-12-20 02:23:21 +00:00
Joe Groff
017440165e Fix the weird capitalization of MetaTypeType.
Swift SVN r11475
2013-12-19 18:43:08 +00:00
Joe Groff
f9a5b2cf25 IRGen: Lower the witness polymorphic convention.
Add a new SourceKind for PolymorphicConvention, 'WitnessSelf', which always introduces a final 'Self' metadata argument to the signature and uses it to fulfill all of the generic parameters of the Self type, regardless of the SIL-level polymorphic signature of the function.

Swift SVN r11467
2013-12-19 06:48:08 +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
Doug Gregor
2d75ca2adf Add a LazyResolver to ProtocolConformance::getWitness().
Swift SVN r11331
2013-12-15 19:40:49 +00:00
Joe Groff
9d2f5719dc IRGen: Factor logic to look up witness tables out of forEachProtocolWitnessTable loop.
This lets us share implementation with emitArchetypeMethodValue and easily generalize emitArchetypeMethodValue to work with concrete types.

Swift SVN r10941
2013-12-06 21:56:33 +00:00
John McCall
4bba9b38f8 Make several new interfaces traffic in AbstractionPatterns.
Swift SVN r10621
2013-11-21 02:19:46 +00:00
Adrian Prantl
a3960c4299 silentium!
Swift SVN r10617
2013-11-21 00:50:52 +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
Joe Groff
d188fd5c0a IRGen: Handle class-existential-to-opaque-archetype cast.
Handle an indirect cast from a class existential, so we can cast class existentials to opaque archetype types. Fixes <rdar://problem/15313840>.

Swift SVN r10545
2013-11-18 19:26:51 +00:00
Adrian Prantl
2abe03fda0 Debug Info: Emit a shadow copy of the type metadata in an alloca at -O0
so we can emit persistent debug info for it.
Fixes <rdar://problem/15428758> dbg.value doesn't make it into the .o file.

Swift SVN r10354
2013-11-12 01:24:12 +00:00
Joe Groff
7de9706403 IRGen/Runtime: Expose extra inhabitants of class protocol types.
This gives 'id?' and other optional class protocol types optimal representation consistent with class types.

Swift SVN r10346
2013-11-11 22:52:23 +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
554abf2d7a IRGen/Runtime: Expose extra inhabitants of class types.
Start using null-page values as extra inhabitants when laying out single-payload enums that contain class pointers as their payload type. Don't use inhabitants that set the lowest bit, to avoid trampling potential ObjC tagged pointer representations. This means that 'T?' for class type T now has a null pointer representation. Enums with multiple empty cases, as well as nested enums like 'T??', should now have optimal representations for class type T as well.

Note that we don't yet expose extra inhabitants for aggregates that contain heap object references, such as structs with class fields, Swift function types, or class-bounded existentials (even when the existential has no witness tables).

Swift SVN r10061
2013-11-09 00:43:40 +00:00
Joe Groff
51f615687c IRGen: Don't assert out when a generic class conforms to a protocol.
Fixes <rdar://problem/15420374>.

Swift SVN r10040
2013-11-08 17:36:59 +00:00
Doug Gregor
0107e36e8b Allow models to omit witnesses for optional protocol requirements.
Swift SVN r9962
2013-11-05 16:28:34 +00:00
Joe Groff
72594e0bc1 IRGen: Remove dead code for producing existential 'typeOf' value witnesses.
Existential value witnesses come from the runtime now.

Swift SVN r9877
2013-11-01 20:21:37 +00:00
Adrian Prantl
459db73092 Debug info: Move the logic for emitting type metadata arguments to
GenProto, and emit both the mangled name and the type variable used by the
programmer for archetypes.
Fixes <rdar://problem/15346134> The $swift.type metadata arguments do not show up anymore

Swift SVN r9844
2013-10-31 04:50:33 +00:00
Jordan Rose
766f41f266 Put top-level decls in the SourceFile DeclContext, rather than in the TU.
Swift SVN r9647
2013-10-24 18:59:24 +00:00
Joe Groff
97eb75294d IRGen: Make getFixedPacking a public interface of TypeInfo.
This is useful for LLDB to determine, given a known fixed-size type, whether values of that type pack inline into fixed-size buffers without having to grovel the VWT in the process memory.

Swift SVN r9632
2013-10-23 23:27:09 +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
f164a88615 IRGen: Emit ObjC protocol records for protocols used in casts.
Greg indicated that objc_getProtocol only works if somebody actually reifies a protocol_t record for the protocol with the runtime, so we need to emit our own protocol_t for every Protocol* value we do a checked cast with. Hijack the ClassDataBuilder to also build protocol_t records.

Swift SVN r9420
2013-10-16 21:50:56 +00:00
Joe Groff
16e66e6f96 IRGen: Swallow the 'Proto' suffix the Clang import tags onto ObjC protocols.
Swift SVN r9400
2013-10-16 01:46:11 +00:00