Commit Graph

6754 Commits

Author SHA1 Message Date
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
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
Joe Groff
706e7baac4 SILGen: Handle abstraction differences in stored property access.
When we produce a physical LValue with an abstraction difference, cap off the LValue with a logical "OrigToSubstComponent", which enacts the abstraction change on load or store, and introduces a writeback for the property when used in an @inout context.

Swift SVN r11498
2013-12-20 02:25:11 +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
1472e4d914 Remove the ASTContext argument from LValueType::get(). It is already
only two loads away from the type argument passed in.



Swift SVN r11496
2013-12-20 01:28:50 +00:00
Joe Groff
af9d91f2a9 SIL: Use 'SILType::fieldType' consistently instead of 'Type::getTypeOfMember'.
Centralizes the somewhat tricky dance to get a property type at the right abstraction level for the containing type. NFC.

Swift SVN r11491
2013-12-19 23:43:33 +00:00
Jordan Rose
308c6139f9 Change ASTContext::allocate(unsigned) to return a MutableArrayRef.
...rather than a raw pointer that points to a buffer with space for N
elements. Just because we *can* get N from context doesn't mean it's
convenient/safe.

No functionality change.

Swift SVN r11488
2013-12-19 23:25:04 +00:00
Joe Groff
017440165e Fix the weird capitalization of MetaTypeType.
Swift SVN r11475
2013-12-19 18:43:08 +00:00
Anna Zaks
e64247b0b3 Insert implicit calls to super.init
Insert calls to super.init at the end of the class initializers that don't
reference any other initializers but have parents. The check for initializer
eligibility, expression construction, and typechecking are done on the AST level.
However, we insert the call inside the epilog block at SILGen to ensure that
constructors with early returns are handled properly.

Addresses radar://13108250.

Swift SVN r11444
2013-12-18 22:49:00 +00:00
John McCall
c5aa41ffd1 Change around some manglings to make them carry more
information and be easier to demangle.

Swift SVN r11423
2013-12-18 08:33:52 +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
Chris Lattner
fbe1d09e77 stop marking "$0" arguments in closures, and generator variables in foreach
loops as 'let', silgen isn't ready for it yet.

Change silgen's handling of let variables to stop using emitLoweredCopyValue,
which is busted for aggregates that contain both trivial and nontrivial types
(15669586).


Swift SVN r11352
2013-12-16 19:38:49 +00:00
Joe Groff
44dcc43fa9 ClangImporter: Make NS_OPTIONS imports conform to RawOptionSet.
This makes the bitwise operations &|^~ work with NS_OPTIONS.

Swift SVN r11349
2013-12-16 19:22:27 +00:00
Doug Gregor
2d75ca2adf Add a LazyResolver to ProtocolConformance::getWitness().
Swift SVN r11331
2013-12-15 19:40:49 +00:00
Joe Groff
1667ed6ec6 SIL: Tweak protocol_method for the SIL-witness-tables regime.
I'd like to treat protocol_method equivalently to archetype_method, but we don't have a way to "open" the implicit type variable inside the existential, so protocol_method still needs to produce a "thick" witness_method reference with the Self polymorphic binding partially applied. We can at least simplify the SIL model by saying that its result is always thick, and let the lowering of @cc(witness_method) @thick in IRGen work out how thick that actually has to be for the given function type, instead of reflecting all the special cases in SIL.

Swift SVN r11330
2013-12-15 06:03:11 +00:00
Joe Groff
d7c819b4f3 SIL: Redefine archetype_method in the SIL-witness-tables regime to return an unsubstituted witness.
Clear up the last bit of wanton implicit behavior in archetype_method by having it return the witness as a thin function generic on <Self: P>. Applying the result with <Self = T> will then naturally provide the polymorphic context parameters required by the witness. Tweak the implementation of SILFunctionType::substGenericArgs to handle a substitution for the Self archetype.

Swift SVN r11316
2013-12-14 21:20:46 +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
Jim Ingham
e0b163ae67 Pass a SILBuilder into the debugger client so that
it can indeed build SIL expressions rather than just
look at them go by.


Swift SVN r11285
2013-12-14 01:14: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
Doug Gregor
c19f9e3719 Add newline at the end of the file.
Swift SVN r11265
2013-12-13 21:20:08 +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
Sean Callanan
a1881434c2 Added support to allow LLDB to provide the
location of variables at SIL generation time.
This patch introduces a SILDebuggerClient that
knows how to resolve the locations of variables
that are generated by the debugger.  These
variables have a flag on them that only LLDB
sets.


Swift SVN r11230
2013-12-13 01:43:02 +00:00
Doug Gregor
0c4baac6f6 Make the 'self' declaration of a value type constructor be '@inout'.
This removes an oddity in the AST whereby the 'self' declaration
within a value type constructor was not represented as @inout, despite
having @inout semantics in the language.


Swift SVN r11194
2013-12-12 18:31:54 +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
Joe Groff
4a25b56846 SILGen: REPL globals are not lazily initialized.
Check for a REPL SourceFileKind along with Main before going the lazy initialization path. Also put response variables in the REPL SourceFile decl context so they are recognized as REPL variables and not lazily initialized. Handle PatternBindingDecls that appear under a script-mode SourceFile decl context but not a TopLevelCodeDecl context.

Swift SVN r11133
2013-12-11 17:54:17 +00:00
Joe Groff
3688e6f60e SILGen: Don't try to emit lazy initializers for globals from Clang.
Swift SVN r11132
2013-12-11 17:54:16 +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
Adrian Prantl
1f927d9ffc Overhaul the handling of return locations for auto-generated code.
- change SILGenFunction to use Cleanup and Implicit return locations for
  auto-generated cleanups/returns where sensible.
- Fix a bug in where ConstructorDecl that would return the wrong
  source range.
- Move the expected locations of some errors to the end of the function
  where they should belong.

Fixes <rdar://problem/15609768> Line tables for classes that don't have
init but just initialize ivars are odd

Swift SVN r11086
2013-12-10 19:23:34 +00:00
Joe Groff
c5dd36cd99 SILGen: Attach debug scopes and location info to lazy init functions.
Swift SVN r11080
2013-12-10 17:41:15 +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
Anna Zaks
799fba7c63 Improve the location information for class and value initializer bodies.
This improves the error location information for DI diagnostics. rdar://15581664

Swift SVN r11062
2013-12-10 00:40:14 +00:00
Chris Lattner
8d997cdafb remove an unnecessary special case from SILGen. There is now only one last
use of initialize_var left, which is used in NSString bridging.  Once that
is gone (tracked by rdar://15568558, which I don't plan to do) then 
initialize_var can be removed as well.


Swift SVN r11054
2013-12-10 00:00:37 +00:00
Chris Lattner
3c03c0b5e4 rework emitOptionalToRef to use an optional code sequence to get a null class
reference, eliminating the last thing that creates a SIL builtin zero.


Swift SVN r11051
2013-12-09 23:37:51 +00:00
Chris Lattner
39224db6a9 remove the ZeroValueExpr AST node.
Swift SVN r11048
2013-12-09 23:16:14 +00:00
Chris Lattner
51a5a3cd50 turn on DI for ObjC classes, resolving:
<rdar://problem/11937539> implement a definite initialization checker in swift

QoI and validating requirements on super.init (15579247) still remain.  This
also leaves a bunch of dead code in Sema, which I'll remove in a bit.


Swift SVN r11032
2013-12-09 17:48:07 +00:00
Joe Groff
e37897b57b SILGen: Always emit physical access to stored properties in 'init' and 'destructor', even for @objc stored properties.
This gives more predictable semantics for initializers and destructors under the DI model, and also unblocks enabling the DI model at all for @objc initializers. <rdar://problem/15614052>

Swift SVN r11029
2013-12-09 17:31:04 +00:00
Chris Lattner
375c92a4af Turn on DI for derived classes. Except for @objc classes, it now
ensures that all ivars in all cases are initialized before super.init
is called.

It is still not handling @objc classes, and still isn't enforcing that
super.init itself happens in the right places.  Also, the QoI could be
better


Swift SVN r11026
2013-12-09 16:44:22 +00:00
Chris Lattner
0aff0a2adc Turn on DI for init methods in root classes that are not marked ObjC.
We are inching towards DI world domination.



Swift SVN r11009
2013-12-09 06:05:01 +00:00