Commit Graph

728 Commits

Author SHA1 Message Date
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
Joe Groff
02a0e996c4 SIL: Kill initialize_var instruction.
Remove the initialize_var instruction now that DI fully diagnoses initialization problems. Change String-to-NSString bridging to explicitly invoke String's default constructor; it was the last remaining user of initialize_var. Remove dead code to emit an implicit default constructor without a body.

Swift SVN r11066
2013-12-10 03:36:59 +00:00
Chris Lattner
e07994c9c8 Two changes:
- Fix a misunderstanding I had about ownership requirements in my previous patch:
   now any references to value-promoted self do a retain and use a ManagedValue,
   just like the semantic load path used to.  This is the change to visitLoadExpr
 - Second, change argument lowering to drop the "self" argument of normal class
   methods into a constant reference, instead of making a box for it.  This 
   greatly reduces the amount of SIL generated for class methods.

The argument lowering piece is somewhat hacky because initializations really want
to be dealing with memory, but it seemed like the best approach given the current
design.  Review appreciated.



Swift SVN r10984
2013-12-07 21:30:38 +00:00
Chris Lattner
73ea257446 remove an old and apparently unnecessary hack in pattern lowering for arguments.
Disable the copyaddr peepholes when the loadexpr is from a constant VarDecl.


Swift SVN r10982
2013-12-07 08:19:38 +00:00
Chris Lattner
8c7ff5bcef inline a lambda into its only caller.
Swift SVN r10981
2013-12-07 07:10:54 +00:00
Chris Lattner
c1b30b86f4 remove CleanupDestructorSelf, which was only used by now-removed
destructor logic for dancing around self issues.


Swift SVN r10979
2013-12-07 05:53:58 +00:00
Chris Lattner
db0fe52b65 Introduce a new CaptureKind::Constant concept to SILGen, allowing it
to correctly form closures over 'constant' VarDecls like 'self' in 
some cases.


Swift SVN r10978
2013-12-07 05:48:59 +00:00
Adrian Prantl
97ce2b1845 Debug info: Emit dbg.values for self arguments without explicit storage
(such as in destructors).
Fixes <rdar://problem/15609657> No debug info for self in some cases.

Swift SVN r10975
2013-12-07 03:08:22 +00:00
Chris Lattner
dec95a6890 At Joe's request, rename CaptureKind::Constant ->
CaptureKind::LocalFunction, and LocalConstants -> LocalFunctions


Swift SVN r10965
2013-12-07 01:25:30 +00:00
Chris Lattner
0e271de509 introduce a new kind of VarLoc to SILGen: "constant". This
is used for VarDecls that are immutable once defined.  This 
will eventually be used to model 'val' in SILGen, but for now
we can use it to optimize some 'self' situations.

At present, we use it for class 'self' in destructors and for
init methods of root classes.  The init methods of derived 
classes need to be able to mutate self when calling super.init
so they can't use this presently.  I haven't gotten around to
switching general methods to use it yet.

This introduces two new regressions that don't appear in the
testsuite: we lose debug info for "self" in this case, and 
we cannot close over self.



Swift SVN r10962
2013-12-07 01:13:55 +00:00
Chris Lattner
567a3175dc extend the mark_initialized SIL instruction to have a "kind" enum field.
Existing uses use a "globalvar" kind.  Add a new "rootinit" kind which
will be used for root initializers (i.e. init methods of structs, enums, 
and root classes).



Swift SVN r10772
2013-12-04 02:02:15 +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
f09950390c SILGen: Don't expect an override for declarations from class extensions.
If a subclass overrides a declaration from an ObjC class extension, that decl won't have a vtable entry, and we shouldn't expect to override it. Fixes <rdar://problem/15282548>.

Swift SVN r10547
2013-11-18 21:00:18 +00:00
Joe Groff
7b9f61de5c SILGen: Emit global var decl refs as calls to the accessor.
Route global var refs (except for those referencing top-level code vars) through the lazy-initializing global accessor functions for those globals.

Swift SVN r10519
2013-11-16 23:52:39 +00:00
Joe Groff
a049ee9d38 SILGen: (Optionally) emit lazy initializers and accessor fns for globals.
For every global pattern binding, emit a lazy initializer token and function that initializes the global variables in that binding. For each of those vars, create an accessor that Builtin.once's the lazy initializer before producing the address. Hide this all behind a switch till the surrounding serialization and IRGen infrastructure catches up.

Swift SVN r10511
2013-11-16 00:50:19 +00:00
Chris Lattner
4968cc208b A couple of related changes:
- Enhance SILBuilder::emitStrongRelease to be smarter.
- Start using emitStrongRelease in type lowering, SILGen,
  CapturePromotion (replacing its implementation of the
  same logic), and MandatoryInlining (one more place)
- Rename the primitive createStrongRetain/ReleaseInst
  instructions to lose their suffix.
- Now that createStrongRetain/ReleaseInst are not special
  cases from the naming perspective, remove some special cases
  from DeserializeSIL and ParseSIL.
  


Swift SVN r10449
2013-11-14 02:21:27 +00:00
Chris Lattner
9570e1fb0c Remove the "createStrongRetain" and "createStrongRelease" SILBuilder methods.
They are the same as createStrongRetainInst and createStrongReleaseInst, but
peephole away FunctionRefInst.  It turns out that there is only a couple
places in SILGen where this behavior is necessary, and this tramples on the
general pattern used in SILBuilder.


Swift SVN r10448
2013-11-14 02:00:41 +00:00
Joe Groff
19f1bbdebb SILGen: Emit global initialization for static properties.
For the subset of static properties we're implementing, we can skate by with global static constructors like we do for global variables. Leave some asserts behind so we revisit this when we implement the hard cases.

Swift SVN r10383
2013-11-12 23:27:47 +00:00
Joe Groff
2a4dfed8f5 SILGen: Emit RawRepresentable methods of imported enums.
In SILGen, when we emit the enum external definition, emit the methods in addition to the case constructors for the enum. Make sure they get thunk linkage.

Swift SVN r10017
2013-11-07 03:49:32 +00:00