Commit Graph

888 Commits

Author SHA1 Message Date
Jordan Rose
af3c3b358d Revert "[ClangImporter] Update for Clang API change in r209002."
We still have an outstanding incompatibility with LLVM trunk, so let's
just get in a state where we can build against known commits for now.

This reverts r18233.

Swift SVN r18234
2014-05-17 01:40:57 +00:00
Jordan Rose
d7c6bbf760 [ClangImporter] Update for Clang API change in r209002.
If you haven't picked up that commit in Clang yet, it should be safe to
revert this patch.

Swift SVN r18233
2014-05-17 00:50:13 +00:00
Jordan Rose
b581365785 [ClangImporter] If a Clang module fails to build, it's not missing.
...so don't report a second "module missing" error from Swift itself.

We do still treat the Clang module failing to build as a fatal error.

<rdar://problem/16175035>

Swift SVN r18231
2014-05-17 00:23:46 +00:00
Jordan Rose
a012602f62 [ClangImporter] Pass diagnostics through to Swift's diagnostic consumer.
We're not mapping source locations over correctly yet, so the file name
where an error occurs gets shoved into the diagnostic text, but that's
fine for now.

This also silences the "module 'Blah' not found" error coming from the
importer whenever Swift itself can be responsible for importing the module.

Still to do: if we can't build a Clang module, we shouldn't report that
error and then say it can't be found.

<rdar://problem/14509389>

Swift SVN r18230
2014-05-17 00:23:44 +00:00
Jordan Rose
bfa7566aec [ClangImporter] Put implicit properties into the list of all class members.
This allows "obj.description!" to work on iOS when 'obj' is an AnyObject,
even though 'description' is an implicit property created by the importer.

Swift SVN r18149
2014-05-16 00:30:55 +00:00
Jordan Rose
869508db2c [ClangImporter] Make sure the imported header module can see the stdlib.
Otherwise, it can't find the appropriate ~= to use for synthesized NS_ENUM
RawRepresentable conformances, leading to bizarre errors about the
underlying type (usually Int) not being able to convert to NSObject.

<rdar://problem/16923405>

Swift SVN r18131
2014-05-15 22:03:31 +00:00
Doug Gregor
d640eb4083 Introduce support for blacklisting factory-methods-as-inits.
Some fcactory methods shouldn't come in as initializers, per
<rdar://problem/16908950>.


Swift SVN r18101
2014-05-15 07:04:46 +00:00
Doug Gregor
3210f19411 Clang importer: replace the designated-initializer whitelist with a general method whitelist.
... which only handles designated initializers, for now at least.


Swift SVN r18100
2014-05-15 06:22:44 +00:00
John McCall
a3fb501114 Recognize the objc_bridge and objc_bridge_mutable
attributes and create implicit conversions for them.

Also, when generating Clang modules for import, set the
appropriate macro to make CoreFoundation actually apply
those attributes to its typedefs.

Also, give shared linkage to imported class method
definitions.

The net effect is that CFString now automatically
converts to NSString and vice-versa.

Depends on Clang r208756 in order to preserve attributes
applied to tag types in multiple typedef declarations.

Swift SVN r18069
2014-05-14 08:19:39 +00:00
Jordan Rose
2877bd0854 Add support for dependency file generation with -emit-dependencies.
This performs very conservative dependency generation for each compile task
within a full compilation. Any source file, swiftmodule, or Objective-C
header file that is /touched/ gets added to the dependencies list, which
is written out on a per-input basis at the end of compilation.

This does /not/ handle dependencies for the aggregated swiftmodule, swiftdoc,
generated header, or linked binary. This is just the minimum needed to get
Xcode to recognize what needs to be rebuilt when a header or Swift source
file changes. We can revisit this later.

This finishes <rdar://problem/14899639> for now.

Swift SVN r18045
2014-05-14 00:34:11 +00:00
Doug Gregor
73528dc0e0 Enable importing factory methods as initializers by default.
Finishes <rdar://problem/16509024>.

Swift SVN r17972
2014-05-12 23:01:20 +00:00
Argyrios Kyrtzidis
63ebd0ef8d [ClangImporter] When creating the FileID for the header import buffer, set the main FileID as include location.
SourceManager expects that SourceLocations have the main FileID as parent, except for the predefines buffer.
Fixes assertion hit in a SourceKit test.

Swift SVN r17851
2014-05-10 22:31:29 +00:00
John McCall
c03b705dd0 Recognize CF "subclasses" and require CFTypeRef to specifically
be 'const void *', not just any 'void*'.

Swift SVN r17659
2014-05-08 00:51:27 +00:00
Jordan Rose
3e917be738 Use full DeclNames for dynamic lookup of calls.
Previously, we were just using the base name, which resulted in massive
inefficiency when dealing with Clang (we basically had to check every
selector in the system to see if it had the same first selector piece).
I've hacked ConstraintSystem a bit to carry a map from UnresolvedDotExpr
to the ApplyExpr that consumes it, so that we can use the full DeclName
and look up methods by full selector.

Now that dynamic lookup is fast, re-enable it for the
Foundation_bridge.swift test. (r17520 actually provided most of the benefit.)

This does break selector lookup on AnyObject when doing selector splitting,
and slightly regresses diagnostics when you try to call a method on AnyObject
and forget a parameter name.

<rdar://problem/16808651>. Part of the Playground performance efforts.

Swift SVN r17524
2014-05-06 02:35:08 +00:00
Jordan Rose
ed4ad291c5 [ClangImporter] Don't bother running lookups on submodules.
We're only using Clang submodules for their imports and link dependencies;
they don't contain decls right now.

Swift SVN r17520
2014-05-06 02:06:06 +00:00
Joe Groff
4a09c9f9dd Add a -print-clang-stats frontend flag.
Prints stats from the Clang importer's ASTReader.

Swift SVN r17512
2014-05-06 01:08:09 +00:00
Jordan Rose
0c46eb821e [ClangImporter] Handle decls declared in imported headers.
This improves the -import-objc-header option to read decls from the header
as well. Any declaration that is not from a module will be considered to be
part of the "header module". Conversely, forward-declarations appearing in
the header will be resolved by looking through all modules responsible for
importing a header.

More of <rdar://problem/16702101>

Swift SVN r17492
2014-05-05 22:52:17 +00:00
Doug Gregor
4996efbfba Implement support for making "with" implicit on the first argument of an initializer.
When importing an Objective-C init method or factory method into an
initializer, if the first camelCase word of the first argument name
starts with "with", drop the "with". This means that

  -initWithRed:green:blue:alpha:

will get imported into Swift as

  init(red:green:blue:alpha:)

as will

  +colorWithRed:green:blue:alpha:

This is <rdar://problem/16795899>, hidden behind the
-implicit-objc-with flag.

Swift SVN r17271
2014-05-02 21:13:04 +00:00
Jordan Rose
cf77de720a Add -import-objc-header option, and wire up the basic infrastructure.
THIS IS NOT READY FOR USE YET.

The new plan for mixed-source non-framework targets is that the Swift
compiler will import an Objective-C header directly, and treat the decls
and imports in that header as explicitly visible to the entire target.
This means users don't have to modularize their headers before bringing
them into Swift.

This commit adds the option and introduces the "imported headers" module
as an implicit import for the source files being compiled. It also directs
the Clang importer to process the given header (using #import, so that it
won't somehow get included twice) and watches for any module imports that
occur as a result of reading that header.

Still to come: import of decls within the header (not within any module),
and proper serialization of cross-references to the header and its imports.

Part of <rdar://problem/16702101>

Swift SVN r17218
2014-05-02 00:55:31 +00:00
Jordan Rose
83e46296d5 [ClangImporter] Constify uses of clang::Module.
No functionality change.

Swift SVN r17216
2014-05-02 00:55:30 +00:00
John McCall
4a0790c072 Do a crazy lookup hack to allow users to write CFString instead
of CFStringRef.

Eventually this should be optimized by generating better
entries in Clang modules.

Swift SVN r17208
2014-05-01 23:29:29 +00:00
Jordan Rose
4d8b4a6930 [ClangImporter] Move the ASTFrontendAction::Execute logic inline in create().
We're going to need the parser again later, and we probably shouldn't be
hoping Clang's -fsyntax-only mode lines up with what we need to do anyway.

Swift SVN r17124
2014-05-01 00:06:19 +00:00
Mark Lacey
35c3799d2a Handle -target-abi as a frontend option and default it to darwinpcs for arm64/Darwin.
Swift SVN r17077
2014-04-30 06:12:54 +00:00
Jordan Rose
0e7bb07b26 Make module loaders owned by the AST context instead of ref-counted.
Also, create the Clang module loader directly rather than indirecting through
a "get constructor" function. It's no longer a valid configuration to not
have a Clang importer.

Swift SVN r16862
2014-04-26 00:57:09 +00:00
Jordan Rose
1dfc037875 [ClangImporter] Pass through target CPU and features properly.
The hardcoding of CPU settings in lib/Driver/Tools.cpp isn't at all ideal,
but it will let us limp along for now.

<rdar://problem/16641385>

Swift SVN r16861
2014-04-26 00:57:07 +00:00
Jordan Rose
76c89fe1e2 [ClangImporter] Avoid Clang's isModuleVisible.
Swift sometimes has a different notion of visibility, even for Clang modules.
In particular, this was causing the C version of NSUTF8StringEncoding
(from Foundation) to show up in AppKit, bypassing the Swift version in the
overlay.

We still want to search for redeclarations of functions, typedefs, and globals,
since these are often repeated in multiple modules without harm. The decl will
still have a "home" module, but this should allow them to be found by lookup.

<rdar://problem/16396994> and possibly <rdar://problem/14665250>

Swift SVN r16762
2014-04-24 18:50:01 +00:00
Jordan Rose
315c2792a4 [ClangImporter] Fix getImportedModules for "all" and "private-only" filters.
"all" was leaving out submodules, which are not privately visible but are
publicly visible. "private-only" had a logic inversion.

This unfortunately introduces some non-determinism in trying to unique the
imports.

Swift SVN r16719
2014-04-23 21:37:34 +00:00
Mark Lacey
509811b3d0 Use darwinpcs for ARM64.
The clang TargetInfo for ARM64 defaults to aapcs unless darwinpcs is
specifically requested (which clang's driver does when compiling for
ARM64), so we end up with the wrong ABI.

I filed <rdar://problem/16687086> because it seems reasonable for
TargetInfo to default to darwinpcs when the target OS is known to be
isOSDarwin.

Swift SVN r16654
2014-04-22 16:13:25 +00:00
Argyrios Kyrtzidis
b3f470ad16 [ClangImporter] Make getting the ClangNode from a swift Decl more efficient by
allocating extra memory and storing it directly before the swift AST object.

Reduces code-completion time for Cocoa by -25%.

Swift SVN r16615
2014-04-21 07:18:50 +00:00
Doug Gregor
ca3c1f7ca3 Don't import nullary factory methods as unary, ()-accepting initializers.
Nobody likes it, and it's so rare that we're better off simply leaving
these rare cases as factory methods.

Swift SVN r16550
2014-04-18 21:36:15 +00:00
Doug Gregor
c56d50a12c Introduce a named argument for imported nullary factory methods with long names.
We started tracking statistics for these in r16529, but because we've
"always" done this for initializers, it's trivial to just implement
the splitting. As with initializers, we synthesize a named argument of
type '()' to capture the part of the first selector piece that follows
the class name.


Swift SVN r16530
2014-04-18 16:41:18 +00:00
Doug Gregor
000aeff4fb Keep track of the number of nullary factory methods we skip due to a "long name".
For example, in an Objective-C class like this:

  @interface NSFoo
  +(instancetype)fooForReading;
  @end

We don't import that class method as an initializer yet.




Swift SVN r16529
2014-04-18 16:24:01 +00:00
Greg Parker
7ea84bbb52 Add -target-cpu and -target-feature options to arm64 importer. Re-enable arm64.
Swift SVN r16501
2014-04-18 06:28:05 +00:00
Argyrios Kyrtzidis
532b8415c4 [ClangImporter] Address the "try to clear your module cache to see if things start working again"
mystical workaround that hits our dogfooders.


Address this by adding '-fmodules-validate-system-headers' to the clang importer, which rebuilds the clang modules if system headers change.
By my unscientific testing I didn't see significant difference for compile time on the template Cocoa project beyond noise level, and it shouldn't
be significant on the project level because clang module importing happens on per-swift-target basis, not per-swift-file.

Swift SVN r16482
2014-04-18 00:29:51 +00:00
Doug Gregor
f56c68386e Start importing factory methods as initializers.
When an Objective-C class method follows the naming convention of a
factory method, i.e., its starting words match the ending words of the
class name, import it as a convenience initializer when it also:
  - Returns instancetype (i.e., dynamic Self in Swift parlance)
  - Has no NSError** parameters, which indicate the potential for failures

This is under a new flag (-enable-objc-factory-method-constructors)
because it is not generally functional. However, this is a step toward
<rdar://problem/16509024>.

Swift SVN r16479
2014-04-17 23:34:00 +00:00
Doug Gregor
96bc99e3c4 Revert "Add a flag -ignore-overlays to ignore overlays, and use it when building the standard library."
This reverts commit r16383.

Swift SVN r16475
2014-04-17 22:07:47 +00:00
Doug Gregor
f384cbfe63 Add a flag -ignore-overlays to ignore overlays, and use it when building the standard library.
Fixes <rdar://problem/16603168>. This was way too much engineering
effort to ban fork() and vfork().

Swift SVN r16383
2014-04-16 00:02:38 +00:00
Argyrios Kyrtzidis
f9775c3c82 [ClangImporter] When providing the display decls, make sure to include extensions
of the module that extend classes from other modules.

rdar://16608340

Swift SVN r16360
2014-04-15 05:20:38 +00:00
Doug Gregor
2dfed7538d Switch the Clang importer over to using ObjCSelector more often.
Swift SVN r16347
2014-04-15 00:35:40 +00:00
Doug Gregor
18bf604360 Distinguish betweeen simple names ("foo") and zero-argument compound names ("foo()").
This isn't actually used yet, but it's an important distinction.

Swift SVN r16326
2014-04-14 20:05:34 +00:00
Ted Kremenek
35c2b6e469 PrintAsObjC: use protocol remapping in the importer to remap to the original protocol name.
Along the way, don't print out the same module import more than once.

Fixes <rdar://problem/16602327>.

Swift SVN r16308
2014-04-14 08:27:11 +00:00
Doug Gregor
9d7f0b6211 Rework the selector-splitting heuristics.
This makes a number of changes to the selector-splitting
heuristics. Specifically:

  - Eliminate last-word splitting, and with it the notion of
    multi-words. We only split at prepositions now.
  - Introduce the notion of "linking verbs" such as "will" or
    "should"; when these show up, we refuse to split a selector, which
    helps with delegates.
  - Eliminate the special case for "get" and "set". It wasn't
    helping.
  




Swift SVN r16265
2014-04-12 20:32:16 +00:00
Argyrios Kyrtzidis
2da311cf1f [IDE] For the module interface, don't print submodule imports, unless they are submodules
of the module we are printing.

rdar://16530804

Swift SVN r16262
2014-04-12 19:20:08 +00:00
Dmitri Hrybenko
110f85bc16 Move @exported to use new attribute infrastructure
Swift SVN r16158
2014-04-10 13:35:35 +00:00
Doug Gregor
e56c2dee3f Split first selector piece after "get" or "set" if there is no preposition.
Addresses <rdar://problem/16548821>.

Swift SVN r16057
2014-04-08 16:34:45 +00:00
Jordan Rose
835bfb15a9 [ClangImporter] Add an option (off by default) to infer "implicit properties".
In Objective-C, any method with no arguments can be used with dot syntax, as
can any method that takes one argument whose name starts with "set". This
commit adds a frontend-only flag -enable-objc-implicit-properties to look for
"setter-like" methods that match up with "getter-like" methods to import them
as Swift properties. By default, such methods are just considered unrelated
methods.

Part of <rdar://problem/16215476>

Swift SVN r16025
2014-04-07 21:49:37 +00:00
Doug Gregor
0a8d792b2f Add some more multiwords.
Swift SVN r16017
2014-04-07 20:03:36 +00:00
Doug Gregor
49387beb25 Selector splitting: don't split selectors in the middle of whitelisted "multi-words".
Swift SVN r16016
2014-04-07 19:17:23 +00:00
Doug Gregor
f6a196f700 Clang importer: when preposition splitting fails, split at the last word.
Swift SVN r16015
2014-04-07 19:17:22 +00:00
Doug Gregor
4130bb15ff Add a whitelist of designated initializers and use it in the Clang importer.
Seed the whitelist with the designated initializers for NSObject,
NSDocument, and UIDocument. We'll grow this list over time.
Fixes <rdar://problem/16521299>.


Swift SVN r16013
2014-04-07 15:06:59 +00:00