Commit Graph

2529 Commits

Author SHA1 Message Date
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
practicalswift
149b50d901 Fix typos in code (non-comment/documentation typos). 2015-12-28 11:42:15 +01:00
practicalswift
db13bcb22e Fix typos. 2015-12-26 14:11:42 +01:00
Kevin Ballard
1dc44b2133 [ClangImporter] Handle SWIFT_ENUM_NAMED when importing enums 2015-12-23 16:07:53 -08:00
Jordan Rose
45302d375c [ClangImporter] Add a bunch of non-null assertions.
rdar://problem/23985987 has a crash report that implies that a null
snuck in here at some point in the past. All the refactoring that's
happened since then probably means it can't happen any more, but
assertions are always good, right?
2015-12-23 14:36:20 -08: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
Max Moiseev
200be71583 Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-23 10:28:04 -08:00
Doug Gregor
a320b6cdc4 Clang importer: centralize the "suppress declaration import" logic.
The Swift name lookup tables and the complete Objective-C "container"
to Swift DeclContext mapping code used similar-but-different logic to
determine when to suppress a declaration (e.g., when suppressing the
accessors for a property). Centralize the logic so we get the same
behavior in both places.
2015-12-22 21:47:01 -08:00
Doug Gregor
d28cc60479 Clang importer: Handle inference of protocol member availability directly.
We were inferring protocol member availability as part of filling in
the complete imported protocol. Do it eagerly when we import a member
of a protocol.
2015-12-22 17:32:44 -08:00
Doug Gregor
c47c669e03 Clang importer: handle factory-method-as-initializer as an alternate declaration.
Alternate declarations now capture all of the ways in which a single
Objective-C method can be reflected into two Swift methods (for
subscripts, factory-methods-as-initializers, and
instance-methods-as-class-methods).
2015-12-22 17:32:44 -08: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
practicalswift
6e3b700b44 Fix typos. 2015-12-23 00:31:13 +01:00
Doug Gregor
48fb38f82a Clang importer: eliminate importSpecialMethod. NFC
This method was only used for importing subscripts. Instead,
import a subscript when the imported name says we should (so we
eliminate the redundant check for "might this be a subscript
accessor?") and use the subscript "alternate declaration" to eliminate
the only other caller to importSpecialMethod.
2015-12-22 14:01:16 -08:00
Doug Gregor
192b16f7fe Clang importer: use "alternate declarations" when enumerating imported members.
When we are creating the complete list of imported members for an
Objective-C class or protocol, start relying on the "alternate
declarations" mapping to get the extra members. Do this only for
subscripts at the moment (now that they record alternate declarations
properly and are idempotent), but eventually we should expand this
out.
2015-12-22 13:38:10 -08:00
Doug Gregor
0c0a0fab4b Clang importer: clean up importing of subscripts.
There was a lot of dodgy code in here that made subscript imports not
necessarily idempotent. Try to clean up the flow a bit, eliminating
the DeclContext parameter (which caused some "interesting" effects if
misused), be more methodical about handling the redeclaration case,
eliminate some unnecessary recursion due to performing name lookup in
the wrong place for override checking, etc.
2015-12-22 13:26:44 -08:00
Max Moiseev
a7339e67ac Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-22 11:36:07 -08:00
practicalswift
36d7072013 Remove immediately adjacent repeated words ("the the", "for for", "an an", etc.). 2015-12-21 22:16:04 +01:00
Doug Gregor
cd1c106e35 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2015-12-18 15:45:48 -08:00
Doug Gregor
8fc9bb56de Clang importer: do selector matches to more carefully wire up overrides.
We were depending on the (nearly) 1-1 mapping from Objective-C
selectors into Swift names when wiring up overrides of Objective-C
methods, but this mapping falls apart under
-enable-omit-needless-words. Use the Objective-C selector, which
represents the truth of overriding in Objective-C, to wire up
overrides properly.
2015-12-18 15:09:29 -08:00
Max Moiseev
3fe0c60d7f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2015-12-17 11:00:02 -08:00
Doug Gregor
e423ad03a3 Clang importer: clean up "alternate declaration" handling for subscripts. 2015-12-16 11:21:38 -08:00
Doug Gregor
2bd31a0e10 Clang importer: introduce "alternate declarations" for redundant imported decls.
There are some Clang declarations that end up being imported as
multiple declarations in Swift, e.g., CF types get imported both with
and without the "Ref" suffix, subscript getters get imported both as a
method and as a subscript, etc. Track this explicitly so it's easy to
query the alternate declaration of a given declaration for name
lookup.

In many of these cases, the alternate declarations should simply go
away, because they're bloating the API. But that's a Swift 3 change
that requires review. For now, we want parity between the behavior
without and with Swift name lookup tables.
2015-12-16 11:21:38 -08:00
Max Moiseev
2021dd5a4d Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2015-12-15 12:49:22 -08:00
Doug Gregor
d421a4fc0a Clang importer: use Swift name lookup tables for AnyObject member lookup.
When we're building Swift name lookup tables, use them for AnyObject
member lookup rather than falling back to the Objective-C selector
table.
2015-12-14 22:05:04 -08:00
Doug Gregor
563bdb9156 Clang importer: remove support for implicit properties.
We decided not to support "implicit" properties, where we import
getter/setter pairs as properties. Rather, we only import a property
when there is an explicit "@property" in Objective-C. Remove the flag
and supporting code for implicit properties.
2015-12-14 14:33:07 -08:00
Max Moiseev
806be29941 Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-14 12:05:35 -08:00
practicalswift
c6e8459187 Fix typos. 2015-12-14 11:13:30 +01:00
practicalswift
8912c8b5d5 Fix typo: containining → containing 2015-12-14 00:11:27 +01:00
Maxim Moiseev
0e0191380a OptionSetType => OptionSet 2015-12-10 14:58:24 -08:00
Doug Gregor
8b82a674ec Clang importer: decouple importFullName from a specific Clang ASTContext. 2015-12-08 17:34:04 -08:00
Doug Gregor
6b3807401a Clang importer: When dropping a variadic parameter, update the selector as well
Fixes breakage on iOS.
2015-12-04 10:20:06 -08:00
Doug Gregor
d9ce07fa41 Clang importer: when dropping the variadic parameter, drop the variadic parameter.
Fixes iOS build.
2015-12-03 11:50:43 -08:00
Doug Gregor
2ea58f93b0 Clang importer: handle CF type renaming in importFullName.
Ensures that the Swift lookup tables get transformed name for imported
CF types, including original name (which is still
available). Otherwise, this is an NFC refactoring that gets the last
of the naming tricks into importFullName.
2015-12-03 11:50:43 -08:00
Doug Gregor
2d7044c024 Clang importer: move name translation for throwing methods into importFullName.
The translation from the Objective-C NSError** convention into Swift
throwing methods alters the names of methods. Move that computation
into importFullName. This should be NFC refactoring for everything
except the Swift name lookup tables, which will now correctly reflect
this name translation.
2015-12-03 11:50:42 -08:00
Doug Gregor
4c50598916 Clang importer: switch method name import to importFullName().
This lets us kill the redundant Objective-C selector to DeclName
mapping used only for methods.
2015-12-03 11:50:42 -08:00
Doug Gregor
3102e2314c Clang importer: switch init method importing over to importFullName.
Yet more name-importing refactoring toward eliminating some redundant
code. As a drive-by, happens to fix swift_private imports for
no-parameter init methods.
2015-12-03 11:50:42 -08:00
Doug Gregor
91d1c3b21a Clang importer: use importFullName for factory methods as initializers.
Eliminates one of the redundant places where we map Objective-C
selectors over to Swift names.
2015-12-03 11:50:42 -08:00
Doug Gregor
fedb6a8b8a Clang importer: give importFullName a richer result type.
Capture the imported name, as well as some information about it, in
the result of importFullName. Some of the clients need this
information.
2015-12-03 11:50:41 -08:00
Doug Gregor
eedf0fc1db Clang importer: teach importFullName to map init methods to initializers.
We're only using this in the Swift lookup tables at the moment.
2015-12-03 11:50:41 -08:00
Doug Gregor
5776fa59c6 Clang importer: migrate "Protocol" suffix computation into importFullName.
Refactoring that lets the Swift lookup tables get the names right for
Objective-C protocols that would conflict with another entity in the
same module (or within the bridging header). It's an NFC cleanup
everywhere else.
2015-12-03 11:50:41 -08:00
Doug Gregor
fa865c7165 Clang importer: handle enumerator prefix stripping in importFullName().
Centralize the mapping of C names to Swift names further by including
enumerator prefix stripping, rather than having that as a separate
path. The actual logic and code for computing the prefix is unchanged
(despite moving from one file to another). This corrects the name
computed for the Swift lookup tables, but is an NFC refactoring for
everything else.

With this, kill off importName(), because it's been entirely
superseded by importFullName().
2015-12-03 11:50:40 -08:00
Doug Gregor
c41535a7fb Clang importer: start computing the effective lookup context with the name.
This places enumerators that will become either cases of a Swift enum
or options in a Swift option into the context of the C enum type for
the name lookup table.
2015-12-03 11:50:40 -08:00
Doug Gregor
f798d53f92 Clang importer: convert more importName callers over to importFullName. NFC
The sole remaining caller to importName is for enumerators, which may
have prefixes that need stripping. That refactor will come in a
subsequent commit.
2015-12-03 11:50:40 -08:00
Doug Gregor
3caf703d47 Narrow the Clang importer's importDeclName to just importIdentifier. NFC
We never used it for non-identifier names, and the former is somewhat
ambiguous with the new importFullName.
2015-12-03 11:50:39 -08:00
Doug Gregor
a861a7345e Clang importer: introduce "importFullName" to centralize name-mapping logic.
The Swift lookup tables are the primary client and test vehicle right
now. This change adds the capability to use the swift_name attribute
to rename C functions when they are imported into Swift, as well as
handling the swift_private attribute more uniformly.

There are a few obvious places where I've applied this API to
eliminate redundancy. Expect it to broaden as the API fills out more.
2015-12-03 11:50:39 -08:00
Johan K. Jensen
fa76656c82 Remove instances of duplicated words 2015-12-03 20:00:29 +01:00
Dmitri Gribenko
4324e7c903 Remove conditional compilation of tvOS 2015-12-01 14:43:45 -07:00
Slava Pestov
2e796aeb9f Remove MappedLanguages enum, NFC
@jrose-apple says this is useless.
2015-11-04 13:53:06 -08:00
Xi Ge
9586337981 [Parser] Allow FuncDecl to record the locations of accessor keywords, e.g. set, get, etc. 2015-11-03 18:13:32 -08:00