Commit Graph

2609 Commits

Author SHA1 Message Date
Jordan Rose
7a30de2efe Disallow inheritance clauses for concrete typealiases.
typealias MyInt: ForwardIndex = Int

There is no real reason to allow this; it's just a static_assert that Int
conforms to ForwardIndex, which would be better spelled some other way.

This only applies to concrete typealiases, i.e. those that simply alias an
underlying type. Associated types can still have both inheritance clauses
and a (default) underlying type.

Swift SVN r11481
2013-12-19 21:13:54 +00:00
Joe Groff
017440165e Fix the weird capitalization of MetaTypeType.
Swift SVN r11475
2013-12-19 18:43:08 +00:00
Dmitri Hrybenko
73875c77e0 Clang importer: don't import BOOL and SEL
Swift SVN r11474
2013-12-19 18:37:23 +00:00
Dmitri Hrybenko
0950901b1b Don't import 'id' and 'Class'
rdar://15693821


Swift SVN r11465
2013-12-19 02:42:13 +00:00
Joe Groff
a9570e2004 ClangImporter: Make NS_OPTIONS conform to LogicValue.
Until we can actually do the implementation work necessary to make 'if optionSetValue.Option {}' work, this is a reasonable affordance to allow the C 'if optionSetValue & .Option {}' pattern to work and bring us to parity with ObjC.

Swift SVN r11412
2013-12-18 02:47:06 +00:00
Dmitri Hrybenko
c54c979f95 Clang importer: don't add @objc *attribute* to imported decls, just set the objc bit
AST printer: print @objc attribute only on top-level imported decls to reduce
the amount of noise.


Swift SVN r11365
2013-12-17 00:50:12 +00:00
Joe Groff
44dcc43fa9 ClangImporter: Make NS_OPTIONS imports conform to RawOptionSet.
This makes the bitwise operations &|^~ work with NS_OPTIONS.

Swift SVN r11349
2013-12-16 19:22:27 +00:00
Doug Gregor
11b6d19dd3 Add a location to NormalProtocolConformance.
This will be used for diagnostics in an upcoming refactor.


Swift SVN r11348
2013-12-16 17:24:15 +00:00
Dmitri Hrybenko
531adcbf45 Remove unused variable
Swift SVN r11293
2013-12-14 02:22:48 +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
Doug Gregor
b4a739854d Stop using ProtocolConformance::getWitnesses().
It's going away, soon.


Swift SVN r11277
2013-12-13 23:44:42 +00:00
Chris Lattner
698380d6d3 Introduce a new bit in VarDecl, "isLet". Teach Sema that 'isLet' properties
are not settable (like get-only ones).  Set the 'isLet' bit in various 
places, but not the particularly interesting or useful places yet.



Swift SVN r11121
2013-12-11 06:45:40 +00:00
Dmitri Hrybenko
2f02b021df Remove accidentally committed debugging code
Swift SVN r11112
2013-12-11 01:32:30 +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
Dmitri Hrybenko
e27001dbc7 Clang importer: determine the module for enums correctly while importing enum's
decl context


Swift SVN r11039
2013-12-09 22:19:47 +00:00
Argyrios Kyrtzidis
345564380c Rename 'ibaction/iboutlet' attributes to 'IBAction/IBOutlet'.
Swift SVN r10953
2013-12-07 00:14:51 +00:00
Doug Gregor
707d04c3d2 Clang importer: always expand out the (Objective-C) protocol list.
Fixes <rdar://problem/15246440>.


Swift SVN r10876
2013-12-05 19:18:57 +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
Jordan Rose
8b8cc8ee62 Turn SerializedModule into SerializedASTFile.
Part of the FileUnit restructuring. A serialized module is now represented as
a TranslationUnit containing a single SerializedASTFile.

As part of this change, the FileUnit interface has been made virtual, rather
than switching on the Kind in every accessor. We think the operations
performed on files are sufficiently high-level that this shouldn't affect us.

A nice side effect of all this is that we now properly model the visibility
of modules imported into source files. Previously, we would always consider
the top-level imports of all files within a target, whether re-exported or
not.

We may still end up wanting to distinguish properties of a complete Swift
module file from a partial AST file, but we can do that within
SerializedModuleLoader.

Swift SVN r10832
2013-12-05 01:51:09 +00:00
Dmitri Hrybenko
d076501cca Don't repeat Context.getIdentifier("self") everywhere in the code base
Swift SVN r10786
2013-12-04 18:42:34 +00:00
Joe Groff
111dd0c248 ClangImporter: Use type name to clip prefix from single-element enums.
Single-case enums actually come up a lot for NS_OPTIONS. Jordan suggested this approach, which works well for now.

Swift SVN r10473
2013-11-14 23:41:37 +00:00
Joe Groff
a1f123350f Enable NS_OPTIONS import by default.
Some work needs to be done on static member lookup and bitwise operations, but what's implemented now isn't a regression from what we have (except for an unfortunate case in Foundation.swift where we need to fully qualify a constant in a single-element NS_OPTIONS).

Swift SVN r10471
2013-11-14 23:21:28 +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
4f2adbe7ed AST: Include 'static' bit in VarDecls.
And track the 'static' SourceLoc in the PatternBindingDecl. This lets isInstanceMember return the right thing for static vars.

Swift SVN r10369
2013-11-12 06:16:48 +00:00
Joe Groff
774db24a8a Enable importing of NS_ENUMs as Swift enums.
A problem with name lookup from Clang module contexts <rdar://problem/15410928> means I have to disable a ~= overload in the ObjectiveC overlay. Other than that, NS_ENUM import should be ready to go.

Swift SVN r10018
2013-11-07 03:49:37 +00:00
Joe Groff
65632a59a4 ClangImporter: Don't register imported case decls.
This keeps the unqualified enum constant name from sneaking back in after the enum has been imported.

Swift SVN r10016
2013-11-07 03:49:27 +00:00
Joe Groff
c16f7778e2 ClangImporter: Don't expose NS_ENUM cases by their unqualified names.
Only import NS_ENUM constants into Swift enum cases as part of the enum itself, not if the original C constant name is referenced by itself through the Clang module.

Swift SVN r10015
2013-11-07 01:16:08 +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
6370f91383 ClangImporter: Handle negative C enum constants.
We needed some patching up to convert negative enum constants into proper negative IntegerLiteralExprs in the imported Swift AST, to handle the obnoxious INT_MIN edge case, and to handle "negative" values of unsigned enums.

Swift SVN r10005
2013-11-06 21:28:24 +00:00
Doug Gregor
df2a6fe7df Import @optional methods in Objective-C protocols as optional methods/subscripts.
Clean up ListMaker and get it compiling again. Delete all of the
stubbed-out table view delegate methods now that they're optional,
fixing the crash when dragging items <rdar://problem/14582991>.


Swift SVN r9995
2013-11-06 18:39:31 +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
Joe Groff
38ceed4e76 ClangImporter: Provide a null SourceLocation when lexing NS_ENUM token.
Using the expansionLoc intermittently leads to an "offset overflow", and we don't really care about the token source location.

Swift SVN r9989
2013-11-06 06:31:22 +00:00
Anna Zaks
54524e622a Replace ExprStmtOrDecl with ASTNode and make it a struct.
Previously, the Parser and BranchStmt typedef-ed ExprStmtOrDecl as a pointer union. Using typedef made the objects compatible, but did not allow us to extend the type with helper methods, such as getSourceRange(), which is something you can get on all of the AST objects. This patch introduces ASTNode that subclasses from PointerUnion and is used by both parser and BranchStmt.

Swift SVN r9971
2013-11-05 21:46:59 +00:00
Joe Groff
5c5d67dd7c ClangImporter: Import enum raw types and values from NS_ENUMs.
Set up the derived RawRepresentable conformance for an imported enum using its C underlying type and constant initializer values.

Swift SVN r9957
2013-11-05 04:28:10 +00:00
Joe Groff
16c5d69e17 ClangImporter: Recognize NS_ENUM declarations and import as Swift enums.
When we see an enum declaration in the Clang importer, look at its source location to see if it was produced as part of an NS_ENUM macro expansion. If so, take the 'Enum' route through the Clang importer and import it as a Swift enum. This will break things until we have end-to-end support for Clang-imported enums, so hide it behind an -import-ns-enum switch for now.

Swift SVN r9951
2013-11-05 01:38:00 +00:00
Joe Groff
5ec3cad5f6 ClangImporter: Emit metadata for imported enums.
Whatever kind of Swift decl we cons up for a Clang enum, add it to the externals list so we can pick it up and emit Swift metadata for it in IRGen. Fixes <rdar://problem/15242452>.

Swift SVN r9801
2013-10-30 18:15:09 +00:00
Doug Gregor
bae79dd8a3 Give imported protocols a proper generic signature.
Swift SVN r9629
2013-10-23 21:20:16 +00:00
Argyrios Kyrtzidis
0dd411d3e8 [ClangImporter] Add appropriate protocol conformances when creating the methods from the inherited protocols.
Swift SVN r9586
2013-10-22 15:47:34 +00:00
Greg Parker
1dbe2ac503 Don't import constructors for class Protocol because they use a symbol that is absent on iOS.
Swift SVN r9500
2013-10-18 21:54:34 +00:00
Joe Groff
5721bdda01 Don't pretend we can parse enum case refined types.
There's no way we'll be able to fully implement GADTs anytime soon.

Swift SVN r9477
2013-10-18 01:34:25 +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
Chris Lattner
09705dc7cd 1) Redesign DeclAttributes to be based around an array indexed by attribute, instead
of having a ton of ad-hoc bools in it.  This allows us to consolidate a ton of 
   boilerplate, eliminating 250 lines of code:

 17 files changed, 435 insertions(+), 662 deletions(-)

2) This eliminates the special case for weak and unowned attributes, which previously
   didn't show up in Attr.def.

3) While we're at it, keep track of proper source locations for each attribute, and
   use these to emit diagnostics pointing at the attribute in question instead of at
   a funcdecl or the @ sign.

4) Fix axle attributes, which had vertex and fragment swapped.



Swift SVN r9263
2013-10-13 01:25:50 +00:00
John McCall
8fbc790d39 Subsume OwnershipConventions into SILFunctionType.
Swift SVN r9186
2013-10-11 00:50:57 +00:00
Joe Groff
1bdbc97056 Drop the 'x as! T' cast syntax.
Now that we have a solid Optional-based story for dynamic casts, it's no longer needed, and can be expressed as '(x as T)!'. Future refinement of the 'as' syntax will deal with the unfortunate extra parens.

Swift SVN r9181
2013-10-10 23:47:59 +00:00
John McCall
dcf9d15cc7 Rewrite SILFunctionTypeInfo in terms of SILFunctionType.
Swift SVN r9090
2013-10-09 20:55:46 +00:00
Doug Gregor
a012f60633 Make protocol methods generic over <Self>.
Pull the implicit 'Self' associated type out of the protocol and into
an implicitly-declared generic parameter list for the protocol. This
makes all of the methods of a protocol polymorphic, e.g., given

  protocol P {
    typealias Assoc
    func getAssoc() -> Assoc
  }

the type of P.getAssoc is:

  <Self : P> (self : @inout P) -> () -> Self.Assoc

This directly expresses the notion that protocol methods are
polymorphic, even though 'Self' is always implicitly bound. It can be
used to simplify IRgen and some parts of the type checker, as well as
laying more of the groundwork for default definitions within
protocols as well as sundry other improvements to the generics
system.

There are a number of moving parts that needed to be updated in tandem
for this. In no particular order:
  - Protocols always get an implicit generic parameter list, with a
  single generic parameter 'Self' that conforms to the protocol itself.
  - The 'Self' archetype type now knows which protocol it is
  associated with (since we can no longer point it at the Self
  associated type declaration).
  - Protocol methods now get interface types (i.e., canonicalizable
  dependent function types).
  - The "all archetypes" list for a polymorphic function type does not
  include the Self archetype nor its nested types, because they are
  handled implicitly. This avoids the need to rework IRGen's handling
  of archetypes for now.
  - When (de-)serializing a XREF for a function type that has an
  interface type, use the canonicalized interface type, which can be
  meaningfully compared during deserialization (unlike the
  PolymorphicFunctionType we'd otherwise be dealing with).
  - Added a SIL-specific type attribute @sil_self, which extracts the
  'Self' archetype of a protocol, because we can no longer refer to
  the associated type "P.Self". 




Swift SVN r9066
2013-10-09 17:27:58 +00:00
Doug Gregor
940717a6ca [Clang importer] Don't double-import subscripts when the getter/setter types conflict.
Swift SVN r8919
2013-10-04 17:30:51 +00:00