Commit Graph

6196 Commits

Author SHA1 Message Date
Doug Gregor
78f722558c Fix weird spacing
Swift SVN r5495
2013-06-06 18:54:18 +00:00
Doug Gregor
452f9562e1 [Clang importer] Only import prototyped functions.
Unprototyped C functions can't sensibly be reflected in the Swift type
system, and are awful besides, so don't import them. Then, always go
through importFunctionType to import function types, fixing the
missing pattern in <rdar://problem/13992215>.


Swift SVN r5494
2013-06-06 18:34:46 +00:00
Doug Gregor
87965ac319 When the index types of an Objective-C class's subscript getter and setter mismatch, don't build thunks for either.
Previously, we would build an invalid AST for the getter.


Swift SVN r5434
2013-06-03 18:23:48 +00:00
Joe Groff
12c5999b44 Strip out -no-nsstring-is-string flag and associated LangOptions bit.
Swift SVN r5383
2013-05-29 19:42:12 +00:00
Doug Gregor
5e2619802d Tighten up the semantics of unchecked downcasts (x as! T).
Explicit detect (and reject) conversions that aren't class
downcasts. We'll want to lift some of these restrictions later (see
<rdar://problem/14013456>), but for now we just reject them with a
decent diagnostic (rather than crashing).

When an explicit downcast is actually just a coercion, complain,
provide a Fix-It, and update the AST appropriately.

This also splits the checking of unchecked downcasts into two different
constraint systems: one for the context of expression, and one for the
subexpression, then compares the results. This eliminates the need to
model "can be downcast to" in the constraint solver, and makes it
easier to provide good diagnostics.



Swift SVN r5377
2013-05-29 17:48:43 +00:00
Joe Groff
11c7a3a92d ClangImporter: Bridge NSString objc properties to String properties.
We had an inconsistency where the synthesized Swift getter/setters were bridged but the VarDecl wasn't, causing assertion failures in SILGen.

Swift SVN r5366
2013-05-28 22:53:14 +00:00
Doug Gregor
1641477826 Eliminate lookupExtensions() and the extension cache.
This infrastructure has been replaced by the extension list on nominal
declaration, which is simpler and more efficient.


Swift SVN r5225
2013-05-20 18:26:07 +00:00
Doug Gregor
8114ce16f8 Use the list of extensions of a nominal type for name lookup into that type.
This replaces the obscure, inefficient lookup into extensions with
something more straightforward: walk all of the known extensions
(available as a simple list), then eliminate any declarations that
have been shadowed by other declarations. The shadowing rules still
need to consider the module re-export DAG, but we'll leave that for
later.

As part of this, keep track of the last time we loaded extensions for
a given nominal type. If the list of extensions is out-of-date with
respect to the global generation count (which tracks resolved module
imports), ask the modules to load any additional extensions. Only the
Clang module importer can currently load extensions in this manner.


Swift SVN r5223
2013-05-20 18:06:51 +00:00
Doug Gregor
dbdc9db90a Keep track of the extensions associated with a nominal type declaration.
Switch the REPL's printing of extensions to use this mechanism, mostly
as a sanity check.



Swift SVN r5221
2013-05-20 15:23:16 +00:00
Doug Gregor
4d60bb7173 Implement trailing closure syntax.
Trailing closure syntax allows one to write a closure following any
other postfix expression, which passes the closure to that postfix
expression as an arguments. For example:

        sort(fruits) { |lhs, rhs|
          print("Comparing \(lhs) to \(rhs)\n")
          return lhs > rhs
        }

As a temporary limitation to work around the ambiguity with

  if foo { ... } { ... }

we require trailing closures to have an explicit parameter list, e.g.,

  if foo { || ... } { ... }



Swift SVN r5210
2013-05-17 19:16:18 +00:00
Jordan Rose
ca498e04ef More -Wdocumentation cleanup.
Swift SVN r5167
2013-05-13 21:41:28 +00:00
Joe Groff
e1c838962e Revert "Remove [objc_block] attribute from Swift type system."
Implementing SIL bridging is going to take more IRGen work than I anticipated.

Swift SVN r5113
2013-05-09 16:32:18 +00:00
Jordan Rose
7bea410369 Introduce a LoadedModule base class for ClangModule and SerializedModule.
This keeps AST insulated from the various module-loading interfaces, which
minimizes special-casing of the differences between ClangModule and the
(upcoming) SerializedModule.

Swift SVN r5096
2013-05-08 18:33:36 +00:00
Jordan Rose
ccae995f61 Use a list of module loaders instead of a single Clang importer.
This paves the way for having a Swift module importer. The eventual goal
here is to eliminate all explicit uses of the Clang module loader, but
I'm not going to push too hard on that for now.

Swift SVN r5092
2013-05-08 18:09:33 +00:00
Joe Groff
38f13e56f5 Remove [objc_block] attribute from Swift type system.
We will handle Swift-function-to-ObjC-block bridging in SILGen as part of general Cocoa-to-Swift type bridging. Temporarily disable building swiftAppKit and tests that exercise block bridging until the new implementation lands.

Swift SVN r5090
2013-05-08 16:52:12 +00:00
Doug Gregor
01e1240b35 [Clang Importer] Map NSString* function parameters/results to String.
This is the trivial part of <rdar://problem/13723763>, which performs
an import-time remapping of NSString* to String. Because this change
completele breaks IR generation, it is under the off-by-default flag
-nsstring-is-string.


Swift SVN r5058
2013-05-06 20:07:42 +00:00
Doug Gregor
9a70c0ebf4 [Clang Importer] Refactor the handling of type import contexts.
The importer has always imported types differently in different
places, e.g., function parameter types have special rules for C++
references. Formalize this notion a bit, and make it work properly
when dealing with typedefs where the underlying type itself might be
imported differently in different contexts. 

As part of this, limit the import of C's 'void' type to the result of
a function type.


Swift SVN r5055
2013-05-06 18:10:46 +00:00
Doug Gregor
0f6b7a9d22 Rework our handling of "external" definitions created by the Clang importer.
Keep track of external definitions as they are created by broadcasting
them through a mutation listener interface. At name binding time, we
just cache them. When a type checker is alive, it immediately performs
any additional operations necessary on those types (e.g., declaring
implicit constructors).

This also eliminates some O(N^2) behavior in the type checker as well,
because we don't have to walk through all of the module imports to
find the external definitions. We just keep a single list in the
ASTContext along with our place in the list.

Fixes <rdar://problem/13769497>.


Swift SVN r5032
2013-05-03 00:24:34 +00:00
Doug Gregor
f3bb94c166 Clang importer: look through macros that simply expand to another macro.
This allows us to import FOO in the following example:

  #define FOO BAR
  #define BAR 5

Fixes <rdar://problem/13768957>.


Swift SVN r5001
2013-04-30 20:25:56 +00:00
Doug Gregor
d94bb268b8 Introduce implicit constructors for imported structs in the type checker.
Previously, the Clang importer would synthesize the memberwise
constructor itself, but not a default constructor. Eliminate the
redundant code path and provide correct semantics for the second by
letting the type checker introduce the implicitly-defined constructors
itself.





Swift SVN r4973
2013-04-29 17:36:11 +00:00
Joe Groff
2b220bcc9d ClangImporter: Work around reentrancy bug importing enum constants.
When importing an enum constant, we import its enum type, which then recursively imports the same enum constant, returns, and finishes importing the enum constant--again. Oops. Hack around this by re-checking for a cached imported definition for an enum constant after importing its type.

Swift SVN r4963
2013-04-28 03:32:35 +00:00
Joe Groff
35f81da656 ClangImporter: Suppress importing no-argument constructors besides 'init'.
NSAppleEventDescriptor has multiple "default" init methods, -init, -initRecordDescriptor, and -initListDescriptor, and they were all getting imported as default constructors in Swift. I don't know what the right thing to do long-term about init methods like these, but short-term I think we can get away with suppressing them.

Swift SVN r4962
2013-04-28 03:32:33 +00:00
Doug Gregor
ce0d0aeda2 Use the same module cache directory as Clang
Swift SVN r4927
2013-04-26 22:08:54 +00:00
Doug Gregor
c057b21193 Ban the use of construction syntax T(x) for coercions and unchecked downcasts.
Use "x as T" for coercions and "x as! T" for unchecked downcasts.


Swift SVN r4683
2013-04-11 21:17:47 +00:00
Doug Gregor
34d6fc944e Fix 80-column violation.
Swift SVN r4639
2013-04-09 21:43:05 +00:00
Doug Gregor
7ab788244f Sync up with Clang API changes when accessing macros.
Swift SVN r4494
2013-03-27 17:48:58 +00:00
Doug Gregor
f43ecceadd <rdar://problem/13037793> Remove the "ObjectiveC" module name hack now that Clang doesn't need it (per Clang r177621).
Unfortunately, we're replacing that hack with a different hack to work
around the complete lack of mapping from Swift source locations to
Clang source locations.


Swift SVN r4460
2013-03-21 01:29:17 +00:00
Doug Gregor
774b454e0d Fake a source location to pass to Clang when asking it to load a module
Swift SVN r4458
2013-03-20 23:17:43 +00:00
Joe Groff
aa6c506f58 Add '[thin]' attribute to function types.
Some SIL operations only make sense on no-context functions, such as creating a context for a function with "curry" or specializing. We're going to need this concept in Swift for interop with C functions too, so I'm adding it to the Swift type system. This patch only adds the attribute bit to function types without exposing the attribute to Swift syntax or providing any means in Swift to produce values of thin function type or to type-check them.

Swift SVN r4416
2013-03-18 19:59:39 +00:00
Joe Groff
2e15d99e80 CMake: Install Clang headers.
Move the path for the Clang headers to lib/swift/clang since that's a place swift can find them either in the build dir or in an installation. Arrange for the headers out of the Clang build dir to be installed in the Swift tree.

Swift SVN r4296
2013-03-06 01:29:49 +00:00
Joe Groff
fdcd04cbc1 ClangImporter: Update constructor import comments.
We don't import 'new'-family methods as Swift ctors anymore.

Swift SVN r4287
2013-03-05 21:39:40 +00:00
Joe Groff
23aaa56143 IRGen: Emit type metadata for Clang structs.
We need type metadata symbols for Clang structs so that they have witness tables and can conform to protocols (or be part of structs that conform to protocols). Consider Clang struct metadata to be 'isClangThunk' like other Clang-emitted definitions so that it all gets linkonce_odr'ed to avoid linker issues when multiple TUs import the same modules. Fixes <rdar://problem/13187143>.

Swift SVN r4170
2013-02-23 21:13:50 +00:00
Joe Groff
67748972b7 ClangImporter: Value ctors for imported structs.
Emit a value constructor for imported structs so that stuff like NSRect(NSPoint(x, y), NSSize(w, h)) works.

Swift SVN r4168
2013-02-23 20:11:05 +00:00
Doug Gregor
6adc44dac1 Fix for Clang r175585
Swift SVN r4106
2013-02-20 17:56:58 +00:00
Doug Gregor
7cc1b6341e Map 64-bit anonymous enums and their enumerators to Int.
Following up on the NS(U)Integer -> Int mapping change, also map
64-bit anonymous enums and their enumerators to Int rather than
directly mapping the underlying integer type. This improves
interoperability with NSInteger types, allowing (e.g.) comparisons of
NSIntegers to NSNotFound.


Swift SVN r4089
2013-02-19 23:04:29 +00:00
Doug Gregor
e6880810ac Map NS(U)Integer to Int in the module importer.
This makes NS(U)Integers fit better with more Swift code, although
it's unfortunate that NSNotFound doesn't get the right type. 


Swift SVN r4088
2013-02-19 22:41:46 +00:00
Joe Groff
74589d788e Make ObjC-ness implicit to ObjC-inherited classes.
Add 'isObjC' as a property of ValueDecl, and set it during type checking if a class is either explicitly annotated with an [objc] attribute or inherits from an isObjC class, or if a func is a method of an isObjC class. Tweak the ClangImporter and other places that summon magic ValueDecl nodes to set up the decls they synthesize as isObjC. Replace logic in typechecking and IRGen that branched on the 'isObjC' attribute to now branch on the 'isObjC' property of ValueDecls.

Swift SVN r4078
2013-02-19 02:11:09 +00:00
Doug Gregor
7ff6df658c Remove unused variable
Swift SVN r4074
2013-02-18 19:19:11 +00:00
Doug Gregor
8ffd2d4df0 Always rely on Clang lookups, not Swift lookups, to establish method overrides for imported methods.
r4035 introduced overridden-method searches into the Clang importer by
looking into the Swift declarations. However, because Objective-C
allows forward declarations, there's no order in which we could
populate the Swift declarations to ensure that all of the appropriate
overrides were found. Instead, we do the right (and lazy) thing of
performing the lookup within Clang, then importing the results. This
change also introduces caching for mirrored protocol imports, so they
can be imported lazily.

Fixes <rdar://problem/13219096>.



Swift SVN r4072
2013-02-18 19:14:56 +00:00
Joe Groff
bd59da3e9e REPL: Find completions from Clang modules.
Integrating Clang's FindVisibleDecls with Swift's by importing every decl created too much per-repl-entry compile time overhead, so as a workaround, just wire completions directly to FindVisibleDecls on the clang translation unit itself. Unfortunately this means we get completions for things Swift can't import yet, but it also means we don't have to wait 30 seconds to compile every entry after doing a completion.

Swift SVN r4061
2013-02-15 22:30:29 +00:00
Joe Groff
d97bc08191 ClangImporter: Map void*/opaque* to COpaquePointer
We should eventually import opaque struct pointers as something more type-safe. For now, this at least makes a good chunk of CoreFoundation available to Swift.

Swift SVN r4051
2013-02-14 22:26:19 +00:00
Doug Gregor
5c26e6cc3d Make sure that the output stream gets flushed before forming the result of getObjCSelector().
Swift SVN r4037
2013-02-13 21:03:11 +00:00
Doug Gregor
b660580f35 Don't permit calling static methods on an instance <rdar://problem/13206762>.
Swift SVN r4033
2013-02-13 19:27:39 +00:00
Doug Gregor
949067001a Don't import 'true' or 'false' from Clang modules <rdar://problem/13187570>.
Swift SVN r4028
2013-02-13 13:56:31 +00:00
Joe Groff
bbc8ebfd7a ClangImporter: Temporarily import id<Proto> as id.
Because of <rdar://problem/13163979> we can't usefully use values of ObjC protocol type yet.

Swift SVN r4004
2013-02-10 05:51:32 +00:00
Jordan Rose
67eaa1abb4 Silence -Wunused-variable warnings.
No functionality change.

Swift SVN r3988
2013-02-08 00:19:54 +00:00
Joe Groff
55997e255c ClangImporter: Update for Clang options change.
'-fmodule-cache-path foo' became '-fmodules-cache-path=foo' upstream.

Swift SVN r3982
2013-02-07 22:19:03 +00:00
Dave Zarzycki
dc73148ce2 Fix the buildbot failure
Swift SVN r3980
2013-02-07 21:46:32 +00:00
Doug Gregor
32855fa161 Handle negation in imported constants, for both macros and enumerators.
Swift SVN r3963
2013-02-06 01:35:04 +00:00
Doug Gregor
a9a90fd56a Track the Clang macros that were used to generate Swift constants.
Swift SVN r3960
2013-02-06 00:57:03 +00:00