Commit Graph

7976 Commits

Author SHA1 Message Date
Doug Gregor
a7a13b6c4f [Constraint solver] Don't bail out early when we have equivalent type variables.
Found by inspection; a misplaced 'break' meant that, if we encountered
a relational constraint where both sides are type variables that are
equivalent, we would stop looking for more type bindings, which could
lead us to miss obvious type inferences. While I wasn't able to
construct a case where this changed the behavior of type inference,
this *does* happen, and the previous code was clearly wrong.
2016-10-20 10:36:02 -07:00
Doug Gregor
3d6de63b4f [Type checker] Don't use default literal types for normal conformance constraints
We previously allowed *any* conformance constraint to an
ExpressibleBy*Literal protocol to provide a default type (e.g.,
Int/Double/String/etc.) based on the kind of literal protocol. This
led to weird type inference behavior. Restrict the defaulting to
actual literals---not just conformances to literal protocols---which
is a much more reasonable rule.

Because this is a source-breaking change, only introduce this new
behavior when the Swift version >= 4, maintaining the old behavior in
Swift 3 compatibility mode.
2016-10-20 10:36:02 -07:00
swift-ci
d5e638f54e Merge pull request #5373 from DougGregor/iuo-infer-28621624 2016-10-19 16:42:51 -07:00
swift-ci
c582190ca7 Merge pull request #5364 from practicalswift/gardening-20161019 2016-10-19 16:29:25 -07:00
Rintaro Ishizaki
31245aaa1a [Sema] Check hasResult() before getResult() from ReturnStmt (#5362)
Fixes compiler_crashers/28390-swift-expr-walk.swift
2016-10-20 08:18:36 +09:00
Doug Gregor
4b9adae8ae [Constraint Solver] Don't perform a join when we've adjusted an IUO to optional.
Fixes rdar://problem/28621624, an intentional source-breaking change
from Swift 3.
2016-10-19 16:08:08 -07:00
Doug Gregor
77942d37d5 Tighten up @objc optional near-miss detection heuristics.
The @objc optional requirement near-miss heuristics were too
permissive, and could occasionally produce ridiculous results that
were nowhere close to a "near" miss. Make the diagnostics more
conservative, and fix an issue with an errant sentinel value.

Fixes rdar://problem/26380688.
2016-10-19 10:55:47 -07:00
practicalswift
5f8ce30ec4 [gardening] Fix recently introduced typos. 2016-10-19 12:59:10 +02:00
swift-ci
e3c3cc542c Merge pull request #5357 from rudkx/sort-file-list 2016-10-18 23:03:19 -07:00
Mark Lacey
a8ddd7c970 Sort the CMakeLists.txt file list for lib/Sema. 2016-10-18 22:09:09 -07:00
Doug Gregor
2f894958ac Merge pull request #5347 from DougGregor/objc-near-miss-suppress
Suppress silly diagnostics from `@objc` near-miss checking
2016-10-18 12:56:59 -07:00
Doug Gregor
da2a7cef46 Don't complain about near misses for declarations that are overrides.
An overriding declaration doesn't have a choice about its signature,
because the signature is dictated by the overridden
declaration. Therefore, don't produce a warning for it.

Fixes rdar://problem/28524237.
2016-10-18 11:25:22 -07:00
Doug Gregor
5267c6a269 If a member is a witness to any @objc requirement, don't call it a near miss.
When @objc inference was extended to look at the conformances of
superclasses, the code that diagnosed near misses was not similarly
updated, so we could end up producing a near-miss diagnostic on a
declaration that was already a witness to another protocol. Use the
same witness-finding logic that we use for @objc inference so this
doesn't happen again.

Fixes the rest of rdar://problem/27348369
2016-10-18 11:25:00 -07:00
Rintaro Ishizaki
c138e4cd8f [Sema] Swift3 compatibility: Fix ambiguous protocol composition production
Fixes: https://bugs.swift.org/browse/SR-2843

'P1 & P2.Type' is mistakingly accepted and parsed as (meatatype (composition P1, P2))
in swift3. Now, we parse it as (composition P1, (metatype P2))

For source compatibility, reconstruct it as Swift3.

Also, this solves inconsistent behavior between type and type-expression in Swift3.

typealias T1 = P1 & P2?  // was accepted as '(P1 & P2)?'
let T2 = (P1 & P2?).self // was silently accepted as 'P1' in Swift3.0
2016-10-19 02:22:23 +09:00
Rintaro Ishizaki
22f56f26c9 [Sema] Fix TypeExpr construction for protocol composition
Previously, non-IdentTypeRepr types are silently discarded.
'(P1? & P2.Type).self' ends up in empty protocol composition (aka 'Any').

Let CompositionType to hold them as well, and TypeChecker to diagnose them.
2016-10-19 02:22:23 +09:00
Rintaro Ishizaki
2fb48c6594 [AST] Rename ProtocolCompositionTypeRepr to CompositionTypeRepr
And make it be able to composite any TypeReprs.

Although Swift doesn't support composition of arbitrary types, AST
should be able to hold any TypeReprs, to represent syntax as accurate as
possible.
2016-10-19 02:22:23 +09:00
Mark Lacey
f72576d03c Merge pull request #5237 from xedin/SR-2484
SR-2484: Improve diagnostic for incorrectly called private init
2016-10-17 18:37:08 -07:00
Robert Widmann
00ec660dc2 Merge pull request #5320 from practicalswift/remove-unused-argument-in-isFavoredParamAndArg
[gardening] Remove unused argument otherArg in isFavoredParamAndArg(…)
2016-10-17 00:23:49 -04:00
Mark Lacey
cdf712349d Check for null or error type and return if we hit either.
In usesTypeMetadataOfFormalType(), bail out if we're checking a cast and
the casted-to type is null or error_type. We would have already emitted
a diagnostic on the function body by this point and this avoids crashing
immediately after.

Suggestions on a better place for the test would be welcome. The crash
requires the cast to be in the body of a function in an NSObject-derived
cast.

Resolves rdar://problem/28583595.
2016-10-16 20:00:16 -07:00
practicalswift
de2c9c64d0 [gardening] Remove unused argument otherArg.
Added in commit 49b833b51a.
2016-10-16 20:24:12 +02:00
Pavel Yaskevich
352f4b7f73 [Diagnostics] SR-2484: Improve diagnostic for incorrectly called private init 2016-10-15 02:35:27 -07:00
Mark Lacey
4d2e0ec427 Merge pull request #5244 from xedin/SR-2193
SR-2193: Improve diagnostic when member exists but it's not a type
2016-10-14 19:24:09 -07:00
swift-ci
a4104d87d5 Merge pull request #5300 from DougGregor/constraint-solver-cleanups 2016-10-14 16:59:09 -07:00
Pavel Yaskevich
578e36a7e1 [Type Checker] SR-2505: Fix "Call arguments did not match up" assertion
Always check arguments of the tuple type against corresponding parameters,
otherwise for a single argument functions e.g. foo(_ a: Any) after SE-0046
type checker is going to produce incorrect solution.
2016-10-14 13:27:33 -07:00
Mark Lacey
32634b1bdd Merge pull request #5239 from xedin/SR-1255
SR-1255: Improve diagnostic when one of the parameters marked as autoclosure
2016-10-14 12:40:21 -07:00
Pavel Yaskevich
72b5939612 [Diagnostics] SR-2193: Improve diagnostic when member exists but it's not a type 2016-10-14 10:34:32 -07:00
Doug Gregor
2e800f4acc [Constraint system] Centralize the handling of "unsolved" returns in matchTypes. 2016-10-14 10:28:20 -07:00
Doug Gregor
11b30a22a6 [Constraint solver] Remove some dead instance variables. 2016-10-14 09:31:23 -07:00
Doug Gregor
49b833b51a [Type checker] Eliminate the 'literalConformanceProto' state on type variables.
The 'literalConformanceProto' field of
TypeVariableType::Implementation didn't take into account equivalence
classes of type variables. Eliminate it, and either look at the actual
expressions (for optimizing constraints during constraint generation)
or the actual constraints on a given type variable (for determining
whether to include optionals in the set of potential type variable
bindings).

(cherry picked from commit 6bdd9cfae5)
2016-10-13 16:22:01 -07:00
Doug Gregor
6ce4be96f1 Merge pull request #5261 from DougGregor/type-checker-extra-constraints
[Type checker] Eliminate generation of useless constraints NFC.
2016-10-13 13:40:09 -07:00
Slava Pestov
5ab94a6ef0 AST: Add "re-sugaring" to GenericEnvironment
Sugared GenericTypeParamTypes point to GenericTypeParamDecls,
allowing the name of the parameter as written by the user to be
recovered. Canonical GenericTypeParamTypes on the other hand
only store a depth and index, without referencing the original
declaration.

When printing SIL, we wish to output the original generic parameter
names, even though SIL only uses canonical types. Previously,
we used to accomplish this by mapping the generic parameter to an
archetype and printing the name of the archetype. This was not
adequate if multiple generic parameters mapped to the same
archetype, or if a generic parameter was mapped to a concrete type.

The new approach preserves the original sugared types in the
GenericEnvironment, adding a new GenericEnvironment::getSugaredType()
method.

There are also some other assorted simplifications made possible
by this.

Unfortunately this makes GenericEnvironments use a bit more memory,
however I have more improvements coming that will offset the gains,
in addition to making substitution lists smaller also.
2016-10-12 18:56:16 -07:00
Graydon Hoare
28b13a18eb Merge pull request #4985 from graydon/SR-2709-available-swift-version
SR-2709: @available(swift, ...)
2016-10-12 13:38:04 -07:00
Mark Lacey
623a163ffe Merge pull request #5259 from rudkx/fix-28722908
Fix source location on collection cast optional-to-Any warning.
2016-10-12 13:33:23 -07:00
Graydon Hoare
098c42ede8 Add missing EncodedDiagnosticMessage wrapper. 2016-10-12 11:21:30 -07:00
Graydon Hoare
cec8f58197 Add swift::diagnoseDeclAvailability, use in TypeCheckType. 2016-10-12 11:21:30 -07:00
Doug Gregor
f1c4e14485 [Type checker] Eliminate generation of useless constraints NFC.
There's no point in adding the constraints known on an associated type
to the constraint system, because they're implied by the protocol
constraint itself.
2016-10-12 11:21:17 -07:00
Graydon Hoare
77df25d892 Generalize AvailableAttr MinVersion checks to cover language versions. 2016-10-12 11:20:44 -07:00
Graydon Hoare
66f2027f62 s/Version/PlatformVersion/ to availability specs, add LanguageVersion. 2016-10-12 11:20:42 -07:00
Graydon Hoare
42c1a6ce42 Rename UnconditionalAvailabilityKind and UnavailableInCurrentSwift.
UnconditionalAvailabilityKind => PlatformAgnosticAvailabilityKind
    ::UnavailableInCurrentSwift =>   ::SwiftVersionSpecific

Plus a couple related method renamings. Prep work for SR-2709.
2016-10-12 11:20:41 -07:00
Doug Gregor
b36bd89865 Merge pull request #5254 from DougGregor/revert-literal-conformance-proto
Speculatively revert "[Type checker] Eliminate the 'literalConformanceProto' state on type variables."
2016-10-12 11:17:49 -07:00
Mark Lacey
30544422af Fix source location on collection cast optional-to-Any warning.
The warnings here are not ideal, nor are the fixits, but having a
correct source location at least helps users determine where the
conversions are happening.

I've filed https://bugs.swift.org/browse/SR-2928 to improve the warnings
and fixits.

This resolves https://bugs.swift.org/browse/SR-2921 and the warning
location portion of rdar://problem/28722908.
2016-10-12 11:09:48 -07:00
Michael Ilseman
7d1da2af3d Merge pull request #5243 from milseman/escaping
[3.0 compat] Don't diagnose @escaping var-arg closures.
2016-10-12 10:44:28 -07:00
Doug Gregor
0699263b84 Eliminate use of now-removed getInnerParenType(). 2016-10-12 09:33:38 -07:00
Doug Gregor
01fa24cc9b Speculatively revert "[Type checker] Eliminate the 'literalConformanceProto' state on type variables."
This reverts commit 6bdd9cfae5. This
commit *appears* to be breaking something in Dollar involving
inference with array literals and 'nil'; pull it back for more
investigation.
2016-10-12 09:20:16 -07:00
Robert Widmann
f59d5cb577 Normalize the way paren types are stripped in Sema. 2016-10-12 00:00:39 -04:00
swift-ci
59aefbc511 Merge pull request #5247 from CodaFi/mu 2016-10-11 20:35:20 -07:00
Doug Gregor
a8db77a569 Merge pull request #5235 from DougGregor/type-checker-cleanups
[NFC] Type checker cleanups
2016-10-11 20:03:43 -07:00
Robert Widmann
975e2db702 fix a misleading comment 2016-10-11 22:40:11 -04:00
Michael Ilseman
12fb0bad7b [swift-version] Allow swift-version 4 and tests
The recent @escaping on variadic argument closures back-compat fix is
the first Swift 3.0 compatibility behavior that we don't want to carry
forwards indefinitely into the future. To address this, we
version-gate the diagnostic suppression.

Makes it an official compatibility check. Creates new test directory
for compatibility testing. Allow -swift-version 4 so that we can test
it both ways.
2016-10-11 17:42:25 -07:00
Doug Gregor
6bdd9cfae5 [Type checker] Eliminate the 'literalConformanceProto' state on type variables.
The 'literalConformanceProto' field of
TypeVariableType::Implementation didn't take into account equivalence
classes of type variables. Eliminate it, and either look at the actual
expressions (for optimizing constraints during constraint generation)
or the actual constraints on a given type variable (for determining
whether to include optionals in the set of potential type variable
bindings).
2016-10-11 17:09:13 -07:00