Commit Graph

747 Commits

Author SHA1 Message Date
Doug Gregor
f05263d4fe Objective-C's -dealloc is a deallocating destructor, not a destroying destructor.
Because Objective-C doesn't have the notion of a destroying
destructor, this is a matter of cleanliness rather than
correctness. Still, it's better not to lie.


Swift SVN r12160
2014-01-10 23:08:42 +00:00
Doug Gregor
2bf20ccbc3 Add the ClassDecl::getDestructor() convenience method.
Swift SVN r12140
2014-01-10 22:32:49 +00:00
Doug Gregor
5f1b8618f4 Make the SILDeclRef for a destroying destructor store a DestructorDecl.
SILDeclRef was previously storing the ClassDecl for this case, because
semantic analysis didn't guarantee that a DestructorDecl was always
present. It is now, and this representation makes more sense.

Swift SVN r12122
2014-01-10 17:33:57 +00:00
Doug Gregor
03edef185a Emit a -dealloc method for Swift classes whose root class is defined in Objective-C.
Teach SILGen to emit a -dealloc method that runs user code, destroys
instance variables, and then calls up to the superclass dealloc. Teach
IRGen to deal with Objective-C destructor methods and add -dealloc to
the instance method table.

There are a few things still wrong here: we're emitting both a Swift
destructor and -dealloc, even though only one of them should ever
actually be used. Additionally, instance variables shouldn't be
destroyed in -dealloc, but in .cxx_destruct, so they persist until the
last of the -dealloc methods is invoked.

Swift SVN r12115
2014-01-10 05:07:33 +00:00
Doug Gregor
6e6eb57857 Don't delay the emission of the destructor in SILGen.
Swift SVN r12096
2014-01-09 18:15:12 +00:00
Doug Gregor
fbb5681110 SILGen doesn't need to cope with missing DestructorDecls.
Swift SVN r12095
2014-01-09 18:15:12 +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
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
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
Joe Groff
c47820ff3d Add a convenience method for reparenting a GenericParamList.
NFC.

Swift SVN r11995
2014-01-07 17:56:36 +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
John McCall
bb63d2312b Hide the constructors of SILFunction/SILGlobalVariable
behind factory methods.

Swift SVN r11967
2014-01-07 00:22:15 +00:00
John McCall
cca5fb3bc0 Remove name mutators for SILFunction and SILGlobalVariable.
Swift SVN r11963
2014-01-06 23:32:52 +00:00
Chris Lattner
d196abc8a4 When binding address-only let declarations to let arguments, use the
buffer being passed in, instead of creating a temporary one and copying
into it.

For:

func generic_identity<T>(let a : T) -> T {
  return a
}

We now get:

sil @_TF2t216generic_identityU__FT1aQ__Q_ : $@thin <$T_0_0> (@out $T_0_0, @in $T_0_0) -> () {
bb0(%0 : $*T, %1 : $*T):
  copy_addr [take] %1 to [initialization] %0 : $*T // id: %2
  %3 = tuple ()                                   // user: %4
  return %3 : $()                                 // id: %4
}

We used to produce:

sil @_TF2t216generic_identityU__FT1aQ__Q_ : $@thin <$T_0_0> (@out $T_0_0, @in $T_0_0) -> () {
bb0(%0 : $*T, %1 : $*T):
  %2 = alloc_box $T  // let a                     // users: %5, %4, %3
  copy_addr [take] %1 to [initialization] %2#1 : $*T // id: %3
  copy_addr %2#1 to [initialization] %0 : $*T     // id: %4
  strong_release %2#0 : $Builtin.ObjectPointer    // id: %5
  %6 = tuple ()                                   // user: %7
  return %6 : $()                                 // id: %7
}

and then optimize it into:

sil @_TF2t216generic_identityU__FT1aQ__Q_ : $@thin <$T_0_0> (@out $T_0_0, @in $T_0_0) -> () {
bb0(%0 : $*T, %1 : $*T):
  %2 = alloc_stack $T  // let a                   // users: %5, %3, %4
  copy_addr [take] %1 to [initialization] %2#1 : $*T // id: %3
  copy_addr [take] %2#1 to [initialization] %0 : $*T // id: %4
  dealloc_stack %2#0 : $*@local_storage T         // id: %5
  %6 = tuple ()                                   // user: %7
  return %6 : $()                                 // id: %7
}



Swift SVN r11941
2014-01-06 19:54:04 +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
Chris Lattner
1523798f5f simplify emitDestructorProlog, NFC.
Swift SVN r11930
2014-01-06 17:21:19 +00:00
Chris Lattner
ac8958a598 remove overly conservative code: destructors always have self decls.
Value types don't have dtors.


Swift SVN r11911
2014-01-04 22:48:44 +00:00
John McCall
17a8acfe43 Remove the vestiges of the SILGen mangler.
Swift SVN r11895
2014-01-04 09:11:15 +00:00
Joe Groff
9631362689 SILGen: Reparent the inner context generic params of witness functions.
For a witness to a generic requirement, the generic parameters of the requirement should be parented to the generic parameters of the conformance, not to the 'Self' parameter list of the original protocol. The generic signature conversion in SILFunctionType construction revealed this improper nesting because it was introducing unused "$T_0_0" parameters into witnesses in nongeneric conformances.

Swift SVN r11861
2014-01-03 18:18:15 +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
468ead25a6 allow 'var' and 'let' to appear in patterns (not just matching patterns).
This allows them to appear in argument lists of functions, enabling behavior
like this:

func test_arguments(a : Int, var b : Int, let c : Int) {
  a = 1  // ok (for now).
  b = 2  // ok.
  c = 3  // expected-error {{cannot assign to the result of this expression}}
}



Swift SVN r11746
2013-12-30 21:48:06 +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
b1a882c093 Fix a problem where let decls of tuple type would die in SILGen when
being closed over.  If we allowed arguments to have tuple type
in the SILFunctionType type system, this would just work.  As it is,
we have to do a bit of [re|de]structuring on the partial_apply and
the closure body side to work things out.


Swift SVN r11680
2013-12-27 23:22:57 +00:00
Chris Lattner
5faf530cf2 implement restructuring assignment of let decls, repurposing the existing
implosion logic.  This resolves rdar://15716277


Swift SVN r11679
2013-12-27 22:30:28 +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
ba7c1ab281 SILGen: Substitution conformances don't actually always match protocol declaration order for associated types.
What's a little more linear search? Maybe there's some other predictable order.

Swift SVN r11616
2013-12-24 04:35:56 +00:00
Chris Lattner
451da95f1a Fix destruction of address-only let decls, which do have boxes despite
being immutable.  This addresses rdar://15717123.


Swift SVN r11604
2013-12-23 06:58:05 +00:00
Joe Groff
312096587e SILGen: Assign protocol witnesses a debug scope.
Swift SVN r11589
2013-12-23 02:45:23 +00:00
Joe Groff
8bd65469cf SILGen: Ignore property requirements when emitting witness tables.
Apparently these exist in the stdlib, and the old IRGen witness table builder ignores them. Let's follow suit for now.

Swift SVN r11585
2013-12-23 00:59:27 +00:00
Doug Gregor
be3463f32d Store a file-level DeclContext* in protocol conformances rather than a module.
We'll need to perform name lookup based on the file-level
DeclContext*, so the module no longer suffices. No functionality
change here yet.


Swift SVN r11523
2013-12-20 22:53:21 +00:00
Chris Lattner
90284eca72 reimplement cleanup processing for 'let' VarDecls. Previously, we would
emit the cleanup for the initializing expression when the expression was
complete, instead of at the end of the let decl scope (releasing things 
too early).

This fixes rdar://15689514, thanks to DaveA for the great testcase.


Swift SVN r11516
2013-12-20 18:50:03 +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
Chris Lattner
2b990be666 remove the rest of the hacky code that special cased "self" in various places in SILGen
to lower it without a box.  The 'let' bit subsumes this now.


Swift SVN r11361
2013-12-16 20:44:08 +00:00
Chris Lattner
1788421e5d Change SILGen to lower and bind non-address-only 'let' variables
as values, without a box at all.  This generalizes some of the
previous hacks I had for silgen'ing 'self' as a value instead of
a box, and capturing them with CaptureKind::Constant.




Swift SVN r11360
2013-12-16 20:36:16 +00:00
Doug Gregor
2d75ca2adf Add a LazyResolver to ProtocolConformance::getWitness().
Swift SVN r11331
2013-12-15 19:40:49 +00:00
Chris Lattner
e87b611fc3 Change silgen to lower non-inout-self arguments as simple values, instead of
allocating a box for them.  When self is not marked inout (which will be
the default for structs someday) it changes the codegen of:

struct Foo {
  ...

  func testfunction() -> Foo {
    return self
  }
}

To:

sil @_TV1t3Foo12testfunctionfS0_FT_S0_ : $@cc(method) @thin (Foo) -> Foo {
bb0(%0 : $Foo):
  %1 = tuple ()
  return %0 : $Foo                                // id: %2
}

instead of allocating a box, doing a store to it, etc.

Also included: don't maintain references into VarLoc where a simple copy
of the element would suffice.  This isn't important, but was part of my
silvtable debugging and seems like the right thing.



Swift SVN r11307
2013-12-14 07:28:53 +00:00
Doug Gregor
07c0793e30 Construct the type witnesses of SpecializedProtocolConformance lazily.
A SpecializedProtocolConformance intentionally contains all of the
information we need to synthesize the type witnesses from the
underlying (generic) conformance. Do so lazily rather than eagerly,
because we won't always need all of them.

As a nice side effect, we no longer need to serialize the witnesses of
these specialized protocol conformances, so we can save some space in
the Swift module file.


Swift SVN r11303
2013-12-14 06:20:44 +00:00
Doug Gregor
b4a739854d Stop using ProtocolConformance::getWitnesses().
It's going away, soon.


Swift SVN r11277
2013-12-13 23:44:42 +00:00
Joe Groff
fe99127bdb SILGen: Don't emit base_protocol or associated_type_protocol witness table entries for @objc requirements.
And put the 'P->isObjC()' check behind a more semantic 'protocolRequiresWitnessTable' check.

Swift SVN r11276
2013-12-13 23:37:07 +00:00
Joe Groff
1da0fba39c SILGen: Emit witness tables for generic types.
Tweak the type lowering code to work when the conforming type is generic. Handle the case of an associated type with protocol requirements being witnessed by an archetype of the conforming type, which results in a null ProtocolConformance pointer in the witnessing substitution.

Swift SVN r11275
2013-12-13 22:59:38 +00:00
Doug Gregor
fadebe02bb Stop using ProtocolConformance::getTypeWitnesses() almost everywhere.
In doing so, make serialization more deterministic. It was depending
on DenseMap ordering for both type and value witnesses. Now, serialize
the witnesses in the declaration order of the requirements.


Swift SVN r11267
2013-12-13 21:31:57 +00:00
Joe Groff
61c674b82f SILGen: Include refined protocol conformances in witness tables.
When a type conforms to a protocol that refines another protocol, emit the witness table for the base protocol, and drop a reference into the witness table for the derived protocol. Keep track of what conformances we've already emitted so we don't emit redundant witness tables when types conform redundantly to base protocols or have multiple references to a base protocol via a refinement diamond.

Swift SVN r11263
2013-12-13 19:23:22 +00:00
Joe Groff
402f4daa58 SILGen: Emit protocol witnesses.
Reuse John's abstraction thunking machinery in SILGenPoly to emit the abstraction change from a protocol requirement to a concrete witness. There are potentially two abstraction changes necessary; if a witness is generic, we need to reabstract again from the concrete substituted type of the witness to the generic witness function's original signature. This currently leads to a bunch of extra temporaries in cases where an argument or return gets unabstracted to a loadable value then reabstracted to a generic parameter, but optimizations should be able to clean this up. Protocol witnesses also have additional potential abstraction changes in their 'self' parameter: the 'self' parameter of the protocol requirement is always considered @inout, but class 'self' parameters are not; also, an operator requirement can be satisfied by a free function, in which case 'self' is discarded.

Also, fix a bug in return value thunking where, if the thunk could reuse its @out parameter as the @out parameter of the underlying function, we would not disable the cleanup we install on the result value, leading to the result getting overreleased.

Swift SVN r11245
2013-12-13 05:58:51 +00:00
Joe Groff
38bbeb4149 SILGen: Don't emit witness tables for @objc protocols.
Swift SVN r11244
2013-12-13 05:58:50 +00:00
Adrian Prantl
c610ac94ef Add an IsBare attribute to SILFunction for functions that do not have an
AST.

Swift SVN r11236
2013-12-13 04:48:37 +00:00
Joe Groff
88e5dece28 SILGen: Implement a visitor to produce witness tables.
Walk the ProtocolConformances of type and extension decls to produce SILWitnessTables for them. Work out the type of the witness function by applying substitutions from the witness map and lowering it at the abstraction level of the requirement, then emit a symbol for the witness function (but don't emit the body of the witness function just yet).

Swift SVN r11143
2013-12-11 21:40:44 +00:00
Joe Groff
6547c69b33 Turn on lazy global initializers.
Swift SVN r11136
2013-12-11 18:59:56 +00:00
Chris Lattner
698380d6d3 Introduce a new bit in VarDecl, "isLet". Teach Sema that 'isLet' properties
are not settable (like get-only ones).  Set the 'isLet' bit in various 
places, but not the particularly interesting or useful places yet.



Swift SVN r11121
2013-12-11 06:45:40 +00:00
Adrian Prantl
2acb71831e SILArgument: Make Decls mandatory for function arguments.
Swift SVN r11099
2013-12-10 23:30:23 +00:00
Joe Groff
4d1459a6e4 SILGen: Don't blow up trying to emit lazy global initializers for computed properties or declarations without initializers.
Swift SVN r11079
2013-12-10 17:41:14 +00:00