Commit Graph

3502 Commits

Author SHA1 Message Date
Doug Gregor
e12afa2e1d Start naming functions more uniformly.
For any function that has a name, ensure that the name is a compound
name with argument names for each of the parameters. 


Swift SVN r16398
2014-04-16 06:05:45 +00:00
Joe Groff
69a1f91ded AST: Fix a typo that caused all generic struct property accesses to be computed.
Two little characters cause array complexity to jump from O(n) to O(n^2)! Fixes <rdar://problem/16629598>.

Swift SVN r16392
2014-04-16 03:31:01 +00:00
Doug Gregor
7c961a501f Migrate off a few more ArgParamPatterns
Swift SVN r16391
2014-04-16 03:22:47 +00:00
Chris Lattner
ca7ed40cf0 change Sema to synthesize getters and setters for properties in classes,
even if they are @final.  To get good performance for them, just always
perform direct access to the underlying storage, instead of going through
the accessors.

This allows them to properly fulfill protocol witnesses without overhead,
allows the objc runtime to find them properly, and is just a cleaner way
to go.


Swift SVN r16357
2014-04-15 04:43:36 +00:00
John McCall
f70879c4d9 Fix a weirdly complicated issue with the order of
type-checking and applying attributes.

We should really move to a model where variables are
type-checked in a single pass, including their attributes.
However, given that we don't, attributes which affect the
type must be applied in multiple places and hence multiple
times to the same declaration.

Swift SVN r16339
2014-04-14 22:54:30 +00:00
Doug Gregor
53b84c121e Switch ValueDecl::getObjCSelector() and friends over to ObjCSelector.
Formatting names into strings repeatedly, and using those for semantic
analysis, is generally considered poor form. Additionally, use the
camelCase utilities to perform the string manipulation we need, and
cache results on the ObjCAttr so we don't repeatedly do string
manipulation.

Swift SVN r16334
2014-04-14 22:02:51 +00:00
Doug Gregor
cd4ca76b6a Introduce the ObjCSelector class to store an Objective-C selector.
We have to work with selectors quite often, so provide an efficient
representation for them. Switch ObjCAttr over to this representation,
which has the nice property that it efficiently represents implicit
@objc attributes with names and allows us to overwrite the Objective-C
name without losing all source information. Addresses
<rdar://problem/16478678>, and sets us up for dealing with selectors
better.

Swift SVN r16327
2014-04-14 20:05:35 +00:00
Chris Lattner
6e90d343be At long last, land the implementation of <rdar://problem/16397000> Should be able to override stored properties
This means that we now synthesize getters and setters a lot more than we used to, so the
implementation work on this shook out a ton of bugs with them.

There is still one failure that I don't understand at all (test/stdlib/NewArray.swift.gyb), 
nor do I understand how to diagnose the problem, so I XFAILed it and filed rdar://16604980 to
track fixing it.



Swift SVN r16299
2014-04-14 04:48:54 +00:00
Argyrios Kyrtzidis
31a620f1ee [IDE/ModuleInterface] Fix erroneously printed newline between a regular comment and the declaration it is 'attached' to.
Swift SVN r16293
2014-04-14 03:28:05 +00:00
Doug Gregor
2d28d70bf8 Remove the language/driver/frontend options to enable/disable mangled names for the ObjC runtime.
Burn the bridges!


Swift SVN r16277
2014-04-13 05:36:08 +00:00
Joe Groff
42a942925b Enable block bridging.
Swift SVN r16248
2014-04-12 05:13:45 +00:00
Joe Groff
ef4afbcffa Allow function-type properties to use ObjC dispatch.
Now they can bridge to blocks.

Swift SVN r16246
2014-04-12 05:13:37 +00:00
John McCall
8a85750c4c Plumb a lot of querying for different kinds of existential
type.

Swift SVN r16232
2014-04-11 22:30:14 +00:00
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