Commit Graph

1704 Commits

Author SHA1 Message Date
Joe Groff
b256ccf467 Switch to native blocks codegen.
Swift SVN r16484
2014-04-18 01:07:12 +00:00
Doug Gregor
f56c68386e Start importing factory methods as initializers.
When an Objective-C class method follows the naming convention of a
factory method, i.e., its starting words match the ending words of the
class name, import it as a convenience initializer when it also:
  - Returns instancetype (i.e., dynamic Self in Swift parlance)
  - Has no NSError** parameters, which indicate the potential for failures

This is under a new flag (-enable-objc-factory-method-constructors)
because it is not generally functional. However, this is a step toward
<rdar://problem/16509024>.

Swift SVN r16479
2014-04-17 23:34:00 +00:00
Doug Gregor
5698fd3b8a Don't look in the standard import locations when building the core standard library.
This is a better way to fix the Darwin overlay <-> swift_stdlib_core
inferred circular dependency <rdar://problem/16603168>.

Swift SVN r16476
2014-04-17 22:07:48 +00:00
Doug Gregor
96bc99e3c4 Revert "Add a flag -ignore-overlays to ignore overlays, and use it when building the standard library."
This reverts commit r16383.

Swift SVN r16475
2014-04-17 22:07:47 +00:00
Arnold Schwaighofer
97892b1cfa Frontend: Add OFast flag
The optimization level -OFast disables runtime checks (overflow, type checks)
and assertions.

rdar://16458612

Swift SVN r16474
2014-04-17 22:05:44 +00:00
Arnold Schwaighofer
45ffb41adf Remove AssertDebug hack and fixup make files
When we build the standard libary with -parse-stdlib the frontend sets the
assert configuration to 'DisableReplacement'. Constant replacement does not take
place and the call to the builtin function 'assert_configuration' call stays in
the serialize SIL of the swiftmodule.

IRGen replaces the function call to the assert_configuration builtin function by
the value for Debug (0). The resuling standard library dylib hence contains the
debug version of the standard library assert function.

Frontend optimization flags can now determine whether asserts should be executed
or not.

This commit removes the SWIFT_ASSERTS cmake flag.

rdar://16458612

Swift SVN r16473
2014-04-17 22:05:43 +00:00
Arnold Schwaighofer
989d554a45 Add support for an assert_configuration builtin function
This patch adds support for a builtin function assert_configuration that is
replaced by constant progpagation by an appropriate value dependent on a compile
time setting. This replacement can also be disabled when serializing sil for a
library.

Using this mechanism we implement assertions that can  be disabled (or whose
behavior changes) depending on compile time build settings (Debug, Release,
DisableReplacement).

In the standard library we can now write one assert function that uses this
builtin function to provide different compile time selectable runtime behavior.

Example

Assert.swift:

@transparent
func assert<T : LogicValue>(
  condition: @auto_closure () -> T, message: StaticString = StaticString(),

  // Do not supply these parameters explicitly; they will be filled in
  // by the compiler and aren't even present when asserts are disabled
  file: StaticString = __FILE__, line: UWord = __LINE__
) {
  // Only in debug mode.
  if _isDebug() {
    assert(condition().getLogicValue(), message, file, line)
  }
}

AssertCommon.swift:

@transparent
func _isDebug() -> Bool {
  return Int32(Builtin.assert_configuration()) == 0;
}

rdar://16458612

Swift SVN r16472
2014-04-17 22:05:42 +00:00
Arnold Schwaighofer
527a3149a8 Remove duplicate code accidently introduced by r16447.
Swift SVN r16471
2014-04-17 22:05:41 +00:00
John McCall
3cf3f42e98 When targeting arm64-apple-ios, the target CPU is cyclone,
which provides the Neon feature.  Do all the necessary
plumbing to get this from the driver to the backend.

Also, support -arch arm64, and diagnose bad -arch values
instead of silently ignoring them.  It's not clear to me
that we really want to support -arch as an alternative
to -target, but unless we rip it out or establish some
sort of real policy about it, it really ought to do
something approximating the right thing.

It would be nice if we could abstract enough of clang's
driver that we could re-use some of its basic logic about
tool chains and targets instaed of iteratively
rediscovering everything it does that's actually
critically important.

Swift SVN r16447
2014-04-17 06:36:03 +00:00
Doug Gregor
f384cbfe63 Add a flag -ignore-overlays to ignore overlays, and use it when building the standard library.
Fixes <rdar://problem/16603168>. This was way too much engineering
effort to ban fork() and vfork().

Swift SVN r16383
2014-04-16 00:02:38 +00:00
Joe Groff
920aa60570 Add a frontend option -enable-native-blocks to stage native block generation.
Swift SVN r16372
2014-04-15 17:51:08 +00:00
Doug Gregor
2d28d70bf8 Remove the language/driver/frontend options to enable/disable mangled names for the ObjC runtime.
Burn the bridges!


Swift SVN r16277
2014-04-13 05:36:08 +00:00
Joe Groff
42a942925b Enable block bridging.
Swift SVN r16248
2014-04-12 05:13:45 +00:00
Ted Kremenek
2d4342b87a Give an error if “@obj” is used without importing ObjectiveC.
The standard library is exemptmpt (-parse-stdlib) from this checking.

Implements <rdar://problem/16559137>.

Swift SVN r16155
2014-04-10 09:08:09 +00:00
Joe Groff
4e789a09f7 Add an -enable-block-bridging frontend option we can hide disruptive changes to block bridging behind.
Swift SVN r16043
2014-04-08 02:43:19 +00:00
Jordan Rose
835bfb15a9 [ClangImporter] Add an option (off by default) to infer "implicit properties".
In Objective-C, any method with no arguments can be used with dot syntax, as
can any method that takes one argument whose name starts with "set". This
commit adds a frontend-only flag -enable-objc-implicit-properties to look for
"setter-like" methods that match up with "getter-like" methods to import them
as Swift properties. By default, such methods are just considered unrelated
methods.

Part of <rdar://problem/16215476>

Swift SVN r16025
2014-04-07 21:49:37 +00:00
Doug Gregor
781adc047e Add a *temporary* build configuration option for selector splitting.
Swift SVN r15880
2014-04-03 17:07:38 +00:00
Doug Gregor
6496d69cb8 Simplify down to a single command-line option for preposition splitting.
Swift SVN r15835
2014-04-02 21:44:19 +00:00
John McCall
c163b30f1e Enable importing ObjC pointers as UncheckedOptional.
There's no point in maintaining a driver option for this
because of the extent of the library changes required to
make it work.

Swift SVN r15784
2014-04-02 09:37:16 +00:00
Doug Gregor
9400e890d3 Emit @objc classes using namespaced names under a new flag -enable-objc-mangling.
Centralize the logic for figuring out what name to use for a class or
protocol in the Objective-C runtime. When the flag is enabled (it's
still disabled by default), use mangled names for all Swift-defined
classes, including those that are @objc. Note that the naming is
determined in the AST, because we're also going to use this logic when
printing an Objective-C header for Clang's consumption. The mangled
names will always start with _Tt, so they're easy to recognize and
demangle in various tools or, eventually, in the Objective-C runtime.

The new test (test/IRGen/objc_mangling.sil) is the only test of this
behavior at the moment. The other test changes are due to the
centralized logic tweaking the names of internal constants (_DATA_*,
_CATEGORY_*, etc.).

This is the majority of <rdar://problem/15506580>.



Swift SVN r15588
2014-03-28 23:00:08 +00:00
Ted Kremenek
8162660be6 Wire up basic driver support for App Extension restrictions.
The frontend/driver flag is "-application-extension'.  This
activates a language option which will be used for more restrictive
availability checking.

Operationally, this also passes...
  - "-fapplication-extension" to the clang importer
  - "-application_extension" to ld

Swift SVN r15543
2014-03-27 01:05:43 +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
Argyrios Kyrtzidis
c5f8821410 [Basic/LangOptions] Use unordered_map/unordered_set for the build configuration options.
Swift SVN r15445
2014-03-25 03:55:30 +00:00
Nadav Rotem
5500bdae22 Add a command line flag for removing cond_fails in SIL.
Swift SVN r15432
2014-03-25 00:51:01 +00:00
Doug Gregor
5d0abd9849 Another preposition splitting option: directional prepositions.
Swift SVN r15297
2014-03-20 21:24:57 +00:00
Doug Gregor
b71a67616e Add option to split after the last preposition.
Swift SVN r15264
2014-03-20 04:01:40 +00:00
Doug Gregor
e5fff12bf0 Add option to split Objective-C selectors based on the last preposition.
The frontend option -split-objc-selectors splits the first part of an
Objective-C selector into both a function name and the first parameter
name at the last preposition. For example, this Objective-C method:

  - (NSString *)stringByPaddingToLength:(NSUInteger)newLength withString:(NSString *)padString startingAtIndex:(NSUInteger)padIndex

is imported as

  func stringByPadding toLength(newLength: Int) withString(padString: String) startingAtIndex(padIndex: Int) -> String




Swift SVN r15156
2014-03-17 20:34:48 +00:00
Adrian Prantl
8892a36321 Emit -resource-dir in the DW_AT_APPLE_FLAGS so LLDB can find Swift Shims.
<rdar://problem/16291929> Unable to evaluate trivial expressions in Cocoa apps

Swift SVN r14938
2014-03-12 00:33:59 +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
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
Michael Gottesman
29e1a53bbb [deserialization] Deserialize transparent functions lazily iff they will be used in mandatory inlining.
Swift SVN r14490
2014-02-28 01:05:01 +00:00
Jordan Rose
cadd6edb9d Move EnableObjCOptional to LangOptions (from ClangImporterOptions).
This is a staging option, and I'm about to use it for type-checker changes.

No functionality change.

Swift SVN r14415
2014-02-26 22:15:53 +00:00
Jordan Rose
0f71586952 [ClangImporter] Start importing Objective-C references using UncheckedOptional.
This is hidden behind the frontend flag -enable-objc-optional. Use -Xfrontend
when invoking the Swift driver.

Part of <rdar://problem/15189135>

Swift SVN r14332
2014-02-25 02:04:02 +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
Joe Groff
c0a0a8b584 Add a -sil-opt-pass-count frontend flag.
Until our SIL printing and parsing is robust enough to round-trip, this is useful for bisecting optimizer issues.

Swift SVN r14061
2014-02-18 23:37:25 +00:00
Michael Gottesman
190de1cc6a Add support for option -time-transforms which causes the pass manager to emit time information for each transform run.
Swift SVN r14042
2014-02-18 15:50:17 +00:00
Jordan Rose
93b87edcbe Add -resource-dir option to find lib/swift directory.
This is equivalent to Clang's -fresource-dir; it provides the location of
compiler modules and libraries.

No end-user-visible changes, but the iOS build will no longer have to use
-I to build and test its own standard libraries.

Swift SVN r13888
2014-02-14 01:27:15 +00:00
Jordan Rose
327439f3ab New frontend: use the target triple to find runtime modules and libraries.
We were accepting -target, but not bothering to recompute the runtime
include path, so we always got lib/swift/macosx (the default target's
platform directory). Fix this by always updating the path after all
options have been parsed.

Tests to come in subsequent commits.

<rdar://problem/16052579>

Swift SVN r13887
2014-02-14 01:27:15 +00:00
Jordan Rose
513e6b5b33 Don't use a default argument in a lambda.
This is a Clang extension to C++11, and it's easy enough to not do it.

No functionality change.

Swift SVN r13803
2014-02-12 01:43:55 +00:00
Jordan Rose
798e13d15c Wire up -emit-objc-header[-path] options that don't do anything yet.
These options piggyback on the "merge module" phase of the driver
because the header we output needs an entire complete module.

Swift SVN r13800
2014-02-12 01:19:13 +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
c24a6a7b46 [driver] Disallow "swift" as a module name unless -parse-stdlib is passed.
I didn't bother duplicating this check in -frontend mode. I think that's
acceptable.

<rdar://problem/15083796>

Swift SVN r13759
2014-02-10 22:40:44 +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
John McCall
b095a5efd8 Add -debugger-support to permit the inevitable series of exceptions
and special-cases that we want to permit when parsing for the debugger.

Swift SVN r13754
2014-02-10 18:47:00 +00:00
Jordan Rose
cb83bb02a8 Provide the correct primary file name to IRGenOpts.
Previously, we were always using the first file name as the main source
file name in the debug info, which was completely wrong and led to only
that file having debug info.

<rdar://problem/15786017>, again.

Swift SVN r13665
2014-02-08 00:13:45 +00:00
Andrew Trick
731000b4cd Added -sil-print-all and -sil-verify-all options.
Swift SVN r13662
2014-02-07 23:07:11 +00:00
Connor Wakamo
9df53c5c71 [frontend] Switch -debug-assert-* from llvm_unreachable() to assert(0).
Swift SVN r13656
2014-02-07 22:30:40 +00:00
Connor Wakamo
9747d87ff6 [frontend] Added a handful of options to force the frontend to assert or crash.
Added -debug-assert-immediately and -debug-crash-immediately, which cause an
llvm_unreachable or LLVM_BUILTIN_TRAP to execute during argument parsing.

Added -debug-assert-after-parse and -debug-crash-after-parse, which cause an
llvm_unreachable or LLVM_BUILTIN_TRAP to execute after calling
CompilerInstance::performParse().

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

Swift SVN r13653
2014-02-07 22:03:32 +00:00
Andrew Trick
04b2b5256b First implementation of <rdar://15922760> Deep devirtualization -
specialize on polymorphic arguments.

This can be enabled with: -sil-devirt-threshold 500.

It currently improves RC4 (when enabled) by 20%, but will be much more
important after Michael's load elimination with alias analysis lands.

This implementation is suitable for experimentation. Superficial code
reviews are also welcome. Although be warned that the design is overly
complex and I plan to rewrite it. I initially abandoned the idea of
incrementally specializing one function at a time, thinking that we
need to analyze full chains. However, I since realized after talking
to Nadav that the incremental approach can be made to work. A lot of
book-keeping will go away with that change.

TODO:

- Resolve protocol argument types. Currently we assume they can be
  reinitialized at applies, but I don't think they can unless they are
  @inouts.  This is an issue with the existing local devirtualizer
  that prevents it working across calls.

- Properly mangle the specialized methods. Find existing
  specializations by demangling rather than maintaining a map.

- Rewrite the logic for specializing chains for simplicity.

- Enable by default.

Swift SVN r13642
2014-02-07 19:10:27 +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