Commit Graph

405 Commits

Author SHA1 Message Date
Dave Zarzycki
31d3c37141 Revert r11855: "simplify some code, managed value does the right thing for us here."
This was causing the tests to spin forever.

Swift SVN r11864
2014-01-03 19:37:44 +00:00
Chris Lattner
5b394f67f3 sink SILDeclRef's down into emitGetAccessor/emitSetAccessor, which are
the things that apparently care about it.  The LValue/RValue machinery is 
happy to pass around the VarDecl/SubscriptDecl for the entity being
referenced, and this simplifies things.


Swift SVN r11857
2014-01-03 07:19:40 +00:00
Chris Lattner
d40295fccd simplify some code, managed value does the right thing for us here.
Swift SVN r11855
2014-01-03 06:38:27 +00:00
Chris Lattner
7d9ae2f418 Use the power of ManagedValue to pass along +1 ownership of the base
receiver until something consumes it.  This means that something with
writeback (which invokes both the getter and setter) needs to copy the
managed value (since two things consume the +1), but that's what
ManagedValue is for.

Upshot of this is that we stop emitting redundant retain/release calls
in cases where writeback isn't needed.  For example:

class Foo {
  var x : Int { get: set: }
}

func test(let f : Foo, let i : Int) {
  f.x = i
}

used to silgen to:

sil @_TF1t4testFTCS_3FooSi_T_ : $@thin (@owned Foo, Int64) -> () {
bb0(%0 : $Foo, %1 : $Int64):
  strong_retain %0 : $Foo                         // id: %2
  strong_retain %0 : $Foo                         // id: %3
  // function_ref t.Foo.x.setter : swift.Int64
  %4 = function_ref @_TFC1t3Foos1xSi : $@cc(method) @thin (Int64, @owned Foo) -> () // user: %5
  %5 = apply %4(%1, %0) : $@cc(method) @thin (Int64, @owned Foo) -> ()
  strong_release %0 : $Foo                        // id: %6
  strong_release %0 : $Foo                        // id: %7
  %8 = tuple ()                                   // user: %9
  return %8 : $()                                 // id: %9
}

now it silgen's to:

sil @_TF1t4testFT1fCS_3Foo1iSi_T_ : $@thin (@owned Foo, Int64) -> () {
bb0(%0 : $Foo, %1 : $Int64):
  strong_retain %0 : $Foo                         // id: %2
  // function_ref t.Foo.x.setter : swift.Int64
  %3 = function_ref @_TFC1t3Foos1xSi : $@cc(method) @thin (Int64, @owned Foo) -> () // user: %4
  %4 = apply %3(%1, %0) : $@cc(method) @thin (Int64, @owned Foo) -> ()
  strong_release %0 : $Foo                        // id: %5
  %6 = tuple ()                                   // user: %7
  return %6 : $()                                 // id: %7
}

When writeback is needed, we still emit the two retains (balanced with the
get and set calls).




Swift SVN r11854
2014-01-03 06:34:27 +00:00
Chris Lattner
10ab56c140 mechanical transition of lvalue emission logic from trafficing in SILValue's
to trafficing in ManagedValues.  No functionality change (yet), we just needed
more management in the mix.


Swift SVN r11851
2014-01-03 05:40:30 +00:00
Chris Lattner
45b78bdf50 rework SILGenFunction::prepareAccessorBaseArg to work with any base type:
it either passes the base as inout or as a +1 rvalue (e.g. references),
metatype bases as a degenerate case.



Swift SVN r11840
2014-01-03 00:58:21 +00:00
Chris Lattner
8f06ca3f2f remove the dead 'resultType' argument from emitGetAccessor.
Swift SVN r11806
2014-01-02 00:51:15 +00:00
Chris Lattner
7e8a382ac2 Rework @inout handling in SILGen. Now @inout is emitted as an rvalue,
not as part of the lvalue path.  This means that the arguments to a 
function (for example) are always rvalues - @inout arguments are not a
special case all over the place.

This removes emitLValueOrRValueAsRValue and emitLValueAsRValue, because
the lvalue that both of them were trying to handle was @inout, not @lvalue.



Swift SVN r11805
2014-01-02 00:49:10 +00:00
Chris Lattner
c73bfe2530 rework sema and silgen of SuperRefExpr. The most notable change is that it
is no longer an lvalue, since it doesn't make sense to assign to super.

This eliminates a bunch of special cases and simplifies things.



Swift SVN r11803
2014-01-01 22:51:10 +00:00
Chris Lattner
859883d88e further detangle @lvalue and @inout. types, this time in libsil.
Swift SVN r11800
2014-01-01 20:46:54 +00:00
Chris Lattner
fafab67216 fix a crash in SILGen when calling through a 'let' vardecl, which was
because let vardecls can't be turned into SILDeclRef constant references.


Swift SVN r11734
2013-12-30 07:17:57 +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
d3c91387e9 Substantially simplify the API to LValueType now that nonsettable is gone.
Swift SVN r11703
2013-12-28 22:48:44 +00:00
Chris Lattner
f99492202f Make some fairly major internal changes to our value system: now, get-only
properties are represented as rvalues, not non-mutable lvalues.  As part of
this, isReferencedAsLValue() only returns true for mutable VarDecls.

This required some pretty serious rearrangement and refactoring of code,
because now (among other things) get-only properties can be emitted as rvalues,
so the rvalue machinery needs to be able to produce getter calls.

This is an important step towards getting proper value semantics going (for
'let's etc) and also allows us to materialize addresses less often.  As a
simple example, before we would silgen this:

struct S {
  var i : Int
}
var P : S { get: ... }
func f() {
  print(P.i)
}

into:

 %2 = function_ref @_TF1tg1PVS_1S : $@thin () -> S // user: %3
  %3 = apply %2() : $@thin () -> S                // user: %5
  %4 = alloc_stack $S                             // users: %9, %6, %5
  store %3 to %4#1 : $*S                          // id: %5
  %6 = struct_element_addr %4#1 : $*S, #i         // user: %7
  %7 = load %6 : $*Int64                          // user: %8

now we generate:

  %2 = function_ref @_TF1tg1PVS_1S : $@thin () -> S // user: %3
  %3 = apply %2() : $@thin () -> S                // user: %4
  %4 = struct_extract %3 : $S, #i                 // user: %5



Swift SVN r11632
2013-12-25 17:43:10 +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
ee71669a52 IRGen: Handle @objc protocols in the -emit-sil-protocol-witness-tables regime.
These still can't ever take any extra polymorphic params without breaking the calling convention, so protocol_method still needs to produce a thin value in SIL, and we have to ensure we don't add any extra polymorphic params in the IR signature.

Swift SVN r11594
2013-12-23 03:57:38 +00:00
Joe Groff
65f45d69ab SILGen: Only apply the primary archetype substitutions to an archetype_method.
This matches what SIL expects for generic function applications. Add a 'getPrimarySubstitutions' convenience method to ConcreteDeclRef.

Swift SVN r11579
2013-12-22 23:20:35 +00:00
Chris Lattner
bc2fa50271 Start driving a stronger wedge between lvalue and rvalues, by making RValueEmitter
only handle rvalues.  Clients that can either have an lvalue or an rvalue (which 
are few, and will be diminishing as other planned changes happen like the tuple
vs argument split) use a specific api to indicate such.


Swift SVN r11572
2013-12-22 20:34:25 +00:00
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
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
Joe Groff
017440165e Fix the weird capitalization of MetaTypeType.
Swift SVN r11475
2013-12-19 18:43:08 +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
dec95a6890 At Joe's request, rename CaptureKind::Constant ->
CaptureKind::LocalFunction, and LocalConstants -> LocalFunctions


Swift SVN r10965
2013-12-07 01:25:30 +00:00
Joe Groff
27d96bbdc9 SIL: Generalize archetype_method to accept concrete types.
Allow archetype_method to look up a witness from a concrete ProtocolConformance record. This will allow generic specialization to apply to constrained generic functions independent of archetype_method devirtualization. <rdar://problem/14748543>

Swift SVN r10950
2013-12-07 00:00:51 +00:00
Chris Lattner
5c8e9bc070 split SILGenFunction & SGFContext out to a new header, to trim down SILGen.h
to being global stuff.


Swift SVN r10926
2013-12-06 18:40:20 +00:00
Joe Groff
0ff977d407 Add a 'WitnessMethod' enumerator to AbstractCC.
We'll use this to represent the slightly-different polymorphic calling convention used for passing Self into protocol witnesses.

Swift SVN r10898
2013-12-06 01:32:35 +00:00
Jordan Rose
eede5ec4f9 Begin refactoring for mixed file kinds within a single module.
The goal of this series of commits is to allow the main module to consist
of both source files and AST files, where the AST files represent files
that were already built and don't need to be rebuilt, or of Swift source
files and imported Clang headers that share a module (because they are in
the same target).

Currently modules are divided into different kinds, and that defines how
decls are looked up, how imports are managed, etc. In order to achieve the
goal above, that polymorphism should be pushed down to the individual units
within a module, so that instead of TranslationUnit, BuiltinModule,
SerializedModule, and ClangModule, we have SourceFile, BuiltinUnit,
SerializedFile, and ClangUnit. (Better names welcome.) At that point we can
hopefully collapse TranslationUnit into Module and make Module non-polymorphic.

This commit makes SourceFile the subclass of an abstract FileUnit, and
makes TranslationUnit hold an array of FileUnits instead of SourceFiles.
To demonstrate that this is actually working, the Builtin module has also
been converted to FileUnit: it is now a TranslationUnit containing a single
BuiltinUnit.

Swift SVN r10830
2013-12-05 01:51:03 +00:00
Dave Zarzycki
8bd3582d3e 15242776 stdlib: rename Slice to Array
The "HArray" name is temporary.

Swift SVN r10707
2013-12-01 08:16:30 +00:00
Chris Lattner
3b954ed44d strength reduce SILGenModule::getBuiltinInfo/getIntrinsicInfo to
take an identifier instead of a FuncDecl.


Swift SVN r10692
2013-11-30 00:57:46 +00:00
Adrian Prantl
b3606333b5 Fix a compile error in release mode.
Swift SVN r10579
2013-11-20 03:38:19 +00:00
John McCall
61360de731 Reabstract scalar arguments correctly in normal argument
emission.

Swift SVN r10572
2013-11-20 00:43:48 +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
e75ca8bef3 AST: Improve modeling of static property references.
Instead of cutting corners by emitting a static property reference as a DeclRef, do the right thing and build a MemberRef on the metatype. Add the smarts to SILGen to recognize static property MemberRefs and emit global_addr instructions for (nongeneric, nondynamic) static properties.

Swift SVN r10482
2013-11-15 01:00:44 +00:00
John McCall
08171453da Make it a bit easier to propogate expressions around instead
of having to lower to an RValue.

This is valuable because we can often emit an expression to a
desired abstraction level more efficiently than just emitting
it to minimal abstraction and then generalizing.

Swift SVN r10455
2013-11-14 05:25:06 +00:00
Joe Groff
0eaea169d0 SILGen: Handle computed static properties.
Produce a metatype value to feed the 'self' argument of the accessor.

Swift SVN r10419
2013-11-13 16:45:42 +00:00
Doug Gregor
50cb22b6da Teach Builtin.castToObjectPointer to handle class-bounded existentials.
Fixes <rdar://problem/15258208>.


Swift SVN r10397
2013-11-13 00:35:02 +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
Doug Gregor
d79b1758c1 Add getter/setter type computations to VarDecl and SubscriptDecl.
Use the getter type computation for dynamic subscript references so
that we can handle optional subscripts in protocols properly.


Swift SVN r9975
2013-11-05 23:31:13 +00:00
Doug Gregor
82184a60b9 s/addSubstitutions/setSubstitutions
Swift SVN r9723
2013-10-28 20:37:13 +00:00
Doug Gregor
55bcdedd5d Replace substitutions vector with an ArrayRef, now that we have only one level.
Swift SVN r9722
2013-10-28 20:35:25 +00:00
Doug Gregor
112c6123eb Terminate SpecializeExpr with extreme prejudice.
There are numerous other cleanups that could be performed now that
this is gone; I'll follow up with some of them.


Swift SVN r9717
2013-10-28 18:50:29 +00:00
Doug Gregor
731fe651e7 Teach OtherConstructorDeclRefExpr to track substitutions.
Eliminates another source of SpecializeExprs.


Swift SVN r9714
2013-10-28 18:35:49 +00:00
Doug Gregor
8ea71f06a7 Teach ExistentialMemberRefExpr to handle all levels of substitutions.
Another SpecializeExpr usage bites the dust.


Swift SVN r9665
2013-10-25 00:02:36 +00:00
Doug Gregor
10164fa56c Teach ArchetypeMemberRefExpr to handle all levels of substitutions.
Eliminates another source of SpecializeExprs.


Swift SVN r9655
2013-10-24 21:44:45 +00:00
Dmitri Hrybenko
80d753d0ab Portability: use std::make_tuple instead of relying on a libc++ extension (an
implicit constructor in std::tuple)


Swift SVN r9615
2013-10-23 06:17:28 +00:00
Doug Gregor
905078a278 Open method references via the interface type rather than the polymorphic type.
Once we've opened method references via the interface type, we then
fold all levels of generic argument specialization into the
DeclRefExpr, rather than using SpecializeExpr. For reference, the call
to x.f in this example:

struct X<T> {
  func f<U>(u : U) { }
}

func honk(x: X<Int>) {
  x.f("hello")
}

goes from this double-specialized AST:

        (specialize_expr implicit type='(u: String) -> ()'
          (with U = String)
          (dot_syntax_call_expr type='<U> (u: U) -> ()'
            (specialize_expr implicit 
               type='(@inout X<Int>) -> <U> (u: U) -> ()'
              (with T = Int)
              (declref_expr type='<T> @inout X<T> -> <U> (u: U) -> ()'
        decl=t.X.f@t.swift:2:8 specialized=no))

to the cleaner, SpecalizeExpr-free:

        (dot_syntax_call_expr type='(u: String) -> ()'
          (declref_expr type='(@inout X<Int>) -> (u: String) -> ()'
            decl=t.X.f@t.swift:2:8 [with T=Int, U=String]
            specialized=no)

which handles substitutions at both levels together. The minor SILGen
tweak 

Note that there are numerous other places where we are still generated
SpecializeExprs.


Swift SVN r9614
2013-10-23 05:35:16 +00:00
Joe Groff
db5fe95abb AST: Add a Builtin.condfail function.
Lowered by SILGen into a cond_fail instruction.

Swift SVN r9591
2013-10-22 15:53:11 +00:00
Doug Gregor
5521b53382 Use DeclRefExpr's substitutions rather than SpecializeExpr for free functions.
Rather than wrapping a DeclRefExpr in a SpecializeExpr for a reference
to a generic free function, just use the substitutions stored within
the DeclRefEXpr. Such DeclRefExprs will always have a concrete
type. One tiny nail in the SpecializeExpr coffin.


Swift SVN r9539
2013-10-21 15:39:56 +00:00
Doug Gregor
f5c6ea1c8e Use requiresObjCDispatch() rather than Decl::isObjC() for accessor callees.
Noticed by inspection.


Swift SVN r9496
2013-10-18 21:20:05 +00:00