Commit Graph

426 Commits

Author SHA1 Message Date
Jordan Rose
db3914e94b Disallow conforming to ObjC protocols with requirements that can't be imported.
For example, variadic ObjC method requirements.

<rdar://problem/17366999>

Swift SVN r19121
2014-06-24 01:23:06 +00:00
Anna Zaks
a7fefdb561 Known ObjC types sidecar: add ability to annotate properties.
Add a simple option that allows to pass along information about properties.

Swift SVN r19110
2014-06-23 23:53:37 +00:00
Anna Zaks
50178f649e Add audited APIs to sidecart for NSView.
From NSView.h, NSRuler.h, NSLayoutConstraint.h.

Swift SVN r19109
2014-06-23 23:53:36 +00:00
Anna Zaks
5f61494928 Add OBJC_CONTEXT(ClassName, Options) to KnownObjCMethods.
This allows to specify the method options most common for the methods in a
given audited class or protocol.

Swift SVN r19108
2014-06-23 23:53:34 +00:00
Anna Zaks
9f122e56b7 Add initial support for importing with tighter Objective C pointer types.
Add the ability to store optionality of the ObjC method parameters and return
type in a sidecar. This hardcoded info is then used to import Objective C
object pointer types as either optional or none, instead of implicitly
unwrapped optionals.

The feature is enabled with -import-with-tighter-objc-types=true.

Swift SVN r19048
2014-06-20 19:19:43 +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
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
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
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
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
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
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
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
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
Ted Kremenek
4e70269c53 More renaming 'unchecked optional' to 'implicitly unwrapped optional'.
Swift SVN r17236
2014-05-02 06:22:01 +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
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
John McCall
23b224a655 Change the type importer to import types abstractly first,
and only later adjust the type for the manner in which
it is actually being used.

This gives us a foundation on which to build a consistent
and defensible model for importing typedefs.

Also fix a subtle problem with typedefs imported from
multiple clang modules.

Swift SVN r17079
2014-04-30 06:46:00 +00:00
Argyrios Kyrtzidis
3a4d5a54cd [AST] Add some static_asserts to make sure adding a ClangNode to the AST object doesn't violate its alignment.
Suggested by Jordan.

Swift SVN r16650
2014-04-22 06:50:00 +00:00
Argyrios Kyrtzidis
b3f470ad16 [ClangImporter] Make getting the ClangNode from a swift Decl more efficient by
allocating extra memory and storing it directly before the swift AST object.

Reduces code-completion time for Cocoa by -25%.

Swift SVN r16615
2014-04-21 07:18:50 +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
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
Doug Gregor
ea647624e3 Eliminate the notion of "selector-style" declarations in the AST.
We still parse them, but the distinction is no longer meaningful
beyond the parsing stage.



Swift SVN r16445
2014-04-17 05:42:58 +00:00
Doug Gregor
8e597cc695 Eliminate argument parameter patterns.
Swift SVN r16444
2014-04-17 05:20:14 +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
Doug Gregor
2dfed7538d Switch the Clang importer over to using ObjCSelector more often.
Swift SVN r16347
2014-04-15 00:35:40 +00:00
Doug Gregor
9520460449 Clean up the import of Objective-C init methods as Swift initializers.
Previously, we would import the init method as a FuncDecl, which
wasn't actually supposed to be used by anything, and then created a
separate ConstructorDecl via importSpecialMember(). That's insane:
just have VisitObjCMethodDecl() produce a ConstructorDecl directly
when given an init method. Should be NFC.

Swift SVN r16313
2014-04-14 14:30:08 +00:00
Doug Gregor
9d7f0b6211 Rework the selector-splitting heuristics.
This makes a number of changes to the selector-splitting
heuristics. Specifically:

  - Eliminate last-word splitting, and with it the notion of
    multi-words. We only split at prepositions now.
  - Introduce the notion of "linking verbs" such as "will" or
    "should"; when these show up, we refuse to split a selector, which
    helps with delegates.
  - Eliminate the special case for "get" and "set". It wasn't
    helping.
  




Swift SVN r16265
2014-04-12 20:32:16 +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
49387beb25 Selector splitting: don't split selectors in the middle of whitelisted "multi-words".
Swift SVN r16016
2014-04-07 19:17:23 +00:00
Doug Gregor
4130bb15ff Add a whitelist of designated initializers and use it in the Clang importer.
Seed the whitelist with the designated initializers for NSObject,
NSDocument, and UIDocument. We'll grow this list over time.
Fixes <rdar://problem/16521299>.


Swift SVN r16013
2014-04-07 15:06:59 +00:00
Doug Gregor
c78a3ecd48 Clang importer: cache the result of the selector -> method mapping.
Swift SVN r15983
2014-04-05 06:04:01 +00:00
Jordan Rose
aa6aa72ba1 Add lazy conformances to nominals and extensions.
...and deserialize conformances lazily.

No intended user-visible change.

Swift SVN r15911
2014-04-04 01:17:54 +00:00
Joe Groff
bef2cdfac4 ClangImporter: Enable importing NSFoo** as ObjCMutablePointer<NSFoo?>.
And blast away a bunch of withUnsafePointer* noise this obviates in the stdlib.

Swift SVN r15896
2014-04-03 22:33:33 +00:00
Doug Gregor
87144a8afa Make splitFirstSelectorPiece() static, now that it has just one caller
Swift SVN r15854
2014-04-03 04:20:10 +00:00
Doug Gregor
a4e16bd8e2 Simple importFunctionType, now that it doesn't handle methods.
Swift SVN r15852
2014-04-03 03:38:35 +00:00
Doug Gregor
e418e93511 Start cleaning up method name importing.
Import a selector into a Swift method name, performing splitting at
that point. Use the resulting method name to determine the argument
names of the parameters, rather than trying to chop up the selector
again. There's more refactoring to do here.

This fixes a longstanding bug where the first argument of an
Objective-C method got the internal parameter name when it should
have gotten no name at all.

Swift SVN r15850
2014-04-03 00:34:40 +00:00
Doug Gregor
527b147ba7 Revert "Allow the first name of a selector-style function declaration to be separated."
This reverts r15140.

Conflicts:
	include/swift/Serialization/ModuleFormat.h
	lib/Parse/ParsePattern.cpp

Swift SVN r15846
2014-04-02 23:27:52 +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
Joe Groff
71404091d4 Add Builtin.fixLifetime as a way for library code to fix object lifetimes.
Lowers directly to the SIL fix_lifetime instruction.

Swift SVN r15637
2014-03-29 22:59:24 +00:00
Dmitri Hrybenko
962c924ab1 Clang importer: put macros into correct module and return them in visible decl
lookup


Swift SVN r15500
2014-03-26 10:27:44 +00:00
Jordan Rose
8d35d75ce3 [ClangImporter] Resolve forward class declarations to definitions in Swift.
When we see an unresolved @class in a Clang module, we check the class name
against the classes in the Swift module with the same name.

This unfortunately necessitates putting a reference to the active type checker
into the ClangImporter, because the class in the current Swift module hasn't
been type-checked yet. This is now being used everywhere we do a lookup.

<rdar://problem/16295994>

Swift SVN r15355
2014-03-22 00:19:59 +00:00