Commit Graph

2516 Commits

Author SHA1 Message Date
Joe Groff
5e580ab08c Sema: Coerce functions to rvalue before looking through @unchecked?.
Fixes a crash when an lvalue unchecked function type was applied.

Swift SVN r16328
2014-04-14 20:10:20 +00:00
Joe Groff
3bad92b342 AST: Remove the stopgap BridgeToBlockExpr and handle block <-> non-block conversions freely as function conversions.
Teach SILGen to handle function representation changes as part of function conversion instead of needing to be spoonfed a special expr for the purpose. Handle representation changes in both directions to and from blocks using the same logic as the bridging conversions.

Swift SVN r16318
2014-04-14 15:00:34 +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
60a52651e2 Deal with weird tuple element expressions that result from tuple-to-scalar conversions.
We're still building tuple types that involve lvalues in the type
checker. Generally, tuple-to-tuple conversion fixes these up, but the
tuple-to-scalar conversion was not. Fixes <rdar://problem/16555384>.

Swift SVN r16191
2014-04-11 01:19:00 +00:00
Joe Groff
7f47ea97fa Sema: Rework __inout_conversion to pass inouts instead of pre-converted RawPointers.
Make it the conversion function's responsibility to addressof the inout if it wants that pointer. For things like mutable array conversion, we actually want the original inout as a parameter, particularly so we can call _makeUnique on it without disturbing its reference count.

Swift SVN r16090
2014-04-09 00:51:40 +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
Joe Groff
c01f57a693 Sema: Don't skip inout-qualification of generic bases to property accesses.
If we don't do the inout qualification, then we end up building a load of the base, which breaks the writeback chain, causing <rdar://problem/16525257>.

Swift SVN r15961
2014-04-04 22:41:22 +00:00
Chris Lattner
b6724db0db rework how implicitly "direct" property access is being computed in two ways:
- Set the direct bit on accesses to "Stored" properties, not just "stored
  with trivial accessors" ones.  This solves a ordering problem when analyzing
  uses of the property before it gets promoted to having trivial accessors.
- Chance our computation of "being directly defined on the type" to look through
  extension declcontexts, so we consider init methods in extensions to be
  directly defined on the type.

This is a prerequisite for other changes I'm working on, NFC from these alone.



Swift SVN r15949
2014-04-04 18:56:22 +00:00
Dmitri Hrybenko
f198c28d75 Serialize @required as a DeclAttribute
Also introduce an invalid bit on a DeclAttribute for use by semantic analysis.

This fixes AST printing for @required.


Swift SVN r15938
2014-04-04 15:24:47 +00:00
John McCall
cc0dcfed2e Allow protocol methods that return Self? to be
called on existentials.

Swift SVN r15774
2014-04-02 04:01:18 +00:00
Joe Groff
ba34976f87 SILGen: Implement lowering for writeback conversion.
Lower LValueConversionExprs to LValueConversionComponents of SILGen's LValues, which add the conversion pair as a logical component of a writeback chain.

Swift SVN r15771
2014-04-02 03:15:12 +00:00
Joe Groff
8f1c2d1e79 Sema: Implement type-checking for inout writeback conversion.
Add a third branch to the constraint system for '&x' expressions that allows conversion from an lvalue to a type via an additional writeback step:

- Add an LValueConversionExpr node that converts from @lvalue T to @lvalue U, given a pair of functions that convert T -> U and U -> T, to represent the writeback temporary.
- Allow conversion in an inout expression from @lvalue T to a type U that has the following members:

  static func __writeback_conversion(Builtin.RawPointer, T.Type) -> U
  static func __writeback_conversion_get(T) -> V
  static func __writeback_conversion_set(V) -> T

which builds a solution that produces an LValueConversion from the get/set pair before passing the pointer to the writeback temporary off to the conversion function.

Swift SVN r15764
2014-04-02 00:17:51 +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
John McCall
6e03b1423c Always coerce the operand of an optional force to
Optional type,

The attempt to coerce the operand to UncheckedOptional for
dynamic member accesses leads to an inconsistency when
applying the constraint solution because we haven't figured
out how to convert to UncheckedOptional<T> --- all the
conversion restrictions are to optional type.

The test case will be part of the standard test suite when
applying the UncheckedOptional import patch.

In order to continue to work around weaknesses in SILGen's
function conversion code, peephole optional conversion in
the function application path.

Swift SVN r15651
2014-03-30 19:15:18 +00:00
John McCall
b87fb132bf Implicitly force the base object when building a dynamic
lookup call.

Swift SVN r15638
2014-03-29 23:17:44 +00:00
Joe Groff
953c93d936 Sema: Rework inout conversion to do simple member lookup instead of using a protocol.
We'll need types to be convertible from multiple kinds of inouts, which currently can't be represented with protocol conformance since we only allow one protocol conformance per type per protocol. Instead just look for a magic "__inout_conversion" static method in the type; this is lame but easy, and inout conversions shouldn't be available outside of the stdlib anyway.

Swift SVN r15599
2014-03-29 02:50:32 +00:00
Joe Groff
5eb493fff4 Sema: Don't crash if conformance testing an inout conversion type fails.
Swift SVN r15597
2014-03-29 02:50:28 +00:00
Joe Groff
b3e9a17269 SILGen: Implement inout address conversion.
Implement lowering for the LValueToPointer and InOutConversion expressions. For the former, we emit the lvalue, then convert it to a RawPointer; for the latter, we introduce an InOutConversion scope, which suppresses any nested writeback conversion scopes.

This completes the implementation of inout address conversion, except that we don't implement reabstraction of the lvalue prior to taking its address. Simply report them unimplemented for now, since reabstraction should not come up for our immediate use case with C types.

Swift SVN r15595
2014-03-29 02:50:26 +00:00
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