Commit Graph

2609 Commits

Author SHA1 Message Date
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
Jordan Rose
070ccba166 Verify that a function's DeclName, TuplePattern, and ParamDecls are in sync.
This required a few changes in places where we synthesize functions to
make sure these properties hold. That's good because we don't know where
we might already be depending on them. (On the other hand, we could also
decide not to care about TuplePattern labels, in which case I wonder if
we could eventually discard them altogether in functions.)

Still untested: that the function type is also in sync.
2015-11-02 18:16:19 -08:00
Xi Ge
1604c4ba9e [ClangImporter] Import variadic C functions as unavailable functions instead of ignoring them. rdar://16677468
Also, this helps us fix rdar://20092567.

Swift SVN r32903
2015-10-27 00:29:44 +00:00
Doug Gregor
fa3bb96f85 Clang importer: allow the swift_name attribute to map any name.
This is functional for arbitrary Objective-C properties and methods
(the subject of rdar://problem/22214302), as well as for changing the
argument labels of C functions. However, it does not work when the
name of a global is changed because name lookup initiated from
Swift goes through the Swift lookup table. Fixes
rdar://problem/22214302 but is only a step toward
rdar://problem/17184411.

Swift SVN r32670
2015-10-13 21:12:28 +00:00
Doug Gregor
2feed84c91 Sketch out the interface to an iterative, lazy type checker.
This is all effectively NFC, but lays out the shape of the iterative
type checker: requests are packaged up in TypeCheckRequest, we can
check whether the request has been satisfied already (isSatisfied),
enumerate its dependencies (enumerateDependenciesOf) in terms of other
TypeCheckRequests, and satisfy a request (satisfy).

Lazily-computed semantic information is captured directly in the
AST, but has been set aside in its own structure to allow us to
experiment with moving it into a lookaside table.

The only request that exists now is to type-check the superclass of
the given class. It currently performs unhealthy recursion into the
existing type checker. As we detangle dependencies, this recursion
between the IterativeTypeChecker and the TypeChecker can go away.

Swift SVN r32558
2015-10-09 17:18:36 +00:00
Erik Eckstein
1a6a98b201 ClangImporter: import LLVM's const and pure function attributes to SIL function effects.
<rdar://problem/19558813>



Swift SVN r32371
2015-10-01 18:04:07 +00:00
Jordan Rose
59176785fa [ClangImporter] Typedefs of CFTypeRef should not be imported as AnyObject.
...or rather, typealiases of AnyObject. They should be typealiases of
CFTypeRef. (The problem is that everywhere else CFFooRef becomes a typealias
for CFFoo, but we don't do the same with 'CFType'.)

Fixes a PrintAsObjC problem where we'd try to mark such typealiases as
'strong' if they show up in the generated ObjC header.

rdar://problem/22827172

Swift SVN r32230
2015-09-25 17:53:45 +00:00
Jordan Rose
87e0d40da5 [ClangImporter] Add PrettyStackTrace breadcrumbs for imported decls.
This lets us see all the times where we get tangled up and crash while
importing way more than we should.

No functionality change.

Swift SVN r32209
2015-09-24 21:57:53 +00:00
Doug Gregor
158a2b1ad5 Omit needless words: remove the Ref/Ptr type-stripping rule.
Instead, when mapping a Clang type to its name for omission purposes,
map CF types to their appropriate names. This more directly mirrors
what will happen on the Swift side, but is otherwise NFC.

Swift SVN r32140
2015-09-22 00:35:10 +00:00
Slava Pestov
bd77eeaf22 ClangImporter: Code review feedback from Jordan Rose for r31924
Swift SVN r31969
2015-09-15 20:39:36 +00:00
Slava Pestov
023596783b ClangImporter: Support unnamed struct and union types
This covers this case:

struct foo {
  struct {
    int x;
    int y;
  } bar;

  union {
    void *ptr;
    float num;
  } baz;
};

Based on the original patch by Graham Batty.

Progress on <rdar://problem/21683348> -- anonymous unnamed unions
are still not supported (struct foo { union { int x, y }; };).

Swift SVN r31924
2015-09-14 08:46:56 +00:00
Chris Lattner
123d7493e6 remove a dead local.
Swift SVN r31790
2015-09-08 23:44:13 +00:00
Slava Pestov
9242f6ab51 ClangImporter support for bitfields
Bitfields are imported as computed properties with Clang-generated
accessors.

While we cannot represent them directly in SIL, we can still
synthesize a memberwise initializer, so also decouple that notion
from "has unreferenceable storage".

Fixes <rdar://problem/21702107>.

Swift SVN r31779
2015-09-08 22:12:14 +00:00
Slava Pestov
20efd60ebd ClangImporter code cleanups, NFC
- Extract makeFieldGetterDecl() and makeFieldSetterDecl()
- Remove makeUnionConstructorDecl(), the ordinary struct constructor logic
  works just fine

Swift SVN r31709
2015-09-05 04:06:22 +00:00
Jordan Rose
845513d359 [ClangImporter] Always treat dispatch_block_t as @convention(block).
Some GCD APIs rely on the pointer identity of blocks, so avoid bridging
when possible. The easiest way to do this was to use our existing rules
for special-casing typedefs.

The summary text for dispatch_block_t comes from the actual GCD headers.

rdar://problem/22432170

Swift SVN r31634
2015-09-02 18:31:51 +00:00
Ben Langmuir
47026609b8 Fix leak of std::function in NominalTypeDecl::DelayedMembers
We were memcopying a std::function into the the AST context memory,
which leaks memory incidentally used by the std::function
implementation.  Fix by using a std::unique_ptr and registering a
destructor cleanup.  Incidentally, I turned the array of functions into
a single function, since we never have more than one anyway.

rdar://problem/22387897

Swift SVN r31600
2015-09-01 16:31:21 +00:00
Chris Lattner
6d1b814d61 fix a bug in code synthesized by the clang importer. The "/*Implicit=*/true"
marker isn't actually setting the implicit bit, it was setting the "trailing 
closure" bit, for something that isn't of function type.  The effect of this
was to cause sema to eat the rawValue: parameter without requiring the label.

Instead of generating this code that happened to work out most of the time,
build the proper TupleExpr with the right parameter label.  NFC.



Swift SVN r31597
2015-09-01 04:39:28 +00:00
David Farler
a75b0831e4 Automatically infer Equatable conformance for plain C enums
This provides the == operator as well as ~=, which allows for
less encumbered pattern matching for these imported types.

rdar://problem/17287720

Swift SVN r31469
2015-08-26 02:25:54 +00:00
Doug Gregor
f3d623b738 DRY: Use the imported initializer's type to compute failability
... rather than having a separate 'failability' computation.

Swift SVN r31429
2015-08-24 18:26:26 +00:00
David Farler
e21e1c40e4 Import fields for named C unions
Create getters and setters for, and initializers taking, fields in
C unions. This doesn't yet fold anonymous unions' fields nested into
a struct, but it does open up APIs that were previously unavailable.

rdar://problem/19660119

Swift SVN r31396
2015-08-21 22:10:17 +00:00
Doug Gregor
00040112cd Eliminate special handling of deserialized inherited protocols.
Now that we have the inheritance lists hanging around, use them: it
makes the conformance lookup table use the same code whether we're
deserializing the conformances or parsing them.

Swift SVN r31383
2015-08-21 17:51:26 +00:00