Commit Graph

889 Commits

Author SHA1 Message Date
Doug Gregor
825e5be3d2 Default-initialize optional variables/properties to 'nil'.
Addresses <rdar://problem/16342813>.


Swift SVN r16222
2014-04-11 17:59:14 +00:00
Dmitri Hrybenko
6a24e5475e Remove a separate bit for @objc inference, and use normal implicit attributes
This allows us to get rid of /* @objc(inferred) */ completely.


Swift SVN r16215
2014-04-11 14:34:28 +00:00
Doug Gregor
fa6ae94e0e Re-organize the checking of @IBOutlet to better handle implicit optionalification.
Swift SVN r16201
2014-04-11 06:09:03 +00:00
Dmitri Hrybenko
110f85bc16 Move @exported to use new attribute infrastructure
Swift SVN r16158
2014-04-10 13:35:35 +00:00
Dmitri Hrybenko
f90e0c153b Make 'override' a keyword
rdar://16462192

Swift SVN r16115
2014-04-09 14:19:50 +00:00
Joe Groff
8adaab0233 Fold ExtInfo::isThin and ::isBlock into a "Representation" enum.
These bits are orthogonal to each other, so combine them into one, and diagnose attempts to produce a type that's both. Spot-fix a bunch of places this revealed by inspection that we would have crashed in SILGen or IRGen if blocks were be handled.

Swift SVN r16088
2014-04-09 00:37:26 +00:00
Doug Gregor
e160f9049c Don't poke at Objective-C ASTs for designated initializers: the importer handles this.
Swift SVN r16011
2014-04-07 14:07:28 +00:00
Dmitri Hrybenko
9a15e6bddd Attributes: hasAttribute() / getAttribute() returns only valid attributes by
default


Swift SVN r16008
2014-04-07 12:06:09 +00:00
Dmitri Hrybenko
fb2a6499cd Move @class_protocol to use the new attribute infrastructure
... and fix a few other bugs:

* always set the inherited protocols on the ProtocolDecl in the type checker,
  so that we can remove a hack in ProtocolDecl::requiresClassSlow();

* diagnose DeclAttributes that are inverted when this is not allowed.


Swift SVN r15992
2014-04-06 01:24:08 +00:00
Dmitri Hrybenko
a272ac75aa Add a change I forgot to add in the previous commit
Swift SVN r15939
2014-04-04 15:26:17 +00:00
Doug Gregor
26c4620b35 Introduce a "descriptive declaration kind" for use in diagnostics, etc.
Provide a fine-grained classification of declarations that can be used
in diagnostics instead of ad hoc %select operations. For now, only cut
over the "overriding a final <whatever>" diagnostic.


Swift SVN r15932
2014-04-04 06:35:42 +00:00
Doug Gregor
604ad33d06 Handle getter/setter overriding more cleanly.
Use recordOverride() for getter and setter overriding. This means that
@objc names get propagated correctly, so we can stop chasing overrides
to find @objc names.



Swift SVN r15928
2014-04-04 05:27:50 +00:00
Doug Gregor
4bcc4daa3d Selector splitting: the first parameter name is always relevant.
Swift SVN r15923
2014-04-04 04:14:34 +00:00
Jordan Rose
aa6aa72ba1 Add lazy conformances to nominals and extensions.
...and deserialize conformances lazily.

No intended user-visible change.

Swift SVN r15911
2014-04-04 01:17:54 +00:00
Doug Gregor
527b147ba7 Revert "Allow the first name of a selector-style function declaration to be separated."
This reverts r15140.

Conflicts:
	include/swift/Serialization/ModuleFormat.h
	lib/Parse/ParsePattern.cpp

Swift SVN r15846
2014-04-02 23:27:52 +00:00
Jordan Rose
107eeefd77 Allow AbstractFunctionDecls to have their bodies "synthesized" on demand.
...then use this functionality for derived conformances for RawRepresentable.

No functionality change because these bodies are always forced right now.

Swift SVN r15828
2014-04-02 21:00:42 +00:00
Argyrios Kyrtzidis
41dbe5384b [AST] Add ClangNode::getLocation(), that returns the clang SourceLocation.
Swift SVN r15808
2014-04-02 17:39:08 +00:00
John McCall
f1180f5e6d in order to work correctly for non-@objc protocols.
Language features like erasing concrete metatype
values are also left for the future.  Still, baby steps.

The singleton ordinary metatype for existential types
is still potentially useful; we allow it to be written
as P.Protocol.

I've been somewhat cavalier in making code accept
AnyMetatypeType instead of a more specific type, and
it's likely that a number of these places can and
should be more restrictive.
When T is an existential type, parse T.Type as an
ExistentialMetatypeType instead of a MetatypeType.

An existential metatype is the formal type
 \exists t:P . (t.Type)
whereas the ordinary metatype is the formal type
 (\exists t:P . t).Type
which is singleton.  Our inability to express that
difference was leading to an ever-increasing cascade
of hacks where information is shadily passed behind
the scenes in order to make various operations with
static members of protocols work correctly.

This patch takes the first step towards fixing that
by splitting out existential metatypes and giving
them a pointer representation.  Eventually, we will
need them to be able to carry protocol witness tables

Swift SVN r15716
2014-04-01 00:38:28 +00:00
Doug Gregor
4f9f945d62 Teach the Clang importer to add @objc(selector) attributes for imported methods and initializers.
With this in place, remove the hacks that peeked at the imported Clang
node to determine the selector for a method. We're all
attribute-driven now. Part of <rdar://problem/16019773>.


Swift SVN r15663
2014-03-31 04:26:32 +00:00
Doug Gregor
f2578cb605 Use a named @objc to provide the name for methods, initializers, getters, and setters.
This is all of the functionality of <rdar://problem/16019773>, but
some cleanup remains.


Swift SVN r15641
2014-03-30 03:59:01 +00:00
Doug Gregor
d51744e396 Clang importer: add @objc(name) attributes to imported classes and protocols.
Now that we represent the Objective-C runtime names of classes and
protocols in a uniform way, stop peeking into the Clang AST nodes to
get this information for imported classes and protocols. This is
better layering and helps test that new code path.


Swift SVN r15632
2014-03-29 21:15:29 +00:00
Doug Gregor
a0e384f517 A named 'objc' attribute on a class or attribute provides the Objective-C runtime name.
Replace the use of 'asmname' for the runtime name of a class or
protocol with 'objc'. Use it for SwiftObject to eliminate a hack.


Swift SVN r15631
2014-03-29 20:53:17 +00:00
Doug Gregor
1e33daddf9 Allow @asmname on classes and protocols,
This will allow a Swift-defined class to put itself in the global
namespace, for example, to replace a previously Objective-C-defined
class. Part of <rdar://problem/15506580>.



Swift SVN r15590
2014-03-28 23:39:10 +00:00
Doug Gregor
9400e890d3 Emit @objc classes using namespaced names under a new flag -enable-objc-mangling.
Centralize the logic for figuring out what name to use for a class or
protocol in the Objective-C runtime. When the flag is enabled (it's
still disabled by default), use mangled names for all Swift-defined
classes, including those that are @objc. Note that the naming is
determined in the AST, because we're also going to use this logic when
printing an Objective-C header for Clang's consumption. The mangled
names will always start with _Tt, so they're easy to recognize and
demangle in various tools or, eventually, in the Objective-C runtime.

The new test (test/IRGen/objc_mangling.sil) is the only test of this
behavior at the moment. The other test changes are due to the
centralized logic tweaking the names of internal constants (_DATA_*,
_CATEGORY_*, etc.).

This is the majority of <rdar://problem/15506580>.



Swift SVN r15588
2014-03-28 23:00:08 +00:00
Doug Gregor
1cdd295182 Move the @objc attribute over to a DeclAttribute.
Swift SVN r15517
2014-03-26 19:33:07 +00:00
Chris Lattner
0ea5a37fc1 rework PatternBindingDecl::hasStorage() to be a dynamic query of the vardecls it
contains, instead of being a stored bit set up by the parser.  Observed properties
have storage... unless they are overriding, and this avoids having to maintain
this bit.

This fixes:
<rdar://problem/16382967> Overriding observing properties have no storage, so shouldn't prevent initializer synth



Swift SVN r15301
2014-03-20 22:43:16 +00:00
Doug Gregor
5e8e7279f8 Allow the first name of a selector-style function declaration to be separated.
Parse function declarations with the form

  func murder inRoom(room: Int) weapon(Int) {}

where the function name ("murder") is separated from the parameter
names. This is the same style used in initializers, i.e.,

  init withCString(cstr: CString) encoding(Encoding)



Swift SVN r15140
2014-03-17 16:04:21 +00:00
Doug Gregor
7e7489936e Ignore stub definitions when checking whether a class overrides parent designated initializers.
Thanks, Dmitri!


Swift SVN r15107
2014-03-15 21:37:33 +00:00
Jordan Rose
455e96e955 @objc should be enough to make a protocol a class protocol.
There are very few times where we'd want to use @class_protocol outside of
@objc, and it feels weird to tell someone coming from Objective-C that they
need to mark their already-@objc protocol as @class_protocol. Instead, just
change ProtocolDecl::requiresClass to check for @objc.

(The commit checks for /both/ @objc-the-attribute and the IsObjC flag.
This is to give the right answer before type-checking, or at least the
likely-intended answer.)

<rdar://problem/16302887>

Swift SVN r15060
2014-03-14 17:56:07 +00:00
Doug Gregor
ea7e70bbf7 Automatically inherit subobject initializers when none are explicitly defined.
If a subclass defines no subobject initializers and all of its stored
properties have initial values, "inherit" all of the subobject
initializers of its superclass by creating a new initializer with the
same signature that overrides (and chains to) the corresponding
subobject initializer of its parent. Do this instead of blindly
creating a default initializer.

Note that we aren't yet doing this for generic initializers. That will
be a separate step.

Swift SVN r14995
2014-03-13 18:43:30 +00:00
Manman Ren
b96ddf48d6 SILParser: parsing GenericParamList.
To parse GenericParamList in SILParser, we try to share code with TypeChecker.
We add handleSILGenericParams in Subsystems.h in order for SILParser to call
TypeChecker's handling of GenericParamList (this is motivated by the example of
SILParser calling performTypeLocChecking). handleSILGenericParams calls
checkGenericParamList and finalizeGenericParamList.

A Builder field (ArchetypeBuilder*) is added to GenericParamList so we can add
the same-type requirements to GenericSignature in getAsCanonicalGenericSignature
by checking SameTypeRequirements of the builder.

resolvePotentialArchetypeToType is moved from a static helper function in
TypeCheckGeneric.cpp to a public helper function in ArchetypeBuilder.cpp.
When constructing the same-type requirements in getAsCanonicalGenericSignature,
we will call it to convert from PotentialArchetype to a dependent type.

rdar://16238241


Swift SVN r14922
2014-03-11 18:01:01 +00:00
Doug Gregor
00162dc243 Start emitting stubs for unimplemented designated initializers of the superclass.
When a subclass does not implement a designated initializer of its
superclass, introduce a stub initializer that simply traps. Such stubs
cannot be invoked directly using Swift syntax, but can be invoked
through the Objective-C runtime and from Objective-C code. Catch such
errors rather than allowing them to violate the memory safety of the
language.

Note that we're currently using cond_fail to trap; this will be
improved in the future,


Swift SVN r14839
2014-03-09 07:16:30 +00:00
Joe Groff
9f12e2e4a4 Enable same-type concrete constraints, e.g. <T: P where T.Assoc == Int>
Let ArchetypeType nested types and PotentialArchetypes be bound to concrete types in addition to archetypes. Constraints to outer context archetypes still suffer type-checker issues, but constraints to true concrete types should work now.

Swift SVN r14832
2014-03-08 17:18:17 +00:00
Jordan Rose
b9d1e14dd6 [serialization] Break a cyclic dependency involving associated types.
The standard library likes to have default definitions for associated types,
which is good. Often the /choice/ of default type, however, is a type that
(indirectly) conforms to the very protocol containing the associated type.
Rather than try to make sure everything is present all at once, just delay
the deserialization of the default definition until it's actually requested.

This does swell the size of AssociatedTypeDecl by two words. I've filed
<rdar://problem/16266669> to remind myself to try to reduce this.

Part of <rdar://problem/16257259>

Swift SVN r14809
2014-03-08 00:07:29 +00:00
Joe Groff
c2339cd091 AST: Unique compound names in the ASTContext.
Add a folding set for CompoundDeclNames so that identical names can be compared by pointer equality.

Swift SVN r14753
2014-03-06 21:10:28 +00:00
Joe Groff
70f4f1db8d SILGen: Allow @objc_block properties to be @objc-dispatched.
Our guard against dispatching function properties should only apply to @objc_blocks. Fixes <rdar://problem/16223478>.

Swift SVN r14741
2014-03-06 18:35:39 +00:00
Joe Groff
db1a304340 @objc protocol compositions are valid object types for @objc subscripts.
Swift SVN r14740
2014-03-06 18:06:45 +00:00
John McCall
69855ba446 Extract a method to generate the all-archetypes list
of a set of generic parameters, and use it to verify
that the stored list matches what we expect.

Swift SVN r14693
2014-03-05 22:41:25 +00:00
Chris Lattner
7bbd9b05a5 Rename DynamicLookup -> AnyObject in a few more comments. This leaves
the DynamicLookupExpr expression and the DeclVisibilityKind::DynamicLookup
enum.  These seem right to me, more descriptive than renaming them AnyObject.
With this, I consider 13327098 to be done.



Swift SVN r14654
2014-03-04 22:17:38 +00:00
Chris Lattner
d758e0dfe3 Eliminate more "DynamicLookup" in favor of "AnyObject", this is the
bulk of finishing rdar://13327098.


Swift SVN r14653
2014-03-04 22:15:46 +00:00
Doug Gregor
15be2159a2 Rename "abstract initializers" to "required initializers".
It's better than what we have.

Swift SVN r14620
2014-03-03 23:12:40 +00:00
Doug Gregor
2c26523201 Require chaining to the superclass initializer to refer to a subobject initializer.
Swift SVN r14601
2014-03-03 18:47:09 +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
Doug Gregor
8f64658fc1 Misc. cleanups related to SuperRefExpr queries.
Swift SVN r14558
2014-03-01 18:54:34 +00:00
Joe Groff
179b101e6f Serialization: Serialize compound names of FuncDecls.
Store the name components as a BCArray, and push the asmname BCBlob into an optional trailing record layout.

Swift SVN r14556
2014-03-01 04:10:33 +00:00
Joe Groff
3226bae79b Add missing early return, and simplify initialization loop using uninitialized_copy.
Thanks Jordan!

Swift SVN r14555
2014-03-01 04:10:29 +00:00
Doug Gregor
d92f1a3158 Inherit complete object initializers when a class supports it.
Teach name lookup to find complete object initializers in its
superclass when the current class overrides all of the subobject
initializers of its direct superclass.

Clean up the implicit declaration of constructors, so we don't rely on
callers in the type checker doing the right thing.

When we refer to a constructor within the type checker, always use the
type through which the constructor was found as the result of
construction, so that we can type-check uses of inherited complete
object initializers. Fixed a problem with the creation of
OpenExistentialExprs when the base object is a metatype.

The changes to the code completion tests are an improvement: we're
generating ExprSpecific completion results when referring to the
superclass initializer with the same signature as the initializer
we're in after "super.".

Swift SVN r14551
2014-03-01 00:51:21 +00:00
Doug Gregor
571ae697d5 Parsing and AST support for complete object initializers.
Enforce that complete object initializers always be delegating.

Swift SVN r14549
2014-03-01 00:51:18 +00:00
Joe Groff
f12f7d3b54 AST: "ValueName" -> "DeclName", and pack it in a single word.
Swift SVN r14541
2014-02-28 23:44:18 +00:00
Joe Groff
ca1b524740 AST: Relax the signature of FuncDecl factories to allow them to be constructed with compound names.
These are the only kinds of decl that will actually have compound names in practice in the short term. Initializers can have selector pieces too, but cannot be referenced outside of a constructor call, so their AST names don't matter.

Swift SVN r14540
2014-02-28 23:44:17 +00:00