Commit Graph

227 Commits

Author SHA1 Message Date
Max Moiseev
a49dab6bf8 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-29 12:08:52 -08:00
Slava Pestov
6812b6926b Sema: Cleanups and minor fixes for protocol 'Self' types
We had four duplicated implementations of checking how a protocol
requirement uses 'Self', all slightly wrong or incomplete:

- When deciding if the protocol type can be used as an existential.
  This one would just ignore 'Self' in the return type of a method
  completely, which was incorrect for cases where 'Self' is
  contravariant but part of the return value, for example:

  func foo() -> (Self -> ())

- When deciding if a member access can be performed on an existential
  value. This is distinct from the former, because the member may
  have been defined in a protocol extension, in which case it cannot
  be used even if the protocol type can be used as an existential.
  Unfortunately, this implementation was overly conservative, and
  would reject uses of 'Self' where Sema could in fact erase the
  existential type, for example:

  func foo() -> Self??
  func foo() -> Self.Type
  func foo() -> (Self, Self)

  This function handled function return types correctly, effectively
  plugging the leak in the previous code. It did lead to inconsistent
  behavior with protocols that had contravariant Self in requirements
  though; sometimes we would diagnose uses of the existential type,
  other times we would only complain about specific members.

- When deciding if a method in a non-final class can model a protocol
  requirement. This one was the most elaborate one, but here
  contravariance and uses of associated types are actually okay, so
  it was written to pick up covariant 'Self' only. However, it also
  did not handle metatypes and tuples.

- When opening the type of member of an existential, we would check
  if the return value was 'Self' or an optional of 'Self', but again
  this check was too conservative, so after the previous three were
  fixed, we could reference members on existentials that did not
  have a correct opened type.

Now, these have been combined into one check. To fix some crashes,
Sema's implementation of erasing existentials now relies on
coerceToType() instead of hand-rolling a few coercions of its own,
and wrapping the rest in CovariantFunctionConversionExpr, which
didn't make much sense if the result was not a function type.

SILGen still does not support function type conversions where an
existential return value is being erased; these would silently
miscompile before, but crash with an assertion now, because they
are correctly modeled as a FunctionConversionExpr, and not
CovariantFunctionConversionExpr.
2016-02-28 23:52:35 -08:00
Daniel Duan
2bc78b8c09 [stdlib] update for 'inout' adjustment (SE-0031) 2016-02-26 12:02:29 -08:00
Max Moiseev
0b759a409c Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-23 14:26:14 -08:00
Max Moiseev
481bcabcba [stdlib] API naming guidelines applied to split and join
- `separator` label for first argument of `split`
- `join` and related types are renamed to `joined`
2016-02-22 15:43:33 -08:00
Daniel Duan
e0cc095063 [Parser] updated tests for "expected declaration" companion note 2016-02-19 11:05:03 -08:00
Dmitri Gribenko
98561f6137 stdlib: joinWithSeparator(_:) => join(separator:) 2016-02-18 22:30:57 -08:00
Dmitri Gribenko
dd75aed67a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-17 14:40:05 -08:00
Max Moiseev
3a3984877a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-15 15:43:34 -08:00
Slava Pestov
27aad39c79 This test already passes on master 2016-02-11 23:51:47 -08:00
Slava Pestov
3aacf5d805 ArchetypeBuilder: Allow generic signature superclass constraints to contain type parameters
There was a diagnostic to catch these, but it wasn't triggered
reliably, and it sounds like users were already relying on this
feature working in the few cases where it did.

So instead, just map an archetype's superclass into context
when building the archetype.

Recursion is still not allowed and is diagnosed, for example
<T, U where T : C<U>, U : C<T>>.

Note that compiler_crashers_fixed/00022-no-stacktrace.swift no
longer produces a diagnostic in Sema, despite the fact that the
code is invalid. It does diagnose in IRGen when we map the
type into context. Diagnosing in Sema requires fixing the
declaration checker to correctly handle recursion through a
generic signature. Right now, if recursion is detected, we bail
out, but do not always diagnose. Alternatively, we could
prohibit unbound generic types from appearing in generic
signatures.

This is a more principled fix for rdar://problem/24590570.
2016-02-11 23:23:26 -08:00
Max Moiseev
55fde4c923 making tests pass 2016-02-10 16:08:40 -08:00
Chris Lattner
42bc090d43 Fix compiler_crashers/28218-swift-valuedecl-settype.swift
In some completely insane cases, typechecking an EnumElementDecl
can recursively reference itself.  Make sure to produce an error
and bail out when this happens.
2016-02-09 21:46:56 -08:00
Chris Lattner
c70923e1fb Fix compiler_crashers/28220-swift-lvaluetype-get.swift by being more
careful about type transforming that produces an ErrorType.
2016-02-09 21:34:15 -08:00
Daniel Duan
6bf8bde92b update tests to reflect changes in previous commit 2016-02-07 22:10:47 -08:00
Max Moiseev
61c837209b Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-04 16:13:39 -08:00
Chris Lattner
94dd92fcb8 Fix compiler_crashers 22725 & 28236 by reworking parameter parsing error
recovery a bit.
2016-02-01 20:50:32 -08:00
Chris Lattner
9b503272a4 fix compiler_crashers/28232-swift-typechecker-typecheckfunctionbodyuntil.swift 2016-01-31 21:46:34 -08:00
Chris Lattner
d0a9479d46 Fix compiler_crashers/28246-swift-expr-propagatelvalueaccesskind.swift
Teach CSApply that InOutExpr around an UnresolvedType shouldn't propagate
lvalue access kinds.
2016-01-31 21:08:38 -08:00
Chris Lattner
a63be90828 fix compiler_crashers/28219-swift-lvaluetype-get.swift
Not all types are l-valuable, notably InoutType's.  This seems like a
weird restriction to put in the type checker, but it is the cleanest
solution to this.  The better solution would be to change how
inoutexpr/inouttype are represented completely... maybe someday.
2016-01-29 23:18:33 -08:00
Chris Lattner
ff34db7950 fix a few compiler crashers
These were due to CSDiags not reverting the semantic expr embedded in CollectionExprs
when retypechecking them.
2016-01-29 21:13:57 -08:00
David Farler
3f635d04c7 Reinstante var bindings in refutable patterns, except function parameters.
This reverts commits: b96e06da44,
                      8f2fbdc93a,
                      93b6962478,
                      64024118f4,
                      a759ca9141,
                      3434f9642b,
                      9f33429891,
                      47c043e8a6.

This commit leaves 'var' on function parameters as a warning to be
merged into Swift 2.2. For Swift 3, this will be an error, to be
converted in a follow-up.
2016-01-29 15:27:08 -08:00
Chris Lattner
9bacb09708 Fix 24969-swift-vardecl-emitlettovarnoteifsimple.swift
A use can happen in an initializer declcontext, which has no containing method body.
2016-01-29 14:40:11 -08:00
Chris Lattner
d12a4b988d Fix 28244-swift-valuedecl-isinstancemember.swift
Formerly we stopped type checking a PatternBindingDecl when it was marked
as invalid.  This prevented semantic analysis from doing things like expanding
"stored" properties in protocols into computed properties with getters and setter,
causing downstream problems.

Stop doing this, and instead do a bit of work to silence the downstream errors in
a more narrow way.
2016-01-29 14:32:55 -08:00
Slava Pestov
1312cb8afa This test no longer crashes with an assertion, so it doesn't require asserts 2016-01-28 15:02:04 -08:00
Slava Pestov
3550897090 The previous patch accidentally fixed some compiler_crashers 2016-01-27 23:51:20 -08:00
Chris Lattner
8654282bee fix 28239-swift-declcontext-lookupqualified.swift, module lookup can be done
without access control now by diagnostics.
2016-01-25 22:08:43 -08:00
Chris Lattner
b5694e941e fix 28241-swift-valuedecl-isaccessiblefrom.swift 2016-01-25 22:06:14 -08:00
Janek Spaderna
24b5c4cd1b Move logic into one place by merging the first loop into the second
Now all the logic to resolve a type by iterating through the decl context hierarchy is moved into one place.
2016-01-25 20:43:23 +01:00
Janek Spaderna
1f0643f404 Correctly resolve associated types in nested protocols
The problem was that an associated type was always resolved with the nearest protocol `Self` as a reference, but in the case of nested protocols the associated type might be from the enclosing protocol leading to a crash.

We now enumerate in a bottom-up way through the contexts until we have found the correct protocol which provides us with the `Self` reference to resolve the associated type.
2016-01-24 14:42:18 +01:00
Joe Pamer
a59e78749d - When simplifying constraint systems generated for deeply nested binary expressions with homogeneous argument types, directly bind the parameter type variable to the argument type. This generally improves type check performance of such expressions.
- Fix the test invocation of a fixed compiler crasher - it now compiles and runs cleanly.
2016-01-22 12:34:34 -08:00
Joe Pamer
e9c44f2877 Resolve three crashers that were fixed by the last set of changes. 2016-01-22 12:34:34 -08:00
Chris Willmore
983a674e0c Make use of curried function declaration syntax an error.
<rdar://problem/23111018>
2016-01-20 21:57:38 -08:00
Dmitri Gribenko
220bac09a7 Remove 'asserts' requirements from fixed compiler crash tests 2016-01-20 14:40:36 -08:00
Max Moiseev
9a018bd77d Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-20 14:38:22 -08:00
Chris Lattner
888c415f06 Two compiler_crashers were fixed by recent changes, update them. 2016-01-20 11:04:54 -08:00
Doug Gregor
7d70b704e4 Merge commit '5e11e3f7287427d386636a169c4065c0373931a8' into swift-3-api-guidelines 2016-01-19 23:18:20 -08:00
Dmitri Gribenko
a6352968a6 Mark a crash test as fixed 2016-01-19 20:22:10 -07:00
Chris Lattner
5ba57cb498 Fix ExprRewriter::coerceClosureExprToVoid to be resilient to type checking
closures which have already been transformed into void conversion closures.

This fixes 28213-swift-expr-walk.swift/28187-llvm-foldingset-swift-constraints-constraintlocator.swift
2016-01-17 12:07:13 -08:00
Chris Lattner
6ea637f698 Fix 28203-swift-typebase-getdesugaredtype.swift by being more careful about setting an errortype on an AssociatedTypeDecl when type checking of the containing protocoltype has failed. 2016-01-17 11:37:35 -08:00
Chris Lattner
d101ccdf98 Fix 28203-swift-typebase-getdesugaredtype.swift by being more careful about
setting an errortype on an AssociatedTypeDecl when type checking of the
containing protocoltype has failed.
2016-01-17 11:37:35 -08:00
Doug Gregor
38c1de69e4 Reinstate "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit ce7b2bcf09, tweaking
a few validation tests appropriately (1 crasher fixed, two -verify
tests that needed updating).
2016-01-14 00:21:48 -08:00
Chris Lattner
2f78b70857 recent diagnostics changes fixed 5 crashers and broke 1. 2016-01-11 22:43:27 -08:00
Chris Lattner
8d835dee7c My diagnostics fix fixed this test along the way. 2016-01-11 20:47:47 -08:00
Max Moiseev
08e1e4a043 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-11 16:51:11 -08:00
Slava Pestov
cbb95a2910 Merge pull request #926 from jtbandes/innermost-params
[AST] Fix inconsistent handling of generic args & params during BoundGenericType::getSubstitutions
2016-01-09 23:30:06 -08:00
Slava Pestov
8b57337ca6 Merge pull request #910 from jtbandes/invalid-proto
[Sema] Improve handling of invalid protocols during conformance checking
2016-01-09 23:27:41 -08:00
Chris Lattner
926adfe7e4 Merge pull request #925 from jtbandes/lvalue-errortype
[Sema] Skip ErrorTypes in potential bindings during constraint solving
2016-01-09 20:19:39 -08:00
Chris Lattner
d9b2fe601b fix a compiler crash in error recovery that @practicalswift just reported. 2016-01-09 20:17:56 -08:00
Chris Lattner
11fda96b85 When we detect a property/subscript that has a setter without a getter, create a dummy
getter to avoid breaking downstream invariants.  This fixes three crashers, including
one added by @practicalswift yesterday.
2016-01-09 11:38:08 -08:00