Commit Graph

9332 Commits

Author SHA1 Message Date
Joe Groff
b2f0b90ba2 SIL: Switch to SILFunctionType interface types in easy-to-reach places.
In nongeneric contexts, or contexts where we only care about the indirectness of parameters or have already substituted the generic parameters for a function, the interface types are interchangeable, so just switch over.

Swift SVN r12044
2014-01-08 04:48:29 +00:00
Joe Groff
14254e8749 Factor logic for structurally substituting dependent types into ArchetypeBuilder.
Add an Archetype::substDependentType method that positionally substitutes dependent parameters and resolves dependent member types using the ArchetypeBuilder's archetypes, as in Array<$T.Foo>.Bar. We will want the same logic for IRGen's type converter when lowering generic signatures. NFC.

Swift SVN r12033
2014-01-08 02:05:19 +00:00
Joe Groff
6ca8873f99 Rename ArchetypeBuilder::resolveType to resolveArchetype.
It only resolves dependent types that directly reference archetypes.

Swift SVN r12032
2014-01-08 02:05:12 +00:00
Joe Groff
8f6a58b998 SIL: Split address-only enum dispatch from destructive projection.
Split 'destructive_switch_enum_addr' into separate 'switch_enum_addr' and 'take_enum_data_addr' instructions. This should unblock some optimization work we would like to do with enums.

Swift SVN r12015
2014-01-07 22:58:21 +00:00
Joe Groff
530e948cb2 SIL: Rename 'enum_data_addr' to 'init_enum_data_addr'.
Emphasize the fact that this address is only intended for initialization. When we split destructive_switch_enum_addr, there will be another similar instruction for destructively taking the payload out of an already-initialized enum.

Swift SVN r12000
2014-01-07 18:40:00 +00:00
Joe Groff
03d2dd7b10 Add an addGenericSignature method to ArchetypeBuilder.
Factors out the loops for adding all the generic parameters and requirements of a signature to an ArchetypeBuilder. NFC.

Swift SVN r11996
2014-01-07 17:56:36 +00:00
Doug Gregor
1cf3bdbe8c Use objc_msgSendSuper[Stret] for foreign initializer delegation.
Introduce the SIL instruction peer_method, which references a method
in the given class or one of its superclasses (but not a subclass). It
IRGen's to objc_msgSendSuper[Stret] (vs. super_method IRGen'ing to
objc_msgSendSuper[Stret]2 for superclass lookup).

Use peer_method for initializer delegation to a foreign initializer
(i.e., an init-family method written in Objective-C) to close the
safety loophole introduced by initializer delegation in r11965. The
loophole still exists, but can only be triggered from Objective-C.

Teach definite initialization that peer_method really isn't a use of
self.



Swift SVN r11992
2014-01-07 17:33:41 +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
Joe Groff
4a8edecc8c SIL: Positionally build archetypes in dependent member types when lowering.
A DependentMemberType may have a complex base type, such as Array<$T_0_0>.IndexType, in which case it resolves not to an archetype but to a conformance of the archetype-substituted contextual base type Array<T>. When we visit a DependentMemberType during TypeLowering, fall back to a positional substitution if the fast path of resolving an archetype with ArchetypeBuilder fails.

Swift SVN r11987
2014-01-07 06:50:17 +00:00
Chris Lattner
7e69153d14 merge the MUI flags for delegating self: there is no need to
differentiate the 'derived' and 'base' cases for delegating
initializers.  One is better than two.


Swift SVN r11981
2014-01-07 05:39:21 +00:00
John McCall
e507341c1b SILModule lookup: now with that magic O(1) flavor.
Swift SVN r11978
2014-01-07 01:21:10 +00:00
John McCall
bb63d2312b Hide the constructors of SILFunction/SILGlobalVariable
behind factory methods.

Swift SVN r11967
2014-01-07 00:22:15 +00:00
Chris Lattner
3f6ce3f888 introduce new flavors of MarkUninitializedInst to model delegating ctors to DI.
Swift SVN r11961
2014-01-06 23:13:41 +00:00
Chris Lattner
5c5c7829da Rework SILGen of address-only let declarations. Previously, we would just drop them
into heap boxes like var decls.  Now we drop them into stack temporaries like rvalues.

No semantic change goes with this.



Swift SVN r11939
2014-01-06 19:42:50 +00:00
Joe Groff
ec4279e0c3 SIL: Dependent types have non-trivial metatypes.
Swift SVN r11937
2014-01-06 19:11:36 +00:00
Joe Groff
2140daf119 SIL: Install a generic context scope in SILFunctionType::substInterfaceGenericArgs.
We need to be able to lower the substituted types against the interface types in the context of the SILFunctionType's generic signature.

Swift SVN r11936
2014-01-06 19:11:35 +00:00
Joe Groff
fbde5914a5 SIL: Simplify dependent-ness of TypeLowering's type keys.
TypeBase::isDependentType() is cheap now thanks to John's refactoring, so it's no longer necessary to cache it as a separate bit in TypeLowering's TypeKey. Also fix it so that the key is considered dependent if either the original abstraction pattern or the substituted type is dependent.

Swift SVN r11935
2014-01-06 19:11:35 +00:00
Chris Lattner
b689013ad3 fix comment header.
Swift SVN r11931
2014-01-06 18:00:30 +00:00
Doug Gregor
bb833773f5 Add some newlines at the end of files
Swift SVN r11922
2014-01-06 16:34:12 +00:00
Joe Groff
8606022036 Give SILFunctionType an interface for substituting its dependent generic signature.
Factor the logic for turning a substitution vector into a TypeSubstitutionMap into a method on GenericSignature, and use it in GenericFunctionType and SILFunctionType to implement their substGenericArgs interfaces.

Swift SVN r11906
2014-01-04 17:53:36 +00:00
John McCall
12b1c9daf7 Add support for multiple encodings to the string_literal
SIL instruction.  Implement IR-gen support for same.  Fix
the parsing of SIL string literals to properly unescape them.

SIL-gen still emits UTF8 literals unconditionally.

Swift SVN r11904
2014-01-04 11:42:57 +00:00
John McCall
8d68478c77 Move the SILDeclRef mangler to the SIL library. NFC.
Swift SVN r11894
2014-01-04 09:11:14 +00:00
Michael Gottesman
f257340f5a Refactor most of the definitions of SILType methods into SILType.cpp.
Currently SILType's method definitions are strewn in various files in
lib/SIL/*.cpp. This patch just adds a new file SILType.cpp that centralizes
many of those definitions.

*NOTE* Any method which uses declarations inside of a specific *.cpp file I left
alone (there were 3). If we want to, we can perhaps create a new header to share
the interface in between the two. I wanted this change to be as incremental as
possible so I left that undone.

Swift SVN r11890
2014-01-04 05:52:05 +00:00
John McCall
5df03ce334 Abstract out a utility for printing strings in quotes.
Swift SVN r11865
2014-01-03 19:39:07 +00:00
Doug Gregor
1ee513e7e8 Use Builtin.Word for array lengths, string literal lengths, etc.
This eliminates a number of 64-bit integer/64-bit pointer assumptions
in the type checker and SILGen.


Swift SVN r11863
2014-01-03 18:53:01 +00:00
Joe Groff
53d2844a2e SIL: Give TypeLowering support for dependent generic contexts.
Give TypeConverter methods to push and pop a generic context given a set of generic parameter types and requirements from a generic signature. Dependent types lowered in this context can then be lowered using an ArchetypeBuilder seeded with that signature. The TypeLowering objects created for dependent types are put in a special arena which we clear out when we pop the generic context. This sets the stage for allowing us to lower SILFunctionTypes using their interface types.

Swift SVN r11848
2014-01-03 04:04:46 +00:00
Chris Lattner
a73d17a559 Tweak the sil printer to print “let” in alloc_stack/box comments instead of var, when the allocation comes from a let.
Swift SVN r11826
2014-01-02 19:19:23 +00:00
Joe Groff
cdc2b34a80 SIL: Give SILFunction context generic params and a mapTypeInContext method.
For now, steal the context generic params from the SILFunctionType, and borrow ArchetypeBuilder's implementation of mapTypeInContext for AST decl contexts. This should eventually be an independent property.

Swift SVN r11811
2014-01-02 05:47:39 +00:00
Joe Groff
e8a6014f09 SIL: Map archetypes out of the interface parameter and result types of SILFunctionTypes.
When we see an uncurried nested PolymorphicFunctionType, such as <T> Foo -> <U> Bar -> Bas, pull the deepest generic parameter list out into the lowered SIL function type, so that dependent archetypes at all levels get properly represented in the generic parameter list, and we can map them to dependent generic types.

Also, apparently deserialized generic param lists get different archetypes from the corresponding deserialized generic param decls. Weird, but hopefully this will all be over soon, so roll with it, man.

Swift SVN r11809
2014-01-02 03:58:44 +00:00
Chris Lattner
917d2a1d9c remove the dead 'TypeConverter::getMethodSelfType' method, which
is also incorrect.


Swift SVN r11807
2014-01-02 00:59:01 +00:00
Chris Lattner
be58684653 further detangle @inout and @lvalue types, making the code more specific
and simpler.


Swift SVN r11801
2014-01-01 21:35:31 +00:00
Chris Lattner
859883d88e further detangle @lvalue and @inout. types, this time in libsil.
Swift SVN r11800
2014-01-01 20:46:54 +00:00
Michael Gottesman
ccf2c2a3de Remove dead code that snuck in.
Swift SVN r11755
2013-12-31 01:15:53 +00:00
Michael Gottesman
962df13b6c [lower-aggregate-instrs] Teach TypeLowering how to produce "lowered" copy values without bugs this time = ).
Originally there was a emitLoweredCopyValue method in TypeLowering, but it was
removed by Chris in r11353 since SILGen was no longer using it and it had bugs.
This method is useful for SILLowerAggregateInstrs, so I resurrected it, fixing
the bugs therein.

The bug was that emitLoweredCopyValue was not reforming aggregates correctly
since it was only considering non-trivial values. The new implementation passes
in all child values, but only recursively lowers the non-trivial children. This
does create an extra tuple_extract, struct_extract for trivial arguments, but
those are easily cleaned up by later dce.

Swift SVN r11753
2013-12-31 01:10:45 +00:00
Michael Gottesman
e960091e31 [lower-aggregate-instrs] Add an additional type lowering style "DeepNoEnum" for use in lowering aggregate memory operations.
The idea here is that the aggregate memory operation is lowered deep recursively
for all types except enums which recieve a shallow lowering. This prevents code
bloat due to the deep lowering of an enum requiring the creation of a bunch of
new basic blocks, code bloat which we do not want.

Another thing to note is that this method is actually not used anywhere else
currently, but in case this behavior was left in on purpose I decided to extend
it by adding the enum class flag rather than just changing the underlying
behavior (i.e. making deep not lower enum values).

Swift SVN r11748
2013-12-30 23:07:32 +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
Chris Lattner
d3c91387e9 Substantially simplify the API to LValueType now that nonsettable is gone.
Swift SVN r11703
2013-12-28 22:48:44 +00:00
Joe Groff
c76548916e SIL: Have VTables and WitnessTables bump the reference counts of SILFunctions.
Fixes <rdar://problem/15725600>.

Swift SVN r11666
2013-12-27 05:59:19 +00:00
Chris Lattner
000292096c fix closures over address only values to properly capture like
boxes, instead of exploding in silgen.



Swift SVN r11652
2013-12-26 03:32:42 +00:00
Nadav Rotem
8d75365b10 Add an assertion
Swift SVN r11622
2013-12-24 21:16:35 +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
3116a389f7 SIL: Consider original abstraction pattern when lowering result of function type.
Lower the result type according to the original abstraction pattern the function is following, so that we represent metatype and function results properly.

Swift SVN r11617
2013-12-24 04:36:00 +00:00
Michael Gottesman
2eb34c35a4 [sil-inliner] Ensure that all special flags are propagated when we create a CleanupLocation, MandatoryInlinedLocation, or InlinedLocation from a SILLocation.
This corresponds to the fix I spoke of in r11595.

Swift SVN r11600
2013-12-23 06:35:38 +00:00
Nadav Rotem
20410a3b92 CondBranchInst: Save the number of true and false arguments.
The current implementation depends on the target basic block to record the number of argumens, but this is a bad idea because it makes it difficult to modify the argument list.



Swift SVN r11597
2013-12-23 06:23:02 +00:00
Michael Gottesman
90cbfb2e57 [sil-inliner] Removed invalid assert.
Given a destructor that is not implicit, one will have a decl that is not
autogenerated implying that this assert will always be hit.

I am going to submit an additional patch after this that changes
InlineLocation/MandatoryInlinedLocation/CleanupLocation that ensures that
the special flags on SILLocation are propagated appropriately (which they are
not right now).

Swift SVN r11595
2013-12-23 06:00:54 +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
8f47dc7383 SIL: Add a SILModule::lookUpWitnessTable method.
Looks up the SILWitnessTable for a ProtocolConformance.

Swift SVN r11576
2013-12-22 22:37:56 +00:00
Joe Groff
fd7b61ac71 SIL: Add a lookup cache StringMap to SILModule.
Because doing linear lookup all the time is dumb. NFC.

Swift SVN r11575
2013-12-22 22:37:55 +00:00
Joe Groff
55ab7ee3fb SIL: Fix a verifier false negative when invoking static methods on archetypes with -emit-sil-protocol-witness-tables.
Swift SVN r11553
2013-12-21 20:57:11 +00:00
Joe Groff
63d08c786d SIL: Handle metatype abstraction differences.
Lower metatype types as @thin or @thick based on whether the type is static and whether the abstraction pattern allows for a thin metatype. Add a '@thick' attribute and require SIL metatypes to always be annotated with either '@thin' or '@thick' to distinguish them from unlowered metatypes.

Swift SVN r11525
2013-12-20 23:06:16 +00:00