Commit Graph

6605 Commits

Author SHA1 Message Date
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
f165afe1aa Replace "-enable-sil-linking=false" with "-disable-sil-linking".
Also, restructure so that the option isn't declared in a random library file.
(And do the same with "-sil-link-all".)

Part of the migration to the new driver.

Swift SVN r13184
2014-01-31 00:02:46 +00:00
Jordan Rose
8f7a2e4d56 Eliminate LLVM pass entry points from swift and swift_driver.
Per previous commit, we should just test these using opt.

Swift SVN r13182
2014-01-30 23:42:40 +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
Connor Wakamo
247228104d [driver] Updated main() to return 1 if there were any errors building the Compilation.
Previously, main() would always return 0 if a Compilation was not built. Now
that the driver is correctly emitting diagnostics, check for any errors to see
if it should return 1 instead.

Swift SVN r13176
2014-01-30 22:42:18 +00:00
Nadav Rotem
230842221e Move the code motion optimizations into a new pass. NFC.
Swift SVN r13150
2014-01-30 17:32:57 +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
Mark Lacey
5e40837b62 Always pass an llvm::Module* to performIRGeneration().
Previously it would create a new module if one was not passed in. There
are no uses where we do not or cannot provide a module, so it seems
reasonable to make the interface consistently require a module.

Swift SVN r13016
2014-01-27 23:48:49 +00:00
Michael Gottesman
49b0668831 Remove alloc_ref with simple destructors and only store users.
This pass attempts to remove alloc_ref and everything that uses the alloc_ref
if:

1. The alloc_ref has a destructor which we can very does not have escaping side
effects.
2. The alloc_ref does not have any non-trivial uses that are not stores.

It reduces ObjInst on my cpu from 10206922128 ns to 46 ns (i.e. nothing).

Swift SVN r12990
2014-01-27 08:59:20 +00:00
Jordan Rose
cf1bb3634f Allow Selector and ObjCBool in @objc methods.
...and update the print-as-ObjC type printer to handle them. IRGen and
@encode changes to come from Mark and Fariborz, presumably.

Swift SVN r12938
2014-01-24 22:27:36 +00:00
Connor Wakamo
cc7d62ecca [driver] Implemented a new "swift_driver -transform-ir" integrated tool.
This tool implements support for running IR transformations; in particular, it
replaces the functionality supported by "swift -arc-optimize" and
"swift -arc-transform".

No tests yet, but this will be used by several tests once we complete the
transition to the new driver.

Swift SVN r12927
2014-01-24 19:20:40 +00:00
Jordan Rose
76c04132c0 [driver] In -g mode, create the __SWIFT,__ast section used by the debugger.
The section contains a copy of the serialized module for the binary.

Swift SVN r12924
2014-01-24 18:42:08 +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
Joe Groff
28c1d340b5 Remove SIL 'StripRuntimeChecks' pass.
Without build configurations we can't strip runtime checks from the SIL without also disable diagnostics for library users. We're going to try a different stopgap approach of not emitting the runtime checks in IRGen for the short term.

Swift SVN r12586
2014-01-20 17:06:00 +00:00
Connor Wakamo
f5d1f5c0d9 [frontend] Added support for -i in the integrated frontend.
Updated frontend_main() and performCompile() to not reject
FrontendOptions::Immediate and instead call RunImmediately() with the correct
IRGenOptions.

Swift SVN r12522
2014-01-18 00:55:46 +00:00
Connor Wakamo
7043cab15f [frontend] Updated assertion message.
Swift SVN r12521
2014-01-18 00:55:46 +00:00
Connor Wakamo
1a3fe6af86 [frontend] Added support for -repl in the integrated frontend.
Updated the swift_driver target so that it links against swiftImmediate and
CoreFoundation.

Updated frontend_main() and performCompile() to not reject FrontendOptions::REPL
and instead call REPLRunLoop().

Swift SVN r12520
2014-01-18 00:55:45 +00:00
Connor Wakamo
8fc6a6d599 [immediate] Moved the support for immediate and REPL modes into a new swiftImmediate library.
In order to implement immediate and REPL modes in swift_driver, this functionality
needs to be in a library (instead of directly in the swift executable).

Swift SVN r12519
2014-01-18 00:55:45 +00:00
Chris Lattner
17d9bf24bf Make DeclContext dump()’able from the debugger. Unmark Decl’s dump method as “Deprecated and only used by the debugger”. This isn’t doing anything useful since the implementation is used by live code anyway.
Swift SVN r12506
2014-01-17 22:07:35 +00:00
Jordan Rose
8cf19bf152 Don't set a default SDK in the new driver, either.
Goes with r12414.

Swift SVN r12439
2014-01-17 00:15:15 +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
Michael Gottesman
3988374855 [sil-strip-debug-info] Added new pass that strips out debug info. Only runs via sil-opt.
The muse hit me.

Swift SVN r12392
2014-01-16 05:14:12 +00:00
Joe Groff
197a1653fd SIL: Start on a StripRuntimeChecks pass.
In the long term we want more detailed configurability of runtime checks, but for our short-term performance work we just want a blanket on/off switch. Add a StripRuntimeChecks SIL pass that, as a start, converts invocations of checked overflow builtins to the equivalent unchecked builtins and kills cond_fails. Expose it through the compiler with a -disable-all-runtime-checks switch.

NB: I haven't tested building the stdlib or running the tests with the switch thrown yet.

Swift SVN r12379
2014-01-16 02:35:16 +00:00
Connor Wakamo
3a1810336e [frontend] Implement support for emitting modules with the integrated frontend.
Added support for the -emit-module and -module-output-path options. -emit-module
and -module-output-path function similarly to -serialize-diagnostics and
-serialized-diagnostics-path: notably, -module-output-path implies -emit-module,
but -emit-module can be passed without -module-output-path and a default path
will be determined based on other inputs.

Added support for the -module-link-name option, which specifies the name of the
library to link against when importing the generated module.

Note that support for these options is only implemented in the integrated
frontend; driver-level support for these options is forthcoming.

Swift SVN r12301
2014-01-14 23:38:36 +00:00
Michael Gottesman
ae3b999925 Recommit "Very initial ARC optimizer implementation."
This recommits r12264 with the necessary changes to fix a bad thinko.

Swift SVN r12272
2014-01-14 03:08:52 +00:00
Dave Abrahams
9f99f02b24 Revert "Very initial ARC optimizer implementation."
This reverts commit r12264, which was breaking tests for me

Swift SVN r12270
2014-01-14 02:35:32 +00:00
Michael Gottesman
3650a75c99 Very initial ARC optimizer implementation.
For simplicity it currently only moves copy_values, strong_retains since we are
not doing the data flow analysis yet.

Even with its limitations (which are extreme), we are removing ~400
retain/release/copyvalue/destroyvalue pairs from the standard library.

Additionally we reduce the time RC4 takes from 7.5-5.5 (2 second delta).

Swift SVN r12264
2014-01-14 01:09:00 +00:00
Connor Wakamo
00f076daa5 [frontend] Implemented support for emitting serialized diagnostics.
Reworked the -serialize-diagnostics option, so that it is now just a flag
indicating that the frontend should generate serialized diagnostics. The path at
which the diagnostics will be serialized is now specified by the
-serialized-diagnostics-path option, which is a frontend-only option. (The
frontend treats -serialized-diagnostics-path as implying -serialize-diagnostics.)

If -serialize-diagnostics is passed but -serialized-diagnostics-path is not
passed, the frontend will choose an output path from a few default values:

- If the frontend has a non-stdout output path, replace that path's extension
  with .dia.
- If there is a primary input filename, use that input's base name as the base
  name for the serialized diagnostics file.
- Otherwise, use the module name as the base name for the serialized diagnostics
  file.

Added support for setting up a serialized diagnostics DiagnosticConsumer in
frontend_main() if FrontendOptions::SerializedDiagnosticsPath is non-empty.

Swift SVN r12251
2014-01-13 21:38:03 +00:00
Nadav Rotem
970c387c34 Refactor devirt related optimizations from sil-combine into a new pass.
The reason is that I would like to add more sophisticated analysis and a
chache, which does not fit into sil-combine very well.



Swift SVN r12221
2014-01-13 07:34:25 +00:00
Dave Zarzycki
3339caddee REPL: Yank the line continuation character
Yes, the current REPL is going away, but it will serve as a model for
the future replacement. The Swift grammar doesn't need this crutch and
the replacement shouldn't be tempted to replicate it.

Swift SVN r12205
2014-01-11 23:14:13 +00:00
Dave Zarzycki
68003c6ae6 REPL: fix unrelated bug found during last commit
We're scanning _backwards_, not forwards to figure out if we have an
unfinished infix expression.

Swift SVN r12204
2014-01-11 22:33:59 +00:00
Dave Zarzycki
b3fa123bd0 REPL: Quick hack to enable better multi-line input history
Hitting 'up arrow' after an error does something far more reasonable now.

EXAMPLE:
	(swift) struct Foo {
			  var a:
			}
	<REPL Input>:2:9: error: expected type
	  var a:
			^
AFTER HITTING 'UP ARROW':
	(swift) struct Foo {
	var a:
	}

Swift SVN r12203
2014-01-11 21:57:46 +00:00
Jordan Rose
11d2e9282b [swift2objc] Print arbitrary class metatypes as "SWIFT_METATYPE(MyClass)"
...and then define SWIFT_METATYPE(X) as a macro for "Class", because
Objective-C doesn't have a way to constrain class types to a certain
hierarchy.

With this change, we should handle every type that makes it through the
@objc validator today.

Swift SVN r12190
2014-01-11 01:39:08 +00:00
Jordan Rose
e4684ddb1a [swift2objc] Handle block types.
C's wonderful declarator syntax makes this rather non-trivial. I've chosen
to implement this by pushing cleanups that will get called at the end of
a "full type", in reverse order.

With much thanks to cdecl.org (created by Peter Ammon from the AppKit team).

Swift SVN r12189
2014-01-11 01:39:08 +00:00
Jordan Rose
9a4a560cfc [swift2objc] Re-order types to be closer to TypeNodes.def.
...but still not exactly in sync, to keep similar bits of code together.

No functionality change.

Swift SVN r12188
2014-01-11 01:39:05 +00:00
Jordan Rose
1a024c1c75 [swift2objc] Handle UnsafePointer.
The @objc validator still rejects UnsafePointers of any non-mapped type,
so things like "NSRect *" and "MyClass **" get rejected, but this code
will do the right thing for those as well.

Swift SVN r12170
2014-01-11 00:02:46 +00:00
Jordan Rose
9f56b54ece [swift2objc] Handle imported enums.
We assume the enum is safe if it got this far.

Swift SVN r12169
2014-01-11 00:02:46 +00:00
Jordan Rose
710e43d7df [swift2objc] Fix bug with protocol composition metatypes: Class, not id!
Swift SVN r12168
2014-01-11 00:02:45 +00:00
Jordan Rose
31e6108304 [swift2objc] Look through ParenTypes (and substituted and syntax-sugar types)
The latter two can't show up right now but if they ever become valid we
should just ignore them.

Swift SVN r12167
2014-01-11 00:02:42 +00:00
Jordan Rose
1213b52e10 [swift2objc] Add COpaquePointer -> void * mapping.
Also, drop special cases for AnyObject and AnyClass; they are handled as
DynamicLookup and DynamicLookup.metatype.

Swift SVN r12163
2014-01-10 23:14:31 +00:00
Jordan Rose
ddada62075 [swift2objc] Handle protocol and protocol composition types.
These get translated as "id <MyProto>" and "id <MyProto, OtherProto>",
of course. There's special handling for protocol metatypes so that we get
"Class <MyProto>". (Objective-C doesn't have any other way to specify what
operations are available on a particular Class, so this is pretty important!)

Swift SVN r12162
2014-01-10 23:14:28 +00:00
Connor Wakamo
c5af8e0269 [frontend] Implement support for primary file mode for post-PrintAST actions.
This, in concert with the driver-level changes to pass -primary-file, enables proper multi-file output in swift_driver.

Swift SVN r12158
2014-01-10 22:39:08 +00:00
Connor Wakamo
5d9e2461ce [frontend] Updated -dump-parse, -dump-ast, and -print-ast to operate on the primary input, if one is specified.
Other modes to follow.

Swift SVN r12157
2014-01-10 22:39:08 +00:00
Jordan Rose
17dfc5979a [swift2objc] Print class types for arguments and return values as "Foo *".
This just assumes the class has already been declared. The next step here
is to add something that walks all of the referenced types /before/ starting
to print the @interface, and makes sure they've been defined or at least
forward-declared.

Swift SVN r12087
2014-01-09 01:20:04 +00:00
Jordan Rose
d58d4835c1 [swift2objc] Handle structs and typealiases that represent ObjC primitives.
...by matching their names in the standard library.

Swift SVN r12085
2014-01-09 01:20:03 +00:00
Jordan Rose
06d1d6a49a [swift2objc] Start printing members (only methods for now).
There is code here to print an entire Objective-C method, but the only type
that's handled is (), so we can't test that yet.

Swift SVN r12084
2014-01-09 01:20:02 +00:00
Jordan Rose
37a578ad0b [swift2objc] Sort output for determinism reasons.
If Module::getTopLevelDecls ever becomes guaranteed to be deterministic,
we can drop this sort.

Swift SVN r12083
2014-01-09 01:20:01 +00:00
Jordan Rose
f83df8c047 [swift2objc] Pull printing code into an ASTVisitor, like the Swift ASTPrinter.
No functionality change.

Swift SVN r12082
2014-01-09 01:19:57 +00:00
Jordan Rose
37e2e1de0e Merge swift2objc (the tool) into swift-ide-test, as -print-as-objc.
The actual printing should move to a library at some point, but for now this
keeps us from having to link Yet Another Testing Binary.

Swift SVN r12034
2014-01-08 02:19:03 +00:00
Jordan Rose
f09cd93194 [autolinking] Hack: autolink any module containing external definitions.
We're still synthesizing external definitions too eagerly, and things
getting pulled in only through submodules aren't getting properly autolinked.
(That is, AppKit imports <QuartzCore/CIImage.h> but doesn't think that
QuartzCore is visible, because it isn't.)

The first right answer is to detect that a part of QuartzCore is visible even
though the whole thing isn't. The second right answer is to properly handle
Clang submodules as real modules---there are a lot of rough edges there.
<rdar://problem/13140302>. The third right answer is that we shouldn't even
emit references to these symbols until the /user/ needs them.

And what I'm doing now is just to attempt to link to every module that we've
synthesized thunks for.

<rdar://problem/15754311>

Swift SVN r12031
2014-01-08 01:52:24 +00:00