Commit Graph

6749 Commits

Author SHA1 Message Date
Chris Lattner
27dd292ce4 this is the right check, the problem is that ctors don't have capture lists and aren't FuncDecls.
Swift SVN r8189
2013-09-13 05:00:14 +00:00
Chris Lattner
fe16d538cd In -enable-top-level-definite-init mode, emit a "mark_function_escape" instruction
for func decls that capture globals defined in the current file.  For example, for:

var x : Int

func foo() {
  print(x)
}

x = 15

We now silgen to:

sil internal @top_level_code : $() -> () {
bb0:
  %0 = global_addr #x : $*Int64                   // user: %1
  %1 = mark_uninitialized %0 : $*Int64            // users: %7, %2
  mark_function_escape %1 : $*Int64
  // function_ref swift.Int64._convertFromBuiltinIntegerLiteral (swift.Int64.metatype)(val : Builtin.Int128) -> swift.Int64
  %3 = function_ref @_TSi33_convertFromBuiltinIntegerLiteralfMSiFT3valBi128__Si : $[thin] ((val : Builtin.Int128), Int64.metatype) -> Int64 // user: %6
  %4 = metatype $Int64.metatype                   // user: %6
  %5 = integer_literal $Builtin.Int128, 15        // user: %6
  %6 = apply [transparent] %3(%5, %4) : $[thin] ((val : Builtin.Int128), Int64.metatype) -> Int64 // user: %7
  assign %6 to %1 : $*Int64
  %8 = tuple ()                                   // user: %9
  return %8 : $()
}

which will allow definite initialization to diagnose the error.

Note that we don't currently handle uses in constructors, like:

class frank {
  constructor() {
    print(x)
  }
}

... because the capture list is only stored for FuncDecls, not for AbstractFunction's.  It should be hoisted up at some point.




Swift SVN r8188
2013-09-13 04:59:20 +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
Dmitri Hrybenko
7da84fd13d Make FuncExpr, PipeClosureExpr and ClosureExpr DeclContexts on their own.
This is a first step to detach them from CapturingExpr and eventually move them
in the AST class hierarchy.


Swift SVN r8171
2013-09-12 23:58:06 +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
Dmitri Hrybenko
fcf8741318 Replace calls to FuncExpr::getType() with FuncDecl::getType()
Swift SVN r8162
2013-09-12 21:03:48 +00:00
Dmitri Hrybenko
c69c79084a Move result typeloc and body result type from FuncExpr to FuncDecl
Swift SVN r8153
2013-09-12 18:40:57 +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
Chris Lattner
0de24cd02c perform one hash table lookup instead of two.
Swift SVN r8145
2013-09-12 05:10:24 +00:00
Dmitri Hrybenko
c6ae53edf1 Don't call getFuncExpr() to create a SIL location with FuncExpr instead of FuncDecl
Seems like nothing cares about this being either way.


Swift SVN r8140
2013-09-12 01:27:40 +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
3aeb4814ad SILGen: Fix assertion failure when currying a natively ObjC method.
If a method comes from Clang, SILGen (correctly) asserts that we don't try to emit a reference to a native Swift entry point for it. Check for and handle this case in the lazy curry thunking logic.

Swift SVN r8128
2013-09-12 00:06:54 +00:00
Joe Groff
c07a6e3eac SILGen: Emit currying thunks lazily with thunk linkage.
Instead of eagerly emitting currying thunks as external symbols, emit them as needed and give them hidden ODR linkage. Partial function/method applications are probably a minority of usages, so this should reduce code volume overall. Also, for ObjC classes from the framework and for protocol methods, I don't think we want to eagerly emit thunks.

Swift SVN r8123
2013-09-11 23:47:19 +00:00
Joe Groff
705102b544 SIL: Rename 'ClangThunk' specifier to 'Thunk'.
Lazily-generated currying thunks will require the same IR-level linkonce_odr linkage as clang thunks currently do, so generalize the name of the existing SIL-level linkage specifier 'clang_thunk'.

Swift SVN r8122
2013-09-11 23:47:15 +00:00
Dmitri Hrybenko
11dbb0c95c SILGen: migrate some uses of FuncExpr to FuncDecl
Swift SVN r8115
2013-09-11 22:06:43 +00:00
Adrian Prantl
46f616938c Debug info: Emit mangled name for bound generic structs and classes.
Implements rdar://problem/14802271

Swift SVN r8095
2013-09-11 17:58:54 +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
Dmitri Hrybenko
3cc01cf7d6 Introduce AbstractFunctionDecl -- a base class for ConstructorDecl,
DestructorDecl, FuncDecl -- and move some of the common concepts and logic
into it

No functionality change.


Swift SVN r8090
2013-09-11 04:04:01 +00:00
Anna Zaks
39b7a43cc0 [SIL] Mark locations of implicit constructors/destructors as auto-generated.
(Also, renames getArtificialLocation -> getAutoGeneratedLocation).

Swift SVN r8085
2013-09-10 22:52:43 +00:00
Anna Zaks
32e14dc63b [SIL] Add another missing location (for BBArguments).
Swift SVN r8084
2013-09-10 22:52:41 +00:00
Anna Zaks
0236dc228f [SIL] Not all location types are valid on all instructions
We check that the expectations are met with the verifier.

Swift SVN r8083
2013-09-10 22:52:37 +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
cdf160ecbd Introduce and optimize for uniquely-referenced opaque values.
If an OpaqueValueExpr is only used in one place, mark it as such. SIL
generation will then elide the retain/release pair associated with
each reference to the opaque value, instead consuming the value at the
point of use.


Swift SVN r8072
2013-09-10 18:03:55 +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
Adrian Prantl
af562d1696 Debug info: name mangling for composite types containing Archetypes.
Among other things this enables mangled names for tuples.
This adds a pointer to the DeclContext to SILFunction and which is used
to provide the necessary context to the Mangler.
Fixes rdar://problem/14808764 and rdar://problem/14813658.

Swift SVN r8070
2013-09-10 17:04:33 +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
fba35a3421 [SIL] Move condbranch location from if/while/.. stmt to the condition
We should be able to get the parent when necessary after we add the parent map.

Swift SVN r8057
2013-09-09 22:34:07 +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
Joe Groff
fbc682442a SILGen: Emit curry thunks for generic functions.
SILGen learned how to forward archetypes for generic class constructors, and we can reuse this knowledge to finally implement curry thunks for generic functions.

Generic methods still pose a problem because we can't return a value of polymorphic type, so we'd need to hoist polymorphic parameters to the outermost uncurry level during SIL function type canonicalization even at uncurry level zero.

Swift SVN r8054
2013-09-09 21:58:59 +00:00
Doug Gregor
8c60d88f5a Provide DynamicMemberRefExpr with .Some(fn)/.None helper expressions.
These helper expressions will eventually be used by SILGen to help
package up the optional values. I expect that we'll eventually have
library builtins for this, so consider this a stop-gap until those
appear.

As part of this, make OpaqueValueExpr a bit more usable: it can now
persist in the AST as a placeholder, but its uses must be within AST
subtrees of some specific introduction point (similarly to how Clang's
OpaqueValueExpr works).


Swift SVN r8051
2013-09-09 19:58:51 +00:00
Dmitri Hrybenko
1e23c936e0 Rename FuncDecl::getBody() to FuncDecl::getFuncExpr()
ConstructorDecl::getBody() and DestructorDecl::getBody() return 'BraceStmt *'.
After changing the AST representation for functions, FuncDecl::getBody() will
return 'BraceStmt *' and FuncDecl::getFuncExpr() will be gone.


Swift SVN r8050
2013-09-09 19:57:27 +00:00
Joe Groff
485e1f4eb5 SILGen: Emit curry thunks for struct instance methods.
Struct instance methods don't need to capture any special dynamic dispatch behavior, so they can use the same codegen path as standalone curried functions. Fixes <rdar://problem/14687373>.

Swift SVN r8049
2013-09-09 19:01:42 +00:00
Chris Lattner
e48b3a4702 Rework how capture lists work in CaptureExpr: now we record
global variables used by functions in the capture list as well.

SILGen and other things that don't care about these (i.e., all 
current current clients) filter the list to get what they want.

This is needed for future definite init improvements, and unblocked
by Doug's patch in r8039 (thanks! :)

No functionality change.



Swift SVN r8045
2013-09-09 18:15:07 +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
Doug Gregor
4cfb77b52a Don't emit Objective-C thunks for protocol members.
For now, this simply ensures that we don't blow up in the mangler due
to our inability to mangle the names of protocol members.


Swift SVN r8036
2013-09-09 16:07:18 +00:00
Anna Zaks
cb43f56edb [SIL] Remove more dependancies on SILLocation(), specifically from debugging related code.
Swift SVN r8019
2013-09-06 23:57:30 +00:00
Anna Zaks
369a948248 [SIL] Minor auto-generated SILLocation API rename/refactor.
Swift SVN r8018
2013-09-06 23:57:27 +00:00
Anna Zaks
42f87d7725 [SIL] Represent module-level locations.
These are used for code that is usually associated with the enclosing decl such as epilog code and cleanups.

Swift SVN r8017
2013-09-06 23:57:25 +00:00
Anna Zaks
b6dba229fd [SIL] Remove another use of SILLocation()
Swift SVN r8016
2013-09-06 23:57:23 +00:00
Anna Zaks
1ba2554fb2 [SIL] Ensure that all loop branches have valid locations.
Also, change the location of "looping back to head" branch to point to the closing brace of the body, which is a more natural source location than the beginning of the enclosing loop statement.

Swift SVN r7989
2013-09-06 17:46:15 +00:00
Chris Lattner
9b53417e5f remove Initialization::defaultInitialize, which is dead now.
Swift SVN r7957
2013-09-05 20:41:57 +00:00
Chris Lattner
dea8213ef9 remove the -enable-definite-init command line option. Definite init
seems to have stuck.


Swift SVN r7956
2013-09-05 20:37:41 +00:00
John McCall
b9dea7f458 Remove the emitSemantic* methods from TypeLowering and
move the corresponding functionality into SILGen.

I've switched around 'assign' so that it's no longer a
semantic assignment --- that is, so that it expects a properly
lowered value as its operand, not an r-value of the semantic
type.  This actually simplifies quite a lot of code and removes
some ugly special-casing from MemoryPromotion.

Swift SVN r7942
2013-09-05 06:44:50 +00:00
John McCall
215ffa5381 Make SILGenFunction methods for stores as well.
Swift SVN r7941
2013-09-05 06:44:48 +00:00
John McCall
a26584584e Move some basic l-values and address operations into SILGenLValue.cpp.
Swift SVN r7940
2013-09-05 06:44:46 +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