Commit Graph

6196 Commits

Author SHA1 Message Date
Jordan Rose
5d2ad6c4d9 [ClangImporter] Import known property accessors with consistent types.
Previously, the getter and setter for a property could disagree on what the
"type of the property" was: Unmanaged<CFType> vs. CFType, or COpaquePointer
vs. CMutableVoidPointer. Now, we treat property accessors as distinct from
normal methods when importing their parameter and result types, and have
those types follow the same rules as they would for the property itself.

This will need a bit of cleanup work once we're importing implicit properties
everywhere, but this handles the crashes and unfortunate limitations we were
seeing for WWDC.

<rdar://problem/16544938>

Swift SVN r17987
2014-05-13 01:32:12 +00:00
Doug Gregor
73528dc0e0 Enable importing factory methods as initializers by default.
Finishes <rdar://problem/16509024>.

Swift SVN r17972
2014-05-12 23:01:20 +00:00
Doug Gregor
2702c943aa When determining whether an imported initializer is a designated initializer, use the context it's being imported into.
Previously, we were using the context where the initializer was declared in Objective-C, rather than where it was being imported. This meant that we wouldn't treat an inherited designated initializer as a designated initializer if (for example) the designated-initializer marking came from our internal table of DIs. Fixes <rdar://problem/16838515>.

Swift SVN r17968
2014-05-12 22:47:38 +00:00
Ted Kremenek
6e83fde849 Suggest ".self", not ".Type" (the old name) for +class remapping.
Swift SVN r17884
2014-05-11 20:28:48 +00:00
Ted Kremenek
4479eb85c0 Import +class and -class as unavailable, suggesting ".type" and ".dynamicType" instead.
Implements <rdar://problem/16871007>.

Swift SVN r17883
2014-05-11 20:22:53 +00:00
Doug Gregor
77ca640d42 Add -objc-bridge-array option to import NSArray* as (AnyObject[])!
This should be the last of the compiler-side functionality for
<rdar://problem/16535097>; we lack any real testing of this.


Swift SVN r17871
2014-05-11 06:29:13 +00:00
Argyrios Kyrtzidis
63ebd0ef8d [ClangImporter] When creating the FileID for the header import buffer, set the main FileID as include location.
SourceManager expects that SourceLocations have the main FileID as parent, except for the predefines buffer.
Fixes assertion hit in a SourceKit test.

Swift SVN r17851
2014-05-10 22:31:29 +00:00
Doug Gregor
ef1c1a8892 Import NSDictionary* as Dictionary<NSObject, AnyObject>.
Note that this is still under -objc-bridge-dictionary, but otherwise
this should be all of the functionality needed for
<rdar://problem/16870626>.

Swift SVN r17848
2014-05-10 21:39:46 +00:00
Joe Groff
3dda4c9cf5 SILGen: Reference ObjC initializers and factories through foreign-to-native thunks.
Eliminate the duplicate half-broken bridging logic in emitClassConstructorAllocator by referencing foreign initializers through their foreign-to-native thunks, which SILGen knows how to emit already. Do the same thing for factory initializers by suppressing their normal allocating initializer codegen and just referencing the usual foreign-to-native thunk for them. This fixes <rdar://problem/16853205> because we get the ownership thunking right now.

Swift SVN r17840
2014-05-10 20:18:53 +00:00
Argyrios Kyrtzidis
19aeaf94fc Fully embrace ParamDecls instead of AnyPattern at function creation time, thus removing the need to create param decls at SILGen or Sema.
Swift SVN r17829
2014-05-10 18:23:50 +00:00
Ted Kremenek
02f8edb20b Revert "Import 'NSError**' in parameters as typealias 'NSErrorResult'."
The outcome is not clear on swift-api-review, and this is breaking
the bots.

Swift SVN r17821
2014-05-10 01:21:11 +00:00
Doug Gregor
d1e8be50be Turn -implicit-objc-with on by default <rdar://problem/16795899>.
Swift SVN r17796
2014-05-09 20:17:42 +00:00
Ted Kremenek
453532ca21 Import 'NSError**' in parameters as typealias 'NSErrorResult'.
Previously 'NSError**' was imported directly as
ObjCMutablePointer<NSError?>, which is verbose and quite ugly
in the synthesized interfaces and overrides.  This remapping
is semantically equivalent by syntactically prettier.

This name needs to go through API review.

The test uses the actual SDK; the clang-importer-sdk didn't work
because the dump of the Foundation module only shows the pieces
from the Swift files, and the Objective-C pieces are just shown
as re-exported modules.  Testing the actual SDK provides good
fidelity anyway.

Swift SVN r17707
2014-05-08 18:46:27 +00:00
Ted Kremenek
3a513a6412 Add 'getFoundationModule()' to ClangImporter::Implementation.
Swift SVN r17706
2014-05-08 18:46:26 +00:00
John McCall
03d3cf9c40 Import the formal type of a property as audited if the
corresponding getter method is audited.

There are a host of other potential consistency problems
here, but this should fix a particular egregious one
that was preventing use of NSColor's CGColor property.

rdar://16846555

Swift SVN r17667
2014-05-08 01:32:25 +00:00
John McCall
c03b705dd0 Recognize CF "subclasses" and require CFTypeRef to specifically
be 'const void *', not just any 'void*'.

Swift SVN r17659
2014-05-08 00:51:27 +00:00
Joe Pamer
d22ffa8cb8 Re-lazify the addition of equatable conformances to imported enum types. (rdar://problem/16808612)
Rather than force conformances to Equatable to be added to all imported enumeration types outright, change them back to being lazily added. We can then handle situations where new overloads of '==' are introduced during constraint generation by re-writing the relevant overload disjunction constraint to include the newly forced declarations as bind options.

Swift SVN r17557
2014-05-06 19:56:29 +00:00
John McCall
cbd662632b Import CFTypeRef as AnyObject, but wrap it in Unmanaged<>
in all the situations that we would wrap e.g. CFStringRef.

Swift SVN r17546
2014-05-06 09:34:24 +00:00
John McCall
a83e5740de Import CF types as managed pointers when they are:
- the type of a const global variable
  - the type of a parameter, always
  - the return type of a function that has been audited
    or has an explicit retained/not-retained attribute
  - the return type of an ObjC method that has an explicit
    retain/not-retained/inner-pointer attribute

Additionally, choose the correct conventions for all
these cases during SIL type lowering.

All this importing logic is still only enabled under
-Xfrontend -import-cf-types.

Swift SVN r17543
2014-05-06 08:29:44 +00:00
Jordan Rose
3e917be738 Use full DeclNames for dynamic lookup of calls.
Previously, we were just using the base name, which resulted in massive
inefficiency when dealing with Clang (we basically had to check every
selector in the system to see if it had the same first selector piece).
I've hacked ConstraintSystem a bit to carry a map from UnresolvedDotExpr
to the ApplyExpr that consumes it, so that we can use the full DeclName
and look up methods by full selector.

Now that dynamic lookup is fast, re-enable it for the
Foundation_bridge.swift test. (r17520 actually provided most of the benefit.)

This does break selector lookup on AnyObject when doing selector splitting,
and slightly regresses diagnostics when you try to call a method on AnyObject
and forget a parameter name.

<rdar://problem/16808651>. Part of the Playground performance efforts.

Swift SVN r17524
2014-05-06 02:35:08 +00:00
Jordan Rose
ed4ad291c5 [ClangImporter] Don't bother running lookups on submodules.
We're only using Clang submodules for their imports and link dependencies;
they don't contain decls right now.

Swift SVN r17520
2014-05-06 02:06:06 +00:00
Joe Groff
e51429eca5 ClangImporter: Guard loadAllMembers with ImportingEntityRAII.
We can enter here without an importing scope if we become more lazy, as can happen when <rdar://problem/16807886> is fixed. Add a regression test that fails when that patch is attached (but not yet on ToT).

Swift SVN r17513
2014-05-06 01:08:09 +00:00
Joe Groff
4a09c9f9dd Add a -print-clang-stats frontend flag.
Prints stats from the Clang importer's ASTReader.

Swift SVN r17512
2014-05-06 01:08:09 +00:00
Jordan Rose
0c46eb821e [ClangImporter] Handle decls declared in imported headers.
This improves the -import-objc-header option to read decls from the header
as well. Any declaration that is not from a module will be considered to be
part of the "header module". Conversely, forward-declarations appearing in
the header will be resolved by looking through all modules responsible for
importing a header.

More of <rdar://problem/16702101>

Swift SVN r17492
2014-05-05 22:52:17 +00:00
Jordan Rose
829d3e6de9 [ClangImporter] Handle macros that use bitshifts, like "(1 << 0)".
<rdar://problem/16202229>

Swift SVN r17462
2014-05-05 17:37:03 +00:00
Jordan Rose
ac15f949d2 [ClangImporter] Import macros that use ~.
This and the previous commit cover <rdar://problem/16521124>.

Swift SVN r17461
2014-05-05 17:37:02 +00:00
Jordan Rose
9e61c4bb62 [ClangImporter] Import NULL, nil, Nil, and ((void*)0) as Swift.nil.
Also, look through one layer of parentheses in general for macros, rather
than special-casing it for each token count.

<rdar://problem/16198517>

Swift SVN r17460
2014-05-05 17:37:00 +00:00
Ted Kremenek
1b2dfb79d4 Hack ClangImporter to *always* import "description", "debugDescription", and "hash" as properties.
This routes around temporary SDK discrepancies.

This change revealed some subtle issues with adding implicit property
definitions.  A big challenge here is that 'description' is defined
in NSObject's protocol, so the implicit property needed to be
generated in all classes that conformed to the protocol.  To make
things more complicated, some classes define 'description' themselves,
so we needed to take care to not generate the same implicit property
twice.

This change reveals a potential bug in the type checker.  This now
crashes:

  func bar(x: String) {
    print(x)
  }

  func foo(x : AnyObject) {
    print(x.description)
  }

but this does not:

  func bar(x: String) {
    print(x)
  }

  func foo(x : NSObject) {
    print(x.description)
  }

This is due to the fact there is a class method "description()" and
a instance property "description" in the lookup on AnyObject.

Swift SVN r17454
2014-05-05 16:37:49 +00:00
Doug Gregor
d255983103 Clang importer: synthesize fromRaw/fromMask w/o any keyword arguments.
Swift SVN r17436
2014-05-05 14:35:18 +00:00
John McCall
2b969c41a2 Track whether a class is "foreign" in the AST.
This basically just means "it's a CF class" for now,
but you could imagine applying this to all sorts of
class-like types from peer runtimes that we can't
support all possible language features for.

There are quite a few language features that require
fairly deep object-model integration to implement,
like subclassing and adding polymorphic methods.
Some of those features, like final classes, are useful
to generally support as attributes, but most of
them aren't.  At least in the short term, it makes
sense to have a big hammer we can hit things with.

Swift SVN r17428
2014-05-05 06:45:40 +00:00
Doug Gregor
1fe794b31a Don't create keyword arguments for the value constructors of imported enums.
NSFooOptions(0) is better than NSFooOptions(value: 0).


Swift SVN r17422
2014-05-05 04:18:07 +00:00
Doug Gregor
eb7a9144a8 Bring keyword arguments to subscripts.
Subscript declarations were still encoding the names of index
variables in the subscript type, which unintentionally made them
keyword arguments. Bring subscript declarations into the modern day,
using compound names to encode the subscript argument names, which
provides consistency for the keyword-argument world
<rdar://problem/14462349>. Note that arguments in subscripts default
to not being keyword arguments, which seems like the right default.

We now get keyword arguments for subscripts, so one can overload
subscripts on the names of the indices, and distinguish at the call
site. Under -strict-keyword-arguments, we require strictness here as well.

The IRGen/IDE/SILGen test updates are because the mangling of common
subscripts changed from accidentally having keyword arguments to not
having keyword arguments.

Swift SVN r17393
2014-05-04 19:31:09 +00:00
Jordan Rose
9d74d25e50 [ClangImporter] Replace one hack to deal with va_list for another.
va_list on i386 and arm64 is a pointer. On armv7, it's a struct that
/contains/ a pointer. But on x86_64, it's an array of one struct element,
which means it decays to a pointer as an argument but not as a variable or
struct field.

This patch:
- Looks for a decayed pointer argument that represents an x86_64 va_list.
- Validates that the va_list on other platforms is at least pointer-sized.
- Uses the decayed (pointer) type when getting the Clang type for
  CVaListPointer.
- Drops the implicit conversion from CVaListPointer to COpaquePointer.

All together, this provides more type-safety for functions using va_list on
x86_64.

Swift SVN r17307
2014-05-03 03:25:20 +00:00
Jordan Rose
2b1a092c27 [ClangImporter] Prefer typedef sugar for blocks even in bridge-able contexts.
We'd rather show dispatch_async as

  // new
  func dispatch_async(queue: dispatch_queue_t!, block: dispatch_block_t!)

than

  // old
  func dispatch_async(queue: dispatch_queue_t!, block: (() -> Void)!)

which was only happening because we were trying to hide the @objc_block
annotation when possible. That's not necessary when we have a typealias.

<rdar://problem/16679280>

Swift SVN r17273
2014-05-02 21:36:59 +00:00
Doug Gregor
4996efbfba Implement support for making "with" implicit on the first argument of an initializer.
When importing an Objective-C init method or factory method into an
initializer, if the first camelCase word of the first argument name
starts with "with", drop the "with". This means that

  -initWithRed:green:blue:alpha:

will get imported into Swift as

  init(red:green:blue:alpha:)

as will

  +colorWithRed:green:blue:alpha:

This is <rdar://problem/16795899>, hidden behind the
-implicit-objc-with flag.

Swift SVN r17271
2014-05-02 21:13:04 +00:00
John McCall
39453cd28e Set up protocol conformances properly for the default
protocols on imported CF types.

This restores r17244.

Swift SVN r17268
2014-05-02 20:17:15 +00:00
Joe Groff
4b327a7805 Revert "Set up protocol conformances properly for the default"
This reverts commit r17244.

Swift SVN r17250
2014-05-02 16:22:37 +00:00
John McCall
046524dd61 Set up protocol conformances properly for the default
protocols on imported CF types.

Swift SVN r17244
2014-05-02 10:50:19 +00:00
Ted Kremenek
4e70269c53 More renaming 'unchecked optional' to 'implicitly unwrapped optional'.
Swift SVN r17236
2014-05-02 06:22:01 +00:00
Ted Kremenek
050fd53af7 Rename UncheckedOptional to ImplicitlyUnwrappedOptional.
Swift SVN r17232
2014-05-02 06:13:57 +00:00
Jordan Rose
cf77de720a Add -import-objc-header option, and wire up the basic infrastructure.
THIS IS NOT READY FOR USE YET.

The new plan for mixed-source non-framework targets is that the Swift
compiler will import an Objective-C header directly, and treat the decls
and imports in that header as explicitly visible to the entire target.
This means users don't have to modularize their headers before bringing
them into Swift.

This commit adds the option and introduces the "imported headers" module
as an implicit import for the source files being compiled. It also directs
the Clang importer to process the given header (using #import, so that it
won't somehow get included twice) and watches for any module imports that
occur as a result of reading that header.

Still to come: import of decls within the header (not within any module),
and proper serialization of cross-references to the header and its imports.

Part of <rdar://problem/16702101>

Swift SVN r17218
2014-05-02 00:55:31 +00:00
Jordan Rose
83e46296d5 [ClangImporter] Constify uses of clang::Module.
No functionality change.

Swift SVN r17216
2014-05-02 00:55:30 +00:00
John McCall
4a0790c072 Do a crazy lookup hack to allow users to write CFString instead
of CFStringRef.

Eventually this should be optimized by generating better
entries in Clang modules.

Swift SVN r17208
2014-05-01 23:29:29 +00:00
John McCall
207fc4db2b Instead of importing CF typedefs as typedefs for Unmanaged<T>,
import them as the underlying class type, then wrap that in
Unmanaged<T>.

Also, trust (and fix) hinting to tell us when to wrap something
in an optional type.

Swift SVN r17207
2014-05-01 23:29:28 +00:00
John McCall
e1bd429cf7 Under -import-cf-types, import
typedef struct __foo *FooRef;
as an Unmanaged<Foo>, where Foo is a class type.

Swift SVN r17206
2014-05-01 23:29:27 +00:00
Jordan Rose
92bcd97d54 [ClangImporter] Don't crash if we have a SWIFT_CLASS but the module is missing.
Also, if the generated header says that a class or protocol is available in
a module, but we can't find it, we should treat the decl as missing rather
than pretending it's a normal Objective-C decl.

Part of <rdar://problem/16776466>

Swift SVN r17175
2014-05-01 20:40:06 +00:00
Doug Gregor
9cfb1b5ca4 Keep track of the locations of the element names in a TupleExpr.
As part of this, use tail allocation to reduce the memory footprint of
TupleExprs. Use factory methods to make it easier to construct.

I'll be using this information in a follow-on patch. SourceKit
probably wants it as well.


Swift SVN r17129
2014-05-01 00:16:36 +00:00
Jordan Rose
3b43187703 [ClangImporter] Strip 'k' prefix even when there is nothing else in common.
<rdar://problem/16768954>

Swift SVN r17126
2014-05-01 00:06:23 +00:00
Jordan Rose
8e44c2ee79 Break "NSUTF16" as "NSUTF, 16", not "NSUT, F16".
Previously, this declaration:

  typedef NS_OPTIONS(NSUInteger, NSABitmapFormat5) {
    NSAA16d,
    NSAB32d,
  };

...would import with members .A16d and .B32d, which is not necessarily
correct. (Is it "NS_AA_16d", or "NSA_A_16d"?) Be more conservative here.

Swift SVN r17125
2014-05-01 00:06:22 +00:00
Jordan Rose
4d8b4a6930 [ClangImporter] Move the ASTFrontendAction::Execute logic inline in create().
We're going to need the parser again later, and we probably shouldn't be
hoping Clang's -fsyntax-only mode lines up with what we need to do anyway.

Swift SVN r17124
2014-05-01 00:06:19 +00:00