Commit Graph

7976 Commits

Author SHA1 Message Date
Xi Ge
0ccbfdb933 Index: Record override-of relationship between a decl in protocol extension and the protocol requirements it can provide default implementations for. (#8418) 2017-03-29 19:39:39 -07:00
practicalswift
5a7aab7647 Merge pull request #8395 from practicalswift/gardening-20170328
[gardening] Fix typos. Fix missing copyright notice. Remove unused method, etc.
2017-03-29 15:32:06 +02:00
Slava Pestov
53759f7126 Use ValueDecl::isDynamic() instead of getAttrs().hasAttribute<DynamicAttr>() 2017-03-29 00:46:43 -07:00
Xi Ge
3ad7df273f [SourceKit] DocSupport: constraint extensions provide default implementation too. rdar://25692947 (#8398) 2017-03-28 15:55:39 -07:00
practicalswift
430e8d4a62 [gardening] Use "foo && isa<C>(foo)" instead of "dyn_cast_or_null<C>(foo)" when the result is unused 2017-03-28 21:48:53 +02:00
Xi Ge
6e3698f7e8 SourceKit: for DocSupport, report default implementations of inherited protocols in sub-protocol's extensions. rdar://25692947 (#8394)
For instance:

protocol P1 { 
  func foo() 
}
protocol P2 : P1 { 
  func bar() 
}
extension P2 { 
  func foo() {} 
}

We report the foo() in P2's extension as the default implementation of foo() declared in P1.
2017-03-28 12:10:29 -07:00
Slava Pestov
56ad8bd482 Merge pull request #8386 from slavapestov/non-overlapping-availability-for-properties
Allow overloading properties with non-overlapping availability
2017-03-27 21:49:38 -07:00
Slava Pestov
4da26110fd Allow overloads of properties with non-overlapping availability
This allows library authors to change the type of a computed
property from one Swift version to the next.
2017-03-27 21:07:37 -07:00
Xi Ge
fb842c789a IDE: Hide the implementation detail of ResolvedMemberResult. NFC (#8385) 2017-03-27 20:47:20 -07:00
Xi Ge
5663f6799f IDE: Simplify/Refactor some code that collects the default implementations in protocol extensions. NFC (#8381) 2017-03-27 18:14:45 -07:00
Slava Pestov
2dc819d1d1 AST: Introduce new form of TypeBase::getCanonicalType()
I've fixed a few bugs recently where I had to switch
a getCanonicalType() call to instead use the stronger
GenericSignature::getCanonicalTypeInContext().

Avoid the 'if (genericSig = ...)' dance by adding a new
form of TypeBase::getCanonicalType() which takes a
signature, and if it's null, just falls back to the
standard getCanonicalType().
2017-03-27 00:18:26 -07:00
Slava Pestov
70f3d93111 Merge pull request #8363 from slavapestov/fix-lvalue-capture-in-generic-function
Sema: Fix captures of lvalues from nested generic functions
2017-03-27 00:17:09 -07:00
Slava Pestov
40cec61217 Sema: Fix captures of lvalues from nested generic functions
The "map into the right context" logic was only getting hit
if we didn't exit early to handle the lvalue case. Move it up
to the top of the function.

Fixes <https://bugs.swift.org/browse/SR-4369>.
2017-03-26 23:31:03 -07:00
Slava Pestov
35a5594035 SILGen: Fixes for *static* 'Self'-returning methods
Take a seat and pour yourself a beer because this is
going to get pretty intense.

Recall that class methods that return 'Self', have a
'self' type of @dynamic_self X or @dynamic_self X.Type,
for some class X, based on if the method is an instance
method or a static method.

The instance type of a metatype is not lowered, and we
preserve DynamicSelfType there. This is required for
correct behavior with the SIL optimizer.

For example if you specialize a function that contains a
'metatype $((T) -> Int, T).Type' SIL instruction or
some other metatype of a structural type containing a
generic parameter, we might end up with something like
'metatype $((@dynamic_self X) -> Int, X).Type'
after substitution, for some class 'X'. Note that the
second occurrence of 'X', is in "lowered position" so
the @dynamic_self did, indeed, get stripped away.

So while *values* of @dynamic_self type don't need to
carry the fact that they're @dynamic_self at the SIL
level, because Sema has inserted all the right casts.

Metatypes do though, because when lowering the 'metatype'
instruction, IRGen has to know to emit the type metadata
from the method's 'self' parameter, and not the static
metadata for the exact class type.

Essentially, 'metatype @dynamic_self X.Type' is
the same as 'value_metatype %self : X.Type', except that
the @dynamic_self type can appear inside other structural
types also, which is something we cannot write in the
AST.

This is all well and good, but when lowering a
SILFunctionType we erase @dynamic_self from the 'self'
parameter type because when you *call* such a function
from another function, you are not necessarily calling
it on your own 'self' value. And if you are, Sema
already emitted the right unchecked downcast there to
turn the result into the right type.

The problem is that the type of an argument (the value
"inside" the function) used to always be identical to
the type of the parameter (the type from "outside" the
function, in the SILFunctionType). Of course this
assumption is no longer correct for static methods,
where the 'self' argument should really have type
@dynamic_self X.Type, not X.Type.

A further complication is closure captures, whose types
can also contain @dynamic_self inside metatypes in other
structural types. We used to erase @dynamic_self from
these.

Both of these are wrong, because if you call a generic
function <T> (T.Type) -> () with a T := @dynamic_self X
substitution (recall that substitutions are written in
terms of AST types and not lowered types) and pass in
the 'self' argument, we would pass in a value of type
X.Type and not @dynamic_self X.Type.

There were similar issues with captures, with
additional complications from nested closures.

Fix all this by having SILGenProlog emit a downcast
to turn the X.Type argument into a value of type
@dynamic_self X.Type, and tweak capture lowering to
not erase @dynamic_self from capture types.

This fixes several cases that used to fail with
asserts in SILGenApply or the SIL verifier, in particular
the example outlined in <rdar://problem/31226650>,
where we would crash when calling a protocol extension
method from a static class method (oops!).

If you got this far and still follow along,
congratulations, you now know more about DynamicSelfType
than I do.
2017-03-26 22:44:35 -07:00
Hugh Bellamy
b39895b0a5 Fix incorrect format specifiers passed to snprintf in Sema 2017-03-26 15:48:02 +07:00
Slava Pestov
19b12aa3b1 Sema: Fix convenience init delegation to a convenience init in a generic base class
While in the constraint system, the delegation is modeled as
returning an instance of the derived class, in the AST we type
the reference as returning an instance of the base class, and
insert a downcast, because in SILGen we're calling the base
class initializer which is typed as returning the base class.

This bit of fixup logic wasn't happening if the base class was
generic, and so we were not inserting the cast, which would
crash in SILGen with an assert.

Fixes <rdar://problem/31000248>.
2017-03-26 00:00:53 -07:00
Slava Pestov
f4396739fd Sema: Fix up override matching in the presence of non-canonical type parameters
Fixes <https://bugs.swift.org/browse/SR-4321>.
2017-03-25 22:52:14 -07:00
Toni Suter
d630c3fa87 [SR-4347] Improve inference of optional supertypes 2017-03-25 07:44:33 +01:00
swift-ci
8597774bee Merge pull request #8319 from nkcsgexi/simplify-message-enum 2017-03-24 12:24:57 -07:00
Xi Ge
65a1ebe668 Sema: Under EditorMode, simplify the message for missing switch cases. rdar://31197583 2017-03-24 11:48:32 -07:00
Slava Pestov
aebf843dda SIL: Addressors don't need vtable entries
In the old vtable emission code, IRGen would skip addressors,
but they had entries in the SILVTable. This is still correct
behavior, so skip addressors explicitly in SILVTableVisitor.

We never call addressors dynamically, only inside a getter,
setter or materializeForSet. When a property with addressors
is overridden we provide new getters and setters (which may
or may not statically dispatch to a peer addressor).
2017-03-23 20:36:12 -07:00
Slava Pestov
38f27c0496 Sema: Always add synthesized accessors in the same spot
We had some non-deterministic behavior where depending on
validation order, synthesized accessors would end up in
different places because we would sometimes just add them
at the end of the member list.

Now add the getter right after the storage, the setter
right after the getter and the materializeForSet right
after the setter.

This changes some test output where the declaration order
did not make sense before but should otherwise have no
functional effect.
2017-03-23 18:17:41 -07:00
swift-ci
846f698b96 Merge pull request #8293 from DougGregor/superclass-constraint-uses-gp 2017-03-22 21:19:07 -07:00
Doug Gregor
bee3f152aa [Type checker] The superclass of a superclass constraint can have type parameters.
Fixes <rdar://problem/31181895>.
2017-03-22 20:49:08 -07:00
Mark Lacey
aab3de7985 [Constraint solver] Exit immediately from solve() if we already have a failed constraint.
As solveRec() already does, exit immediately if we have a failed
constraint from constraint generation. Not doing so means that we can
create a SolverScope in constraint propagation, and on destruction of
that SolverScope we clear out the failedConstraint field, obscuring the
fact that we had a failure.
2017-03-22 14:49:06 -07:00
Xi Ge
8c497eb02c Sema: Extract the printing part in filling-missing-enum-cases fixit. NFC (#8274) 2017-03-22 13:16:13 -07:00
Mark Lacey
4a4e0f4ab8 [Constraint solver] Minor tweak to where constraint propagation runs.
No real functionality at this point - move the point of invocation for
the moment.
2017-03-21 19:32:32 -07:00
Mark Lacey
a697a2b64b [Constraint solver] Mark a function as static. 2017-03-21 19:32:32 -07:00
Mark Lacey
839e3e9132 [Constraint solver] Disable shrink() when constraint propagation is enabled. 2017-03-21 19:32:32 -07:00
Mark Lacey
c42f6b200b Minor formatting tweak. 2017-03-21 19:32:32 -07:00
Xi Ge
383b0abd62 AST: Deep sugar type reconstitution should be optional. (#8244)
Tentatively fixing a test failure in Sil parser.
2017-03-21 11:04:53 -07:00
Hugh Bellamy
d9879522fb Fix top of tree Clang unused lambda capture warnings 2017-03-21 19:15:08 +07:00
Slava Pestov
99da2ea244 Merge pull request #8211 from practicalswift/use-is-instead-of-getas-where-appropriate
[gardening] Use .is<T>() instead of .getAs<T>() if the result is not needed
2017-03-21 00:39:23 -07:00
Slava Pestov
eb770a5384 Sema: Fix crash when resolving generic typealias inside generic type where the underlying type is not dependent
Stupid corner case missed in testing.

Fixes <rdar://problem/31072437>.
2017-03-20 17:54:46 -07:00
swift-ci
ba4691b87a Merge pull request #8214 from nkcsgexi/reconstitute-sugar-type 2017-03-20 17:23:46 -07:00
Xi Ge
92975fb9c0 AST: Expose reconstituteSugar as a public member function of TypeBase. NFC 2017-03-20 16:14:51 -07:00
practicalswift
83526fe224 [gardening] Use .is<T>() instead of .getAs<T>() if the result is not needed 2017-03-20 22:54:01 +01:00
David Hart
13edc600f0 [SR-2421] Remove variable_never_used fixit to work with two-stage let initialization
The variable_never_used fixit transforms into invalid code in the case of two-stage let initialization. I introduced a new diagnostic that does not fixit and suggests removing the value.
2017-03-18 00:21:18 +01:00
swift-ci
242a177e73 Merge pull request #8093 from hartbit/fix-crasher 2017-03-17 13:19:12 -07:00
practicalswift
3144f4ce1a [gardening] Remove unused variable superclassSig 2017-03-17 08:22:11 +01:00
practicalswift
30e29cf9ac [gardening] Remove unused method isUnparenthesizedTrailingClosure(Type type) 2017-03-17 08:21:08 +01:00
Hugh Bellamy
7a704b2605 Fix MSVC control path warnings 2017-03-16 08:55:51 +07:00
Huon Wilson
ca3a398b4a Merge pull request #8021 from huonw/protocol-where-clause
Parse/typecheck/print where clauses on protocols
2017-03-15 11:00:46 -07:00
David Hart
01b5b6a037 [SR-4205] Removed the non_trailing_closure_before_default_args warning (#8033)
rdar://problem/21193574 says that this warning dates back to when closure args before default args used to be considered as trailing closures. This is not the case anymore so Jordan suggested we remove the warning.
2017-03-15 09:55:08 -07:00
Mark Lacey
abfd19c5b1 [Constraint solver] Update LiteralExpr::shallowClone to set types in type map.
It was getting types from the type map, but not setting them in it.
2017-03-15 00:16:54 -07:00
David Hart
ba13a894c0 Fixed crasher 28707
The @_versioned accessibility check is done against the formal access. But the diagnostics is printed with getAccessForDiagnostics. In cases where the effective access is internal, the diagnostics will crash. Example:

```
class A { // implicitly internal
    @_versioned public var a: Int = 0 // explicity public
}
```
2017-03-15 07:38:53 +01:00
Mark Lacey
041a25ecf1 [Constraint solver] More progress on the constraint solver type map. 2017-03-14 21:56:13 -07:00
Slava Pestov
7809446735 Sema: Fix assertion when performing conformance check of protocol in another file
GenericSignature::getConformanceAccessPath() would call
computeRequirementSignature() if the protocol did not already
have one.

If this happened before the protocol was validated with
validateDecl(), then we would hit an assertion because
validateDecl() calls computeRequirementSignature()
unconditionally.

Change validateDecl() to only call computeRequirementSignature()
if the protocol does not already have a requirement signature.

Progress on <rdar://problem/30817732>.
2017-03-14 21:17:01 -07:00
Slava Pestov
bd6c70c9d2 AST: Fix TypeBase::adjustSuperclassMemberDeclType() to strip generic signatures
Type::subst() does stupid things if you give it a
GenericFunctionType, attempting to build a new "substituted"
GenericSignature by hand.

As the newly-added test case demonstrates, this can trigger
assertions, and the callers of adjustSuperclassMemberDeclType()
didn't care about the generic signature anyway, so strip it off
first.

Soon, I want to have Type::subst() assert if it encounters a
GenericFunctionType, and remove all the junk there altogether,
but there's more work to be done first.

Progress on <rdar://problem/30817732> (RxCocoa build failures on
master), but now it hits further regressions.
2017-03-14 19:10:44 -07:00
John McCall
3c5de5fa0a Preserve type canonicality better in several places and
idiomatize some uses of SILType::getSwiftRValueType().
2017-03-14 14:59:43 -04:00