Commit Graph

6196 Commits

Author SHA1 Message Date
Doug Gregor
dd8c668aa8 Import NSDictionary as Dictionary<NSObject, AnyObject>
Fixes <rdar://problem/16870626>.


Swift SVN r18907
2014-06-15 10:44:23 +00:00
Joe Groff
4d4a324497 Import Protocol as a foreign class.
In modern ObjC Protocol's object-ness is vestigial, and its class object isn't even visible from newer runtimes, so we can't use it as type metadata. Import it as a foreign class so that we make our own artificial metadata. Fixes <rdar://problem/17303759>.

Swift SVN r18882
2014-06-13 23:07:10 +00:00
John McCall
8a6ee4c8e7 Fix harder for LLVM/Clang trunk.
Swift SVN r18839
2014-06-12 21:11:11 +00:00
Bob Wilson
751301a72b Update diag::Mapping to diag::Severity to match clang r210518.
Swift SVN r18833
2014-06-12 19:48:40 +00:00
Bob Wilson
97ab82ea23 ClangImporter: Update for clang API change in r209002.
Patch by Justin Bogner

Swift SVN r18831
2014-06-12 19:48:38 +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
Jordan Rose
a4ea927426 [ClangImporter] If a protocol and a class have the same name, add "Protocol".
.../if/ the protocol and the class are from the same top-level Clang module.
If not, the protocol is /not/ renamed, and users will have to disambiguate
with module qualification.

This kills our hardcoded "RenamedProtocols" list; it turns out this pattern
is more common than we thought /and/ leads to cross-referencing issues.

<rdar://problem/16206627>

Swift SVN r18809
2014-06-11 23:00:00 +00:00
Jordan Rose
54c0baa9aa [ClangImporter] Don't recurse infinitely on "#define X X".
<rdar://problem/17182523>

Swift SVN r18772
2014-06-10 01:18:29 +00:00
Chris Lattner
7bda183b8b rename SuppressedMacros.def -> MacroTable.def
Swift SVN r18749
2014-06-09 17:32:55 +00:00
Chris Lattner
4dbff38780 Change NULL/Nil/nil and various other macros to be imported as an unavailable decl,
instead of importing them as _Nil (which will be going away when nil becomes an expr).

You now get an error saying:
error: 'NULL' is unavailable: use 'nil' instead of this imported macro

This is pretty cool all around, except for the GCD macros that need to be fixed, I'll
handle that as a follow-up.


Swift SVN r18747
2014-06-09 17:08:11 +00:00
Doug Gregor
1d99cdaf63 Add a defensive assertion to make sure the Clang importer doesn't return null imported modules
Swift SVN r18687
2014-06-01 02:01:46 +00:00
Jordan Rose
171fc95d27 [ClangImporter] Suppress macros named TRUE and FALSE.
These are too close to "true" and "false" for comfort; they add confusion and
mess up code completion. If the names appear in other contexts, though (such
as enumerator names), we should still bring them through.

<rdar://problem/17080279>

Swift SVN r18670
2014-05-30 18:39:39 +00:00
Jordan Rose
577f16c48a [ClangImporter] Import constant globals using 'let' instead of 'var'.
Previously, we considered all imported globals to be mutable, which would
cause problems if you actually tried to change them.

<rdar://problem/17020952>

Swift SVN r18663
2014-05-29 23:04:26 +00:00
Jordan Rose
88a64eb54a Revert "ClangImporter: Update for clang API change"
Until we can build against LLVM and Clang master completely, we should hold
off on any changes that take us out of sync with the wwdc-master tags.

This reverts r18661.

Swift SVN r18662
2014-05-29 20:51:16 +00:00
Justin Bogner
df0b230fb2 ClangImporter: Update for clang API change
Swift SVN r18661
2014-05-29 20:07:13 +00:00
Jordan Rose
3ba8808a6f [ClangImporter] When remapping an init method's name, change the selector too.
This is what we use to drop the variadic parameter on UIActionSheet and
UIAlertView's initializers, along with secretly adding a category to each
to provide the one-fewer-parameter init method implementation. However,
we haven't been using the Swift name for the method to generate Objective-C
calls for a while now--we use the @objc attribute. And that was still using
the original selector, and so we crashed.

Fixed by passing the new selector to the @objc attribute.

<rdar://problem/17012323>

Swift SVN r18582
2014-05-23 01:56:56 +00:00
Doug Gregor
67ca1c9ea1 Implement the new casting syntaxes "as" and "as?".
There's a bit of a reshuffle of the ExplicitCastExpr subclasses:
  - The existing ConditionalCheckedCastExpr expression node now represents
"as?". 
  - A new ForcedCheckedCastExpr node represents "as" when it is a
  downcast.
  - CoerceExpr represents "as" when it is a coercion.
  - A new UnresolvedCheckedCastExpr node describes "as" before it has
  been type-checked down to ForcedCheckedCastExpr or CoerceExpr. This
  wasn't a strictly necessary change, but it helps us detangle what's
  going on.

There are a few new diagnostics to help users avoid getting bitten by
as/as? mistakes:
  - Custom errors when a forced downcast (as) is used as the operand
  of postfix '!' or '?', with Fix-Its to remove the '!' or make the
  downcast conditional (with as?), respectively.
  - A warning when a forced downcast is injected into an optional,
  with a suggestion to use a conditional downcast.
  - A new error when the postfix '!' is used for a contextual
  downcast, with a Fix-It to replace it with "as T" with the
  contextual type T.

Lots of test updates, none of which felt like regressions. The new
tests are in test/expr/cast/optionals.swift. 

Addresses <rdar://problem/17000058>


Swift SVN r18556
2014-05-22 06:15:29 +00:00
Jordan Rose
f256d65669 [ClangImporter] NSProcessInfo.processInfo() is distinct from NSProcessInfo().
Thankfully, Doug already put in infrastructure for this, so it just required
adding one more entry to the table.

<rdar://problem/16995980>

Swift SVN r18537
2014-05-22 00:20:32 +00:00
Jordan Rose
5bee45b776 [ClangImporter] Treat non-modular content imported via framework as an error.
This is -Werror=non-modular-include-in-framework-module for Clang, and
prevents the same content from being treated as part of two different
modules. It's mostly just a sanity check to keep from having problems later.

<rdar://problem/16966705>

Swift SVN r18525
2014-05-21 22:21:50 +00:00
Jordan Rose
e6db58a6ae [ClangImporter] Map u_int*_t [sic] to UInt*.
These types come from <sys/types.h> indirectly and show up in a few
interesting functions like arc4random_uniform.

This commit also introduces a new test file for mapping fixed-sized integers,
to eliminate boilerplate as we continue to rack up aliases for UInt*.

<rdar://problem/16978349>

Swift SVN r18505
2014-05-21 19:45:42 +00:00
Jordan Rose
d3cdebc84e [ClangImporter] Add missing early exit after emitting a fatal error.
This doesn't really matter, since the error that follows will just be
ignored, but it's more correct.

Swift SVN r18463
2014-05-20 19:50:26 +00:00
Jordan Rose
6d376f9627 [ClangImporter] Make a missing bridging header a fatal error.
<rdar://problem/16920163>

Swift SVN r18442
2014-05-20 02:13:32 +00:00
John McCall
ef90a920f9 Update for macosx SDK change. The iOS SDK still uses the
old macro for now.

Swift SVN r18385
2014-05-19 04:00:44 +00:00
Jordan Rose
2981cd3579 [ClangImporter] Note that Clang's getPresumedLoc handles invalid source locs.
Per feedback from Ted. Comment change only.

Swift SVN r18366
2014-05-18 22:51:26 +00:00
Argyrios Kyrtzidis
5d2d762cd3 [ClangImporter] A typedef to a typedef should get imported as a typealias.
Swift SVN r18328
2014-05-18 16:08:56 +00:00
Doug Gregor
3b61830f81 Mark -[NSObject dealloc] as unavailable.
This is most of <rdar://problem/16486790>, solved trivially.

Swift SVN r18275
2014-05-17 21:43:34 +00:00
Doug Gregor
c0e218c982 Mark -[NSExtensionContext openURL:completion:] as unavailable <rdar://problem/16909180>
Swift SVN r18274
2014-05-17 21:37:14 +00:00
Ted Kremenek
f0b112288f Per design discussion today, add back type sugar NSError** out parameters.
The new sugar is 'NSErrorPointer', which hides 'AutoreleasingUnsafePointer<NSError?>'.

I have not yet tested this on iOS, which previously had problems
with the type sugar import.  I'll try and test that now.

Swift SVN r18270
2014-05-17 20:50:40 +00:00
Doug Gregor
f338c9f9bf Extend ObjC methods whitelist to support adding an "unavailable" attribute.
Use this for -class and +class, to make them less ad hoc. More to follow.

As part of this, actually mark imported unavailable declarations in a
protocol as "optional", because nobody should have to implement an
unavailable declaration.

Swift SVN r18262
2014-05-17 19:18:02 +00:00
Doug Gregor
b345aa4827 Revert "Reinstate Jordan's r18233 now that our branches have caught up with the Clang API change."
This reverts commit r18251.

Swift SVN r18257
2014-05-17 17:11:56 +00:00
Doug Gregor
8b70f34ea8 Revert r18196: Clang importer: use T* type sugar when importing as UnsafePointer<T>.
Swift SVN r18254
2014-05-17 16:38:44 +00:00
Doug Gregor
53bf4ead80 Reinstate Jordan's r18233 now that our branches have caught up with the Clang API change.
Swift SVN r18251
2014-05-17 16:36:32 +00:00
Joe Groff
e8f71c12a2 Rename ObjCMutablePointer to AutoreleasingUnsafePointer.
This relates its interface and behavior to that of UnsafePointer, and draws an analogy to '__autoreleasing *' in ARC.

Swift SVN r18236
2014-05-17 04:44:44 +00:00
Jordan Rose
af3c3b358d Revert "[ClangImporter] Update for Clang API change in r209002."
We still have an outstanding incompatibility with LLVM trunk, so let's
just get in a state where we can build against known commits for now.

This reverts r18233.

Swift SVN r18234
2014-05-17 01:40:57 +00:00
Jordan Rose
d7c6bbf760 [ClangImporter] Update for Clang API change in r209002.
If you haven't picked up that commit in Clang yet, it should be safe to
revert this patch.

Swift SVN r18233
2014-05-17 00:50:13 +00:00
Jordan Rose
b581365785 [ClangImporter] If a Clang module fails to build, it's not missing.
...so don't report a second "module missing" error from Swift itself.

We do still treat the Clang module failing to build as a fatal error.

<rdar://problem/16175035>

Swift SVN r18231
2014-05-17 00:23:46 +00:00
Jordan Rose
a012602f62 [ClangImporter] Pass diagnostics through to Swift's diagnostic consumer.
We're not mapping source locations over correctly yet, so the file name
where an error occurs gets shoved into the diagnostic text, but that's
fine for now.

This also silences the "module 'Blah' not found" error coming from the
importer whenever Swift itself can be responsible for importing the module.

Still to do: if we can't build a Clang module, we shouldn't report that
error and then say it can't be found.

<rdar://problem/14509389>

Swift SVN r18230
2014-05-17 00:23:44 +00:00
Doug Gregor
2e499b8cdd Clang importer: use T* type sugar when importing as UnsafePointer<T>.
Swift SVN r18196
2014-05-16 15:44:25 +00:00
Doug Gregor
c4622014f8 Start importing NSArray* with the sugar AnyObject[]! rather than Array<AnyObject>!.
... and simplify type printing so we don't overparenthesize such types.



Swift SVN r18183
2014-05-16 06:17:38 +00:00
Jordan Rose
3a8208ec17 [ClangImporter] Drop support for @partial_interface.
We're not going to ship this feature.

Swift SVN r18168
2014-05-16 03:49:02 +00:00
Jordan Rose
bfa7566aec [ClangImporter] Put implicit properties into the list of all class members.
This allows "obj.description!" to work on iOS when 'obj' is an AnyObject,
even though 'description' is an implicit property created by the importer.

Swift SVN r18149
2014-05-16 00:30:55 +00:00
Jordan Rose
869508db2c [ClangImporter] Make sure the imported header module can see the stdlib.
Otherwise, it can't find the appropriate ~= to use for synthesized NS_ENUM
RawRepresentable conformances, leading to bizarre errors about the
underlying type (usually Int) not being able to convert to NSObject.

<rdar://problem/16923405>

Swift SVN r18131
2014-05-15 22:03:31 +00:00
Doug Gregor
d640eb4083 Introduce support for blacklisting factory-methods-as-inits.
Some fcactory methods shouldn't come in as initializers, per
<rdar://problem/16908950>.


Swift SVN r18101
2014-05-15 07:04:46 +00:00
Doug Gregor
3210f19411 Clang importer: replace the designated-initializer whitelist with a general method whitelist.
... which only handles designated initializers, for now at least.


Swift SVN r18100
2014-05-15 06:22:44 +00:00
John McCall
a3fb501114 Recognize the objc_bridge and objc_bridge_mutable
attributes and create implicit conversions for them.

Also, when generating Clang modules for import, set the
appropriate macro to make CoreFoundation actually apply
those attributes to its typedefs.

Also, give shared linkage to imported class method
definitions.

The net effect is that CFString now automatically
converts to NSString and vice-versa.

Depends on Clang r208756 in order to preserve attributes
applied to tag types in multiple typedef declarations.

Swift SVN r18069
2014-05-14 08:19:39 +00:00
Jordan Rose
2877bd0854 Add support for dependency file generation with -emit-dependencies.
This performs very conservative dependency generation for each compile task
within a full compilation. Any source file, swiftmodule, or Objective-C
header file that is /touched/ gets added to the dependencies list, which
is written out on a per-input basis at the end of compilation.

This does /not/ handle dependencies for the aggregated swiftmodule, swiftdoc,
generated header, or linked binary. This is just the minimum needed to get
Xcode to recognize what needs to be rebuilt when a header or Swift source
file changes. We can revisit this later.

This finishes <rdar://problem/14899639> for now.

Swift SVN r18045
2014-05-14 00:34:11 +00:00
Doug Gregor
63edc38d0a Use a bit to avoid performing early declaration attribute validation more than once.
Attribute validation is not naturally idempotent, and we shouldn’t need to make it so. Rather, we should only do the validation once. This fixes an immediate issue with @NSManaged in multi-file situations (<rdar://problem/16879162>) and avoids some redundant work.

Longer term, we have a ton of redundant visitation that needs to be addressed <rdar://problem/16905199>.

Swift SVN r18039
2014-05-13 23:36:09 +00:00
Doug Gregor
7bedd5ca22 Recognize colliding imported constructors properly.
I had gotten the type computation incorrect, causing the
deserialization crashes seen on the buildbot.

Swift SVN r18032
2014-05-13 22:30:19 +00:00
Doug Gregor
d5a9c2ab94 Only supersede initializers with other imported initializers when the types match.
This fixes a case where the Swift-variadic and C-varargs versions of
various initializers were superseding each other
<rdar://problem/16801456>.

It also uncovered some more cases where we weren't getting quite the
right semantics for factory-methods-as-initializers, which are also
fixed here.

Swift SVN r18010
2014-05-13 16:49:39 +00:00
Doug Gregor
9ecb07409b Make the "superseded" diagnostic better.
Users shouldn't actually see this diagnostic, but if it does show up,
it should at least be useful:

error: 'init' is unavailable: superseded by import of
    -[NSArray(NSArrayCreation) initWithObjects:]

Swift SVN r18009
2014-05-13 16:49:36 +00:00