Commit Graph

2428 Commits

Author SHA1 Message Date
Dmitri Hrybenko
5889e17528 Rewrite the long assertion so that it does not trigger -Wlogical-op-parentheses
Swift SVN r14575
2014-03-02 16:21:29 +00:00
Dmitri Hrybenko
197a682e14 Don't compare 'const char *' with ==, use StringRef
Swift SVN r14574
2014-03-02 15:41:33 +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
Joe Groff
8e6b353542 Derive conformances of Equatable and Hashable for simple enums.
If an enum has no cases with payloads, make it implicitly Equatable and Hashable, and derive default implementations of '==' and 'hashValue'. Insert the derived '==' into module context wrapped in a new DerivedFileUnit kind, and arrange for it to be codegenned with the deriving EnumDecl by adding a 'DerivedOperatorDecls' array to NominalTypeDecls that gets visited at SILGen time.

Swift SVN r14471
2014-02-27 20:28:38 +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
Chris Lattner
1344319677 Rename the internal compiler lexicon from val -> let.
Swift SVN r14408
2014-02-26 21:21:18 +00:00
Dmitri Hrybenko
a44da77de7 Clang importer: don't import structs with bitfields
Fixes rdar://16028632


Swift SVN r14395
2014-02-26 15:21:39 +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
3e846134e1 [ClangImporter] Don't mirror a protocol's methods if they're in the superclass.
Right now we have a hack to mirror ObjC protocol methods into an imported
ObjC class, because Swift's lookup only looks into superclasses, not into
protocols (by default, anyway). This already isn't great because it's wrong
for @optional, but it was particularly bad if /two/ superclasses conformed
to the same protocol (directly or indirectly). Because the mirrored methods
weren't marked as overrides, the type checker would consider them both as
possibilities, leading to strange errors like this:

  <REPL Input>:1:1: error: ambiguous use of 'description'
  w.description()
  ^
  AppKit.NSWindow:268:8: note: found this candidate
    func description() -> String
         ^
  ObjectiveC.NSObject:72:8: note: found this candidate
    func description() -> String
         ^

Now, we check to see if a superclass conforms to a protocol already before
mirroring its methods into the current class or category.

<rdar://problem/16102321> and possibly also <rdar://problem/16038085>

Swift SVN r14189
2014-02-21 00:35:49 +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
Chris Lattner
ecbbb4a42c rework our representations of subscripts to not curry the indexes
separately from the get/set value.  There is no exposed way in the
source language to use this, and this causes shorter term annoyance.

I chose to flatten the value and indices so the value comes first.
In principle, this allows us to completely eliminate our ObjC importer
thunks.  I haven't removed them though, because they might be useful
for something else.


Swift SVN r14049
2014-02-18 21:34:33 +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
Chris Lattner
28903887e7 Rename the internal compiler lexicon from let -> val.
Swift SVN r13992
2014-02-17 16:48:21 +00:00
Dmitri Hrybenko
571c9b3c5e Split 'type' keyword into 'static' and 'class'
rdar://15911697


Swift SVN r13908
2014-02-14 14:50:32 +00:00
Dmitri Hrybenko
b8817ae5f6 Move two operators to KnownIdentifiers.def
Swift SVN r13866
2014-02-13 10:37:31 +00:00
Doug Gregor
873396fd41 Check for recursive @property imports in the Clang importer.
Fixes <rdar://problem/16053872>.


Swift SVN r13852
2014-02-13 00:09:30 +00:00
Joe Groff
5c9470b9ca AST: Shun empty GenericSignatures, and remove the ASTContext argument from GenericSignature factories.
GenericSignatures with no params or requirements are a bug, so verify that they don't happen by making GenericSignature::get return null and GenericFunctionType assert that it has a nonnull signature. Hack Sema not to try to produce nongeneric GenericFunctionTypes when a function in a local type in a generic function context is type-checked; there's a deeper modeling issue that needs to be fixed here, but that's beyond the scope of 1.0. Now that GenericSignature always has at least one subtype, its factories no longer need an independent ASTContext argument.

Swift SVN r13837
2014-02-12 19:17:27 +00:00
Joe Groff
68db63b45d AST: Have GenericFunctionType use GenericSignature.
Change GenericFunctionType to reference a GenericSignature instead of containing its generic parameters and requirements in-line, and clean up some interface type APIs that awkwardly returned ArrayRef pairs to instead return GenericSignatures instead.

Swift SVN r13807
2014-02-12 03:44:28 +00:00
Doug Gregor
eaf410f9f5 Import Objective-C instancetype methods as DynamicSelf methods.
This eliminates a pile of extra casting when interacting with
Objective-C APIs. Addresses the majority of <rdar://problem/14044307>,
but there is still cleanup to do.


Swift SVN r13780
2014-02-11 06:42:53 +00:00
Jordan Rose
0de8d19514 Define globals for the names of the stdlib, ObjectiveC, and Foundation modules.
This is mostly useful for the standard library, whose name is going to
change to "Swift" soon. (See <rdar://problem/15972383>.) But it's good DRY.

Swift SVN r13758
2014-02-10 22:40:42 +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
Chris Lattner
78a6f969a2 rework SubscriptDecls to work the same as VarDecls: first the
SubscriptDecl is created, then the accessors are installed on it.
This allows us to create the subscript decl before the accessors
have been parsed, allowing us to build the subscript even in invalid
cases (better for later error recovery).

More importantly, this allows us to add it to Decls before calling
parseGetSet, so we can now make parseGetSet add accessors to Decls
without breaking source order (something that deeply upsets the IDE
features).

With all this untangled, we can now remove the 'addAccessorsInOrder'
hack where we parsed the accessors and then later tried to figure out
which order they came for the purpose of linking up the AST: accessors
now work just like everything else.



Swift SVN r13708
2014-02-09 18:22:30 +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
Chris Lattner
70d547c1da remove a bunch of code that is manually monkeying around with DeclContexts,
now that they are implicitly updated.  This exposes two things:
1) we're unncessarily serializing selfdecls in ctors and dtors.
2) The index pattern of a SubscriptDecl has no sensible DeclContext that 
   owns variables in it.

I'll deal with the first tomorrow, I'm not sure what to do with
the second one.


Swift SVN r13703
2014-02-09 07:36:18 +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
Doug Gregor
a47917246c Import Objective-C properties with custom getter/setter methods.
Retrieve the getter/setter selector from the underlying Clang node,
when there is one. This allows using and overriding Objective-C
properties that have custom getters and setters (i.e., for Boolean
properties where the getter is named isPropName), which narrowly
addresses <rdar://problem/15877160>.

One cannot declare a property in Swift and give it a different
selector. That would require a more general attribute such as
<rdar://problem/16019773>.



Swift SVN r13680
2014-02-08 17:04:31 +00:00
Chris Lattner
9f32d521a2 now that ctors and dtors have self patterns, we can unify and simplify the
implementation of AbstractFuncDecl::getImplicitSelfDecl() and eliminate
the ImplicitSelfDeclAndIsCached ivar.


Swift SVN r13351
2014-02-03 15:17:21 +00:00
Chris Lattner
3e08673772 Introduce patterns for self arguments to ctors and dtors, making them uniform
with FuncDecls.  This allows us to eliminate special case code for handling
self in various parts of the compiler.

This also improves loc info (debug info and AST info) because 'self' now
has a location instead of being invalid.

I also took the opportunity to factor a bunch of places creating self decls
to use similar patterns and less copy and paste code.



Swift SVN r13196
2014-01-31 02:17:22 +00:00
Chris Lattner
05edbb39e8 Further cleanups to the clang importer. Factor more mechanics of setting
up self arguments into helpers.


Swift SVN r13171
2014-01-30 21:36:02 +00:00
Chris Lattner
422a06cba3 Create a new createTypedNamedPattern function and refactor a bunch of code
to use it, NFC.


Swift SVN r13169
2014-01-30 20:40:22 +00:00
Joe Groff
9fe1ab427a Implement 'if let' and 'while let' statements.
Allow IfStmts and WhileStmts to have as their condition either an expression, as usual, or a pattern binding introduced by 'var' or 'let', which will conditionally bind to the value inside an optional. Unlike normal pattern bindings, these bindings require an in-line initializer, which will be required to be Optional type. Parse variable bindings in this position, and type-check them by requiring an Optional on the right-hand side and unwrapping it to form the pattern type. Extend SILGen's lowering of if and while statements to handle conditionally binding variables.

Swift SVN r13146
2014-01-30 10:37:39 +00:00
Mark Lacey
d69b305200 Generate IR for inline functions from Clang modules.
Currently only inline functions referenced from Swift source files, or
from the REPL, will get IR generated for them. Inline functions
referenced by other inline functions will require additional effort to
generate properly.

With this change we use the clang::CodeGenerator-created llvm::Module
for all IR generation in Swift. This is perhaps undesirable, but
unavoidable given the interface the public Clang APIs expose, which do
not allow for building a ModuleBuilder that borrows an existing
llvm::Module.

Also unfortunate is the hack to generate a UsedAttr for each imported
inline function, but the public Clang APIs do not provide a way to only
emit deferred decls without emitting other things (e.g. module flags
that conflict with what the Swift IRGen emits). Note that we do not do
IRGen for every inline function in the module - only the ones that the
importer pulls in, which appears to be only those transitively
referenced from Swift code.

Swift SVN r13134
2014-01-30 02:33:37 +00:00
Joe Groff
96d4364f87 ClangImporter: Give NS_OPTIONS imports a default constructor.
Add a default constructor to imported NS_OPTIONS types that sets their raw value to zero (no options).

Swift SVN r13111
2014-01-29 17:54:44 +00:00
Chris Lattner
929ad99f08 Clean up and generalize the code pertaining to how a FuncDecl accessor
knows about the AbstractStorageDecl it works on.  NFC.



Swift SVN r12994
2014-01-27 17:57:38 +00:00
Argyrios Kyrtzidis
7cfe28b722 Fix build failures due to API change in clang r200082.
Swift SVN r12955
2014-01-25 21:04:45 +00:00
John McCall
f416dd81a8 Track whether a PatternBindingDecl theoretically
declares storage or not.

Swift SVN r12942
2014-01-24 22:46:22 +00:00
Dave Zarzycki
6eba6ceeeb Zap accumlated unused variable warnings in non-assert builds
Swift SVN r12861
2014-01-23 08:11:37 +00:00
Dave Abrahams
d58caea0cd Revert "Zap accumlated warnings in non-assert builds"
This reverts r12850, which broke the build for me.

Swift SVN r12856
2014-01-23 06:47:29 +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
Dave Zarzycki
17eb84d9c6 Zap accumlated warnings in non-assert builds
Swift SVN r12850
2014-01-23 05:45:24 +00:00
Jordan Rose
d6281b74f8 [ClangImporter] For now, don't import properties with custom accessor names.
Instead, just import them as a pair of methods. This is obviously suboptimal,
but better than the alternative in which you can see the property, but
attempting to use the accessor with the customized name results in a crash
at runtime.

Swift SVN r12755
2014-01-22 18:27:58 +00:00
Jordan Rose
d1a68b5bf7 [ClangImporter] When importing members, don't use a forward declaration.
The canonical Clang decl is often not the same as the definition decl.
Fixes a bug introduced in r12685.

Swift SVN r12689
2014-01-22 02:43:28 +00:00
Doug Gregor
d52cec4b20 Eliminate a pile of literal identifiers for self, init, destructor, etc.
... because I can't stomach adding another one of these.


Swift SVN r12687
2014-01-22 01:09:49 +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
b49b91eee0 Don't import Objective-C ivars at all.
Direct access to ivars is very rare in our frameworks, and they can conflict
with property names (which we should prefer). On top of that, we weren't
even emitting the right code to access them correctly.

<rdar://problem/15818047>

Swift SVN r12604
2014-01-20 19:06:07 +00:00
Doug Gregor
7cd716227f Import non-prototyped functions as if they have no parameters <rdar://problem/15084122>.
Swift SVN r12598
2014-01-20 18:42:50 +00:00
Chris Lattner
f5b85341a1 Expand out the "isComputed" property in AbstractStorageDecl to be an enum
with two kinds, and some more specific predicates that clients can use.

The notion of 'computed or not' isn't specific enough for how properties
are accessed.  We already have problems with ObjC properties that are 
stored but usually accessed through getters and setters, and a bool here
isn't helping matters.

NFC.



Swift SVN r12593
2014-01-20 18:16:30 +00:00
Chris Lattner
7e67fdb30a decls always can get to an ASTContext, remove the unneeded
ASTContext argument from VarDecl::setComputedAccessors.


Swift SVN r12538
2014-01-18 20:04:05 +00:00
Doug Gregor
1bd15b7b17 Clean up handling of getter/setter thunks. <rdar://problem/14109713>
Swift SVN r12461
2014-01-17 04:23:11 +00:00