Commit Graph

747 Commits

Author SHA1 Message Date
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
Doug Gregor
eb7ce396db Use VarDecl::get[GS]etterType() and SubscriptDecl::get[GS]etterType() in SILGen
Eliminate SILGen's own computation of getter/setter types in favor of
the AST methods to compute the same.


Swift SVN r9992
2013-11-06 06:53:13 +00:00
Joe Groff
6f519d7b6f SILGen: Emit enum constructors for Clang-imported enums.
Swift SVN r9990
2013-11-06 06:31:26 +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
c57ea38b95 SILGen: Don't produce context arguments for captured typealiases.
If a local function tried to reference a local typealias, we were trying to emit a SIL variable reference and freaking out, causing <rdar://problem/15360605>. For now, don't emit any capture arguments for local typealiases. Any context a local typealias requires should be handled by capturing the external context's generic parameters.

Swift SVN r9865
2013-11-01 00:12:29 +00:00
Joe Groff
5ec3cad5f6 ClangImporter: Emit metadata for imported enums.
Whatever kind of Swift decl we cons up for a Clang enum, add it to the externals list so we can pick it up and emit Swift metadata for it in IRGen. Fixes <rdar://problem/15242452>.

Swift SVN r9801
2013-10-30 18:15:09 +00:00
Chris Lattner
cff509767f fix 80 column violations
Swift SVN r9704
2013-10-28 00:36:23 +00:00
Chris Lattner
5ce1700021 - Mark the copyaddr's generated for inout shadow variables as autogenerated,
so they can be easily identified by the inout deshadowing pass.  This does
  not mark the alloc_box as autogenerated though, since it is a user variable
  when the variable escapes.

- Fix some wonky indentation in SILLocation.



Swift SVN r9700
2013-10-27 22:48:05 +00:00
Adrian Prantl
5bbe0afb9f Debug info: Properly handle the function prologue in the line table.
Introduces a new flag in SILLocation: InPrologue to mark instructions
that setup the stack and allocate storage for local variables/arguments.

Fixes rdar://problem/15290023: Breakpoint set on prologue - crash ensues.

Swift SVN r9686
2013-10-26 00:12:20 +00:00
John McCall
8fbc790d39 Subsume OwnershipConventions into SILFunctionType.
Swift SVN r9186
2013-10-11 00:50:57 +00:00
John McCall
b880e60100 Remove SILFunctionTypeInfo in favor of SILFunctionType.
We still don't actually use this as a type, however.

Swift SVN r9091
2013-10-09 20:55:55 +00:00
John McCall
dcf9d15cc7 Rewrite SILFunctionTypeInfo in terms of SILFunctionType.
Swift SVN r9090
2013-10-09 20:55:46 +00:00
Doug Gregor
a012f60633 Make protocol methods generic over <Self>.
Pull the implicit 'Self' associated type out of the protocol and into
an implicitly-declared generic parameter list for the protocol. This
makes all of the methods of a protocol polymorphic, e.g., given

  protocol P {
    typealias Assoc
    func getAssoc() -> Assoc
  }

the type of P.getAssoc is:

  <Self : P> (self : @inout P) -> () -> Self.Assoc

This directly expresses the notion that protocol methods are
polymorphic, even though 'Self' is always implicitly bound. It can be
used to simplify IRgen and some parts of the type checker, as well as
laying more of the groundwork for default definitions within
protocols as well as sundry other improvements to the generics
system.

There are a number of moving parts that needed to be updated in tandem
for this. In no particular order:
  - Protocols always get an implicit generic parameter list, with a
  single generic parameter 'Self' that conforms to the protocol itself.
  - The 'Self' archetype type now knows which protocol it is
  associated with (since we can no longer point it at the Self
  associated type declaration).
  - Protocol methods now get interface types (i.e., canonicalizable
  dependent function types).
  - The "all archetypes" list for a polymorphic function type does not
  include the Self archetype nor its nested types, because they are
  handled implicitly. This avoids the need to rework IRGen's handling
  of archetypes for now.
  - When (de-)serializing a XREF for a function type that has an
  interface type, use the canonicalized interface type, which can be
  meaningfully compared during deserialization (unlike the
  PolymorphicFunctionType we'd otherwise be dealing with).
  - Added a SIL-specific type attribute @sil_self, which extracts the
  'Self' archetype of a protocol, because we can no longer refer to
  the associated type "P.Self". 




Swift SVN r9066
2013-10-09 17:27:58 +00:00
Joe Groff
0bda31c02b Switch over to Generator as the 'for' loop protocol.
Rewrite ForEachStmt SILGen to use the Optional intrinsics with the Generator.next method to iterate through sequences, and kill off the Enumerator path in Sema. Cut over 'EnumeratorType.Element' requirements to instead require 'GeneratorType.Element' in the stdlib.

There are a couple of bugs remaining that need follow-up work. There appears to be a bug in nested enum layout (e.g. T??) that's causing test/Interpreter/enum to break; I'll investigate and fix. There's also a lingering type-checker bug with inferred associated types that causes them to fail requirement checks <rdar://problem/15172101>, which I think Doug needs to look into.

Swift SVN r9017
2013-10-08 01:46:51 +00:00
Joe Groff
7fc2720826 SILGen: Replace uses of TypeLowering::emitCopyInto with CopyAddrInsts.
Chris and I want to move toward canonicalizing on more abstract aggregate operations (copy_addr) instead of on the component load/store/copy|destroy_value/retain|release operations, which is easier for early passes like inout deshadowing, NRVO, and move optimization to reason about. As a first step, replace the handful of places where SILGen currently used TypeLowering::emitCopyInto with simple CopyAddrInst insertions. This affects inout initializations and emitSemanticLoadInto, neither of which should disturb early passes that relied on the old behavior.

Swift SVN r8991
2013-10-07 21:17:48 +00:00
Chris Lattner
607114f6c6 Introduce a new "emitDestroyAddr" function, which attempts to fold destroy_addr into
preceding copy_addr instruction when totally trivial.  Adopt this in SILGen, eliminating
a couple dozen destroy_addr instructions from the stdlib and producing more canonical SIL.


Swift SVN r8968
2013-10-07 17:47:17 +00:00
Joe Groff
aca3bd52ac SILGen: Build SILVTables while visiting classes.
When we walk a ClassDecl, generate its vtable, first pulling in decls from its ancestor classes, then overlaying overridden or new decls as we discover them.

Swift SVN r8947
2013-10-06 01:02:14 +00:00
Adrian Prantl
8808d48578 Debug info: emit captured variables in closures. rdar://problem/15035486
Swift SVN r8859
2013-10-02 22:46:03 +00:00
John McCall
298577676e Introduce the monadic ? operator.
A ? operator is interpreted as this if it's left-bound,
so ternary operators now have to be spaced on the left.

Swift SVN r8832
2013-10-02 01:27:45 +00:00
John McCall
a1867380d0 Distinguish the "cleanup handle" and "scope" use-cases
of CleanupsDepth.

Only with different typedefs for now, but the communicative
effect is significant.

Swift SVN r8831
2013-10-02 01:27:41 +00:00
John McCall
916b566fa6 Push and invalidate uninitialized-local cleanups.
No effect currently; just resolves a FIXME.

Swift SVN r8830
2013-10-02 01:27:39 +00:00
Joe Groff
82a18333ed SIL: Purge SpecializeInst.
Make ApplyInst and PartialApplyInst directly take substitutions for generic functions instead of trying to stage out substitutions separately. The legacy reasons for doing this are gone.

Swift SVN r8747
2013-09-28 00:15:45 +00:00
Doug Gregor
1e95e4e8f5 Emit Objective-C entry points for initializers defined within class extensions.
Swift SVN r8743
2013-09-27 22:17:33 +00:00
Jordan Rose
626479fbd9 s/property/accessor/ in SILGen and TypeLowering
Several places in SILGen and TypeLowering were using "property" to mean
"accessor" (for both variables and subscripts).

Swift SVN r8702
2013-09-26 21:53:03 +00:00
Jordan Rose
e05c03d5bc Standardize terminology for "computed", "stored", "variable", and "property".
These are the terms sent out in the proposal last week and described in
StoredAndComputedVariables.rst.

variable
  anything declared with 'var'
member variable
  a variable inside a nominal type (may be an instance variable or not)
property
  another term for "member variable"
computed variable
  a variable with a custom getter or setter
stored variable
  a variable with backing storage; any non-computed variable

These terms pre-exist in SIL and IRGen, so I only attempted to solidify
their definitions. Other than the use of "field" for "tuple element",
none of these should be exposed to users.

field
  a tuple element, or
  the underlying storage for a stored variable in a struct or class
physical
  describes an entity whose value can be accessed directly
logical
  describes an entity whose value must be accessed through some accessor

Swift SVN r8698
2013-09-26 18:50:44 +00:00
Joe Groff
cbfe3710f6 SIL: Rename the 'isObjC' SILDeclRef specifier to 'isForeign'.
Doug pointed out that 'isObjC' incorrectly excludes C functions, for which we'll also need to be able to independently reference Swift and foreign entries.

Swift SVN r8669
2013-09-25 21:59:03 +00:00
Doug Gregor
40eba067b2 Limit the "requires Objective-C dispatch" predicate's use of hasClangNode().
Swift SVN r8667
2013-09-25 21:28:19 +00:00
Joe Groff
3d4c1251f1 Rename 'byref' attribute to 'inout'.
Swift SVN r8661
2013-09-25 20:56:52 +00:00
Joe Groff
8f585557ca SIL: Fully capture byref shadow copy boxes.
Remove 'Byref' as a separate CaptureKind, and always capture the full box for all variables.

Swift SVN r8633
2013-09-25 18:41:50 +00:00
Joe Groff
d69eb660a6 SILGen: Emit shadow copies of byref arguments.
Create a local box for byref arguments that can be closed over. The box receives the value of the byref at function entry, and the value in the box at function exit is written back to the byref. This will allow us to eliminate the no-capture restriction on byrefs, allowing them to be used in auto closures and other HOFs, and doing the right thing in the 99% case where closures are effectively nocapture without requiring user annotation. <rdar://problem/14732389>

There are a couple of loose ends:

- The type-checker can lose its restriction on byref captures. I'll do that next.
- Debug info needs to learn how to represent local byref boxes. Adrian is better qualified to decide how to do that.
- Byref shadow copies completely defeat the copy-on-write optimization for String, making append sequences ridiculously slow. Memory promotion needs to learn to eliminate shadow copies completely when it promotes away byref boxes in order to solve this regression.

Swift SVN r8630
2013-09-25 17:19:00 +00:00
Doug Gregor
6a1db609e0 Allow [objc] subscripts and emit Objective-C thunks for the getters/setters.
Sema and SILGen; IRGen to follow.


Swift SVN r8589
2013-09-24 02:26:23 +00:00
John McCall
22a3574654 Use copy_value and destroy_value when destroying loadable
aggregates in SIL-gen.  Leave the old expanded paths around
as emitLoweredCopyValue and emitLoweredDestroyValue.

Swift SVN r8535
2013-09-20 23:33:40 +00:00