Commit Graph

48 Commits

Author SHA1 Message Date
Ted Kremenek
8c1148784a Merge pull request #15516 from tkremenek/version-4_2-importname
Translate effective version name of '4.x' to '4.2' for ImportNameVersion.
2018-11-06 15:51:39 -08:00
Bob Wilson
c3e02955bb [master-next] Adjust for VersionTuple moving from clang to llvm.
LLVM r334399 (and related Clang changes) moved clang::VersionTuple to
llvm::VersionTuple. Update Swift to match.

Patch by Jason Molenda.
rdar://problem/41025046
2018-06-12 16:44:11 -07:00
Rintaro Ishizaki
b3453c17fe [ClangImporter] Take isCompatibilityAlias() into account in interface printing (#16625)
If the Clang declrations are *types*, canonical declaration in Swift is
imported for newest version of Swift. In interface generation, if the
declaration is versioned and it's imported as a member in either or both
version of Swift, we have to take compatibility typealias into account.

* Fixed 'ClangModuleUnit::getTopLevelDecls' to take isCompatibilityAlias() into account
* Fixed bugs in ClangImporter where member-to-member versioned types aren't properly imported.
  * Fixed 'SwiftDeclConverter::importFullName' to check equality of getEffectiveContext()
  * Fixed 'importer::addEntryToLookupTable' to check equality of getEffectiveContext()
    (moved 'ClangImporter::Implementation::forEachDistinctName' to 'NameImporter')
2018-05-22 13:38:45 +09:00
Ted Kremenek
a2951aa052 Translate effective version name of '4.x' to '4.2' for ImportNameVersion for x >= 2. 2018-03-26 10:51:51 -07:00
Ted Kremenek
3da51018b6 Teach ClangImporter to handle effective Swift version with minor release.
Needed to support Swift 4.2.
2018-03-23 00:30:44 -07:00
Jordan Rose
00b890f9f1 [ClangImporter] Stop copying EnumInfo strings into Swift's ASTContext
They're all kept alive by Clang's ASTContext already. Since the enum
info is only accessible through the Clang importer, that's a
sufficient lifetime. (Note that this only works because all of the
strings are derived from text actually present in the C sources:
either attribute arguments or names of declarations.)

Fixes a small TODO and probably saves a tiny bit of memory usage.
2018-01-04 15:06:26 -08:00
Doug Gregor
a49455e3b2 [Clang importer] Move the "all properties" lists into the name importer.
Swift's ASTContext contained all of the logic to find the complete list
of properties for an Objective-C class, which is used by the Clang importer
to influence the mapping of Objective-C names into Swift. Swift's
ASTContext also included a *cache* for this information, indexed by
the Clang `ObjCInterfaceDecl *`. However, this cache was getting
populated/queried from the Clang importer's name importer, such that
the keys would be Clang declarations used to build modules and then
deallocated. If that memory eventually gets reused for a different
`ObjCInterfaceDecl *`, we would get incorrect/stale all-properties
information.

Almost Surely fixes rdar://problem/35347167, which is a
nondeterministic failure where UIView's `addGestureRecognizer(_:)` gets
occasionally imported as `add(_:)`.
2017-11-08 15:25:15 -08:00
Jordan Rose
a0117b0cd0 [ClangImporter] Bump the maximum supported version to Swift 5
"...finally."

This was technically enabled two commits ago, since nothing checks
that you're not /over/ maxVersion(). This is only used for

- deciding the canonical way to import renamed types
- trying to import things in multiple ways

...and so there are very few observable differences, especially
before anyone has added any API notes that differentiate Swift 4
and Swift 5.

At some point we should start encoding name versions in the lookup
tables so that we only have to try all the names /once/, but the test
suite doesn't seem to get measureably slower with this change,
probably because it's pretty quick to decide that most things don't
have multiple names. So we can put that off until later.
2017-09-15 14:30:24 -07:00
Jordan Rose
9a04bee421 [ClangImporter] Turn ImportNameVersion into a struct.
...so that we don't have to keep coming back to update it every major
release. And also so we can actually put methods on it instead of
using free functions.

No intended behavior change (yet).
2017-09-15 14:30:24 -07:00
Jordan Rose
ff31714b69 [ClangImporter] ImportedName doesn't need to know its version.
Preparation for making ImportNameVersion a generalized struct rather
than an enum. We could have kept cramming it into a bitfield, sure,
but we don't actually need this.

No intended functionality change.
2017-09-11 18:06:35 -07:00
Jordan Rose
9a9d139320 [ClangImporter] Import Swift 3 and 4 names for enumerators. (#9523)
Also lays the groundwork for rdar://problem/16513537, which is about
being able to find an enum by its original top-level name so that we
can show a diagnostic for that. I'll file a public bug about that
later.

rdar://problem/31893305
2017-05-12 14:51:40 -07:00
Jordan Rose
cb9b9ea734 [ClangImporter] Always import types under their Swift 4 name.
This means all cross-module references and all mangled names will
consistently use the Swift 4 name (the canonical type), no special
handling required.

The main thing we lose here is that the Swift 4 names of imported
types become usable in Swift 3 mode without any diagnostics, similar
to how most language features introduced in Swift 4 are available in
Swift 3 mode. It also implies that the Swift 4 name will show up in
demangled names.

rdar://problem/31616162
2017-04-26 13:07:03 -07:00
Jordan Rose
f7562e42b6 [ClangImporter] Add versioned stubs for import-as-member renames. (#8272)
A more general solution to ae458a84ad: import all versions of a name
that are going to show up as members, ignore those that aren't.

Further work on <rdar://problem/29170671> Import APIs under their
Swift 3 names.
2017-03-23 13:46:51 -07:00
Jordan Rose
c9124d989d [ClangImporter] Import Swift 3 versions of top-level decls in Swift 4.
...and Swift 4 versions in Swift 3, and Swift 2 and "raw" versions in
both. This allows the compiler to produce sensible errors and fix-its
when someone uses the "wrong" name for an API. The diagnostics
certainly have room to improve, but at least the essentials are there.

Note that this commit only addresses /top-level/ decls, i.e. those
found by lookup into a module. We're still limited to producing all
members of a nominal type up front, so that'll require a slightly
different approach.

Part of rdar://problem/29170671
2017-02-24 14:01:10 -08:00
Jordan Rose
ce810efe75 [ClangImporter] Route getFactoryAsInit through findSwiftNameAttr.
The next commit will make findSwiftNameAttr handle Swift 3 / Swift 4
API notes, so it's important that everything is consistently using it.
(The other place that isn't updated yet is enum info; conceivably, the
prefix for enum constants might be different based on which
SwiftNameAttrs are in play.
2017-02-24 13:26:22 -08:00
Jordan Rose
a5da848064 [ClangImporter] Put all versions of names into the lookup table.
The compiler uses the non-active names to import unavailable
declarations telling the user the correct name. Right now it's still
only importing "Swift 2" and "current", but that should change.

For reference, the best example of a declaration that has four names
is a factory method with a custom NS_SWIFT_NAME annotation:

- Its raw name is the plain Objective-C name, written as a method:
  'fooByFrobnicatingBar(_:)'.
- Its "Swift 2" name is the Swift-2-style translation of that to an
  initializer: 'init(byFrobnicatingBar:)'
- Its "Swift 3" name applies the "omit needless words" transformation:
  'init(frobnicating:)'.
- Its "Swift 4" name uses the name specified by NS_SWIFT_NAME.
2017-02-24 13:26:21 -08:00
Xi Ge
b32424953e [SourceKit] Add a new request to translate from Objc names to Swift names and vice versa.
Extensive cross-language tooling support needs to bridge decl names between two different languages more freely. This SourceKit request is designed to translate Objc names to Swift names and vice versa. Working similarly to cursor-info requisition, the name translation request requires a Swift reference to a Swift/Clang decl, and the preferred name to translate from, and language kind that the given name belongs to. If the translation succeeds, SourceKit service responds with the corresponding name than belongs to the other kind of language.

Newly introduced keys:

“key.namekind": “source.lang.name.kind.objc” | "source.lang.name.kind.swift"
“key.basename”: “name"
“key.argnames”: [“name"]
“key.selectorpieces”: [“name[:]"]

This commit only implements translation from Objc to Swift.
2017-02-10 17:50:12 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Jordan Rose
d1e087797c [ClangImporter] "Fix" too-wide bitfield.
Maximum value of an enum != number of bits required.
2016-12-22 17:32:32 -08:00
Michael Ilseman
1e42a16247 [Clang Importer] Plumb versions everywhere
Remove all occurrences of a "useSwift2Name" bool, and replace it with
version plumbing. This means that ImportDecl is now entirely
version-based, and the importer Impl knows versions. This will be
needed for marking Swift 3 names as deprecated, when there is a new
Swift 4 name.

NFC.
2016-12-14 19:55:14 -08:00
Michael Ilseman
e9613dccc7 [Import Name] Finish weaning importName() off of options.
Switch all of ImportName over to be version based, including
internally. NFC.
2016-12-14 13:28:48 -08:00
Michael Ilseman
623038bc1c Incorporate review feedback 2016-12-12 15:29:24 -08:00
Michael Ilseman
9bc065f73d [Clang Importer] Shrink ImportedName more
Re-arrange and repack some bits to bring the size of ImportedName down
to 5 pointers. The size will start to become important as we're going
to be storing one for every Swift version we want diagnostics for per
every Clang decl we might import.
2016-12-12 13:49:27 -08:00
Michael Ilseman
a21d1827a9 [Clang Importer] Unified ForeignErrorConvention
Expose a ForeignErrorConvention::Info struct, so that the
ClangImporter can also utilize this space-efficient
storage. Eliminates the ClangImporter's ad-hoc representation, and
shaves off a pointer or so off of the ImportedName size.

While we're out it, make some of the bools bitfields to shave off
another pointer in size. Total ImportedName size is now 6.
2016-12-12 13:29:26 -08:00
Michael Ilseman
01ee1eee61 [Clang Importer] Shave space off EffectiveClangContext/ImportedName
Shave off a pointer from the EffectiveClangContext, by re-arranging
some of its data. Down to 2 pointers from 3.

Inside of ImportName, factor out the does-it-have-a-value from
multiple stored Optionals so as to shave off a couple of
pointers. Present the same programming interface as before. Down to 8
pointers in size from 10, and still much further to go.
2016-12-12 13:22:36 -08:00
Michael Ilseman
2b01c25364 [Import Name] Refactor ImportedName to be a class
Change the interfaces to ImportedName to be method based, rather than
direct struct field accesses. We're going to be changing how these are
used in the future. Also, we will be storing large quantities of
these, so we will soon want to crunch down on their size.
2016-12-05 08:57:18 -08:00
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
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
Michael Ilseman
3508e267eb [Import Name] Cleanup some needless parameters 2016-11-07 16:12:58 -08:00
Michael Ilseman
f436dd2d8a [Clang Importer] Delete and simplify code
Drop the ImportNameSwiftContext, which was merely used to pass around
some global state. Instead, pass the relevant parts
directly. Additionally, remove the 2-phase initialization of a
NameImporter from the module writers, as they are only invoked once
per Clang instance anyways, we can hold a local instance. Also
streamlines some APIs.

NFC
2016-10-01 17:20:01 -07: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
1d5ccc0d1b [ClangImporter] EnumInfos are now cached by Clang decl
Now that we have a EnumInfoCache per NameImporter which is per Clang
instance, we can just cache our EnumInfo based off of Clang decl,
rather than using a faux-USR technique. This greatly speeds up and
simplifies enum imports.

EnumInfos are requested about 200k times when building the module
cache for Foundation, and thousands of times for simple tests during
normal import, so efficiency here is important. While building module
caches, the EnumInfoCache is hit 99% of the time, and it is hit 98% of
the time during normal import with pre-built module caches.

NFC.
2016-10-01 17:20:00 -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
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
8a7b50d269 [ImportName] Wean SwiftNameLookupExtension off of Impl
Finally, SwiftNameLookupExtension no longer stors a reference to
ClangImporter::Implementation, a false encapsulation. Instead, it uses
a NameImporter of its own, and merely keeps a reference to the lookup
table map.

Future directions include making the NameImporter specific to a Clang
instance, meaning that we can effectively cache Clang entities better
(and not resort to EnumInfoCache's stringly keyed caches). We can also
then drop all notions of a "ClangOverride" and other messy phase
entanglement.

NFC
2016-09-28 22:40:57 -07:00
Michael Ilseman
a8ba351079 [ImportName] Static-ize addEntryToLookupTable
addEntryToLookupTable is one of the laggards holding back the
Impl-free Clang lookup table effort. Make a static variant, now that
we have the convenient NameImporter.

NFC
2016-09-28 22:40:55 -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
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
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
6854f739b8 Delete stray comment 2016-09-12 21:01:47 -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
Michael Ilseman
5685ad9039 [ClangImporter] Begin refactoring of ImportName
Refactors out some definitions and types from the
ClangImporter::Implementation into a new component ImportName. Future
work will include more separation and finally some redesigning of name
determination components.
2016-09-09 11:05:59 -07:00