Commit Graph

270 Commits

Author SHA1 Message Date
Joe Groff
e37897b57b SILGen: Always emit physical access to stored properties in 'init' and 'destructor', even for @objc stored properties.
This gives more predictable semantics for initializers and destructors under the DI model, and also unblocks enabling the DI model at all for @objc initializers. <rdar://problem/15614052>

Swift SVN r11029
2013-12-09 17:31:04 +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
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
Jordan Rose
417b5d3982 Merge TranslationUnit into Module, and eliminate the term "translation unit".
This completes the FileUnit refactoring. A module consists of multiple
FileUnits, which provide decls from various file-like sources. I say
"file-like" because the Builtin module is implemented with a single
BuiltinUnit, and imported Clang modules are just a single FileUnit source
within a module.

Most modules, therefore, contain a single file unit; only the main module
will contain multiple source files (and eventually partial AST files).

The term "translation unit" has been scrubbed from the project. To refer
to the context of declarations outside of any other declarations, use
"top-level" or "module scope". To refer to a .swift file or its DeclContext,
use "source file". To refer to a single unit of compilation, use "module",
since the model is that an entire module will be compiled with a single
driver call. (It will still be possible to compile a single source file
through the direct-to-frontend interface, but only in the context of the
whole module.)

Swift SVN r10837
2013-12-05 01:51:15 +00:00
Jordan Rose
be12d86ddd Turn ClangModule into ClangModuleUnit.
Part of the FileUnit restructuring. A Clang module (whether from a framework
or a simple collection of headers) is now imported as a TranslationUnit
containing a single ClangModuleUnit.

One wrinkle in all this is that Swift very much wants to do searches on a
per-module basis, but Clang can only do lookups across the entire
TranslationUnit. Unless and until we get a better way to deal with this,
we're stuck with an inefficiency here. Previously, we used to hack around
this by ignoring the "per-module" bit and only performing one lookup into
all Clang modules, but that's not actually correct with respect to visibility.

Now, we're just taking the filtering hit for looking up a particular name,
and caching the results when we look up everything (for code completion).
This isn't ideal, but it doesn't seem to be costing too much in performance,
at least not right now, and it means we can get visibility correct.

In the future, it might make sense to include a ClangModuleUnit alongside a
SerializedASTFile for adapter modules, rather than having two separate
modules with the same name. I haven't really thought through this yet, though.

Swift SVN r10834
2013-12-05 01:51:11 +00:00
Jordan Rose
8b8cc8ee62 Turn SerializedModule into SerializedASTFile.
Part of the FileUnit restructuring. A serialized module is now represented as
a TranslationUnit containing a single SerializedASTFile.

As part of this change, the FileUnit interface has been made virtual, rather
than switching on the Kind in every accessor. We think the operations
performed on files are sufficiently high-level that this shouldn't affect us.

A nice side effect of all this is that we now properly model the visibility
of modules imported into source files. Previously, we would always consider
the top-level imports of all files within a target, whether re-exported or
not.

We may still end up wanting to distinguish properties of a complete Swift
module file from a partial AST file, but we can do that within
SerializedModuleLoader.

Swift SVN r10832
2013-12-05 01:51:09 +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
Chris Lattner
5061ee57a8 stop emitting initialize_var instructions in enum constructors. This is
all we need to enable DI for enum constructors.  Structs and classes are
more complex, and the diagnostic produced is not great.  This resolves 
rdar://14922277.

Also, now an unreachable code diagnostic (with no source location) is 
produced when building the stdlib.  I'll investigate.


Swift SVN r10725
2013-12-02 17:35:38 +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
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
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
Joe Groff
6f519d7b6f SILGen: Emit enum constructors for Clang-imported enums.
Swift SVN r9990
2013-11-06 06:31:26 +00:00
Chris Lattner
68af974227 Remove 'axle' related code and build machinery. It turns out that we
will not be pursuing this project in the immediate future.



Swift SVN r9901
2013-11-03 16:04:27 +00:00
Joe Groff
003709d51f SIL: Add a backreference from SILModule to its originating Swift Module.
Ideally this wouldn't be necessary, but the type substitution APIs required by generic specialization and SIL verification currently require a Module* pointer, and it's obnoxious to have to pass it down separately everywhere it's needed. Longer-term the reliance on Modules for type substitution might be able to go away.

Swift SVN r9866
2013-11-01 00:46:21 +00:00
Jordan Rose
28e01f3c3a Eliminate "MainSourceFile" from TranslationUnit in favor of an array.
Anywhere that assumes a single input file per TU now has to do so explicitly.
Parsing still puts all files in a single SourceFile instance; that's next on
the list.

There are a lot of issues still to go, but the design is now in place.

Swift SVN r9669
2013-10-25 17:30:37 +00:00
Joe Groff
3a5267c020 SILGen: Build a thunk in SILGen instead of using convert_cc instruction.
We already know how to call external functions in SILGen, why reimplement all that in IRGen? Instead of representing the thunk operation as a SIL instruction, let's just emit the thunk using existing SILGen machinery. Fixes <rdar://problem/14097136>.

Swift SVN r9576
2013-10-22 03:16:15 +00:00
Jordan Rose
5ed38c0b72 Clarify SourceFile vs. TranslationUnit interfaces for SILGen and IRGen.
Once we have multiple SourceFiles in a TranslationUnit, it no longer makes
sense to say "only SILGen decls starting from element N" without specifying
which source file you mean.

Also, clarify ownership by having performSILGeneration return a unique_ptr
instead of just a bare pointer.

Swift SVN r9112
2013-10-09 23:44:43 +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
Jordan Rose
597640a5d2 Introduce "SourceFile" within a TranslationUnit.
Right now this is just an extra layer of indirection for the decls,
operators, and imports in a TU, but it's the first step towards compiling
multiple source files at once without pretending they're all in a single
file. This is important for the "implicit visibility" feature, where
declarations from other source files in the same module are accessible
from the file currently being compiled.

Swift SVN r9072
2013-10-09 18:38:15 +00:00
John Garvin
a1badb1777 Add kernel/shader data to SILFunction.
Swift SVN r9047
2013-10-09 01:11:20 +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
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
Anna Zaks
59175bdc08 [SIL] Remove TranslationUnit pointer from SILModule.
This reverts r8624 and compensates by passing the TU to the SILModule printer when needed.

This addresses concerns that Jordan and Sean had raised.

Swift SVN r8678
2013-09-25 23:52:04 +00:00
Joe Groff
3d4c1251f1 Rename 'byref' attribute to 'inout'.
Swift SVN r8661
2013-09-25 20:56:52 +00:00
Jordan Rose
15bfc8db2b Don't type-check imported decls unless referenced in the source file.
Instead, pass a LazyResolver down through name lookup, and type-check
things on demand. Most of the churn here is simply passing that extra
LazyResolver parameter through.

This doesn't actually work yet; the later commits will fix this.

Swift SVN r8643
2013-09-25 20:08:14 +00:00
Anna Zaks
4c61550b20 [SIL] Use TranslationUnit instead of ASTContext when creating a SILModule.
TU contains Decls that will need to be serialized when we print the SILModule.

Swift SVN r8626
2013-09-25 17:08:40 +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
Argyrios Kyrtzidis
eecb56a9ad Move the Mangler from the SIL library to the AST one.
No other functionality change.

Swift SVN r8527
2013-09-20 23:10:58 +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
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
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
Doug Gregor
90b8b3e499 Constructor selectors always start with 'init'.
Implement the new rules for mapping between selector names and
constructors. The selector for a given constructor is formed by
looking at the names of the constructor parameters:
  * For the first parameter, prepend "init" to the parameter name and
  uppercase the first letter of the parameter name. Append ':' if
  there are > 1 parameters or the parameter has non-empty-tuple type.
  * For the remaining parameters, the name of each parameter followed
  by ':'.

When a parameter doesn't exist, assume that the parameter name is the
empty string.

And, because I failed to commit it separately, support selector-style
declarations of constructor parameters so that we can actually write
constructors nicely, e.g.:

  // selector is initWithFoo:bar:
  constructor withFoo(foo : Foo) bar(bar : Bar) { ... }



Swift SVN r8361
2013-09-17 22:49:05 +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
f1f189f4e0 Rename PipeClosureExpr -> ClosureExpr
Swift SVN r8321
2013-09-17 01:37:36 +00:00
Dmitri Hrybenko
b18c38a322 Rename ImplicitClosureExpr -> AutoClosureExpr
Swift SVN r8304
2013-09-16 23:03:50 +00:00
Dmitri Hrybenko
e7af4d6c72 Collapse ImplicitClosureExpr into its abstract base class, ClosureExpr
Swift SVN r8280
2013-09-16 18:31:05 +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
Chris Lattner
e2436e1429 enhance SILGen to emit mark_function_escape instructions for
ctors and dtors, allowing definite init to reason about them.


Swift SVN r8243
2013-09-14 04:32:45 +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
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
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
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
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