Commit Graph

304 Commits

Author SHA1 Message Date
Dmitri Hrybenko
e50b52fa02 Serializer/Driver: serialize comments to separate .swiftdoc files
The driver infers the filename from the module file by replacing the extension,
and passes the explicit path to the swiftdoc file to the frontend.  But there
is no option in the driver to control emission of swiftdoc (it is always
emitted, and name is always inferred from the swiftmodule name).

The swiftdoc file consists of a single table that maps USRs to {brief comment,
raw comment}.  In order to look up a comment for decl we generate the USR
first.  We hope that the performance hit will not be that bad, because most
declarations come from Clang.  The advantage of this design is that the
swiftdoc file is not locked to the swiftmodule file, and can be updated,
replaced, and even localized.


Swift SVN r14914
2014-03-11 10:42:26 +00:00
Sean Callanan
3b95376949 Added a new AST transformation pass called the
"Playground Transform."  This is an
instrumentation pass that adds calls to a
function called playground_log at locations of
interest.  Roughly speaking, these locations are

- Initialization of variables
- Modification of variables
- Expressions returning values
- Application of mutating methods on objects

The playground transform currently only finds
modifications of variables, but the intent is to
make all of these cases work.

It is enabled by a frontend option, and can
also be invoked by calling

swift::performPlaygroundTransform(SF)

which is the way LLDB, its main client, will
use it.

The frontend option is intended for testing,
and indeed I will add tests for this
transformation in the coming week as I bring
more functionality online.


Swift SVN r14801
2014-03-07 22:59:19 +00:00
John McCall
10ac15ed0d Lex $notAllDigits as an identifier and diagnose it in the lexer
outside of debugger-support mode.  Rip out the existing special-case
code when parsing expr-identifier.

This means that the Lexer needs a LangOptions.  Doug and I
talked about just adding that as a field of SourceMgr, but
decided that it was worth it to preserve the possibility of
parsing different dialects in different source files.

By design, the lexer doesn't tokenize fundamentally differently
in different language modes; it might decide something is invalid,
or it might (eventually) use a different token kind for the
same consumed text, but we don't want it deciding to consume more or
less of the stream per token.

Note that SIL mode does make that kind of difference, and that
arguably means that various APIs for tokenizing need to take a
"is SIL mode" flag, but we're getting away with it because we
just don't really care about fidelity of SIL source files.

rdar://14899000

Swift SVN r13896
2014-02-14 01:54:17 +00:00
Jordan Rose
0de8d19514 Define globals for the names of the stdlib, ObjectiveC, and Foundation modules.
This is mostly useful for the standard library, whose name is going to
change to "Swift" soon. (See <rdar://problem/15972383>.) But it's good DRY.

Swift SVN r13758
2014-02-10 22:40:42 +00:00
Mark Lacey
5c696fda8b Make IR generation take an explicit LLVMContext.
Prior to r13134, the modules being constructed for IRGen always used the
LLVM global context due to <rdar://problem/15283227>, but the interface
should really take this as a parameter rather than baking the behavior
into IRGen.

Swift SVN r13260
2014-02-01 01:07:14 +00:00
Jordan Rose
bac31d985a Add '-sil-serialize-all' testing option to the new frontend.
Swift SVN r13190
2014-01-31 01:02:06 +00:00
Jordan Rose
101fd40076 Rip out -emit-module-for-lldb option.
We ended up not using the wrapper around the module data in the Mach-O.

Swift SVN r13185
2014-01-31 00:02:47 +00:00
Jordan Rose
fb21a2da84 Move LLVM passes into a library, and use opt to test them instead of swift.
These don't really have anything to do with Swift, and there's no reason to
include this capability in the new driver.

Swift SVN r13181
2014-01-30 23:42:38 +00:00
Mark Lacey
d69b305200 Generate IR for inline functions from Clang modules.
Currently only inline functions referenced from Swift source files, or
from the REPL, will get IR generated for them. Inline functions
referenced by other inline functions will require additional effort to
generate properly.

With this change we use the clang::CodeGenerator-created llvm::Module
for all IR generation in Swift. This is perhaps undesirable, but
unavoidable given the interface the public Clang APIs expose, which do
not allow for building a ModuleBuilder that borrows an existing
llvm::Module.

Also unfortunate is the hack to generate a UsedAttr for each imported
inline function, but the public Clang APIs do not provide a way to only
emit deferred decls without emitting other things (e.g. module flags
that conflict with what the Swift IRGen emits). Note that we do not do
IRGen for every inline function in the module - only the ones that the
importer pulls in, which appears to be only those transitively
referenced from Swift code.

Swift SVN r13134
2014-01-30 02:33:37 +00:00
Jordan Rose
c312e51962 Add the ability to serialize modules with LLDB's wrapper info around them.
Currently when compiling with debug info, the AST gets serialized into the
.o file for use by the debugger. However, when we switch to one .o file
per .swift file, this won't really make sense any more. Instead, we should
collect all the ASTs at the end of the build and merge them together, then
write /that/ into the final binary.

This commit handles writing a serialized AST with an LLDB wrapper around it,
so that we can take a merged AST, write it out in the wrapper, and splice it
into the final binary using ld's -sectcreate option.

In the long run, we probably won't need the LLDB wrapper, but for now I'm
trying to disturb as little as possible. (It looks like the layout is
broken on 32-bit platforms, though...there was a problem with 64-bit
relocations in the existing SwiftASTStreamerPass, but nothing ever tried to
/read/ the new layout in 32 bits. I'm holding off on dealing with this
right now.)

Part of <rdar://problem/15786017>

Swift SVN r12667
2014-01-21 23:13:26 +00:00
Argyrios Kyrtzidis
e244f51229 [Lexer] Add some const goodness to the SourceManager that the Lexer uses.
No functionality change.

Swift SVN r12182
2014-01-11 01:09:30 +00:00
Connor Wakamo
59f18f9fc0 Renamed irgen::Options and irgen::OutputKind to IRGenOptions and IRGenOutputKind, and move both out of the irgen namespace now that they're in swiftAST.
Swift SVN r11405
2013-12-18 01:17:09 +00:00
John McCall
7173cec9db Thread contextual information about parsing the top-level
through various bits and use that to globally discriminate.

Swift SVN r11379
2013-12-17 04:31:40 +00:00
Michael Gottesman
4379283013 Remove inclusion of SILPasses/Passes.h into Subsystems.h and update all relevant files.
Swift SVN r10880
2013-12-05 19:58:21 +00:00
Michael Gottesman
b3fd8e90a5 Refactor out SILPass declarations from Subsystems.h => SILPasses/Passes.h.
Swift SVN r10877
2013-12-05 19:20:54 +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
Michael Gottesman
f2b8c0991d [cse] Initial implementation of EarlyCSE Port.
This patch contains an initial implementation of CSE for SIL ported from LLVM's
earlycse pass. It follows the overall general structure using
ScopedHashTables/DominatorTrees to perform the computation.

Currently it only handles integer literals to ease with the initial review. Once
this gets in I will be spending some time extending the pass to handle other
instructions.

Even with just handling integers this reduces the size of the stdlib in SIL by
~300 lines.

Swift SVN r10794
2013-12-04 21:49:37 +00:00
Chris Lattner
dadc9fc6d1 split predictable memory optimization (load promotion + alloc deletion) out to
its own SIL pass.  The bulk of this patch is updating the DI testcase to detangle
DI tests from load promotion tests.



Swift SVN r10721
2013-12-02 01:33:29 +00:00
John McCall
00dad2e89f Thread an isSILType bit through the validateType APIs.
Has no effect... yet.

Swift SVN r9983
2013-11-06 01:56:40 +00:00
Jordan Rose
93295737f0 [serialization] Initial -multi-file-output support.
If given a SourceFile, only decls within that SourceFile will be serialized.
Decls within other SourceFiles are emitted using cross-references that refer
to the current module.

Known issues:
- External definitions won't be serialized by any source file. They probably
  have to be serialized into /all/ of them.
- Nothing can actually /read/ a serialized partial-module yet. We need a
  notion of a TranslationUnit that can contain both source and serialized
  files, and we probably need loading to be more lazy.

Swift SVN r9978
2013-11-06 00:11:00 +00:00
Jordan Rose
70dd310522 [driver] Honor -o in -emit-sil, -emit-silgen, and -emit-llvm modes.
These modes naturally print to stdout, but if the user explicitly
specifies an output file/directory we should honor that.

Swift SVN r9887
2013-11-02 01:08:08 +00:00
Chris Lattner
d5fd6a67e0 Sketch out a trivial start at a simplify-cfg pass with one optimization to delete
dead blocks (which happens to be incorrect).

Unlike the LLVM SimplifyCFG pass, this one will be worklist-based instead of 
iterative, avoiding needless iteration over the entire function when a small
local changes are being made.


Swift SVN r9756
2013-10-29 04:37:27 +00:00
Chris Lattner
968e89a3be improve the DEBUG output of inout-deshadow and allocbox-to-stack.
clean up a couple random things in silcombiner:
  - it shouldn't return "made any changes" out of the pass.
  - statistics should be spelled out more and don't end with periods.



Swift SVN r9755
2013-10-29 04:02:32 +00:00
Jordan Rose
32130d3cc3 Teach delayed parsing to get its SourceFile from the saved DeclContext.
This makes it possible to delay decls in more than one source file.

Swift SVN r9672
2013-10-25 17:30:43 +00:00
Jordan Rose
2aeba96d53 Use SourceFile in a few more places.
- Local name lookup
- AST verification
- Delayed parsing
- Type checker, for the file kind
- Context of synthesized REPL decls

Swift SVN r9648
2013-10-24 18:59:26 +00:00
Michael Gottesman
bdf7cbe178 [sil-combine] Initial SILCombine implementation.
This pass is a port of InstCombine from LLVM to SIL. Thus if you are familiar
with the code from InstCombine you will feel right at home.

Keep in mind that in order to help with review, this is just a skeleton with no
optimizations in it besides a simple DCE based off of isInstructionTriviallyDead
(which this patch exposes in Local.h like LLVM does) to ensure that trivial
testing of the pass can be accomplished since otherwise it would do nothing
implying that no tests could be written at all.

I additionally modified one test which no longer passed due to SILCombine
removing 1x unused metatype instruction from the standard library.

Swift SVN r9404
2013-10-16 03:10:14 +00:00
Stephen Lin
94dbad4666 Add (but do not enable by default) a pass for closure capture promotion (rdar://problem/14757727).
Swift SVN r9362
2013-10-15 19:11:54 +00:00
Jordan Rose
ce612d3231 Remove TranslationUnit's HasBuiltinModuleAccess field.
This information is important when a SourceFile is created, and never
again after that.

Swift SVN r9240
2013-10-12 00:08:04 +00:00
Jordan Rose
7b936e2b85 Remove unfinished notion of "Component" (originally for resilience).
docs/Resilience.rst describes the notion of a resilience component:
if the current source file is in the same component as a module being
used, it can use fragile access for everything in the other module,
with the assumption that everything in a component will always be
recompiled together.

However, nothing is actually using this today, and the interface we
have is probably not what we'll want in 2.0, when we actually implement
resilience.

Swift SVN r9174
2013-10-10 21:41:57 +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
Jordan Rose
9d09d9c7a5 Adopt SourceFile for type checking.
Swift SVN r9106
2013-10-09 22:44:33 +00:00
Jordan Rose
0d2ccf7cb3 Adopt SourceFile in name-binding.
Swift SVN r9105
2013-10-09 22:44:32 +00:00
Jordan Rose
9f7ea273d6 Make performAutoImport work in terms of SourceFiles.
Swift SVN r9078
2013-10-09 18:38:27 +00:00
Jordan Rose
f5de2e43d7 Push SourceFile into Parser and REPL somewhat.
Swift SVN r9073
2013-10-09 18:38:17 +00:00
Jordan Rose
9d3720c8e2 Excise TranslationUnit from some parts of code completion and type checking.
In most cases an ASTContext and/or DeclContext is good enough.

Swift SVN r9013
2013-10-08 00:48:56 +00:00
Jordan Rose
c2b00fc2d4 Excise the global TranslationUnit from TypeChecker.
Now that TypeChecker is being used to check all sorts of things (not all
from a single TU), it's not really correct to have a single top-level TU
that gets used everywhere. Instead, we should be using the TU that's
appropriate for whatever's being checked. This is a small correctness win
for order-independent type-checking, but is critical for multi-file
translation units, which is needed for implicit visibility.

This basically involves passing around DeclContexts much more.

Caveat: we aren't smart about, say, filtering extensions based on the
current context, so we're still not 100% correct here.

Swift SVN r9006
2013-10-07 23:47:55 +00:00
Chris Lattner
73ad4dbb6a Completely remove the stacktossa pass, it is dead now.
Swift SVN r8996
2013-10-07 22:11:32 +00:00
Chris Lattner
d6b01a42ad add a new (skeleton) pass for deshadowing inout variables.
Swift SVN r8954
2013-10-07 15:53:40 +00:00
Anna Zaks
a19d7569cc Introduce Builtin.staticReport, which allows compiler diagnostic reporting.
- Introduces the Builtin
- If the first parameter evaluates to '1', the dataflow diagnostics pass produces a diagnostic.
- The Builtin gets cleaned up before IRGen, but not before SIL serialization.

This patch also removes the current, overflow warning and XFAILs one of the tests. The other test is switched to use Builtin.staticReport.

TODO:
 - Utilize the other parameters to the builtin - the Message and IsError flag.
 - Use this Builtin within the stdlib.

Swift SVN r8939
2013-10-05 00:12:23 +00:00
Chris Lattner
767da738bb Change the command line option to sil-opt for the definite initialization
pass to be -definite-init instead of -memory-promotion, rename the
entrypoint for the pass to match, and tidy various and sundry comments.


Swift SVN r8927
2013-10-04 18:45:09 +00:00
Jordan Rose
7055713d36 Remove declaration of nonexistent function swift::performCaptureAnalysis()
I think this is now TypeChecker::computeCaptures() and is only needed in Sema.

Swift SVN r8826
2013-10-01 23:10:22 +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
Dmitri Hrybenko
a11f623a47 Code completion: partial type checking of constructor bodies
Swift SVN r8343
2013-09-17 18:45:51 +00:00
Manman Ren
fa0acc9328 SIL Serialiation: add implementation to deserialize SIL and a wrapper class
SerializedSILLoader to hold a list of SIL deserializers.

Also add an intial implementation of a linking pass that is run right after
SILGen to link the declaration of SILFunction to the actual definition in
the serialized module.

We add two blocks to the serialized module: a sil index block that
maps identifier to a function ID and also holds a list of function offsets,
and a sil block for the actual SILFunctions. We can probably use subblock
instead of two top-level blocks.

The serialization/de-serialization of the function hash table and the function
offsets are implemented. But we are missing handling of types (see FIXME in
the code).

ModuleFile::Serialized is made public to be used by SIL deserializer, as well
as ModuleFile::getType.

The SIL deserializer holds a pointer to the ModuleFile, it gets the sil cursor
and the sil index cursor from the ModuleFile. The other option is for SIL
deserializer to find the start of the two sil blocks within itself, thus having
less coupling with ModuleFile.

No testing case yet because we are missing handling of types.


Swift SVN r8206
2013-09-13 17:44:41 +00:00
Dmitri Hrybenko
5975fb71b2 Use FuncDecl in typeCheckFunctionBody() parameters
Swift SVN r8139
2013-09-12 01:23:21 +00:00
Dmitri Hrybenko
37ee3a210c Run AST verifier on modules produced by Clang importer and fix bugs found by it
Fixes two bugs in Clang importer and deserialization code that were found by
the verifier:

(1) FuncExprs were created with a null FuncDecl

(2) BoundGenericType that was created by Clang importer for UnsafePtr<> and
    other magic types did not have substitutions.


Swift SVN r8073
2013-09-10 18:22:12 +00:00
Manman Ren
64ccd88c8c SIL Serialiation: pass in a SILModule to serialize and a few other functions.
Add SerializeSIL.cpp for basic implementation of a SIL serializer.

serialize, serializeToStream, Serializer::writeToStream, and
Serializer::writeTranslationUnit all take an additional SILModule to pass it
to Serializer::writeSILFunctions.

Serializer::writeSILFunctions goes through all SILFunctions in a SILModule, and
serializes all SILFunctions that are transparent.


Swift SVN r7875
2013-09-03 22:57:37 +00:00
Stephen Lin
a0f44d50b2 Update remaining references to [force_inline] to [transparent]
Swift SVN r7627
2013-08-27 18:46:03 +00:00
Jordan Rose
ee2ed392c7 Hack in a -module-link-name option for autolinking.
In Swift, a module is expected to know which libraries it needs, rather than
having this specified by an external module map. While we haven't quite
designed this yet (frameworks get this for free in Clang, for example),
we can at least provide a simple option for the common case of a module
associated with a single library.

This will probably change in the future, so I left in the more general
deserialization code I was working on before simplifying the use case.
A loaded module can in theory specify any arbitrary frameworks or libraries
as dependencies, not just a single dylib.

Swift SVN r7583
2013-08-26 18:57:48 +00:00
Adrian Prantl
661315763a Debug Info: This patch implements the "emit modules when compiling -g"
proposal.
When compiling with debug info, build a swiftmodule that contains all the
type decls referenced by DWARF and emit it into a special __apple_swiftast
section in the .o file.

Swift SVN r7398
2013-08-21 01:07:30 +00:00