Commit Graph

27 Commits

Author SHA1 Message Date
Jordan Rose
cee28189a2 Add a BodyKind for implicitly-synthesized memberwise initializers.
...rather than just assuming any initializer without a body that makes it
to SILGen is a memberwise initializer.

In the long term we want SILGen to stop handling these initializers, at
which point we can see if it makes sense to remove this body kind.

No intended functionality change.

Swift SVN r25723
2015-03-03 23:22:21 +00:00
Jordan Rose
511f19c6de Mark inherited required initializers as required.
rdar://problem/19793782 (and its dups)

Swift SVN r25704
2015-03-03 03:28:40 +00:00
Jordan Rose
1d03915dfc Make sure static vars in protocols don't get mutating setters.
Static members are never mutating, and having them be mutating in protocols
resulted in requirement mismatches.

rdar://problem/19887250

Swift SVN r25593
2015-02-27 04:54:01 +00:00
Xi Ge
7f668e7b49 Add isUserAccessible() in Decl to show whether swift users should know such decl exists. For instance, a.storage for lazy var a is a inaccessible decl. An implicit decl is not necessarily inaccessible, for instance, self.
Fixing rdar://18760063

Swift SVN r25556
2015-02-26 19:16:54 +00:00
Chris Lattner
accfcaa80f revert r25545, a different approach will be needed.
Swift SVN r25554
2015-02-26 18:18:30 +00:00
Chris Lattner
60e9b9dbbb Revert r25551, more investigation is required.
Swift SVN r25552
2015-02-26 18:04:08 +00:00
Chris Lattner
5cfc38f13d there is no need to validate stored properties when synthesizing a memberwise
initializer, it has already been done now.


Swift SVN r25551
2015-02-26 17:50:51 +00:00
Chris Lattner
c74848cf30 Rework how synthesis of initializers is performed. Before, we would do it before
type checking any of the members of the type being analyzed, which leads to the
really exciting task of generating (e.g.) a memberwise initializer when you don't
know what the types of the members are.

Instead, synthesize these after the members are checked, which makes the code flow
much more like the other code synthesis stuff we do, and paves the way for future
improvements. NFC except one diagnostic in an error case (due to an order-of-checking 
change).

This resolves <rdar://problem/16921173> implicit constructor synthesization works without validating the members of the type


Swift SVN r25545
2015-02-26 07:10:17 +00:00
Chris Lattner
56bf85cc5f fix <rdar://problem/19874152> Swift 1.2 struct memberwise initializer violates new sanctity of previously set let property
If a non-static 'let' field in a struct has an initializer, its implicitly generated
memberwise initializer should not override that.  Handle this by having the memberwise initializer
and default initializer use the initial value of the property instead of an argument to the init.

This would have been a lot easier if sema was synthesizing the ctor bodies instead of SILGen,
but here it is.  The missing case is narrow (let (x,y) = (1,2)) and for now we just disable
implicit synthesization of the incorrect case.



Swift SVN r25424
2015-02-20 07:26:57 +00:00
David Farler
a079cbc49a Generate trivial accessors for static stored properties in objc classes
Expose static stored properties in @objc classes as trivial class
methods.

static let i: T => +(T)i
static var i: T => +(T)i and +(void)setI:
static var k T { get set } => No change.

Fixes rdar://problem/19784053

Swift SVN r25152
2015-02-11 00:44:59 +00:00
Joe Groff
b0fabcef7b Sema: Force dynamic materializeForSet accessors to be statically dispatched.
The materializeForSet accessor for a `dynamic` property needs to dynamically invoke the getter and setter of the property in order to allow for runtime modification, so it doesn't need to be dynamically dispatched itself. If the property came from an imported ObjC class, then we can't dynamically dispatch it without polluting the selector namespace. Introduce a new 'ForcedStaticDispatch' bit and set it in order to force `dynamic` materializeForSet accessors to be statically dispatched. (They can't be `final` because it's legal to override a dynamic property.) If the property came from ObjC, register materializeForSet as an external declaration so it gets generated by SIL. Fixes rdar://problem/18706056.

Swift SVN r24930
2015-02-04 00:46:24 +00:00
Joe Groff
c1db47ed13 Sema: Synthesize materializeForSet with dynamically-dispatched accessors for dynamic properties.
Semantically, a dynamic property must always be dispatched in case it gets replaced at runtime, and an @NSManaged property may not have static accessors at all. Use ordinary access to the computed property accessors in materializeForSet when a property is dynamic or ObjC-originated. More rdar://problem/18706056.

There's still a problem--we try to vtable-dispatch materializeForSet, which is redundant for native classes, but impossible for imported ObjC classes. We should suppress this, but trying to make materializeForSet "final" breaks subclassing if the property is overridden.

This time, update test/SILGen/objc_properties.swift to avoid a false negative test failure.

Swift SVN r24888
2015-02-01 20:24:57 +00:00
Dmitri Hrybenko
2037fe0059 Revert "Sema: Synthesize materializeForSet with dynamically-dispatched accessors for dynamic properties."
This reverts commit r24882.  It broke SILGen/objc_properties.swift.

Swift SVN r24883
2015-02-01 03:17:49 +00:00
Joe Groff
456288fb6f Sema: Synthesize materializeForSet with dynamically-dispatched accessors for dynamic properties.
Semantically, a dynamic property must always be dispatched in case it gets replaced at runtime, and an @NSManaged property may not have static accessors at all. Use ordinary access to the computed property accessors in materializeForSet when a property is dynamic or ObjC-originated. More rdar://problem/18706056.

There's still a problem--we try to vtable-dispatch materializeForSet, which is redundant for native classes, but impossible for imported ObjC classes. We should suppress this, but trying to make materializeForSet "final" breaks subclassing if the property is overridden.

Swift SVN r24882
2015-02-01 02:09:27 +00:00
Joe Groff
0225fa568a Sema: Don't synth "materializeForSet" for @objc protocol requirements.
Another fix for rdar://problem/18706056. This should make @NSManaged properties work fine with @objc protocols, but I expect us to still be broken with native protocols.

Swift SVN r24862
2015-01-30 23:41:10 +00:00
Joe Groff
06fb3bdf8d Sema: Don't synth materializeForSet accessors on behalf of get-only property requirements.
One of several inefficiencies in the area exposed by rdar://problem/18706056.

Swift SVN r24858
2015-01-30 23:13:18 +00:00
Doug Gregor
b642c555be Allow one to change the argument labels of curried function parameters.
Curried function parameters (i.e., those past the first written
parameter list) default to having argument labels (which they always
have), but any attempt to change or remove the argument labels would
fail. Use the fact that we keep both the argument labels and the
parameter names in patterns to generalize our handling of argument
labels to address this problem.

The IDE changes are due to some positive fallout from this change: we
were using the body parameters as labels in code completions for
subscript operations, which was annoying and wrong.

Fixes rdar://problem/17237268.

Swift SVN r24525
2015-01-19 22:15:14 +00:00
John McCall
cae0f6e3db Add the ability for a owning addressor to return
a non-native owner.  This is required by Slice, which
will use an ObjC immutable array object as the owner
as long as all the elements are contiguous.

As part of this, I decided it was best to encode the
native requirement in the accessor names.  This makes
some of these accessors really long; we can revisit this
if we productize this feature.

Note that pinning addressors still require a native
owner, since pinning as a feature is specific to swift
refcounting.

Swift SVN r24420
2015-01-14 19:14:20 +00:00
John McCall
6a46350546 Bugfixes for the new addressor kinds.
Permit non-Ordinary accesses on references to functions,
with the semantics of devirtualizing the call if the
function is a class member.  This is important for
constructing direct call to addressors from synthesized
materializeForSet accessors: for one, it's more
performant, and for another, addressors do not currently
appear in v-tables.

Synthesize trivial accessors for addressed class members.
We weren't doing this at all before, and I'm still not
sure we're doing it right in all cases.  This is a mess.

Assorted other fixes.  The new addressor kinds seem
to work now.

Swift SVN r24393
2015-01-13 10:37:22 +00:00
John McCall
dc4431ebff Split addressors into unsafe, owning, and pinning variants.
Change all the existing addressors to the unsafe variant.

Update the addressor mangling to include the variant.

The addressor and mutable-addressor may be any of the
variants, independent of the choice for the other.

SILGen and code synthesis for the new variants is still
untested.

Swift SVN r24387
2015-01-13 03:09:16 +00:00
John McCall
f3dc58667d Improve the typing of materializeForSet callbacks to
use a thin function type.

We still need thin-function-to-RawPointer conversions
for generic code, but that's fixable with some sort of
partial_apply_thin_recoverable instruction.

Swift SVN r24364
2015-01-11 21:13:35 +00:00
Chris Willmore
03a6190a1f <rdar://problem/19031957> Change failable casts from "as" to "as!"
Previously the "as" keyword could either represent coercion or or forced
downcasting. This change separates the two notions. "as" now only means
type conversion, while the new "as!" operator is used to perform forced
downcasting. If a program uses "as" where "as!" is called for, we emit a
diagnostic and fixit.

Internally, this change removes the UnresolvedCheckedCastExpr class, in
favor of directly instantiating CoerceExpr when parsing the "as"
operator, and ForcedCheckedCastExpr when parsing the "as!" operator.

Swift SVN r24253
2015-01-08 00:33:59 +00:00
Chris Lattner
763bb6386f Implement parser, AST representation, type checker, etc support for generalized
if-let statements (also while and var, of course) that include multiple bindings
and where clauses.

SILGen support still remains, it currently just asserts on the new constructs.



Swift SVN r24239
2015-01-07 07:03:02 +00:00
Nadav Rotem
636c6bdf2b Use =default for the default destructor.
Swift SVN r24228
2015-01-06 23:27:36 +00:00
Nadav Rotem
efd3495f60 Add a virtual dtor to silence a warning.
Swift SVN r24217
2015-01-06 22:02:57 +00:00
John McCall
44eec49842 Change the signature of materializeForSet to return an
optional callback; retrofit existing implementations.

There's a lot of unpleasant traffic in raw pointers here
which I'm going to try to clean up.

Swift SVN r24123
2014-12-23 22:14:38 +00:00
John McCall
94e5d98ff7 Move 1700 lines of AST-synthesis code out of TypeCheckDecl.cpp.
It's only 6500 lines now!  So much better.

Swift SVN r23994
2014-12-17 23:42:36 +00:00