Commit Graph

1877 Commits

Author SHA1 Message Date
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
Doug Gregor
c40b45eb8c [Clang importer] Factor out and tidy up global-as-initializer import. 2016-03-06 21:57:37 -08:00
Doug Gregor
d88f546f0a [Clang importer / Interface printing] Print extensions in the appropriate submodule.
When printing the interface for a (sub)module, make sure that we only
print those extensions that were created to hold that submodule's
globals that were imported as members.
2016-03-04 17:21:13 -08:00
Michael Ilseman
e452b38119 [Clang Importer] Import as methods
Print module functionality hooked up to import global functions a
methods, if dictated by the swift_name attribute. Test case included.

No SILGen support yet.
2016-03-03 21:58:57 -08:00
Doug Gregor
08c8155d6c [Clang importer] Eliminate importGlobalsAsMembers. NFC 2016-03-03 17:25:58 -08:00
Doug Gregor
42f0356aec [Clang importer] Wire up extensions for globals-as-members.
Wire up the extensions created when importing globals-as-members via
the same mechanisms we use for Objective-C categories, e.g.,
implementing loadAllExtensions() to find the extensions and lazily
loading their members via the member loader. Addresses most of my
comments on the way extensions were wired in.

Extend our testing for importing globals as members to two different
submodules, so we can see the separation of extensions.

As part of this, fold getOrCreateExtension into importDeclContextOf.
2016-03-03 17:22:47 -08:00
Michael Ilseman
a54221f4f1 [Clang Importer] Turn on import as init
Specially identify and import-as-init. Module printing works, but not
SILGen.

This will break any SILGen tests over a file that imports a module
with an import-as-init name, as newly imported inits are not hooked up
correctly.
2016-03-03 16:30:10 -08:00
Michael Ilseman
e32353ec03 [Clang Importer] getOrCreateExtensionPoint for import as member
When importing as a member, we want a single unique extension
declaration per type per Clang submodule. This adds the mapping,
switches import-as-member VarDecl importing to use it, and forces the
created extensions to show up.
2016-03-02 23:30:17 -08:00
Michael Ilseman
c247bbf5b6 [Clang Importer] Import as member: bare bones variables.
Adds tentative and very basic functionality for importing global
variables as members of structs and classes. Test case added
2016-03-02 22:19:37 -08:00
Doug Gregor
3ffbe020d7 [Clang importer] Handle name mapping for "getter:" and "setter:" in swift_name.
The swift_name string format now supports "getter:" and "setter:"
prefixes to indicate that a function is the getter or setter of a
Swift-synthesized property. Start parsing these DeclNames and make
sure they're reflected in the Swift name lookup tables.

[Clang update required]
2016-03-01 15:33:21 -08:00
Doug Gregor
7265328e07 [Clang importer] Generalize name lookup tables for globals-as-members.
A swift_name attribute on a global declaration can specify a dotted
name (e.g., SomeStruct.member) to map that global into a member of the
(Swift-)named type. Handle this mapping in DeclName parsing, plumb it
through importFullName, and cope with it in the Swift name lookup
tables (tested via the dump) and importing into a Swift DeclContext
(as-yet-untested). Part of SE-0033.
2016-03-01 15:33:20 -08:00