Commit Graph

2546 Commits

Author SHA1 Message Date
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
Jordan Rose
ba8d1a5656 [ClangImporter] Ban a few deprecated methods of NSDocument.
...so that their modern NSError-based variants won't be imported using an
extra "error: ()" parameter. Apart from looking prettier, this avoids a
crash when overriding the "error: ()" versions, rdar://problem/21144509.

Once NS_REFINED_IN_SWIFT has been implemented we can probably use that instead.
Filed rdar://problem/21192039 to remove the hack at that point.

rdar://problem/21177341

Swift SVN r29212
2015-06-01 23:04:01 +00:00
Dave Abrahams
d65f696344 Kill off [_]RawOptionSetType
Now that we are using OptionSetType for option sets, all the support for
doing things the old way can die.

Note: the fix-it that used to apply to RawOptionSetType, it seemed to me,
should still apply to OptionSetType, so I switched it over instead of
removing it.

Swift SVN r29066
2015-05-27 15:55:54 +00:00
Jordan Rose
cb2ca7d997 [ClangImporter] Remap factory methods according to the swift_name attr.
On a factory method, swift_name can have two effects:

- If the custom name has a base name of "init", import the method as an
  initializer, even if it doesn't follow the usual naming conventions.
- Otherwise, import the method as a method, even if it /would have/ been
  imported as an initializer.

There's a bit of trickiness around NSError**: currently you have to specify
the name of the error parameter on the Clang side even if it's going to be
deleted on the Swift side. We may want to change this later.

The test cases here exposed the issues in the previous two commits,
so this effectively depends on those for passing tests.

More of rdar://problem/19240897.

Swift SVN r28979
2015-05-24 01:48:24 +00:00
Jordan Rose
5db7e8591f [ClangImporter] Don't use 'Self?' for a throwing method.
We have special logic to handle instancetype returns, but that hadn't
been updated for error handling.

Tested in next commit.

Swift SVN r28978
2015-05-24 01:48:21 +00:00
Jordan Rose
b92e0c944d [ClangImporter] Implement NS_SWIFT_NAME for enumerators.
NS_SWIFT_NAME on enum constants has two effects: on top of renaming the
member, it also removes it from the prefix-matching logic.

Part of rdar://problem/19240897

Swift SVN r28927
2015-05-22 20:15:09 +00:00
Joe Groff
d1b6fa32c4 Revert "Revert "[stdlib] Land OptionSetType et. al.""
This recommits r28892, r28894, and r28895; the previous commits should have addressed the previous breakage.

Swift SVN r28905
2015-05-22 05:47:29 +00:00
Dave Abrahams
21b9a97e88 Revert "[stdlib] Land OptionSetType et. al."
This reverts commit r28892, r28894, and r28895.

They broke validation tests; JoeG is going to look at what's needed to
make them work again.

Swift SVN r28897
2015-05-22 00:13:53 +00:00
Dave Abrahams
ad7f7c6779 [stdlib] Land OptionSetType et. al.
This has passed review, or at least satisfied Tony Parker, provided we
do something to hide SetAlgebraDispatchType.  I think I can eliminate it
in an imminent commit.

Swift SVN r28892
2015-05-21 22:55:02 +00:00
Jordan Rose
fa5bd4c6c8 [ClangImporter] Allow apinotes to affect inherited initializers.
Then use that to ban NSError.init(), because it doesn't create a valid
NSError. In the long run Foundation will hopefully add this to their
headers, but they can't yet (rdar://problem/19977891).

rdar://problem/21042412

Swift SVN r28881
2015-05-21 18:11:17 +00:00
Dmitri Hrybenko
ea17483633 Add CMake options and #ifs to hide tvOS
Swift SVN r28752
2015-05-19 05:15:52 +00:00
Devin Coughlin
4b23d4a219 Update clang importer and target platform detection for watchOS.
For the moment, we do not consider APIs deprecated earlier than watchOS 2.0 as
unavailable. rdar://problem/20948019 track changing this once the ultimate
decision on this policy has been made.

This addresses the compile-time components of rdar://problem/20774229

Swift SVN r28559
2015-05-14 04:20:43 +00:00
Joe Groff
b1a965fd1e Clang Importer: Import struct elementwise constructors as transparent.
We need to ensure they get inlined away if they're referenced from other transparent definitions, as a workaround for SIL deserialization being unable to trigger instantiation of Clang-importer-synthesized modules. Still doesn't solve that problem, but works around it enough for rdar://problem/20902115.

Swift SVN r28526
2015-05-13 20:53:26 +00:00
Ted Kremenek
62feb5c949 Change @availability to @available.
This came out of today's language review meeting.
The intent is to match #available with the attribute
that describes availability.

This is a divergence from Objective-C.

Swift SVN r28484
2015-05-12 20:06:13 +00:00
Doug Gregor
340e4d8f8a Simplify parsing and representation of extension declarations.
Now that we don't have generic parameter lists at arbitrary positions
within the extended type of an extension declaration, simplify the
representation of the extended type down to a TypeLoc along with a
(compiler-synthesized) generic parameter list.

On the parsing side, just parse a type for the extended type, rather
than having a special grammar. We still reject anything that is not a
nominal type (of course), but it's simpler just to call it a type.

As a drive-by, fix the crasher when extending a type with module
qualification, rdar://problem/20900870.

Swift SVN r28469
2015-05-12 16:26:13 +00:00
Jordan Rose
46b52576d3 Recognize imported enum case aliases in TypeCheckPattern.cpp.
...so that they can still be used with exhaustive switches.

This is a hack---groveling through the AST to see if it's in the particular
form of an imported enum case alias---but at least it's limited to imported
properties.

More rdar://problem/18662118

Swift SVN r28326
2015-05-08 21:01:52 +00:00
Doug Gregor
edbb75eef8 Eliminate the 'Module' variant from UnqualifiedLookupResult.
Make unqualified lookup always provide a declaration for the things it
finds, rather than providing either a module or a declaration. Unify
various code paths in our type checker now that module declarations
come in with the other declarations.

Swift SVN r28286
2015-05-07 21:10:55 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00
Joe Groff
73dfea0ba0 ClangImporter: Import option sets as conforming to OptionSetType.
This is pretty much a simplification of the existing RawOptionSetType logic; now, instead of generating a bunch of implicit decls, we provide the minimum set of declarations from which the stdlib will be able to generate default implementations of everything else. The new imported declaration looks like this:

struct MyOptions: OptionSetType {
  let rawValue: UInt // or whatever raw type
  init(rawValue: UInt)

  static var A: MyOptions { return MyOptions(rawValue: 1) }
  static var B: MyOptions { return MyOptions(rawValue: 2) }
  /* etc. */
}

Still hidden behind a staging flag, until the stdlib implementation can land.

Swift SVN r28213
2015-05-06 19:45:52 +00:00
Doug Gregor
de635a8cd9 Implement the 'warn_unused_result' attribute.
@warn_unused_result can be attached to function declarations to
produce a warning if the function is called but its result is not
used. It has two optional parameters that can be placed in
parentheses:

  message="some message": a message to include with the warning.

  mutable_variant="somedecl": the name of the mutable variant of the
  method that should be suggested when the subject method is called on
  a mutable value.

The specific use we're implementing this for now is for the mutating
and in-place operations. For example:

  @warn_unused_result(mutable_variant="sortInPlace") func sort() -> [Generator.Element] { ... }
  mutating func sortInPlace() { ... }

Translate Clang's __attribute__((warn_unused_result)) into
@warn_unused_result.

Implements rdar://problem/18165189.

Swift SVN r28019
2015-05-01 04:10:40 +00:00
Devin Coughlin
4f366b1ff6 Do not treat iOS as active on tvOS.
Change the active-platform availability logic to not consider iOS as active on
tvOS. We want all of the messiness of the fact that tvOS was branched
from iOS to be handled in clang, which "transcribes" iOS availability attributes
to their corresponding tvOS counterparts as long as there is not an
existing explicit tvOS availability attribute on the declaration.

This change exposed several places where I needed to add explicit handling of
of tvOS and where we will need to handle watchOS as well.
rdar://problem/20774229 tracks adding logic and tests to handle watchOS in these
places.

It is also unfortunately the case that llvm::triple returns true when isiOS()
is called on tvOS. This means that to test whether an llvm:triple target is
really iOS, we need to check for iOS then check explicitly that it is not
tvOS. We will eventually change llvm's behavior here so that the double
check is not needed.

Swift SVN r28013
2015-05-01 01:54:24 +00:00
John McCall
26b3f386e0 Fix a bug with importing inherited factory methods with
foreign-error conventions.

Swift SVN r28003
2015-04-30 22:34:41 +00:00