Commit Graph

687 Commits

Author SHA1 Message Date
David Farler
949d9b6a60 ClangImporter: Bump the CoreImage SDK Epoch
rdar://problem/26403639
2016-05-24 18:39:09 -07:00
Jordan Rose
28757ab2de [ClangImporter] Don't put forward-declared structs in the lookup table. (#2610)
Merge pull request #2610 from jrose-apple/cg-import-as-member
2016-05-23 14:23:21 -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
Jordan Rose
a4162c5d79 [ClangImporter] Don't put forward-declared structs in the lookup table.
Otherwise, the lookup table for "CGColor" has two entries, because of
this:

    typedef struct CGColor *CGColorRef;

and that interferes with our ability to import things as members of
"CGColor" (as opposed to "CGColorRef"), which affects the fix-its we
generate when you try to use the non-member form.

This isn't necessarily the best long-term solution (as noted in the
FIXME) but it is expedient and won't break any current users.

More rdar://problem/26347297
2016-05-19 18:00:19 -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
John McCall
79c83c7303 Teach IRGen to tell Clang to emit lazy definitions on demand.
Previously, we had hacks in place to eagerly emit everything in
the global ExternalDefinitions list.  These can now be removed,
at least at the IRGen layer.
2016-05-18 22:48:45 -07:00
Jacob Mizraji
7b7122fc11 Update ClangImporter and IRGenDebugInfo to build with upstream clang
(cherry picked from commit dab04d0517)
(cherry picked from commit d6b6594d77e01f5bb006897a42ec0a65665fcb9d)
2016-05-13 22:03:27 -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
Jordan Rose
fee9c2a130 Allow importing pointer-returning methods as throwing. (#2420)
Leftover bits of SE-0055. Now that pointer nullability is reflected
in the type system, we can properly import throwing methods with
non-object pointer return types.

Note that Swift still won't let you declare them. That's coming next.
2016-05-09 09:58:09 -07:00
Doug Gregor
de7ef4b676 [Clang importer] Don't prefix-strip notification names. 2016-05-08 23:55:50 -07:00
Michael Ilseman
8ca22f8729 [Clang importer] Minor cleanup 2016-05-08 22:01:06 -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
c390c97255 [Clang importer] Minor fixes for swift_newtype name adjustments. 2016-05-07 14:44:48 -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
Ryan Lovelett
0c0bcbb094 Convert "armv7l" to "armv7" for the architecture component of paths (#2369)
On the Raspberry Pi 2 when trying to import Glibc, without this patch, it will attempt to
find the module map at "/usr/lib/swift/linux/armv7l/glibc.modulemap" and
fail to do so.

With this patch it will attempt to find the module map at
"/usr/lib/swift/linux/armv7/glibc.modulemap" where it will succeed in
finding the module map.

Similar behavior currently happens in the Driver and Frontend. To DRY up
this behavior it has been extracted to the Swift platform.
2016-05-02 15:25:58 -07:00
Jordan Rose
d7b3b6a462 Validate the "renamed" argument to @available.
It should have the same form as the argument to NS_SWIFT_NAME
in Objective-C, except that it permits operators and (currently)
disallows instance members and properties. We do get to share the
same parsing code, at least.

This actually caught an error in the Foundation overlay!

Groundwork for SR-1008.
2016-04-28 20:21:30 -07:00
Doug Gregor
60ac5d612e [Clang importer] libdispatch epoch 0 is the dawn of dispatch time. 2016-04-26 17:15:00 -07:00
Doug Gregor
a2e03d556b Stage implementation of SE-0033 behind a flag, -enable-swift-newtype.
We're going to quarantine this feature behind a frontend flag for a
bit.
2016-04-25 18:03:04 -07:00
Todd Fiala
42d97ed7dc Merge pull request #2279 from tfiala/SR-1109-fix
fix SR-1109: don't use the clang resource override dir for glibc
2016-04-23 15:35:44 -07:00
Todd Fiala
b89c37f2bc fix SR-1109: don't use the clang resource override dir for glibc 2016-04-22 17:52:49 -06:00
Michael Ilseman
476f92d2de [Clang Importer] Only strip common prefix for swift_newtype
Rather than do whole-word common-word stripping, we only strip common
prefixes. This is not as powerful as what was originally intended, but
much less magical in the mapping into Swift.

Test case adjusted, and common utility functions exposed.
2016-04-22 16:26:19 -07:00
Michael Ilseman
faceb558d7 [Clang Importer] Initial support for swift_newtype(struct)
This introduces support for swift_newtype(struct) attribute (also
known as swift_wrapper). The Clang importer will create a brand new
struct corresponding to the annotated typedefs, which has a backing
raw value. Globals of that type are imported as static members on the
struct.

Additionally, this interacts seamlessly with prior import-as-member
work, meaning that the newly created type can be imported onto. Tests
included.
2016-04-21 16:40:10 -07:00
Michael Ilseman
13c2a3427a [Import as member] Temporary hack to work around a clang module cache issue 2016-04-06 12:55:07 -07:00
Michael Ilseman
74ba9ede7f [Import as member] Check the module attribute to kick of inference 2016-04-06 11:03:18 -07:00
Doug Gregor
9e2c68866c [Clang importer] Be robust against invalid Objective-C categories.
The Clang importer was crashing when encountering an Objective-C
category for an unknown class. Fixes rdar://problem/24244116.
2016-04-05 13:55:24 -07:00
Doug Gregor
c5252c8247 [Clang importer] Add an epoch for libdispatch 2016-04-05 09:41:49 -07:00
Doug Gregor
138bbe2167 [Clang importer] Delay resolution of import-as-member declarations when needed.
It's possible for swift_name to make a global declaration into a
member of another entity that has not been seen yet. In such cases,
delay resolution until the end of the translation unit (module). Fixes
the rest of rdar://problem/25502497.
2016-04-05 00:03:36 -07:00
practicalswift
abfecfde17 [gardening] if ([space]…[space]) → if (…), for(…) → for (…), while(…) → while (…), [[space]x, y[space]] → [x, y] 2016-04-04 16:22:11 +02:00
Arnold Schwaighofer
43ec6ad74b Don't disable stripping the name when -disable-swift-bridge-attr is enabled 2016-03-31 10:25:54 -07:00
practicalswift
bbef13a050 [gardening] Fix recently introduced typo: "attribtue" → "attribute"
[gardening] Fix recently introduced typo: "delinated" → "delineated"

[gardening] Fix recently introduced typo: "abstactions" → "abstractions"

[gardening] Fix recently introduced typo: "cannoted" → "cannot"

[gardening] Fix recently introduced typo: "accomodate" → "accommodate"

[gardening] Fix recently introduced typo: "bulding" → "building"

[gardening] Fix recently introduced typo: "abstactions" → "abstractions"

[gardening] Fix recently introduced typo: "intiializers" → "initializers"
2016-03-30 18:20:53 +02:00
Arnold Schwaighofer
7a129649bc Add a hidden flag to disable the swift bridge attribute
This will be used for writing performance tests
2016-03-29 14:12:45 -07:00
Chris Willmore
3bcb169f0b Import lightweight Objective-C generics as Swift generic type
parameters.
2016-03-28 09:50:30 -07:00
practicalswift
c9facfbbac [gardening] Weekly gardening: typos, duplicate includes, header formatting, etc. 2016-03-25 14:14:19 -07:00
Michael Ilseman
47e73ad4f1 Merge branch 'master' of github.com:apple/swift into import-as-member 2016-03-23 17:01:47 -07:00
Michael Ilseman
d7581d1b36 Merge commit 'a31edf53d0580efe47f4e9ef89dccc4429c056e8' into import-as-member 2016-03-23 13:05:57 -07:00
Doug Gregor
5b97f8eeb9 [Clang importer] Don't strip prefixes from swift_bridge'd classes or their subclasses.
Part of rdar://problem/24050011.
2016-03-23 11:32:36 -07:00
Doug Gregor
593932741c Remove historical flags -enable-omit-needless-words/-enable-infer-default-arguments/-enable-swift-name-lookup-tables.
NFC; all of these options are always-on now and we no longer have a
way to turn them off.
2016-03-22 17:04:19 -07:00
Doug Gregor
865288941d [Clang importer] Only strip "NS" prefix from types and protocols.
Part of rdar://problem/24050011.
2016-03-22 14:55:50 -07:00
Doug Gregor
0bdbce653c [Clang importer] Propagate NS prefix stripping flag correctly. 2016-03-22 14:08:13 -07:00
Brian Gesiak
c6121d56b1 [Un-revert][Glibc] Configure modulemap for target, not host
This reverts commit f2154ee94d, which reverted 04e1cd5bda. The original
commit needed to be reverted because of an issue in which install
targets were added to OS X builds that did not target Linux. This
addresses that issue by guarding all the Linux-only CMake logic with a
check for the SDK being built.
2016-03-16 14:55:33 -04:00
Michael Ilseman
f2154ee94d Revert "[Glibc] Configure modulemap for target, not host" 2016-03-16 09:47:52 -07:00
Brian Gesiak
5e24af7fba Merge pull request #1679 from modocache/target-specific-glibc
[Glibc] Configure modulemap for target, not host
2016-03-16 01:08:16 -04:00
Brian Gesiak
04e1cd5bda [Glibc] Configure modulemap for target, not host
The current Glibc CMakeLists.txt uses the host machine to determine
which modulemap to use. The same modulemap can't be used for all
platforms because headers are available in different locations on
different platforms.

Using the host machine to determine which modulemap to configure and
place at a specific path in the resource dir is fine, so long as:

1. Only one Glibc is being compiled in a single CMake invocation.
2. The target machine needs the same modulemap as the host.

https://github.com/apple/swift/pull/1442 violates both of these
assumptions: the Glibc module for both Linux and Android is compiled
at the same time, and the Android target can't use the Linux modulemap.

This commit instead uses the target(s) to determine which
modulemap to use. The modulemap is configured and placed in an OS-
and architecture-specific directory in the resource dir. The path to
that modulemap is referenced by the ClangImporter (since it is no
longer at a path that is automatically discovered as an implicit
modulemap).
2016-03-15 18:40:17 -04:00
Doug Gregor
c7dfed7b5a Merge pull request #1449 from jrose-apple/c-decls-in-objc-interface
[ClangImporter] Record C declarations found in @interfaces.
2016-03-14 11:31:45 -07:00
Michael Ilseman
de37991151 [Swift lookup table] hash InferImportAsMember option 2016-03-08 18:24:09 -08:00
Michael Ilseman
c39aebce24 [Clang importer] Infer static properties and methods
Adds inference support for static properties and methods, requiring us
to accurately do longest-prefix typename searches.

Tests cases included.
2016-03-07 16:36:59 -08:00
Michael Ilseman
ff03498797 [Clang importer] Hook up inference system
Import as member inference hooked up, though not producing the final
results we want, yet.

Basic test case included.
2016-03-07 10:37:34 -08:00
Michael Ilseman
1b83dee698 [Clang importer] Inferr import as member flags
Plumbing for -enable-infer-import-as-member options and flags.Tests
coming soon.
2016-03-06 23:54:56 -08:00
Doug Gregor
94ba6e7a16 [Clang importer] Test import-as-member with CF types. 2016-03-06 22:31:51 -08:00