Commit Graph

161 Commits

Author SHA1 Message Date
Roman Levenstein
141b8f814d Verify SIL modules at the beginning and at the end of the SIL optimization pipelines, if -sil-verify-all is provided
Till now, a SIL module would be only verified if an optimization has changed it. But if there were no changes, then no verification would happen and some SIL module format errors would stay unnoticed. This was happening in certain cases when reading a textual SIL module representation, which turned out to be broken, but SIL verifier wouldn't catch it.

Swift SVN r31863
2015-09-10 22:26:37 +00:00
Roman Levenstein
66e13af73e Add support for whole-module optimizations for SIL files.
To invoke the front-end on a SIL with whole-module optimizations enabled, execute:
swiftc -frontend myfile.sil

To invoke the front-end on a SIL without whole-module optimizations enabled, add a -primary-file option:
swiftc -frontend -primary-file myfile.sil

To invoke a sil-opt with whole-module optimizations enabled, use the -wmo option:
sil-opt myfile.sil -wmo

This change was need to be able to write SIL unit tests which should be compiled in the WMO mode.

Swift SVN r31862
2015-09-10 22:26:35 +00:00
Chris Willmore
d58dd6d55e If type-checking raised any errors, don't attempt playground transform.
<rdar://problem/22334177> Mandelbrot playground crashes compiler extension

Swift SVN r31614
2015-09-02 01:30:23 +00:00
Jordan Rose
3028dc8f44 Failure to load a bridging header -> failure to load a module.
This is important for both test targets and for debugging.

rdar://problem/20616099

Swift SVN r30784
2015-07-30 00:39:35 +00:00
Devin Coughlin
3e96e1f06b [Sema] Suppress warning about useless availability checks in playgrounds and immediate mode.
We normally report a warning when a #available() check will always be true
because of the minimum deployment target. These warnings are potentially
annoying when the developer either cannot change the minimum deployment target
from the default (as in playgrounds) or when doing so is burdensome (as for
interpreted command-line scripts, which would require passing a target triple)
-- so suppress them.

The is a updated version of the reverted r29582, which didn't check for
immediate mode properly.

rdar://problem/21324005

Swift SVN r29646
2015-06-24 23:09:22 +00:00
Jordan Rose
98ed31fb99 Make -import-underlying-module automatically export that module.
That's how everything behaved anyway. Might as well make it explicit and
stop special-casing it.

I've left in compatibility for modules built with older compilers so that
people using the OS toolchains aren't immediately unable to debug their apps.
As soon as we change the module format in a more significant way, I can take
this out.

Groundwork for rdar://problem/21254367; see next commit.

Swift SVN r29437
2015-06-17 04:47:39 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00
Connor Wakamo
eb36def696 [frontend] Updated the behavior for -import-module so it can be specified multiple times.
Instead of only honoring the last occurrence of -import-module, the frontend now
honors all occurrences of -import-module, making all of the modules specified on
the command line implicitly visible.

This fixes <rdar://problem/20422696>.

Swift SVN r27299
2015-04-15 00:22:48 +00:00
Chris Willmore
d3a977d824 <rdar://problem/20402026> Remove scope entry/exit log entries
Don't emit scope entry/exit logging code in instrumentation for
playgrounds if -playground-high-performance option is passed.

Swift SVN r27046
2015-04-06 22:09:20 +00:00
Jordan Rose
85a3751f6d Remove SourceFile::getImports in favor of FileUnit::getImportedModules.
getImportedModules is the canonical way to get imports, whether private,
public, or both. This is especially true now that we have more flags
for SourceFile imports that really shouldn't be consumed by anyone
outside of SourceFile.

In this same vein, provide addImports instead of setImports, since imports
are always additive.

No visible functionality change.

Swift SVN r26634
2015-03-27 16:36:47 +00:00
Jordan Rose
e334eed7a4 Record @testable in a SourceFile's import list.
No functionality change, since nothing's using it yet.

Swift SVN r26632
2015-03-27 16:36:44 +00:00
Jordan Rose
e6c2131bda Check that "@testable import Foo" is only used to import testable modules.
(i.e. modules compiled with -enable-testing)

Part of testability (rdar://problem/17732115)

Swift SVN r26293
2015-03-19 02:20:41 +00:00
Jordan Rose
c6739b6b6c Add the -enable-testing flag, and serialize it.
This flag indicates that internal APIs within the module should be made
available to client code for testing purposes. Currently does nothing.

Not ready for developer consumption yet, ergo a hidden frontend-only flag.

Part of testability (rdar://problem/17732115)

Swift SVN r26292
2015-03-19 02:20:38 +00:00
Manman Ren
a43db3621f [Driver] add InputFileKind to FrontendOptions.
Separate InputFileKind from SourceFileKind, FrontendOptions will now use
InputFileKind, while Module will use SourceFileKind.

This is in preparation for adding an input file kind for LLVM IR.

rdar://19048891


Swift SVN r25555
2015-02-26 19:13:39 +00:00
Jordan Rose
dbd3b60f6b [Serialization] Move (Module)Status and validateSerializedAST into a namespace.
Also into a separate file.

Before (swift/Serialization/SerializedModuleLoader.h):
  ModuleStatus
  SerializedModuleLoader::ValidationInfo
  SerializedModuleLoader::ExtendedValidationInfo
  SerializedModuleLoader::isSerializedAST
  SerializedModuleLoader::validateSerializedAST

After (swift/Serialization/Validation.h):
  serialization::Status
  serialization::ValidationInfo
  serialization::ExtendedValidationInfo
  serialization::isSerializedAST
  serialization::validateSerializedAST

No functionality change, just a lot of renaming and a bit of reorganizing.

Swift SVN r25226
2015-02-12 05:32:25 +00:00
Ben Langmuir
b3e9f13464 Revert "Workaround FD leaks from clang module files in performSema"
This reverts commit r25038.

Swift SVN r25041
2015-02-06 19:28:01 +00:00
Ben Langmuir
d258d764ea Workaround FD leaks from clang module files in performSema
Until we get a proper fix for rdar://problem/19720334 to close the .pcm
files immediately after reading them, forcefully close all the .pcm file
descriptors at the end of performSema.  This avoids file descriptor
leaks that eventually bring down SourceKit.

rdar://problem/19059478

Swift SVN r25038
2015-02-06 18:53:26 +00:00
Jordan Rose
c97c949fcf Add frontend flag -import-module <name>.
This implicitly adds the named module as an import of every source file
in the module being compiled. This is not intended to be used generally,
but will be useful for playgrounds.

rdar://problem/19605934

Swift SVN r24905
2015-02-02 22:20:13 +00:00
Denis Vnukov
68b756bf90 Fix for rdar://19548610, Fuzzing Swift: performSema(...) crashes: Assertion failed: (Done && "Parser returned early?")
Parser may stop at some erroneous constructions like stray #else or #endif, in some cases closing brace ‘}’, etc…
continue parsing until we are done.



Swift SVN r24822
2015-01-29 21:51:06 +00:00
Jordan Rose
a3a6c2695b Put the current target into LangOptions.
This has been long in coming. We always had it in IRGenOpts (in string form).
We had the version number in LangOpts for availability purposes. We had to
pass IRGenOpts to the ClangImporter to actually create the right target.
Some of our semantic checks tested the current OS by looking at the "os"
target configuration! And we're about to need to serialize the target for
debugging purposes.

Swift SVN r24468
2015-01-16 02:48:54 +00:00
Jordan Rose
97b3a3da40 Include cross-module dependencies in swiftdeps files.
These are the same dependencies collected for .d files, including
headers and imported swiftmodules. These can also cause a file to be out
of date.

Part of rdar://problem/19270920

Swift SVN r24334
2015-01-10 00:38:09 +00:00
Jordan Rose
8612e24e0f -debug-time-function-bodies: dump time spent type-checking each function.
This is a hidden frontend-only option intended for debugging purposes,
mainly for identifying where in a file the type checker is spending most
of its time. Use with "sort -g" to get the top problem functions.

Swift SVN r23789
2014-12-08 23:07:07 +00:00
Michael Gottesman
85e2502f96 Pass in SILOptions to SILModule.
This should have been done a long time ago since SILOptions are options that
should be able to effect everything SIL related. In this case I just want to
pass in a flag on the SILModule to enable +0 self. By putting it on the
SILModule I can conveniently check it in SILFunctionType without exposing any
internal state from SILFunctionType.cpp.

Swift SVN r23647
2014-12-03 07:43:52 +00:00
Doug Gregor
b3badc601a Handle consistency checking that requires the entire module.
Objective-C method unintended override checking is one such case where
properly checking unintended overrides requires us to essentially look
at the whole module, because one translation unit may declare
something that produces an Objective-C method "setFoo:" in a
superclass while another translation unit declares something with a
distinct name that produces an Objective-C method "setFoo:". So, when
we don't have a primary file (e.g., when we're doing the merge-module
step), delay such checks until after all the source files for the
module have been type-checked. When there is a primary file, we
perform the checking that we can based on type checking that primary
file (and whatever got touched along the way), so we get a subset of
the proper diagnostics.

Swift SVN r23179
2014-11-08 06:20:57 +00:00
Jordan Rose
fc09bd4585 Add basic reference tracking based on name lookups.
This tracks top-level qualified and unqualified lookups in the primary
source file, meaning we see all top-level names used in the file. This
is part of the intra-module dependency tracking work that can enable
incremental rebuilds.

This doesn't quite cover all of a file's dependencies. In particular, it
misses cases involving extensions  defined in terms of typealiases, and
it doesn't yet track operator lookups. The whole scheme is also very
dependent on being used to track file-level dependencies; if C is a subclass
of B and B is a subclass of A, C doesn't appear to depend on A. It only
works because changing A will mark B as dirty.

Part of rdar://problem/15353101

Swift SVN r22925
2014-10-24 22:23:03 +00:00
Argyrios Kyrtzidis
0e55e054b9 [Frontend] Allow explicit control for enabling the playground instrumenter.
Related to rdar://18095436

Swift SVN r22915
2014-10-24 17:16:59 +00:00
Argyrios Kyrtzidis
633e672f7c [Frontend] Set the primary file to the code-completion point if one exists.
Swift SVN r22688
2014-10-11 05:07:34 +00:00
Adrian Prantl
7cae8fdfca update for upstream API change.
Swift SVN r22577
2014-10-07 21:42:10 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Jordan Rose
d3a9e58133 Use Nothing instead of {} to initialize Optionals.
In preparation for the switch to llvm::Optional, which has an explicit
default constructor.

Swift SVN r22470
2014-10-02 18:51:33 +00:00
Jordan Rose
4cce3460c9 Have CompilerInvocation::getMainModule() lazily create the main module.
This allows clients to set up the main module before calling performSema.
This should not affect the compiler in any way.

Swift SVN r22270
2014-09-25 00:15:34 +00:00
Jordan Rose
a185af4617 Don't forget to name-bind main.swift if it's not the primary file.
Fixes an assertion failure and very possibly a crash.

rdar://problem/18358753

Swift SVN r22144
2014-09-19 21:43:56 +00:00
Manman Ren
7c70eb4ce5 [SIL] disable access control when processing .sil.
This enables us to parse dumped .sil files with swiftc. Before this
commit we could parse them with sil-opt, but not swiftc.

rdar://17860394


Swift SVN r21492
2014-08-27 22:31:18 +00:00
Dmitri Hrybenko
42b25d939d Update for upstream LLVM changes is MemoryBuffer APIs
Swift SVN r21409
2014-08-22 08:28:03 +00:00
Jordan Rose
9b0d643029 Move 'Playground' into LangOptions and out of FrontendOptions and IRGenOptions.
Also, use 'Playground' to control the behavior of ignored expressions
(which are not an error because they are displayed in the playground log).

This is preparation for LLDB no longer passing 'DebuggerSupport' for a
playground <rdar://problem/18090611>. 'DebuggerSupport' now only applies
to REPL-like contexts and enables identifiers beginning with $, special
rules for parsing top-level code, ignored expressions (like playgrounds),
and the @LLDBDebuggerSupport attribute.

Besides ignored expressions, 'Playground' enables the playground transformation
and provides an entry point for debugger initialization.

Note that this is a bit insincere---many of the options controlled by both
'Playground' and 'DebuggerSupport' really only apply to the main source file
or main module. If/when we add back support for source file imports, we'll
need to revisit all of LangOptions and see which of them should /really/
apply to /everything/ in the ASTContext.

Swift SVN r21384
2014-08-21 22:36:24 +00:00
Nadav Rotem
f9d4a84e18 Remove the rest of the tryFinal logic. rdar://17890078.
Swift SVN r21138
2014-08-12 00:06:35 +00:00
Jordan Rose
4eebcb9853 Change ASTContext's LoadedModules map to be keyed by Identifiers, not strings.
No intended functionality change, but there's no reason to be performing
string lookups here.

Swift SVN r20902
2014-08-01 18:03:47 +00:00
Michael Ilseman
1df56990bd Also try to add final to non-public members of public classes.
Teaches TryAddFinal to descend into public and objc classes. Only
tries to add final if we're either whole compilation mode, or we're
processing the primary source buffer.

Updates test cases. Includes workarounds for <rdar://problem/17860781>
and <rdar://problem/17862348>.

Swift SVN r20790
2014-07-31 00:32:50 +00:00
Jordan Rose
0481b87ba5 Move target configuration setup into CompilerInvocation.
Without this, clients that don't use a CompilerInstance (like LLDB) won't
have target configuration options available.

Also, move minimum OS checking into the driver. This makes sure the check
happens early (and only once), and in general fits the philosophy of
allowing the frontend to use configurations that might be banned for users.

<rdar://problem/17688913>

Swift SVN r20701
2014-07-29 21:48:59 +00:00
Sean Callanan
155253124e Testcase for the playground transform.
This is the first testcase and includes the test
harness which will work for other testcases as
well.

Also includes a fix to make sure that we only
instrument once per main source file, and not
once per parse as we were doing before.


Swift SVN r20456
2014-07-24 01:31:56 +00:00
Sean Callanan
9bc668b119 Fixes to the playground transform to make it work
with the test case I'm working on.

Who knew that test cases find bugs?


Swift SVN r20451
2014-07-24 00:42:18 +00:00
Dmitri Hrybenko
fe326db2f5 Update for upstream LLVM changes
Swift SVN r20409
2014-07-23 16:15:20 +00:00
Michael Ilseman
41dec5b58c Invoke TryAddFinal after type checking.
Run whole-module checks at the end of perform Sema, specifically
TryAddFinal. After everything has been type checked, accessibility has
been provided, and we have had a chance to see any potential
overrides, we try to add the final attribute to class members.

This ends up de-virtualizing many functions, or rather they avoid the
vtable altogether. Thus, there are many test file changes. New test
file add_final.swift. Other tests updated to either reflect the
non-virtual call, or to have public added to them.

Swift SVN r20338
2014-07-22 21:31:58 +00:00
Jordan Rose
fce31decdc Serialize bridging headers into the merged module file.
We do this so that the swiftmodule file contains all info necessary to
reconstruct the AST for debugging purposes. If the swiftmodule file is copied
into a dSYM bundle, it can (in theory) be used to debug a built app months
later. The header is processed with -frewrite-includes so that it includes
any non-modular content; the user will not have to recreate their project
structure and header maps to reload the AST.

There is some extra complexity here: a target with a bridging header
(such as a unit test target) may depend on another target with a bridging
header (such as an app target). This is a rare case, but one we'd like to
still keep working. However, if both bridging headers import some common.h,
we have a problem, because -frewrite-includes will lose the once-ness
of #import. Therefore, we /also/ store the path, size, and mtime of a
bridging header in the swiftmodule, and prefer to use a regular parse from
the original file if it can be located and hasn't been changed.

<rdar://problem/17688408>

Swift SVN r20128
2014-07-18 00:22:53 +00:00
Doug Gregor
a885d1b3bd Transfer the buffer for the module documentation file only when it exists.
More fallout from LLVM r212408.

Swift SVN r19613
2014-07-07 15:31:55 +00:00
Pete Cooper
0d0defff9a Update which matches clang r212408, ie, using ErrorOr for file loading
Swift SVN r19607
2014-07-07 14:49:01 +00:00
Ted Kremenek
d075f06573 Require a minimum deployment target of iOS 7 or OSX 10.9
Implements <rdar://problem/17532113>

Swift SVN r19451
2014-07-02 06:23:38 +00:00
Argyrios Kyrtzidis
ab14eeb8cc [Frontend] For CompilerInstance::performParseOnly() make sure to mark the main buffer so a hashbang is accepted.
Test case on the SourceKit side.
rdar://17282145

Swift SVN r19320
2014-06-28 03:23:13 +00:00
Bob Wilson
9ab1136ba8 Update error_code usage to match llvm trunk.
LLVM's system_error.h has been changed to forward to the standard
version of the same. Update usage for the minor API changes that this
entails.

Based in part on a patch by Justin Bogner.

Swift SVN r18832
2014-06-12 19:48:39 +00:00
Jordan Rose
79b45268e2 Allow ASTContext::getStdlibModule to load the stdlib if it isn't present.
This is better than requiring people to go through Ctx.getModule() using
Ctx.StdlibModuleName. There aren't that many cases of this, but they
shouldn't be using a completely different API.

The default behavior remains the same: if the standard library has not been
loaded, null will be returned.

Refinement of r18796, which modified the behavior of SourceFiles to assume
that the standard library had already been loaded.

Swift SVN r18813
2014-06-11 23:34:41 +00:00