Commit Graph

767 Commits

Author SHA1 Message Date
Slava Pestov
20efd60ebd ClangImporter code cleanups, NFC
- Extract makeFieldGetterDecl() and makeFieldSetterDecl()
- Remove makeUnionConstructorDecl(), the ordinary struct constructor logic
  works just fine

Swift SVN r31709
2015-09-05 04:06:22 +00:00
Jordan Rose
845513d359 [ClangImporter] Always treat dispatch_block_t as @convention(block).
Some GCD APIs rely on the pointer identity of blocks, so avoid bridging
when possible. The easiest way to do this was to use our existing rules
for special-casing typedefs.

The summary text for dispatch_block_t comes from the actual GCD headers.

rdar://problem/22432170

Swift SVN r31634
2015-09-02 18:31:51 +00:00
Ben Langmuir
47026609b8 Fix leak of std::function in NominalTypeDecl::DelayedMembers
We were memcopying a std::function into the the AST context memory,
which leaks memory incidentally used by the std::function
implementation.  Fix by using a std::unique_ptr and registering a
destructor cleanup.  Incidentally, I turned the array of functions into
a single function, since we never have more than one anyway.

rdar://problem/22387897

Swift SVN r31600
2015-09-01 16:31:21 +00:00
Chris Lattner
6d1b814d61 fix a bug in code synthesized by the clang importer. The "/*Implicit=*/true"
marker isn't actually setting the implicit bit, it was setting the "trailing 
closure" bit, for something that isn't of function type.  The effect of this
was to cause sema to eat the rawValue: parameter without requiring the label.

Instead of generating this code that happened to work out most of the time,
build the proper TupleExpr with the right parameter label.  NFC.



Swift SVN r31597
2015-09-01 04:39:28 +00:00
David Farler
a75b0831e4 Automatically infer Equatable conformance for plain C enums
This provides the == operator as well as ~=, which allows for
less encumbered pattern matching for these imported types.

rdar://problem/17287720

Swift SVN r31469
2015-08-26 02:25:54 +00:00
Doug Gregor
f3d623b738 DRY: Use the imported initializer's type to compute failability
... rather than having a separate 'failability' computation.

Swift SVN r31429
2015-08-24 18:26:26 +00:00
David Farler
e21e1c40e4 Import fields for named C unions
Create getters and setters for, and initializers taking, fields in
C unions. This doesn't yet fold anonymous unions' fields nested into
a struct, but it does open up APIs that were previously unavailable.

rdar://problem/19660119

Swift SVN r31396
2015-08-21 22:10:17 +00:00
Doug Gregor
00040112cd Eliminate special handling of deserialized inherited protocols.
Now that we have the inheritance lists hanging around, use them: it
makes the conformance lookup table use the same code whether we're
deserializing the conformances or parsing them.

Swift SVN r31383
2015-08-21 17:51:26 +00:00
Doug Gregor
cab320296d Stop recording protocol lists in nominal types.
The conformance lookup table is responsible for answering queries
about the protocols to which a particular nominal type conforms, so
stop storing (redundant and incorrect) protocol lists on the ASTs for
nominal types. Protocol types still store the list of protocols that
they inherit, however.

As a drive-by, stop lying about the number of bits that ProtocolDecl
uses on top of NominalTypeDecl, and move the overflow bits down into
ProtocolDecl itself so we don't bloat Decl unnecessarily.

Swift SVN r31381
2015-08-21 17:51:23 +00:00
Doug Gregor
ee7803a87a Eliminate the list of protocols from ExtensionDecl. NFC
Swift SVN r31349
2015-08-19 21:33:52 +00:00
Doug Gregor
83cb1e69bb Serialize the list of inherited types for all nominal types.
This provides better AST fidelity through module files and further
reduces our dependencies on storing a list of protocols on nominal
type declarations.

Swift SVN r31345
2015-08-19 21:10:45 +00:00
Doug Gregor
dd68b9fc59 Start serializing the "inherited" list of extension declarations.
This improves the fidelity of the AST printed from a loaded module, as
well as consistency in the AST. Also teach the Clang importer to add
"inherited" clauses, providing better fidelity for the mapping from
Objective-C to Swift.

With trivial update to SDKAnalyzer test.

Swift SVN r31344
2015-08-19 21:10:42 +00:00
Ted Kremenek
60174804e1 Revert "Start serializing the "inherited" list of extension declarations."
This reverts commit r31337.

Swift SVN r31340
2015-08-19 20:13:13 +00:00
Doug Gregor
1393ee18a4 Start serializing the "inherited" list of extension declarations.
This improves the fidelity of the AST printed from a loaded module, as
well as consistency in the AST. Also teach the Clang importer to add
"inherited" clauses, providing better fidelity for the mapping from
Objective-C to Swift.

Swift SVN r31337
2015-08-19 18:29:11 +00:00
Jordan Rose
ca394f3e05 Make sure to IRGen all static functions.
...not just inline ones. Otherwise we'll end up with linker errors.

Swift SVN r31248
2015-08-14 19:50:25 +00:00
Jordan Rose
f5b1efb354 Move client-affecting configuration options into a generated Config.h.
This way they can be used from other projects, like LLDB. The downside
is we now have to make sure the header is included consistently in all
the places we care about, but I think in practice that won't be a problem,
especially not with tests.

rdar://problem/22240127

Swift SVN r31173
2015-08-12 17:50:13 +00:00
Devin Coughlin
9dc0c8a173 Importer: Prefer more available convenience factory initializers over less available convenience initializers
Update the importer and name lookup to prefer a factory initializer that is more available
over a convenience initializer that is less available even though we generally prefer
convenience initializers over convenience factory initializers. The motivation for this
change is CIColor, which has added a new convenience initializer:

- (instancetype)initWithRed:(CGFloat)r green:(CGFloat)g blue:(CGFloat)b NS_AVAILABLE(10_11, 9_0);

but already has existing convenience factory initializer:

+ (instancetype)colorWithRed:(CGFloat)r green:(CGFloat)g blue:(CGFloat)b;

Without this change we prefer -initWithRed:green:blue, so instantiating CIColor with:

let colorChannelValue: CGFloat = …
let ciColor = CIColor(red: colorChannelValue, green: colorChannelValue, blue: colorChannelValue)

results in an availability error even though there is a perfectly available convenience
factory initializer. With this change, we choose the convenience factory initializer
when importing, so there is no availability error.

rdar://problem/20617581

Swift SVN r30946
2015-08-03 17:21:21 +00:00
Jordan Rose
1e84e571a5 [ClangImporter] Remove dead code after r30814.
Swift SVN r30829
2015-07-31 00:49:08 +00:00
Jordan Rose
8edbbef5fe [ClangImporter] Use real negative literals for imported constants.
The old code predates NumberLiteralExpr having a "negative" field.
Fixing this avoids creating a temporary signed integer with a value of
INT_MAX+1 when trying to compute INT_MIN.

rdar://problem/21680700

Swift SVN r30814
2015-07-30 21:55:04 +00:00
Jordan Rose
62bae87406 [ClangImporter] Import typedefs of block types as fully-bridged closures.
Block types can't be used in structs (because they're managed by ARC),
are rarely referred to by pointers, and would pretty much never be
globals. Additionally, their syntax is complicated enough that people
tend to make typedefs for them fairly frequently. We'd like to preserve
that sugar, but we don't really need to preserve the representation
when the most likely use of the block is in a bridged context (e.g. a
method parameter). In the rare case where the representation /is/
important, fall back to re-importing the underlying type.

rdar://problem/22013912

Swift SVN r30738
2015-07-29 00:06:55 +00:00
Jordan Rose
bfd30db4c2 [ClangImporter] Be more careful about stripping 'k' from enum constants.
This condition was wrong and could occasionally produce enum constant
names that started with digits.

rdar://problem/21820628

Swift SVN r30549
2015-07-23 20:50:49 +00:00
Slava Pestov
78bbcce84a Factor out some code duplication with setting EnumElementDecl types, NFC
Swift SVN r30387
2015-07-19 20:57:15 +00:00
Slava Pestov
e748908990 Sema: Don't set type of TypeAliasDecl until we resolve the alias type
This changes the behavior to match NominalTypeDecls, which don't have a type
until everything is set up either. In a few places we construct TypeAliasDecls
from known types directly, and we have to call computeType().

Fixes <rdar://problem/19534837>.

Swift SVN r30386
2015-07-19 20:55:53 +00:00
Dmitri Hrybenko
373c872f6c Revert "Ignore certain NS_SWIFT_UNAVAILABLE attributes in Foundation"
This reverts commit r29252.

rdar://21192622

Swift SVN r30358
2015-07-18 02:39:05 +00:00
Jordan Rose
5c71b75b25 Add @warn_unqualified_access, and apply it to imported methods named 'print'.
Otherwise, people subclassing NSView will accidentally call NSView.print
when they're trying to call Swift.print.

rdar://problem/18309853

Swift SVN r30334
2015-07-17 22:02:35 +00:00
Devin Coughlin
56cb80c9c2 Importer: Apply protocol availability to imported mirror decl members
When adding mirror declaration members to a class, if the protocol has an annotated
availability then apply that availability to the mirror declaration member unless the
protocol member already has its own availability.

rdar://problem/21825141

Swift SVN r30251
2015-07-16 04:49:35 +00:00
Devin Coughlin
5274af3314 Importer: Synthesize inferred availability for members mirrored from unannotated Obj-C protocols
The importer conjures up "mirrored" member declarations for imported
Obj-C classes that conform to a protocol with members that aren't exposed
in public headers. This commit extends our existing inference of availability
for members of unannotated Obj-C protocols to cover mirrored declarations
as well. For these mirrored declarations, we additionally constrain the
inferred availability with the availability of the class itself.

Swift SVN r30244
2015-07-16 01:34:43 +00:00
Devin Coughlin
0000179351 Importer: Fix bad indentation introduced in r30096. NFC.
Swift SVN r30097
2015-07-10 23:21:09 +00:00
Devin Coughlin
259b54748c Importer: Synthesize inferred availability for unannotated Obj-C protocols
Based on feedback from Jordan, update r30060 to synthesize availability
attributes on unannotated Obj-C protocols in the importer. This has a
user-visible effect: calls to protocol requirements with these synthesized
attributes will now cause an availability error if the requirement is not
available in the calling type refinement context.

Swift SVN r30096
2015-07-10 22:48:22 +00:00
Jordan Rose
0b5428fcd3 Import DarwinBoolean as Bool in fully-bridgeable contexts.
These are contexts where we have enough information to bridge /back/
properly; that is, where we can distinguish CBool, ObjCBool, and
DarwinBoolean. In cases where we can't, we keep the three separate;
only CBool is really the same type as Bool.

This also affects current import behavior for ObjCBool, which was previously
incorrectly conflated with CBool in certain cases.

More rdar://problem/19013551

Swift SVN r30051
2015-07-10 01:11:30 +00:00
Jordan Rose
498ab24341 [ClangImporter] Allow performSelector... methods, but make the result Unmanaged.
Per discussion, there are certain times where our APIs really want you to use
the performSelector family of methods (e.g. when the framework hands you a selector
and expects you to call it upon completion).

Although the methods still aren't type-safe, we are at least making the result
Unmanaged so that you're forced to think about whether it's +1 or +0 before you
use it, and so that the compiler doesn't accidentally try to retain a non-object
pointer.

This commit also removes the blocks on the makeObjectsPerformSelector... methods,
but Foundation plans to add NS_SWIFT_UNAVAILABLE there (see rdar://problem/21150180).

rdar://problem/21150277

Swift SVN r30044
2015-07-09 22:54:41 +00:00
Jordan Rose
b1c4ae4287 [ClangImporter] Expose getEnumConstantName for use in the debugger.
rdar://problem/21640482

Swift SVN r29892
2015-07-02 17:29:30 +00:00
Jordan Rose
d9ddc21f49 [ClangImporter] Fix underscore handling from r29673 to handle plurals.
The improvements there caused regressions in other enums. Thanks for catching this
Denis (and Xi)!

Fix-up to rdar://problem/20800204

Swift SVN r29829
2015-07-01 01:01:28 +00:00
Jordan Rose
285ee60fd4 [ClangImporter] Generalize the hack from r29212 to cover any unavailable members.
If there is a method -foo: that's unavailable (for whatever reason), and we now
have a method -foo:error: that we'd like to import, it's okay to drop the error
parameter there. Overload resolution can handle filtering out the unavailable
method.

rdar://problem/21497221

Swift SVN r29746
2015-06-26 22:19:20 +00:00
Jordan Rose
3be416ba3d [ClangImporter] Recognize Swift classes and protocols renamed with @objc.
This is the counterpart of the previous commit---if a class or protocol
is renamed with @objc, we should not be looking for it in Swift under
its Objective-C name.

Finishes rdar://problem/17469485

Swift SVN r29744
2015-06-26 18:28:50 +00:00
Jordan Rose
e900823862 [ClangImporter] Tweak enum import rules to remove more underscores.
If the common prefix of the enum /elements/ had an underscore in the /middle/,
we previously had cases where we'd end up leaving that underscore in place.

rdar://problem/20800204

Swift SVN r29673
2015-06-25 17:32:28 +00:00
Jordan Rose
0178453f45 [ClangImporter] Pretend dyld.h's DYLD_BOOL was declared with NS_ENUM.
We wouldn't care except that its constants are named TRUE and FALSE and
that shows up in the global namespace.

rdar://problem/20943410

Swift SVN r29651
2015-06-25 01:45:13 +00:00
Jordan Rose
460b03d367 [ClangImporter] Remove a hack put in for the Security framework.
They've updated their headers and things are better now.

rdar://problem/19020927

Swift SVN r29588
2015-06-24 00:52:52 +00:00
Jordan Rose
4fda02e846 [ClangImporter] Follow swift_name more closely when error params are involved.
+ (Foo *)foo:(id)obj error:(NSError **)error NS_SWIFT_NAME(init(object:));
  + (Foo *)foo:(id)obj error:(NSError **)error NS_SWIFT_NAME(init(object:error:));

These are now mapped, respectively, to

  init(object: AnyObject) throws
  init(object: AnyObject, error: ()) throws

rather than both mapping to the first one and having no way to specify the second.

Swift side of rdar://problem/21091469. Requires Clang commits.

Swift SVN r29534
2015-06-20 18:55:10 +00:00
Jordan Rose
9dc736bbdd Re-apply "[ClangImporter] Don't import subscripts with swift_private getters/setters."
Test limited to ObjC-compatible OSs in the next commit.

Swift SVN r29434
2015-06-17 02:29:32 +00:00
Ted Kremenek
2714262306 Revert "[ClangImporter] Don't import subscripts with swift_private getters/setters."
This was breaking the Linux bot.

Swift SVN r29433
2015-06-17 02:23:01 +00:00
Jordan Rose
418cc9e2e5 [ClangImporter] Don't import subscripts with swift_private getters/setters.
Instead, we just import the pieces as methods, which can be rebuilt into a
new subscript in the overlay.

Last piece of rdar://problem/20070465

Swift SVN r29430
2015-06-17 01:46:17 +00:00
Jordan Rose
34f69491c6 [ClangImporter] Import swift_private rules for methods and initializers.
A method has "__" prepended to its basename; an initializer has "__"
prepended to its first argument.

There are a few holes here involving no-argument initializers and factory
methods, but hopefully we won't need to remap those with swift_private anyway.

More of rdar://problem/20070465

Swift SVN r29429
2015-06-17 01:46:16 +00:00
Jordan Rose
615a32ae11 [ClangImporter] Handle swift_private renaming for a variety of imported decls.
...including structs and struct fields, enums and enum cases, typedefs,
protocols, classes, and properties.

The main problem is that this /doesn't/ handle top-level /lookup/, so you
can't actually find any of these renamed types. This is fixed in the next
commit.

This does not handle methods, subscripts, or initializers.

Part of rdar://problem/20070465

Swift SVN r29427
2015-06-17 01:46:14 +00:00
Jordan Rose
7cc910b39a [ClangImporter] Add a version of importName that takes a clang::NamedDecl.
At this point this is just for convenience, but see next commit.

Swift SVN r29426
2015-06-17 01:46:13 +00:00
Jordan Rose
a696730061 [ClangImporter] Remove suffix appending from importName.
This isn't used anymore. No functionality change.

Swift SVN r29425
2015-06-17 01:46:12 +00:00
John McCall
58111522c5 Consider modules-hidden declarations when looking for a type
with the same name as an Objective-C protocol.

Fixes a crash when importing a module containing an ObjC
class that subclasses NSObject when that module doesn't
re-export NSObject.

Swift SVN r29286
2015-06-04 00:22:32 +00:00
Dmitri Hrybenko
445ab98267 Ignore certain NS_SWIFT_UNAVAILABLE attributes in Foundation
This is a temporary workaround.  rdar://21192622 tracks reverting this
change.

Swift SVN r29252
2015-06-02 20:59:14 +00:00
Jordan Rose
bfcc8482d8 Re-apply "[ClangImporter] Ban a few deprecated methods of NSDocument."
Now with the right REQUIRES line in the new test.

rdar://problem/21177341

Swift SVN r29237
2015-06-02 17:30:28 +00:00
Ted Kremenek
b2fa002ce4 Revert "[ClangImporter] Ban a few deprecated methods of NSDocument."
This is breaking the iOS testers.

Swift SVN r29227
2015-06-02 05:42:15 +00:00