Commit Graph

430 Commits

Author SHA1 Message Date
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
Joe Groff
5d8a7ff9e7 Allow multiple comma-separated enum elements in a 'case' decl.
Introduce an EnumCaseDecl for source fidelity to track the 'case' location and ordering of EnumElementDecls. Parse a comma-separated list of EnumElementDecls after a 'case' token.

Swift SVN r8509
2013-09-20 19:51:13 +00:00
Dmitri Hrybenko
429633b18a Let the type checker create implicit DestructorDecls
Improve the type checker to create implicit DestructorDecls, tighten the
assertion in ImplicitReturnLocation::getImplicitReturnLoc(), and add a verifier
check that a class in a type checked AST always has exactly one destructor.

SILGen used to generate a destructor if the class does not have a
DestructorDecl.  SILGen used to put the ClassDecl inside the SILLocation for
the destructor SIL code.  This is not a very clean solution: in this case
ImplicitReturnLocation SILLocations contain ClassDecl, which is surprising.

rdar://14970972 Implicit destructors should have AST nodes


Swift SVN r8498
2013-09-20 17:34:22 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Anna Zaks
4d2444ab6a [SIL] Ensure that we mark the apply instructions within ObjC getters/setters
Swift SVN r8406
2013-09-18 17:30:53 +00:00
Doug Gregor
f7a2d5eed0 Emit Objective-C thunks for [objc] initializing constructors.
Now that all [objc] constructors have a suitable "init" selector, emit
an Objective-C thunk for the initializing constructor (not the
allocating constructor!) with that selector, and make sure it shows up
in the Objective-C metadata. 

With this, we can write a Swift constructor "constructor()" to
override "-init"; see the change to ListMaker that exercises this.

Joe or John: I'd love a review of these.



Swift SVN r8373
2013-09-18 00:30:54 +00:00
John McCall
6f32a8464f Add a convenient method to create a new basic block.
Swift SVN r8326
2013-09-17 07:22:23 +00:00
Dmitri Hrybenko
f2cc4cb303 Rename CapturingExpr -> AbstractClosureExpr
Swift SVN r8299
2013-09-16 21:58:44 +00:00
Chris Lattner
74bf9c98c6 change the CaptureInfo::getLocalCaptures() method to return a SmallVector
by reference, avoiding allocating heap memory.



Swift SVN r8275
2013-09-16 15:25:48 +00:00
Chris Lattner
de64743c83 DI for TLC seems to have stuck, remove the conditional logic it was hiding behind.
Swift SVN r8272
2013-09-16 14:28:25 +00:00
Dmitri Hrybenko
536ed954ad Remove FuncExpr. Add CaptureInfo to FuncDecl. Introduce AnyFunctionRef.
AnyFunctionRef is a universal function reference that can wrap all AST nodes
that represent functions and exposes a common interface to them.  Use it in two
places in SIL where CapturingExpr was used previously.

AnyFunctionRef allows further simplifications in other places, but these will
be done separately.


Swift SVN r8239
2013-09-14 02:15:48 +00:00
Dmitri Hrybenko
5ac875e5dc Add CaptureInfo class that manages capture lists
Swift SVN r8234
2013-09-14 00:22:44 +00:00
Chris Lattner
9c793e5b9a Add a new (temporary and hidden) commandline option: -enable-top-level-definite-init.
When enabled, this causes references to global variables in the 
top_level_code function to be emitted as:

  %0 = global_addr #x : $*Int64
  %1 = mark_uninitialized %0 : $*Int64

where all local uses of "x" use the %1 value.  This representation will
allow the definite initialization pass to know that "x" must be forced
to be initialized before the function returns or the value escapes (which
we don't have a representation for yet).



Swift SVN r8147
2013-09-12 05:32:39 +00:00
Chris Lattner
c3e2519bad When emitting the top-level-code function and processing pattern
binding decls for global variables, enter the global_addr into the
VarLocs mapping so that the global_addrs are CSE'd in the generated
SIL code.  For now, this simply reduces the size of the generated
SIL (by reducing some common subexpressions) with no other 
functionality change.



Swift SVN r8146
2013-09-12 05:18:13 +00:00
Dmitri Hrybenko
169a0a321e Remove a redundant parameter from SILGenModule::emitFunction()
Swift SVN r8134
2013-09-12 00:40:27 +00:00
Dmitri Hrybenko
e08eee270e Move some of SILGen for functions to use FuncDecl instead of FuncExpr
This changes most SILLocations to point to FuncDecls instead of FuncExprs,
thus SIL diagnostics had to be fixed up for this change.


Swift SVN r8132
2013-09-12 00:32:18 +00:00
Joe Groff
cc37187c53 SIL: Remove 'UncurryDirection' and uncurry all methods right-to-left.
ObjC methods are already tagged with a special calling convention and have special IRGen handling to keep the _cmd argument abstracted away from SIL. We can use the CC to also abstract away the detail that Swift methods pass 'self' last but ObjC methods pass 'self' first. This eliminates a weird special case from SIL's perspective, and also means that 'partial_apply' can work on objc methods correctly without becoming significantly more complex.

Swift SVN r8091
2013-09-11 17:05:44 +00:00
Anna Zaks
32e14dc63b [SIL] Add another missing location (for BBArguments).
Swift SVN r8084
2013-09-10 22:52:41 +00:00