Commit Graph

1889 Commits

Author SHA1 Message Date
Doug Gregor
c2bf16c0a9 Clang importer: start building a Swift name -> Clang declarations table.
When we parse a bridging header, start building a mapping from Swift
names (both base names and full names) to the Clang declarations that
have those names in particular Clang contexts. For now, just provide
the ability to build the table (barely) and dump it out; we'll grow
it's contents in time.
2015-12-03 11:50:39 -08:00
shrx
ea1ced5873 fix some cases
for consistency
2015-12-03 19:48:51 +01:00
Dmitri Gribenko
4324e7c903 Remove conditional compilation of tvOS 2015-12-01 14:43:45 -07:00
David Farler
e11efcb6f6 ClangImporter: Fix external project crash in lookups
Before going and asking for the top level module, check for nullness.

In addition, only ask for the top level of the module that had a
redeclaration.

rdar://problem/23701588
2015-12-01 00:13:20 -08:00
David Farler
6f806b418f Compare top-level modules when deciding visibility for redeclarations
When importing C declarations, one can come across a redeclaration due
to two different clang modules textually including the same header.

Previously, to decide visibility of a declaration from a particular
module, the module in which it is redeclarated had to exactly match the
one we saw before, so a struct defined in A.B.C might cause it to be
hidden in A.X.Y, because we were already popping off submodule names on
the "left hand side", so the module comparison was A != A.X.Y. If
someone imports A.X.Y and expects that struct, they won't see it.

Now, strip off submodules of the "right hand side", correctly comparing
if the top-level modules match (A == A).

This may have the effect of allowing more declarations to be visible
than before but it prevents weird situations where struct typedefs can
be hidden in overly complicated nested header includes normally found in
OS system headers.

rdar://problem/23588593
2015-11-30 15:03:41 -08:00
Doug Gregor
0f673f5d7a Omit needless words: distinguish class vs. instance properties for pruning.
A class method named "bezierPath" should not prevent
"appendBezierPath" from being stripped.
2015-11-16 16:15:26 -08:00
Doug Gregor
106bf80152 Omit needless words: don't prune "properties" of the context from the base name.
The properties of a context indicate those things that are considered
"contained within" the context (among other things). This helps us
avoid producing overly-generic names when we identify a redundancy in
the base name. For example, NSView contains the following:

  var gestureRecognizers: [NSGestureRecognizer]
  func addGestureRecognizer(gestureRecognizer: NSGestureRecognizer)
  func removeGestureRecognizer(gestureRecognizer: NSGestureRecognizer)

Normally, omit-needless-words would prune the two method names down to
"add" and "remove", respectively, because they restate type
information. However, this pruning is not ideal, because a view isn't
primarily a collection of gesture recognizers.

Use the presence of the property "gestureRecognizers" to indicate that
we should not strip "gestureRecognizer" or "gestureRecognizers" from
the base names of methods within that class (or its subclasses).

Note that there is more work to do here to properly deal with API
evolution: a newly-added property shouldn't have any effect on
existing APIs. We should use availability information here, and only
consider properties introduced no later than the entity under
consideration.
2015-11-16 15:27:38 -08:00
Jordan Rose
e6bdcbcc7c [ClangImporter] Drop the version from Clang's resource directory.
Background: Clang has a set of base headers distributed with the compiler
that contain things like vector operations, stddef.h, and tgmath.h.
Swift also needs these headers in order to import C and Objective-C (not
really a surprise), so we symlink to them from lib/swift/clang/. When we
build installable packages, we actually copy them in.

Now the tricky part. Clang's headers are actually at a path like
"include/clang/3.6.0/include/tgmath.h". That "3.6.0" is the Clang version,
which allows multiple Clangs to be installed on a single system. Swift
currently links to the top-level directory, but of course it's only
guaranteed to work with a specific version of the Clang headers. So the
version number here is always the version of Clang we use to build Swift.

Rather than leave the (relatively meaningless) version number here, just
make the symlink point at the "3.6.0" directory rather than the "clang"
directory. This means Swift doesn't have to think about the version number
here at all.

rdar://problem/23223066
2015-11-13 14:43:23 -08:00
Xi Ge
280124fcf8 [CodeComplete] Hold a local copy of module names instead of referencing them. 2015-11-10 13:19:26 -08:00
Xi Ge
827ea69fd3 [CodeComplete] Mark already-imported modules as not-recommended. rdar://23209864
When auto-completing import decls, we should prioritize not-yet imported modules
over already-imported modules. To do so, we mark the latter with not-recommended tag.
2015-11-10 11:57:29 -08:00
Xi Ge
0f881f5ad7 [CodeComplete] Add code completion for Clang sub-modules at import decls. rdar://23244877
e.g. completing at "import Foundation.<HERE>" should give the list of the submodules of Foundation.

Swift SVN r32852
2015-10-24 00:22:25 +00:00
David Farler
e1a7a0f0ab Refactor CompilerVersion
This is a WIP to make CompilerVersion more general.

- Rename CompilerVersion to just "Version"
- Make version comparison general and put _compiler_version special logic
  with its second version component in a specialized parsing function
- Add a generic version parsing function

Swift SVN r32726
2015-10-16 17:43:28 +00:00
David Farler
7c48e3a362 Define __SWIFT_COMPILER_VERSION in the ClangImporter
Pass a preprocessor definition for the internal compiler
version when importing types.

rdar://problem/23100689

Swift SVN r32725
2015-10-16 17:43:27 +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
7778790a68 Omit needless words: prepend "is" to Boolean property names.
Prepend       "is" to        Boolean property names (e.g., "empty" becomes
"isEmpty") unless the property name strongly indicates its Boolean
nature or we're   likely to ruin the name. Therefore, the  presence of
one of the following in  the property name will suppress   this
transformation:

* An auxiliary verb, such as "is", "has", "may", "should", or "will".

* A word ending in "s", indicating either a plural (for which
  prepending "is" would be incorrect) or a verb in the continuous
  tense (which indicates its Boolean nature, e.g., "translates" in
  "translatesCoordinates").

Swift SVN r32458
2015-10-06 07:03:17 +00:00
Doug Gregor
44e34850ae Omit needless words: give initial Boolean parameters argument labels.
When the first parameter of a function has Boolean type, try to create
an argument label for it. We start with the (normally non-API)
parameter name as the argument label, then try to match that against
the end of the base name of the method to eliminate redundancy. Add a
little magic, and here are some diffs:

    -  func openUntitledDocumentAndDisplay(_: Bool) throws -> NSDocument
    +  func openUntitledDocument(display _: Bool) throws -> NSDocument

    -  func fontMenu(_: Bool) -> NSMenu?
    -  func fontPanel(_: Bool) -> NSFontPanel?
    +  func fontMenu(create _: Bool) -> NSMenu?
    +  func fontPanel(create _: Bool) -> NSFontPanel?

    -  func lockFocusFlipped(_: Bool)
    +  func lockFocus(flipped _: Bool)

    -  func rectForSearchTextWhenCentered(_: Bool) -> NSRect
    +  func rectForSearchText(whenCentered _: Bool) -> NSRect

    -  func dismissPreviewAnimated(_: Bool)
    -  func dismissMenuAnimated(_: Bool)
    +  func dismissPreview(animated _: Bool)
    +  func dismissMenu(animated _: Bool)

Swift SVN r32392
2015-10-01 23:34:21 +00:00
Doug Gregor
f3b20a4412 Omit needless words: strip context type from the name prefix consistently.
When the context type of a declaraton matches the result type,
strip off redundant type information at the beginning of the
declaration name if it is followed by a preposition. This covers the
class of transformations on performs on a class that produce a value
of the same type as that class, e.g., NSURL's "URLWithHTTPS" or
NSString's "stringByAppendingString".

When that preposition is the magical "By" and is followed by a gerund,
strip the "By" as well. Note that this is slightly more conservative
now for methods, which previously stripped based on the result type
(always). For example, in NSCalendar:

-  func adding(_: NSDateComponents, to: NSDate, options:
   NSCalendarOptions = [])
 -> NSDate?
+  func dateByAdding(_: NSDateComponents, to: NSDate, options:
   NSCalendarOptions
 = []) -> NSDate?

but it's more general for properties, e.g.,

-  @NSCopying var bezierPathByFlattening: NSBezierPath { get }
-  @NSCopying var bezierPathByReversing: NSBezierPath { get }
+  @NSCopying var byFlattening: NSBezierPath { get }
+  @NSCopying var reversing: NSBezierPath { get }

The important part is that the rules are more uniform and the code is
more regularly structured: we strip this leading type information when
it's redundant with the context and result type, regardless of whether
we have a property or a method, and the "By" rule is no longer special
in that regard.

Swift SVN r32129
2015-09-21 22:52:14 +00:00
Doug Gregor
44b8d45288 Clean up inference of default arguments from imported APIs (mostly).
My temporary hackery around inferring default arguments from imported
APIs was too horrible. Make it slightly more sane by:

1) Actually marking these as default arguments in the type system,
rather than doing everything outside of the type system. This is a
step closer to what we would really do, if we go in this
direction. Put it behind the new -frontend flag
-enable-infer-default-arguments.

2) Only inferring a default argument from option sets and from
explicitly "nullable" parameters, as stated in the (Objective-)C API
or API notes. This eliminates a pile of spurious, non-sensical "=
nil"'s in the resulting output.

Note that there is one ugly tweak to the overloading rules to prefer
declarations with fewer defaulted arguments. This is a bad
implementation of what is probably a reasonable rule (prefer to bind
fewer default arguments), which intentionally only kicks in when we're
dealing with imported APIs that have default arguments.

Swift SVN r32078
2015-09-18 21:50:59 +00:00
Jordan Rose
ea9117c18d [ClangImporter] Prefer -Xcc options, then -F search paths, then -I paths.
This makes Swift (a) more likely to prefer frameworks over bare headers,
reducing potential issues with non-modular headers, and (b) more likely
to fail in the same way as LLDB if the -Xcc options also contain or affect
search paths.

rdar://problem/22413525

Swift SVN r31950
2015-09-15 00:14:08 +00:00
Doug Gregor
406e7c6e48 Omit needless words: generalize the scratch space for strings.
NFC for now, but we'll need to handle multiple strings soon.

Swift SVN r31834
2015-09-10 00:03:09 +00:00
Michael Gottesman
59099b627f [ClangImporter] Make DetailedPreprocessingRecord a first-class option.
...though not one we set from the command line.

Swift SVN r31806
2015-09-09 04:37:23 +00:00
Michael Gottesman
0d6cd9bd18 [ClangImporter] Remove broken handling of -detailed-preprocessing-record.
- We shouldn't add flags based on other flags.
- We shouldn't add frontend flags if we can help it, and need to use -Xclang
  if we can't help it.

This is steps towards compiling; we can make the tests pass later.

Swift SVN r31805
2015-09-09 04:37:22 +00:00
Michael Gottesman
05ad340d5f [ClangImporter] Update for Clang API changes.
Swift SVN r31804
2015-09-09 04:37:21 +00:00
Michael Gottesman
c7cdf34110 Update module format handling to match upstream API.
Swift SVN r31802
2015-09-09 04:37:19 +00:00
Jordan Rose
5edf1ce5b7 [ClangImporter] Allow structs to be declared in multiple modules (too).
(And unions, and enums. Now with a fix for forward declarations.)

This isn't common, but we shouldn't break when it happens.

rdar://problem/22570681

Swift SVN r31692
2015-09-04 21:57:08 +00:00
Jordan Rose
e1de95d0fd Revert "[ClangImporter] Allow structs to be declared in multiple modules."
This reverts r31684. C only allows one definition of a tag decl, formally,
so we shouldn't expect definitions in multiple modules. We certainly don't
want every /declaration/ to count as making a struct part of a module's
interface.

Swift SVN r31686
2015-09-04 01:16:09 +00:00
Jordan Rose
13023505cb [ClangImporter] Allow structs to be declared in multiple modules (too).
(And unions, and enums.)

This isn't common, but we shouldn't break when it happens.

rdar://problem/22548309

Swift SVN r31684
2015-09-04 00:50:58 +00:00
Doug Gregor
7960ca1619 Omit needless words: strip out prefixes that are redundant with the result type.
When the prefix of a method/property name is restating the result
type, followed by "By" and then a gerund, drop everything up to the
gerund. For example:

  func stringByAppendingString(string: String) -> String

becomes

  func appending(string: String) -> String

Swift SVN r31683
2015-09-04 00:07:38 +00:00
Doug Gregor
86eb26a88c Factor out the matching of type names at the beginning of a name. NFC
Swift SVN r31682
2015-09-04 00:07:27 +00:00
Jordan Rose
a1ad2908b4 Use Clang's mangler for __attribute__((overloadable)) functions.
At some point we should probably just use Clang's mangler for all imported
functions, but I didn't want to rock the boat.

Swift SVN r31249
2015-08-14 19:50:28 +00:00
Doug Gregor
c02cd1a424 Factor omit-needless-words logic out of the Clang importer.
Sink the actual logic for omitting needless words way down into
Basic, so we can re-use it elsewhere. Tie the Clang importer into that
logic, mapping Clang types down to strings appropriately. NFC

Swift SVN r31233
2015-08-13 23:39:29 +00:00
Doug Gregor
100d38de2c Omit needless words from property and nullary-methods producing values of the enclosing class type.
Examples:
  NSString's

    @property (nonatomic, copy) NSString *uppercaseString;

  becomes

    var uppercase: String { get }

  NSColor's

    +(NSColor *)redColor;

  becomes

    class func red() -> NSColor

More heuristics for rdar://problem/22232287.

Swift SVN r31221
2015-08-13 18:31:33 +00:00
Doug Gregor
284d8e52cf Introduce an option to omit needless words when importing from Clang.
The -enable-omit-needless-words option attempts to omit needless words
from method names imported from Clang. Broadly speaking, a word is
needless if it merely restates the type of the corresponding parameter,
using reverse camel-case matching of the type name to the
function/parameter name. The word "With" is also considered needless
if whether follows it is needless, e.g.,

  func copyWithZone(zone: NSZone)

gets reduced to

  func copy(zone: NSZone)

because "Zone" merely restates type information and the remaining,
trailing "With" is also needless.

There are some special type naming rules for builtin Objective-C types,
e.g.,

  id -> "Object"
  SEL -> "Selector"
  Block pointer types -> "Block"

as well as some very-Cocoa-specific matching rules, e.g., the type
"IndexSet" matches the name "Indexes" or "Indices".

Expect a lot of churn with these heuristics; this is part of
rdar://problem/22232287.

Swift SVN r31178
2015-08-12 18:21:45 +00:00
Jordan Rose
f5b1efb354 Move client-affecting configuration options into a generated Config.h.
This way they can be used from other projects, like LLDB. The downside
is we now have to make sure the header is included consistently in all
the places we care about, but I think in practice that won't be a problem,
especially not with tests.

rdar://problem/22240127

Swift SVN r31173
2015-08-12 17:50:13 +00:00
Jordan Rose
aee63ec5d3 [ClangImporter] Allow importing from CarbonCore's UnicodeUtilities.h.
We blacklist most of CarbonCore, but UnicodeUtilities still has some
APIs that don't yet have newer replacements.

rdar://problem/21686090

Swift SVN r31150
2015-08-11 23:19:30 +00:00
Doug Gregor
a92cb576c4 Remove the ErrorHandling option from the Clang importer.
It was always-on; this was just for staging.

Swift SVN r31145
2015-08-11 20:24:12 +00:00
Argyrios Kyrtzidis
2ec7a31b6f [IDE] When doing ObjC header interface printing, ignore forward references to protocols as well.
Swift SVN r30945
2015-08-03 15:25:19 +00:00
Argyrios Kyrtzidis
881a98bca9 [IDE] When doing ObjC header interface printing, ignore decls in that header that are forward references.
rdar://21135249

Swift SVN r30941
2015-08-03 05:27:11 +00:00
Argyrios Kyrtzidis
b3dd0fa461 [IDE] When doing ObjC header interface printing, make sure to handle -include properly.
rdar://20893507

Swift SVN r30939
2015-08-03 02:12:14 +00:00
Jordan Rose
26438e47aa [ClangImporter] Handle -Xcc -include, sort of.
What does that mean? We'll indeed parse the provided prefix header.
If you aren't using a bridging header, that's all you get -- nothing
extra is made visible. If you /are/ using a bridging header, the prefix
header is prepended to it...but none of the modular content it imports
is made visible. I cloned rdar://problem/22083824 to fix that.

The important thing is that we /won't/ try to import overlays before
we've even finished setting up all the module loaders, and therefore
won't crash.

rdar://problem/20893290

Swift SVN r30831
2015-07-31 00:49:43 +00:00
Jordan Rose
3028dc8f44 Failure to load a bridging header -> failure to load a module.
This is important for both test targets and for debugging.

rdar://problem/20616099

Swift SVN r30784
2015-07-30 00:39:35 +00:00
Xi Ge
af589ebaa7 [InterfacePrinting] Print missing import decls from Swift module instance. rdar://20695897
Swift SVN r30588
2015-07-24 20:44:21 +00:00
Jordan Rose
d33f40478e [ClangImporter] Allow importing modules even if there's a fatal Clang error.
This was supposed to prevent crashes, but it ended up /causing/ crashes
because we may hit a fatal Clang error /while/ importing Clang modules
and bridging headers.

I left the test on the logic that imports bridging headers because that
happens under more controlled circumstances. (Clang modules that have
Swift counterparts should never have bridging headers.)

rdar://problem/21689014

Swift SVN r30512
2015-07-22 23:12:56 +00:00
Jordan Rose
0e3e08f0c6 [ClangImporter] Use Clang's -fembed-bitcode mode when under -embed-bitcode.
This should have no functionality change, but is supposed to keep us from
accidentally relying on the "full" Clang importer when in a backend job.
I tested it by archiving a little iOS app from a developer.

Unfortunately, part of the motivation here was that we'd get error messages when
we pass something Clang doesn't like, and that doesn't seem to be happening.

rdar://problem/21389553

Swift SVN r30407
2015-07-20 17:23:51 +00:00
Dmitri Hrybenko
109add8131 Foundation overlay: add NSCoder.decodeObjectOfClasses(_:forKey:)
Due to the fact that AnyClass is not Hashable, and that currently
NSKeyedArchiver/Unarchiver work with NSObject-derived, NSCoding
compliant classes, we are marking the decodeObjectOfClasses API refined
for Swift in our objc header and providing the desired overlay in our
overlay as shown below.

Arrays were also considered (for both API), but the underlying
implementation is entirely set-based, and using Arrays in Swift vs Sets
in objective C felt like too far a deviation.

Patch by Michael LeHew Jr.

Changes to the Dictionary test are caused by bumping the Fonudation API
epoch and taking in a fix in the types used in an NSDictionary
initializer.

rdar://21486551

Swift SVN r30297
2015-07-17 03:07:47 +00:00
Dmitri Hrybenko
ec9af44fe8 Adjust for new macro API in Clang
Swift SVN r29706
2015-06-25 22:01:45 +00:00
Dmitri Hrybenko
bc371ec1a2 [ClangImporter] Update for changes to how Clang manages macros in modules.
- Macros that aren't visible won't have macro info.
- Making a module visible to Sema doesn't make it visible to the Preprocessor.

Part of rdar://problem/21480635

Patch by Jordan Rose.

Swift SVN r29703
2015-06-25 22:01:42 +00:00
Dmitri Hrybenko
3a6ed7759f Adjust to the reshuffle in the LLVMModuleProvider API
Swift SVN r29702
2015-06-25 22:01:40 +00:00
Jordan Rose
8ad5297001 Don't complain when using '@testable import' on a Clang-only module.
Justification: if you delete all the Swift code out of a framework,
you shouldn't have to change your tests.

rdar://problem/21207346

Swift SVN r29452
2015-06-17 17:52:44 +00:00
Jordan Rose
34f69491c6 [ClangImporter] Import swift_private rules for methods and initializers.
A method has "__" prepended to its basename; an initializer has "__"
prepended to its first argument.

There are a few holes here involving no-argument initializers and factory
methods, but hopefully we won't need to remap those with swift_private anyway.

More of rdar://problem/20070465

Swift SVN r29429
2015-06-17 01:46:16 +00:00