Commit Graph

2550 Commits

Author SHA1 Message Date
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
Doug Gregor
535d03687b Infer the requires_stored_property_inits attribute for NSManagedObject.
Swift SVN r12316
2014-01-15 05:11:52 +00:00
Doug Gregor
23aeafc195 Finish switching "static" over to "type" in examples, proposals, etc.
Swift SVN r12048
2014-01-08 05:28:59 +00:00
Dave Zarzycki
720052c3fe Clang Importer: Remove gross '6432' constant
Swift SVN r11933
2014-01-06 19:05:13 +00:00
Dave Zarzycki
3abeb338a4 Teach the importer about word-sized types
Swift SVN r11917
2014-01-05 22:58:23 +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
Doug Gregor
41b6a42067 Clang importer: whitelist certain Objective-C protocols for renaming.
Rather than append the "Proto" suffix to all imported Objective-C
protocols, which can be confusing, whitelist those protocols that we
do have to rename. Only NSObject falls into this category so far.

Fixes <rdar://problem/15741699>.

Swift SVN r11856
2014-01-03 07:04:44 +00:00
Chris Lattner
2b521ffa46 mark a couple more 'self' decls in functions synthesized by the
importer as 'lets'.  This should produce slightly better code,
but is more useful in that it improves consistency.



Swift SVN r11816
2014-01-02 17:59:04 +00:00
Joe Groff
8bebb084e6 Rename 'RequirementKind::ValueWitnessMarker' to 'WitnessMarker'.
It's witnessing protocol requirements, not values, and "value witness" has a particular meaning in IRGen.

Swift SVN r11814
2014-01-02 17:47:40 +00:00
Doug Gregor
e1d3cbd01d [Clang importer] Synthesize protocol conformances for imported declarations.
This allows us to enable a verifier that ensures that protocol
conformances account for all requirements in the corresponding
protocol.

Swift SVN r11813
2014-01-02 16:04:23 +00:00
Doug Gregor
631b0c361a Don't import the same Objective-C method twice (recursively).
Swift SVN r11812
2014-01-02 16:04:11 +00:00
Chris Lattner
f000a98035 fix a fixme, importing NSOPTIONS methods as non-mutable methods.
Swift SVN r11706
2013-12-28 23:07:25 +00:00
Chris Lattner
d3c91387e9 Substantially simplify the API to LValueType now that nonsettable is gone.
Swift SVN r11703
2013-12-28 22:48:44 +00:00
Jordan Rose
69a51655c7 [ClangImporter] Instance methods on NSObject are also class methods.
More specifically, instance methods on root objects are also class methods,
because the metatype for that class will inherit from the root class.
(That is, NSObject's metatype extends NSObject.)

This is necessary to allow calling, say, -respondsToSelector: on a class.
Unfortunately, it also brings in every other method on NSObject, including
"informal protocol" category methods like -awakeFromNib. We should probably
disprefer these in code completion, especially if they're declared in another
module, but it is perfectly legal to call these methods on Class objects in
Objective-C.

<rdar://problem/13371711>

Swift SVN r11614
2013-12-24 01:34:07 +00:00
Argyrios Kyrtzidis
a4ed3e19d0 [ClangImporter] When creating the member declarations for NS_ENUM/NS_OPTIONS, also associate the
clang declaration that they came from.

rdar://15574386

Swift SVN r11543
2013-12-21 17:40:31 +00:00
Argyrios Kyrtzidis
3882ab6bd4 [ClangImporter] When checking for NS_ENUM/NS_OPTIONS enums, use clang::Preprocessor::getImmediateMacroName()
and check for CF_ENUM/CF_OPTIONS, which NS_ENUM/NS_OPTIONS expand to.

This:
- Simplifies code
- Handles CF_ENUM/CF_OPTIONS enums
- Handles correctly an NS_ENUM/NS_OPTIONS enum that was itself expanded from another macro.

Swift SVN r11542
2013-12-21 17:40:28 +00:00
Doug Gregor
be3463f32d Store a file-level DeclContext* in protocol conformances rather than a module.
We'll need to perform name lookup based on the file-level
DeclContext*, so the module no longer suffices. No functionality
change here yet.


Swift SVN r11523
2013-12-20 22:53:21 +00:00
Chris Lattner
b29748a6be remove the ASTContext argument from Type::transform,
(various) FunctionType::get's, ArrayType::get,
ArraySliceType::get, OptionalType::get, and a few
other places.

There is more to be done here, but this is all I plan to do
for now.


Swift SVN r11497
2013-12-20 02:23:21 +00:00
Chris Lattner
1472e4d914 Remove the ASTContext argument from LValueType::get(). It is already
only two loads away from the type argument passed in.



Swift SVN r11496
2013-12-20 01:28:50 +00:00
Doug Gregor
b9696e1c01 Create protocol conformances and then, separately, fill in the witnesses.
This is a structural baby step toward lazily filling in protocol
conformances. We always build a ProtocolConformance, then mark it
either "complete" (when it's well-formed) or "invalid" (when it's
ill-formed). At present, the only benefit to this is that it slows
diagnostic cascades from invalid conformances.


Swift SVN r11492
2013-12-20 00:29:00 +00:00
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