Commit Graph

2448 Commits

Author SHA1 Message Date
Joe Groff
46f77c6181 Sema: Build the AST for inout address conversions.
Add two new AST node types:

- InOutConversionExpr, which represents an '&x' expression that involves inout conversion. This will be a signal to SILGen not to introduce a writeback scope for the nested conversion call.

- LValueToPointerExpr, which represents the primitive '@lvalue T' to 'RawPointer' conversion that produces the argument to the inout conversion.

Build an InOutConversionExpr AST when an inout expression is resolved by a conversion to an BuiltinInOutAddressConvertible type.

Swift SVN r15594
2014-03-29 02:50:25 +00:00
Joe Groff
93f319c706 Sema: Set up constraints for inout conversions.
Set up the disjunction system for '&x' expressions that allows them to type-check either as simple lvalue-to-inout conversions, as before, or as address conversions that go through one of the BuiltinInOut*Convertible protocols. The solution side is not yet implemented.

Swift SVN r15593
2014-03-29 02:50:24 +00:00
John McCall
3c8eb16c71 Rename replaceResultType to replaceCovariantResultType
and make it preserve optionality.

Swift SVN r15570
2014-03-28 05:39:20 +00:00
Joe Pamer
eebe1ebf37 When importing external enum types, delay the creation of implicit members and their associated support functions until after the types are actually referenced.
This significantly reduces the amount of overhead incurred when naively importing large external modules without referencing many of its members, which should directly improve response times in the playground. For example, the repro code attached to rdar://problem/16387393 imports Foundation but references none of its members, and with these changes its total compilation time is almost 2.5x faster.

Swift SVN r15479
2014-03-26 01:06:27 +00:00
Joe Groff
45eadd1d9b Rename AddressOfExpr to InOutExpr.
The "address" is an implementation detail; formally, it turns an lvalue into an inout parameter.

Swift SVN r15458
2014-03-25 16:28:28 +00:00
John McCall
1ed9c46fda Permit ! to do the AnyObject downcast magic through one level of
optional type.

Swift SVN r15306
2014-03-20 23:58:14 +00:00
John McCall
607b326ab5 When type-checking downcasts, just optimistically
assume that we know about all the optional types in play.

This isn't correct for types that can dynamically be
more optional than they appear statically, e.g. archetypes
and existentials, but it's the easiest thing to do,
and there are workarounds.  I filed rdar://16374053
to handle doing the right thing.

Swift SVN r15254
2014-03-20 00:25:00 +00:00
John McCall
53565efe8d Teach the type-checker to bind and capture optional
values when casting to or from optional types.

rdar://16076966

Swift SVN r15211
2014-03-18 22:57:36 +00:00
John McCall
486463a398 Track the depth of a BindOptionalExpr.
Swift SVN r15210
2014-03-18 22:57:34 +00:00
Doug Gregor
8e0edceea8 When opening an existential metatype, the result is an archetype metatype.
No functionaliy change in anything that works. The is AST cleanup in
advance of work on calling initializers on existentials.



Swift SVN r15112
2014-03-16 05:20:36 +00:00
Doug Gregor
d32f668fb2 Introduce "inherited" default arguments and use them for inherited initializers.
Previously, we were cloning the default arguments completely, which
meant code duplication (when inheriting within a module) or simply a
failure (when inheriting across modules). Now, we reference the
default arguments where we inherited them, eliminating the
duplication. Part of <rdar://problem/16318855>.

Swift SVN r15062
2014-03-14 18:31:22 +00:00
John McCall
5531ffde25 Add a conversion from T? to @unchecked T?. This is not
a subtype conversion.

Swift SVN r15026
2014-03-14 04:43:46 +00:00
Chris Lattner
18886e9a44 use the TupleExpr empty-tuple convenience ctor in a few obvious places.
Swift SVN r15021
2014-03-14 00:41:53 +00:00
Joe Groff
d5ef5cbd19 Sema: Don't try to form substitutions for type parameters that were constrained away to concrete types.
Fixes a crash when same-type constraints appear in protocol requirements.

Swift SVN r14904
2014-03-11 02:58:30 +00:00
Doug Gregor
70d0825e48 Use TypeBase::replaceResultType() rather than a hand-rolled version.
Swift SVN r14840
2014-03-09 07:23:19 +00:00
Chris Lattner
536b6e30ae Reapply r14811 and r14813 with fixes to not warn on anonymous closure arguments
and to not warn about switch case matching.  Other fixes to the stdlib were
already committed.


Swift SVN r14831
2014-03-08 07:35:45 +00:00
John McCall
e3f6be8631 Permit @unchecked T? to be coerced to T as a conversion.
Originally, I didn't want this because I felt it made
unchecked-optional too non-local --- it wasn't always
obvious that an assignment might crash because it was
implicitly dropping optionality.  And that's still a
concern!  But I think that overall, if we're prepared
to accept that that danger is inherent in @unchecked T?,
this is a more consistent model: @unchecked T? means
that we don't know enough about the value to say for
certain that nil is a real possibility, so we'll let
you coerce it to the underlying type, and that coercion
just might not be dynamically safe.  No more special
cases for calls and member access (to the user; of
course, to the implementation these are still special cases
because of lookup and overload resolution).

Swift SVN r14796
2014-03-07 21:57:36 +00:00
Joe Groff
1585b625f9 Sema: Wire up compound name lookup to UnresolvedSelectorExpr.
Resolve selector references using compound name lookup, pushing DeclNames a bit deeper through the type-checker and diagnostics as necessary.

Swift SVN r14791
2014-03-07 20:52:30 +00:00
Joe Groff
9e5bc637ae Add __FUNCTION__ as a magic literal identifier.
Add __FUNCTION__ to the repertoire of magic source-location-identifying tokens. Inside a function, it gives the function name; inside a property accessor, it gives the property name; inside special members like 'init', 'subscript', and 'deinit', it gives the keyword name, and at top level, it gives the module name. As a bit of future-proofing, stringify the full DeclName, even though we only ever give declarations simple names currently.

Swift SVN r14710
2014-03-06 01:06:06 +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
John McCall
d6335efd3f Make nil convert to both T? and @unchecked T?.
This was blocked by some type-checker issues:

First, we weren't registering a constraint restriction when
tail-recursing in matchTypes (as opposed to when creating
a disjunction because multiple conversions applied).  Do so,
and move the set of constraint restrictions to the constraint
system in order to make this simpler.  A large amount of similar
solver state is already there, and of course solving the system
already prospectively modifies the constraint graph.

Second, only set up a potential existential conversion when
working with concrete types.  Without this, we would fail to
typecheck conversions to optional protocol types, but not
optional class/struct/whatever types.  It's not clear whether
whether we should ever really be considering conversions when
either of the types is non-concrete.

I believe it was the second fix which removed a need for a !
in the NewArray test case.

Swift SVN r14637
2014-03-04 08:20:04 +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
Chris Lattner
7e3338c427 IRGen can't handle curried Objective-C methods. Instead of crashing on them, emit a nice
error message saying you can't do this.  This resolves:
<rdar://problem/15643576> Shouldn't crash on partial application of objc method



Swift SVN r14588
2014-03-03 07:59:25 +00:00
Chris Lattner
bcbd4311bb reapply Doug's r14562, with a testcase update to go with it, now that DI is more
cooperative about pointless redundant upcasts ;-)


Swift SVN r14583
2014-03-03 05:50:01 +00:00
Chris Lattner
11bedff2f3 the swift.Slice type got removed a long time ago, being replaced with
what is now Swift.Array.  Update various internal stuff to refer to
Array instead of Slice.  NFC.


Swift SVN r14567
2014-03-02 06:21:37 +00:00
Doug Gregor
b9c1785421 Revert r14559; we still need to cannibalize SuperRefExprs for DI.
Swift SVN r14562
2014-03-01 22:36:27 +00:00
Doug Gregor
054e844f70 Stop cannibalizing SuperRefExprs in the type checker.
Swift SVN r14559
2014-03-01 19:07:26 +00:00
Doug Gregor
8f64658fc1 Misc. cleanups related to SuperRefExpr queries.
Swift SVN r14558
2014-03-01 18:54:34 +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
Joe Groff
363a324984 Parse: Start parsing selector member references.
Parse 'x.y:z:' for at least two selector pieces as an UnresolvedSelectorExpr, and declare it unimplemented in Sema.

Swift SVN r14492
2014-02-28 01:47:32 +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
Joe Groff
c0d8ae7c13 Parse 'x.self' as an identity expression.
Factor an IdentityExpr base class out of ParenExpr, and migrate most of the logic to see through ParenExprs to see through IdentityExprs instead. Add DotSelfExpr as a new subclass of IdentityExpr, produced by parsing 'x.self'.

Swift SVN r14381
2014-02-26 06:23:55 +00:00
Joe Pamer
dc42cbac74 When attempting to convert an expression type to a built-in protocol, it is incorrect to assume that the expression will always conform to that protocol. (Or if it doesn't that the protocol is "broken".) In these cases, produce an error type.
Swift SVN r14342
2014-02-25 17:34:26 +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
5eb0a81974 Implement support for <rdar://problem/15912000> Stored property doesn't properly fulfil a protocol property requirement
Swift SVN r14333
2014-02-25 02:08:26 +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
Doug Gregor
61c240c8a8 Allow construction of existential values based on an existential metatype value.
... but obviously not when we've statically derived the existential
metatype. This isn't quite the way I'd like to prohibit these issues,
but more work on existentials and metatypes is coming up shortly.


Swift SVN r14326
2014-02-25 00:32:31 +00:00
Doug Gregor
6a532e05c6 Allow construction of archetype values via archetype metatypes.
Swift SVN r14325
2014-02-25 00:11:24 +00:00
Chris Lattner
3392c4e8ab remove ArchetypeSubscriptExpr, since it is dead now.
Swift SVN r14284
2014-02-23 08:04:51 +00:00
Chris Lattner
d69f91d68e switch Sema to produce SubscriptExpr for archetype subscripts, instead of producing
ArchetypeSubscriptExpr.  This implements support for subscripting archetypes.


Swift SVN r14283
2014-02-23 08:04:10 +00:00
Chris Lattner
30f4b1ba4a remove the unused ArchetypeMemberRefExpr and ExistentialMemberRefExpr nodes.
Swift SVN r14274
2014-02-22 22:09:38 +00:00
Chris Lattner
e6dcae5c4f Change sema to form MemberRefExpr instead of ArchetypeMemberRefExpr. The most
significant impact of this is that it eliminates a bunch of near duplicate logic
in SILGen and makes ArchetypeMemberRefExpr dead.


Swift SVN r14273
2014-02-22 21:59:36 +00:00
Chris Lattner
1bb9d28680 switch all existential member refs to be done with MemberRefExpr, making
ExistentialMemberRefExpr dead.


Swift SVN r14272
2014-02-22 21:24:16 +00:00
Chris Lattner
728a865904 change Sema to form vardecl member references in protocols as MemberRefExpr instead of
ExistentialMemberRefExpr, and enhance silgen to avoid unnecessary copies of protocol
and archetype bases.   With this, uses of properties in protocols start to work.


Swift SVN r14270
2014-02-22 20:52:11 +00:00
Chris Lattner
380e44c615 remove ExistentialSubscriptExpr. We don't need specialized forms of
subscriptexpr for various base types, for the same reason we don't need
multiple different kinds of MemberRefExpr.


Swift SVN r14268
2014-02-22 20:18:02 +00:00
Chris Lattner
0134eb2309 rework sema and silgen to build subscripts on protocols as
SubscriptExpr instead of ExistentialSubscriptExpr.  The later
is just a special case of the former.


Swift SVN r14267
2014-02-22 20:09:54 +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