Commit Graph

721 Commits

Author SHA1 Message Date
Jordan Rose
921f93ddf4 [ClangImporter] Allow importing modules even without an SDK.
In these cases, disable the standard system include paths so we don't
accidentally pick up headers in /.

This is going to be used by the runtime team for low-level interfaces with
C and Objective-C in the standard library.

Swift SVN r14789
2014-03-07 20:03:12 +00:00
Chris Lattner
4a827b7de4 enhance the clang importer to import noreturn functions like abort/exit as noreturn
swift functions.  Unfortunately, this can't be satisfactorily tested at the moment,
but that will be fixed soon.



Swift SVN r14709
2014-03-06 00:56:44 +00:00
Jordan Rose
a84f939545 [ClangImporter] Import string macros as CStrings.
Also, pass "-std=gnu11" so that we accept UTF-8 strings in these macros.

<rdar://problem/16198953>

Swift SVN r14664
2014-03-05 00:29:43 +00:00
Doug Gregor
9a3a9addd2 Mirror Objective-C initializers in subclasses that don't have designated inits.
This reverts part of r14563, which swapped out the mirroring of
Objective-C initializers into subclasses. We still need to do this
when a subclass does not declare it's designated initializers. At
least the mirroring code is more robust, and marks declarations as
implicit so they won't show up when printed.



Swift SVN r14633
2014-03-04 05:51:44 +00:00
Doug Gregor
a77d08f5a1 Use inherited initializers rather than cloning for Objective-C classes.
Make Objective-C initializers inherited according to the inheritance
rules we've specified. Prevent the Clang importer from manually
copying all of the initializers from every superclass into each
class. 

This eliminates a ton of extra allocating constructors generated when
importing Objective-C init methods. Now we only generate allocating
constructors for the init methods that are actually declared.

Note that initializer inheritance only actually works for
Objective-C-defined classes. More to come.



Swift SVN r14563
2014-03-02 01:59:54 +00:00
Jordan Rose
0d4b039e11 Support properties in Objective-C protocols.
There are two parts to this:
- Import protocol properties as properties, instead of as a pair of methods.
- Fix IRGen to handle property accesses in @objc protocols.

<rdar://problem/12993073>

Swift SVN r14438
2014-02-27 01:19:08 +00:00
Jordan Rose
0f71586952 [ClangImporter] Start importing Objective-C references using UncheckedOptional.
This is hidden behind the frontend flag -enable-objc-optional. Use -Xfrontend
when invoking the Swift driver.

Part of <rdar://problem/15189135>

Swift SVN r14332
2014-02-25 02:04:02 +00:00
Jordan Rose
5c9aea79f0 [ClangImporter] Restore typealiases for NSInteger, size_t, etc.
We will still import these as just 'Int', 'UInt', etc., but we still want to
allow users to write some of these types themselves. We now have an enum field
in MappedTypes.def to control this.

Fix-up for r14069 and <rdar://problem/16067854>

Swift SVN r14105
2014-02-19 22:29:25 +00:00
Jordan Rose
518c777bc8 [ClangImporter] Treat NSUInteger as UInt when it's an enum underlying type.
...rather than Int.

This handles the case where there are existing 32-bit enum constants with
the bit set, which isn't that uncommon for NS_OPTIONS declarations.

Part of <rdar://problem/15368372>, but should also fix the main issue in
<rdar://problem/15236662>.

Swift SVN r14090
2014-02-19 18:29:46 +00:00
Jordan Rose
0b2541b58f Rename the standard library to "Swift" (instead of "swift")
This is more in line with all other modules currently on our system.
If/when we get our final name for the language, we're at least now set
up to rename the library without /too/ much trouble. (This is mostly just
a lot of searching for "import swift", "swift.", "'swift'", and '"swift"'.
The compiler itself is pretty much just using STDLIB_NAME consistently now,
per r13758.)

<rdar://problem/15972383>

Swift SVN r14001
2014-02-17 19:30:47 +00:00
Argyrios Kyrtzidis
ffbd199770 [ClangImporter] When passing imported declarations to ASTContext, mimic the order that they would
be passed recursively (LIFO).

Swift SVN r13709
2014-02-09 18:27:39 +00:00
Argyrios Kyrtzidis
338ec06fab [ClangImporter] Add a statistic about the number of clang entities we imported.
Swift SVN r13706
2014-02-09 16:57:28 +00:00
Argyrios Kyrtzidis
8ae03064fb [ClangImporter] Pass the imported declaration to ASTContext after we have finished importing it.
This is to reduce the 'recursiveness' of the clang importer and its stack usage.

Addresses rdar://15929821.

Swift SVN r13688
2014-02-08 23:57:16 +00:00
Greg Parker
2b6bee7fb8 Add an importer mapping for C va_list.
This is necessary on 32-bit arm, where va_list's canonical type is void*. 
Without a typedef-based mapping the importer would drop declarations used 
by the NSStringAPI bridge because they appear to have void* parameters.

This mapping does not work on x86_64. SwiftTypeConverter::VisitTypedefType() 
never sees va_list on that architecture only, perhaps due to that 
architecture's unusual definition of __builtin_va_list. The default mapping 
to COpaquePointer plus the conversion CVaListPointer=>COpaquePointer 
is still in place for that architecture. 


Swift SVN r12853
2014-01-23 06:17:15 +00:00
Jordan Rose
5299a502d0 [ClangImporter] Import class, protocol, and category members lazily.
This still isn't /that/ lazy because a lot of things can force member
deserialization (such as the type-checker generating a DestructorDecl for
every imported class), and we don't do this in a member-granular way just
yet. I don't see any change in testing time, for example.

But besides just being a good thing in general, this perturbs the order
of imported decls enough to fix <rdar://problem/15799697>: we can now
reliably see that there is a -URL:something: function on NSObject that
blocks any properties named 'URL' from being imported as properties.

(Which we don't actually want; see <rdar://problem/15456130>.)

Swift SVN r12685
2014-01-22 00:54:47 +00:00
Jordan Rose
d53863b3a3 Don't provide an SDK by default.
Hardcoding a path to a particular SDK is definitely the wrong thing to do.
Let's see how far we can get without setting a default SDK.

See discussion in <rdar://problem/14395800>

Swift SVN r12414
2014-01-16 20:08:07 +00:00
Jordan Rose
ae3feb845a [ClangImporter] Fix the visible decls cache to handle new modules being loaded.
This can happen when importing a decl causes a new Swift module to be loaded
(because it uses one of our bridged types), which then brings in a new Clang
module. In this case we have no choice but to throw out the existing cache
and start over. We do keep a map of everything we've imported already, though,
so at least we don't have to do that part again.

This appears to make r12309 unnecessary for correctness, but it probably still
makes performance more consistent.

<rdar://problem/15785883>

Swift SVN r12336
2014-01-15 19:13:38 +00:00
Dave Zarzycki
720052c3fe Clang Importer: Remove gross '6432' constant
Swift SVN r11933
2014-01-06 19:05:13 +00:00
Jordan Rose
8a843f3879 [ClangImporter] Protocol instance methods are also class methods on roots.
-respondsToSelector: is declared on the NSObject protocol, which is adopted
by the NSObject root class. The NSObject metaclass also extends NSObject,
so it also needs a respondsToSelector:. This effectively becomes a
+respondsToSelector: method on NSObject-the-class.

Change importMirroredProtocolMembers to actually do this, just like
importObjCMembers was changed in r11614 for instance methods declared
directly within the class.

Finishes <rdar://problem/13371711>.

Swift SVN r11881
2014-01-04 00:56:37 +00:00
Dmitri Hrybenko
7e56d75a1e Clang importer: don't import superfluous typedefs to tag decls that have the same name
Not only this creates less ASTs, but this makes the resulting AST correct (it
is invalid to have a struct and a typealias with the same name).  But the
primary motivation is AST pretty-printing: we don't want to print those extra
useless typealiases.


Swift SVN r11289
2013-12-14 01:39:03 +00:00
Dmitri Hrybenko
9d45fe97f2 ClangImporter: factor out a routine to search in the cache
Swift SVN r11282
2013-12-14 00:03:02 +00:00
Dmitri Hrybenko
788912da16 Introduce AnyObject and AnyClass (for 'DynamicLookup' and 'DynamicLookup.metatype')
Also stop importing declarations that don't belong to a Clang module.  'id' and
'Class' were the last two that we cared about.


Swift SVN r11107
2013-12-11 01:07:13 +00:00
Dmitri Hrybenko
73c26e7e4c Clang importer: rename importDeclContext -> importDeclContextImpl to emphasize
that it should not be used directly.


Swift SVN r11043
2013-12-09 22:35:10 +00:00
Jordan Rose
5dda63aa82 Remove LoadedModule, and strip ModuleLoader down to just loading things.
Now that everything is done in terms of FileUnits, we don't need LoadedModule
anymore, and now that FileUnits just use virtual dispatch, we don't need to
indirect through ModuleLoader to distinguish them.

This doesn't quite simplify as much as it could, because the next change is
going to combine TranslationUnit and Module.

Swift SVN r10836
2013-12-05 01:51:12 +00:00
Jordan Rose
be12d86ddd Turn ClangModule into ClangModuleUnit.
Part of the FileUnit restructuring. A Clang module (whether from a framework
or a simple collection of headers) is now imported as a TranslationUnit
containing a single ClangModuleUnit.

One wrinkle in all this is that Swift very much wants to do searches on a
per-module basis, but Clang can only do lookups across the entire
TranslationUnit. Unless and until we get a better way to deal with this,
we're stuck with an inefficiency here. Previously, we used to hack around
this by ignoring the "per-module" bit and only performing one lookup into
all Clang modules, but that's not actually correct with respect to visibility.

Now, we're just taking the filtering hit for looking up a particular name,
and caching the results when we look up everything (for code completion).
This isn't ideal, but it doesn't seem to be costing too much in performance,
at least not right now, and it means we can get visibility correct.

In the future, it might make sense to include a ClangModuleUnit alongside a
SerializedASTFile for adapter modules, rather than having two separate
modules with the same name. I haven't really thought through this yet, though.

Swift SVN r10834
2013-12-05 01:51:11 +00:00
Joe Groff
fdd858dd21 ClangImporter: Import NS_OPTIONS constants as static properties.
Apply the same prefix-chopping logic as for NS_ENUM to produce static property names to put inside the Swift type we create. For now, continue importing NS_OPTIONS as structs with a single integer field; in the short term it's easy to put a C-like interface over them this way.

Swift SVN r10434
2013-11-13 23:19:32 +00:00
Joe Groff
975382599e ClangImporter: Rename 'EnumKind::Options' to 'Unknown'.
We're going to implement a newer, better path for 'Options'. No functionality change yet.

Swift SVN r10430
2013-11-13 20:58:06 +00:00
Joe Groff
96d1038c8c ClangImporter: Drop enum constant aliases.
Swift enums don't yet support aliasing of enum cases, so if we see multiple constants in an NS_ENUM with the same underlying value, drop all but the first. Hopefully the first one is the "proper" name for the constant.

Swift SVN r10008
2013-11-06 22:40:08 +00:00
Joe Groff
1650a3d75b ClangImporter: Remove common prefix of C enum case names from Swift names.
Swift enum cases are already namespaced to their type, but Cocoa NS_ENUM constants are manually namespaced with a common prefix, so if we imported them as-is, we'd end up with expressions like 'NSStringSearchOptions.NSStringSearchCaseSensitive'. To make this a bit nicer, look for a common prefix of camel-case words among all of the constants in the enum, and remove that prefix from the enum case names in the Swift interface.

In the case of a single enum case, we have no basis for determining a prefix, so do nothing. This case doesn't come up in the frameworks (that I can see).

Swift SVN r9993
2013-11-06 18:15:07 +00:00
Dmitri Hrybenko
2e53423e33 ASTContext: add "the one true way" to get the stdlib module
Swift SVN r9952
2013-11-05 01:40:24 +00:00
Dmitri Hrybenko
679b254469 Clang importer: don't verify imported modules if we verified them already
This helps improve responsiveness of code completion in REPL.


Swift SVN r9661
2013-10-24 22:38:01 +00:00
Jordan Rose
d527df57d9 [ClangImporter] Force NSDictionary's subscript index to conform to NSCopying.
NSDictionary's implementation of -objectForKeyedSubscript: takes an id
instead of 'id <NSCopying>' because a dictionary could in theory have non-
copyable keys. However, Swift requires the getter and setter for a subscript
operator to have the same type. Therefore, we unilaterally import the
getter as 'subscript(key : NSCopyingProto) { get }', and just rely on the
fact that the representation of 'id' and 'id <NSCopying>' is the same.

What doesn't change:
- objectForKey() still takes a plain 'id', in the rare cases that that is
  useful.
- Looping over an NSDictionary still gives you (id, id) pairs, on the grounds
  that if you actually want to do something with the key, it probably isn't
  going to be copying it. Without this, doing something useful with the key
  would require an explicit cast.
- If any other subscript indexes don't match up, the subscript is dropped
  (r8636).

<rdar://problem/14397360>

Swift SVN r9424
2013-10-16 22:25:06 +00:00
Jordan Rose
54b9f8c026 ClangImporter: Make sure Foundation is available when bridging NSString.
If Foundation wasn't ever actually loaded into the ASTContext, type
lowering would fail to find the NSString-to-String conversion functions.
Fix this by only bridging NSString when a module named "Foundation" can
be loaded.

This still isn't very precise, since the bridging functions could still
be missing, but it at least avoids a user-triggerable error.

<rdar://problem/15027448>

Swift SVN r9380
2013-10-15 22:01:04 +00:00
Jordan Rose
7b936e2b85 Remove unfinished notion of "Component" (originally for resilience).
docs/Resilience.rst describes the notion of a resilience component:
if the current source file is in the same component as a module being
used, it can use fragile access for everything in the other module,
with the assumption that everything in a component will always be
recompiled together.

However, nothing is actually using this today, and the interface we
have is probably not what we'll want in 2.0, when we actually implement
resilience.

Swift SVN r9174
2013-10-10 21:41:57 +00:00
Argyrios Kyrtzidis
097d9a0d0e When we have selector-style syntax for functions, make the argument patterns implicit.
Argument patterns create pseudo-named patterns, so make them implicit and ignore them when scanning for explicit source information.
Also make sure that the clang importer sets the HasSelectorStyleSignature bit appropriately.

Swift SVN r8803
2013-10-01 15:37:46 +00:00
Joe Groff
3d4c1251f1 Rename 'byref' attribute to 'inout'.
Swift SVN r8661
2013-09-25 20:56:52 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Jordan Rose
2ebd4756b6 [ClangImporter] Force load adapter modules whenever a Clang module is named.
Loading Cocoa (Clang) triggers the loading of several other modules,
including Foundation (Clang). We want to make sure we bring in the adapter
module Foundation (Swift), so loading Cocoa currently triggers a walk of
all imported modules to check for an adapter. The problem is that
Foundation (Swift) contains some eagerly-deserialized decls, which refer
to decls in Foundation (Clang). These decls were not importing correctly
because we hadn't finished loading all the adapters -- specifically, we
hadn't yet loaded ObjectiveC (Swift). This meant SEL was loaded as
swift.COpaquePointer instead of ObjectiveC.ObjCSel.

Now, when Foundation (Swift) asks to load Foundation (Clang), we'll walk
all imported modules under Foundation (Clang) to check for an adapter
before returning, even if Foundation (Clang) is already in our system.
This probably still isn't the best way to deal with this (particularly
since the modules in the subtree will get visited twice), but it ensures
that we've loaded all necessary adapter modules before trying to import
any decls.

TLDR: Importing Cocoa now correctly imports the Swift overlay for the
ObjectiveC module, meaning SELs are correctly imported.

<rdar://problem/14759044>

Swift SVN r7293
2013-08-16 21:56:00 +00:00
Dmitri Hrybenko
bb3d38b727 Clang importer: put the top-level declarations into the correct ClangModule
Before this change, DeclContext of all imported decls was set to the first
imported module.

No tests now, will be tested by future code completion commits.


Swift SVN r6949
2013-08-06 21:06:44 +00:00
Jordan Rose
674a03b085 Replace "oneof" with "union"...everywhere.
We haven't fully updated references to union cases, and enums still are not
their own thing yet, but "oneof" is gone. Long live "union"!

Swift SVN r6783
2013-07-31 21:33:33 +00:00
Jordan Rose
501b0e9394 Implement getReexportedModules for Clang modules.
This handles both Clang’s transitive inclusion and the use of
"adapter modules" to augment the Clang modules (e.g. Foundation.swift),
at the cost of a bit more memory (used to wrap all the Clang modules
in ClangModule objects). This is paving the way for making Sema
independent of ClangImporter.

Swift SVN r6698
2013-07-29 18:56:58 +00:00
Jordan Rose
d9b7c8ad5a Move ClangModule into the ClangImporter library.
This makes it very clear who is depending on special behavior at the
module level. Doing isa<ClangModule> now requires a header import; anything
more requires actually linking against the ClangImporter library.

If the current source file really can't import ClangModule.h, it can
still fall back to checking against the DeclContext's getContextKind()
(and indeed AST currently does in a few places).

Swift SVN r6695
2013-07-29 18:56:35 +00:00
Joe Groff
647421a013 ClangImporter: Rename 'BridgedTypes' to 'MappedTypes'.
This avoids some potential confusion with what SIL calls "bridged types", which involve more than a simple mapping to bridge.

Swift SVN r5815
2013-06-26 17:20:08 +00:00
Dmitri Hrybenko
05203f70f3 ClangImporter: Use ConstDeclVisitor and constify Clang's decls throughout the importer
Swift SVN r5788
2013-06-24 20:27:57 +00:00
Dmitri Hrybenko
8c3995996f Add infrastructure to easily map C types to swift stdlib types when they are
binary compatible.

This enables us to import MacTypes.h types as stdlib swift types to avoid name
conflicts.  We also import stdint.h types as stdlib swift types.

We can not map 'long double'-based ctypes.Float80 to swift.Float80 because size
of long double is 128 according to SysV ABI, and I compare that against what
the type name says (I did not find a way to find the size of the type).

Darwin.Float80 is a struct, so I don’t think we can import it as swift.Float80.
So with import Darwin, Float80 is still ambiguous.

I had to rename test/ClangModules/ctypes.swift ->
test/ClangModules/ctypes_test.swift because other tests do 'import ctypes',
which picks up 'ctypes.swift'.


Swift SVN r5727
2013-06-20 22:08:35 +00:00
Dmitri Hrybenko
49fa6738b9 Remove CPointer<T>, it was almost equivalent to UnsafePointer<T>, but
implemented pointer arithmetic.  Enhanced UnsafePointer<T> to do pointer
arithmetic.

Also: update Clang importer to import T* as UsafePointer<T>, fix standard
library fallout.


Swift SVN r5616
2013-06-17 17:10:08 +00:00
Joe Groff
11c7a3a92d ClangImporter: Bridge NSString objc properties to String properties.
We had an inconsistency where the synthesized Swift getter/setters were bridged but the VarDecl wasn't, causing assertion failures in SILGen.

Swift SVN r5366
2013-05-28 22:53:14 +00:00
Jordan Rose
ca498e04ef More -Wdocumentation cleanup.
Swift SVN r5167
2013-05-13 21:41:28 +00:00
Doug Gregor
9a70c0ebf4 [Clang Importer] Refactor the handling of type import contexts.
The importer has always imported types differently in different
places, e.g., function parameter types have special rules for C++
references. Formalize this notion a bit, and make it work properly
when dealing with typedefs where the underlying type itself might be
imported differently in different contexts. 

As part of this, limit the import of C's 'void' type to the result of
a function type.


Swift SVN r5055
2013-05-06 18:10:46 +00:00
Doug Gregor
c057b21193 Ban the use of construction syntax T(x) for coercions and unchecked downcasts.
Use "x as T" for coercions and "x as! T" for unchecked downcasts.


Swift SVN r4683
2013-04-11 21:17:47 +00:00