Commit Graph

514 Commits

Author SHA1 Message Date
Chris Willmore
3bcb169f0b Import lightweight Objective-C generics as Swift generic type
parameters.
2016-03-28 09:50:30 -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
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
0e40128d1a [Clang importer] Use Clang swift_bridge attribute for bridging.
When an Objective-C class type is annotated with the swift_bridge
value type, bridge it to the named type. Use API notes on Foundation
rather than special cases.

For Objective-C classes where bridging was baked into the Clang
importer (NSString, NSArray, NSDictionary, NSSet), add API notes to
put the appropriate swift_bridge attribute on these Objective-C
classes.

Note: requires Clang update.
2016-03-10 23:10:28 -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
47b2be3138 [Clang importer] Import a getter or getter/setter pair as a property.
When a global function is determined to be a lone getter or a
getter/setter pair, import it as a property. Handle global, instance,
and static properties.

As part of this, generalize importAsMethod to also handle static
methods and map pointer-to-non-const arguments to 'mutating' methods.
2016-03-06 21:25:43 -08:00
Doug Gregor
af3769773e [Clang importer] Fix the use-after-free with enum info harder.
This is more of rdar://problem/24869070; StringRefs are leaking out of
importFullName still, in a DenseMap that can get deallocated. When we
cache this data, put them in "permanent" (Swift ASTContext) storage.
2016-03-04 14:37:03 -08:00
Doug Gregor
b2eafa4c85 [Clang importer] Fix a use-after-free in enum info caching.
Also, make the cache kick in between when a module is built and when
it is used. This isn't actually an important case, but it makes it a
whole lot more common to actually see the use-after-free break things.

Fixes rdar://problem/24869070.
2016-03-03 22:08:50 -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
Michael Ilseman
98e1d2d1ae [Clang Importer] cleanup import-as-init code
NFC
2016-03-03 18:13:53 -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
678c42490c [Clang Importer] import as member: Refactor out shared functionality
NFC
2016-03-03 16:23:42 -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
practicalswift
b4be924c64 [gardening] Fix recently introduced typo: "contet" → "context" 2016-03-01 11:28:42 +01:00
Doug Gregor
940a65a994 [Clang importer] Make the "effective context" a core part of ImportedName.
Previously, the "effective context" parameter to importFullName was
used only during the construction of Swift name lookup tables, so we
can associate each declaration with a context. Expand the role of
"effective context" so it is always a part of ImportedName and is also
used by importDecl when actually importing the enum declaration.

This is partially a cleanup, and partially staging for SE-0033, which
will require this functionality more broadly.
2016-02-29 15:32:34 -08:00
Andrew Trick
ff02652108 Move enums into AttrKind.h.
This reorganization allows adding attributes that refer to types.
I need this for a @_specialize attribute with a type list.

PrintOptions.h and other headers depend on these enums. But Attr.h
defines a lot of classes that almost never need to be included.
2016-02-26 21:10:22 -08:00
Doug Gregor
7d2273fe57 [Omit needless words] Don't infer empty option sets for setters.
Fixes rdar://problem/24618895.
2016-02-22 14:11:09 -08:00
Doug Gregor
c1cc39accc [Clang importer] Rely on Clang's mapping of API notes to attributes directly.
Rather than managing API notes directly in the Clang importer, tell
Clang where to find the API notes files and let it map them directly
to attributes. Then, use the existing attribute-mapping
mechanisms---with minor extensions for cases where Clang previously
didn't map some Swift-specific API notes---to get at that information.

There is a minor regression where we can no longer apply API notes to
declarations that don't have a specific Clang declaration. The
specific example (NSError's inherited init()) comes from
rdar://problem/21042412; we've regressed here, but the correct fix is
(and has always been) on the Objective-C side
(rdar://problem/19977891).

Finishes rdar://problem/24447420.
2016-02-18 16:48:02 -08:00
Doug Gregor
ca736fd27c [Omit needless words] Ensure Swift name consistency for overriding/overridden decalrations.
When we transform an Objective-C method or property name, we take into
account the parameter types, result type, and type of the enclosing
context. Doing so means that one can get different Swift names for a
particular method (or property) and one that overrides it, which leads
to dangerous inconsistencies in the Swift names. Address this
limitation by using the original declaration's name (i.e., one that
does not override any other).

It is possible that there is more than one "original declaration",
when the same method/property name comes from different
protocols. When this is the case, check for consistency and complain
if there are inconsistencies.

Amusingly, this changes exactly one method in Cocoa
(UINavigationController's showViewController:sender:), with no conflicts
detected. Fixes rdar://problem/24558337.
2016-02-17 23:35:41 -08:00
practicalswift
b1685652f3 [gardening] Fix recently introduced typo: "perfom" → "perform" 2016-02-11 19:13:10 +01:00
Doug Gregor
8aaf014de6 [Clang importer] Cache enum information based on modulename.enumname.
Caching information based on Clang declaration pointers, when that
information is used via importFullName, is unsafe because the
declaration pointers may point into Clang AST contexts built
temporarily built for modules, and therefore go stale. I believe this
is the cause of the recent ASan failures.

Again, the whole passing-through-a-different-Clang-Sema thing with
importFullName is an architectural fail that requires refactoring, so
we don't keep falling into this trap.
2016-02-10 13:32:38 -08:00
Doug Gregor
1eb1adac6b [Clang importer] Remove unused DenseMap. NFC 2016-02-10 13:32:38 -08:00
Michael Ilseman
283bfefb14 Merge pull request #1196 from milseman/error_enum
[Clang Importer] Import ns_error_domain attribute with _BridgedNSError
2016-02-04 20:45:29 -08:00
Michael Ilseman
c8be2873e8 [Clang Importer] Refactor information pertaining to enums out
Introduces new class, EnumInfo, just for the implementation of the
ClangImporter to encapsulate various computed information about the
enum we're importing.

This helps refactor some functionality, aids clarity, and also
prevents us from repeating calculations multiple times, as we were
doing with classifyEnum's macro-expansion tracking. Provides a base
where we can add more heavy lifting in classifyEnum in the future.
2016-02-04 16:57:22 -08:00
Doug Gregor
319e2a7462 [Clang importer] Strip "NS" prefix from macro names, too 2016-02-03 21:03:09 -08:00
Doug Gregor
8e000fb738 [Clang importer] Factor mapping of macro names into a single location. NFC 2016-02-03 16:11:59 -08:00
practicalswift
a3f857ca7b [gardening] Add "-*- C++ -*-" to header files currently missing it 2016-01-23 11:53:05 +01:00
Doug Gregor
312a7f0aea [Clang importer] Strip the "NS" prefix from entities in Foundation.
As part of the improved import of Objective-C APIs into Swift, strip
the "NS" prefix from entities defined in the Foundation
framework. Addresses rdar://problem/24050011, which is part of
SE-0005. Naturally, this is hidden behind -enable-omit-needless-words.
2016-01-20 15:02:54 -08:00
Doug Gregor
72aabcb6f3 Revert "[Clang importer] Strip the "NS" prefix from entities in Foundation"
This reverts commit e51e969b35. This is
a temporary revert to aid in merging to the swift-3-api-guidelines branch.
2016-01-20 13:26:05 -08:00
Doug Gregor
679ee11898 [Clang importer] Eliminate retain cycle involving the Clang importer implementation.
The Clang importer implementation held on to a Clang instance, which
held a list of module file extensions, which included the Clang
importer implementation... break the cycle by separating out the
module file extension from the Clang importer. Fixes SR-562 /
rdar://problem/24225173.
2016-01-20 11:50:55 -08:00
Doug Gregor
e51e969b35 [Clang importer] Strip the "NS" prefix from entities in Foundation
As part of the improved import of Objective-C APIs into Swift, strip
the "NS" prefix from entities defined in the Foundation
framework. Addresses rdar://problem/24050011, which is part of
SE-0005. Naturally, this is hidden behind -enable-omit-needless-words.
2016-01-17 23:40:14 -08:00
Doug Gregor
0b6cedd961 [Clang importer] Infer default argument [:] for some NSDictionary parameters.
Both option set (CF_OPTIONS/NS_OPTIONS) and NSDictionary parameters
tend to be used as option sets. The former already get a default
argument of []. This commit adds a default argument of [:] for the
latter, identified by a parameter whose argument label involves
"options", "attributes", or "userInfo".
2016-01-06 14:08:11 -08:00
Doug Gregor
5aa40dd0aa Extend DefaultArgumentKind with cases for nil, [], and [:].
Under -enable-infer-default-arguments, the Clang importer infers some
default arguments for imported declarations. Rather than jumping
through awful hoops to make sure that we create default argument
generators (which will likely imply eager type checking), simply
handle these cases as callee-side expansions.

This makes -enable-infer-default-arguments usable, fixing
rdar://problem/24049927.
2016-01-06 10:19:12 -08:00
Chris Lattner
19bb1e147b move a & from a caller to the callee to appease Jordan. 2016-01-05 21:25:40 -08:00
practicalswift
ca92efc8e6 Use consistent formatting of header comments.
Correct format:
```
//===--- Name of file - Description ----------------------------*- Lang -*-===//
```

Notes:
* Comment line should be exactly 80 chars.
* Padding: Pad with dashes after "Description" to reach 80 chars.
* "Name of file", "Description" and "Lang" are all optional.
* In case of missing "Lang": drop the "-*-" markers.
* In case of missing space: drop one, two or three dashes before "Name of file".
2016-01-04 23:00:53 +01:00
Chris Lattner
a30ae2bf55 Merge pull request #836 from zachpanz88/new-year
Update copyright date
2015-12-31 19:36:14 -08:00
Chris Lattner
7daaa22d93 Completely reimplement/redesign the AST representation of parameters.
Parameters (to methods, initializers, accessors, subscripts, etc) have always been represented
as Pattern's (of a particular sort), stemming from an early design direction that was abandoned.
Being built on top of patterns leads to patterns being overly complicated (e.g. tuple patterns
have to have varargs and default parameters) and make working on parameter lists complicated
and error prone.  This might have been ok in 2015, but there is no way we can live like this in
2016.

Instead of using Patterns, carve out a new ParameterList and Parameter type to represent all the
parameter specific stuff.  This simplifies many things and allows a lot of simplifications.
Unfortunately, I wasn't able to do this very incrementally, so this is a huge patch.  The good
news is that it erases a ton of code, and the technical debt that went with it.  Ignoring test
suite changes, we have:
   77 files changed, 2359 insertions(+), 3221 deletions(-)

This patch also makes a bunch of wierd things dead, but I'll sweep those out in follow-on
patches.

Fixes <rdar://problem/22846558> No code completions in Foo( when Foo has error type
Fixes <rdar://problem/24026538> Slight regression in generated header, which I filed to go with 3a23d75.

Fixes an overloading bug involving default arguments and curried functions (see the diff to
Constraints/diagnostics.swift, which we now correctly accept).

Fixes cases where problems with parameters would get emitted multiple times, e.g. in the
test/Parse/subscripting.swift testcase.

The source range for ParamDecl now includes its type, which permutes some of the IDE / SourceModel tests
(for the better, I think).

Eliminates the bogus "type annotation missing in pattern" error message when a type isn't
specified for a parameter (see test/decl/func/functions.swift).

This now consistently parenthesizes argument lists in function types, which leads to many diffs in the
SILGen tests among others.

This does break the "sibling indentation" test in SourceKit/CodeFormat/indent-sibling.swift, and
I haven't been able to figure it out.  Given that this is experimental functionality anyway,
I'm just XFAILing the test for now.  i'll look at it separately from this mongo diff.
2015-12-31 19:24:46 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Doug Gregor
7c0c092004 Eagerly update a protocol's "has missing required members" flag.
Rather than plumbing a "has missing required members" flag all the way
through the LazyResolver's loadAllMembers and its implementations,
just eagerly update the "has missing required members" flag in the
Clang importer when it happens. More NFC cleanup.
2015-12-23 13:38:35 -08:00
practicalswift
81e7439a9a Fix typos. 2015-12-23 11:16:34 +01:00
Doug Gregor
6ddce0b042 Clang importer: centralize the logic for importing instance methods as class methods.
Objective-C instance methods of root classes can also be used as class
methods, which we handle by performing a redundant import, the code
for which was scattered. Centralize this import as part of importing
the original (instance) method, and record it as an alternate
declaration to the original instance method. This eliminates a number
of special cases in the Clang importer.
2015-12-22 17:32:44 -08:00
Doug Gregor
3932797480 Implement Clang module's "getTopLevelDecls" using the Swift lookup tables.
Various interface-printing facilities use getTopLevelDecls to
enumerate the top-level declarations of a given module. For modules
imported from Clang, this walked a giant cached list of all
declarations known from Clang, then filtered out those that didn't
fit. Instead, just use the information provided by the Swift name
lookup tables, which is inherently module-specific and complete.
2015-12-21 16:01:21 -08:00
Doug Gregor
4c6d972691 Clang importer: collapse redefined macros.
In C, macros can be redefined so long as the redefinitions are
tokenwise equivalent. Provide the Clang importer with the same ability by
determining when tokenwise equivalent macros would be imported as
different Swift declarations, and collapse them into a single
declaration.
2015-12-21 14:43:46 -08:00
Doug Gregor
16d9766ea2 Clang importer: stop importing types to map to their names for omit-needless-words. 2015-12-17 22:35:56 -08:00
Doug Gregor
a8702619bc Clang importer: use proper Clang context when omitting needless words.
When we're omitting needless words and building Swift name lookup
tables, make sure to use the proper Clang
Sema/Preprocessor/ASTContext. This still needs to be properly
detangled, but at least now we can handle omit-needless-words for
builtin Clang types (e.g., SEL) properly.

As part of this, put OmitNeedlessWords and InferDefaultArguments into
the module file extension hash for the Swift name lookup tables, since
those settings will affect the results.
2015-12-17 15:24:59 -08:00
Doug Gregor
b858ba3e1a Clang importer: factor out "should this declaration be imported?". NFC 2015-12-17 15:24:59 -08:00