Commit Graph

1871 Commits

Author SHA1 Message Date
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
Jordan Rose
8410a9bdea [ClangImporter] Teach lookupValue to find top-level swift_private declarations.
Essentially, if we see a name that starts with "__", start the whole process
again.

Part of rdar://problem/20070465

Swift SVN r29428
2015-06-17 01:46:15 +00:00
Jordan Rose
615a32ae11 [ClangImporter] Handle swift_private renaming for a variety of imported decls.
...including structs and struct fields, enums and enum cases, typedefs,
protocols, classes, and properties.

The main problem is that this /doesn't/ handle top-level /lookup/, so you
can't actually find any of these renamed types. This is fixed in the next
commit.

This does not handle methods, subscripts, or initializers.

Part of rdar://problem/20070465

Swift SVN r29427
2015-06-17 01:46:14 +00:00
Jordan Rose
7cc910b39a [ClangImporter] Add a version of importName that takes a clang::NamedDecl.
At this point this is just for convenience, but see next commit.

Swift SVN r29426
2015-06-17 01:46:13 +00:00
Jordan Rose
a696730061 [ClangImporter] Remove suffix appending from importName.
This isn't used anymore. No functionality change.

Swift SVN r29425
2015-06-17 01:46:12 +00:00
Jordan Rose
6658c94988 [ClangImporter] Consistently name Swift->Clang helpers "export*".
If Clang->Swift functions are named "import*" ("importDecl", "importName",
etc.), then clearly Swift->Clang functions should be called "export*".
(Originally we called both directions "import", but recent additions have
used "export" for Swift->Clang instead.)

No functionality change.

Swift SVN r29424
2015-06-17 01:46:06 +00:00
Jordan Rose
cb2ca7d997 [ClangImporter] Remap factory methods according to the swift_name attr.
On a factory method, swift_name can have two effects:

- If the custom name has a base name of "init", import the method as an
  initializer, even if it doesn't follow the usual naming conventions.
- Otherwise, import the method as a method, even if it /would have/ been
  imported as an initializer.

There's a bit of trickiness around NSError**: currently you have to specify
the name of the error parameter on the Clang side even if it's going to be
deleted on the Swift side. We may want to change this later.

The test cases here exposed the issues in the previous two commits,
so this effectively depends on those for passing tests.

More of rdar://problem/19240897.

Swift SVN r28979
2015-05-24 01:48:24 +00:00
Argyrios Kyrtzidis
d9032c0e39 [IDE] Make sure that ClangImporter::lookupDeclsFromHeader forwards to the passed in filter
function and that filter receives macros as well.

Swift SVN r28971
2015-05-23 20:20:27 +00:00
Argyrios Kyrtzidis
9917e74533 [IDE] Support printing the header interface for a header, that belongs to a clang module
that the clang invocation is importing.

Fully addresses rdar://21067984

Swift SVN r28962
2015-05-23 08:14:59 +00:00
Dmitri Hrybenko
8c41d4d4ca SDK overlay: actually request new APIs from CoreImage
Swift SVN r28831
2015-05-20 17:36:07 +00:00
Dmitri Hrybenko
ea17483633 Add CMake options and #ifs to hide tvOS
Swift SVN r28752
2015-05-19 05:15:52 +00:00
Adrian Prantl
70279d192f Disable module debug info generation when -detailed-preprocessing-record
is enabled.

rdar://problem/20898265

This reapplies r28503 with a testcase and a corrected condition.

Swift SVN r28624
2015-05-15 16:15:01 +00:00
Jordan Rose
c129637bf6 Name lookup: avoid even calling lookup code on Clang submodules.
This is a hack.

We currently don't put anything in Clang submodules; they're just wrappers
to track what is and isn't visible. All lookups happen through the top-
level module.

This commit adds a new API getImportedModulesForLookup, which is ONLY used
by top-level name lookup and forAllVisibleModules. It is identical to
getImportedModules for everything but ClangModuleUnits, which instead
compute and cache a list of their transitively imported top-level modules.

This speeds up building Foundation.swiftmodule with a release compiler by
a bit more than 5%, and makes a previously lookup-bound test case compile
a third faster than before.

This is a hack.

rdar://problem/20813240

Swift SVN r28598
2015-05-15 01:26:05 +00:00
Jordan Rose
6786158edb [ClangImporter] Always sort top-level value lookups from Clang.
The order of lookups affects the order of imports, which can sadly end up
causing different behavior down the line.

The sort is by Clang TU source order, which isn't wonderful but should be
consistent. There are generally fewer decls without source locations that
come from Clang.

Swift SVN r28578
2015-05-14 20:10:59 +00:00
Devin Coughlin
4b23d4a219 Update clang importer and target platform detection for watchOS.
For the moment, we do not consider APIs deprecated earlier than watchOS 2.0 as
unavailable. rdar://problem/20948019 track changing this once the ultimate
decision on this policy has been made.

This addresses the compile-time components of rdar://problem/20774229

Swift SVN r28559
2015-05-14 04:20:43 +00:00
Adrian Prantl
f8c52caa37 Revert "Disable module debug info generation when -detailed-preprocessing-record"
This reverts commit r28503 while investigating Linux buildbot breakage.

Swift SVN r28535
2015-05-13 21:48:28 +00:00
Adrian Prantl
5a20c4d026 Disable module debug info generation when -detailed-preprocessing-record
is enabled.

rdar://problem/20898265

Swift SVN r28503
2015-05-13 03:13:49 +00:00
Ted Kremenek
9be9444242 Adjust overlay to CoreImage nullability changes.
Implements rdar://problem/20645743.

Swift SVN r28490
2015-05-12 22:15:03 +00:00
Argyrios Kyrtzidis
f000fcd383 [IDE] For header interface printing, include macros and module imports.
Swift SVN r28413
2015-05-11 06:48:28 +00:00