Commit Graph

405 Commits

Author SHA1 Message Date
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
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
Doug Gregor
611a5cce4b Replace the library-defined postfix '!' with an expr-postfix production.
As with the monadic '?', we treat any left-bound '!' as a postfix
operator. Currently, it extracts the value of its optional
subexpression, failing at run-time if the optional is empty.


Swift SVN r8948
2013-10-06 23:09:58 +00:00
John McCall
97033996ba Rework optional intrinsic methods to work with RValues.
Swift SVN r8836
2013-10-02 05:48:29 +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
Dmitri Hrybenko
4a0c050d81 Store the standard library module name as ASTContext::StdlibModuleName
... instead of repeating it everywhere


Swift SVN r8792
2013-09-30 21:07:35 +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
0d33ff3f40 Teach SILGen to directly emit optional injection operations for dynamic lookup.
... rather than synthesizing expressions in the AST.


Swift SVN r8723
2013-09-27 14:12:33 +00:00
Doug Gregor
5a1a7c0f60 Fix emission of the index for a dynamic subscript.
SILGen the index of a dynamic subscript in its own context; it's
result doesn't go into the current initialization. As an added bonus, 
always evaluate the index, so that side effects occur predictable
regardless of whether the function is available.


Swift SVN r8718
2013-09-27 03:54:32 +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
Doug Gregor
3a72c7ff88 Use dynamic dispatch for [objc] properties and methods used in lvalues.
There are two major restrictions on this at the moment:
  1) It only applies to [objc] properties/subscripts (where we go
  through Objective-C dispatch). It still does static dispatch for
  non-[objc] properties/subscripts in classes.
  2) The Clang importer doesn't mark imported Objective-C properties
  and subscript operators as [objc], so this is useless in practice.



Swift SVN r8691
2013-09-26 14:13:19 +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
Joe Groff
3d4c1251f1 Rename 'byref' attribute to 'inout'.
Swift SVN r8661
2013-09-25 20:56:52 +00:00
Doug Gregor
b8daa3c68d SIL generation for dynamic subscript expressions.
Re-instates r8591 with rather more sensible generated SIL.


Swift SVN r8599
2013-09-24 20:08:19 +00:00
Doug Gregor
e3b50c207c Back out r8591; it's going to take me a bit longer to fix.
Swift SVN r8596
2013-09-24 18:56:09 +00:00
Doug Gregor
fdd5ebd342 SIL generation for dynamic subscript expressions.
No IRGen testing yet because the recently-introduced [objc] subscript
thunks (r8587) can't be IRGen'd properly yet.



Swift SVN r8593
2013-09-24 14:48:51 +00:00
Doug Gregor
f67aa78d69 Dynamic lookup for subscripts: semantic analysis and ASTs.
Swift SVN r8591
2013-09-24 05:51:30 +00:00
Joe Groff
014f270516 SIL: Have project_existential_ref project to a protocol Self archetype.
This mirrors the behavior of project_existential and simplifies some special cases in SILGen. It unfortunately makes dynamic_lookup sequences a bit noisier because of the need to explicitly cast the projection from DynamicLookup.Self to Builtin.ObjCPointer, but I think this modeling is more solid and will fit better with my planned redesign of archetype_method/protocol_method.

Swift SVN r8572
2013-09-23 21:57:12 +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
Doug Gregor
903a4d2ea1 Implement SILGen/IRGen support for dynamic lookup that resolves to properties.
Swift SVN r8521
2013-09-20 22:15:03 +00:00
Doug Gregor
bcf5345626 Eliminate the completely-broken implicit default constructor for classes.
When a given class definition has no constructors, the parser was
introducing an implicit-declared default constructor in the class. The
type checker ignored it. SILGen creating something that was completely
broken. Remove all of that and fix the fallout.




Swift SVN r8432
2013-09-18 23:58:34 +00:00
Doug Gregor
18f9420bcb Stop generating definitions for the imported initializing constructors.
When we import an Objective-C init method into Swift as a constructor,
the Clang importer currently synthesizes both a +alloc call (used by
the allocating constructor) and a body that forwards to the
corresponding init method. Eliminate the body and stop emitting an
initializing constructor at all: instead, the allocating constructor
will invoke the init method through objc_msgSend.



Swift SVN r8420
2013-09-18 21:35:38 +00:00
Doug Gregor
5515922d14 Don't force a dynamic member reference if there is no outer call.
Swift SVN r8313
2013-09-17 00:21:57 +00:00
Doug Gregor
f9ff9f290c SILGen: Handle non-forced dynamic lookup of class methods on metatype instances.
Swift SVN r8298
2013-09-16 21:28:03 +00:00
Doug Gregor
6af084a22f SILGen support for forced dynamic member lookups on DynamicLookup.metatype instances.
Swift SVN r8297
2013-09-16 21:17:04 +00:00
Anna Zaks
fe63b96109 [SIL] Provide a single source for determining a function transparency.
Makes sure the logic for determining if a function is transparent is shared
between the inliner and the SIL serializer.

Swift SVN r8173
2013-09-13 00:54:54 +00:00
Anna Zaks
9e887fc3c7 [SIL] Mark calls to implicitly generated union element constructors and default arg generators as transparent.
Swift SVN r8168
2013-09-12 22:45: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
Joe Groff
c7852b55c1 SILGen: Emit currying thunks for class methods.
In SILGenApply, if we have a partially-applied invocation of a class method, make a call to a currying thunk instead of trying to perform dynamic dispatch in-line. Emit the class dynamic dispatch instead as part of the currying thunk itself, and close over the dynamic method pointer as part of the curried closure context.

Swift SVN r8076
2013-09-10 18:59:15 +00:00
Doug Gregor
d04e9b7659 SILGen: Manage retain/release properly for dynamic member lookups.
Introduce a proper cleanup for the Optional<T> value created by
non-forced dynamic member lookups.

Additionally, properly manage each reference to an OpaqueValue within
an expression, and release the value when the RAII object goes out of
scope. This is the conservative approach to be optimized soon.


Swift SVN r8071
2013-09-10 17:40:51 +00:00
Doug Gregor
24f4706056 SIL: Introduce the dynamic_method_br instruction.
The dynamic_method_br instruction branches depending on whether a
particular object can accept a given message, as determined at
runtime. If the object can accept the message, it branches to the
first basic block, providing the uncurried method as the BB
argument. If the object cannot accept the message, it branches to the
second basic block. Either way, the result is packaged up into an
optional type and passed along to the continuation block, which
provides the optional result.

Note that this instruction is restricted to lookup of Objective-C
methods.

Documentation and IR generation (via -respondsToSelector) to
follow. Review greatly appreciated!



Swift SVN r8065
2013-09-09 23:46:10 +00:00
Anna Zaks
c06bd83358 [SIL] Remove the last few uses of SILLocation constructor.
This also removes the constructor itself, which forces future users of
SILLocation to construct a valid location.

Swift SVN r8056
2013-09-09 22:34:05 +00:00
Doug Gregor
c5557a624c SIL: Introduce the 'dynamic_method' instruction for dynamic method dispatch.
The dynamic_method instruction handles method lookup on an existential
of type DynamicLookup based on the selector of an [objc] method of a
class or protocol. It is only introduced in the narrow case where we
are forcing a use of the method with '!', e.g.,

class X {
  func [objc] f() { println("Dynamic lookup") }
}

var x : DynamicLookup = X()
x.f!()



Swift SVN r8037
2013-09-09 16:12:50 +00:00
John McCall
6aae6402ba Refactor in support of semantic vs. storage type differences.
Swift SVN r7939
2013-09-05 06:44:44 +00:00
Stephen Lin
b3c4dfa361 SILGenApply: minor local variable rename for consistency
Swift SVN r7928
2013-09-05 00:02:48 +00:00
Stephen Lin
5951c66b6c Allow [transparent] on curried functions, but only apply it to the fully uncurried call.
Swift SVN r7927
2013-09-05 00:02:46 +00:00
Anna Zaks
a1f21b20d7 [SIL] Add a location to destructive_switch_union_addr + a couple more.
Swift SVN r7926
2013-09-05 00:01:56 +00:00
Anna Zaks
115a15830b [SIL] Replace empty locations with valid locations in tuple exploding/encoding and pattern gen code.
Tuple exploding happens during RValue construction, so changed the constructor and addElement() method to take the location parameter. The imploding happens on RValue::forwardAsSingleValue and RValue::getAsSingleValue(). Make sure the right SIL locations are passed to all of these

Also, added some missing locations in pattern matching code.

Swift SVN r7916
2013-09-04 21:57:52 +00:00
Anna Zaks
2ea48d3d52 [SIL] Assign SIL location info for tuple initialization code.
Swift SVN r7915
2013-09-04 21:57:50 +00:00
Stephen Lin
d4f17ee840 Mark calls to [auto_closure] variables as [transparent]. Technically, we only want this to apply to parameters; however, I'm told that the plan on record is for [auto_closure] only to be allowed on parameters anyway and that the parser accepting local variable [auto_closures] is a bug, so I've implemented this assuming that will be fixed. This does not require [auto_closure] to be in the SIL type system; the [auto_closure] type information is pulled from the AST during lowering.
Note that this does not actually require the function containing the [auto_closure] parameter to be marked [transparent]. However, if the function is not marked [transparent], then the [transparent] flag on the application of the [auto_closure] will have no effect anyway because the callee of the function will not be visible, so there's no harm in putting the flag on without checking.

Swift SVN r7904
2013-09-04 17:53:40 +00:00
Doug Gregor
0dcca3aeda Eliminate CoerceExpr entirely.
Swift SVN r7876
2013-09-03 22:58:22 +00:00
John McCall
02ce2fe199 Make is_nonnull produce a primitive Builtin.Int1 instead
of Bool, and use swift._getBool to turn that into a Bool
as necessary.

Swift SVN r7720
2013-08-29 06:47:15 +00:00
Dmitri Hrybenko
1593632d7b More 'this' -> 'self' replacements
Swift SVN r7659
2013-08-28 03:08:07 +00:00
Dmitri Hrybenko
69cfa73640 More 'this' -> 'self' replacements
Swift SVN r7657
2013-08-28 02:57:21 +00:00
Ted Kremenek
8f5b8ccb02 Rename "This" to "Self" and "this" to "self".
This was not likely an error-free change.  Where you see problems
please correct them.  This went through a fairly tedious audit
before committing, but comments might have been changed incorrectly,
not changed at all, etc.

Swift SVN r7631
2013-08-27 21:58:27 +00:00
Michael Gottesman
d41b871b3a At Joe's suggestion added the prefix strong to instructions Retain,Release,RetainAutoreleased,RetainUnowned to prevent confusion in between RetainUnowned and UnownedRetain.
This is was a very mechanical patch where I basically first renamed SILNodes.def
and then just kept fixing things until everything compiled, so even though it is
large patch I feel ok(ish) with committing it.

If anyone has any concerns/etc, please email me and I will revert in 1 second.

Swift SVN r7604
2013-08-26 23:32:16 +00:00