Commit Graph

6196 Commits

Author SHA1 Message Date
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
6298c15578 [ClangImporter] Don't verify imported Decls in Release builds, or in the REPL.
The former is an obvious fix; the latter is a speed optimization when using
the Debug REPL. Running the crashing code through -i will get nearly the
same effect with verification turned on.

Swift SVN r14468
2014-02-27 19:28:40 +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
Ted Kremenek
028f9d0561 Remove rest of Makefile build except for 'docs' and 'www'.
For 'docs' and 'www' it is possible these are still being used,
as they work independent of the Makefile build.  Keeping them for now.

Swift SVN r14418
2014-02-26 22:21:25 +00:00
Jordan Rose
cadd6edb9d Move EnableObjCOptional to LangOptions (from ClangImporterOptions).
This is a staging option, and I'm about to use it for type-checker changes.

No functionality change.

Swift SVN r14415
2014-02-26 22:15:53 +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
Joe Groff
98d6fecc99 '.metatype' -> '.Type'
Also, reserve 'type' as a keyword for ensuing syntax changes.

Swift SVN r14375
2014-02-26 04:23:21 +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
Argyrios Kyrtzidis
eeb9589d2c [AST] Introduce "hasName()" convenience methods and replace "getName().empty()" callers.
Swift SVN r14206
2014-02-21 15:00:38 +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
26d93ebb7c [ClangImporter] Use MAP_STDLIB_TYPE for CFIndex (instead of MAP_TYPE).
...now that it allows you to specify what to do with the typealias.

No functionality change.

Swift SVN r14107
2014-02-19 22:41:27 +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
065d7707f7 [ClangImporter] Import anonymous enums as Int rather than CInt.
More precisely, import anonymous enums with no fixed underlying type as Int
if they would have fit in a 32-bit signed integer. If not, we can't be sure
"Int" is a valid type for code that compiles for multiple architectures.

(Currently that means we'll fall back to the C type, which is probably /also/
wrong for multiple architectures. We could try to be smarter here, since we
have the number of required bits, but let's start with just this.)

Also, remove existing code that assumed that any 64-bit underlying type was
compatible with Int, which it definitely isn't any more on 32-bit platforms.

Part of <rdar://problem/15368372>

Swift SVN r14089
2014-02-19 18:29:45 +00:00
Jordan Rose
3e95a9c366 [ClangImporter] Preserve the CFIndex typealias.
NSInteger and NSUInteger are such core Cocoa types that it will be clearly
documented that they're bridged to Int. However, I can easily see someone
trying to use CFIndex and not understanding why it's missing.

At some point we may want a general solution for all the mapped types
("don't use intptr_t directly; use Int"), but for now treat CFIndex
specially.

Swift SVN r14071
2014-02-19 01:30:14 +00:00
Jordan Rose
11e4afaad0 [ClangImporter] Import "CFIndex" as "Int", just like "NSInteger".
<rdar://problem/16102896>

Swift SVN r14070
2014-02-19 01:12:51 +00:00
Jordan Rose
d71cff5d16 [ClangImporter] Don't create typealiases for NSInteger, uint16_t, etc.
Just use the native Swift names for these: Int, UInt16, etc.

<rdar://problem/16067854>

Swift SVN r14069
2014-02-19 01:12:48 +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
Jordan Rose
70f8c198dd Add the standard library as a private import for pure Clang modules.
This is needed for the implicit conformances we synthesize. Remove a
hack from TypeCheckConstraints to find swift.~= now that it's available
using normal lookup.

<rdar://problem/15410928>

Swift SVN r13850
2014-02-12 23:57:43 +00:00
Jordan Rose
7995dde448 Module::getImportedModules can now get public, private, or all imports.
...whereas before the only options were "public" and "all".

No functionality change.

Swift SVN r13849
2014-02-12 23:57:43 +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
Jordan Rose
cbcf17f9bd Stop leaking memory from Module and FileUnit.
Also, disallow creating Modules and FileUnits on the stack. They must always
live as long as the ASTContext.

<rdar://problem/15596964>

Swift SVN r13671
2014-02-08 02:12:57 +00:00
Dmitri Hrybenko
cf1a1b901c Clang importer: add tests for importing some standard C types as word-sized types
Swift SVN r13431
2014-02-04 12:45:17 +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
Jordan Rose
d0d4286d21 Put modules for 32-bit iOS builds in lib/swift/iphone{os,simulator}/32.
This keeps us from having to deal with fat swiftmodules for now.
In the long run we're hoping to solve this problem with build configurations,
so that a single module file can support multiple architectures.
(See <rdar://problem/15056323>)

<rdar://problem/15204953>

Swift SVN r13135
2014-01-30 03:26:50 +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
Joe Groff
333bd8edbd Fixes to sync up with Apple master.
Swift SVN r12979
2014-01-27 01:28:05 +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
Jordan Rose
130ebe4fd4 Revert "Special-case the standard library to always live relative to the compiler."
This reverts r12932; it breaks the iOS simulator build.

Swift SVN r12944
2014-01-24 23:12:24 +00:00