Commit Graph

2523 Commits

Author SHA1 Message Date
Mishal Shah
23b646eed2 Update master to build with Xcode 8 beta 2, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs 2016-07-06 10:48:45 -07:00
Doug Gregor
71882c6516 [API Notes] Use API notes rather than overlays to make error enums bridge.
The Clang attribute allows one to state that a particular enumeration
type describes an error, and associates it with a particular domain
constant. However, due to lack of API notes support, this attribute
wasn't actually getting used. Instead, we had a number of explicit
extensions to enum types to make them conform to the _BridgedNSError
protocol explicitly.

Now that we have API notes, use them to make these enums into error
enums with the appropriate domain, so that the Clang importer will
synthesize the _BridgedNSError conformances. Then, remove all of the
explicit conformances---and with them, the overlays for 12 frameworks.

There is a small fix to more eagerly consider these conformances as
"used" if an expression is formed with the error enum as a value
type. This better ensures that the conformances will be available at
runtime when needed.

This cleanup is needed to implement SE-0112 (NSError bridging),
although it is useful by itself.
2016-07-06 09:54:59 -07:00
Joe Groff
8c2631a37f Merge pull request #3294 from jckarter/id-as-any-import
Initial 'id as Any' Clang importer implementation
2016-07-05 16:03:35 -07:00
Joe Groff
231db9d108 Clang importer: Import ObjC 'id' as Swift 'Any' (behind a flag).
For experimentation purposes, add a flag to cause the Clang importer to map ObjC APIs using `id` to `Any` instead of `AnyObject`.
2016-07-05 12:29:45 -07:00
Slava Pestov
5a902935e8 Sema: Explicitly set interface type on all AbstractFunctionDecls
Previously getInterfaceType() would punt to getType() if no
interface type was set. This patch changes getInterfaceType()
to assert if no interface type is set, and updates various
places to set the interface type explicitly.

This brings us a step closer to removing PolymorphicFunctionType.
2016-07-05 00:24:28 -07:00
Slava Pestov
584eda38ed ClangImporter: More principled use of mapType{Into,OutOf}Context()
Before we would construct types containing a mix of interface and
contextual types, and then map them in and out. Straighten this out.

Note that I've also had to start untangling the issue where
synthesized ParamDecls do not have an interface type.
2016-07-02 05:36:35 -07:00
Slava Pestov
680688cbf5 AST: Cleanups for TypeBase::getSuperclass()
First, enforce that the superclass of a class is an interface type.
Previously, Swift classes used interface types but imported
Objective-C generics used archetypes.

When the superclass type is always an interface type, we
can use the recently-added gatherAllSubstitutions() instead of
rolling our own parent type walk.

Also, this exposed an issue in name lookup where we would call
getSuperclass() on a type whose parent was an unbound generic.
This doesn't make sense, so generalize the existing check there.
2016-07-02 05:35:16 -07:00
Slava Pestov
409af27eb3 Sema: Use DeclContext::getSelfInterfaceType() and DeclContext::getSelfTypeInContext() more, NFC
There are many places where we do the 'if inside a protocol, get the
Self type parameter, otherwise, use the declared type' dance.
We actually have really handy utility methods that encapsulate this,
so let's use them more.
2016-07-02 05:35:15 -07:00
Jordan Rose
3b6e40c030 Use ClassDecl::ForeignKind to model Clang's objc_runtime_visible.
We're now correctly checking for inheritance, adding @objc methods,
and adding @objc protocols for both CF types and objc_runtime_visible
classes (those without visible symbols). The latter is used for some
of the types in Dispatch, which has exposed some of the classes that
were considered implementation details on past OSs.

We still don't properly implement using 'as?' to check conformance to
a Swift protocol for a CF or objc_runtime_visible type, but we can do
that later.

rdar://problem/26850367
2016-06-30 11:20:58 -07:00
Jordan Rose
53118e9a5f Split the "Foreign" flag into a ForeignKind enum.
This flag tracks whether we have a special kind of imported class
that has limitations in what you can do with it. Currently it's
used for two things: CF classes, and the magic "Protocol" class used
to represent Objective-C protocol metadata. I'm planning to add a
third to handle classes with the recently-added objc_runtime_visible
attribute, which describes an Objective-C class whose runtime symbols
are hidden (forcibly preventing categories and subclassing). This is
used for some of the types in Dispatch, which has exposed some of the
classes that were considered implementation details on past OSs.

I'm splitting the flag into an enum rather than just marking the
Dispatch classes with the existing flag because we still need to
be able to /cast/ to the Dispatch types (which you can't do with CF
types today) and because they deserve better than to be lumped in
with CF for diagnostic purposes.

Groundwork for rdar://problem/26850367, which is that Swift will
happily let you extend the new Dispatch classes but then fails to find
the symbols at link-time.
2016-06-29 14:20:21 -07:00
Mishal Shah
87b7bcfd3e Update master to build with Xcode 8 beta 1, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs. 2016-06-14 14:53:55 -07:00
Trent Nadeau
78a420d850 Made use of @warn_unused_result a warning with a fixit (#2760)
https://bugs.swift.org/browse/SR-1052
2016-06-08 10:10:21 -07:00
Doug Gregor
ee85891d11 Revert "[Type checker] Be more rigorous about extracting argument labels from calls."
This reverts commit 3753d779bc. It's
causing some type-inference problems I need to investigate.
2016-06-03 10:21:27 -07:00
Doug Gregor
3753d779bc [Type checker] Be more rigorous about extracting argument labels from calls.
Whenever we have a call, retrieve the argument labels from the
argument structurally and associate them with the callee. We were
previously doing this as a separate AST walk (which was unnecessary),
so fold that into constraint generation for a CallExpr. We were also
allowing weird ASTs to effectively disable this information: tighten
that up and require that CallExprs always have a ParenExpr, TupleExpr,
or (as a temporary hack) a TypeExpr whose representation is a
TupleTypeRepr as their argument prior to type checking. This gives us
a more sane AST to work with, and guarantees that we aren't losing
label information.

From the user perspective, this should be NFC, because it's mostly AST
cleanup and staging.
2016-06-02 17:15:51 -07:00
Slava Pestov
0d3ef548e7 ClangImporter: Add support for __attribute__((availability(..., replacement="")))
We map clang::AvailabilityAttr::getReplacement() to
swift::AvailableAttr::Rename, transforming the replacement
name using by looking up the named Clang replacement, and
importing its name.

Fixes <rdar://problem/26301742>.
2016-06-01 23:12:48 -07:00
Slava Pestov
112511cd1c Remember to set AbstractFunctionDecl's generic signature in a few places
I originally added this so that we would keep the signature around
even if type checking failed, and the function was given an
ErrorType.

Add a formal check to the AST verifier for this, and set the signature
in a few places where it wasn't being set.

Note that since we only serialize valid declarations, we don't have
to serialize a reference to the generic signature separately, but we
do have to remember to set it when deserializing, which wasn't being
done for destructors.
2016-05-28 22:30:40 -07:00
Michael Ilseman
d79546a3d7 Merge pull request #2751 from milseman/newtype_fixit
[Import as Member] Print full context in fixit
2016-05-27 13:38:12 -07:00
Michael Ilseman
22ec60007a [Import as Member] Print full context in fixit
Due to swift_name and swift_newtype, we are frequently importing onto
different contexts. This was confusing the fixit logic for unavailable
swift2 names, as we were trying to use Clang names when the Swift name
might be totally different (and even a nested type). This change has a
two-fold effect:

1) Globals who are imported onto swift_newtype-ed typedefs should be
   considered ImportAsMember.
2) When printing out the name of an ImportAsMember Swift 3 decl, we
   need to print out a fully qualified context, which also uses the
   Swift names, not the Clang names.
2016-05-27 11:39:19 -07:00
Joe Groff
b47b16850b Merge pull request #2731 from jckarter/objc-generic-protocol-conformance
Clang importer: Fix the 'self' type of imported ObjC generic members.
2016-05-26 19:11:05 -07:00
Joe Groff
615cfd4a10 Clang importer: Fix the 'self' type of imported ObjC generic members.
A variable was called `selfInterfaceType` even though it was inconsistently set to a contextual Self archetype for protocols, and an interface type for nominal types, and the one place we used the type expected to work with contextual types. Fixes rdar://problem/26396895.
2016-05-26 16:34:56 -07:00
Jordan Rose
239b5e02a6 [ClangImporter] Import NS_OPTIONS 0 values with explicit Swift-names.
This shows that the owner of the option set has thought about the
zero case, and wants it to be available in Swift, rather than disabling
it with the default "use [] to construct an empty option set" message.

rdar://problem/26290766
2016-05-26 11:08:24 -07:00
Joe Groff
9d86ca26df Merge pull request #2686 from jckarter/generic-anyobject-chaining-properties-subscripts
SILGen: Fix crashes when conditionally looking up generic subscripts and properties via AnyObject.
2016-05-25 09:46:12 -07:00
Slava Pestov
19f72c8593 ClangImporter: Fix diagnostics for NS* prefix stripping from generic types
We were failing to create an unavailable TypeAlias for the old name
in the case the renamed type was generic, leading to poor diagnostics.

Also, Sema resolves generic TypeAliases very early, while building
a Type from a TypeRepr -- this means the unavailable/deprecated
check runs too late to catch generic TypeAlises.

Add a hack where we preserve a reference to the original TypeAliasDecl
by way of constructing a SubstitutedType which desugars to the
replacement type, rather than resolving the replacement type
directly, so that the availability check can pick it up.

A better fix for this would be to introduce a BoundGenericAliasType
sugared type, but that's a bigger change that can come later.

Fixes <rdar://problem/26206263>.
2016-05-25 00:32:11 -07:00
Doug Gregor
abc42b459e [Clang importer] Allow a CF type spelled with "void *".
There wasn't any justification for the "const" restriction. Fixes
rdar://problem/24821660.
2016-05-24 22:39:20 -07:00
Joe Groff
5e2b20d05f SILGen: Fix crashes when conditionally looking up generic subscripts and properties via AnyObject.
The fix for methods to lower the dynamic method type from the substituted AST type of the expression also needed to be applied to the optional chaining, subscript, and property paths.

This also exposed a problem in the Clang importer, where imported subscript accessors would get the unbound generic context type as their Self parameter type instead of the type with the correct generic parameters. Fix this by renaming the all-too-convenient ParamDecl::createSelf factory to `createUnboundSelf`, and introduce a new `createSelf` that uses the bound generic type.

Fixes rdar://problem/26447758.
2016-05-24 19:18:37 -07:00
Michael Ilseman
bd3e590925 [Clang importer] Comments and cleanup. NFC 2016-05-24 10:12:08 -07:00
Michael Ilseman
134f41ccae [Clang importer] Use OptionSets for makeStructRawValued
NFC
2016-05-23 16:21:17 -07:00
Michael Ilseman
e0414a457f [swift_newtype] Structs have label-less init
Adds an unlabeled rawValue init for swift_newtype(struct), which
expresses the extensibility theme better.  This makes the use and
creation of new instances of that type more succinct.
swift_newtype(enum) still requires the explicit label, as it is
non-extensible.
2016-05-23 14:40:41 -07:00
Slava Pestov
170992c39f AST: Add Throws flag and ThrowsLoc to AbstractFunctionDecl
The verifier now asserts that Throws, ThrowsLoc and isBodyThrowing()
match up.

Also, add /*Label=*/ comments where necessary to make the long argument
lists easier to read, and cleaned up some inconsistent naming conventions.

I caught a case where ClangImporter where we were passing in a loc as
StaticLoc instead of FuncLoc, but probably this didn't affect anything.
2016-05-21 12:51:50 -07:00
Doug Gregor
1255a5cdb9 [Clang importer] Make sure an unavailable superclass init doesn't override an available import-as-member-init.
More generally, an unavailable initializer shouldn't stomp on an
available initializer, because it's possible that (for example) a
designated initializer will be unavailable but a factory initializer
will be available, so one still construct objects of that type.
Fixes rdar://problem/26238032.
2016-05-20 09:39:57 -07:00
David Farler
ee4d9d36aa [QoI] Don't skip over protocols when importing Swift 2 type aliases
Protocols have the implicit Self generic parameter, which was
preventing this type alias from getting created, so some renamed
imported protocols for Swift 3 weren't emitting the expected
diagnostics and fix-its.

rdar://problem/26304496
2016-05-20 09:18:09 -07:00
Jordan Rose
2fa3da4089 Drop the notion of "alias" names for CF types.
Previously we imported a Core Foundation type "CCFooRef" as "CCFoo",
but also provided a typealias "CCFooRef". In Swift 3, we decided to
mark "CCFooRef" unavailable to force developers to consistently use
"CCFoo". Now that we have infrastructure to mark /all/ renamed
declarations as unavailable, just use that to track the renaming,
i.e. pretend that "CCFooRef" was the "Swift 2" name for the type.

This doesn't change the conflict resolution behavior: if there's
another name "CCFoo" in the same module, the CF type will be
imported as just "CCFooRef".

Groundwork cleanup for rdar://problem/26347297, which notes that our
import-as-member fix-its use the "Ref" names rather than the short
names.
2016-05-19 13:21:47 -07:00
Joe Groff
7154c6167b Stray punctuation, NFC 2016-05-16 13:11:49 -07:00
Jordan Rose
26e1f5be27 [ClangImporter] Don't include Swift members in AnyObject lookup. (#2503)
More specifically, don't include declarations of methods and properties
in the list of "all imported Objective-C members" if said method or
property is in a generated header. (We actually key off of whether the
enclosing class, protocol, or category is marked as coming from Swift,
but since users aren't supposed to modify generated headers themselves
it's much the same thing.)

This previously caused a crash because we tried to import a Clang member
onto a Swift decl in order to provide the particular member on AnyObject.

rdar://problem/25955831 and probably also rdar://problem/25828987, which
deals with the fix-it to migrate to #selector. (We do an AnyObject-like
lookup to find out which class likely implements the specified selector.)
2016-05-12 16:58:31 -07:00
Doug Gregor
dfc8d5a5f8 [Sema/SILGen] Track per-source-file "used" conformances to reference in SILGen
Sema was dutifully tracking conformances that were "used" as part of
type checking, so it could make sure that those conformances got
completed for SILGen to use. However, this information never actually
made it to SILGen, which included its own (more conservative, not
broad enough) heuristics for finding "used" conformances. Teach Sema
to record conformances within the appropriate source file, and have
SILGen reference the conformances when it emits SIL for the source
file.
2016-05-09 20:43:12 -07:00
Michael Ilseman
c62eb2e5aa [swift_newtype] Handle un-audited CF types
Special case logic for CF types, which may be coming in as
unmanaged. In this case, we will use audit information if present to
import with the new type, otherwise we have to fall back to
Unmanaged<CF...>.

We still import global variables that must be unmanaged onto the new
type, though they keep their unmanaged types. This helps to
consolidate the definitions, as well as make future migration easier
if they get audited.

Test cases included.
2016-05-09 14:26:26 -07:00
Michael Ilseman
b5d29b54d2 [swift_newtype] Also newtype up CF Ref types.
Code cleaup and generalization to also catch typedefs of CF reference
types. Tests will be included in a subsequent commit, as this now
exhibits a latent problem when interacting with Unmanaged.
2016-05-09 11:48:18 -07:00
Doug Gregor
b4a58650dd [SE-0033] Add _SwiftNewtypeWrapper protocol for swift_newtype'd types.
This protocol lets us identify swift_newtype'd types. More
importantly, use protocol extensions to make it easy to transfer
specific conformances from the underlying type to the wrapper
type. So, for example, if the underlying type is Hashable, make the
wrapper type Hashable as well. Do the same for Equatable, Comparable,
and _ObjectiveCBridgeable. Fixes rdar://problem/26010804.
2016-05-08 22:34:39 -07:00
Michael Ilseman
a8cebdc5d3 [swift_newtype] Special handling for Notifications
We now specially import global decls who we identify as fitting the
notification pattern: extern NSStrings whose name ends in
"Notification". When we see them, we import them as a member of
NSNotificationName and, if NSNotificationName is swift_newtype-ed, we
use that new type.

Test cases included.
2016-05-08 19:17:32 -07:00
Doug Gregor
26fcf1ab4a [Clang importer] Properly create getter for bridged swift_newtype's rawValue.
When swift_newtype is introducing a new Swift type that wraps a
bridged type, the actual storage (called _rawValue) matches the
Objective-C type and "rawValue" itself is a computed
properly. Properly create the getter for that computed property, which
performs a bridging conversion.
2016-05-08 00:51:02 -07:00
Doug Gregor
3739470553 [Clang importer] Fix rawValue initializer for swift_newtype'd types.
The code was creating a new "self" rather than using the existing
"self", which was caught by DI.
2016-05-08 00:00:50 -07:00
Ted Kremenek
d3c41c4668 Revert "Revert "SE-0072: Fully eliminate implicit bridging conversions from Swift"" (#2441) 2016-05-06 23:26:45 -07:00
Ted Kremenek
4df003c291 Revert "SE-0072: Fully eliminate implicit bridging conversions from Swift" (#2440) 2016-05-06 23:22:56 -07:00
Doug Gregor
2fd0a9f79e [Clang importer] Don't import swift_newtype'd underlying types as optional. 2016-05-06 22:32:38 -07:00
Joe Pamer
6af546e89e Merge pull request #2419 from apple/se-0072
SE-0072: Fully eliminate implicit bridging conversions from Swift
2016-05-06 22:14:13 -07:00
Doug Gregor
55a3f5398c [Clang importer] Import Swift 2 "stubs" to improve errors in "Swift 2" code.
When attempting to compile Swift 2 code (or any Swift code using the
Swift 2 names) in Swift 3, the compiler diagnostics are often entirely
useless because the names have changed radically enough that one
generally gets "no member named 'foo'" errors rather than a helpful
"'foo' was renamed to 'bar'" error. This makes for a very poor user
experience when (e.g.) trying to move Swift 2 code forward to Swift 3.

To improve the experience, when the Swift 2 and Swift 3 names of an
API differ, the Clang importer will produce a "stub" declaration that
matches the Swift 2 API. That stub will be marked with a synthesized
attribute

  @available(unavailable, renamed: "the-swift-3-name")

that enables better diagnostics (e.g., "'foo' is unavailable: renamed
to 'bar') along with Fix-Its (courtesy of @jrose-apple's recent work)
that fix the Swift 2 code to compile in Swift 3.

This change addresses much of rdar://problem/25309323 (concerning QoI
of Swift 2 code compiled with a Swift 3 compiler), but some cleanup
remains.
2016-05-06 21:12:20 -07:00
Doug Gregor
9f6734312d [Clang importer] Factor the checking for -enable-swift-newtype more sensibly. NFC 2016-05-06 16:45:13 -07:00
Jordan Rose
e0e5563a96 [ClangImporter] Allow NS_SWIFT_NAME to just specify a base name.
...when renaming C functions. This is currently rejected by Clang
itself, but showed up when testing apinotes. Rather than complicate
the apinotes by including parameter placeholders, just do the
obvious thing (and future-proof against us potentially allowing this
in the future).

rdar://problem/26133744
2016-05-06 11:25:30 -07:00
Joe Pamer
3b4d98445e SE-0072: Fully eliminate implicit bridging conversions from Swift
Per Swift Evolution proposal SE-0072, these changes prevent the compiler from introducing implicit bridging conversions during type checking.
2016-05-05 19:36:33 -07:00
Chris Willmore
af0c7bd620 Initial implementation of SE-0054 "Abolish IUO Type" (#2322)
This is a squash of the following commits:

* [SE-0054] Import function pointer arg, return types, typedefs as optional

IUOs are only allowed on function decl arguments and return types, so
don't import typedefs or function pointer args or return types as IUO.

* [SE-0054] Only allow IUOs in function arg and result type.

When validating a TypeRepr, raise a diagnostic if an IUO is found
anywhere other thn the top level or as a function parameter or return
tpye.

* [SE-0054] Disable inference of IUOs by default

When considering a constraint of the form '$T1 is convertible to T!',
generate potential bindings 'T' and 'T?' for $T1, but not 'T!'. This
prevents variables without explicit type information from ending up with
IUO type. It also prevents implicit instantiation of functions and types
with IUO type arguments.

* [SE-0054] Remove the -disable-infer-iuos flag.

* Add nonnull annotations to ObjectiveCTests.h in benchmark suite.
2016-05-03 14:06:19 -07:00