Commit Graph

144 Commits

Author SHA1 Message Date
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
Connor Wakamo
1ecc5cc3e6 [frontend] Moved ImportSearchPaths out of CompilerInvocation/ASTContext and into SearchPathOptions.
Also updated findModule() in SourceLoader.cpp and SerializedModuleLoader.cpp to get the ImportSearchPaths from the ASTContext’s SearchPathOpts, instead of directly from the ASTContext.

Swift SVN r11214
2013-12-12 22:15:58 +00:00
Connor Wakamo
86b4a3b049 [frontend] Begin moving search path-related options into SearchPathOptions.
Added a new SearchPathOptions class to swiftAST, which will contain options like import search paths and the SDK path.
Moved the RuntimeIncludePath from CompilerInvocation into SearchPathOptions. For now, at least, the RuntimeIncludePath is handled separately from other ImportSearchPaths, since we can’t yet guarantee that RuntimeIncludePath is set up before we parse the ImportSearchPaths.
Added a SearchPathOptions member to ASTContext.
Updated findModule() in SourceLoader.cpp and SerializedModuleLoader.cpp to check RuntimeIncludePath after everything else if no module was found. (This matches existing behavior, which had RuntimeIncludedPath at the end of ImportSearchPaths.)

Swift SVN r11213
2013-12-12 21:38:11 +00:00
Jordan Rose
439ba3e624 Accept swiftmodule files on the command line as partial AST inputs.
Each loaded file gets added to the main module, rather than being a standalone
separate module. In theory, this will be used to assemble several partial
ASTs into a complete module. In practice, there's still a ways to go...but
this can already round-trip a single module file.

This also factors out the FileUnit-creating part of SerializedModuleLoader,
which should help clients like SourceKit that don't need to search for a
swiftmodule file associated with a particular import.

Swift SVN r10952
2013-12-07 00:14:01 +00:00
Jordan Rose
b4e4b551bd Rename CompilerInstance::doIt to performParse.
'doIt' is semantically meaningless, and doesn't mention the fact that nothing
has actually been compiled yet (to SIL, to IR, or to machine code).
'performParse' matches the compiler flag -parse, which stops after
type-checking.

No functionality change.

Swift SVN r10951
2013-12-07 00:13:58 +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
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
Jordan Rose
fb0fa908b6 [Frontend] Parse the main file last to make sure implicit visibility works.
Otherwise, we'll try to type-check bits of the main source file before we've
even looked at any of the supporting files.

This affects implicit multi-file mode, where "main.swift" is assumed to be
the main source file and all others are treated as library files. (See r9890.)

<rdar://problem/15526743>

Swift SVN r10795
2013-12-04 21:54:43 +00:00
Argyrios Kyrtzidis
6fb1dce5c1 [Frontend] When setting up the buffers for a CompilerInstance, allow a memory buffer to
provide the contents of a filename, based on its buffer identifier.

Swift SVN r10042
2013-11-08 18:29:38 +00:00
Argyrios Kyrtzidis
44d46de7c9 Use swift::SourceManager's addNewSourceBuffer() instead of llvm::SourceMgr's AddNewSourceBuffer().
Also remove the SourceLoc parameter from addNewSourceBuffer(). In llvm::SourceMgr
it is used to indicate textual inclusion, which we don't have in swift.

Swift SVN r10014
2013-11-07 00:51:56 +00:00
Jordan Rose
b43dd09107 All SourceFiles should always remember their buffer IDs, not just imports.
Swift SVN r9946
2013-11-04 23:50:48 +00:00
Jordan Rose
aeb22194a0 [driver] Treat "main.swift" as the main source file if given multiple inputs.
New rules for the driver (first match):
1. -repl: no input files allowed
2. -parse-sil: one input file allowed
3. -parse-as-library: any number of input files, all treated as Library
4. one input, extension is .sil: treated as SIL
5. one input: treated as Main
6. many inputs: treated as Library by default; "main.swift" is treated as Main

If we want more control here we can also add a -main-file option to explicitly
call out the main source file, but this at least unblocks building an entire
app target (like ListMaker) with a single Swift invocation.

Swift SVN r9890
2013-11-02 01:08:40 +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
a333b692b4 Flip the switch: multiple input files = multiple SourceFiles.
There is still plenty of fallout to get everything fully correct, but
right now we can build the standard library and run all the tests in
multiple-file mode.

Swift SVN r9673
2013-10-25 17:30:45 +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
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
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