Commit Graph

1877 Commits

Author SHA1 Message Date
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
Doug Gregor
7e8d5f7cfe Use a different selector encoding in the .def file that allows nullary selectors. NFC.
Swift SVN r16012
2014-04-07 14:17:43 +00:00
Doug Gregor
0364e0b977 Assert that the # of selector pieces matches the # of method arguments.
Swift SVN r15985
2014-04-05 06:54:14 +00:00
Doug Gregor
57d54cacee Clang importer: add a hardwired table mapping selectors to method names.
Regardless of the heuristic we choose when importing Objective-C
selectors into Swift method names, there will be poor cases. Allow us
to bake specific mappings into the compiler so we can address those
cases without having to modify the Objective-C headers.

Part of <rdar://problem/16341485>.


Swift SVN r15984
2014-04-05 06:52:38 +00:00
Doug Gregor
c78a3ecd48 Clang importer: cache the result of the selector -> method mapping.
Swift SVN r15983
2014-04-05 06:04:01 +00:00
Doug Gregor
6baa7eb35c PrintAsObjC: Emit objc_runtime_name attributes for Swift classes.
This makes sure that Clang uses the mangled class names for
Swift-defined classes. Should be last compiler-side piece of
<rdar://problem/15506580>.


Swift SVN r15977
2014-04-05 04:45:21 +00:00
Doug Gregor
7102f1bb0b Clang importer: add a statistic for trailing prepositions in the first selector piece.
Swift SVN r15887
2014-04-03 18:08:01 +00:00
Doug Gregor
104cfe8919 Clang importer: add some statistics related to selector splitting.
Swift SVN r15873
2014-04-03 16:10:13 +00:00
Doug Gregor
08e7797f86 [Selector splitting] Drop non-directional prepositions from the beginning of imported argument names.
Swift SVN r15865
2014-04-03 14:22:20 +00:00
Doug Gregor
87144a8afa Make splitFirstSelectorPiece() static, now that it has just one caller
Swift SVN r15854
2014-04-03 04:20:10 +00:00
Doug Gregor
708bb64c6f Migrate initializer importing over to importMethodType().
We now consistently use the method name to form the types of
Objective-C methods.


Swift SVN r15851
2014-04-03 03:32:09 +00:00
Doug Gregor
e418e93511 Start cleaning up method name importing.
Import a selector into a Swift method name, performing splitting at
that point. Use the resulting method name to determine the argument
names of the parameters, rather than trying to chop up the selector
again. There's more refactoring to do here.

This fixes a longstanding bug where the first argument of an
Objective-C method got the internal parameter name when it should
have gotten no name at all.

Swift SVN r15850
2014-04-03 00:34:40 +00:00