Commit Graph

228 Commits

Author SHA1 Message Date
Michael Ilseman
68737b78c2 [ClangImporter] Refactor name importing to be version based
Rather than use importName using a set of options of what to choose,
phrase the API in terms of language version. Be explicit about what
version is being requested at the call site, as it's a necessary
consideration for the client.
2016-12-03 13:26:08 -08:00
Michael Ilseman
d1efc80b1f [Import Decl] Don’t import as init using omit needless words
Previously, for an Objective-C class method declaration that could be
imported as init, we were making 4 decls:

1) The Swift 2 init
2) The Swift 2 class method decl (suppressing init formation)
3) The Swift 3 init (omitting needless words)
4) The Swift 3 class method decl (suppressing init formation and
   omitting needless words)

Decls 1), 2), and 4) exist for diagnostics and redirect the user at
3). But, 4) does not correspond to any actual Swift version name and
producing it correctly would require the user to understand how
omit-needless-words and other importer magic operates. It provides
very limited value and more importantly gets in the way of future
Clang importer refactoring. We’d like to turn Decl importing into
something that is simpler and language-version parameterized, but
there is no real Swift version to correspond to decl 4).

Therefore we will be making the following decls:

1) The "raw" decl, the name as it would appear to the user if they
   copy-pasted Objective-C code
2) The name as it appeared in Swift 2 (which could be an init)
3) The name as it appeared in Swift 3 (which could be an init and omit
   needless words)

This aligns with the language versions we want to import as in the
future: raw, swift2, swift3, …, and current.

Note that swift-ide-test prunes decls that are unavailable in the
current Swift version, so the Swift 2 non-init decls are not printed
out, though they are still present. Tests were updated and expanded to
ensure this was still the case.
2016-12-01 18:50:40 -08:00
Michael Ilseman
15f5367409 [Clang Importer] Simplify and move more lookup table APIs 2016-12-01 18:18:12 -08:00
Hugh Bellamy
071ec47224 Fix errors and warnings build swift/clangImporter using MSVC on Windows (#5950) 2016-11-30 13:27:36 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Jordan Rose
d7cc1fd81e [ClangImporter] C static-qualified array params are non-nullable. (#5617)
If the keyword 'static' also appears within the '[' and ']' of the
    array type derivation, then for each call to the function, the
    value of the corresponding actual argument shall provide access to
    the first element of an array with at least as many elements as
    specified by the size expression. (C11 6.7.6.3p7)

Limit this change to Swift 4 so as not to break existing code, though
use of 'static' in this way is rare to begin with and passing nil
would probably be an error anyway.

Small part of rdar://problem/25846421.
2016-11-16 09:14:28 -08:00
Michael Ilseman
3508e267eb [Import Name] Cleanup some needless parameters 2016-11-07 16:12:58 -08:00
Michael Ilseman
85ab0318c7 [Import Name] Cache NameImporter calls
During normal import, the name for a foreign entity may be requested
many times. As we have more and more complex logic to compute these
new names, the overhead of potential re-computations adds up. This
cache is hit about 1/3rd of the time when running a simple
CoreGraphics test case.

NFC
2016-10-01 17:20:01 -07:00
Michael Ilseman
a2267fdf86 [Clang Importer] Refactor and simplify
Now that we have per-Clang-instance NameImporters, we can drop the
2-phase initialization that was internally present in
NameImporter. This lets NameImporter host the EnumInfoCache directly,
and streamlines the APIs.

NFC
2016-10-01 17:20:00 -07:00
Michael Ilseman
99c12b002b [Clang Importer] Eliminate clangSemaOverride
Banish the abomination that is clangSemaOverride, a previously
necessary evil. When building the module caches, different Clang
instances will be spawned than the one used by the normal
importer. Since we want to reuse code and get the same name both ways,
this meant threading through alternative clang Semas and preprocessors
throughtout, some of the time. This broke the abstraction and
encapsulation of the Impl, complicated the programming model, and
otherwise made effective caching hard.

Now that we’ve done enough ImportName refactoring, we can create a
NameImporter per Clang instance, and encapsulate naming therein. We
can now remove the sema overrides, as we have already done to the
preprocessor overrides.

This shifts the 2-phase initialization problem to the Impl and the
Clang module writers.

NFC
2016-10-01 17:19:51 -07:00
Michael Ilseman
bf77f75aa7 [Clang Importer] Make EnumInfoCache be per-Clang-instance based.
Delay initialization of the EnumInfoCache until a Clang instance is
ready, simplifying its interface and allowing us to finally make this
per-Clang-instance. This will allow us to further de-couple ImportName
from the importer imply, as well as allow us to use a more efficient
and simpler caching mechanism. It is now owned by the NameImporter.

NFC.
2016-10-01 16:37:31 -07:00
Michael Ilseman
7a1a6af836 [Clang Importer] Restore shouldIgnoreMacro API 2016-09-29 15:36:43 -07:00
Michael Ilseman
e092774a08 [Import Name] Ruin SwiftNameLookupExtension and Impl's friendship
SwiftNameLookupExtension and ClangImporter::Implementation were
friends, but as time goes on they have drifted apart. As part of the
ImportName refactoring, these are being decoupled to facilitate
multiple-name importing, and fight the existing false encapsulation
present in the Impl.

SwiftNameLookupExtension is now spun off into its own entity, and can
evolve to have and use its own de-coupled NameImporter.
2016-09-29 11:10:13 -07:00
Michael Ilseman
3911907ef6 [Import Name] Force explicit options
Prevent easy and common errors by dropping default import options. In
the future, these options wont be used, as we want to be able to
calculate all potentially relevant names up front.
2016-09-29 09:02:54 -07:00
Michael Ilseman
ead13d40ff [Import Name] Introduce contextual class Name Importer
Name Importer wraps references to the Swift context and other needed
encapsulation. The eventual goal is to allow name lookup tables to
live separately from the Impl, and do better Clang-instance-based
caching in the future, as well as general separation of concerns.

NFC
2016-09-28 22:37:24 -07:00
practicalswift
9185c052a9 [gardening] Fix inconsistent headers 2016-09-14 20:48:28 +02:00
Michael Ilseman
618b8224af [Clang Importer] Refactor out ClangEffectiveContext determination 2016-09-13 21:05:24 -07:00
Michael Ilseman
5cd26e9ee7 [ClangImporter] Refactor out conflict name detection 2016-09-13 20:29:58 -07:00
Michael Ilseman
eaf45c51b9 [Clang Importer] Refactor out SwiftPrivate logic 2016-09-13 20:20:32 -07:00
Michael Ilseman
01ae90341e [ClangImporter] factor out scratch, so we can reuse it in the future 2016-09-13 20:20:03 -07:00
Michael Ilseman
8895a3b5c5 [ClangImporter] importFullName refactored out
Finally separates out importFullName from the Impl, and it now only
relies on relevant Swift and Clang information, but no importer
state. Convenience functionality, better APIs, and more clean up
coming soon.
2016-09-12 21:05:37 -07:00
Michael Ilseman
1cbfdc9e58 [ClangImporter] Refactor omitNeedlessWordsInFunctionName
Pull omitNeedlessWordsInFunctionName off of the Impl, and into a
static function local to ImportName.cpp. Separate it out from the Impl
entirely. Though this adds a couple of extra ugly parameters, it's one
of the last bits of tie-in between importFullName and the Impl.
2016-09-12 21:05:36 -07:00
Michael Ilseman
15af7f224d [ClangImporter] Refactor Clang reasoning into new files.
Introduces new files ClangAdapter.h/cpp, which will serve as a
convenient place to put code reasoning about Clang details. Refactors
out most Clang-related is*, has*, and get* methods from the
ImporterImpl. In the future, an adapter class could help serve to
seperate the concerns of the importer from the details of how to
correctly use Clang APIs.
2016-09-12 21:02:09 -07:00
Michael Ilseman
b51e0f61f7 [ClangImporter] Refactor off CF reasoning helpers
Move helper methods off of the Impl and into CFTypeInfo.h, where we
have the other CF type reasoning logic.

NFC
2016-09-10 18:41:06 -07:00
Michael Ilseman
ffadf0524b [ClangImporter] Refactor off class methods
Many of the Impl's methods are relevant to only one file or task. Make
more of them static, and when possible, move them off of the Impl
class.

NFC
2016-09-10 18:40:04 -07:00
Michael Ilseman
12fc7c83ff [ClangImporter] cleanup
Delete some dead code related to module prefixes. Make many methods
static on ClangImporter::Implementation when possible.
2016-09-09 14:23:38 -07:00
Michael Ilseman
d625ed288e [ClangImporter] remove antiquated swift_newtype options 2016-09-09 13:55:20 -07:00
Michael Ilseman
7f179448ef [ClangImporter] Move code to ImportName.cpp
Refactors much of the import name determination from ClangImporter.cpp
into ImportName.cpp.

This is not a perfect separation, but it's a step in the right
direction. Long term, we'd like to get as much functionality off of
the ClangImporter::Implementation class and onto more specialized and
seperable (and stateless!) components.
2016-09-09 11:05:59 -07:00