Commit Graph

215 Commits

Author SHA1 Message Date
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
f8b7db4e76 Excise the terms "blacklist" and "whitelist" from Swift source. (#11687)
The etymology of these terms isn't about race, but "black" = "blocked"
and "white" = "allowed" isn't really a good look these days. In most
cases we weren't using these terms particularly precisely anyway, so
the rephrasing is actually an improvement.
2017-08-30 09:28:00 -07:00
Ewa Matejska
1272cd3aac Making master call itself 4.1, updating the swift 3 compatiblity mode to be 3.3 (from 3.2), adding ability to pass swift-version 5. Importer work not done yet. 2017-08-17 20:57:01 -07:00
Jordan Rose
43c0289dd4 [ClangImporter] Avoid trying to import enums without definitions. (#11394)
This would fail later down the line anyway, meaning this does not
change the ultimate behavior of the importer, but since I added an
assertion that we're expecting a definition here in 2c68f8d49d, we
need to avoid even asking the question.

Also fix up a few other places where we aren't sure we'll have a
definition when calling these functions.

rdar://problem/33784466
2017-08-09 13:51:03 -07:00
Chris Bieneman
9c35042ae6 Merge remote-tracking branch 'origin/master' into master-next 2017-07-28 09:51:36 -07:00
Jordan Rose
2c68f8d49d [ClangImporter] Assert when we're expecting a definition (#11170)
No functionality change.
2017-07-27 09:06:43 -07:00
swift-ci
787d8a8a9f Merge remote-tracking branch 'origin/master' into master-next 2017-05-28 17:28:35 -07:00
Alex Hoppen
f302afc97f Unify approach to printing declaration names (#9320)
Printing a declaration's name using `<<` and `getBaseName()` is be
independent of the return type of `getBaseName()` which will change in
the future from `Identifier` to `DeclBaseName`
2017-05-28 17:25:20 -07:00
swift-ci
dec3920830 Merge remote-tracking branch 'origin/master' into master-next 2017-05-12 15:08:51 -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
Bob Wilson
e55cc83fa6 Adjust use of Preprocessor::getCurrentSubmodule to match clang r302098. 2017-05-06 11:22:44 -07:00
swift-ci
edf0e6ed66 Merge remote-tracking branch 'origin/master' into master-next 2017-04-19 11:28:45 -07:00
Graydon Hoare
3a79d83233 Forward declare TypeRepr in TypeLoc.h, adjust other code to compensate. 2017-04-18 11:12:53 -07:00
swift-ci
0142fa1f13 Merge remote-tracking branch 'origin/master' into master-next 2017-04-15 10:08:32 -07:00
practicalswift
40cf4d183d [gardening] Use consistent spacing after if, for and while 2017-04-14 17:35:36 +02:00
swift-ci
c523ca44ad Merge remote-tracking branch 'origin/master' into master-next 2017-04-12 01:08:31 -07:00
practicalswift
5e255e07d7 [gardening] Remove redundant logic 2017-04-11 23:04:55 +02:00
swift-ci
5e85308c23 Merge remote-tracking branch 'origin/master' into master-next 2017-03-03 19:08:55 -08:00
Hugh Bellamy
33f5f89912 Update unreachable control path annotations 2017-03-03 20:21:49 +07:00
swift-ci
5589665b36 Merge remote-tracking branch 'origin/master' into master-next 2017-02-24 15:28:57 -08: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
Michael Gottesman
c60f6b2600 [upstream-update] Handle two CXX entities that have been added upstream in clang.
Since we do not support importing CXX this change just makes sure an unreachable
triggers in various covered switches.
2017-02-21 12:32:28 -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
Jordan Rose
51d9254d5d [ClangImporter] Drop support for FactoryAsInit in API notes. (#6907)
SwiftName covers this use case, so we're going to remove FactoryAsInit
entirely.
2017-01-19 15:39:07 -08:00
Jordan Rose
c011aa04fd Pull PointerLikeTypeTraits<DeclName> up to Identifier.h
No functionality change.
2017-01-10 16:43:40 -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
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
Jordan Rose
dab6d49596 [ClangImporter] Don't crash on empty initial selector pieces. (#6284)
Yes, ':' is a valid selector, as are '::' and ':seriously:'.

rdar://problem/28448188
2016-12-15 14:41:19 -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
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
2a5c185bae [Import Name] Delete dead code
NFC
2016-12-05 08:55:43 -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
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