Commit Graph

889 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
Dmitri Hrybenko
54a39dfeb8 Allow type checking qualified references to generic nominals with free type
variables

This change allows the type checker to create member references to generic
nominals with free type variables -- see tests.  This is important for code
completion, for example, swift.Dictionary.#^A^#

Fixes rdar://15980316


Swift SVN r14461
2014-02-27 14:40:28 +00:00
Chris Lattner
1344319677 Rename the internal compiler lexicon from val -> let.
Swift SVN r14408
2014-02-26 21:21:18 +00:00
Doug Gregor
981f8f6509 Rename "destructor" -> "deinit" (as a keyword) and -> "deinitializer" (in diagnostics).
Swift SVN r14380
2014-02-26 05:51:45 +00:00
Chris Lattner
b2b15d2d88 Fix <rdar://problem/16151899> init method shouldn't directly access superclasses ivars
Swift SVN r14336
2014-02-25 07:08:54 +00:00
Chris Lattner
7f4c0b981c rename the StoredObjC storage class to StoredWithTrivialAccessors since
we'll be using it for more general things soon.  NFC.


Swift SVN r14329
2014-02-25 01:08:27 +00:00
Joe Pamer
f83f94d9d8 Support build and target configurations
These changes add support for build and target configurations in the compiler.
Build and target configurations, combined with the use of #if/#else/#endif allow
for conditional compilation within declaration and statement contexts.

Build configurations can be passed into the compiler via the new '-D' flag, or
set within the LangOptions class. Target configurations are implicit, and
currently only "os" and "arch" are supported.

Swift SVN r14305
2014-02-24 18:16:48 +00:00
Doug Gregor
b5af687b6d Emit and use vtable entries for abstract initializers.
Emit vtable entries for abstract initializers. When we're constructing
an object using an abstract initializer based on a metatype value that
is not statically derivable, use the vtable entry to call the
subclass's allocating constructor.

Most of the IRGen work here is hacking around the lossy SILDeclRef ->
(Code|Function)Ref -> SILDeclRef conversion. I'd feel bad about this
if John hadn't already agreed to clean this up at some point.



Swift SVN r14238
2014-02-21 23:15:46 +00:00
Doug Gregor
0da11a8b0b Implement semantic analysis for abstract initializers.
Swift SVN r14221
2014-02-21 19:41:14 +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
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
Chris Lattner
9ee7d99a46 switch a few things off of argument patterns, onto body patterns.
Swift SVN r13891
2014-02-14 01:33:14 +00:00
Chris Lattner
3f7d3877a4 Re-commit r13836 with more correctness this time:
Sink the getObjCGetterSelector/Setter methods from VarDecl/SubscriptDecl down to
AbstractStorageDecl.  NFC.



Swift SVN r13842
2014-02-12 22:49:47 +00:00
Mark Lacey
525c9323cc Revert "since the getObjCGetterSelector/Setter methods from VarDecl/SubscriptDecl down"
This reverts commit r13836, since it broke the build.

Swift SVN r13839
2014-02-12 20:59:24 +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
Chris Lattner
c23185d9ba since the getObjCGetterSelector/Setter methods from VarDecl/SubscriptDecl down
to AbstractStorageDecl, NFC.


Swift SVN r13836
2014-02-12 19:16:40 +00:00
Joe Groff
e880da0b71 AST: Add canonical generic signatures.
For better type safety in SILFunctionTypes, which always want canonical types, and to provide a unique place to hang information common to all equivalent generic signatures, give GenericSignatures a concept of being "canonical".

Swift SVN r13794
2014-02-12 00:32:02 +00:00
Chris Lattner
ba0f502a02 Implement <rdar://problem/16034296> observing properties should not be mutable in their willset method
Swift SVN r13783
2014-02-11 07:09:08 +00:00
Chris Lattner
b56d46b8c9 Teach sema that uses of local observing properties are direct when in
the accessors.  This completes:
<rdar://problem/15922884> support non-member observing properties



Swift SVN r13782
2014-02-11 06:57:41 +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
Chris Lattner
ce9d97c2b9 similar to the previous patch, have all NominalTypeDecls auto-reparent
all of their generic parameters.  This simplifies logic creating them,
allowing us to eliminate all setDeclContext() calls from the parser.

While we're at it, change Parser::addVarsToScope to be a static 
function in ParseStmt.cpp and dramatically cut it down since none of
its remaining clients are using most of its capabilities.  It needs
to be simplified even further.


Swift SVN r13702
2014-02-09 07:20:03 +00:00
Chris Lattner
40316dc769 Change FuncDecl/CtorDecl/DTorDecl/ClosureExpr constructors to
automatically reparent VarDecls in their arg/body patterns and
GenericParameters to themselves.  These all have to be created
before the actual context decl is created and then reparented,
so we might as well have the reparenting be done by the decl
itself.  This lets us take out some setDeclContext reparenting
loops from around the parser.  

I'm sure that there are a lot more places they can be removed
from as well.

NFC.


Swift SVN r13701
2014-02-09 07:02:33 +00:00
Joe Groff
05daca8e79 IRGen: Use interface types to implement the PolymorphicConvention.
Refactor the base PolymorphicConvention implementation to work using generic signatures and dependent types instead of GenericParamLists and archetypes, using an ArchetypeBuilder to produce representative archetypes as a convenience when we need to consider all of the requirements attached to a dependent type. In EmitPolymorphicParameters, map the dependent types into context to resolve the archetypes that should be bound in the body of the function.

Swift SVN r13685
2014-02-08 21:04:15 +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
Joe Groff
06b7ca2855 AST: Include "Self" and associated archetypes in AllArchetypes of a GenericParamList.
The need to hide Self from AllArchetypes of a GenericParamList is (almost) defined away by @cc(witness_method); IRGen now knows how to do the right thing for witnesses regardless of their generic signature. Eliminating this special case from the AST allows us to clear up a bunch of ugly hacks that piled up elsewhere to try to accommodate that special case, and makes the prospect of moving IRGen's PolymorphicConvention to interface types more manageable.

We do need an unfortunate hack to suppress emitting associated archetypes of Self when considering an archetype as the polymorphic source for a witness, since we can't actually pass those through the witness CC without breaking ABI compatibility between generic signatures.

Swift SVN r13663
2014-02-07 23:24:51 +00:00
Jordan Rose
532a6e0bd3 [swift2objc] Handle properties.
All properties are considered nonatomic. If a property comes from Objective-C,
the accessor names may be customized, so always print them out in that case.

Swift SVN r13644
2014-02-07 19:31:26 +00:00
Chris Lattner
a2579527e9 rearrange how the get/set decls are synthesized for observing properties. Now the
parser creates the get/set decls, and sema fills them in, instead of having sema 
do all the work.  This makes it easier to update DeclContexts in all cases.


Swift SVN r13597
2014-02-06 21:36:01 +00:00
Chris Lattner
595817bd89 Rename data structures relating to WillSetDidSet properties to call them "Observing"
properties internally to the compiler.  NFC.


Swift SVN r13587
2014-02-06 17:51:45 +00:00
Chris Lattner
827acad533 Various inout improvements:
- purge @inout from comments in the compiler except for places talking about
   the SIL argument convention.
 - change diagnostics to not refer to @inout
 - Change the astprinter to print InoutType without the @, so it doesn't show
   up in diagnostics or in closure argument types in code completion.
 - Implement type parsing support for the new inout syntax (before we just 
   handled patterns).
 - Switch the last couple of uses in the stdlib (in types) to inout.
 - Various testcase updates (more to come).



Swift SVN r13564
2014-02-06 06:22:27 +00:00
Joe Pamer
e06f98cabd Protect against upstream errors when resolving the 'self' type of an initializer method.
When type checking constructors, ensure that any upstream errors in the resolution of the self type are accounted for (rather than assuming that the self type is always well-formed).  Not doing so can be especially problematic within the context of a type extension, since there may not even be a self type to resolve to.

Swift SVN r13506
2014-02-05 21:06:35 +00:00
Sonny Falk
35f7bdff0f Rename local variable startLoc to StartLoc. NFC.
Swift SVN r13438
2014-02-04 18:31:20 +00:00
Sonny Falk
3715f632cf Update the source range for FuncDecl to include the proper start location for type functions, using getStartLoc().
This addresses <rdar://problem/15969165>.

Swift SVN r13435
2014-02-04 18:11:32 +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
Doug Gregor
995d8732f3 The self type behind a DynamicSelf for a protocol is 'Self', not the protocol.
We can now emit witness tables for conformances to protocols
containing DynamicSelf methods.

This temporarily "breaks" uses of DynamicSelf methods on
existentials. We'll come back to that.


Swift SVN r13310
2014-02-02 02:23:40 +00:00
Argyrios Kyrtzidis
48023490de [AST] Move AccessorKind enum to top-level so it can be forward declared.
No functionality change.

Swift SVN r13299
2014-02-01 08:50:15 +00:00
Doug Gregor
fe2ef0e5c6 Fix interface types and type lowering of DynamicSelf so archetypes don't creep in.
Allows us to invoke DynamicSelf methods of generic classes.


Swift SVN r13290
2014-02-01 05:12:39 +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
Doug Gregor
bbf6f57b93 Properly handle type checking of references to DynamicSelf methods in generic classes.
Swift SVN r13154
2014-01-30 18:06:09 +00:00
Doug Gregor
030770a8c2 Make DynamicSelf into its own special type node.
Making DynamicSelf its own special type node makes it easier to opt-in
to the behavior we want rather than opting out of the behavior we
don't want. Some things already work better with this representation,
such as mangling and overriding; others are more broken, such as the
handling of DynamicSelf within generic classes and the lookup of the
DynamicSelf type.


Swift SVN r13141
2014-01-30 05:36:20 +00:00
Doug Gregor
9ccaf820b8 Start making the method overriding rules a bit more sane.
When we type check the signature of a method, determine which method
it overrides (if any) at that time. This ensures that we always have
this information for name lookup (per <rdar://problem/15932845>). 

As part of this, start to make the overriding rules a little more
sane. John has worked out more of the model here, but this patch:
  - Considers an Objective-C method an override of another Objective-C
  method if the selectors match and the type vs. instance-ness of the
  methods match. The method types are checked for consistency
  (subtyping is okay).
  - Diagnoses when a method overrides more than one method from a
  superclass, and
  - Eliminates the "cannot overload method from a superclass"
  diagnostic, which is overly pedantic and oddly limiting.

Note that we lose some amount of checking here. Specifically, we don't
have a good place to check that one has not provided two different
methods that override the same superclass method. The older code did
that (somewhat), and it's not a trivial problem to solve efficiently.

This fixes the part of <rdar://problem/15597226> that is needed for
<rdar://problem/15932845>. It still doesn't handle properties,
subscripts, and undoubtedly other issues.



Swift SVN r13108
2014-01-29 11:08:56 +00:00
Chris Lattner
38c7decf66 fix <rdar://problem/15933538> let decl rejected in @objc class
When a let decl is in an @objc class, it is converted to StoredObjC
storage.  However, since it is not mutable, it should only have a getter
synthesized for it, not a setter.


Swift SVN r13096
2014-01-29 06:39:30 +00:00
Chris Lattner
a571d5800e Change the storage of a property to WillSetDidSet before touching
its willset/didset pieces, to avoid tripping assertions.


Swift SVN r13018
2014-01-28 00:05:24 +00:00
Chris Lattner
e668e86cc3 With many prerequisites out of the way, lets start actually working on didset/willset
properties.  This step provides AST support to model them.


Swift SVN r13011
2014-01-27 22:11:16 +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
Chris Lattner
170cf3fc8c Change computeInterfaceSelfType to abort if called on a function in a non-type context,
fix the two places that this broke.



Swift SVN r12986
2014-01-27 06:55:01 +00:00
Chris Lattner
9369d518ae merge all the common code between AFD::computeSelfType/computeInterfaceSelfType
into their implementation function.


Swift SVN r12985
2014-01-27 06:45:14 +00:00
Chris Lattner
0a88809fb6 now that there is only one caller of getSelfTypeInContext and
getInterfaceSelfType, inline them into their caller.  This
has the nice effect of moving getSelfTypeForContainer into
Decl.cpp instead of being in DeclContext.cpp (which never
made sense to me).


Swift SVN r12984
2014-01-27 06:32:21 +00:00
Chris Lattner
a945271aa8 Now that properties in protocols are always computed, and that StoredObjC
properties have accessors, we have an amazing property: everything that we
want to form a getter or setter for ... really has one! I suspect many things
can be simplified now, but the first on the chopping block is 
StorageDecl::getGetterType (and its three friends) which is now always exactly
just getGetter()->getType().



Swift SVN r12983
2014-01-27 06:17:28 +00:00