Commit Graph

161 Commits

Author SHA1 Message Date
Jordan Rose
e022a97386 [Frontend] Check in advance that we can load the standard library.
This doesn't really affect anyone in real life, but it will catch cases
where someone's trying to compile for iOS without the iOS stdlib around.

Swift SVN r18796
2014-06-11 00:02:00 +00:00
Jordan Rose
2877bd0854 Add support for dependency file generation with -emit-dependencies.
This performs very conservative dependency generation for each compile task
within a full compilation. Any source file, swiftmodule, or Objective-C
header file that is /touched/ gets added to the dependencies list, which
is written out on a per-input basis at the end of compilation.

This does /not/ handle dependencies for the aggregated swiftmodule, swiftdoc,
generated header, or linked binary. This is just the minimum needed to get
Xcode to recognize what needs to be rebuilt when a header or Swift source
file changes. We can revisit this later.

This finishes <rdar://problem/14899639> for now.

Swift SVN r18045
2014-05-14 00:34:11 +00:00
Argyrios Kyrtzidis
1f430cb4b8 [Frontend] Simplify CompilerInstance::performParseOnly() by only supporting parsing a single file.
Swift SVN r17634
2014-05-07 17:55:19 +00:00
Argyrios Kyrtzidis
9afa0333db [Frontend] Make sure we don't do any module imports during parse-only pass.
Fixes performance regression of rdar://16816861

Swift SVN r17600
2014-05-07 02:37:49 +00:00
Argyrios Kyrtzidis
796afac0af [Frontend] Rename CompilerInstance::performParse() -> performSema() to make it more clear that it is doing parsing + type checking.
Swift SVN r17597
2014-05-07 02:13:49 +00:00
Argyrios Kyrtzidis
136284430c [Frontend] Separate parse-only functionality into its own function, CompilerInstance::performParseOnly().
Parse-only is a hot path; keep the semantics for it separate from normal parsing, otherwise it is very
easy to introduce something expensive without checking for Invocation.getParseOnly().

Also cleans up a bit CompilerInstance::performParse() as well.

Swift SVN r17596
2014-05-07 02:13:48 +00:00
Jordan Rose
0c46eb821e [ClangImporter] Handle decls declared in imported headers.
This improves the -import-objc-header option to read decls from the header
as well. Any declaration that is not from a module will be considered to be
part of the "header module". Conversely, forward-declarations appearing in
the header will be resolved by looking through all modules responsible for
importing a header.

More of <rdar://problem/16702101>

Swift SVN r17492
2014-05-05 22:52:17 +00:00
Jordan Rose
cf77de720a Add -import-objc-header option, and wire up the basic infrastructure.
THIS IS NOT READY FOR USE YET.

The new plan for mixed-source non-framework targets is that the Swift
compiler will import an Objective-C header directly, and treat the decls
and imports in that header as explicitly visible to the entire target.
This means users don't have to modularize their headers before bringing
them into Swift.

This commit adds the option and introduces the "imported headers" module
as an implicit import for the source files being compiled. It also directs
the Clang importer to process the given header (using #import, so that it
won't somehow get included twice) and watches for any module imports that
occur as a result of reading that header.

Still to come: import of decls within the header (not within any module),
and proper serialization of cross-references to the header and its imports.

Part of <rdar://problem/16702101>

Swift SVN r17218
2014-05-02 00:55:31 +00:00
Argyrios Kyrtzidis
9418fb9948 [DiagnosticEngine] Mark module import diagnostic errors as 'fatal' errors, and supress subsequent diagnostics
to avoid a cascade of errors that drown out the original failure.

Swift SVN r17141
2014-05-01 05:24:48 +00:00
Jordan Rose
8699a3b83f Add -import-underlying-module option.
This option implicitly imports the Clang module with the same name as the
module being built into every source file in the module being built.
This will be used for mixed-source framework targets to give Swift code the
same implicit visibility for Objective-C decls in the same module that it
already has for other Swift decls.

<rdar://problem/16701230>

Swift SVN r17053
2014-04-29 23:13:45 +00:00
Jordan Rose
0e7bb07b26 Make module loaders owned by the AST context instead of ref-counted.
Also, create the Clang module loader directly rather than indirecting through
a "get constructor" function. It's no longer a valid configuration to not
have a Clang importer.

Swift SVN r16862
2014-04-26 00:57:09 +00:00
Jordan Rose
1dfc037875 [ClangImporter] Pass through target CPU and features properly.
The hardcoding of CPU settings in lib/Driver/Tools.cpp isn't at all ideal,
but it will let us limp along for now.

<rdar://problem/16641385>

Swift SVN r16861
2014-04-26 00:57:07 +00:00
Dmitri Hrybenko
9153ff0615 Remove workaround for missing arm64 backend, now that it is committed upstream
Swift SVN r15648
2014-03-30 15:20:38 +00:00
Argyrios Kyrtzidis
f1d14c0911 [Basic/LangOptions] Remove std::unordered_map/unordered_set from LangOptions and use SmallVector instead.
The config options are so few that a map is not worth it currently.

Swift SVN r15476
2014-03-26 00:26:17 +00:00
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
Dmitri Hrybenko
ef78e2811a Code completion: make sure to always emit a diagnostic so that ASTContext is
marked as erroneous

This is important so that other parts of the compiler (e.g., AST verifier) are
less strict about AST invariants.

Alternatively, we could make sure to emit a diagnostic in the parser when we
consume the code completion token, but chasing every place where we do it now
(and remembering to do this in future) does not scale well.

Fixes the crash in rdar://problem/16100914


Swift SVN r14865
2014-03-10 10:37:52 +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
Dmitri Hrybenko
b30edaeed6 Remove 'swift::' qualifications that are not needed
Swift SVN r14780
2014-03-07 13:05:28 +00:00
Dmitri Hrybenko
ba33352636 Move comment to the correct place
Swift SVN r14779
2014-03-07 12:32:42 +00:00
Dmitri Hrybenko
b62e7e5271 Simplify code, NFC
Swift SVN r14778
2014-03-07 12:24:36 +00:00
Dmitri Hrybenko
ef0942c69c Add a convenience API SourceManager::addMemBufferCopy() to simplify adding a
buffer in case the client does not need a pointer to the buffer.


Swift SVN r14777
2014-03-07 11:41:08 +00:00
Dmitri Hrybenko
255b8e88c8 Fix a leak that I introduced in r14729: FrontendOptions does not own input
buffers, so undo 'unique_ptr'fication here


Swift SVN r14733
2014-03-06 13:53:04 +00:00
Dmitri Hrybenko
f232267f23 Replace llvm::OwningPtr with std::unique_ptr
It looks like llvm::OwningPtr is going to be removed soon.


Swift SVN r14729
2014-03-06 09:47:17 +00:00
Dmitri Hrybenko
cd48638f9a Fix a use-after-free caused by creating DerivedFileUnit on the fly
Sema was creating DerivedFileUnit on the fly, while something else is iterating
over FileUnits in the module.  The fix is to create DerivedFileUnit in advance.
This change immediately uncovered a lot of code that assumed that the module
consists of a single FileUnit at certain conditions.  This patch also fixes
that code (SourceKit patch is separate, not sending it).

The test change is because now operator == on NSObjects is correctly recognised
as coming from a system module.

rdar://16153700, rdar://16227621, possibly rdar://16049613


Swift SVN r14692
2014-03-05 22:24:25 +00:00
Dmitri Hrybenko
3430229a79 Simplify code
Swift SVN r14641
2014-03-04 11:41:47 +00:00
Dmitri Hrybenko
15fd90c31c Revert r14589, a proper fix will be committed soon
Swift SVN r14639
2014-03-04 10:19:22 +00:00
Dmitri Hrybenko
a5c5daf336 Fix a use-after-free: type checker can add 'DerivedFileUnit's now, so we need
to be careful when iterating over the vector of all files and type checknig
them.

This is related to rdar://16153700, but it looks like that it does not yet
completely fix it.


Swift SVN r14589
2014-03-03 11:21:33 +00:00
Joe Pamer
0be3362ba9 Update target configuration values to conform with current conventions (use i386, x86_64, arm and arm64 instead of I386, X64, ARM and ARM64).
Swift SVN r14371
2014-02-26 02:06:30 +00:00
Dmitri Hrybenko
db6f0772b4 Allow Swift to be compiled with open-source LLVM
Swift SVN r14311
2014-02-24 20:57:36 +00:00
Joe Pamer
b46d20240d Update build configuration tests to be independent of their runtime platform.
Also, add more tests for the "os" and "arch" target configurations, to exercise likely
build configurations for iOS and the iOS simulator.

Swift SVN r14307
2014-02-24 18:16:50 +00:00
Joe Pamer
988a5877f2 Some updates:
- Respond to Doug's code review feedback
   - Stop hacking around with scopes and use "emplace" to work around RAII in the inactive config case
   - Limit use of StringRef on the front-end, in favor of std::string
   - Use ArrayRef rather than SmallVector within IfConfigDecl
   - Reorder new property declarations on BraceStmt to prevent unnecessary alignment issues
- Update ParseBraceItems to better capture top-level declarations, rather than using token lookahead

Swift SVN r14306
2014-02-24 18:16:49 +00:00
Joe Pamer
f83f94d9d8 Support build and target configurations
These changes add support for build and target configurations in the compiler.
Build and target configurations, combined with the use of #if/#else/#endif allow
for conditional compilation within declaration and statement contexts.

Build configurations can be passed into the compiler via the new '-D' flag, or
set within the LangOptions class. Target configurations are implicit, and
currently only "os" and "arch" are supported.

Swift SVN r14305
2014-02-24 18:16:48 +00:00
Michael Gottesman
648d3fee40 Pass in Args.size() - 1, not Args.size() so the nullptr arg is not included in "argc".
Swift SVN r13762
2014-02-10 22:58:51 +00:00
Michael Gottesman
f88bc1ed3e Teach the frontend how to pass through -Xllvm commands.
This patch allows you to pass through commands to llvm from the driver so now
one can when compiling swift files get debug messages!

Swift SVN r13761
2014-02-10 22:49:56 +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
Jordan Rose
cbcf17f9bd Stop leaking memory from Module and FileUnit.
Also, disallow creating Modules and FileUnits on the stack. They must always
live as long as the ASTContext.

<rdar://problem/15596964>

Swift SVN r13671
2014-02-08 02:12:57 +00:00
Jordan Rose
302f9cb50d Disallow importing other Swift source files as modules.
Because this is useful in testing, I've left in a frontend option
-enable-source-import for both swift and swift-ide-test that sidesteps the
module restriction. Right now, though, this is the right thing to avoid
users running into strange issues when they import another file within
their module and Swift treats it as a separate module.

<rdar://problem/15937521>

Swift SVN r13248
2014-01-31 23:01:04 +00:00
Connor Wakamo
c38c95c0a1 Fixed indentation issue.
Swift SVN r13159
2014-01-30 18:44:40 +00:00
Connor Wakamo
68290c72e3 [frontend] If there is a primary input, only call performTypeChecking() on the primary input.
This has the potential to significantly reduce compile times in primary file
mode: for example, compiling Song.swift from the Name That Tune example as the
primary file previously took ~2.0s with a release build on my machine; with this
change, it now only takes ~0.8s. (The old compile time was presumably dominated
the time it takes to type-check AppDelegate.swift, which is a larger file.)

Swift SVN r13140
2014-01-30 04:53:19 +00:00
Jordan Rose
12fb34d60f Eliminate "Immediate" flag from CompilerInvocation.
This adds some ugliness in the current swift binary because we weren't
bothering to set a requested action before, but it keeps things simpler
elsewhere. (Thanks, Connor.)

Swift SVN r13067
2014-01-28 22:20:13 +00:00
Jordan Rose
cc3119be51 Teach the Mach-O-based AST importer to accept bare serialized ASTs.
This necessitated adding a new function to validate a serialized AST, so
that we can get the same information that used to be extracted from the
section header.

For now, we'll continue accepting the wrapped ASTs as well, since we
haven't changed the existing debug info generator.

Swift SVN r12922
2014-01-24 18:42:07 +00:00
Jordan Rose
11008f0ed1 Split diagnostics out into separate files.
Thanks to the way we've set up our diagnostics engine, there's not actually
a reason for /everything/ to get rebuilt when /one/ diagnostic changes.
I've split them up into five categories for now: Parse, Sema, SIL, IRGen,
and Frontend, plus a set of "Common" diagnostics that are used in multiple
areas of the compiler. We can massage this later.

No functionality change, but should speed up compile times!

Swift SVN r12438
2014-01-17 00:15:12 +00:00
Jordan Rose
d53863b3a3 Don't provide an SDK by default.
Hardcoding a path to a particular SDK is definitely the wrong thing to do.
Let's see how far we can get without setting a default SDK.

See discussion in <rdar://problem/14395800>

Swift SVN r12414
2014-01-16 20:08:07 +00:00
Connor Wakamo
a35540be40 [frontend] Added CompilerInstance::getPrimarySourceFile().
During CompilerInstance::performParse(), set CompilerInstance::PrimarySourceFile if we create a SourceFile from a buffer whose ID matches the PrimaryBufferID.
This allows clients of CompilerInstance to get a SourceFile for the user-specified primary input.

Swift SVN r12156
2014-01-10 22:39:08 +00:00
Connor Wakamo
9f89b432b5 [frontend] Added CompilerInstance::PrimaryBufferID.
This maps a particular buffer ID to the PrimaryInput, which will (eventually) allow us to map a SourceFile to the PrimaryInput.

Swift SVN r12155
2014-01-10 22:39:07 +00:00
Connor Wakamo
6eb9a82465 [frontend] Switch CompilerInstance::MainBufferIndex to CompilerInstance::MainBufferID.
This matches how we will handle primary inputs.
This also fixes an issue where a file named main.swift may not be chosen as the main file if there were multiple inputs and it was replaced by an input buffer.

Swift SVN r12154
2014-01-10 22:39:07 +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
Connor Wakamo
af6da9b455 [ClangImporter] Adjusted ClangImporter::create so that it accepts a ClangImporterOptions instead of individual parameters.
Swift SVN r11240
2013-12-13 04:52:59 +00:00
Connor Wakamo
48a111b0b3 [ClangImporter] Switch ClangImporter::create from directly accepting search path information to using the ASTContext’s SearchPathOptions.
Swift SVN r11239
2013-12-13 04:52:59 +00:00
Jordan Rose
1011340094 Always record known protocols even when there are no source inputs.
This isn't significant yet, but it will be once we can load partial ASTs.

Swift SVN r11225
2013-12-13 00:26:12 +00:00